@schemx/vue 1.0.0-next.0 → 1.0.0-next.1
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 +135 -122
- package/dist/analyze.html +1 -1
- package/dist/components/FormItem/index.d.ts +4 -5
- package/dist/components/FormItem/index.d.ts.map +1 -1
- package/dist/components/FormItem/slot.d.ts +48 -0
- package/dist/components/FormItem/slot.d.ts.map +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/hocs/withRemoteOptions.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/provideFormConfigContext.d.ts +3 -4
- package/dist/hooks/provideFormConfigContext.d.ts.map +1 -1
- package/dist/hooks/provideFormContext.d.ts +4 -2
- package/dist/hooks/provideFormContext.d.ts.map +1 -1
- package/dist/hooks/useField.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +237 -151
- package/dist/index.mjs.map +1 -1
- package/dist/types/dictionary.d.ts +6 -3
- package/dist/types/dictionary.d.ts.map +1 -1
- package/dist/types/form.d.ts +1 -1
- package/dist/types/form.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/rendererProvider.d.ts +2 -1
- package/dist/utils/rendererProvider.d.ts.map +1 -1
- package/package.json +8 -6
- package/dist/hooks/useEffect.d.ts +0 -33
- package/dist/hooks/useEffect.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
|
-
import { getCurrentInstance, inject, onScopeDispose, provide, onUnmounted, shallowRef, computed, ref, onMounted, watchEffect, defineComponent, watch, createVNode, h,
|
|
3
|
-
import
|
|
4
|
-
import { createRendererRegistry, createValidationRuleRegistry, mergeSchemxConfig, createForm, createField, createWatch, createEffect, isSchemxSchemas, defaultSchemxConfigKeys } from "@schemx/core";
|
|
2
|
+
import { getCurrentInstance, inject, onScopeDispose, provide, onUnmounted, shallowRef, computed, ref, onMounted, watchEffect, defineComponent, watch, createVNode, h, createTextVNode, mergeProps, reactive, openBlock, createElementBlock, normalizeClass, normalizeStyle, Fragment, renderList, unref, createBlock, createSlots, withCtx, renderSlot } from "vue";
|
|
3
|
+
import { createValidationRuleRegistry, mergeSchemxConfig, createForm, createField, createWatch, isViewGroupSchema, isSchemxViewFieldSchema, isSchemxSchemas, defaultSchemxConfigKeys } from "@schemx/core";
|
|
5
4
|
export * from "@schemx/core";
|
|
5
|
+
import classnames from "classnames";
|
|
6
6
|
import { pick } from "es-toolkit";
|
|
7
|
+
import { createRendererRegistry } from "@schemx/core/adapter";
|
|
7
8
|
const SCHEMX_APP_CONFIG_KEY = Symbol("schemx:app-config");
|
|
8
9
|
const EMPTY_SCHEMX_CONFIG = Object.freeze({
|
|
9
10
|
schemaConfig: Object.freeze({}),
|
|
@@ -57,8 +58,7 @@ function getUseFormSchemxConfig(options) {
|
|
|
57
58
|
validatorAdapters = [],
|
|
58
59
|
defaultRendererType = void 0,
|
|
59
60
|
rendererRegistry: rendererRegistry2 = void 0,
|
|
60
|
-
validationRuleRegistry: validationRuleRegistry2 = void 0
|
|
61
|
-
...rest
|
|
61
|
+
validationRuleRegistry: validationRuleRegistry2 = void 0
|
|
62
62
|
} = options;
|
|
63
63
|
return {
|
|
64
64
|
schemaConfig,
|
|
@@ -174,13 +174,9 @@ function useWatchFields(names, callback, options) {
|
|
|
174
174
|
function useWatchAll(callback, options) {
|
|
175
175
|
return useWatch(callback, options);
|
|
176
176
|
}
|
|
177
|
-
function useEffect(callback) {
|
|
178
|
-
const dispose = createEffect(callback);
|
|
179
|
-
onUnmounted(dispose);
|
|
180
|
-
return dispose;
|
|
181
|
-
}
|
|
182
177
|
function normalizeError(err) {
|
|
183
|
-
if (err instanceof Error)
|
|
178
|
+
if (err instanceof Error)
|
|
179
|
+
return err;
|
|
184
180
|
return new Error(String(err));
|
|
185
181
|
}
|
|
186
182
|
const useDictionary = (options, fieldName) => {
|
|
@@ -229,9 +225,11 @@ const useDictionary = (options, fieldName) => {
|
|
|
229
225
|
error.value = void 0;
|
|
230
226
|
const currentCount = ++requestCount;
|
|
231
227
|
const res = await executeWithRetry(formValues);
|
|
232
|
-
if (currentCount !== requestCount)
|
|
228
|
+
if (currentCount !== requestCount)
|
|
229
|
+
return;
|
|
233
230
|
const formatted = await format(res);
|
|
234
|
-
if (currentCount !== requestCount)
|
|
231
|
+
if (currentCount !== requestCount)
|
|
232
|
+
return;
|
|
235
233
|
list.value = formatted;
|
|
236
234
|
error.value = void 0;
|
|
237
235
|
if (typeof options.onSuccess === "function") {
|
|
@@ -289,7 +287,8 @@ function useFormConfigContext() {
|
|
|
289
287
|
const isShallowEqual = (a, b) => {
|
|
290
288
|
const keysA = Object.keys(a);
|
|
291
289
|
const keysB = Object.keys(b);
|
|
292
|
-
if (keysA.length !== keysB.length)
|
|
290
|
+
if (keysA.length !== keysB.length)
|
|
291
|
+
return false;
|
|
293
292
|
return keysA.every((key) => a[key] === b[key]);
|
|
294
293
|
};
|
|
295
294
|
function useStableRef(factory) {
|
|
@@ -313,13 +312,17 @@ function useViewSchemas(form) {
|
|
|
313
312
|
return viewSchemas;
|
|
314
313
|
}
|
|
315
314
|
function isValidTrigger(v) {
|
|
316
|
-
if (v === void 0)
|
|
317
|
-
|
|
315
|
+
if (v === void 0)
|
|
316
|
+
return false;
|
|
317
|
+
if (Array.isArray(v) && v.length === 0)
|
|
318
|
+
return false;
|
|
318
319
|
return true;
|
|
319
320
|
}
|
|
320
321
|
function mergeTrigger(columnTrigger, contextTrigger, defaultTrigger) {
|
|
321
|
-
if (isValidTrigger(columnTrigger))
|
|
322
|
-
|
|
322
|
+
if (isValidTrigger(columnTrigger))
|
|
323
|
+
return columnTrigger;
|
|
324
|
+
if (isValidTrigger(contextTrigger))
|
|
325
|
+
return contextTrigger;
|
|
323
326
|
return defaultTrigger;
|
|
324
327
|
}
|
|
325
328
|
function normalizeTrigger(t) {
|
|
@@ -334,7 +337,8 @@ function normalizeTrigger(t) {
|
|
|
334
337
|
return map[t] ?? "submit";
|
|
335
338
|
}
|
|
336
339
|
function shouldValidateOn(event, trigger) {
|
|
337
|
-
if (!trigger)
|
|
340
|
+
if (!trigger)
|
|
341
|
+
return false;
|
|
338
342
|
const triggers = Array.isArray(trigger) ? trigger : [trigger];
|
|
339
343
|
return triggers.some((t) => normalizeTrigger(t) === event);
|
|
340
344
|
}
|
|
@@ -347,17 +351,21 @@ const kebabToCamel = (str) => {
|
|
|
347
351
|
return str.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
348
352
|
};
|
|
349
353
|
const normalizeToKebab = (str) => {
|
|
350
|
-
if (isCamelCase(str))
|
|
354
|
+
if (isCamelCase(str))
|
|
355
|
+
return camelToKebab(str);
|
|
351
356
|
return str;
|
|
352
357
|
};
|
|
353
358
|
const normalizeToCamel = (str) => {
|
|
354
|
-
if (isKebabCase(str))
|
|
359
|
+
if (isKebabCase(str))
|
|
360
|
+
return kebabToCamel(str);
|
|
355
361
|
return str;
|
|
356
362
|
};
|
|
357
363
|
const resolveSlot = (slots, name) => {
|
|
358
|
-
if (slots[name])
|
|
364
|
+
if (slots[name])
|
|
365
|
+
return slots[name];
|
|
359
366
|
const alt = isCamelCase(name) ? camelToKebab(name) : isKebabCase(name) ? kebabToCamel(name) : void 0;
|
|
360
|
-
if (alt && slots[alt])
|
|
367
|
+
if (alt && slots[alt])
|
|
368
|
+
return slots[alt];
|
|
361
369
|
return void 0;
|
|
362
370
|
};
|
|
363
371
|
const extractChildSlots = (fieldName, allSlots) => {
|
|
@@ -420,7 +428,7 @@ const FormGroup = /* @__PURE__ */ defineComponent((props, {
|
|
|
420
428
|
"style": !destroyOnCollapse && isCollapsed ? {
|
|
421
429
|
display: "none"
|
|
422
430
|
} : void 0
|
|
423
|
-
}, [schema.children.map((child) => createVNode(FormItem, {
|
|
431
|
+
}, [schema.children.map((child) => createVNode(FormItem$1, {
|
|
424
432
|
"key": child.key,
|
|
425
433
|
"schema": child
|
|
426
434
|
}, slots))]);
|
|
@@ -467,9 +475,105 @@ const FormGroup = /* @__PURE__ */ defineComponent((props, {
|
|
|
467
475
|
}
|
|
468
476
|
}
|
|
469
477
|
});
|
|
478
|
+
const FormGroup$1 = FormGroup;
|
|
470
479
|
const normalizeId = (key) => {
|
|
471
480
|
return String(key).replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
472
481
|
};
|
|
482
|
+
function createFormItemSlotRenderers(options) {
|
|
483
|
+
const {
|
|
484
|
+
schemaRef,
|
|
485
|
+
field,
|
|
486
|
+
form,
|
|
487
|
+
formContext,
|
|
488
|
+
componentProps,
|
|
489
|
+
slots
|
|
490
|
+
} = options;
|
|
491
|
+
const renderRequired = () => {
|
|
492
|
+
const showRequiredMark = schemaRef.value.showRequiredMark ?? Boolean(schemaRef.value.required);
|
|
493
|
+
if (!showRequiredMark || schemaRef.value.disabled || schemaRef.value.readonly) {
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
return createVNode("span", {
|
|
497
|
+
"class": "schemx-item__required"
|
|
498
|
+
}, [createTextVNode("*")]);
|
|
499
|
+
};
|
|
500
|
+
const createSlotProps = (additionalProps = {}) => {
|
|
501
|
+
return {
|
|
502
|
+
...componentProps.value,
|
|
503
|
+
value: field.value.value,
|
|
504
|
+
...additionalProps
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
const renderFieldSlot = (suffix) => {
|
|
508
|
+
const slot = resolveSlot(slots, `${schemaRef.value.name}${suffix}`);
|
|
509
|
+
return (slot == null ? void 0 : slot(createSlotProps())) ?? null;
|
|
510
|
+
};
|
|
511
|
+
const renderLabel = () => {
|
|
512
|
+
const labelSlot = resolveSlot(slots, `${schemaRef.value.name}Label`);
|
|
513
|
+
if (labelSlot) {
|
|
514
|
+
return labelSlot(schemaRef.value);
|
|
515
|
+
}
|
|
516
|
+
const labelAlign = schemaRef.value.labelAlign || formContext.schemaConfig.labelAlign;
|
|
517
|
+
const labelWidth = schemaRef.value.labelWidth || formContext.schemaConfig.labelWidth;
|
|
518
|
+
const colon = schemaRef.value.colon ?? formContext.schemaConfig.colon;
|
|
519
|
+
return createVNode("label", {
|
|
520
|
+
"class": "schemx-item__label",
|
|
521
|
+
"style": {
|
|
522
|
+
width: labelWidth,
|
|
523
|
+
textAlign: labelAlign
|
|
524
|
+
}
|
|
525
|
+
}, [renderRequired(), createVNode("span", {
|
|
526
|
+
"class": "schemx-item__label-text"
|
|
527
|
+
}, [schemaRef.value.label, colon ? ":" : ""])]);
|
|
528
|
+
};
|
|
529
|
+
const renderBefore = () => renderFieldSlot("Before");
|
|
530
|
+
const renderContent = () => {
|
|
531
|
+
const component = form.getRenderer(schemaRef.value.componentType);
|
|
532
|
+
if (!component) {
|
|
533
|
+
throw new Error(`[schemx] Can not find component renderer of "${schemaRef.value.componentType}".`);
|
|
534
|
+
}
|
|
535
|
+
const childSlots = extractChildSlots(normalizeNameKey(schemaRef.value.name), slots);
|
|
536
|
+
const columnElement = h(component, componentProps.value, childSlots);
|
|
537
|
+
const contentSlot = resolveSlot(slots, `${schemaRef.value.name}Content`);
|
|
538
|
+
if (contentSlot) {
|
|
539
|
+
return contentSlot(createSlotProps({
|
|
540
|
+
columnElement
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
return createVNode("div", {
|
|
544
|
+
"class": "schemx-item__control"
|
|
545
|
+
}, [columnElement]);
|
|
546
|
+
};
|
|
547
|
+
const renderAfter = () => renderFieldSlot("After");
|
|
548
|
+
const renderError = () => {
|
|
549
|
+
const errorSlot = resolveSlot(slots, `${schemaRef.value.name}Error`);
|
|
550
|
+
if (errorSlot) {
|
|
551
|
+
return errorSlot(createSlotProps({
|
|
552
|
+
errors: field.errors.value
|
|
553
|
+
}));
|
|
554
|
+
}
|
|
555
|
+
if (field.errors.value.length === 0) {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
return createVNode("div", {
|
|
559
|
+
"class": "schemx-item__error"
|
|
560
|
+
}, [field.errors.value[0]]);
|
|
561
|
+
};
|
|
562
|
+
return {
|
|
563
|
+
createSlotProps,
|
|
564
|
+
renderAfter,
|
|
565
|
+
renderBefore,
|
|
566
|
+
renderContent,
|
|
567
|
+
renderError,
|
|
568
|
+
renderLabel
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function normalizeNameKey(name) {
|
|
572
|
+
if (Array.isArray(name)) {
|
|
573
|
+
return name.map((part) => String(part)).join(".");
|
|
574
|
+
}
|
|
575
|
+
return String(name);
|
|
576
|
+
}
|
|
473
577
|
const FormItem = /* @__PURE__ */ defineComponent({
|
|
474
578
|
name: "SchemxItem",
|
|
475
579
|
props: {
|
|
@@ -483,8 +587,8 @@ const FormItem = /* @__PURE__ */ defineComponent({
|
|
|
483
587
|
}) {
|
|
484
588
|
return () => {
|
|
485
589
|
const schema = props.schema;
|
|
486
|
-
if (isViewGroupSchema
|
|
487
|
-
return h(FormGroup, {
|
|
590
|
+
if (isViewGroupSchema(schema)) {
|
|
591
|
+
return h(FormGroup$1, {
|
|
488
592
|
schema
|
|
489
593
|
}, slots);
|
|
490
594
|
}
|
|
@@ -496,6 +600,7 @@ const FormItem = /* @__PURE__ */ defineComponent({
|
|
|
496
600
|
});
|
|
497
601
|
const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
498
602
|
name: "SchemxFieldItem",
|
|
603
|
+
inheritAttrs: false,
|
|
499
604
|
props: {
|
|
500
605
|
schema: {
|
|
501
606
|
type: Object,
|
|
@@ -503,145 +608,120 @@ const FieldFormItem = /* @__PURE__ */ defineComponent({
|
|
|
503
608
|
}
|
|
504
609
|
},
|
|
505
610
|
setup(props, {
|
|
611
|
+
attrs,
|
|
506
612
|
slots
|
|
507
613
|
}) {
|
|
508
|
-
const schemaRef = toRef(props, "schema");
|
|
509
614
|
const form = useFormContext();
|
|
615
|
+
const inputSchema = props.schema;
|
|
616
|
+
const schemaVersion = shallowRef(0);
|
|
617
|
+
const disposeSchemaEffect = form.effect(() => {
|
|
618
|
+
form.getViewSchemas();
|
|
619
|
+
schemaVersion.value++;
|
|
620
|
+
});
|
|
621
|
+
onUnmounted(disposeSchemaEffect);
|
|
622
|
+
const schemaRef = computed(() => {
|
|
623
|
+
void schemaVersion.value;
|
|
624
|
+
const latestSchema = form.getViewSchemas().find((viewSchema) => viewSchema.key === inputSchema.key);
|
|
625
|
+
return latestSchema && isSchemxViewFieldSchema(latestSchema) ? latestSchema : inputSchema;
|
|
626
|
+
});
|
|
510
627
|
const formContext = useFormConfigContext();
|
|
511
|
-
const
|
|
512
|
-
const field = useField(schema().name);
|
|
628
|
+
const field = useField(schemaRef.value.name);
|
|
513
629
|
createFieldContext(field);
|
|
514
|
-
const trigger = computed(() => mergeTrigger(
|
|
630
|
+
const trigger = computed(() => mergeTrigger(schemaRef.value.validationTrigger, formContext.schemaConfig.validationTrigger, "onChange"));
|
|
515
631
|
const canVerified = computed(() => {
|
|
516
|
-
const isOperate =
|
|
517
|
-
const rules =
|
|
518
|
-
const hasRules = Array.isArray(rules) ? (rules == null ? void 0 : rules.length) > 0 : !!
|
|
519
|
-
return isOperate && (Boolean(
|
|
632
|
+
const isOperate = schemaRef.value.visible && !schemaRef.value.readonly && !schemaRef.value.disabled;
|
|
633
|
+
const rules = schemaRef.value.rules;
|
|
634
|
+
const hasRules = Array.isArray(rules) ? (rules == null ? void 0 : rules.length) > 0 : !!schemaRef.value.rules;
|
|
635
|
+
return isOperate && (Boolean(schemaRef.value.required) || hasRules);
|
|
520
636
|
});
|
|
521
637
|
const handleChange = (v) => {
|
|
522
638
|
var _a, _b;
|
|
523
639
|
field.setValue(v);
|
|
524
|
-
(_b = (_a =
|
|
640
|
+
(_b = (_a = schemaRef.value.componentProps) == null ? void 0 : _a.onChange) == null ? void 0 : _b.call(_a, v);
|
|
525
641
|
if (canVerified.value && shouldValidateOn("change", trigger.value)) {
|
|
526
642
|
field.validate();
|
|
527
643
|
}
|
|
528
644
|
};
|
|
529
645
|
const handleBlur = (v) => {
|
|
530
646
|
var _a, _b;
|
|
531
|
-
(_b = (_a =
|
|
647
|
+
(_b = (_a = schemaRef.value.componentProps) == null ? void 0 : _a.onBlur) == null ? void 0 : _b.call(_a, v);
|
|
532
648
|
if (canVerified.value && shouldValidateOn("blur", trigger.value)) {
|
|
533
649
|
field.validate();
|
|
534
650
|
}
|
|
535
651
|
};
|
|
652
|
+
const handleValueUpdate = (v) => {
|
|
653
|
+
field.setValue(v);
|
|
654
|
+
};
|
|
536
655
|
const componentProps = useStableRef(() => {
|
|
537
|
-
const currentSchema =
|
|
656
|
+
const currentSchema = schemaRef.value;
|
|
657
|
+
const currentComponentProps = currentSchema.componentProps ?? {};
|
|
658
|
+
const formItemProps = {
|
|
659
|
+
name: currentSchema.name,
|
|
660
|
+
label: currentSchema.label,
|
|
661
|
+
componentType: currentSchema.componentType,
|
|
662
|
+
...currentComponentProps.formItemProps
|
|
663
|
+
};
|
|
538
664
|
return {
|
|
539
|
-
...
|
|
540
|
-
|
|
665
|
+
...currentComponentProps,
|
|
666
|
+
value: field.value.value,
|
|
541
667
|
disabled: currentSchema.disabled,
|
|
668
|
+
readonly: currentSchema.readonly,
|
|
669
|
+
readonlyPlaceholder: currentSchema.readonlyPlaceholder,
|
|
542
670
|
placeholder: currentSchema.placeholder,
|
|
543
|
-
formItemProps:
|
|
544
|
-
|
|
671
|
+
formItemProps: {
|
|
672
|
+
...formItemProps,
|
|
673
|
+
disabled: currentSchema.disabled,
|
|
674
|
+
readonly: currentSchema.readonly,
|
|
675
|
+
readonlyPlaceholder: currentSchema.readonlyPlaceholder,
|
|
676
|
+
placeholder: currentSchema.placeholder
|
|
677
|
+
},
|
|
545
678
|
onChange: handleChange,
|
|
546
679
|
onBlur: handleBlur,
|
|
547
|
-
"onUpdate:value":
|
|
680
|
+
"onUpdate:value": handleValueUpdate
|
|
548
681
|
};
|
|
549
682
|
});
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const labelWidth = schema().labelWidth || formContext.schemaConfig.labelWidth;
|
|
566
|
-
const colon = schema().colon ?? formContext.schemaConfig.colon;
|
|
567
|
-
return createVNode("label", {
|
|
568
|
-
"class": "schemx-item__label",
|
|
569
|
-
"style": {
|
|
570
|
-
width: labelWidth,
|
|
571
|
-
textAlign: labelAlign
|
|
572
|
-
}
|
|
573
|
-
}, [renderRequired(), createVNode("span", {
|
|
574
|
-
"class": "schemx-item__label-text"
|
|
575
|
-
}, [schema().label, colon ? ":" : ""])]);
|
|
576
|
-
};
|
|
577
|
-
const renderContent = () => {
|
|
578
|
-
const component = form.getRenderer(schema().componentType);
|
|
579
|
-
if (!component) {
|
|
580
|
-
throw new Error(`[schemx] Can not find component renderer of "${schema().componentType}".`);
|
|
581
|
-
}
|
|
582
|
-
const childSlots = extractChildSlots(normalizeNameKey(schema().name), slots);
|
|
583
|
-
const columnElement = h(component, componentProps.value, childSlots);
|
|
584
|
-
const contentSlot = resolveSlot(slots, `${schema().name}Content`);
|
|
585
|
-
if (contentSlot) {
|
|
586
|
-
return contentSlot({
|
|
587
|
-
...schema(),
|
|
588
|
-
columnElement
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
return createVNode("div", {
|
|
592
|
-
"class": "schemx-item__control"
|
|
593
|
-
}, [columnElement]);
|
|
594
|
-
};
|
|
595
|
-
const renderError = () => {
|
|
596
|
-
const errorSlot = resolveSlot(slots, `${schema().name}Error`);
|
|
597
|
-
if (errorSlot) {
|
|
598
|
-
return errorSlot({
|
|
599
|
-
...schema(),
|
|
600
|
-
errors: field.errors.value
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
if (field.errors.value.length === 0) {
|
|
604
|
-
return null;
|
|
605
|
-
}
|
|
606
|
-
return createVNode("div", {
|
|
607
|
-
"class": "schemx-item__error"
|
|
608
|
-
}, [field.errors.value[0]]);
|
|
609
|
-
};
|
|
683
|
+
const {
|
|
684
|
+
createSlotProps,
|
|
685
|
+
renderAfter,
|
|
686
|
+
renderBefore,
|
|
687
|
+
renderContent,
|
|
688
|
+
renderError,
|
|
689
|
+
renderLabel
|
|
690
|
+
} = createFormItemSlotRenderers({
|
|
691
|
+
schemaRef,
|
|
692
|
+
field,
|
|
693
|
+
form,
|
|
694
|
+
formContext,
|
|
695
|
+
componentProps,
|
|
696
|
+
slots
|
|
697
|
+
});
|
|
610
698
|
return () => {
|
|
611
|
-
if (!
|
|
699
|
+
if (!schemaRef.value.visible) {
|
|
612
700
|
return null;
|
|
613
701
|
}
|
|
614
|
-
const itemSlot = resolveSlot(slots, normalizeNameKey(
|
|
702
|
+
const itemSlot = resolveSlot(slots, normalizeNameKey(schemaRef.value.name));
|
|
615
703
|
if (itemSlot) {
|
|
616
|
-
return itemSlot(
|
|
704
|
+
return itemSlot(createSlotProps());
|
|
617
705
|
}
|
|
618
|
-
const labelPosition =
|
|
619
|
-
return createVNode("div", {
|
|
620
|
-
"class": classnames("schemx-item-wrapper"),
|
|
621
|
-
"style":
|
|
622
|
-
}, [createVNode("div", {
|
|
623
|
-
"class": classnames("schemx-item", `schemx-item--label-${labelPosition}`,
|
|
624
|
-
"is-readonly":
|
|
625
|
-
"is-disabled":
|
|
706
|
+
const labelPosition = schemaRef.value.labelPosition || formContext.schemaConfig.labelPosition;
|
|
707
|
+
return createVNode("div", mergeProps(attrs, {
|
|
708
|
+
"class": classnames("schemx-item-wrapper", attrs.class),
|
|
709
|
+
"style": [attrs.style, schemaRef.value.style]
|
|
710
|
+
}), [createVNode("div", {
|
|
711
|
+
"class": classnames("schemx-item", `schemx-item--label-${labelPosition}`, schemaRef.value.class, {
|
|
712
|
+
"is-readonly": schemaRef.value.readonly,
|
|
713
|
+
"is-disabled": schemaRef.value.disabled
|
|
626
714
|
}),
|
|
627
715
|
"style": {
|
|
628
|
-
...
|
|
716
|
+
...schemaRef.value.style ?? {}
|
|
629
717
|
}
|
|
630
718
|
}, [renderLabel(), createVNode("div", {
|
|
631
719
|
"class": "schemx-item__content"
|
|
632
|
-
}, [renderContent(), renderError()])])]);
|
|
720
|
+
}, [renderBefore(), renderContent(), renderAfter(), renderError()])])]);
|
|
633
721
|
};
|
|
634
722
|
}
|
|
635
723
|
});
|
|
636
|
-
const
|
|
637
|
-
return "children" in schema;
|
|
638
|
-
};
|
|
639
|
-
const normalizeNameKey = (name) => {
|
|
640
|
-
if (Array.isArray(name)) {
|
|
641
|
-
return name.map((part) => String(part)).join(".");
|
|
642
|
-
}
|
|
643
|
-
return String(name);
|
|
644
|
-
};
|
|
724
|
+
const FormItem$1 = FormItem;
|
|
645
725
|
function getSectionPosition(list, currentKey) {
|
|
646
726
|
const currentIndex = list.findIndex((item) => item.key === currentKey);
|
|
647
727
|
if (currentIndex === -1) {
|
|
@@ -665,9 +745,6 @@ function getSectionPosition(list, currentKey) {
|
|
|
665
745
|
isLast: !hasPositionItemInSection(list, currentIndex, 1)
|
|
666
746
|
};
|
|
667
747
|
}
|
|
668
|
-
function isViewGroupSchema(item) {
|
|
669
|
-
return !!item && "children" in item;
|
|
670
|
-
}
|
|
671
748
|
function isPositionItem(item) {
|
|
672
749
|
return !!item && !isViewGroupSchema(item) && item.visible !== false;
|
|
673
750
|
}
|
|
@@ -753,6 +830,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
753
830
|
(_a = props.onFieldsChange) == null ? void 0 : _a.call(props, changedPaths, allPaths);
|
|
754
831
|
}
|
|
755
832
|
});
|
|
833
|
+
const isExternalForm = props.form !== void 0;
|
|
756
834
|
createFormContext(form);
|
|
757
835
|
let syncingFromModel = false;
|
|
758
836
|
watch(
|
|
@@ -761,10 +839,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
761
839
|
syncingFromModel = true;
|
|
762
840
|
form.setFieldsValue(values);
|
|
763
841
|
syncingFromModel = false;
|
|
764
|
-
}
|
|
842
|
+
},
|
|
843
|
+
{ deep: true }
|
|
765
844
|
);
|
|
766
845
|
const disposeWatch = createWatch(form, (latestSnapshot) => {
|
|
767
|
-
if (syncingFromModel)
|
|
846
|
+
if (syncingFromModel)
|
|
847
|
+
return;
|
|
768
848
|
emit("update:modelValue", latestSnapshot);
|
|
769
849
|
});
|
|
770
850
|
onUnmounted(disposeWatch);
|
|
@@ -788,11 +868,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
788
868
|
"schemx-item-wrapper--last": isLast
|
|
789
869
|
};
|
|
790
870
|
};
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
871
|
+
watch(
|
|
872
|
+
pickSchemaConfig,
|
|
873
|
+
(nextSchemaConfig) => {
|
|
874
|
+
Object.assign(formSchemaConfig, nextSchemaConfig);
|
|
875
|
+
form.updateSchemaConfig(nextSchemaConfig);
|
|
876
|
+
},
|
|
877
|
+
{ deep: false, immediate: isExternalForm }
|
|
878
|
+
);
|
|
796
879
|
__expose({
|
|
797
880
|
...form
|
|
798
881
|
});
|
|
@@ -802,7 +885,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
802
885
|
style: normalizeStyle(props.style)
|
|
803
886
|
}, [
|
|
804
887
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(viewSchemas), (schema) => {
|
|
805
|
-
return openBlock(), createBlock(unref(FormItem), {
|
|
888
|
+
return openBlock(), createBlock(unref(FormItem$1), {
|
|
806
889
|
key: schema.key,
|
|
807
890
|
schema,
|
|
808
891
|
class: normalizeClass(getFormItemClass(schema))
|
|
@@ -831,31 +914,35 @@ const SchemxFormExport = withInstall(_sfc_main, {
|
|
|
831
914
|
app.component("SchemxForm", _sfc_main);
|
|
832
915
|
},
|
|
833
916
|
/** FormItem 子组件引用 */
|
|
834
|
-
FormItem
|
|
917
|
+
FormItem: FormItem$1
|
|
835
918
|
});
|
|
919
|
+
const SchemxFormExport$1 = SchemxFormExport;
|
|
920
|
+
function normalizeDictionary(dictionary) {
|
|
921
|
+
if (typeof dictionary === "function") {
|
|
922
|
+
return { api: dictionary };
|
|
923
|
+
}
|
|
924
|
+
return dictionary;
|
|
925
|
+
}
|
|
836
926
|
function WithRemoteOptions(WrappedComponent) {
|
|
837
927
|
return defineComponent({
|
|
838
928
|
name: `WithRemoteOptions(${WrappedComponent.name || "Anonymous"})`,
|
|
839
929
|
inheritAttrs: false,
|
|
840
930
|
props: {
|
|
841
931
|
dict: {
|
|
842
|
-
type: Object,
|
|
843
|
-
default: void 0
|
|
844
|
-
},
|
|
845
|
-
fieldName: {
|
|
846
|
-
type: [String, Array],
|
|
932
|
+
type: [Object, Function],
|
|
847
933
|
default: void 0
|
|
848
934
|
}
|
|
849
935
|
},
|
|
850
936
|
setup(props, { attrs, slots }) {
|
|
851
|
-
const
|
|
852
|
-
const
|
|
937
|
+
const dictionary = normalizeDictionary(props.dict);
|
|
938
|
+
const fieldName = dictionary ? attrs.fieldName ?? useFieldContext().name : void 0;
|
|
939
|
+
const dictResult = dictionary ? useDictionary(dictionary, fieldName) : null;
|
|
853
940
|
const childrenProps = computed(() => {
|
|
854
941
|
return {
|
|
855
942
|
...attrs,
|
|
856
|
-
dict:
|
|
857
|
-
options:
|
|
858
|
-
loading:
|
|
943
|
+
dict: dictionary,
|
|
944
|
+
options: dictionary ? dictResult == null ? void 0 : dictResult.list.value : attrs.options,
|
|
945
|
+
loading: dictionary ? dictResult == null ? void 0 : dictResult.loading.value : attrs.loading
|
|
859
946
|
};
|
|
860
947
|
});
|
|
861
948
|
return () => h(WrappedComponent, childrenProps.value, slots);
|
|
@@ -863,17 +950,16 @@ function WithRemoteOptions(WrappedComponent) {
|
|
|
863
950
|
});
|
|
864
951
|
}
|
|
865
952
|
export {
|
|
866
|
-
FormGroup,
|
|
867
|
-
FormItem,
|
|
953
|
+
FormGroup$1 as FormGroup,
|
|
954
|
+
FormItem$1 as FormItem,
|
|
868
955
|
WithRemoteOptions,
|
|
869
956
|
createFieldContext,
|
|
870
957
|
createFormConfigContext,
|
|
871
958
|
createFormContext,
|
|
872
|
-
SchemxFormExport as default,
|
|
959
|
+
SchemxFormExport$1 as default,
|
|
873
960
|
rendererRegistry,
|
|
874
|
-
SchemxFormExport as schemxForm,
|
|
961
|
+
SchemxFormExport$1 as schemxForm,
|
|
875
962
|
useDictionary,
|
|
876
|
-
useEffect,
|
|
877
963
|
useField,
|
|
878
964
|
useFieldContext,
|
|
879
965
|
useForm,
|