v-float 0.7.2 → 0.9.0

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 (61) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +346 -327
  3. package/dist/composables/index.d.ts +1 -3
  4. package/dist/composables/index.d.ts.map +1 -1
  5. package/dist/composables/interactions/index.d.ts +2 -2
  6. package/dist/composables/interactions/index.d.ts.map +1 -1
  7. package/dist/composables/interactions/navigation-strategies.d.ts +36 -0
  8. package/dist/composables/interactions/navigation-strategies.d.ts.map +1 -0
  9. package/dist/composables/interactions/polygon.d.ts +2 -2
  10. package/dist/composables/interactions/polygon.d.ts.map +1 -1
  11. package/dist/composables/interactions/use-click.d.ts +2 -2
  12. package/dist/composables/interactions/use-click.d.ts.map +1 -1
  13. package/dist/composables/interactions/use-escape-key.d.ts +2 -2
  14. package/dist/composables/interactions/use-escape-key.d.ts.map +1 -1
  15. package/dist/composables/interactions/use-focus-trap.d.ts +41 -0
  16. package/dist/composables/interactions/use-focus-trap.d.ts.map +1 -0
  17. package/dist/composables/interactions/use-focus.d.ts +30 -25
  18. package/dist/composables/interactions/use-focus.d.ts.map +1 -1
  19. package/dist/composables/interactions/use-hover.d.ts +2 -2
  20. package/dist/composables/interactions/use-hover.d.ts.map +1 -1
  21. package/dist/composables/interactions/use-list-navigation.d.ts +109 -0
  22. package/dist/composables/interactions/use-list-navigation.d.ts.map +1 -0
  23. package/dist/composables/middlewares/arrow.d.ts +1 -2
  24. package/dist/composables/middlewares/arrow.d.ts.map +1 -1
  25. package/dist/composables/middlewares/index.d.ts +2 -1
  26. package/dist/composables/middlewares/index.d.ts.map +1 -1
  27. package/dist/composables/positioning/index.d.ts +5 -0
  28. package/dist/composables/positioning/index.d.ts.map +1 -0
  29. package/dist/composables/positioning/use-arrow.d.ts.map +1 -0
  30. package/dist/composables/{interactions → positioning}/use-client-point.d.ts +2 -2
  31. package/dist/composables/positioning/use-client-point.d.ts.map +1 -0
  32. package/dist/composables/{use-floating-tree.d.ts → positioning/use-floating-tree.d.ts} +134 -11
  33. package/dist/composables/positioning/use-floating-tree.d.ts.map +1 -0
  34. package/dist/composables/{use-floating.d.ts → positioning/use-floating.d.ts} +21 -6
  35. package/dist/composables/positioning/use-floating.d.ts.map +1 -0
  36. package/dist/composables/utils/is-using-keyboard.d.ts +2 -0
  37. package/dist/composables/utils/is-using-keyboard.d.ts.map +1 -0
  38. package/dist/composables/utils/use-active-descendant.d.ts +8 -0
  39. package/dist/composables/utils/use-active-descendant.d.ts.map +1 -0
  40. package/dist/types.d.ts +15 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils.d.ts +84 -7
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/v-float.es.js +2749 -1836
  45. package/dist/v-float.umd.js +4 -1
  46. package/package.json +74 -76
  47. package/dist/composables/interactions/use-client-point.d.ts.map +0 -1
  48. package/dist/composables/interactions/utils/browser-detection.d.ts +0 -23
  49. package/dist/composables/interactions/utils/browser-detection.d.ts.map +0 -1
  50. package/dist/composables/interactions/utils/element-detection.d.ts +0 -53
  51. package/dist/composables/interactions/utils/element-detection.d.ts.map +0 -1
  52. package/dist/composables/interactions/utils/event-utils.d.ts +0 -30
  53. package/dist/composables/interactions/utils/event-utils.d.ts.map +0 -1
  54. package/dist/composables/interactions/utils/index.d.ts +0 -11
  55. package/dist/composables/interactions/utils/index.d.ts.map +0 -1
  56. package/dist/composables/interactions/utils/tree-context.d.ts +0 -32
  57. package/dist/composables/interactions/utils/tree-context.d.ts.map +0 -1
  58. package/dist/composables/use-arrow.d.ts.map +0 -1
  59. package/dist/composables/use-floating-tree.d.ts.map +0 -1
  60. package/dist/composables/use-floating.d.ts.map +0 -1
  61. /package/dist/composables/{use-arrow.d.ts → positioning/use-arrow.d.ts} +0 -0
@@ -25,28 +25,120 @@ interface AddNodeOptions extends UseFloatingOptions {
25
25
  */
26
26
  parentId?: string;
27
27
  }
28
+ /**
29
+ * Represents a single node in a tree structure with hierarchical relationships.
30
+ *
31
+ * A TreeNode maintains references to its parent and children, allowing bidirectional
32
+ * traversal of the tree. Each node stores generic data and provides methods for
33
+ * tree navigation and manipulation.
34
+ *
35
+ * @template T The type of data stored in the node
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const node = createTreeNode({ name: 'Parent' });
40
+ * const childNode = createTreeNode({ name: 'Child' }, node);
41
+ * node.addChild(childNode);
42
+ * ```
43
+ */
28
44
  export interface TreeNode<T> {
45
+ /**
46
+ * Unique identifier for this node
47
+ */
29
48
  readonly id: string;
49
+ /**
50
+ * The data stored in this node
51
+ */
30
52
  readonly data: T;
53
+ /**
54
+ * Reference to the parent node, or null if this is the root
55
+ */
31
56
  readonly parent: Ref<TreeNode<T> | null>;
57
+ /**
58
+ * Array of child nodes
59
+ */
32
60
  readonly children: Ref<TreeNode<T>[]>;
61
+ /**
62
+ * Whether this node is the root of the tree
63
+ */
33
64
  readonly isRoot: boolean;
65
+ /**
66
+ * Computed property indicating whether this node has no children
67
+ */
34
68
  readonly isLeaf: Readonly<Ref<boolean>>;
69
+ /**
70
+ * Adds a child node to this node's children array
71
+ */
35
72
  addChild: (childNode: TreeNode<T>) => void;
73
+ /**
74
+ * Internal method to remove a child instance from this node
75
+ */
36
76
  _removeChildInstance: (childNode: TreeNode<T>) => boolean;
77
+ /**
78
+ * Finds the first immediate child matching the predicate
79
+ */
37
80
  findChild: (predicate: (node: TreeNode<T>) => boolean) => TreeNode<T> | null;
81
+ /**
82
+ * Recursively finds the first descendant matching the predicate
83
+ */
38
84
  findDescendant: (predicate: (node: TreeNode<T>) => boolean) => TreeNode<T> | null;
85
+ /**
86
+ * Checks if this node is a descendant of the given ancestor
87
+ */
39
88
  isDescendantOf: (potentialAncestor: TreeNode<T>) => boolean;
89
+ /**
90
+ * Returns the path from root to this node (inclusive)
91
+ */
40
92
  getPath: () => TreeNode<T>[];
41
93
  }
94
+ /**
95
+ * Core tree data structure for managing hierarchical node relationships.
96
+ *
97
+ * Provides methods for adding, removing, moving, and traversing nodes.
98
+ * Maintains a root node and a map of all nodes for efficient lookups.
99
+ * Supports both orphaning and recursive deletion strategies.
100
+ *
101
+ * @template T The type of data stored in tree nodes
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const tree = createTree<{ name: string }>();
106
+ * const child = tree.addNode({ name: 'Child' }, tree.root?.id);
107
+ * tree.traverse('dfs'); // Get all nodes in depth-first order
108
+ * ```
109
+ */
42
110
  export interface Tree<T> {
43
- readonly root: TreeNode<T>;
111
+ /**
112
+ * The root node of the tree, or null if empty
113
+ */
114
+ readonly root: TreeNode<T> | null;
115
+ /**
116
+ * Read-only map of all nodes indexed by their ID for O(1) lookups
117
+ */
44
118
  readonly nodeMap: Readonly<Map<string, TreeNode<T>>>;
119
+ /**
120
+ * Finds a node by its ID anywhere in the tree
121
+ */
45
122
  findNodeById: (id: string) => TreeNode<T> | null;
123
+ /**
124
+ * Adds a new node to the tree as a child of the specified parent
125
+ */
46
126
  addNode: (data: T, parentId?: string | null, nodeOptions?: CreateTreeNodeOptions) => TreeNode<T> | null;
127
+ /**
128
+ * Removes a node from the tree using the specified deletion strategy
129
+ */
47
130
  removeNode: (nodeId: string, deleteStrategy?: "orphan" | "recursive") => boolean;
131
+ /**
132
+ * Moves a node to become a child of a different parent
133
+ */
48
134
  moveNode: (nodeId: string, newParentId: string | null) => boolean;
135
+ /**
136
+ * Traverses the tree using DFS or BFS strategy, optionally starting from a specific node
137
+ */
49
138
  traverse: (strategy?: "dfs" | "bfs", startNode?: TreeNode<T> | null) => TreeNode<T>[];
139
+ /**
140
+ * Clears all nodes from the tree to allow garbage collection
141
+ */
50
142
  dispose: () => void;
51
143
  }
52
144
  /**
@@ -54,10 +146,40 @@ export interface Tree<T> {
54
146
  */
55
147
  export interface FloatingTreeOptions extends CreateTreeOptions {
56
148
  }
57
- export interface UseFloatingTreeReturn extends Omit<Tree<FloatingContext>, "addNode"> {
149
+ /**
150
+ * Return type for the useFloatingTree composable.
151
+ *
152
+ * Extends the base Tree interface with floating-specific methods for managing
153
+ * a hierarchical tree of floating UI elements. Each node wraps a FloatingContext
154
+ * and provides methods to query and manipulate open states across the tree.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * const tree = useFloatingTree();
159
+ * const childNode = tree.addNode(anchorEl, floatingEl, { parentId: tree.root?.id });
160
+ * const deepest = tree.getDeepestOpenNode();
161
+ * tree.applyToNodes(childNode.id, (node) => node.data.setOpen(false), {
162
+ * relationship: 'descendants-only'
163
+ * });
164
+ * ```
165
+ */
166
+ export interface UseFloatingTreeReturn extends Omit<Tree<FloatingContext>, "addNode" | "root"> {
167
+ /**
168
+ * The root node of the floating tree
169
+ */
170
+ root: TreeNode<FloatingContext> | null;
171
+ /**
172
+ * Adds a new floating element node to the tree with the specified anchor and floating elements
173
+ */
58
174
  addNode: (anchorEl: Ref<AnchorElement>, floatingEl: Ref<FloatingElement>, options?: AddNodeOptions) => TreeNode<FloatingContext> | null;
175
+ /**
176
+ * Returns an array of all nodes that are currently open
177
+ */
59
178
  getAllOpenNodes: () => TreeNode<FloatingContext>[];
60
- getTopmostOpenNode: () => TreeNode<FloatingContext> | null;
179
+ /**
180
+ * Returns the deepest (most nested) open node in the tree, or null if none are open
181
+ */
182
+ getDeepestOpenNode: () => TreeNode<FloatingContext> | null;
61
183
  /**
62
184
  * Executes a provided function once for each tree node that matches the specified relationship.
63
185
  * This is a flexible iteration method that can target nodes based on their relationship to a target node.
@@ -78,13 +200,15 @@ type NodeRelationship = "ancestors-only" | "siblings-only" | "descendants-only"
78
200
  /**
79
201
  * Creates and manages a hierarchical tree of floating elements.
80
202
  *
81
- * @param anchorEl - The anchor element for the root floating context
82
- * @param floatingEl - The floating element for the root floating context
83
- * @param options - Options for the root floating context
203
+ * Each node in the tree is assigned a stable ID. For non-root nodes, `addNode` generates
204
+ * the ID and injects it into the created FloatingContext (passed to `useFloating`).
205
+ * Consumers should not provide a custom `id` in `UseFloatingOptions` when using `addNode`;
206
+ * it will be ignored in favor of the generated one.
207
+ *
84
208
  * @param treeOptions - Options for tree behavior
85
209
  * @returns UseFloatingTreeReturn with tree management methods and root context
86
210
  */
87
- export declare function useFloatingTree(anchorEl: Ref<AnchorElement>, floatingEl: Ref<FloatingElement>, options?: UseFloatingOptions, treeOptions?: FloatingTreeOptions): UseFloatingTreeReturn;
211
+ export declare function useFloatingTree(treeOptions?: FloatingTreeOptions): UseFloatingTreeReturn;
88
212
  /**
89
213
  * Creates a reactive tree node with data, parent reference, and children references.
90
214
  * @param data The data to store in the node
@@ -102,16 +226,15 @@ export declare function createTreeNode<T>(data: T, parent?: TreeNode<T> | null,
102
226
  * traversal and search functionality.
103
227
  *
104
228
  * @template T The type of data stored in the tree nodes.
105
- * @param initialRootData Data for the root node.
106
229
  * @param options Configuration options for the tree behavior.
107
230
  * @returns A tree management object with methods and reactive properties
108
231
  *
109
232
  * @example
110
233
  * ```ts
111
- * const myTree = createTree({ name: 'Root' });
112
- * const childNode = myTree.addNode({ name: 'Child' }, myTree.root.id);
234
+ * const myTree = createTree<{ name: string }>();
235
+ * const childNode = myTree.addNode({ name: 'Child' }, myTree.root?.id);
113
236
  * ```
114
237
  */
115
- export declare function createTree<T>(initialRootData: T, options?: CreateTreeOptions): Tree<T>;
238
+ export declare function createTree<T>(options?: CreateTreeOptions): Tree<T>;
116
239
  export {};
117
240
  //# sourceMappingURL=use-floating-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-floating-tree.d.ts","sourceRoot":"","sources":["../../../src/composables/positioning/use-floating-tree.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EACnB,MAAM,gBAAgB,CAAA;AAOvB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,MA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,EACnC,MAAM,UAAQ,GACb,QAAQ,CAAC,CAAC,CAAC,CAiEb;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,CAmPlE"}
@@ -1,5 +1,6 @@
1
- import { AutoUpdateOptions, Middleware, MiddlewareData, Placement, Strategy, VirtualElement } from '@floating-ui/dom';
1
+ import { AutoUpdateOptions, Middleware, MiddlewareData, Placement, Strategy } from '@floating-ui/dom';
2
2
  import { MaybeRefOrGetter, Ref } from 'vue';
3
+ import { OpenChangeReason, VirtualElement } from '../../types';
3
4
  /**
4
5
  * Type for anchor element in floating UI
5
6
  */
@@ -39,6 +40,12 @@ export type FloatingStyles = {
39
40
  * Options for configuring floating element behavior
40
41
  */
41
42
  export interface UseFloatingOptions {
43
+ /**
44
+ * Optional stable identifier for this floating context.
45
+ * Only relevant for tree-aware behavior and typically generated by `useFloatingTree().addNode(...)`.
46
+ * Standalone usage should omit this.
47
+ */
48
+ id?: string;
42
49
  /**
43
50
  * Where to place the floating element relative to its anchor element.
44
51
  * @default 'bottom'
@@ -60,20 +67,28 @@ export interface UseFloatingOptions {
60
67
  middlewares?: MaybeRefOrGetter<Middleware[]>;
61
68
  /**
62
69
  * Whether to automatically update the position of the floating element.
63
- * Can be a boolean or an `AutoUpdateOptions` object.
64
70
  * @default true
65
71
  */
66
72
  autoUpdate?: boolean | AutoUpdateOptions;
67
73
  /**
68
- * Whether the floating element is open.
69
- * @default false
70
- */
74
+ * Whether the floating element is open.
75
+ * @default false
76
+ */
71
77
  open?: Ref<boolean>;
78
+ /**
79
+ * Callback invoked whenever the open state changes via setOpen.
80
+ * Provides the new state, the reason, and the triggering DOM event (if any).
81
+ */
82
+ onOpenChange?: (open: boolean, reason: OpenChangeReason, event?: Event) => void;
72
83
  }
73
84
  /**
74
85
  * Context object returned by useFloating containing all necessary data and methods
75
86
  */
76
87
  export interface FloatingContext {
88
+ /**
89
+ * Stable identifier for this floating context. Used for tree-aware interactions.
90
+ */
91
+ id?: string;
77
92
  /**
78
93
  * The x-coordinate of the floating element
79
94
  */
@@ -121,7 +136,7 @@ export interface FloatingContext {
121
136
  /**
122
137
  * Function to explicitly set the open state of the floating element.
123
138
  */
124
- setOpen: (open: boolean) => void;
139
+ setOpen: (open: boolean, reason?: OpenChangeReason, event?: Event) => void;
125
140
  }
126
141
  /**
127
142
  * Composable function that provides positioning for a floating element relative to an anchor element
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-floating.d.ts","sourceRoot":"","sources":["../../../src/composables/positioning/use-floating.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,SAAS,EACT,QAAQ,EACT,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO/D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,cAAc,GAAG,IAAI,CAAA;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,IAAI,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAElB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,GAAG;IAGF,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,GAAG,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,EAAE,CAAC,EA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CAAC,cAAc,CAAC,CAAC,CAAA;IAE7C;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAA;IAElB;;OAEG;IACH,IAAI,EAAE;QACJ,QAAQ,EAAE,GAAG,CAAC,aAAa,CAAC,CAAA;QAC5B,UAAU,EAAE,GAAG,CAAC,eAAe,CAAC,CAAA;QAChC,OAAO,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;KACjC,CAAA;IAED;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAE5B;;OAEG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAA;CAC3E;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,GAAG,CAAC,aAAa,CAAC,EAC5B,UAAU,EAAE,GAAG,CAAC,eAAe,CAAC,EAChC,OAAO,GAAE,kBAAuB,GAC/B,eAAe,CAmKjB"}
@@ -0,0 +1,2 @@
1
+ export declare const isUsingKeyboard: Readonly<import('vue').Ref<boolean, boolean>>;
2
+ //# sourceMappingURL=is-using-keyboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-using-keyboard.d.ts","sourceRoot":"","sources":["../../../src/composables/utils/is-using-keyboard.ts"],"names":[],"mappings":"AAkCA,eAAO,MAAM,eAAe,+CAAuB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ export interface UseActiveDescendantOptions {
3
+ virtual: MaybeRefOrGetter<boolean>;
4
+ open: Ref<boolean>;
5
+ virtualItemRef?: Ref<HTMLElement | null>;
6
+ }
7
+ export declare function useActiveDescendant(anchorEl: ComputedRef<HTMLElement | null>, listRef: Ref<Array<HTMLElement | null>>, activeIndex: MaybeRefOrGetter<number | null>, options: UseActiveDescendantOptions): void;
8
+ //# sourceMappingURL=use-active-descendant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-active-descendant.d.ts","sourceRoot":"","sources":["../../../src/composables/utils/use-active-descendant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,GAAG,EAAkB,MAAM,KAAK,CAAA;AAEjG,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAClC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAClB,cAAc,CAAC,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;CACzC;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,EACvC,WAAW,EAAE,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,EAC5C,OAAO,EAAE,0BAA0B,GAClC,IAAI,CAmBN"}
package/dist/types.d.ts CHANGED
@@ -1,3 +1,18 @@
1
1
  export type AnyFn<T extends unknown[] = unknown[], U = unknown> = (...args: T) => U;
2
2
  export type Fn = () => void;
3
+ /**
4
+ * Minimal VirtualElement interface compatible with Floating UI expectations.
5
+ * Provides a bounding client rect and an optional context element for layout.
6
+ */
7
+ export interface VirtualElement {
8
+ getBoundingClientRect: () => DOMRect;
9
+ /**
10
+ * Optional context element used by Floating UI to resolve layout metrics.
11
+ */
12
+ contextElement?: Element;
13
+ }
14
+ /**
15
+ * Primary interaction reasons for open state changes. Minimal and extensible.
16
+ */
17
+ export type OpenChangeReason = "anchor-click" | "keyboard-activate" | "outside-pointer" | "focus" | "blur" | "hover" | "escape-key" | "tree-ancestor-close" | "programmatic";
3
18
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAA;AACnF,MAAM,MAAM,EAAE,GAAG,MAAM,IAAI,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAA;AACnF,MAAM,MAAM,EAAE,GAAG,MAAM,IAAI,CAAA;AAE3B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB,EAAE,MAAM,OAAO,CAAA;IACpC;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,mBAAmB,GACnB,iBAAiB,GACjB,OAAO,GACP,MAAM,GACN,OAAO,GACP,YAAY,GACZ,qBAAqB,GACrB,cAAc,CAAA"}
package/dist/utils.d.ts CHANGED
@@ -1,15 +1,92 @@
1
- import { AnyFn } from './types';
1
+ import { AnyFn, VirtualElement } from './types';
2
+ import { FloatingContext } from './composables/positioning/use-floating';
3
+ import { TreeNode } from './composables/positioning/use-floating-tree';
2
4
  /**
3
- * Generates a unique ID.
4
- * The ID is incremented with each call.
5
- * @returns A unique string ID.
5
+ * Wrapper around Vue's useId that provides a fallback counter-based ID generator.
6
+ * This ensures unique IDs even when useId() returns empty strings (e.g., in test environments).
6
7
  */
7
8
  export declare function useId(): string;
8
9
  /**
9
10
  * Checks if a value is a function
10
- * @param value - The value to check
11
- * @returns True if the value is a function, false otherwise
12
11
  */
13
12
  export declare function isFunction(value: unknown): value is AnyFn;
14
- export declare function isHTMLElement(value: unknown): value is HTMLElement;
13
+ /**
14
+ * Type guard for HTMLElement
15
+ */
16
+ export declare function isHTMLElement(value: unknown | null): value is HTMLElement;
17
+ /**
18
+ * Checks if the user agent is on a Mac.
19
+ */
20
+ export declare function isMac(): boolean;
21
+ /**
22
+ * Checks if the browser is Safari.
23
+ */
24
+ export declare function isSafari(): boolean;
25
+ /**
26
+ * A simple utility to check if an element matches `:focus-visible`.
27
+ */
28
+ export declare function matchesFocusVisible(element: Element): boolean;
29
+ /**
30
+ * Checks if the pointer type is mouse-like (mouse or pen).
31
+ */
32
+ export declare function isMouseLikePointerType(pointerType: string | undefined, strict?: boolean): boolean;
33
+ /**
34
+ * Checks if the element is an input, textarea, or contenteditable element.
35
+ */
36
+ export declare function isTypeableElement(element: Element | null): boolean;
37
+ /**
38
+ * Checks if the event target is a button-like element.
39
+ */
40
+ export declare function isButtonTarget(event: KeyboardEvent): boolean;
41
+ /**
42
+ * Checks if the Space key press should be ignored for the given element.
43
+ */
44
+ export declare function isSpaceIgnored(element: Element | null): boolean;
45
+ /**
46
+ * Checks if the value is a VirtualElement.
47
+ */
48
+ export declare function isVirtualElement(el: unknown): el is VirtualElement;
49
+ /**
50
+ * Checks if the event target is within the given element.
51
+ */
52
+ export declare function isEventTargetWithin(event: Event, element: Element | null | undefined): boolean;
53
+ /**
54
+ * Checks if a click event occurred on a scrollbar.
55
+ */
56
+ export declare function isClickOnScrollbar(event: MouseEvent, target: HTMLElement): boolean;
57
+ /**
58
+ * Simple element containment wrapper.
59
+ */
60
+ export declare function contains(el: HTMLElement, target: Element | null): boolean;
61
+ /**
62
+ * Event target extraction utility.
63
+ */
64
+ export declare function getTarget(event: MouseEvent | TouchEvent): Element | null;
65
+ /**
66
+ * Safe performance timing that handles environments without performance API.
67
+ */
68
+ export declare function getCurrentTime(): number;
69
+ /**
70
+ * Centralized timeout management to prevent memory leaks.
71
+ */
72
+ export declare function clearTimeoutIfSet(timeoutId: number): void;
73
+ /**
74
+ * Type guard to determine if the context parameter is a TreeNode.
75
+ */
76
+ export declare function isTreeNode(context: FloatingContext | TreeNode<FloatingContext>): context is TreeNode<FloatingContext>;
77
+ /**
78
+ * Extracts floating context and tree context from the parameter.
79
+ */
80
+ export declare function getContextFromParameter(context: FloatingContext | TreeNode<FloatingContext>): {
81
+ floatingContext: FloatingContext;
82
+ treeContext: TreeNode<FloatingContext> | null;
83
+ };
84
+ /**
85
+ * Checks if a target node is within an anchor or floating element, handling VirtualElement.
86
+ */
87
+ export declare function isTargetWithinElement(target: Node, element: unknown): boolean;
88
+ /**
89
+ * Finds a descendant node that contains the target element.
90
+ */
91
+ export declare function findDescendantContainingTarget(node: TreeNode<FloatingContext>, target: Node): TreeNode<FloatingContext> | null;
15
92
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC;;;;GAIG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAEzD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAKpC;;;GAGG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAI9B;AAED,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAA;AAM3E;;G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