@wise/dynamic-flow-client 4.3.8 → 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
@@ -2508,6 +2508,8 @@ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
2508
2508
  ...draft.persistedState.slice(0, index),
2509
2509
  ...draft.persistedState.slice(index + 1)
2510
2510
  ];
2511
+ draft.value.splice(index, 1);
2512
+ draft.files.splice(index, 1);
2511
2513
  });
2512
2514
  throw error;
2513
2515
  });
@@ -2561,9 +2563,17 @@ var debounce = (callback, waitMs) => {
2561
2563
  clearTimer();
2562
2564
  }
2563
2565
  };
2566
+ debouncedFn.isPending = () => timeoutId !== null;
2564
2567
  return debouncedFn;
2565
2568
  };
2566
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
+
2567
2577
  // src/revamp/domain/features/refresh/getPerformRefresh.ts
2568
2578
  var getPerformRefresh = (schema, onRefresh) => {
2569
2579
  var _a, _b;
@@ -2576,7 +2586,21 @@ var getPerformRefresh = (schema, onRefresh) => {
2576
2586
  }
2577
2587
  return void 0;
2578
2588
  };
2579
- 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
+ };
2580
2604
 
2581
2605
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
2582
2606
  var getComponentValidationAsync = (update, performValidationAsync) => (
@@ -2627,9 +2651,6 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2627
2651
  }
2628
2652
  );
2629
2653
 
2630
- // src/revamp/domain/components/utils/isOrWasValid.ts
2631
- var isOrWasValid = (getErrors, previous, current) => getErrors(previous).length === 0 || getErrors(current).length === 0;
2632
-
2633
2654
  // src/revamp/domain/components/NumberInputComponent.ts
2634
2655
  var createNumberInputComponent = (numberInputProps, updateComponent) => {
2635
2656
  const _a = numberInputProps, {
@@ -2651,9 +2672,9 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2651
2672
  "onValueChange",
2652
2673
  "summariser"
2653
2674
  ]);
2654
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
2655
2675
  const update = getInputUpdateFunction(uid, updateComponent);
2656
2676
  const getValidationErrors = getLocalValueValidator(checks);
2677
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
2657
2678
  const getAndSetValidationErrors = (currentValue) => {
2658
2679
  const messages = getValidationErrors(currentValue);
2659
2680
  update((draft) => {
@@ -2679,9 +2700,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2679
2700
  draft.validationAsyncState.messages = {};
2680
2701
  draft.value = updatedValue;
2681
2702
  });
2682
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
2683
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2684
- }
2703
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
2685
2704
  onValueChange();
2686
2705
  },
2687
2706
  async getSubmittableValue() {
@@ -3443,9 +3462,9 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3443
3462
  "onValueChange",
3444
3463
  "summariser"
3445
3464
  ]);
3446
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
3447
3465
  const update = getInputUpdateFunction(uid, updateComponent);
3448
3466
  const getValidationErrors = getLocalValueValidator(checks);
3467
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3449
3468
  const getAndSetValidationErrors = (currentValue) => {
3450
3469
  const messages = getValidationErrors(currentValue);
3451
3470
  update((draft) => {
@@ -3472,9 +3491,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3472
3491
  draft.validationAsyncState.messages = {};
3473
3492
  draft.value = updatedValue;
3474
3493
  });
3475
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
3476
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3477
- }
3494
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3478
3495
  onValueChange();
3479
3496
  },
3480
3497
  async getSubmittableValue() {
@@ -4076,9 +4093,9 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4076
4093
  "summariser",
4077
4094
  "value"
4078
4095
  ]);
4079
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
4080
4096
  const update = getInputUpdateFunction(uid, updateComponent);
4081
4097
  const getValidationErrors = getLocalValueValidator(checks);
4098
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4082
4099
  const getAndSetValidationErrors = (currentValue) => {
4083
4100
  const messages = getValidationErrors(currentValue);
4084
4101
  update((draft) => {
@@ -4105,9 +4122,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4105
4122
  draft.validationAsyncState.messages = {};
4106
4123
  draft.value = updatedValue;
4107
4124
  });
4108
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
4109
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
4110
- }
4125
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4111
4126
  onValueChange();
4112
4127
  },
4113
4128
  async getSubmittableValue() {
@@ -6357,12 +6372,12 @@ function useDynamicFlowCore(props) {
6357
6372
  );
6358
6373
  const trackEvent = (0, import_react3.useCallback)(
6359
6374
  (eventName, properties) => {
6360
- var _a2, _b, _c, _d;
6361
- const stepId = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key;
6362
- const analytics = (_d = stepRef.current) == null ? void 0 : _d.analytics;
6363
- const metadata = __spreadValues(__spreadValues(__spreadValues({
6375
+ var _a2, _b, _c, _d, _e;
6376
+ const stepId = stepRef.current ? (_d = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key) != null ? _d : "" : null;
6377
+ const analytics = (_e = stepRef.current) == null ? void 0 : _e.analytics;
6378
+ const metadata = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
6364
6379
  flowId
6365
- }, stepId ? { stepId } : {}), analytics), properties);
6380
+ }, stepId !== null ? { stepId } : {}), stepRef.current ? { stepCount: stepCount.current } : {}), analytics), properties);
6366
6381
  try {
6367
6382
  onEvent == null ? void 0 : onEvent(`Dynamic Flow - ${eventName}`, __spreadValues({}, metadata));
6368
6383
  } catch (e) {
@@ -6374,12 +6389,12 @@ function useDynamicFlowCore(props) {
6374
6389
  const trackCoreEvent = trackEvent;
6375
6390
  const logEvent = (0, import_react3.useCallback)(
6376
6391
  (level, message, properties) => {
6377
- var _a2, _b, _c;
6392
+ var _a2, _b, _c, _d;
6393
+ const stepId = stepRef.current ? (_d = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key) != null ? _d : "" : null;
6378
6394
  try {
6379
- onLog == null ? void 0 : onLog(level, message, __spreadProps(__spreadValues({}, properties), {
6380
- flowId,
6381
- stepId: (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key
6382
- }));
6395
+ onLog == null ? void 0 : onLog(level, message, __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, properties), {
6396
+ flowId
6397
+ }), stepId !== null ? { stepId } : {}), stepRef.current ? { stepCount: stepCount.current } : {}));
6383
6398
  } catch (e) {
6384
6399
  }
6385
6400
  },
package/build/main.mjs CHANGED
@@ -2465,6 +2465,8 @@ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
2465
2465
  ...draft.persistedState.slice(0, index),
2466
2466
  ...draft.persistedState.slice(index + 1)
2467
2467
  ];
2468
+ draft.value.splice(index, 1);
2469
+ draft.files.splice(index, 1);
2468
2470
  });
2469
2471
  throw error;
2470
2472
  });
@@ -2518,9 +2520,17 @@ var debounce = (callback, waitMs) => {
2518
2520
  clearTimer();
2519
2521
  }
2520
2522
  };
2523
+ debouncedFn.isPending = () => timeoutId !== null;
2521
2524
  return debouncedFn;
2522
2525
  };
2523
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
+
2524
2534
  // src/revamp/domain/features/refresh/getPerformRefresh.ts
2525
2535
  var getPerformRefresh = (schema, onRefresh) => {
2526
2536
  var _a, _b;
@@ -2533,7 +2543,21 @@ var getPerformRefresh = (schema, onRefresh) => {
2533
2543
  }
2534
2544
  return void 0;
2535
2545
  };
2536
- 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
+ };
2537
2561
 
2538
2562
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
2539
2563
  var getComponentValidationAsync = (update, performValidationAsync) => (
@@ -2584,9 +2608,6 @@ var getComponentValidationAsync = (update, performValidationAsync) => (
2584
2608
  }
2585
2609
  );
2586
2610
 
2587
- // src/revamp/domain/components/utils/isOrWasValid.ts
2588
- var isOrWasValid = (getErrors, previous, current) => getErrors(previous).length === 0 || getErrors(current).length === 0;
2589
-
2590
2611
  // src/revamp/domain/components/NumberInputComponent.ts
2591
2612
  var createNumberInputComponent = (numberInputProps, updateComponent) => {
2592
2613
  const _a = numberInputProps, {
@@ -2608,9 +2629,9 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2608
2629
  "onValueChange",
2609
2630
  "summariser"
2610
2631
  ]);
2611
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
2612
2632
  const update = getInputUpdateFunction(uid, updateComponent);
2613
2633
  const getValidationErrors = getLocalValueValidator(checks);
2634
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
2614
2635
  const getAndSetValidationErrors = (currentValue) => {
2615
2636
  const messages = getValidationErrors(currentValue);
2616
2637
  update((draft) => {
@@ -2636,9 +2657,7 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
2636
2657
  draft.validationAsyncState.messages = {};
2637
2658
  draft.value = updatedValue;
2638
2659
  });
2639
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
2640
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
2641
- }
2660
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
2642
2661
  onValueChange();
2643
2662
  },
2644
2663
  async getSubmittableValue() {
@@ -3400,9 +3419,9 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3400
3419
  "onValueChange",
3401
3420
  "summariser"
3402
3421
  ]);
3403
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
3404
3422
  const update = getInputUpdateFunction(uid, updateComponent);
3405
3423
  const getValidationErrors = getLocalValueValidator(checks);
3424
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3406
3425
  const getAndSetValidationErrors = (currentValue) => {
3407
3426
  const messages = getValidationErrors(currentValue);
3408
3427
  update((draft) => {
@@ -3429,9 +3448,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
3429
3448
  draft.validationAsyncState.messages = {};
3430
3449
  draft.value = updatedValue;
3431
3450
  });
3432
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
3433
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3434
- }
3451
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3435
3452
  onValueChange();
3436
3453
  },
3437
3454
  async getSubmittableValue() {
@@ -4033,9 +4050,9 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4033
4050
  "summariser",
4034
4051
  "value"
4035
4052
  ]);
4036
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh);
4037
4053
  const update = getInputUpdateFunction(uid, updateComponent);
4038
4054
  const getValidationErrors = getLocalValueValidator(checks);
4055
+ const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4039
4056
  const getAndSetValidationErrors = (currentValue) => {
4040
4057
  const messages = getValidationErrors(currentValue);
4041
4058
  update((draft) => {
@@ -4062,9 +4079,7 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
4062
4079
  draft.validationAsyncState.messages = {};
4063
4080
  draft.value = updatedValue;
4064
4081
  });
4065
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
4066
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
4067
- }
4082
+ performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4068
4083
  onValueChange();
4069
4084
  },
4070
4085
  async getSubmittableValue() {
@@ -6314,12 +6329,12 @@ function useDynamicFlowCore(props) {
6314
6329
  );
6315
6330
  const trackEvent = useCallback2(
6316
6331
  (eventName, properties) => {
6317
- var _a2, _b, _c, _d;
6318
- const stepId = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key;
6319
- const analytics = (_d = stepRef.current) == null ? void 0 : _d.analytics;
6320
- const metadata = __spreadValues(__spreadValues(__spreadValues({
6332
+ var _a2, _b, _c, _d, _e;
6333
+ const stepId = stepRef.current ? (_d = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key) != null ? _d : "" : null;
6334
+ const analytics = (_e = stepRef.current) == null ? void 0 : _e.analytics;
6335
+ const metadata = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
6321
6336
  flowId
6322
- }, stepId ? { stepId } : {}), analytics), properties);
6337
+ }, stepId !== null ? { stepId } : {}), stepRef.current ? { stepCount: stepCount.current } : {}), analytics), properties);
6323
6338
  try {
6324
6339
  onEvent == null ? void 0 : onEvent(`Dynamic Flow - ${eventName}`, __spreadValues({}, metadata));
6325
6340
  } catch (e) {
@@ -6331,12 +6346,12 @@ function useDynamicFlowCore(props) {
6331
6346
  const trackCoreEvent = trackEvent;
6332
6347
  const logEvent = useCallback2(
6333
6348
  (level, message, properties) => {
6334
- var _a2, _b, _c;
6349
+ var _a2, _b, _c, _d;
6350
+ const stepId = stepRef.current ? (_d = (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key) != null ? _d : "" : null;
6335
6351
  try {
6336
- onLog == null ? void 0 : onLog(level, message, __spreadProps(__spreadValues({}, properties), {
6337
- flowId,
6338
- stepId: (_c = (_a2 = stepRef.current) == null ? void 0 : _a2.id) != null ? _c : (_b = stepRef.current) == null ? void 0 : _b.key
6339
- }));
6352
+ onLog == null ? void 0 : onLog(level, message, __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, properties), {
6353
+ flowId
6354
+ }), stepId !== null ? { stepId } : {}), stepRef.current ? { stepCount: stepCount.current } : {}));
6340
6355
  } catch (e) {
6341
6356
  }
6342
6357
  },
@@ -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.8",
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",