@uxf/core-react 13.0.3 → 14.1.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.
Files changed (61) hide show
  1. package/README.md +85 -56
  2. package/clickable/_use-simulated-button.js +9 -5
  3. package/clickable/use-button-props.js +108 -47
  4. package/global-context/index.test.js +23 -2
  5. package/hooks/use-body-scroll-lock.js +56 -27
  6. package/hooks/use-composed-refs.test.js +14 -2
  7. package/hooks/use-debounce.js +21 -6
  8. package/hooks/use-debounce.test.d.ts +1 -0
  9. package/hooks/use-debounce.test.js +75 -0
  10. package/hooks/use-focus-return.js +55 -23
  11. package/hooks/use-focus-trap.js +87 -53
  12. package/hooks/use-increment.js +47 -5
  13. package/hooks/use-input-focus.js +65 -19
  14. package/hooks/use-is-hydrated.d.ts +10 -0
  15. package/hooks/use-is-hydrated.js +24 -0
  16. package/hooks/use-is-hydrated.test.d.ts +1 -0
  17. package/hooks/use-is-hydrated.test.js +45 -0
  18. package/hooks/use-is-mounted.d.ts +5 -0
  19. package/hooks/use-is-mounted.js +20 -1
  20. package/hooks/use-isomorphic-layout-effect.d.ts +4 -0
  21. package/hooks/use-isomorphic-layout-effect.js +4 -0
  22. package/hooks/use-key.js +49 -18
  23. package/hooks/use-key.test.d.ts +1 -0
  24. package/hooks/use-key.test.js +145 -0
  25. package/hooks/use-latest.d.ts +5 -0
  26. package/hooks/use-latest.js +5 -0
  27. package/hooks/use-media-query.d.ts +10 -1
  28. package/hooks/use-media-query.js +77 -19
  29. package/hooks/use-media-query.test.d.ts +1 -0
  30. package/hooks/use-media-query.test.js +76 -0
  31. package/hooks/use-min-window-width.js +39 -18
  32. package/hooks/use-mouse-drag-to-scroll.js +116 -61
  33. package/hooks/use-mouse-drag-to-scroll.test.js +56 -10
  34. package/hooks/use-on-mount.js +20 -3
  35. package/hooks/use-on-unmount.d.ts +1 -0
  36. package/hooks/use-on-unmount.js +23 -7
  37. package/hooks/use-on-unmount.test.d.ts +1 -0
  38. package/hooks/use-on-unmount.test.js +16 -0
  39. package/hooks/use-on-update.d.ts +8 -0
  40. package/hooks/use-on-update.js +32 -8
  41. package/hooks/use-on-update.test.d.ts +1 -0
  42. package/hooks/use-on-update.test.js +90 -0
  43. package/hooks/use-pagination.js +30 -14
  44. package/hooks/use-previous.d.ts +5 -0
  45. package/hooks/use-previous.js +19 -3
  46. package/hooks/use-raf-state.js +35 -8
  47. package/hooks/use-toggle.js +42 -4
  48. package/hooks/use-window-scroll.d.ts +7 -2
  49. package/hooks/use-window-scroll.js +36 -15
  50. package/hooks/use-window-scroll.test.js +141 -39
  51. package/hooks/use-window-size.d.ts +7 -2
  52. package/hooks/use-window-size.js +34 -12
  53. package/hooks/use-window-size.test.js +147 -29
  54. package/package.json +10 -4
  55. package/swipeable/use-swipeable.test.js +31 -5
  56. package/translations/index.js +1 -1
  57. package/translations/replace-variables.js +4 -1
  58. package/translations/replace-variables.test.d.ts +1 -0
  59. package/translations/replace-variables.test.js +13 -0
  60. package/components/viewport-height-polyfill.d.ts +0 -2
  61. package/components/viewport-height-polyfill.js +0 -58
package/README.md CHANGED
@@ -24,30 +24,6 @@ import { Show } from "@uxf/core-react/components/show";
24
24
  <Show when={SOME_CONDITION}>...some content</Show>;
25
25
  ```
26
26
 
27
- ### ViewportHeightPolyfill
28
-
29
- Polyfill for custom css variable `--viewport-height` to mimic functionality of browser's [dynamic viewport height](https://web.dev/blog/viewport-units).
30
-
31
- Add component to react app root (eg. `_app.tsx`).
32
-
33
- ```tsx
34
- import { ViewportHeightPolyfill } from "@uxf/core-react/components/viewport-height-polyfill";
35
-
36
- <ViewportHeightPolyfill />;
37
- ```
38
-
39
- Add css variable declaration with fallback to app global styles (eg. `base.css`) if already not there.
40
-
41
- ```css
42
- :root {
43
- --viewport-height: 100vh;
44
-
45
- @supports (height: 100dvh) {
46
- --viewport-height: 100dvh;
47
- }
48
- }
49
- ```
50
-
51
27
  ## Hooks
52
28
 
53
29
  ---
@@ -76,7 +52,7 @@ useBodyScrollLock<HTMLDivElement>(innerRef, isOpen, {
76
52
 
77
53
  ---
78
54
 
79
- ### isMounted
55
+ ### useIsMounted
80
56
 
81
57
  Check if component is mounted.
82
58
 
@@ -86,11 +62,34 @@ import { useIsMounted } from "@uxf/core-react/hooks/use-is-mounted";
86
62
  const isMounted = useIsMounted();
87
63
  ```
88
64
 
65
+ Deprecated in favour of `useIsHydrated` for rendering something only in the browser. Keep it only where the code
66
+ needs effects to have run (refs attached).
67
+
68
+ ---
69
+
70
+ ### useIsHydrated
71
+
72
+ False on the server and during hydration, true in every other render, including the first render of a component
73
+ that mounts later on the client. Use it to render something only in the browser (`window`, a portal into
74
+ `document.body`, an editor) without the extra commit and the flash of fallback that `useIsMounted` costs on every
75
+ client-side mount. It does not mean effects have run: refs are not attached yet in the render where it turns true.
76
+
77
+ ```tsx
78
+ import { useIsHydrated } from "@uxf/core-react/hooks/use-is-hydrated";
79
+
80
+ const isHydrated = useIsHydrated();
81
+
82
+ return isHydrated ? <Editor /> : <Loader />;
83
+ ```
84
+
89
85
  ---
90
86
 
91
87
  ### useIsomorphicLayoutEffect
92
88
 
93
- Returns `useEffect` on client and `useLayoutEffect` on server.
89
+ **Deprecated – use `useLayoutEffect`.** It only silenced React's server warning about `useLayoutEffect`, which
90
+ React 19 removed; on the server `useLayoutEffect` simply does not run.
91
+
92
+ Returns `useLayoutEffect` in the browser and `useEffect` on the server.
94
93
 
95
94
  ```tsx
96
95
  import { useIsomorphicLayoutEffect } from "@uxf/core-react/hooks/use-isomorphic-layout-effect";
@@ -107,7 +106,8 @@ useIsomorphicLayoutEffect(
107
106
 
108
107
  ### useKey
109
108
 
110
- Trigger callback on given key.
109
+ Trigger callback on given key. The callback and the key filter are always the latest ones, also when passed inline.
110
+ The listener follows `targetRef`: a target that mounts later or is replaced gets it after the next commit.
111
111
 
112
112
  ```tsx
113
113
  import { useKey } from "@uxf/core-react/hooks/use-key";
@@ -173,21 +173,34 @@ const [state, setState] = useRafState<boolean>(false);
173
173
 
174
174
  ### useOnMount
175
175
 
176
- Calls the callback on component mount.
176
+ Calls the callback on component mount; a returned function runs on unmount.
177
177
 
178
178
  ```tsx
179
- import { useOnUnmount } from "@uxf/core-react/hooks/use-on-unmount";
179
+ import { useOnMount } from "@uxf/core-react/hooks/use-on-mount";
180
+
181
+ useOnMount(() => console.log("mounted"));
182
+ ```
183
+
184
+ ---
185
+
186
+ ### useOnUnmount
180
187
 
181
- const exampleCallback = () => {};
188
+ Calls the callback on component unmount, in its version from the latest render.
182
189
 
183
- useOnUnmount(exampleCallback());
190
+ ```tsx
191
+ import { useOnUnmount } from "@uxf/core-react/hooks/use-on-unmount";
192
+
193
+ useOnUnmount(() => clearTimeout(timer.current));
184
194
  ```
185
195
 
186
196
  ---
187
197
 
188
198
  ### useOnUpdate
189
199
 
190
- Calls the callback only on component update, except initial mount.
200
+ Calls the callback when the deps change, not on mount. It compares the deps with those of its previous run, so
201
+ StrictMode's second mount run is skipped too, and so is a reconnect with the same deps (an `<Activity>` shown again),
202
+ whose cleanup has already run. Work that has to survive a reconnect, like a pending timer, belongs in a plain
203
+ `useEffect`.
191
204
 
192
205
  ```tsx
193
206
  import { useOnUpdate } from "@uxf/core-react/hooks/use-on-update";
@@ -204,21 +217,23 @@ useOnUpdate(
204
217
 
205
218
  ### useWindowScroll
206
219
 
207
- Returns x and y scroll coordinates of window on scroll.
220
+ Returns the window's scroll position (`x`, `y`), updated at most once per animation frame. `undefined` on the
221
+ server and during hydration, the current position from the first render of a component mounted later.
208
222
 
209
223
  ```tsx
210
224
  import { useWindowScroll } from "@uxf/core-react/hooks/use-window-scroll";
211
225
 
212
226
  const windowScroll = useWindowScroll();
213
227
 
214
- const example = windowScroll && windowScroll.y > 100 ? "scroled" : "on top";
228
+ const example = windowScroll && windowScroll.y > 100 ? "scrolled" : "on top";
215
229
  ```
216
230
 
217
231
  ---
218
232
 
219
233
  ### useWindowSize
220
234
 
221
- Returns window width and height.
235
+ Returns the window's inner `width` and `height`, updated at most once per animation frame. `undefined` on the
236
+ server and during hydration, the current size from the first render of a component mounted later.
222
237
 
223
238
  ```tsx
224
239
  import { useWindowSize } from "@uxf/core-react/hooks/use-window-size";
@@ -267,6 +282,12 @@ useFocusReturn(active);
267
282
 
268
283
  Returns props for anchor element.
269
284
 
285
+ `type: "submit"` works like a native submit button, through `form.requestSubmit()` on the form the element sits in
286
+ (or, outside any form, the form that has focus). The browser validates first (`required`, `type="email"`, …) unless
287
+ the form has `noValidate`, which `@uxf/form`'s `Form` sets. A form whose `submit` handler does not call
288
+ `preventDefault()` is then submitted natively, so the page navigates. Earlier versions dispatched a bare `submit`
289
+ event instead: no validation and no native submission.
290
+
270
291
  ```tsx
271
292
  import { useAnchorProps } from "@uxf/core-react/clickable/use-anchor-props";
272
293
  import { AnchorHTMLAttributes } from "react";
@@ -342,7 +363,8 @@ const buttonProps = useButtonProps<Props>({
342
363
 
343
364
  ### useClickableProps
344
365
 
345
- Returns props for clickable element.
366
+ Returns props for clickable element. `type: "submit"` submits the element's form through `requestSubmit()`, as
367
+ described under `useAnchorProps`.
346
368
 
347
369
  ```tsx
348
370
  import { useClickableProps } from "@uxf/core-react/clickable/use-clickable-props";
@@ -418,7 +440,11 @@ const input = useInputFocus(focusRef, onBlur, onFocus);
418
440
 
419
441
  ### useLatest
420
442
 
421
- Allways returns latest value of given variable.
443
+ **Deprecated.** It writes `ref.current` during render, which React 19 asks not to do. To read the latest props or
444
+ state from an effect or a listener it registers, use `useEffectEvent`; for a value read during render, use the value
445
+ itself.
446
+
447
+ Always returns the latest value of the given variable.
422
448
 
423
449
  ```tsx
424
450
  import { useLatest } from "@uxf/core-react/hooks/use-latest";
@@ -455,7 +481,11 @@ callback on every call, so use it only outside a component.
455
481
 
456
482
  ### usePrevious
457
483
 
458
- Returns previous value of given variable.
484
+ **Deprecated.** Its ref is only useful when read during render, which React 19 asks not to do. To react to a change,
485
+ keep the previous value in state and compare during render
486
+ ([React docs](https://react.dev/reference/react/useState#storing-information-from-previous-renders)).
487
+
488
+ Returns the previous value of the given variable.
459
489
 
460
490
  ```tsx
461
491
  import { usePrevious } from "@uxf/core-react/hooks/use-previous";
@@ -507,28 +537,19 @@ import { useDebounce } from "@uxf/core-react/hooks/use-debounce";
507
537
  const debouncedValue = useDebounce<string>("some value", 300);
508
538
  ```
509
539
 
510
- ## String helpers
511
-
512
- ```tsx
513
- import { nl2br } from "@uxf/core-react/string/nl2br";
514
-
515
- <div>{nl2br("Hello\nWorld")}</div>;
516
- ```
517
-
518
- ---
519
-
520
540
  ### useMediaQuery
521
541
 
522
542
  Returns whether the given media query is currently matched. Optionally accepts a callback that is called on every change.
523
543
 
524
- Uses `window.matchMedia` with a `change` event listener (via `AbortController`) for efficient updates.
544
+ Reads `window.matchMedia` through `useSyncExternalStore`: `false` on the server and during hydration (no mismatch),
545
+ the real value from the first render of a component mounted on the client, and updated on every `change`.
525
546
 
526
547
  ```tsx
527
548
  import { useMediaQuery } from "@uxf/core-react/hooks/use-media-query";
528
549
  import type { UseMediaQueryCallback } from "@uxf/core-react/hooks/use-media-query";
529
550
  import { twScreens } from "@generated/tw-tokens/tw-screens";
530
551
 
531
- // Basic usage – reactive boolean (SSR-safe, initializes as false)
552
+ // Basic usage – reactive boolean, SSR-safe
532
553
  const isDesktop = useMediaQuery(`(min-width: ${twScreens.sm})`);
533
554
 
534
555
  // With optional callback – fired on every match change
@@ -537,17 +558,25 @@ const callback: UseMediaQueryCallback = (isMatching, mediaQueryString) => {
537
558
  };
538
559
 
539
560
  const isDesktopWithCallback = useMediaQuery(`(min-width: ${twScreens.sm})`, callback);
540
-
541
- // Client-only usage – initializes immediately from window.matchMedia (no SSR hydration)
542
- // Pass isSSR=false only when the component is guaranteed to render client-side only
543
- const isDesktopClientOnly = useMediaQuery(`(min-width: ${twScreens.sm})`, undefined, false);
544
561
  ```
545
562
 
546
563
  **Parameters:**
547
564
 
548
565
  - `mediaQueryString` – CSS media query string
549
- - `callback` _(optional)_ – called with `(isMatching, mediaQueryString)` on every match change
550
- - `isSSR` _(optional, default: `true`)_ – when `true`, initial state is `false` to avoid SSR/hydration mismatch; when `false`, initial state is read directly from `window.matchMedia` (use only in client-only components)
566
+ - `callback` _(optional)_ – called with `(isMatching, mediaQueryString)` once after mount and on every match change; always the latest callback, without resubscribing
567
+ - `isSSR` – deprecated and ignored; a client-only component gets the real value in its first render anyway
568
+
569
+ ---
570
+
571
+ ## String helpers
572
+
573
+ ```tsx
574
+ import { nl2br } from "@uxf/core-react/string/nl2br";
575
+
576
+ <div>{nl2br("Hello\nWorld")}</div>;
577
+ ```
578
+
579
+ ---
551
580
 
552
581
  ## Drag and Drop
553
582
 
@@ -7,16 +7,20 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
7
7
  const [isBusy, setIsBusy] = (0, react_1.useState)(false);
8
8
  // eslint-disable-next-line react-hooks/rules-of-hooks
9
9
  const _onClick = (0, react_1.useCallback)((e) => {
10
- var _a;
10
+ var _a, _b;
11
11
  if ((isClickable || isHyperlink) && analyticsCallback) {
12
12
  analyticsCallback();
13
13
  }
14
14
  if (isClickable) {
15
15
  if (isSubmitType) {
16
- const closestForm = (_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.closest("form");
17
- if (closestForm) {
18
- closestForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
19
- }
16
+ // The element's own form first: a mouse click in Safari does not focus it, so focus can be on
17
+ // <body> or in another form. The focused element's form is the fallback for a button rendered
18
+ // outside any form, e.g. clicked programmatically from a field's Enter handler.
19
+ const form = (_a = e.currentTarget.closest("form")) !== null && _a !== void 0 ? _a : (_b = document.activeElement) === null || _b === void 0 ? void 0 : _b.closest("form");
20
+ // `requestSubmit`, not a dispatched `Event("submit")`: it validates, fires a real `SubmitEvent`
21
+ // and submits natively unless a handler prevents it. This element is no submit button, so it
22
+ // cannot be passed as the submitter.
23
+ form === null || form === void 0 ? void 0 : form.requestSubmit();
20
24
  }
21
25
  // TODO @vejvis - jaktože tady je onclick který vrací void a ne Promise<void> ?
22
26
  const clickResult = onClick === null || onClick === void 0 ? void 0 : onClick(e);
@@ -1,60 +1,121 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useButtonProps = useButtonProps;
4
+ const compiler_runtime_1 = require("react/compiler-runtime");
4
5
  const cx_1 = require("@uxf/core/utils/cx");
5
- const react_1 = require("react");
6
6
  const add_busy_and_disabled_classnames_1 = require("./add-busy-and-disabled-classnames");
7
7
  const add_is_hoverable_classname_1 = require("./add-is-hoverable-classname");
8
- function useButtonProps(props, options = {}) {
9
- const { ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps } = props;
10
- const isBusy = loading ? loading : Boolean(ariaBusy);
11
- const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
12
- const isBusyOrDisabled = isBusy || isDisabled;
13
- const _className = (0, add_busy_and_disabled_classnames_1.addBusyAndDisabledClassnames)(className, { isBusy, isDisabled }, options);
14
- const _onClick = (0, react_1.useCallback)((e) => {
15
- if (isBusyOrDisabled) {
16
- e.preventDefault();
17
- }
18
- else {
19
- if (analyticsCallback) {
20
- analyticsCallback();
8
+ function useButtonProps(props, t0) {
9
+ const $ = (0, compiler_runtime_1.c)(16);
10
+ let restProps;
11
+ let role;
12
+ let t1;
13
+ let t2;
14
+ let tabIndex;
15
+ if ($[0] !== props || $[1] !== t0) {
16
+ t2 = Symbol.for("react.early_return_sentinel");
17
+ bb0: {
18
+ const options = t0 === undefined ? {} : t0;
19
+ const { "aria-busy": ariaBusy, "aria-disabled": ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role: t3, tabIndex: t4, type, value, ...t5 } = props;
20
+ role = t3;
21
+ tabIndex = t4;
22
+ restProps = t5;
23
+ const isBusy = loading ? loading : Boolean(ariaBusy);
24
+ const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
25
+ const isBusyOrDisabled = isBusy || isDisabled;
26
+ const _className = (0, add_busy_and_disabled_classnames_1.addBusyAndDisabledClassnames)(className, {
27
+ isBusy,
28
+ isDisabled
29
+ }, options);
30
+ let t6;
31
+ if ($[7] !== analyticsCallback || $[8] !== isBusyOrDisabled || $[9] !== onClick) {
32
+ t6 = e => {
33
+ if (isBusyOrDisabled) {
34
+ e.preventDefault();
35
+ }
36
+ else {
37
+ if (analyticsCallback) {
38
+ analyticsCallback();
39
+ }
40
+ if (onClick) {
41
+ onClick(e);
42
+ }
43
+ }
44
+ };
45
+ $[7] = analyticsCallback;
46
+ $[8] = isBusyOrDisabled;
47
+ $[9] = onClick;
48
+ $[10] = t6;
21
49
  }
22
- if (onClick) {
23
- onClick(e);
50
+ else {
51
+ t6 = $[10];
24
52
  }
53
+ const _onClick = t6;
54
+ if (onClick || type === "reset" || type === "submit") {
55
+ let submitProps = {};
56
+ if (type === "submit") {
57
+ submitProps = {
58
+ formAction,
59
+ formEncType,
60
+ formMethod,
61
+ formNoValidate,
62
+ formTarget,
63
+ name,
64
+ value
65
+ };
66
+ }
67
+ t2 = {
68
+ "aria-busy": isBusy,
69
+ "aria-disabled": ariaDisabled,
70
+ autoFocus,
71
+ className: (0, cx_1.cx)((0, add_is_hoverable_classname_1.addIsHoverableClassname)(options), ..._className),
72
+ disabled,
73
+ onClick: _onClick,
74
+ role,
75
+ tabIndex: isBusyOrDisabled ? -1 : tabIndex,
76
+ type,
77
+ ...submitProps,
78
+ ...restProps
79
+ };
80
+ break bb0;
81
+ }
82
+ t1 = (0, cx_1.cx)(..._className);
25
83
  }
26
- }, [analyticsCallback, isBusyOrDisabled, onClick]);
27
- if (onClick || type === "reset" || type === "submit") {
28
- let submitProps = {};
29
- if (type === "submit") {
30
- submitProps = {
31
- formAction,
32
- formEncType,
33
- formMethod,
34
- formNoValidate,
35
- formTarget,
36
- name,
37
- value,
38
- };
39
- }
40
- return {
41
- "aria-busy": isBusy,
42
- "aria-disabled": ariaDisabled,
43
- autoFocus,
44
- className: (0, cx_1.cx)((0, add_is_hoverable_classname_1.addIsHoverableClassname)(options), ..._className),
45
- disabled,
46
- onClick: _onClick,
84
+ $[0] = props;
85
+ $[1] = t0;
86
+ $[2] = restProps;
87
+ $[3] = role;
88
+ $[4] = t1;
89
+ $[5] = t2;
90
+ $[6] = tabIndex;
91
+ }
92
+ else {
93
+ restProps = $[2];
94
+ role = $[3];
95
+ t1 = $[4];
96
+ t2 = $[5];
97
+ tabIndex = $[6];
98
+ }
99
+ if (t2 !== Symbol.for("react.early_return_sentinel")) {
100
+ return t2;
101
+ }
102
+ const t3 = tabIndex !== null && tabIndex !== void 0 ? tabIndex : -1;
103
+ let t4;
104
+ if ($[11] !== restProps || $[12] !== role || $[13] !== t1 || $[14] !== t3) {
105
+ t4 = {
106
+ className: t1,
47
107
  role,
48
- tabIndex: isBusyOrDisabled ? -1 : tabIndex,
49
- type,
50
- ...submitProps,
51
- ...restProps,
108
+ tabIndex: t3,
109
+ ...restProps
52
110
  };
111
+ $[11] = restProps;
112
+ $[12] = role;
113
+ $[13] = t1;
114
+ $[14] = t3;
115
+ $[15] = t4;
116
+ }
117
+ else {
118
+ t4 = $[15];
53
119
  }
54
- return {
55
- className: (0, cx_1.cx)(..._className),
56
- role,
57
- tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : -1,
58
- ...restProps,
59
- };
120
+ return t4;
60
121
  }
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const compiler_runtime_1 = require("react/compiler-runtime");
36
37
  const react_1 = require("@testing-library/react");
37
38
  const react_2 = __importStar(require("react"));
38
39
  const index_1 = require("./index");
@@ -74,11 +75,31 @@ describe("createGlobalContext", () => {
74
75
  it("returns the provided value through Provider/useContext", () => {
75
76
  const ctx = (0, index_1.createGlobalContext)("test/provider-consumer", "default");
76
77
  function Consumer() {
78
+ const $ = (0, compiler_runtime_1.c)(2);
77
79
  const value = (0, react_2.useContext)(ctx);
78
- return react_2.default.createElement("span", null, value);
80
+ let t0;
81
+ if ($[0] !== value) {
82
+ t0 = react_2.default.createElement("span", null, value);
83
+ $[0] = value;
84
+ $[1] = t0;
85
+ }
86
+ else {
87
+ t0 = $[1];
88
+ }
89
+ return t0;
79
90
  }
80
91
  function Wrapper(props) {
81
- return react_2.default.createElement(ctx.Provider, { value: "provided" }, props.children);
92
+ const $ = (0, compiler_runtime_1.c)(2);
93
+ let t0;
94
+ if ($[0] !== props.children) {
95
+ t0 = react_2.default.createElement(ctx.Provider, { value: "provided" }, props.children);
96
+ $[0] = props.children;
97
+ $[1] = t0;
98
+ }
99
+ else {
100
+ t0 = $[1];
101
+ }
102
+ return t0;
82
103
  }
83
104
  (0, react_1.render)(react_2.default.createElement(Wrapper, null,
84
105
  react_2.default.createElement(Consumer, null)));
@@ -1,36 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBodyScrollLock = useBodyScrollLock;
4
+ const compiler_runtime_1 = require("react/compiler-runtime");
4
5
  const body_scroll_lock_1 = require("@uxf/core/utils/body-scroll-lock");
5
6
  const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
6
7
  const react_1 = require("react");
7
- function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, willClearAllOnClose, willReserveScrollBarGap } = {}) {
8
- (0, react_1.useEffect)(() => {
9
- const node = containerRef.current;
10
- if (isOpen && node) {
11
- (0, body_scroll_lock_1.disableBodyScroll)(node, {
12
- allowTouchMove: allowTouchMove ||
13
- ((element) => {
14
- while (element !== document.body) {
15
- if (element.getAttribute("data-body-scroll-lock-ignore") !== null) {
16
- return true;
17
- }
18
- if ((0, is_not_nil_1.isNotNil)(element.parentElement)) {
19
- element = element.parentElement;
20
- }
21
- }
22
- return false;
23
- }),
24
- willReserveScrollBarGap,
25
- });
26
- }
27
- return () => {
28
- if (node) {
29
- (0, body_scroll_lock_1.enableBodyScroll)(node);
30
- }
31
- if (willClearAllOnClose) {
32
- (0, body_scroll_lock_1.clearAllBodyScrollLocks)();
8
+ function useBodyScrollLock(containerRef, isOpen, t0) {
9
+ const $ = (0, compiler_runtime_1.c)(9);
10
+ let t1;
11
+ if ($[0] !== t0) {
12
+ t1 = t0 === undefined ? {} : t0;
13
+ $[0] = t0;
14
+ $[1] = t1;
15
+ }
16
+ else {
17
+ t1 = $[1];
18
+ }
19
+ const { allowTouchMove, willClearAllOnClose, willReserveScrollBarGap } = t1;
20
+ let t2;
21
+ let t3;
22
+ if ($[2] !== allowTouchMove || $[3] !== containerRef || $[4] !== isOpen || $[5] !== willClearAllOnClose || $[6] !== willReserveScrollBarGap) {
23
+ t2 = () => {
24
+ const node = containerRef.current;
25
+ if (isOpen && node) {
26
+ (0, body_scroll_lock_1.disableBodyScroll)(node, {
27
+ allowTouchMove: allowTouchMove || _temp,
28
+ willReserveScrollBarGap
29
+ });
33
30
  }
31
+ return () => {
32
+ if (node) {
33
+ (0, body_scroll_lock_1.enableBodyScroll)(node);
34
+ }
35
+ if (willClearAllOnClose) {
36
+ (0, body_scroll_lock_1.clearAllBodyScrollLocks)();
37
+ }
38
+ };
34
39
  };
35
- }, [allowTouchMove, willClearAllOnClose, containerRef, isOpen, willReserveScrollBarGap]);
40
+ t3 = [allowTouchMove, willClearAllOnClose, containerRef, isOpen, willReserveScrollBarGap];
41
+ $[2] = allowTouchMove;
42
+ $[3] = containerRef;
43
+ $[4] = isOpen;
44
+ $[5] = willClearAllOnClose;
45
+ $[6] = willReserveScrollBarGap;
46
+ $[7] = t2;
47
+ $[8] = t3;
48
+ }
49
+ else {
50
+ t2 = $[7];
51
+ t3 = $[8];
52
+ }
53
+ (0, react_1.useEffect)(t2, t3);
54
+ }
55
+ function _temp(element) {
56
+ while (element !== document.body) {
57
+ if (element.getAttribute("data-body-scroll-lock-ignore") !== null) {
58
+ return true;
59
+ }
60
+ if ((0, is_not_nil_1.isNotNil)(element.parentElement)) {
61
+ element = element.parentElement;
62
+ }
63
+ }
64
+ return false;
36
65
  }
@@ -33,17 +33,29 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const compiler_runtime_1 = require("react/compiler-runtime");
36
37
  const react_1 = require("@testing-library/react");
37
38
  const react_2 = __importStar(require("react"));
38
39
  const use_composed_refs_1 = require("./use-composed-refs");
39
40
  function Probe(props) {
41
+ const $ = (0, compiler_runtime_1.c)(3);
40
42
  const ref = (0, use_composed_refs_1.useComposedRefs)(props.outerRef, props.innerRef);
41
- return react_2.default.createElement("span", { ref: ref }, props.label);
43
+ let t0;
44
+ if ($[0] !== props.label || $[1] !== ref) {
45
+ t0 = react_2.default.createElement("span", { ref: ref }, props.label);
46
+ $[0] = props.label;
47
+ $[1] = ref;
48
+ $[2] = t0;
49
+ }
50
+ else {
51
+ t0 = $[2];
52
+ }
53
+ return t0;
42
54
  }
43
55
  test("keeps the same composed ref across re-renders, so a cleanup ref attaches once", () => {
44
56
  var _a;
45
57
  const calls = [];
46
- const cleanupRef = (node) => {
58
+ const cleanupRef = node => {
47
59
  calls.push(node ? "attach" : "null");
48
60
  return () => {
49
61
  calls.push("cleanup");
@@ -1,15 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDebounce = useDebounce;
4
+ const compiler_runtime_1 = require("react/compiler-runtime");
4
5
  const react_1 = require("react");
5
- const use_on_update_1 = require("./use-on-update");
6
6
  function useDebounce(value, delay) {
7
+ const $ = (0, compiler_runtime_1.c)(4);
7
8
  const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
8
- (0, use_on_update_1.useOnUpdate)(() => {
9
- const timer = setTimeout(() => setDebouncedValue(value), delay !== null && delay !== void 0 ? delay : 500);
10
- return () => {
11
- clearTimeout(timer);
9
+ let t0;
10
+ let t1;
11
+ if ($[0] !== delay || $[1] !== value) {
12
+ t0 = () => {
13
+ const timer = setTimeout(() => setDebouncedValue(value), delay !== null && delay !== void 0 ? delay : 500);
14
+ return () => {
15
+ clearTimeout(timer);
16
+ };
12
17
  };
13
- }, [value, delay]);
18
+ t1 = [value, delay];
19
+ $[0] = delay;
20
+ $[1] = value;
21
+ $[2] = t0;
22
+ $[3] = t1;
23
+ }
24
+ else {
25
+ t0 = $[2];
26
+ t1 = $[3];
27
+ }
28
+ (0, react_1.useEffect)(t0, t1);
14
29
  return debouncedValue;
15
30
  }
@@ -0,0 +1 @@
1
+ export {};