@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/dist/utils.js ADDED
@@ -0,0 +1,164 @@
1
+ const JSONPATH_JOIN_CHAR = '.';
2
+ const format = [
3
+ {
4
+ name: 'date-time'
5
+ },
6
+ {
7
+ name: 'date'
8
+ },
9
+ {
10
+ name: 'email'
11
+ },
12
+ {
13
+ name: 'hostname'
14
+ },
15
+ {
16
+ name: 'ipv4'
17
+ },
18
+ {
19
+ name: 'ipv6'
20
+ },
21
+ {
22
+ name: 'uri'
23
+ }
24
+ ];
25
+ const SCHEMA_TYPE = [
26
+ 'string',
27
+ 'number',
28
+ 'array',
29
+ 'object',
30
+ 'boolean',
31
+ 'integer'
32
+ ];
33
+ const defaultSchema = {
34
+ string: {
35
+ type: 'string'
36
+ },
37
+ number: {
38
+ type: 'number'
39
+ },
40
+ array: {
41
+ type: 'array',
42
+ items: {
43
+ type: 'string'
44
+ }
45
+ },
46
+ object: {
47
+ type: 'object',
48
+ properties: {}
49
+ },
50
+ boolean: {
51
+ type: 'boolean'
52
+ },
53
+ integer: {
54
+ type: 'integer'
55
+ }
56
+ };
57
+ const debounce = (func, wait)=>{
58
+ let timeout;
59
+ return function(...args) {
60
+ clearTimeout(timeout);
61
+ timeout = setTimeout(()=>{
62
+ func.apply(this, args);
63
+ }, wait);
64
+ };
65
+ };
66
+ function getData(state, keys) {
67
+ let curState = state;
68
+ for(let i = 0; i < keys.length; i++){
69
+ if (null == curState) return;
70
+ curState = curState[keys[i]];
71
+ }
72
+ return curState;
73
+ }
74
+ function setData(state, keys, value) {
75
+ let curState = state;
76
+ for(let i = 0; i < keys.length - 1; i++){
77
+ const key = keys[i];
78
+ if (null == curState[key]) curState[key] = 'number' == typeof keys[i + 1] ? [] : {};
79
+ curState = curState[key];
80
+ }
81
+ curState[keys[keys.length - 1]] = value;
82
+ }
83
+ function deleteData(state, keys) {
84
+ let curState = state;
85
+ for(let i = 0; i < keys.length - 1; i++){
86
+ const key = keys[i];
87
+ if (null == curState[key]) return;
88
+ curState = curState[key];
89
+ }
90
+ delete curState[keys[keys.length - 1]];
91
+ }
92
+ function getParentKeys(keys) {
93
+ if (keys.length <= 1) return [];
94
+ const arr = [
95
+ ...keys
96
+ ];
97
+ arr.splice(keys.length - 1, 1);
98
+ return arr;
99
+ }
100
+ function clearSomeFields(keys, data) {
101
+ const newData = {
102
+ ...data
103
+ };
104
+ keys.forEach((key)=>{
105
+ delete newData[key];
106
+ });
107
+ return newData;
108
+ }
109
+ function getFieldstitle(data) {
110
+ return Object.keys(data);
111
+ }
112
+ function handleSchemaRequired(schema, checked) {
113
+ if ('object' === schema.type) {
114
+ const requiredtitle = getFieldstitle(schema.properties || {});
115
+ if (checked) schema.required = [
116
+ ...requiredtitle
117
+ ];
118
+ else delete schema.required;
119
+ if (schema.properties) handleObject(schema.properties, checked);
120
+ } else {
121
+ if ('array' !== schema.type || !schema.items) return schema;
122
+ handleSchemaRequired(schema.items, checked);
123
+ }
124
+ }
125
+ function handleObject(properties, checked) {
126
+ for(const key in properties)if ('array' === properties[key].type || 'object' === properties[key].type) handleSchemaRequired(properties[key], checked);
127
+ }
128
+ function isNil(value) {
129
+ return null == value;
130
+ }
131
+ function isEqual(a, b) {
132
+ if (a === b) return true;
133
+ if (null == a || null == b) return false;
134
+ if (typeof a !== typeof b) return false;
135
+ if (Array.isArray(a)) {
136
+ if (!Array.isArray(b) || a.length !== b.length) return false;
137
+ for(let i = 0; i < a.length; i++)if (!isEqual(a[i], b[i])) return false;
138
+ return true;
139
+ }
140
+ if ('object' == typeof a) {
141
+ const keysA = Object.keys(a);
142
+ const keysB = Object.keys(b);
143
+ if (keysA.length !== keysB.length) return false;
144
+ for (const key of keysA)if (!Object.prototype.hasOwnProperty.call(b, key) || !isEqual(a[key], b[key])) return false;
145
+ return true;
146
+ }
147
+ return false;
148
+ }
149
+ function cloneObject(obj) {
150
+ if ('object' != typeof obj || null === obj) return obj;
151
+ if (Array.isArray(obj)) {
152
+ const newArr = [];
153
+ obj.forEach((item, index)=>{
154
+ newArr[index] = cloneObject(item);
155
+ });
156
+ return newArr;
157
+ }
158
+ {
159
+ const newObj = {};
160
+ for(const key in obj)newObj[key] = cloneObject(obj[key]);
161
+ return newObj;
162
+ }
163
+ }
164
+ export { JSONPATH_JOIN_CHAR, SCHEMA_TYPE, clearSomeFields, cloneObject, debounce, defaultSchema, deleteData, format, getData, getParentKeys, handleSchemaRequired, isEqual, isNil, setData };
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@tyx1703/json-schema-editor-visual",
3
+ "version": "1.0.0",
4
+ "description": "A React component for visually editing JSON Schema",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "tyx1703",
8
+ "repository": "github:YanxinTang/json-schema-editor-visual",
9
+ "keywords": [
10
+ "json-schema",
11
+ "editor",
12
+ "react",
13
+ "visual",
14
+ "antd"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./dist/index.css": "./dist/index.css"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "sideEffects": [
25
+ "**/*.css"
26
+ ],
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "build": "rslib",
34
+ "build:test": "cross-env NODE_ENV='test' rslib",
35
+ "dev": "rslib --watch",
36
+ "test": "rstest",
37
+ "test:watch": "rstest --watch"
38
+ },
39
+ "dependencies": {
40
+ "@monaco-editor/react": "^4.7.0",
41
+ "@reduxjs/toolkit": "^2.11.2",
42
+ "generate-schema": "^2.6.0",
43
+ "monaco-editor": "^0.55.1",
44
+ "react-redux": "^9.2.0"
45
+ },
46
+ "devDependencies": {
47
+ "@ant-design/icons": "^6.0.0",
48
+ "@rsbuild/plugin-react": "^2.0.0",
49
+ "@rslib/core": "^0.21.4",
50
+ "@rslint/core": "^0.5.2",
51
+ "@rstest/adapter-rslib": "^0.2.2",
52
+ "@rstest/browser": "^0.9.10",
53
+ "@rstest/browser-react": "^0.9.10",
54
+ "@rstest/core": "^0.9.10",
55
+ "@rstest/coverage-istanbul": "^0.3.2",
56
+ "@testing-library/dom": "^10.0.0",
57
+ "@testing-library/jest-dom": "^6.9.1",
58
+ "@testing-library/react": "^16.3.2",
59
+ "@testing-library/user-event": "^14.6.1",
60
+ "@types/node": "^24.12.2",
61
+ "@types/react": "^19.2.14",
62
+ "antd": "6",
63
+ "cross-env": "^7.0.3",
64
+ "happy-dom": "^20.9.0",
65
+ "playwright": "^1.49.1",
66
+ "react": "^19.2.5",
67
+ "react-dom": "^19.2.5",
68
+ "typescript": "^6.0.3"
69
+ },
70
+ "peerDependencies": {
71
+ "@ant-design/icons": "^5 || ^6",
72
+ "antd": "^5 || ^6",
73
+ "react": "^18 || ^19",
74
+ "react-dom": "^18 || ^19"
75
+ }
76
+ }