@zoobzio/nuxt 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,8 @@ behind Nuxt's two virtual modules stay live, filled only by
23
23
  hold links come as the layer's own wrappers, which render every link
24
24
  through `NuxtLink` (see [Components](#components)). It also carries
25
25
  `Icon`, from `@icon-sheets/nuxt` (see [Icons](#icons)).
26
+ - `#imports` also carries `useUntheme`, `useUnthemeRenderer`, and
27
+ `useUnthemeCatalog`, from `@untheme/nuxt` (see [Theme](#theme)).
26
28
  - `#imports` carries the `define*` constructors of `@zoobzio/vue` and the
27
29
  layer's own surface: the composables, factories, stores, and constants
28
30
  as values, and everything under `types/` as types. It also carries the
@@ -140,12 +142,19 @@ draws its alias: `expand` after a select's, multi select's, or
140
142
  accordion's trigger and as a tree branch's toggle; `prev` and `next` on
141
143
  the calendars and pickers and `calendar` on a picker's trigger; `search`
142
144
  before a command's filter; `remove` on a tag's and a file's remove
143
- button; `close` on a toast's; `top` on a scroller's back-to-top; `check`
145
+ button and after an autocomplete chip's label; `close` on a toast's; `top` on a scroller's back-to-top; `check`
144
146
  in a checkbox; the editor's and rich text's tools by key (`bold`,
145
147
  `heading`, `bullet-list`, `undo`, …, see `EDITOR_TOOL_ICONS`); and on
146
148
  the table and browser, `refresh`, `columns`, `actions`, `drag`,
147
149
  `sort-asc` or `sort-desc` after a sorted header, `folder` before a
148
- folder, and the pagination's `first`, `prev`, `next`, and `last`. A slot
150
+ folder, `magic` before the table's search, `next` after an autocomplete
151
+ option that enters a stage (a field or an operator) and `expand` after the
152
+ active trail option whose stage is open, and the pagination's `first`,
153
+ `prev`, `next`, and `last`. The table's search renders through the
154
+ layer's `TableSearch`: its Autocomplete with the `magic` icon in
155
+ `inputPrepend`, the search key (`TABLE_SEARCH_KEY`, `/`) as a `kbd` in
156
+ `inputAppend`, and that key focusing the input from anywhere on the page
157
+ the user is not already typing, through `useFocusKey`. A slot
149
158
  that replaces a Fab renders the part with the icon as its content, so the
150
159
  label stays the button's `aria-label` and the visible text goes. The
151
160
  facets', keywords', and date filters' triggers draw `filter`, `keywords`,
@@ -153,14 +162,17 @@ and `calendar` that way.
153
162
 
154
163
  An item draws its own `icon`. The vue item types (`Option`, which the
155
164
  tabs, segmented control, accordion, select, and command options extend,
156
- plus `MenuItem`, `BreadcrumbItem`, `DirectoryItem`, and `FacetItem`) and
157
- the action descriptors of `@zoobzio/table` and `@zoobzio/browser` are
165
+ plus `MenuItem`, `BreadcrumbItem`, `DirectoryItem`, and `FacetItem`), the
166
+ action descriptors of `@zoobzio/table` and `@zoobzio/browser`, and the
167
+ `Field` and `Option` of `@zoobzio/query` are
158
168
  interfaces, and `app/app.d.ts` widens each with an optional
159
169
  `icon: IconAlias` by declaration merging, so the one type the package,
160
170
  the layer, and the app share carries the field, and the wrapper draws it
161
171
  in the item's `prepend` slot. A row, file, folder, or bulk action given to
162
172
  `createTable` or `createBrowser` with an `icon` draws it the same way,
163
- since the layer's `Menu` renders those actions.
173
+ since the layer's `Menu` renders those actions. A query field with an
174
+ `icon` draws it before its option in the autocomplete's panel and trail,
175
+ since the query service carries it onto the field's option.
164
176
 
165
177
  ```vue
166
178
  <script setup lang="ts">
@@ -184,6 +196,55 @@ const groups: MenuGroup[] = [
184
196
  </template>
185
197
  ```
186
198
 
199
+ ## Theme
200
+
201
+ The components of `@zoobzio/vue` read no tokens: they are unstyled, and a
202
+ consumer's stylesheet binds them. The layer loads
203
+ [`@untheme/nuxt`](https://github.com/zoobzio/untheme) with the foundation
204
+ theme from [`@zoobzio/theme`](../../packages/theme/) as its default
205
+ `untheme` option, so an app that extends the layer boots the foundation
206
+ palette, gets the aurora cascade (`--surface`, `--primary`, `--space-*`,
207
+ `--type-*`, …) under `@layer untheme` on every page, and may swap a scheme
208
+ or apply one of aurora's themes through `useUntheme()` with no setup. The
209
+ module mirrors the selection onto `<html>` as `data-<modifier>` attributes
210
+ (`data-color="dark"`), so an app's stylesheet selects on them too.
211
+
212
+ ```vue
213
+ <script setup lang="ts">
214
+ import { useUntheme } from "#imports";
215
+
216
+ const untheme = useUntheme();
217
+ </script>
218
+
219
+ <template>
220
+ <button @click="untheme.swap('color', 'dark')">Dark</button>
221
+ </template>
222
+ ```
223
+
224
+ The theme is also where foundation keeps the tokens it reads itself. The
225
+ shell's loading indicator draws `var(--loading-indicator)`, a role of
226
+ `@zoobzio/theme` bound to `{primary}`, so it follows the scheme and the
227
+ applied theme and a downstream theme rebinds it without touching the shell.
228
+ A new token of the shell is one more entry in the theme's `src/roles.json`.
229
+
230
+ An app with a theme of its own builds it over `@zoobzio/theme` in place of
231
+ aurora (`source: "npm:/@zoobzio/theme"` in its kit config), so the shell's
232
+ roles come along and its palette takes the base, and passes its package as
233
+ the preset. The untheme module takes the closest layer's `untheme` option
234
+ as a whole, so the app's preset replaces the foundation's:
235
+
236
+ ```ts
237
+ export default defineNuxtConfig({
238
+ extends: ["@zoobzio/nuxt"],
239
+ untheme: { preset: "@acme/theme" },
240
+ });
241
+ ```
242
+
243
+ The module resolves a preset from the app's root, so an app that keeps the
244
+ layer's default lists `@zoobzio/theme` and `untheme` in its own
245
+ dependencies. See the theme package for the palette, the roles, and the
246
+ extension.
247
+
187
248
  ## Stores and factories
188
249
 
189
250
  The data components of `@zoobzio/vue` (`Table`, `Form`, `Browser`,
@@ -350,11 +411,12 @@ const { push } = useNotifications();
350
411
  push({ variant: "success", title: "Saved" });
351
412
  ```
352
413
 
353
- The layer loads one stylesheet, `app/assets/css/reset.css`: a
414
+ The layer loads one stylesheet of its own, `app/assets/css/reset.css`: a
354
415
  Preflight-style reset inside `@layer reset`, so any unlayered stylesheet
355
416
  (the system's own semantic classes, the app's CSS) wins every
356
417
  equal-specificity conflict. It uses no tokens, so it applies before and
357
- independently of any theme.
418
+ independently of the theme's cascade, which `@untheme/nuxt` links in under
419
+ `@layer untheme` (see [Theme](#theme)).
358
420
 
359
421
  The shell also wraps the page in a `NuxtErrorBoundary`. An error thrown
360
422
  under it is toasted rather than replacing the page: when the error's `data`
@@ -366,13 +428,13 @@ variant.
366
428
 
367
429
  ```
368
430
  app/
369
- app.vue — the root: reka providers, loading indicator, error boundary, toaster
431
+ app.vue — the root: reka providers, loading indicator (colored by the theme's `loading-indicator` role), error boundary, toaster
370
432
  components/ — the wrapped vue components: wrap(<Core>, { pt, slots }), NuxtLink under link parts, icons in the slots, the layer's components under nested parts; icon.ts is the icon glue they share
371
433
  error.vue — the error page
372
434
  app.d.ts — RuntimeNuxtHooks augmentation for the relayed events; the vue item types and the headless action descriptors widened with `icon`
373
- constants/ — error page status codes, log levels, the editor tools' icons
435
+ constants/ — error page status codes, log levels, the editor tools' icons, the table's search key
374
436
  assets/css/ — reset.css, loaded by the layer config
375
- composables/ — useAppError, useHooks, useLogger, useNotifications, useRequest, useLazyRequest
437
+ composables/ — useAppError, useFocusKey, useHooks, useLogger, useNotifications, useRequest, useLazyRequest
376
438
  factories/ — create<Name>(id, options) → use<Name>(): Service
377
439
  plugins/ — log: provides $log and $logger
378
440
  stores/ — access<Name>(id, …) → the id's shared state container; accessLogs, accessNotifications
@@ -380,5 +442,5 @@ app/
380
442
  utils/ — split (actions → descriptors + handlers), seed (state), editor (a tool's icon by key)
381
443
  modules/ — local Nuxt modules: imports/ fills #components and #imports (the @zoobzio/vue components, definitions, and types, and the layer's own surface) and references app.d.ts for consumers
382
444
  tests/ — vitest + happy-dom, mirroring app/ path-for-path
383
- nuxt.config.ts — layer config (no implicit imports, no component scanning or tag resolution; loads the reset and @icon-sheets/nuxt with the foundation contract)
445
+ nuxt.config.ts — layer config (no implicit imports, no component scanning or tag resolution; loads the reset, @icon-sheets/nuxt with the foundation contract, and @untheme/nuxt with the foundation theme)
384
446
  ```
package/app/app.d.ts CHANGED
@@ -50,6 +50,17 @@ declare module "@zoobzio/table" {
50
50
  }
51
51
  }
52
52
 
53
+ // A query field's `icon` is carried onto its option by the service, so the
54
+ // autocomplete draws it before the field's label in the panel and the trail.
55
+ declare module "@zoobzio/query" {
56
+ interface Field {
57
+ icon?: IconAlias;
58
+ }
59
+ interface Option {
60
+ icon?: IconAlias;
61
+ }
62
+ }
63
+
53
64
  declare module "@zoobzio/browser" {
54
65
  interface ActionDescriptor {
55
66
  icon?: IconAlias;
package/app/app.vue CHANGED
@@ -45,7 +45,7 @@ const onError = (err: unknown) => {
45
45
  <template>
46
46
  <ConfigProvider :use-id="useIdFunction">
47
47
  <TooltipProvider>
48
- <NuxtLoadingIndicator color="var(--sys-primary)" :threshold="0" />
48
+ <NuxtLoadingIndicator color="var(--loading-indicator)" :threshold="0" />
49
49
  <NuxtErrorBoundary @error="onError">
50
50
  <NuxtLayout>
51
51
  <NuxtPage />
@@ -0,0 +1,29 @@
1
+ // The vue autocomplete with the layer's Scroller as the viewport of its
2
+ // active panel, the `remove` icon after each chip's label (the chip is the
3
+ // button that removes its entry), an option's `icon` before its label, and
4
+ // an arrow after an option that branches: `next` on a field or operator
5
+ // option, as selecting it enters a stage, and `expand` on an active trail
6
+ // option, as its stage is the one open. A value option commits, so it
7
+ // draws no arrow.
8
+ import type { QueryOption } from "@zoobzio/vue/types/components/autocomplete";
9
+ import type { VNode } from "vue";
10
+
11
+ import Core from "@zoobzio/vue/components/autocomplete.vue";
12
+
13
+ import { icon, iconOf } from "./icon";
14
+ import { wrap } from "@zoobzio/vue/utils/wrap";
15
+ import Scroller from "./scroller";
16
+
17
+ const arrow = (option: QueryOption): VNode[] => {
18
+ if (option.stage === "value") return [];
19
+ return [icon(option.active ? "expand" : "next")];
20
+ };
21
+
22
+ export default wrap(Core, {
23
+ pt: { viewport: { as: Scroller } },
24
+ slots: {
25
+ chipAppend: () => [icon("remove")],
26
+ itemPrepend: ({ option }) => iconOf(option.icon),
27
+ itemArrow: ({ option }) => arrow(option),
28
+ },
29
+ });
@@ -0,0 +1,56 @@
1
+ // The layer's Autocomplete as the table's search: the `magic` icon before
2
+ // its input, the search key drawn as a `kbd` after it, and that key
3
+ // focusing the input from anywhere on the page the user is not already
4
+ // typing. It stands in for the Autocomplete: attrs pass through, a
5
+ // consumer's slot wins over the defaults, its `update:open` is relayed,
6
+ // and its `ctx` is exposed as this one's.
7
+ import type { Component, ComponentPublicInstance, VNode } from "vue";
8
+
9
+ import { computed, defineComponent, h, shallowRef } from "vue";
10
+ import { TABLE_SEARCH_KEY } from "../constants/table";
11
+ import { useFocusKey } from "../composables/focus";
12
+ import Autocomplete from "./autocomplete";
13
+ import { icon } from "./icon";
14
+
15
+ type Instance = ComponentPublicInstance & { ctx?: unknown };
16
+
17
+ // Rendered as a plain component, as `wrap` renders its core: the attrs are
18
+ // the consumer's props, handed on whole rather than checked here.
19
+ const Core: Component = Autocomplete;
20
+
21
+ export default defineComponent({
22
+ name: "TableSearch",
23
+ inheritAttrs: false,
24
+ emits: ["update:open"],
25
+ setup(_, { attrs, slots, emit, expose }) {
26
+ const el = shallowRef<Instance | null>(null);
27
+ // The autocomplete's root is a fragment, so the input is reached from
28
+ // the key hint, which the autocomplete renders in the input's group.
29
+ const hint = shallowRef<HTMLElement | null>(null);
30
+ useFocusKey(
31
+ () => hint.value?.parentElement?.querySelector("input") ?? null,
32
+ TABLE_SEARCH_KEY,
33
+ );
34
+ expose({ ctx: computed(() => el.value?.ctx) });
35
+ return (): VNode =>
36
+ h(
37
+ Core,
38
+ {
39
+ ...attrs,
40
+ "onUpdate:open": (open: boolean) => emit("update:open", open),
41
+ ref: el,
42
+ },
43
+ {
44
+ inputPrepend: () => [icon("magic")],
45
+ inputAppend: () => [
46
+ h(
47
+ "kbd",
48
+ { ref: hint, class: "f-kbd", "aria-hidden": "true" },
49
+ TABLE_SEARCH_KEY,
50
+ ),
51
+ ],
52
+ ...slots,
53
+ },
54
+ );
55
+ },
56
+ });
@@ -1,7 +1,9 @@
1
1
  // The vue table with the layer's parts behind its own: NuxtLink under the
2
2
  // body's `link`, the layer's Menu for row actions (so an action's `icon`
3
3
  // draws), the layer's Checkbox for the row and select-all checkboxes, the
4
- // layer's Command behind the column manager, and the layer's Pagination.
4
+ // layer's Command behind the column manager, the layer's TableSearch (its
5
+ // Autocomplete with the `magic` icon, the `/` key hint, and the `/` key
6
+ // focusing it) as the search, and the layer's Pagination.
5
7
  // Its Fab slots draw the `refresh`, `columns`, and `actions` icons; the
6
8
  // head draws `drag` on each handle and `sort-asc` or `sort-desc` after a
7
9
  // sorted header; a bulk action draws its own `icon`.
@@ -18,11 +20,13 @@ import Checkbox from "./checkbox";
18
20
  import Command from "./command";
19
21
  import Menu from "./menu";
20
22
  import Pagination from "./pagination";
23
+ import TableSearch from "./table-search";
21
24
  import { icon, iconOf, iconPart } from "./icon";
22
25
 
23
26
  export default wrap(Core, {
24
27
  pt: (pt) => ({
25
28
  ...pt,
29
+ search: { as: TableSearch, ...pt?.search },
26
30
  pagination: { as: Pagination, ...pt?.pagination },
27
31
  head: layer<TableHeadPassthrough>(pt?.head, {
28
32
  selectAllCheckbox: { as: Checkbox },
@@ -0,0 +1,58 @@
1
+ import type { MaybeRefOrGetter } from "vue";
2
+
3
+ import { useMagicKeys, whenever } from "@vueuse/core";
4
+ import { toValue } from "vue";
5
+
6
+ /**
7
+ * Where a keypress is already text: a field, a text area, a select, or an
8
+ * editable region. A key pressed in one of these belongs to it.
9
+ */
10
+ const EDITABLE =
11
+ "input, textarea, select, [contenteditable]:not([contenteditable='false'])";
12
+
13
+ const MODIFIERS = ["control", "meta", "alt"];
14
+
15
+ const editing = (target: EventTarget | null): boolean =>
16
+ target instanceof Element && target.closest(EDITABLE) !== null;
17
+
18
+ /**
19
+ * Focuses `target` when `key` is pressed on its own, anywhere on the page
20
+ * the user is not already typing. The listener is the window's, through
21
+ * `useMagicKeys`, and is removed with the calling component. A press the
22
+ * composable claims is cancelled, so the key does not land in the field it
23
+ * focuses; a press with a modifier held, or inside an editable element, is
24
+ * left to its own handler. Where two callers share a key, the last mounted
25
+ * takes the focus.
26
+ *
27
+ * @param target - The element to focus, or a source of it.
28
+ * @param key - The key, as `KeyboardEvent.key` names it (`/`).
29
+ */
30
+ export const useFocusKey = (
31
+ target: MaybeRefOrGetter<HTMLElement | null | undefined>,
32
+ key: string,
33
+ ): void => {
34
+ const claims = (event: KeyboardEvent): boolean =>
35
+ event.type === "keydown" &&
36
+ event.key === key &&
37
+ !event.ctrlKey &&
38
+ !event.metaKey &&
39
+ !event.altKey &&
40
+ !editing(event.target);
41
+
42
+ const keys = useMagicKeys({
43
+ passive: false,
44
+ onEventFired: (event) => {
45
+ if (claims(event)) event.preventDefault();
46
+ },
47
+ });
48
+
49
+ whenever(
50
+ () => keys[key]?.value === true,
51
+ () => {
52
+ if (MODIFIERS.some((modifier) => keys.current.has(modifier))) return;
53
+ if (editing(document.activeElement)) return;
54
+ toValue(target)?.focus();
55
+ },
56
+ { flush: "sync" },
57
+ );
58
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The key that focuses a table's search from anywhere on the page, as
3
+ * `KeyboardEvent.key` names it. The search draws it as its key hint.
4
+ */
5
+ export const TABLE_SEARCH_KEY = "/";
@@ -57,6 +57,7 @@ export const COMPONENTS = [
57
57
  // vue component, so no separate declaration is needed.
58
58
  export const WRAPPED = [
59
59
  "accordion",
60
+ "autocomplete",
60
61
  "breadcrumb",
61
62
  "browser",
62
63
  "calendar",
@@ -136,6 +137,7 @@ export const DEFINITIONS = [
136
137
  // `utils/` is plumbing the factories use and is not registered.
137
138
  export const LAYER = {
138
139
  "composables/error": ["useAppError"],
140
+ "composables/focus": ["useFocusKey"],
139
141
  "composables/hook": ["useHooks"],
140
142
  "composables/log": ["useLogger"],
141
143
  "composables/notification": ["useNotifications"],
@@ -146,6 +148,7 @@ export const LAYER = {
146
148
  "ERROR_NOT_FOUND_STATUS_CODE",
147
149
  ],
148
150
  "constants/log": ["LOG_ROOT_NAME", "LOG_LEVELS"],
151
+ "constants/table": ["TABLE_SEARCH_KEY"],
149
152
  "factories/browser": ["createBrowser"],
150
153
  "factories/code": ["createCode"],
151
154
  "factories/editor": ["createEditor"],
package/nuxt.config.ts CHANGED
@@ -4,7 +4,7 @@ import { defineNuxtConfig } from "nuxt/config";
4
4
  export default defineNuxtConfig({
5
5
  compatibilityDate: "2025-11-06",
6
6
 
7
- modules: ["@icon-sheets/nuxt"],
7
+ modules: ["@icon-sheets/nuxt", "@untheme/nuxt"],
8
8
 
9
9
  imports: { autoImport: false, scan: false },
10
10
 
@@ -15,6 +15,8 @@ export default defineNuxtConfig({
15
15
 
16
16
  iconSheets: { preset: "@zoobzio/icons" },
17
17
 
18
+ untheme: { preset: "@zoobzio/theme" },
19
+
18
20
  css: [fileURLToPath(new URL("./app/assets/css/reset.css", import.meta.url))],
19
21
 
20
22
  build: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoobzio/nuxt",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Nuxt layer for the foundation design system: the Nuxt wiring over @zoobzio/vue and the headless services (useState stores, hook-bus factories, app shell).",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -38,16 +38,21 @@
38
38
  "dependencies": {
39
39
  "@icon-sheets/nuxt": "0.0.8",
40
40
  "@nuxt/kit": "^4.5.0",
41
+ "@untheme/nuxt": "^0.6.1",
42
+ "@vueuse/core": "^14.3.0",
41
43
  "ltrl-http": "^0.0.20",
42
44
  "objectively": "^0.3.0",
43
45
  "reka-ui": "^2.6.0",
44
- "@zoobzio/browser": "0.0.13",
45
- "@zoobzio/code": "0.0.13",
46
- "@zoobzio/editor": "0.0.13",
47
- "@zoobzio/form": "0.0.13",
48
- "@zoobzio/icons": "0.0.13",
49
- "@zoobzio/table": "0.0.13",
50
- "@zoobzio/vue": "0.0.13"
46
+ "untheme": "^0.6.1",
47
+ "@zoobzio/browser": "0.0.14",
48
+ "@zoobzio/code": "0.0.14",
49
+ "@zoobzio/form": "0.0.14",
50
+ "@zoobzio/editor": "0.0.14",
51
+ "@zoobzio/icons": "0.0.14",
52
+ "@zoobzio/query": "0.0.14",
53
+ "@zoobzio/theme": "0.0.14",
54
+ "@zoobzio/table": "0.0.14",
55
+ "@zoobzio/vue": "0.0.14"
51
56
  },
52
57
  "devDependencies": {
53
58
  "@codemirror/state": "^6.7.6",