Skip to content

Commit 3a83a69

Browse files
committed
Squashed commit of the following:
commit b43354e Author: Carl Smith <[email protected]> Date: Thu Jul 25 11:35:42 2024 +1200 Update Undefined.tsx commit 45ad791 Author: Carl Smith <[email protected]> Date: Thu Jul 25 11:33:15 2024 +1200 Update Undefined.tsx commit a9987e5 Author: Carl Smith <[email protected]> Date: Thu Jul 25 11:31:08 2024 +1200 Update Undefined.tsx commit 4cf1234 Merge: 8539748 130d33e Author: Carl Smith <[email protected]> Date: Thu Jul 25 11:02:31 2024 +1200 Merge branch 'main' into 94-undefined-component commit 8539748 Author: Carl Smith <[email protected]> Date: Fri Jul 19 13:35:21 2024 +1200 INIT
1 parent 130d33e commit 3a83a69

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

demo/src/customComponents/DateTimePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import React from 'react'
1212
import DatePicker from 'react-datepicker'
1313
import { Button } from '@chakra-ui/react'
14-
import { CustomNodeProps, CustomNodeDefinition } from '../JsonEditImport'
14+
import { CustomNodeProps, CustomNodeDefinition } from '../_imports'
1515

1616
// Styles
1717
import 'react-datepicker/dist/react-datepicker.css'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This is not exported with the package, but here is a simple way to get
2+
// "undefined" nodes to be editable, and the "undefined" type to appear in the
3+
// type selector
4+
5+
import React from 'react'
6+
import { CustomNodeProps, CustomNodeDefinition } from 'json-edit-react'
7+
8+
export const Undefined: React.FC<CustomNodeProps> = ({ children }) => {
9+
return <>{children}</>
10+
}
11+
12+
// Definition for custom node behaviour
13+
export const undefinedNodeDefinition: CustomNodeDefinition = {
14+
condition: ({ value }) => typeof value === 'undefined',
15+
element: Undefined, // the component defined above
16+
showOnView: false,
17+
showOnEdit: false,
18+
name: 'undefined', // shown in the Type selector menu
19+
showInTypesSelector: true,
20+
defaultValue: undefined, // when instantiated
21+
}

demo/src/demoData/data.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const data: Record<string, object> = {
44
number: 99,
55
boolean: true,
66
nothing: null,
7+
undefined: undefined,
78
Usage: [
89
'Edit a value by clicking the "edit" icon, or double-clicking the value.',
910
'You can change the type of any value',

demo/src/demoData/dataDefinitions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Input } from 'object-property-assigner/build'
2525
import jsonSchema from './jsonSchema.json'
2626
import customNodesSchema from './customNodesSchema.json'
2727
import Ajv from 'ajv'
28+
import { undefinedNodeDefinition } from '../customComponents/Undefined'
2829

2930
const ajv = new Ajv()
3031
const validateJsonSchema = ajv.compile(jsonSchema)
@@ -90,7 +91,7 @@ export const demoDataDefinitions: Record<string, DemoData> = {
9091
rootName: 'data',
9192
collapse: 2,
9293
data: data.intro,
93-
customNodeDefinitions: [dateNodeDefinition],
94+
customNodeDefinitions: [dateNodeDefinition, undefinedNodeDefinition],
9495
},
9596
starWars: {
9697
name: '🚀 Star Wars',

0 commit comments

Comments
 (0)