numori-ui 0.4.0 → 0.6.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/CHANGELOG.md +120 -0
- package/README.md +27 -20
- package/dist/components/AppShell.js +234 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/Avatar.js +71 -19
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/Checkbox.js +11 -2
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/CopyField.js +195 -0
- package/dist/components/CopyField.js.map +1 -0
- package/dist/components/DescriptionList.js +116 -0
- package/dist/components/DescriptionList.js.map +1 -0
- package/dist/components/Dropdown.js +3 -1
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/EmptyState.js +123 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormField.js +43 -13
- package/dist/components/FormField.js.map +1 -1
- package/dist/components/Input.js +15 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/Modal.js +61 -4
- package/dist/components/Modal.js.map +1 -1
- package/dist/components/PageHeader.js +106 -0
- package/dist/components/PageHeader.js.map +1 -0
- package/dist/components/Pagination.js +236 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/Prompt.js +11 -6
- package/dist/components/Prompt.js.map +1 -1
- package/dist/components/Segmented.js +10 -2
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +11 -2
- package/dist/components/Select.js.map +1 -1
- package/dist/components/Sidebar.js +69 -0
- package/dist/components/Sidebar.js.map +1 -0
- package/dist/components/SidebarGroup.js +50 -0
- package/dist/components/SidebarGroup.js.map +1 -0
- package/dist/components/SidebarItem.js +167 -0
- package/dist/components/SidebarItem.js.map +1 -0
- package/dist/components/Skeleton.js +122 -0
- package/dist/components/Skeleton.js.map +1 -0
- package/dist/components/SplitPane.js +264 -0
- package/dist/components/SplitPane.js.map +1 -0
- package/dist/components/StatCard.js +185 -0
- package/dist/components/StatCard.js.map +1 -0
- package/dist/components/Table.js +182 -50
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Tabs.js +216 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Toggle.js +11 -2
- package/dist/components/Toggle.js.map +1 -1
- package/dist/components/Tree.js +417 -0
- package/dist/components/Tree.js.map +1 -0
- package/dist/components/VirtualList.js +292 -0
- package/dist/components/VirtualList.js.map +1 -0
- package/dist/components/index.js +105 -81
- package/dist/components/index.js.map +1 -1
- package/dist/icons/mdi.js +12 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +54 -39
- package/dist/index.js.map +1 -1
- package/dist/internal/focusTrap.js +163 -0
- package/dist/internal/focusTrap.js.map +1 -0
- package/dist/internal/formField.js +26 -0
- package/dist/internal/formField.js.map +1 -0
- package/dist/manifest.js +16 -1
- package/dist/manifest.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppShell.vue +231 -0
- package/src/components/Avatar.vue +69 -18
- package/src/components/Checkbox.vue +5 -0
- package/src/components/CopyField.vue +178 -0
- package/src/components/DescriptionList.vue +114 -0
- package/src/components/Dropdown.vue +4 -1
- package/src/components/EmptyState.vue +107 -0
- package/src/components/FormField.vue +37 -4
- package/src/components/Input.vue +9 -0
- package/src/components/Modal.vue +51 -3
- package/src/components/PageHeader.vue +102 -0
- package/src/components/Pagination.vue +199 -0
- package/src/components/Prompt.vue +14 -3
- package/src/components/Segmented.vue +5 -0
- package/src/components/Select.vue +6 -1
- package/src/components/Sidebar.vue +61 -0
- package/src/components/SidebarGroup.vue +43 -0
- package/src/components/SidebarItem.vue +159 -0
- package/src/components/Skeleton.vue +91 -0
- package/src/components/SplitPane.vue +264 -0
- package/src/components/StatCard.vue +165 -0
- package/src/components/Table.vue +148 -18
- package/src/components/Tabs.vue +217 -0
- package/src/components/Toggle.vue +5 -0
- package/src/components/Tree.vue +428 -0
- package/src/components/VirtualList.vue +250 -0
- package/src/components/index.js +45 -6
- package/src/icons/mdi.js +12 -0
- package/src/internal/focusTrap.js +185 -0
- package/src/internal/formField.js +23 -0
- package/src/manifest.js +15 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="scrollerRef"
|
|
4
|
+
class="relative min-h-0 overflow-y-auto overscroll-contain focus-visible:outline-none"
|
|
5
|
+
:role="role || undefined"
|
|
6
|
+
:aria-label="label || undefined"
|
|
7
|
+
:aria-multiselectable="role === 'listbox' && multiselectable ? 'true' : undefined"
|
|
8
|
+
:tabindex="focusable ? 0 : undefined"
|
|
9
|
+
@scroll.passive="onScroll"
|
|
10
|
+
>
|
|
11
|
+
<slot v-if="items.length === 0" name="empty" />
|
|
12
|
+
<!-- One spacer as tall as the whole list keeps the scrollbar honest; only
|
|
13
|
+
the rows near the viewport are rendered inside it. -->
|
|
14
|
+
<div v-else class="relative w-full" :style="{ height: `${totalHeight}px` }">
|
|
15
|
+
<div
|
|
16
|
+
v-for="row in visibleRows"
|
|
17
|
+
:key="row.key"
|
|
18
|
+
:role="itemRole || undefined"
|
|
19
|
+
:aria-setsize="items.length"
|
|
20
|
+
:aria-posinset="row.index + 1"
|
|
21
|
+
class="absolute inset-x-0"
|
|
22
|
+
:style="{ top: `${row.index * itemHeight}px`, height: `${itemHeight}px` }"
|
|
23
|
+
>
|
|
24
|
+
<slot :item="row.item" :index="row.index" />
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script setup>
|
|
31
|
+
/**
|
|
32
|
+
* UiVirtualList — a scrolling list that renders only the rows near the
|
|
33
|
+
* viewport, so ten thousand items cost about as much as thirty.
|
|
34
|
+
*
|
|
35
|
+
* Rows have a fixed height (`itemHeight`). That is a deliberate restriction:
|
|
36
|
+
* it makes the position of every row a multiplication rather than a
|
|
37
|
+
* measurement, so scrolling never jumps and `scrollToIndex` is exact. Lists
|
|
38
|
+
* with variable-height content (an inbox with optional snippets, say) should
|
|
39
|
+
* pick one height per density setting.
|
|
40
|
+
*
|
|
41
|
+
* Accessibility: because most rows are not in the DOM, each rendered row
|
|
42
|
+
* carries `aria-setsize` and `aria-posinset`, so a screen reader still
|
|
43
|
+
* announces "item 412 of 9,000". The container and row roles default to
|
|
44
|
+
* `list` / `listitem`; for a selectable list set `role="listbox"` and
|
|
45
|
+
* `item-role="option"`, and put `aria-selected` on your row content's root via
|
|
46
|
+
* the slot (or pass `item-role=""` and supply roles yourself).
|
|
47
|
+
*
|
|
48
|
+
* Keyboard navigation between rows is the caller's job — what Up and Down mean
|
|
49
|
+
* differs between a picker and an inbox — but `scrollToIndex()` is exposed so
|
|
50
|
+
* the active row can be kept in view.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* <UiVirtualList :items="messages" :item-height="72" label="Messages" @end-reached="loadMore">
|
|
54
|
+
* <template #default="{ item }"><MessageRow :message="item" /></template>
|
|
55
|
+
* <template #empty><UiEmptyState title="Nothing here" /></template>
|
|
56
|
+
* </UiVirtualList>
|
|
57
|
+
*
|
|
58
|
+
* @emits {{ start: number, end: number }} range — The rendered index range changed
|
|
59
|
+
* (end exclusive). Useful for prefetching what is about to be seen.
|
|
60
|
+
* @emits {void} end-reached — Scrolled within `endThreshold` rows of the bottom.
|
|
61
|
+
* @emits {Event} scroll — The list scrolled.
|
|
62
|
+
*
|
|
63
|
+
* @slot default — One row. Scope: `{ item, index }`.
|
|
64
|
+
* @slot empty — Shown when `items` is empty.
|
|
65
|
+
*/
|
|
66
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
67
|
+
|
|
68
|
+
const props = defineProps({
|
|
69
|
+
/**
|
|
70
|
+
* The rows to render.
|
|
71
|
+
* @type {Array<any>}
|
|
72
|
+
* @default []
|
|
73
|
+
*/
|
|
74
|
+
items: { type: Array, default: () => [] },
|
|
75
|
+
/**
|
|
76
|
+
* Height of every row in pixels.
|
|
77
|
+
* @type {number}
|
|
78
|
+
* @default 48
|
|
79
|
+
*/
|
|
80
|
+
itemHeight: { type: Number, default: 48 },
|
|
81
|
+
/**
|
|
82
|
+
* Property used as each row's key, or a function `(item, index) => key`.
|
|
83
|
+
* Falls back to the index when the property is missing.
|
|
84
|
+
* @type {string | Function}
|
|
85
|
+
* @default 'id'
|
|
86
|
+
*/
|
|
87
|
+
itemKey: { type: [String, Function], default: 'id' },
|
|
88
|
+
/**
|
|
89
|
+
* Extra rows rendered above and below the viewport, so fast scrolling does
|
|
90
|
+
* not show blank space.
|
|
91
|
+
* @type {number}
|
|
92
|
+
* @default 8
|
|
93
|
+
*/
|
|
94
|
+
overscan: { type: Number, default: 8 },
|
|
95
|
+
/**
|
|
96
|
+
* Viewport height assumed before the list has been measured (and on the
|
|
97
|
+
* server), in pixels.
|
|
98
|
+
* @type {number}
|
|
99
|
+
* @default 800
|
|
100
|
+
*/
|
|
101
|
+
initialHeight: { type: Number, default: 800 },
|
|
102
|
+
/**
|
|
103
|
+
* How many rows from the bottom `end-reached` fires.
|
|
104
|
+
* @type {number}
|
|
105
|
+
* @default 5
|
|
106
|
+
*/
|
|
107
|
+
endThreshold: { type: Number, default: 5 },
|
|
108
|
+
/**
|
|
109
|
+
* ARIA role of the scroll container. Empty for none.
|
|
110
|
+
* @type {string}
|
|
111
|
+
* @default 'list'
|
|
112
|
+
*/
|
|
113
|
+
role: { type: String, default: 'list' },
|
|
114
|
+
/**
|
|
115
|
+
* ARIA role of each row wrapper. Empty for none.
|
|
116
|
+
* @type {string}
|
|
117
|
+
* @default 'listitem'
|
|
118
|
+
*/
|
|
119
|
+
itemRole: { type: String, default: 'listitem' },
|
|
120
|
+
/**
|
|
121
|
+
* Accessible name for the list.
|
|
122
|
+
* @type {string}
|
|
123
|
+
* @default ''
|
|
124
|
+
*/
|
|
125
|
+
label: { type: String, default: '' },
|
|
126
|
+
/**
|
|
127
|
+
* With `role="listbox"`, announce that several rows can be selected.
|
|
128
|
+
* @type {boolean}
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
multiselectable: { type: Boolean, default: false },
|
|
132
|
+
/**
|
|
133
|
+
* Make the scroll container itself a tab stop, so keyboard users can scroll
|
|
134
|
+
* it. Turn off when your rows manage focus themselves.
|
|
135
|
+
* @type {boolean}
|
|
136
|
+
* @default true
|
|
137
|
+
*/
|
|
138
|
+
focusable: { type: Boolean, default: true },
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const emit = defineEmits(['range', 'end-reached', 'scroll'])
|
|
142
|
+
|
|
143
|
+
const scrollerRef = ref(null)
|
|
144
|
+
const scrollTop = ref(0)
|
|
145
|
+
const viewport = ref(props.initialHeight)
|
|
146
|
+
|
|
147
|
+
const totalHeight = computed(() => props.items.length * props.itemHeight)
|
|
148
|
+
|
|
149
|
+
const range = computed(() => {
|
|
150
|
+
const first = Math.floor(scrollTop.value / props.itemHeight)
|
|
151
|
+
const visible = Math.ceil(viewport.value / props.itemHeight) + 1
|
|
152
|
+
const start = Math.max(0, first - props.overscan)
|
|
153
|
+
const end = Math.min(props.items.length, first + visible + props.overscan)
|
|
154
|
+
return { start, end }
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const keyOf = (item, index) => {
|
|
158
|
+
if (typeof props.itemKey === 'function') return props.itemKey(item, index)
|
|
159
|
+
const key = item && typeof item === 'object' ? item[props.itemKey] : undefined
|
|
160
|
+
return key ?? index
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const visibleRows = computed(() => {
|
|
164
|
+
const rows = []
|
|
165
|
+
for (let index = range.value.start; index < range.value.end; index++) {
|
|
166
|
+
const item = props.items[index]
|
|
167
|
+
rows.push({ item, index, key: keyOf(item, index) })
|
|
168
|
+
}
|
|
169
|
+
return rows
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
watch(range, (next, previous) => {
|
|
173
|
+
if (previous && next.start === previous.start && next.end === previous.end) return
|
|
174
|
+
emit('range', { ...next })
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// ── End detection ──
|
|
178
|
+
// Fires once per arrival at the bottom; scrolling away and back re-arms it.
|
|
179
|
+
let endArmed = true
|
|
180
|
+
const checkEnd = () => {
|
|
181
|
+
const remaining =
|
|
182
|
+
props.items.length - Math.ceil((scrollTop.value + viewport.value) / props.itemHeight)
|
|
183
|
+
if (remaining <= props.endThreshold) {
|
|
184
|
+
if (endArmed && props.items.length > 0) {
|
|
185
|
+
endArmed = false
|
|
186
|
+
emit('end-reached')
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
endArmed = true
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// New items arriving (a page loaded) re-arms the trigger.
|
|
194
|
+
watch(
|
|
195
|
+
() => props.items.length,
|
|
196
|
+
() => {
|
|
197
|
+
endArmed = true
|
|
198
|
+
checkEnd()
|
|
199
|
+
},
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
function onScroll(event) {
|
|
203
|
+
scrollTop.value = event.target.scrollTop
|
|
204
|
+
checkEnd()
|
|
205
|
+
emit('scroll', event)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Scroll so the row at `index` is visible.
|
|
210
|
+
*
|
|
211
|
+
* @param {number} index
|
|
212
|
+
* @param {'auto' | 'start' | 'center' | 'end'} [align='auto'] `auto` scrolls
|
|
213
|
+
* only as far as needed, and not at all if the row is already in view.
|
|
214
|
+
*/
|
|
215
|
+
function scrollToIndex(index, align = 'auto') {
|
|
216
|
+
const el = scrollerRef.value
|
|
217
|
+
if (!el || index < 0 || index >= props.items.length) return
|
|
218
|
+
const top = index * props.itemHeight
|
|
219
|
+
const bottom = top + props.itemHeight
|
|
220
|
+
const view = el.clientHeight
|
|
221
|
+
let target = null
|
|
222
|
+
if (align === 'start') target = top
|
|
223
|
+
else if (align === 'end') target = bottom - view
|
|
224
|
+
else if (align === 'center') target = top - (view - props.itemHeight) / 2
|
|
225
|
+
else if (top < el.scrollTop) target = top
|
|
226
|
+
else if (bottom > el.scrollTop + view) target = bottom - view
|
|
227
|
+
if (target === null) return
|
|
228
|
+
el.scrollTop = Math.max(0, target)
|
|
229
|
+
scrollTop.value = el.scrollTop
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
defineExpose({ scrollToIndex, scrollerRef })
|
|
233
|
+
|
|
234
|
+
// ── Measure the viewport ──
|
|
235
|
+
let observer = null
|
|
236
|
+
onMounted(() => {
|
|
237
|
+
const el = scrollerRef.value
|
|
238
|
+
if (!el) return
|
|
239
|
+
const measure = () => {
|
|
240
|
+
viewport.value = el.clientHeight || props.initialHeight
|
|
241
|
+
checkEnd()
|
|
242
|
+
}
|
|
243
|
+
measure()
|
|
244
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
245
|
+
observer = new ResizeObserver(measure)
|
|
246
|
+
observer.observe(el)
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
250
|
+
</script>
|
package/src/components/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* consumers; `scripts/verify.mjs` keeps the two in sync.
|
|
11
11
|
*/
|
|
12
12
|
import Alert from './Alert.vue'
|
|
13
|
+
import AppShell from './AppShell.vue'
|
|
13
14
|
import Avatar from './Avatar.vue'
|
|
14
15
|
import Badge from './Badge.vue'
|
|
15
16
|
import Banner from './Banner.vue'
|
|
@@ -18,11 +19,14 @@ import Button from './Button.vue'
|
|
|
18
19
|
import Card from './Card.vue'
|
|
19
20
|
import Checkbox from './Checkbox.vue'
|
|
20
21
|
import CodeBlock from './CodeBlock.vue'
|
|
22
|
+
import CopyField from './CopyField.vue'
|
|
23
|
+
import DescriptionList from './DescriptionList.vue'
|
|
21
24
|
import Divider from './Divider.vue'
|
|
22
25
|
import Dropdown from './Dropdown.vue'
|
|
23
26
|
import DropdownItem from './DropdownItem.vue'
|
|
24
27
|
import DropdownRow from './DropdownRow.vue'
|
|
25
28
|
import DropdownSubmenu from './DropdownSubmenu.vue'
|
|
29
|
+
import EmptyState from './EmptyState.vue'
|
|
26
30
|
import FileInput from './FileInput.vue'
|
|
27
31
|
import FormField from './FormField.vue'
|
|
28
32
|
import IconTile from './IconTile.vue'
|
|
@@ -32,6 +36,8 @@ import ListMenu from './ListMenu.vue'
|
|
|
32
36
|
import ListMenuItem from './ListMenuItem.vue'
|
|
33
37
|
import Modal from './Modal.vue'
|
|
34
38
|
import Numpad from './Numpad.vue'
|
|
39
|
+
import PageHeader from './PageHeader.vue'
|
|
40
|
+
import Pagination from './Pagination.vue'
|
|
35
41
|
import Popup from './Popup.vue'
|
|
36
42
|
import ProgressBar from './ProgressBar.vue'
|
|
37
43
|
import Prompt from './Prompt.vue'
|
|
@@ -39,18 +45,28 @@ import Radio from './Radio.vue'
|
|
|
39
45
|
import SectionHeading from './SectionHeading.vue'
|
|
40
46
|
import Segmented from './Segmented.vue'
|
|
41
47
|
import Select from './Select.vue'
|
|
48
|
+
import Sidebar from './Sidebar.vue'
|
|
49
|
+
import SidebarGroup from './SidebarGroup.vue'
|
|
50
|
+
import SidebarItem from './SidebarItem.vue'
|
|
51
|
+
import Skeleton from './Skeleton.vue'
|
|
42
52
|
import Slider from './Slider.vue'
|
|
43
53
|
import Spinner from './Spinner.vue'
|
|
54
|
+
import SplitPane from './SplitPane.vue'
|
|
55
|
+
import StatCard from './StatCard.vue'
|
|
44
56
|
import Stepper from './Stepper.vue'
|
|
45
57
|
import Table from './Table.vue'
|
|
58
|
+
import Tabs from './Tabs.vue'
|
|
46
59
|
import ThemeToggle from './ThemeToggle.vue'
|
|
47
60
|
import Toast from './Toast.vue'
|
|
48
61
|
import Toggle from './Toggle.vue'
|
|
49
62
|
import Tooltip from './Tooltip.vue'
|
|
63
|
+
import Tree from './Tree.vue'
|
|
64
|
+
import VirtualList from './VirtualList.vue'
|
|
50
65
|
import Icon from '../icons/Icon.vue'
|
|
51
66
|
|
|
52
67
|
export {
|
|
53
68
|
Alert as UiAlert,
|
|
69
|
+
AppShell as UiAppShell,
|
|
54
70
|
Avatar as UiAvatar,
|
|
55
71
|
Badge as UiBadge,
|
|
56
72
|
Banner as UiBanner,
|
|
@@ -59,11 +75,14 @@ export {
|
|
|
59
75
|
Card as UiCard,
|
|
60
76
|
Checkbox as UiCheckbox,
|
|
61
77
|
CodeBlock as UiCodeBlock,
|
|
78
|
+
CopyField as UiCopyField,
|
|
79
|
+
DescriptionList as UiDescriptionList,
|
|
62
80
|
Divider as UiDivider,
|
|
63
81
|
Dropdown as UiDropdown,
|
|
64
82
|
DropdownItem as UiDropdownItem,
|
|
65
83
|
DropdownRow as UiDropdownRow,
|
|
66
84
|
DropdownSubmenu as UiDropdownSubmenu,
|
|
85
|
+
EmptyState as UiEmptyState,
|
|
67
86
|
FileInput as UiFileInput,
|
|
68
87
|
FormField as UiFormField,
|
|
69
88
|
IconTile as UiIconTile,
|
|
@@ -73,6 +92,8 @@ export {
|
|
|
73
92
|
ListMenuItem as UiListMenuItem,
|
|
74
93
|
Modal as UiModal,
|
|
75
94
|
Numpad as UiNumpad,
|
|
95
|
+
PageHeader as UiPageHeader,
|
|
96
|
+
Pagination as UiPagination,
|
|
76
97
|
Popup as UiPopup,
|
|
77
98
|
ProgressBar as UiProgressBar,
|
|
78
99
|
Prompt as UiPrompt,
|
|
@@ -80,24 +101,29 @@ export {
|
|
|
80
101
|
SectionHeading as UiSectionHeading,
|
|
81
102
|
Segmented as UiSegmented,
|
|
82
103
|
Select as UiSelect,
|
|
104
|
+
Sidebar as UiSidebar,
|
|
105
|
+
SidebarGroup as UiSidebarGroup,
|
|
106
|
+
SidebarItem as UiSidebarItem,
|
|
107
|
+
Skeleton as UiSkeleton,
|
|
83
108
|
Slider as UiSlider,
|
|
84
109
|
Spinner as UiSpinner,
|
|
110
|
+
SplitPane as UiSplitPane,
|
|
111
|
+
StatCard as UiStatCard,
|
|
85
112
|
Stepper as UiStepper,
|
|
86
113
|
Table as UiTable,
|
|
114
|
+
Tabs as UiTabs,
|
|
87
115
|
ThemeToggle as UiThemeToggle,
|
|
88
116
|
Toast as UiToast,
|
|
89
117
|
Toggle as UiToggle,
|
|
90
118
|
Tooltip as UiTooltip,
|
|
119
|
+
Tree as UiTree,
|
|
120
|
+
VirtualList as UiVirtualList,
|
|
91
121
|
Icon as UiIcon,
|
|
92
122
|
}
|
|
93
123
|
|
|
94
|
-
/**
|
|
95
|
-
* Base-name -> component map, used by the Vue plugin to register everything
|
|
96
|
-
* under whatever prefix the host chose.
|
|
97
|
-
* @type {Record<string, import('vue').Component>}
|
|
98
|
-
*/
|
|
99
124
|
export const components = {
|
|
100
125
|
Alert,
|
|
126
|
+
AppShell,
|
|
101
127
|
Avatar,
|
|
102
128
|
Badge,
|
|
103
129
|
Banner,
|
|
@@ -106,11 +132,14 @@ export const components = {
|
|
|
106
132
|
Card,
|
|
107
133
|
Checkbox,
|
|
108
134
|
CodeBlock,
|
|
135
|
+
CopyField,
|
|
136
|
+
DescriptionList,
|
|
109
137
|
Divider,
|
|
110
138
|
Dropdown,
|
|
111
139
|
DropdownItem,
|
|
112
140
|
DropdownRow,
|
|
113
141
|
DropdownSubmenu,
|
|
142
|
+
EmptyState,
|
|
114
143
|
FileInput,
|
|
115
144
|
FormField,
|
|
116
145
|
IconTile,
|
|
@@ -120,6 +149,8 @@ export const components = {
|
|
|
120
149
|
ListMenuItem,
|
|
121
150
|
Modal,
|
|
122
151
|
Numpad,
|
|
152
|
+
PageHeader,
|
|
153
|
+
Pagination,
|
|
123
154
|
Popup,
|
|
124
155
|
ProgressBar,
|
|
125
156
|
Prompt,
|
|
@@ -127,13 +158,21 @@ export const components = {
|
|
|
127
158
|
SectionHeading,
|
|
128
159
|
Segmented,
|
|
129
160
|
Select,
|
|
161
|
+
Sidebar,
|
|
162
|
+
SidebarGroup,
|
|
163
|
+
SidebarItem,
|
|
164
|
+
Skeleton,
|
|
130
165
|
Slider,
|
|
131
166
|
Spinner,
|
|
167
|
+
SplitPane,
|
|
168
|
+
StatCard,
|
|
132
169
|
Stepper,
|
|
133
170
|
Table,
|
|
171
|
+
Tabs,
|
|
134
172
|
ThemeToggle,
|
|
135
173
|
Toast,
|
|
136
174
|
Toggle,
|
|
137
175
|
Tooltip,
|
|
138
|
-
|
|
176
|
+
Tree,
|
|
177
|
+
VirtualList,
|
|
139
178
|
}
|
package/src/icons/mdi.js
CHANGED
|
@@ -21,6 +21,8 @@ export const mdiPaths = {
|
|
|
21
21
|
'account-group': "M12 5.5A3.5 3.5 0 0 1 15.5 9a3.5 3.5 0 0 1-3.5 3.5A3.5 3.5 0 0 1 8.5 9A3.5 3.5 0 0 1 12 5.5M5 8c.56 0 1.08.15 1.53.42c-.15 1.43.27 2.85 1.13 3.96C7.16 13.34 6.16 14 5 14a3 3 0 0 1-3-3a3 3 0 0 1 3-3m14 0a3 3 0 0 1 3 3a3 3 0 0 1-3 3c-1.16 0-2.16-.66-2.66-1.62a5.54 5.54 0 0 0 1.13-3.96c.45-.27.97-.42 1.53-.42M5.5 18.25c0-2.07 2.91-3.75 6.5-3.75s6.5 1.68 6.5 3.75V20h-13zM0 20v-1.5c0-1.39 1.89-2.56 4.45-2.9c-.59.68-.95 1.62-.95 2.65V20zm24 0h-3.5v-1.75c0-1.03-.36-1.97-.95-2.65c2.56.34 4.45 1.51 4.45 2.9z",
|
|
22
22
|
'alert-circle': "M13 13h-2V7h2m0 10h-2v-2h2M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2",
|
|
23
23
|
'alert-outline': "M12 2L1 21h22M12 6l7.53 13H4.47M11 10v4h2v-4m-2 6v2h2v-2",
|
|
24
|
+
'arrow-down': "M11 4h2v12l5.5-5.5l1.42 1.42L12 19.84l-7.92-7.92L5.5 10.5L11 16z",
|
|
25
|
+
'arrow-up': "M13 20h-2V8l-5.5 5.5l-1.42-1.42L12 4.16l7.92 7.92l-1.42 1.42L13 8z",
|
|
24
26
|
'backspace-outline': "M19 15.59L17.59 17L14 13.41L10.41 17L9 15.59L12.59 12L9 8.41L10.41 7L14 10.59L17.59 7L19 8.41L15.41 12zM22 3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H7c-.69 0-1.23-.36-1.59-.89L0 12l5.41-8.12C5.77 3.35 6.31 3 7 3zm0 2H7l-4.72 7L7 19h15z",
|
|
25
27
|
'check': "M21 7L9 19l-5.5-5.5l1.41-1.41L9 16.17L19.59 5.59z",
|
|
26
28
|
'check-circle': "M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10s10-4.5 10-10S17.5 2 12 2m-2 15l-5-5l1.41-1.41L10 14.17l7.59-7.59L19 8z",
|
|
@@ -38,13 +40,19 @@ export const mdiPaths = {
|
|
|
38
40
|
'eraser': "m16.24 3.56l4.95 4.94c.78.79.78 2.05 0 2.84L12 20.53a4.01 4.01 0 0 1-5.66 0L2.81 17c-.78-.79-.78-2.05 0-2.84l10.6-10.6c.79-.78 2.05-.78 2.83 0M4.22 15.58l3.54 3.53c.78.79 2.04.79 2.83 0l3.53-3.53l-4.95-4.95z",
|
|
39
41
|
'eye-off-outline': "M2 5.27L3.28 4L20 20.72L18.73 22l-3.08-3.08c-1.15.38-2.37.58-3.65.58c-5 0-9.27-3.11-11-7.5c.69-1.76 1.79-3.31 3.19-4.54zM12 9a3 3 0 0 1 3 3a3 3 0 0 1-.17 1L11 9.17A3 3 0 0 1 12 9m0-4.5c5 0 9.27 3.11 11 7.5a11.8 11.8 0 0 1-4 5.19l-1.42-1.43A9.86 9.86 0 0 0 20.82 12A9.82 9.82 0 0 0 12 6.5c-1.09 0-2.16.18-3.16.5L7.3 5.47c1.44-.62 3.03-.97 4.7-.97M3.18 12A9.82 9.82 0 0 0 12 17.5c.69 0 1.37-.07 2-.21L11.72 15A3.064 3.064 0 0 1 9 12.28L5.6 8.87c-.99.85-1.82 1.91-2.42 3.13",
|
|
40
42
|
'eye-outline': "M12 9a3 3 0 0 1 3 3a3 3 0 0 1-3 3a3 3 0 0 1-3-3a3 3 0 0 1 3-3m0-4.5c5 0 9.27 3.11 11 7.5c-1.73 4.39-6 7.5-11 7.5S2.73 16.39 1 12c1.73-4.39 6-7.5 11-7.5M3.18 12a9.821 9.821 0 0 0 17.64 0a9.821 9.821 0 0 0-17.64 0",
|
|
43
|
+
'file-document-outline': "M6 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm0 2h7v5h5v11H6zm2 8v2h8v-2zm0 4v2h5v-2z",
|
|
44
|
+
'folder-outline': "M20 18H4V8h16m0-2h-8l-2-2H4c-1.11 0-2 .89-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2",
|
|
41
45
|
'format-bold': "M13.5 15.5H10v-3h3.5A1.5 1.5 0 0 1 15 14a1.5 1.5 0 0 1-1.5 1.5m-3.5-9h3A1.5 1.5 0 0 1 14.5 8A1.5 1.5 0 0 1 13 9.5h-3m5.6 1.29c.97-.68 1.65-1.79 1.65-2.79c0-2.26-1.75-4-4-4H7v14h7.04c2.1 0 3.71-1.7 3.71-3.79c0-1.52-.86-2.82-2.15-3.42",
|
|
42
46
|
'format-italic': "M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z",
|
|
43
47
|
'format-text': "m18.5 4l1.16 4.35l-.96.26c-.45-.87-.91-1.74-1.44-2.18C16.73 6 16.11 6 15.5 6H13v10.5c0 .5 0 1 .33 1.25c.34.25 1 .25 1.67.25v1H9v-1c.67 0 1.33 0 1.67-.25c.33-.25.33-.75.33-1.25V6H8.5c-.61 0-1.23 0-1.76.43c-.53.44-.99 1.31-1.44 2.18l-.96-.26L5.5 4z",
|
|
48
|
+
'inbox': "M19 15h-4a3 3 0 0 1-3 3a3 3 0 0 1-3-3H5V5h14m0-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2",
|
|
49
|
+
'inbox-outline': "M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2M5 19v-2h3.13a4.13 4.13 0 0 0 1.27 2m9.6 0h-4.4a4.13 4.13 0 0 0 1.27-2H19m0-2h-5v1a2 2 0 0 1-4 0v-1H5V5h14Z",
|
|
44
50
|
'information': "M13 9h-2V7h2m0 10h-2v-6h2m-1-9A10 10 0 0 0 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2",
|
|
51
|
+
'lan-connect': "M4 1c-1.11 0-2 .89-2 2v4c0 1.11.89 2 2 2H1v2h12V9h-3c1.11 0 2-.89 2-2V3c0-1.11-.89-2-2-2zm0 2h6v4H4zM3 13v7h7v-2H5v-5zm11 0c-1.11 0-2 .89-2 2v4c0 1.11.89 2 2 2h-3v2h12v-2h-3c1.11 0 2-.89 2-2v-4c0-1.11-.89-2-2-2zm0 2h6v4h-6z",
|
|
45
52
|
'loading': "M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8",
|
|
46
53
|
'lock': "M12 17a2 2 0 0 0 2-2a2 2 0 0 0-2-2a2 2 0 0 0-2 2a2 2 0 0 0 2 2m6-9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2h1V6a5 5 0 0 1 5-5a5 5 0 0 1 5 5v2zm-6-5a3 3 0 0 0-3 3v2h6V6a3 3 0 0 0-3-3",
|
|
47
54
|
'logout': "m17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5M4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4z",
|
|
55
|
+
'menu': "M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z",
|
|
48
56
|
'minus': "M19 13H5v-2h14z",
|
|
49
57
|
'minus-circle-outline': "M12 20c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2M7 13h10v-2H7",
|
|
50
58
|
'note-text-outline': "M15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9zm4 16H5V5h9v5h5m-2 4H7v-2h10m-3 5H7v-2h7",
|
|
@@ -57,6 +65,10 @@ export const mdiPaths = {
|
|
|
57
65
|
'translate': "m12.87 15.07l-2.54-2.51l.03-.03A17.5 17.5 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35C8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5l3.11 3.11zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2zm-2.62 7l1.62-4.33L19.12 17z",
|
|
58
66
|
'trash-can': "M9 3v1H4v2h1v13a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6h1V4h-5V3zm0 5h2v9H9zm4 0h2v9h-2z",
|
|
59
67
|
'trash-can-outline': "M9 3v1H4v2h1v13a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6h1V4h-5V3zM7 6h10v13H7zm2 2v9h2V8zm4 0v9h2V8z",
|
|
68
|
+
'trending-down': "m16 18l2.29-2.29l-4.88-4.88l-4 4L2 7.41L3.41 6l6 6l4-4l6.3 6.29L22 12v6z",
|
|
69
|
+
'trending-neutral': "m22 12l-4-4v3H3v2h15v3z",
|
|
70
|
+
'trending-up': "m16 6l2.29 2.29l-4.88 4.88l-4-4L2 16.59L3.41 18l6-6l4 4l6.3-6.29L22 12V6z",
|
|
71
|
+
'unfold-more-horizontal': "M12 18.17L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15M12 5.83L15.17 9l1.41-1.41L12 3L7.41 7.59L8.83 9z",
|
|
60
72
|
'view-grid': "M3 11h8V3H3m0 18h8v-8H3m10 8h8v-8h-8m0-10v8h8V3",
|
|
61
73
|
'view-list': "M9 5v4h12V5M9 19h12v-4H9m0-1h12v-4H9M4 9h4V5H4m0 14h4v-4H4m0-1h4v-4H4z",
|
|
62
74
|
'weather-night': "m17.75 4.09l-2.53 1.94l.91 3.06l-2.63-1.81l-2.63 1.81l.91-3.06l-2.53-1.94L12.44 4l1.06-3l1.06 3zm3.5 6.91l-1.64 1.25l.59 1.98l-1.7-1.17l-1.7 1.17l.59-1.98L15.75 11l2.06-.05L18.5 9l.69 1.95zm-2.28 4.95c.83-.08 1.72 1.1 1.19 1.85c-.32.45-.66.87-1.08 1.27C15.17 23 8.84 23 4.94 19.07c-3.91-3.9-3.91-10.24 0-14.14c.4-.4.82-.76 1.27-1.08c.75-.53 1.93.36 1.85 1.19c-.27 2.86.69 5.83 2.89 8.02a9.96 9.96 0 0 0 8.02 2.89m-1.64 2.02a12.08 12.08 0 0 1-7.8-3.47c-2.17-2.19-3.33-5-3.49-7.82c-2.81 3.14-2.7 7.96.31 10.98c3.02 3.01 7.84 3.12 10.98.31",
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus management for modal surfaces (`UiModal`, and anything built on it).
|
|
3
|
+
*
|
|
4
|
+
* A modal dialog has three keyboard obligations under the WAI-ARIA dialog
|
|
5
|
+
* pattern, and all three are easy to get subtly wrong:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Move focus in** when it opens — otherwise a keyboard user is left on
|
|
8
|
+
* the button behind the backdrop, and a screen reader never announces the
|
|
9
|
+
* dialog.
|
|
10
|
+
* 2. **Keep focus in** while it is open — Tab from the last control wraps to
|
|
11
|
+
* the first, Shift+Tab from the first wraps to the last.
|
|
12
|
+
* 3. **Put focus back** when it closes, on whatever opened it.
|
|
13
|
+
*
|
|
14
|
+
* Escape also closes the dialog, unless the caller says otherwise.
|
|
15
|
+
*
|
|
16
|
+
* Dialogs can stack (a confirmation over a settings modal), and only the top
|
|
17
|
+
* one may react to Tab or Escape — so every trap registers on a module-level
|
|
18
|
+
* stack and a single listener dispatches to whichever is on top.
|
|
19
|
+
*
|
|
20
|
+
* That listener is on `window`, not `document`, deliberately: `window` is the
|
|
21
|
+
* last stop of a bubbling keydown, so a control inside the dialog that closes
|
|
22
|
+
* itself on Escape (an open `UiDropdown`, `UiSelect`'s search field) runs first
|
|
23
|
+
* and calls `preventDefault()`, and the dialog then leaves the key alone. One
|
|
24
|
+
* Escape closes one thing.
|
|
25
|
+
*
|
|
26
|
+
* Initial focus is only moved if nothing inside the container already has it.
|
|
27
|
+
* That lets a wrapper such as `UiPrompt` focus its confirm button without the
|
|
28
|
+
* trap then stealing focus back to the first control.
|
|
29
|
+
*
|
|
30
|
+
* SSR-safe: nothing touches `document` until the trap activates, which only
|
|
31
|
+
* happens in the browser.
|
|
32
|
+
*/
|
|
33
|
+
import { nextTick, onBeforeUnmount, watch } from 'vue'
|
|
34
|
+
|
|
35
|
+
// ── Focusable elements ───────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
const FOCUSABLE = [
|
|
38
|
+
'a[href]',
|
|
39
|
+
'area[href]',
|
|
40
|
+
'button:not([disabled])',
|
|
41
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
42
|
+
'select:not([disabled])',
|
|
43
|
+
'textarea:not([disabled])',
|
|
44
|
+
'iframe',
|
|
45
|
+
'audio[controls]',
|
|
46
|
+
'video[controls]',
|
|
47
|
+
'[contenteditable]:not([contenteditable="false"])',
|
|
48
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
49
|
+
].join(',')
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Tabbable descendants of `container`, in DOM order, skipping anything hidden.
|
|
53
|
+
*
|
|
54
|
+
* @param {HTMLElement} container
|
|
55
|
+
* @returns {HTMLElement[]}
|
|
56
|
+
*/
|
|
57
|
+
export function tabbableIn(container) {
|
|
58
|
+
if (!container) return []
|
|
59
|
+
return [...container.querySelectorAll(FOCUSABLE)].filter(
|
|
60
|
+
(el) => !el.closest('[inert]') && el.getClientRects().length > 0,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── The stack of active traps ────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
/** @type {Array<{ container: () => HTMLElement | null, onEscape: (() => void) | null }>} */
|
|
67
|
+
const stack = []
|
|
68
|
+
let listening = false
|
|
69
|
+
|
|
70
|
+
function onWindowKeydown(event) {
|
|
71
|
+
const top = stack[stack.length - 1]
|
|
72
|
+
if (!top) return
|
|
73
|
+
const container = top.container()
|
|
74
|
+
if (!container) return
|
|
75
|
+
|
|
76
|
+
if (event.key === 'Escape') {
|
|
77
|
+
// A control inside the dialog (an open select, a search field) may have
|
|
78
|
+
// handled Escape already; respect that rather than closing over it.
|
|
79
|
+
if (event.defaultPrevented || !top.onEscape) return
|
|
80
|
+
event.preventDefault()
|
|
81
|
+
top.onEscape()
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (event.key !== 'Tab') return
|
|
86
|
+
const items = tabbableIn(container)
|
|
87
|
+
if (items.length === 0) {
|
|
88
|
+
event.preventDefault()
|
|
89
|
+
container.focus()
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
const first = items[0]
|
|
93
|
+
const last = items[items.length - 1]
|
|
94
|
+
const active = document.activeElement
|
|
95
|
+
const inside = container.contains(active)
|
|
96
|
+
if (event.shiftKey && (active === first || !inside)) {
|
|
97
|
+
event.preventDefault()
|
|
98
|
+
last.focus()
|
|
99
|
+
} else if (!event.shiftKey && (active === last || !inside)) {
|
|
100
|
+
event.preventDefault()
|
|
101
|
+
first.focus()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function push(entry) {
|
|
106
|
+
stack.push(entry)
|
|
107
|
+
if (!listening) {
|
|
108
|
+
window.addEventListener('keydown', onWindowKeydown)
|
|
109
|
+
listening = true
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function remove(entry) {
|
|
114
|
+
const index = stack.indexOf(entry)
|
|
115
|
+
if (index !== -1) stack.splice(index, 1)
|
|
116
|
+
if (stack.length === 0 && listening) {
|
|
117
|
+
window.removeEventListener('keydown', onWindowKeydown)
|
|
118
|
+
listening = false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ── Composable ───────────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Trap focus inside an element while `active()` is true.
|
|
126
|
+
*
|
|
127
|
+
* @param {() => HTMLElement | null | undefined} container Getter for the
|
|
128
|
+
* element focus is confined to. It must itself be focusable
|
|
129
|
+
* (`tabindex="-1"`) so there is somewhere to land when it has no controls.
|
|
130
|
+
* @param {object} options
|
|
131
|
+
* @param {() => boolean} options.active Whether the trap is engaged.
|
|
132
|
+
* @param {(() => boolean) | boolean} [options.escape] Whether Escape closes.
|
|
133
|
+
* @param {() => void} [options.onEscape] Called when Escape should close.
|
|
134
|
+
*/
|
|
135
|
+
export function useFocusTrap(container, { active, escape = true, onEscape }) {
|
|
136
|
+
const entry = {
|
|
137
|
+
container: () => container() ?? null,
|
|
138
|
+
onEscape: null,
|
|
139
|
+
}
|
|
140
|
+
let returnTo = null
|
|
141
|
+
let engaged = false
|
|
142
|
+
// The element as it was while open. A template ref is cleared the moment its
|
|
143
|
+
// owner starts leaving, but a Transition keeps the element (and the focus
|
|
144
|
+
// inside it) on screen for the length of the leave animation.
|
|
145
|
+
let lastEl = null
|
|
146
|
+
|
|
147
|
+
const engage = () => {
|
|
148
|
+
if (engaged || typeof document === 'undefined') return
|
|
149
|
+
engaged = true
|
|
150
|
+
returnTo = document.activeElement
|
|
151
|
+
entry.onEscape = () => {
|
|
152
|
+
const allowed = typeof escape === 'function' ? escape() : escape
|
|
153
|
+
if (allowed) onEscape?.()
|
|
154
|
+
}
|
|
155
|
+
push(entry)
|
|
156
|
+
nextTick(() => {
|
|
157
|
+
const el = entry.container()
|
|
158
|
+
if (el) lastEl = el
|
|
159
|
+
if (!el || el.contains(document.activeElement)) return
|
|
160
|
+
const [first] = tabbableIn(el)
|
|
161
|
+
;(first ?? el).focus({ preventScroll: true })
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const release = () => {
|
|
166
|
+
if (!engaged) return
|
|
167
|
+
engaged = false
|
|
168
|
+
remove(entry)
|
|
169
|
+
const target = returnTo
|
|
170
|
+
const closing = entry.container() ?? lastEl
|
|
171
|
+
returnTo = null
|
|
172
|
+
lastEl = null
|
|
173
|
+
// Only restore if focus is still lost inside the closing surface or on the
|
|
174
|
+
// body — never yank it away from somewhere the user has since moved to.
|
|
175
|
+
if (target && typeof target.focus === 'function' && document.contains(target)) {
|
|
176
|
+
const current = document.activeElement
|
|
177
|
+
if (!current || current === document.body || closing?.contains(current)) {
|
|
178
|
+
target.focus({ preventScroll: true })
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
watch(active, (on) => (on ? engage() : release()), { immediate: true, flush: 'post' })
|
|
184
|
+
onBeforeUnmount(release)
|
|
185
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { inject } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Link between UiFormField and the control inside it.
|
|
5
|
+
*
|
|
6
|
+
* UiFormField provides the id its `<label for>` points at, plus the ids of its
|
|
7
|
+
* hint and error text; each form control injects them and sets `id`,
|
|
8
|
+
* `aria-describedby` and `aria-invalid` on its real control element. That is
|
|
9
|
+
* what makes the label, hint and error reach assistive technology.
|
|
10
|
+
*/
|
|
11
|
+
export const FORM_FIELD_KEY = 'numori-ui:form-field'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @returns {null | {
|
|
15
|
+
* controlId: import('vue').ComputedRef<string>,
|
|
16
|
+
* labelId: string,
|
|
17
|
+
* describedBy: import('vue').ComputedRef<string | undefined>,
|
|
18
|
+
* invalid: import('vue').ComputedRef<boolean>,
|
|
19
|
+
* }}
|
|
20
|
+
*/
|
|
21
|
+
export function useFormField() {
|
|
22
|
+
return inject(FORM_FIELD_KEY, null)
|
|
23
|
+
}
|