@zoobzio/nuxt 0.1.8 → 0.1.10

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.
@@ -0,0 +1,19 @@
1
+ // The vue image input with its pick and remove labels in the visitor's
2
+ // locale, the `image` icon in its placeholder, and the `camera` and
3
+ // `remove` icons before the pick and remove labels.
4
+ import Core from "@zoobzio/vue/components/image-input.vue";
5
+
6
+ import { icon } from "./icon";
7
+ import { textIn } from "./text";
8
+ import { wrap } from "@zoobzio/vue/utils/wrap";
9
+
10
+ export default wrap(Core, {
11
+ slots: {
12
+ placeholderContent: () => [icon("image")],
13
+ pickPrepend: () => [icon("camera")],
14
+ pickText: ({ src }) =>
15
+ textIn("span", "f-span", src ? "imageInput.change" : "imageInput.choose"),
16
+ removePrepend: () => [icon("remove")],
17
+ removeText: () => textIn("span", "f-span", "imageInput.remove"),
18
+ },
19
+ });
@@ -3,12 +3,14 @@
3
3
  // draws), the layer's Checkbox for the row and select-all checkboxes, the
4
4
  // layer's Command behind the column manager, the layer's TableSearch (its
5
5
  // Autocomplete with the `magic` icon, the `/` key hint, and the `/` key
6
- // focusing it) as the search, and the layer's Pagination.
6
+ // focusing it) as the search, the layer's Scroller around the `table`
7
+ // element, and the layer's Pagination.
7
8
  // Its Fab slots draw the `refresh`, `columns`, and `actions` icons; the
8
9
  // head draws `drag` on each handle, a column's own `icon` before its
9
10
  // header, and `sort-asc` or `sort-desc` after a sorted header; a bulk action
10
11
  // draws its own `icon`. Its own text — the toolbar's labels and
11
- // placeholders, the empty state, the clear button — reads in the
12
+ // placeholders, the empty state, the clear button, the name of a column's
13
+ // resizer — reads in the
12
14
  // visitor's locale, and a date, number, currency, file size or boolean
13
15
  // cell formats through the app's prosary service, a date or a datetime in
14
16
  // the table's time zone.
@@ -16,10 +18,12 @@ import type {
16
18
  TableBodyPassthrough,
17
19
  TableCellContext,
18
20
  } from "@zoobzio/vue/types/components/table-body";
21
+ import type { RowData } from "@zoobzio/table";
19
22
  import type { TableColumnsPassthrough } from "@zoobzio/vue/types/components/table-columns";
20
23
  import type { TableHeadPassthrough } from "@zoobzio/vue/types/components/table-head";
21
24
 
22
25
  import Core from "@zoobzio/vue/components/table.vue";
26
+ import { columnLabel } from "@zoobzio/vue/utils/table";
23
27
 
24
28
  import NuxtLink from "#app/components/nuxt-link";
25
29
  import { layer } from "@zoobzio/vue/utils/passthrough";
@@ -28,6 +32,7 @@ import Checkbox from "./checkbox";
28
32
  import Command from "./command";
29
33
  import Menu from "./menu";
30
34
  import Pagination from "./pagination";
35
+ import Scroller from "./scroller";
31
36
  import TableSearch from "./table-search";
32
37
  import { icon, iconOf, iconPart } from "./icon";
33
38
  import { cellSlots } from "./cell";
@@ -43,10 +48,16 @@ export default wrap(Core, {
43
48
  },
44
49
  refresh: { label: text("table.refresh"), ...pt?.refresh },
45
50
  pagination: { as: Pagination, ...pt?.pagination },
46
- head: layer<TableHeadPassthrough>(pt?.head, {
51
+ scroller: { as: Scroller, ...pt?.scroller },
52
+ head: layer<TableHeadPassthrough<RowData>>(pt?.head, {
47
53
  selectAllCheckbox: { as: Checkbox },
54
+ resizer: (column) => ({
55
+ "aria-label": text("table.resize", {
56
+ column: text(columnLabel(column)),
57
+ }),
58
+ }),
48
59
  }),
49
- body: layer<TableBodyPassthrough<unknown>>(pt?.body, {
60
+ body: layer<TableBodyPassthrough<RowData>>(pt?.body, {
50
61
  link: () => ({ as: NuxtLink }),
51
62
  rowCheckbox: { as: Checkbox },
52
63
  actionsTrigger: { label: text("table.actions") },
@@ -58,16 +69,16 @@ export default wrap(Core, {
58
69
  }),
59
70
  }),
60
71
  slots: {
61
- ...cellSlots<TableCellContext<unknown>>(({ table }) => table),
72
+ ...cellSlots<TableCellContext<RowData>>(({ table }) => table),
62
73
  refresh: ({ settings }) => iconPart(settings.refresh, "refresh"),
63
74
  columns: ({ settings }) => iconPart(settings.trigger, "columns"),
64
75
  actions: ({ settings }) => iconPart(settings.actionsTrigger, "actions"),
65
76
  dragPrepend: () => [icon("drag")],
66
- headerPrepend: ({ column }) => iconOf(column.icon),
67
- headerAppend: ({ table, column }) =>
68
- table.isSorted(column)
69
- ? [icon(table.sortDirection === "asc" ? "sort-asc" : "sort-desc")]
70
- : [],
77
+ headerPrepend: ({ column }) => iconOf(column.columnDef.meta?.icon),
78
+ headerAppend: ({ column }) => {
79
+ const sorted = column.getIsSorted();
80
+ return sorted ? [icon(sorted === "asc" ? "sort-asc" : "sort-desc")] : [];
81
+ },
71
82
  bulkActionPrepend: ({ action }) => iconOf(action.icon),
72
83
  bulkClear: () => textSlot("table.clear"),
73
84
  empty: () => textSlot("table.empty"),
@@ -0,0 +1,68 @@
1
+ // The vue views with the layer's parts behind its own: the layer's Tabs
2
+ // (so a view's name reads from the contract where it is a key of it), its
3
+ // Menu, its Fab behind the menu, and its Dialog for the confirmation and
4
+ // for naming a view. The menu's trigger draws the `settings` icon before
5
+ // its label and `expand` after it. Its own text — the actions, the dialogs' titles,
6
+ // bodies and buttons, the name of the mark on an edited view's tab —
7
+ // reads in the visitor's locale.
8
+ import Core from "@zoobzio/vue/components/views.vue";
9
+
10
+ import { h } from "vue";
11
+ import { wrap } from "@zoobzio/vue/utils/wrap";
12
+ import Dialog from "./dialog";
13
+ import Fab from "./fab";
14
+ import Menu from "./menu";
15
+ import Tabs from "./tabs";
16
+ import { icon } from "./icon";
17
+ import { text, textIn, textSlot } from "./text";
18
+
19
+ export default wrap(Core, {
20
+ // The layer's Fab and Dialog resolve the texts they are handed, so a
21
+ // part names a key of the contract and never calls `text` out of a
22
+ // render.
23
+ pt: {
24
+ tabs: { as: Tabs },
25
+ menu: { as: Menu },
26
+ trigger: { as: Fab, label: "views.menu" },
27
+ confirm: (kind) => ({
28
+ as: Dialog,
29
+ title: `views.${kind}Title`,
30
+ description: `views.${kind}Description`,
31
+ }),
32
+ naming: (mode) => ({
33
+ as: Dialog,
34
+ title: `views.${mode}Title`,
35
+ description: "views.nameDescription",
36
+ }),
37
+ },
38
+ slots: {
39
+ badge: ({ option }) =>
40
+ option.drifted
41
+ ? [
42
+ h("span", {
43
+ class: "f-span f-views-badge",
44
+ role: "img",
45
+ "aria-label": text("views.edited"),
46
+ }),
47
+ ]
48
+ : [],
49
+ // The trigger part with the icons around its label. The label is the
50
+ // part's own, so a consumer's `pt.trigger.label` still names it.
51
+ trigger: ({ settings }) => {
52
+ const { as, ...props } = settings.trigger;
53
+ return [
54
+ h(as, props, () => [
55
+ icon("settings"),
56
+ h("span", { class: "f-span" }, text(props.label ?? "views.menu")),
57
+ icon("expand"),
58
+ ]),
59
+ ];
60
+ },
61
+ actionLabel: ({ item }) =>
62
+ textIn("span", "f-span", text(`views.${item.key}`)),
63
+ nameLabel: () => textSlot("views.name"),
64
+ cancelLabel: () => textSlot("views.cancel"),
65
+ saveLabel: () => textSlot("views.save"),
66
+ proceedLabel: ({ kind }) => textSlot(`views.${kind}Proceed`),
67
+ },
68
+ });
@@ -0,0 +1,26 @@
1
+ import type { IconAlias } from "../types/icon";
2
+ import type { AppMessage } from "../types/text";
3
+
4
+ /**
5
+ * The icon of each calendar tool, by the tool's key: the two steps. Today
6
+ * and the views have none: each reads by name. The calendar wrapper draws
7
+ * these as each button's content, in place of the label text.
8
+ */
9
+ export const CALENDAR_TOOL_ICONS: Readonly<Record<string, IconAlias>> = {
10
+ prev: "prev",
11
+ next: "next",
12
+ };
13
+
14
+ /**
15
+ * The message of each calendar tool's label, by the tool's key: today, the
16
+ * two steps, and the views.
17
+ */
18
+ export const CALENDAR_TOOL_TEXT: Readonly<Record<string, AppMessage>> = {
19
+ today: "calendar.today",
20
+ prev: "calendar.previous",
21
+ next: "calendar.next",
22
+ month: "calendar.month",
23
+ week: "calendar.week",
24
+ day: "calendar.day",
25
+ agenda: "calendar.agenda",
26
+ };
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+
3
+ const entry = z.discriminatedUnion("kind", [
4
+ z.object({
5
+ kind: z.literal("literal"),
6
+ key: z.string(),
7
+ value: z.string(),
8
+ }),
9
+ z.object({
10
+ kind: z.literal("filter"),
11
+ key: z.string(),
12
+ op: z.string().optional(),
13
+ value: z.string(),
14
+ }),
15
+ ]);
16
+
17
+ /**
18
+ * The schema of a table's saved view: what the table's `snapshot` yields
19
+ * and its `restore` takes. Hand it to `createViews` for views over a
20
+ * table. Every member has a default, so a view stored before a member
21
+ * existed still reads; an app with more to save in a view extends it.
22
+ */
23
+ export const TABLE_VIEW_SCHEMA = z.object({
24
+ sorting: z.array(z.object({ id: z.string(), desc: z.boolean() })).default([]),
25
+ columnOrder: z.array(z.string()).default([]),
26
+ columnVisibility: z.record(z.string(), z.boolean()).default({}),
27
+ columnSizing: z.record(z.string(), z.number()).default({}),
28
+ pageSize: z.number().int().positive().default(10),
29
+ entries: z.array(entry).default([]),
30
+ });
31
+
32
+ /**
33
+ * The schema of a browser's saved view: what the browser's `snapshot`
34
+ * yields and its `restore` takes.
35
+ */
36
+ export const BROWSER_VIEW_SCHEMA = z.object({
37
+ sortField: z.string().nullable().default(null),
38
+ sortDirection: z.enum(["asc", "desc"]).default("asc"),
39
+ entries: z.array(entry).default([]),
40
+ });
@@ -3,6 +3,7 @@ import type { Actions, Config, Service } from "@zoobzio/browser";
3
3
 
4
4
  import { useNuxtApp } from "#app";
5
5
  import { BrowserService } from "@zoobzio/browser";
6
+ import { QUERY_TEXT_KEY, QUERY_TEXT_LITERAL } from "@zoobzio/query";
6
7
  import { accessBrowser } from "../stores/browser";
7
8
  import { split } from "../utils/actions";
8
9
  import { resolveTexts } from "../utils/text";
@@ -13,11 +14,14 @@ import { resolveTexts } from "../utils/text";
13
14
  * the wiring (the fetch and the handlers), and `id` keys everything that
14
15
  * follows. Each call of the composable, in setup, builds a service over
15
16
  * the id's shared store and relays its domain events onto the app logger and the Nuxt hook
16
- * bus as `browser:updated` and `browser:navigated`. Every text of the
17
- * config — the columns' and the actions' labels, the root crumb's —
18
- * resolves through the app's prosary service as the service is built. A
19
- * config that names no `rootLabel` takes the contract's `browser.root`,
20
- * so the root crumb reads in the visitor's locale. The machine itself is
17
+ * bus as `browser:updated`, `browser:navigated`, `browser:filtered`, and
18
+ * `browser:restored`.
19
+ * Every text of the config — the columns' and the actions' labels, the
20
+ * root crumb's, the literals' — resolves through the app's prosary service
21
+ * as the service is built. A config that names no `rootLabel` takes the
22
+ * contract's `browser.root`, and one that names no `literals` the query's
23
+ * text literal under `browser.text`, so the root crumb and the search's
24
+ * leading option read in the visitor's locale. The machine itself is
21
25
  * `@zoobzio/browser`; the Vue browser renders it through its `service`
22
26
  * prop.
23
27
  */
@@ -33,6 +37,9 @@ export const createBrowser = <T>(
33
37
  const config: Config<T> = {
34
38
  ...rest,
35
39
  rootLabel: rest.rootLabel ?? "browser.root",
40
+ literals: rest.literals ?? {
41
+ [QUERY_TEXT_KEY]: { ...QUERY_TEXT_LITERAL, label: "browser.text" },
42
+ },
36
43
  actions: files.descriptors,
37
44
  folderActions: folders.descriptors,
38
45
  bulkActions: bulk.descriptors,
@@ -57,6 +64,14 @@ export const createBrowser = <T>(
57
64
  log.debug("Browser navigated", event);
58
65
  nuxt.callHook("browser:navigated", event);
59
66
  });
67
+ service.on("filtered", (event) => {
68
+ log.debug("Browser filtered", event);
69
+ nuxt.callHook("browser:filtered", event);
70
+ });
71
+ service.on("restored", (event) => {
72
+ log.debug("Browser restored", event);
73
+ nuxt.callHook("browser:restored", event);
74
+ });
60
75
  return service;
61
76
  };
62
77
  };
@@ -0,0 +1,48 @@
1
+ import type { CalendarOptions, UseCalendar } from "../types/calendar";
2
+ import type { Actions, Config, Service } from "@zoobzio/calendar";
3
+
4
+ import { useNuxtApp } from "#app";
5
+ import { CalendarService } from "@zoobzio/calendar";
6
+ import { accessCalendar } from "../stores/calendar";
7
+
8
+ /**
9
+ * Builds the id-scoped composable of a calendar. Call it at module scope:
10
+ * the options split once into the headless config and the actions (the
11
+ * reader, the writer, the fetch, the save), and `id` keys everything that
12
+ * follows. Each call of the composable, in setup, builds a service over
13
+ * the id's shared store and relays its domain events onto the app logger
14
+ * and the Nuxt hook bus under the `calendar:` prefix. The machine itself
15
+ * is `@zoobzio/calendar`; the Vue calendar renders it through its
16
+ * `service` prop.
17
+ */
18
+ export const createCalendar = <I, O>(
19
+ id: string,
20
+ options: CalendarOptions<I, O>,
21
+ ): UseCalendar<I, O> => {
22
+ const { read, write, fetch, save, now, uid, initial, ...config } = options;
23
+ const wiring: Actions<I, O> = { read, write, fetch, save, now, uid };
24
+ const settings: Config = config;
25
+ return (): Service<I, O> => {
26
+ const nuxt = useNuxtApp();
27
+ const log = nuxt.$logger(id);
28
+ const state = accessCalendar(id, settings, initial);
29
+ const service = new CalendarService<I, O>(id, settings, state, wiring);
30
+ service.on("navigated", (event) => {
31
+ log.debug("Calendar navigated", event);
32
+ nuxt.callHook("calendar:navigated", event);
33
+ });
34
+ service.on("loaded", (event) => {
35
+ log.debug("Calendar loaded", event);
36
+ nuxt.callHook("calendar:loaded", event);
37
+ });
38
+ service.on("changed", (event) => {
39
+ log.debug("Calendar changed", event);
40
+ nuxt.callHook("calendar:changed", event);
41
+ });
42
+ service.on("selected", (event) => {
43
+ log.debug("Calendar selected", event);
44
+ nuxt.callHook("calendar:selected", event);
45
+ });
46
+ return service;
47
+ };
48
+ };
@@ -1,6 +1,7 @@
1
1
  import type { TableOptions, UseTable } from "../types/table";
2
- import type { Actions, Config, Service } from "@zoobzio/table";
2
+ import type { Actions, Config, RowData, Service } from "@zoobzio/table";
3
3
 
4
+ import { toValue } from "vue";
4
5
  import { useNuxtApp } from "#app";
5
6
  import { QUERY_TEXT_KEY, QUERY_TEXT_LITERAL } from "@zoobzio/query";
6
7
  import { TableService } from "@zoobzio/table";
@@ -14,21 +15,24 @@ import { resolveTexts } from "../utils/text";
14
15
  * wiring (the fetch and the handlers), and `id` keys everything that
15
16
  * follows. Each call of the composable, in setup, builds a service over
16
17
  * the id's shared store and relays its domain events onto the app logger and the Nuxt hook
17
- * bus as `table:updated` and `table:filtered`. Every text of the config —
18
- * the columns' and the actions' labels, the literals' — resolves through
18
+ * bus as `table:updated`, `table:filtered`, and `table:restored`. Every text of the config —
19
+ * the labels of the columns' `meta` and of the actions, the literals' — resolves through
19
20
  * the app's prosary service as the service is built, so a label that is a
20
21
  * key of the app's contract reaches the machine — and the search that
21
22
  * matches a typed prefix against it — as the visitor reads it. A config
22
23
  * that names no literals takes the query's text literal under the
23
24
  * contract's `table.text`, so its option reads in the visitor's locale as
24
- * the search's placeholder does. The machine itself is `@zoobzio/table`;
25
+ * the search's placeholder does. The composable takes the permissions of
26
+ * the visitor it is called for, as a record, a ref, or a getter: they
27
+ * stand over the options' `permissions`, key by key, and are read on every
28
+ * check. The machine itself is `@zoobzio/table`;
25
29
  * the Vue table renders it through its `service` prop.
26
30
  */
27
- export const createTable = <T>(
31
+ export const createTable = <T extends RowData>(
28
32
  id: string,
29
33
  options: TableOptions<T>,
30
34
  ): UseTable<T> => {
31
- const { fetch, actions, bulkActions, initial, ...rest } = options;
35
+ const { fetch, actions, bulkActions, ...rest } = options;
32
36
  const rows = split(actions);
33
37
  const bulk = split(bulkActions);
34
38
  const config: Config<T> = {
@@ -44,11 +48,17 @@ export const createTable = <T>(
44
48
  actions: rows.handlers,
45
49
  bulkActions: bulk.handlers,
46
50
  };
47
- return (): Service<T> => {
51
+ return (permissions): Service<T> => {
48
52
  const nuxt = useNuxtApp();
49
53
  const log = nuxt.$logger(id);
50
54
  const resolved = resolveTexts(nuxt.$prosary, config);
51
- const state = accessTable(id, resolved, initial);
55
+ // Past the copy `resolveTexts` makes, so the source is read as it
56
+ // stands on every check.
57
+ Object.defineProperty(resolved, "permissions", {
58
+ get: () => ({ ...config.permissions, ...toValue(permissions) }),
59
+ enumerable: true,
60
+ });
61
+ const state = accessTable(id, resolved);
52
62
  const service = new TableService(id, resolved, state, wiring);
53
63
  service.on("updated", (event) => {
54
64
  log.debug("Table updated", event);
@@ -58,6 +68,10 @@ export const createTable = <T>(
58
68
  log.debug("Table filtered", event);
59
69
  nuxt.callHook("table:filtered", event);
60
70
  });
71
+ service.on("restored", (event) => {
72
+ log.debug("Table restored", event);
73
+ nuxt.callHook("table:restored", event);
74
+ });
61
75
  return service;
62
76
  };
63
77
  };
@@ -0,0 +1,70 @@
1
+ import type { UseViews, ViewsOptions, ViewsTarget } from "../types/views";
2
+ import type { Config, Service } from "@zoobzio/views";
3
+
4
+ import { useNuxtApp } from "#app";
5
+ import { ViewsService } from "@zoobzio/views";
6
+ import { accessViews } from "../stores/views";
7
+
8
+ /**
9
+ * Builds the id-scoped composable of a set of saved views. Call it at
10
+ * module scope: the options split once into the headless config and the
11
+ * storage, and `id` keys everything that follows. Each call of the
12
+ * composable, in setup, takes what the views are over (a table or a
13
+ * browser service, or anything with a `snapshot` and a `restore`), builds
14
+ * a service over the id's shared store that reads and applies through it,
15
+ * and relays its domain events onto the app logger and the Nuxt hook bus
16
+ * under the `views:` prefix. A view's name is not resolved here: the
17
+ * layer's tabs read it from the app's contract where it is a key of it,
18
+ * so the app's own views read in the visitor's locale and a user's stand
19
+ * as typed. The machine itself is `@zoobzio/views`; the Vue views render
20
+ * it through their `service` prop.
21
+ */
22
+ export const createViews = <P>(
23
+ id: string,
24
+ options: ViewsOptions<P>,
25
+ ): UseViews<P> => {
26
+ const { load, save, remove, key, ...config } = options;
27
+ const resolved: Config<P> = config;
28
+ return (target: ViewsTarget<P>): Service<P> => {
29
+ const nuxt = useNuxtApp();
30
+ const log = nuxt.$logger(id);
31
+ const state = accessViews(id, resolved);
32
+ const service = new ViewsService(id, resolved, state, {
33
+ read: () => target.snapshot(),
34
+ apply: (payload) => target.restore(payload),
35
+ load,
36
+ save,
37
+ remove,
38
+ key,
39
+ });
40
+ service.on("initialized", (event) => {
41
+ log.debug("Views initialized", event);
42
+ nuxt.callHook("views:initialized", event);
43
+ });
44
+ service.on("selected", (event) => {
45
+ log.debug("Views selected", event);
46
+ nuxt.callHook("views:selected", event);
47
+ });
48
+ service.on("saved", (event) => {
49
+ log.debug("Views saved", event);
50
+ nuxt.callHook("views:saved", event);
51
+ });
52
+ service.on("renamed", (event) => {
53
+ log.debug("Views renamed", event);
54
+ nuxt.callHook("views:renamed", event);
55
+ });
56
+ service.on("removed", (event) => {
57
+ log.debug("Views removed", event);
58
+ nuxt.callHook("views:removed", event);
59
+ });
60
+ service.on("reverted", (event) => {
61
+ log.debug("Views reverted", event);
62
+ nuxt.callHook("views:reverted", event);
63
+ });
64
+ service.on("failed", (event) => {
65
+ log.debug("Views failed", event);
66
+ nuxt.callHook("views:failed", event);
67
+ });
68
+ return service;
69
+ };
70
+ };
@@ -0,0 +1,24 @@
1
+ import type { CalendarInitial } from "../types/calendar";
2
+ import type { Config, State } from "@zoobzio/calendar";
3
+
4
+ import { useState } from "#app";
5
+ import { createCalendarState } from "@zoobzio/calendar";
6
+ import { seed } from "../utils/state";
7
+
8
+ /**
9
+ * The Nuxt backing for a calendar's state container: one `useState` record
10
+ * keyed `calendar-<id>`. Its value is a reactive proxy, so the service's
11
+ * field writes are tracked; instances sharing an id share the container
12
+ * across the app, and it survives SSR hydration, the entries the server
13
+ * fetched and the day it read as today included. `config` and `initial`
14
+ * shape the record once, when it is first created; later calls under the
15
+ * same id get the record as it stands.
16
+ */
17
+ export const accessCalendar = (
18
+ id: string,
19
+ config: Config = {},
20
+ initial?: CalendarInitial,
21
+ ): State =>
22
+ useState<State>(`calendar-${id}`, () =>
23
+ seed(createCalendarState(config), initial),
24
+ ).value;
@@ -1,23 +1,18 @@
1
- import type { TableInitial } from "../types/table";
2
- import type { Config, State } from "@zoobzio/table";
1
+ import type { Config, RowData, State } from "@zoobzio/table";
3
2
 
4
3
  import { useState } from "#app";
5
4
  import { createTableState } from "@zoobzio/table";
6
- import { seed } from "../utils/state";
7
5
 
8
6
  /**
9
7
  * The Nuxt backing for a table's state container: one `useState` record
10
8
  * keyed `table-<id>`. Its value is a reactive proxy, so the service's field
11
9
  * writes are tracked; instances sharing an id share the container across
12
- * the app, and it survives SSR hydration. `config` and `initial` shape the
13
- * record once, when it is first created; later calls under the same id get
14
- * the record as it stands.
10
+ * the app, and it survives SSR hydration. `config` shapes the record once,
11
+ * when it is first created, its `initialState` and `initialEntries`
12
+ * included; later calls under the same id get the record as it stands.
15
13
  */
16
- export const accessTable = <T>(
14
+ export const accessTable = <T extends RowData>(
17
15
  id: string,
18
16
  config: Config<T>,
19
- initial?: TableInitial<T>,
20
17
  ): State<T> =>
21
- useState<State<T>>(`table-${id}`, () =>
22
- seed(createTableState(config), initial),
23
- ).value;
18
+ useState<State<T>>(`table-${id}`, () => createTableState(config)).value;
@@ -0,0 +1,15 @@
1
+ import type { Config, State } from "@zoobzio/views";
2
+
3
+ import { useState } from "#app";
4
+ import { createViewsState } from "@zoobzio/views";
5
+
6
+ /**
7
+ * The Nuxt backing for a views state container: one `useState` record
8
+ * keyed `views-<id>`. Its value is a reactive proxy, so the service's
9
+ * field writes are tracked; instances sharing an id share the container
10
+ * across the app, and it survives SSR hydration. `config` shapes the
11
+ * record once, when it is first created, its `views` and `initial`
12
+ * included; later calls under the same id get the record as it stands.
13
+ */
14
+ export const accessViews = <P>(id: string, config: Config<P>): State<P> =>
15
+ useState<State<P>>(`views-${id}`, () => createViewsState(config)).value;
@@ -20,25 +20,33 @@ export type BrowserAction<T> = Bound<ActionDescriptor, FileAction<T>["action"]>;
20
20
  /**
21
21
  * A folder action: its descriptor and its handler, under the config key.
22
22
  */
23
- export type BrowserFolderAction = Bound<
23
+ export type BrowserFolderAction<T = unknown> = Bound<
24
24
  ActionDescriptor,
25
- FolderAction["action"]
25
+ FolderAction<T>["action"]
26
26
  >;
27
27
 
28
28
  /**
29
- * A bulk action over the selected files: its descriptor and its handler,
30
- * under the config key.
29
+ * A bulk action over the selected files and folders: its descriptor and
30
+ * its handler, under the config key.
31
31
  */
32
32
  export type BrowserBulkAction = Bound<ActionDescriptor, BulkAction["action"]>;
33
33
 
34
34
  /**
35
35
  * The slice of the state container a browser may start from: the trail,
36
- * the file sort, and the selection the consumer chooses, never what a fetch
37
- * fills in. It seeds the `useState` record, so it must survive Nuxt's
36
+ * the file sort, the selection, and the search's entries the consumer
37
+ * chooses, never what a fetch fills in. It seeds the `useState` record, so it must survive Nuxt's
38
38
  * payload (devalue carries the `Set`).
39
39
  */
40
40
  export type BrowserInitial<T> = Partial<
41
- Pick<State<T>, "path" | "sortField" | "sortDirection" | "selected">
41
+ Pick<
42
+ State<T>,
43
+ | "path"
44
+ | "sortField"
45
+ | "sortDirection"
46
+ | "selected"
47
+ | "selectedFolders"
48
+ | "entries"
49
+ >
42
50
  >;
43
51
 
44
52
  /**
@@ -52,14 +60,14 @@ export type BrowserOptions<T> = Omit<
52
60
  > & {
53
61
  fetch: Actions<T>["fetch"];
54
62
  actions?: Record<string, BrowserAction<T>>;
55
- folderActions?: Record<string, BrowserFolderAction>;
63
+ folderActions?: Record<string, BrowserFolderAction<T>>;
56
64
  bulkActions?: Record<string, BrowserBulkAction>;
57
65
  initial?: BrowserInitial<T>;
58
66
  };
59
67
 
60
68
  /**
61
- * The Nuxt hooks a browser relays: `browser:updated` and
62
- * `browser:navigated`, each carrying the service's payload with its
69
+ * The Nuxt hooks a browser relays: `browser:updated`,
70
+ * `browser:navigated`, `browser:filtered`, and `browser:restored`, each carrying the service's payload with its
63
71
  * scoping `id`.
64
72
  */
65
73
  export type BrowserHooks = Hooks<"browser", Events<unknown>>;
@@ -0,0 +1,40 @@
1
+ import type { Hooks } from "./hooks";
2
+ import type {
3
+ Actions,
4
+ Config,
5
+ Events,
6
+ Service,
7
+ State,
8
+ } from "@zoobzio/calendar";
9
+
10
+ /**
11
+ * The slice of the state container a calendar may start from: the view,
12
+ * the date it is anchored on, and the selected occurrence, never what a
13
+ * fetch fills in. It seeds the `useState` record.
14
+ */
15
+ export type CalendarInitial = Partial<
16
+ Pick<State, "view" | "date" | "selected">
17
+ >;
18
+
19
+ /**
20
+ * What `createCalendar` takes: the headless config, the actions (the
21
+ * reader, the writer, the fetch, and the save), and the initial state.
22
+ * Config and actions share no key, so they sit side by side.
23
+ */
24
+ export type CalendarOptions<I, O> = Config &
25
+ Actions<I, O> & {
26
+ initial?: CalendarInitial;
27
+ };
28
+
29
+ /**
30
+ * The Nuxt hooks a calendar relays: `calendar:navigated`,
31
+ * `calendar:loaded`, `calendar:changed`, and `calendar:selected`, each
32
+ * carrying the service's payload with its scoping `id`.
33
+ */
34
+ export type CalendarHooks = Hooks<"calendar", Events<unknown>>;
35
+
36
+ /**
37
+ * The id-scoped composable `createCalendar` returns. Call it in setup;
38
+ * every call yields a service over the same shared container.
39
+ */
40
+ export type UseCalendar<I, O> = () => Service<I, O>;