@ailuracode/alpine-menu 0.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/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/global.d.ts +49 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +290 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) ailuracode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @ailuracode/alpine-menu
|
|
2
|
+
|
|
3
|
+
Headless accessible menu store for Alpine.js — dropdowns, context menus, keyboard navigation, and roving tabindex. No markup or CSS included.
|
|
4
|
+
|
|
5
|
+
**[Full documentation →](../../docs/plugins/menu.md)**
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ailuracode/alpine-menu alpinejs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
Alpine.plugin(
|
|
17
|
+
menu({
|
|
18
|
+
onLockChange(locked) {
|
|
19
|
+
// compose with $store.scroll.lock() / unlock()
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Store API
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
$store.menu.open("user-menu");
|
|
29
|
+
$store.menu.close("user-menu");
|
|
30
|
+
$store.menu.toggle("user-menu");
|
|
31
|
+
$store.menu.isOpen("user-menu");
|
|
32
|
+
$store.menu.activeItem("user-menu");
|
|
33
|
+
```
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="@types/alpinejs" />
|
|
2
|
+
|
|
3
|
+
export type MenuOrientation = "horizontal" | "vertical";
|
|
4
|
+
|
|
5
|
+
export interface MenuStore {
|
|
6
|
+
instances: Record<string, import("./store.js").MenuInstance>;
|
|
7
|
+
open(id: string): void;
|
|
8
|
+
close(id: string): void;
|
|
9
|
+
toggle(id: string): void;
|
|
10
|
+
isOpen(id: string): boolean;
|
|
11
|
+
activeItem(id: string): string | null;
|
|
12
|
+
register(id: string, options?: import("./store.js").MenuInstanceOptions): void;
|
|
13
|
+
unregister(id: string): void;
|
|
14
|
+
registerItem(
|
|
15
|
+
menuId: string,
|
|
16
|
+
itemId: string,
|
|
17
|
+
options?: import("./store.js").MenuItemOptions
|
|
18
|
+
): void;
|
|
19
|
+
unregisterItem(menuId: string, itemId: string): void;
|
|
20
|
+
bindMenu(menuId: string, container: HTMLElement | null): void;
|
|
21
|
+
bindTrigger(menuId: string, trigger: HTMLElement | null): void;
|
|
22
|
+
handleOutsideClick(menuId: string, event: MouseEvent): void;
|
|
23
|
+
setActiveItem(menuId: string, itemId: string | null): void;
|
|
24
|
+
selectItem(menuId: string, itemId: string): void;
|
|
25
|
+
handleKeydown(menuId: string, event: KeyboardEvent): void;
|
|
26
|
+
itemProps(menuId: string, itemId: string): Record<string, string | number | boolean | undefined>;
|
|
27
|
+
menuProps(menuId: string): Record<string, string | boolean | undefined>;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MenuPluginOptions {
|
|
32
|
+
onLockChange?: (locked: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function menuOptions<const T extends MenuPluginOptions>(options: T): T;
|
|
36
|
+
export function createMenuStore(config?: { onLockChange?: (locked: boolean) => void }): MenuStore;
|
|
37
|
+
|
|
38
|
+
export default function menuPlugin(options?: MenuPluginOptions): import("alpinejs").PluginCallback;
|
|
39
|
+
|
|
40
|
+
declare global {
|
|
41
|
+
namespace Alpine {
|
|
42
|
+
interface Stores {
|
|
43
|
+
menu: MenuStore;
|
|
44
|
+
}
|
|
45
|
+
interface Magics<T> {
|
|
46
|
+
$menu: MenuStore;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import AlpineType from 'alpinejs';
|
|
2
|
+
|
|
3
|
+
type MenuOrientation = "vertical" | "horizontal";
|
|
4
|
+
type MenuItemState = {
|
|
5
|
+
id: string;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
parentId: string | null;
|
|
8
|
+
};
|
|
9
|
+
type MenuInstance = {
|
|
10
|
+
open: boolean;
|
|
11
|
+
activeItemId: string | null;
|
|
12
|
+
orientation: MenuOrientation;
|
|
13
|
+
closeOnSelect: boolean;
|
|
14
|
+
items: MenuItemState[];
|
|
15
|
+
container: HTMLElement | null;
|
|
16
|
+
trigger: HTMLElement | null;
|
|
17
|
+
onOpen?: () => void;
|
|
18
|
+
onClose?: () => void;
|
|
19
|
+
onSelect?: (itemId: string) => void;
|
|
20
|
+
};
|
|
21
|
+
type MenuItemOptions = {
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
parentId?: string | null;
|
|
24
|
+
};
|
|
25
|
+
type MenuInstanceOptions = {
|
|
26
|
+
orientation?: MenuOrientation;
|
|
27
|
+
closeOnSelect?: boolean;
|
|
28
|
+
onOpen?: () => void;
|
|
29
|
+
onClose?: () => void;
|
|
30
|
+
onSelect?: (itemId: string) => void;
|
|
31
|
+
};
|
|
32
|
+
type MenuStore = {
|
|
33
|
+
/** Reactive registry of menu instances. */
|
|
34
|
+
instances: Record<string, MenuInstance>;
|
|
35
|
+
open(id: string): void;
|
|
36
|
+
close(id: string): void;
|
|
37
|
+
toggle(id: string): void;
|
|
38
|
+
isOpen(id: string): boolean;
|
|
39
|
+
activeItem(id: string): string | null;
|
|
40
|
+
register(id: string, options?: MenuInstanceOptions): void;
|
|
41
|
+
unregister(id: string): void;
|
|
42
|
+
registerItem(menuId: string, itemId: string, options?: MenuItemOptions): void;
|
|
43
|
+
unregisterItem(menuId: string, itemId: string): void;
|
|
44
|
+
bindMenu(menuId: string, container: HTMLElement | null): void;
|
|
45
|
+
bindTrigger(menuId: string, trigger: HTMLElement | null): void;
|
|
46
|
+
handleOutsideClick(menuId: string, event: MouseEvent): void;
|
|
47
|
+
setActiveItem(menuId: string, itemId: string | null): void;
|
|
48
|
+
selectItem(menuId: string, itemId: string): void;
|
|
49
|
+
handleKeydown(menuId: string, event: KeyboardEvent): void;
|
|
50
|
+
itemProps(menuId: string, itemId: string): Record<string, string | number | boolean | undefined>;
|
|
51
|
+
menuProps(menuId: string): Record<string, string | boolean | undefined>;
|
|
52
|
+
destroy(): void;
|
|
53
|
+
};
|
|
54
|
+
type MenuStoreConfig = {
|
|
55
|
+
onLockChange?: (locked: boolean) => void;
|
|
56
|
+
};
|
|
57
|
+
/** Creates the headless menu store. */
|
|
58
|
+
declare function createMenuStore(config?: MenuStoreConfig): MenuStore;
|
|
59
|
+
|
|
60
|
+
interface MenuPluginOptions {
|
|
61
|
+
onLockChange?: (locked: boolean) => void;
|
|
62
|
+
}
|
|
63
|
+
/** Builds typed menu plugin options. */
|
|
64
|
+
declare function menuOptions<const T extends MenuPluginOptions>(options: T): T;
|
|
65
|
+
/** Alpine.js menu plugin. Registers `$store.menu`. */
|
|
66
|
+
declare function menuPlugin(options?: MenuPluginOptions): AlpineType.PluginCallback;
|
|
67
|
+
declare global {
|
|
68
|
+
namespace Alpine {
|
|
69
|
+
interface Stores {
|
|
70
|
+
menu: MenuStore;
|
|
71
|
+
}
|
|
72
|
+
interface Magics<T> {
|
|
73
|
+
$menu: MenuStore;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type MenuInstanceOptions, type MenuItemOptions, type MenuOrientation, type MenuPluginOptions, type MenuStore, createMenuStore, menuPlugin as default, menuOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// src/store.ts
|
|
2
|
+
function enabledItems(instance) {
|
|
3
|
+
return instance.items.filter((item) => !item.disabled);
|
|
4
|
+
}
|
|
5
|
+
function itemIndex(instance, itemId) {
|
|
6
|
+
return enabledItems(instance).findIndex((item) => item.id === itemId);
|
|
7
|
+
}
|
|
8
|
+
function moveActive(instance, delta) {
|
|
9
|
+
const items = enabledItems(instance);
|
|
10
|
+
if (items.length === 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const currentIndex = instance.activeItemId ? itemIndex(instance, instance.activeItemId) : -1;
|
|
14
|
+
const nextIndex = (currentIndex + delta + items.length) % items.length;
|
|
15
|
+
return items[nextIndex]?.id ?? null;
|
|
16
|
+
}
|
|
17
|
+
function firstItem(instance) {
|
|
18
|
+
return enabledItems(instance)[0]?.id ?? null;
|
|
19
|
+
}
|
|
20
|
+
function lastItem(instance) {
|
|
21
|
+
const items = enabledItems(instance);
|
|
22
|
+
return items[items.length - 1]?.id ?? null;
|
|
23
|
+
}
|
|
24
|
+
function createInstance(options = {}) {
|
|
25
|
+
return {
|
|
26
|
+
open: false,
|
|
27
|
+
activeItemId: null,
|
|
28
|
+
orientation: options.orientation ?? "vertical",
|
|
29
|
+
closeOnSelect: options.closeOnSelect ?? true,
|
|
30
|
+
items: [],
|
|
31
|
+
container: null,
|
|
32
|
+
trigger: null,
|
|
33
|
+
onOpen: options.onOpen,
|
|
34
|
+
onClose: options.onClose,
|
|
35
|
+
onSelect: options.onSelect
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function focusActiveItem(container) {
|
|
39
|
+
if (!container) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const active = container.querySelector('[role="menuitem"][tabindex="0"]');
|
|
43
|
+
active?.focus();
|
|
44
|
+
}
|
|
45
|
+
function focusActiveMenu(instance) {
|
|
46
|
+
focusActiveItem(instance.container);
|
|
47
|
+
}
|
|
48
|
+
function handleMenuKeydown(menuId, instance, event, selectItem, close) {
|
|
49
|
+
const vertical = instance.orientation === "vertical";
|
|
50
|
+
const horizontal = instance.orientation === "horizontal";
|
|
51
|
+
if (event.key === "ArrowDown" && vertical) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
instance.activeItemId = moveActive(instance, 1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (event.key === "ArrowUp" && vertical) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
instance.activeItemId = moveActive(instance, -1);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (event.key === "ArrowRight" && horizontal) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
instance.activeItemId = moveActive(instance, 1);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (event.key === "ArrowLeft" && horizontal) {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
instance.activeItemId = moveActive(instance, -1);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (event.key === "Home") {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
instance.activeItemId = firstItem(instance);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (event.key === "End") {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
instance.activeItemId = lastItem(instance);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if ((event.key === "Enter" || event.key === " ") && instance.activeItemId) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
selectItem(menuId, instance.activeItemId);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (event.key === "Escape") {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
close(menuId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function createMenuStore(config = {}) {
|
|
92
|
+
let lockCount = 0;
|
|
93
|
+
function setLock(locked) {
|
|
94
|
+
if (locked) {
|
|
95
|
+
if (lockCount === 0) {
|
|
96
|
+
config.onLockChange?.(true);
|
|
97
|
+
}
|
|
98
|
+
lockCount++;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (lockCount === 0) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
lockCount--;
|
|
105
|
+
if (lockCount === 0) {
|
|
106
|
+
config.onLockChange?.(false);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function getOrCreate(store2, id) {
|
|
110
|
+
store2.instances[id] ??= createInstance();
|
|
111
|
+
return store2.instances[id];
|
|
112
|
+
}
|
|
113
|
+
const store = {
|
|
114
|
+
instances: {},
|
|
115
|
+
register(id, options = {}) {
|
|
116
|
+
this.instances[id] = createInstance(options);
|
|
117
|
+
},
|
|
118
|
+
unregister(id) {
|
|
119
|
+
if (this.isOpen(id)) {
|
|
120
|
+
this.close(id);
|
|
121
|
+
}
|
|
122
|
+
delete this.instances[id];
|
|
123
|
+
},
|
|
124
|
+
registerItem(menuId, itemId, options = {}) {
|
|
125
|
+
const instance = getOrCreate(this, menuId);
|
|
126
|
+
const existing = instance.items.find((item) => item.id === itemId);
|
|
127
|
+
if (existing) {
|
|
128
|
+
existing.disabled = options.disabled ?? existing.disabled;
|
|
129
|
+
existing.parentId = options.parentId ?? existing.parentId;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
instance.items.push({
|
|
133
|
+
id: itemId,
|
|
134
|
+
disabled: options.disabled ?? false,
|
|
135
|
+
parentId: options.parentId ?? null
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
unregisterItem(menuId, itemId) {
|
|
139
|
+
const instance = this.instances[menuId];
|
|
140
|
+
if (!instance) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
instance.items = instance.items.filter((item) => item.id !== itemId);
|
|
144
|
+
if (instance.activeItemId === itemId) {
|
|
145
|
+
instance.activeItemId = firstItem(instance);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
open(id) {
|
|
149
|
+
const instance = getOrCreate(this, id);
|
|
150
|
+
if (instance.open) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
instance.open = true;
|
|
154
|
+
if (!instance.activeItemId) {
|
|
155
|
+
instance.activeItemId = firstItem(instance);
|
|
156
|
+
}
|
|
157
|
+
setLock(true);
|
|
158
|
+
instance.onOpen?.();
|
|
159
|
+
queueMicrotask(() => focusActiveMenu(instance));
|
|
160
|
+
},
|
|
161
|
+
close(id) {
|
|
162
|
+
const instance = this.instances[id];
|
|
163
|
+
if (!instance?.open) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
instance.open = false;
|
|
167
|
+
setLock(false);
|
|
168
|
+
instance.onClose?.();
|
|
169
|
+
},
|
|
170
|
+
toggle(id) {
|
|
171
|
+
if (this.isOpen(id)) {
|
|
172
|
+
this.close(id);
|
|
173
|
+
} else {
|
|
174
|
+
this.open(id);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
isOpen(id) {
|
|
178
|
+
return this.instances[id]?.open ?? false;
|
|
179
|
+
},
|
|
180
|
+
activeItem(id) {
|
|
181
|
+
return this.instances[id]?.activeItemId ?? null;
|
|
182
|
+
},
|
|
183
|
+
setActiveItem(menuId, itemId) {
|
|
184
|
+
const instance = getOrCreate(this, menuId);
|
|
185
|
+
if (itemId === null) {
|
|
186
|
+
instance.activeItemId = null;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const item = instance.items.find((entry) => entry.id === itemId);
|
|
190
|
+
if (item && !item.disabled) {
|
|
191
|
+
instance.activeItemId = itemId;
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
bindMenu(menuId, container) {
|
|
195
|
+
const instance = getOrCreate(this, menuId);
|
|
196
|
+
instance.container = container;
|
|
197
|
+
if (instance.open) {
|
|
198
|
+
queueMicrotask(() => focusActiveMenu(instance));
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
bindTrigger(menuId, trigger) {
|
|
202
|
+
const instance = getOrCreate(this, menuId);
|
|
203
|
+
instance.trigger = trigger;
|
|
204
|
+
},
|
|
205
|
+
handleOutsideClick(menuId, event) {
|
|
206
|
+
const instance = this.instances[menuId];
|
|
207
|
+
if (!instance?.open) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const target = event.target;
|
|
211
|
+
if (!(target instanceof Node)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (instance.trigger?.contains(target) || instance.container?.contains(target)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this.close(menuId);
|
|
218
|
+
},
|
|
219
|
+
selectItem(menuId, itemId) {
|
|
220
|
+
const instance = this.instances[menuId];
|
|
221
|
+
const item = instance?.items.find((entry) => entry.id === itemId);
|
|
222
|
+
if (!(instance && item) || item.disabled) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
instance.activeItemId = itemId;
|
|
226
|
+
instance.onSelect?.(itemId);
|
|
227
|
+
if (instance.closeOnSelect) {
|
|
228
|
+
this.close(menuId);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
handleKeydown(menuId, event) {
|
|
232
|
+
const instance = this.instances[menuId];
|
|
233
|
+
if (instance?.open) {
|
|
234
|
+
handleMenuKeydown(
|
|
235
|
+
menuId,
|
|
236
|
+
instance,
|
|
237
|
+
event,
|
|
238
|
+
this.selectItem.bind(this),
|
|
239
|
+
this.close.bind(this)
|
|
240
|
+
);
|
|
241
|
+
queueMicrotask(() => focusActiveMenu(instance));
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
itemProps(menuId, itemId) {
|
|
245
|
+
const instance = this.instances[menuId];
|
|
246
|
+
const item = instance?.items.find((entry) => entry.id === itemId);
|
|
247
|
+
const active = instance?.activeItemId === itemId;
|
|
248
|
+
return {
|
|
249
|
+
role: "menuitem",
|
|
250
|
+
tabindex: active ? 0 : -1,
|
|
251
|
+
"aria-disabled": item?.disabled ?? false
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
menuProps(menuId) {
|
|
255
|
+
const instance = this.instances[menuId];
|
|
256
|
+
return {
|
|
257
|
+
role: "menu",
|
|
258
|
+
"aria-orientation": instance?.orientation
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
destroy() {
|
|
262
|
+
for (const id of Object.keys(this.instances)) {
|
|
263
|
+
this.unregister(id);
|
|
264
|
+
}
|
|
265
|
+
lockCount = 0;
|
|
266
|
+
config.onLockChange?.(false);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
return store;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/index.ts
|
|
273
|
+
function menuOptions(options) {
|
|
274
|
+
return options;
|
|
275
|
+
}
|
|
276
|
+
function menuPlugin(options = {}) {
|
|
277
|
+
return function registerMenu(Alpine) {
|
|
278
|
+
const store = createMenuStore({
|
|
279
|
+
onLockChange: options.onLockChange
|
|
280
|
+
});
|
|
281
|
+
Alpine.store("menu", store);
|
|
282
|
+
Alpine.magic("menu", () => Alpine.store("menu"));
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
createMenuStore,
|
|
287
|
+
menuPlugin as default,
|
|
288
|
+
menuOptions
|
|
289
|
+
};
|
|
290
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/store.ts","../src/index.ts"],"sourcesContent":["export type MenuOrientation = \"vertical\" | \"horizontal\";\n\nexport type MenuItemState = {\n id: string;\n disabled: boolean;\n parentId: string | null;\n};\n\nexport type MenuInstance = {\n open: boolean;\n activeItemId: string | null;\n orientation: MenuOrientation;\n closeOnSelect: boolean;\n items: MenuItemState[];\n container: HTMLElement | null;\n trigger: HTMLElement | null;\n onOpen?: () => void;\n onClose?: () => void;\n onSelect?: (itemId: string) => void;\n};\n\nexport type MenuItemOptions = {\n disabled?: boolean;\n parentId?: string | null;\n};\n\nexport type MenuInstanceOptions = {\n orientation?: MenuOrientation;\n closeOnSelect?: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n onSelect?: (itemId: string) => void;\n};\n\nexport type MenuStore = {\n /** Reactive registry of menu instances. */\n instances: Record<string, MenuInstance>;\n open(id: string): void;\n close(id: string): void;\n toggle(id: string): void;\n isOpen(id: string): boolean;\n activeItem(id: string): string | null;\n register(id: string, options?: MenuInstanceOptions): void;\n unregister(id: string): void;\n registerItem(menuId: string, itemId: string, options?: MenuItemOptions): void;\n unregisterItem(menuId: string, itemId: string): void;\n bindMenu(menuId: string, container: HTMLElement | null): void;\n bindTrigger(menuId: string, trigger: HTMLElement | null): void;\n handleOutsideClick(menuId: string, event: MouseEvent): void;\n setActiveItem(menuId: string, itemId: string | null): void;\n selectItem(menuId: string, itemId: string): void;\n handleKeydown(menuId: string, event: KeyboardEvent): void;\n itemProps(menuId: string, itemId: string): Record<string, string | number | boolean | undefined>;\n menuProps(menuId: string): Record<string, string | boolean | undefined>;\n destroy(): void;\n};\n\ntype MenuStoreConfig = {\n onLockChange?: (locked: boolean) => void;\n};\n\nfunction enabledItems(instance: MenuInstance): MenuItemState[] {\n return instance.items.filter((item) => !item.disabled);\n}\n\nfunction itemIndex(instance: MenuInstance, itemId: string): number {\n return enabledItems(instance).findIndex((item) => item.id === itemId);\n}\n\nfunction moveActive(instance: MenuInstance, delta: number): string | null {\n const items = enabledItems(instance);\n if (items.length === 0) {\n return null;\n }\n\n const currentIndex = instance.activeItemId ? itemIndex(instance, instance.activeItemId) : -1;\n const nextIndex = (currentIndex + delta + items.length) % items.length;\n return items[nextIndex]?.id ?? null;\n}\n\nfunction firstItem(instance: MenuInstance): string | null {\n return enabledItems(instance)[0]?.id ?? null;\n}\n\nfunction lastItem(instance: MenuInstance): string | null {\n const items = enabledItems(instance);\n return items[items.length - 1]?.id ?? null;\n}\n\nfunction createInstance(options: MenuInstanceOptions = {}): MenuInstance {\n return {\n open: false,\n activeItemId: null,\n orientation: options.orientation ?? \"vertical\",\n closeOnSelect: options.closeOnSelect ?? true,\n items: [],\n container: null,\n trigger: null,\n onOpen: options.onOpen,\n onClose: options.onClose,\n onSelect: options.onSelect,\n };\n}\n\nfunction focusActiveItem(container: HTMLElement | null): void {\n if (!container) {\n return;\n }\n\n const active = container.querySelector<HTMLElement>('[role=\"menuitem\"][tabindex=\"0\"]');\n active?.focus();\n}\n\nfunction focusActiveMenu(instance: MenuInstance): void {\n focusActiveItem(instance.container);\n}\n\nfunction handleMenuKeydown(\n menuId: string,\n instance: MenuInstance,\n event: KeyboardEvent,\n selectItem: (menuId: string, itemId: string) => void,\n close: (menuId: string) => void\n): void {\n const vertical = instance.orientation === \"vertical\";\n const horizontal = instance.orientation === \"horizontal\";\n\n if (event.key === \"ArrowDown\" && vertical) {\n event.preventDefault();\n instance.activeItemId = moveActive(instance, 1);\n return;\n }\n\n if (event.key === \"ArrowUp\" && vertical) {\n event.preventDefault();\n instance.activeItemId = moveActive(instance, -1);\n return;\n }\n\n if (event.key === \"ArrowRight\" && horizontal) {\n event.preventDefault();\n instance.activeItemId = moveActive(instance, 1);\n return;\n }\n\n if (event.key === \"ArrowLeft\" && horizontal) {\n event.preventDefault();\n instance.activeItemId = moveActive(instance, -1);\n return;\n }\n\n if (event.key === \"Home\") {\n event.preventDefault();\n instance.activeItemId = firstItem(instance);\n return;\n }\n\n if (event.key === \"End\") {\n event.preventDefault();\n instance.activeItemId = lastItem(instance);\n return;\n }\n\n if ((event.key === \"Enter\" || event.key === \" \") && instance.activeItemId) {\n event.preventDefault();\n selectItem(menuId, instance.activeItemId);\n return;\n }\n\n if (event.key === \"Escape\") {\n event.preventDefault();\n close(menuId);\n }\n}\n\n/** Creates the headless menu store. */\nexport function createMenuStore(config: MenuStoreConfig = {}): MenuStore {\n let lockCount = 0;\n\n function setLock(locked: boolean): void {\n if (locked) {\n if (lockCount === 0) {\n config.onLockChange?.(true);\n }\n lockCount++;\n return;\n }\n\n if (lockCount === 0) {\n return;\n }\n\n lockCount--;\n if (lockCount === 0) {\n config.onLockChange?.(false);\n }\n }\n\n function getOrCreate(store: MenuStore, id: string): MenuInstance {\n store.instances[id] ??= createInstance();\n return store.instances[id];\n }\n\n const store: MenuStore = {\n instances: {},\n\n register(id, options = {}) {\n this.instances[id] = createInstance(options);\n },\n\n unregister(id) {\n if (this.isOpen(id)) {\n this.close(id);\n }\n delete this.instances[id];\n },\n\n registerItem(menuId, itemId, options = {}) {\n const instance = getOrCreate(this, menuId);\n const existing = instance.items.find((item) => item.id === itemId);\n if (existing) {\n existing.disabled = options.disabled ?? existing.disabled;\n existing.parentId = options.parentId ?? existing.parentId;\n return;\n }\n\n instance.items.push({\n id: itemId,\n disabled: options.disabled ?? false,\n parentId: options.parentId ?? null,\n });\n },\n\n unregisterItem(menuId, itemId) {\n const instance = this.instances[menuId];\n if (!instance) {\n return;\n }\n\n instance.items = instance.items.filter((item) => item.id !== itemId);\n if (instance.activeItemId === itemId) {\n instance.activeItemId = firstItem(instance);\n }\n },\n\n open(id) {\n const instance = getOrCreate(this, id);\n if (instance.open) {\n return;\n }\n\n instance.open = true;\n if (!instance.activeItemId) {\n instance.activeItemId = firstItem(instance);\n }\n\n setLock(true);\n\n instance.onOpen?.();\n queueMicrotask(() => focusActiveMenu(instance));\n },\n\n close(id) {\n const instance = this.instances[id];\n if (!instance?.open) {\n return;\n }\n\n instance.open = false;\n\n setLock(false);\n\n instance.onClose?.();\n },\n\n toggle(id) {\n if (this.isOpen(id)) {\n this.close(id);\n } else {\n this.open(id);\n }\n },\n\n isOpen(id) {\n return this.instances[id]?.open ?? false;\n },\n\n activeItem(id) {\n return this.instances[id]?.activeItemId ?? null;\n },\n\n setActiveItem(menuId, itemId) {\n const instance = getOrCreate(this, menuId);\n if (itemId === null) {\n instance.activeItemId = null;\n return;\n }\n\n const item = instance.items.find((entry) => entry.id === itemId);\n if (item && !item.disabled) {\n instance.activeItemId = itemId;\n }\n },\n\n bindMenu(menuId, container) {\n const instance = getOrCreate(this, menuId);\n instance.container = container;\n\n if (instance.open) {\n queueMicrotask(() => focusActiveMenu(instance));\n }\n },\n\n bindTrigger(menuId, trigger) {\n const instance = getOrCreate(this, menuId);\n instance.trigger = trigger;\n },\n\n handleOutsideClick(menuId, event) {\n const instance = this.instances[menuId];\n if (!instance?.open) {\n return;\n }\n\n const target = event.target;\n if (!(target instanceof Node)) {\n return;\n }\n\n if (instance.trigger?.contains(target) || instance.container?.contains(target)) {\n return;\n }\n\n this.close(menuId);\n },\n\n selectItem(menuId, itemId) {\n const instance = this.instances[menuId];\n const item = instance?.items.find((entry) => entry.id === itemId);\n if (!(instance && item) || item.disabled) {\n return;\n }\n\n instance.activeItemId = itemId;\n instance.onSelect?.(itemId);\n\n if (instance.closeOnSelect) {\n this.close(menuId);\n }\n },\n\n handleKeydown(menuId, event) {\n const instance = this.instances[menuId];\n if (instance?.open) {\n handleMenuKeydown(\n menuId,\n instance,\n event,\n this.selectItem.bind(this),\n this.close.bind(this)\n );\n queueMicrotask(() => focusActiveMenu(instance));\n }\n },\n\n itemProps(menuId, itemId) {\n const instance = this.instances[menuId];\n const item = instance?.items.find((entry) => entry.id === itemId);\n const active = instance?.activeItemId === itemId;\n\n return {\n role: \"menuitem\",\n tabindex: active ? 0 : -1,\n \"aria-disabled\": item?.disabled ?? false,\n };\n },\n\n menuProps(menuId) {\n const instance = this.instances[menuId];\n return {\n role: \"menu\",\n \"aria-orientation\": instance?.orientation,\n };\n },\n\n destroy() {\n for (const id of Object.keys(this.instances)) {\n this.unregister(id);\n }\n lockCount = 0;\n config.onLockChange?.(false);\n },\n };\n\n return store;\n}\n","import type AlpineType from \"alpinejs\";\nimport { createMenuStore, type MenuStore } from \"./store.js\";\n\nexport {\n createMenuStore,\n type MenuInstanceOptions,\n type MenuItemOptions,\n type MenuOrientation,\n type MenuStore,\n} from \"./store.js\";\n\nexport interface MenuPluginOptions {\n onLockChange?: (locked: boolean) => void;\n}\n\n/** Builds typed menu plugin options. */\nexport function menuOptions<const T extends MenuPluginOptions>(options: T): T {\n return options;\n}\n\n/** Alpine.js menu plugin. Registers `$store.menu`. */\nexport default function menuPlugin(options: MenuPluginOptions = {}): AlpineType.PluginCallback {\n return function registerMenu(Alpine) {\n const store = createMenuStore({\n onLockChange: options.onLockChange,\n });\n Alpine.store(\"menu\", store);\n Alpine.magic(\"menu\", () => Alpine.store(\"menu\"));\n };\n}\n\ndeclare global {\n namespace Alpine {\n interface Stores {\n menu: MenuStore;\n }\n interface Magics<T> {\n $menu: MenuStore;\n }\n }\n}\n"],"mappings":";AA6DA,SAAS,aAAa,UAAyC;AAC7D,SAAO,SAAS,MAAM,OAAO,CAAC,SAAS,CAAC,KAAK,QAAQ;AACvD;AAEA,SAAS,UAAU,UAAwB,QAAwB;AACjE,SAAO,aAAa,QAAQ,EAAE,UAAU,CAAC,SAAS,KAAK,OAAO,MAAM;AACtE;AAEA,SAAS,WAAW,U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6B,CAAC,GAA8B;AAC7F,SAAO,SAAS,aAAa,QAAQ;AACnC,UAAM,QAAQ,gBAAgB;AAAA,MAC5B,cAAc,QAAQ;AAAA,IACxB,CAAC;AACD,WAAO,MAAM,QAAQ,KAAK;AAC1B,WAAO,MAAM,QAAQ,MAAM,OAAO,MAAM,MAAM,CAAC;AAAA,EACjD;AACF;","names":["store"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ailuracode/alpine-menu",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Alpine.js headless accessible menu store",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "ailuracode",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ailuracode/alpinejs-toolkit.git",
|
|
14
|
+
"directory": "packages/menu"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/ailuracode/alpinejs-toolkit/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/ailuracode/alpinejs-toolkit/tree/master/packages/menu#readme",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./global": {
|
|
30
|
+
"types": "./dist/global.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"types": "./dist/global.d.ts",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"alpinejs": "^3.0.0",
|
|
36
|
+
"@types/alpinejs": "^3.13.11"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@types/alpinejs": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"alpinejs",
|
|
45
|
+
"alpine",
|
|
46
|
+
"plugin",
|
|
47
|
+
"menu",
|
|
48
|
+
"dropdown",
|
|
49
|
+
"accessibility",
|
|
50
|
+
"headless"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup src/index.ts --format esm --dts --clean --sourcemap --out-dir dist && cp src/global.d.ts dist/global.d.ts",
|
|
54
|
+
"test": "vitest run --config ../../vitest.config.ts test"
|
|
55
|
+
}
|
|
56
|
+
}
|