numori-ui 0.5.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +9 -1
  3. package/dist/components/Avatar.js +71 -19
  4. package/dist/components/Avatar.js.map +1 -1
  5. package/dist/components/Dropdown.js +3 -1
  6. package/dist/components/Dropdown.js.map +1 -1
  7. package/dist/components/Modal.js +61 -4
  8. package/dist/components/Modal.js.map +1 -1
  9. package/dist/components/Prompt.js +11 -6
  10. package/dist/components/Prompt.js.map +1 -1
  11. package/dist/components/Select.js +1 -1
  12. package/dist/components/Select.js.map +1 -1
  13. package/dist/components/Skeleton.js +122 -0
  14. package/dist/components/Skeleton.js.map +1 -0
  15. package/dist/components/SplitPane.js +264 -0
  16. package/dist/components/SplitPane.js.map +1 -0
  17. package/dist/components/Tree.js +417 -0
  18. package/dist/components/Tree.js.map +1 -0
  19. package/dist/components/VirtualList.js +292 -0
  20. package/dist/components/VirtualList.js.map +1 -0
  21. package/dist/components/index.js +29 -22
  22. package/dist/components/index.js.map +1 -1
  23. package/dist/icons/mdi.js +2 -0
  24. package/dist/icons/mdi.js.map +1 -1
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +15 -11
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/focusTrap.js +163 -0
  29. package/dist/internal/focusTrap.js.map +1 -0
  30. package/dist/manifest.js +5 -1
  31. package/dist/manifest.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/components/Avatar.vue +69 -18
  34. package/src/components/Dropdown.vue +4 -1
  35. package/src/components/Modal.vue +51 -3
  36. package/src/components/Prompt.vue +14 -3
  37. package/src/components/Select.vue +1 -1
  38. package/src/components/Skeleton.vue +91 -0
  39. package/src/components/SplitPane.vue +264 -0
  40. package/src/components/Tree.vue +428 -0
  41. package/src/components/VirtualList.vue +250 -0
  42. package/src/components/index.js +12 -1
  43. package/src/icons/mdi.js +2 -0
  44. package/src/internal/focusTrap.js +185 -0
  45. package/src/manifest.js +4 -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>
@@ -48,8 +48,10 @@ import Select from './Select.vue'
48
48
  import Sidebar from './Sidebar.vue'
49
49
  import SidebarGroup from './SidebarGroup.vue'
50
50
  import SidebarItem from './SidebarItem.vue'
51
+ import Skeleton from './Skeleton.vue'
51
52
  import Slider from './Slider.vue'
52
53
  import Spinner from './Spinner.vue'
54
+ import SplitPane from './SplitPane.vue'
53
55
  import StatCard from './StatCard.vue'
54
56
  import Stepper from './Stepper.vue'
55
57
  import Table from './Table.vue'
@@ -58,6 +60,8 @@ import ThemeToggle from './ThemeToggle.vue'
58
60
  import Toast from './Toast.vue'
59
61
  import Toggle from './Toggle.vue'
60
62
  import Tooltip from './Tooltip.vue'
63
+ import Tree from './Tree.vue'
64
+ import VirtualList from './VirtualList.vue'
61
65
  import Icon from '../icons/Icon.vue'
62
66
 
63
67
  export {
@@ -100,8 +104,10 @@ export {
100
104
  Sidebar as UiSidebar,
101
105
  SidebarGroup as UiSidebarGroup,
102
106
  SidebarItem as UiSidebarItem,
107
+ Skeleton as UiSkeleton,
103
108
  Slider as UiSlider,
104
109
  Spinner as UiSpinner,
110
+ SplitPane as UiSplitPane,
105
111
  StatCard as UiStatCard,
106
112
  Stepper as UiStepper,
107
113
  Table as UiTable,
@@ -110,6 +116,8 @@ export {
110
116
  Toast as UiToast,
111
117
  Toggle as UiToggle,
112
118
  Tooltip as UiTooltip,
119
+ Tree as UiTree,
120
+ VirtualList as UiVirtualList,
113
121
  Icon as UiIcon,
114
122
  }
115
123
 
@@ -153,8 +161,10 @@ export const components = {
153
161
  Sidebar,
154
162
  SidebarGroup,
155
163
  SidebarItem,
164
+ Skeleton,
156
165
  Slider,
157
166
  Spinner,
167
+ SplitPane,
158
168
  StatCard,
159
169
  Stepper,
160
170
  Table,
@@ -163,5 +173,6 @@ export const components = {
163
173
  Toast,
164
174
  Toggle,
165
175
  Tooltip,
166
- Icon,
176
+ Tree,
177
+ VirtualList,
167
178
  }
package/src/icons/mdi.js CHANGED
@@ -41,9 +41,11 @@ export const mdiPaths = {
41
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",
42
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
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",
44
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",
45
46
  'format-italic': "M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z",
46
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",
47
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",
48
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",
49
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",
@@ -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
+ }
package/src/manifest.js CHANGED
@@ -59,8 +59,10 @@ export const COMPONENT_NAMES = [
59
59
  'Sidebar',
60
60
  'SidebarGroup',
61
61
  'SidebarItem',
62
+ 'Skeleton',
62
63
  'Slider',
63
64
  'Spinner',
65
+ 'SplitPane',
64
66
  'StatCard',
65
67
  'Stepper',
66
68
  'Table',
@@ -69,6 +71,8 @@ export const COMPONENT_NAMES = [
69
71
  'Toast',
70
72
  'Toggle',
71
73
  'Tooltip',
74
+ 'Tree',
75
+ 'VirtualList',
72
76
  ]
73
77
 
74
78
  /**