@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
@@ -3,19 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const compiler_runtime_1 = require("react/compiler-runtime");
6
7
  const react_1 = require("@testing-library/react");
7
8
  const react_2 = __importDefault(require("react"));
8
9
  const use_swipeable_1 = require("./use-swipeable");
9
10
  function Swipeable(props) {
11
+ const $ = (0, compiler_runtime_1.c)(3);
10
12
  const handlers = (0, use_swipeable_1.useSwipeable)(props);
11
- return props.isShown === false ? null : react_2.default.createElement("div", { ...handlers }, "swipe");
13
+ let t0;
14
+ if ($[0] !== handlers || $[1] !== props.isShown) {
15
+ t0 = props.isShown === false ? null : react_2.default.createElement("div", { ...handlers }, "swipe");
16
+ $[0] = handlers;
17
+ $[1] = props.isShown;
18
+ $[2] = t0;
19
+ }
20
+ else {
21
+ t0 = $[2];
22
+ }
23
+ return t0;
12
24
  }
13
25
  function swipeLeft(element) {
14
- const touch = (clientX) => ({ touches: [{ clientX, clientY: 0 }], timeStamp: 1 });
26
+ const touch = clientX => ({
27
+ touches: [{
28
+ clientX,
29
+ clientY: 0
30
+ }],
31
+ timeStamp: 1
32
+ });
15
33
  react_1.fireEvent.touchStart(element, touch(200));
16
34
  react_1.fireEvent.touchMove(element, touch(100));
17
35
  react_1.fireEvent.touchMove(element, touch(0));
18
- react_1.fireEvent.touchEnd(element, { touches: [] });
36
+ react_1.fireEvent.touchEnd(element, {
37
+ touches: []
38
+ });
19
39
  }
20
40
  test("a swipe reaches the latest callback", () => {
21
41
  const first = jest.fn();
@@ -29,9 +49,15 @@ test("a swipe reaches the latest callback", () => {
29
49
  test("unmounting in the middle of a mouse drag stops tracking the mouse on the document", () => {
30
50
  const onSwiping = jest.fn();
31
51
  const { getByText, unmount } = (0, react_1.render)(react_2.default.createElement(Swipeable, { onSwiping: onSwiping, trackMouse: true }));
32
- react_1.fireEvent.mouseDown(getByText("swipe"), { clientX: 0, clientY: 0 });
52
+ react_1.fireEvent.mouseDown(getByText("swipe"), {
53
+ clientX: 0,
54
+ clientY: 0
55
+ });
33
56
  unmount();
34
- react_1.fireEvent.mouseMove(document, { clientX: 100, clientY: 0 });
57
+ react_1.fireEvent.mouseMove(document, {
58
+ clientX: 100,
59
+ clientY: 0
60
+ });
35
61
  expect(onSwiping).not.toHaveBeenCalled();
36
62
  });
37
63
  test("after unmounting, touches on the element no longer count", () => {
@@ -7,7 +7,7 @@ const react_1 = require("react");
7
7
  const global_context_1 = require("../global-context");
8
8
  /* intellisense and linting is broken with any other more specific type */
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- const translationsContext = (0, global_context_1.createGlobalContext)("core-react/translations", (key) => key);
10
+ const translationsContext = (0, global_context_1.createGlobalContext)("core-react/translations", key => key);
11
11
  exports.TranslationsProvider = translationsContext.Provider;
12
12
  function useUxfTranslation() {
13
13
  return (0, react_1.useContext)(translationsContext);
@@ -2,5 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceVariables = replaceVariables;
4
4
  function replaceVariables(translation, options) {
5
- return Object.keys(options).reduce((result, variable) => result.replace(new RegExp(`{{${variable}}}`, "g"), options[variable]), translation);
5
+ return Object.keys(options).reduce(
6
+ // A literal search instead of a RegExp built from the name, and a replacer function instead of a string, so
7
+ // that neither the name nor the value is interpreted (`.` in a name, `$&` or `$$` in a value).
8
+ (result, variable) => result.replaceAll(`{{${variable}}}`, () => String(options[variable])), translation);
6
9
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const replace_variables_1 = require("./replace-variables");
4
+ test("replaces every occurrence of a variable", () => {
5
+ expect((0, replace_variables_1.replaceVariables)("{{name}} and {{name}}", { name: "Eva" })).toBe("Eva and Eva");
6
+ });
7
+ test('puts "$" in a value literally', () => {
8
+ expect((0, replace_variables_1.replaceVariables)("Price: {{price}}", { price: "$$5" })).toBe("Price: $$5");
9
+ expect((0, replace_variables_1.replaceVariables)("Hi {{name}}", { name: "a$&b" })).toBe("Hi a$&b");
10
+ });
11
+ test("treats a variable name as text, not as a regular expression", () => {
12
+ expect((0, replace_variables_1.replaceVariables)("{{a.b}} {{axb}}", { "a.b": "1" })).toBe("1 {{axb}}");
13
+ });
@@ -1,2 +0,0 @@
1
- import { ReactNode } from "react";
2
- export declare function ViewportHeightPolyfill(): ReactNode;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ViewportHeightPolyfill = ViewportHeightPolyfill;
38
- const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
39
- const react_1 = __importStar(require("react"));
40
- const use_is_mounted_1 = require("@uxf/core-react/hooks/use-is-mounted");
41
- const use_on_mount_1 = require("@uxf/core-react/hooks/use-on-mount");
42
- function ViewportHeightPolyfill() {
43
- const isMounted = (0, use_is_mounted_1.useIsMounted)();
44
- const [viewportHeight, setViewportHeight] = (0, react_1.useState)();
45
- (0, use_on_mount_1.useOnMount)(() => {
46
- if (!CSS.supports("height: 100dvh")) {
47
- return;
48
- }
49
- const updateViewportHeight = () => setViewportHeight(window.innerHeight);
50
- updateViewportHeight();
51
- window.addEventListener("resize", updateViewportHeight);
52
- return () => window.removeEventListener("resize", updateViewportHeight);
53
- });
54
- if (isMounted && (0, is_not_nil_1.isNotNil)(viewportHeight)) {
55
- return react_1.default.createElement("style", null, `:root { --viewport-height: ${viewportHeight}px; }`);
56
- }
57
- return null;
58
- }