@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.
- package/README.md +53 -51
- package/contracts/token-requirements.v0.json +58 -1
- package/package.json +5 -2
- package/presets/web-surface.v0.json +14 -12
- package/src/components/Accordion.vmz +127 -94
- package/src/components/Alert.vmz +125 -28
- package/src/components/AppShell.vmz +125 -57
- package/src/components/Autocomplete.vmz +261 -154
- package/src/components/Avatar.vmz +20 -12
- package/src/components/Badge.vmz +62 -70
- package/src/components/Breadcrumb.vmz +86 -72
- package/src/components/BulkActions.vmz +56 -51
- package/src/components/Button.vmz +237 -211
- package/src/components/Callout.vmz +178 -77
- package/src/components/Card.vmz +141 -120
- package/src/components/Checkbox.vmz +131 -55
- package/src/components/CodeBlock.vmz +77 -30
- package/src/components/Collapse.vmz +64 -11
- package/src/components/ConsoleShell.vmz +405 -251
- package/src/components/Content.vmz +15 -1
- package/src/components/DataTable.vmz +294 -194
- package/src/components/DatePicker.vmz +766 -674
- package/src/components/Descriptions.vmz +90 -0
- package/src/components/Dialog.vmz +137 -38
- package/src/components/Divider.vmz +8 -1
- package/src/components/Drawer.vmz +518 -427
- package/src/components/Dropdown.vmz +195 -51
- package/src/components/Empty.vmz +96 -54
- package/src/components/Field.vmz +170 -115
- package/src/components/FilterBar.vmz +34 -4
- package/src/components/Flex.vmz +3 -1
- package/src/components/Footer.vmz +6 -3
- package/src/components/Form.vmz +41 -0
- package/src/components/FormItem.vmz +78 -79
- package/src/components/Grid.vmz +6 -3
- package/src/components/Header.vmz +193 -6
- package/src/components/Layout.vmz +3 -1
- package/src/components/Link.vmz +25 -10
- package/src/components/List.vmz +124 -102
- package/src/components/Menu.vmz +416 -243
- package/src/components/Message.vmz +167 -0
- package/src/components/Notification.vmz +132 -37
- package/src/components/Pagination.vmz +237 -69
- package/src/components/Popconfirm.vmz +287 -0
- package/src/components/Popover.vmz +341 -223
- package/src/components/Progress.vmz +16 -5
- package/src/components/Prose.vmz +180 -81
- package/src/components/QueryForm.vmz +31 -9
- package/src/components/RadioGroup.vmz +204 -124
- package/src/components/Result.vmz +60 -27
- package/src/components/Segmented.vmz +86 -51
- package/src/components/Select.vmz +620 -533
- package/src/components/Sider.vmz +120 -7
- package/src/components/Skeleton.vmz +9 -7
- package/src/components/Space.vmz +9 -3
- package/src/components/Spinner.vmz +5 -4
- package/src/components/Steps.vmz +118 -103
- package/src/components/Switch.vmz +131 -98
- package/src/components/Table.vmz +270 -165
- package/src/components/Tabs.vmz +125 -110
- package/src/components/Tag.vmz +60 -43
- package/src/components/TextArea.vmz +125 -118
- package/src/components/Timeline.vmz +111 -76
- package/src/components/Toc.vmz +90 -74
- package/src/components/Tooltip.vmz +107 -58
- package/src/components/Tree.vmz +214 -191
- package/src/components/Typography.vmz +23 -8
- package/src/components/Upload.vmz +1394 -1289
package/src/components/Menu.vmz
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.vmz-ui-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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>
|