@uipath/apollo-wind 2.47.0 → 2.47.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.
@@ -132,19 +132,23 @@ function FormFieldRenderer({ field, context, customComponents, disabled: formDis
132
132
  getValues,
133
133
  watchedRuleDependentValues
134
134
  ]);
135
+ const isOptionsField = (0, external_form_schema_cjs_namespaceObject.hasOptions)(field);
136
+ const inlineOptions = isOptionsField ? field.options : void 0;
135
137
  (0, external_react_namespaceObject.useEffect)(()=>{
136
138
  if (field.dataSource) return;
137
- if (!(0, external_form_schema_cjs_namespaceObject.hasOptions)(field)) return;
138
- const inlineOptions = field.options || [];
139
+ if (!isOptionsField) return;
140
+ const nextOptions = inlineOptions || [];
139
141
  setFieldState((prev)=>{
140
- if ((0, index_cjs_namespaceObject.deepEqual)(prev.options, inlineOptions)) return prev;
142
+ if ((0, index_cjs_namespaceObject.deepEqual)(prev.options, nextOptions)) return prev;
141
143
  return {
142
144
  ...prev,
143
- options: inlineOptions
145
+ options: nextOptions
144
146
  };
145
147
  });
146
148
  }, [
147
- field
149
+ field.dataSource,
150
+ isOptionsField,
151
+ inlineOptions
148
152
  ]);
149
153
  (0, external_react_namespaceObject.useEffect)(()=>{
150
154
  if (!field.dataSource) return;
@@ -104,19 +104,23 @@ function FormFieldRenderer({ field, context, customComponents, disabled: formDis
104
104
  getValues,
105
105
  watchedRuleDependentValues
106
106
  ]);
107
+ const isOptionsField = hasOptions(field);
108
+ const inlineOptions = isOptionsField ? field.options : void 0;
107
109
  useEffect(()=>{
108
110
  if (field.dataSource) return;
109
- if (!hasOptions(field)) return;
110
- const inlineOptions = field.options || [];
111
+ if (!isOptionsField) return;
112
+ const nextOptions = inlineOptions || [];
111
113
  setFieldState((prev)=>{
112
- if (deepEqual(prev.options, inlineOptions)) return prev;
114
+ if (deepEqual(prev.options, nextOptions)) return prev;
113
115
  return {
114
116
  ...prev,
115
- options: inlineOptions
117
+ options: nextOptions
116
118
  };
117
119
  });
118
120
  }, [
119
- field
121
+ field.dataSource,
122
+ isOptionsField,
123
+ inlineOptions
120
124
  ]);
121
125
  useEffect(()=>{
122
126
  if (!field.dataSource) return;
@@ -27,16 +27,20 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  FormStateViewer: ()=>FormStateViewer
28
28
  });
29
29
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
30
+ const external_lucide_react_namespaceObject = require("lucide-react");
30
31
  const external_react_namespaceObject = require("react");
32
+ const external_react_hook_form_namespaceObject = require("react-hook-form");
31
33
  const badge_cjs_namespaceObject = require("../ui/badge.cjs");
32
34
  const card_cjs_namespaceObject = require("../ui/card.cjs");
33
- const tabs_cjs_namespaceObject = require("../ui/tabs.cjs");
34
35
  const scroll_area_cjs_namespaceObject = require("../ui/scroll-area.cjs");
35
- const external_lucide_react_namespaceObject = require("lucide-react");
36
+ const tabs_cjs_namespaceObject = require("../ui/tabs.cjs");
36
37
  function FormStateViewer({ form, title = 'Form State', className = '', compact = false }) {
37
38
  const [activeTab, setActiveTab] = (0, external_react_namespaceObject.useState)('values');
38
- const { formState, watch } = form;
39
- const values = watch();
39
+ const { formState, control, getValues } = form;
40
+ (0, external_react_hook_form_namespaceObject.useWatch)({
41
+ control
42
+ });
43
+ const values = getValues();
40
44
  const stats = {
41
45
  isValid: formState.isValid,
42
46
  isDirty: formState.isDirty,
@@ -1,4 +1,4 @@
1
- import type { UseFormReturn, FieldValues } from 'react-hook-form';
1
+ import { type FieldValues, type UseFormReturn } from 'react-hook-form';
2
2
  /**
3
3
  * FormStateViewer Component
4
4
  *
@@ -1,14 +1,18 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AlertCircle, CheckCircle2, Database, Eye, FileEdit, XCircle } from "lucide-react";
2
3
  import { useState } from "react";
4
+ import { useWatch } from "react-hook-form";
3
5
  import { Badge } from "../ui/badge.js";
4
6
  import { Card } from "../ui/card.js";
5
- import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs.js";
6
7
  import { ScrollArea } from "../ui/scroll-area.js";
7
- import { AlertCircle, CheckCircle2, Database, Eye, FileEdit, XCircle } from "lucide-react";
8
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs.js";
8
9
  function FormStateViewer({ form, title = 'Form State', className = '', compact = false }) {
9
10
  const [activeTab, setActiveTab] = useState('values');
10
- const { formState, watch } = form;
11
- const values = watch();
11
+ const { formState, control, getValues } = form;
12
+ useWatch({
13
+ control
14
+ });
15
+ const values = getValues();
12
16
  const stats = {
13
17
  isValid: formState.isValid,
14
18
  isDirty: formState.isDirty,
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
3
12
  (()=>{
4
13
  __webpack_require__.d = (exports1, definition)=>{
5
14
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -29,11 +38,13 @@ __webpack_require__.d(__webpack_exports__, {
29
38
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
30
39
  const standard_schema_namespaceObject = require("@hookform/resolvers/standard-schema");
31
40
  const external_react_namespaceObject = require("react");
41
+ var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
32
42
  const external_react_hook_form_namespaceObject = require("react-hook-form");
33
43
  const v4_namespaceObject = require("zod/v4");
34
44
  const accordion_cjs_namespaceObject = require("../ui/accordion.cjs");
35
45
  const button_cjs_namespaceObject = require("../ui/button.cjs");
36
46
  const tabs_cjs_namespaceObject = require("../ui/tabs.cjs");
47
+ const index_cjs_namespaceObject = require("../../lib/index.cjs");
37
48
  const external_data_fetcher_cjs_namespaceObject = require("./data-fetcher.cjs");
38
49
  const external_field_renderer_cjs_namespaceObject = require("./field-renderer.cjs");
39
50
  const external_rules_engine_cjs_namespaceObject = require("./rules-engine.cjs");
@@ -43,20 +54,31 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
43
54
  const [currentStep, setCurrentStep] = (0, external_react_namespaceObject.useState)(0);
44
55
  const [customComponents, setCustomComponents] = (0, external_react_namespaceObject.useState)({});
45
56
  const [isInitialized, setIsInitialized] = (0, external_react_namespaceObject.useState)(false);
46
- const zodSchema = (0, external_react_namespaceObject.useMemo)(()=>buildZodSchema(schema), [
57
+ const schemaRef = (0, external_react_namespaceObject.useRef)(schema);
58
+ const stableSchema = (0, external_react_namespaceObject.useMemo)(()=>{
59
+ if ((0, index_cjs_namespaceObject.deepEqual)(schemaRef.current, schema)) return schemaRef.current;
60
+ schemaRef.current = schema;
61
+ return schema;
62
+ }, [
47
63
  schema
48
64
  ]);
65
+ const zodSchema = (0, external_react_namespaceObject.useMemo)(()=>buildZodSchema(stableSchema), [
66
+ stableSchema
67
+ ]);
49
68
  const form = (0, external_react_hook_form_namespaceObject.useForm)({
50
69
  resolver: (0, standard_schema_namespaceObject.standardSchemaResolver)(zodSchema),
51
- mode: schema.mode || 'onSubmit',
52
- reValidateMode: schema.reValidateMode || 'onChange'
70
+ defaultValues: stableSchema.initialData || {},
71
+ mode: stableSchema.mode || 'onSubmit',
72
+ reValidateMode: stableSchema.reValidateMode || 'onChange'
53
73
  });
54
74
  const { watch, handleSubmit, reset } = form;
55
- const valuesRef = (0, external_react_namespaceObject.useRef)({});
56
- const watchedValues = watch();
57
- valuesRef.current = watchedValues;
75
+ const valuesRef = (0, external_react_namespaceObject.useRef)(form.getValues());
76
+ const pluginsRef = (0, external_react_namespaceObject.useRef)(plugins);
77
+ pluginsRef.current = plugins;
78
+ const onSubmitRef = (0, external_react_namespaceObject.useRef)(onSubmit);
79
+ onSubmitRef.current = onSubmit;
58
80
  const context = (0, external_react_namespaceObject.useMemo)(()=>({
59
- schema,
81
+ schema: stableSchema,
60
82
  form,
61
83
  get values () {
62
84
  return valuesRef.current;
@@ -70,7 +92,7 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
70
92
  get isDirty () {
71
93
  return form.formState.isDirty;
72
94
  },
73
- currentStep: schema.steps ? currentStep : void 0,
95
+ currentStep: stableSchema.steps ? currentStep : void 0,
74
96
  evaluateConditions: (conditions)=>external_rules_engine_cjs_namespaceObject.RulesEngine.evaluateConditions(conditions, valuesRef.current, 'AND'),
75
97
  fetchData: async (source)=>{
76
98
  const result = await external_data_fetcher_cjs_namespaceObject.DataFetcher.fetch(source, valuesRef.current);
@@ -83,17 +105,31 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
83
105
  }));
84
106
  }
85
107
  }), [
86
- schema,
108
+ stableSchema,
87
109
  form,
88
110
  currentStep
89
111
  ]);
90
112
  const contextRef = (0, external_react_namespaceObject.useRef)(context);
91
113
  contextRef.current = context;
114
+ const isInitializedRef = (0, external_react_namespaceObject.useRef)(isInitialized);
115
+ isInitializedRef.current = isInitialized;
116
+ (0, external_react_namespaceObject.useEffect)(()=>{
117
+ const subscription = watch((value, { name })=>{
118
+ valuesRef.current = value;
119
+ if (!name || !isInitializedRef.current) return;
120
+ pluginsRef.current.forEach((plugin)=>{
121
+ plugin.onValueChange?.(name, (0, index_cjs_namespaceObject.get)(value, name), contextRef.current);
122
+ });
123
+ });
124
+ return ()=>subscription.unsubscribe();
125
+ }, [
126
+ watch
127
+ ]);
92
128
  (0, external_react_namespaceObject.useEffect)(()=>{
93
129
  if (isInitialized) return;
94
130
  const initializeForm = async ()=>{
95
- if (schema.initialData) {
96
- const data = await loadInitialData(schema.initialData, contextRef.current);
131
+ if (stableSchema.initialData) {
132
+ const data = await loadInitialData(stableSchema.initialData, contextRef.current);
97
133
  reset(data);
98
134
  }
99
135
  for (const plugin of plugins)await plugin.onFormInit?.(contextRef.current);
@@ -103,41 +139,30 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
103
139
  }, [
104
140
  isInitialized
105
141
  ]);
106
- (0, external_react_namespaceObject.useEffect)(()=>{
107
- if (!isInitialized) return;
108
- const subscription = watch((value, { name })=>{
109
- if (name) {
110
- valuesRef.current = value;
111
- plugins.forEach((plugin)=>{
112
- plugin.onValueChange?.(name, value[name], contextRef.current);
113
- });
114
- }
115
- });
116
- return ()=>subscription.unsubscribe();
117
- }, [
118
- watch,
119
- isInitialized,
120
- plugins
142
+ const handleFormSubmit = (0, external_react_namespaceObject.useMemo)(()=>handleSubmit(async (data)=>{
143
+ let finalData = data;
144
+ for (const plugin of pluginsRef.current)if (plugin.onSubmit) finalData = await plugin.onSubmit(finalData, contextRef.current) || finalData;
145
+ if (onSubmitRef.current) await onSubmitRef.current(finalData);
146
+ }), [
147
+ handleSubmit
148
+ ]);
149
+ const handleReset = (0, external_react_namespaceObject.useCallback)(()=>reset(), [
150
+ reset
121
151
  ]);
122
- const handleFormSubmit = handleSubmit(async (data)=>{
123
- let finalData = data;
124
- for (const plugin of plugins)if (plugin.onSubmit) finalData = await plugin.onSubmit(finalData, context) || finalData;
125
- if (onSubmit) await onSubmit(finalData);
126
- });
127
152
  const renderContent = ()=>{
128
- if (schema.steps) {
153
+ if (stableSchema.steps) {
129
154
  if ('tabs' === stepVariant) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(TabbedStepForm, {
130
- schema: schema,
155
+ schema: stableSchema,
131
156
  context: context,
132
157
  customComponents: customComponents,
133
158
  disabled: disabled,
134
159
  sectionVariant: sectionVariant,
135
160
  activeStepId: activeStepId,
136
161
  onActiveStepChange: onActiveStepChange,
137
- onReset: ()=>reset()
162
+ onReset: handleReset
138
163
  });
139
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(MultiStepForm, {
140
- schema: schema,
164
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_MultiStepForm, {
165
+ schema: stableSchema,
141
166
  context: context,
142
167
  currentStep: currentStep,
143
168
  setCurrentStep: setCurrentStep,
@@ -146,8 +171,8 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
146
171
  sectionVariant: sectionVariant
147
172
  });
148
173
  }
149
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SinglePageForm, {
150
- schema: schema,
174
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_SinglePageForm, {
175
+ schema: stableSchema,
151
176
  context: context,
152
177
  customComponents: customComponents,
153
178
  disabled: disabled,
@@ -162,21 +187,36 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
162
187
  autoComplete: autoComplete,
163
188
  children: [
164
189
  renderContent(),
165
- !schema.steps && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FormActions, {
166
- schema: schema,
190
+ !stableSchema.steps && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_FormActions, {
191
+ schema: stableSchema,
167
192
  context: context,
168
- onReset: ()=>reset()
193
+ onReset: handleReset
169
194
  })
170
195
  ]
171
196
  })
172
197
  });
173
198
  }
174
- function SinglePageForm({ schema, context, customComponents, disabled, sectionVariant }) {
199
+ function conditionDependencies(conditionGroups) {
200
+ const fields = new Set();
201
+ for (const conditions of conditionGroups)for (const condition of conditions || [])if (condition.when) fields.add(condition.when);
202
+ return Array.from(fields);
203
+ }
204
+ function useConditionDependencies(context, conditionFields) {
205
+ (0, external_react_hook_form_namespaceObject.useWatch)({
206
+ control: context.form.control,
207
+ name: conditionFields
208
+ });
209
+ }
210
+ const metadata_form_SinglePageForm = /*#__PURE__*/ external_react_default().memo(function({ schema, context, customComponents, disabled, sectionVariant }) {
175
211
  const sections = schema.sections || [];
212
+ const conditionFields = (0, external_react_namespaceObject.useMemo)(()=>conditionDependencies(schema.sections?.map((section)=>section.conditions) ?? []), [
213
+ schema
214
+ ]);
215
+ useConditionDependencies(context, conditionFields);
176
216
  const visibleSections = sections.filter((section)=>!section.conditions || context.evaluateConditions(section.conditions));
177
217
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
178
218
  className: 'plain' === sectionVariant ? void 0 : 'space-y-2',
179
- children: visibleSections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FormSection, {
219
+ children: visibleSections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_FormSection, {
180
220
  section: section,
181
221
  context: context,
182
222
  customComponents: customComponents,
@@ -184,15 +224,30 @@ function SinglePageForm({ schema, context, customComponents, disabled, sectionVa
184
224
  sectionVariant: sectionVariant
185
225
  }, section.id))
186
226
  });
187
- }
188
- function MultiStepForm({ schema, context, currentStep, setCurrentStep, customComponents, disabled, sectionVariant }) {
227
+ });
228
+ const metadata_form_MultiStepForm = /*#__PURE__*/ external_react_default().memo(function({ schema, context, currentStep, setCurrentStep, customComponents, disabled, sectionVariant }) {
189
229
  const steps = schema.steps || [];
190
- const step = steps[currentStep];
191
- if (!step) return null;
192
- if (step.conditions && !context.evaluateConditions(step.conditions)) {
193
- if (currentStep < steps.length - 1) setCurrentStep(currentStep + 1);
194
- return null;
230
+ const conditionFields = (0, external_react_namespaceObject.useMemo)(()=>conditionDependencies(schema.steps?.map((step)=>step.conditions) ?? []), [
231
+ schema
232
+ ]);
233
+ useConditionDependencies(context, conditionFields);
234
+ let visibleStepIndex = -1;
235
+ for(let i = currentStep; i < steps.length; i++){
236
+ const candidate = steps[i];
237
+ if (!candidate.conditions || context.evaluateConditions(candidate.conditions)) {
238
+ visibleStepIndex = i;
239
+ break;
240
+ }
195
241
  }
242
+ (0, external_react_namespaceObject.useEffect)(()=>{
243
+ if (-1 !== visibleStepIndex && visibleStepIndex !== currentStep) setCurrentStep(visibleStepIndex);
244
+ }, [
245
+ visibleStepIndex,
246
+ currentStep,
247
+ setCurrentStep
248
+ ]);
249
+ const step = -1 !== visibleStepIndex ? steps[visibleStepIndex] : void 0;
250
+ if (!step || visibleStepIndex !== currentStep) return null;
196
251
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
197
252
  className: "space-y-6",
198
253
  children: [
@@ -224,7 +279,7 @@ function MultiStepForm({ schema, context, currentStep, setCurrentStep, customCom
224
279
  }),
225
280
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
226
281
  className: 'plain' === sectionVariant ? void 0 : 'space-y-2',
227
- children: step.sections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FormSection, {
282
+ children: step.sections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_FormSection, {
228
283
  section: section,
229
284
  context: context,
230
285
  customComponents: customComponents,
@@ -256,9 +311,16 @@ function MultiStepForm({ schema, context, currentStep, setCurrentStep, customCom
256
311
  })
257
312
  ]
258
313
  });
259
- }
314
+ });
260
315
  function TabbedStepForm({ schema, context, customComponents, disabled, sectionVariant, onReset, activeStepId, onActiveStepChange }) {
261
316
  const steps = schema.steps || [];
317
+ const conditionFields = (0, external_react_namespaceObject.useMemo)(()=>conditionDependencies(schema.steps?.flatMap((step)=>[
318
+ step.conditions,
319
+ ...step.sections.map((section)=>section.conditions)
320
+ ]) ?? []), [
321
+ schema
322
+ ]);
323
+ useConditionDependencies(context, conditionFields);
262
324
  const visibleSteps = steps.filter((step)=>{
263
325
  if (step.conditions && !context.evaluateConditions(step.conditions)) return false;
264
326
  const hasVisibleSection = step.sections.some((section)=>!section.conditions || context.evaluateConditions(section.conditions));
@@ -334,7 +396,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
334
396
  children: step.emptyState
335
397
  }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
336
398
  className: 'plain' === sectionVariant ? 'pb-6 [padding-inline:var(--mf-content-inset,0px)]' : 'space-y-2 pb-6 pt-4 [padding-inline:var(--mf-content-inset,0px)]',
337
- children: stepSections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FormSection, {
399
+ children: stepSections.map((section)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_FormSection, {
338
400
  section: section,
339
401
  context: context,
340
402
  customComponents: customComponents,
@@ -346,7 +408,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
346
408
  })
347
409
  ]
348
410
  }),
349
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(FormActions, {
411
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(metadata_form_FormActions, {
350
412
  schema: schema,
351
413
  context: context,
352
414
  onReset: onReset
@@ -354,7 +416,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
354
416
  ]
355
417
  });
356
418
  }
357
- function FormSection({ section, context, customComponents, disabled, sectionVariant = 'card' }) {
419
+ const metadata_form_FormSection = /*#__PURE__*/ external_react_default().memo(function({ section, context, customComponents, disabled, sectionVariant = 'card' }) {
358
420
  const gridColumns = context.schema.layout?.columns || 1;
359
421
  const gap = context.schema.layout?.gap || 4;
360
422
  const isPlain = 'plain' === sectionVariant;
@@ -430,8 +492,15 @@ function FormSection({ section, context, customComponents, disabled, sectionVari
430
492
  })
431
493
  ]
432
494
  });
433
- }
434
- function FormActions({ schema, context, onReset }) {
495
+ });
496
+ const metadata_form_FormActions = /*#__PURE__*/ external_react_default().memo(function({ schema, context, onReset }) {
497
+ const { isSubmitting } = (0, external_react_hook_form_namespaceObject.useFormState)({
498
+ control: context.form.control
499
+ });
500
+ const conditionFields = (0, external_react_namespaceObject.useMemo)(()=>conditionDependencies(schema.actions?.map((action)=>action.conditions) ?? []), [
501
+ schema
502
+ ]);
503
+ useConditionDependencies(context, conditionFields);
435
504
  const actions = schema.actions || [
436
505
  {
437
506
  id: 'submit',
@@ -455,12 +524,12 @@ function FormActions({ schema, context, onReset }) {
455
524
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(button_cjs_namespaceObject.Button, {
456
525
  type: 'submit' === action.type ? 'submit' : 'button',
457
526
  variant: action.variant || 'default',
458
- disabled: action.disabled || 'submit' === action.type && context.isSubmitting,
459
- children: action.loading && context.isSubmitting ? 'Loading...' : action.label
527
+ disabled: action.disabled || 'submit' === action.type && isSubmitting,
528
+ children: action.loading && isSubmitting ? 'Loading...' : action.label
460
529
  }, action.id);
461
530
  })
462
531
  });
463
- }
532
+ });
464
533
  function buildZodSchema(schema) {
465
534
  const shape = {};
466
535
  const fields = schema.steps ? schema.steps.flatMap((step)=>step.sections.flatMap((s)=>s.fields)) : schema.sections?.flatMap((s)=>s.fields) || [];
@@ -1,11 +1,12 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
3
- import { useEffect, useMemo, useRef, useState } from "react";
4
- import { FormProvider, useForm, useFormState } from "react-hook-form";
3
+ import react, { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { FormProvider, useForm, useFormState, useWatch } from "react-hook-form";
5
5
  import { z } from "zod/v4";
6
6
  import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "../ui/accordion.js";
7
7
  import { Button } from "../ui/button.js";
8
8
  import { ScrollableTabsList, Tabs, TabsContent, TabsTrigger } from "../ui/tabs.js";
9
+ import { deepEqual, get } from "../../lib/index.js";
9
10
  import { DataFetcher } from "./data-fetcher.js";
10
11
  import { FormFieldRenderer } from "./field-renderer.js";
11
12
  import { RulesEngine } from "./rules-engine.js";
@@ -15,20 +16,31 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
15
16
  const [currentStep, setCurrentStep] = useState(0);
16
17
  const [customComponents, setCustomComponents] = useState({});
17
18
  const [isInitialized, setIsInitialized] = useState(false);
18
- const zodSchema = useMemo(()=>buildZodSchema(schema), [
19
+ const schemaRef = useRef(schema);
20
+ const stableSchema = useMemo(()=>{
21
+ if (deepEqual(schemaRef.current, schema)) return schemaRef.current;
22
+ schemaRef.current = schema;
23
+ return schema;
24
+ }, [
19
25
  schema
20
26
  ]);
27
+ const zodSchema = useMemo(()=>buildZodSchema(stableSchema), [
28
+ stableSchema
29
+ ]);
21
30
  const form = useForm({
22
31
  resolver: standardSchemaResolver(zodSchema),
23
- mode: schema.mode || 'onSubmit',
24
- reValidateMode: schema.reValidateMode || 'onChange'
32
+ defaultValues: stableSchema.initialData || {},
33
+ mode: stableSchema.mode || 'onSubmit',
34
+ reValidateMode: stableSchema.reValidateMode || 'onChange'
25
35
  });
26
36
  const { watch, handleSubmit, reset } = form;
27
- const valuesRef = useRef({});
28
- const watchedValues = watch();
29
- valuesRef.current = watchedValues;
37
+ const valuesRef = useRef(form.getValues());
38
+ const pluginsRef = useRef(plugins);
39
+ pluginsRef.current = plugins;
40
+ const onSubmitRef = useRef(onSubmit);
41
+ onSubmitRef.current = onSubmit;
30
42
  const context = useMemo(()=>({
31
- schema,
43
+ schema: stableSchema,
32
44
  form,
33
45
  get values () {
34
46
  return valuesRef.current;
@@ -42,7 +54,7 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
42
54
  get isDirty () {
43
55
  return form.formState.isDirty;
44
56
  },
45
- currentStep: schema.steps ? currentStep : void 0,
57
+ currentStep: stableSchema.steps ? currentStep : void 0,
46
58
  evaluateConditions: (conditions)=>RulesEngine.evaluateConditions(conditions, valuesRef.current, 'AND'),
47
59
  fetchData: async (source)=>{
48
60
  const result = await DataFetcher.fetch(source, valuesRef.current);
@@ -55,17 +67,31 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
55
67
  }));
56
68
  }
57
69
  }), [
58
- schema,
70
+ stableSchema,
59
71
  form,
60
72
  currentStep
61
73
  ]);
62
74
  const contextRef = useRef(context);
63
75
  contextRef.current = context;
76
+ const isInitializedRef = useRef(isInitialized);
77
+ isInitializedRef.current = isInitialized;
78
+ useEffect(()=>{
79
+ const subscription = watch((value, { name })=>{
80
+ valuesRef.current = value;
81
+ if (!name || !isInitializedRef.current) return;
82
+ pluginsRef.current.forEach((plugin)=>{
83
+ plugin.onValueChange?.(name, get(value, name), contextRef.current);
84
+ });
85
+ });
86
+ return ()=>subscription.unsubscribe();
87
+ }, [
88
+ watch
89
+ ]);
64
90
  useEffect(()=>{
65
91
  if (isInitialized) return;
66
92
  const initializeForm = async ()=>{
67
- if (schema.initialData) {
68
- const data = await loadInitialData(schema.initialData, contextRef.current);
93
+ if (stableSchema.initialData) {
94
+ const data = await loadInitialData(stableSchema.initialData, contextRef.current);
69
95
  reset(data);
70
96
  }
71
97
  for (const plugin of plugins)await plugin.onFormInit?.(contextRef.current);
@@ -75,41 +101,30 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
75
101
  }, [
76
102
  isInitialized
77
103
  ]);
78
- useEffect(()=>{
79
- if (!isInitialized) return;
80
- const subscription = watch((value, { name })=>{
81
- if (name) {
82
- valuesRef.current = value;
83
- plugins.forEach((plugin)=>{
84
- plugin.onValueChange?.(name, value[name], contextRef.current);
85
- });
86
- }
87
- });
88
- return ()=>subscription.unsubscribe();
89
- }, [
90
- watch,
91
- isInitialized,
92
- plugins
104
+ const handleFormSubmit = useMemo(()=>handleSubmit(async (data)=>{
105
+ let finalData = data;
106
+ for (const plugin of pluginsRef.current)if (plugin.onSubmit) finalData = await plugin.onSubmit(finalData, contextRef.current) || finalData;
107
+ if (onSubmitRef.current) await onSubmitRef.current(finalData);
108
+ }), [
109
+ handleSubmit
110
+ ]);
111
+ const handleReset = useCallback(()=>reset(), [
112
+ reset
93
113
  ]);
94
- const handleFormSubmit = handleSubmit(async (data)=>{
95
- let finalData = data;
96
- for (const plugin of plugins)if (plugin.onSubmit) finalData = await plugin.onSubmit(finalData, context) || finalData;
97
- if (onSubmit) await onSubmit(finalData);
98
- });
99
114
  const renderContent = ()=>{
100
- if (schema.steps) {
115
+ if (stableSchema.steps) {
101
116
  if ('tabs' === stepVariant) return /*#__PURE__*/ jsx(TabbedStepForm, {
102
- schema: schema,
117
+ schema: stableSchema,
103
118
  context: context,
104
119
  customComponents: customComponents,
105
120
  disabled: disabled,
106
121
  sectionVariant: sectionVariant,
107
122
  activeStepId: activeStepId,
108
123
  onActiveStepChange: onActiveStepChange,
109
- onReset: ()=>reset()
124
+ onReset: handleReset
110
125
  });
111
- return /*#__PURE__*/ jsx(MultiStepForm, {
112
- schema: schema,
126
+ return /*#__PURE__*/ jsx(metadata_form_MultiStepForm, {
127
+ schema: stableSchema,
113
128
  context: context,
114
129
  currentStep: currentStep,
115
130
  setCurrentStep: setCurrentStep,
@@ -118,8 +133,8 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
118
133
  sectionVariant: sectionVariant
119
134
  });
120
135
  }
121
- return /*#__PURE__*/ jsx(SinglePageForm, {
122
- schema: schema,
136
+ return /*#__PURE__*/ jsx(metadata_form_SinglePageForm, {
137
+ schema: stableSchema,
123
138
  context: context,
124
139
  customComponents: customComponents,
125
140
  disabled: disabled,
@@ -134,21 +149,36 @@ function MetadataForm({ schema, plugins = DEFAULT_PLUGINS, onSubmit, className,
134
149
  autoComplete: autoComplete,
135
150
  children: [
136
151
  renderContent(),
137
- !schema.steps && /*#__PURE__*/ jsx(FormActions, {
138
- schema: schema,
152
+ !stableSchema.steps && /*#__PURE__*/ jsx(metadata_form_FormActions, {
153
+ schema: stableSchema,
139
154
  context: context,
140
- onReset: ()=>reset()
155
+ onReset: handleReset
141
156
  })
142
157
  ]
143
158
  })
144
159
  });
145
160
  }
146
- function SinglePageForm({ schema, context, customComponents, disabled, sectionVariant }) {
161
+ function conditionDependencies(conditionGroups) {
162
+ const fields = new Set();
163
+ for (const conditions of conditionGroups)for (const condition of conditions || [])if (condition.when) fields.add(condition.when);
164
+ return Array.from(fields);
165
+ }
166
+ function useConditionDependencies(context, conditionFields) {
167
+ useWatch({
168
+ control: context.form.control,
169
+ name: conditionFields
170
+ });
171
+ }
172
+ const metadata_form_SinglePageForm = /*#__PURE__*/ react.memo(function({ schema, context, customComponents, disabled, sectionVariant }) {
147
173
  const sections = schema.sections || [];
174
+ const conditionFields = useMemo(()=>conditionDependencies(schema.sections?.map((section)=>section.conditions) ?? []), [
175
+ schema
176
+ ]);
177
+ useConditionDependencies(context, conditionFields);
148
178
  const visibleSections = sections.filter((section)=>!section.conditions || context.evaluateConditions(section.conditions));
149
179
  return /*#__PURE__*/ jsx("div", {
150
180
  className: 'plain' === sectionVariant ? void 0 : 'space-y-2',
151
- children: visibleSections.map((section)=>/*#__PURE__*/ jsx(FormSection, {
181
+ children: visibleSections.map((section)=>/*#__PURE__*/ jsx(metadata_form_FormSection, {
152
182
  section: section,
153
183
  context: context,
154
184
  customComponents: customComponents,
@@ -156,15 +186,30 @@ function SinglePageForm({ schema, context, customComponents, disabled, sectionVa
156
186
  sectionVariant: sectionVariant
157
187
  }, section.id))
158
188
  });
159
- }
160
- function MultiStepForm({ schema, context, currentStep, setCurrentStep, customComponents, disabled, sectionVariant }) {
189
+ });
190
+ const metadata_form_MultiStepForm = /*#__PURE__*/ react.memo(function({ schema, context, currentStep, setCurrentStep, customComponents, disabled, sectionVariant }) {
161
191
  const steps = schema.steps || [];
162
- const step = steps[currentStep];
163
- if (!step) return null;
164
- if (step.conditions && !context.evaluateConditions(step.conditions)) {
165
- if (currentStep < steps.length - 1) setCurrentStep(currentStep + 1);
166
- return null;
192
+ const conditionFields = useMemo(()=>conditionDependencies(schema.steps?.map((step)=>step.conditions) ?? []), [
193
+ schema
194
+ ]);
195
+ useConditionDependencies(context, conditionFields);
196
+ let visibleStepIndex = -1;
197
+ for(let i = currentStep; i < steps.length; i++){
198
+ const candidate = steps[i];
199
+ if (!candidate.conditions || context.evaluateConditions(candidate.conditions)) {
200
+ visibleStepIndex = i;
201
+ break;
202
+ }
167
203
  }
204
+ useEffect(()=>{
205
+ if (-1 !== visibleStepIndex && visibleStepIndex !== currentStep) setCurrentStep(visibleStepIndex);
206
+ }, [
207
+ visibleStepIndex,
208
+ currentStep,
209
+ setCurrentStep
210
+ ]);
211
+ const step = -1 !== visibleStepIndex ? steps[visibleStepIndex] : void 0;
212
+ if (!step || visibleStepIndex !== currentStep) return null;
168
213
  return /*#__PURE__*/ jsxs("div", {
169
214
  className: "space-y-6",
170
215
  children: [
@@ -196,7 +241,7 @@ function MultiStepForm({ schema, context, currentStep, setCurrentStep, customCom
196
241
  }),
197
242
  /*#__PURE__*/ jsx("div", {
198
243
  className: 'plain' === sectionVariant ? void 0 : 'space-y-2',
199
- children: step.sections.map((section)=>/*#__PURE__*/ jsx(FormSection, {
244
+ children: step.sections.map((section)=>/*#__PURE__*/ jsx(metadata_form_FormSection, {
200
245
  section: section,
201
246
  context: context,
202
247
  customComponents: customComponents,
@@ -228,9 +273,16 @@ function MultiStepForm({ schema, context, currentStep, setCurrentStep, customCom
228
273
  })
229
274
  ]
230
275
  });
231
- }
276
+ });
232
277
  function TabbedStepForm({ schema, context, customComponents, disabled, sectionVariant, onReset, activeStepId, onActiveStepChange }) {
233
278
  const steps = schema.steps || [];
279
+ const conditionFields = useMemo(()=>conditionDependencies(schema.steps?.flatMap((step)=>[
280
+ step.conditions,
281
+ ...step.sections.map((section)=>section.conditions)
282
+ ]) ?? []), [
283
+ schema
284
+ ]);
285
+ useConditionDependencies(context, conditionFields);
234
286
  const visibleSteps = steps.filter((step)=>{
235
287
  if (step.conditions && !context.evaluateConditions(step.conditions)) return false;
236
288
  const hasVisibleSection = step.sections.some((section)=>!section.conditions || context.evaluateConditions(section.conditions));
@@ -306,7 +358,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
306
358
  children: step.emptyState
307
359
  }) : /*#__PURE__*/ jsx("div", {
308
360
  className: 'plain' === sectionVariant ? 'pb-6 [padding-inline:var(--mf-content-inset,0px)]' : 'space-y-2 pb-6 pt-4 [padding-inline:var(--mf-content-inset,0px)]',
309
- children: stepSections.map((section)=>/*#__PURE__*/ jsx(FormSection, {
361
+ children: stepSections.map((section)=>/*#__PURE__*/ jsx(metadata_form_FormSection, {
310
362
  section: section,
311
363
  context: context,
312
364
  customComponents: customComponents,
@@ -318,7 +370,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
318
370
  })
319
371
  ]
320
372
  }),
321
- /*#__PURE__*/ jsx(FormActions, {
373
+ /*#__PURE__*/ jsx(metadata_form_FormActions, {
322
374
  schema: schema,
323
375
  context: context,
324
376
  onReset: onReset
@@ -326,7 +378,7 @@ function TabbedStepForm({ schema, context, customComponents, disabled, sectionVa
326
378
  ]
327
379
  });
328
380
  }
329
- function FormSection({ section, context, customComponents, disabled, sectionVariant = 'card' }) {
381
+ const metadata_form_FormSection = /*#__PURE__*/ react.memo(function({ section, context, customComponents, disabled, sectionVariant = 'card' }) {
330
382
  const gridColumns = context.schema.layout?.columns || 1;
331
383
  const gap = context.schema.layout?.gap || 4;
332
384
  const isPlain = 'plain' === sectionVariant;
@@ -402,8 +454,15 @@ function FormSection({ section, context, customComponents, disabled, sectionVari
402
454
  })
403
455
  ]
404
456
  });
405
- }
406
- function FormActions({ schema, context, onReset }) {
457
+ });
458
+ const metadata_form_FormActions = /*#__PURE__*/ react.memo(function({ schema, context, onReset }) {
459
+ const { isSubmitting } = useFormState({
460
+ control: context.form.control
461
+ });
462
+ const conditionFields = useMemo(()=>conditionDependencies(schema.actions?.map((action)=>action.conditions) ?? []), [
463
+ schema
464
+ ]);
465
+ useConditionDependencies(context, conditionFields);
407
466
  const actions = schema.actions || [
408
467
  {
409
468
  id: 'submit',
@@ -427,12 +486,12 @@ function FormActions({ schema, context, onReset }) {
427
486
  return /*#__PURE__*/ jsx(Button, {
428
487
  type: 'submit' === action.type ? 'submit' : 'button',
429
488
  variant: action.variant || 'default',
430
- disabled: action.disabled || 'submit' === action.type && context.isSubmitting,
431
- children: action.loading && context.isSubmitting ? 'Loading...' : action.label
489
+ disabled: action.disabled || 'submit' === action.type && isSubmitting,
490
+ children: action.loading && isSubmitting ? 'Loading...' : action.label
432
491
  }, action.id);
433
492
  })
434
493
  });
435
- }
494
+ });
436
495
  function buildZodSchema(schema) {
437
496
  const shape = {};
438
497
  const fields = schema.steps ? schema.steps.flatMap((step)=>step.sections.flatMap((s)=>s.fields)) : schema.sections?.flatMap((s)=>s.fields) || [];
@@ -24,19 +24,19 @@ var __webpack_modules__ = {
24
24
  "./button-group" (module) {
25
25
  module.exports = require("./button-group.cjs");
26
26
  },
27
- "@/components/ui/button" (module) {
27
+ "./button" (module) {
28
28
  module.exports = require("./button.cjs");
29
29
  },
30
30
  "./calendar" (module) {
31
31
  module.exports = require("./calendar.cjs");
32
32
  },
33
- "./card" (module) {
33
+ "@/components/ui/card" (module) {
34
34
  module.exports = require("./card.cjs");
35
35
  },
36
36
  "./chart" (module) {
37
37
  module.exports = require("./chart.cjs");
38
38
  },
39
- "@/components/ui/checkbox" (module) {
39
+ "./checkbox" (module) {
40
40
  module.exports = require("./checkbox.cjs");
41
41
  },
42
42
  "@/components/ui/collapsible" (module) {
@@ -105,7 +105,7 @@ var __webpack_modules__ = {
105
105
  "./pagination" (module) {
106
106
  module.exports = require("./pagination.cjs");
107
107
  },
108
- "@/components/ui/popover" (module) {
108
+ "./popover" (module) {
109
109
  module.exports = require("./popover.cjs");
110
110
  },
111
111
  "@/components/ui/portal-container" (module) {
@@ -159,7 +159,7 @@ var __webpack_modules__ = {
159
159
  "./switch" (module) {
160
160
  module.exports = require("./switch.cjs");
161
161
  },
162
- "./table" (module) {
162
+ "@/components/ui/table" (module) {
163
163
  module.exports = require("./table.cjs");
164
164
  },
165
165
  "./tabs" (module) {
@@ -171,7 +171,7 @@ var __webpack_modules__ = {
171
171
  "./toggle-group" (module) {
172
172
  module.exports = require("./toggle-group.cjs");
173
173
  },
174
- "./toggle" (module) {
174
+ "@/components/ui/toggle" (module) {
175
175
  module.exports = require("./toggle.cjs");
176
176
  },
177
177
  "./tooltip" (module) {
@@ -279,7 +279,7 @@ var __webpack_exports__ = {};
279
279
  "default"
280
280
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_breadcrumb__rspack_import_6[__rspack_import_key];
281
281
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
282
- var _button__rspack_import_7 = __webpack_require__("@/components/ui/button");
282
+ var _button__rspack_import_7 = __webpack_require__("./button");
283
283
  var __rspack_reexport = {};
284
284
  for(const __rspack_import_key in _button__rspack_import_7)if ([
285
285
  "TreeView",
@@ -300,7 +300,7 @@ var __webpack_exports__ = {};
300
300
  "default"
301
301
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_calendar__rspack_import_9[__rspack_import_key];
302
302
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
303
- var _card__rspack_import_10 = __webpack_require__("./card");
303
+ var _card__rspack_import_10 = __webpack_require__("@/components/ui/card");
304
304
  var __rspack_reexport = {};
305
305
  for(const __rspack_import_key in _card__rspack_import_10)if ([
306
306
  "TreeView",
@@ -314,7 +314,7 @@ var __webpack_exports__ = {};
314
314
  "default"
315
315
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_chart__rspack_import_11[__rspack_import_key];
316
316
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
317
- var _checkbox__rspack_import_12 = __webpack_require__("@/components/ui/checkbox");
317
+ var _checkbox__rspack_import_12 = __webpack_require__("./checkbox");
318
318
  var __rspack_reexport = {};
319
319
  for(const __rspack_import_key in _checkbox__rspack_import_12)if ([
320
320
  "TreeView",
@@ -475,7 +475,7 @@ var __webpack_exports__ = {};
475
475
  "default"
476
476
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_pagination__rspack_import_34[__rspack_import_key];
477
477
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
478
- var _popover__rspack_import_35 = __webpack_require__("@/components/ui/popover");
478
+ var _popover__rspack_import_35 = __webpack_require__("./popover");
479
479
  var __rspack_reexport = {};
480
480
  for(const __rspack_import_key in _popover__rspack_import_35)if ([
481
481
  "TreeView",
@@ -601,7 +601,7 @@ var __webpack_exports__ = {};
601
601
  "default"
602
602
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_switch__rspack_import_52[__rspack_import_key];
603
603
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
604
- var _table__rspack_import_53 = __webpack_require__("./table");
604
+ var _table__rspack_import_53 = __webpack_require__("@/components/ui/table");
605
605
  var __rspack_reexport = {};
606
606
  for(const __rspack_import_key in _table__rspack_import_53)if ([
607
607
  "TreeView",
@@ -622,7 +622,7 @@ var __webpack_exports__ = {};
622
622
  "default"
623
623
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_textarea__rspack_import_55[__rspack_import_key];
624
624
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
625
- var _toggle__rspack_import_56 = __webpack_require__("./toggle");
625
+ var _toggle__rspack_import_56 = __webpack_require__("@/components/ui/toggle");
626
626
  var __rspack_reexport = {};
627
627
  for(const __rspack_import_key in _toggle__rspack_import_56)if ([
628
628
  "TreeView",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/apollo-wind",
3
- "version": "2.47.0",
3
+ "version": "2.47.1",
4
4
  "description": "UiPath wind design system - A Tailwind CSS based React component library",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",