@adam-milo/ui 1.0.28 → 1.0.29
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/index.cjs +1 -1
- package/dist/index.js +3 -1
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +1 -1
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +1 -1
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +1 -1
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +2 -2
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +1 -1
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +1 -1
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +1 -1
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +43 -12
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +1 -1
- package/dist/index20.cjs +1 -0
- package/dist/index20.js +14 -0
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +20 -299
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +298 -13
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +16 -0
- package/dist/{index26.cjs → index27.cjs} +1 -1
- package/dist/{index26.js → index27.js} +21 -21
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +2 -2
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +1 -1
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +18 -3
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +3 -8
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +7 -66
- package/dist/index43.cjs +1 -1
- package/dist/index43.js +66 -35
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +31 -56
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +60 -6
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +6 -208
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +203 -20
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +23 -202
- package/dist/index49.cjs +1 -1
- package/dist/index49.js +204 -10
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +1 -1
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +10 -289
- package/dist/index51.cjs +1 -1
- package/dist/index51.js +288 -13
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +14 -39
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +36 -82
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +84 -9
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +8 -65
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +68 -3
- package/dist/index57.cjs +1 -1
- package/dist/index57.js +3 -11
- package/dist/index58.cjs +1 -1
- package/dist/index58.js +11 -31
- package/dist/index59.cjs +1 -1
- package/dist/index59.js +30 -118
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +2 -2
- package/dist/index60.cjs +1 -1
- package/dist/index60.js +120 -9
- package/dist/index61.cjs +1 -1
- package/dist/index61.js +8 -14
- package/dist/index63.cjs +1 -1
- package/dist/index63.js +14 -22
- package/dist/index64.cjs +1 -1
- package/dist/index64.js +291 -33
- package/dist/index65.cjs +1 -1
- package/dist/index65.js +22 -622
- package/dist/index66.cjs +1 -1
- package/dist/index66.js +35 -35
- package/dist/index67.cjs +1 -1
- package/dist/index67.js +620 -33
- package/dist/index68.cjs +1 -1
- package/dist/index68.js +37 -5
- package/dist/index69.cjs +1 -1
- package/dist/index69.js +36 -8
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +1 -1
- package/dist/index70.cjs +1 -1
- package/dist/index70.js +5 -3
- package/dist/index71.cjs +1 -1
- package/dist/index71.js +8 -33
- package/dist/index72.cjs +1 -1
- package/dist/index72.js +3 -178
- package/dist/index73.cjs +1 -1
- package/dist/index73.js +31 -17
- package/dist/index74.cjs +1 -1
- package/dist/index74.js +165 -706
- package/dist/index75.cjs +1 -1
- package/dist/index75.js +16 -149
- package/dist/index76.cjs +1 -1
- package/dist/index76.js +697 -149
- package/dist/index77.cjs +1 -1
- package/dist/index77.js +150 -43
- package/dist/index78.cjs +1 -1
- package/dist/index78.js +170 -10
- package/dist/index79.cjs +1 -1
- package/dist/index79.js +83 -14
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +1 -1
- package/dist/index80.cjs +1 -1
- package/dist/index80.js +41 -96
- package/dist/index81.cjs +1 -1
- package/dist/index81.js +10 -85
- package/dist/index82.cjs +1 -1
- package/dist/index82.js +15 -7
- package/dist/index83.cjs +1 -1
- package/dist/index83.js +99 -26
- package/dist/index84.cjs +1 -1
- package/dist/index84.js +8 -34
- package/dist/index85.cjs +1 -1
- package/dist/index85.js +27 -14
- package/dist/index86.cjs +1 -1
- package/dist/index86.js +30 -41
- package/dist/index87.cjs +1 -1
- package/dist/index87.js +13 -6
- package/dist/index88.cjs +1 -0
- package/dist/index88.js +48 -0
- package/dist/index89.cjs +1 -0
- package/dist/index89.js +9 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +2 -2
- package/dist/src/components/typography/text/Text.component.d.ts +93 -0
- package/dist/src/components/typography/text/Text.component.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/dist/index21.cjs +0 -1
- package/dist/index21.js +0 -22
- package/dist/index38.cjs +0 -1
- package/dist/index38.js +0 -21
- package/dist/index62.cjs +0 -1
- package/dist/index62.js +0 -297
- /package/dist/{index34.cjs → index35.cjs} +0 -0
- /package/dist/{index34.js → index35.js} +0 -0
package/dist/index48.js
CHANGED
|
@@ -1,208 +1,29 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useCallbackRef } from "./index54.js";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
|
7
|
-
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
|
8
|
-
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
|
9
|
-
var FOCUS_SCOPE_NAME = "FocusScope";
|
|
10
|
-
var FocusScope = React.forwardRef((props, forwardedRef) => {
|
|
11
|
-
const {
|
|
12
|
-
loop = false,
|
|
13
|
-
trapped = false,
|
|
14
|
-
onMountAutoFocus: onMountAutoFocusProp,
|
|
15
|
-
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
16
|
-
...scopeProps
|
|
17
|
-
} = props;
|
|
18
|
-
const [container, setContainer] = React.useState(null);
|
|
19
|
-
const onMountAutoFocus = useCallbackRef(onMountAutoFocusProp);
|
|
20
|
-
const onUnmountAutoFocus = useCallbackRef(onUnmountAutoFocusProp);
|
|
21
|
-
const lastFocusedElementRef = React.useRef(null);
|
|
22
|
-
const composedRefs = useComposedRefs(forwardedRef, (node) => setContainer(node));
|
|
23
|
-
const focusScope = React.useRef({
|
|
24
|
-
paused: false,
|
|
25
|
-
pause() {
|
|
26
|
-
this.paused = true;
|
|
27
|
-
},
|
|
28
|
-
resume() {
|
|
29
|
-
this.paused = false;
|
|
30
|
-
}
|
|
31
|
-
}).current;
|
|
2
|
+
var count = 0;
|
|
3
|
+
function useFocusGuards() {
|
|
32
4
|
React.useEffect(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
focus(lastFocusedElementRef.current, { select: true });
|
|
41
|
-
}
|
|
42
|
-
}, handleFocusOut2 = function(event) {
|
|
43
|
-
if (focusScope.paused || !container) return;
|
|
44
|
-
const relatedTarget = event.relatedTarget;
|
|
45
|
-
if (relatedTarget === null) return;
|
|
46
|
-
if (!container.contains(relatedTarget)) {
|
|
47
|
-
focus(lastFocusedElementRef.current, { select: true });
|
|
48
|
-
}
|
|
49
|
-
}, handleMutations2 = function(mutations) {
|
|
50
|
-
const focusedElement = document.activeElement;
|
|
51
|
-
if (focusedElement !== document.body) return;
|
|
52
|
-
for (const mutation of mutations) {
|
|
53
|
-
if (mutation.removedNodes.length > 0) focus(container);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
document.addEventListener("focusin", handleFocusIn2);
|
|
57
|
-
document.addEventListener("focusout", handleFocusOut2);
|
|
58
|
-
const mutationObserver = new MutationObserver(handleMutations2);
|
|
59
|
-
if (container) mutationObserver.observe(container, { childList: true, subtree: true });
|
|
60
|
-
return () => {
|
|
61
|
-
document.removeEventListener("focusin", handleFocusIn2);
|
|
62
|
-
document.removeEventListener("focusout", handleFocusOut2);
|
|
63
|
-
mutationObserver.disconnect();
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}, [trapped, container, focusScope.paused]);
|
|
67
|
-
React.useEffect(() => {
|
|
68
|
-
if (container) {
|
|
69
|
-
focusScopesStack.add(focusScope);
|
|
70
|
-
const previouslyFocusedElement = document.activeElement;
|
|
71
|
-
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
|
72
|
-
if (!hasFocusedCandidate) {
|
|
73
|
-
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
74
|
-
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
75
|
-
container.dispatchEvent(mountEvent);
|
|
76
|
-
if (!mountEvent.defaultPrevented) {
|
|
77
|
-
focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
|
|
78
|
-
if (document.activeElement === previouslyFocusedElement) {
|
|
79
|
-
focus(container);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return () => {
|
|
84
|
-
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
85
|
-
setTimeout(() => {
|
|
86
|
-
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
87
|
-
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
88
|
-
container.dispatchEvent(unmountEvent);
|
|
89
|
-
if (!unmountEvent.defaultPrevented) {
|
|
90
|
-
focus(previouslyFocusedElement ?? document.body, { select: true });
|
|
91
|
-
}
|
|
92
|
-
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
93
|
-
focusScopesStack.remove(focusScope);
|
|
94
|
-
}, 0);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}, [container, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
|
98
|
-
const handleKeyDown = React.useCallback(
|
|
99
|
-
(event) => {
|
|
100
|
-
if (!loop && !trapped) return;
|
|
101
|
-
if (focusScope.paused) return;
|
|
102
|
-
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
103
|
-
const focusedElement = document.activeElement;
|
|
104
|
-
if (isTabKey && focusedElement) {
|
|
105
|
-
const container2 = event.currentTarget;
|
|
106
|
-
const [first, last] = getTabbableEdges(container2);
|
|
107
|
-
const hasTabbableElementsInside = first && last;
|
|
108
|
-
if (!hasTabbableElementsInside) {
|
|
109
|
-
if (focusedElement === container2) event.preventDefault();
|
|
110
|
-
} else {
|
|
111
|
-
if (!event.shiftKey && focusedElement === last) {
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
if (loop) focus(first, { select: true });
|
|
114
|
-
} else if (event.shiftKey && focusedElement === first) {
|
|
115
|
-
event.preventDefault();
|
|
116
|
-
if (loop) focus(last, { select: true });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
[loop, trapped, focusScope.paused]
|
|
122
|
-
);
|
|
123
|
-
return /* @__PURE__ */ jsx(Primitive.div, { tabIndex: -1, ...scopeProps, ref: composedRefs, onKeyDown: handleKeyDown });
|
|
124
|
-
});
|
|
125
|
-
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
|
126
|
-
function focusFirst(candidates, { select = false } = {}) {
|
|
127
|
-
const previouslyFocusedElement = document.activeElement;
|
|
128
|
-
for (const candidate of candidates) {
|
|
129
|
-
focus(candidate, { select });
|
|
130
|
-
if (document.activeElement !== previouslyFocusedElement) return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function getTabbableEdges(container) {
|
|
134
|
-
const candidates = getTabbableCandidates(container);
|
|
135
|
-
const first = findVisible(candidates, container);
|
|
136
|
-
const last = findVisible(candidates.reverse(), container);
|
|
137
|
-
return [first, last];
|
|
138
|
-
}
|
|
139
|
-
function getTabbableCandidates(container) {
|
|
140
|
-
const nodes = [];
|
|
141
|
-
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
142
|
-
acceptNode: (node) => {
|
|
143
|
-
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
144
|
-
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
|
145
|
-
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
while (walker.nextNode()) nodes.push(walker.currentNode);
|
|
149
|
-
return nodes;
|
|
150
|
-
}
|
|
151
|
-
function findVisible(elements, container) {
|
|
152
|
-
for (const element of elements) {
|
|
153
|
-
if (!isHidden(element, { upTo: container })) return element;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function isHidden(node, { upTo }) {
|
|
157
|
-
if (getComputedStyle(node).visibility === "hidden") return true;
|
|
158
|
-
while (node) {
|
|
159
|
-
if (upTo !== void 0 && node === upTo) return false;
|
|
160
|
-
if (getComputedStyle(node).display === "none") return true;
|
|
161
|
-
node = node.parentElement;
|
|
162
|
-
}
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
function isSelectableInput(element) {
|
|
166
|
-
return element instanceof HTMLInputElement && "select" in element;
|
|
167
|
-
}
|
|
168
|
-
function focus(element, { select = false } = {}) {
|
|
169
|
-
if (element && element.focus) {
|
|
170
|
-
const previouslyFocusedElement = document.activeElement;
|
|
171
|
-
element.focus({ preventScroll: true });
|
|
172
|
-
if (element !== previouslyFocusedElement && isSelectableInput(element) && select)
|
|
173
|
-
element.select();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
var focusScopesStack = createFocusScopesStack();
|
|
177
|
-
function createFocusScopesStack() {
|
|
178
|
-
let stack = [];
|
|
179
|
-
return {
|
|
180
|
-
add(focusScope) {
|
|
181
|
-
const activeFocusScope = stack[0];
|
|
182
|
-
if (focusScope !== activeFocusScope) {
|
|
183
|
-
activeFocusScope == null ? void 0 : activeFocusScope.pause();
|
|
5
|
+
const edgeGuards = document.querySelectorAll("[data-radix-focus-guard]");
|
|
6
|
+
document.body.insertAdjacentElement("afterbegin", edgeGuards[0] ?? createFocusGuard());
|
|
7
|
+
document.body.insertAdjacentElement("beforeend", edgeGuards[1] ?? createFocusGuard());
|
|
8
|
+
count++;
|
|
9
|
+
return () => {
|
|
10
|
+
if (count === 1) {
|
|
11
|
+
document.querySelectorAll("[data-radix-focus-guard]").forEach((node) => node.remove());
|
|
184
12
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (index !== -1) {
|
|
199
|
-
updatedArray.splice(index, 1);
|
|
200
|
-
}
|
|
201
|
-
return updatedArray;
|
|
202
|
-
}
|
|
203
|
-
function removeLinks(items) {
|
|
204
|
-
return items.filter((item) => item.tagName !== "A");
|
|
13
|
+
count--;
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
}
|
|
17
|
+
function createFocusGuard() {
|
|
18
|
+
const element = document.createElement("span");
|
|
19
|
+
element.setAttribute("data-radix-focus-guard", "");
|
|
20
|
+
element.tabIndex = 0;
|
|
21
|
+
element.style.outline = "none";
|
|
22
|
+
element.style.opacity = "0";
|
|
23
|
+
element.style.position = "fixed";
|
|
24
|
+
element.style.pointerEvents = "none";
|
|
25
|
+
return element;
|
|
205
26
|
}
|
|
206
27
|
export {
|
|
207
|
-
|
|
28
|
+
useFocusGuards
|
|
208
29
|
};
|
package/dist/index49.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("./index44.cjs"),n=require("./index53.cjs"),o=require("./index55.cjs"),r=require("react/jsx-runtime");function u(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const c=u(e);var s="focusScope.autoFocusOnMount",i="focusScope.autoFocusOnUnmount",a={bubbles:!1,cancelable:!0},d=c.forwardRef((e,u)=>{const{loop:d=!1,trapped:m=!1,onMountAutoFocus:E,onUnmountAutoFocus:b,...y}=e,[T,g]=c.useState(null),S=o.useCallbackRef(E),L=o.useCallbackRef(b),h=c.useRef(null),F=t.useComposedRefs(u,e=>g(e)),N=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(m){let e=function(e){if(N.paused||!T)return;const t=e.target;T.contains(t)?h.current=t:v(h.current,{select:!0})},t=function(e){if(N.paused||!T)return;const t=e.relatedTarget;null!==t&&(T.contains(t)||v(h.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(const t of e)t.removedNodes.length>0&&v(T)};document.addEventListener("focusin",e),document.addEventListener("focusout",t);const o=new MutationObserver(n);return T&&o.observe(T,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",t),o.disconnect()}}},[m,T,N.paused]),c.useEffect(()=>{if(T){p.add(N);const t=document.activeElement;if(!T.contains(t)){const n=new CustomEvent(s,a);T.addEventListener(s,S),T.dispatchEvent(n),n.defaultPrevented||(!function(e,{select:t=!1}={}){const n=document.activeElement;for(const o of e)if(v(o,{select:t}),document.activeElement!==n)return}((e=l(T),e.filter(e=>"A"!==e.tagName)),{select:!0}),document.activeElement===t&&v(T))}return()=>{T.removeEventListener(s,S),setTimeout(()=>{const e=new CustomEvent(i,a);T.addEventListener(i,L),T.dispatchEvent(e),e.defaultPrevented||v(t??document.body,{select:!0}),T.removeEventListener(i,L),p.remove(N)},0)}}var e},[T,S,L,N]);const x=c.useCallback(e=>{if(!d&&!m)return;if(N.paused)return;const t="Tab"===e.key&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){const t=e.currentTarget,[o,r]=function(e){const t=l(e),n=f(t,e),o=f(t.reverse(),e);return[n,o]}(t);o&&r?e.shiftKey||n!==r?e.shiftKey&&n===o&&(e.preventDefault(),d&&v(r,{select:!0})):(e.preventDefault(),d&&v(o,{select:!0})):n===t&&e.preventDefault()}},[d,m,N.paused]);return r.jsx(n.Primitive.div,{tabIndex:-1,...y,ref:F,onKeyDown:x})});function l(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function f(e,t){for(const n of e)if(!m(n,{upTo:t}))return n}function m(e,{upTo:t}){if("hidden"===getComputedStyle(e).visibility)return!0;for(;e;){if(void 0!==t&&e===t)return!1;if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}function v(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&t&&e.select()}}d.displayName="FocusScope";var p=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=E(e,t),e.unshift(t)},remove(t){var n;e=E(e,t),null==(n=e[0])||n.resume()}}}();function E(e,t){const n=[...e],o=n.indexOf(t);return-1!==o&&n.splice(o,1),n}exports.FocusScope=d;
|
package/dist/index49.js
CHANGED
|
@@ -1,14 +1,208 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { useComposedRefs } from "./index44.js";
|
|
3
|
+
import { Primitive } from "./index53.js";
|
|
4
|
+
import { useCallbackRef } from "./index55.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
|
7
|
+
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
|
8
|
+
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
|
9
|
+
var FOCUS_SCOPE_NAME = "FocusScope";
|
|
10
|
+
var FocusScope = React.forwardRef((props, forwardedRef) => {
|
|
11
|
+
const {
|
|
12
|
+
loop = false,
|
|
13
|
+
trapped = false,
|
|
14
|
+
onMountAutoFocus: onMountAutoFocusProp,
|
|
15
|
+
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
16
|
+
...scopeProps
|
|
17
|
+
} = props;
|
|
18
|
+
const [container, setContainer] = React.useState(null);
|
|
19
|
+
const onMountAutoFocus = useCallbackRef(onMountAutoFocusProp);
|
|
20
|
+
const onUnmountAutoFocus = useCallbackRef(onUnmountAutoFocusProp);
|
|
21
|
+
const lastFocusedElementRef = React.useRef(null);
|
|
22
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setContainer(node));
|
|
23
|
+
const focusScope = React.useRef({
|
|
24
|
+
paused: false,
|
|
25
|
+
pause() {
|
|
26
|
+
this.paused = true;
|
|
27
|
+
},
|
|
28
|
+
resume() {
|
|
29
|
+
this.paused = false;
|
|
30
|
+
}
|
|
31
|
+
}).current;
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (trapped) {
|
|
34
|
+
let handleFocusIn2 = function(event) {
|
|
35
|
+
if (focusScope.paused || !container) return;
|
|
36
|
+
const target = event.target;
|
|
37
|
+
if (container.contains(target)) {
|
|
38
|
+
lastFocusedElementRef.current = target;
|
|
39
|
+
} else {
|
|
40
|
+
focus(lastFocusedElementRef.current, { select: true });
|
|
41
|
+
}
|
|
42
|
+
}, handleFocusOut2 = function(event) {
|
|
43
|
+
if (focusScope.paused || !container) return;
|
|
44
|
+
const relatedTarget = event.relatedTarget;
|
|
45
|
+
if (relatedTarget === null) return;
|
|
46
|
+
if (!container.contains(relatedTarget)) {
|
|
47
|
+
focus(lastFocusedElementRef.current, { select: true });
|
|
48
|
+
}
|
|
49
|
+
}, handleMutations2 = function(mutations) {
|
|
50
|
+
const focusedElement = document.activeElement;
|
|
51
|
+
if (focusedElement !== document.body) return;
|
|
52
|
+
for (const mutation of mutations) {
|
|
53
|
+
if (mutation.removedNodes.length > 0) focus(container);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
document.addEventListener("focusin", handleFocusIn2);
|
|
57
|
+
document.addEventListener("focusout", handleFocusOut2);
|
|
58
|
+
const mutationObserver = new MutationObserver(handleMutations2);
|
|
59
|
+
if (container) mutationObserver.observe(container, { childList: true, subtree: true });
|
|
60
|
+
return () => {
|
|
61
|
+
document.removeEventListener("focusin", handleFocusIn2);
|
|
62
|
+
document.removeEventListener("focusout", handleFocusOut2);
|
|
63
|
+
mutationObserver.disconnect();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}, [trapped, container, focusScope.paused]);
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if (container) {
|
|
69
|
+
focusScopesStack.add(focusScope);
|
|
70
|
+
const previouslyFocusedElement = document.activeElement;
|
|
71
|
+
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
|
72
|
+
if (!hasFocusedCandidate) {
|
|
73
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
74
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
75
|
+
container.dispatchEvent(mountEvent);
|
|
76
|
+
if (!mountEvent.defaultPrevented) {
|
|
77
|
+
focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
|
|
78
|
+
if (document.activeElement === previouslyFocusedElement) {
|
|
79
|
+
focus(container);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return () => {
|
|
84
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
87
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
88
|
+
container.dispatchEvent(unmountEvent);
|
|
89
|
+
if (!unmountEvent.defaultPrevented) {
|
|
90
|
+
focus(previouslyFocusedElement ?? document.body, { select: true });
|
|
91
|
+
}
|
|
92
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
93
|
+
focusScopesStack.remove(focusScope);
|
|
94
|
+
}, 0);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}, [container, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
|
98
|
+
const handleKeyDown = React.useCallback(
|
|
99
|
+
(event) => {
|
|
100
|
+
if (!loop && !trapped) return;
|
|
101
|
+
if (focusScope.paused) return;
|
|
102
|
+
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
103
|
+
const focusedElement = document.activeElement;
|
|
104
|
+
if (isTabKey && focusedElement) {
|
|
105
|
+
const container2 = event.currentTarget;
|
|
106
|
+
const [first, last] = getTabbableEdges(container2);
|
|
107
|
+
const hasTabbableElementsInside = first && last;
|
|
108
|
+
if (!hasTabbableElementsInside) {
|
|
109
|
+
if (focusedElement === container2) event.preventDefault();
|
|
110
|
+
} else {
|
|
111
|
+
if (!event.shiftKey && focusedElement === last) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
if (loop) focus(first, { select: true });
|
|
114
|
+
} else if (event.shiftKey && focusedElement === first) {
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
if (loop) focus(last, { select: true });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[loop, trapped, focusScope.paused]
|
|
122
|
+
);
|
|
123
|
+
return /* @__PURE__ */ jsx(Primitive.div, { tabIndex: -1, ...scopeProps, ref: composedRefs, onKeyDown: handleKeyDown });
|
|
124
|
+
});
|
|
125
|
+
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
|
126
|
+
function focusFirst(candidates, { select = false } = {}) {
|
|
127
|
+
const previouslyFocusedElement = document.activeElement;
|
|
128
|
+
for (const candidate of candidates) {
|
|
129
|
+
focus(candidate, { select });
|
|
130
|
+
if (document.activeElement !== previouslyFocusedElement) return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function getTabbableEdges(container) {
|
|
134
|
+
const candidates = getTabbableCandidates(container);
|
|
135
|
+
const first = findVisible(candidates, container);
|
|
136
|
+
const last = findVisible(candidates.reverse(), container);
|
|
137
|
+
return [first, last];
|
|
138
|
+
}
|
|
139
|
+
function getTabbableCandidates(container) {
|
|
140
|
+
const nodes = [];
|
|
141
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
142
|
+
acceptNode: (node) => {
|
|
143
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
144
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
|
145
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
while (walker.nextNode()) nodes.push(walker.currentNode);
|
|
149
|
+
return nodes;
|
|
150
|
+
}
|
|
151
|
+
function findVisible(elements, container) {
|
|
152
|
+
for (const element of elements) {
|
|
153
|
+
if (!isHidden(element, { upTo: container })) return element;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function isHidden(node, { upTo }) {
|
|
157
|
+
if (getComputedStyle(node).visibility === "hidden") return true;
|
|
158
|
+
while (node) {
|
|
159
|
+
if (upTo !== void 0 && node === upTo) return false;
|
|
160
|
+
if (getComputedStyle(node).display === "none") return true;
|
|
161
|
+
node = node.parentElement;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
function isSelectableInput(element) {
|
|
166
|
+
return element instanceof HTMLInputElement && "select" in element;
|
|
167
|
+
}
|
|
168
|
+
function focus(element, { select = false } = {}) {
|
|
169
|
+
if (element && element.focus) {
|
|
170
|
+
const previouslyFocusedElement = document.activeElement;
|
|
171
|
+
element.focus({ preventScroll: true });
|
|
172
|
+
if (element !== previouslyFocusedElement && isSelectableInput(element) && select)
|
|
173
|
+
element.select();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
var focusScopesStack = createFocusScopesStack();
|
|
177
|
+
function createFocusScopesStack() {
|
|
178
|
+
let stack = [];
|
|
179
|
+
return {
|
|
180
|
+
add(focusScope) {
|
|
181
|
+
const activeFocusScope = stack[0];
|
|
182
|
+
if (focusScope !== activeFocusScope) {
|
|
183
|
+
activeFocusScope == null ? void 0 : activeFocusScope.pause();
|
|
184
|
+
}
|
|
185
|
+
stack = arrayRemove(stack, focusScope);
|
|
186
|
+
stack.unshift(focusScope);
|
|
187
|
+
},
|
|
188
|
+
remove(focusScope) {
|
|
189
|
+
var _a;
|
|
190
|
+
stack = arrayRemove(stack, focusScope);
|
|
191
|
+
(_a = stack[0]) == null ? void 0 : _a.resume();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function arrayRemove(array, item) {
|
|
196
|
+
const updatedArray = [...array];
|
|
197
|
+
const index = updatedArray.indexOf(item);
|
|
198
|
+
if (index !== -1) {
|
|
199
|
+
updatedArray.splice(index, 1);
|
|
200
|
+
}
|
|
201
|
+
return updatedArray;
|
|
202
|
+
}
|
|
203
|
+
function removeLinks(items) {
|
|
204
|
+
return items.filter((item) => item.tagName !== "A");
|
|
11
205
|
}
|
|
12
206
|
export {
|
|
13
|
-
|
|
207
|
+
FocusScope
|
|
14
208
|
};
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),a=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),a=require("./index23.cjs"),r=t.forwardRef(({min:r,max:i,step:s=1,allowDecimals:u=!1,validate:n,"data-cy":l,"data-testid":c,...d},o)=>{const m=t.useCallback(e=>{if(!e)return;const t=parseFloat(e);return isNaN(t)?"Please enter a valid number":u||Number.isInteger(t)?void 0!==r&&t<r?`Must be at least ${r}`:void 0!==i&&t>i?`Must be at most ${i}`:void 0:"Decimals are not allowed"},[r,i,u]),p=t.useCallback(e=>n?m(e)||n(e):m(e),[m,n]);return e.jsx(a.Input,{ref:o,type:"number",min:r,max:i,validate:p,"data-cy":l||"numeric-input","data-testid":c||"numeric-input",...d,step:u?"any":s})});r.displayName="NumericInput",exports.NumericInput=r;
|
package/dist/index5.js
CHANGED
package/dist/index50.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("./index57.cjs");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const n=r(e);var o=n[" useId ".trim().toString()]||(()=>{}),u=0;exports.useId=function(e){const[r,c]=n.useState(o());return t.useLayoutEffect(()=>{c(e=>e??String(u++))},[e]),e||(r?`radix-${r}`:"")};
|