@skygraph/react 0.0.0-placeholder.0 → 0.4.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/LICENSE +21 -0
- package/dist/Table-BqN2u5ma.d.cts +1015 -0
- package/dist/Table-IvijKCyd.d.ts +1015 -0
- package/dist/chunk-2OCEO636.js +91 -0
- package/dist/chunk-2OCEO636.js.map +1 -0
- package/dist/chunk-6SHHUUAE.js +1667 -0
- package/dist/chunk-6SHHUUAE.js.map +1 -0
- package/dist/chunk-BNMJSYI2.js +54 -0
- package/dist/chunk-BNMJSYI2.js.map +1 -0
- package/dist/chunk-DRBAZI46.js +57 -0
- package/dist/chunk-DRBAZI46.js.map +1 -0
- package/dist/chunk-GJDDPZH7.js +226 -0
- package/dist/chunk-GJDDPZH7.js.map +1 -0
- package/dist/chunk-KCFWFDSP.js +847 -0
- package/dist/chunk-KCFWFDSP.js.map +1 -0
- package/dist/chunk-MJAEAFPN.js +3791 -0
- package/dist/chunk-MJAEAFPN.js.map +1 -0
- package/dist/chunk-MLEBVELO.js +1412 -0
- package/dist/chunk-MLEBVELO.js.map +1 -0
- package/dist/chunk-SEQI65CF.js +61 -0
- package/dist/chunk-SEQI65CF.js.map +1 -0
- package/dist/chunk-ZJF6SJLP.js +200 -0
- package/dist/chunk-ZJF6SJLP.js.map +1 -0
- package/dist/common-CdpocIEz.d.cts +27 -0
- package/dist/common-CdpocIEz.d.ts +27 -0
- package/dist/datagrid-B6hg5yJh.d.cts +200 -0
- package/dist/datagrid-B6hg5yJh.d.ts +200 -0
- package/dist/datagrid.cjs +1052 -0
- package/dist/datagrid.cjs.map +1 -0
- package/dist/datagrid.d.cts +2 -0
- package/dist/datagrid.d.ts +2 -0
- package/dist/datagrid.js +10 -0
- package/dist/datagrid.js.map +1 -0
- package/dist/devtools.cjs +253 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +29 -0
- package/dist/devtools.d.ts +29 -0
- package/dist/devtools.js +9 -0
- package/dist/devtools.js.map +1 -0
- package/dist/form.cjs +1723 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.cts +530 -0
- package/dist/form.d.ts +530 -0
- package/dist/form.js +49 -0
- package/dist/form.js.map +1 -0
- package/dist/index.cjs +22419 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3671 -0
- package/dist/index.d.ts +3671 -0
- package/dist/index.js +14087 -0
- package/dist/index.js.map +1 -0
- package/dist/table.cjs +4130 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +31 -0
- package/dist/table.d.ts +31 -0
- package/dist/table.js +26 -0
- package/dist/table.js.map +1 -0
- package/dist/tree.cjs +1821 -0
- package/dist/tree.cjs.map +1 -0
- package/dist/tree.d.cts +348 -0
- package/dist/tree.d.ts +348 -0
- package/dist/tree.js +13 -0
- package/dist/tree.js.map +1 -0
- package/dist/virtual.cjs +145 -0
- package/dist/virtual.cjs.map +1 -0
- package/dist/virtual.d.cts +50 -0
- package/dist/virtual.d.ts +50 -0
- package/dist/virtual.js +11 -0
- package/dist/virtual.js.map +1 -0
- package/package.json +108 -18
- package/README.md +0 -12
- package/index.js +0 -3
package/dist/form.cjs
ADDED
|
@@ -0,0 +1,1723 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/form.ts
|
|
31
|
+
var form_exports = {};
|
|
32
|
+
__export(form_exports, {
|
|
33
|
+
AutoField: () => AutoField,
|
|
34
|
+
Field: () => Field,
|
|
35
|
+
Form: () => Form,
|
|
36
|
+
FormContext: () => FormContext,
|
|
37
|
+
FormList: () => FormList,
|
|
38
|
+
FormProvider: () => FormProvider,
|
|
39
|
+
SchemaForm: () => SchemaForm,
|
|
40
|
+
SubmitButton: () => SubmitButton,
|
|
41
|
+
jsonSchemaToDefaults: () => jsonSchemaToDefaults,
|
|
42
|
+
jsonSchemaToFields: () => jsonSchemaToFields,
|
|
43
|
+
jsonSchemaToRules: () => jsonSchemaToRules,
|
|
44
|
+
useField: () => useField,
|
|
45
|
+
useFieldArray: () => useFieldArray,
|
|
46
|
+
useForm: () => useForm,
|
|
47
|
+
useFormContext: () => useFormContext,
|
|
48
|
+
useFormProvider: () => useFormProvider,
|
|
49
|
+
useWatch: () => useWatch,
|
|
50
|
+
zodDefaults: () => zodDefaults,
|
|
51
|
+
zodRule: () => zodRule,
|
|
52
|
+
zodRules: () => zodRules,
|
|
53
|
+
zodToJsonSchema: () => zodToJsonSchema
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(form_exports);
|
|
56
|
+
|
|
57
|
+
// src/hooks/useField.ts
|
|
58
|
+
var import_react = require("react");
|
|
59
|
+
function useField(core, form, name) {
|
|
60
|
+
const [value, setValue] = (0, import_react.useState)(() => form.getValue(name));
|
|
61
|
+
const [meta, setMeta] = (0, import_react.useState)(() => form.getFieldState(name));
|
|
62
|
+
const nameRef = (0, import_react.useRef)(name);
|
|
63
|
+
nameRef.current = name;
|
|
64
|
+
(0, import_react.useEffect)(() => {
|
|
65
|
+
const unsubs = [];
|
|
66
|
+
unsubs.push(
|
|
67
|
+
core.subscribe(name, (v) => {
|
|
68
|
+
setValue(v);
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
unsubs.push(
|
|
72
|
+
core.subscribe(`$meta.${name}.errors`, () => {
|
|
73
|
+
setMeta(form.getFieldState(nameRef.current));
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
unsubs.push(
|
|
77
|
+
core.subscribe(`$meta.${name}.warnings`, () => {
|
|
78
|
+
setMeta(form.getFieldState(nameRef.current));
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
unsubs.push(
|
|
82
|
+
core.subscribe(`$meta.${name}.touched`, () => {
|
|
83
|
+
setMeta(form.getFieldState(nameRef.current));
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
unsubs.push(
|
|
87
|
+
core.subscribe(`$meta.${name}.dirty`, () => {
|
|
88
|
+
setMeta(form.getFieldState(nameRef.current));
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
unsubs.push(
|
|
92
|
+
core.subscribe(`$meta.${name}.validating`, () => {
|
|
93
|
+
setMeta(form.getFieldState(nameRef.current));
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
return () => {
|
|
97
|
+
for (const u of unsubs) u();
|
|
98
|
+
};
|
|
99
|
+
}, [core, form, name]);
|
|
100
|
+
const onChange = (0, import_react.useCallback)(
|
|
101
|
+
(v) => {
|
|
102
|
+
form.setValue(nameRef.current, v);
|
|
103
|
+
},
|
|
104
|
+
[form]
|
|
105
|
+
);
|
|
106
|
+
const onBlur = (0, import_react.useCallback)(() => {
|
|
107
|
+
form.onFieldBlur(nameRef.current);
|
|
108
|
+
}, [form]);
|
|
109
|
+
return {
|
|
110
|
+
value,
|
|
111
|
+
errors: meta.errors,
|
|
112
|
+
warnings: meta.warnings,
|
|
113
|
+
error: meta.error,
|
|
114
|
+
touched: meta.touched,
|
|
115
|
+
dirty: meta.dirty,
|
|
116
|
+
validating: meta.validating,
|
|
117
|
+
status: meta.status,
|
|
118
|
+
onChange,
|
|
119
|
+
onBlur
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/hooks/useForm.ts
|
|
124
|
+
var import_react2 = require("react");
|
|
125
|
+
var import_core = require("@skygraph/core");
|
|
126
|
+
function useForm(options) {
|
|
127
|
+
const optionsRef = (0, import_react2.useRef)(options);
|
|
128
|
+
optionsRef.current = options;
|
|
129
|
+
const [{ core, form }] = (0, import_react2.useState)(() => {
|
|
130
|
+
const c = (0, import_core.createCore)();
|
|
131
|
+
const f = (0, import_core.createForm)(c, options);
|
|
132
|
+
return { core: c, form: f };
|
|
133
|
+
});
|
|
134
|
+
const [formState, setFormState] = (0, import_react2.useState)(() => form.getFormState());
|
|
135
|
+
const refreshState = (0, import_react2.useCallback)(() => {
|
|
136
|
+
setFormState(form.getFormState());
|
|
137
|
+
}, [form]);
|
|
138
|
+
const submit = (0, import_react2.useCallback)(async () => {
|
|
139
|
+
refreshState();
|
|
140
|
+
await form.submit(async (values) => {
|
|
141
|
+
await optionsRef.current?.onSubmit?.(values);
|
|
142
|
+
});
|
|
143
|
+
const state = form.getFormState();
|
|
144
|
+
setFormState(state);
|
|
145
|
+
if (!state.isValid && optionsRef.current?.onSubmitInvalid) {
|
|
146
|
+
optionsRef.current.onSubmitInvalid(
|
|
147
|
+
(await form.validate()).errors
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}, [form, refreshState]);
|
|
151
|
+
const reset = (0, import_react2.useCallback)(
|
|
152
|
+
(values) => {
|
|
153
|
+
form.reset(values);
|
|
154
|
+
setFormState(form.getFormState());
|
|
155
|
+
},
|
|
156
|
+
[form]
|
|
157
|
+
);
|
|
158
|
+
const setFieldValue = (0, import_react2.useCallback)(
|
|
159
|
+
(name, value) => {
|
|
160
|
+
form.setValue(name, value);
|
|
161
|
+
},
|
|
162
|
+
[form]
|
|
163
|
+
);
|
|
164
|
+
const setFieldsValue = (0, import_react2.useCallback)(
|
|
165
|
+
(values) => {
|
|
166
|
+
form.setFieldsValue(values);
|
|
167
|
+
},
|
|
168
|
+
[form]
|
|
169
|
+
);
|
|
170
|
+
const getFieldValue = (0, import_react2.useCallback)((name) => form.getValue(name), [form]);
|
|
171
|
+
const getFieldsValue = (0, import_react2.useCallback)(() => form.getFieldsValue(), [form]);
|
|
172
|
+
const validateFields = (0, import_react2.useCallback)((name) => form.validate(name), [form]);
|
|
173
|
+
return (0, import_react2.useMemo)(
|
|
174
|
+
() => ({
|
|
175
|
+
core,
|
|
176
|
+
form,
|
|
177
|
+
formState,
|
|
178
|
+
submit,
|
|
179
|
+
reset,
|
|
180
|
+
setFieldValue,
|
|
181
|
+
setFieldsValue,
|
|
182
|
+
getFieldValue,
|
|
183
|
+
getFieldsValue,
|
|
184
|
+
validateFields
|
|
185
|
+
}),
|
|
186
|
+
[
|
|
187
|
+
core,
|
|
188
|
+
form,
|
|
189
|
+
formState,
|
|
190
|
+
submit,
|
|
191
|
+
reset,
|
|
192
|
+
setFieldValue,
|
|
193
|
+
setFieldsValue,
|
|
194
|
+
getFieldValue,
|
|
195
|
+
getFieldsValue,
|
|
196
|
+
validateFields
|
|
197
|
+
]
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/hooks/useFieldArray.ts
|
|
202
|
+
var import_react3 = require("react");
|
|
203
|
+
function useFieldArray(form, name) {
|
|
204
|
+
const counterRef = (0, import_react3.useRef)(0);
|
|
205
|
+
const genKey2 = (0, import_react3.useCallback)(() => `fa_${name}_${++counterRef.current}`, [name]);
|
|
206
|
+
const [keys, setKeys] = (0, import_react3.useState)(() => {
|
|
207
|
+
const list = form.getListValue(name);
|
|
208
|
+
return list.map(() => genKey2());
|
|
209
|
+
});
|
|
210
|
+
const fields = (0, import_react3.useMemo)(
|
|
211
|
+
() => keys.map((key, index) => ({ key, index })),
|
|
212
|
+
[keys]
|
|
213
|
+
);
|
|
214
|
+
const append = (0, import_react3.useCallback)(
|
|
215
|
+
(defaultValue) => {
|
|
216
|
+
form.listAdd(name, defaultValue);
|
|
217
|
+
setKeys((prev) => [...prev, genKey2()]);
|
|
218
|
+
},
|
|
219
|
+
[form, name, genKey2]
|
|
220
|
+
);
|
|
221
|
+
const remove = (0, import_react3.useCallback)(
|
|
222
|
+
(index) => {
|
|
223
|
+
form.listRemove(name, index);
|
|
224
|
+
setKeys((prev) => prev.filter((_, i) => i !== index));
|
|
225
|
+
},
|
|
226
|
+
[form, name]
|
|
227
|
+
);
|
|
228
|
+
const move = (0, import_react3.useCallback)(
|
|
229
|
+
(from, to) => {
|
|
230
|
+
form.listMove(name, from, to);
|
|
231
|
+
setKeys((prev) => {
|
|
232
|
+
const next = [...prev];
|
|
233
|
+
const [item] = next.splice(from, 1);
|
|
234
|
+
next.splice(to, 0, item);
|
|
235
|
+
return next;
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
[form, name]
|
|
239
|
+
);
|
|
240
|
+
const replace = (0, import_react3.useCallback)(
|
|
241
|
+
(values) => {
|
|
242
|
+
const currentLen = form.getListValue(name).length;
|
|
243
|
+
for (let i = currentLen - 1; i >= 0; i--) {
|
|
244
|
+
form.listRemove(name, i);
|
|
245
|
+
}
|
|
246
|
+
const newKeys = [];
|
|
247
|
+
for (const v of values) {
|
|
248
|
+
form.listAdd(name, v);
|
|
249
|
+
newKeys.push(genKey2());
|
|
250
|
+
}
|
|
251
|
+
setKeys(newKeys);
|
|
252
|
+
},
|
|
253
|
+
[form, name, genKey2]
|
|
254
|
+
);
|
|
255
|
+
return (0, import_react3.useMemo)(
|
|
256
|
+
() => ({ fields, append, remove, move, replace }),
|
|
257
|
+
[fields, append, remove, move, replace]
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/hooks/useWatch.ts
|
|
262
|
+
var import_react4 = require("react");
|
|
263
|
+
function useWatch(core, name) {
|
|
264
|
+
const [value, setValue] = (0, import_react4.useState)(() => core.get(name));
|
|
265
|
+
(0, import_react4.useEffect)(() => {
|
|
266
|
+
setValue(core.get(name));
|
|
267
|
+
return core.subscribe(name, (v) => {
|
|
268
|
+
setValue(v);
|
|
269
|
+
});
|
|
270
|
+
}, [core, name]);
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/components/complex/Form.tsx
|
|
275
|
+
var import_react8 = require("react");
|
|
276
|
+
|
|
277
|
+
// src/components/complex/FormContext.ts
|
|
278
|
+
var import_react5 = require("react");
|
|
279
|
+
var FormContext = (0, import_react5.createContext)(null);
|
|
280
|
+
function useFormContext() {
|
|
281
|
+
const ctx = (0, import_react5.useContext)(FormContext);
|
|
282
|
+
if (!ctx) {
|
|
283
|
+
throw new Error("SkyGraph: useFormContext must be used inside <Form>");
|
|
284
|
+
}
|
|
285
|
+
return ctx;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/components/ConfigProvider.tsx
|
|
289
|
+
var import_react6 = require("react");
|
|
290
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
291
|
+
var SgConfigContext = (0, import_react6.createContext)({});
|
|
292
|
+
function useConfig() {
|
|
293
|
+
return (0, import_react6.useContext)(SgConfigContext);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/components/complex/FormProvider.tsx
|
|
297
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
298
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
299
|
+
var FormProviderContext = (0, import_react7.createContext)(null);
|
|
300
|
+
function FormProvider({ onFormFinish, onFormChange, children }) {
|
|
301
|
+
const formsRef = (0, import_react7.useRef)({});
|
|
302
|
+
const registerForm = (0, import_react7.useCallback)((name, form) => {
|
|
303
|
+
formsRef.current[name] = form;
|
|
304
|
+
}, []);
|
|
305
|
+
const unregisterForm = (0, import_react7.useCallback)((name) => {
|
|
306
|
+
delete formsRef.current[name];
|
|
307
|
+
}, []);
|
|
308
|
+
const value = (0, import_react7.useMemo)(
|
|
309
|
+
() => ({
|
|
310
|
+
registerForm,
|
|
311
|
+
unregisterForm,
|
|
312
|
+
onFormFinish,
|
|
313
|
+
onFormChange
|
|
314
|
+
}),
|
|
315
|
+
[registerForm, unregisterForm, onFormFinish, onFormChange]
|
|
316
|
+
);
|
|
317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormProviderContext.Provider, { value, children });
|
|
318
|
+
}
|
|
319
|
+
function useFormProvider() {
|
|
320
|
+
return (0, import_react7.useContext)(FormProviderContext);
|
|
321
|
+
}
|
|
322
|
+
function useFormProviderRegister(name, form) {
|
|
323
|
+
const provider = (0, import_react7.useContext)(FormProviderContext);
|
|
324
|
+
import_react7.default.useEffect(() => {
|
|
325
|
+
if (!provider || !name) return;
|
|
326
|
+
provider.registerForm(name, form);
|
|
327
|
+
return () => provider.unregisterForm(name);
|
|
328
|
+
}, [provider, name, form]);
|
|
329
|
+
return provider;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/components/complex/Form.tsx
|
|
333
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
334
|
+
function Form({
|
|
335
|
+
form: externalForm,
|
|
336
|
+
name: formName,
|
|
337
|
+
layout = "vertical",
|
|
338
|
+
size: sizeProp,
|
|
339
|
+
disabled: disabledProp,
|
|
340
|
+
colon,
|
|
341
|
+
requiredMark,
|
|
342
|
+
labelCol,
|
|
343
|
+
wrapperCol,
|
|
344
|
+
labelAlign,
|
|
345
|
+
className,
|
|
346
|
+
style,
|
|
347
|
+
children,
|
|
348
|
+
scrollToFirstError,
|
|
349
|
+
preserve,
|
|
350
|
+
feedbackIcons,
|
|
351
|
+
onFinish,
|
|
352
|
+
initialValues,
|
|
353
|
+
...formOptions
|
|
354
|
+
}) {
|
|
355
|
+
const config = useConfig();
|
|
356
|
+
const size = sizeProp ?? config.size ?? "middle";
|
|
357
|
+
const disabled = disabledProp ?? config.disabled;
|
|
358
|
+
const mergedFormOptions = {
|
|
359
|
+
...formOptions,
|
|
360
|
+
defaultValues: formOptions.defaultValues ?? initialValues,
|
|
361
|
+
onSubmit: async (values) => {
|
|
362
|
+
await formOptions.onSubmit?.(values);
|
|
363
|
+
await onFinish?.(values);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const internalForm = useForm(externalForm ? void 0 : mergedFormOptions);
|
|
367
|
+
const { core, form, submit } = externalForm ?? internalForm;
|
|
368
|
+
const formRef = (0, import_react8.useRef)(null);
|
|
369
|
+
useFormProviderRegister(formName, form);
|
|
370
|
+
const handleSubmit = async (e) => {
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
await submit();
|
|
373
|
+
if (scrollToFirstError) {
|
|
374
|
+
const result = await form.validate();
|
|
375
|
+
if (!result.valid) {
|
|
376
|
+
const firstErrorField = Object.keys(result.errors)[0];
|
|
377
|
+
if (firstErrorField && formRef.current) {
|
|
378
|
+
const el = formRef.current.querySelector(`[data-field-name="${firstErrorField}"]`) ?? formRef.current.querySelector(`[name="${firstErrorField}"]`);
|
|
379
|
+
if (el) {
|
|
380
|
+
const scrollOpts = typeof scrollToFirstError === "object" ? scrollToFirstError : { behavior: "smooth", block: "center" };
|
|
381
|
+
el.scrollIntoView(scrollOpts);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const classes = ["sg-form", `sg-form-${layout}`, `sg-form-${size}`];
|
|
388
|
+
if (disabled) classes.push("sg-form-disabled");
|
|
389
|
+
if (className) classes.push(className);
|
|
390
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
391
|
+
FormContext.Provider,
|
|
392
|
+
{
|
|
393
|
+
value: {
|
|
394
|
+
core,
|
|
395
|
+
form,
|
|
396
|
+
layout,
|
|
397
|
+
size,
|
|
398
|
+
disabled,
|
|
399
|
+
colon,
|
|
400
|
+
requiredMark,
|
|
401
|
+
labelCol,
|
|
402
|
+
wrapperCol,
|
|
403
|
+
labelAlign,
|
|
404
|
+
preserve,
|
|
405
|
+
feedbackIcons
|
|
406
|
+
},
|
|
407
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
408
|
+
"form",
|
|
409
|
+
{
|
|
410
|
+
ref: formRef,
|
|
411
|
+
name: formName,
|
|
412
|
+
className: classes.join(" "),
|
|
413
|
+
style,
|
|
414
|
+
onSubmit: handleSubmit,
|
|
415
|
+
noValidate: true,
|
|
416
|
+
children
|
|
417
|
+
}
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/components/complex/Field.tsx
|
|
424
|
+
var import_react13 = require("react");
|
|
425
|
+
|
|
426
|
+
// src/components/ui/Spin.tsx
|
|
427
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
428
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
429
|
+
function Spin({
|
|
430
|
+
spinning = true,
|
|
431
|
+
size: sizeProp,
|
|
432
|
+
delay,
|
|
433
|
+
tip,
|
|
434
|
+
fullscreen,
|
|
435
|
+
indicator,
|
|
436
|
+
children,
|
|
437
|
+
className,
|
|
438
|
+
style,
|
|
439
|
+
unstyled
|
|
440
|
+
}) {
|
|
441
|
+
const config = useConfig();
|
|
442
|
+
const resolvedSize = sizeProp ?? config.size ?? "middle";
|
|
443
|
+
const [visible, setVisible] = import_react9.default.useState(delay ? false : spinning);
|
|
444
|
+
import_react9.default.useEffect(() => {
|
|
445
|
+
if (!delay) {
|
|
446
|
+
setVisible(spinning);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (spinning) {
|
|
450
|
+
const timer = setTimeout(() => setVisible(true), delay);
|
|
451
|
+
return () => clearTimeout(timer);
|
|
452
|
+
}
|
|
453
|
+
setVisible(false);
|
|
454
|
+
}, [spinning, delay]);
|
|
455
|
+
if (!visible && !children) return null;
|
|
456
|
+
if (!visible && children) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
|
|
457
|
+
const spinSizeClass = resolvedSize === "middle" ? "default" : resolvedSize;
|
|
458
|
+
const spinClasses = unstyled ? className ?? "" : ["sg-spin", `sg-spin-${spinSizeClass}`, className].filter(Boolean).join(" ");
|
|
459
|
+
const spinElement = indicator ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
460
|
+
"span",
|
|
461
|
+
{
|
|
462
|
+
className: spinClasses,
|
|
463
|
+
style,
|
|
464
|
+
role: "status",
|
|
465
|
+
"aria-live": "polite",
|
|
466
|
+
"aria-label": config.locale?.spin?.loading ?? "Loading"
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
if (fullscreen) {
|
|
470
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: unstyled ? "" : "sg-spin-fullscreen", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: unstyled ? "" : "sg-spin-fullscreen-inner", children: [
|
|
471
|
+
spinElement,
|
|
472
|
+
tip && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: unstyled ? "" : "sg-spin-tip", children: tip })
|
|
473
|
+
] }) });
|
|
474
|
+
}
|
|
475
|
+
if (!children) {
|
|
476
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: unstyled ? "" : "sg-spin-standalone", style, children: [
|
|
477
|
+
spinElement,
|
|
478
|
+
tip && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: unstyled ? "" : "sg-spin-tip", children: tip })
|
|
479
|
+
] });
|
|
480
|
+
}
|
|
481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: unstyled ? "" : "sg-spin-container", style, children: [
|
|
482
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: unstyled ? "" : "sg-spin-overlay", children: [
|
|
483
|
+
spinElement,
|
|
484
|
+
tip && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: unstyled ? "" : "sg-spin-tip", children: tip })
|
|
485
|
+
] }),
|
|
486
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: visible ? unstyled ? "" : "sg-spin-blur" : "", children })
|
|
487
|
+
] });
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/components/ui/Input.tsx
|
|
491
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
492
|
+
function Input({
|
|
493
|
+
value,
|
|
494
|
+
defaultValue,
|
|
495
|
+
placeholder,
|
|
496
|
+
type = "text",
|
|
497
|
+
readOnly = false,
|
|
498
|
+
size: sizeProp,
|
|
499
|
+
disabled: disabledProp,
|
|
500
|
+
loading,
|
|
501
|
+
onChange,
|
|
502
|
+
onBlur,
|
|
503
|
+
onFocus,
|
|
504
|
+
"aria-invalid": ariaInvalid,
|
|
505
|
+
"aria-required": ariaRequired,
|
|
506
|
+
"aria-describedby": ariaDescribedBy,
|
|
507
|
+
id,
|
|
508
|
+
className,
|
|
509
|
+
style,
|
|
510
|
+
unstyled
|
|
511
|
+
}) {
|
|
512
|
+
const config = useConfig();
|
|
513
|
+
const size = sizeProp ?? config.size ?? "middle";
|
|
514
|
+
const disabled = disabledProp ?? config.disabled ?? false;
|
|
515
|
+
const wrapperClasses = unstyled ? className ?? "" : [
|
|
516
|
+
"sg-input-wrapper",
|
|
517
|
+
`sg-input-wrapper-${size}`,
|
|
518
|
+
loading ? "sg-input-wrapper-loading" : "",
|
|
519
|
+
readOnly ? "sg-input-wrapper-readonly" : "",
|
|
520
|
+
className
|
|
521
|
+
].filter(Boolean).join(" ");
|
|
522
|
+
const inputClasses = unstyled ? "" : [
|
|
523
|
+
"sg-input",
|
|
524
|
+
`sg-input-${size}`,
|
|
525
|
+
readOnly ? "sg-input-readonly" : ""
|
|
526
|
+
].filter(Boolean).join(" ");
|
|
527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: wrapperClasses, style, children: [
|
|
528
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
529
|
+
"input",
|
|
530
|
+
{
|
|
531
|
+
id,
|
|
532
|
+
type,
|
|
533
|
+
className: inputClasses,
|
|
534
|
+
value,
|
|
535
|
+
defaultValue,
|
|
536
|
+
placeholder,
|
|
537
|
+
disabled: disabled || loading,
|
|
538
|
+
readOnly,
|
|
539
|
+
"aria-invalid": ariaInvalid,
|
|
540
|
+
"aria-required": ariaRequired,
|
|
541
|
+
"aria-readonly": readOnly || void 0,
|
|
542
|
+
"aria-describedby": ariaDescribedBy,
|
|
543
|
+
onChange: (e) => onChange?.(e.target.value),
|
|
544
|
+
onBlur,
|
|
545
|
+
onFocus
|
|
546
|
+
}
|
|
547
|
+
),
|
|
548
|
+
loading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spin, { size: "small", unstyled })
|
|
549
|
+
] });
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/components/ui/Textarea.tsx
|
|
553
|
+
var import_react10 = __toESM(require("react"), 1);
|
|
554
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
555
|
+
function Textarea({
|
|
556
|
+
value,
|
|
557
|
+
defaultValue,
|
|
558
|
+
placeholder,
|
|
559
|
+
rows = 4,
|
|
560
|
+
maxLength,
|
|
561
|
+
showCount,
|
|
562
|
+
disabled: disabledProp,
|
|
563
|
+
loading,
|
|
564
|
+
size: sizeProp,
|
|
565
|
+
onChange,
|
|
566
|
+
onBlur,
|
|
567
|
+
onFocus,
|
|
568
|
+
id,
|
|
569
|
+
"aria-invalid": ariaInvalid,
|
|
570
|
+
"aria-describedby": ariaDescribedBy,
|
|
571
|
+
"aria-required": ariaRequired,
|
|
572
|
+
className,
|
|
573
|
+
style,
|
|
574
|
+
unstyled
|
|
575
|
+
}) {
|
|
576
|
+
const config = useConfig();
|
|
577
|
+
const disabled = disabledProp ?? config.disabled;
|
|
578
|
+
const size = sizeProp ?? config.size ?? "middle";
|
|
579
|
+
const [internalValue, setInternalValue] = import_react10.default.useState(value ?? defaultValue ?? "");
|
|
580
|
+
const currentValue = value ?? internalValue;
|
|
581
|
+
const handleChange = (e) => {
|
|
582
|
+
const v = e.target.value;
|
|
583
|
+
if (maxLength && v.length > maxLength) return;
|
|
584
|
+
setInternalValue(v);
|
|
585
|
+
onChange?.(v);
|
|
586
|
+
};
|
|
587
|
+
const wrapperClass = unstyled ? className ?? "" : ["sg-textarea-wrapper", `sg-textarea-${size}`, loading ? "sg-textarea-wrapper-loading" : "", className].filter(Boolean).join(" ");
|
|
588
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: wrapperClass, style, children: [
|
|
589
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
590
|
+
"textarea",
|
|
591
|
+
{
|
|
592
|
+
id,
|
|
593
|
+
className: unstyled ? "" : "sg-input sg-textarea",
|
|
594
|
+
value: currentValue,
|
|
595
|
+
placeholder,
|
|
596
|
+
rows,
|
|
597
|
+
disabled: disabled || loading,
|
|
598
|
+
"aria-disabled": disabled || loading,
|
|
599
|
+
"aria-invalid": ariaInvalid,
|
|
600
|
+
"aria-describedby": ariaDescribedBy,
|
|
601
|
+
"aria-required": ariaRequired,
|
|
602
|
+
onChange: handleChange,
|
|
603
|
+
onBlur,
|
|
604
|
+
onFocus
|
|
605
|
+
}
|
|
606
|
+
),
|
|
607
|
+
loading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Spin, { size: "small", unstyled }),
|
|
608
|
+
showCount && !unstyled && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "sg-textarea-count", children: [
|
|
609
|
+
currentValue.length,
|
|
610
|
+
maxLength ? ` / ${maxLength}` : ""
|
|
611
|
+
] })
|
|
612
|
+
] });
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/components/ui/Tooltip.tsx
|
|
616
|
+
var import_react12 = require("react");
|
|
617
|
+
|
|
618
|
+
// src/components/ui/Transition.tsx
|
|
619
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
620
|
+
function Transition({
|
|
621
|
+
visible,
|
|
622
|
+
name = "sg-fade",
|
|
623
|
+
duration = 200,
|
|
624
|
+
enterFrom,
|
|
625
|
+
enterTo,
|
|
626
|
+
leaveFrom,
|
|
627
|
+
leaveTo,
|
|
628
|
+
onAfterEnter,
|
|
629
|
+
onAfterLeave,
|
|
630
|
+
children,
|
|
631
|
+
unmountOnExit = true
|
|
632
|
+
}) {
|
|
633
|
+
const [mounted, setMounted] = (0, import_react11.useState)(visible);
|
|
634
|
+
const [phase, setPhase] = (0, import_react11.useState)(visible ? "idle" : "idle");
|
|
635
|
+
const nodeRef = (0, import_react11.useRef)(null);
|
|
636
|
+
const timerRef = (0, import_react11.useRef)(void 0);
|
|
637
|
+
const prevVisible = (0, import_react11.useRef)(visible);
|
|
638
|
+
const getEnterClasses = (0, import_react11.useCallback)(() => {
|
|
639
|
+
if (enterFrom && enterTo) return { from: enterFrom, active: `${name}-enter-active`, to: enterTo };
|
|
640
|
+
return { from: `${name}-enter-from`, active: `${name}-enter-active`, to: `${name}-enter-to` };
|
|
641
|
+
}, [name, enterFrom, enterTo]);
|
|
642
|
+
const getLeaveClasses = (0, import_react11.useCallback)(() => {
|
|
643
|
+
if (leaveFrom && leaveTo) return { from: leaveFrom, active: `${name}-leave-active`, to: leaveTo };
|
|
644
|
+
return { from: `${name}-leave-from`, active: `${name}-leave-active`, to: `${name}-leave-to` };
|
|
645
|
+
}, [name, leaveFrom, leaveTo]);
|
|
646
|
+
(0, import_react11.useEffect)(() => {
|
|
647
|
+
if (visible === prevVisible.current) return;
|
|
648
|
+
prevVisible.current = visible;
|
|
649
|
+
clearTimeout(timerRef.current);
|
|
650
|
+
if (visible) {
|
|
651
|
+
setMounted(true);
|
|
652
|
+
setPhase("enter");
|
|
653
|
+
requestAnimationFrame(() => {
|
|
654
|
+
requestAnimationFrame(() => setPhase("enter-active"));
|
|
655
|
+
});
|
|
656
|
+
timerRef.current = setTimeout(() => {
|
|
657
|
+
setPhase("idle");
|
|
658
|
+
onAfterEnter?.();
|
|
659
|
+
}, duration);
|
|
660
|
+
} else {
|
|
661
|
+
setPhase("leave");
|
|
662
|
+
requestAnimationFrame(() => {
|
|
663
|
+
requestAnimationFrame(() => setPhase("leave-active"));
|
|
664
|
+
});
|
|
665
|
+
timerRef.current = setTimeout(() => {
|
|
666
|
+
setPhase("idle");
|
|
667
|
+
if (unmountOnExit) setMounted(false);
|
|
668
|
+
onAfterLeave?.();
|
|
669
|
+
}, duration);
|
|
670
|
+
}
|
|
671
|
+
}, [visible, duration, unmountOnExit, onAfterEnter, onAfterLeave]);
|
|
672
|
+
(0, import_react11.useEffect)(() => {
|
|
673
|
+
return () => clearTimeout(timerRef.current);
|
|
674
|
+
}, []);
|
|
675
|
+
if (!mounted && unmountOnExit) return null;
|
|
676
|
+
const enterC = getEnterClasses();
|
|
677
|
+
const leaveC = getLeaveClasses();
|
|
678
|
+
let transitionClass = "";
|
|
679
|
+
switch (phase) {
|
|
680
|
+
case "enter":
|
|
681
|
+
transitionClass = `${enterC.from} ${enterC.active}`;
|
|
682
|
+
break;
|
|
683
|
+
case "enter-active":
|
|
684
|
+
transitionClass = `${enterC.to} ${enterC.active}`;
|
|
685
|
+
break;
|
|
686
|
+
case "leave":
|
|
687
|
+
transitionClass = `${leaveC.from} ${leaveC.active}`;
|
|
688
|
+
break;
|
|
689
|
+
case "leave-active":
|
|
690
|
+
transitionClass = `${leaveC.to} ${leaveC.active}`;
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
return import_react11.default.cloneElement(children, {
|
|
694
|
+
ref: nodeRef,
|
|
695
|
+
className: [children.props.className, transitionClass].filter(Boolean).join(" ")
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// src/components/ui/Tooltip.tsx
|
|
700
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
701
|
+
function Tooltip({
|
|
702
|
+
title,
|
|
703
|
+
placement = "top",
|
|
704
|
+
children,
|
|
705
|
+
className,
|
|
706
|
+
unstyled
|
|
707
|
+
}) {
|
|
708
|
+
const [visible, setVisible] = (0, import_react12.useState)(false);
|
|
709
|
+
const ref = (0, import_react12.useRef)(null);
|
|
710
|
+
const tooltipId = (0, import_react12.useId)();
|
|
711
|
+
const triggerWithAria = (0, import_react12.isValidElement)(children) ? (0, import_react12.cloneElement)(children, {
|
|
712
|
+
"aria-describedby": visible ? [children.props["aria-describedby"], tooltipId].filter(Boolean).join(" ") : children.props["aria-describedby"],
|
|
713
|
+
onFocus: (e) => {
|
|
714
|
+
setVisible(true);
|
|
715
|
+
children.props.onFocus?.(e);
|
|
716
|
+
},
|
|
717
|
+
onBlur: (e) => {
|
|
718
|
+
setVisible(false);
|
|
719
|
+
children.props.onBlur?.(e);
|
|
720
|
+
}
|
|
721
|
+
}) : children;
|
|
722
|
+
if (unstyled) {
|
|
723
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
724
|
+
"div",
|
|
725
|
+
{
|
|
726
|
+
className,
|
|
727
|
+
onMouseEnter: () => setVisible(true),
|
|
728
|
+
onMouseLeave: () => setVisible(false),
|
|
729
|
+
style: { position: "relative", display: "inline-block" },
|
|
730
|
+
children: [
|
|
731
|
+
triggerWithAria,
|
|
732
|
+
visible && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { id: tooltipId, role: "tooltip", children: title })
|
|
733
|
+
]
|
|
734
|
+
}
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
738
|
+
"div",
|
|
739
|
+
{
|
|
740
|
+
className: ["sg-tooltip-wrapper", className].filter(Boolean).join(" "),
|
|
741
|
+
onMouseEnter: () => setVisible(true),
|
|
742
|
+
onMouseLeave: () => setVisible(false),
|
|
743
|
+
ref,
|
|
744
|
+
children: [
|
|
745
|
+
triggerWithAria,
|
|
746
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Transition, { visible, name: "sg-fade", unmountOnExit: true, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { id: tooltipId, role: "tooltip", className: `sg-tooltip sg-tooltip-${placement}`, children: [
|
|
747
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sg-tooltip-content", children: title }),
|
|
748
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sg-tooltip-arrow" })
|
|
749
|
+
] }) })
|
|
750
|
+
]
|
|
751
|
+
}
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// src/components/complex/Field.tsx
|
|
756
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
757
|
+
function FeedbackIcon({
|
|
758
|
+
status,
|
|
759
|
+
icons
|
|
760
|
+
}) {
|
|
761
|
+
if (!status) return null;
|
|
762
|
+
const defaults = {
|
|
763
|
+
validating: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Spin, { size: "small" }),
|
|
764
|
+
error: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-feedback-icon sg-field-feedback-error", children: "\u2715" }),
|
|
765
|
+
warning: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-feedback-icon sg-field-feedback-warning", children: "!" }),
|
|
766
|
+
success: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-feedback-icon sg-field-feedback-success", children: "\u2713" })
|
|
767
|
+
};
|
|
768
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-feedback", children: icons?.[status] ?? defaults[status] });
|
|
769
|
+
}
|
|
770
|
+
function Field({
|
|
771
|
+
name,
|
|
772
|
+
label,
|
|
773
|
+
required,
|
|
774
|
+
rules = [],
|
|
775
|
+
warningRules,
|
|
776
|
+
dependencies,
|
|
777
|
+
hidden,
|
|
778
|
+
disabled: fieldDisabled,
|
|
779
|
+
unstyled,
|
|
780
|
+
placeholder,
|
|
781
|
+
type = "text",
|
|
782
|
+
help,
|
|
783
|
+
extra,
|
|
784
|
+
tooltip,
|
|
785
|
+
children,
|
|
786
|
+
noStyle,
|
|
787
|
+
normalize,
|
|
788
|
+
getValueFromEvent: _getValueFromEvent,
|
|
789
|
+
validateFirst,
|
|
790
|
+
validateStatus: manualStatus,
|
|
791
|
+
hasFeedback,
|
|
792
|
+
preserve,
|
|
793
|
+
labelCol: fieldLabelCol,
|
|
794
|
+
wrapperCol: fieldWrapperCol,
|
|
795
|
+
messageVariables: _messageVariables
|
|
796
|
+
}) {
|
|
797
|
+
const ctx = useFormContext();
|
|
798
|
+
const { core, form } = ctx;
|
|
799
|
+
const disabled = fieldDisabled ?? ctx.disabled;
|
|
800
|
+
const formLocale = useConfig().locale?.form;
|
|
801
|
+
const requiredMarker = formLocale?.required ?? "*";
|
|
802
|
+
const optionalMarker = formLocale?.optional ?? "(optional)";
|
|
803
|
+
const autoId = (0, import_react13.useId)();
|
|
804
|
+
const fieldId = `sg-field-${autoId.replace(/:/g, "")}-${name.replace(/\./g, "-")}`;
|
|
805
|
+
const helpId = `${fieldId}-help`;
|
|
806
|
+
const field = useField(core, form, name);
|
|
807
|
+
const prevValueRef = (0, import_react13.useRef)(field.value);
|
|
808
|
+
(0, import_react13.useEffect)(() => {
|
|
809
|
+
const allRules = [...rules];
|
|
810
|
+
if (required) {
|
|
811
|
+
allRules.unshift({ required: true });
|
|
812
|
+
}
|
|
813
|
+
form.register(name, {
|
|
814
|
+
rules: allRules,
|
|
815
|
+
warningRules,
|
|
816
|
+
dependencies,
|
|
817
|
+
validateFirst,
|
|
818
|
+
label,
|
|
819
|
+
preserve: preserve ?? ctx.preserve
|
|
820
|
+
});
|
|
821
|
+
return () => form.unregister(name);
|
|
822
|
+
}, [name, form, required]);
|
|
823
|
+
if (hidden) return null;
|
|
824
|
+
const wrappedOnChange = normalize ? (v) => {
|
|
825
|
+
const normalized = normalize(v, prevValueRef.current);
|
|
826
|
+
prevValueRef.current = normalized;
|
|
827
|
+
field.onChange(normalized);
|
|
828
|
+
} : field.onChange;
|
|
829
|
+
const effectiveStatus = manualStatus ?? field.status;
|
|
830
|
+
const hasErrors = field.errors.length > 0;
|
|
831
|
+
const hasWarnings = field.warnings.length > 0;
|
|
832
|
+
const layout = ctx.layout ?? "vertical";
|
|
833
|
+
const lCol = fieldLabelCol ?? ctx.labelCol;
|
|
834
|
+
const wCol = fieldWrapperCol ?? ctx.wrapperCol;
|
|
835
|
+
const labelAlign = ctx.labelAlign ?? "right";
|
|
836
|
+
const labelNode = label ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
837
|
+
"label",
|
|
838
|
+
{
|
|
839
|
+
htmlFor: fieldId,
|
|
840
|
+
className: "sg-field-label",
|
|
841
|
+
style: layout === "horizontal" && lCol?.offset ? { marginLeft: `${lCol.offset / 24 * 100}%` } : void 0,
|
|
842
|
+
children: [
|
|
843
|
+
tooltip ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Tooltip, { title: tooltip, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: label }) }) : label,
|
|
844
|
+
(required || ctx.requiredMark === true) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-required", children: requiredMarker }),
|
|
845
|
+
ctx.requiredMark === "optional" && !required && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sg-field-optional", children: optionalMarker }),
|
|
846
|
+
ctx.colon && ":"
|
|
847
|
+
]
|
|
848
|
+
}
|
|
849
|
+
) : null;
|
|
850
|
+
const errorNodes = hasErrors ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { id: helpId, className: "sg-field-error", role: "alert", children: field.errors.map((e, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { children: e }, i)) }) : null;
|
|
851
|
+
const warningNodes = hasWarnings && !hasErrors ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { id: helpId, className: "sg-field-warning", children: field.warnings.map((w, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { children: w }, i)) }) : null;
|
|
852
|
+
const helpNode = errorNodes ?? warningNodes ?? (help ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { id: helpId, className: "sg-field-help", children: help }) : null);
|
|
853
|
+
const describedBy = helpNode ? helpId : void 0;
|
|
854
|
+
const extraNode = extra ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "sg-field-extra", children: extra }) : null;
|
|
855
|
+
const feedbackIcon = hasFeedback && field.touched ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FeedbackIcon, { status: effectiveStatus, icons: ctx.feedbackIcons }) : null;
|
|
856
|
+
const renderControl = () => {
|
|
857
|
+
if (typeof children === "function") {
|
|
858
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
859
|
+
children({ ...field, onChange: wrappedOnChange }),
|
|
860
|
+
feedbackIcon
|
|
861
|
+
] });
|
|
862
|
+
}
|
|
863
|
+
if (children) {
|
|
864
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
865
|
+
children,
|
|
866
|
+
feedbackIcon
|
|
867
|
+
] });
|
|
868
|
+
}
|
|
869
|
+
const inputElement = type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
870
|
+
Textarea,
|
|
871
|
+
{
|
|
872
|
+
id: fieldId,
|
|
873
|
+
value: field.value ?? "",
|
|
874
|
+
onChange: (v) => wrappedOnChange(v),
|
|
875
|
+
onBlur: field.onBlur,
|
|
876
|
+
disabled,
|
|
877
|
+
placeholder,
|
|
878
|
+
unstyled,
|
|
879
|
+
"aria-invalid": hasErrors || void 0,
|
|
880
|
+
"aria-required": required || void 0,
|
|
881
|
+
"aria-describedby": describedBy
|
|
882
|
+
}
|
|
883
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
884
|
+
Input,
|
|
885
|
+
{
|
|
886
|
+
id: fieldId,
|
|
887
|
+
type,
|
|
888
|
+
value: field.value ?? "",
|
|
889
|
+
onChange: (v) => wrappedOnChange(type === "number" ? Number(v) : v),
|
|
890
|
+
onBlur: field.onBlur,
|
|
891
|
+
disabled,
|
|
892
|
+
placeholder,
|
|
893
|
+
unstyled,
|
|
894
|
+
"aria-invalid": hasErrors || void 0,
|
|
895
|
+
"aria-required": required || void 0,
|
|
896
|
+
"aria-describedby": describedBy
|
|
897
|
+
}
|
|
898
|
+
);
|
|
899
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
900
|
+
inputElement,
|
|
901
|
+
feedbackIcon
|
|
902
|
+
] });
|
|
903
|
+
};
|
|
904
|
+
if (noStyle) {
|
|
905
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: renderControl() });
|
|
906
|
+
}
|
|
907
|
+
if (unstyled) {
|
|
908
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
909
|
+
labelNode,
|
|
910
|
+
renderControl(),
|
|
911
|
+
helpNode,
|
|
912
|
+
extraNode
|
|
913
|
+
] });
|
|
914
|
+
}
|
|
915
|
+
if (layout === "horizontal" && lCol) {
|
|
916
|
+
const labelSpan = lCol.span ?? 6;
|
|
917
|
+
const wrapperSpan = wCol?.span ?? 24 - labelSpan;
|
|
918
|
+
const labelPct = `${labelSpan / 24 * 100}%`;
|
|
919
|
+
const wrapperPct = `${wrapperSpan / 24 * 100}%`;
|
|
920
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
921
|
+
"div",
|
|
922
|
+
{
|
|
923
|
+
className: [
|
|
924
|
+
"sg-field",
|
|
925
|
+
"sg-field-horizontal",
|
|
926
|
+
hasErrors ? "sg-field-has-error" : "",
|
|
927
|
+
hasWarnings && !hasErrors ? "sg-field-has-warning" : "",
|
|
928
|
+
effectiveStatus ? `sg-field-status-${effectiveStatus}` : ""
|
|
929
|
+
].filter(Boolean).join(" "),
|
|
930
|
+
"data-field-name": name,
|
|
931
|
+
children: [
|
|
932
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
933
|
+
"div",
|
|
934
|
+
{
|
|
935
|
+
className: "sg-field-label-wrap",
|
|
936
|
+
style: {
|
|
937
|
+
width: labelPct,
|
|
938
|
+
textAlign: labelAlign
|
|
939
|
+
},
|
|
940
|
+
children: labelNode
|
|
941
|
+
}
|
|
942
|
+
),
|
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "sg-field-control-wrap", style: { width: wrapperPct }, children: [
|
|
944
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "sg-field-control", children: renderControl() }),
|
|
945
|
+
helpNode,
|
|
946
|
+
extraNode
|
|
947
|
+
] })
|
|
948
|
+
]
|
|
949
|
+
}
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
const fieldClasses = [
|
|
953
|
+
"sg-field",
|
|
954
|
+
hasErrors ? "sg-field-has-error" : "",
|
|
955
|
+
hasWarnings && !hasErrors ? "sg-field-has-warning" : "",
|
|
956
|
+
effectiveStatus ? `sg-field-status-${effectiveStatus}` : ""
|
|
957
|
+
];
|
|
958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: fieldClasses.filter(Boolean).join(" "), "data-field-name": name, children: [
|
|
959
|
+
labelNode,
|
|
960
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "sg-field-control", children: renderControl() }),
|
|
961
|
+
helpNode,
|
|
962
|
+
extraNode
|
|
963
|
+
] });
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// src/components/ui/Button.tsx
|
|
967
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
968
|
+
function Button({
|
|
969
|
+
type = "default",
|
|
970
|
+
size: sizeProp,
|
|
971
|
+
disabled: disabledProp,
|
|
972
|
+
loading,
|
|
973
|
+
htmlType = "button",
|
|
974
|
+
danger = false,
|
|
975
|
+
block = false,
|
|
976
|
+
onClick,
|
|
977
|
+
children,
|
|
978
|
+
className,
|
|
979
|
+
style,
|
|
980
|
+
unstyled
|
|
981
|
+
}) {
|
|
982
|
+
const config = useConfig();
|
|
983
|
+
const size = sizeProp ?? config.size ?? "middle";
|
|
984
|
+
const disabled = disabledProp ?? config.disabled ?? false;
|
|
985
|
+
const classes = unstyled ? className ?? "" : [
|
|
986
|
+
"sg-button",
|
|
987
|
+
`sg-button-${type}`,
|
|
988
|
+
`sg-button-${size}`,
|
|
989
|
+
danger ? "sg-button-danger" : "",
|
|
990
|
+
block ? "sg-button-block" : "",
|
|
991
|
+
loading ? "sg-button-loading" : "",
|
|
992
|
+
className
|
|
993
|
+
].filter(Boolean).join(" ");
|
|
994
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
995
|
+
"button",
|
|
996
|
+
{
|
|
997
|
+
type: htmlType,
|
|
998
|
+
className: classes,
|
|
999
|
+
style,
|
|
1000
|
+
disabled: disabled || loading,
|
|
1001
|
+
"aria-disabled": disabled || loading,
|
|
1002
|
+
"aria-busy": loading,
|
|
1003
|
+
onClick,
|
|
1004
|
+
children: [
|
|
1005
|
+
loading && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Spin, { size: "small", unstyled }),
|
|
1006
|
+
children
|
|
1007
|
+
]
|
|
1008
|
+
}
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// src/components/complex/SubmitButton.tsx
|
|
1013
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1014
|
+
function SubmitButton({
|
|
1015
|
+
children = "Submit",
|
|
1016
|
+
disabled,
|
|
1017
|
+
loading,
|
|
1018
|
+
className,
|
|
1019
|
+
style,
|
|
1020
|
+
unstyled
|
|
1021
|
+
}) {
|
|
1022
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1023
|
+
Button,
|
|
1024
|
+
{
|
|
1025
|
+
type: "primary",
|
|
1026
|
+
htmlType: "submit",
|
|
1027
|
+
disabled,
|
|
1028
|
+
loading,
|
|
1029
|
+
className,
|
|
1030
|
+
style,
|
|
1031
|
+
unstyled,
|
|
1032
|
+
children
|
|
1033
|
+
}
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// src/components/complex/FormList.tsx
|
|
1038
|
+
var import_react14 = __toESM(require("react"), 1);
|
|
1039
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1040
|
+
var listUid = 0;
|
|
1041
|
+
function genKey() {
|
|
1042
|
+
return `fl_${++listUid}`;
|
|
1043
|
+
}
|
|
1044
|
+
function FormList({ name, initialValue, draggable, children }) {
|
|
1045
|
+
const { core, form } = useFormContext();
|
|
1046
|
+
import_react14.default.useEffect(() => {
|
|
1047
|
+
if (initialValue && !Array.isArray(core.get(name))) {
|
|
1048
|
+
core.set(name, initialValue);
|
|
1049
|
+
}
|
|
1050
|
+
}, []);
|
|
1051
|
+
const listValue = useWatch(core, name);
|
|
1052
|
+
const items = Array.isArray(listValue) ? listValue : [];
|
|
1053
|
+
const [keys, setKeys] = (0, import_react14.useState)(() => items.map(() => genKey()));
|
|
1054
|
+
import_react14.default.useEffect(() => {
|
|
1055
|
+
setKeys((prev) => {
|
|
1056
|
+
if (prev.length === items.length) return prev;
|
|
1057
|
+
if (items.length > prev.length) {
|
|
1058
|
+
return [...prev, ...Array.from({ length: items.length - prev.length }, () => genKey())];
|
|
1059
|
+
}
|
|
1060
|
+
return prev.slice(0, items.length);
|
|
1061
|
+
});
|
|
1062
|
+
}, [items.length]);
|
|
1063
|
+
const fields = (0, import_react14.useMemo)(
|
|
1064
|
+
() => keys.slice(0, items.length).map((key, index) => ({ key, index })),
|
|
1065
|
+
[keys, items.length]
|
|
1066
|
+
);
|
|
1067
|
+
const add = (0, import_react14.useCallback)(
|
|
1068
|
+
(defaultValue, insertIndex) => {
|
|
1069
|
+
form.listAdd(name, defaultValue, insertIndex);
|
|
1070
|
+
setKeys((prev) => {
|
|
1071
|
+
const k = genKey();
|
|
1072
|
+
if (insertIndex !== void 0 && insertIndex >= 0 && insertIndex <= prev.length) {
|
|
1073
|
+
const next = [...prev];
|
|
1074
|
+
next.splice(insertIndex, 0, k);
|
|
1075
|
+
return next;
|
|
1076
|
+
}
|
|
1077
|
+
return [...prev, k];
|
|
1078
|
+
});
|
|
1079
|
+
},
|
|
1080
|
+
[form, name]
|
|
1081
|
+
);
|
|
1082
|
+
const remove = (0, import_react14.useCallback)(
|
|
1083
|
+
(index) => {
|
|
1084
|
+
form.listRemove(name, index);
|
|
1085
|
+
setKeys((prev) => {
|
|
1086
|
+
if (Array.isArray(index)) {
|
|
1087
|
+
const indices = new Set(index);
|
|
1088
|
+
return prev.filter((_, i) => !indices.has(i));
|
|
1089
|
+
}
|
|
1090
|
+
return prev.filter((_, i) => i !== index);
|
|
1091
|
+
});
|
|
1092
|
+
},
|
|
1093
|
+
[form, name]
|
|
1094
|
+
);
|
|
1095
|
+
const move = (0, import_react14.useCallback)(
|
|
1096
|
+
(from, to) => {
|
|
1097
|
+
form.listMove(name, from, to);
|
|
1098
|
+
setKeys((prev) => {
|
|
1099
|
+
const next = [...prev];
|
|
1100
|
+
const [item] = next.splice(from, 1);
|
|
1101
|
+
next.splice(to, 0, item);
|
|
1102
|
+
return next;
|
|
1103
|
+
});
|
|
1104
|
+
},
|
|
1105
|
+
[form, name]
|
|
1106
|
+
);
|
|
1107
|
+
const replace = (0, import_react14.useCallback)(
|
|
1108
|
+
(values) => {
|
|
1109
|
+
form.listReplace(name, values);
|
|
1110
|
+
setKeys(values.map(() => genKey()));
|
|
1111
|
+
},
|
|
1112
|
+
[form, name]
|
|
1113
|
+
);
|
|
1114
|
+
const operation = (0, import_react14.useMemo)(
|
|
1115
|
+
() => ({ add, remove, move, replace }),
|
|
1116
|
+
[add, remove, move, replace]
|
|
1117
|
+
);
|
|
1118
|
+
const meta = (0, import_react14.useMemo)(() => ({ errors: form.getFieldErrors(name) }), [form, name]);
|
|
1119
|
+
const dragIdx = (0, import_react14.useRef)(-1);
|
|
1120
|
+
const dragOverIdx = (0, import_react14.useRef)(-1);
|
|
1121
|
+
if (!draggable) {
|
|
1122
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: children(fields, operation, meta) });
|
|
1123
|
+
}
|
|
1124
|
+
const dragFields = fields.map((f) => ({
|
|
1125
|
+
...f,
|
|
1126
|
+
dragProps: {
|
|
1127
|
+
draggable: true,
|
|
1128
|
+
onDragStart: () => {
|
|
1129
|
+
dragIdx.current = f.index;
|
|
1130
|
+
},
|
|
1131
|
+
onDragOver: (e) => {
|
|
1132
|
+
e.preventDefault();
|
|
1133
|
+
dragOverIdx.current = f.index;
|
|
1134
|
+
},
|
|
1135
|
+
onDrop: () => {
|
|
1136
|
+
if (dragIdx.current !== -1 && dragOverIdx.current !== -1 && dragIdx.current !== dragOverIdx.current) {
|
|
1137
|
+
move(dragIdx.current, dragOverIdx.current);
|
|
1138
|
+
}
|
|
1139
|
+
dragIdx.current = -1;
|
|
1140
|
+
dragOverIdx.current = -1;
|
|
1141
|
+
},
|
|
1142
|
+
onDragEnd: () => {
|
|
1143
|
+
dragIdx.current = -1;
|
|
1144
|
+
dragOverIdx.current = -1;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}));
|
|
1148
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: children(dragFields, operation, meta) });
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/components/complex/AutoField/AutoField.tsx
|
|
1152
|
+
var import_react15 = require("react");
|
|
1153
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1154
|
+
function AutoField(props) {
|
|
1155
|
+
const {
|
|
1156
|
+
name,
|
|
1157
|
+
label,
|
|
1158
|
+
type: forcedType,
|
|
1159
|
+
options,
|
|
1160
|
+
placeholder,
|
|
1161
|
+
disabled: disabledProp,
|
|
1162
|
+
className,
|
|
1163
|
+
style,
|
|
1164
|
+
min,
|
|
1165
|
+
max,
|
|
1166
|
+
step,
|
|
1167
|
+
accept,
|
|
1168
|
+
multiple
|
|
1169
|
+
} = props;
|
|
1170
|
+
const config = useConfig();
|
|
1171
|
+
const disabled = disabledProp ?? config.disabled;
|
|
1172
|
+
const { form } = useFormContext();
|
|
1173
|
+
const value = form.getValue(name);
|
|
1174
|
+
const meta = form.getFieldState(name);
|
|
1175
|
+
const inferredType = (0, import_react15.useMemo)(() => {
|
|
1176
|
+
if (forcedType) return forcedType;
|
|
1177
|
+
if (options && options.length > 0) return "select";
|
|
1178
|
+
if (typeof value === "boolean") return "boolean";
|
|
1179
|
+
if (typeof value === "number") return "number";
|
|
1180
|
+
if (typeof value === "string") {
|
|
1181
|
+
if (value.includes("@")) return "email";
|
|
1182
|
+
if (value.startsWith("http")) return "url";
|
|
1183
|
+
}
|
|
1184
|
+
return "string";
|
|
1185
|
+
}, [forcedType, options, value]);
|
|
1186
|
+
const handleChange = (newValue) => {
|
|
1187
|
+
form.setValue(name, newValue);
|
|
1188
|
+
};
|
|
1189
|
+
const errorId = `${name}-error`;
|
|
1190
|
+
const hasErrors = meta.errors.length > 0;
|
|
1191
|
+
const hasWarnings = meta.warnings.length > 0;
|
|
1192
|
+
const wrapperStyle = {
|
|
1193
|
+
display: "flex",
|
|
1194
|
+
flexDirection: "column",
|
|
1195
|
+
gap: 4,
|
|
1196
|
+
...style
|
|
1197
|
+
};
|
|
1198
|
+
const inputStyle = {
|
|
1199
|
+
padding: "6px 12px",
|
|
1200
|
+
border: `1px solid ${hasErrors ? "var(--sg-error, #ff4d4f)" : hasWarnings ? "var(--sg-warning, #faad14)" : "var(--sg-border, #d9d9d9)"}`,
|
|
1201
|
+
borderRadius: "var(--sg-radius, 6px)",
|
|
1202
|
+
fontSize: 14,
|
|
1203
|
+
outline: "none",
|
|
1204
|
+
background: disabled ? "var(--sg-bg-disabled, #f5f5f5)" : "var(--sg-bg, #fff)"
|
|
1205
|
+
};
|
|
1206
|
+
function renderInput() {
|
|
1207
|
+
switch (inferredType) {
|
|
1208
|
+
case "boolean":
|
|
1209
|
+
case "switch":
|
|
1210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 8, cursor: "pointer" }, children: [
|
|
1211
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1212
|
+
"input",
|
|
1213
|
+
{
|
|
1214
|
+
type: "checkbox",
|
|
1215
|
+
checked: !!value,
|
|
1216
|
+
onChange: (e) => handleChange(e.target.checked),
|
|
1217
|
+
disabled,
|
|
1218
|
+
role: inferredType === "switch" ? "switch" : void 0
|
|
1219
|
+
}
|
|
1220
|
+
),
|
|
1221
|
+
label
|
|
1222
|
+
] });
|
|
1223
|
+
case "number":
|
|
1224
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1225
|
+
"input",
|
|
1226
|
+
{
|
|
1227
|
+
type: "number",
|
|
1228
|
+
value: value == null ? "" : String(value),
|
|
1229
|
+
onChange: (e) => handleChange(e.target.value === "" ? null : Number(e.target.value)),
|
|
1230
|
+
onBlur: () => form.onFieldBlur(name),
|
|
1231
|
+
placeholder,
|
|
1232
|
+
disabled,
|
|
1233
|
+
min,
|
|
1234
|
+
max,
|
|
1235
|
+
step,
|
|
1236
|
+
style: inputStyle,
|
|
1237
|
+
"aria-invalid": hasErrors,
|
|
1238
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1239
|
+
}
|
|
1240
|
+
);
|
|
1241
|
+
case "textarea":
|
|
1242
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1243
|
+
"textarea",
|
|
1244
|
+
{
|
|
1245
|
+
value: value == null ? "" : String(value),
|
|
1246
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1247
|
+
onBlur: () => form.onFieldBlur(name),
|
|
1248
|
+
placeholder,
|
|
1249
|
+
disabled,
|
|
1250
|
+
style: { ...inputStyle, minHeight: 80, resize: "vertical" },
|
|
1251
|
+
"aria-invalid": hasErrors,
|
|
1252
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1255
|
+
case "select":
|
|
1256
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
1257
|
+
"select",
|
|
1258
|
+
{
|
|
1259
|
+
value: value == null ? "" : String(value),
|
|
1260
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1261
|
+
disabled,
|
|
1262
|
+
style: inputStyle,
|
|
1263
|
+
"aria-invalid": hasErrors,
|
|
1264
|
+
"aria-describedby": hasErrors ? errorId : void 0,
|
|
1265
|
+
children: [
|
|
1266
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "", children: placeholder ?? "-- Select --" }),
|
|
1267
|
+
options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
1268
|
+
]
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
case "multiselect":
|
|
1272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1273
|
+
"select",
|
|
1274
|
+
{
|
|
1275
|
+
multiple: true,
|
|
1276
|
+
value: Array.isArray(value) ? value.map(String) : [],
|
|
1277
|
+
onChange: (e) => {
|
|
1278
|
+
const selected = Array.from(e.target.selectedOptions, (o) => o.value);
|
|
1279
|
+
handleChange(selected);
|
|
1280
|
+
},
|
|
1281
|
+
disabled,
|
|
1282
|
+
style: { ...inputStyle, minHeight: 80 },
|
|
1283
|
+
"aria-invalid": hasErrors,
|
|
1284
|
+
"aria-describedby": hasErrors ? errorId : void 0,
|
|
1285
|
+
children: options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
1286
|
+
}
|
|
1287
|
+
);
|
|
1288
|
+
case "radio":
|
|
1289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { role: "radiogroup", style: { display: "flex", gap: 12, flexWrap: "wrap" }, children: options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: 4, cursor: "pointer" }, children: [
|
|
1290
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1291
|
+
"input",
|
|
1292
|
+
{
|
|
1293
|
+
type: "radio",
|
|
1294
|
+
name,
|
|
1295
|
+
value: opt.value,
|
|
1296
|
+
checked: value === opt.value,
|
|
1297
|
+
onChange: () => handleChange(opt.value),
|
|
1298
|
+
disabled
|
|
1299
|
+
}
|
|
1300
|
+
),
|
|
1301
|
+
opt.label
|
|
1302
|
+
] }, opt.value)) });
|
|
1303
|
+
case "date":
|
|
1304
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1305
|
+
"input",
|
|
1306
|
+
{
|
|
1307
|
+
type: "date",
|
|
1308
|
+
value: value == null ? "" : String(value),
|
|
1309
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1310
|
+
disabled,
|
|
1311
|
+
style: inputStyle,
|
|
1312
|
+
"aria-invalid": hasErrors,
|
|
1313
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1314
|
+
}
|
|
1315
|
+
);
|
|
1316
|
+
case "time":
|
|
1317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1318
|
+
"input",
|
|
1319
|
+
{
|
|
1320
|
+
type: "time",
|
|
1321
|
+
value: value == null ? "" : String(value),
|
|
1322
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1323
|
+
disabled,
|
|
1324
|
+
style: inputStyle,
|
|
1325
|
+
"aria-invalid": hasErrors,
|
|
1326
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1327
|
+
}
|
|
1328
|
+
);
|
|
1329
|
+
case "password":
|
|
1330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1331
|
+
"input",
|
|
1332
|
+
{
|
|
1333
|
+
type: "password",
|
|
1334
|
+
value: value == null ? "" : String(value),
|
|
1335
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1336
|
+
onBlur: () => form.onFieldBlur(name),
|
|
1337
|
+
placeholder,
|
|
1338
|
+
disabled,
|
|
1339
|
+
style: inputStyle,
|
|
1340
|
+
"aria-invalid": hasErrors,
|
|
1341
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1342
|
+
}
|
|
1343
|
+
);
|
|
1344
|
+
case "color":
|
|
1345
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1346
|
+
"input",
|
|
1347
|
+
{
|
|
1348
|
+
type: "color",
|
|
1349
|
+
value: value == null ? "#000000" : String(value),
|
|
1350
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1351
|
+
disabled,
|
|
1352
|
+
style: { ...inputStyle, padding: 2, width: 48, height: 32 }
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
case "slider":
|
|
1356
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
1357
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1358
|
+
"input",
|
|
1359
|
+
{
|
|
1360
|
+
type: "range",
|
|
1361
|
+
value: value == null ? min ?? 0 : Number(value),
|
|
1362
|
+
onChange: (e) => handleChange(Number(e.target.value)),
|
|
1363
|
+
min: min ?? 0,
|
|
1364
|
+
max: max ?? 100,
|
|
1365
|
+
step: step ?? 1,
|
|
1366
|
+
disabled,
|
|
1367
|
+
style: { flex: 1 }
|
|
1368
|
+
}
|
|
1369
|
+
),
|
|
1370
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: { minWidth: 32, textAlign: "right", fontSize: 14 }, children: String(value ?? min ?? 0) })
|
|
1371
|
+
] });
|
|
1372
|
+
case "rate": {
|
|
1373
|
+
const maxStars = max ?? 5;
|
|
1374
|
+
const currentRate = typeof value === "number" ? value : 0;
|
|
1375
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: { display: "flex", gap: 2 }, children: Array.from({ length: maxStars }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1376
|
+
"button",
|
|
1377
|
+
{
|
|
1378
|
+
type: "button",
|
|
1379
|
+
onClick: () => !disabled && handleChange(i + 1),
|
|
1380
|
+
disabled,
|
|
1381
|
+
style: {
|
|
1382
|
+
background: "none",
|
|
1383
|
+
border: "none",
|
|
1384
|
+
cursor: disabled ? "default" : "pointer",
|
|
1385
|
+
fontSize: 20,
|
|
1386
|
+
color: i < currentRate ? "var(--sg-warning, #faad14)" : "var(--sg-border, #d9d9d9)",
|
|
1387
|
+
padding: 0
|
|
1388
|
+
},
|
|
1389
|
+
"aria-label": `${i + 1} star${i !== 0 ? "s" : ""}`,
|
|
1390
|
+
children: "\u2605"
|
|
1391
|
+
},
|
|
1392
|
+
i
|
|
1393
|
+
)) });
|
|
1394
|
+
}
|
|
1395
|
+
case "file":
|
|
1396
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1397
|
+
"input",
|
|
1398
|
+
{
|
|
1399
|
+
type: "file",
|
|
1400
|
+
accept,
|
|
1401
|
+
multiple,
|
|
1402
|
+
onChange: (e) => {
|
|
1403
|
+
const files = e.target.files;
|
|
1404
|
+
if (files) handleChange(multiple ? Array.from(files) : files[0] ?? null);
|
|
1405
|
+
},
|
|
1406
|
+
disabled,
|
|
1407
|
+
style: inputStyle
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
case "email":
|
|
1411
|
+
case "url":
|
|
1412
|
+
case "string":
|
|
1413
|
+
default:
|
|
1414
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1415
|
+
"input",
|
|
1416
|
+
{
|
|
1417
|
+
type: inferredType === "email" ? "email" : inferredType === "url" ? "url" : "text",
|
|
1418
|
+
value: value == null ? "" : String(value),
|
|
1419
|
+
onChange: (e) => handleChange(e.target.value),
|
|
1420
|
+
onBlur: () => form.onFieldBlur(name),
|
|
1421
|
+
placeholder,
|
|
1422
|
+
disabled,
|
|
1423
|
+
style: inputStyle,
|
|
1424
|
+
"aria-invalid": hasErrors,
|
|
1425
|
+
"aria-describedby": hasErrors ? errorId : void 0
|
|
1426
|
+
}
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: `sg-autofield ${className ?? ""}`, style: wrapperStyle, children: [
|
|
1431
|
+
inferredType !== "boolean" && inferredType !== "switch" && label && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { style: { fontWeight: 500, fontSize: 14 }, children: label }),
|
|
1432
|
+
renderInput(),
|
|
1433
|
+
hasErrors && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { id: errorId, role: "alert", style: { color: "var(--sg-error, #ff4d4f)", fontSize: 12 }, children: meta.errors.join("; ") }),
|
|
1434
|
+
hasWarnings && !hasErrors && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { style: { color: "var(--sg-warning, #faad14)", fontSize: 12 }, children: meta.warnings.join("; ") })
|
|
1435
|
+
] });
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// src/adapters/jsonSchemaAdapter.ts
|
|
1439
|
+
function jsonTypeToFieldType(schema) {
|
|
1440
|
+
if (schema.enum || schema.oneOf) return "select";
|
|
1441
|
+
if (schema.format === "email") return "email";
|
|
1442
|
+
if (schema.format === "uri" || schema.format === "url") return "url";
|
|
1443
|
+
if (schema.format === "date") return "date";
|
|
1444
|
+
if (schema.format === "time") return "time";
|
|
1445
|
+
if (schema.format === "password") return "password";
|
|
1446
|
+
if (schema.format === "color") return "color";
|
|
1447
|
+
switch (schema.type) {
|
|
1448
|
+
case "number":
|
|
1449
|
+
case "integer":
|
|
1450
|
+
return "number";
|
|
1451
|
+
case "boolean":
|
|
1452
|
+
return "boolean";
|
|
1453
|
+
case "array":
|
|
1454
|
+
return "multiselect";
|
|
1455
|
+
default:
|
|
1456
|
+
if (schema.maxLength && schema.maxLength > 200) return "textarea";
|
|
1457
|
+
return "string";
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
function buildOptions(schema) {
|
|
1461
|
+
if (schema.oneOf) {
|
|
1462
|
+
return schema.oneOf.map((item) => ({
|
|
1463
|
+
value: item.const,
|
|
1464
|
+
label: item.title ?? String(item.const)
|
|
1465
|
+
}));
|
|
1466
|
+
}
|
|
1467
|
+
if (schema.enum) {
|
|
1468
|
+
return schema.enum.map((val, i) => ({
|
|
1469
|
+
value: val,
|
|
1470
|
+
label: schema.enumNames?.[i] ?? String(val)
|
|
1471
|
+
}));
|
|
1472
|
+
}
|
|
1473
|
+
return void 0;
|
|
1474
|
+
}
|
|
1475
|
+
function jsonSchemaToFields(schema) {
|
|
1476
|
+
const result = [];
|
|
1477
|
+
const props = schema.properties ?? {};
|
|
1478
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
1479
|
+
result.push({
|
|
1480
|
+
name,
|
|
1481
|
+
label: prop.title ?? name,
|
|
1482
|
+
type: jsonTypeToFieldType(prop),
|
|
1483
|
+
placeholder: prop.description,
|
|
1484
|
+
options: buildOptions(prop),
|
|
1485
|
+
min: prop.minimum,
|
|
1486
|
+
max: prop.maximum
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
return result;
|
|
1490
|
+
}
|
|
1491
|
+
function jsonSchemaToRules(schema) {
|
|
1492
|
+
const result = {};
|
|
1493
|
+
const props = schema.properties ?? {};
|
|
1494
|
+
const requiredFields = new Set(schema.required ?? []);
|
|
1495
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
1496
|
+
const rules = [];
|
|
1497
|
+
if (requiredFields.has(name)) {
|
|
1498
|
+
rules.push({ required: true, message: `${prop.title ?? name} is required` });
|
|
1499
|
+
}
|
|
1500
|
+
if (prop.type === "string") {
|
|
1501
|
+
if (prop.minLength !== void 0) {
|
|
1502
|
+
rules.push({ min: prop.minLength, message: `Minimum ${prop.minLength} characters` });
|
|
1503
|
+
}
|
|
1504
|
+
if (prop.maxLength !== void 0) {
|
|
1505
|
+
rules.push({ max: prop.maxLength, message: `Maximum ${prop.maxLength} characters` });
|
|
1506
|
+
}
|
|
1507
|
+
if (prop.pattern) {
|
|
1508
|
+
rules.push({ pattern: new RegExp(prop.pattern), message: `Invalid format` });
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
if (prop.type === "number" || prop.type === "integer") {
|
|
1512
|
+
if (prop.minimum !== void 0) {
|
|
1513
|
+
rules.push({ min: prop.minimum, type: "number" });
|
|
1514
|
+
}
|
|
1515
|
+
if (prop.maximum !== void 0) {
|
|
1516
|
+
rules.push({ max: prop.maximum, type: "number" });
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if (prop.format === "email") {
|
|
1520
|
+
rules.push({ type: "email" });
|
|
1521
|
+
}
|
|
1522
|
+
if (prop.format === "uri" || prop.format === "url") {
|
|
1523
|
+
rules.push({ type: "url" });
|
|
1524
|
+
}
|
|
1525
|
+
if (rules.length > 0) {
|
|
1526
|
+
result[name] = rules;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
return result;
|
|
1530
|
+
}
|
|
1531
|
+
function jsonSchemaToDefaults(schema) {
|
|
1532
|
+
const result = {};
|
|
1533
|
+
const props = schema.properties ?? {};
|
|
1534
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
1535
|
+
if (prop.default !== void 0) {
|
|
1536
|
+
result[name] = prop.default;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// src/adapters/zodAdapter.ts
|
|
1543
|
+
function zodRule(schema, options) {
|
|
1544
|
+
const rule = (value) => {
|
|
1545
|
+
const result = schema.safeParse(value);
|
|
1546
|
+
if (result.success) return null;
|
|
1547
|
+
const issues = result.error?.issues ?? [];
|
|
1548
|
+
if (issues.length === 0) return options?.message ?? "Validation failed";
|
|
1549
|
+
if (options?.pick === "all") {
|
|
1550
|
+
return issues.map((i) => i.message).join("; ");
|
|
1551
|
+
}
|
|
1552
|
+
return options?.message ?? issues[0].message;
|
|
1553
|
+
};
|
|
1554
|
+
return rule;
|
|
1555
|
+
}
|
|
1556
|
+
function zodRules(schema, options) {
|
|
1557
|
+
const result = {};
|
|
1558
|
+
for (const [key, fieldSchema] of Object.entries(schema.shape)) {
|
|
1559
|
+
result[key] = [zodRule(fieldSchema, options)];
|
|
1560
|
+
}
|
|
1561
|
+
return result;
|
|
1562
|
+
}
|
|
1563
|
+
function zodDefaults(schema) {
|
|
1564
|
+
const defaults = {};
|
|
1565
|
+
for (const [key, fieldSchema] of Object.entries(schema.shape)) {
|
|
1566
|
+
try {
|
|
1567
|
+
const result = fieldSchema.safeParse(void 0);
|
|
1568
|
+
if (result.success && result.data !== void 0) {
|
|
1569
|
+
defaults[key] = result.data;
|
|
1570
|
+
}
|
|
1571
|
+
} catch {
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
return defaults;
|
|
1575
|
+
}
|
|
1576
|
+
function zodToJsonSchema(schema) {
|
|
1577
|
+
const properties = {};
|
|
1578
|
+
const required = [];
|
|
1579
|
+
const shape = schema.shape ?? schema.shape;
|
|
1580
|
+
if (!shape) return { properties, required };
|
|
1581
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
1582
|
+
const prop = { title: key };
|
|
1583
|
+
let def = field._def;
|
|
1584
|
+
if (def.typeName === "ZodOptional" || def.typeName === "ZodNullable") {
|
|
1585
|
+
def = def.innerType?._def ?? def;
|
|
1586
|
+
} else {
|
|
1587
|
+
required.push(key);
|
|
1588
|
+
}
|
|
1589
|
+
if (def.typeName === "ZodDefault") {
|
|
1590
|
+
prop.default = def.defaultValue?.();
|
|
1591
|
+
def = def.innerType?._def ?? def;
|
|
1592
|
+
}
|
|
1593
|
+
switch (def.typeName) {
|
|
1594
|
+
case "ZodString":
|
|
1595
|
+
prop.type = "string";
|
|
1596
|
+
for (const check of def.checks ?? []) {
|
|
1597
|
+
if (check.kind === "min") prop.minLength = check.value;
|
|
1598
|
+
if (check.kind === "max") prop.maxLength = check.value;
|
|
1599
|
+
if (check.kind === "email") prop.format = "email";
|
|
1600
|
+
if (check.kind === "url") prop.format = "url";
|
|
1601
|
+
if (check.kind === "regex" && check.regex) prop.pattern = check.regex.source;
|
|
1602
|
+
}
|
|
1603
|
+
break;
|
|
1604
|
+
case "ZodNumber":
|
|
1605
|
+
prop.type = "number";
|
|
1606
|
+
for (const check of def.checks ?? []) {
|
|
1607
|
+
if (check.kind === "min") prop.minimum = check.value;
|
|
1608
|
+
if (check.kind === "max") prop.maximum = check.value;
|
|
1609
|
+
}
|
|
1610
|
+
break;
|
|
1611
|
+
case "ZodBoolean":
|
|
1612
|
+
prop.type = "boolean";
|
|
1613
|
+
break;
|
|
1614
|
+
case "ZodEnum":
|
|
1615
|
+
prop.type = "string";
|
|
1616
|
+
prop.enum = def.values ?? [];
|
|
1617
|
+
break;
|
|
1618
|
+
case "ZodDate":
|
|
1619
|
+
prop.type = "string";
|
|
1620
|
+
prop.format = "date";
|
|
1621
|
+
break;
|
|
1622
|
+
default:
|
|
1623
|
+
prop.type = "string";
|
|
1624
|
+
}
|
|
1625
|
+
if (field.description) prop.description = field.description;
|
|
1626
|
+
properties[key] = prop;
|
|
1627
|
+
}
|
|
1628
|
+
return { properties, required };
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// src/components/complex/SchemaForm.tsx
|
|
1632
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1633
|
+
function isZodSchema(schema) {
|
|
1634
|
+
return typeof schema === "object" && schema !== null && "_def" in schema;
|
|
1635
|
+
}
|
|
1636
|
+
function SchemaForm({
|
|
1637
|
+
schema: rawSchema,
|
|
1638
|
+
onSubmit,
|
|
1639
|
+
layout,
|
|
1640
|
+
size,
|
|
1641
|
+
disabled,
|
|
1642
|
+
form: externalForm,
|
|
1643
|
+
labelCol,
|
|
1644
|
+
wrapperCol,
|
|
1645
|
+
className,
|
|
1646
|
+
style,
|
|
1647
|
+
submitText: submitTextProp,
|
|
1648
|
+
children
|
|
1649
|
+
}) {
|
|
1650
|
+
const config = useConfig();
|
|
1651
|
+
const submitText = submitTextProp ?? config.locale?.form?.submitText ?? "Submit";
|
|
1652
|
+
const jsonSchema = isZodSchema(rawSchema) ? zodToJsonSchema(rawSchema) : rawSchema;
|
|
1653
|
+
const fields = jsonSchemaToFields(jsonSchema);
|
|
1654
|
+
const rulesMap = jsonSchemaToRules(jsonSchema);
|
|
1655
|
+
const defaults = jsonSchemaToDefaults(jsonSchema);
|
|
1656
|
+
const internalForm = useForm({
|
|
1657
|
+
defaultValues: defaults,
|
|
1658
|
+
onSubmit
|
|
1659
|
+
});
|
|
1660
|
+
const formInstance = externalForm ?? internalForm;
|
|
1661
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1662
|
+
Form,
|
|
1663
|
+
{
|
|
1664
|
+
form: formInstance,
|
|
1665
|
+
layout,
|
|
1666
|
+
size,
|
|
1667
|
+
disabled,
|
|
1668
|
+
labelCol,
|
|
1669
|
+
wrapperCol,
|
|
1670
|
+
className,
|
|
1671
|
+
style,
|
|
1672
|
+
children: [
|
|
1673
|
+
fields.map((fieldConfig) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1674
|
+
Field,
|
|
1675
|
+
{
|
|
1676
|
+
name: fieldConfig.name,
|
|
1677
|
+
label: typeof fieldConfig.label === "string" ? fieldConfig.label : void 0,
|
|
1678
|
+
rules: rulesMap[fieldConfig.name],
|
|
1679
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1680
|
+
AutoField,
|
|
1681
|
+
{
|
|
1682
|
+
name: fieldConfig.name,
|
|
1683
|
+
type: fieldConfig.type,
|
|
1684
|
+
options: fieldConfig.options,
|
|
1685
|
+
placeholder: fieldConfig.placeholder,
|
|
1686
|
+
min: fieldConfig.min,
|
|
1687
|
+
max: fieldConfig.max,
|
|
1688
|
+
disabled: disabled ?? field.validating
|
|
1689
|
+
}
|
|
1690
|
+
)
|
|
1691
|
+
},
|
|
1692
|
+
fieldConfig.name
|
|
1693
|
+
)),
|
|
1694
|
+
children ?? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "submit", className: "sg-button sg-button-primary", children: submitText })
|
|
1695
|
+
]
|
|
1696
|
+
}
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1700
|
+
0 && (module.exports = {
|
|
1701
|
+
AutoField,
|
|
1702
|
+
Field,
|
|
1703
|
+
Form,
|
|
1704
|
+
FormContext,
|
|
1705
|
+
FormList,
|
|
1706
|
+
FormProvider,
|
|
1707
|
+
SchemaForm,
|
|
1708
|
+
SubmitButton,
|
|
1709
|
+
jsonSchemaToDefaults,
|
|
1710
|
+
jsonSchemaToFields,
|
|
1711
|
+
jsonSchemaToRules,
|
|
1712
|
+
useField,
|
|
1713
|
+
useFieldArray,
|
|
1714
|
+
useForm,
|
|
1715
|
+
useFormContext,
|
|
1716
|
+
useFormProvider,
|
|
1717
|
+
useWatch,
|
|
1718
|
+
zodDefaults,
|
|
1719
|
+
zodRule,
|
|
1720
|
+
zodRules,
|
|
1721
|
+
zodToJsonSchema
|
|
1722
|
+
});
|
|
1723
|
+
//# sourceMappingURL=form.cjs.map
|