@schemx/vue 1.0.0 → 1.0.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.
Files changed (110) hide show
  1. package/README.md +161 -141
  2. package/dist/analyze.html +1 -1
  3. package/dist/bridge/fieldBridge.d.ts +12 -0
  4. package/dist/bridge/fieldBridge.d.ts.map +1 -1
  5. package/dist/bridge/formBridge.d.ts +33 -0
  6. package/dist/bridge/formBridge.d.ts.map +1 -1
  7. package/dist/bridge/formInstance.d.ts +20 -1
  8. package/dist/bridge/formInstance.d.ts.map +1 -1
  9. package/dist/bridge/helpers.d.ts +8 -0
  10. package/dist/bridge/helpers.d.ts.map +1 -1
  11. package/dist/bridge/index.d.ts +1 -1
  12. package/dist/bridge/index.d.ts.map +1 -1
  13. package/dist/bridge/types.d.ts +94 -4
  14. package/dist/bridge/types.d.ts.map +1 -1
  15. package/dist/bridge/viewSchemaBridge.d.ts +14 -1
  16. package/dist/bridge/viewSchemaBridge.d.ts.map +1 -1
  17. package/dist/components/Button/index.d.ts.map +1 -1
  18. package/dist/components/Button/index.vue.d.ts +12 -0
  19. package/dist/components/Button/index.vue.d.ts.map +1 -1
  20. package/dist/components/Button/types.d.ts +15 -5
  21. package/dist/components/Button/types.d.ts.map +1 -1
  22. package/dist/components/Col/index.d.ts +4 -5
  23. package/dist/components/Col/index.d.ts.map +1 -1
  24. package/dist/components/ConfigProvider/index.d.ts +8 -2
  25. package/dist/components/ConfigProvider/index.d.ts.map +1 -1
  26. package/dist/components/Dynamic/index.d.ts +9 -3
  27. package/dist/components/Dynamic/index.d.ts.map +1 -1
  28. package/dist/components/Field/index.d.ts +13 -2
  29. package/dist/components/Field/index.d.ts.map +1 -1
  30. package/dist/components/Field/slot.d.ts +32 -9
  31. package/dist/components/Field/slot.d.ts.map +1 -1
  32. package/dist/components/Group/index.d.ts +15 -5
  33. package/dist/components/Group/index.d.ts.map +1 -1
  34. package/dist/components/Group/slot.d.ts +36 -9
  35. package/dist/components/Group/slot.d.ts.map +1 -1
  36. package/dist/components/SchemaList/index.d.ts +15 -5
  37. package/dist/components/SchemaList/index.d.ts.map +1 -1
  38. package/dist/components/Wrapper/index.vue.d.ts +6 -0
  39. package/dist/components/Wrapper/index.vue.d.ts.map +1 -1
  40. package/dist/config/appConfig.d.ts +10 -0
  41. package/dist/config/appConfig.d.ts.map +1 -1
  42. package/dist/config/defaultVueSchemaConfig.d.ts +40 -0
  43. package/dist/config/defaultVueSchemaConfig.d.ts.map +1 -0
  44. package/dist/config/index.d.ts +15 -1
  45. package/dist/config/index.d.ts.map +1 -1
  46. package/dist/config/vueConfig.d.ts +7 -0
  47. package/dist/config/vueConfig.d.ts.map +1 -1
  48. package/dist/context/configProviderContext.d.ts +15 -0
  49. package/dist/context/configProviderContext.d.ts.map +1 -0
  50. package/dist/context/fieldContext.d.ts +11 -0
  51. package/dist/context/fieldContext.d.ts.map +1 -0
  52. package/dist/context/formContext.d.ts +76 -0
  53. package/dist/context/formContext.d.ts.map +1 -0
  54. package/dist/context/index.d.ts +18 -0
  55. package/dist/context/index.d.ts.map +1 -0
  56. package/dist/form.d.ts +8 -0
  57. package/dist/form.d.ts.map +1 -1
  58. package/dist/hocs/withRemoteOptions.d.ts +6 -2
  59. package/dist/hocs/withRemoteOptions.d.ts.map +1 -1
  60. package/dist/hooks/index.d.ts +24 -14
  61. package/dist/hooks/index.d.ts.map +1 -1
  62. package/dist/hooks/useDictionary.d.ts +32 -9
  63. package/dist/hooks/useDictionary.d.ts.map +1 -1
  64. package/dist/hooks/useField.d.ts +7 -0
  65. package/dist/hooks/useField.d.ts.map +1 -1
  66. package/dist/hooks/useForm.d.ts.map +1 -1
  67. package/dist/hooks/useFormSelector.d.ts.map +1 -1
  68. package/dist/hooks/useViewSchemas.d.ts +26 -2
  69. package/dist/hooks/useViewSchemas.d.ts.map +1 -1
  70. package/dist/index.cjs +1 -1
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.ts +33 -11
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.mjs +224 -164
  75. package/dist/index.mjs.map +1 -1
  76. package/dist/style.css +1 -1
  77. package/dist/types/definition.d.ts +153 -0
  78. package/dist/types/definition.d.ts.map +1 -0
  79. package/dist/types/dictionary.d.ts +9 -3
  80. package/dist/types/dictionary.d.ts.map +1 -1
  81. package/dist/types/field.d.ts +116 -21
  82. package/dist/types/field.d.ts.map +1 -1
  83. package/dist/types/form.d.ts +42 -1
  84. package/dist/types/form.d.ts.map +1 -1
  85. package/dist/types/index.d.ts +0 -15
  86. package/dist/types/index.d.ts.map +1 -1
  87. package/dist/types/layout.d.ts +31 -6
  88. package/dist/types/layout.d.ts.map +1 -1
  89. package/dist/utils/colProvider.d.ts +3 -1
  90. package/dist/utils/colProvider.d.ts.map +1 -1
  91. package/dist/utils/diff.d.ts +3 -6
  92. package/dist/utils/diff.d.ts.map +1 -1
  93. package/dist/utils/dynamic.d.ts +6 -2
  94. package/dist/utils/dynamic.d.ts.map +1 -1
  95. package/dist/utils/equal.d.ts +2 -2
  96. package/dist/utils/helpers.d.ts +26 -2
  97. package/dist/utils/helpers.d.ts.map +1 -1
  98. package/dist/utils/index.d.ts +15 -4
  99. package/dist/utils/index.d.ts.map +1 -1
  100. package/dist/utils/validation.d.ts +6 -2
  101. package/dist/utils/validation.d.ts.map +1 -1
  102. package/package.json +2 -2
  103. package/dist/config/providerConfig.d.ts +0 -22
  104. package/dist/config/providerConfig.d.ts.map +0 -1
  105. package/dist/hooks/provideFieldContext.d.ts +0 -40
  106. package/dist/hooks/provideFieldContext.d.ts.map +0 -1
  107. package/dist/hooks/provideFormConfigContext.d.ts +0 -71
  108. package/dist/hooks/provideFormConfigContext.d.ts.map +0 -1
  109. package/dist/hooks/provideFormContext.d.ts +0 -26
  110. package/dist/hooks/provideFormContext.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./style.css";
2
- import { shallowRef, computed, getCurrentInstance, inject, provide, onScopeDispose, onUnmounted, ref, onMounted, watchEffect, watch, readonly, createVNode, h, createTextVNode, defineComponent, mergeProps, useAttrs, openBlock, createElementBlock, unref, renderSlot, createCommentVNode, createStaticVNode, Fragment, toDisplayString, markRaw, toRaw, isVNode, useSlots, reactive, normalizeClass, normalizeStyle, createSlots, renderList, withCtx, normalizeProps, guardReactiveProps, createBlock, nextTick } from "vue";
3
- import { isViewGroupSchema, isViewDynamicSchema, mergeSchemxConfig, createPresetRuleRegistry, createForm, createField, createWatch, isSchemxViewFieldSchema, getGlobalSchemxConfig, mergeAndResolveSchemxConfig, isSchemxSchemas, defaultSchemxConfigKeys } from "@schemx/core";
2
+ import { shallowRef, computed, getCurrentScope, onScopeDispose, provide, inject, getCurrentInstance, onUnmounted, ref, onMounted, watchEffect, watch, readonly, createVNode, h, createTextVNode, defineComponent, mergeProps, useAttrs, openBlock, createElementBlock, unref, renderSlot, createCommentVNode, createStaticVNode, Fragment, toDisplayString, markRaw, toRaw, isVNode, useSlots, normalizeClass, normalizeStyle, createSlots, renderList, withCtx, normalizeProps, guardReactiveProps, createBlock, nextTick } from "vue";
3
+ import { isViewGroupSchema, isViewDynamicSchema, mergeSchemxConfig, createPresetRuleRegistry, createForm, createField, createWatch, isSchemxViewFieldSchema, defaultSchemxConfigKeys, getGlobalSchemxConfig, resolveSchemxConfig, isSchemxSchemas } from "@schemx/core";
4
4
  export * from "@schemx/core";
5
5
  import classnames from "classnames";
6
6
  import { createFormStateAdapter, createRendererRegistry } from "@schemx/core/adapter";
@@ -169,7 +169,14 @@ function createViewSchemaIndex(viewSchemas) {
169
169
  return schemasByKey;
170
170
  }
171
171
  const runtimeCache = /* @__PURE__ */ new WeakMap();
172
- const instanceRuntimeCache = /* @__PURE__ */ new WeakMap();
172
+ function useVueFormRuntime(form) {
173
+ if (!getCurrentScope()) {
174
+ throw new Error("[schemx] useVueFormRuntime() requires an active Vue scope.");
175
+ }
176
+ const { runtime, release } = acquireVueFormRuntime(form);
177
+ onScopeDispose(release);
178
+ return runtime;
179
+ }
173
180
  function acquireVueFormRuntime(form) {
174
181
  const runtime = getOrCreateVueFormRuntime(form);
175
182
  const release = runtime.retain();
@@ -179,17 +186,13 @@ function acquireVueFormRuntime(form) {
179
186
  };
180
187
  }
181
188
  function getOrCreateVueFormRuntime(form) {
182
- const cachedByInstance = instanceRuntimeCache.get(form);
183
- if (cachedByInstance) {
184
- return cachedByInstance;
185
- }
186
189
  const cachedByCore = runtimeCache.get(form);
187
190
  if (cachedByCore) {
188
191
  return cachedByCore;
189
192
  }
190
193
  const runtime = createVueFormRuntime(form);
191
194
  runtimeCache.set(form, runtime);
192
- instanceRuntimeCache.set(runtime.instance, runtime);
195
+ runtimeCache.set(runtime.instance, runtime);
193
196
  return runtime;
194
197
  }
195
198
  function createVueFormRuntime(core) {
@@ -203,26 +206,27 @@ function createVueFormRuntime(core) {
203
206
  const pendingFields = bindSnapshotSource(stateAdapter.pendingFields);
204
207
  const loading = bindSnapshotSource(stateAdapter.loading);
205
208
  const fieldStates = /* @__PURE__ */ new Map();
206
- let viewSchemaState;
207
209
  let disposed = false;
208
210
  const dispose = () => {
211
+ var _a;
209
212
  if (disposed) {
210
213
  return;
211
214
  }
212
215
  disposed = true;
216
+ (_a = currentResources.viewSchemaState) == null ? void 0 : _a.dispose();
213
217
  fieldStates.clear();
214
218
  stateAdapter.dispose();
215
219
  };
216
- return {
220
+ const currentResources = {
217
221
  stateAdapter,
218
222
  values,
219
223
  touchedFields,
220
224
  pendingFields,
221
225
  loading,
222
226
  fieldStates,
223
- viewSchemaState,
224
227
  dispose
225
228
  };
229
+ return currentResources;
226
230
  };
227
231
  const ensureResources = () => {
228
232
  if (destroyed) {
@@ -335,6 +339,120 @@ function createVueFormRuntime(core) {
335
339
  };
336
340
  return runtime;
337
341
  }
342
+ const SCHEMX_FORM_CONTEXT_KEY = Symbol("schemx:form-context");
343
+ const LEGACY_FORM_INSTANCE_KEY = Symbol("schemx:instance");
344
+ const LEGACY_FORM_CONFIG_KEY = Symbol("schemx:form-config");
345
+ function provideFormContext(options) {
346
+ const runtime = useVueFormRuntime(options.form);
347
+ const context = {
348
+ form: runtime.instance,
349
+ get schemaConfig() {
350
+ return options.schemaConfig;
351
+ }
352
+ };
353
+ provide(
354
+ SCHEMX_FORM_CONTEXT_KEY,
355
+ context
356
+ );
357
+ return runtime.instance;
358
+ }
359
+ function useFormContextValue() {
360
+ const context = inject(SCHEMX_FORM_CONTEXT_KEY, null);
361
+ if (context) {
362
+ return context;
363
+ }
364
+ const form = inject(LEGACY_FORM_INSTANCE_KEY, null);
365
+ const config = inject(LEGACY_FORM_CONFIG_KEY, null);
366
+ if (form && config) {
367
+ return {
368
+ form,
369
+ schemaConfig: config.schemaConfig
370
+ };
371
+ }
372
+ throw new Error(
373
+ "[schemx] useFormContextValue() must be called inside a <SchemxForm> descendant. Ensure provideFormContext({ form, schemaConfig }) is called synchronously during setup()."
374
+ );
375
+ }
376
+ function createFormContext(instance) {
377
+ const runtime = useVueFormRuntime(instance);
378
+ provide(
379
+ LEGACY_FORM_INSTANCE_KEY,
380
+ runtime.instance
381
+ );
382
+ return runtime.instance;
383
+ }
384
+ function useFormContext() {
385
+ const context = inject(SCHEMX_FORM_CONTEXT_KEY, null);
386
+ if (context) {
387
+ return context.form;
388
+ }
389
+ const instance = inject(
390
+ LEGACY_FORM_INSTANCE_KEY,
391
+ null
392
+ );
393
+ if (!instance) {
394
+ throw new Error(
395
+ "[schemx] useFormContext() must be called inside a <SchemxForm> descendant. Ensure createFormContext(form) is called synchronously during setup()."
396
+ );
397
+ }
398
+ return instance;
399
+ }
400
+ function createFormConfigContext(props) {
401
+ provide(LEGACY_FORM_CONFIG_KEY, props);
402
+ }
403
+ function useFormConfigContext() {
404
+ const context = inject(SCHEMX_FORM_CONTEXT_KEY, null);
405
+ if (context) {
406
+ return context;
407
+ }
408
+ const config = inject(LEGACY_FORM_CONFIG_KEY, null);
409
+ if (!config) {
410
+ throw new Error(
411
+ "[schemx] useFormConfigContext() must be called inside a <SchemxForm> descendant. Ensure createFormConfigContext(props) is called synchronously during setup()."
412
+ );
413
+ }
414
+ return config;
415
+ }
416
+ function useFormRuntimeContext() {
417
+ return useVueFormRuntime(useFormContext());
418
+ }
419
+ const SCHEMX_FIELD_CONTEXT_KEY = Symbol("schemx:field");
420
+ function createFieldContext(field) {
421
+ provide(SCHEMX_FIELD_CONTEXT_KEY, field);
422
+ }
423
+ function useFieldContext() {
424
+ const field = inject(SCHEMX_FIELD_CONTEXT_KEY, null);
425
+ if (!field) {
426
+ throw new Error(
427
+ "[schemx] useFieldContext() must be called inside a component tree where createFieldContext(field) has been called."
428
+ );
429
+ }
430
+ return field;
431
+ }
432
+ const SCHEMX_CONFIG_PROVIDER_KEY = Symbol(
433
+ "schemx:config-provider"
434
+ );
435
+ function createConfigProviderContext(config) {
436
+ const parentConfig = inject(SCHEMX_CONFIG_PROVIDER_KEY, void 0);
437
+ const mergedConfig = computed(() => {
438
+ const mergedCoreConfig = mergeSchemxConfig(config.value, (parentConfig == null ? void 0 : parentConfig.value) ?? {});
439
+ return {
440
+ ...mergedCoreConfig,
441
+ colComponent: config.value.colComponent ?? (parentConfig == null ? void 0 : parentConfig.value.colComponent)
442
+ };
443
+ });
444
+ provide(SCHEMX_CONFIG_PROVIDER_KEY, mergedConfig);
445
+ }
446
+ function useConfigProviderContext() {
447
+ var _a;
448
+ return (_a = useConfigProviderContextRef()) == null ? void 0 : _a.value;
449
+ }
450
+ function useConfigProviderContextRef() {
451
+ if (getCurrentInstance() === null) {
452
+ return void 0;
453
+ }
454
+ return inject(SCHEMX_CONFIG_PROVIDER_KEY, void 0);
455
+ }
338
456
  const SCHEMX_APP_CONFIG_KEY = Symbol("schemx:app-config");
339
457
  const EMPTY_SCHEMX_CONFIG = Object.freeze({
340
458
  schemaConfig: Object.freeze({}),
@@ -372,34 +490,10 @@ function getSchemxAppConfig() {
372
490
  }
373
491
  return inject(SCHEMX_APP_CONFIG_KEY, EMPTY_SCHEMX_CONFIG);
374
492
  }
375
- const SCHEMX_CONFIG_PROVIDER_KEY = Symbol(
376
- "schemx:config-provider"
377
- );
378
- function provideSchemxConfigProvider(config) {
379
- const parentConfig = inject(SCHEMX_CONFIG_PROVIDER_KEY, void 0);
380
- const mergedConfig = computed(() => {
381
- const mergedCoreConfig = mergeSchemxConfig(config.value, (parentConfig == null ? void 0 : parentConfig.value) ?? {});
382
- return {
383
- ...mergedCoreConfig,
384
- colComponent: config.value.colComponent ?? (parentConfig == null ? void 0 : parentConfig.value.colComponent)
385
- };
386
- });
387
- provide(SCHEMX_CONFIG_PROVIDER_KEY, mergedConfig);
388
- }
389
- function getSchemxConfigProvider() {
390
- var _a;
391
- return (_a = getSchemxConfigProviderRef()) == null ? void 0 : _a.value;
392
- }
393
- function getSchemxConfigProviderRef() {
394
- if (getCurrentInstance() === null) {
395
- return void 0;
396
- }
397
- return inject(SCHEMX_CONFIG_PROVIDER_KEY, void 0);
398
- }
399
493
  const presetRuleRegistry = createPresetRuleRegistry();
400
494
  const rendererRegistry = createRendererRegistry("input");
401
495
  function mergeVueSchemxConfig(localConfig, fallbackConfig = {}) {
402
- const providerConfig = getSchemxConfigProvider();
496
+ const providerConfig = useConfigProviderContext();
403
497
  return mergeSchemxConfig(
404
498
  localConfig,
405
499
  providerConfig ?? {},
@@ -411,6 +505,39 @@ function mergeVueSchemxConfig(localConfig, fallbackConfig = {}) {
411
505
  }
412
506
  );
413
507
  }
508
+ const defaultVueSchemaConfig = Object.freeze({
509
+ /**
510
+ * 表单级标签图标默认值。
511
+ */
512
+ labelIcon: "",
513
+ /**
514
+ * 表单级标签对齐默认值。
515
+ */
516
+ labelAlign: "left",
517
+ /**
518
+ * 表单级标签位置默认值。
519
+ */
520
+ labelPosition: "left",
521
+ /**
522
+ * 表单级标签宽度默认值。
523
+ */
524
+ labelWidth: "auto",
525
+ /**
526
+ * 表单级内容对齐默认值。
527
+ */
528
+ contentAlign: "right",
529
+ /**
530
+ * 表单级标签冒号默认值。
531
+ */
532
+ colon: true,
533
+ /**
534
+ * 表单级必填标记默认值。
535
+ */
536
+ showRequiredMark: void 0
537
+ });
538
+ const defaultVueSchemaConfigKeys = Object.keys(
539
+ defaultVueSchemaConfig
540
+ );
414
541
  function useForm(options = {}) {
415
542
  const configuredOptions = mergeVueSchemxConfig(getUseFormSchemxConfig(options));
416
543
  const mergedOptions = {
@@ -418,10 +545,8 @@ function useForm(options = {}) {
418
545
  ...configuredOptions
419
546
  };
420
547
  const instance = createForm(mergedOptions);
421
- const acquired = acquireVueFormRuntime(instance);
422
- const form = acquired.runtime.instance;
548
+ const form = useVueFormRuntime(instance).instance;
423
549
  onScopeDispose(() => {
424
- acquired.release();
425
550
  form.destroy();
426
551
  });
427
552
  return form;
@@ -444,41 +569,6 @@ function getUseFormSchemxConfig(options) {
444
569
  validatorAdapters
445
570
  };
446
571
  }
447
- const SCHEMX_FORM_INSTANCE_KEY = Symbol(
448
- "schemx:instance"
449
- );
450
- const SCHEMX_FORM_RUNTIME_KEY = Symbol(
451
- "schemx:runtime"
452
- );
453
- function createFormContext(instance) {
454
- const { runtime, release } = acquireVueFormRuntime(instance);
455
- provide(
456
- SCHEMX_FORM_INSTANCE_KEY,
457
- runtime.instance
458
- );
459
- provide(SCHEMX_FORM_RUNTIME_KEY, runtime);
460
- onScopeDispose(release);
461
- return runtime.instance;
462
- }
463
- function useFormContext() {
464
- const instance = inject(SCHEMX_FORM_INSTANCE_KEY, null);
465
- if (!instance) {
466
- throw new Error(
467
- "[schemx] useFormContext() must be called inside a <SchemxForm> descendant. Ensure createFormContext(form) is called synchronously during setup()."
468
- );
469
- }
470
- return instance;
471
- }
472
- function useFormRuntimeContext() {
473
- const providedRuntime = inject(SCHEMX_FORM_RUNTIME_KEY, null);
474
- if (providedRuntime) {
475
- return providedRuntime;
476
- }
477
- const instance = useFormContext();
478
- const acquired = acquireVueFormRuntime(instance);
479
- onScopeDispose(acquired.release);
480
- return acquired.runtime;
481
- }
482
572
  function createFieldHook(form, coreForm, name, fieldState) {
483
573
  const coreField = createField(coreForm, name);
484
574
  const errors = computed(() => fieldState.errors.value);
@@ -507,27 +597,12 @@ const useField = (name) => {
507
597
  const form = useFormContext();
508
598
  const runtime = useFormRuntimeContext();
509
599
  const fieldState = runtime.getFieldState(name);
510
- return createFieldHook(form, runtime.core, name, fieldState);
600
+ return createFieldHook(form, runtime.instance, name, fieldState);
511
601
  };
512
- const SCHEMX_FORM_FIELD_KEY = Symbol(
513
- "schemx:field"
514
- );
515
- function createFieldContext(field) {
516
- provide(SCHEMX_FORM_FIELD_KEY, field);
517
- }
518
- function useFieldContext() {
519
- const field = inject(SCHEMX_FORM_FIELD_KEY);
520
- if (!field) {
521
- throw new Error(
522
- "[schemx] useFieldContext() must be called inside a component tree where createFieldContext(field) has been called."
523
- );
524
- }
525
- return field;
526
- }
527
602
  function useWatch(nameOrNamesOrCallback, callbackOrOptions, maybeOptions) {
528
603
  const runtime = useFormRuntimeContext();
529
604
  const dispose = createWatch(
530
- runtime.core,
605
+ runtime.instance,
531
606
  nameOrNamesOrCallback,
532
607
  callbackOrOptions,
533
608
  maybeOptions
@@ -692,21 +767,6 @@ function callDictionaryApi(values, form, api, signal) {
692
767
  }
693
768
  return api(values, form);
694
769
  }
695
- const SCHEMX_FORM_CONFIG_KEY = Symbol(
696
- "schemx:form-config"
697
- );
698
- const createFormConfigContext = (props) => {
699
- provide(SCHEMX_FORM_CONFIG_KEY, props);
700
- };
701
- function useFormConfigContext() {
702
- const context = inject(SCHEMX_FORM_CONFIG_KEY);
703
- if (!context) {
704
- throw new Error(
705
- "[schemx] useFormConfigContext() must be called inside a <SchemxForm> descendant. Ensure createFormConfigContext(props) is called synchronously during setup()."
706
- );
707
- }
708
- return context;
709
- }
710
770
  const isShallowEqual = (a, b) => {
711
771
  const keysA = Object.keys(a);
712
772
  const keysB = Object.keys(b);
@@ -725,24 +785,19 @@ function useStableRef(factory) {
725
785
  return stableRef;
726
786
  }
727
787
  function useViewSchemas(form) {
728
- const acquired = acquireVueFormRuntime(form);
729
- const state = acquired.runtime.getViewSchemaState();
730
- onScopeDispose(acquired.release);
788
+ const state = useVueFormRuntime(form).getViewSchemaState();
731
789
  return state.viewSchemas;
732
790
  }
733
791
  function useViewSchema(form, getKey) {
734
- const acquired = acquireVueFormRuntime(form);
735
- const state = acquired.runtime.getViewSchemaState();
792
+ const state = useVueFormRuntime(form).getViewSchemaState();
736
793
  const schema = computed(() => state.schemasByKey.value.get(getKey()));
737
- onScopeDispose(acquired.release);
738
794
  return schema;
739
795
  }
740
796
  function useFormSelector(form, selector, options = {}) {
741
- const acquired = acquireVueFormRuntime(form);
742
- const values = acquired.runtime.getValuesRef();
797
+ const values = useVueFormRuntime(form).getValuesRef();
743
798
  const selected = shallowRef(selector(values.value));
744
799
  const equals = options.equals ?? Object.is;
745
- const stop = watch(
800
+ watch(
746
801
  values,
747
802
  (values2) => {
748
803
  const next = selector(values2);
@@ -752,10 +807,6 @@ function useFormSelector(form, selector, options = {}) {
752
807
  },
753
808
  { flush: options.flush ?? "sync" }
754
809
  );
755
- onScopeDispose(() => {
756
- stop();
757
- acquired.release();
758
- });
759
810
  return readonly(selected);
760
811
  }
761
812
  function isValidTrigger(v) {
@@ -924,7 +975,9 @@ function createFieldSlotRenderers(options) {
924
975
  width: labelWidth,
925
976
  textAlign: labelAlign
926
977
  }
927
- }, [renderRequired(), createVNode("span", {
978
+ }, [renderRequired(), schemaRef.value.labelIcon ? createVNode("span", {
979
+ "class": "schemx-field__label-icon"
980
+ }, [schemaRef.value.labelIcon]) : null, createVNode("span", {
928
981
  "class": "schemx-field__label-text"
929
982
  }, [schemaRef.value.label, colon ? ":" : ""])]);
930
983
  };
@@ -989,6 +1042,7 @@ const Field = /* @__PURE__ */ defineComponent({
989
1042
  default: void 0
990
1043
  }
991
1044
  },
1045
+ slots: Object,
992
1046
  /**
993
1047
  * 初始化字段上下文,并组合响应式 schema、校验处理器与插槽渲染器。
994
1048
  *
@@ -1000,13 +1054,13 @@ const Field = /* @__PURE__ */ defineComponent({
1000
1054
  attrs,
1001
1055
  slots
1002
1056
  }) {
1003
- const form = useFormContext();
1057
+ const formContext = useFormContextValue();
1058
+ const form = formContext.form;
1004
1059
  const inputSchema = computed(() => props.schema);
1005
1060
  const latestSchema = useViewSchema(form, () => inputSchema.value.key);
1006
1061
  const schemaRef = computed(() => {
1007
1062
  return latestSchema.value && isSchemxViewFieldSchema(latestSchema.value) ? latestSchema.value : inputSchema.value;
1008
1063
  });
1009
- const formContext = useFormConfigContext();
1010
1064
  const field = useField(schemaRef.value.name);
1011
1065
  createFieldContext(field);
1012
1066
  const trigger = computed(() => mergeTrigger(schemaRef.value.validationTrigger, formContext.schemaConfig.validationTrigger, "onChange"));
@@ -1017,31 +1071,38 @@ const Field = /* @__PURE__ */ defineComponent({
1017
1071
  return isOperate && (Boolean(schemaRef.value.required) || hasRules);
1018
1072
  });
1019
1073
  const handleChange = (v) => {
1020
- var _a, _b;
1074
+ var _a, _b, _c, _d;
1021
1075
  field.setValue(v);
1022
1076
  (_b = (_a = schemaRef.value.componentProps) == null ? void 0 : _a.onChange) == null ? void 0 : _b.call(_a, v);
1077
+ (_d = (_c = schemaRef.value).onChange) == null ? void 0 : _d.call(_c, v, form);
1023
1078
  if (canVerified.value && shouldValidateOn("change", trigger.value)) {
1024
1079
  field.validate();
1025
1080
  }
1026
1081
  };
1027
1082
  const handleBlur = (v) => {
1028
- var _a, _b;
1083
+ var _a, _b, _c, _d;
1029
1084
  (_b = (_a = schemaRef.value.componentProps) == null ? void 0 : _a.onBlur) == null ? void 0 : _b.call(_a, v);
1085
+ (_d = (_c = schemaRef.value).onBlur) == null ? void 0 : _d.call(_c, form);
1030
1086
  if (canVerified.value && shouldValidateOn("blur", trigger.value)) {
1031
1087
  field.validate();
1032
1088
  }
1033
1089
  };
1034
- const handleValueUpdate = (v) => {
1090
+ const updateValue = (v) => {
1035
1091
  field.setValue(v);
1036
1092
  };
1037
1093
  const componentProps = useStableRef(() => {
1038
1094
  const currentComponentProps = schemaRef.value.componentProps ?? {};
1039
1095
  return {
1040
1096
  ...currentComponentProps,
1097
+ align: schemaRef.value.readonly ? "right" : currentComponentProps.align ?? schemaRef.value.contentAlign,
1098
+ readonly: schemaRef.value.readonly,
1099
+ disabled: schemaRef.value.disabled,
1100
+ placeholder: currentComponentProps.placeholder ?? schemaRef.value.placeholder,
1101
+ readonlyPlaceholder: currentComponentProps.readonlyPlaceholder ?? schemaRef.value.readonlyPlaceholder,
1041
1102
  value: field.value.value,
1042
1103
  onChange: handleChange,
1043
1104
  onBlur: handleBlur,
1044
- "onUpdate:value": handleValueUpdate
1105
+ "onUpdate:value": updateValue
1045
1106
  };
1046
1107
  });
1047
1108
  const {
@@ -1267,6 +1328,7 @@ const Group = /* @__PURE__ */ defineComponent({
1267
1328
  default: void 0
1268
1329
  }
1269
1330
  },
1331
+ slots: Object,
1270
1332
  setup(props, {
1271
1333
  attrs,
1272
1334
  slots
@@ -1593,11 +1655,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1593
1655
  const props = __props;
1594
1656
  const emit = __emit;
1595
1657
  const slots = useSlots();
1658
+ const schemaConfigKeys = [
1659
+ ...defaultSchemxConfigKeys,
1660
+ ...defaultVueSchemaConfigKeys
1661
+ ];
1596
1662
  const pickSchemaConfig = () => {
1597
- const schemaConfig = pick(
1598
- props,
1599
- defaultSchemxConfigKeys
1600
- );
1663
+ const schemaConfig = pick(props, schemaConfigKeys);
1601
1664
  return Object.fromEntries(
1602
1665
  Object.entries(schemaConfig).filter(([, value]) => value !== void 0)
1603
1666
  );
@@ -1605,7 +1668,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1605
1668
  const isExternalForm = props.form !== void 0;
1606
1669
  const schemaConfigProps = computed(pickSchemaConfig);
1607
1670
  const appConfig = getSchemxAppConfig();
1608
- const providerConfig = getSchemxConfigProviderRef();
1671
+ const providerConfig = useConfigProviderContextRef();
1609
1672
  const coreConfig = getGlobalSchemxConfig();
1610
1673
  const formFallbackConfig = {
1611
1674
  schemaConfig: {
@@ -1613,45 +1676,29 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1613
1676
  validationTrigger: ["blur", "change"]
1614
1677
  }
1615
1678
  };
1616
- const contextSchemaConfig = computed(() => {
1617
- const mergedConfig = isExternalForm ? mergeSchemxConfig({ schemaConfig: schemaConfigProps.value }, formFallbackConfig) : mergeSchemxConfig(
1618
- { schemaConfig: schemaConfigProps.value },
1619
- (providerConfig == null ? void 0 : providerConfig.value) ?? {},
1620
- appConfig,
1621
- formFallbackConfig
1622
- );
1623
- return mergedConfig.schemaConfig ?? {};
1624
- });
1625
- const resolvedSchemaConfig = computed(
1626
- () => mergeAndResolveSchemxConfig(
1679
+ const mergedConfig = computed(
1680
+ () => isExternalForm ? mergeSchemxConfig({ schemaConfig: schemaConfigProps.value }, formFallbackConfig) : mergeSchemxConfig(
1627
1681
  { schemaConfig: schemaConfigProps.value },
1628
1682
  (providerConfig == null ? void 0 : providerConfig.value) ?? {},
1629
1683
  appConfig,
1630
1684
  formFallbackConfig,
1631
1685
  coreConfig
1632
- ).schemaConfig
1686
+ )
1633
1687
  );
1634
- const initialContextSchemaConfig = contextSchemaConfig.value;
1635
- const initialCoreSchemaConfig = isExternalForm ? initialContextSchemaConfig : resolvedSchemaConfig.value;
1636
- const formSchemaConfig = reactive(
1637
- initialContextSchemaConfig
1688
+ const contextSchemaConfig = computed(() => ({
1689
+ ...defaultVueSchemaConfig,
1690
+ ...mergedConfig.value.schemaConfig
1691
+ }));
1692
+ const resolvedSchemaConfig = computed(
1693
+ () => resolveSchemxConfig(mergedConfig.value).schemaConfig
1638
1694
  );
1639
1695
  const hasSchemaConfigKey = (config, key) => Object.prototype.hasOwnProperty.call(config, key);
1640
- const replaceFormSchemaConfig = (nextSchemaConfig) => {
1641
- for (const key of defaultSchemxConfigKeys) {
1642
- if (!hasSchemaConfigKey(nextSchemaConfig, key)) {
1643
- delete formSchemaConfig[key];
1644
- }
1645
- }
1646
- Object.assign(formSchemaConfig, nextSchemaConfig);
1647
- };
1648
1696
  const resolvedColComponent = computed(
1649
1697
  () => props.colComponent ?? (providerConfig == null ? void 0 : providerConfig.value.colComponent) ?? appConfig.colComponent ?? registeredColComponent.value
1650
1698
  );
1651
- createFormConfigContext({ schemaConfig: formSchemaConfig });
1652
1699
  const providedForm = props.form ? props.form : useForm({
1653
1700
  schemas: props.schemas,
1654
- schemaConfig: initialCoreSchemaConfig,
1701
+ schemaConfig: resolvedSchemaConfig.value,
1655
1702
  initialValues: Object.keys(props.modelValue).length > 0 ? props.modelValue : props.initialValues,
1656
1703
  rendererProps: props.rendererProps,
1657
1704
  rendererRegistry: props.rendererRegistry,
@@ -1718,7 +1765,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1718
1765
  (_a = props.onFieldsChange) == null ? void 0 : _a.call(props, changedPaths, allPaths);
1719
1766
  }
1720
1767
  });
1721
- const formInstance = createFormContext(providedForm);
1768
+ const formInstance = provideFormContext({
1769
+ form: providedForm,
1770
+ get schemaConfig() {
1771
+ return contextSchemaConfig.value;
1772
+ }
1773
+ });
1722
1774
  const effectiveLoading = computed(() => props.loading ?? formInstance.isLoading());
1723
1775
  const formRootClass = computed(() => ["schemx", props.class]);
1724
1776
  const formRootStyle = computed(() => props.style);
@@ -1818,19 +1870,17 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1818
1870
  };
1819
1871
  };
1820
1872
  const syncInternalSchemaConfig = (nextSchemaConfig) => {
1821
- replaceFormSchemaConfig(contextSchemaConfig.value);
1822
1873
  formInstance.updateSchemaConfig(nextSchemaConfig);
1823
1874
  };
1824
1875
  const syncExternalSchemaConfig = (nextSchemaConfig, previousSchemaConfig) => {
1825
1876
  const patch = { ...nextSchemaConfig };
1826
1877
  if (previousSchemaConfig !== void 0) {
1827
- for (const key of defaultSchemxConfigKeys) {
1878
+ for (const key of schemaConfigKeys) {
1828
1879
  if (hasSchemaConfigKey(previousSchemaConfig, key) && !hasSchemaConfigKey(nextSchemaConfig, key)) {
1829
1880
  patch[key] = void 0;
1830
1881
  }
1831
1882
  }
1832
1883
  }
1833
- replaceFormSchemaConfig(contextSchemaConfig.value);
1834
1884
  if (Object.keys(patch).length > 0) {
1835
1885
  formInstance.updateSchemaConfig(patch);
1836
1886
  }
@@ -1912,12 +1962,16 @@ function withInstall(comp, extra) {
1912
1962
  return Object.assign(comp, extra);
1913
1963
  }
1914
1964
  const SchemxFormExport = withInstall(_sfc_main$1, {
1915
- /** Vue 插件安装方法 */
1965
+ /**
1966
+ * Vue 插件安装方法
1967
+ */
1916
1968
  install(app, options = {}) {
1917
1969
  provideSchemxAppConfig(app, options);
1918
1970
  app.component("SchemxForm", _sfc_main$1);
1919
1971
  },
1920
- /** Field 子组件引用 */
1972
+ /**
1973
+ * Field 子组件引用
1974
+ */
1921
1975
  Field: Field$1
1922
1976
  });
1923
1977
  const SchemxFormExport$1 = SchemxFormExport;
@@ -2045,7 +2099,7 @@ const ConfigProvider = /* @__PURE__ */ defineComponent({
2045
2099
  presetRuleRegistry: props.presetRuleRegistry,
2046
2100
  colComponent: props.colComponent
2047
2101
  }));
2048
- provideSchemxConfigProvider(config);
2102
+ createConfigProviderContext(config);
2049
2103
  return () => {
2050
2104
  var _a;
2051
2105
  return (_a = slots.default) == null ? void 0 : _a.call(slots);
@@ -2060,20 +2114,26 @@ export {
2060
2114
  Group$1 as Group,
2061
2115
  WithRemoteOptions,
2062
2116
  _sfc_main as Wrapper,
2117
+ createConfigProviderContext,
2063
2118
  createFieldContext,
2064
2119
  createFormConfigContext,
2065
2120
  createFormContext,
2066
2121
  SchemxFormExport$1 as default,
2067
2122
  presetRuleRegistry,
2123
+ provideFormContext,
2068
2124
  registerCol,
2069
2125
  rendererRegistry,
2070
2126
  SchemxFormExport$1 as schemxForm,
2127
+ useConfigProviderContext,
2128
+ useConfigProviderContextRef,
2071
2129
  useDictionary,
2072
2130
  useField,
2073
2131
  useFieldContext,
2074
2132
  useForm,
2075
2133
  useFormConfigContext,
2076
2134
  useFormContext,
2135
+ useFormContextValue,
2136
+ useFormRuntimeContext,
2077
2137
  useFormSelector,
2078
2138
  useStableRef,
2079
2139
  useViewSchemas,