@wise/dynamic-flow-client 4.3.9 → 4.3.10

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
@@ -2563,9 +2563,17 @@ var debounce = (callback, waitMs) => {
2563
2563
  clearTimer();
2564
2564
  }
2565
2565
  };
2566
+ debouncedFn.isPending = () => timeoutId !== null;
2566
2567
  return debouncedFn;
2567
2568
  };
2568
2569
 
2570
+ // src/revamp/domain/components/utils/isOrWasValid.ts
2571
+ var isOrWasValid = (getErrors, previous, current) => {
2572
+ const wasValid = getErrors(previous).length === 0 && previous !== null;
2573
+ const isValid = getErrors(current).length === 0;
2574
+ return wasValid || isValid;
2575
+ };
2576
+
2569
2577
  // src/revamp/domain/features/refresh/getPerformRefresh.ts
2570
2578
  var getPerformRefresh = (schema, onRefresh) => {
2571
2579
  var _a, _b;
@@ -2578,7 +2586,21 @@ var getPerformRefresh = (schema, onRefresh) => {
2578
2586
  }
2579
2587
  return void 0;
2580
2588
  };
2581
- var getDebouncedPerformRefresh = (performRefresh) => performRefresh ? debounce(performRefresh, 1e3) : void 0;
2589
+ var getDebouncedPerformRefresh = (performRefresh, getValidationErrors) => {
2590
+ if (!performRefresh) {
2591
+ return void 0;
2592
+ }
2593
+ const performDebouncedRefresh = debounce(performRefresh, 1e3);
2594
+ const debouncedFn = (prevValue, updatedValue) => {
2595
+ if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.isPending())) {
2596
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2597
+ }
2598
+ };
2599
+ debouncedFn.flush = () => performDebouncedRefresh.flush();
2600
+ debouncedFn.cancel = () => performDebouncedRefresh.cancel();
2601
+ debouncedFn.isPending = () => performDebouncedRefresh.isPending();
2602
+ return debouncedFn;
2603
+ };
2582
2604
 
2583
2605
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
2584
2606
  var getComponentValidationAsync = (update, performValidationAsync) => (
@@ -2629,9 +2651,6 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2629
2651
  }
2630
2652
  );
2631
2653
 
2632
- // src/revamp/domain/components/utils/isOrWasValid.ts
2633
- var isOrWasValid = (getErrors, previous, current) => getErrors(previous).length === 0 || getErrors(current).length === 0;
2634
-
2635
2654
  // src/revamp/domain/components/NumberInputComponent.ts
2636
2655
  var createNumberInputComponent = (numberInputProps, updateComponent) => {
2637
2656
  const _a = numberInputProps, {
@@ -2653,9 +2672,9 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2653
2672
  "onValueChange",
2654
2673
  "summariser"
2655
2674
  ]);
2656
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
2657
2675
  const update = getInputUpdateFunction(uid, updateComponent);
2658
2676
  const getValidationErrors = getLocalValueValidator(checks);
2677
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
2659
2678
  const getAndSetValidationErrors = (currentValue) => {
2660
2679
  const messages = getValidationErrors(currentValue);
2661
2680
  update((draft) => {
@@ -2681,9 +2700,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2681
2700
  draft.validationAsyncState.messages = {};
2682
2701
  draft.value = updatedValue;
2683
2702
  });
2684
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
2685
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2686
- }
2703
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
2687
2704
  onValueChange();
2688
2705
  },
2689
2706
  async getSubmittableValue() {
@@ -3445,9 +3462,9 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3445
3462
  "onValueChange",
3446
3463
  "summariser"
3447
3464
  ]);
3448
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
3449
3465
  const update = getInputUpdateFunction(uid, updateComponent);
3450
3466
  const getValidationErrors = getLocalValueValidator(checks);
3467
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3451
3468
  const getAndSetValidationErrors = (currentValue) => {
3452
3469
  const messages = getValidationErrors(currentValue);
3453
3470
  update((draft) => {
@@ -3474,9 +3491,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3474
3491
  draft.validationAsyncState.messages = {};
3475
3492
  draft.value = updatedValue;
3476
3493
  });
3477
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
3478
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3479
- }
3494
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3480
3495
  onValueChange();
3481
3496
  },
3482
3497
  async getSubmittableValue() {
@@ -4078,9 +4093,9 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4078
4093
  "summariser",
4079
4094
  "value"
4080
4095
  ]);
4081
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
4082
4096
  const update = getInputUpdateFunction(uid, updateComponent);
4083
4097
  const getValidationErrors = getLocalValueValidator(checks);
4098
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4084
4099
  const getAndSetValidationErrors = (currentValue) => {
4085
4100
  const messages = getValidationErrors(currentValue);
4086
4101
  update((draft) => {
@@ -4107,9 +4122,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4107
4122
  draft.validationAsyncState.messages = {};
4108
4123
  draft.value = updatedValue;
4109
4124
  });
4110
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
4111
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
4112
- }
4125
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4113
4126
  onValueChange();
4114
4127
  },
4115
4128
  async getSubmittableValue() {
package/build/main.mjs CHANGED
@@ -2520,9 +2520,17 @@ var debounce = (callback, waitMs) => {
2520
2520
  clearTimer();
2521
2521
  }
2522
2522
  };
2523
+ debouncedFn.isPending = () => timeoutId !== null;
2523
2524
  return debouncedFn;
2524
2525
  };
2525
2526
 
2527
+ // src/revamp/domain/components/utils/isOrWasValid.ts
2528
+ var isOrWasValid = (getErrors, previous, current) => {
2529
+ const wasValid = getErrors(previous).length === 0 && previous !== null;
2530
+ const isValid = getErrors(current).length === 0;
2531
+ return wasValid || isValid;
2532
+ };
2533
+
2526
2534
  // src/revamp/domain/features/refresh/getPerformRefresh.ts
2527
2535
  var getPerformRefresh = (schema, onRefresh) => {
2528
2536
  var _a, _b;
@@ -2535,7 +2543,21 @@ var getPerformRefresh = (schema, onRefresh) => {
2535
2543
  }
2536
2544
  return void 0;
2537
2545
  };
2538
- var getDebouncedPerformRefresh = (performRefresh) => performRefresh ? debounce(performRefresh, 1e3) : void 0;
2546
+ var getDebouncedPerformRefresh = (performRefresh, getValidationErrors) => {
2547
+ if (!performRefresh) {
2548
+ return void 0;
2549
+ }
2550
+ const performDebouncedRefresh = debounce(performRefresh, 1e3);
2551
+ const debouncedFn = (prevValue, updatedValue) => {
2552
+ if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.isPending())) {
2553
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2554
+ }
2555
+ };
2556
+ debouncedFn.flush = () => performDebouncedRefresh.flush();
2557
+ debouncedFn.cancel = () => performDebouncedRefresh.cancel();
2558
+ debouncedFn.isPending = () => performDebouncedRefresh.isPending();
2559
+ return debouncedFn;
2560
+ };
2539
2561
 
2540
2562
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
2541
2563
  var getComponentValidationAsync = (update, performValidationAsync) => (
@@ -2586,9 +2608,6 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2586
2608
  }
2587
2609
  );
2588
2610
 
2589
- // src/revamp/domain/components/utils/isOrWasValid.ts
2590
- var isOrWasValid = (getErrors, previous, current) => getErrors(previous).length === 0 || getErrors(current).length === 0;
2591
-
2592
2611
  // src/revamp/domain/components/NumberInputComponent.ts
2593
2612
  var createNumberInputComponent = (numberInputProps, updateComponent) => {
2594
2613
  const _a = numberInputProps, {
@@ -2610,9 +2629,9 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2610
2629
  "onValueChange",
2611
2630
  "summariser"
2612
2631
  ]);
2613
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
2614
2632
  const update = getInputUpdateFunction(uid, updateComponent);
2615
2633
  const getValidationErrors = getLocalValueValidator(checks);
2634
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
2616
2635
  const getAndSetValidationErrors = (currentValue) => {
2617
2636
  const messages = getValidationErrors(currentValue);
2618
2637
  update((draft) => {
@@ -2638,9 +2657,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2638
2657
  draft.validationAsyncState.messages = {};
2639
2658
  draft.value = updatedValue;
2640
2659
  });
2641
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
2642
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2643
- }
2660
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
2644
2661
  onValueChange();
2645
2662
  },
2646
2663
  async getSubmittableValue() {
@@ -3402,9 +3419,9 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3402
3419
  "onValueChange",
3403
3420
  "summariser"
3404
3421
  ]);
3405
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
3406
3422
  const update = getInputUpdateFunction(uid, updateComponent);
3407
3423
  const getValidationErrors = getLocalValueValidator(checks);
3424
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3408
3425
  const getAndSetValidationErrors = (currentValue) => {
3409
3426
  const messages = getValidationErrors(currentValue);
3410
3427
  update((draft) => {
@@ -3431,9 +3448,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3431
3448
  draft.validationAsyncState.messages = {};
3432
3449
  draft.value = updatedValue;
3433
3450
  });
3434
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
3435
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3436
- }
3451
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3437
3452
  onValueChange();
3438
3453
  },
3439
3454
  async getSubmittableValue() {
@@ -4035,9 +4050,9 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4035
4050
  "summariser",
4036
4051
  "value"
4037
4052
  ]);
4038
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
4039
4053
  const update = getInputUpdateFunction(uid, updateComponent);
4040
4054
  const getValidationErrors = getLocalValueValidator(checks);
4055
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4041
4056
  const getAndSetValidationErrors = (currentValue) => {
4042
4057
  const messages = getValidationErrors(currentValue);
4043
4058
  update((draft) => {
@@ -4064,9 +4079,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4064
4079
  draft.validationAsyncState.messages = {};
4065
4080
  draft.value = updatedValue;
4066
4081
  });
4067
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
4068
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
4069
- }
4082
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4070
4083
  onValueChange();
4071
4084
  },
4072
4085
  async getSubmittableValue() {
@@ -2,5 +2,6 @@ export interface DebouncedFunc<T extends (...args: Parameters<T>) => ReturnType<
2
2
  (...args: Parameters<T>): void;
3
3
  cancel: () => void;
4
4
  flush: () => void;
5
+ isPending: () => boolean;
5
6
  }
6
7
  export declare const debounce: <T extends (...args: Parameters<T>) => ReturnType<T>>(callback: T, waitMs: number) => DebouncedFunc<T>;
@@ -1,5 +1,12 @@
1
1
  import type { Schema } from '@wise/dynamic-flow-types/build/next';
2
- import type { OnRefresh } from '../../types';
2
+ import type { LocalValue, OnRefresh } from '../../types';
3
3
  export type PerformRefresh = () => void;
4
4
  export declare const getPerformRefresh: (schema: Schema, onRefresh: OnRefresh) => PerformRefresh | undefined;
5
- export declare const getDebouncedPerformRefresh: (performRefresh: PerformRefresh | undefined) => import("../../components/utils/debounce").DebouncedFunc<PerformRefresh> | undefined;
5
+ type DebouncedPerformRefresh<V extends LocalValue> = {
6
+ (prevValue: V, updatedValue: V): void;
7
+ cancel: () => void;
8
+ flush: () => void;
9
+ isPending: () => boolean;
10
+ };
11
+ export declare const getDebouncedPerformRefresh: <V extends LocalValue>(performRefresh: PerformRefresh | undefined, getValidationErrors: (value: V) => string[]) => DebouncedPerformRefresh<V> | undefined;
12
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "4.3.9",
3
+ "version": "4.3.10",
4
4
  "description": "Dynamic Flow web client",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.js",
@@ -85,8 +85,8 @@
85
85
  "tsx": "4.19.3",
86
86
  "typescript": "5.8.3",
87
87
  "webpack": "5.98.0",
88
- "@wise/dynamic-flow-fixtures": "0.0.1",
89
- "@wise/dynamic-flow-renderers": "0.0.0"
88
+ "@wise/dynamic-flow-renderers": "0.0.0",
89
+ "@wise/dynamic-flow-fixtures": "0.0.1"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "@transferwise/components": "^46.92.0",