@uipath/apollo-wind 2.60.1 → 2.61.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.
Files changed (152) hide show
  1. package/dist/components/forms/field-actions.cjs +181 -0
  2. package/dist/components/forms/field-actions.d.ts +131 -0
  3. package/dist/components/forms/field-actions.js +129 -0
  4. package/dist/components/forms/field-control.cjs +415 -0
  5. package/dist/components/forms/field-control.d.ts +52 -0
  6. package/dist/components/forms/field-control.js +372 -0
  7. package/dist/components/forms/field-renderer.cjs +77 -420
  8. package/dist/components/forms/field-renderer.d.ts +2 -3
  9. package/dist/components/forms/field-renderer.js +78 -421
  10. package/dist/components/forms/form-designer.cjs +7 -1
  11. package/dist/components/forms/form-designer.js +7 -1
  12. package/dist/components/forms/form-schema.d.ts +121 -2
  13. package/dist/components/forms/form-strings.cjs +67 -0
  14. package/dist/components/forms/form-strings.d.ts +30 -0
  15. package/dist/components/forms/form-strings.js +30 -0
  16. package/dist/components/forms/index.cjs +53 -9
  17. package/dist/components/forms/index.d.ts +6 -1
  18. package/dist/components/forms/index.js +6 -1
  19. package/dist/components/forms/literal-value-context.cjs +37 -0
  20. package/dist/components/forms/literal-value-context.d.ts +5 -0
  21. package/dist/components/forms/literal-value-context.js +3 -0
  22. package/dist/components/forms/metadata-form.cjs +100 -21
  23. package/dist/components/forms/metadata-form.d.ts +5 -0
  24. package/dist/components/forms/metadata-form.js +101 -22
  25. package/dist/components/forms/mode-aware-field.cjs +589 -0
  26. package/dist/components/forms/mode-aware-field.d.ts +15 -0
  27. package/dist/components/forms/mode-aware-field.js +555 -0
  28. package/dist/components/forms/opaque-value.cjs +44 -0
  29. package/dist/components/forms/opaque-value.d.ts +7 -0
  30. package/dist/components/forms/opaque-value.js +7 -0
  31. package/dist/components/forms/rules-engine.cjs +13 -0
  32. package/dist/components/forms/rules-engine.js +13 -0
  33. package/dist/components/forms/schema-serializer.cjs +8 -0
  34. package/dist/components/forms/schema-serializer.js +8 -0
  35. package/dist/components/forms/string-list-field.cjs +36 -18
  36. package/dist/components/forms/string-list-field.d.ts +6 -0
  37. package/dist/components/forms/string-list-field.js +35 -20
  38. package/dist/components/forms/validation-converter.cjs +32 -2
  39. package/dist/components/forms/validation-converter.d.ts +17 -1
  40. package/dist/components/forms/validation-converter.js +30 -3
  41. package/dist/components/forms/value-modes.cjs +253 -0
  42. package/dist/components/forms/value-modes.d.ts +236 -0
  43. package/dist/components/forms/value-modes.js +180 -0
  44. package/dist/components/ui/avatar.d.ts +1 -1
  45. package/dist/components/ui/badge.d.ts +1 -1
  46. package/dist/components/ui/boolean-radio-group.cjs +114 -0
  47. package/dist/components/ui/boolean-radio-group.d.ts +24 -0
  48. package/dist/components/ui/boolean-radio-group.js +77 -0
  49. package/dist/components/ui/button.d.ts +2 -2
  50. package/dist/components/ui/command.d.ts +7 -7
  51. package/dist/components/ui/field-addons/field-menu.cjs +1 -0
  52. package/dist/components/ui/field-addons/field-menu.d.ts +2 -0
  53. package/dist/components/ui/field-addons/field-menu.js +1 -0
  54. package/dist/components/ui/field-addons/index.cjs +4 -0
  55. package/dist/components/ui/field-addons/index.d.ts +1 -0
  56. package/dist/components/ui/field-addons/index.js +2 -1
  57. package/dist/components/ui/field-addons/value-mode-strings.cjs +7 -1
  58. package/dist/components/ui/field-addons/value-mode-strings.d.ts +9 -0
  59. package/dist/components/ui/field-addons/value-mode-strings.js +7 -1
  60. package/dist/components/ui/field-addons/value-mode-switch-dialog.cjs +73 -0
  61. package/dist/components/ui/field-addons/value-mode-switch-dialog.d.ts +16 -0
  62. package/dist/components/ui/field-addons/value-mode-switch-dialog.js +39 -0
  63. package/dist/components/ui/form-field.cjs +2 -1
  64. package/dist/components/ui/form-field.d.ts +2 -0
  65. package/dist/components/ui/form-field.js +2 -1
  66. package/dist/components/ui/index.cjs +230 -186
  67. package/dist/components/ui/index.d.ts +4 -0
  68. package/dist/components/ui/index.js +4 -0
  69. package/dist/components/ui/input-group.cjs +6 -3
  70. package/dist/components/ui/input-group.d.ts +6 -5
  71. package/dist/components/ui/input-group.js +6 -3
  72. package/dist/components/ui/json-tree-view/DecorationChip.cjs +81 -0
  73. package/dist/components/ui/json-tree-view/DecorationChip.d.ts +4 -0
  74. package/dist/components/ui/json-tree-view/DecorationChip.js +47 -0
  75. package/dist/components/ui/json-tree-view/EditorChrome.cjs +88 -0
  76. package/dist/components/ui/json-tree-view/EditorChrome.d.ts +21 -0
  77. package/dist/components/ui/json-tree-view/EditorChrome.js +51 -0
  78. package/dist/components/ui/json-tree-view/JsonContainerEditor.cjs +95 -0
  79. package/dist/components/ui/json-tree-view/JsonContainerEditor.d.ts +18 -0
  80. package/dist/components/ui/json-tree-view/JsonContainerEditor.js +61 -0
  81. package/dist/components/ui/json-tree-view/JsonLeafValueEditor.cjs +86 -0
  82. package/dist/components/ui/json-tree-view/JsonLeafValueEditor.d.ts +12 -0
  83. package/dist/components/ui/json-tree-view/JsonLeafValueEditor.js +52 -0
  84. package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.cjs +74 -0
  85. package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.d.ts +13 -0
  86. package/dist/components/ui/json-tree-view/JsonMultilineLeafEditor.js +40 -0
  87. package/dist/components/ui/json-tree-view/JsonTree.cjs +253 -0
  88. package/dist/components/ui/json-tree-view/JsonTree.d.ts +81 -0
  89. package/dist/components/ui/json-tree-view/JsonTree.js +219 -0
  90. package/dist/components/ui/json-tree-view/JsonTree.types.cjs +18 -0
  91. package/dist/components/ui/json-tree-view/JsonTree.types.d.ts +253 -0
  92. package/dist/components/ui/json-tree-view/JsonTree.types.js +0 -0
  93. package/dist/components/ui/json-tree-view/JsonTreeRow.cjs +284 -0
  94. package/dist/components/ui/json-tree-view/JsonTreeRow.d.ts +50 -0
  95. package/dist/components/ui/json-tree-view/JsonTreeRow.js +244 -0
  96. package/dist/components/ui/json-tree-view/JsonTreeToolbar.cjs +209 -0
  97. package/dist/components/ui/json-tree-view/JsonTreeToolbar.d.ts +35 -0
  98. package/dist/components/ui/json-tree-view/JsonTreeToolbar.js +175 -0
  99. package/dist/components/ui/json-tree-view/JsonTreeTooltip.cjs +84 -0
  100. package/dist/components/ui/json-tree-view/JsonTreeTooltip.d.ts +21 -0
  101. package/dist/components/ui/json-tree-view/JsonTreeTooltip.js +47 -0
  102. package/dist/components/ui/json-tree-view/JsonTypeBadge.cjs +70 -0
  103. package/dist/components/ui/json-tree-view/JsonTypeBadge.d.ts +17 -0
  104. package/dist/components/ui/json-tree-view/JsonTypeBadge.js +36 -0
  105. package/dist/components/ui/json-tree-view/NodeKey.cjs +77 -0
  106. package/dist/components/ui/json-tree-view/NodeKey.d.ts +16 -0
  107. package/dist/components/ui/json-tree-view/NodeKey.js +43 -0
  108. package/dist/components/ui/json-tree-view/RowActions.cjs +120 -0
  109. package/dist/components/ui/json-tree-view/RowActions.d.ts +15 -0
  110. package/dist/components/ui/json-tree-view/RowActions.js +86 -0
  111. package/dist/components/ui/json-tree-view/ScalarValueCell.cjs +112 -0
  112. package/dist/components/ui/json-tree-view/ScalarValueCell.d.ts +18 -0
  113. package/dist/components/ui/json-tree-view/ScalarValueCell.js +75 -0
  114. package/dist/components/ui/json-tree-view/buildJsonTree.cjs +324 -0
  115. package/dist/components/ui/json-tree-view/buildJsonTree.d.ts +75 -0
  116. package/dist/components/ui/json-tree-view/buildJsonTree.js +257 -0
  117. package/dist/components/ui/json-tree-view/clipboard.cjs +63 -0
  118. package/dist/components/ui/json-tree-view/clipboard.d.ts +6 -0
  119. package/dist/components/ui/json-tree-view/clipboard.js +29 -0
  120. package/dist/components/ui/json-tree-view/index.cjs +175 -0
  121. package/dist/components/ui/json-tree-view/index.d.ts +10 -0
  122. package/dist/components/ui/json-tree-view/index.js +11 -0
  123. package/dist/components/ui/json-tree-view/leafEditTypes.cjs +74 -0
  124. package/dist/components/ui/json-tree-view/leafEditTypes.d.ts +12 -0
  125. package/dist/components/ui/json-tree-view/leafEditTypes.js +34 -0
  126. package/dist/components/ui/json-tree-view/strings.cjs +122 -0
  127. package/dist/components/ui/json-tree-view/strings.d.ts +65 -0
  128. package/dist/components/ui/json-tree-view/strings.js +79 -0
  129. package/dist/components/ui/prompt-value-control.cjs +70 -0
  130. package/dist/components/ui/prompt-value-control.d.ts +28 -0
  131. package/dist/components/ui/prompt-value-control.js +36 -0
  132. package/dist/components/ui/sheet.d.ts +1 -1
  133. package/dist/components/ui/spinner.d.ts +1 -1
  134. package/dist/components/ui/switch.d.ts +2 -2
  135. package/dist/components/ui/textarea.cjs +1 -1
  136. package/dist/components/ui/textarea.js +1 -1
  137. package/dist/components/ui/toggle-group.d.ts +2 -2
  138. package/dist/components/ui/toggle.d.ts +2 -2
  139. package/dist/components/ui/variable-value-control.cjs +98 -0
  140. package/dist/components/ui/variable-value-control.d.ts +35 -0
  141. package/dist/components/ui/variable-value-control.js +64 -0
  142. package/dist/index.cjs +145 -16
  143. package/dist/index.d.ts +21 -3
  144. package/dist/index.js +11 -2
  145. package/dist/lib/index.cjs +4 -1
  146. package/dist/lib/index.d.ts +1 -1
  147. package/dist/lib/index.js +2 -2
  148. package/dist/lib/utils.cjs +21 -1
  149. package/dist/lib/utils.d.ts +8 -0
  150. package/dist/lib/utils.js +18 -1
  151. package/dist/styles.css +225 -0
  152. package/package.json +1 -1
@@ -48,9 +48,13 @@ const tabs_cjs_namespaceObject = require("../ui/tabs.cjs");
48
48
  const tooltip_cjs_namespaceObject = require("../ui/tooltip.cjs");
49
49
  const index_cjs_namespaceObject = require("../../lib/index.cjs");
50
50
  const external_data_fetcher_cjs_namespaceObject = require("./data-fetcher.cjs");
51
+ const external_field_actions_cjs_namespaceObject = require("./field-actions.cjs");
51
52
  const external_field_renderer_cjs_namespaceObject = require("./field-renderer.cjs");
53
+ const external_form_strings_cjs_namespaceObject = require("./form-strings.cjs");
54
+ const external_literal_value_context_cjs_namespaceObject = require("./literal-value-context.cjs");
52
55
  const external_rules_engine_cjs_namespaceObject = require("./rules-engine.cjs");
53
56
  const external_validation_converter_cjs_namespaceObject = require("./validation-converter.cjs");
57
+ const external_value_modes_cjs_namespaceObject = require("./value-modes.cjs");
54
58
  const DEFAULT_PLUGINS = [];
55
59
  function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className, disabled = false, autoComplete, stepVariant = 'wizard', sectionVariant = 'card', activeStepId, onActiveStepChange, container = 'form' }) {
56
60
  const [currentStep, setCurrentStep] = (0, external_react_namespaceObject.useState)(0);
@@ -69,12 +73,41 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
69
73
  ...stableSchema.sections ?? [],
70
74
  ...(stableSchema.steps ?? []).flatMap((step)=>step.sections)
71
75
  ];
72
- return sections.some((section)=>section.fields.some((field)=>void 0 !== field.tooltip));
76
+ return sections.some((section)=>section.fields.some((field)=>void 0 !== field.tooltip || void 0 !== field.valueModes || !!field.headerActions));
73
77
  }, [
74
78
  stableSchema
75
79
  ]);
76
- const zodSchema = (0, external_react_namespaceObject.useMemo)(()=>buildZodSchema(stableSchema), [
77
- stableSchema
80
+ const stablePlugins = useShallowStable(plugins);
81
+ const valueModeRegistry = (0, external_react_namespaceObject.useMemo)(()=>(0, external_value_modes_cjs_namespaceObject.buildValueModeRegistry)(stablePlugins), [
82
+ stablePlugins
83
+ ]);
84
+ const fieldActionRegistry = (0, external_react_namespaceObject.useMemo)(()=>(0, external_field_actions_cjs_namespaceObject.buildFieldActionRegistry)(stablePlugins), [
85
+ stablePlugins
86
+ ]);
87
+ const formStrings = (0, external_react_namespaceObject.useMemo)(()=>(0, external_form_strings_cjs_namespaceObject.buildFormStrings)(stablePlugins), [
88
+ stablePlugins
89
+ ]);
90
+ const readLiteralValue = (0, external_react_namespaceObject.useCallback)((name, stored)=>(0, external_value_modes_cjs_namespaceObject.literalValueOf)(name, stored, stableSchema, valueModeRegistry.codecs), [
91
+ stableSchema,
92
+ valueModeRegistry
93
+ ]);
94
+ const formVariables = (0, external_react_namespaceObject.useMemo)(()=>[
95
+ ...stablePlugins
96
+ ].reverse().find((plugin)=>plugin.variables)?.variables, [
97
+ stablePlugins
98
+ ]);
99
+ const codecs = useShallowStable(valueModeRegistry.codecs);
100
+ const validators = useShallowStable(modeValidators(valueModeRegistry));
101
+ const requiredMessage = formStrings.validation.required;
102
+ const zodSchema = (0, external_react_namespaceObject.useMemo)(()=>buildZodSchema(stableSchema, {
103
+ codecs,
104
+ validators,
105
+ requiredMessage
106
+ }), [
107
+ stableSchema,
108
+ codecs,
109
+ validators,
110
+ requiredMessage
78
111
  ]);
79
112
  const form = (0, external_react_hook_form_namespaceObject.useForm)({
80
113
  resolver: (0, standard_schema_namespaceObject.standardSchemaResolver)(zodSchema),
@@ -88,7 +121,9 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
88
121
  pluginsRef.current = plugins;
89
122
  const onSubmitRef = (0, external_react_namespaceObject.useRef)(onSubmit);
90
123
  onSubmitRef.current = onSubmit;
91
- const context = (0, external_react_namespaceObject.useMemo)(()=>({
124
+ const context = (0, external_react_namespaceObject.useMemo)(()=>{
125
+ const readValues = (values)=>(0, external_value_modes_cjs_namespaceObject.literalValues)(values, stableSchema, valueModeRegistry.codecs);
126
+ return {
92
127
  schema: stableSchema,
93
128
  form,
94
129
  get values () {
@@ -104,9 +139,9 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
104
139
  return form.formState.isDirty;
105
140
  },
106
141
  currentStep: stableSchema.steps ? currentStep : void 0,
107
- evaluateConditions: (conditions)=>external_rules_engine_cjs_namespaceObject.RulesEngine.evaluateConditions(conditions, valuesRef.current, 'AND'),
142
+ evaluateConditions: (conditions)=>external_rules_engine_cjs_namespaceObject.RulesEngine.evaluateConditions(conditions, readValues(valuesRef.current), 'AND'),
108
143
  fetchData: async (source)=>{
109
- const result = await external_data_fetcher_cjs_namespaceObject.DataFetcher.fetch(source, valuesRef.current);
144
+ const result = await external_data_fetcher_cjs_namespaceObject.DataFetcher.fetch(source, readValues(valuesRef.current));
110
145
  return result;
111
146
  },
112
147
  registerCustomComponent: (name, component)=>{
@@ -114,11 +149,20 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
114
149
  ...prev,
115
150
  [name]: component
116
151
  }));
117
- }
118
- }), [
152
+ },
153
+ valueModes: valueModeRegistry,
154
+ fieldActions: fieldActionRegistry,
155
+ strings: formStrings,
156
+ variables: formVariables
157
+ };
158
+ }, [
119
159
  stableSchema,
120
160
  form,
121
- currentStep
161
+ currentStep,
162
+ valueModeRegistry,
163
+ fieldActionRegistry,
164
+ formStrings,
165
+ formVariables
122
166
  ]);
123
167
  const contextRef = (0, external_react_namespaceObject.useRef)(context);
124
168
  contextRef.current = context;
@@ -170,13 +214,13 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
170
214
  ]);
171
215
  const allCustomComponents = (0, external_react_namespaceObject.useMemo)(()=>{
172
216
  const fromPlugins = {};
173
- for (const plugin of plugins)Object.assign(fromPlugins, plugin.components);
217
+ for (const plugin of stablePlugins)Object.assign(fromPlugins, plugin.components);
174
218
  return {
175
219
  ...fromPlugins,
176
220
  ...customComponents
177
221
  };
178
222
  }, [
179
- plugins,
223
+ stablePlugins,
180
224
  customComponents
181
225
  ]);
182
226
  const enterSwallowRef = (0, external_react_namespaceObject.useRef)(null);
@@ -248,9 +292,12 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
248
292
  });
249
293
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_hook_form_namespaceObject.FormProvider, {
250
294
  ...form,
251
- children: hasFieldTooltip ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_cjs_namespaceObject.TooltipProvider, {
252
- children: body
253
- }) : body
295
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_literal_value_context_cjs_namespaceObject.LiteralValueContext.Provider, {
296
+ value: readLiteralValue,
297
+ children: hasFieldTooltip ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_cjs_namespaceObject.TooltipProvider, {
298
+ children: body
299
+ }) : body
300
+ })
254
301
  });
255
302
  }
256
303
  function conditionDependencies(conditionGroups) {
@@ -590,7 +637,12 @@ const metadata_form_FormActions = /*#__PURE__*/ external_react_default().memo(fu
590
637
  })
591
638
  });
592
639
  });
593
- function buildZodSchema(schema) {
640
+ function modeValidators(registry) {
641
+ const validators = {};
642
+ for (const [mode, definition] of Object.entries(registry.definitions))if (definition?.validate) validators[mode] = definition.validate;
643
+ return validators;
644
+ }
645
+ function buildZodSchema(schema, { codecs, validators, requiredMessage }) {
594
646
  const shape = {};
595
647
  const fields = schema.steps ? schema.steps.flatMap((step)=>step.sections.flatMap((s)=>s.fields)) : schema.sections?.flatMap((s)=>s.fields) || [];
596
648
  const dynamicValidationFields = [];
@@ -601,33 +653,49 @@ function buildZodSchema(schema) {
601
653
  const hasStaticRequired = field.validation?.required === true;
602
654
  const hasAnyRequired = hasStaticRequired || hasUnconditionalRequired || hasConditionalRequired;
603
655
  if (field.rules && (hasConditionalRequired || hasAnyRequired && hasVisibilityRules)) dynamicValidationFields.push({
656
+ field,
604
657
  name: field.name,
605
658
  rules: field.rules,
606
659
  staticRequired: hasStaticRequired || hasUnconditionalRequired || false,
607
660
  customRequiredMessage: field.validation?.messages?.required
608
661
  });
609
662
  const shouldIncludeRequiredInBase = (hasUnconditionalRequired || hasStaticRequired) && !hasVisibilityRules;
610
- const validationConfig = field.validation ? {
663
+ const baseValidation = field.validation ? {
611
664
  ...field.validation,
612
665
  required: shouldIncludeRequiredInBase
613
666
  } : shouldIncludeRequiredInBase ? {
614
667
  required: true
615
668
  } : void 0;
616
- shape[field.name] = (0, external_validation_converter_cjs_namespaceObject.validationConfigToZod)(validationConfig, field.type, 'custom' === field.type ? field.valueType : void 0);
669
+ const validationConfig = baseValidation?.required ? {
670
+ ...baseValidation,
671
+ messages: {
672
+ ...baseValidation.messages,
673
+ required: baseValidation.messages?.required || requiredMessage
674
+ }
675
+ } : baseValidation;
676
+ const fieldTypeSchema = (0, external_validation_converter_cjs_namespaceObject.validationConfigToZod)(validationConfig, field.type, 'custom' === field.type ? field.valueType : void 0);
677
+ shape[field.name] = field.valueModes ? (0, external_validation_converter_cjs_namespaceObject.modeAwareSchema)(fieldTypeSchema, {
678
+ codec: (0, external_value_modes_cjs_namespaceObject.resolveCodec)(codecs, field.valueModes),
679
+ context: (0, external_value_modes_cjs_namespaceObject.codecContext)(field, field.valueModes),
680
+ required: shouldIncludeRequiredInBase,
681
+ requiredMessage: field.validation?.messages?.required ?? requiredMessage,
682
+ validators
683
+ }) : fieldTypeSchema;
617
684
  });
618
685
  const baseSchema = v4_namespaceObject.z.object(shape);
619
686
  if (0 === dynamicValidationFields.length) return baseSchema;
620
687
  return baseSchema.superRefine((data, ctx)=>{
621
- const values = data;
622
- for (const { name, rules, staticRequired, customRequiredMessage } of dynamicValidationFields){
688
+ const stored = data;
689
+ const values = (0, external_value_modes_cjs_namespaceObject.literalValues)(stored, schema, codecs);
690
+ for (const { field, name, rules, staticRequired, customRequiredMessage } of dynamicValidationFields){
623
691
  const isVisible = external_rules_engine_cjs_namespaceObject.RulesEngine.isFieldVisible(rules, values);
624
692
  if (!isVisible) continue;
625
693
  const ruleResult = external_rules_engine_cjs_namespaceObject.RulesEngine.applyRules(rules, values, {});
626
694
  const isRequired = true === ruleResult.required || staticRequired;
627
695
  if (isRequired) {
628
- if ((0, external_validation_converter_cjs_namespaceObject.isEmptyFieldValue)(values[name])) ctx.addIssue({
696
+ if ((0, external_value_modes_cjs_namespaceObject.isEmptyModeValue)(stored[name], field, codecs)) ctx.addIssue({
629
697
  code: v4_namespaceObject.z.ZodIssueCode.custom,
630
- message: customRequiredMessage || 'This field is required',
698
+ message: customRequiredMessage || requiredMessage,
631
699
  path: [
632
700
  name
633
701
  ]
@@ -636,6 +704,17 @@ function buildZodSchema(schema) {
636
704
  }
637
705
  });
638
706
  }
707
+ function useShallowStable(value) {
708
+ const ref = (0, external_react_namespaceObject.useRef)(value);
709
+ if (!shallowEqual(ref.current, value)) ref.current = value;
710
+ return ref.current;
711
+ }
712
+ function shallowEqual(a, b) {
713
+ if (a === b) return true;
714
+ const aKeys = Object.keys(a);
715
+ const bKeys = Object.keys(b);
716
+ return aKeys.length === bKeys.length && aKeys.every((key)=>key in b && a[key] === b[key]);
717
+ }
639
718
  async function loadInitialData(initialData, _context) {
640
719
  if (!initialData) return {};
641
720
  return initialData;
@@ -6,6 +6,11 @@ export { useWatch } from 'react-hook-form';
6
6
  */
7
7
  export interface MetadataFormProps {
8
8
  schema: FormSchema;
9
+ /**
10
+ * Keep each plugin object stable (a module constant or memoized): a new plugin object rebuilds
11
+ * the registries, re-renders every field and, when its codecs or validators change, rebuilds the
12
+ * validation schema. A new array holding the same plugins is fine.
13
+ */
9
14
  plugins?: FormPlugin[];
10
15
  onSubmit?: (data: unknown) => void | Promise<void>;
11
16
  className?: string;
@@ -9,9 +9,13 @@ import { ScrollableTabsList, Tabs, TabsContent, TabsTrigger } from "../ui/tabs.j
9
9
  import { TooltipProvider } from "../ui/tooltip.js";
10
10
  import { deepEqual, get } from "../../lib/index.js";
11
11
  import { DataFetcher } from "./data-fetcher.js";
12
+ import { buildFieldActionRegistry } from "./field-actions.js";
12
13
  import { FormFieldRenderer } from "./field-renderer.js";
14
+ import { buildFormStrings } from "./form-strings.js";
15
+ import { LiteralValueContext } from "./literal-value-context.js";
13
16
  import { RulesEngine } from "./rules-engine.js";
14
- import { isEmptyFieldValue, validationConfigToZod } from "./validation-converter.js";
17
+ import { modeAwareSchema, validationConfigToZod } from "./validation-converter.js";
18
+ import { buildValueModeRegistry, codecContext, isEmptyModeValue, literalValueOf, literalValues, resolveCodec } from "./value-modes.js";
15
19
  const DEFAULT_PLUGINS = [];
16
20
  function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className, disabled = false, autoComplete, stepVariant = 'wizard', sectionVariant = 'card', activeStepId, onActiveStepChange, container = 'form' }) {
17
21
  const [currentStep, setCurrentStep] = useState(0);
@@ -30,12 +34,41 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
30
34
  ...stableSchema.sections ?? [],
31
35
  ...(stableSchema.steps ?? []).flatMap((step)=>step.sections)
32
36
  ];
33
- return sections.some((section)=>section.fields.some((field)=>void 0 !== field.tooltip));
37
+ return sections.some((section)=>section.fields.some((field)=>void 0 !== field.tooltip || void 0 !== field.valueModes || !!field.headerActions));
34
38
  }, [
35
39
  stableSchema
36
40
  ]);
37
- const zodSchema = useMemo(()=>buildZodSchema(stableSchema), [
38
- stableSchema
41
+ const stablePlugins = useShallowStable(plugins);
42
+ const valueModeRegistry = useMemo(()=>buildValueModeRegistry(stablePlugins), [
43
+ stablePlugins
44
+ ]);
45
+ const fieldActionRegistry = useMemo(()=>buildFieldActionRegistry(stablePlugins), [
46
+ stablePlugins
47
+ ]);
48
+ const formStrings = useMemo(()=>buildFormStrings(stablePlugins), [
49
+ stablePlugins
50
+ ]);
51
+ const readLiteralValue = useCallback((name, stored)=>literalValueOf(name, stored, stableSchema, valueModeRegistry.codecs), [
52
+ stableSchema,
53
+ valueModeRegistry
54
+ ]);
55
+ const formVariables = useMemo(()=>[
56
+ ...stablePlugins
57
+ ].reverse().find((plugin)=>plugin.variables)?.variables, [
58
+ stablePlugins
59
+ ]);
60
+ const codecs = useShallowStable(valueModeRegistry.codecs);
61
+ const validators = useShallowStable(modeValidators(valueModeRegistry));
62
+ const requiredMessage = formStrings.validation.required;
63
+ const zodSchema = useMemo(()=>buildZodSchema(stableSchema, {
64
+ codecs,
65
+ validators,
66
+ requiredMessage
67
+ }), [
68
+ stableSchema,
69
+ codecs,
70
+ validators,
71
+ requiredMessage
39
72
  ]);
40
73
  const form = useForm({
41
74
  resolver: standardSchemaResolver(zodSchema),
@@ -49,7 +82,9 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
49
82
  pluginsRef.current = plugins;
50
83
  const onSubmitRef = useRef(onSubmit);
51
84
  onSubmitRef.current = onSubmit;
52
- const context = useMemo(()=>({
85
+ const context = useMemo(()=>{
86
+ const readValues = (values)=>literalValues(values, stableSchema, valueModeRegistry.codecs);
87
+ return {
53
88
  schema: stableSchema,
54
89
  form,
55
90
  get values () {
@@ -65,9 +100,9 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
65
100
  return form.formState.isDirty;
66
101
  },
67
102
  currentStep: stableSchema.steps ? currentStep : void 0,
68
- evaluateConditions: (conditions)=>RulesEngine.evaluateConditions(conditions, valuesRef.current, 'AND'),
103
+ evaluateConditions: (conditions)=>RulesEngine.evaluateConditions(conditions, readValues(valuesRef.current), 'AND'),
69
104
  fetchData: async (source)=>{
70
- const result = await DataFetcher.fetch(source, valuesRef.current);
105
+ const result = await DataFetcher.fetch(source, readValues(valuesRef.current));
71
106
  return result;
72
107
  },
73
108
  registerCustomComponent: (name, component)=>{
@@ -75,11 +110,20 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
75
110
  ...prev,
76
111
  [name]: component
77
112
  }));
78
- }
79
- }), [
113
+ },
114
+ valueModes: valueModeRegistry,
115
+ fieldActions: fieldActionRegistry,
116
+ strings: formStrings,
117
+ variables: formVariables
118
+ };
119
+ }, [
80
120
  stableSchema,
81
121
  form,
82
- currentStep
122
+ currentStep,
123
+ valueModeRegistry,
124
+ fieldActionRegistry,
125
+ formStrings,
126
+ formVariables
83
127
  ]);
84
128
  const contextRef = useRef(context);
85
129
  contextRef.current = context;
@@ -131,13 +175,13 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
131
175
  ]);
132
176
  const allCustomComponents = useMemo(()=>{
133
177
  const fromPlugins = {};
134
- for (const plugin of plugins)Object.assign(fromPlugins, plugin.components);
178
+ for (const plugin of stablePlugins)Object.assign(fromPlugins, plugin.components);
135
179
  return {
136
180
  ...fromPlugins,
137
181
  ...customComponents
138
182
  };
139
183
  }, [
140
- plugins,
184
+ stablePlugins,
141
185
  customComponents
142
186
  ]);
143
187
  const enterSwallowRef = useRef(null);
@@ -209,9 +253,12 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
209
253
  });
210
254
  return /*#__PURE__*/ jsx(FormProvider, {
211
255
  ...form,
212
- children: hasFieldTooltip ? /*#__PURE__*/ jsx(TooltipProvider, {
213
- children: body
214
- }) : body
256
+ children: /*#__PURE__*/ jsx(LiteralValueContext.Provider, {
257
+ value: readLiteralValue,
258
+ children: hasFieldTooltip ? /*#__PURE__*/ jsx(TooltipProvider, {
259
+ children: body
260
+ }) : body
261
+ })
215
262
  });
216
263
  }
217
264
  function conditionDependencies(conditionGroups) {
@@ -551,7 +598,12 @@ const metadata_form_FormActions = /*#__PURE__*/ react.memo(function({ schema, co
551
598
  })
552
599
  });
553
600
  });
554
- function buildZodSchema(schema) {
601
+ function modeValidators(registry) {
602
+ const validators = {};
603
+ for (const [mode, definition] of Object.entries(registry.definitions))if (definition?.validate) validators[mode] = definition.validate;
604
+ return validators;
605
+ }
606
+ function buildZodSchema(schema, { codecs, validators, requiredMessage }) {
555
607
  const shape = {};
556
608
  const fields = schema.steps ? schema.steps.flatMap((step)=>step.sections.flatMap((s)=>s.fields)) : schema.sections?.flatMap((s)=>s.fields) || [];
557
609
  const dynamicValidationFields = [];
@@ -562,33 +614,49 @@ function buildZodSchema(schema) {
562
614
  const hasStaticRequired = field.validation?.required === true;
563
615
  const hasAnyRequired = hasStaticRequired || hasUnconditionalRequired || hasConditionalRequired;
564
616
  if (field.rules && (hasConditionalRequired || hasAnyRequired && hasVisibilityRules)) dynamicValidationFields.push({
617
+ field,
565
618
  name: field.name,
566
619
  rules: field.rules,
567
620
  staticRequired: hasStaticRequired || hasUnconditionalRequired || false,
568
621
  customRequiredMessage: field.validation?.messages?.required
569
622
  });
570
623
  const shouldIncludeRequiredInBase = (hasUnconditionalRequired || hasStaticRequired) && !hasVisibilityRules;
571
- const validationConfig = field.validation ? {
624
+ const baseValidation = field.validation ? {
572
625
  ...field.validation,
573
626
  required: shouldIncludeRequiredInBase
574
627
  } : shouldIncludeRequiredInBase ? {
575
628
  required: true
576
629
  } : void 0;
577
- shape[field.name] = validationConfigToZod(validationConfig, field.type, 'custom' === field.type ? field.valueType : void 0);
630
+ const validationConfig = baseValidation?.required ? {
631
+ ...baseValidation,
632
+ messages: {
633
+ ...baseValidation.messages,
634
+ required: baseValidation.messages?.required || requiredMessage
635
+ }
636
+ } : baseValidation;
637
+ const fieldTypeSchema = validationConfigToZod(validationConfig, field.type, 'custom' === field.type ? field.valueType : void 0);
638
+ shape[field.name] = field.valueModes ? modeAwareSchema(fieldTypeSchema, {
639
+ codec: resolveCodec(codecs, field.valueModes),
640
+ context: codecContext(field, field.valueModes),
641
+ required: shouldIncludeRequiredInBase,
642
+ requiredMessage: field.validation?.messages?.required ?? requiredMessage,
643
+ validators
644
+ }) : fieldTypeSchema;
578
645
  });
579
646
  const baseSchema = z.object(shape);
580
647
  if (0 === dynamicValidationFields.length) return baseSchema;
581
648
  return baseSchema.superRefine((data, ctx)=>{
582
- const values = data;
583
- for (const { name, rules, staticRequired, customRequiredMessage } of dynamicValidationFields){
649
+ const stored = data;
650
+ const values = literalValues(stored, schema, codecs);
651
+ for (const { field, name, rules, staticRequired, customRequiredMessage } of dynamicValidationFields){
584
652
  const isVisible = RulesEngine.isFieldVisible(rules, values);
585
653
  if (!isVisible) continue;
586
654
  const ruleResult = RulesEngine.applyRules(rules, values, {});
587
655
  const isRequired = true === ruleResult.required || staticRequired;
588
656
  if (isRequired) {
589
- if (isEmptyFieldValue(values[name])) ctx.addIssue({
657
+ if (isEmptyModeValue(stored[name], field, codecs)) ctx.addIssue({
590
658
  code: z.ZodIssueCode.custom,
591
- message: customRequiredMessage || 'This field is required',
659
+ message: customRequiredMessage || requiredMessage,
592
660
  path: [
593
661
  name
594
662
  ]
@@ -597,6 +665,17 @@ function buildZodSchema(schema) {
597
665
  }
598
666
  });
599
667
  }
668
+ function useShallowStable(value) {
669
+ const ref = useRef(value);
670
+ if (!shallowEqual(ref.current, value)) ref.current = value;
671
+ return ref.current;
672
+ }
673
+ function shallowEqual(a, b) {
674
+ if (a === b) return true;
675
+ const aKeys = Object.keys(a);
676
+ const bKeys = Object.keys(b);
677
+ return aKeys.length === bKeys.length && aKeys.every((key)=>key in b && a[key] === b[key]);
678
+ }
600
679
  async function loadInitialData(initialData, _context) {
601
680
  if (!initialData) return {};
602
681
  return initialData;