@reshaped/utilities 3.10.0-canary.5 → 3.10.0-canary.7
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/dist/a11y/TrapFocus.js +1 -1
- package/dist/constants/keys.d.ts +14 -11
- package/dist/constants/keys.js +14 -11
- package/dist/flyout/types.d.ts +1 -4
- package/dist/flyout/utilities/applyPosition.js +4 -4
- package/dist/flyout/utilities/getRectFromCoordinates.d.ts +1 -1
- package/dist/flyout/utilities/tests/isFullyVisible.test.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/types/global.d.ts +4 -0
- package/package.json +1 -1
- package/dist/flyout/utilities/findClosestScrollableContainer.d.ts +0 -5
- package/dist/flyout/utilities/findClosestScrollableContainer.js +0 -12
- package/dist/flyout/utilities/tests/findClosestScrollableContainer.test.js +0 -66
- package/dist/helpers/classNames.d.ts +0 -7
- package/dist/helpers/classNames.js +0 -19
- package/dist/helpers/tests/classNames.test.d.ts +0 -1
- package/dist/helpers/tests/classNames.test.js +0 -63
- /package/dist/{flyout/utilities/tests/findClosestScrollableContainer.test.d.ts → types/global.js} +0 -0
package/dist/a11y/TrapFocus.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import
|
|
2
|
+
import keys from "../constants/keys.js";
|
|
3
3
|
import { getShadowRoot } from "../dom/index.js";
|
|
4
4
|
import Chain from "./Chain.js";
|
|
5
5
|
import { getActiveElement, getFocusableElements, focusElement, getFocusData } from "./focus.js";
|
package/dist/constants/keys.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
declare const keys: {
|
|
2
|
+
ESC: string;
|
|
3
|
+
SPACE: string;
|
|
4
|
+
ENTER: string;
|
|
5
|
+
TAB: string;
|
|
6
|
+
UP: string;
|
|
7
|
+
DOWN: string;
|
|
8
|
+
RIGHT: string;
|
|
9
|
+
LEFT: string;
|
|
10
|
+
HOME: string;
|
|
11
|
+
END: string;
|
|
12
|
+
BACKSPACE: string;
|
|
13
|
+
};
|
|
14
|
+
export default keys;
|
package/dist/constants/keys.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
const keys = {
|
|
2
|
+
ESC: "Escape",
|
|
3
|
+
SPACE: " ",
|
|
4
|
+
ENTER: "Enter",
|
|
5
|
+
TAB: "Tab",
|
|
6
|
+
UP: "ArrowUp",
|
|
7
|
+
DOWN: "ArrowDown",
|
|
8
|
+
RIGHT: "ArrowRight",
|
|
9
|
+
LEFT: "ArrowLeft",
|
|
10
|
+
HOME: "Home",
|
|
11
|
+
END: "End",
|
|
12
|
+
BACKSPACE: "Backspace",
|
|
13
|
+
};
|
|
14
|
+
export default keys;
|
package/dist/flyout/types.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import type { Coordinates } from "../types/global";
|
|
1
2
|
type XSide = "start" | "end";
|
|
2
3
|
type YSide = "top" | "bottom";
|
|
3
4
|
export type Side = XSide | YSide;
|
|
4
5
|
export type Position = `${YSide}` | `${YSide}-${XSide}` | `${XSide}` | `${XSide}-${YSide}`;
|
|
5
|
-
export type Coordinates = {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
};
|
|
9
6
|
export type Width = "trigger" | string;
|
|
10
7
|
export type Options = {
|
|
11
8
|
content: HTMLElement;
|
|
@@ -56,7 +56,7 @@ const applyPosition = (args) => {
|
|
|
56
56
|
...result,
|
|
57
57
|
fallbackAdjustLayout,
|
|
58
58
|
fallbackMinHeight,
|
|
59
|
-
width,
|
|
59
|
+
width: options?.width,
|
|
60
60
|
flyoutBounds,
|
|
61
61
|
containerBounds,
|
|
62
62
|
triggerBounds: resolvedTriggerBounds,
|
|
@@ -79,7 +79,7 @@ const applyPosition = (args) => {
|
|
|
79
79
|
let calculated = null;
|
|
80
80
|
const testOrder = getPositionFallbacks(position, fallbackPositions);
|
|
81
81
|
testOrder.some((currentPosition) => {
|
|
82
|
-
const tested = testPosition(currentPosition);
|
|
82
|
+
const tested = testPosition(currentPosition, { width });
|
|
83
83
|
const visible = testVisibility(tested);
|
|
84
84
|
if (visible)
|
|
85
85
|
calculated = tested;
|
|
@@ -98,7 +98,7 @@ const applyPosition = (args) => {
|
|
|
98
98
|
}
|
|
99
99
|
// None of the positions fit, use the last used position or the default position
|
|
100
100
|
if (!calculated)
|
|
101
|
-
calculated = testPosition(lastUsedPosition ?? position);
|
|
101
|
+
calculated = testPosition(lastUsedPosition ?? position, { width });
|
|
102
102
|
root.removeChild(contentClone);
|
|
103
103
|
const { styles } = calculated;
|
|
104
104
|
const translateX = (styles.right !== null ? -styles.right : styles.left) + window.scrollX;
|
|
@@ -112,8 +112,8 @@ const applyPosition = (args) => {
|
|
|
112
112
|
width: styles.width !== null ? `${styles.width}px` : (width ?? undefined),
|
|
113
113
|
transform: `translate(${translateX}px, ${translateY}px)`,
|
|
114
114
|
};
|
|
115
|
-
content.style.cssText = "";
|
|
116
115
|
Object.entries(resolvedStyles).forEach(([key, value]) => {
|
|
116
|
+
content.style.removeProperty(key);
|
|
117
117
|
if (!value)
|
|
118
118
|
return;
|
|
119
119
|
content.style.setProperty(key, value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import isFullyVisible from "flyout/utilities/isFullyVisible";
|
|
2
1
|
import { expect, test, describe } from "vitest";
|
|
2
|
+
import isFullyVisible from "../isFullyVisible.js";
|
|
3
3
|
describe("flyout/isFullyVisible", () => {
|
|
4
4
|
test("returns true when flyout is fully visible within visual container", () => {
|
|
5
5
|
const result = isFullyVisible({
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/internal.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const findClosestScrollableContainer = (args) => {
|
|
2
|
-
const { el, iteration } = args;
|
|
3
|
-
const style = el && window.getComputedStyle(el);
|
|
4
|
-
const overflowY = style.overflowY;
|
|
5
|
-
const isScrollable = overflowY.includes("scroll") || overflowY.includes("auto");
|
|
6
|
-
if (!el.parentElement)
|
|
7
|
-
return null;
|
|
8
|
-
if (isScrollable && el.scrollHeight > el.clientHeight)
|
|
9
|
-
return el;
|
|
10
|
-
return findClosestScrollableContainer({ el: el.parentElement, iteration: iteration + 1 });
|
|
11
|
-
};
|
|
12
|
-
export default (args) => findClosestScrollableContainer({ ...args, iteration: 0 });
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe } from "vitest";
|
|
2
|
-
import findClosestScrollableContainer from "../findClosestScrollableContainer.js";
|
|
3
|
-
describe("flyout/findClosestScrollableContainer", () => {
|
|
4
|
-
test("returns null when element has no parent", () => {
|
|
5
|
-
const result = findClosestScrollableContainer({ el: document.documentElement });
|
|
6
|
-
expect(result).toBe(null);
|
|
7
|
-
});
|
|
8
|
-
test("returns the element itself has overflow auto", () => {
|
|
9
|
-
const scrollableEl = document.createElement("div");
|
|
10
|
-
scrollableEl.style.overflowY = "auto";
|
|
11
|
-
scrollableEl.style.height = "100px";
|
|
12
|
-
const childEl = document.createElement("div");
|
|
13
|
-
childEl.style.height = "200px";
|
|
14
|
-
scrollableEl.appendChild(childEl);
|
|
15
|
-
document.body.appendChild(scrollableEl);
|
|
16
|
-
const result = findClosestScrollableContainer({ el: scrollableEl });
|
|
17
|
-
expect(result).toBe(scrollableEl);
|
|
18
|
-
});
|
|
19
|
-
test("returns the element itself has overflow scroll", () => {
|
|
20
|
-
const scrollableEl = document.createElement("div");
|
|
21
|
-
scrollableEl.style.overflowY = "scroll";
|
|
22
|
-
scrollableEl.style.height = "100px";
|
|
23
|
-
const childEl = document.createElement("div");
|
|
24
|
-
childEl.style.height = "200px";
|
|
25
|
-
scrollableEl.appendChild(childEl);
|
|
26
|
-
document.body.appendChild(scrollableEl);
|
|
27
|
-
const result = findClosestScrollableContainer({ el: scrollableEl });
|
|
28
|
-
expect(result).toBe(scrollableEl);
|
|
29
|
-
});
|
|
30
|
-
test("returns grandparent when it is scrollable", () => {
|
|
31
|
-
const scrollableEl = document.createElement("div");
|
|
32
|
-
scrollableEl.style.overflowY = "auto";
|
|
33
|
-
scrollableEl.style.height = "100px";
|
|
34
|
-
const childEl = document.createElement("div");
|
|
35
|
-
childEl.style.height = "200px";
|
|
36
|
-
const grandChildEl = document.createElement("div");
|
|
37
|
-
grandChildEl.style.height = "100px";
|
|
38
|
-
childEl.appendChild(grandChildEl);
|
|
39
|
-
scrollableEl.appendChild(childEl);
|
|
40
|
-
document.body.appendChild(scrollableEl);
|
|
41
|
-
const result = findClosestScrollableContainer({ el: grandChildEl });
|
|
42
|
-
expect(result).toBe(scrollableEl);
|
|
43
|
-
});
|
|
44
|
-
test("returns null when no scrollable container is found", () => {
|
|
45
|
-
const scrollableEl = document.createElement("div");
|
|
46
|
-
scrollableEl.style.overflowY = "visible";
|
|
47
|
-
scrollableEl.style.height = "100px";
|
|
48
|
-
const childEl = document.createElement("div");
|
|
49
|
-
childEl.style.height = "200px";
|
|
50
|
-
scrollableEl.appendChild(childEl);
|
|
51
|
-
document.body.appendChild(scrollableEl);
|
|
52
|
-
const result = findClosestScrollableContainer({ el: childEl });
|
|
53
|
-
expect(result).toBe(null);
|
|
54
|
-
});
|
|
55
|
-
test("does not return element with overflow auto but scrollHeight <= clientHeight", () => {
|
|
56
|
-
const scrollableEl = document.createElement("div");
|
|
57
|
-
scrollableEl.style.overflowY = "auto";
|
|
58
|
-
scrollableEl.style.height = "100px";
|
|
59
|
-
const childEl = document.createElement("div");
|
|
60
|
-
childEl.style.height = "100px";
|
|
61
|
-
scrollableEl.appendChild(childEl);
|
|
62
|
-
document.body.appendChild(scrollableEl);
|
|
63
|
-
const result = findClosestScrollableContainer({ el: childEl });
|
|
64
|
-
expect(result).toBe(null);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type ClassNameValue = string | null | undefined | false;
|
|
2
|
-
export type ClassName = ClassNameValue | ClassNameValue[] | ClassName[];
|
|
3
|
-
/**
|
|
4
|
-
* Resolve an array of values into a classname string
|
|
5
|
-
*/
|
|
6
|
-
declare const classNames: (...args: ClassName[]) => string;
|
|
7
|
-
export default classNames;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve an array of values into a classname string
|
|
3
|
-
*/
|
|
4
|
-
const classNames = (...args) => {
|
|
5
|
-
return args
|
|
6
|
-
.reduce((acc, cur) => {
|
|
7
|
-
if (Array.isArray(cur)) {
|
|
8
|
-
const className = classNames(...cur);
|
|
9
|
-
if (!className)
|
|
10
|
-
return acc;
|
|
11
|
-
return `${acc} ${className}`;
|
|
12
|
-
}
|
|
13
|
-
if (cur)
|
|
14
|
-
return `${acc} ${cur}`;
|
|
15
|
-
return acc;
|
|
16
|
-
}, "")
|
|
17
|
-
.trim();
|
|
18
|
-
};
|
|
19
|
-
export default classNames;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe } from "vitest";
|
|
2
|
-
import classNames from "../classNames.js";
|
|
3
|
-
describe("helpers/classNames", () => {
|
|
4
|
-
test("returns empty string when no arguments are provided", () => {
|
|
5
|
-
expect(classNames()).toBe("");
|
|
6
|
-
});
|
|
7
|
-
test("returns a single class name", () => {
|
|
8
|
-
expect(classNames("foo")).toBe("foo");
|
|
9
|
-
});
|
|
10
|
-
test("concatenates multiple class names", () => {
|
|
11
|
-
expect(classNames("foo", "bar", "baz")).toBe("foo bar baz");
|
|
12
|
-
});
|
|
13
|
-
test("filters out null values", () => {
|
|
14
|
-
expect(classNames("foo", null, "bar")).toBe("foo bar");
|
|
15
|
-
expect(classNames(null, "foo", null)).toBe("foo");
|
|
16
|
-
expect(classNames(null, null)).toBe("");
|
|
17
|
-
});
|
|
18
|
-
test("filters out undefined values", () => {
|
|
19
|
-
expect(classNames("foo", undefined, "bar")).toBe("foo bar");
|
|
20
|
-
expect(classNames(undefined, "foo", undefined)).toBe("foo");
|
|
21
|
-
expect(classNames(undefined, undefined)).toBe("");
|
|
22
|
-
});
|
|
23
|
-
test("filters out false values", () => {
|
|
24
|
-
expect(classNames("foo", false, "bar")).toBe("foo bar");
|
|
25
|
-
expect(classNames(false, "foo", false)).toBe("foo");
|
|
26
|
-
expect(classNames(false, false)).toBe("");
|
|
27
|
-
});
|
|
28
|
-
test("handles arrays of class names", () => {
|
|
29
|
-
expect(classNames(["foo", "bar"])).toBe("foo bar");
|
|
30
|
-
expect(classNames(["foo", "bar"], "baz")).toBe("foo bar baz");
|
|
31
|
-
expect(classNames("foo", ["bar", "baz"])).toBe("foo bar baz");
|
|
32
|
-
});
|
|
33
|
-
test("handles nested arrays", () => {
|
|
34
|
-
expect(classNames(["foo", ["bar", "baz"]])).toBe("foo bar baz");
|
|
35
|
-
expect(classNames([["foo", "bar"], "baz"])).toBe("foo bar baz");
|
|
36
|
-
expect(classNames([["foo"], ["bar"], ["baz"]])).toBe("foo bar baz");
|
|
37
|
-
});
|
|
38
|
-
test("filters out falsy values in arrays", () => {
|
|
39
|
-
expect(classNames(["foo", null, "bar"])).toBe("foo bar");
|
|
40
|
-
expect(classNames(["foo", undefined, "bar"])).toBe("foo bar");
|
|
41
|
-
expect(classNames(["foo", false, "bar"])).toBe("foo bar");
|
|
42
|
-
expect(classNames([null, undefined, false])).toBe("");
|
|
43
|
-
});
|
|
44
|
-
test("handles deeply nested arrays with falsy values", () => {
|
|
45
|
-
expect(classNames([["foo", null], [undefined, "bar"], false])).toBe("foo bar");
|
|
46
|
-
expect(classNames(["foo", [null, undefined, ["bar", false, "baz"]]])).toBe("foo bar baz");
|
|
47
|
-
});
|
|
48
|
-
test("handles empty arrays", () => {
|
|
49
|
-
expect(classNames([])).toBe("");
|
|
50
|
-
expect(classNames("foo", [], "bar")).toBe("foo bar");
|
|
51
|
-
expect(classNames([[], []])).toBe("");
|
|
52
|
-
});
|
|
53
|
-
test("handles empty strings", () => {
|
|
54
|
-
expect(classNames("", "foo")).toBe("foo");
|
|
55
|
-
expect(classNames("foo", "", "bar")).toBe("foo bar");
|
|
56
|
-
expect(classNames("", "", "")).toBe("");
|
|
57
|
-
});
|
|
58
|
-
test("handles conditional class names", () => {
|
|
59
|
-
const isActive = true;
|
|
60
|
-
const isDisabled = false;
|
|
61
|
-
expect(classNames("button", isActive && "active", isDisabled && "disabled")).toBe("button active");
|
|
62
|
-
});
|
|
63
|
-
});
|
/package/dist/{flyout/utilities/tests/findClosestScrollableContainer.test.d.ts → types/global.js}
RENAMED
|
File without changes
|