@wise/dynamic-flow-client-internal 5.29.0-experimental-3acf859 → 5.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/main.js CHANGED
@@ -146,7 +146,7 @@ var import_dynamic_flow_client4 = require("@wise/dynamic-flow-client");
146
146
  // src/dynamicFlow/telemetry/app-version.ts
147
147
  var appVersion = (
148
148
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
149
- typeof process !== "undefined" ? "5.28.4" : "0.0.0"
149
+ typeof process !== "undefined" ? "5.29.0" : "0.0.0"
150
150
  );
151
151
 
152
152
  // src/dynamicFlow/context-menu/useContextMenu.tsx
@@ -1808,6 +1808,10 @@ var isIOSWebKit = () => {
1808
1808
  const mtp = navigator.maxTouchPoints;
1809
1809
  return _isIOSResult = navigator.platform === "MacIntel" && mtp !== void 0 && mtp > 0;
1810
1810
  };
1811
+ var getRect = (element) => {
1812
+ const { offsetWidth, offsetHeight } = element;
1813
+ return { width: offsetWidth, height: offsetHeight };
1814
+ };
1811
1815
  var defaultKeyExtractor = (index) => index;
1812
1816
  var defaultRangeExtractor = (range) => {
1813
1817
  const start = Math.max(range.startIndex - range.overscan, 0);
@@ -1819,6 +1823,43 @@ var defaultRangeExtractor = (range) => {
1819
1823
  }
1820
1824
  return arr;
1821
1825
  };
1826
+ var observeElementRect = (instance, cb) => {
1827
+ const element = instance.scrollElement;
1828
+ if (!element) {
1829
+ return;
1830
+ }
1831
+ const targetWindow = instance.targetWindow;
1832
+ if (!targetWindow) {
1833
+ return;
1834
+ }
1835
+ const handler = (rect) => {
1836
+ const { width, height } = rect;
1837
+ cb({ width: Math.round(width), height: Math.round(height) });
1838
+ };
1839
+ handler(getRect(element));
1840
+ if (!targetWindow.ResizeObserver) {
1841
+ return () => {
1842
+ };
1843
+ }
1844
+ const observer = new targetWindow.ResizeObserver((entries) => {
1845
+ const run = () => {
1846
+ const entry = entries[0];
1847
+ if (entry == null ? void 0 : entry.borderBoxSize) {
1848
+ const box = entry.borderBoxSize[0];
1849
+ if (box) {
1850
+ handler({ width: box.inlineSize, height: box.blockSize });
1851
+ return;
1852
+ }
1853
+ }
1854
+ handler(getRect(element));
1855
+ };
1856
+ instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
1857
+ });
1858
+ observer.observe(element, { box: "border-box" });
1859
+ return () => {
1860
+ observer.unobserve(element);
1861
+ };
1862
+ };
1822
1863
  var addEventListenerOptions = {
1823
1864
  passive: true
1824
1865
  };
@@ -1872,6 +1913,10 @@ var observeOffset = (instance, cb, readOffset) => {
1872
1913
  fallback == null ? void 0 : fallback.cancel();
1873
1914
  };
1874
1915
  };
1916
+ var observeElementOffset = (instance, cb) => observeOffset(instance, cb, (el) => {
1917
+ const { horizontal, isRtl } = instance.options;
1918
+ return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
1919
+ });
1875
1920
  var observeWindowOffset = (instance, cb) => observeOffset(
1876
1921
  instance,
1877
1922
  cb,
@@ -1914,6 +1959,7 @@ var scrollWithAdjustments = (offset, {
1914
1959
  });
1915
1960
  };
1916
1961
  var windowScroll = scrollWithAdjustments;
1962
+ var elementScroll = scrollWithAdjustments;
1917
1963
  var Virtualizer = class {
1918
1964
  constructor(opts) {
1919
1965
  this.unsubs = [];
@@ -3156,6 +3202,13 @@ function useVirtualizerBase(_a) {
3156
3202
  });
3157
3203
  return instance;
3158
3204
  }
3205
+ function useVirtualizer(options) {
3206
+ return useVirtualizerBase(__spreadValues({
3207
+ observeElementRect,
3208
+ observeElementOffset,
3209
+ scrollToFn: elementScroll
3210
+ }, options));
3211
+ }
3159
3212
  function useWindowVirtualizer(options) {
3160
3213
  return useVirtualizerBase(__spreadValues({
3161
3214
  getScrollElement: () => typeof document !== "undefined" ? window : null,
@@ -3228,7 +3281,7 @@ var FooterWithScrollButton = ({ footer }) => {
3228
3281
  ] })
3229
3282
  ] });
3230
3283
  };
3231
- var useIsElementVisible = (elementRef) => {
3284
+ var useIsElementVisible = (elementRef, root = null) => {
3232
3285
  const [isVisible, setIsVisible] = (0, import_react8.useState)(false);
3233
3286
  (0, import_react8.useEffect)(() => {
3234
3287
  const element = elementRef.current;
@@ -3237,11 +3290,11 @@ var useIsElementVisible = (elementRef) => {
3237
3290
  ([entry]) => {
3238
3291
  setIsVisible(entry.isIntersecting);
3239
3292
  },
3240
- { rootMargin: "1px" }
3293
+ { root, rootMargin: "1px" }
3241
3294
  );
3242
3295
  observer.observe(element);
3243
3296
  return () => observer.disconnect();
3244
- }, [elementRef]);
3297
+ }, [elementRef, root]);
3245
3298
  return isVisible;
3246
3299
  };
3247
3300
 
@@ -3263,12 +3316,40 @@ var collection_messages_default = (0, import_react_intl8.defineMessages)({
3263
3316
  }
3264
3317
  });
3265
3318
 
3319
+ // ../renderers/src/CollectionRenderer/components/getScrollableAncestor.ts
3320
+ var SCROLLABLE_OVERFLOW_VALUES = /* @__PURE__ */ new Set(["auto", "overlay", "scroll"]);
3321
+ var getScrollableAncestor = (element) => {
3322
+ var _a;
3323
+ const view = element == null ? void 0 : element.ownerDocument.defaultView;
3324
+ let ancestor = (_a = element == null ? void 0 : element.parentElement) != null ? _a : null;
3325
+ if (!view) {
3326
+ return null;
3327
+ }
3328
+ while (ancestor) {
3329
+ const { overflowY } = view.getComputedStyle(ancestor);
3330
+ const hasScrollableOverflow = SCROLLABLE_OVERFLOW_VALUES.has(overflowY);
3331
+ if (hasScrollableOverflow && ancestor.scrollHeight > ancestor.clientHeight) {
3332
+ return ancestor;
3333
+ }
3334
+ ancestor = ancestor.parentElement;
3335
+ }
3336
+ return null;
3337
+ };
3338
+
3266
3339
  // ../renderers/src/CollectionRenderer/components/ContentComponent.tsx
3267
3340
  var import_jsx_runtime36 = require("react/jsx-runtime");
3268
3341
  var ContentComponent = (props) => {
3269
3342
  const { state, status, SectionHeader, Item } = props;
3343
+ const contentRef = (0, import_react9.useRef)(null);
3344
+ const [scrollElement, setScrollElement] = (0, import_react9.useState)(null);
3345
+ (0, import_react9.useLayoutEffect)(() => {
3346
+ const nextScrollElement = getScrollableAncestor(contentRef.current);
3347
+ setScrollElement(
3348
+ (currentScrollElement) => currentScrollElement === nextScrollElement ? currentScrollElement : nextScrollElement
3349
+ );
3350
+ }, []);
3270
3351
  const endOfContentRef = (0, import_react9.useRef)(null);
3271
- const isBottomVisible = useIsElementVisible(endOfContentRef);
3352
+ const isBottomVisible = useIsElementVisible(endOfContentRef, scrollElement);
3272
3353
  (0, import_react9.useEffect)(() => {
3273
3354
  const shouldAutoLoad = isBottomVisible && status.type === "idle" && state.afterSectionsProps.length === 0;
3274
3355
  if (shouldAutoLoad && status.loadMore) {
@@ -3300,51 +3381,90 @@ var ContentComponent = (props) => {
3300
3381
  var _a, _b;
3301
3382
  listOffsetRef.current = (_b = (_a = listRef.current) == null ? void 0 : _a.offsetTop) != null ? _b : 0;
3302
3383
  });
3303
- const virtualizer = useWindowVirtualizer({
3304
- count: stateCount,
3305
- estimateSize: () => 120,
3306
- overscan: 10,
3307
- // eslint-disable-next-line react-hooks/refs
3308
- scrollMargin: listOffsetRef.current
3309
- });
3310
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { ref: listRef, children: [
3384
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { ref: contentRef, children: [
3311
3385
  state.beforeSections,
3312
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3313
- "div",
3386
+ scrollElement ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3387
+ ElementVirtualizedItems,
3314
3388
  {
3315
- style: {
3316
- height: `${virtualizer.getTotalSize()}px`,
3317
- width: "100%",
3318
- position: "relative"
3319
- },
3320
- children: virtualizer.getVirtualItems().map((item) => {
3321
- const i = items[item.index];
3322
- if (!i) {
3323
- return null;
3324
- }
3325
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3326
- "div",
3327
- {
3328
- ref: virtualizer.measureElement,
3329
- "data-index": item.index,
3330
- style: {
3331
- position: "absolute",
3332
- top: 0,
3333
- left: 0,
3334
- width: "100%",
3335
- transform: `translateY(${item.start - virtualizer.options.scrollMargin}px)`
3336
- },
3337
- children: i.type === "header" ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(SectionHeader, __spreadValues({}, i)) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Item, __spreadValues({}, i.item))
3338
- },
3339
- item.key
3340
- );
3341
- })
3389
+ Item,
3390
+ SectionHeader,
3391
+ items,
3392
+ scrollElement,
3393
+ stateCount
3394
+ }
3395
+ ) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3396
+ WindowVirtualizedItems,
3397
+ {
3398
+ Item,
3399
+ SectionHeader,
3400
+ items,
3401
+ stateCount
3342
3402
  }
3343
3403
  ),
3344
3404
  /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { ref: endOfContentRef, className: "d-flex m-x-auto m-y-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(PaginationComponent, { status, state }) }),
3345
3405
  state.afterSections
3346
3406
  ] });
3347
3407
  };
3408
+ var WindowVirtualizedItems = (props) => {
3409
+ const { stateCount } = props;
3410
+ const virtualItemsRef = (0, import_react9.useRef)(null);
3411
+ const virtualizer = useWindowVirtualizer({
3412
+ count: stateCount,
3413
+ estimateSize: () => 120,
3414
+ overscan: 10
3415
+ });
3416
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(VirtualizedItems, __spreadProps(__spreadValues({}, props), { virtualItemsRef, virtualizer }));
3417
+ };
3418
+ var ElementVirtualizedItems = (props) => {
3419
+ const { scrollElement, stateCount } = props;
3420
+ const virtualItemsRef = (0, import_react9.useRef)(null);
3421
+ const virtualizer = useVirtualizer({
3422
+ count: stateCount,
3423
+ getScrollElement: () => scrollElement,
3424
+ estimateSize: () => 120,
3425
+ overscan: 10
3426
+ });
3427
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(VirtualizedItems, __spreadProps(__spreadValues({}, props), { virtualItemsRef, virtualizer }));
3428
+ };
3429
+ var VirtualizedItems = ({
3430
+ Item,
3431
+ SectionHeader,
3432
+ items,
3433
+ virtualItemsRef,
3434
+ virtualizer
3435
+ }) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3436
+ "div",
3437
+ {
3438
+ ref: virtualItemsRef,
3439
+ style: {
3440
+ height: `${virtualizer.getTotalSize()}px`,
3441
+ width: "100%",
3442
+ position: "relative"
3443
+ },
3444
+ children: virtualizer.getVirtualItems().map((item) => {
3445
+ const i = items[item.index];
3446
+ if (!i) {
3447
+ return null;
3448
+ }
3449
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3450
+ "div",
3451
+ {
3452
+ ref: virtualizer.measureElement,
3453
+ "data-index": item.index,
3454
+ style: {
3455
+ position: "absolute",
3456
+ top: 0,
3457
+ left: 0,
3458
+ width: "100%",
3459
+ transform: `translateY(${item.start - virtualizer.options.scrollMargin}px)`
3460
+ },
3461
+ children: i.type === "header" ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(SectionHeader, __spreadValues({}, i)) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Item, __spreadValues({}, i.item))
3462
+ },
3463
+ item.key
3464
+ );
3465
+ })
3466
+ }
3467
+ );
3348
3468
  var PaginationComponent = ({
3349
3469
  status,
3350
3470
  state
@@ -6642,27 +6762,19 @@ var commonKeys = [
6642
6762
  "disabled",
6643
6763
  "displayFormat",
6644
6764
  "id",
6645
- "maxLength",
6646
- "minLength",
6647
6765
  "onBlur",
6648
6766
  "onFocus",
6649
6767
  "placeholder",
6650
- "required",
6651
6768
  "value"
6652
6769
  ];
6653
6770
  function VariableTextInput(inputProps) {
6654
- const { id, value, control, displayFormat, onChange } = inputProps;
6771
+ const { id, value, control, onChange } = inputProps;
6655
6772
  const commonProps = __spreadProps(__spreadValues({}, pick(inputProps, ...commonKeys)), { name: id });
6656
- if (control === "ssn-input" || (displayFormat == null ? void 0 : displayFormat.includes("*"))) {
6657
- return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(SsnInput, __spreadProps(__spreadValues({}, commonProps), { onChange }));
6658
- }
6659
6773
  switch (control) {
6660
6774
  case "email":
6661
6775
  return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(TextInput, __spreadProps(__spreadValues({}, commonProps), { type: "email", onChange }));
6662
6776
  case "password":
6663
6777
  return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(TextInput, __spreadProps(__spreadValues({}, commonProps), { type: "password", onChange }));
6664
- case "ssn-input":
6665
- return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(SsnInput, __spreadProps(__spreadValues({}, commonProps), { onChange }));
6666
6778
  case "numeric": {
6667
6779
  const numericProps = __spreadProps(__spreadValues({}, commonProps), { type: "number", onWheel });
6668
6780
  return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
@@ -6683,65 +6795,10 @@ function VariableTextInput(inputProps) {
6683
6795
  }
6684
6796
  }
6685
6797
  function TextInput(props) {
6686
- const _a = props, { control, displayFormat, onChange, type } = _a, commonProps = __objRest(_a, ["control", "displayFormat", "onChange", "type"]);
6798
+ const _a = props, { control, displayFormat, onChange } = _a, commonProps = __objRest(_a, ["control", "displayFormat", "onChange"]);
6687
6799
  const InputWithPattern = control === "textarea" ? import_components68.TextareaWithDisplayFormat : import_components68.InputWithDisplayFormat;
6688
6800
  const InputWithoutPattern = control === "textarea" ? import_components68.TextArea : import_components68.Input;
6689
- return displayFormat ? /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(InputWithPattern, __spreadProps(__spreadValues({ displayPattern: displayFormat }, commonProps), { onChange })) : /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(InputWithoutPattern, __spreadProps(__spreadValues({}, commonProps), { type, onChange: (e) => onChange(e.target.value) }));
6690
- }
6691
- function SsnInput(props) {
6692
- const _a = props, {
6693
- displayFormat = "",
6694
- maxLength,
6695
- minLength: _minLength,
6696
- onChange,
6697
- type: _type,
6698
- value = ""
6699
- } = _a, commonProps = __objRest(_a, [
6700
- "displayFormat",
6701
- "maxLength",
6702
- "minLength",
6703
- "onChange",
6704
- "type",
6705
- "value"
6706
- ]);
6707
- const maxDigits = displayFormat.split("").filter((character) => character === "*").length || maxLength || Infinity;
6708
- const maskedValue = displayFormat ? displayFormat.split("").reduce(
6709
- ({ display, digitsUsed }, character) => {
6710
- if (character === "*") {
6711
- return digitsUsed < value.length ? { display: `${display}\u2022`, digitsUsed: digitsUsed + 1 } : { display, digitsUsed };
6712
- }
6713
- return digitsUsed > 0 && digitsUsed < value.length ? { display: `${display}${character}`, digitsUsed } : { display, digitsUsed };
6714
- },
6715
- { display: "", digitsUsed: 0 }
6716
- ).display : "\u2022".repeat(value.length);
6717
- return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
6718
- "input",
6719
- __spreadProps(__spreadValues({}, commonProps), {
6720
- className: "form-control np-form-control np-form-control--size-auto np-input np-input--shape-rectangle",
6721
- type: "text",
6722
- inputMode: "numeric",
6723
- maxLength: displayFormat.length || maxLength,
6724
- value: maskedValue,
6725
- onChange: () => void 0,
6726
- onKeyDown: (event) => {
6727
- const rawValue = value.replace(/[^0-9]/g, "");
6728
- if (/^[0-9]$/.test(event.key)) {
6729
- event.preventDefault();
6730
- if (rawValue.length < maxDigits) {
6731
- onChange(`${rawValue}${event.key}`);
6732
- }
6733
- } else if (event.key === "Backspace") {
6734
- event.preventDefault();
6735
- onChange(rawValue.slice(0, -1));
6736
- }
6737
- },
6738
- onPaste: (event) => {
6739
- event.preventDefault();
6740
- const pastedValue = event.clipboardData.getData("text").replace(/[^0-9]/g, "");
6741
- onChange(`${value}${pastedValue}`.replace(/[^0-9]/g, "").slice(0, maxDigits));
6742
- }
6743
- })
6744
- );
6801
+ return displayFormat ? /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(InputWithPattern, __spreadProps(__spreadValues({ displayPattern: displayFormat }, commonProps), { onChange })) : /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(InputWithoutPattern, __spreadProps(__spreadValues({}, commonProps), { onChange: (e) => onChange(e.target.value) }));
6745
6802
  }
6746
6803
 
6747
6804
  // ../renderers/src/TextInputRenderer.tsx