@schemx/vue 0.2.3 → 1.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +290 -229
- package/dist/analyze.html +1 -1
- package/dist/components/FormGroup/index.d.ts +3 -4
- package/dist/components/FormGroup/index.d.ts.map +1 -1
- package/dist/components/FormItem/index.d.ts +3 -4
- package/dist/components/FormItem/index.d.ts.map +1 -1
- package/dist/config/appConfig.d.ts +19 -0
- package/dist/config/appConfig.d.ts.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/form.d.ts +11 -8
- package/dist/form.d.ts.map +1 -1
- package/dist/hocs/withRemoteOptions.d.ts +3 -29
- package/dist/hocs/withRemoteOptions.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/provideFieldContext.d.ts +1 -2
- package/dist/hooks/provideFormConfigContext.d.ts +24 -19
- package/dist/hooks/provideFormConfigContext.d.ts.map +1 -1
- package/dist/hooks/provideFormContext.d.ts +0 -1
- package/dist/hooks/useDictionary.d.ts +13 -8
- package/dist/hooks/useDictionary.d.ts.map +1 -1
- package/dist/hooks/useEffect.d.ts +0 -1
- package/dist/hooks/useField.d.ts +1 -2
- package/dist/hooks/useField.d.ts.map +1 -1
- package/dist/hooks/useForm.d.ts +2 -3
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useStableRef.d.ts +2 -3
- package/dist/hooks/useStableRef.d.ts.map +1 -1
- package/dist/hooks/useViewSchemas.d.ts +16 -2
- package/dist/hooks/useViewSchemas.d.ts.map +1 -1
- package/dist/hooks/useWatch.d.ts +64 -13
- package/dist/hooks/useWatch.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +195 -82
- package/dist/index.mjs.map +1 -1
- package/dist/types/dictionary.d.ts +18 -18
- package/dist/types/dictionary.d.ts.map +1 -1
- package/dist/types/field.d.ts +20 -11
- package/dist/types/field.d.ts.map +1 -1
- package/dist/types/form.d.ts +41 -4
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/diff.d.ts +2 -2
- package/dist/utils/diff.d.ts.map +1 -1
- package/dist/utils/dynamic.d.ts +13 -14
- package/dist/utils/dynamic.d.ts.map +1 -1
- package/dist/utils/equal.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +5 -6
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/rendererProvider.d.ts +2 -3
- package/dist/utils/rendererProvider.d.ts.map +1 -1
- package/dist/utils/rulesProvider.d.ts +5 -6
- package/dist/utils/rulesProvider.d.ts.map +1 -1
- package/dist/utils/slot.d.ts.map +1 -1
- package/dist/utils/validation.d.ts +0 -1
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
|
-
import { onScopeDispose, provide,
|
|
2
|
+
import { getCurrentInstance, inject, onScopeDispose, provide, onUnmounted, shallowRef, computed, ref, onMounted, watchEffect, defineComponent, watch, createVNode, h, toRef, createTextVNode, reactive, openBlock, createElementBlock, normalizeStyle, normalizeClass, Fragment, renderList, unref, createBlock, createSlots, withCtx, renderSlot, mergeProps } from "vue";
|
|
3
3
|
import classnames from "classnames";
|
|
4
|
-
import { createRendererRegistry,
|
|
4
|
+
import { createRendererRegistry, createValidationRuleRegistry, mergeSchemxConfig, createForm, createField, createWatch, createEffect, isSchemxSchemas, defaultSchemxConfigKeys } from "@schemx/core";
|
|
5
5
|
export * from "@schemx/core";
|
|
6
|
-
import {
|
|
6
|
+
import { pick } from "es-toolkit";
|
|
7
|
+
const SCHEMX_APP_CONFIG_KEY = Symbol("schemx:app-config");
|
|
8
|
+
const EMPTY_SCHEMX_CONFIG = Object.freeze({
|
|
9
|
+
schemaConfig: Object.freeze({}),
|
|
10
|
+
validatorAdapters: Object.freeze([])
|
|
11
|
+
});
|
|
12
|
+
function normalizeSchemxAppConfig(config) {
|
|
13
|
+
const schemaConfig = Object.freeze({ ...config.schemaConfig ?? {} });
|
|
14
|
+
const validatorAdapters = Object.freeze([...config.validatorAdapters ?? []]);
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
schemaConfig,
|
|
17
|
+
validatorAdapters,
|
|
18
|
+
defaultRendererType: config.defaultRendererType,
|
|
19
|
+
rendererRegistry: config.rendererRegistry,
|
|
20
|
+
validationRuleRegistry: config.validationRuleRegistry
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function provideSchemxAppConfig(app, config = {}) {
|
|
24
|
+
const normalizedConfig = normalizeSchemxAppConfig(config);
|
|
25
|
+
app.provide(SCHEMX_APP_CONFIG_KEY, normalizedConfig);
|
|
26
|
+
}
|
|
27
|
+
function getSchemxAppConfig() {
|
|
28
|
+
if (getCurrentInstance() === null) {
|
|
29
|
+
return EMPTY_SCHEMX_CONFIG;
|
|
30
|
+
}
|
|
31
|
+
return inject(SCHEMX_APP_CONFIG_KEY, EMPTY_SCHEMX_CONFIG);
|
|
32
|
+
}
|
|
7
33
|
const rendererRegistry = createRendererRegistry("input");
|
|
8
|
-
const
|
|
34
|
+
const validationRuleRegistry = createValidationRuleRegistry();
|
|
9
35
|
function useForm(options = {}) {
|
|
36
|
+
const configuredOptions = mergeSchemxConfig(
|
|
37
|
+
getUseFormSchemxConfig(options),
|
|
38
|
+
getSchemxAppConfig(),
|
|
39
|
+
{
|
|
40
|
+
rendererRegistry,
|
|
41
|
+
validationRuleRegistry
|
|
42
|
+
}
|
|
43
|
+
);
|
|
10
44
|
const mergedOptions = {
|
|
11
45
|
...options,
|
|
12
|
-
|
|
13
|
-
validatorRegistry: options.validatorRegistry ?? validatorRegistry
|
|
46
|
+
...configuredOptions
|
|
14
47
|
};
|
|
15
48
|
const instance = createForm(mergedOptions);
|
|
16
49
|
onScopeDispose(() => {
|
|
@@ -18,6 +51,23 @@ function useForm(options = {}) {
|
|
|
18
51
|
});
|
|
19
52
|
return instance;
|
|
20
53
|
}
|
|
54
|
+
function getUseFormSchemxConfig(options) {
|
|
55
|
+
const {
|
|
56
|
+
schemaConfig = {},
|
|
57
|
+
validatorAdapters = [],
|
|
58
|
+
defaultRendererType = void 0,
|
|
59
|
+
rendererRegistry: rendererRegistry2 = void 0,
|
|
60
|
+
validationRuleRegistry: validationRuleRegistry2 = void 0,
|
|
61
|
+
...rest
|
|
62
|
+
} = options;
|
|
63
|
+
return {
|
|
64
|
+
schemaConfig,
|
|
65
|
+
defaultRendererType,
|
|
66
|
+
rendererRegistry: rendererRegistry2,
|
|
67
|
+
validationRuleRegistry: validationRuleRegistry2,
|
|
68
|
+
validatorAdapters
|
|
69
|
+
};
|
|
70
|
+
}
|
|
21
71
|
const SCHEMX_FORM_INSTANCE_KEY = Symbol("schemx:instance");
|
|
22
72
|
function createFormContext(instance) {
|
|
23
73
|
provide(SCHEMX_FORM_INSTANCE_KEY, instance);
|
|
@@ -35,14 +85,14 @@ const fieldHookCache = /* @__PURE__ */ new WeakMap();
|
|
|
35
85
|
function createFieldHook(form, name) {
|
|
36
86
|
const field = createField(form, name);
|
|
37
87
|
const fieldValue = shallowRef(field.getValue());
|
|
38
|
-
const
|
|
88
|
+
const fieldErrors = shallowRef(field.getErrors());
|
|
39
89
|
const fieldPending = shallowRef(field.isPending());
|
|
40
90
|
const dispose = field.effect(() => {
|
|
41
91
|
fieldValue.value = field.getValue();
|
|
42
|
-
|
|
92
|
+
fieldErrors.value = field.getErrors();
|
|
43
93
|
fieldPending.value = field.isPending();
|
|
44
94
|
});
|
|
45
|
-
const
|
|
95
|
+
const errors = computed(() => fieldErrors.value);
|
|
46
96
|
const dirty = computed(() => {
|
|
47
97
|
void fieldValue.value;
|
|
48
98
|
return field.isTouched();
|
|
@@ -51,7 +101,7 @@ function createFieldHook(form, name) {
|
|
|
51
101
|
const result = {
|
|
52
102
|
name,
|
|
53
103
|
value: fieldValue,
|
|
54
|
-
|
|
104
|
+
errors,
|
|
55
105
|
dirty,
|
|
56
106
|
pending,
|
|
57
107
|
...field,
|
|
@@ -136,7 +186,7 @@ function normalizeError(err) {
|
|
|
136
186
|
const useDictionary = (options, fieldName) => {
|
|
137
187
|
var _a;
|
|
138
188
|
const instance = useFormContext();
|
|
139
|
-
const list =
|
|
189
|
+
const list = shallowRef([]);
|
|
140
190
|
const loading = ref(false);
|
|
141
191
|
const error = ref(void 0);
|
|
142
192
|
let requestCount = 0;
|
|
@@ -144,6 +194,11 @@ const useDictionary = (options, fieldName) => {
|
|
|
144
194
|
if (typeof (options == null ? void 0 : options.formatter) === "function") {
|
|
145
195
|
return await options.formatter(res, instance);
|
|
146
196
|
}
|
|
197
|
+
if (!Array.isArray(res)) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
"[schemx] Dictionary api must return an array when formatter is not provided."
|
|
200
|
+
);
|
|
201
|
+
}
|
|
147
202
|
return res;
|
|
148
203
|
};
|
|
149
204
|
const executeWithRetry = async (formValues) => {
|
|
@@ -216,18 +271,9 @@ const useDictionary = (options, fieldName) => {
|
|
|
216
271
|
});
|
|
217
272
|
return { list, loading, error, loadDict, refresh, mutate };
|
|
218
273
|
};
|
|
219
|
-
const SCHEMX_FORM_CONFIG_KEY = Symbol(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
"modelValue",
|
|
223
|
-
"rendererRegistry",
|
|
224
|
-
"validatorRegistry",
|
|
225
|
-
"defaultRendererType",
|
|
226
|
-
"onFinish",
|
|
227
|
-
"onFinishFailed",
|
|
228
|
-
"onValuesChange",
|
|
229
|
-
"onFieldsChange"
|
|
230
|
-
];
|
|
274
|
+
const SCHEMX_FORM_CONFIG_KEY = Symbol(
|
|
275
|
+
"schemx:form-config"
|
|
276
|
+
);
|
|
231
277
|
const createFormConfigContext = (props) => {
|
|
232
278
|
provide(SCHEMX_FORM_CONFIG_KEY, props);
|
|
233
279
|
};
|
|
@@ -257,7 +303,9 @@ function useStableRef(factory) {
|
|
|
257
303
|
return stableRef;
|
|
258
304
|
}
|
|
259
305
|
function useViewSchemas(form) {
|
|
260
|
-
const viewSchemas = shallowRef(
|
|
306
|
+
const viewSchemas = shallowRef(
|
|
307
|
+
form.getViewSchemas()
|
|
308
|
+
);
|
|
261
309
|
const unsubscribe = form.subscribeViewSchemas((nextSchemas) => {
|
|
262
310
|
viewSchemas.value = nextSchemas;
|
|
263
311
|
});
|
|
@@ -328,30 +376,76 @@ const extractChildSlots = (fieldName, allSlots) => {
|
|
|
328
376
|
const FormGroup = /* @__PURE__ */ defineComponent((props, {
|
|
329
377
|
slots
|
|
330
378
|
}) => {
|
|
331
|
-
|
|
379
|
+
var _a;
|
|
380
|
+
const internalCollapsed = ref(Boolean(props.schema.defaultCollapsed));
|
|
381
|
+
const collapsed = computed(() => props.schema.collapsed ?? internalCollapsed.value);
|
|
382
|
+
const componentId = ((_a = getCurrentInstance()) == null ? void 0 : _a.uid) ?? 0;
|
|
383
|
+
watch(() => props.schema.collapsed, (nextCollapsed, previousCollapsed) => {
|
|
384
|
+
if (nextCollapsed !== void 0) {
|
|
385
|
+
internalCollapsed.value = nextCollapsed;
|
|
386
|
+
} else if (previousCollapsed !== void 0) {
|
|
387
|
+
internalCollapsed.value = previousCollapsed;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
332
390
|
const toggle = () => {
|
|
333
|
-
|
|
334
|
-
|
|
391
|
+
var _a2, _b;
|
|
392
|
+
if (!props.schema.collapsible || props.schema.disabled) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const nextCollapsed = !collapsed.value;
|
|
396
|
+
if (props.schema.collapsed === void 0) {
|
|
397
|
+
internalCollapsed.value = nextCollapsed;
|
|
335
398
|
}
|
|
399
|
+
(_b = (_a2 = props.schema).onCollapsedChange) == null ? void 0 : _b.call(_a2, nextCollapsed);
|
|
336
400
|
};
|
|
337
401
|
return () => {
|
|
402
|
+
var _a2;
|
|
338
403
|
const schema = props.schema;
|
|
404
|
+
if (schema.visible === false) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
339
407
|
const collapsible = Boolean(schema.collapsible);
|
|
408
|
+
const isCollapsed = collapsed.value;
|
|
409
|
+
const destroyOnCollapse = schema.destroyOnCollapse ?? true;
|
|
410
|
+
const uniqueId = ((_a2 = schema.debug) == null ? void 0 : _a2.runtimeNodeId) ?? `local-${componentId}`;
|
|
411
|
+
const idBase = `schemx-group-${uniqueId}-${normalizeId(schema.key)}`;
|
|
412
|
+
const headerId = `${idBase}-header`;
|
|
413
|
+
const bodyId = `${idBase}-body`;
|
|
414
|
+
const body = createVNode("div", {
|
|
415
|
+
"id": bodyId,
|
|
416
|
+
"role": "group",
|
|
417
|
+
"aria-labelledby": schema.label ? headerId : void 0,
|
|
418
|
+
"aria-hidden": isCollapsed || void 0,
|
|
419
|
+
"class": "schemx-group__body",
|
|
420
|
+
"style": !destroyOnCollapse && isCollapsed ? {
|
|
421
|
+
display: "none"
|
|
422
|
+
} : void 0
|
|
423
|
+
}, [schema.children.map((child) => createVNode(FormItem, {
|
|
424
|
+
"key": child.key,
|
|
425
|
+
"schema": child
|
|
426
|
+
}, slots))]);
|
|
340
427
|
return createVNode("div", {
|
|
341
428
|
"class": classnames("schemx-group", {
|
|
342
|
-
"schemx-group--collapsed":
|
|
429
|
+
"schemx-group--collapsed": isCollapsed,
|
|
430
|
+
"is-readonly": schema.readonly,
|
|
431
|
+
"is-disabled": schema.disabled
|
|
343
432
|
}, schema.class),
|
|
344
433
|
"style": schema.style,
|
|
345
|
-
"data-key": schema.key
|
|
434
|
+
"data-key": schema.key,
|
|
435
|
+
"aria-disabled": schema.disabled || void 0
|
|
346
436
|
}, [schema.label && createVNode("div", {
|
|
437
|
+
"id": headerId,
|
|
347
438
|
"role": collapsible ? "button" : void 0,
|
|
348
|
-
"tabindex": collapsible ? 0 : void 0,
|
|
439
|
+
"tabindex": collapsible ? schema.disabled ? -1 : 0 : void 0,
|
|
440
|
+
"aria-expanded": collapsible ? !isCollapsed : void 0,
|
|
441
|
+
"aria-controls": collapsible ? bodyId : void 0,
|
|
442
|
+
"aria-disabled": collapsible ? schema.disabled || void 0 : void 0,
|
|
349
443
|
"class": classnames("schemx-group__header", {
|
|
350
|
-
"schemx-group__header--clickable": collapsible
|
|
444
|
+
"schemx-group__header--clickable": collapsible && !schema.disabled
|
|
351
445
|
}),
|
|
352
446
|
"onClick": toggle,
|
|
353
447
|
"onKeydown": (e) => {
|
|
354
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
448
|
+
if (!schema.disabled && (e.key === "Enter" || e.key === " ")) {
|
|
355
449
|
e.preventDefault();
|
|
356
450
|
toggle();
|
|
357
451
|
}
|
|
@@ -360,14 +454,9 @@ const FormGroup = /* @__PURE__ */ defineComponent((props, {
|
|
|
360
454
|
"class": "schemx-group__title"
|
|
361
455
|
}, [schema.label]), collapsible && createVNode("span", {
|
|
362
456
|
"class": classnames("schemx-group__arrow", {
|
|
363
|
-
"schemx-group__arrow--down": !
|
|
457
|
+
"schemx-group__arrow--down": !isCollapsed
|
|
364
458
|
})
|
|
365
|
-
}, null)]), !
|
|
366
|
-
"class": "schemx-group__body"
|
|
367
|
-
}, [schema.children.map((child) => createVNode(FormItem, {
|
|
368
|
-
"key": child.key,
|
|
369
|
-
"schema": child
|
|
370
|
-
}, slots))])]);
|
|
459
|
+
}, null)]), destroyOnCollapse ? !isCollapsed && body : body]);
|
|
371
460
|
};
|
|
372
461
|
}, {
|
|
373
462
|
name: "SchemxGroup",
|
|
@@ -378,6 +467,9 @@ const FormGroup = /* @__PURE__ */ defineComponent((props, {
|
|
|
378
467
|
}
|
|
379
468
|
}
|
|
380
469
|
});
|
|
470
|
+
const normalizeId = (key) => {
|
|
471
|
+
return String(key).replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
472
|
+
};
|
|
381
473
|
const FormItem = /* @__PURE__ */ defineComponent({
|
|
382
474
|
name: "SchemxItem",
|
|
383
475
|
props: {
|
|
@@ -391,7 +483,7 @@ const FormItem = /* @__PURE__ */ defineComponent({
|
|
|
391
483
|
}) {
|
|
392
484
|
return () => {
|
|
393
485
|
const schema = props.schema;
|
|
394
|
-
if (isViewGroupSchema(schema)) {
|
|
486
|
+
if (isViewGroupSchema$1(schema)) {
|
|
395
487
|
return h(FormGroup, {
|
|
396
488
|
schema
|
|
397
489
|
}, slots);
|
|
@@ -419,12 +511,12 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
419
511
|
const schema = () => schemaRef.value;
|
|
420
512
|
const field = useField(schema().name);
|
|
421
513
|
createFieldContext(field);
|
|
422
|
-
const trigger = computed(() => mergeTrigger(schema().validationTrigger, formContext.validationTrigger, "onChange"));
|
|
514
|
+
const trigger = computed(() => mergeTrigger(schema().validationTrigger, formContext.schemaConfig.validationTrigger, "onChange"));
|
|
423
515
|
const canVerified = computed(() => {
|
|
424
516
|
const isOperate = schema().visible && !schema().readonly && !schema().disabled;
|
|
425
517
|
const rules = schema().rules;
|
|
426
518
|
const hasRules = Array.isArray(rules) ? (rules == null ? void 0 : rules.length) > 0 : !!schema().rules;
|
|
427
|
-
return isOperate && hasRules;
|
|
519
|
+
return isOperate && (Boolean(schema().required) || hasRules);
|
|
428
520
|
});
|
|
429
521
|
const handleChange = (v) => {
|
|
430
522
|
var _a, _b;
|
|
@@ -456,7 +548,8 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
456
548
|
};
|
|
457
549
|
});
|
|
458
550
|
const renderRequired = () => {
|
|
459
|
-
|
|
551
|
+
const showRequiredMark = schema().showRequiredMark ?? Boolean(schema().required);
|
|
552
|
+
if (!showRequiredMark || schema().disabled || schema().readonly) {
|
|
460
553
|
return null;
|
|
461
554
|
}
|
|
462
555
|
return createVNode("span", {
|
|
@@ -468,9 +561,9 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
468
561
|
if (labelSlot) {
|
|
469
562
|
return labelSlot(schema());
|
|
470
563
|
}
|
|
471
|
-
const labelAlign = schema().labelAlign || formContext.labelAlign;
|
|
472
|
-
const labelWidth = schema().labelWidth || formContext.labelWidth;
|
|
473
|
-
const colon = schema().colon ?? formContext.colon;
|
|
564
|
+
const labelAlign = schema().labelAlign || formContext.schemaConfig.labelAlign;
|
|
565
|
+
const labelWidth = schema().labelWidth || formContext.schemaConfig.labelWidth;
|
|
566
|
+
const colon = schema().colon ?? formContext.schemaConfig.colon;
|
|
474
567
|
return createVNode("label", {
|
|
475
568
|
"class": "schemx-item__label",
|
|
476
569
|
"style": {
|
|
@@ -504,15 +597,15 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
504
597
|
if (errorSlot) {
|
|
505
598
|
return errorSlot({
|
|
506
599
|
...schema(),
|
|
507
|
-
errors: field.
|
|
600
|
+
errors: field.errors.value
|
|
508
601
|
});
|
|
509
602
|
}
|
|
510
|
-
if (
|
|
603
|
+
if (field.errors.value.length === 0) {
|
|
511
604
|
return null;
|
|
512
605
|
}
|
|
513
606
|
return createVNode("div", {
|
|
514
607
|
"class": "schemx-item__error"
|
|
515
|
-
}, [field.
|
|
608
|
+
}, [field.errors.value[0]]);
|
|
516
609
|
};
|
|
517
610
|
return () => {
|
|
518
611
|
if (!schema().visible) {
|
|
@@ -522,7 +615,7 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
522
615
|
if (itemSlot) {
|
|
523
616
|
return itemSlot(schema());
|
|
524
617
|
}
|
|
525
|
-
const labelPosition = schema().labelPosition || formContext.labelPosition;
|
|
618
|
+
const labelPosition = schema().labelPosition || formContext.schemaConfig.labelPosition;
|
|
526
619
|
return createVNode("div", {
|
|
527
620
|
"class": classnames("schemx-item-wrapper"),
|
|
528
621
|
"style": schema().style
|
|
@@ -540,8 +633,8 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
540
633
|
};
|
|
541
634
|
}
|
|
542
635
|
});
|
|
543
|
-
const isViewGroupSchema = (schema) => {
|
|
544
|
-
return
|
|
636
|
+
const isViewGroupSchema$1 = (schema) => {
|
|
637
|
+
return "children" in schema;
|
|
545
638
|
};
|
|
546
639
|
const normalizeNameKey = (name) => {
|
|
547
640
|
if (Array.isArray(name)) {
|
|
@@ -566,32 +659,54 @@ function getSectionPosition(list, currentKey) {
|
|
|
566
659
|
isLast: false
|
|
567
660
|
};
|
|
568
661
|
}
|
|
569
|
-
const prevItem = findPositionItem(list, currentIndex, -1);
|
|
570
|
-
const nextItem = findPositionItem(list, currentIndex, 1);
|
|
571
662
|
return {
|
|
572
663
|
found: true,
|
|
573
|
-
isFirst: !
|
|
574
|
-
isLast: !
|
|
664
|
+
isFirst: !hasPositionItemInSection(list, currentIndex, -1),
|
|
665
|
+
isLast: !hasPositionItemInSection(list, currentIndex, 1)
|
|
575
666
|
};
|
|
576
667
|
}
|
|
668
|
+
function isViewGroupSchema(item) {
|
|
669
|
+
return !!item && "children" in item;
|
|
670
|
+
}
|
|
577
671
|
function isPositionItem(item) {
|
|
578
|
-
return !!item &&
|
|
672
|
+
return !!item && !isViewGroupSchema(item) && item.visible !== false;
|
|
579
673
|
}
|
|
580
|
-
function
|
|
674
|
+
function hasPositionItemInSection(list, startIndex, step) {
|
|
581
675
|
for (let index = startIndex + step; index >= 0 && index < list.length; index += step) {
|
|
582
|
-
|
|
583
|
-
|
|
676
|
+
const item = list[index];
|
|
677
|
+
if (item.visible === false) {
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (isViewGroupSchema(item)) {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
if (isPositionItem(item)) {
|
|
684
|
+
return true;
|
|
584
685
|
}
|
|
585
686
|
}
|
|
586
|
-
return
|
|
687
|
+
return false;
|
|
587
688
|
}
|
|
588
689
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
589
690
|
...{ name: "SchemxForm" },
|
|
590
691
|
__name: "form",
|
|
591
692
|
props: {
|
|
693
|
+
schemas: { default: () => [] },
|
|
694
|
+
initialValues: { default: () => ({}) },
|
|
695
|
+
modelValue: { default: () => ({}) },
|
|
696
|
+
form: { default: void 0 },
|
|
592
697
|
class: { default: "" },
|
|
593
698
|
style: { type: [Boolean, null, String, Object, Array], default: () => ({}) },
|
|
594
|
-
|
|
699
|
+
validatorAdapters: {},
|
|
700
|
+
defaultRendererType: {},
|
|
701
|
+
rendererRegistry: { default: void 0 },
|
|
702
|
+
validationRuleRegistry: { default: void 0 },
|
|
703
|
+
onRuleError: {},
|
|
704
|
+
onFinish: { type: Function, default: void 0 },
|
|
705
|
+
onFinishFailed: { type: Function, default: void 0 },
|
|
706
|
+
onValuesChange: { type: Function, default: void 0 },
|
|
707
|
+
onFieldsChange: { type: Function, default: void 0 },
|
|
708
|
+
lifecycleHooks: {},
|
|
709
|
+
required: { type: [Boolean, Object] },
|
|
595
710
|
readonly: { type: Boolean },
|
|
596
711
|
disabled: { type: Boolean },
|
|
597
712
|
visible: { type: Boolean, default: true },
|
|
@@ -602,31 +717,25 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
602
717
|
contentAlign: {},
|
|
603
718
|
validationTrigger: {},
|
|
604
719
|
colon: { type: Boolean },
|
|
605
|
-
|
|
606
|
-
initialValues: { default: () => ({}) },
|
|
607
|
-
schemas: { default: () => [] },
|
|
608
|
-
form: { default: void 0 },
|
|
609
|
-
rendererRegistry: { default: void 0 },
|
|
610
|
-
defaultRendererType: {},
|
|
611
|
-
validatorRegistry: { default: void 0 },
|
|
612
|
-
onFinish: { type: Function, default: void 0 },
|
|
613
|
-
onFinishFailed: { type: Function, default: void 0 },
|
|
614
|
-
onValuesChange: { type: Function, default: void 0 },
|
|
615
|
-
onFieldsChange: { type: Function, default: void 0 }
|
|
720
|
+
showRequiredMark: { type: Boolean }
|
|
616
721
|
},
|
|
617
722
|
emits: ["update:modelValue"],
|
|
618
723
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
619
724
|
const props = __props;
|
|
620
725
|
const emit = __emit;
|
|
621
|
-
|
|
726
|
+
const pickSchemaConfig = () => {
|
|
727
|
+
return pick(props, defaultSchemxConfigKeys);
|
|
728
|
+
};
|
|
729
|
+
const formSchemaConfig = reactive(pickSchemaConfig());
|
|
730
|
+
createFormConfigContext({ schemaConfig: formSchemaConfig });
|
|
622
731
|
const form = props.form ? props.form : useForm({
|
|
623
732
|
schemas: props.schemas,
|
|
733
|
+
schemaConfig: pickSchemaConfig(),
|
|
624
734
|
initialValues: Object.keys(props.modelValue).length > 0 ? props.modelValue : props.initialValues,
|
|
625
735
|
rendererRegistry: props.rendererRegistry,
|
|
626
736
|
defaultRendererType: props.defaultRendererType,
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
disabled: props.disabled,
|
|
737
|
+
validationRuleRegistry: props.validationRuleRegistry,
|
|
738
|
+
validatorAdapters: props.validatorAdapters,
|
|
630
739
|
onFinish: async (values) => {
|
|
631
740
|
var _a;
|
|
632
741
|
(_a = props.onFinish) == null ? void 0 : _a.call(props, values);
|
|
@@ -662,7 +771,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
662
771
|
watch(
|
|
663
772
|
() => props.schemas,
|
|
664
773
|
(schemas) => {
|
|
665
|
-
|
|
774
|
+
if (!isSchemxSchemas(schemas)) {
|
|
775
|
+
form.setSchemas(schemas);
|
|
776
|
+
}
|
|
666
777
|
},
|
|
667
778
|
{ deep: false, immediate: !!props.form }
|
|
668
779
|
);
|
|
@@ -678,7 +789,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
678
789
|
};
|
|
679
790
|
};
|
|
680
791
|
watchEffect(() => {
|
|
681
|
-
|
|
792
|
+
const nextSchemaConfig = pickSchemaConfig();
|
|
793
|
+
Object.assign(formSchemaConfig, nextSchemaConfig);
|
|
794
|
+
form.updateSchemaConfig(nextSchemaConfig);
|
|
682
795
|
});
|
|
683
796
|
__expose({
|
|
684
797
|
...form
|
|
@@ -713,7 +826,8 @@ function withInstall(comp, extra) {
|
|
|
713
826
|
}
|
|
714
827
|
const SchemxFormExport = withInstall(_sfc_main, {
|
|
715
828
|
/** Vue 插件安装方法 */
|
|
716
|
-
install(app,
|
|
829
|
+
install(app, options = {}) {
|
|
830
|
+
provideSchemxAppConfig(app, options);
|
|
717
831
|
app.component("SchemxForm", _sfc_main);
|
|
718
832
|
},
|
|
719
833
|
/** FormItem 子组件引用 */
|
|
@@ -756,7 +870,6 @@ export {
|
|
|
756
870
|
createFormConfigContext,
|
|
757
871
|
createFormContext,
|
|
758
872
|
SchemxFormExport as default,
|
|
759
|
-
formConfigContextOmitKey,
|
|
760
873
|
rendererRegistry,
|
|
761
874
|
SchemxFormExport as schemxForm,
|
|
762
875
|
useDictionary,
|
|
@@ -772,6 +885,6 @@ export {
|
|
|
772
885
|
useWatchAll,
|
|
773
886
|
useWatchField,
|
|
774
887
|
useWatchFields,
|
|
775
|
-
|
|
888
|
+
validationRuleRegistry
|
|
776
889
|
};
|
|
777
890
|
//# sourceMappingURL=index.mjs.map
|