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,163 @@
1
+ import { nextTick, onBeforeUnmount, watch } from "vue";
2
+ //#region src/internal/focusTrap.js
3
+ /**
4
+ * Focus management for modal surfaces (`UiModal`, and anything built on it).
5
+ *
6
+ * A modal dialog has three keyboard obligations under the WAI-ARIA dialog
7
+ * pattern, and all three are easy to get subtly wrong:
8
+ *
9
+ * 1. **Move focus in** when it opens — otherwise a keyboard user is left on
10
+ * the button behind the backdrop, and a screen reader never announces the
11
+ * dialog.
12
+ * 2. **Keep focus in** while it is open — Tab from the last control wraps to
13
+ * the first, Shift+Tab from the first wraps to the last.
14
+ * 3. **Put focus back** when it closes, on whatever opened it.
15
+ *
16
+ * Escape also closes the dialog, unless the caller says otherwise.
17
+ *
18
+ * Dialogs can stack (a confirmation over a settings modal), and only the top
19
+ * one may react to Tab or Escape — so every trap registers on a module-level
20
+ * stack and a single listener dispatches to whichever is on top.
21
+ *
22
+ * That listener is on `window`, not `document`, deliberately: `window` is the
23
+ * last stop of a bubbling keydown, so a control inside the dialog that closes
24
+ * itself on Escape (an open `UiDropdown`, `UiSelect`'s search field) runs first
25
+ * and calls `preventDefault()`, and the dialog then leaves the key alone. One
26
+ * Escape closes one thing.
27
+ *
28
+ * Initial focus is only moved if nothing inside the container already has it.
29
+ * That lets a wrapper such as `UiPrompt` focus its confirm button without the
30
+ * trap then stealing focus back to the first control.
31
+ *
32
+ * SSR-safe: nothing touches `document` until the trap activates, which only
33
+ * happens in the browser.
34
+ */
35
+ var FOCUSABLE = [
36
+ "a[href]",
37
+ "area[href]",
38
+ "button:not([disabled])",
39
+ "input:not([disabled]):not([type=\"hidden\"])",
40
+ "select:not([disabled])",
41
+ "textarea:not([disabled])",
42
+ "iframe",
43
+ "audio[controls]",
44
+ "video[controls]",
45
+ "[contenteditable]:not([contenteditable=\"false\"])",
46
+ "[tabindex]:not([tabindex=\"-1\"])"
47
+ ].join(",");
48
+ /**
49
+ * Tabbable descendants of `container`, in DOM order, skipping anything hidden.
50
+ *
51
+ * @param {HTMLElement} container
52
+ * @returns {HTMLElement[]}
53
+ */
54
+ function tabbableIn(container) {
55
+ if (!container) return [];
56
+ return [...container.querySelectorAll(FOCUSABLE)].filter((el) => !el.closest("[inert]") && el.getClientRects().length > 0);
57
+ }
58
+ /** @type {Array<{ container: () => HTMLElement | null, onEscape: (() => void) | null }>} */
59
+ var stack = [];
60
+ var listening = false;
61
+ function onWindowKeydown(event) {
62
+ const top = stack[stack.length - 1];
63
+ if (!top) return;
64
+ const container = top.container();
65
+ if (!container) return;
66
+ if (event.key === "Escape") {
67
+ if (event.defaultPrevented || !top.onEscape) return;
68
+ event.preventDefault();
69
+ top.onEscape();
70
+ return;
71
+ }
72
+ if (event.key !== "Tab") return;
73
+ const items = tabbableIn(container);
74
+ if (items.length === 0) {
75
+ event.preventDefault();
76
+ container.focus();
77
+ return;
78
+ }
79
+ const first = items[0];
80
+ const last = items[items.length - 1];
81
+ const active = document.activeElement;
82
+ const inside = container.contains(active);
83
+ if (event.shiftKey && (active === first || !inside)) {
84
+ event.preventDefault();
85
+ last.focus();
86
+ } else if (!event.shiftKey && (active === last || !inside)) {
87
+ event.preventDefault();
88
+ first.focus();
89
+ }
90
+ }
91
+ function push(entry) {
92
+ stack.push(entry);
93
+ if (!listening) {
94
+ window.addEventListener("keydown", onWindowKeydown);
95
+ listening = true;
96
+ }
97
+ }
98
+ function remove(entry) {
99
+ const index = stack.indexOf(entry);
100
+ if (index !== -1) stack.splice(index, 1);
101
+ if (stack.length === 0 && listening) {
102
+ window.removeEventListener("keydown", onWindowKeydown);
103
+ listening = false;
104
+ }
105
+ }
106
+ /**
107
+ * Trap focus inside an element while `active()` is true.
108
+ *
109
+ * @param {() => HTMLElement | null | undefined} container Getter for the
110
+ * element focus is confined to. It must itself be focusable
111
+ * (`tabindex="-1"`) so there is somewhere to land when it has no controls.
112
+ * @param {object} options
113
+ * @param {() => boolean} options.active Whether the trap is engaged.
114
+ * @param {(() => boolean) | boolean} [options.escape] Whether Escape closes.
115
+ * @param {() => void} [options.onEscape] Called when Escape should close.
116
+ */
117
+ function useFocusTrap(container, { active, escape = true, onEscape }) {
118
+ const entry = {
119
+ container: () => container() ?? null,
120
+ onEscape: null
121
+ };
122
+ let returnTo = null;
123
+ let engaged = false;
124
+ let lastEl = null;
125
+ const engage = () => {
126
+ if (engaged || typeof document === "undefined") return;
127
+ engaged = true;
128
+ returnTo = document.activeElement;
129
+ entry.onEscape = () => {
130
+ if (typeof escape === "function" ? escape() : escape) onEscape?.();
131
+ };
132
+ push(entry);
133
+ nextTick(() => {
134
+ const el = entry.container();
135
+ if (el) lastEl = el;
136
+ if (!el || el.contains(document.activeElement)) return;
137
+ const [first] = tabbableIn(el);
138
+ (first ?? el).focus({ preventScroll: true });
139
+ });
140
+ };
141
+ const release = () => {
142
+ if (!engaged) return;
143
+ engaged = false;
144
+ remove(entry);
145
+ const target = returnTo;
146
+ const closing = entry.container() ?? lastEl;
147
+ returnTo = null;
148
+ lastEl = null;
149
+ if (target && typeof target.focus === "function" && document.contains(target)) {
150
+ const current = document.activeElement;
151
+ if (!current || current === document.body || closing?.contains(current)) target.focus({ preventScroll: true });
152
+ }
153
+ };
154
+ watch(active, (on) => on ? engage() : release(), {
155
+ immediate: true,
156
+ flush: "post"
157
+ });
158
+ onBeforeUnmount(release);
159
+ }
160
+ //#endregion
161
+ export { tabbableIn, useFocusTrap };
162
+
163
+ //# sourceMappingURL=focusTrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focusTrap.js","names":[],"sources":["../../src/internal/focusTrap.js"],"sourcesContent":["/**\n * Focus management for modal surfaces (`UiModal`, and anything built on it).\n *\n * A modal dialog has three keyboard obligations under the WAI-ARIA dialog\n * pattern, and all three are easy to get subtly wrong:\n *\n * 1. **Move focus in** when it opens — otherwise a keyboard user is left on\n * the button behind the backdrop, and a screen reader never announces the\n * dialog.\n * 2. **Keep focus in** while it is open — Tab from the last control wraps to\n * the first, Shift+Tab from the first wraps to the last.\n * 3. **Put focus back** when it closes, on whatever opened it.\n *\n * Escape also closes the dialog, unless the caller says otherwise.\n *\n * Dialogs can stack (a confirmation over a settings modal), and only the top\n * one may react to Tab or Escape — so every trap registers on a module-level\n * stack and a single listener dispatches to whichever is on top.\n *\n * That listener is on `window`, not `document`, deliberately: `window` is the\n * last stop of a bubbling keydown, so a control inside the dialog that closes\n * itself on Escape (an open `UiDropdown`, `UiSelect`'s search field) runs first\n * and calls `preventDefault()`, and the dialog then leaves the key alone. One\n * Escape closes one thing.\n *\n * Initial focus is only moved if nothing inside the container already has it.\n * That lets a wrapper such as `UiPrompt` focus its confirm button without the\n * trap then stealing focus back to the first control.\n *\n * SSR-safe: nothing touches `document` until the trap activates, which only\n * happens in the browser.\n */\nimport { nextTick, onBeforeUnmount, watch } from 'vue'\n\n// ── Focusable elements ───────────────────────────────────────────────\n\nconst FOCUSABLE = [\n 'a[href]',\n 'area[href]',\n 'button:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'iframe',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n '[tabindex]:not([tabindex=\"-1\"])',\n].join(',')\n\n/**\n * Tabbable descendants of `container`, in DOM order, skipping anything hidden.\n *\n * @param {HTMLElement} container\n * @returns {HTMLElement[]}\n */\nexport function tabbableIn(container) {\n if (!container) return []\n return [...container.querySelectorAll(FOCUSABLE)].filter(\n (el) => !el.closest('[inert]') && el.getClientRects().length > 0,\n )\n}\n\n// ── The stack of active traps ────────────────────────────────────────\n\n/** @type {Array<{ container: () => HTMLElement | null, onEscape: (() => void) | null }>} */\nconst stack = []\nlet listening = false\n\nfunction onWindowKeydown(event) {\n const top = stack[stack.length - 1]\n if (!top) return\n const container = top.container()\n if (!container) return\n\n if (event.key === 'Escape') {\n // A control inside the dialog (an open select, a search field) may have\n // handled Escape already; respect that rather than closing over it.\n if (event.defaultPrevented || !top.onEscape) return\n event.preventDefault()\n top.onEscape()\n return\n }\n\n if (event.key !== 'Tab') return\n const items = tabbableIn(container)\n if (items.length === 0) {\n event.preventDefault()\n container.focus()\n return\n }\n const first = items[0]\n const last = items[items.length - 1]\n const active = document.activeElement\n const inside = container.contains(active)\n if (event.shiftKey && (active === first || !inside)) {\n event.preventDefault()\n last.focus()\n } else if (!event.shiftKey && (active === last || !inside)) {\n event.preventDefault()\n first.focus()\n }\n}\n\nfunction push(entry) {\n stack.push(entry)\n if (!listening) {\n window.addEventListener('keydown', onWindowKeydown)\n listening = true\n }\n}\n\nfunction remove(entry) {\n const index = stack.indexOf(entry)\n if (index !== -1) stack.splice(index, 1)\n if (stack.length === 0 && listening) {\n window.removeEventListener('keydown', onWindowKeydown)\n listening = false\n }\n}\n\n// ── Composable ───────────────────────────────────────────────────────\n\n/**\n * Trap focus inside an element while `active()` is true.\n *\n * @param {() => HTMLElement | null | undefined} container Getter for the\n * element focus is confined to. It must itself be focusable\n * (`tabindex=\"-1\"`) so there is somewhere to land when it has no controls.\n * @param {object} options\n * @param {() => boolean} options.active Whether the trap is engaged.\n * @param {(() => boolean) | boolean} [options.escape] Whether Escape closes.\n * @param {() => void} [options.onEscape] Called when Escape should close.\n */\nexport function useFocusTrap(container, { active, escape = true, onEscape }) {\n const entry = {\n container: () => container() ?? null,\n onEscape: null,\n }\n let returnTo = null\n let engaged = false\n // The element as it was while open. A template ref is cleared the moment its\n // owner starts leaving, but a Transition keeps the element (and the focus\n // inside it) on screen for the length of the leave animation.\n let lastEl = null\n\n const engage = () => {\n if (engaged || typeof document === 'undefined') return\n engaged = true\n returnTo = document.activeElement\n entry.onEscape = () => {\n const allowed = typeof escape === 'function' ? escape() : escape\n if (allowed) onEscape?.()\n }\n push(entry)\n nextTick(() => {\n const el = entry.container()\n if (el) lastEl = el\n if (!el || el.contains(document.activeElement)) return\n const [first] = tabbableIn(el)\n ;(first ?? el).focus({ preventScroll: true })\n })\n }\n\n const release = () => {\n if (!engaged) return\n engaged = false\n remove(entry)\n const target = returnTo\n const closing = entry.container() ?? lastEl\n returnTo = null\n lastEl = null\n // Only restore if focus is still lost inside the closing surface or on the\n // body — never yank it away from somewhere the user has since moved to.\n if (target && typeof target.focus === 'function' && document.contains(target)) {\n const current = document.activeElement\n if (!current || current === document.body || closing?.contains(current)) {\n target.focus({ preventScroll: true })\n }\n }\n }\n\n watch(active, (on) => (on ? engage() : release()), { immediate: true, flush: 'post' })\n onBeforeUnmount(release)\n}\n"],"mappings":"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"}
package/dist/manifest.js CHANGED
@@ -58,8 +58,10 @@ var COMPONENT_NAMES = [
58
58
  "Sidebar",
59
59
  "SidebarGroup",
60
60
  "SidebarItem",
61
+ "Skeleton",
61
62
  "Slider",
62
63
  "Spinner",
64
+ "SplitPane",
63
65
  "StatCard",
64
66
  "Stepper",
65
67
  "Table",
@@ -67,7 +69,9 @@ var COMPONENT_NAMES = [
67
69
  "ThemeToggle",
68
70
  "Toast",
69
71
  "Toggle",
70
- "Tooltip"
72
+ "Tooltip",
73
+ "Tree",
74
+ "VirtualList"
71
75
  ];
72
76
  /**
73
77
  * The icon component is listed separately: it lives outside `components/`
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.js","names":[],"sources":["../src/manifest.js"],"sourcesContent":["/**\n * Component manifest — the single list of what Numori UI ships.\n *\n * Kept as plain data (no imports) so it can be consumed by things that must\n * not pull Vue or any `.vue` file into their graph: the Nuxt module and the\n * Vite plugin both run in Node at config time and only need names and paths.\n *\n * `src/components/index.js` holds the matching real imports for bundling. The\n * two are cross-checked by `scripts/verify.mjs`, so a component added in one\n * place and forgotten in the other fails the build rather than shipping\n * half-registered.\n */\n\n/** Default prefix for registered component names, e.g. `Ui` -> `<UiButton>`. */\nexport const DEFAULT_PREFIX = 'Ui'\n\n/**\n * Base names of every shipped component, without prefix or extension.\n * Order is alphabetical, matching the files on disk.\n * @type {string[]}\n */\nexport const COMPONENT_NAMES = [\n 'Alert',\n 'AppShell',\n 'Avatar',\n 'Badge',\n 'Banner',\n 'Breadcrumb',\n 'Button',\n 'Card',\n 'Checkbox',\n 'CodeBlock',\n 'CopyField',\n 'DescriptionList',\n 'Divider',\n 'Dropdown',\n 'DropdownItem',\n 'DropdownRow',\n 'DropdownSubmenu',\n 'EmptyState',\n 'FileInput',\n 'FormField',\n 'IconTile',\n 'Input',\n 'Kbd',\n 'ListMenu',\n 'ListMenuItem',\n 'Modal',\n 'Numpad',\n 'PageHeader',\n 'Pagination',\n 'Popup',\n 'ProgressBar',\n 'Prompt',\n 'Radio',\n 'SectionHeading',\n 'Segmented',\n 'Select',\n 'Sidebar',\n 'SidebarGroup',\n 'SidebarItem',\n 'Slider',\n 'Spinner',\n 'StatCard',\n 'Stepper',\n 'Table',\n 'Tabs',\n 'ThemeToggle',\n 'Toast',\n 'Toggle',\n 'Tooltip',\n]\n\n/**\n * The icon component is listed separately: it lives outside `components/`\n * because it is the framework seam rather than a UI primitive, and the other\n * components import it directly by path.\n */\nexport const ICON_COMPONENT = { name: 'Icon', file: 'icons/Icon.vue' }\n\n/**\n * Every registerable component as `{ name, file }`, where `file` is relative\n * to `src/`. Includes the icon component.\n * @returns {Array<{ name: string, file: string }>}\n */\nexport function componentEntries() {\n return [\n ...COMPONENT_NAMES.map((name) => ({ name, file: `components/${name}.vue` })),\n ICON_COMPONENT,\n ]\n}\n\n/**\n * Apply a prefix to a base component name.\n *\n * The prefix must be non-empty; the entry points validate this. Registering\n * bare names breaks `Button`, whose root is `<component :is=\"tag\">` with `tag`\n * defaulting to `'button'` — Vue capitalises when resolving dynamic components,\n * so a registered `Button` would match its own root element and recurse.\n *\n * @param {string} name Base name, e.g. 'Button'.\n * @param {string} [prefix=DEFAULT_PREFIX] Prefix to apply, e.g. 'Ui' or 'N'.\n * @returns {string} e.g. 'UiButton'\n */\nexport function prefixed(name, prefix = DEFAULT_PREFIX) {\n return `${prefix || ''}${name}`\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,iBAAiB;;;;;;AAO9B,IAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,IAAa,iBAAiB;CAAE,MAAM;CAAQ,MAAM;AAAiB;;;;;;AAOrE,SAAgB,mBAAmB;CACjC,OAAO,CACL,GAAG,gBAAgB,KAAK,UAAU;EAAE;EAAM,MAAM,cAAc,KAAK;CAAM,EAAE,GAC3E,cACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,SAAS,MAAM,SAAA,MAAyB;CACtD,OAAO,GAAG,UAAU,KAAK;AAC3B"}
1
+ {"version":3,"file":"manifest.js","names":[],"sources":["../src/manifest.js"],"sourcesContent":["/**\n * Component manifest — the single list of what Numori UI ships.\n *\n * Kept as plain data (no imports) so it can be consumed by things that must\n * not pull Vue or any `.vue` file into their graph: the Nuxt module and the\n * Vite plugin both run in Node at config time and only need names and paths.\n *\n * `src/components/index.js` holds the matching real imports for bundling. The\n * two are cross-checked by `scripts/verify.mjs`, so a component added in one\n * place and forgotten in the other fails the build rather than shipping\n * half-registered.\n */\n\n/** Default prefix for registered component names, e.g. `Ui` -> `<UiButton>`. */\nexport const DEFAULT_PREFIX = 'Ui'\n\n/**\n * Base names of every shipped component, without prefix or extension.\n * Order is alphabetical, matching the files on disk.\n * @type {string[]}\n */\nexport const COMPONENT_NAMES = [\n 'Alert',\n 'AppShell',\n 'Avatar',\n 'Badge',\n 'Banner',\n 'Breadcrumb',\n 'Button',\n 'Card',\n 'Checkbox',\n 'CodeBlock',\n 'CopyField',\n 'DescriptionList',\n 'Divider',\n 'Dropdown',\n 'DropdownItem',\n 'DropdownRow',\n 'DropdownSubmenu',\n 'EmptyState',\n 'FileInput',\n 'FormField',\n 'IconTile',\n 'Input',\n 'Kbd',\n 'ListMenu',\n 'ListMenuItem',\n 'Modal',\n 'Numpad',\n 'PageHeader',\n 'Pagination',\n 'Popup',\n 'ProgressBar',\n 'Prompt',\n 'Radio',\n 'SectionHeading',\n 'Segmented',\n 'Select',\n 'Sidebar',\n 'SidebarGroup',\n 'SidebarItem',\n 'Skeleton',\n 'Slider',\n 'Spinner',\n 'SplitPane',\n 'StatCard',\n 'Stepper',\n 'Table',\n 'Tabs',\n 'ThemeToggle',\n 'Toast',\n 'Toggle',\n 'Tooltip',\n 'Tree',\n 'VirtualList',\n]\n\n/**\n * The icon component is listed separately: it lives outside `components/`\n * because it is the framework seam rather than a UI primitive, and the other\n * components import it directly by path.\n */\nexport const ICON_COMPONENT = { name: 'Icon', file: 'icons/Icon.vue' }\n\n/**\n * Every registerable component as `{ name, file }`, where `file` is relative\n * to `src/`. Includes the icon component.\n * @returns {Array<{ name: string, file: string }>}\n */\nexport function componentEntries() {\n return [\n ...COMPONENT_NAMES.map((name) => ({ name, file: `components/${name}.vue` })),\n ICON_COMPONENT,\n ]\n}\n\n/**\n * Apply a prefix to a base component name.\n *\n * The prefix must be non-empty; the entry points validate this. Registering\n * bare names breaks `Button`, whose root is `<component :is=\"tag\">` with `tag`\n * defaulting to `'button'` — Vue capitalises when resolving dynamic components,\n * so a registered `Button` would match its own root element and recurse.\n *\n * @param {string} name Base name, e.g. 'Button'.\n * @param {string} [prefix=DEFAULT_PREFIX] Prefix to apply, e.g. 'Ui' or 'N'.\n * @returns {string} e.g. 'UiButton'\n */\nexport function prefixed(name, prefix = DEFAULT_PREFIX) {\n return `${prefix || ''}${name}`\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,iBAAiB;;;;;;AAO9B,IAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,IAAa,iBAAiB;CAAE,MAAM;CAAQ,MAAM;AAAiB;;;;;;AAOrE,SAAgB,mBAAmB;CACjC,OAAO,CACL,GAAG,gBAAgB,KAAK,UAAU;EAAE;EAAM,MAAM,cAAc,KAAK;CAAM,EAAE,GAC3E,cACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,SAAS,MAAM,SAAA,MAAyB;CACtD,OAAO,GAAG,UAAU,KAAK;AAC3B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "numori-ui",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
5
5
  "description": "The Numori design system — a Tailwind 4 Vue 3 component library, consumable as a Nuxt module or a Vite plugin.",
6
6
  "author": {
7
7
  "name": "Erik Bjerke",
@@ -1,48 +1,80 @@
1
1
  <template>
2
- <!-- Circular avatar container with image or fallback icon -->
2
+ <!-- Circular avatar container with an image, initials or a fallback icon -->
3
3
  <div
4
4
  class="rounded-full flex items-center justify-center overflow-hidden shrink-0"
5
5
  :class="[sizeClass, bgClass, ringClass]"
6
+ :role="showImage ? undefined : 'img'"
7
+ :aria-label="showImage ? undefined : alt"
6
8
  >
7
- <img v-if="src" :src="src" :alt="alt" class="w-full h-full object-cover" />
8
- <UiIcon v-else :name="fallbackIcon" :class="iconSizeClass" />
9
+ <img
10
+ v-if="showImage"
11
+ ref="imgRef"
12
+ :src="src"
13
+ :alt="alt"
14
+ class="w-full h-full object-cover"
15
+ @error="failed = true"
16
+ />
17
+ <span
18
+ v-else-if="shownInitials"
19
+ class="font-semibold leading-none tracking-tight select-none"
20
+ :class="textSizeClass"
21
+ aria-hidden="true"
22
+ >{{ shownInitials }}</span
23
+ >
24
+ <UiIcon v-else :name="fallbackIcon" :class="iconSizeClass" aria-hidden="true" />
9
25
  </div>
10
26
  </template>
11
27
 
12
28
  <script setup>
13
29
  /**
14
- * UiAvatar — Circular avatar component displaying an image or a fallback icon.
30
+ * UiAvatar — Circular avatar component displaying an image, initials or a fallback icon.
15
31
  *
16
- * When a `src` URL is provided, renders a cover-fit image. Otherwise, displays
17
- * a configurable fallback icon on a colored background. Supports five sizes,
18
- * two color themes for the fallback state, and an optional ring border.
32
+ * When a `src` URL is provided, renders a cover-fit image; if the image fails
33
+ * to load, it falls back rather than showing a broken-image glyph. Without an
34
+ * image it shows `initials` (at most two characters, upper-cased), and without
35
+ * those a configurable fallback icon, on a colored background. Supports five
36
+ * sizes, two color themes for the fallback state, and an optional ring border.
37
+ *
38
+ * Without an image the avatar is exposed as `role="img"` named by `alt`, so
39
+ * pass the person's name there rather than the default.
19
40
  *
20
41
  * @example Image avatar
21
42
  * <UiAvatar src="/img/user.jpg" alt="Jane Doe" size="lg" />
22
43
  *
44
+ * @example Initials
45
+ * <UiAvatar initials="JD" alt="Jane Doe" />
46
+ *
23
47
  * @example Fallback icon avatar with ring
24
48
  * <UiAvatar size="md" color="primary" ring />
25
49
  *
26
50
  * @example Small gray avatar with custom icon
27
51
  * <UiAvatar size="sm" color="gray" fallback-icon="mdi:account-group" />
28
52
  */
29
- import { computed } from 'vue'
53
+ import { computed, onMounted, ref, watch } from 'vue'
30
54
  import UiIcon from '../icons/Icon.vue'
55
+
31
56
  const props = defineProps({
32
57
  /**
33
- * Image source URL. When empty, the fallback icon is shown.
58
+ * Image source URL. When empty (or it fails to load), initials or the
59
+ * fallback icon are shown.
34
60
  * @type {string}
35
61
  * @default ''
36
62
  */
37
63
  src: { type: String, default: '' },
38
-
39
64
  /**
40
- * Alt text for the avatar image (accessibility).
65
+ * Alt text for the avatar image (accessibility), and the accessible name
66
+ * when initials or the icon are shown.
41
67
  * @type {string}
42
68
  * @default 'Avatar'
43
69
  */
44
70
  alt: { type: String, default: 'Avatar' },
45
-
71
+ /**
72
+ * Initials shown when there is no image. Trimmed to two characters and
73
+ * upper-cased.
74
+ * @type {string}
75
+ * @default ''
76
+ */
77
+ initials: { type: String, default: '' },
46
78
  /**
47
79
  * Avatar size controlling width, height, and icon dimensions.
48
80
  * @type {string}
@@ -50,14 +82,12 @@ const props = defineProps({
50
82
  * @values 'xs' (24px) | 'sm' (32px) | 'md' (36px) | 'lg' (48px) | 'xl' (64px)
51
83
  */
52
84
  size: { type: String, default: 'md' },
53
-
54
85
  /**
55
- * MDI icon name used when no image src is provided.
86
+ * MDI icon name used when there is neither an image nor initials.
56
87
  * @type {string}
57
88
  * @default 'mdi:account'
58
89
  */
59
90
  fallbackIcon: { type: String, default: 'mdi:account' },
60
-
61
91
  /**
62
92
  * Background color theme for the fallback icon state.
63
93
  * @type {string}
@@ -65,7 +95,6 @@ const props = defineProps({
65
95
  * @values 'primary' | 'gray'
66
96
  */
67
97
  color: { type: String, default: 'primary' },
68
-
69
98
  /**
70
99
  * Show a ring border around the avatar for emphasis.
71
100
  * @type {boolean}
@@ -74,6 +103,23 @@ const props = defineProps({
74
103
  ring: { type: Boolean, default: false },
75
104
  })
76
105
 
106
+ // A failed load falls back to initials or the icon; a new src retries.
107
+ const failed = ref(false)
108
+ const imgRef = ref(null)
109
+ watch(
110
+ () => props.src,
111
+ () => (failed.value = false),
112
+ )
113
+ // Server-rendered images can fail before hydration attaches `@error`, so the
114
+ // event is never seen. Check once on mount for an image that already failed.
115
+ onMounted(() => {
116
+ const img = imgRef.value
117
+ if (img && img.complete && img.naturalWidth === 0) failed.value = true
118
+ })
119
+ const showImage = computed(() => !!props.src && !failed.value)
120
+
121
+ const shownInitials = computed(() => [...props.initials.trim()].slice(0, 2).join('').toUpperCase())
122
+
77
123
  const sizeClass = computed(() => {
78
124
  const map = { xs: 'w-6 h-6', sm: 'w-8 h-8', md: 'w-9 h-9', lg: 'w-12 h-12', xl: 'w-16 h-16' }
79
125
  return map[props.size] || map.md
@@ -84,9 +130,14 @@ const iconSizeClass = computed(() => {
84
130
  return map[props.size] || map.md
85
131
  })
86
132
 
87
- // Only apply background color when showing the fallback icon (not when an image is loaded)
133
+ const textSizeClass = computed(() => {
134
+ const map = { xs: 'text-[10px]', sm: 'text-xs', md: 'text-sm', lg: 'text-base', xl: 'text-xl' }
135
+ return map[props.size] || map.md
136
+ })
137
+
138
+ // Only apply background color when not showing an image
88
139
  const bgClass = computed(() => {
89
- if (props.src) return ''
140
+ if (showImage.value) return ''
90
141
  const map = {
91
142
  primary: 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400',
92
143
  gray: 'bg-gray-200 dark:bg-gray-700 text-gray-500 dark:text-gray-400',
@@ -155,7 +155,10 @@ const close = () => {
155
155
  onClickOutside(containerRef, close)
156
156
 
157
157
  useEventListener(globalThis.document, 'keydown', (e) => {
158
- if (e.key === 'Escape') close()
158
+ if (e.key !== 'Escape' || !isOpen.value) return
159
+ // Claim the key so an enclosing UiModal does not close too.
160
+ e.preventDefault()
161
+ close()
159
162
  })
160
163
 
161
164
  defineExpose({ isOpen, toggle, close })
@@ -27,7 +27,13 @@
27
27
  >
28
28
  <div
29
29
  v-if="show"
30
- class="modal-panel bg-white dark:bg-gray-925 overflow-hidden flex flex-col"
30
+ ref="panelRef"
31
+ role="dialog"
32
+ aria-modal="true"
33
+ :aria-label="labelledby ? undefined : label || undefined"
34
+ :aria-labelledby="labelledby || undefined"
35
+ tabindex="-1"
36
+ class="modal-panel bg-white dark:bg-gray-925 overflow-hidden flex flex-col focus:outline-none"
31
37
  :class="[panelClass, maxWidthClass, roundedClass, mobileLayoutClass]"
32
38
  @click.stop
33
39
  >
@@ -47,6 +53,13 @@
47
53
  * (xs through 5xl and full-screen), persistent mode to prevent backdrop-click dismissal,
48
54
  * and customizable z-index and padding. The panel uses a scale+fade transition on enter/leave.
49
55
  *
56
+ * The panel is a real dialog: `role="dialog"` and `aria-modal="true"`, named by
57
+ * `label` or `labelledby`. While open, focus moves into the panel (unless
58
+ * something inside already has it), Tab and Shift+Tab wrap within it, Escape
59
+ * closes it (unless `persistent` or `close-on-escape` is false), and focus
60
+ * returns to whatever opened it. Stacked modals behave: only the top one
61
+ * responds to Tab and Escape.
62
+ *
50
63
  * @example Basic modal
51
64
  * <UiModal :show="isOpen" @close="isOpen = false">
52
65
  * <div class="p-6">Hello!</div>
@@ -68,12 +81,19 @@
68
81
  * <div class="p-6">Centered on all screens</div>
69
82
  * </UiModal>
70
83
  *
71
- * @emits {void} close — Emitted when the modal should close (backdrop click or programmatic)
84
+ * @example Named by its heading
85
+ * <UiModal :show="isOpen" labelledby="settings-title" @close="isOpen = false">
86
+ * <h2 id="settings-title">Settings</h2>
87
+ * </UiModal>
88
+ *
89
+ * @emits {void} close — Emitted when the modal should close (backdrop click, Escape,
90
+ * the Android back button, or programmatic)
72
91
  *
73
92
  * @slot default — Modal content
74
93
  */
75
- import { computed, watch, onBeforeUnmount } from 'vue'
94
+ import { computed, ref, watch, onBeforeUnmount } from 'vue'
76
95
  import { useBackButton } from '../composables/useBackButton.js'
96
+ import { useFocusTrap } from '../internal/focusTrap.js'
77
97
  const props = defineProps({
78
98
  /**
79
99
  * Controls modal visibility. Use with v-model or :show + @close.
@@ -125,10 +145,38 @@ const props = defineProps({
125
145
  * @default 'md:p-4'
126
146
  */
127
147
  padding: { type: String, default: 'md:p-4' },
148
+ /**
149
+ * Accessible name for the dialog. Prefer `labelledby` when the content has a
150
+ * visible heading.
151
+ * @type {string}
152
+ * @default ''
153
+ */
154
+ label: { type: String, default: '' },
155
+ /**
156
+ * Id of the element that names the dialog, usually its heading.
157
+ * @type {string}
158
+ * @default ''
159
+ */
160
+ labelledby: { type: String, default: '' },
161
+ /**
162
+ * Whether Escape closes the modal. Ignored (treated as false) when
163
+ * `persistent` is set.
164
+ * @type {boolean}
165
+ * @default true
166
+ */
167
+ closeOnEscape: { type: Boolean, default: true },
128
168
  })
129
169
 
130
170
  const emit = defineEmits(['close'])
131
171
 
172
+ // ── Focus: move in, keep in, put back ──
173
+ const panelRef = ref(null)
174
+ useFocusTrap(() => panelRef.value, {
175
+ active: () => props.show,
176
+ escape: () => props.closeOnEscape && !props.persistent,
177
+ onEscape: () => emit('close'),
178
+ })
179
+
132
180
  // ── Back-button interception (Capacitor) ──
133
181
  const { register: registerBack, unregister: unregisterBack } = useBackButton()
134
182
  let backHandlerId = null
@@ -4,6 +4,7 @@
4
4
  max-width="sm"
5
5
  :fullscreen-mobile="fullscreenMobile"
6
6
  :panel-class="panelClass"
7
+ :labelledby="titleId"
7
8
  @close="handleClose"
8
9
  >
9
10
  <div
@@ -15,11 +16,20 @@
15
16
  <div class="flex items-center justify-between p-4 pb-0 mb-3 shrink-0">
16
17
  <div class="flex items-center gap-2">
17
18
  <UiIcon v-if="icon" :name="icon" class="w-5 h-5" :class="iconColorClass" />
18
- <h2 class="text-sm font-semibold text-gray-900 dark:text-gray-200 leading-none">
19
+ <h2
20
+ :id="titleId"
21
+ class="text-sm font-semibold text-gray-900 dark:text-gray-200 leading-none"
22
+ >
19
23
  {{ title }}
20
24
  </h2>
21
25
  </div>
22
- <UiButton variant="ghost" color="gray" icon-only @click="handleClose">
26
+ <UiButton
27
+ variant="ghost"
28
+ color="gray"
29
+ icon-only
30
+ :aria-label="cancelLabel"
31
+ @click="handleClose"
32
+ >
23
33
  <UiIcon name="mdi:close" class="block w-5 h-5" />
24
34
  </UiButton>
25
35
  </div>
@@ -87,7 +97,7 @@
87
97
  * <UiInput v-model="name" @keydown.enter="save" />
88
98
  * </UiPrompt>
89
99
  */
90
- import { ref, computed, watch, nextTick, useSlots } from 'vue'
100
+ import { ref, computed, watch, nextTick, useSlots, useId } from 'vue'
91
101
  import UiButton from './Button.vue'
92
102
  import UiModal from './Modal.vue'
93
103
  import UiIcon from '../icons/Icon.vue'
@@ -119,6 +129,7 @@ const props = defineProps({
119
129
  const emit = defineEmits(['close', 'confirm'])
120
130
 
121
131
  const confirmRef = ref(null)
132
+ const titleId = `${useId()}-title`
122
133
  const hasCustomActions = computed(() => !!useSlots().actions)
123
134
 
124
135
  const iconColorClass = computed(() => {
@@ -78,7 +78,7 @@
78
78
  type="text"
79
79
  placeholder="Search..."
80
80
  class="w-full px-2.5 py-1.5 text-sm border border-gray-200 dark:border-gray-700 rounded-md bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-gray-300 outline-none focus:ring-1 focus:ring-primary-500 placeholder-gray-400"
81
- @keydown.escape="close"
81
+ @keydown.escape.prevent="close"
82
82
  @keydown.enter.prevent="selectFirst"
83
83
  />
84
84
  </div>
@@ -0,0 +1,91 @@
1
+ <template>
2
+ <div v-if="variant === 'text'" :class="['flex flex-col', gapClass]" v-bind="a11yAttrs">
3
+ <span v-if="label" class="sr-only">{{ label }}</span>
4
+ <div
5
+ v-for="line in lines"
6
+ :key="line"
7
+ :class="[baseClass, 'h-3 rounded-md', line === lines && lines > 1 ? 'w-3/5' : 'w-full']"
8
+ aria-hidden="true"
9
+ />
10
+ </div>
11
+ <div v-else :class="[baseClass, shapeClass]" v-bind="a11yAttrs">
12
+ <span v-if="label" class="sr-only">{{ label }}</span>
13
+ </div>
14
+ </template>
15
+
16
+ <script setup>
17
+ /**
18
+ * UiSkeleton — a placeholder shaped like the content that is about to load.
19
+ *
20
+ * Three shapes: `text` (one or more lines, the last one shorter), `rect` and
21
+ * `circle`. Size the shape with ordinary classes — `class="h-24 w-full"`, or
22
+ * `class="size-9"` for an avatar-sized circle.
23
+ *
24
+ * The shimmer is a gentle pulse and stops for anyone who prefers reduced
25
+ * motion. Skeletons are decorative (`aria-hidden`) by default; give one a
26
+ * `label` and it becomes a polite status message instead, so a screen reader
27
+ * hears "Loading messages" once rather than nothing at all. Label one
28
+ * skeleton per region, not every line.
29
+ *
30
+ * @example A message row while it loads
31
+ * <div class="flex items-center gap-3">
32
+ * <UiSkeleton variant="circle" class="size-9" />
33
+ * <UiSkeleton :lines="2" class="flex-1" />
34
+ * </div>
35
+ *
36
+ * @example Announced to screen readers
37
+ * <UiSkeleton variant="rect" class="h-40" label="Loading message" />
38
+ */
39
+ import { computed } from 'vue'
40
+
41
+ const props = defineProps({
42
+ /**
43
+ * Shape of the placeholder.
44
+ * @type {string}
45
+ * @default 'text'
46
+ * @values 'text' | 'rect' | 'circle'
47
+ */
48
+ variant: { type: String, default: 'text' },
49
+ /**
50
+ * Number of lines for `variant="text"`.
51
+ * @type {number}
52
+ * @default 1
53
+ */
54
+ lines: { type: Number, default: 1 },
55
+ /**
56
+ * Spacing between text lines.
57
+ * @type {string}
58
+ * @default 'md'
59
+ * @values 'sm' | 'md' | 'lg'
60
+ */
61
+ gap: { type: String, default: 'md' },
62
+ /**
63
+ * Pulse while waiting. Always off under `prefers-reduced-motion`.
64
+ * @type {boolean}
65
+ * @default true
66
+ */
67
+ animated: { type: Boolean, default: true },
68
+ /**
69
+ * Announce the placeholder as a loading status with this text. Empty keeps
70
+ * it hidden from assistive technology.
71
+ * @type {string}
72
+ * @default ''
73
+ */
74
+ label: { type: String, default: '' },
75
+ })
76
+
77
+ const baseClass = computed(() =>
78
+ [
79
+ 'block bg-gray-200 dark:bg-gray-800',
80
+ props.animated ? 'animate-pulse motion-reduce:animate-none' : '',
81
+ ].join(' '),
82
+ )
83
+
84
+ const shapeClass = computed(() => (props.variant === 'circle' ? 'rounded-full' : 'rounded-lg'))
85
+
86
+ const gapClass = computed(() => ({ sm: 'gap-1.5', md: 'gap-2', lg: 'gap-3' })[props.gap] ?? 'gap-2')
87
+
88
+ const a11yAttrs = computed(() =>
89
+ props.label ? { role: 'status', 'aria-live': 'polite' } : { 'aria-hidden': 'true' },
90
+ )
91
+ </script>