@zealakit/overlay-react 1.0.0 → 1.1.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.
- package/README.md +1 -0
- package/dist/animation/presence.js +3 -2
- package/dist/components/arrow.js +2 -0
- package/dist/components/context-menu/content.js +1 -1
- package/dist/components/context-menu/context-menu.js +2 -12
- package/dist/components/context-menu/index.d.ts +4 -4
- package/dist/components/context-menu/index.js +2 -2
- package/dist/components/context-menu/items.js +3 -3
- package/dist/components/context-menu/menu-navigation.js +22 -6
- package/dist/components/context-menu/menu-surface.d.ts +4 -4
- package/dist/components/context-menu/menu-surface.js +10 -11
- package/dist/components/context-menu/sub.d.ts +1 -1
- package/dist/components/context-menu/sub.js +3 -13
- package/dist/components/context-menu/trigger.js +0 -1
- package/dist/components/dialog/content.d.ts +3 -3
- package/dist/components/dialog/content.js +13 -15
- package/dist/components/dialog/dialog.js +1 -1
- package/dist/components/dialog/helpers.js +1 -0
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/trigger.js +2 -0
- package/dist/components/popover/content.d.ts +24 -24
- package/dist/components/popover/content.js +13 -17
- package/dist/components/popover/helpers.js +1 -0
- package/dist/components/popover/index.d.ts +2 -2
- package/dist/components/popover/index.js +1 -1
- package/dist/components/popover/popover.js +3 -1
- package/dist/components/portal.d.ts +1 -1
- package/dist/components/slot.js +1 -4
- package/dist/components/tooltip/content.d.ts +2 -2
- package/dist/components/tooltip/content.js +1 -3
- package/dist/components/tooltip/index.d.ts +5 -5
- package/dist/components/tooltip/index.js +4 -4
- package/dist/components/tooltip/provider.js +2 -2
- package/dist/components/tooltip/tooltip.js +19 -28
- package/dist/hooks/use-layer.js +4 -4
- package/dist/hooks/use-overlay.js +4 -4
- package/dist/hooks/use-positioner.js +3 -12
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/vendor/core/animation/keyframes.d.ts +12 -3
- package/dist/vendor/core/animation/keyframes.js +63 -25
- package/dist/vendor/core/animation/run-animation.d.ts +1 -1
- package/dist/vendor/core/animation/run-animation.js +5 -10
- package/dist/vendor/core/controller/animator.js +2 -2
- package/dist/vendor/core/controller/context-menu-behavior.js +48 -37
- package/dist/vendor/core/controller/overlay-controller.d.ts +1 -1
- package/dist/vendor/core/controller/overlay-controller.js +52 -72
- package/dist/vendor/core/controller/tooltip-behavior.js +1 -3
- package/dist/vendor/core/controller/types.d.ts +15 -1
- package/dist/vendor/core/events/outside.d.ts +6 -3
- package/dist/vendor/core/events/outside.js +12 -25
- package/dist/vendor/core/events/pointer.d.ts +7 -7
- package/dist/vendor/core/events/pointer.js +7 -9
- package/dist/vendor/core/focus/focus.js +45 -105
- package/dist/vendor/core/layer/create-layer-stack.d.ts +14 -12
- package/dist/vendor/core/layer/create-layer-stack.js +114 -158
- package/dist/vendor/core/layer/create-layer.js +1 -2
- package/dist/vendor/core/layer/index.d.ts +1 -2
- package/dist/vendor/core/layer/index.js +1 -2
- package/dist/vendor/core/menu/index.d.ts +1 -1
- package/dist/vendor/core/menu/index.js +1 -1
- package/dist/vendor/core/menu/navigation.d.ts +0 -12
- package/dist/vendor/core/menu/navigation.js +0 -42
- package/dist/vendor/core/modal/background.js +13 -5
- package/dist/vendor/core/portal/index.d.ts +1 -1
- package/dist/vendor/core/portal/index.js +1 -1
- package/dist/vendor/core/positioning/compute.js +3 -3
- package/dist/vendor/core/positioning/coordinates.js +1 -1
- package/dist/vendor/core/positioning/create-positioner.d.ts +6 -3
- package/dist/vendor/core/positioning/create-positioner.js +86 -76
- package/dist/vendor/core/positioning/placement.js +1 -3
- package/dist/vendor/core/scroll-lock/scroll-lock.d.ts +8 -6
- package/dist/vendor/core/scroll-lock/scroll-lock.js +14 -60
- package/dist/vendor/core/types/animation.d.ts +10 -18
- package/dist/vendor/core/types/animation.js +3 -5
- package/dist/vendor/core/types/dismissal.d.ts +15 -2
- package/dist/vendor/core/types/geometry.d.ts +14 -5
- package/dist/vendor/core/types/layer.d.ts +2 -0
- package/dist/vendor/core/types/positioner.d.ts +8 -1
- package/dist/vendor/core/utils/global-state.js +6 -0
- package/package.json +4 -13
- package/dist/vendor/core/layer/manager.d.ts +0 -9
- package/dist/vendor/core/layer/manager.js +0 -157
|
@@ -1,207 +1,161 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isPointerOutside } from "../events/pointer.js";
|
|
3
|
-
import { listen } from "../lifecycle/events.js";
|
|
4
|
-
import { getGlobalState } from "../utils/global-state.js";
|
|
1
|
+
import { createLayer } from "@zealakit/ui-engine";
|
|
5
2
|
import { resolveElement } from "../utils/element.js";
|
|
6
|
-
import { createLayerManager } from "./manager.js";
|
|
7
3
|
/**
|
|
8
|
-
* Shared stack
|
|
4
|
+
* Shared layer stack backed by the engine's page-wide stack.
|
|
9
5
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* The engine owns ordering, Escape and outside-press dismissal; this wrapper
|
|
7
|
+
* keeps overlay's `LayerStack` vocabulary for the adapters: registration
|
|
8
|
+
* options map to `LayerOptions`, engine reasons map to overlay's
|
|
9
|
+
* `DismissReason`, and snapshots expose overlay handles.
|
|
10
|
+
*
|
|
11
|
+
* There are no document listeners here: the engine's listener hub owns them
|
|
12
|
+
* (§3 rule 5, P1/P2).
|
|
13
13
|
*/
|
|
14
|
-
export function createLayerStack(
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
let detach = null;
|
|
14
|
+
export function createLayerStack(_options = {}) {
|
|
15
|
+
const records = new Map();
|
|
16
|
+
const order = [];
|
|
17
|
+
const byHandle = new WeakMap();
|
|
18
|
+
const listeners = new Set();
|
|
20
19
|
let disposed = false;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return activeDocument;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (typeof document !== "undefined") {
|
|
33
|
-
activeDocument = document;
|
|
34
|
-
return activeDocument;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
};
|
|
38
|
-
const topLayer = () => {
|
|
39
|
-
const top = manager.getTopmost();
|
|
40
|
-
return top ? (layers.get(top.id) ?? null) : null;
|
|
41
|
-
};
|
|
42
|
-
const resolveBoundaries = (source) => {
|
|
43
|
-
if (!source) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(source)) {
|
|
47
|
-
return source;
|
|
48
|
-
}
|
|
49
|
-
return [source];
|
|
50
|
-
};
|
|
51
|
-
const handleKeyDown = (event) => {
|
|
52
|
-
if (event.defaultPrevented) {
|
|
53
|
-
return;
|
|
20
|
+
const toEntry = (record) => ({
|
|
21
|
+
id: record.handle.id,
|
|
22
|
+
parentId: record.parentId,
|
|
23
|
+
});
|
|
24
|
+
const notify = () => {
|
|
25
|
+
const snapshot = order.map(toEntry);
|
|
26
|
+
for (const listener of [...listeners]) {
|
|
27
|
+
listener(snapshot);
|
|
54
28
|
}
|
|
55
|
-
const top = topLayer();
|
|
56
|
-
if (!top?.dismissOnEscape || !isEscapeKey(event)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
top.onDismiss?.("escape-key");
|
|
60
|
-
};
|
|
61
|
-
const handlePointerDown = (event) => {
|
|
62
|
-
if (event.defaultPrevented) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const top = topLayer();
|
|
66
|
-
if (!top?.dismissOnOutsidePress) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const elements = [];
|
|
70
|
-
const sources = [top.element, top.reference, ...top.boundaries];
|
|
71
|
-
for (const source of sources) {
|
|
72
|
-
const element = resolveElement(source);
|
|
73
|
-
if (element && !elements.includes(element)) {
|
|
74
|
-
elements.push(element);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (elements.length === 0) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (isPointerOutside(event, elements)) {
|
|
81
|
-
top.onDismiss?.("outside-press");
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const detachListeners = () => {
|
|
85
|
-
detach?.();
|
|
86
|
-
detach = null;
|
|
87
|
-
};
|
|
88
|
-
const syncListeners = () => {
|
|
89
|
-
const needed = [...layers.values()].some((layer) => layer.dismissOnEscape || layer.dismissOnOutsidePress);
|
|
90
|
-
if (!needed) {
|
|
91
|
-
detachListeners();
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (detach) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const ownerDocument = resolveDocument();
|
|
98
|
-
if (!ownerDocument) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const offKeyDown = listen(ownerDocument, "keydown", handleKeyDown);
|
|
102
|
-
const offPointerDown = listen(ownerDocument, "pointerdown", handlePointerDown, true);
|
|
103
|
-
detach = () => {
|
|
104
|
-
offKeyDown();
|
|
105
|
-
offPointerDown();
|
|
106
|
-
};
|
|
107
29
|
};
|
|
108
30
|
const remove = (id) => {
|
|
109
|
-
|
|
31
|
+
const record = records.get(id);
|
|
32
|
+
if (disposed || record === undefined) {
|
|
110
33
|
return false;
|
|
111
34
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
35
|
+
records.delete(id);
|
|
36
|
+
byHandle.delete(record.handle);
|
|
37
|
+
const index = order.indexOf(record);
|
|
38
|
+
if (index !== -1) {
|
|
39
|
+
order.splice(index, 1);
|
|
40
|
+
}
|
|
41
|
+
// The engine re-parents surviving children to this layer's parent (D4);
|
|
42
|
+
// mirror that in the snapshots.
|
|
43
|
+
for (const child of order) {
|
|
44
|
+
if (child.parentId === id) {
|
|
45
|
+
child.parentId = record.parentId;
|
|
117
46
|
}
|
|
118
47
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
syncListeners();
|
|
125
|
-
return removed;
|
|
48
|
+
record.engine.release();
|
|
49
|
+
notify();
|
|
50
|
+
return true;
|
|
126
51
|
};
|
|
127
52
|
return {
|
|
128
53
|
get size() {
|
|
129
|
-
return
|
|
54
|
+
return records.size;
|
|
130
55
|
},
|
|
131
56
|
register(layerOptions = {}) {
|
|
132
57
|
if (disposed) {
|
|
133
58
|
throw new Error("[overlay-core] Layer stack is disposed.");
|
|
134
59
|
}
|
|
135
60
|
const parent = layerOptions.parent ?? null;
|
|
136
|
-
if (parent) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
61
|
+
if (parent !== null && !byHandle.has(parent)) {
|
|
62
|
+
// Page-global engine ids are unique, so a handle from another stack is
|
|
63
|
+
// reported as unknown rather than colliding on the old `layer-1` id.
|
|
64
|
+
throw new Error(`[overlay-core] Unknown parent layer: "${parent.id}".`);
|
|
65
|
+
}
|
|
66
|
+
const parentRecord = parent === null ? null : (byHandle.get(parent) ?? null);
|
|
67
|
+
const inside = [];
|
|
68
|
+
const reference = resolveElement(layerOptions.reference ?? null);
|
|
69
|
+
if (reference !== null) {
|
|
70
|
+
inside.push(reference);
|
|
71
|
+
}
|
|
72
|
+
for (const boundary of resolveBoundaries(layerOptions.boundaries)) {
|
|
73
|
+
const element = resolveElement(boundary);
|
|
74
|
+
if (element !== null) {
|
|
75
|
+
inside.push(element);
|
|
143
76
|
}
|
|
144
77
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
78
|
+
const engine = createLayer({
|
|
79
|
+
// Overlay works in `Element`; the engine's sources are `HTMLElement`.
|
|
80
|
+
element: (layerOptions.element ?? null),
|
|
81
|
+
inside,
|
|
82
|
+
parent: parentRecord?.engine ?? null,
|
|
83
|
+
modal: layerOptions.modal ?? false,
|
|
84
|
+
dismiss: {
|
|
85
|
+
escapeKey: layerOptions.dismissOnEscape ?? true,
|
|
86
|
+
outsidePress: layerOptions.dismissOnOutsidePress ?? true,
|
|
87
|
+
},
|
|
88
|
+
onDismiss: (reason) => {
|
|
89
|
+
layerOptions.onDismiss?.(reason);
|
|
90
|
+
},
|
|
150
91
|
});
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
reference: layerOptions.reference ?? null,
|
|
158
|
-
boundaries: resolveBoundaries(layerOptions.boundaries),
|
|
159
|
-
};
|
|
160
|
-
layers.set(layer.id, layer);
|
|
92
|
+
const id = layerOptions.id ?? engine.id;
|
|
93
|
+
if (records.has(id)) {
|
|
94
|
+
engine.release();
|
|
95
|
+
throw new Error(`[overlay-core] Duplicate layer id: "${id}".`);
|
|
96
|
+
}
|
|
97
|
+
const parentId = parentRecord?.handle.id ?? null;
|
|
161
98
|
const handle = {
|
|
162
|
-
id
|
|
163
|
-
parentId
|
|
99
|
+
id,
|
|
100
|
+
parentId,
|
|
164
101
|
get isRegistered() {
|
|
165
|
-
return
|
|
102
|
+
return records.has(id) && !disposed;
|
|
166
103
|
},
|
|
167
104
|
get isTopmost() {
|
|
168
|
-
return
|
|
105
|
+
return order[order.length - 1]?.handle.id === id;
|
|
169
106
|
},
|
|
170
107
|
dispose() {
|
|
171
|
-
remove(
|
|
108
|
+
remove(id);
|
|
172
109
|
},
|
|
173
110
|
};
|
|
174
|
-
|
|
175
|
-
|
|
111
|
+
const record = { handle, engine, parentId };
|
|
112
|
+
records.set(id, record);
|
|
113
|
+
byHandle.set(handle, record);
|
|
114
|
+
order.push(record);
|
|
115
|
+
notify();
|
|
176
116
|
return handle;
|
|
177
117
|
},
|
|
178
118
|
getTopmost() {
|
|
179
|
-
|
|
119
|
+
const top = order[order.length - 1];
|
|
120
|
+
return top === undefined ? null : toEntry(top);
|
|
180
121
|
},
|
|
181
122
|
isTopmost(id) {
|
|
182
|
-
return
|
|
123
|
+
return order[order.length - 1]?.handle.id === id;
|
|
183
124
|
},
|
|
184
125
|
subscribe(listener) {
|
|
185
|
-
|
|
126
|
+
listeners.add(listener);
|
|
127
|
+
return () => {
|
|
128
|
+
listeners.delete(listener);
|
|
129
|
+
};
|
|
186
130
|
},
|
|
187
131
|
dispose() {
|
|
188
132
|
if (disposed) {
|
|
189
133
|
return;
|
|
190
134
|
}
|
|
191
135
|
disposed = true;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
136
|
+
for (const record of [...order]) {
|
|
137
|
+
record.engine.release();
|
|
138
|
+
}
|
|
139
|
+
records.clear();
|
|
140
|
+
listeners.clear();
|
|
141
|
+
order.length = 0;
|
|
196
142
|
},
|
|
197
143
|
};
|
|
198
144
|
}
|
|
145
|
+
function resolveBoundaries(source) {
|
|
146
|
+
if (source === undefined) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(source)) {
|
|
150
|
+
return source;
|
|
151
|
+
}
|
|
152
|
+
return [source];
|
|
153
|
+
}
|
|
199
154
|
/**
|
|
200
|
-
*
|
|
155
|
+
* Per-document registry kept for the adapters' shared-stack contract.
|
|
201
156
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* when the last consumer unmounts.
|
|
157
|
+
* The engine already keeps one page-wide stack; this registry only shares the
|
|
158
|
+
* wrapper object so a React and a Vue overlay acquire the same `LayerStack`.
|
|
205
159
|
*/
|
|
206
160
|
export function createLayerStackRegistry() {
|
|
207
161
|
const stacks = new WeakMap();
|
|
@@ -234,13 +188,15 @@ export function createLayerStackRegistry() {
|
|
|
234
188
|
},
|
|
235
189
|
};
|
|
236
190
|
}
|
|
237
|
-
|
|
191
|
+
// X7: a module-local registry. Two bundled Core copies therefore get two
|
|
192
|
+
// wrapper objects, which is fine: ordering and dismissal live in the engine's
|
|
193
|
+
// page-wide stack, so every wrapper still sees the same layers in the same order.
|
|
194
|
+
const sharedLayerStackRegistry = createLayerStackRegistry();
|
|
238
195
|
/**
|
|
239
196
|
* Shared per-document layer stack used by all adapters by default.
|
|
240
197
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* listener pair and one ordering stack.
|
|
198
|
+
* Every adapter's wrapper talks to the same engine stack, so a React overlay
|
|
199
|
+
* and a Vue overlay on one page share ordering, Escape, and outside presses.
|
|
244
200
|
*/
|
|
245
201
|
export function acquireSharedLayerStack(documentRef) {
|
|
246
202
|
return sharedLayerStackRegistry.acquire(documentRef);
|
|
@@ -7,8 +7,7 @@ function resolveConfig(config) {
|
|
|
7
7
|
return {
|
|
8
8
|
defaultOpen: config.defaultOpen ?? DEFAULT_LAYER_CONFIG.defaultOpen,
|
|
9
9
|
dismissOnEscape: config.dismissOnEscape ?? DEFAULT_LAYER_CONFIG.dismissOnEscape,
|
|
10
|
-
dismissOnOutsidePress: config.dismissOnOutsidePress ??
|
|
11
|
-
DEFAULT_LAYER_CONFIG.dismissOnOutsidePress,
|
|
10
|
+
dismissOnOutsidePress: config.dismissOnOutsidePress ?? DEFAULT_LAYER_CONFIG.dismissOnOutsidePress,
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { createLayer, DEFAULT_LAYER_CONFIG, type CreateLayerOptions
|
|
2
|
-
export { createLayerManager } from "./manager.js";
|
|
1
|
+
export { createLayer, DEFAULT_LAYER_CONFIG, type CreateLayerOptions } from "./create-layer.js";
|
|
3
2
|
export { createLayerStack, createLayerStackRegistry, acquireSharedLayerStack, } from "./create-layer-stack.js";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { createLayer, DEFAULT_LAYER_CONFIG
|
|
2
|
-
export { createLayerManager } from "./manager.js";
|
|
1
|
+
export { createLayer, DEFAULT_LAYER_CONFIG } from "./create-layer.js";
|
|
3
2
|
export { createLayerStack, createLayerStackRegistry, acquireSharedLayerStack, } from "./create-layer-stack.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { focusFirstMenuItem, focusLastMenuItem, focusMenuItem, getMenuItems, moveMenuFocus, } from "./navigation.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { focusFirstMenuItem, focusLastMenuItem, focusMenuItem, getMenuItems, moveMenuFocus, } from "./navigation.js";
|
|
@@ -8,15 +8,3 @@ export declare function focusFirstMenuItem(container: HTMLElement): HTMLElement
|
|
|
8
8
|
export declare function focusLastMenuItem(container: HTMLElement): HTMLElement | null;
|
|
9
9
|
/** Move focus to the next/previous item, wrapping around. */
|
|
10
10
|
export declare function moveMenuFocus(container: HTMLElement, delta: 1 | -1): void;
|
|
11
|
-
/**
|
|
12
|
-
* Focus the next item (after `active`, wrapping) whose text starts with
|
|
13
|
-
* `buffer`, case-insensitively.
|
|
14
|
-
*/
|
|
15
|
-
export declare function focusMenuTypeahead(container: HTMLElement, buffer: string, active: Element | null): HTMLElement | null;
|
|
16
|
-
export type TypeaheadBuffer = {
|
|
17
|
-
/** Append a key and restart the reset timer; returns the current buffer. */
|
|
18
|
-
push(key: string): string;
|
|
19
|
-
clear(): void;
|
|
20
|
-
};
|
|
21
|
-
/** A character buffer that clears itself after `timeout` ms of inactivity. */
|
|
22
|
-
export declare function createTypeaheadBuffer(timeout?: number): TypeaheadBuffer;
|
|
@@ -63,45 +63,3 @@ export function moveMenuFocus(container, delta) {
|
|
|
63
63
|
: (index + delta + items.length) % items.length;
|
|
64
64
|
focusMenuItem(items[nextIndex] ?? null);
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Focus the next item (after `active`, wrapping) whose text starts with
|
|
68
|
-
* `buffer`, case-insensitively.
|
|
69
|
-
*/
|
|
70
|
-
export function focusMenuTypeahead(container, buffer, active) {
|
|
71
|
-
const items = getMenuItems(container);
|
|
72
|
-
const normalized = buffer.toLocaleLowerCase();
|
|
73
|
-
const currentIndex = active ? items.indexOf(active) : -1;
|
|
74
|
-
const ordered = [
|
|
75
|
-
...items.slice(currentIndex + 1),
|
|
76
|
-
...items.slice(0, currentIndex + 1),
|
|
77
|
-
];
|
|
78
|
-
const match = ordered.find((item) => (item.textContent ?? "")
|
|
79
|
-
.trim()
|
|
80
|
-
.toLocaleLowerCase()
|
|
81
|
-
.startsWith(normalized)) ?? null;
|
|
82
|
-
focusMenuItem(match);
|
|
83
|
-
return match;
|
|
84
|
-
}
|
|
85
|
-
/** A character buffer that clears itself after `timeout` ms of inactivity. */
|
|
86
|
-
export function createTypeaheadBuffer(timeout = 500) {
|
|
87
|
-
let value = "";
|
|
88
|
-
let timer = null;
|
|
89
|
-
const clear = () => {
|
|
90
|
-
if (timer !== null) {
|
|
91
|
-
clearTimeout(timer);
|
|
92
|
-
timer = null;
|
|
93
|
-
}
|
|
94
|
-
value = "";
|
|
95
|
-
};
|
|
96
|
-
return {
|
|
97
|
-
push(key) {
|
|
98
|
-
if (timer !== null) {
|
|
99
|
-
clearTimeout(timer);
|
|
100
|
-
}
|
|
101
|
-
value += key;
|
|
102
|
-
timer = setTimeout(clear, timeout);
|
|
103
|
-
return value;
|
|
104
|
-
},
|
|
105
|
-
clear,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { getGlobalState } from "../utils/global-state.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Created on first use, not at import: importing a package must not create
|
|
4
|
+
* page-global state (NQ11, the engine's own rule).
|
|
5
|
+
*/
|
|
6
|
+
let cachedStates;
|
|
7
|
+
function states() {
|
|
8
|
+
cachedStates ??= getGlobalState("modal-background", () => new WeakMap());
|
|
9
|
+
return cachedStates;
|
|
10
|
+
}
|
|
3
11
|
function topLevelBodyChild(root, body) {
|
|
4
12
|
let node = root;
|
|
5
13
|
while (node?.parentElement && node.parentElement !== body) {
|
|
@@ -80,10 +88,10 @@ function apply(state, documentRef) {
|
|
|
80
88
|
* each element's original `inert`/`aria-hidden` attributes.
|
|
81
89
|
*/
|
|
82
90
|
export function acquireModalBackground(documentRef, roots) {
|
|
83
|
-
let state = states.get(documentRef);
|
|
91
|
+
let state = states().get(documentRef);
|
|
84
92
|
if (!state) {
|
|
85
93
|
state = { entries: [], hidden: new Map() };
|
|
86
|
-
states.set(documentRef, state);
|
|
94
|
+
states().set(documentRef, state);
|
|
87
95
|
}
|
|
88
96
|
const entry = [...roots];
|
|
89
97
|
state.entries.push(entry);
|
|
@@ -94,7 +102,7 @@ export function acquireModalBackground(documentRef, roots) {
|
|
|
94
102
|
return;
|
|
95
103
|
}
|
|
96
104
|
released = true;
|
|
97
|
-
const current = states.get(documentRef);
|
|
105
|
+
const current = states().get(documentRef);
|
|
98
106
|
if (!current) {
|
|
99
107
|
return;
|
|
100
108
|
}
|
|
@@ -107,7 +115,7 @@ export function acquireModalBackground(documentRef, roots) {
|
|
|
107
115
|
restore(element, saved);
|
|
108
116
|
}
|
|
109
117
|
current.hidden.clear();
|
|
110
|
-
states.delete(documentRef);
|
|
118
|
+
states().delete(documentRef);
|
|
111
119
|
return;
|
|
112
120
|
}
|
|
113
121
|
apply(current, documentRef);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { moveToPortal, restorePortal, type PortalState
|
|
1
|
+
export { moveToPortal, restorePortal, type PortalState } from "./portal.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { moveToPortal, restorePortal
|
|
1
|
+
export { moveToPortal, restorePortal } from "./portal.js";
|
|
@@ -15,8 +15,8 @@ export function computePosition(reference, floating, options = {}) {
|
|
|
15
15
|
width: floatingRect.width,
|
|
16
16
|
height: floatingRect.height,
|
|
17
17
|
},
|
|
18
|
-
placement: options.placement,
|
|
19
|
-
offset: options.offset,
|
|
20
|
-
alignOffset: options.alignOffset,
|
|
18
|
+
...(options.placement === undefined ? {} : { placement: options.placement }),
|
|
19
|
+
...(options.offset === undefined ? {} : { offset: options.offset }),
|
|
20
|
+
...(options.alignOffset === undefined ? {} : { alignOffset: options.alignOffset }),
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -9,7 +9,7 @@ export const DEFAULT_OFFSET = 0;
|
|
|
9
9
|
* lives here.
|
|
10
10
|
*/
|
|
11
11
|
export function resolvePlacementCoordinates(input) {
|
|
12
|
-
const { reference, floating, offset = DEFAULT_OFFSET, alignOffset = DEFAULT_OFFSET
|
|
12
|
+
const { reference, floating, offset = DEFAULT_OFFSET, alignOffset = DEFAULT_OFFSET } = input;
|
|
13
13
|
const { placement, side, align } = parsePlacement(input.placement ?? DEFAULT_PLACEMENT);
|
|
14
14
|
let x = 0;
|
|
15
15
|
let y = 0;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { CreatePositionerOptions, Positioner } from "../types/positioner.js";
|
|
2
2
|
/**
|
|
3
|
-
* Create a collision-aware positioning session
|
|
3
|
+
* Create a collision-aware positioning session backed by
|
|
4
|
+
* `@zealakit/ui-engine/position`.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The engine owns the placement math, flip/shift, and auto-update. Core keeps
|
|
7
|
+
* the overlay-facing API, normalizes overlay placements (including `-center`
|
|
8
|
+
* aliases), resolves the CSS strategy, and computes the arrow offset from the
|
|
9
|
+
* engine's measured rects (the engine deliberately ships no arrow middleware).
|
|
7
10
|
*/
|
|
8
11
|
export declare function createPositioner(initial?: CreatePositionerOptions): Positioner;
|