@tyx1703/json-schema-editor-visual 1.0.0
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/README.md +109 -0
- package/dist/JsonSchemaEditor.d.ts +19 -0
- package/dist/JsonSchemaEditor.js +478 -0
- package/dist/components/LocalProvider/index.d.ts +79 -0
- package/dist/components/LocalProvider/index.js +80 -0
- package/dist/components/MockSelect/index.d.ts +9 -0
- package/dist/components/MockSelect/index.js +40 -0
- package/dist/components/MonacoEditor/index.d.ts +16 -0
- package/dist/components/MonacoEditor/index.js +77 -0
- package/dist/components/SchemaComponents/FieldInput.d.ts +8 -0
- package/dist/components/SchemaComponents/FieldInput.js +36 -0
- package/dist/components/SchemaComponents/SchemaJson.d.ts +36 -0
- package/dist/components/SchemaComponents/SchemaJson.js +634 -0
- package/dist/components/SchemaComponents/SchemaOther.d.ts +9 -0
- package/dist/components/SchemaComponents/SchemaOther.js +735 -0
- package/dist/components/SchemaComponents/schemaJson.css +128 -0
- package/dist/index.css +53 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15 -0
- package/dist/schema.d.ts +15 -0
- package/dist/schema.js +24 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +11 -0
- package/dist/store/schemaSlice.d.ts +49 -0
- package/dist/store/schemaSlice.js +208 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +31 -0
- package/dist/utils.js +164 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @tyx1703/json-schema-editor-visual
|
|
2
|
+
|
|
3
|
+
A React component for visually editing JSON Schema.
|
|
4
|
+
|
|
5
|
+
## Peer Dependencies
|
|
6
|
+
|
|
7
|
+
- `react` ^18 or ^19
|
|
8
|
+
- `react-dom` ^18 or ^19
|
|
9
|
+
- `antd` ^5 or ^6
|
|
10
|
+
- `@ant-design/icons` ^5 or ^6
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @tyx1703/json-schema-editor-visual
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Basic
|
|
21
|
+
|
|
22
|
+
```jsx
|
|
23
|
+
import JsonSchemaEditorVisual from '@tyx1703/json-schema-editor-visual';
|
|
24
|
+
|
|
25
|
+
export default () => {
|
|
26
|
+
return <JsonSchemaEditorVisual />;
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Mock Data
|
|
31
|
+
|
|
32
|
+
Pass a `mock` array to display a mock data column in the editor.
|
|
33
|
+
|
|
34
|
+
```jsx
|
|
35
|
+
import JsonSchemaEditorVisual from '@tyx1703/json-schema-editor-visual';
|
|
36
|
+
|
|
37
|
+
const MOCK_SOURCE = [
|
|
38
|
+
{ name: '字符串', mock: '@string' },
|
|
39
|
+
{ name: '自然数', mock: '@natural' },
|
|
40
|
+
{ name: '布尔', mock: '@boolean' },
|
|
41
|
+
{ name: 'email', mock: '@email' },
|
|
42
|
+
{ name: '日期', mock: '@date' },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
export default () => {
|
|
46
|
+
return <JsonSchemaEditorVisual mock={MOCK_SOURCE} />;
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Controlled Component
|
|
51
|
+
|
|
52
|
+
Use `data` to initialize and `onChange` to receive schema updates.
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
import JsonSchemaEditorVisual from '@tyx1703/json-schema-editor-visual';
|
|
56
|
+
|
|
57
|
+
const data = `{"type":"object","title":"title","properties":{"field_1":{"type":"string","title":"field_1_title","description":"field_1_description"}},"required":["field_1"]}`;
|
|
58
|
+
|
|
59
|
+
export default () => {
|
|
60
|
+
return (
|
|
61
|
+
<JsonSchemaEditorVisual
|
|
62
|
+
data={data}
|
|
63
|
+
onChange={(value) => console.log('value: ', value)}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### i18n
|
|
70
|
+
|
|
71
|
+
The component reads the locale from antd's `ConfigProvider`. Wrap with `ConfigProvider` and pass a locale to switch language.
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
import { ConfigProvider } from 'antd';
|
|
75
|
+
import zhCN from 'antd/locale/zh_CN';
|
|
76
|
+
import JsonSchemaEditorVisual from '@tyx1703/json-schema-editor-visual';
|
|
77
|
+
|
|
78
|
+
export default () => {
|
|
79
|
+
return (
|
|
80
|
+
<ConfigProvider locale={zhCN}>
|
|
81
|
+
<JsonSchemaEditorVisual />
|
|
82
|
+
</ConfigProvider>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The component defaults to Chinese (`zh_CN`) when the antd locale starts with `zh`, and English (`en_US`) otherwise.
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Default | Description |
|
|
92
|
+
| ------------ | -------------------------- | ------- | ------------------------------------------------------------------------------------------- |
|
|
93
|
+
| `data` | `string` | — | JSON Schema string to initialize the editor |
|
|
94
|
+
| `onChange` | `(schema: string) => void` | — | Callback fired when the schema changes |
|
|
95
|
+
| `showEditor` | `boolean` | `true` | Show/hide the left-side JSON source editor panel |
|
|
96
|
+
| `format` | `Format` | `[]` | Custom format options (`{ name: string; title?: string }[]`) |
|
|
97
|
+
| `mock` | `MockSource` | — | Mock data source; when provided, a mock column appears (`{ name: string; mock: string }[]`) |
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
This project is a pnpm monorepo.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pnpm install # Install dependencies
|
|
105
|
+
pnpm run build # Build the library
|
|
106
|
+
pnpm run dev # Watch mode
|
|
107
|
+
pnpm run test # Unit tests (Rstest)
|
|
108
|
+
pnpm e2e # Build + e2e tests (Playwright)
|
|
109
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MockSource, Format } from './types';
|
|
2
|
+
import './index.css';
|
|
3
|
+
/** JSON Schema 编辑器属性 */
|
|
4
|
+
export interface JsonSchemaEditorCoreProps {
|
|
5
|
+
/** JSON Schema 字符串,用于初始化编辑器 */
|
|
6
|
+
data?: string;
|
|
7
|
+
/** Schema 变更回调 */
|
|
8
|
+
onChange?: (schema: string) => void;
|
|
9
|
+
/** 是否显示左侧 JSON 源码编辑器 */
|
|
10
|
+
showEditor?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 自定义 format 选项列表
|
|
13
|
+
* @default []
|
|
14
|
+
*/
|
|
15
|
+
format?: Format;
|
|
16
|
+
/** mock 数据源,传入后自动显示 mock 列 */
|
|
17
|
+
mock?: MockSource;
|
|
18
|
+
}
|
|
19
|
+
export default function JsonSchemaEditorCore(props: JsonSchemaEditorCoreProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Button, Checkbox, Col, Input, Modal, Row, Select, Space, Tabs, Tooltip, message } from "antd";
|
|
4
|
+
import { CaretDownOutlined, CaretRightOutlined, EditOutlined, PlusOutlined, QuestionCircleOutlined, SettingOutlined } from "@ant-design/icons";
|
|
5
|
+
import MonacoEditor from "./components/MonacoEditor/index.js";
|
|
6
|
+
import SchemaJson from "./components/SchemaComponents/SchemaJson.js";
|
|
7
|
+
import { SCHEMA_TYPE, debounce, format as external_utils_js_format } from "./utils.js";
|
|
8
|
+
import json from "generate-schema/src/schemas/json.js";
|
|
9
|
+
import SchemaOther from "./components/SchemaComponents/SchemaOther.js";
|
|
10
|
+
import { useLocalProvider } from "./components/LocalProvider/index.js";
|
|
11
|
+
import MockSelect from "./components/MockSelect/index.js";
|
|
12
|
+
import { useAppDispatch, useAppSelector } from "./store/index.js";
|
|
13
|
+
import { addChildFieldAction, changeEditorSchemaAction, changeTypeAction, changeValueAction, requireAllAction } from "./store/schemaSlice.js";
|
|
14
|
+
import "./index.css";
|
|
15
|
+
const Option = Select.Option;
|
|
16
|
+
const { TextArea: TextArea } = Input;
|
|
17
|
+
function JsonSchemaEditorCore(props) {
|
|
18
|
+
const { data, onChange, showEditor, format = external_utils_js_format, mock } = props;
|
|
19
|
+
const dispatch = useAppDispatch();
|
|
20
|
+
const schema = useAppSelector((state)=>state.schema.data);
|
|
21
|
+
const LocalProvider = useLocalProvider();
|
|
22
|
+
const jsonDataRef = useRef(null);
|
|
23
|
+
const jsonSchemaDataRef = useRef(null);
|
|
24
|
+
const importJsonTypeRef = useRef(null);
|
|
25
|
+
const prevDataRef = useRef(data);
|
|
26
|
+
const alterMsgRef = useRef(debounce(()=>{}, 2000));
|
|
27
|
+
const [visible, setVisible] = useState(false);
|
|
28
|
+
const [show, setShow] = useState(true);
|
|
29
|
+
const [editVisible, setEditVisible] = useState(false);
|
|
30
|
+
const [descriptionKey, setDescriptionKey] = useState(null);
|
|
31
|
+
const [advVisible, setAdvVisible] = useState(false);
|
|
32
|
+
const [itemKey, setItemKey] = useState([]);
|
|
33
|
+
const [curItemCustomValue, setCurItemCustomValue] = useState(null);
|
|
34
|
+
const [checked, setChecked] = useState(false);
|
|
35
|
+
const [editorModalName, setEditorModalName] = useState('');
|
|
36
|
+
const [editValue, setEditValue] = useState('');
|
|
37
|
+
useEffect(()=>{
|
|
38
|
+
const parsed = data ? JSON.parse(data) : {
|
|
39
|
+
type: 'object',
|
|
40
|
+
title: 'title',
|
|
41
|
+
properties: {}
|
|
42
|
+
};
|
|
43
|
+
dispatch(changeEditorSchemaAction({
|
|
44
|
+
value: parsed
|
|
45
|
+
}));
|
|
46
|
+
}, []);
|
|
47
|
+
useEffect(()=>{
|
|
48
|
+
if (data && data !== prevDataRef.current) dispatch(changeEditorSchemaAction({
|
|
49
|
+
value: JSON.parse(data)
|
|
50
|
+
}));
|
|
51
|
+
prevDataRef.current = data;
|
|
52
|
+
}, [
|
|
53
|
+
data,
|
|
54
|
+
dispatch
|
|
55
|
+
]);
|
|
56
|
+
useEffect(()=>{
|
|
57
|
+
if ('function' == typeof onChange) onChange(JSON.stringify(schema || ''));
|
|
58
|
+
}, [
|
|
59
|
+
schema
|
|
60
|
+
]);
|
|
61
|
+
const showModal = useCallback(()=>setVisible(true), []);
|
|
62
|
+
const handleOk = useCallback(()=>{
|
|
63
|
+
if ('schema' !== importJsonTypeRef.current) {
|
|
64
|
+
if (!jsonDataRef.current) return message.error('json 数据格式有误');
|
|
65
|
+
const jsonData = json(jsonDataRef.current);
|
|
66
|
+
dispatch(changeEditorSchemaAction({
|
|
67
|
+
value: jsonData
|
|
68
|
+
}));
|
|
69
|
+
} else {
|
|
70
|
+
if (!jsonSchemaDataRef.current) return message.error('json 数据格式有误');
|
|
71
|
+
dispatch(changeEditorSchemaAction({
|
|
72
|
+
value: jsonSchemaDataRef.current
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
setVisible(false);
|
|
76
|
+
}, [
|
|
77
|
+
dispatch
|
|
78
|
+
]);
|
|
79
|
+
const handleCancel = useCallback(()=>setVisible(false), []);
|
|
80
|
+
const handleImportJson = useCallback((e)=>{
|
|
81
|
+
if (!e.text || true !== e.format) {
|
|
82
|
+
jsonDataRef.current = null;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
jsonDataRef.current = e.jsonData;
|
|
86
|
+
}, []);
|
|
87
|
+
const handleImportJsonSchema = useCallback((e)=>{
|
|
88
|
+
if (!e.text || true !== e.format) {
|
|
89
|
+
jsonSchemaDataRef.current = null;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
jsonSchemaDataRef.current = e.jsonData;
|
|
93
|
+
}, []);
|
|
94
|
+
const handleParams = useCallback((e)=>{
|
|
95
|
+
if (!e.text) return;
|
|
96
|
+
if (true !== e.format) return alterMsgRef.current();
|
|
97
|
+
dispatch(changeEditorSchemaAction({
|
|
98
|
+
value: e.jsonData
|
|
99
|
+
}));
|
|
100
|
+
}, [
|
|
101
|
+
dispatch
|
|
102
|
+
]);
|
|
103
|
+
const changeType = useCallback((key, value)=>{
|
|
104
|
+
dispatch(changeTypeAction({
|
|
105
|
+
key: [
|
|
106
|
+
key
|
|
107
|
+
],
|
|
108
|
+
value
|
|
109
|
+
}));
|
|
110
|
+
}, [
|
|
111
|
+
dispatch
|
|
112
|
+
]);
|
|
113
|
+
const addChildField = useCallback((key)=>{
|
|
114
|
+
dispatch(addChildFieldAction({
|
|
115
|
+
key: [
|
|
116
|
+
key
|
|
117
|
+
]
|
|
118
|
+
}));
|
|
119
|
+
setShow(true);
|
|
120
|
+
}, [
|
|
121
|
+
dispatch
|
|
122
|
+
]);
|
|
123
|
+
const clickIcon = useCallback(()=>setShow((s)=>!s), []);
|
|
124
|
+
const changeValue = useCallback((key, value)=>{
|
|
125
|
+
if ('mock' === key[0]) value = value ? {
|
|
126
|
+
mock: value
|
|
127
|
+
} : '';
|
|
128
|
+
dispatch(changeValueAction({
|
|
129
|
+
key,
|
|
130
|
+
value
|
|
131
|
+
}));
|
|
132
|
+
}, [
|
|
133
|
+
dispatch
|
|
134
|
+
]);
|
|
135
|
+
const handleEditOk = useCallback((name)=>{
|
|
136
|
+
setEditVisible(false);
|
|
137
|
+
let value = editValue;
|
|
138
|
+
if ('mock' === name) value = value ? {
|
|
139
|
+
mock: value
|
|
140
|
+
} : '';
|
|
141
|
+
if (!descriptionKey) return;
|
|
142
|
+
dispatch(changeValueAction({
|
|
143
|
+
key: descriptionKey,
|
|
144
|
+
value
|
|
145
|
+
}));
|
|
146
|
+
}, [
|
|
147
|
+
editValue,
|
|
148
|
+
descriptionKey,
|
|
149
|
+
dispatch
|
|
150
|
+
]);
|
|
151
|
+
const handleEditCancel = useCallback(()=>setEditVisible(false), []);
|
|
152
|
+
const showEdit = useCallback((prefix, name, value, type)=>{
|
|
153
|
+
if ('object' === type || 'array' === type) return;
|
|
154
|
+
const key = [
|
|
155
|
+
...prefix,
|
|
156
|
+
name
|
|
157
|
+
];
|
|
158
|
+
const val = 'mock' === name ? value ? value.mock : '' : value;
|
|
159
|
+
setEditVisible(true);
|
|
160
|
+
setEditValue(val);
|
|
161
|
+
setDescriptionKey(key);
|
|
162
|
+
setEditorModalName(name);
|
|
163
|
+
}, []);
|
|
164
|
+
const changeDesc = useCallback((e)=>setEditValue(e), []);
|
|
165
|
+
const handleAdvOk = useCallback(()=>{
|
|
166
|
+
if (0 === itemKey.length) {
|
|
167
|
+
if (!curItemCustomValue) return;
|
|
168
|
+
dispatch(changeEditorSchemaAction({
|
|
169
|
+
value: curItemCustomValue
|
|
170
|
+
}));
|
|
171
|
+
} else dispatch(changeValueAction({
|
|
172
|
+
key: itemKey,
|
|
173
|
+
value: curItemCustomValue
|
|
174
|
+
}));
|
|
175
|
+
setAdvVisible(false);
|
|
176
|
+
}, [
|
|
177
|
+
itemKey,
|
|
178
|
+
curItemCustomValue,
|
|
179
|
+
dispatch
|
|
180
|
+
]);
|
|
181
|
+
const handleAdvCancel = useCallback(()=>setAdvVisible(false), []);
|
|
182
|
+
const showAdv = useCallback((key, value)=>{
|
|
183
|
+
setAdvVisible(true);
|
|
184
|
+
setItemKey(key);
|
|
185
|
+
setCurItemCustomValue(value);
|
|
186
|
+
}, []);
|
|
187
|
+
const changeCustomValue = useCallback((newValue)=>setCurItemCustomValue(newValue), []);
|
|
188
|
+
const changeCheckBox = useCallback((e)=>{
|
|
189
|
+
setChecked(e);
|
|
190
|
+
dispatch(requireAllAction({
|
|
191
|
+
required: e,
|
|
192
|
+
value: schema
|
|
193
|
+
}));
|
|
194
|
+
}, [
|
|
195
|
+
schema,
|
|
196
|
+
dispatch
|
|
197
|
+
]);
|
|
198
|
+
const disabled = 'object' !== schema.type && 'array' !== schema.type;
|
|
199
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
200
|
+
className: "json-schema-react-editor",
|
|
201
|
+
children: [
|
|
202
|
+
/*#__PURE__*/ jsx(Button, {
|
|
203
|
+
className: "import-json-button",
|
|
204
|
+
type: "primary",
|
|
205
|
+
onClick: showModal,
|
|
206
|
+
children: LocalProvider('import_json')
|
|
207
|
+
}),
|
|
208
|
+
/*#__PURE__*/ jsx(Modal, {
|
|
209
|
+
width: 780,
|
|
210
|
+
maskClosable: false,
|
|
211
|
+
open: visible,
|
|
212
|
+
title: LocalProvider('import_json'),
|
|
213
|
+
onOk: handleOk,
|
|
214
|
+
onCancel: handleCancel,
|
|
215
|
+
className: "json-schema-react-editor-import-modal",
|
|
216
|
+
okText: 'ok',
|
|
217
|
+
cancelText: LocalProvider('cancel'),
|
|
218
|
+
footer: [
|
|
219
|
+
/*#__PURE__*/ jsx(Button, {
|
|
220
|
+
onClick: handleCancel,
|
|
221
|
+
children: LocalProvider('cancel')
|
|
222
|
+
}, "back"),
|
|
223
|
+
/*#__PURE__*/ jsx(Button, {
|
|
224
|
+
type: "primary",
|
|
225
|
+
onClick: handleOk,
|
|
226
|
+
children: LocalProvider('ok')
|
|
227
|
+
}, "submit")
|
|
228
|
+
],
|
|
229
|
+
children: /*#__PURE__*/ jsx(Tabs, {
|
|
230
|
+
defaultActiveKey: "json",
|
|
231
|
+
onChange: (key)=>{
|
|
232
|
+
importJsonTypeRef.current = key;
|
|
233
|
+
},
|
|
234
|
+
items: [
|
|
235
|
+
{
|
|
236
|
+
key: 'json',
|
|
237
|
+
label: 'JSON',
|
|
238
|
+
children: /*#__PURE__*/ jsx(MonacoEditor, {
|
|
239
|
+
data: "",
|
|
240
|
+
mode: "json",
|
|
241
|
+
onChange: handleImportJson
|
|
242
|
+
})
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
key: 'schema',
|
|
246
|
+
label: 'JSON-SCHEMA',
|
|
247
|
+
children: /*#__PURE__*/ jsx(MonacoEditor, {
|
|
248
|
+
data: "",
|
|
249
|
+
mode: "json",
|
|
250
|
+
onChange: handleImportJsonSchema
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
})
|
|
255
|
+
}),
|
|
256
|
+
/*#__PURE__*/ jsx(Modal, {
|
|
257
|
+
title: /*#__PURE__*/ jsxs("div", {
|
|
258
|
+
children: [
|
|
259
|
+
LocalProvider(editorModalName),
|
|
260
|
+
"\xa0",
|
|
261
|
+
'mock' === editorModalName && /*#__PURE__*/ jsx(Tooltip, {
|
|
262
|
+
title: LocalProvider('mockLink'),
|
|
263
|
+
children: /*#__PURE__*/ jsx("a", {
|
|
264
|
+
target: "_blank",
|
|
265
|
+
rel: "noopener noreferrer",
|
|
266
|
+
href: "https://github.com/YMFE/json-schema-editor-visual/issues/38",
|
|
267
|
+
children: /*#__PURE__*/ jsx(QuestionCircleOutlined, {})
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
}),
|
|
272
|
+
maskClosable: false,
|
|
273
|
+
open: editVisible,
|
|
274
|
+
onOk: ()=>handleEditOk(editorModalName),
|
|
275
|
+
onCancel: handleEditCancel,
|
|
276
|
+
okText: LocalProvider('ok'),
|
|
277
|
+
cancelText: LocalProvider('cancel'),
|
|
278
|
+
children: /*#__PURE__*/ jsx(TextArea, {
|
|
279
|
+
value: editValue,
|
|
280
|
+
placeholder: LocalProvider(editorModalName),
|
|
281
|
+
onChange: (e)=>changeDesc(e.target.value),
|
|
282
|
+
autoSize: {
|
|
283
|
+
minRows: 6,
|
|
284
|
+
maxRows: 10
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
}),
|
|
288
|
+
advVisible && /*#__PURE__*/ jsx(Modal, {
|
|
289
|
+
title: LocalProvider('adv_setting'),
|
|
290
|
+
maskClosable: false,
|
|
291
|
+
open: advVisible,
|
|
292
|
+
onOk: handleAdvOk,
|
|
293
|
+
onCancel: handleAdvCancel,
|
|
294
|
+
okText: LocalProvider('ok'),
|
|
295
|
+
width: 780,
|
|
296
|
+
cancelText: LocalProvider('cancel'),
|
|
297
|
+
className: "json-schema-react-editor-adv-modal",
|
|
298
|
+
"data-testid": null,
|
|
299
|
+
children: /*#__PURE__*/ jsx(SchemaOther, {
|
|
300
|
+
data: JSON.stringify(curItemCustomValue, null, 2),
|
|
301
|
+
changeCustomValue: changeCustomValue,
|
|
302
|
+
format: format
|
|
303
|
+
})
|
|
304
|
+
}),
|
|
305
|
+
/*#__PURE__*/ jsxs(Row, {
|
|
306
|
+
children: [
|
|
307
|
+
showEditor && /*#__PURE__*/ jsx(Col, {
|
|
308
|
+
span: 8,
|
|
309
|
+
children: /*#__PURE__*/ jsx(MonacoEditor, {
|
|
310
|
+
className: "pretty-editor",
|
|
311
|
+
mode: "json",
|
|
312
|
+
data: JSON.stringify(schema, null, 2),
|
|
313
|
+
onChange: handleParams
|
|
314
|
+
})
|
|
315
|
+
}),
|
|
316
|
+
/*#__PURE__*/ jsxs(Col, {
|
|
317
|
+
span: showEditor ? 16 : 24,
|
|
318
|
+
className: "wrapper object-style",
|
|
319
|
+
children: [
|
|
320
|
+
/*#__PURE__*/ jsxs(Row, {
|
|
321
|
+
align: "middle",
|
|
322
|
+
children: [
|
|
323
|
+
/*#__PURE__*/ jsx(Col, {
|
|
324
|
+
span: 8,
|
|
325
|
+
className: "col-item name-item col-item-name",
|
|
326
|
+
children: /*#__PURE__*/ jsxs(Row, {
|
|
327
|
+
justify: "space-around",
|
|
328
|
+
align: "middle",
|
|
329
|
+
children: [
|
|
330
|
+
/*#__PURE__*/ jsx(Col, {
|
|
331
|
+
span: 2,
|
|
332
|
+
className: "down-style-col",
|
|
333
|
+
children: 'object' === schema.type ? /*#__PURE__*/ jsx("span", {
|
|
334
|
+
className: "down-style",
|
|
335
|
+
onClick: clickIcon,
|
|
336
|
+
children: show ? /*#__PURE__*/ jsx(CaretDownOutlined, {
|
|
337
|
+
className: "icon-object",
|
|
338
|
+
type: "caret-down"
|
|
339
|
+
}) : /*#__PURE__*/ jsx(CaretRightOutlined, {
|
|
340
|
+
className: "icon-object",
|
|
341
|
+
type: "caret-right"
|
|
342
|
+
})
|
|
343
|
+
}) : null
|
|
344
|
+
}),
|
|
345
|
+
/*#__PURE__*/ jsx(Col, {
|
|
346
|
+
span: 22,
|
|
347
|
+
children: /*#__PURE__*/ jsxs(Space.Compact, {
|
|
348
|
+
children: [
|
|
349
|
+
/*#__PURE__*/ jsx(Input, {
|
|
350
|
+
disabled: true,
|
|
351
|
+
value: "root"
|
|
352
|
+
}),
|
|
353
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
354
|
+
placement: "top",
|
|
355
|
+
title: 'checked_all',
|
|
356
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
357
|
+
type: "text",
|
|
358
|
+
disabled: true,
|
|
359
|
+
children: /*#__PURE__*/ jsx(Checkbox, {
|
|
360
|
+
checked: checked,
|
|
361
|
+
disabled: disabled,
|
|
362
|
+
onChange: (e)=>changeCheckBox(e.target.checked)
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
]
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
]
|
|
370
|
+
})
|
|
371
|
+
}),
|
|
372
|
+
/*#__PURE__*/ jsx(Col, {
|
|
373
|
+
span: 3,
|
|
374
|
+
className: "col-item col-item-type",
|
|
375
|
+
children: /*#__PURE__*/ jsx(Select, {
|
|
376
|
+
className: "type-select-style",
|
|
377
|
+
onChange: (e)=>changeType("type", e),
|
|
378
|
+
value: schema.type || 'object',
|
|
379
|
+
children: SCHEMA_TYPE.map((item, index)=>/*#__PURE__*/ jsx(Option, {
|
|
380
|
+
value: item,
|
|
381
|
+
children: item
|
|
382
|
+
}, index))
|
|
383
|
+
})
|
|
384
|
+
}),
|
|
385
|
+
mock && /*#__PURE__*/ jsx(Col, {
|
|
386
|
+
span: 3,
|
|
387
|
+
className: "col-item col-item-mock",
|
|
388
|
+
children: /*#__PURE__*/ jsx(MockSelect, {
|
|
389
|
+
schema: schema,
|
|
390
|
+
showEdit: ()=>showEdit([], 'mock', schema.mock, schema.type),
|
|
391
|
+
onChange: (value)=>changeValue([
|
|
392
|
+
'mock'
|
|
393
|
+
], value),
|
|
394
|
+
mock: mock
|
|
395
|
+
})
|
|
396
|
+
}),
|
|
397
|
+
/*#__PURE__*/ jsx(Col, {
|
|
398
|
+
span: mock ? 4 : 5,
|
|
399
|
+
className: "col-item col-item-mock",
|
|
400
|
+
children: /*#__PURE__*/ jsxs(Space.Compact, {
|
|
401
|
+
children: [
|
|
402
|
+
/*#__PURE__*/ jsx(Input, {
|
|
403
|
+
placeholder: LocalProvider('title'),
|
|
404
|
+
value: schema.title,
|
|
405
|
+
onChange: (e)=>changeValue([
|
|
406
|
+
'title'
|
|
407
|
+
], e.target.value)
|
|
408
|
+
}),
|
|
409
|
+
/*#__PURE__*/ jsx(Button, {
|
|
410
|
+
icon: /*#__PURE__*/ jsx(EditOutlined, {}),
|
|
411
|
+
onClick: ()=>showEdit([], 'title', schema.title)
|
|
412
|
+
})
|
|
413
|
+
]
|
|
414
|
+
})
|
|
415
|
+
}),
|
|
416
|
+
/*#__PURE__*/ jsx(Col, {
|
|
417
|
+
span: mock ? 4 : 5,
|
|
418
|
+
className: "col-item col-item-desc",
|
|
419
|
+
children: /*#__PURE__*/ jsxs(Space.Compact, {
|
|
420
|
+
children: [
|
|
421
|
+
/*#__PURE__*/ jsx(Input, {
|
|
422
|
+
placeholder: LocalProvider("description"),
|
|
423
|
+
value: schema.description,
|
|
424
|
+
onChange: (e)=>changeValue([
|
|
425
|
+
"description"
|
|
426
|
+
], e.target.value)
|
|
427
|
+
}),
|
|
428
|
+
/*#__PURE__*/ jsx(Button, {
|
|
429
|
+
icon: /*#__PURE__*/ jsx(EditOutlined, {}),
|
|
430
|
+
onClick: ()=>showEdit([], "description", schema.description)
|
|
431
|
+
})
|
|
432
|
+
]
|
|
433
|
+
})
|
|
434
|
+
}),
|
|
435
|
+
/*#__PURE__*/ jsxs(Col, {
|
|
436
|
+
span: 2,
|
|
437
|
+
className: "col-item col-item-setting",
|
|
438
|
+
children: [
|
|
439
|
+
/*#__PURE__*/ jsx("span", {
|
|
440
|
+
className: "adv-set",
|
|
441
|
+
onClick: ()=>showAdv([], schema),
|
|
442
|
+
children: /*#__PURE__*/ jsx(Tooltip, {
|
|
443
|
+
placement: "top",
|
|
444
|
+
title: LocalProvider('adv_setting'),
|
|
445
|
+
children: /*#__PURE__*/ jsx(SettingOutlined, {
|
|
446
|
+
type: "setting"
|
|
447
|
+
})
|
|
448
|
+
})
|
|
449
|
+
}),
|
|
450
|
+
'object' === schema.type ? /*#__PURE__*/ jsx("span", {
|
|
451
|
+
onClick: ()=>addChildField('properties'),
|
|
452
|
+
children: /*#__PURE__*/ jsx(Tooltip, {
|
|
453
|
+
placement: "top",
|
|
454
|
+
title: LocalProvider('add_child_node'),
|
|
455
|
+
children: /*#__PURE__*/ jsx(PlusOutlined, {
|
|
456
|
+
type: "plus",
|
|
457
|
+
className: "plus"
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
}) : null
|
|
461
|
+
]
|
|
462
|
+
})
|
|
463
|
+
]
|
|
464
|
+
}),
|
|
465
|
+
show && /*#__PURE__*/ jsx(SchemaJson, {
|
|
466
|
+
data: schema,
|
|
467
|
+
showEdit: showEdit,
|
|
468
|
+
showAdv: showAdv,
|
|
469
|
+
mock: mock
|
|
470
|
+
})
|
|
471
|
+
]
|
|
472
|
+
})
|
|
473
|
+
]
|
|
474
|
+
})
|
|
475
|
+
]
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
export default JsonSchemaEditorCore;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
declare const langs: {
|
|
2
|
+
en_US: {
|
|
3
|
+
title: string;
|
|
4
|
+
import_json: string;
|
|
5
|
+
base_setting: string;
|
|
6
|
+
all_setting: string;
|
|
7
|
+
default: string;
|
|
8
|
+
description: string;
|
|
9
|
+
adv_setting: string;
|
|
10
|
+
add_child_node: string;
|
|
11
|
+
add_sibling_node: string;
|
|
12
|
+
add_node: string;
|
|
13
|
+
child_node: string;
|
|
14
|
+
sibling_node: string;
|
|
15
|
+
ok: string;
|
|
16
|
+
cancel: string;
|
|
17
|
+
minLength: string;
|
|
18
|
+
maxLength: string;
|
|
19
|
+
pattern: string;
|
|
20
|
+
exclusiveMinimum: string;
|
|
21
|
+
exclusiveMaximum: string;
|
|
22
|
+
minimum: string;
|
|
23
|
+
maximum: string;
|
|
24
|
+
unique_items: string;
|
|
25
|
+
min_items: string;
|
|
26
|
+
max_items: string;
|
|
27
|
+
checked_all: string;
|
|
28
|
+
valid_json: string;
|
|
29
|
+
enum: string;
|
|
30
|
+
enum_msg: string;
|
|
31
|
+
enum_desc: string;
|
|
32
|
+
enum_desc_msg: string;
|
|
33
|
+
required: string;
|
|
34
|
+
mock: string;
|
|
35
|
+
mockLink: string;
|
|
36
|
+
};
|
|
37
|
+
zh_CN: {
|
|
38
|
+
title: string;
|
|
39
|
+
import_json: string;
|
|
40
|
+
base_setting: string;
|
|
41
|
+
all_setting: string;
|
|
42
|
+
default: string;
|
|
43
|
+
description: string;
|
|
44
|
+
adv_setting: string;
|
|
45
|
+
add_child_node: string;
|
|
46
|
+
add_sibling_node: string;
|
|
47
|
+
add_node: string;
|
|
48
|
+
child_node: string;
|
|
49
|
+
sibling_node: string;
|
|
50
|
+
ok: string;
|
|
51
|
+
cancel: string;
|
|
52
|
+
minLength: string;
|
|
53
|
+
maxLength: string;
|
|
54
|
+
pattern: string;
|
|
55
|
+
exclusiveMinimum: string;
|
|
56
|
+
exclusiveMaximum: string;
|
|
57
|
+
minimum: string;
|
|
58
|
+
maximum: string;
|
|
59
|
+
unique_items: string;
|
|
60
|
+
min_items: string;
|
|
61
|
+
max_items: string;
|
|
62
|
+
checked_all: string;
|
|
63
|
+
valid_json: string;
|
|
64
|
+
enum: string;
|
|
65
|
+
enum_msg: string;
|
|
66
|
+
enum_desc: string;
|
|
67
|
+
enum_desc_msg: string;
|
|
68
|
+
required: string;
|
|
69
|
+
mock: string;
|
|
70
|
+
mockLink: string;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export type MessageKey = keyof (typeof langs)['en_US'];
|
|
74
|
+
/**
|
|
75
|
+
* 从 antd ConfigProvider 中获取当前语言环境,并返回国际化查询函数
|
|
76
|
+
* @returns 一个接受 MessageKey 返回对应语言字符串的函数
|
|
77
|
+
*/
|
|
78
|
+
export declare function useLocalProvider(): (message: MessageKey) => string;
|
|
79
|
+
export {};
|