@wise/dynamic-flow-client 4.3.12 → 4.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/main.js CHANGED
@@ -1159,7 +1159,6 @@ var getRenderFunction = (renderers) => {
1159
1159
  };
1160
1160
 
1161
1161
  // src/revamp/utils/type-utils.ts
1162
- var hasChildren = (component) => "getChildren" in component && typeof component.getChildren === "function";
1163
1162
  var isHiddenComponent = (component) => "hidden" in component && component.hidden;
1164
1163
  var isObjectLocalValue = (value) => value != null && typeof value === "object" && !Array.isArray(value) && !(value instanceof File);
1165
1164
  var isArrayLocalValue = (value) => Array.isArray(value);
@@ -1813,47 +1812,67 @@ var import_dynamic_flow_types2 = require("@wise/dynamic-flow-types");
1813
1812
  var import_react3 = require("react");
1814
1813
  var import_react_intl7 = require("react-intl");
1815
1814
 
1815
+ // src/revamp/domain/components/utils/component-utils.ts
1816
+ var getInputUpdateFunction = (updateComponent) => {
1817
+ return (component, updateFn) => {
1818
+ updateFn(component);
1819
+ updateComponent();
1820
+ };
1821
+ };
1822
+
1816
1823
  // src/revamp/domain/components/RootDomainComponent.ts
1817
- var createRootDomainComponent = () => ({
1818
- type: "root",
1819
- uid: "root",
1820
- stepComponent: null,
1821
- getChildren() {
1822
- return this.stepComponent ? [this.stepComponent] : [];
1823
- },
1824
- getLocalValue() {
1825
- return this.stepComponent ? this.stepComponent.getLocalValue() : null;
1826
- },
1827
- async getSubmittableValue() {
1828
- return this.stepComponent ? this.stepComponent.getSubmittableValue() : null;
1829
- },
1830
- getSubmittableValueSync() {
1831
- return this.stepComponent ? this.stepComponent.getSubmittableValueSync() : null;
1832
- },
1833
- getSummary() {
1834
- return this.stepComponent ? this.stepComponent.getSummary() : {};
1835
- },
1836
- validate() {
1837
- return this.stepComponent ? this.stepComponent.validate() : false;
1838
- },
1839
- setLoadingState(loadingState) {
1840
- var _a;
1841
- (_a = this.stepComponent) == null ? void 0 : _a.setLoadingState(loadingState);
1842
- },
1843
- getLoadingState() {
1844
- return this.stepComponent ? this.stepComponent.loadingState : "initial";
1845
- },
1846
- getTrackEvent() {
1847
- return this.stepComponent ? this.stepComponent.trackEvent : null;
1848
- },
1849
- hasStep() {
1850
- return Boolean(this.stepComponent);
1851
- },
1852
- stop() {
1853
- var _a;
1854
- (_a = this.stepComponent) == null ? void 0 : _a.stop();
1855
- }
1856
- });
1824
+ var createRootDomainComponent = (updateComponent) => {
1825
+ const update = getInputUpdateFunction(updateComponent);
1826
+ const rootComponent = {
1827
+ type: "root",
1828
+ uid: "root",
1829
+ stepComponent: null,
1830
+ _update(updateFn) {
1831
+ update(this, updateFn);
1832
+ },
1833
+ getChildren() {
1834
+ return this.stepComponent ? [this.stepComponent] : [];
1835
+ },
1836
+ getLocalValue() {
1837
+ return this.stepComponent ? this.stepComponent.getLocalValue() : null;
1838
+ },
1839
+ async getSubmittableValue() {
1840
+ return this.stepComponent ? this.stepComponent.getSubmittableValue() : null;
1841
+ },
1842
+ getSubmittableValueSync() {
1843
+ return this.stepComponent ? this.stepComponent.getSubmittableValueSync() : null;
1844
+ },
1845
+ getSummary() {
1846
+ return this.stepComponent ? this.stepComponent.getSummary() : {};
1847
+ },
1848
+ validate() {
1849
+ return this.stepComponent ? this.stepComponent.validate() : false;
1850
+ },
1851
+ setLoadingState(loadingState) {
1852
+ var _a;
1853
+ (_a = this.stepComponent) == null ? void 0 : _a.setLoadingState(loadingState);
1854
+ },
1855
+ getLoadingState() {
1856
+ return this.stepComponent ? this.stepComponent.loadingState : "initial";
1857
+ },
1858
+ getTrackEvent() {
1859
+ return this.stepComponent ? this.stepComponent.trackEvent : null;
1860
+ },
1861
+ hasStep() {
1862
+ return Boolean(this.stepComponent);
1863
+ },
1864
+ stop() {
1865
+ var _a;
1866
+ (_a = this.stepComponent) == null ? void 0 : _a.stop();
1867
+ },
1868
+ setStep(stepComponent) {
1869
+ this._update((draft) => {
1870
+ draft.stepComponent = stepComponent;
1871
+ });
1872
+ }
1873
+ };
1874
+ return rootComponent;
1875
+ };
1857
1876
 
1858
1877
  // src/revamp/utils/component-utils.ts
1859
1878
  var getSubmittableData = async (components) => Promise.all(components.map(async (component) => component.getSubmittableValue())).then(
@@ -1926,22 +1945,17 @@ var summaryIfProvides = (summary, { value, icon, image }) => {
1926
1945
  var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
1927
1946
  var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
1928
1947
 
1929
- // src/revamp/domain/components/utils/component-utils.ts
1930
- var getInputUpdateFunction = (uid, updateComponent) => (updateFn) => {
1931
- updateComponent(uid, (draft) => {
1932
- const draftState = draft;
1933
- updateFn(draftState);
1934
- });
1935
- };
1936
-
1937
1948
  // src/revamp/domain/components/StepDomainComponent.ts
1938
1949
  var createStepComponent = (stepProps) => {
1939
1950
  const _a = stepProps, { uid, stepPolling, stepRefreshAfter, updateComponent } = _a, rest = __objRest(_a, ["uid", "stepPolling", "stepRefreshAfter", "updateComponent"]);
1940
- const update = getInputUpdateFunction(uid, updateComponent);
1941
- return __spreadProps(__spreadValues({
1951
+ const update = getInputUpdateFunction(updateComponent);
1952
+ const component = __spreadProps(__spreadValues({
1942
1953
  uid
1943
1954
  }, rest), {
1944
1955
  type: "step",
1956
+ _update(updateFn) {
1957
+ update(this, updateFn);
1958
+ },
1945
1959
  getChildren() {
1946
1960
  return this.components;
1947
1961
  },
@@ -1961,7 +1975,7 @@ var createStepComponent = (stepProps) => {
1961
1975
  return validateComponents(this.getChildren());
1962
1976
  },
1963
1977
  setLoadingState(loadingState) {
1964
- update((draft) => {
1978
+ this._update((draft) => {
1965
1979
  draft.loadingState = loadingState;
1966
1980
  });
1967
1981
  },
@@ -1970,6 +1984,7 @@ var createStepComponent = (stepProps) => {
1970
1984
  stepRefreshAfter == null ? void 0 : stepRefreshAfter.stop();
1971
1985
  }
1972
1986
  });
1987
+ return component;
1973
1988
  };
1974
1989
 
1975
1990
  // src/revamp/domain/mappers/utils/behavior-utils.ts
@@ -2393,6 +2408,22 @@ var createDividerComponent = (props) => __spreadProps(__spreadValues({
2393
2408
  // src/revamp/domain/mappers/layout/dividerLayoutToComponent.ts
2394
2409
  var dividerLayoutToComponent = (uid, { control, margin = "md" }) => createDividerComponent({ uid, control, margin });
2395
2410
 
2411
+ // src/revamp/domain/components/utils/getRandomId.ts
2412
+ var getRandomId = () => Math.random().toString(36).substring(2);
2413
+
2414
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
2415
+ var isExactLocalValueMatch = (valueA, valueB) => {
2416
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
2417
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
2418
+ }
2419
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
2420
+ const keysA = Object.keys(valueA);
2421
+ const keysB = Object.keys(valueB);
2422
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
2423
+ }
2424
+ return valueA === valueB;
2425
+ };
2426
+
2396
2427
  // src/revamp/domain/features/utils/http-utils.ts
2397
2428
  function constructPayload({
2398
2429
  value,
@@ -2420,37 +2451,21 @@ var abortAndResetController = (abortController) => {
2420
2451
  return new AbortController();
2421
2452
  };
2422
2453
 
2423
- // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
2424
- var isExactLocalValueMatch = (valueA, valueB) => {
2425
- if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
2426
- return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
2427
- }
2428
- if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
2429
- const keysA = Object.keys(valueA);
2430
- const keysB = Object.keys(valueB);
2431
- return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
2432
- }
2433
- return valueA === valueB;
2434
- };
2435
-
2436
- // src/revamp/domain/components/utils/getRandomId.ts
2437
- var getRandomId = () => Math.random().toString(36).substring(2);
2438
-
2439
2454
  // src/revamp/domain/features/persistAsync/getComponentPersistAsync.ts
2440
2455
  var getComponentPersistAsync = (update, performPersistAsync) => (
2441
2456
  /**
2442
2457
  * Will update the persistedState when a new request is made, and will update
2443
2458
  * the value or set errors when the request completes.
2444
2459
  */
2445
- async (persistedState, currentValue) => {
2446
- const { abortController, lastSubmitted, submission } = persistedState;
2460
+ async (component, currentValue) => {
2461
+ const { abortController, lastSubmitted, submission } = component.persistedState;
2447
2462
  if (isExactLocalValueMatch(lastSubmitted, currentValue)) {
2448
2463
  return submission;
2449
2464
  }
2450
2465
  const newAbortController = abortAndResetController(abortController);
2451
2466
  if (isNullish(currentValue) || currentValue === "") {
2452
2467
  const resolvedNull = Promise.resolve(null);
2453
- update((draft) => {
2468
+ update(component, (draft) => {
2454
2469
  draft.persistedState.abortController = newAbortController;
2455
2470
  draft.persistedState.lastResponse = null;
2456
2471
  draft.persistedState.lastSubmitted = currentValue;
@@ -2460,7 +2475,7 @@ var getComponentPersistAsync = (update, performPersistAsync) => (
2460
2475
  }
2461
2476
  const { signal } = newAbortController;
2462
2477
  const newSubmission = performPersistAsync({ value: currentValue, signal }).then((newValue) => {
2463
- update((draft) => {
2478
+ update(component, (draft) => {
2464
2479
  draft.persistedState.lastResponse = newValue;
2465
2480
  });
2466
2481
  return newValue;
@@ -2468,14 +2483,14 @@ var getComponentPersistAsync = (update, performPersistAsync) => (
2468
2483
  if (error instanceof DOMException && error.name === "AbortError") {
2469
2484
  return null;
2470
2485
  }
2471
- update((draft) => {
2486
+ update(component, (draft) => {
2472
2487
  draft.errors = [error.message];
2473
2488
  draft.persistedState.lastResponse = null;
2474
2489
  draft.persistedState.lastSubmitted = null;
2475
2490
  });
2476
2491
  throw error;
2477
2492
  });
2478
- update((draft) => {
2493
+ update(component, (draft) => {
2479
2494
  draft.persistedState = {
2480
2495
  abortController: newAbortController,
2481
2496
  lastResponse: null,
@@ -2491,19 +2506,19 @@ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
2491
2506
  * Will update the persistedState when a new request is made, and will update
2492
2507
  * the value or set errors when the request completes.
2493
2508
  */
2494
- async (index, value) => {
2509
+ async (component, index, value) => {
2495
2510
  if (isNullish(value)) {
2496
2511
  throw new Error("Value must be a file or base64 string.");
2497
2512
  }
2498
2513
  const newAbortController = new AbortController();
2499
2514
  const { signal } = newAbortController;
2500
2515
  const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
2501
- update((draft) => {
2516
+ update(component, (draft) => {
2502
2517
  draft.persistedState[index].lastResponse = newValue;
2503
2518
  });
2504
2519
  return newValue;
2505
2520
  }).catch((error) => {
2506
- update((draft) => {
2521
+ update(component, (draft) => {
2507
2522
  draft.persistedState = [
2508
2523
  ...draft.persistedState.slice(0, index),
2509
2524
  ...draft.persistedState.slice(index + 1)
@@ -2513,7 +2528,7 @@ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
2513
2528
  });
2514
2529
  throw error;
2515
2530
  });
2516
- update((draft) => {
2531
+ update(component, (draft) => {
2517
2532
  draft.persistedState = [
2518
2533
  ...draft.persistedState.slice(0, index),
2519
2534
  {
@@ -2608,11 +2623,11 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2608
2623
  * Will update the validationAsyncState when a new request is made, and will update
2609
2624
  * the description or set errors when the request completes.
2610
2625
  */
2611
- async (validationAsyncState, currentValue) => {
2612
- const { abortController } = validationAsyncState;
2626
+ async (component, currentValue) => {
2627
+ const { abortController } = component.validationAsyncState;
2613
2628
  const newAbortController = abortAndResetController(abortController);
2614
2629
  if (isNullish(currentValue)) {
2615
- update((draft) => {
2630
+ update(component, (draft) => {
2616
2631
  draft.validationAsyncState = {
2617
2632
  abortController: newAbortController,
2618
2633
  lastSubmitted: currentValue,
@@ -2623,7 +2638,7 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2623
2638
  }
2624
2639
  const { signal } = newAbortController;
2625
2640
  const newSubmission = performValidationAsync({ value: currentValue, signal }).then((message) => {
2626
- update((draft) => {
2641
+ update(component, (draft) => {
2627
2642
  if (message) {
2628
2643
  draft.validationAsyncState.messages.success = message;
2629
2644
  }
@@ -2633,11 +2648,11 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2633
2648
  if (error instanceof DOMException && error.name === "AbortError") {
2634
2649
  return null;
2635
2650
  }
2636
- update((draft) => {
2651
+ update(component, (draft) => {
2637
2652
  draft.validationAsyncState.messages.error = error.message;
2638
2653
  });
2639
2654
  });
2640
- update((draft) => {
2655
+ update(component, (draft) => {
2641
2656
  draft.validationAsyncState = {
2642
2657
  abortController: newAbortController,
2643
2658
  lastSubmitted: currentValue,
@@ -2670,22 +2685,18 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2670
2685
  "onValueChange",
2671
2686
  "summariser"
2672
2687
  ]);
2673
- const update = getInputUpdateFunction(uid, updateComponent);
2688
+ const update = getInputUpdateFunction(updateComponent);
2674
2689
  const getValidationErrors = getLocalValueValidator(checks);
2675
2690
  const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
2676
- const getAndSetValidationErrors = (currentValue) => {
2677
- const messages = getValidationErrors(currentValue);
2678
- update((draft) => {
2679
- draft.errors = messages;
2680
- });
2681
- return messages;
2682
- };
2683
2691
  const numberComponent = __spreadValues({
2684
2692
  type: "number",
2685
2693
  uid,
2686
2694
  id,
2695
+ _update(updateFn) {
2696
+ update(this, updateFn);
2697
+ },
2687
2698
  onBlur() {
2688
- getAndSetValidationErrors(this.getLocalValue());
2699
+ this.validate();
2689
2700
  performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
2690
2701
  },
2691
2702
  onFocus() {
@@ -2693,7 +2704,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2693
2704
  // Noop
2694
2705
  onChange(updatedValue) {
2695
2706
  const prevValue = this.value;
2696
- update((draft) => {
2707
+ this._update((draft) => {
2697
2708
  draft.errors = [];
2698
2709
  draft.validationAsyncState.messages = {};
2699
2710
  draft.value = updatedValue;
@@ -2715,8 +2726,11 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2715
2726
  return this.value;
2716
2727
  },
2717
2728
  validate() {
2718
- const messages = getAndSetValidationErrors(this.getLocalValue());
2719
- return messages.length === 0;
2729
+ const errors = getValidationErrors(this.getLocalValue());
2730
+ this._update((draft) => {
2731
+ draft.errors = errors;
2732
+ });
2733
+ return errors.length === 0;
2720
2734
  }
2721
2735
  }, rest);
2722
2736
  if (performRefresh) {
@@ -2727,12 +2741,12 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2727
2741
  return __spreadProps(__spreadValues({}, numberComponent), {
2728
2742
  onBlur() {
2729
2743
  if (this.validate()) {
2730
- persist(this.persistedState, this.getLocalValue()).catch(() => {
2744
+ persist(this, this.getLocalValue()).catch(() => {
2731
2745
  });
2732
2746
  }
2733
2747
  },
2734
2748
  async getSubmittableValue() {
2735
- return persist(this.persistedState, this.getLocalValue());
2749
+ return persist(this, this.getLocalValue());
2736
2750
  },
2737
2751
  getSubmittableValueSync() {
2738
2752
  return this.persistedState.lastResponse;
@@ -2750,7 +2764,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2750
2764
  onChange(updatedValue) {
2751
2765
  numberComponent.onChange.call(this, updatedValue);
2752
2766
  if (getValidationErrors(updatedValue).length === 0) {
2753
- validateAsync(this.validationAsyncState, updatedValue);
2767
+ validateAsync(this, updatedValue);
2754
2768
  }
2755
2769
  }
2756
2770
  });
@@ -2872,6 +2886,9 @@ var getRequiredCheck = (required, messageFunctions) => (value) => {
2872
2886
  if (isArray(value) && value.length === 0) {
2873
2887
  return messageFunctions.required();
2874
2888
  }
2889
+ if (value === "") {
2890
+ return messageFunctions.required();
2891
+ }
2875
2892
  return isNullish(value) ? messageFunctions.required() : null;
2876
2893
  };
2877
2894
 
@@ -3038,7 +3055,7 @@ var getPerformPersistAsync = ({
3038
3055
  }
3039
3056
  return json[idProperty];
3040
3057
  }
3041
- } catch (error) {
3058
+ } catch (e) {
3042
3059
  trackFailure();
3043
3060
  throw new Error(genericErrorMessage);
3044
3061
  }
@@ -3465,23 +3482,19 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3465
3482
  "onValueChange",
3466
3483
  "summariser"
3467
3484
  ]);
3468
- const update = getInputUpdateFunction(uid, updateComponent);
3485
+ const update = getInputUpdateFunction(updateComponent);
3469
3486
  const getValidationErrors = getLocalValueValidator(checks);
3470
3487
  const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3471
- const getAndSetValidationErrors = (currentValue) => {
3472
- const messages = getValidationErrors(currentValue);
3473
- update((draft) => {
3474
- draft.errors = messages;
3475
- });
3476
- return messages;
3477
- };
3478
3488
  const integerComponent = __spreadValues({
3479
3489
  type: "integer",
3480
3490
  uid,
3481
3491
  id,
3482
3492
  value,
3493
+ _update(updateFn) {
3494
+ update(this, updateFn);
3495
+ },
3483
3496
  onBlur() {
3484
- getAndSetValidationErrors(this.getLocalValue());
3497
+ this.validate();
3485
3498
  performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
3486
3499
  },
3487
3500
  onFocus() {
@@ -3489,7 +3502,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3489
3502
  // Noop
3490
3503
  onChange(updatedValue) {
3491
3504
  const prevValue = this.value;
3492
- update((draft) => {
3505
+ this._update((draft) => {
3493
3506
  draft.errors = [];
3494
3507
  draft.validationAsyncState.messages = {};
3495
3508
  draft.value = updatedValue;
@@ -3511,8 +3524,11 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3511
3524
  return this.value;
3512
3525
  },
3513
3526
  validate() {
3514
- const messages = getAndSetValidationErrors(this.getLocalValue());
3515
- return messages.length === 0;
3527
+ const errors = getValidationErrors(this.getLocalValue());
3528
+ this._update((draft) => {
3529
+ draft.errors = errors;
3530
+ });
3531
+ return errors.length === 0;
3516
3532
  }
3517
3533
  }, rest);
3518
3534
  if (performRefresh) {
@@ -3523,12 +3539,12 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3523
3539
  return __spreadProps(__spreadValues({}, integerComponent), {
3524
3540
  onBlur() {
3525
3541
  if (this.validate()) {
3526
- persist(this.persistedState, this.getLocalValue()).catch(() => {
3542
+ persist(this, this.getLocalValue()).catch(() => {
3527
3543
  });
3528
3544
  }
3529
3545
  },
3530
3546
  async getSubmittableValue() {
3531
- return persist(this.persistedState, this.getLocalValue());
3547
+ return persist(this, this.getLocalValue());
3532
3548
  },
3533
3549
  getSubmittableValueSync() {
3534
3550
  return this.persistedState.lastResponse;
@@ -3546,7 +3562,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3546
3562
  onChange(updatedValue) {
3547
3563
  integerComponent.onChange.call(this, updatedValue);
3548
3564
  if (getValidationErrors(updatedValue).length === 0) {
3549
- validateAsync(this.validationAsyncState, updatedValue);
3565
+ validateAsync(this, updatedValue);
3550
3566
  }
3551
3567
  }
3552
3568
  });
@@ -3620,16 +3636,9 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
3620
3636
  (option) => isPartialModelMatch(option.component.getSubmittableValueSync(), initialModel)
3621
3637
  );
3622
3638
  const selectedIndex = matchingOptions.filter((match) => match).length === 1 ? matchingOptions.indexOf(true) : null;
3623
- const update = getInputUpdateFunction(uid, updateComponent);
3639
+ const update = getInputUpdateFunction(updateComponent);
3624
3640
  const getValidationErrors = getLocalValueValidator(checks);
3625
- const getAndSetValidationErrors = (currentValue) => {
3626
- const messages = getValidationErrors(currentValue);
3627
- update((draft) => {
3628
- draft.errors = messages;
3629
- });
3630
- return messages;
3631
- };
3632
- return __spreadProps(__spreadValues({
3641
+ const component = __spreadProps(__spreadValues({
3633
3642
  uid,
3634
3643
  type: "select",
3635
3644
  children,
@@ -3637,6 +3646,9 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
3637
3646
  selectedIndex,
3638
3647
  value: null
3639
3648
  }, rest), {
3649
+ _update(updateFn) {
3650
+ update(this, updateFn);
3651
+ },
3640
3652
  getChildren() {
3641
3653
  return this.children;
3642
3654
  },
@@ -3660,7 +3672,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
3660
3672
  return (_b = (_a2 = this.getSelectedChild()) == null ? void 0 : _a2.getLocalValue()) != null ? _b : null;
3661
3673
  },
3662
3674
  onBlur() {
3663
- getAndSetValidationErrors(this.getLocalValue());
3675
+ this.validate();
3664
3676
  },
3665
3677
  onFocus() {
3666
3678
  },
@@ -3672,7 +3684,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
3672
3684
  schemaId: this.children[updatedIndex].analyticsId
3673
3685
  });
3674
3686
  }
3675
- update((draft) => {
3687
+ this._update((draft) => {
3676
3688
  draft.errors = [];
3677
3689
  draft.selectedIndex = updatedIndex;
3678
3690
  });
@@ -3682,10 +3694,14 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
3682
3694
  validate() {
3683
3695
  var _a2, _b;
3684
3696
  const validChild = (_b = (_a2 = this.getSelectedChild()) == null ? void 0 : _a2.validate()) != null ? _b : true;
3685
- const messages = getAndSetValidationErrors(this.getLocalValue());
3686
- return messages.length === 0 && validChild;
3697
+ const errors = getValidationErrors(this.getLocalValue());
3698
+ this._update((draft) => {
3699
+ draft.errors = errors;
3700
+ });
3701
+ return errors.length === 0 && validChild;
3687
3702
  }
3688
3703
  });
3704
+ return component;
3689
3705
  };
3690
3706
 
3691
3707
  // src/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.ts
@@ -3780,29 +3796,25 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
3780
3796
  "summariser",
3781
3797
  "value"
3782
3798
  ]);
3783
- const update = getInputUpdateFunction(uid, updateComponent);
3799
+ const update = getInputUpdateFunction(updateComponent);
3784
3800
  const getValidationErrors = getLocalValueValidator(checks);
3785
- const getAndSetValidationErrors = (currentValue) => {
3786
- const messages = getValidationErrors(currentValue);
3787
- update((draft) => {
3788
- draft.errors = messages;
3789
- });
3790
- return messages;
3791
- };
3792
3801
  const dateInputComponent = __spreadValues({
3793
3802
  type: "date",
3794
3803
  uid,
3795
3804
  id,
3796
3805
  value,
3806
+ _update(updateFn) {
3807
+ update(this, updateFn);
3808
+ },
3797
3809
  onBlur() {
3798
- getAndSetValidationErrors(this.getLocalValue());
3810
+ this.validate();
3799
3811
  },
3800
3812
  onFocus() {
3801
3813
  },
3802
3814
  // Noop
3803
3815
  onChange(updatedValue) {
3804
3816
  const prevValue = this.value;
3805
- update((draft) => {
3817
+ this._update((draft) => {
3806
3818
  draft.errors = [];
3807
3819
  draft.validationAsyncState.messages = {};
3808
3820
  draft.value = updatedValue;
@@ -3826,8 +3838,11 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
3826
3838
  return this.value;
3827
3839
  },
3828
3840
  validate() {
3829
- const messages = getAndSetValidationErrors(this.getLocalValue());
3830
- return messages.length === 0;
3841
+ const errors = getValidationErrors(this.getLocalValue());
3842
+ this._update((draft) => {
3843
+ draft.errors = errors;
3844
+ });
3845
+ return errors.length === 0;
3831
3846
  }
3832
3847
  }, rest);
3833
3848
  if (performRefresh) {
@@ -3840,12 +3855,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
3840
3855
  dateInputComponent.onChange.call(this, updatedValue);
3841
3856
  const isValid = getValidationErrors(updatedValue).length === 0;
3842
3857
  if (isValid) {
3843
- persist(this.persistedState, this.getLocalValue()).catch(() => {
3858
+ persist(this, this.getLocalValue()).catch(() => {
3844
3859
  });
3845
3860
  }
3846
3861
  },
3847
3862
  async getSubmittableValue() {
3848
- return persist(this.persistedState, this.getLocalValue());
3863
+ return persist(this, this.getLocalValue());
3849
3864
  },
3850
3865
  getSubmittableValueSync() {
3851
3866
  return this.persistedState.lastResponse;
@@ -3857,7 +3872,7 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
3857
3872
  return __spreadProps(__spreadValues({}, dateInputComponent), {
3858
3873
  onBlur() {
3859
3874
  if (this.validate()) {
3860
- validateAsync(this.validationAsyncState, this.getLocalValue()).catch(() => {
3875
+ validateAsync(this, this.getLocalValue()).catch(() => {
3861
3876
  });
3862
3877
  }
3863
3878
  }
@@ -3960,29 +3975,25 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
3960
3975
  "onValueChange",
3961
3976
  "summariser"
3962
3977
  ]);
3963
- const update = getInputUpdateFunction(uid, updateComponent);
3978
+ const update = getInputUpdateFunction(updateComponent);
3964
3979
  const getValidationErrors = getLocalValueValidator(checks);
3965
- const getAndSetValidationErrors = (currentValue) => {
3966
- const messages = getValidationErrors(currentValue);
3967
- update((draft) => {
3968
- draft.errors = messages;
3969
- });
3970
- return messages;
3971
- };
3972
3980
  const uploadComponent = __spreadValues({
3973
3981
  type: "upload",
3974
3982
  uid,
3975
3983
  id,
3976
3984
  format: "base64",
3977
3985
  value,
3986
+ _update(updateFn) {
3987
+ update(this, updateFn);
3988
+ },
3978
3989
  onBlur() {
3979
- getAndSetValidationErrors(this.getLocalValue());
3990
+ this.validate();
3980
3991
  },
3981
3992
  onFocus() {
3982
3993
  },
3983
3994
  // Noop
3984
3995
  async onUpload(updatedValue) {
3985
- update((draft) => {
3996
+ this._update((draft) => {
3986
3997
  draft.errors = [];
3987
3998
  draft.value = updatedValue;
3988
3999
  });
@@ -4004,8 +4015,11 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4004
4015
  return this.value;
4005
4016
  },
4006
4017
  validate() {
4007
- const messages = getAndSetValidationErrors(this.getLocalValue());
4008
- return messages.length === 0;
4018
+ const errors = getValidationErrors(this.getLocalValue());
4019
+ this._update((draft) => {
4020
+ draft.errors = errors;
4021
+ });
4022
+ return errors.length === 0;
4009
4023
  }
4010
4024
  }, rest);
4011
4025
  if (!performPersistAsync) {
@@ -4015,14 +4029,14 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4015
4029
  return __spreadProps(__spreadValues({}, uploadComponent), {
4016
4030
  format,
4017
4031
  async onUpload(file) {
4018
- update((draft) => {
4032
+ this._update((draft) => {
4019
4033
  draft.errors = [];
4020
4034
  draft.value = file;
4021
4035
  });
4022
4036
  onValueChange();
4023
4037
  const submission = format === "base64" && file ? await toBase64(file) : file;
4024
- await persist(this.persistedState, submission).catch((error) => {
4025
- update((draft) => {
4038
+ await persist(this, submission).catch((error) => {
4039
+ this._update((draft) => {
4026
4040
  draft.persistedState.lastResponse = null;
4027
4041
  draft.persistedState.lastSubmitted = null;
4028
4042
  draft.persistedState.submission = Promise.resolve(null);
@@ -4101,23 +4115,19 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4101
4115
  "summariser",
4102
4116
  "value"
4103
4117
  ]);
4104
- const update = getInputUpdateFunction(uid, updateComponent);
4118
+ const update = getInputUpdateFunction(updateComponent);
4105
4119
  const getValidationErrors = getLocalValueValidator(checks);
4106
4120
  const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4107
- const getAndSetValidationErrors = (currentValue) => {
4108
- const messages = getValidationErrors(currentValue);
4109
- update((draft) => {
4110
- draft.errors = messages;
4111
- });
4112
- return messages;
4113
- };
4114
4121
  const inputComponent = __spreadValues({
4115
4122
  type: "text",
4116
4123
  uid,
4117
4124
  id,
4118
4125
  value,
4126
+ _update(updateFn) {
4127
+ update(this, updateFn);
4128
+ },
4119
4129
  onBlur() {
4120
- getAndSetValidationErrors(this.getLocalValue());
4130
+ this.validate();
4121
4131
  performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
4122
4132
  },
4123
4133
  onFocus() {
@@ -4125,7 +4135,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4125
4135
  // Noop
4126
4136
  onChange(updatedValue) {
4127
4137
  const prevValue = this.value;
4128
- update((draft) => {
4138
+ this._update((draft) => {
4129
4139
  draft.errors = [];
4130
4140
  draft.validationAsyncState.messages = {};
4131
4141
  draft.value = updatedValue;
@@ -4137,8 +4147,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4137
4147
  return this.getSubmittableValueSync();
4138
4148
  },
4139
4149
  getSubmittableValueSync() {
4140
- var _a2;
4141
- return (_a2 = this.getLocalValue()) != null ? _a2 : null;
4150
+ return this.getLocalValue() || null;
4142
4151
  },
4143
4152
  getSummary() {
4144
4153
  return summariser(this.getLocalValue());
@@ -4147,8 +4156,11 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4147
4156
  return this.value;
4148
4157
  },
4149
4158
  validate() {
4150
- const messages = getAndSetValidationErrors(this.getLocalValue());
4151
- return messages.length === 0;
4159
+ const errors = getValidationErrors(this.getLocalValue());
4160
+ this._update((draft) => {
4161
+ draft.errors = errors;
4162
+ });
4163
+ return errors.length === 0;
4152
4164
  }
4153
4165
  }, rest);
4154
4166
  if (performRefresh) {
@@ -4159,12 +4171,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4159
4171
  return __spreadProps(__spreadValues({}, inputComponent), {
4160
4172
  onBlur() {
4161
4173
  if (this.validate()) {
4162
- persist(this.persistedState, this.getLocalValue()).catch(() => {
4174
+ persist(this, this.getLocalValue()).catch(() => {
4163
4175
  });
4164
4176
  }
4165
4177
  },
4166
4178
  async getSubmittableValue() {
4167
- return persist(this.persistedState, this.getLocalValue());
4179
+ return persist(this, this.getLocalValue());
4168
4180
  },
4169
4181
  getSubmittableValueSync() {
4170
4182
  return this.persistedState.lastResponse;
@@ -4182,7 +4194,10 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4182
4194
  onChange(updatedValue) {
4183
4195
  inputComponent.onChange.call(this, updatedValue);
4184
4196
  if (getValidationErrors(updatedValue).length === 0) {
4185
- validateAsync(this.validationAsyncState, updatedValue);
4197
+ validateAsync(this, updatedValue);
4198
+ }
4199
+ if (!updatedValue) {
4200
+ validateAsync.cancel();
4186
4201
  }
4187
4202
  }
4188
4203
  });
@@ -4317,9 +4332,9 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4317
4332
  "createEditableComponent",
4318
4333
  "summariser"
4319
4334
  ]);
4320
- const update = getInputUpdateFunction(uid, updateComponent);
4335
+ const update = getInputUpdateFunction(updateComponent);
4321
4336
  const getValidationErrors = getLocalValueValidator(checks);
4322
- return __spreadProps(__spreadValues({
4337
+ const repeatableComponent = __spreadProps(__spreadValues({
4323
4338
  uid,
4324
4339
  id,
4325
4340
  type: "repeatable",
@@ -4333,8 +4348,11 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4333
4348
  image: summary == null ? void 0 : summary.defaultImage
4334
4349
  }
4335
4350
  }, componentProps), {
4351
+ _update(updateFn) {
4352
+ update(this, updateFn);
4353
+ },
4336
4354
  onEdit(itemIndex) {
4337
- update((draft) => {
4355
+ this._update((draft) => {
4338
4356
  draft.editableComponent = createEditableComponent(
4339
4357
  draft.components[itemIndex].getLocalValue()
4340
4358
  );
@@ -4342,7 +4360,7 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4342
4360
  });
4343
4361
  },
4344
4362
  onAdd() {
4345
- update((draft) => {
4363
+ this._update((draft) => {
4346
4364
  draft.editableComponent = createEditableComponent(null);
4347
4365
  draft.editableIndex = null;
4348
4366
  draft.errors = [];
@@ -4354,7 +4372,7 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4354
4372
  if (!isValid) {
4355
4373
  return false;
4356
4374
  }
4357
- update((draft) => {
4375
+ this._update((draft) => {
4358
4376
  if (draft.editableComponent === null) {
4359
4377
  return;
4360
4378
  }
@@ -4373,7 +4391,7 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4373
4391
  return true;
4374
4392
  },
4375
4393
  onRemove() {
4376
- update((draft) => {
4394
+ this._update((draft) => {
4377
4395
  if (draft.editableIndex === null) {
4378
4396
  return;
4379
4397
  }
@@ -4401,12 +4419,13 @@ var createRepeatableComponent = (repeatableProps, updateComponent) => {
4401
4419
  validate() {
4402
4420
  const messages = getValidationErrors(this.getLocalValue());
4403
4421
  const childComponentsValid = validateComponents(this.getChildren());
4404
- update((draft) => {
4422
+ this._update((draft) => {
4405
4423
  draft.errors = messages;
4406
4424
  });
4407
4425
  return messages.length === 0 && childComponentsValid;
4408
4426
  }
4409
4427
  });
4428
+ return repeatableComponent;
4410
4429
  };
4411
4430
 
4412
4431
  // src/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToRepeatableComponent.ts
@@ -4506,30 +4525,26 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4506
4525
  "onValueChange",
4507
4526
  "summariser"
4508
4527
  ]);
4509
- const update = getInputUpdateFunction(uid, updateComponent);
4528
+ const update = getInputUpdateFunction(updateComponent);
4510
4529
  const getValidationErrors = getLocalValueValidator(checks);
4511
4530
  const getFileValidationErrors = getLocalValueValidator(fileChecks);
4512
- const getAndSetValidationErrors = (currentValue) => {
4513
- const messages = getValidationErrors(currentValue);
4514
- update((draft) => {
4515
- draft.errors = messages;
4516
- });
4517
- return messages;
4518
- };
4519
4531
  const uploadComponent = __spreadValues({
4520
4532
  type: "multi-upload",
4521
4533
  uid,
4522
4534
  id,
4523
4535
  format: "base64",
4524
4536
  files: [],
4537
+ _update(updateFn) {
4538
+ update(this, updateFn);
4539
+ },
4525
4540
  onBlur() {
4526
- getAndSetValidationErrors(this.getLocalValue());
4541
+ this.validate();
4527
4542
  },
4528
4543
  onFocus() {
4529
4544
  },
4530
4545
  // Noop
4531
4546
  async onRemoveFile(index) {
4532
- update((draft) => {
4547
+ this._update((draft) => {
4533
4548
  draft.value.splice(index, 1);
4534
4549
  draft.files.splice(index, 1);
4535
4550
  });
@@ -4537,7 +4552,7 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4537
4552
  async onInsertFile(index, file) {
4538
4553
  const fileErrors = getFileValidationErrors(file);
4539
4554
  const fileId = getRandomId();
4540
- update((draft) => {
4555
+ this._update((draft) => {
4541
4556
  draft.value.splice(index, 0, file);
4542
4557
  draft.files.splice(index, 0, { file, id: fileId, errors: fileErrors });
4543
4558
  draft.errors = [];
@@ -4559,8 +4574,11 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4559
4574
  return this.value;
4560
4575
  },
4561
4576
  validate() {
4562
- const messages = getAndSetValidationErrors(this.getLocalValue());
4563
- return messages.length === 0 && this.files.every(({ errors }) => errors.length === 0);
4577
+ const errorMsgs = getValidationErrors(this.getLocalValue());
4578
+ this._update((draft) => {
4579
+ draft.errors = errorMsgs;
4580
+ });
4581
+ return errorMsgs.length === 0 && this.files.every(({ errors }) => errors.length === 0);
4564
4582
  }
4565
4583
  }, rest);
4566
4584
  if (!performPersistAsync) {
@@ -4572,7 +4590,7 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4572
4590
  async onInsertFile(index, file) {
4573
4591
  const fileId = await uploadComponent.onInsertFile.call(this, index, file);
4574
4592
  const submission = format === "blob" ? file : await toBase64(file);
4575
- await persist(index, submission);
4593
+ await persist(this, index, submission);
4576
4594
  onValueChange();
4577
4595
  return fileId;
4578
4596
  },
@@ -4580,7 +4598,7 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4580
4598
  var _a2;
4581
4599
  await uploadComponent.onRemoveFile.call(this, index);
4582
4600
  (_a2 = this.persistedState[index]) == null ? void 0 : _a2.abortController.abort();
4583
- update((draft) => {
4601
+ this._update((draft) => {
4584
4602
  draft.persistedState = draft.persistedState.splice(index, 1);
4585
4603
  });
4586
4604
  },
@@ -4686,17 +4704,10 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4686
4704
  "performRefresh",
4687
4705
  "onValueChange"
4688
4706
  ]);
4689
- const update = getInputUpdateFunction(uid, updateComponent);
4707
+ const update = getInputUpdateFunction(updateComponent);
4690
4708
  const children = options.map((option) => option.component);
4691
4709
  const selectedIndices = getInitialModelIndices(initialValue, children);
4692
4710
  const getValidationErrors = getLocalValueValidator(checks);
4693
- const getAndSetValidationErrors = (currentValue) => {
4694
- const messages = getValidationErrors(currentValue);
4695
- update((draft) => {
4696
- draft.errors = messages;
4697
- });
4698
- return messages;
4699
- };
4700
4711
  const inputComponent = __spreadProps(__spreadValues({
4701
4712
  uid,
4702
4713
  type: "multi-select",
@@ -4705,14 +4716,20 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4705
4716
  selectedIndices,
4706
4717
  value: null
4707
4718
  }, rest), {
4719
+ _update(updateFn) {
4720
+ update(this, updateFn);
4721
+ },
4708
4722
  onSelect(indices) {
4709
- update((draft) => {
4723
+ this._update((draft) => {
4710
4724
  draft.selectedIndices = indices;
4711
4725
  draft.errors = [];
4712
4726
  });
4713
4727
  performRefresh == null ? void 0 : performRefresh();
4714
4728
  onValueChange();
4715
- getAndSetValidationErrors(this.getLocalValue());
4729
+ const errors = getValidationErrors(this.getLocalValue());
4730
+ this._update((draft) => {
4731
+ draft.errors = errors;
4732
+ });
4716
4733
  },
4717
4734
  onBlur() {
4718
4735
  },
@@ -4725,8 +4742,11 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4725
4742
  return (_b = (_a2 = this.getSelectedChildren()) == null ? void 0 : _a2.map((child) => child.getLocalValue())) != null ? _b : null;
4726
4743
  },
4727
4744
  validate() {
4728
- const messages = getAndSetValidationErrors(this.getLocalValue());
4729
- return messages.length === 0;
4745
+ const errors = getValidationErrors(this.getLocalValue());
4746
+ this._update((draft) => {
4747
+ draft.errors = errors;
4748
+ });
4749
+ return errors.length === 0;
4730
4750
  },
4731
4751
  async getSubmittableValue() {
4732
4752
  const selected = this.getSelectedChildren();
@@ -4756,7 +4776,7 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4756
4776
  onSelect(indices) {
4757
4777
  inputComponent.onSelect.call(this, indices);
4758
4778
  if (this.validate()) {
4759
- validateAsync(this.validationAsyncState, this.getLocalValue()).catch(() => {
4779
+ validateAsync(this, this.getLocalValue()).catch(() => {
4760
4780
  });
4761
4781
  }
4762
4782
  }
@@ -4957,13 +4977,16 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4957
4977
  "onValueChange",
4958
4978
  "summariser"
4959
4979
  ]);
4960
- const update = getInputUpdateFunction(uid, updateComponent);
4980
+ const update = getInputUpdateFunction(updateComponent);
4961
4981
  const booleanComponent = __spreadValues({
4962
4982
  type: "boolean",
4963
4983
  uid,
4964
4984
  id,
4965
4985
  autoComplete: "",
4966
4986
  value,
4987
+ _update(updateFn) {
4988
+ update(this, updateFn);
4989
+ },
4967
4990
  onBlur() {
4968
4991
  },
4969
4992
  // Noop
@@ -4971,7 +4994,7 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4971
4994
  },
4972
4995
  // Noop
4973
4996
  onChange(updatedValue) {
4974
- update((draft) => {
4997
+ this._update((draft) => {
4975
4998
  draft.errors = [];
4976
4999
  draft.value = updatedValue;
4977
5000
  });
@@ -5000,11 +5023,11 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
5000
5023
  return __spreadProps(__spreadValues({}, booleanComponent), {
5001
5024
  onChange(updatedValue) {
5002
5025
  booleanComponent.onChange.call(this, updatedValue);
5003
- persist(this.persistedState, this.getLocalValue()).catch(() => {
5026
+ persist(this, this.getLocalValue()).catch(() => {
5004
5027
  });
5005
5028
  },
5006
5029
  async getSubmittableValue() {
5007
- return persist(this.persistedState, this.getLocalValue());
5030
+ return persist(this, this.getLocalValue());
5008
5031
  },
5009
5032
  getSubmittableValueSync() {
5010
5033
  return this.persistedState.lastResponse;
@@ -5016,7 +5039,7 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
5016
5039
  return __spreadProps(__spreadValues({}, booleanComponent), {
5017
5040
  onChange(updatedValue) {
5018
5041
  booleanComponent.onChange.call(this, updatedValue);
5019
- validateAsync(this.validationAsyncState, this.getLocalValue()).catch(() => {
5042
+ validateAsync(this, this.getLocalValue()).catch(() => {
5020
5043
  });
5021
5044
  }
5022
5045
  });
@@ -5461,9 +5484,9 @@ var getOrientationControl = ({
5461
5484
  var DEBOUNCE_TIME = 400;
5462
5485
  var createSearchComponent = (searchProps, performSearch, onBehavior, updateComponent) => {
5463
5486
  const { uid, control, emptyMessage, margin, title } = searchProps;
5464
- const update = getInputUpdateFunction(uid, updateComponent);
5487
+ const update = getInputUpdateFunction(updateComponent);
5465
5488
  let abortController = new AbortController();
5466
- const search = (query, searchConfig) => {
5489
+ const search = (component2, query, searchConfig) => {
5467
5490
  abortController.abort();
5468
5491
  abortController = new AbortController();
5469
5492
  const { signal } = abortController;
@@ -5473,7 +5496,7 @@ var createSearchComponent = (searchProps, performSearch, onBehavior, updateCompo
5473
5496
  config: searchConfig
5474
5497
  }).then((results) => {
5475
5498
  if (!signal.aborted) {
5476
- update((draft) => {
5499
+ update(component2, (draft) => {
5477
5500
  draft.results = results;
5478
5501
  draft.isLoading = false;
5479
5502
  draft.error = void 0;
@@ -5481,33 +5504,15 @@ var createSearchComponent = (searchProps, performSearch, onBehavior, updateCompo
5481
5504
  }
5482
5505
  }).catch(() => {
5483
5506
  if (!signal.aborted) {
5484
- update((draft) => {
5507
+ update(component2, (draft) => {
5485
5508
  draft.error = "No response";
5486
5509
  draft.isLoading = false;
5487
5510
  });
5488
5511
  }
5489
5512
  });
5490
5513
  };
5491
- const onSelect = ({ type, value }) => {
5492
- if (type === "action") {
5493
- void onBehavior({ type: "action", action: value });
5494
- } else {
5495
- update((draft) => {
5496
- draft.query = value.query;
5497
- draft.isLoading = true;
5498
- });
5499
- search(value.query, { method: value.method, param: value.param, url: value.url });
5500
- }
5501
- };
5502
5514
  const debouncedSearch = debounce(search, DEBOUNCE_TIME);
5503
- const onChange = (query) => {
5504
- update((draft) => {
5505
- draft.query = query;
5506
- draft.isLoading = true;
5507
- });
5508
- debouncedSearch(query.trim());
5509
- };
5510
- return {
5515
+ const component = {
5511
5516
  type: "search",
5512
5517
  uid,
5513
5518
  control,
@@ -5517,15 +5522,39 @@ var createSearchComponent = (searchProps, performSearch, onBehavior, updateCompo
5517
5522
  isLoading: false,
5518
5523
  query: "",
5519
5524
  results: [],
5525
+ _update(updateFn) {
5526
+ update(this, updateFn);
5527
+ },
5520
5528
  getSubmittableValue: async () => null,
5521
5529
  getSubmittableValueSync: () => null,
5522
5530
  getLocalValue: () => null,
5523
5531
  getSummary: () => ({}),
5524
5532
  // Noop
5525
5533
  validate: () => true,
5526
- onChange,
5527
- onSelect
5534
+ onChange(query) {
5535
+ this._update((draft) => {
5536
+ draft.query = query;
5537
+ draft.isLoading = true;
5538
+ });
5539
+ debouncedSearch(this, query.trim());
5540
+ },
5541
+ onSelect({ type, value }) {
5542
+ if (type === "action") {
5543
+ void onBehavior({ type: "action", action: value });
5544
+ } else {
5545
+ this._update((draft) => {
5546
+ draft.query = value.query;
5547
+ draft.isLoading = true;
5548
+ });
5549
+ search(this, value.query, {
5550
+ method: value.method,
5551
+ param: value.param,
5552
+ url: value.url
5553
+ });
5554
+ }
5555
+ }
5528
5556
  };
5557
+ return component;
5529
5558
  };
5530
5559
 
5531
5560
  // src/revamp/domain/features/search/getPerformSearchFunction.ts
@@ -6255,29 +6284,6 @@ var formatDateOptions = {
6255
6284
  dateStyle: "long"
6256
6285
  };
6257
6286
 
6258
- // src/revamp/utils/findComponent.ts
6259
- var findComponent = (components, id, logEvent) => {
6260
- const flattened = flattenComponents(components);
6261
- const matching = flattened.filter((component) => component.uid === id);
6262
- if (matching.length === 1) {
6263
- return matching[0];
6264
- }
6265
- if (matching.length > 1) {
6266
- throw new Error(`Multiple components with the same uid: ${id}`);
6267
- }
6268
- logEvent("error", "Failed to find domain layer component", {
6269
- componentUid: id,
6270
- componentsTree: flattened.map((component) => component.uid)
6271
- });
6272
- throw new Error(`Failed to find any components with uid: ${id}`);
6273
- };
6274
- var flattenComponents = (components) => components.reduce((acc, component) => {
6275
- if (hasChildren(component)) {
6276
- return [...acc, component, ...flattenComponents(component.getChildren())];
6277
- }
6278
- return [...acc, component];
6279
- }, []);
6280
-
6281
6287
  // src/revamp/utils/useStableCallback.tsx
6282
6288
  var import_react2 = require("react");
6283
6289
  function useStableCallback(handler) {
@@ -6304,15 +6310,7 @@ function useDynamicFlowCore(props) {
6304
6310
  [formatMessage, locale]
6305
6311
  );
6306
6312
  const rerender = useRerender();
6307
- const rootComponentRef = (0, import_react3.useRef)(createRootDomainComponent());
6308
- const updateComponent = (0, import_react3.useCallback)(
6309
- (id, update) => {
6310
- update(findComponent([rootComponentRef.current], id, logEvent));
6311
- rerender();
6312
- },
6313
- // eslint-disable-next-line react-hooks/exhaustive-deps
6314
- []
6315
- );
6313
+ const rootComponentRef = (0, import_react3.useRef)(createRootDomainComponent(rerender));
6316
6314
  const stepCount = (0, import_react3.useRef)(0);
6317
6315
  const stepRef = (0, import_react3.useRef)(initialStep != null ? initialStep : null);
6318
6316
  const etagRef = (0, import_react3.useRef)(null);
@@ -6357,25 +6355,24 @@ function useDynamicFlowCore(props) {
6357
6355
  });
6358
6356
  }
6359
6357
  try {
6360
- const newStepComponent = mapStepToComponent({
6361
- uid: `${rootComponentRef.current.uid}:${stepCount.current}`,
6362
- stepLocalValue: localValue,
6363
- step: newStep,
6364
- displayStepTitle,
6365
- loadingState: "idle",
6366
- updateComponent,
6367
- getErrorMessageFunctions,
6368
- trackEvent,
6369
- logEvent,
6370
- httpClient,
6371
- onBehavior,
6372
- onRefresh,
6373
- onPoll,
6374
- onValueChange
6375
- });
6376
- updateComponent(rootComponentRef.current.uid, (draft) => {
6377
- draft.stepComponent = newStepComponent;
6378
- });
6358
+ rootComponentRef.current.setStep(
6359
+ mapStepToComponent({
6360
+ uid: `${rootComponentRef.current.uid}:${stepCount.current}`,
6361
+ stepLocalValue: localValue,
6362
+ step: newStep,
6363
+ displayStepTitle,
6364
+ loadingState: "idle",
6365
+ updateComponent: () => rerender(),
6366
+ getErrorMessageFunctions,
6367
+ trackEvent,
6368
+ logEvent,
6369
+ httpClient,
6370
+ onBehavior,
6371
+ onRefresh,
6372
+ onPoll,
6373
+ onValueChange
6374
+ })
6375
+ );
6379
6376
  } catch (error) {
6380
6377
  closeWithError(error);
6381
6378
  }