@octanejs/floating-ui 0.1.47 → 0.1.48
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/utils/index.cjs +4 -40
- package/dist/cjs/utils/nodes.cjs +87 -0
- package/package.json +4 -4
- package/src/utils/index.ts +3 -49
- package/src/utils/nodes.ts +75 -0
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -32,7 +32,7 @@ __export(utils_exports, {
|
|
|
32
32
|
execWithArgsOrReturn: () => execWithArgsOrReturn,
|
|
33
33
|
findNonDisabledListIndex: () => findNonDisabledListIndex,
|
|
34
34
|
getDPR: () => getDPR,
|
|
35
|
-
getDeepestNode: () => getDeepestNode,
|
|
35
|
+
getDeepestNode: () => import_nodes.getDeepestNode,
|
|
36
36
|
getDelay: () => getDelay,
|
|
37
37
|
getDocument: () => getDocument,
|
|
38
38
|
getFloatingFocusElement: () => getFloatingFocusElement,
|
|
@@ -42,8 +42,8 @@ __export(utils_exports, {
|
|
|
42
42
|
getMaxListIndex: () => getMaxListIndex,
|
|
43
43
|
getMinListIndex: () => getMinListIndex,
|
|
44
44
|
getNextTabbable: () => getNextTabbable,
|
|
45
|
-
getNodeAncestors: () => getNodeAncestors,
|
|
46
|
-
getNodeChildren: () => getNodeChildren,
|
|
45
|
+
getNodeAncestors: () => import_nodes.getNodeAncestors,
|
|
46
|
+
getNodeChildren: () => import_nodes.getNodeChildren,
|
|
47
47
|
getPlatform: () => getPlatform,
|
|
48
48
|
getPreviousTabbable: () => getPreviousTabbable,
|
|
49
49
|
getTabbableOptions: () => getTabbableOptions,
|
|
@@ -80,6 +80,7 @@ var import_utils = require("@floating-ui/utils");
|
|
|
80
80
|
var import_tabbable = require("tabbable");
|
|
81
81
|
var import_octane = require("octane");
|
|
82
82
|
var import_internal = require("../internal.cjs");
|
|
83
|
+
var import_nodes = require("./nodes.cjs");
|
|
83
84
|
function getPlatform() {
|
|
84
85
|
const uaData = navigator.userAgentData;
|
|
85
86
|
if (uaData != null && uaData.platform) {
|
|
@@ -194,43 +195,6 @@ function getFloatingFocusElement(floatingElement) {
|
|
|
194
195
|
}
|
|
195
196
|
return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
|
|
196
197
|
}
|
|
197
|
-
function getNodeChildren(nodes, id, onlyOpenChildren = true) {
|
|
198
|
-
const directChildren = nodes.filter(
|
|
199
|
-
(node) => node.parentId === id && (!onlyOpenChildren || node.context?.open)
|
|
200
|
-
);
|
|
201
|
-
return directChildren.flatMap((child) => [
|
|
202
|
-
child,
|
|
203
|
-
...getNodeChildren(nodes, child.id, onlyOpenChildren)
|
|
204
|
-
]);
|
|
205
|
-
}
|
|
206
|
-
function getDeepestNode(nodes, id) {
|
|
207
|
-
let deepestNodeId;
|
|
208
|
-
let maxDepth = -1;
|
|
209
|
-
function findDeepest(nodeId, depth) {
|
|
210
|
-
if (depth > maxDepth) {
|
|
211
|
-
deepestNodeId = nodeId;
|
|
212
|
-
maxDepth = depth;
|
|
213
|
-
}
|
|
214
|
-
const children = getNodeChildren(nodes, nodeId);
|
|
215
|
-
children.forEach((child) => {
|
|
216
|
-
findDeepest(child.id, depth + 1);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
findDeepest(id, 0);
|
|
220
|
-
return nodes.find((node) => node.id === deepestNodeId);
|
|
221
|
-
}
|
|
222
|
-
function getNodeAncestors(nodes, id) {
|
|
223
|
-
let allAncestors = [];
|
|
224
|
-
let currentParentId = nodes.find((node) => node.id === id)?.parentId;
|
|
225
|
-
while (currentParentId) {
|
|
226
|
-
const currentNode = nodes.find((node) => node.id === currentParentId);
|
|
227
|
-
currentParentId = currentNode?.parentId;
|
|
228
|
-
if (currentNode) {
|
|
229
|
-
allAncestors = allAncestors.concat(currentNode);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return allAncestors;
|
|
233
|
-
}
|
|
234
198
|
function stopEvent(event) {
|
|
235
199
|
event.preventDefault();
|
|
236
200
|
event.stopPropagation();
|
|
@@ -0,0 +1,87 @@
|
|
|
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 nodes_exports = {};
|
|
20
|
+
__export(nodes_exports, {
|
|
21
|
+
getDeepestNode: () => getDeepestNode,
|
|
22
|
+
getNodeAncestors: () => getNodeAncestors,
|
|
23
|
+
getNodeChildren: () => getNodeChildren
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(nodes_exports);
|
|
26
|
+
function getNodeChildren(nodes, id, onlyOpenChildren = true) {
|
|
27
|
+
const directChildren = nodes.filter(
|
|
28
|
+
(node) => node.parentId === id && (!onlyOpenChildren || node.context?.open)
|
|
29
|
+
);
|
|
30
|
+
return directChildren.flatMap((child) => [
|
|
31
|
+
child,
|
|
32
|
+
...getNodeChildren(nodes, child.id, onlyOpenChildren)
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
function getDeepestNode(nodes, id) {
|
|
36
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const node of nodes) {
|
|
38
|
+
if (!node.context?.open) continue;
|
|
39
|
+
const siblings = childrenByParent.get(node.parentId);
|
|
40
|
+
if (siblings) {
|
|
41
|
+
siblings.push(node);
|
|
42
|
+
} else {
|
|
43
|
+
childrenByParent.set(node.parentId, [node]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let deepestNodeId = id;
|
|
47
|
+
let maxDepth = 0;
|
|
48
|
+
const stack = [];
|
|
49
|
+
const rootChildren = childrenByParent.get(id);
|
|
50
|
+
if (rootChildren) {
|
|
51
|
+
for (let index = rootChildren.length - 1; index >= 0; index--) {
|
|
52
|
+
stack.push([rootChildren[index], 1]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
while (stack.length) {
|
|
56
|
+
const [node, depth] = stack.pop();
|
|
57
|
+
if (depth > maxDepth) {
|
|
58
|
+
deepestNodeId = node.id;
|
|
59
|
+
maxDepth = depth;
|
|
60
|
+
}
|
|
61
|
+
const children = childrenByParent.get(node.id);
|
|
62
|
+
if (children) {
|
|
63
|
+
for (let index = children.length - 1; index >= 0; index--) {
|
|
64
|
+
stack.push([children[index], depth + 1]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return nodes.find((node) => node.id === deepestNodeId);
|
|
69
|
+
}
|
|
70
|
+
function getNodeAncestors(nodes, id) {
|
|
71
|
+
let allAncestors = [];
|
|
72
|
+
let currentParentId = nodes.find((node) => node.id === id)?.parentId;
|
|
73
|
+
while (currentParentId) {
|
|
74
|
+
const currentNode = nodes.find((node) => node.id === currentParentId);
|
|
75
|
+
currentParentId = currentNode?.parentId;
|
|
76
|
+
if (currentNode) {
|
|
77
|
+
allAncestors = allAncestors.concat(currentNode);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return allAncestors;
|
|
81
|
+
}
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
getDeepestNode,
|
|
85
|
+
getNodeAncestors,
|
|
86
|
+
getNodeChildren
|
|
87
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/floating-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"tabbable": "^6.5.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"octane": "0.1.
|
|
56
|
+
"octane": "0.1.49"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@radix-ui/react-checkbox": "1.0.4",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"vite": "^8.1.5",
|
|
81
81
|
"vitest": "3.0.9",
|
|
82
82
|
"vitest-browser-react": "0.1.1",
|
|
83
|
-
"@octanejs/testing-library": "0.1.
|
|
84
|
-
"octane": "0.1.
|
|
83
|
+
"@octanejs/testing-library": "0.1.46",
|
|
84
|
+
"octane": "0.1.49"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"build:cjs": "node ../../scripts/build-package-commonjs.mjs",
|
package/src/utils/index.ts
CHANGED
|
@@ -12,7 +12,9 @@ import type { Octane } from 'octane/jsx-runtime';
|
|
|
12
12
|
import type { Dimensions } from '@floating-ui/dom';
|
|
13
13
|
|
|
14
14
|
import { subSlot } from '../internal';
|
|
15
|
-
import type { Delay,
|
|
15
|
+
import type { Delay, MutableRefObject } from '../types';
|
|
16
|
+
|
|
17
|
+
export { getDeepestNode, getNodeAncestors, getNodeChildren } from './nodes';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* The OBJECT form of octane's `style` prop — the port's analog of
|
|
@@ -155,54 +157,6 @@ export function getFloatingFocusElement(
|
|
|
155
157
|
floatingElement;
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
export function getNodeChildren<RT extends ReferenceType = ReferenceType>(
|
|
159
|
-
nodes: Array<FloatingNodeType<RT>>,
|
|
160
|
-
id: string | undefined,
|
|
161
|
-
onlyOpenChildren = true,
|
|
162
|
-
): Array<FloatingNodeType<RT>> {
|
|
163
|
-
const directChildren = nodes.filter(
|
|
164
|
-
(node) => node.parentId === id && (!onlyOpenChildren || node.context?.open),
|
|
165
|
-
);
|
|
166
|
-
return directChildren.flatMap((child) => [
|
|
167
|
-
child,
|
|
168
|
-
...getNodeChildren(nodes, child.id, onlyOpenChildren),
|
|
169
|
-
]);
|
|
170
|
-
}
|
|
171
|
-
export function getDeepestNode<RT extends ReferenceType = ReferenceType>(
|
|
172
|
-
nodes: Array<FloatingNodeType<RT>>,
|
|
173
|
-
id: string | undefined,
|
|
174
|
-
): FloatingNodeType<RT> | undefined {
|
|
175
|
-
let deepestNodeId: string | undefined;
|
|
176
|
-
let maxDepth = -1;
|
|
177
|
-
function findDeepest(nodeId: string | undefined, depth: number) {
|
|
178
|
-
if (depth > maxDepth) {
|
|
179
|
-
deepestNodeId = nodeId;
|
|
180
|
-
maxDepth = depth;
|
|
181
|
-
}
|
|
182
|
-
const children = getNodeChildren(nodes, nodeId);
|
|
183
|
-
children.forEach((child) => {
|
|
184
|
-
findDeepest(child.id, depth + 1);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
findDeepest(id, 0);
|
|
188
|
-
return nodes.find((node) => node.id === deepestNodeId);
|
|
189
|
-
}
|
|
190
|
-
export function getNodeAncestors<RT extends ReferenceType = ReferenceType>(
|
|
191
|
-
nodes: Array<FloatingNodeType<RT>>,
|
|
192
|
-
id: string | undefined,
|
|
193
|
-
): Array<FloatingNodeType<RT>> {
|
|
194
|
-
let allAncestors: Array<FloatingNodeType<RT>> = [];
|
|
195
|
-
let currentParentId = nodes.find((node) => node.id === id)?.parentId;
|
|
196
|
-
while (currentParentId) {
|
|
197
|
-
const currentNode = nodes.find((node) => node.id === currentParentId);
|
|
198
|
-
currentParentId = currentNode?.parentId;
|
|
199
|
-
if (currentNode) {
|
|
200
|
-
allAncestors = allAncestors.concat(currentNode);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return allAncestors;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
160
|
export function stopEvent(event: Event): void {
|
|
207
161
|
event.preventDefault();
|
|
208
162
|
event.stopPropagation();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Ported from @floating-ui/react/utils/nodes. Kept separate from the DOM and
|
|
2
|
+
// hook helpers so tree algorithms can be exercised without a browser runtime.
|
|
3
|
+
import type { FloatingNodeType, ReferenceType } from '../types';
|
|
4
|
+
|
|
5
|
+
export function getNodeChildren<RT extends ReferenceType = ReferenceType>(
|
|
6
|
+
nodes: Array<FloatingNodeType<RT>>,
|
|
7
|
+
id: string | undefined,
|
|
8
|
+
onlyOpenChildren = true,
|
|
9
|
+
): Array<FloatingNodeType<RT>> {
|
|
10
|
+
const directChildren = nodes.filter(
|
|
11
|
+
(node) => node.parentId === id && (!onlyOpenChildren || node.context?.open),
|
|
12
|
+
);
|
|
13
|
+
return directChildren.flatMap((child) => [
|
|
14
|
+
child,
|
|
15
|
+
...getNodeChildren(nodes, child.id, onlyOpenChildren),
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getDeepestNode<RT extends ReferenceType = ReferenceType>(
|
|
20
|
+
nodes: Array<FloatingNodeType<RT>>,
|
|
21
|
+
id: string | undefined,
|
|
22
|
+
): FloatingNodeType<RT> | undefined {
|
|
23
|
+
const childrenByParent = new Map<string | null | undefined, Array<FloatingNodeType<RT>>>();
|
|
24
|
+
for (const node of nodes) {
|
|
25
|
+
if (!node.context?.open) continue;
|
|
26
|
+
const siblings = childrenByParent.get(node.parentId);
|
|
27
|
+
if (siblings) {
|
|
28
|
+
siblings.push(node);
|
|
29
|
+
} else {
|
|
30
|
+
childrenByParent.set(node.parentId, [node]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let deepestNodeId = id;
|
|
35
|
+
let maxDepth = 0;
|
|
36
|
+
const stack: Array<[FloatingNodeType<RT>, number]> = [];
|
|
37
|
+
const rootChildren = childrenByParent.get(id);
|
|
38
|
+
if (rootChildren) {
|
|
39
|
+
for (let index = rootChildren.length - 1; index >= 0; index--) {
|
|
40
|
+
stack.push([rootChildren[index], 1]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
while (stack.length) {
|
|
45
|
+
const [node, depth] = stack.pop()!;
|
|
46
|
+
if (depth > maxDepth) {
|
|
47
|
+
deepestNodeId = node.id;
|
|
48
|
+
maxDepth = depth;
|
|
49
|
+
}
|
|
50
|
+
const children = childrenByParent.get(node.id);
|
|
51
|
+
if (children) {
|
|
52
|
+
for (let index = children.length - 1; index >= 0; index--) {
|
|
53
|
+
stack.push([children[index], depth + 1]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return nodes.find((node) => node.id === deepestNodeId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getNodeAncestors<RT extends ReferenceType = ReferenceType>(
|
|
62
|
+
nodes: Array<FloatingNodeType<RT>>,
|
|
63
|
+
id: string | undefined,
|
|
64
|
+
): Array<FloatingNodeType<RT>> {
|
|
65
|
+
let allAncestors: Array<FloatingNodeType<RT>> = [];
|
|
66
|
+
let currentParentId = nodes.find((node) => node.id === id)?.parentId;
|
|
67
|
+
while (currentParentId) {
|
|
68
|
+
const currentNode = nodes.find((node) => node.id === currentParentId);
|
|
69
|
+
currentParentId = currentNode?.parentId;
|
|
70
|
+
if (currentNode) {
|
|
71
|
+
allAncestors = allAncestors.concat(currentNode);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return allAncestors;
|
|
75
|
+
}
|