@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.
@@ -0,0 +1,128 @@
1
+ .json-schema-react-editor .option-formStyle {
2
+ padding-top: 8px;
3
+ }
4
+
5
+ .json-schema-react-editor .required-icon {
6
+ color: red;
7
+ padding-left: 5px;
8
+ font-size: 1em;
9
+ font-weight: bold;
10
+ }
11
+
12
+ .json-schema-react-editor .object-style {
13
+ margin-top: 8px;
14
+ padding-top: 6px;
15
+ }
16
+
17
+ .json-schema-react-editor .col-item-type {
18
+ text-align: center;
19
+ }
20
+
21
+ .json-schema-react-editor .down-style {
22
+ cursor: pointer;
23
+ }
24
+
25
+ .json-schema-react-editor .col-item-desc {
26
+ text-align: center;
27
+ }
28
+
29
+ .json-schema-react-editor .col-item-mock {
30
+ text-align: center;
31
+ padding-right: 6px;
32
+ }
33
+
34
+ .json-schema-react-editor .col-item-setting {
35
+ cursor: pointer;
36
+ padding-left: 6px;
37
+ }
38
+
39
+ .json-schema-react-editor .plus {
40
+ color: #2395f1;
41
+ }
42
+
43
+ .json-schema-react-editor .close {
44
+ color: #ff561b;
45
+ }
46
+
47
+ .json-schema-react-editor .array-type {
48
+ margin-top: 8px;
49
+ }
50
+
51
+ .json-schema-react-editor .delete-item {
52
+ padding-right: 8px;
53
+ }
54
+
55
+ .json-schema-react-editor .object-style .name-item .ant-input-group-addon {
56
+ background-color: unset;
57
+ border: unset;
58
+ }
59
+
60
+ .json-schema-react-editor .object-style .name-item .ant-input-group > .ant-input:first-child, .ant-input-group-addon:first-child {
61
+ border-top-right-radius: 4px;
62
+ border-bottom-right-radius: 4px;
63
+ }
64
+
65
+ .json-schema-react-editor .icon-object {
66
+ color: #0d1b3ea6;
67
+ font-size: 10px;
68
+ font-weight: 400;
69
+ }
70
+
71
+ .json-schema-react-editor .down-style-col {
72
+ width: 10px;
73
+ }
74
+
75
+ .json-schema-react-editor .wrapper {
76
+ padding-left: 8px;
77
+ }
78
+
79
+ .json-schema-react-editor .adv-set {
80
+ color: #00a854;
81
+ padding-right: 8px;
82
+ }
83
+
84
+ .json-schema-react-editor .type-select-style {
85
+ width: 90%;
86
+ }
87
+
88
+ .json-schema-react-editor-import-modal .ant-tabs-nav .ant-tabs-tab {
89
+ height: auto;
90
+ }
91
+
92
+ .json-schema-react-editor-adv-modal .other-row {
93
+ margin-bottom: 16px;
94
+ }
95
+
96
+ .json-schema-react-editor-adv-modal .other-label {
97
+ text-align: right;
98
+ padding-right: 8px;
99
+ }
100
+
101
+ .json-schema-react-editor-adv-modal .default-setting {
102
+ border-left: 3px solid #2395f1;
103
+ margin-bottom: 16px;
104
+ padding-left: 8px;
105
+ font-size: 16px;
106
+ font-weight: 400;
107
+ }
108
+
109
+ .json-schema-react-editor-adv-modal .ant-modal-body {
110
+ min-height: 400px;
111
+ }
112
+
113
+ .json-schema-react-editor-adv-modal .ant-modal-body .monaco-editor-container {
114
+ min-height: 350px;
115
+ }
116
+
117
+ .json-schema-react-editor-adv-modal-select .format-items-title {
118
+ color: #999;
119
+ position: absolute;
120
+ right: 16px;
121
+ }
122
+
123
+ .ant-modal-close-x {
124
+ justify-content: center;
125
+ align-items: center;
126
+ display: flex;
127
+ }
128
+
package/dist/index.css ADDED
@@ -0,0 +1,53 @@
1
+ ::-webkit-scrollbar {
2
+ width: 6px;
3
+ }
4
+
5
+ ::-webkit-scrollbar-track {
6
+ -webkit-box-shadow: inset006pxrgba(255, 0, 0, .3);
7
+ background: #ffffff1a;
8
+ }
9
+
10
+ ::-webkit-scrollbar-thumb {
11
+ -webkit-box-shadow: inset006pxrgba(0, 0, 0, .5);
12
+ background: #0003;
13
+ border-radius: 4px;
14
+ }
15
+
16
+ ::-webkit-scrollbar-thumb:window-inactive {
17
+ background: #0003;
18
+ }
19
+
20
+ .json-schema-react-editor {
21
+ font-size: 14px;
22
+ }
23
+
24
+ .json-schema-react-editor .array-item-type {
25
+ text-align: left;
26
+ }
27
+
28
+ .json-schema-react-editor .add-btn {
29
+ margin: 8px;
30
+ }
31
+
32
+ .json-schema-react-editor .pretty-editor {
33
+ border: 1px solid #d9d9d9;
34
+ border-radius: 4px;
35
+ height: 800px;
36
+ }
37
+
38
+ .json-schema-react-editor .import-json-button {
39
+ margin: 5px;
40
+ }
41
+
42
+ .json-schema-react-editor .mock-select {
43
+ width: 100%;
44
+ }
45
+
46
+ .json-schema-react-editor .certain-category-search {
47
+ flex: 1;
48
+ }
49
+
50
+ .json-schema-react-editor .certain-category-search .ant-select-search__field__wrap {
51
+ display: unset;
52
+ }
53
+
@@ -0,0 +1,2 @@
1
+ import { JsonSchemaEditorCoreProps } from './JsonSchemaEditor';
2
+ export default function JsonSchemaEditorVisual(props: JsonSchemaEditorCoreProps): import("react/jsx-runtime").JSX.Element;
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { Provider } from "react-redux";
4
+ import { createStore } from "./store/index.js";
5
+ import JsonSchemaEditor from "./JsonSchemaEditor.js";
6
+ function JsonSchemaEditorVisual(props) {
7
+ const store = useMemo(()=>createStore(), []);
8
+ return /*#__PURE__*/ jsx(Provider, {
9
+ store: store,
10
+ children: /*#__PURE__*/ jsx(JsonSchemaEditor, {
11
+ ...props
12
+ })
13
+ });
14
+ }
15
+ export default JsonSchemaEditorVisual;
@@ -0,0 +1,15 @@
1
+ import type { JsonSchema } from './types';
2
+ /**
3
+ * Input type for schema handling functions.
4
+ * Allows missing fields that handleSchema will fill in with defaults.
5
+ */
6
+ interface SchemaInput {
7
+ type?: string;
8
+ title?: string;
9
+ items?: SchemaInput;
10
+ properties?: Record<string, SchemaInput>;
11
+ required?: string[];
12
+ [key: string]: unknown;
13
+ }
14
+ export declare function handleSchema(schema: SchemaInput): JsonSchema;
15
+ export {};
package/dist/schema.js ADDED
@@ -0,0 +1,24 @@
1
+ function handleType(schema) {
2
+ if (!schema.type && schema.properties && 'object' == typeof schema.properties) schema.type = 'object';
3
+ }
4
+ function handleSchema(schema) {
5
+ if (schema && !schema.type && !schema.properties) schema.type = 'string';
6
+ handleType(schema);
7
+ if ('object' === schema.type) {
8
+ if (!schema.properties) schema.properties = {};
9
+ handleObject(schema.properties);
10
+ return schema;
11
+ }
12
+ if ('array' !== schema.type) return schema;
13
+ if (!schema.items) schema.items = {
14
+ type: 'string'
15
+ };
16
+ return handleSchema(schema.items);
17
+ }
18
+ function handleObject(properties) {
19
+ for(const key in properties){
20
+ handleType(properties[key]);
21
+ if ('array' === properties[key].type || 'object' === properties[key].type) handleSchema(properties[key]);
22
+ }
23
+ }
24
+ export { handleSchema };
@@ -0,0 +1,16 @@
1
+ export declare const createStore: () => import("@reduxjs/toolkit").EnhancedStore<{
2
+ schema: import("./schemaSlice").SchemaState;
3
+ }, import("@reduxjs/toolkit").UnknownAction, import("@reduxjs/toolkit").Tuple<[import("@reduxjs/toolkit").StoreEnhancer<{
4
+ dispatch: import("@reduxjs/toolkit").ThunkDispatch<{
5
+ schema: import("./schemaSlice").SchemaState;
6
+ }, undefined, import("@reduxjs/toolkit").UnknownAction>;
7
+ }>, import("@reduxjs/toolkit").StoreEnhancer]>>;
8
+ export type Store = ReturnType<typeof createStore>;
9
+ export type RootState = ReturnType<Store['getState']>;
10
+ export type AppDispatch = Store['dispatch'];
11
+ export declare const useAppDispatch: import("react-redux").UseDispatch<import("@reduxjs/toolkit").ThunkDispatch<{
12
+ schema: import("./schemaSlice").SchemaState;
13
+ }, undefined, import("@reduxjs/toolkit").UnknownAction> & import("@reduxjs/toolkit").Dispatch<import("@reduxjs/toolkit").UnknownAction>>;
14
+ export declare const useAppSelector: import("react-redux").UseSelector<{
15
+ schema: import("./schemaSlice").SchemaState;
16
+ }>;
@@ -0,0 +1,11 @@
1
+ import { configureStore } from "@reduxjs/toolkit";
2
+ import { reducer } from "./schemaSlice.js";
3
+ import { useDispatch, useSelector } from "react-redux";
4
+ const createStore = ()=>configureStore({
5
+ reducer: {
6
+ schema: reducer
7
+ }
8
+ });
9
+ const useAppDispatch = useDispatch.withTypes();
10
+ const useAppSelector = useSelector.withTypes();
11
+ export { createStore, useAppDispatch, useAppSelector };
@@ -0,0 +1,49 @@
1
+ import type { JsonSchema } from '../types';
2
+ export interface SchemaState {
3
+ fieldNum: number;
4
+ message: string | null;
5
+ data: JsonSchema;
6
+ open: Record<string, boolean>;
7
+ }
8
+ interface ChangeEditorSchemaPayload {
9
+ value: Record<string, unknown>;
10
+ }
11
+ interface ChangeNamePayload {
12
+ prefix: string[];
13
+ name: string;
14
+ value: string;
15
+ }
16
+ interface ChangeValuePayload {
17
+ key: string[];
18
+ value: unknown;
19
+ }
20
+ interface ChangeTypePayload {
21
+ key: string[];
22
+ value: string;
23
+ }
24
+ interface EnableRequirePayload {
25
+ prefix: string[];
26
+ name: string;
27
+ required: boolean;
28
+ }
29
+ interface RequireAllPayload {
30
+ required: boolean;
31
+ value: JsonSchema;
32
+ }
33
+ interface DeleteItemPayload {
34
+ key: string[];
35
+ }
36
+ interface AddFieldPayload {
37
+ prefix: string[];
38
+ name: string;
39
+ }
40
+ interface AddChildFieldPayload {
41
+ key: string[];
42
+ }
43
+ interface SetOpenValuePayload {
44
+ key: string[];
45
+ value?: boolean;
46
+ }
47
+ export declare const reducer: import("@reduxjs/toolkit").Reducer<SchemaState>;
48
+ export declare const changeEditorSchemaAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<ChangeEditorSchemaPayload, "schema/changeEditorSchemaAction">, changeNameAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<ChangeNamePayload, "schema/changeNameAction">, changeValueAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<ChangeValuePayload, "schema/changeValueAction">, changeTypeAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<ChangeTypePayload, "schema/changeTypeAction">, enableRequireAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<EnableRequirePayload, "schema/enableRequireAction">, requireAllAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<RequireAllPayload, "schema/requireAllAction">, deleteItemAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<DeleteItemPayload, "schema/deleteItemAction">, addFieldAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<AddFieldPayload, "schema/addFieldAction">, addChildFieldAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<AddChildFieldPayload, "schema/addChildFieldAction">, setOpenValueAction: import("@reduxjs/toolkit").ActionCreatorWithPayload<SetOpenValuePayload, "schema/setOpenValueAction">;
49
+ export {};
@@ -0,0 +1,208 @@
1
+ import { createSlice, original } from "@reduxjs/toolkit";
2
+ import { handleSchema } from "../schema.js";
3
+ import * as __rspack_external__utils_js_db66b9f7 from "../utils.js";
4
+ const initialState = {
5
+ fieldNum: 1,
6
+ message: null,
7
+ data: {
8
+ title: '',
9
+ type: 'object',
10
+ description: '',
11
+ properties: {},
12
+ required: []
13
+ },
14
+ open: {
15
+ properties: true
16
+ }
17
+ };
18
+ const schemaSlice = createSlice({
19
+ name: 'schema',
20
+ initialState: initialState,
21
+ reducers: {
22
+ changeEditorSchemaAction: function(state, action) {
23
+ const { payload } = action;
24
+ state.data = handleSchema(payload.value);
25
+ },
26
+ changeNameAction: function(state, action) {
27
+ const { payload } = action;
28
+ const oldState = original(state);
29
+ if (!oldState) return;
30
+ const keys = payload.prefix;
31
+ const name = payload.name;
32
+ const value = payload.value;
33
+ const oldData = oldState.data;
34
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
35
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
36
+ let requiredData = [
37
+ ...parentData.required ?? []
38
+ ];
39
+ const propertiesData = __rspack_external__utils_js_db66b9f7.getData(oldData, keys);
40
+ const newPropertiesData = {};
41
+ const curData = propertiesData[name];
42
+ const openKeys = [
43
+ ...keys,
44
+ value,
45
+ 'properties'
46
+ ].join(__rspack_external__utils_js_db66b9f7.JSONPATH_JOIN_CHAR);
47
+ const oldOpenKeys = [
48
+ ...keys,
49
+ name,
50
+ 'properties'
51
+ ].join(__rspack_external__utils_js_db66b9f7.JSONPATH_JOIN_CHAR);
52
+ if (curData.properties) {
53
+ delete state.open[oldOpenKeys];
54
+ state.open[openKeys] = true;
55
+ }
56
+ if (propertiesData[value] && 'object' == typeof propertiesData[value]) return;
57
+ requiredData = requiredData.map((item)=>{
58
+ if (item === name) return value;
59
+ return item;
60
+ });
61
+ parentKeys.push('required');
62
+ __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, requiredData);
63
+ for(const i in propertiesData)if (i === name) newPropertiesData[value] = propertiesData[i];
64
+ else newPropertiesData[i] = propertiesData[i];
65
+ __rspack_external__utils_js_db66b9f7.setData(state.data, keys, newPropertiesData);
66
+ },
67
+ changeValueAction: function(state, action) {
68
+ const { payload } = action;
69
+ const keys = payload.key;
70
+ if (payload.value) __rspack_external__utils_js_db66b9f7.setData(state.data, keys, payload.value);
71
+ else __rspack_external__utils_js_db66b9f7.deleteData(state.data, keys);
72
+ },
73
+ changeTypeAction: function(state, action) {
74
+ const { payload } = action;
75
+ const oldState = original(state);
76
+ if (!oldState) return;
77
+ const keys = payload.key;
78
+ const value = payload.value;
79
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
80
+ const oldData = oldState.data;
81
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
82
+ if (parentData.type === value) return;
83
+ const newParentDataItem = __rspack_external__utils_js_db66b9f7.defaultSchema[value];
84
+ const parentDataItem = parentData.description ? {
85
+ description: parentData.description
86
+ } : {};
87
+ const newParentData = Object.assign({}, newParentDataItem, parentDataItem);
88
+ const newKeys = [
89
+ 'data',
90
+ ...parentKeys
91
+ ];
92
+ __rspack_external__utils_js_db66b9f7.setData(state, newKeys, newParentData);
93
+ },
94
+ enableRequireAction: function(state, action) {
95
+ const { payload } = action;
96
+ const oldState = original(state);
97
+ if (!oldState) return;
98
+ const keys = payload.prefix;
99
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
100
+ const oldData = oldState.data;
101
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
102
+ const requiredData = [
103
+ ...parentData.required ?? []
104
+ ];
105
+ const index = requiredData.indexOf(payload.name);
106
+ if (!payload.required && index >= 0) {
107
+ requiredData.splice(index, 1);
108
+ parentKeys.push('required');
109
+ if (0 === requiredData.length) __rspack_external__utils_js_db66b9f7.deleteData(state.data, parentKeys);
110
+ else __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, requiredData);
111
+ } else if (payload.required && -1 === index) {
112
+ requiredData.push(payload.name);
113
+ parentKeys.push('required');
114
+ __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, requiredData);
115
+ }
116
+ },
117
+ requireAllAction: function(state, action) {
118
+ const { payload } = action;
119
+ const oldState = original(state);
120
+ if (!oldState) return;
121
+ const data = __rspack_external__utils_js_db66b9f7.cloneObject(payload.value);
122
+ __rspack_external__utils_js_db66b9f7.handleSchemaRequired(data, payload.required);
123
+ state.data = data;
124
+ },
125
+ deleteItemAction: function(state, action) {
126
+ const { payload } = action;
127
+ const oldState = original(state);
128
+ if (!oldState) return;
129
+ const keys = payload.key;
130
+ const name = keys[keys.length - 1];
131
+ const oldData = oldState.data;
132
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
133
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
134
+ const newParentData = {};
135
+ for(const i in parentData)if (i !== name) newParentData[i] = parentData[i];
136
+ __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, newParentData);
137
+ },
138
+ addFieldAction: function(state, action) {
139
+ const { payload } = action;
140
+ const oldState = original(state);
141
+ if (!oldState) return;
142
+ const keys = payload.prefix;
143
+ const oldData = oldState.data;
144
+ const name = payload.name;
145
+ const propertiesData = __rspack_external__utils_js_db66b9f7.getData(oldData, keys);
146
+ let newPropertiesData = {};
147
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
148
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
149
+ const requiredData = [
150
+ ...parentData.required ?? []
151
+ ];
152
+ if (name) for(const i in propertiesData){
153
+ newPropertiesData[i] = propertiesData[i];
154
+ if (i === name) {
155
+ const ranName = 'field_' + state.fieldNum++;
156
+ newPropertiesData[ranName] = __rspack_external__utils_js_db66b9f7.defaultSchema.string;
157
+ requiredData.push(ranName);
158
+ }
159
+ }
160
+ else {
161
+ newPropertiesData = Object.assign({}, propertiesData);
162
+ const ranName = 'field_' + state.fieldNum++;
163
+ newPropertiesData[ranName] = __rspack_external__utils_js_db66b9f7.defaultSchema.string;
164
+ requiredData.push(ranName);
165
+ }
166
+ __rspack_external__utils_js_db66b9f7.setData(state.data, keys, newPropertiesData);
167
+ parentKeys.push('required');
168
+ __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, requiredData);
169
+ },
170
+ addChildFieldAction: function(state, action) {
171
+ const { payload } = action;
172
+ const oldState = original(state);
173
+ if (!oldState) return;
174
+ const keys = payload.key;
175
+ const oldData = oldState.data;
176
+ const propertiesData = __rspack_external__utils_js_db66b9f7.getData(oldData, keys);
177
+ let newPropertiesData = {};
178
+ newPropertiesData = Object.assign({}, propertiesData);
179
+ const ranName = 'field_' + state.fieldNum++;
180
+ newPropertiesData[ranName] = __rspack_external__utils_js_db66b9f7.defaultSchema.string;
181
+ __rspack_external__utils_js_db66b9f7.setData(state.data, keys, newPropertiesData);
182
+ const parentKeys = __rspack_external__utils_js_db66b9f7.getParentKeys(keys);
183
+ const parentData = __rspack_external__utils_js_db66b9f7.getData(oldData, parentKeys);
184
+ const requiredData = [
185
+ ...parentData.required ?? []
186
+ ];
187
+ requiredData.push(ranName);
188
+ parentKeys.push('required');
189
+ __rspack_external__utils_js_db66b9f7.setData(state.data, parentKeys, requiredData);
190
+ },
191
+ setOpenValueAction: function(state, action) {
192
+ const { payload } = action;
193
+ const oldState = original(state);
194
+ if (!oldState) return;
195
+ const keys = payload.key.join(__rspack_external__utils_js_db66b9f7.JSONPATH_JOIN_CHAR);
196
+ let status;
197
+ status = __rspack_external__utils_js_db66b9f7.isNil(payload.value) ? !__rspack_external__utils_js_db66b9f7.getData(oldState.open, [
198
+ keys
199
+ ]) : payload.value;
200
+ __rspack_external__utils_js_db66b9f7.setData(state.open, [
201
+ keys
202
+ ], status);
203
+ }
204
+ }
205
+ });
206
+ const { reducer: reducer } = schemaSlice;
207
+ const { changeEditorSchemaAction: changeEditorSchemaAction, changeNameAction: changeNameAction, changeValueAction: changeValueAction, changeTypeAction: changeTypeAction, enableRequireAction: enableRequireAction, requireAllAction: requireAllAction, deleteItemAction: deleteItemAction, addFieldAction: addFieldAction, addChildFieldAction: addChildFieldAction, setOpenValueAction: setOpenValueAction } = schemaSlice.actions;
208
+ export { addChildFieldAction, addFieldAction, changeEditorSchemaAction, changeNameAction, changeTypeAction, changeValueAction, deleteItemAction, enableRequireAction, reducer, requireAllAction, setOpenValueAction };
@@ -0,0 +1,56 @@
1
+ export type Format = {
2
+ name: string;
3
+ title?: string;
4
+ }[];
5
+ export type MockSource = {
6
+ name: string;
7
+ mock: string;
8
+ }[];
9
+ /**
10
+ * Discriminated union JSON Schema types
11
+ */
12
+ interface JsonSchemaBase {
13
+ title?: string;
14
+ description?: string;
15
+ enumDesc?: string;
16
+ mock?: {
17
+ mock: string;
18
+ };
19
+ items?: JsonSchema;
20
+ properties?: Record<string, JsonSchema>;
21
+ required?: string[];
22
+ [key: string]: unknown;
23
+ }
24
+ export interface JsonSchemaString extends JsonSchemaBase {
25
+ type: 'string';
26
+ default?: string;
27
+ enum?: string[];
28
+ minLength?: number;
29
+ maxLength?: number;
30
+ pattern?: string;
31
+ format?: string;
32
+ }
33
+ export interface JsonSchemaNumber extends JsonSchemaBase {
34
+ type: 'number' | 'integer';
35
+ default?: number;
36
+ enum?: number[];
37
+ minimum?: number;
38
+ maximum?: number;
39
+ exclusiveMinimum?: boolean;
40
+ exclusiveMaximum?: boolean;
41
+ }
42
+ export interface JsonSchemaBoolean extends JsonSchemaBase {
43
+ type: 'boolean';
44
+ default?: boolean;
45
+ }
46
+ export interface JsonSchemaArray extends JsonSchemaBase {
47
+ type: 'array';
48
+ uniqueItems?: boolean;
49
+ minItems?: number;
50
+ maxItems?: number;
51
+ }
52
+ export interface JsonSchemaObject extends JsonSchemaBase {
53
+ type: 'object';
54
+ }
55
+ export type JsonSchema = JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaArray | JsonSchemaObject;
56
+ export {};
package/dist/types.js ADDED
File without changes
@@ -0,0 +1,31 @@
1
+ import { Format, JsonSchema } from './types';
2
+ export declare const JSONPATH_JOIN_CHAR = ".";
3
+ export declare const format: Format;
4
+ export declare const SCHEMA_TYPE: readonly ["string", "number", "array", "object", "boolean", "integer"];
5
+ export declare const defaultSchema: Record<string, JsonSchema>;
6
+ export declare const debounce: <T extends (...args: unknown[]) => unknown>(func: T, wait: number) => ((...args: Parameters<T>) => void);
7
+ export declare function getData(state: Record<string, unknown>, keys: PropertyKey[]): unknown;
8
+ export declare function setData(state: Record<string, unknown>, keys: PropertyKey[], value: unknown): void;
9
+ export declare function deleteData(state: Record<string, unknown>, keys: PropertyKey[]): void;
10
+ export declare function getParentKeys<T>(keys: T[]): T[];
11
+ export declare function clearSomeFields<T extends Record<string, unknown>>(keys: string[], data: T): T;
12
+ export declare function handleSchemaRequired(schema: JsonSchema, checked: boolean): JsonSchema | void;
13
+ /**
14
+ * 检查值是否为 null 或 undefined
15
+ * @param value - 要检查的值
16
+ * @returns 当值为 null 或 undefined 时返回 true,否则返回 false
17
+ * @example
18
+ * isNil(null) // true
19
+ * isNil(undefined) // true
20
+ * isNil(0) // false
21
+ * isNil('') // false
22
+ */
23
+ export declare function isNil(value: unknown): value is null | undefined;
24
+ /**
25
+ * 深度比较两个值是否相等
26
+ * @param a - 第一个值
27
+ * @param b - 第二个值
28
+ * @returns 两个值深度相等时返回 true
29
+ */
30
+ export declare function isEqual(a: unknown, b: unknown): boolean;
31
+ export declare function cloneObject<T>(obj: T): T;