atom.io 0.33.10 → 0.33.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/index.js +2 -43
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.css +173 -42
- package/dist/react-devtools/index.css.map +1 -1
- package/dist/react-devtools/index.d.ts +4 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +381 -271
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/use-o-BrXc7Qro.js +47 -0
- package/dist/use-o-BrXc7Qro.js.map +1 -0
- package/package.json +1 -1
- package/src/react-devtools/Button.tsx +1 -1
- package/src/react-devtools/devtools.css +173 -42
- package/src/react-devtools/json-editor/default-components.tsx +4 -1
- package/src/react-devtools/json-editor/editors-by-type/array-editor.tsx +105 -20
- package/src/react-devtools/json-editor/editors-by-type/object-editor.tsx +121 -46
- package/src/react-devtools/json-editor/editors-by-type/primitive-editors.tsx +5 -0
- package/src/react-devtools/json-editor/editors-by-type/utilities/object-properties.ts +30 -8
- package/src/react-devtools/json-editor/index.ts +0 -25
- package/src/react-devtools/json-editor/json-editor-internal.tsx +99 -54
|
@@ -4,6 +4,8 @@ import { NumberInput, TextInput } from "../../elastic-input"
|
|
|
4
4
|
import type { JsonEditorProps_INTERNAL } from "../json-editor-internal"
|
|
5
5
|
|
|
6
6
|
export const BooleanEditor = ({
|
|
7
|
+
path = [],
|
|
8
|
+
isReadonly = () => false,
|
|
7
9
|
data,
|
|
8
10
|
set,
|
|
9
11
|
Components,
|
|
@@ -11,6 +13,7 @@ export const BooleanEditor = ({
|
|
|
11
13
|
}: JsonEditorProps_INTERNAL<boolean>): ReactElement => (
|
|
12
14
|
<Components.BooleanWrapper>
|
|
13
15
|
<input
|
|
16
|
+
disabled={isReadonly(path)}
|
|
14
17
|
data-testid={`${testid}-boolean-input`}
|
|
15
18
|
type="checkbox"
|
|
16
19
|
checked={data}
|
|
@@ -38,6 +41,7 @@ export const NumberEditor = ({
|
|
|
38
41
|
}: JsonEditorProps_INTERNAL<number>): ReactElement => (
|
|
39
42
|
<Components.NumberWrapper>
|
|
40
43
|
<NumberInput
|
|
44
|
+
disabled={isReadonly(path)}
|
|
41
45
|
testid={`${testid}-number-input`}
|
|
42
46
|
value={data}
|
|
43
47
|
set={
|
|
@@ -63,6 +67,7 @@ export const StringEditor = ({
|
|
|
63
67
|
return (
|
|
64
68
|
<Components.StringWrapper>
|
|
65
69
|
<TextInput
|
|
70
|
+
readOnly={isReadonly(path)}
|
|
66
71
|
testid={`${testid}-string-input`}
|
|
67
72
|
value={data}
|
|
68
73
|
set={isReadonly(path) ? undefined : set}
|
|
@@ -45,7 +45,9 @@ export const makePropertyRenamers = <T extends Json.Tree.Object>(
|
|
|
45
45
|
]),
|
|
46
46
|
)
|
|
47
47
|
|
|
48
|
-
export const makePropertyRemovers = <
|
|
48
|
+
export const makePropertyRemovers = <
|
|
49
|
+
T extends Json.Tree.Array | Json.Tree.Object,
|
|
50
|
+
>(
|
|
49
51
|
data: T,
|
|
50
52
|
set: SetterOrUpdater<T>,
|
|
51
53
|
): { [K in keyof T]: () => void } =>
|
|
@@ -54,14 +56,24 @@ export const makePropertyRemovers = <T extends Json.Tree.Object>(
|
|
|
54
56
|
key,
|
|
55
57
|
() => {
|
|
56
58
|
set(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
let next: T
|
|
60
|
+
if (Array.isArray(data)) {
|
|
61
|
+
const copy = [...data]
|
|
62
|
+
copy.splice(key as number, 1)
|
|
63
|
+
next = copy as unknown as T
|
|
64
|
+
} else {
|
|
65
|
+
const { [key]: _, ...rest } = data
|
|
66
|
+
next = rest as T
|
|
67
|
+
}
|
|
68
|
+
return next
|
|
59
69
|
})
|
|
60
70
|
},
|
|
61
71
|
]),
|
|
62
72
|
)
|
|
63
73
|
|
|
64
|
-
export const makePropertyRecasters = <
|
|
74
|
+
export const makePropertyRecasters = <
|
|
75
|
+
T extends Json.Tree.Array | Json.Tree.Object,
|
|
76
|
+
>(
|
|
65
77
|
data: T,
|
|
66
78
|
set: SetterOrUpdater<T>,
|
|
67
79
|
): { [K in keyof T]: (newType: JsonTypeName) => void } =>
|
|
@@ -69,10 +81,20 @@ export const makePropertyRecasters = <T extends Json.Tree.Object>(
|
|
|
69
81
|
toEntries(data).map(([key, value]) => [
|
|
70
82
|
key,
|
|
71
83
|
(newType: JsonTypeName) => {
|
|
72
|
-
set(() =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
set(() => {
|
|
85
|
+
let next: T
|
|
86
|
+
if (Array.isArray(data)) {
|
|
87
|
+
const copy = [...data]
|
|
88
|
+
copy[key as number] = castToJson(value)[newType]
|
|
89
|
+
next = copy as unknown as T
|
|
90
|
+
} else {
|
|
91
|
+
next = {
|
|
92
|
+
...data,
|
|
93
|
+
[key]: castToJson(value)[newType],
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return next
|
|
97
|
+
})
|
|
76
98
|
},
|
|
77
99
|
]),
|
|
78
100
|
)
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { JsonTypes } from "atom.io/json"
|
|
2
|
-
import type { FC } from "react"
|
|
3
|
-
|
|
4
|
-
import { ArrayEditor } from "./editors-by-type/array-editor"
|
|
5
|
-
import { ObjectEditor } from "./editors-by-type/object-editor"
|
|
6
|
-
import {
|
|
7
|
-
BooleanEditor,
|
|
8
|
-
NullEditor,
|
|
9
|
-
NumberEditor,
|
|
10
|
-
StringEditor,
|
|
11
|
-
} from "./editors-by-type/primitive-editors"
|
|
12
|
-
import type { JsonEditorProps_INTERNAL } from "./json-editor-internal"
|
|
13
|
-
|
|
14
1
|
export * from "./default-components"
|
|
15
2
|
export * from "./developer-interface"
|
|
16
3
|
export * from "./editors-by-type/utilities/cast-to-json"
|
|
@@ -18,15 +5,3 @@ export * from "./editors-by-type/utilities/cast-to-json"
|
|
|
18
5
|
export type SetterOrUpdater<T> = <New extends T>(
|
|
19
6
|
next: New | ((old: T) => New),
|
|
20
7
|
) => void
|
|
21
|
-
|
|
22
|
-
export const SubEditors: Record<
|
|
23
|
-
keyof JsonTypes,
|
|
24
|
-
FC<JsonEditorProps_INTERNAL<any>>
|
|
25
|
-
> = {
|
|
26
|
-
array: ArrayEditor,
|
|
27
|
-
boolean: BooleanEditor,
|
|
28
|
-
null: NullEditor,
|
|
29
|
-
number: NumberEditor,
|
|
30
|
-
object: ObjectEditor,
|
|
31
|
-
string: StringEditor,
|
|
32
|
-
}
|
|
@@ -3,6 +3,7 @@ import type { JsonTypes } from "atom.io/json"
|
|
|
3
3
|
import { isJson } from "atom.io/json"
|
|
4
4
|
import type { CSSProperties, FC, ReactElement } from "react"
|
|
5
5
|
|
|
6
|
+
import { button } from "../Button"
|
|
6
7
|
import { ElasticInput } from "../elastic-input"
|
|
7
8
|
import type { SetterOrUpdater } from "."
|
|
8
9
|
import { SubEditors } from "."
|
|
@@ -23,6 +24,8 @@ export type JsonEditorProps_INTERNAL<T> = {
|
|
|
23
24
|
style?: CSSProperties | undefined
|
|
24
25
|
Header?: FC<{ data: T }> | undefined
|
|
25
26
|
Components: JsonEditorComponents
|
|
27
|
+
isOpen?: boolean
|
|
28
|
+
setIsOpen?: (newValue: boolean) => void
|
|
26
29
|
testid?: string | undefined
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -38,8 +41,9 @@ export const JsonEditor_INTERNAL = <T,>({
|
|
|
38
41
|
isHidden = () => false,
|
|
39
42
|
className,
|
|
40
43
|
style,
|
|
41
|
-
Header: HeaderDisplay,
|
|
42
44
|
Components,
|
|
45
|
+
isOpen,
|
|
46
|
+
setIsOpen,
|
|
43
47
|
testid,
|
|
44
48
|
}: JsonEditorProps_INTERNAL<T>): ReactElement | null => {
|
|
45
49
|
const dataIsJson = isJson(data)
|
|
@@ -53,6 +57,8 @@ export const JsonEditor_INTERNAL = <T,>({
|
|
|
53
57
|
|
|
54
58
|
const disabled = isReadonly(path)
|
|
55
59
|
|
|
60
|
+
const dataIsTree = refined.type === `array` || refined.type === `object`
|
|
61
|
+
|
|
56
62
|
return isHidden(path) ? null : (
|
|
57
63
|
<Components.ErrorBoundary>
|
|
58
64
|
<Components.EditorWrapper
|
|
@@ -60,69 +66,108 @@ export const JsonEditor_INTERNAL = <T,>({
|
|
|
60
66
|
style={style}
|
|
61
67
|
testid={testid}
|
|
62
68
|
>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
<Components.Button disabled testid={`${testid}-delete`}>
|
|
66
|
-
<Components.DeleteIcon />
|
|
67
|
-
</Components.Button>
|
|
68
|
-
) : (
|
|
69
|
+
<header>
|
|
70
|
+
{remove ? (
|
|
69
71
|
<Components.Button
|
|
70
|
-
|
|
72
|
+
disabled={disabled}
|
|
71
73
|
onClick={() => {
|
|
72
74
|
remove()
|
|
73
75
|
}}
|
|
76
|
+
testid={`${testid}-delete`}
|
|
74
77
|
>
|
|
75
78
|
<Components.DeleteIcon />
|
|
76
79
|
</Components.Button>
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
value={name}
|
|
84
|
-
onChange={
|
|
85
|
-
disabled
|
|
86
|
-
? undefined
|
|
87
|
-
: (e) => {
|
|
88
|
-
rename(e.target.value)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
disabled={disabled}
|
|
92
|
-
data-testid={`${testid}-rename`}
|
|
80
|
+
) : null}
|
|
81
|
+
{dataIsTree && isOpen !== undefined && setIsOpen ? (
|
|
82
|
+
<button.OpenClose
|
|
83
|
+
isOpen={isOpen}
|
|
84
|
+
testid={`${testid}-open-close`}
|
|
85
|
+
setIsOpen={setIsOpen}
|
|
93
86
|
/>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
: (e) => {
|
|
87
|
+
) : null}
|
|
88
|
+
{rename && (
|
|
89
|
+
<Components.KeyWrapper>
|
|
90
|
+
<ElasticInput
|
|
91
|
+
value={name}
|
|
92
|
+
onChange={(e) => {
|
|
93
|
+
rename(e.target.value)
|
|
94
|
+
}}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
data-testid={`${testid}-rename`}
|
|
97
|
+
/>
|
|
98
|
+
</Components.KeyWrapper>
|
|
99
|
+
)}
|
|
100
|
+
{dataIsTree ? (
|
|
101
|
+
<>
|
|
102
|
+
{recast ? (
|
|
103
|
+
<select
|
|
104
|
+
onChange={(e) => {
|
|
113
105
|
recast(e.target.value as keyof JsonTypes)
|
|
106
|
+
}}
|
|
107
|
+
value={refined.type}
|
|
108
|
+
disabled={disabled}
|
|
109
|
+
data-testid={`${testid}-recast`}
|
|
110
|
+
>
|
|
111
|
+
{Object.keys(SubEditors).map((type) => (
|
|
112
|
+
<option key={type} value={type}>
|
|
113
|
+
{type}
|
|
114
|
+
</option>
|
|
115
|
+
))}
|
|
116
|
+
</select>
|
|
117
|
+
) : null}
|
|
118
|
+
{isOpen !== undefined && setIsOpen ? (
|
|
119
|
+
<span className="json_viewer">{JSON.stringify(data)}</span>
|
|
120
|
+
) : null}
|
|
121
|
+
</>
|
|
122
|
+
) : (
|
|
123
|
+
<>
|
|
124
|
+
<SubEditor
|
|
125
|
+
data={refined.data as never}
|
|
126
|
+
set={set}
|
|
127
|
+
remove={remove}
|
|
128
|
+
rename={rename}
|
|
129
|
+
path={path}
|
|
130
|
+
isReadonly={isReadonly}
|
|
131
|
+
isHidden={isHidden}
|
|
132
|
+
Components={Components}
|
|
133
|
+
testid={testid}
|
|
134
|
+
/>
|
|
135
|
+
{recast && dataIsJson ? (
|
|
136
|
+
<select
|
|
137
|
+
onChange={
|
|
138
|
+
disabled
|
|
139
|
+
? undefined
|
|
140
|
+
: (e) => {
|
|
141
|
+
recast(e.target.value as keyof JsonTypes)
|
|
142
|
+
}
|
|
114
143
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
value={refined.type}
|
|
145
|
+
disabled={disabled}
|
|
146
|
+
data-testid={`${testid}-recast`}
|
|
147
|
+
>
|
|
148
|
+
{Object.keys(SubEditors).map((type) => (
|
|
149
|
+
<option key={type} value={type}>
|
|
150
|
+
{type}
|
|
151
|
+
</option>
|
|
152
|
+
))}
|
|
153
|
+
</select>
|
|
154
|
+
) : null}
|
|
155
|
+
</>
|
|
156
|
+
)}
|
|
157
|
+
</header>
|
|
158
|
+
|
|
159
|
+
{dataIsTree && isOpen !== false ? (
|
|
160
|
+
<SubEditor
|
|
161
|
+
data={refined.data as never}
|
|
162
|
+
set={set}
|
|
163
|
+
remove={remove}
|
|
164
|
+
rename={rename}
|
|
165
|
+
path={path}
|
|
166
|
+
isReadonly={isReadonly}
|
|
167
|
+
isHidden={isHidden}
|
|
168
|
+
Components={Components}
|
|
169
|
+
testid={testid}
|
|
170
|
+
/>
|
|
126
171
|
) : null}
|
|
127
172
|
</Components.EditorWrapper>
|
|
128
173
|
</Components.ErrorBoundary>
|