Skip to content

Commit 7673d8c

Browse files
authored
Docs (#10)
1 parent 5e988fc commit 7673d8c

18 files changed

+414
-105
lines changed

README.md

Lines changed: 329 additions & 3 deletions
Large diffs are not rendered by default.

demo/src/App.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { ArrowBackIcon, ArrowForwardIcon } from '@chakra-ui/icons'
3434
import demoData from './data'
3535
import { useDatabase } from './useDatabase'
3636
import './style.css'
37-
import { FilterMethod } from './json-edit-react/src/types'
37+
import { FilterFunction } from './json-edit-react/src/types'
3838

3939
function App() {
4040
const [selectedData, setSelectedData] = useState('basic')
@@ -53,7 +53,7 @@ function App() {
5353
const previousThemeName = useRef('') // Used when resetting after theme editing
5454
const toast = useToast()
5555

56-
const { guestbook, updateGuestbook } = useDatabase()
56+
const { liveData, updateLiveData } = useDatabase()
5757

5858
const [{ present: data }, { set: setData, reset, undo, redo, canUndo, canRedo }] = useUndo(
5959
demoData[selectedData].data
@@ -63,10 +63,10 @@ function App() {
6363
switch (selectedData) {
6464
case 'editTheme':
6565
return
66-
case 'liveGuestbook':
67-
setCollapseLevel(demoData.liveGuestbook.collapse)
68-
if (!guestbook) reset({ 'Oops!': "We couldn't load this data, sorry " })
69-
else reset(guestbook)
66+
case 'liveData':
67+
setCollapseLevel(demoData.liveData.collapse)
68+
if (!liveData) reset({ 'Oops!': "We couldn't load this data, sorry " })
69+
else reset(liveData)
7070
return
7171
default:
7272
const newData = demoData[selectedData]
@@ -75,19 +75,19 @@ function App() {
7575
}
7676
}, [selectedData, reset])
7777

78-
const restrictEdit: FilterMethod | boolean = (() => {
78+
const restrictEdit: FilterFunction | boolean = (() => {
7979
const customRestrictor = demoData[selectedData]?.restrictEdit
8080
if (customRestrictor) return (input) => !allowEdit || customRestrictor(input)
8181
return !allowEdit
8282
})()
8383

84-
const restrictDelete: FilterMethod | boolean = (() => {
84+
const restrictDelete: FilterFunction | boolean = (() => {
8585
const customRestrictor = demoData[selectedData]?.restrictDelete
8686
if (customRestrictor) return (input) => !allowDelete || customRestrictor(input)
8787
return !allowDelete
8888
})()
8989

90-
const restrictAdd: FilterMethod | boolean = (() => {
90+
const restrictAdd: FilterFunction | boolean = (() => {
9191
const customRestrictor = demoData[selectedData]?.restrictAdd
9292
if (customRestrictor) return (input) => !allowAdd || customRestrictor(input)
9393
return !allowAdd
@@ -115,9 +115,9 @@ function App() {
115115
case 'editTheme':
116116
reset(themes[previousThemeName.current])
117117
return
118-
case 'liveGuestbook':
118+
case 'liveData':
119119
setIsSaving(true)
120-
await updateGuestbook(data)
120+
await updateLiveData(data)
121121
setIsSaving(false)
122122
toast({
123123
title: 'Whoosh!',
@@ -126,7 +126,7 @@ function App() {
126126
duration: 5000,
127127
isClosable: true,
128128
})
129-
console.log(guestbook)
129+
console.log(liveData)
130130
reset(data)
131131
return
132132
default:
@@ -207,6 +207,7 @@ function App() {
207207
showArrayIndices={showIndices}
208208
maxWidth={650}
209209
className="block-shadow"
210+
stringTruncate={80}
210211
/>
211212
<VStack w="100%" align="flex-end" gap={4}>
212213
<HStack w="100%" justify="space-between" mt={4}>
@@ -238,13 +239,13 @@ function App() {
238239
</Text>
239240
<Button
240241
colorScheme="accentScheme"
241-
leftIcon={selectedData === 'liveGuestbook' ? <AiOutlineCloudUpload /> : <BiReset />}
242+
leftIcon={selectedData === 'liveData' ? <AiOutlineCloudUpload /> : <BiReset />}
242243
variant="outline"
243244
onClick={handleReset}
244245
visibility={canUndo ? 'visible' : 'hidden'}
245246
isLoading={isSaving}
246247
>
247-
{selectedData === 'liveGuestbook' ? 'Push to the cloud' : 'Reset'}
248+
{selectedData === 'liveData' ? 'Push to the cloud' : 'Reset'}
248249
</Button>
249250
</HStack>
250251
</VStack>

demo/src/data.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const data = {
6262
</Text>
6363
</Flex>
6464
),
65-
restrictEdit: ({ value }) => typeof value === 'object' && value !== null,
65+
// restrictEdit: ({ value }) => typeof value === 'object' && value !== null,
6666
restrictDelete: ({ value }) => typeof value === 'object' && value !== null,
6767
restrictAdd: ({ value }) => !Array.isArray(value),
6868
collapse: 1,
@@ -1768,8 +1768,8 @@ const data = {
17681768
'editor.formatOnSave': true,
17691769
},
17701770
},
1771-
liveGuestbook: {
1772-
name: '📖 Live Guestbook',
1771+
liveData: {
1772+
name: '📖 Live Data (from database)',
17731773
description: (
17741774
<Text>
17751775
Let's try a little experiment. You can save this JSON object to a live database, so feel

demo/src/image/logo_500.png

-10.9 KB
Binary file not shown.

demo/src/useDatabase.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const db = getFirestore(firebaseApp)
99

1010
export const useDatabase = () => {
1111
const [value, loading, error] = useDocument(
12-
doc(getFirestore(firebaseApp), 'json-edit-react', 'guestbook')
12+
doc(getFirestore(firebaseApp), 'json-edit-react', 'live_json_data')
1313
)
1414

15-
const updateGuestbook = async (data) => {
16-
await setDoc(doc(db, 'json-edit-react', 'guestbook'), data, { merge: true })
15+
const updateLiveData = async (data) => {
16+
await setDoc(doc(db, 'json-edit-react', 'live_json_data'), data, { merge: true })
1717
}
1818

19-
return { guestbook: value?.data(), loading, error, updateGuestbook }
19+
return { liveData: value?.data(), loading, error, updateLiveData }
2020
}

image/logo192.png

28.8 KB
Loading

image/screenshot.png

111 KB
Loading

image/theme_edit_after.png

6.78 KB
Loading

image/theme_edit_before.png

6.73 KB
Loading

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-edit-react",
33
"version": "0.9.0",
4-
"description": "React component for editing/viewing JSON/object data",
4+
"description": "React component for editing or viewing JSON/object data",
55
"main": "build/index.cjs.js",
66
"module": "build/index.esm.js",
77
"types": "build/index.d.ts",
@@ -23,7 +23,6 @@
2323
"react-dom": "^18.2.0"
2424
},
2525
"dependencies": {
26-
"@react-hookz/web": "^23.0.0",
2726
"just-clone": "^6.2.0",
2827
"object-property-assigner": "^1.0.1",
2928
"object-property-extractor": "^1.0.6",

0 commit comments

Comments
 (0)