@vmz/ui 0.3.6 → 0.3.8

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 (68) hide show
  1. package/README.md +53 -51
  2. package/contracts/token-requirements.v0.json +58 -1
  3. package/package.json +5 -2
  4. package/presets/web-surface.v0.json +14 -12
  5. package/src/components/Accordion.vmz +127 -94
  6. package/src/components/Alert.vmz +125 -28
  7. package/src/components/AppShell.vmz +125 -57
  8. package/src/components/Autocomplete.vmz +261 -154
  9. package/src/components/Avatar.vmz +20 -12
  10. package/src/components/Badge.vmz +62 -70
  11. package/src/components/Breadcrumb.vmz +86 -72
  12. package/src/components/BulkActions.vmz +56 -51
  13. package/src/components/Button.vmz +237 -211
  14. package/src/components/Callout.vmz +178 -77
  15. package/src/components/Card.vmz +141 -120
  16. package/src/components/Checkbox.vmz +131 -55
  17. package/src/components/CodeBlock.vmz +77 -30
  18. package/src/components/Collapse.vmz +64 -11
  19. package/src/components/ConsoleShell.vmz +405 -251
  20. package/src/components/Content.vmz +15 -1
  21. package/src/components/DataTable.vmz +294 -194
  22. package/src/components/DatePicker.vmz +766 -674
  23. package/src/components/Descriptions.vmz +90 -0
  24. package/src/components/Dialog.vmz +137 -38
  25. package/src/components/Divider.vmz +8 -1
  26. package/src/components/Drawer.vmz +518 -427
  27. package/src/components/Dropdown.vmz +195 -51
  28. package/src/components/Empty.vmz +96 -54
  29. package/src/components/Field.vmz +170 -115
  30. package/src/components/FilterBar.vmz +34 -4
  31. package/src/components/Flex.vmz +3 -1
  32. package/src/components/Footer.vmz +6 -3
  33. package/src/components/Form.vmz +41 -0
  34. package/src/components/FormItem.vmz +78 -79
  35. package/src/components/Grid.vmz +6 -3
  36. package/src/components/Header.vmz +193 -6
  37. package/src/components/Layout.vmz +3 -1
  38. package/src/components/Link.vmz +25 -10
  39. package/src/components/List.vmz +124 -102
  40. package/src/components/Menu.vmz +416 -243
  41. package/src/components/Message.vmz +167 -0
  42. package/src/components/Notification.vmz +132 -37
  43. package/src/components/Pagination.vmz +237 -69
  44. package/src/components/Popconfirm.vmz +287 -0
  45. package/src/components/Popover.vmz +341 -223
  46. package/src/components/Progress.vmz +16 -5
  47. package/src/components/Prose.vmz +180 -81
  48. package/src/components/QueryForm.vmz +31 -9
  49. package/src/components/RadioGroup.vmz +204 -124
  50. package/src/components/Result.vmz +60 -27
  51. package/src/components/Segmented.vmz +86 -51
  52. package/src/components/Select.vmz +620 -533
  53. package/src/components/Sider.vmz +120 -7
  54. package/src/components/Skeleton.vmz +9 -7
  55. package/src/components/Space.vmz +9 -3
  56. package/src/components/Spinner.vmz +5 -4
  57. package/src/components/Steps.vmz +118 -103
  58. package/src/components/Switch.vmz +131 -98
  59. package/src/components/Table.vmz +270 -165
  60. package/src/components/Tabs.vmz +125 -110
  61. package/src/components/Tag.vmz +60 -43
  62. package/src/components/TextArea.vmz +125 -118
  63. package/src/components/Timeline.vmz +111 -76
  64. package/src/components/Toc.vmz +90 -74
  65. package/src/components/Tooltip.vmz +107 -58
  66. package/src/components/Tree.vmz +214 -191
  67. package/src/components/Typography.vmz +23 -8
  68. package/src/components/Upload.vmz +1394 -1289
@@ -1,243 +1,416 @@
1
- <template>
2
- <div data-vmz-ui="menu" :data-vmz-overlay-open="open" class="vmz-ui-menu">
3
- <button type="button" data-vmz-menu="trigger" aria-haspopup="menu" :aria-expanded="open ? 'true' : 'false'" :aria-controls="menuId" @click="toggle" :onKeyDown="onTriggerKeyDown" class="vmz-ui-menu__trigger">
4
- {{ label }}
5
- </button>
6
- <div v-if="open" :id="menuId" role="menu" data-vmz-overlay="menu" data-vmz-overlay-owner="menu" data-vmz-focus="enter" tabindex="-1" :onKeyDown="onMenuKeyDown" class="vmz-ui-menu__panel">
7
- <button v-for="item in items" :key="item.id" type="button" role="menuitem" :data-vmz-menu-item="item.id" @click="onItemClick" class="vmz-ui-menu__item">
8
- {{ item.title }}
9
- </button>
10
- </div>
11
- </div>
12
- </template>
13
- <style>
14
- .vmz-ui-menu {
15
- position: relative;
16
- display: inline-block;
17
- }
18
-
19
- .vmz-ui-menu__trigger {
20
- font: inherit;
21
- font-size: 0.875rem;
22
- font-weight: 400;
23
- min-height: var(--vmz-control-height, 2rem);
24
- padding: 0.25rem 0.75rem;
25
- border: 1px solid var(--vmz-line-default);
26
- border-radius: var(--vmz-radius-md, 6px);
27
- cursor: pointer;
28
- background: var(--vmz-surface-paper, #fff);
29
- color: var(--vmz-text-ink);
30
- outline: none;
31
- }
32
-
33
- .vmz-ui-menu__trigger:hover {
34
- color: var(--vmz-action-primary-background);
35
- border-color: var(--vmz-action-primary-background);
36
- }
37
-
38
- .vmz-ui-menu__trigger:focus-visible {
39
- box-shadow: 0 0 0 3px var(--vmz-focus-ring);
40
- }
41
-
42
- .vmz-ui-menu__panel {
43
- position: absolute;
44
- z-index: 30;
45
- top: calc(100% + 0.25rem);
46
- left: 0;
47
- min-width: 10rem;
48
- padding: 0.25rem;
49
- border: 1px solid var(--vmz-line-default);
50
- border-radius: var(--vmz-radius-md, 6px);
51
- background: var(--vmz-surface-paper, #fff);
52
- color: var(--vmz-text-ink);
53
- box-shadow: var(--vmz-shadow-popup);
54
- outline: none;
55
- }
56
-
57
- .vmz-ui-menu__panel:focus-visible {
58
- box-shadow: 0 0 0 3px var(--vmz-focus-ring);
59
- }
60
-
61
- .vmz-ui-menu__item {
62
- display: block;
63
- width: 100%;
64
- text-align: left;
65
- font: inherit;
66
- padding: 0.375rem 0.625rem;
67
- border: 0;
68
- border-radius: var(--vmz-radius-md, 6px);
69
- background: transparent;
70
- color: inherit;
71
- cursor: pointer;
72
- outline: none;
73
- }
74
-
75
- .vmz-ui-menu__item:hover,
76
- .vmz-ui-menu__item:focus-visible {
77
- background: color-mix(in srgb, var(--vmz-action-primary-background) 18%, transparent);
78
- }
79
-
80
- .vmz-ui-menu__item:focus-visible {
81
- box-shadow: 0 0 0 3px var(--vmz-focus-ring);
82
- }
83
- </style>
84
- <script client>
85
- /**
86
- * VMZ UI — Menu (UI2).
87
- * Parent owns `open`; Escape / choose closes via onClose; focus restore to trigger.
88
- */
89
- export default class Menu {
90
- public label: string = "Menu";
91
- public open: boolean = false;
92
- public menuId: string = "vmz-menu";
93
- /** @type {{ id: string, title: string }[]} */
94
- public items: {
95
- id: string;
96
- title: string;
97
- }[] = [];
98
- public onOpenChange: ((open: boolean) => void) | null = null;
99
- public onSelect: ((id: string) => void) | null = null;
100
- _restoreFocus = null;
101
- _panel = null;
102
- _docKeyHandler = null;
103
- _docPointerHandler = null;
104
- _observer = null;
105
- async onMount() {
106
- if (typeof document === "undefined" || typeof MutationObserver === "undefined") return;
107
- const root = this.__vmzDomRoot;
108
- if (!root || typeof root.querySelector !== "function") return;
109
- this._observer = new MutationObserver(() => this._syncFromDom());
110
- this._observer.observe(root, {
111
- childList: true,
112
- subtree: true,
113
- });
114
- this._syncFromDom();
115
- }
116
- onDestroy() {
117
- if (this._observer) {
118
- this._observer.disconnect();
119
- this._observer = null;
120
- }
121
- this._teardownDoc();
122
- this._panel = null;
123
- this._restoreFocus = null;
124
- }
125
- toggle() {
126
- if (typeof this.onOpenChange === "function") this.onOpenChange(!this.open);
127
- }
128
- close() {
129
- if (typeof this.onOpenChange === "function") this.onOpenChange(false);
130
- }
131
- choose(id) {
132
- if (typeof this.onSelect === "function") this.onSelect(id);
133
- this.close();
134
- }
135
- onItemClick(ev) {
136
- const el = ev?.currentTarget;
137
- const id =
138
- el && typeof el.getAttribute === "function"
139
- ? el.getAttribute("data-vmz-menu-item")
140
- : null;
141
- if (id) this.choose(id);
142
- }
143
- onTriggerKeyDown(ev) {
144
- if (!ev) return;
145
- if ((ev.key === "ArrowDown" || ev.key === "Enter" || ev.key === " ") && !this.open) {
146
- ev.preventDefault();
147
- if (typeof this.onOpenChange === "function") this.onOpenChange(true);
148
- }
149
- }
150
- onMenuKeyDown(ev) {
151
- if (!ev || !this._panel) return;
152
- if (ev.key === "Escape") {
153
- ev.preventDefault();
154
- this.close();
155
- return;
156
- }
157
- const nodes = [...this._panel.querySelectorAll('[role="menuitem"]')].filter(
158
- (n) => n instanceof HTMLElement && n.offsetParent !== null,
159
- );
160
- if (!nodes.length) return;
161
- const idx = nodes.indexOf(document.activeElement);
162
- if (ev.key === "ArrowDown") {
163
- ev.preventDefault();
164
- nodes[(idx + 1 + nodes.length) % nodes.length].focus();
165
- } else if (ev.key === "ArrowUp") {
166
- ev.preventDefault();
167
- nodes[(idx - 1 + nodes.length) % nodes.length].focus();
168
- } else if (ev.key === "Home") {
169
- ev.preventDefault();
170
- nodes[0].focus();
171
- } else if (ev.key === "End") {
172
- ev.preventDefault();
173
- nodes[nodes.length - 1].focus();
174
- }
175
- }
176
- _syncFromDom() {
177
- const root = this.__vmzDomRoot;
178
- const panel =
179
- root && typeof root.querySelector === "function"
180
- ? root.querySelector('[data-vmz-overlay="menu"][data-vmz-focus="enter"]')
181
- : null;
182
- if (panel && !this._panel) this._enterFocus(panel);
183
- else if (!panel && this._panel) this._exitFocus();
184
- }
185
- _enterFocus(panel) {
186
- if (typeof document === "undefined") return;
187
- const root = this.__vmzDomRoot;
188
- const trigger =
189
- root && typeof root.querySelector === "function"
190
- ? root.querySelector('[data-vmz-menu="trigger"]')
191
- : null;
192
- const active = document.activeElement;
193
- if (!this._restoreFocus) {
194
- if (trigger instanceof HTMLElement) this._restoreFocus = trigger;
195
- else if (active instanceof HTMLElement) this._restoreFocus = active;
196
- }
197
- this._panel = panel instanceof HTMLElement ? panel : null;
198
- const first =
199
- this._panel && typeof this._panel.querySelector === "function"
200
- ? this._panel.querySelector('[role="menuitem"]')
201
- : null;
202
- if (first && typeof first.focus === "function") first.focus();
203
- else if (this._panel && typeof this._panel.focus === "function") this._panel.focus();
204
- if (!this._docKeyHandler) {
205
- this._docKeyHandler = (ev) => {
206
- if (ev.key === "Escape") {
207
- ev.preventDefault();
208
- this.close();
209
- }
210
- };
211
- document.addEventListener("keydown", this._docKeyHandler);
212
- }
213
- if (!this._docPointerHandler) {
214
- this._docPointerHandler = (ev) => {
215
- const t = ev.target;
216
- if (!(t instanceof Node)) return;
217
- if (root && typeof root.contains === "function" && root.contains(t)) return;
218
- this.close();
219
- };
220
- document.addEventListener("pointerdown", this._docPointerHandler, true);
221
- }
222
- }
223
- _exitFocus() {
224
- this._teardownDoc();
225
- this._panel = null;
226
- const restore = this._restoreFocus;
227
- this._restoreFocus = null;
228
- if (restore && typeof restore.focus === "function" && document.contains(restore)) {
229
- restore.focus();
230
- }
231
- }
232
- _teardownDoc() {
233
- if (typeof document !== "undefined") {
234
- if (this._docKeyHandler) document.removeEventListener("keydown", this._docKeyHandler);
235
- if (this._docPointerHandler) {
236
- document.removeEventListener("pointerdown", this._docPointerHandler, true);
237
- }
238
- }
239
- this._docKeyHandler = null;
240
- this._docPointerHandler = null;
241
- }
242
- }
243
- </script>
1
+ <template>
2
+ <div data-vmz-ui="menu" :data-vmz-overlay-open="open" class="vmz-ui-menu">
3
+ <button type="button" data-vmz-menu="trigger" aria-haspopup="menu" :aria-expanded="open ? 'true' : 'false'" :aria-controls="menuId" @click="toggle" :onKeyDown="onTriggerKeyDown" class="vmz-ui-menu__trigger">
4
+ <span class="vmz-ui-menu__trigger-label">
5
+ {{ label }}
6
+ </span>
7
+ <Icon name="action.chevron-down" size="sm" decorative />
8
+ </button>
9
+ <div v-if="open" :id="menuId" role="menu" data-vmz-overlay="menu" data-vmz-overlay-owner="menu" data-vmz-focus="enter" tabindex="-1" :onKeyDown="onMenuKeyDown" class="vmz-ui-menu__panel">
10
+ <div v-for="item in items" :key="item.id" :data-kind="item.kind || 'item'" :data-vmz-menu-row="item.id" class="vmz-ui-menu__row">
11
+ <div v-if="item.kind === 'divider'" role="separator" class="vmz-ui-menu__divider" />
12
+ <div v-else-if="item.kind === 'group'" role="presentation" class="vmz-ui-menu__group">
13
+ {{ item.title }}
14
+ </div>
15
+ <div v-else-if="item.children && item.children.length" :data-open="subOpen(item.id) ? 'true' : 'false'" :data-danger="item.danger ? 'true' : 'false'" class="vmz-ui-menu__submenu">
16
+ <button type="button" role="menuitem" aria-haspopup="menu" :aria-expanded="subOpen(item.id) ? 'true' : 'false'" :disabled="item.disabled" @click="toggleSub(item.id)" class="vmz-ui-menu__item vmz-ui-menu__item--sub">
17
+ <span class="vmz-ui-menu__label">
18
+ {{ item.title }}
19
+ </span>
20
+ <Icon name="action.chevron-right" size="sm" decorative />
21
+ </button>
22
+ <div v-if="subOpen(item.id)" role="menu" class="vmz-ui-menu__subpanel">
23
+ <button v-for="child in item.children" :key="child.id" type="button" role="menuitem" :data-vmz-menu-item="child.id" :data-danger="child.danger ? 'true' : 'false'" :data-active="child.active ? 'true' : 'false'" :disabled="child.disabled" @click="onItemClick" class="vmz-ui-menu__item">
24
+ {{ child.title }}
25
+ </button>
26
+ </div>
27
+ </div>
28
+ <button v-else type="button" role="menuitem" :data-vmz-menu-item="item.id" :data-danger="item.danger ? 'true' : 'false'" :data-active="item.active ? 'true' : 'false'" :disabled="item.disabled" @click="onItemClick" class="vmz-ui-menu__item">
29
+ {{ item.title }}
30
+ </button>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </template>
35
+ <style>
36
+ .vmz-ui-menu {
37
+ position: relative;
38
+ display: inline-block;
39
+ }
40
+
41
+ .vmz-ui-menu__trigger {
42
+ display: inline-flex;
43
+ align-items: center;
44
+ gap: 6px;
45
+ font: inherit;
46
+ font-size: 14px;
47
+ font-weight: 400;
48
+ line-height: 22px;
49
+ min-height: var(--vmz-control-height, 32px);
50
+ padding: 0 12px;
51
+ border: 1px solid var(--vmz-line-default);
52
+ border-radius: var(--vmz-radius-md);
53
+ cursor: pointer;
54
+ background: var(--vmz-surface-paper);
55
+ color: var(--vmz-text-ink);
56
+ outline: none;
57
+ transition:
58
+ color var(--vmz-motion-control-duration) var(--vmz-motion-control-easing),
59
+ border-color var(--vmz-motion-control-duration) var(--vmz-motion-control-easing);
60
+ }
61
+
62
+ .vmz-ui-menu__trigger:hover {
63
+ color: var(--vmz-action-primary-background);
64
+ border-color: var(--vmz-action-primary-background);
65
+ }
66
+
67
+ .vmz-ui-menu__trigger:focus-visible {
68
+ box-shadow: 0 0 0 3px var(--vmz-focus-ring);
69
+ }
70
+
71
+ .vmz-ui-menu__trigger-label:empty {
72
+ display: none;
73
+ }
74
+
75
+ .vmz-ui-menu[data-vmz-overlay-open="true"] .vmz-ui-menu__trigger {
76
+ border-color: var(--vmz-action-primary-background);
77
+ }
78
+
79
+ .vmz-ui-menu[data-vmz-overlay-open="true"] .vmz-ui-menu__trigger .vmz-ui-icon {
80
+ transform: rotate(180deg);
81
+ }
82
+
83
+ .vmz-ui-menu__panel {
84
+ position: absolute;
85
+ z-index: 30;
86
+ top: calc(100% + 4px);
87
+ left: 0;
88
+ min-width: 176px;
89
+ max-height: 320px;
90
+ overflow: auto;
91
+ box-sizing: border-box;
92
+ padding: 4px;
93
+ border: 1px solid var(--vmz-line-subtle);
94
+ border-radius: var(--vmz-radius-lg);
95
+ background: var(--vmz-surface-paper);
96
+ color: var(--vmz-text-ink);
97
+ box-shadow: var(--vmz-shadow-popup);
98
+ outline: none;
99
+ animation: vmz-ui-menu-in var(--vmz-motion-overlay-duration)
100
+ var(--vmz-motion-overlay-easing);
101
+ }
102
+
103
+ .vmz-ui-menu__panel:focus-visible {
104
+ box-shadow: 0 0 0 3px var(--vmz-focus-ring);
105
+ }
106
+
107
+ .vmz-ui-menu__row {
108
+ display: contents;
109
+ }
110
+
111
+ .vmz-ui-menu__item {
112
+ display: flex;
113
+ align-items: center;
114
+ gap: 8px;
115
+ width: 100%;
116
+ min-height: 32px;
117
+ box-sizing: border-box;
118
+ text-align: left;
119
+ font: inherit;
120
+ font-size: 14px;
121
+ line-height: 22px;
122
+ padding: 0 12px;
123
+ border: 0;
124
+ border-radius: var(--vmz-radius-md);
125
+ background: transparent;
126
+ color: var(--vmz-text-ink);
127
+ cursor: pointer;
128
+ outline: none;
129
+ transition:
130
+ color var(--vmz-motion-control-duration) var(--vmz-motion-control-easing),
131
+ background-color var(--vmz-motion-control-duration) var(--vmz-motion-control-easing);
132
+ }
133
+
134
+ .vmz-ui-menu__item:hover {
135
+ background: var(--vmz-surface-mist);
136
+ }
137
+
138
+ .vmz-ui-menu__item:focus-visible {
139
+ background: var(--vmz-surface-mist);
140
+ box-shadow: 0 0 0 2px var(--vmz-focus-ring) inset;
141
+ }
142
+
143
+ .vmz-ui-menu__item[data-active="true"] {
144
+ background: color-mix(in srgb, var(--vmz-action-primary-background) 10%, transparent);
145
+ box-shadow: inset 2px 0 0 var(--vmz-action-primary-background);
146
+ color: var(--vmz-text-ink);
147
+ }
148
+
149
+ .vmz-ui-menu__item[data-active="true"]:hover,
150
+ .vmz-ui-menu__item[data-active="true"]:focus-visible {
151
+ background: color-mix(in srgb, var(--vmz-action-primary-background) 16%, transparent);
152
+ }
153
+
154
+ .vmz-ui-menu__item[data-danger="true"] {
155
+ color: var(--vmz-status-danger-foreground);
156
+ }
157
+
158
+ .vmz-ui-menu__item[data-danger="true"]:hover,
159
+ .vmz-ui-menu__item[data-danger="true"]:focus-visible {
160
+ background: color-mix(in srgb, var(--vmz-status-danger-accent) 12%, transparent);
161
+ }
162
+
163
+ .vmz-ui-menu__item:disabled {
164
+ opacity: 0.45;
165
+ cursor: not-allowed;
166
+ background: transparent;
167
+ color: var(--vmz-text-tertiary);
168
+ }
169
+
170
+ .vmz-ui-menu__label {
171
+ flex: 1 1 auto;
172
+ min-width: 0;
173
+ overflow: hidden;
174
+ text-overflow: ellipsis;
175
+ white-space: nowrap;
176
+ }
177
+
178
+ .vmz-ui-menu__item--sub .vmz-ui-icon {
179
+ flex: 0 0 auto;
180
+ color: var(--vmz-text-tertiary);
181
+ }
182
+
183
+ .vmz-ui-menu__group {
184
+ padding: 8px 12px 4px;
185
+ font-size: 12px;
186
+ font-weight: 600;
187
+ line-height: 20px;
188
+ color: var(--vmz-text-tertiary);
189
+ }
190
+
191
+ .vmz-ui-menu__divider {
192
+ height: 1px;
193
+ margin: 4px 8px;
194
+ background: var(--vmz-line-subtle);
195
+ }
196
+
197
+ .vmz-ui-menu__submenu {
198
+ position: relative;
199
+ }
200
+
201
+ .vmz-ui-menu__submenu[data-open="true"] > .vmz-ui-menu__item--sub {
202
+ background: var(--vmz-surface-mist);
203
+ }
204
+
205
+ .vmz-ui-menu__subpanel {
206
+ display: flex;
207
+ flex-direction: column;
208
+ margin: 2px 0 4px;
209
+ padding: 4px 0 4px 12px;
210
+ border-left: 1px solid var(--vmz-line-subtle);
211
+ }
212
+
213
+ @keyframes vmz-ui-menu-in {
214
+ from {
215
+ opacity: 0;
216
+ transform: translateY(-4px);
217
+ }
218
+ to {
219
+ opacity: 1;
220
+ transform: none;
221
+ }
222
+ }
223
+
224
+ @media (prefers-reduced-motion: reduce) {
225
+ .vmz-ui-menu__panel,
226
+ .vmz-ui-menu__trigger,
227
+ .vmz-ui-menu__item {
228
+ animation: none;
229
+ transition: none;
230
+ }
231
+ }
232
+ </style>
233
+ <script client>
234
+ /**
235
+ * VMZ UI — Menu (UI2).
236
+ * Parent owns `open`; Escape / choose closes via onClose; focus restore to trigger.
237
+ *
238
+ * Item model: `{ id, title, kind?: "item"|"group"|"divider", danger?, disabled?,
239
+ * active?, children?: MenuItem[] }`. Submenus render a nested panel with a
240
+ * chevron-right affordance.
241
+ */
242
+ export default class Menu {
243
+ public label: string = "";
244
+ public open: boolean = false;
245
+ public menuId: string = "vmz-menu";
246
+ /** @type {{ id: string, title: string, kind?: string, danger?: boolean, disabled?: boolean, active?: boolean, children?: { id: string, title: string, danger?: boolean, disabled?: boolean, active?: boolean }[] }[]} */
247
+ public items: {
248
+ id: string;
249
+ title: string;
250
+ kind?: string;
251
+ danger?: boolean;
252
+ disabled?: boolean;
253
+ active?: boolean;
254
+ children?: {
255
+ id: string;
256
+ title: string;
257
+ danger?: boolean;
258
+ disabled?: boolean;
259
+ active?: boolean;
260
+ }[];
261
+ }[] = [];
262
+ public onOpenChange: ((open: boolean) => void) | null = null;
263
+ public onSelect: ((id: string) => void) | null = null;
264
+ _restoreFocus = null;
265
+ _panel = null;
266
+ _docKeyHandler = null;
267
+ _docPointerHandler = null;
268
+ _observer = null;
269
+ _subOpen: Record<string, boolean> = {};
270
+ async onMount() {
271
+ if (typeof document === "undefined" || typeof MutationObserver === "undefined") return;
272
+ const root = this.__vmzDomRoot;
273
+ if (!root || typeof root.querySelector !== "function") return;
274
+ this._observer = new MutationObserver(() => this._syncFromDom());
275
+ this._observer.observe(root, {
276
+ childList: true,
277
+ subtree: true,
278
+ });
279
+ this._syncFromDom();
280
+ }
281
+ onDestroy() {
282
+ if (this._observer) {
283
+ this._observer.disconnect();
284
+ this._observer = null;
285
+ }
286
+ this._teardownDoc();
287
+ this._panel = null;
288
+ this._restoreFocus = null;
289
+ }
290
+ subOpen(id) {
291
+ return !!this._subOpen[id];
292
+ }
293
+ toggleSub(id) {
294
+ this._subOpen = { ...this._subOpen, [id]: !this._subOpen[id] };
295
+ }
296
+ toggle() {
297
+ if (typeof this.onOpenChange === "function") this.onOpenChange(!this.open);
298
+ }
299
+ close() {
300
+ if (typeof this.onOpenChange === "function") this.onOpenChange(false);
301
+ }
302
+ choose(id) {
303
+ if (typeof this.onSelect === "function") this.onSelect(id);
304
+ this.close();
305
+ }
306
+ onItemClick(ev) {
307
+ const el = ev?.currentTarget;
308
+ if (el && typeof el.getAttribute === "function" && el.disabled) return;
309
+ const id =
310
+ el && typeof el.getAttribute === "function"
311
+ ? el.getAttribute("data-vmz-menu-item")
312
+ : null;
313
+ if (id) this.choose(id);
314
+ }
315
+ onTriggerKeyDown(ev) {
316
+ if (!ev) return;
317
+ if ((ev.key === "ArrowDown" || ev.key === "Enter" || ev.key === " ") && !this.open) {
318
+ ev.preventDefault();
319
+ if (typeof this.onOpenChange === "function") this.onOpenChange(true);
320
+ }
321
+ }
322
+ onMenuKeyDown(ev) {
323
+ if (!ev || !this._panel) return;
324
+ if (ev.key === "Escape") {
325
+ ev.preventDefault();
326
+ this.close();
327
+ return;
328
+ }
329
+ const nodes = [...this._panel.querySelectorAll('[role="menuitem"]')].filter(
330
+ (n) => n instanceof HTMLElement && n.offsetParent !== null,
331
+ );
332
+ if (!nodes.length) return;
333
+ const idx = nodes.indexOf(document.activeElement);
334
+ if (ev.key === "ArrowDown") {
335
+ ev.preventDefault();
336
+ nodes[(idx + 1 + nodes.length) % nodes.length].focus();
337
+ } else if (ev.key === "ArrowUp") {
338
+ ev.preventDefault();
339
+ nodes[(idx - 1 + nodes.length) % nodes.length].focus();
340
+ } else if (ev.key === "Home") {
341
+ ev.preventDefault();
342
+ nodes[0].focus();
343
+ } else if (ev.key === "End") {
344
+ ev.preventDefault();
345
+ nodes[nodes.length - 1].focus();
346
+ }
347
+ }
348
+ _syncFromDom() {
349
+ const root = this.__vmzDomRoot;
350
+ const panel =
351
+ root && typeof root.querySelector === "function"
352
+ ? root.querySelector('[data-vmz-overlay="menu"][data-vmz-focus="enter"]')
353
+ : null;
354
+ if (panel && !this._panel) this._enterFocus(panel);
355
+ else if (!panel && this._panel) this._exitFocus();
356
+ }
357
+ _enterFocus(panel) {
358
+ if (typeof document === "undefined") return;
359
+ const root = this.__vmzDomRoot;
360
+ const trigger =
361
+ root && typeof root.querySelector === "function"
362
+ ? root.querySelector('[data-vmz-menu="trigger"]')
363
+ : null;
364
+ const active = document.activeElement;
365
+ if (!this._restoreFocus) {
366
+ if (trigger instanceof HTMLElement) this._restoreFocus = trigger;
367
+ else if (active instanceof HTMLElement) this._restoreFocus = active;
368
+ }
369
+ this._panel = panel instanceof HTMLElement ? panel : null;
370
+ const first =
371
+ this._panel && typeof this._panel.querySelector === "function"
372
+ ? this._panel.querySelector('[role="menuitem"]')
373
+ : null;
374
+ if (first && typeof first.focus === "function") first.focus();
375
+ else if (this._panel && typeof this._panel.focus === "function") this._panel.focus();
376
+ if (!this._docKeyHandler) {
377
+ this._docKeyHandler = (ev) => {
378
+ if (ev.key === "Escape") {
379
+ ev.preventDefault();
380
+ this.close();
381
+ }
382
+ };
383
+ document.addEventListener("keydown", this._docKeyHandler);
384
+ }
385
+ if (!this._docPointerHandler) {
386
+ this._docPointerHandler = (ev) => {
387
+ const t = ev.target;
388
+ if (!(t instanceof Node)) return;
389
+ if (root && typeof root.contains === "function" && root.contains(t)) return;
390
+ this.close();
391
+ };
392
+ document.addEventListener("pointerdown", this._docPointerHandler, true);
393
+ }
394
+ }
395
+ _exitFocus() {
396
+ this._teardownDoc();
397
+ this._panel = null;
398
+ this._subOpen = {};
399
+ const restore = this._restoreFocus;
400
+ this._restoreFocus = null;
401
+ if (restore && typeof restore.focus === "function" && document.contains(restore)) {
402
+ restore.focus();
403
+ }
404
+ }
405
+ _teardownDoc() {
406
+ if (typeof document !== "undefined") {
407
+ if (this._docKeyHandler) document.removeEventListener("keydown", this._docKeyHandler);
408
+ if (this._docPointerHandler) {
409
+ document.removeEventListener("pointerdown", this._docPointerHandler, true);
410
+ }
411
+ }
412
+ this._docKeyHandler = null;
413
+ this._docPointerHandler = null;
414
+ }
415
+ }
416
+ </script>