@octanejs/floating-ui 0.1.32 → 0.1.34
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/cjs/Composite.cjs +235 -0
- package/dist/cjs/FloatingArrow.cjs +143 -0
- package/dist/cjs/FloatingFocusManager.cjs +701 -0
- package/dist/cjs/FloatingList.cjs +145 -0
- package/dist/cjs/FloatingOverlay.cjs +100 -0
- package/dist/cjs/FloatingPortal.cjs +241 -0
- package/dist/cjs/context.cjs +184 -0
- package/dist/cjs/delayGroup.cjs +154 -0
- package/dist/cjs/index.cjs +166 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/pubsub.cjs +44 -0
- package/dist/cjs/safePolygon.cjs +269 -0
- package/dist/cjs/transitions.cjs +150 -0
- package/dist/cjs/tree.cjs +105 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/useClick.cjs +139 -0
- package/dist/cjs/useClientPoint.cjs +201 -0
- package/dist/cjs/useDismiss.cjs +337 -0
- package/dist/cjs/useFloating.cjs +224 -0
- package/dist/cjs/useFocus.cjs +146 -0
- package/dist/cjs/useHover.cjs +393 -0
- package/dist/cjs/useId.cjs +31 -0
- package/dist/cjs/useInteractions.cjs +106 -0
- package/dist/cjs/useListNavigation.cjs +633 -0
- package/dist/cjs/useMergeRefs.cjs +77 -0
- package/dist/cjs/useRole.cjs +118 -0
- package/dist/cjs/useTypeahead.cjs +164 -0
- package/dist/cjs/utils/index.cjs +709 -0
- package/package.json +13 -6
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FloatingList_exports = {};
|
|
20
|
+
__export(FloatingList_exports, {
|
|
21
|
+
FloatingList: () => FloatingList,
|
|
22
|
+
FloatingListContext: () => FloatingListContext,
|
|
23
|
+
useListItem: () => useListItem
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(FloatingList_exports);
|
|
26
|
+
var import_octane = require("octane");
|
|
27
|
+
var import_internal = require("./internal.cjs");
|
|
28
|
+
var import_utils = require("./utils/index.cjs");
|
|
29
|
+
function sortByDocumentPosition(a, b) {
|
|
30
|
+
const position = a.compareDocumentPosition(b);
|
|
31
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING || position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
32
|
+
return -1;
|
|
33
|
+
}
|
|
34
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING || position & Node.DOCUMENT_POSITION_CONTAINS) {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
const FloatingListContext = (0, import_octane.createContext)({
|
|
40
|
+
register: () => {
|
|
41
|
+
},
|
|
42
|
+
unregister: () => {
|
|
43
|
+
},
|
|
44
|
+
map: /* @__PURE__ */ new Map(),
|
|
45
|
+
elementsRef: { current: [] }
|
|
46
|
+
});
|
|
47
|
+
function FloatingList(props) {
|
|
48
|
+
const children = props.children;
|
|
49
|
+
const elementsRef = props.elementsRef;
|
|
50
|
+
const labelsRef = props.labelsRef;
|
|
51
|
+
const [nodes, setNodes] = (0, import_octane.useState)(() => /* @__PURE__ */ new Set(), (0, import_internal.S)("FloatingList:nodes"));
|
|
52
|
+
const register = (0, import_octane.useCallback)(
|
|
53
|
+
(node) => {
|
|
54
|
+
setNodes((prevSet) => new Set(prevSet).add(node));
|
|
55
|
+
},
|
|
56
|
+
[],
|
|
57
|
+
(0, import_internal.S)("FloatingList:register")
|
|
58
|
+
);
|
|
59
|
+
const unregister = (0, import_octane.useCallback)(
|
|
60
|
+
(node) => {
|
|
61
|
+
setNodes((prevSet) => {
|
|
62
|
+
const set = new Set(prevSet);
|
|
63
|
+
set.delete(node);
|
|
64
|
+
return set;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
[],
|
|
68
|
+
(0, import_internal.S)("FloatingList:unregister")
|
|
69
|
+
);
|
|
70
|
+
const map = (0, import_octane.useMemo)(
|
|
71
|
+
() => {
|
|
72
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
73
|
+
const sortedNodes = Array.from(nodes.keys()).sort(sortByDocumentPosition);
|
|
74
|
+
sortedNodes.forEach((node, index) => {
|
|
75
|
+
newMap.set(node, index);
|
|
76
|
+
});
|
|
77
|
+
return newMap;
|
|
78
|
+
},
|
|
79
|
+
[nodes],
|
|
80
|
+
(0, import_internal.S)("FloatingList:map")
|
|
81
|
+
);
|
|
82
|
+
const value = (0, import_octane.useMemo)(
|
|
83
|
+
() => ({ register, unregister, map, elementsRef, labelsRef }),
|
|
84
|
+
[register, unregister, map, elementsRef, labelsRef],
|
|
85
|
+
(0, import_internal.S)("FloatingList:value")
|
|
86
|
+
);
|
|
87
|
+
return (0, import_octane.createElement)(FloatingListContext.Provider, { value, children });
|
|
88
|
+
}
|
|
89
|
+
function useListItem(...args) {
|
|
90
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
91
|
+
const slot = slotArg ?? (0, import_internal.S)("useListItem");
|
|
92
|
+
const props = user[0] ?? {};
|
|
93
|
+
const label = props.label;
|
|
94
|
+
const { register, unregister, map, elementsRef, labelsRef } = (0, import_octane.useContext)(FloatingListContext);
|
|
95
|
+
const [index, setIndex] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "index"));
|
|
96
|
+
const componentRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ref"));
|
|
97
|
+
const ref = (0, import_octane.useCallback)(
|
|
98
|
+
(node) => {
|
|
99
|
+
componentRef.current = node;
|
|
100
|
+
if (index !== null) {
|
|
101
|
+
elementsRef.current[index] = node;
|
|
102
|
+
if (labelsRef) {
|
|
103
|
+
const isLabelDefined = label !== void 0;
|
|
104
|
+
labelsRef.current[index] = isLabelDefined ? label : node?.textContent ?? null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[index, elementsRef, labelsRef, label],
|
|
109
|
+
(0, import_internal.subSlot)(slot, "cb")
|
|
110
|
+
);
|
|
111
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
112
|
+
() => {
|
|
113
|
+
const node = componentRef.current;
|
|
114
|
+
if (node) {
|
|
115
|
+
register(node);
|
|
116
|
+
return () => {
|
|
117
|
+
unregister(node);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[register, unregister],
|
|
122
|
+
(0, import_internal.subSlot)(slot, "e:reg")
|
|
123
|
+
);
|
|
124
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
125
|
+
() => {
|
|
126
|
+
const idx = componentRef.current ? map.get(componentRef.current) : null;
|
|
127
|
+
if (idx != null) {
|
|
128
|
+
setIndex(idx);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
[map],
|
|
132
|
+
(0, import_internal.subSlot)(slot, "e:idx")
|
|
133
|
+
);
|
|
134
|
+
return (0, import_octane.useMemo)(
|
|
135
|
+
() => ({ ref, index: index == null ? -1 : index }),
|
|
136
|
+
[index, ref],
|
|
137
|
+
(0, import_internal.subSlot)(slot, "ret")
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
+
0 && (module.exports = {
|
|
142
|
+
FloatingList,
|
|
143
|
+
FloatingListContext,
|
|
144
|
+
useListItem
|
|
145
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FloatingOverlay_exports = {};
|
|
20
|
+
__export(FloatingOverlay_exports, {
|
|
21
|
+
FloatingOverlay: () => FloatingOverlay
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(FloatingOverlay_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
var import_utils = require("./utils/index.cjs");
|
|
27
|
+
const scrollbarProperty = "--floating-ui-scrollbar-width";
|
|
28
|
+
let lockCount = 0;
|
|
29
|
+
let cleanup = () => {
|
|
30
|
+
};
|
|
31
|
+
function enableScrollLock() {
|
|
32
|
+
const platform = (0, import_utils.getPlatform)();
|
|
33
|
+
const isIOS = /iP(hone|ad|od)|iOS/.test(platform) || platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
34
|
+
const bodyStyle = document.body.style;
|
|
35
|
+
const scrollbarX = Math.round(document.documentElement.getBoundingClientRect().left) + document.documentElement.scrollLeft;
|
|
36
|
+
const paddingProp = scrollbarX ? "paddingLeft" : "paddingRight";
|
|
37
|
+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
|
38
|
+
const scrollX = bodyStyle.left ? parseFloat(bodyStyle.left) : window.scrollX;
|
|
39
|
+
const scrollY = bodyStyle.top ? parseFloat(bodyStyle.top) : window.scrollY;
|
|
40
|
+
bodyStyle.overflow = "hidden";
|
|
41
|
+
bodyStyle.setProperty(scrollbarProperty, scrollbarWidth + "px");
|
|
42
|
+
if (scrollbarWidth) {
|
|
43
|
+
bodyStyle[paddingProp] = scrollbarWidth + "px";
|
|
44
|
+
}
|
|
45
|
+
if (isIOS) {
|
|
46
|
+
const offsetLeft = window.visualViewport?.offsetLeft || 0;
|
|
47
|
+
const offsetTop = window.visualViewport?.offsetTop || 0;
|
|
48
|
+
Object.assign(bodyStyle, {
|
|
49
|
+
position: "fixed",
|
|
50
|
+
top: -(scrollY - Math.floor(offsetTop)) + "px",
|
|
51
|
+
left: -(scrollX - Math.floor(offsetLeft)) + "px",
|
|
52
|
+
right: "0"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
Object.assign(bodyStyle, { overflow: "", [paddingProp]: "" });
|
|
57
|
+
bodyStyle.removeProperty(scrollbarProperty);
|
|
58
|
+
if (isIOS) {
|
|
59
|
+
Object.assign(bodyStyle, { position: "", top: "", left: "", right: "" });
|
|
60
|
+
window.scrollTo(scrollX, scrollY);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function FloatingOverlay(props) {
|
|
65
|
+
const { lockScroll = false, ref, ...rest } = props;
|
|
66
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
67
|
+
() => {
|
|
68
|
+
if (!lockScroll) return;
|
|
69
|
+
lockCount++;
|
|
70
|
+
if (lockCount === 1) {
|
|
71
|
+
cleanup = enableScrollLock();
|
|
72
|
+
}
|
|
73
|
+
return () => {
|
|
74
|
+
lockCount--;
|
|
75
|
+
if (lockCount === 0) {
|
|
76
|
+
cleanup();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
[lockScroll],
|
|
81
|
+
(0, import_internal.S)("FloatingOverlay:lock")
|
|
82
|
+
);
|
|
83
|
+
return (0, import_octane.createElement)("div", {
|
|
84
|
+
ref,
|
|
85
|
+
...rest,
|
|
86
|
+
style: {
|
|
87
|
+
position: "fixed",
|
|
88
|
+
overflow: "auto",
|
|
89
|
+
top: 0,
|
|
90
|
+
right: 0,
|
|
91
|
+
bottom: 0,
|
|
92
|
+
left: 0,
|
|
93
|
+
...rest.style
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
FloatingOverlay
|
|
100
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FloatingPortal_exports = {};
|
|
20
|
+
__export(FloatingPortal_exports, {
|
|
21
|
+
FloatingPortal: () => FloatingPortal,
|
|
22
|
+
FocusGuard: () => FocusGuard,
|
|
23
|
+
PortalContext: () => PortalContext,
|
|
24
|
+
useFloatingPortalNode: () => useFloatingPortalNode,
|
|
25
|
+
usePortalContext: () => usePortalContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(FloatingPortal_exports);
|
|
28
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
29
|
+
var import_octane = require("octane");
|
|
30
|
+
var import_internal = require("./internal.cjs");
|
|
31
|
+
var import_useId = require("./useId.cjs");
|
|
32
|
+
var import_utils = require("./utils/index.cjs");
|
|
33
|
+
const HIDDEN_STYLES = {
|
|
34
|
+
border: 0,
|
|
35
|
+
clip: "rect(0 0 0 0)",
|
|
36
|
+
height: "1px",
|
|
37
|
+
margin: "-1px",
|
|
38
|
+
overflow: "hidden",
|
|
39
|
+
padding: 0,
|
|
40
|
+
position: "fixed",
|
|
41
|
+
whiteSpace: "nowrap",
|
|
42
|
+
width: "1px",
|
|
43
|
+
top: 0,
|
|
44
|
+
left: 0
|
|
45
|
+
};
|
|
46
|
+
function FocusGuard(props) {
|
|
47
|
+
const [role, setRole] = (0, import_octane.useState)(void 0, (0, import_internal.S)("FocusGuard:role"));
|
|
48
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
49
|
+
() => {
|
|
50
|
+
if ((0, import_utils.isSafari)()) {
|
|
51
|
+
setRole("button");
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[],
|
|
55
|
+
(0, import_internal.S)("FocusGuard:eff")
|
|
56
|
+
);
|
|
57
|
+
return (0, import_octane.createElement)("span", {
|
|
58
|
+
...props,
|
|
59
|
+
tabIndex: 0,
|
|
60
|
+
role,
|
|
61
|
+
"aria-hidden": role ? void 0 : true,
|
|
62
|
+
[(0, import_utils.createAttribute)("focus-guard")]: "",
|
|
63
|
+
style: HIDDEN_STYLES
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const HIDDEN_OWNER_STYLES = {
|
|
67
|
+
clipPath: "inset(50%)",
|
|
68
|
+
position: "fixed",
|
|
69
|
+
top: 0,
|
|
70
|
+
left: 0
|
|
71
|
+
};
|
|
72
|
+
const PortalContext = (0, import_octane.createContext)(null);
|
|
73
|
+
const attr = (0, import_utils.createAttribute)("portal");
|
|
74
|
+
function useFloatingPortalNode(...args) {
|
|
75
|
+
const [user, slotArg] = (0, import_internal.splitSlot)(args);
|
|
76
|
+
const slot = slotArg ?? (0, import_internal.S)("useFloatingPortalNode");
|
|
77
|
+
const props = user[0] ?? {};
|
|
78
|
+
const id = props.id;
|
|
79
|
+
const root = props.root;
|
|
80
|
+
const uniqueId = (0, import_useId.useId)((0, import_internal.subSlot)(slot, "id"));
|
|
81
|
+
const portalContext = usePortalContext();
|
|
82
|
+
const [portalNode, setPortalNode] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "node"));
|
|
83
|
+
const portalNodeRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "noderef"));
|
|
84
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
85
|
+
() => {
|
|
86
|
+
return () => {
|
|
87
|
+
portalNode?.remove();
|
|
88
|
+
queueMicrotask(() => {
|
|
89
|
+
portalNodeRef.current = null;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
[portalNode],
|
|
94
|
+
(0, import_internal.subSlot)(slot, "e:cleanup")
|
|
95
|
+
);
|
|
96
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
97
|
+
() => {
|
|
98
|
+
if (!uniqueId) return;
|
|
99
|
+
if (portalNodeRef.current) return;
|
|
100
|
+
const existingIdRoot = id ? document.getElementById(id) : null;
|
|
101
|
+
if (!existingIdRoot) return;
|
|
102
|
+
const subRoot = document.createElement("div");
|
|
103
|
+
subRoot.id = uniqueId;
|
|
104
|
+
subRoot.setAttribute(attr, "");
|
|
105
|
+
existingIdRoot.appendChild(subRoot);
|
|
106
|
+
portalNodeRef.current = subRoot;
|
|
107
|
+
setPortalNode(subRoot);
|
|
108
|
+
},
|
|
109
|
+
[id, uniqueId],
|
|
110
|
+
(0, import_internal.subSlot)(slot, "e:id")
|
|
111
|
+
);
|
|
112
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
113
|
+
() => {
|
|
114
|
+
if (root === null) return;
|
|
115
|
+
if (!uniqueId) return;
|
|
116
|
+
if (portalNodeRef.current) return;
|
|
117
|
+
let container = root || portalContext?.portalNode;
|
|
118
|
+
if (container && !(0, import_dom.isNode)(container)) container = container.current;
|
|
119
|
+
container = container || document.body;
|
|
120
|
+
let idWrapper = null;
|
|
121
|
+
if (id) {
|
|
122
|
+
idWrapper = document.createElement("div");
|
|
123
|
+
idWrapper.id = id;
|
|
124
|
+
container.appendChild(idWrapper);
|
|
125
|
+
}
|
|
126
|
+
const subRoot = document.createElement("div");
|
|
127
|
+
subRoot.id = uniqueId;
|
|
128
|
+
subRoot.setAttribute(attr, "");
|
|
129
|
+
container = idWrapper || container;
|
|
130
|
+
container.appendChild(subRoot);
|
|
131
|
+
portalNodeRef.current = subRoot;
|
|
132
|
+
setPortalNode(subRoot);
|
|
133
|
+
},
|
|
134
|
+
[id, root, uniqueId, portalContext],
|
|
135
|
+
(0, import_internal.subSlot)(slot, "e:root")
|
|
136
|
+
);
|
|
137
|
+
return portalNode;
|
|
138
|
+
}
|
|
139
|
+
function FloatingPortal(props) {
|
|
140
|
+
const children = props.children;
|
|
141
|
+
const id = props.id;
|
|
142
|
+
const root = props.root;
|
|
143
|
+
const preserveTabOrder = props.preserveTabOrder ?? true;
|
|
144
|
+
const portalNode = useFloatingPortalNode({ id, root }, (0, import_internal.S)("FloatingPortal:node"));
|
|
145
|
+
const [focusManagerState, setFocusManagerState] = (0, import_octane.useState)(
|
|
146
|
+
null,
|
|
147
|
+
(0, import_internal.S)("FloatingPortal:fms")
|
|
148
|
+
);
|
|
149
|
+
const beforeOutsideRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FloatingPortal:bo"));
|
|
150
|
+
const afterOutsideRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FloatingPortal:ao"));
|
|
151
|
+
const beforeInsideRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FloatingPortal:bi"));
|
|
152
|
+
const afterInsideRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FloatingPortal:ai"));
|
|
153
|
+
const modal = focusManagerState?.modal;
|
|
154
|
+
const open = focusManagerState?.open;
|
|
155
|
+
const shouldRenderGuards = !!focusManagerState && !focusManagerState.modal && focusManagerState.open && preserveTabOrder && !!(root || portalNode);
|
|
156
|
+
(0, import_octane.useEffect)(
|
|
157
|
+
() => {
|
|
158
|
+
if (!portalNode || !preserveTabOrder || modal) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
function onFocus(event) {
|
|
162
|
+
if (portalNode && (0, import_utils.isOutsideEvent)(event)) {
|
|
163
|
+
const focusing = event.type === "focusin";
|
|
164
|
+
const manageFocus = focusing ? import_utils.enableFocusInside : import_utils.disableFocusInside;
|
|
165
|
+
manageFocus(portalNode);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
portalNode.addEventListener("focusin", onFocus, true);
|
|
169
|
+
portalNode.addEventListener("focusout", onFocus, true);
|
|
170
|
+
return () => {
|
|
171
|
+
portalNode.removeEventListener("focusin", onFocus, true);
|
|
172
|
+
portalNode.removeEventListener("focusout", onFocus, true);
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
[portalNode, preserveTabOrder, modal],
|
|
176
|
+
(0, import_internal.S)("FloatingPortal:e:tab")
|
|
177
|
+
);
|
|
178
|
+
(0, import_octane.useEffect)(
|
|
179
|
+
() => {
|
|
180
|
+
if (!portalNode) return;
|
|
181
|
+
if (open) return;
|
|
182
|
+
(0, import_utils.enableFocusInside)(portalNode);
|
|
183
|
+
},
|
|
184
|
+
[open, portalNode],
|
|
185
|
+
(0, import_internal.S)("FloatingPortal:e:enable")
|
|
186
|
+
);
|
|
187
|
+
const value = (0, import_octane.useMemo)(
|
|
188
|
+
() => ({
|
|
189
|
+
preserveTabOrder,
|
|
190
|
+
beforeOutsideRef,
|
|
191
|
+
afterOutsideRef,
|
|
192
|
+
beforeInsideRef,
|
|
193
|
+
afterInsideRef,
|
|
194
|
+
portalNode,
|
|
195
|
+
setFocusManagerState
|
|
196
|
+
}),
|
|
197
|
+
[preserveTabOrder, portalNode],
|
|
198
|
+
(0, import_internal.S)("FloatingPortal:value")
|
|
199
|
+
);
|
|
200
|
+
return (0, import_octane.createElement)(PortalContext.Provider, {
|
|
201
|
+
value,
|
|
202
|
+
children: [
|
|
203
|
+
shouldRenderGuards && portalNode && (0, import_octane.createElement)(FocusGuard, {
|
|
204
|
+
"data-type": "outside",
|
|
205
|
+
ref: beforeOutsideRef,
|
|
206
|
+
onFocus: (event) => {
|
|
207
|
+
if ((0, import_utils.isOutsideEvent)(event, portalNode)) {
|
|
208
|
+
beforeInsideRef.current?.focus();
|
|
209
|
+
} else {
|
|
210
|
+
const domReference = focusManagerState ? focusManagerState.domReference : null;
|
|
211
|
+
(0, import_utils.getPreviousTabbable)(domReference)?.focus();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}),
|
|
215
|
+
shouldRenderGuards && portalNode && (0, import_octane.createElement)("span", { "aria-owns": portalNode.id, style: HIDDEN_OWNER_STYLES }),
|
|
216
|
+
portalNode && (0, import_octane.createPortal)(children, portalNode),
|
|
217
|
+
shouldRenderGuards && portalNode && (0, import_octane.createElement)(FocusGuard, {
|
|
218
|
+
"data-type": "outside",
|
|
219
|
+
ref: afterOutsideRef,
|
|
220
|
+
onFocus: (event) => {
|
|
221
|
+
if ((0, import_utils.isOutsideEvent)(event, portalNode)) {
|
|
222
|
+
afterInsideRef.current?.focus();
|
|
223
|
+
} else {
|
|
224
|
+
const domReference = focusManagerState ? focusManagerState.domReference : null;
|
|
225
|
+
(0, import_utils.getNextTabbable)(domReference)?.focus();
|
|
226
|
+
focusManagerState?.closeOnFocusOut && focusManagerState?.onOpenChange(false, event, "focus-out");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
]
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const usePortalContext = () => (0, import_octane.useContext)(PortalContext);
|
|
234
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
235
|
+
0 && (module.exports = {
|
|
236
|
+
FloatingPortal,
|
|
237
|
+
FocusGuard,
|
|
238
|
+
PortalContext,
|
|
239
|
+
useFloatingPortalNode,
|
|
240
|
+
usePortalContext
|
|
241
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var context_exports = {};
|
|
20
|
+
__export(context_exports, {
|
|
21
|
+
createPubSub: () => import_pubsub2.createPubSub,
|
|
22
|
+
useFloating: () => useFloating,
|
|
23
|
+
useFloatingRootContext: () => useFloatingRootContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(context_exports);
|
|
26
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
27
|
+
var import_octane = require("octane");
|
|
28
|
+
var import_internal = require("./internal.cjs");
|
|
29
|
+
var import_pubsub = require("./pubsub.cjs");
|
|
30
|
+
var import_tree = require("./tree.cjs");
|
|
31
|
+
var import_useId = require("./useId.cjs");
|
|
32
|
+
var import_useFloating = require("./useFloating.cjs");
|
|
33
|
+
var import_utils = require("./utils/index.cjs");
|
|
34
|
+
var import_pubsub2 = require("./pubsub.cjs");
|
|
35
|
+
function useFloatingRootContext(options, slot) {
|
|
36
|
+
const open = options.open ?? false;
|
|
37
|
+
const onOpenChangeProp = options.onOpenChange;
|
|
38
|
+
const elementsProp = options.elements;
|
|
39
|
+
const floatingId = (0, import_useId.useId)((0, import_internal.subSlot)(slot, "id"));
|
|
40
|
+
const dataRef = (0, import_octane.useRef)({}, (0, import_internal.subSlot)(slot, "data"));
|
|
41
|
+
const [events] = (0, import_octane.useState)(() => (0, import_pubsub.createPubSub)(), (0, import_internal.subSlot)(slot, "events"));
|
|
42
|
+
const nested = (0, import_tree.useFloatingParentNodeId)() != null;
|
|
43
|
+
const [positionReference, setPositionReference] = (0, import_octane.useState)(
|
|
44
|
+
elementsProp.reference,
|
|
45
|
+
(0, import_internal.subSlot)(slot, "posref")
|
|
46
|
+
);
|
|
47
|
+
const onOpenChange = (0, import_utils.useEffectEvent)(
|
|
48
|
+
(openVal, event, reason) => {
|
|
49
|
+
dataRef.current.openEvent = openVal ? event : void 0;
|
|
50
|
+
events.emit("openchange", { open: openVal, event, reason, nested });
|
|
51
|
+
onOpenChangeProp?.(openVal, event, reason);
|
|
52
|
+
},
|
|
53
|
+
(0, import_internal.subSlot)(slot, "ooc")
|
|
54
|
+
);
|
|
55
|
+
const refs = (0, import_octane.useMemo)(() => ({ setPositionReference }), [], (0, import_internal.subSlot)(slot, "m:refs"));
|
|
56
|
+
const elements = (0, import_octane.useMemo)(
|
|
57
|
+
() => ({
|
|
58
|
+
reference: positionReference || elementsProp.reference || null,
|
|
59
|
+
floating: elementsProp.floating || null,
|
|
60
|
+
domReference: elementsProp.reference
|
|
61
|
+
}),
|
|
62
|
+
[positionReference, elementsProp.reference, elementsProp.floating],
|
|
63
|
+
(0, import_internal.subSlot)(slot, "m:el")
|
|
64
|
+
);
|
|
65
|
+
return (0, import_octane.useMemo)(
|
|
66
|
+
() => ({ dataRef, open, onOpenChange, elements, events, floatingId, refs }),
|
|
67
|
+
[open, onOpenChange, elements, events, floatingId, refs],
|
|
68
|
+
(0, import_internal.subSlot)(slot, "m:ret")
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function useFloating(...args) {
|
|
72
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
73
|
+
const options = user[0] ?? {};
|
|
74
|
+
const nodeId = options.nodeId;
|
|
75
|
+
const internalRootContext = useFloatingRootContext(
|
|
76
|
+
{
|
|
77
|
+
...options,
|
|
78
|
+
elements: {
|
|
79
|
+
reference: null,
|
|
80
|
+
floating: null,
|
|
81
|
+
...options.elements
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
(0, import_internal.subSlot)(slot, "root")
|
|
85
|
+
);
|
|
86
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
87
|
+
const computedElements = rootContext.elements;
|
|
88
|
+
const [_domReference, setDomReference] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "domref"));
|
|
89
|
+
const [positionReference, _setPositionReference] = (0, import_octane.useState)(
|
|
90
|
+
null,
|
|
91
|
+
(0, import_internal.subSlot)(slot, "posref")
|
|
92
|
+
);
|
|
93
|
+
const optionDomReference = computedElements?.domReference;
|
|
94
|
+
const domReference = optionDomReference || _domReference;
|
|
95
|
+
const domReferenceRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "domrefref"));
|
|
96
|
+
const tree = (0, import_tree.useFloatingTree)();
|
|
97
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
98
|
+
() => {
|
|
99
|
+
if (domReference) {
|
|
100
|
+
domReferenceRef.current = domReference;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
[domReference],
|
|
104
|
+
(0, import_internal.subSlot)(slot, "e:domref")
|
|
105
|
+
);
|
|
106
|
+
const position = (0, import_useFloating.usePositionFloating)([
|
|
107
|
+
{
|
|
108
|
+
...options,
|
|
109
|
+
elements: {
|
|
110
|
+
...computedElements,
|
|
111
|
+
...positionReference ? { reference: positionReference } : {}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
(0, import_internal.subSlot)(slot, "pos")
|
|
115
|
+
]);
|
|
116
|
+
const setPositionReference = (0, import_octane.useCallback)(
|
|
117
|
+
(node) => {
|
|
118
|
+
const computedPositionReference = (0, import_dom.isElement)(node) ? {
|
|
119
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
120
|
+
getClientRects: () => node.getClientRects(),
|
|
121
|
+
contextElement: node
|
|
122
|
+
} : node;
|
|
123
|
+
_setPositionReference(computedPositionReference);
|
|
124
|
+
position.refs.setReference(computedPositionReference);
|
|
125
|
+
},
|
|
126
|
+
[position.refs],
|
|
127
|
+
(0, import_internal.subSlot)(slot, "spr")
|
|
128
|
+
);
|
|
129
|
+
const setReference = (0, import_octane.useCallback)(
|
|
130
|
+
(node) => {
|
|
131
|
+
if ((0, import_dom.isElement)(node) || node === null) {
|
|
132
|
+
domReferenceRef.current = node;
|
|
133
|
+
setDomReference(node);
|
|
134
|
+
}
|
|
135
|
+
if ((0, import_dom.isElement)(position.refs.reference.current) || position.refs.reference.current === null || node !== null && !(0, import_dom.isElement)(node)) {
|
|
136
|
+
position.refs.setReference(node);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
[position.refs],
|
|
140
|
+
(0, import_internal.subSlot)(slot, "sr")
|
|
141
|
+
);
|
|
142
|
+
const refs = (0, import_octane.useMemo)(
|
|
143
|
+
() => ({
|
|
144
|
+
...position.refs,
|
|
145
|
+
setReference,
|
|
146
|
+
setPositionReference,
|
|
147
|
+
domReference: domReferenceRef
|
|
148
|
+
}),
|
|
149
|
+
[position.refs, setReference, setPositionReference],
|
|
150
|
+
(0, import_internal.subSlot)(slot, "m:refs")
|
|
151
|
+
);
|
|
152
|
+
const elements = (0, import_octane.useMemo)(
|
|
153
|
+
() => ({ ...position.elements, domReference }),
|
|
154
|
+
[position.elements, domReference],
|
|
155
|
+
(0, import_internal.subSlot)(slot, "m:el")
|
|
156
|
+
);
|
|
157
|
+
const context = (0, import_octane.useMemo)(
|
|
158
|
+
() => ({ ...position, ...rootContext, refs, elements, nodeId }),
|
|
159
|
+
[position, refs, elements, nodeId, rootContext],
|
|
160
|
+
(0, import_internal.subSlot)(slot, "m:ctx")
|
|
161
|
+
);
|
|
162
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
163
|
+
() => {
|
|
164
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
165
|
+
const node = tree?.nodesRef.current.find((n) => n.id === nodeId);
|
|
166
|
+
if (node) {
|
|
167
|
+
node.context = context;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
void 0,
|
|
171
|
+
(0, import_internal.subSlot)(slot, "e:ctx")
|
|
172
|
+
);
|
|
173
|
+
return (0, import_octane.useMemo)(
|
|
174
|
+
() => ({ ...position, context, refs, elements }),
|
|
175
|
+
[position, refs, elements, context],
|
|
176
|
+
(0, import_internal.subSlot)(slot, "m:ret")
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
createPubSub,
|
|
182
|
+
useFloating,
|
|
183
|
+
useFloatingRootContext
|
|
184
|
+
});
|