Skip to content

Commit d354967

Browse files
authored
feat: next component (#18)
1 parent c9f6d32 commit d354967

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+933
-3739
lines changed

examples/basic/pages/index.tsx

+48-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import JsonViewer from '@textea/json-viewer'
1+
import { TextField } from '@mui/material'
2+
import {
3+
applyValue,
4+
JsonViewer,
5+
JsonViewerOnChange
6+
} from '@textea/json-viewer'
27
import type React from 'react'
3-
import { useCallback, useState } from 'react'
8+
import { useCallback, useEffect, useState } from 'react'
49

5-
import type { InteractionProps } from '../../../src/type'
6-
7-
function aPlusB (a:number, b: number) {
10+
function aPlusB (a: number, b: number) {
811
return a + b
912
}
1013

1114
const example = {
12-
string: 'this is a test string',
15+
string: 'this is a string',
1316
integer: 42,
14-
array: [1, 2, 3, 'test', NaN],
15-
float: 3.14159,
17+
array: [19, 19, 810, 'test', NaN],
18+
float: 114.514,
1619
undefined,
1720
object: {
1821
'first-child': true,
@@ -21,17 +24,50 @@ const example = {
2124
},
2225
fn: aPlusB,
2326
string_number: '1234',
27+
timer: 0,
2428
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)')
2529
}
2630

2731
const IndexPage: React.FC = () => {
28-
const [src, setSrc] = useState<object>(() => example)
29-
const handleEdit = useCallback((update: InteractionProps) => {
30-
setSrc(update.updated_src)
32+
const [indent, setIndent] = useState(2)
33+
const [src, setSrc] = useState(() => example)
34+
useEffect(() => {
35+
const loop = () => {
36+
setSrc(src => ({
37+
...src,
38+
timer: src.timer + 1
39+
}))
40+
}
41+
const id = setInterval(loop, 1000)
42+
return () => {
43+
clearInterval(id)
44+
}
3145
}, [])
3246
return (
3347
<div>
34-
<JsonViewer src={src} onEdit={handleEdit}/>
48+
<TextField
49+
value={indent}
50+
type='number'
51+
onChange={
52+
event => {
53+
const indent = parseInt(event.target.value)
54+
if (indent > -1 && indent < 10) {
55+
setIndent(indent)
56+
}
57+
}
58+
}
59+
/>
60+
<JsonViewer
61+
value={src}
62+
indentWidth={indent}
63+
onChange={
64+
useCallback<JsonViewerOnChange>(
65+
(path, oldValue, newValue) => {
66+
setSrc(src => applyValue(src, path, newValue))
67+
}, []
68+
)
69+
}
70+
/>
3571
</div>
3672
)
3773
}

examples/next/next-env.d.ts

-5
This file was deleted.

examples/next/next.config.js

-15
This file was deleted.

examples/next/package.json

-24
This file was deleted.

examples/next/pages/index.tsx

-57
This file was deleted.

examples/next/tsconfig.json

-20
This file was deleted.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"tree-view",
2424
"treeview"
2525
],
26-
"types": "src/type.d.ts",
26+
"types": "dist/src/index.d.ts",
2727
"main": "dist/index.js",
2828
"module": "dist/index.mjs",
2929
"exports": {
@@ -35,7 +35,6 @@
3535
}
3636
},
3737
"files": [
38-
"src/**.d.ts",
3938
"dist"
4039
],
4140
"scripts": {

src/components/ArrayGroup.jsx

-150
This file was deleted.

0 commit comments

Comments
 (0)