Skip to content

Commit a064e12

Browse files
committed
Update demo
1 parent 086bb2b commit a064e12

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Features include:
3131
- [Undo functionality](#undo-functionality)
3232
- [Issues, bugs, suggestions?](#issues-bugs-suggestions)
3333
- [Roadmap](#roadmap)
34+
- [Inspiration](#inspiration)
3435
- [Changelog](#changelog)
3536

3637

@@ -328,7 +329,12 @@ The main features I'd like to introduce are:
328329
2. **Visibility filter function***hide* properties from the UI completely based on a Filter function. This should arguably be done outside the component though (filter the data upstream), so would be less of a priority (though it would be fairly simple to implement, so 🤷‍♂️)
329330
3. **Search** — allow the user to narrow the list of visible keys with a simple search input. This would be useful for very large data objects, but is possibly getting a bit too much in terms of opinionated UI, so would need to ensure it can be styled easily. Perhaps it would be better if the "Search" input was handled outside this package, and we just accepted a "search" string prop?
330331

332+
## Inspiration
333+
334+
This component is heavily inspired by [react-json-view](https://github.com/mac-s-g/react-json-view), a great package that I've used in my own projects. However, it seems to have been abandoned now, and requires a few critical fixes, so I decided to create my own from scratch and extend the functionality while I was at it.
331335

332336
## Changelog
333337

334-
- **0.9.0**: Initial release
338+
- **0.9.0**: Initial release
339+
- **0.9.1**: Export more Types from the package
340+

demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/react-dom": "^18.2.4",
1818
"firebase": "^9.22.1",
1919
"framer-motion": "^10.12.12",
20-
"json-edit-react": "^0.9.0",
20+
"json-edit-react": "^0.9.1",
2121
"just-clone": "^6.2.0",
2222
"just-compare": "^2.3.0",
2323
"react": "^18.2.0",

demo/src/App.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useRef } from 'react'
2-
// import { JsonEditor, ThemeName, Theme, themes } from './json-edit-react/src'
3-
import { JsonEditor, ThemeName, Theme, themes } from 'json-edit-react'
2+
// import { JsonEditor, themes, ThemeName, Theme, ThemeInput } from './json-edit-react/src'
3+
import { JsonEditor, themes, ThemeName, Theme, ThemeInput } from 'json-edit-react'
44
import { FaNpm, FaExternalLinkAlt, FaGithub } from 'react-icons/fa'
55
import { BiReset } from 'react-icons/bi'
66
import { AiOutlineCloudUpload } from 'react-icons/ai'
@@ -42,7 +42,7 @@ function App() {
4242
const [rootName, setRootName] = useState('data')
4343
const [indent, setIndent] = useState(4)
4444
const [collapseLevel, setCollapseLevel] = useState(2)
45-
const [theme, setTheme] = useState<ThemeName>('default')
45+
const [theme, setTheme] = useState<ThemeInput>('default')
4646
const [allowEdit, setAllowEdit] = useState(true)
4747
const [allowDelete, setAllowDelete] = useState(true)
4848
const [allowAdd, setAllowAdd] = useState(true)
@@ -76,6 +76,10 @@ function App() {
7676
}
7777
}, [selectedData, reset])
7878

79+
useEffect(() => {
80+
if (selectedData === 'editTheme') setTheme(data)
81+
}, [data])
82+
7983
const restrictEdit: FilterFunction | boolean = (() => {
8084
const customRestrictor = demoData[selectedData]?.restrictEdit
8185
if (customRestrictor) return (input) => !allowEdit || customRestrictor(input)
@@ -115,6 +119,7 @@ function App() {
115119
switch (selectedData) {
116120
case 'editTheme':
117121
reset(themes[previousThemeName.current])
122+
setTheme(themes[previousThemeName.current])
118123
return
119124
case 'liveData':
120125
setIsSaving(true)
@@ -185,7 +190,7 @@ function App() {
185190
indent={indent}
186191
onUpdate={({ newData }) => {
187192
setData(newData)
188-
if (selectedData === 'editTheme') setTheme(newData as any)
193+
if (selectedData === 'editTheme') setTheme(newData)
189194
}}
190195
collapse={collapseLevel}
191196
enableClipboard={

demo/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -7633,10 +7633,10 @@ jsesc@~0.5.0:
76337633
resolved "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz"
76347634
integrity sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==
76357635

7636-
json-edit-react@^0.9.0:
7637-
version "0.9.0"
7638-
resolved "https://registry.yarnpkg.com/json-edit-react/-/json-edit-react-0.9.0.tgz#341945fdfc8a8d680ce925b916d4838ad7bc1834"
7639-
integrity sha512-q2ZGlEQyeoAH/fcx5FohwSrS1HRzAZ9b9zAuJILnl+XPo0H0uCoZmzGB9f8V3HLCc6kBQ2oyGwnDmU7H7Tjllg==
7636+
json-edit-react@^0.9.1:
7637+
version "0.9.1"
7638+
resolved "https://registry.yarnpkg.com/json-edit-react/-/json-edit-react-0.9.1.tgz#fe01443cfd722504bcd78479d8fd23c9d790e5ef"
7639+
integrity sha512-NIVaLggyK+rxmxeIqFGjZjO1j5CANDKoXlxUgf4lzy8X6yZWj1c5VrxuU2bfP5RZr5XTUR5MtgmJ2I6n1bGAKA==
76407640
dependencies:
76417641
just-clone "^6.2.0"
76427642
object-property-assigner "^1.0.1"

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import JsonEditor from './JsonEditor'
2-
import { themes, ThemeName, Theme } from './theme'
2+
import { themes, ThemeName, Theme, ThemeInput } from './theme'
33

4-
export { JsonEditor, themes, type ThemeName, type Theme }
4+
export { JsonEditor, themes, type ThemeName, type Theme, type ThemeInput }

0 commit comments

Comments
 (0)