@reshaped/utilities 3.9.1-canary.3 → 3.10.0-canary.5

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 (93) hide show
  1. package/README.md +232 -0
  2. package/dist/a11y/Chain.d.ts +20 -0
  3. package/dist/a11y/Chain.js +60 -0
  4. package/dist/a11y/TrapFocus.d.ts +28 -0
  5. package/dist/a11y/TrapFocus.js +162 -0
  6. package/dist/a11y/TrapScreenReader.d.ts +15 -0
  7. package/dist/a11y/TrapScreenReader.js +42 -0
  8. package/dist/a11y/focus.d.ts +38 -0
  9. package/dist/a11y/focus.js +101 -0
  10. package/dist/a11y/index.d.ts +4 -0
  11. package/dist/a11y/index.js +3 -0
  12. package/dist/a11y/keyboardMode.d.ts +4 -0
  13. package/dist/a11y/keyboardMode.js +10 -0
  14. package/dist/a11y/tests/Chain.test.js +88 -0
  15. package/dist/a11y/tests/TrapFocus.test.d.ts +1 -0
  16. package/dist/a11y/tests/TrapFocus.test.js +313 -0
  17. package/dist/a11y/tests/TrapScreenReader.test.d.ts +1 -0
  18. package/dist/a11y/tests/TrapScreenReader.test.js +126 -0
  19. package/dist/a11y/tests/focus.test.d.ts +1 -0
  20. package/dist/a11y/tests/focus.test.js +278 -0
  21. package/dist/a11y/tests/keyboardMode.test.d.ts +1 -0
  22. package/dist/a11y/tests/keyboardMode.test.js +27 -0
  23. package/dist/a11y/types.d.ts +24 -0
  24. package/dist/a11y/types.js +1 -0
  25. package/dist/constants/keys.d.ts +11 -0
  26. package/dist/constants/keys.js +11 -0
  27. package/dist/css/StyleCache.d.ts +7 -0
  28. package/dist/css/StyleCache.js +19 -0
  29. package/dist/css/classNames.d.ts +7 -0
  30. package/dist/css/classNames.js +19 -0
  31. package/dist/css/index.d.ts +2 -0
  32. package/dist/css/index.js +4 -0
  33. package/dist/css/tests/StyleCache.test.d.ts +1 -0
  34. package/dist/css/tests/StyleCache.test.js +45 -0
  35. package/dist/css/tests/classNames.test.d.ts +1 -0
  36. package/dist/css/tests/classNames.test.js +63 -0
  37. package/dist/dom/findClosestScrollableContainer.d.ts +5 -0
  38. package/dist/dom/findClosestScrollableContainer.js +12 -0
  39. package/dist/dom/findParent.d.ts +2 -0
  40. package/dist/dom/findParent.js +10 -0
  41. package/dist/dom/index.d.ts +3 -0
  42. package/dist/dom/index.js +4 -0
  43. package/dist/dom/tests/findClosestScrollableContainer.test.d.ts +1 -0
  44. package/dist/dom/tests/findClosestScrollableContainer.test.js +61 -0
  45. package/dist/dom/tests/findParent.test.d.ts +1 -0
  46. package/dist/dom/tests/findParent.test.js +45 -0
  47. package/dist/flyout/Flyout.d.ts +2 -2
  48. package/dist/flyout/Flyout.js +6 -6
  49. package/dist/flyout/index.d.ts +1 -1
  50. package/dist/flyout/index.js +1 -1
  51. package/dist/flyout/tests/Flyout.test.js +9 -9
  52. package/dist/flyout/types.d.ts +2 -2
  53. package/dist/flyout/utilities/applyPosition.js +1 -1
  54. package/dist/flyout/utilities/tests/applyPosition.test.js +10 -10
  55. package/dist/flyout/utilities/tests/calculateLayoutAdjustment.test.js +2 -2
  56. package/dist/flyout/utilities/tests/calculatePosition.test.js +1 -1
  57. package/dist/flyout/utilities/tests/centerBySize.test.js +1 -1
  58. package/dist/flyout/utilities/tests/getPositionFallbacks.test.js +1 -1
  59. package/dist/flyout/utilities/tests/getRTLPosition.test.js +1 -1
  60. package/dist/flyout/utilities/tests/isFullyVisible.test.js +1 -1
  61. package/dist/helpers/classNames.d.ts +7 -0
  62. package/dist/helpers/classNames.js +19 -0
  63. package/dist/helpers/index.d.ts +1 -0
  64. package/dist/helpers/index.js +2 -0
  65. package/dist/helpers/tests/classNames.test.d.ts +1 -0
  66. package/dist/helpers/tests/classNames.test.js +63 -0
  67. package/dist/i18n/index.d.ts +1 -0
  68. package/dist/i18n/index.js +2 -0
  69. package/dist/index.d.ts +5 -1
  70. package/dist/index.js +5 -1
  71. package/dist/internal.d.ts +11 -0
  72. package/dist/internal.js +10 -0
  73. package/dist/platform/index.d.ts +1 -0
  74. package/dist/platform/index.js +16 -0
  75. package/dist/scroll/disable.d.ts +7 -0
  76. package/dist/scroll/disable.js +15 -0
  77. package/dist/scroll/helpers.d.ts +1 -0
  78. package/dist/scroll/helpers.js +17 -0
  79. package/dist/scroll/index.d.ts +2 -0
  80. package/dist/scroll/index.js +4 -0
  81. package/dist/scroll/lock.d.ts +7 -0
  82. package/dist/scroll/lock.js +26 -0
  83. package/dist/scroll/lockSafari.d.ts +2 -0
  84. package/dist/scroll/lockSafari.js +20 -0
  85. package/dist/scroll/lockStandard.d.ts +4 -0
  86. package/dist/scroll/lockStandard.js +15 -0
  87. package/dist/scroll/tests/lock.test.d.ts +1 -0
  88. package/dist/scroll/tests/lock.test.js +81 -0
  89. package/package.json +6 -1
  90. package/dist/flyout/utilities/findClosestFixedContainer.d.ts +0 -5
  91. package/dist/flyout/utilities/findClosestFixedContainer.js +0 -18
  92. package/dist/flyout/utilities/tests/findClosestFixedContainer.test.js +0 -46
  93. /package/dist/{flyout/utilities/tests/findClosestFixedContainer.test.d.ts → a11y/tests/Chain.test.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { expect, test, describe, beforeEach, vi, afterEach } from "vitest";
2
+ import { lockScroll } from "../lock.js";
3
+ // Mock the platform module to avoid iOS path
4
+ vi.mock("@/platform", () => ({
5
+ isIOS: () => false,
6
+ }));
7
+ describe("scroll/lockScroll", () => {
8
+ beforeEach(() => {
9
+ // Reset the body styles before each test
10
+ document.body.style.overflow = "";
11
+ document.body.style.paddingRight = "";
12
+ document.body.innerHTML = "";
13
+ });
14
+ afterEach(() => {
15
+ // Clean up
16
+ document.body.style.overflow = "";
17
+ document.body.style.paddingRight = "";
18
+ document.body.innerHTML = "";
19
+ });
20
+ test("locks scroll on body", () => {
21
+ const unlock = lockScroll({});
22
+ expect(document.body.style.overflow).toBe("hidden");
23
+ unlock?.();
24
+ expect(document.body.style.overflow).toBe("");
25
+ });
26
+ test("locks scroll on custom container element", () => {
27
+ const container = document.createElement("div");
28
+ container.style.overflow = "auto";
29
+ container.style.height = "200px";
30
+ document.body.appendChild(container);
31
+ const unlock = lockScroll({ containerEl: container });
32
+ expect(container.style.overflow).toBe("hidden");
33
+ expect(document.body.style.overflow).not.toBe("hidden");
34
+ unlock?.();
35
+ expect(container.style.overflow).toBe("auto");
36
+ });
37
+ test("finds scrollable container from origin element", () => {
38
+ const scrollableContainer = document.createElement("div");
39
+ scrollableContainer.style.overflow = "auto";
40
+ scrollableContainer.style.height = "200px";
41
+ document.body.appendChild(scrollableContainer);
42
+ // Add content to make it scrollable
43
+ const content = document.createElement("div");
44
+ content.style.height = "500px";
45
+ scrollableContainer.appendChild(content);
46
+ const originEl = document.createElement("div");
47
+ scrollableContainer.appendChild(originEl);
48
+ const unlock = lockScroll({ originEl });
49
+ expect(scrollableContainer.style.overflow).toBe("hidden");
50
+ unlock?.();
51
+ expect(scrollableContainer.style.overflow).toBe("auto");
52
+ });
53
+ test("unlocks after multiple locks", () => {
54
+ const unlock1 = lockScroll({});
55
+ const unlock2 = lockScroll({});
56
+ expect(document.body.style.overflow).toBe("hidden");
57
+ unlock1?.();
58
+ expect(document.body.style.overflow).toBe("");
59
+ unlock2?.();
60
+ expect(document.body.style.overflow).toBe("");
61
+ });
62
+ test("calls lock callback immediately", () => {
63
+ const lockCb = vi.fn();
64
+ lockScroll({ callback: lockCb });
65
+ expect(lockCb).toHaveBeenCalledTimes(1);
66
+ });
67
+ test("calls unlock callback when unlocking", () => {
68
+ const unlockCb = vi.fn();
69
+ const unlock = lockScroll({});
70
+ unlock?.({ callback: unlockCb });
71
+ expect(unlockCb).toHaveBeenCalledTimes(1);
72
+ });
73
+ test("handles origin element when no scrollable container is found (falls back to body)", () => {
74
+ const originEl = document.createElement("div");
75
+ document.body.appendChild(originEl);
76
+ const unlock = lockScroll({ originEl });
77
+ expect(document.body.style.overflow).toBe("hidden");
78
+ unlock?.();
79
+ expect(document.body.style.overflow).toBe("");
80
+ });
81
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reshaped/utilities",
3
3
  "description": "Vanilla JS utilities for implementing common UI patterns",
4
- "version": "3.9.1-canary.3",
4
+ "version": "3.10.0-canary.5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://reshaped.so",
7
7
  "repository": {
@@ -27,6 +27,11 @@
27
27
  "import": "./dist/index.js",
28
28
  "default": "./dist/index.js"
29
29
  },
30
+ "./internal": {
31
+ "types": "./dist/internal.d.ts",
32
+ "import": "./dist/internal.js",
33
+ "default": "./dist/internal.js"
34
+ },
30
35
  "./package.json": "./package.json"
31
36
  },
32
37
  "peerDependencies": {
@@ -1,5 +0,0 @@
1
- type Args = {
2
- el: HTMLElement | null;
3
- };
4
- declare const _default: (args: Args) => HTMLElement;
5
- export default _default;
@@ -1,18 +0,0 @@
1
- import getShadowRoot from "../../dom/getShadowRoot.js";
2
- const findClosestPositionContainer = (args) => {
3
- const { el, iteration = 0 } = args;
4
- const style = el && window.getComputedStyle(el);
5
- const position = style?.position;
6
- const isFixed = position === "fixed" || position === "sticky";
7
- if (iteration === 0) {
8
- const shadowRoot = getShadowRoot(el);
9
- if (shadowRoot?.firstElementChild)
10
- return shadowRoot.firstElementChild;
11
- }
12
- if (el === document.body || !el)
13
- return document.body;
14
- if (isFixed)
15
- return el;
16
- return findClosestPositionContainer({ el: el.parentElement, iteration: iteration + 1 });
17
- };
18
- export default (args) => findClosestPositionContainer({ ...args, iteration: 0 });
@@ -1,46 +0,0 @@
1
- import { expect, test, describe } from "vitest";
2
- import findClosestFixedContainer from "flyout/utilities/findClosestFixedContainer";
3
- describe("flyout/findClosestFixedContainer", () => {
4
- test("returns document.body when element is null", () => {
5
- const result = findClosestFixedContainer({ el: null });
6
- expect(result).toBe(document.body);
7
- });
8
- test("returns document.body when element is document.body", () => {
9
- const result = findClosestFixedContainer({ el: document.body });
10
- expect(result).toBe(document.body);
11
- });
12
- test("returns the element itself when it has position fixed", () => {
13
- const fixedEl = document.createElement("div");
14
- fixedEl.style.position = "fixed";
15
- document.body.appendChild(fixedEl);
16
- const result = findClosestFixedContainer({ el: fixedEl });
17
- expect(result).toBe(fixedEl);
18
- });
19
- test("returns the element itself when it has position sticky", () => {
20
- const stickyEl = document.createElement("div");
21
- stickyEl.style.position = "sticky";
22
- document.body.appendChild(stickyEl);
23
- const result = findClosestFixedContainer({ el: stickyEl });
24
- expect(result).toBe(stickyEl);
25
- });
26
- test("returns grandparent when it has position fixed", () => {
27
- const fixedEl = document.createElement("div");
28
- fixedEl.style.position = "fixed";
29
- const childEl = document.createElement("div");
30
- const grandChildEl = document.createElement("div");
31
- childEl.appendChild(grandChildEl);
32
- fixedEl.appendChild(childEl);
33
- document.body.appendChild(fixedEl);
34
- const result = findClosestFixedContainer({ el: grandChildEl });
35
- expect(result).toBe(fixedEl);
36
- });
37
- test("returns document.body when no fixed container is found", () => {
38
- const staticEl = document.createElement("div");
39
- staticEl.style.position = "static";
40
- const childEl = document.createElement("div");
41
- staticEl.appendChild(childEl);
42
- document.body.appendChild(staticEl);
43
- const result = findClosestFixedContainer({ el: childEl });
44
- expect(result).toBe(document.body);
45
- });
46
- });