@zoobzio/nuxt 0.1.9 → 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.
package/README.md CHANGED
@@ -99,14 +99,15 @@ way. Where a vue component renders another of its own as a part, the
99
99
  wrapper names the layer's wrapped component through the part's `as`, so
100
100
  nested components navigate through `NuxtLink` and draw their icons
101
101
  without the consumer reaching in: the table's row actions and the
102
- browser's file and folder actions render through the layer's `Menu`, the
103
- browser's trail through its `Breadcrumb`, the table's pagination, column
102
+ browser's file and folder actions and its sort options render through the
103
+ layer's `Menu`, the browser's trail through its `Breadcrumb` (under
104
+ `pt.head`), its search through the layer's `TableSearch`, the table's pagination, column
104
105
  manager command, and checkboxes through its `Pagination`, `Command`, and
105
106
  `Checkbox`, a form's fields through its `FormField` and that field's
106
107
  controls through its `Select`, `MultiSelect`, `Checkbox`, `DatePicker`,
107
- `TagsInput`, `FileInput`, and `RichText`, and the facets', keywords', and
108
+ `TagsInput`, `FileInput`, `ImageInput`, and `RichText`, and the facets', keywords', and
108
109
  date filters' popover contents through its `Command`, `TagsInput`,
109
- `SegmentedControl`, `Calendar`, and `RangeCalendar`.
110
+ `SegmentedControl`, `DateGrid`, and `DateRangeGrid`.
110
111
 
111
112
  ## Icons
112
113
 
@@ -140,24 +141,31 @@ A wrapper fills those slots from the contract by default through the
140
141
  one, and the wrapper's default fills in while it does not. A fixed role
141
142
  draws its alias: `expand` after a select's, multi select's, or
142
143
  accordion's trigger and as a tree branch's toggle; `prev` and `next` on
143
- the calendars and pickers and `calendar` on a picker's trigger; `search`
144
+ the date grids and pickers and `calendar` on a picker's trigger; `search`
144
145
  before a command's filter and before an autocomplete literal option that
145
146
  names no icon of its own (the text literal, the one that opens the quote
146
- free text is typed in); `remove` on a tag's and a file's remove
147
- button and after an autocomplete chip's label; `close` on a toast's; `top` on a scroller's back-to-top; `check`
147
+ free text is typed in); `remove` on a tag's, a file's, and an image
148
+ input's remove button, `image` in an image input's placeholder and
149
+ `camera` before its pick label; `remove` also after an autocomplete chip's label; `close` on a toast's; `top` on a scroller's back-to-top; `check`
148
150
  in a checkbox; the editor's and rich text's tools by key (`bold`,
149
151
  `bullet-list`, `undo`, …, see `EDITOR_TOOL_ICONS`), each drawn in place
150
152
  of the button's text so the toolbar is icon-only, with the tool's label in
151
153
  the visitor's locale as the button's accessible name and its `title`, and
152
154
  `expand` after the block type dropdown's text, which reads in the
153
- visitor's locale as its entries do; and on
155
+ visitor's locale as its entries do; the calendar's steps by key (`prev`,
156
+ `next`, see `CALENDAR_TOOL_ICONS`), drawn the same way, while today and
157
+ the views keep their names as text; and on
154
158
  the table and browser, `refresh`, `columns`, `actions`, `drag`,
155
159
  `sort-asc` or `sort-desc` after a sorted header, `folder` before a
156
- folder, `magic` before the table's search, `next` after an autocomplete
160
+ folder, `folder-open` before the root crumb of the browser's trail, `sort`
161
+ as the browser's sort trigger until its files sort by a column and
162
+ `sort-asc` or `sort-desc` from then on, as after that column's item in the
163
+ menu, `magic` before the table's and the browser's search, `next` after an autocomplete
157
164
  option that enters a stage (a field or an operator; a literal option is
158
165
  terminal and draws none) and
159
166
  `expand` after the active trail option whose stage is open, and the pagination's `first`,
160
- `prev`, `next`, and `last`. The table's search renders through the
167
+ `prev`, `next`, and `last`; and on the views' menu trigger, `settings`
168
+ before its label and `expand` after it. The table's search renders through the
161
169
  layer's `TableSearch`: its Autocomplete with the `magic` icon in
162
170
  `inputPrepend` at the front of the field, before its chips, the search
163
171
  key (`TABLE_SEARCH_KEY`, `/`) as a `kbd` in `inputAppend`, and that key
@@ -221,8 +229,8 @@ a form field or a toast takes a message in place of a string:
221
229
  ```ts
222
230
  const table = createTable("users", {
223
231
  columns: [
224
- { key: "name", label: "users.column.name" },
225
- { key: "role", label: "users.column.role" },
232
+ { accessorKey: "name", meta: { label: "users.column.name" } },
233
+ { accessorKey: "role", meta: { label: "users.column.role" } },
226
234
  ],
227
235
  actions: { remove: { label: "users.action.remove", action: (row) => … } },
228
236
  });
@@ -262,7 +270,8 @@ what reaches `@zoobzio/vue` is always a string:
262
270
  the columns, actions, fields and literals — once, when the service is
263
271
  built in setup, and lays the contract's messages under the defaults the
264
272
  headless packages ship in English: the query's text literal
265
- (`table.text`) and the browser's root crumb (`browser.root`). The
273
+ (`table.text`, `browser.text`) and the browser's root crumb
274
+ (`browser.root`). The
266
275
  search then matches a typed prefix against a column's label as the
267
276
  visitor reads it. The layer's `locale` plugin reloads the app when the
268
277
  visitor switches locale, so a built service never holds a stale one.
@@ -352,15 +361,18 @@ import { createTable } from "@zoobzio/nuxt/factories/table";
352
361
 
353
362
  export const useUsers = createTable<User>("users", {
354
363
  columns: [
355
- { key: "id", label: "ID", type: "number" },
356
- { key: "name", label: "Name", type: "text", sortable: true },
364
+ { accessorKey: "id", meta: { label: "ID", type: "number" } },
365
+ { accessorKey: "name", meta: { label: "Name", type: "text" } },
357
366
  ],
358
- rowKey: "id",
367
+ getRowId: (user) => user.id,
359
368
  fetch: (params) => $fetch("/api/users", { query: params }),
360
369
  actions: {
361
370
  edit: { label: "Edit", action: (user) => navigateTo(`/users/${user.id}`) },
362
371
  },
363
- initial: { pageSize: 50, sortField: "name" },
372
+ initialState: {
373
+ pagination: { pageIndex: 0, pageSize: 50 },
374
+ sorting: [{ id: "name", desc: false }],
375
+ },
364
376
  });
365
377
  ```
366
378
 
@@ -389,13 +401,28 @@ must be something Nuxt's payload can carry: plain data, with `Set` and
389
401
  `Date` allowed (devalue serializes them). A second id with the same
390
402
  options is a second, independent state.
391
403
 
392
- | Factory | Store | Hooks relayed |
393
- | --------------- | --------------- | --------------------------------------------------------------------------------------------------- |
394
- | `createTable` | `accessTable` | `table:updated`, `table:filtered` |
395
- | `createForm` | `accessForm` | `form:initialized`, `form:submitted`, `form:rejected`, `form:restored`, `form:reset`, `form:failed` |
396
- | `createBrowser` | `accessBrowser` | `browser:updated`, `browser:navigated` |
397
- | `createEditor` | `accessEditor` | `editor:loaded`, `editor:updated`, `editor:mounted`, `editor:unmounted` |
398
- | `createCode` | `accessCode` | `code:loaded`, `code:updated`, `code:mounted`, `code:unmounted` |
404
+ A table's composable takes the permissions of the visitor it is called
405
+ for: a record of booleans, or a ref or a getter of one, which the table
406
+ follows as it changes. They stand over the options' own `permissions`, key
407
+ by key, and one left out is granted.
408
+
409
+ ```ts
410
+ const session = useSession();
411
+ const users = useUsers(() => ({
412
+ bulkActions: session.can("users.write"),
413
+ reorder: session.can("users.arrange"),
414
+ }));
415
+ ```
416
+
417
+ | Factory | Store | Hooks relayed |
418
+ | ---------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------ |
419
+ | `createTable` | `accessTable` | `table:updated`, `table:filtered`, `table:restored` |
420
+ | `createForm` | `accessForm` | `form:initialized`, `form:submitted`, `form:rejected`, `form:restored`, `form:reset`, `form:failed` |
421
+ | `createBrowser` | `accessBrowser` | `browser:updated`, `browser:navigated`, `browser:filtered`, `browser:restored` |
422
+ | `createEditor` | `accessEditor` | `editor:loaded`, `editor:updated`, `editor:mounted`, `editor:unmounted` |
423
+ | `createCode` | `accessCode` | `code:loaded`, `code:updated`, `code:mounted`, `code:unmounted` |
424
+ | `createCalendar` | `accessCalendar` | `calendar:navigated`, `calendar:loaded`, `calendar:changed`, `calendar:selected` |
425
+ | `createViews` | `accessViews` | `views:initialized`, `views:selected`, `views:saved`, `views:renamed`, `views:removed`, `views:reverted`, `views:failed` |
399
426
 
400
427
  Every relayed payload carries the service's `id`. `useHooks` subscribes
401
428
  for one instance: each listener fires for events with that id only, and
@@ -413,6 +440,60 @@ useHooks("users", {
413
440
  Each relay is also logged at `debug` under the service's id (see
414
441
  [Logging](#logging)).
415
442
 
443
+ `createViews` builds saved views over another service. Its composable
444
+ takes what the views are over, anything with a `snapshot` and a `restore`,
445
+ which a table and a browser service each have; `TABLE_VIEW_SCHEMA` and
446
+ `BROWSER_VIEW_SCHEMA` are the Zod schemas of what each yields, and
447
+ `TableView` and `BrowserView` their types. Without a `load`, a `save`, and
448
+ a `remove` the views live in the store alone.
449
+
450
+ ```ts
451
+ import { TABLE_VIEW_SCHEMA } from "@zoobzio/nuxt/constants/views";
452
+ import { createViews } from "@zoobzio/nuxt/factories/views";
453
+
454
+ const all = TABLE_VIEW_SCHEMA.parse({});
455
+
456
+ export const useUserViews = createViews("users", {
457
+ schema: TABLE_VIEW_SCHEMA,
458
+ views: [
459
+ { id: "all", name: "All users", payload: all },
460
+ {
461
+ id: "newest",
462
+ name: "Newest",
463
+ payload: { ...all, sorting: [{ id: "created", desc: true }] },
464
+ },
465
+ ],
466
+ load: () => $fetch("/api/views/users"),
467
+ save: (view) =>
468
+ $fetch(`/api/views/users/${view.id}`, { method: "PUT", body: view }),
469
+ remove: (view) => $fetch(`/api/views/users/${view.id}`, { method: "DELETE" }),
470
+ });
471
+ ```
472
+
473
+ ```vue
474
+ <script setup lang="ts">
475
+ import { Table, Views } from "#components";
476
+
477
+ const users = useUsers();
478
+ const views = useUserViews(users);
479
+ // The views first: the active one is applied, and the table's first
480
+ // fetch reads it.
481
+ await views.init();
482
+ await users.init();
483
+ </script>
484
+
485
+ <template>
486
+ <Views :service="views" />
487
+ <Table :service="users" />
488
+ </template>
489
+ ```
490
+
491
+ `Views` draws the views as tabs with the active view's actions in a menu
492
+ beside them, marks the active tab once the table moves off it, and asks
493
+ before a switch, a discard, or a delete loses anything. A view's name
494
+ reads from the app's contract where it is a key of it, so the app's own
495
+ views read in the visitor's locale.
496
+
416
497
  The hook names and payloads are declared on `RuntimeNuxtHooks` in
417
498
  `app/app.d.ts`; the option, initial-state, and hook types live in
418
499
  `types/<name>`.
@@ -511,7 +592,7 @@ app/
511
592
  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
512
593
  error.vue — the error page
513
594
  app.d.ts — RuntimeNuxtHooks augmentation for the relayed events; the vue item types and the headless action descriptors widened with `icon`
514
- constants/ — error page status codes, log levels, the editor tools' icons, the table's search key
595
+ constants/ — error page status codes, log levels, the editor's and the calendar's tools' icons and text, the table's search key, the schemas of a table's and a browser's saved view
515
596
  assets/css/ — reset.css, loaded by the layer config
516
597
  composables/ — useAppError, useFocusKey, useHooks, useLogger, useNotifications, useRequest, useLazyRequest
517
598
  factories/ — create<Name>(id, options) → use<Name>(): Service
package/app/app.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import type { BrowserHooks } from "./types/browser";
2
+ import type { CalendarHooks } from "./types/calendar";
2
3
  import type { CodeHooks } from "./types/code";
3
4
  import type { EditorHooks } from "./types/editor";
4
5
  import type { FormHooks } from "./types/form";
5
6
  import type { Logger } from "./types/log";
6
7
  import type { IconAlias } from "./types/icon";
7
8
  import type { TableHooks } from "./types/table";
9
+ import type { ViewsHooks } from "./types/views";
8
10
  import type { AppMessage } from "./types/text";
11
+ import type { CellData, RowData, TableFeatures } from "@tanstack/table-core";
9
12
 
10
13
  // The text the packages carry admits the app's messages: a `label`,
11
14
  // `placeholder` or `hint` of any service or component takes a key of the
@@ -58,14 +61,22 @@ declare module "@zoobzio/vue/types/components/facets" {
58
61
  }
59
62
  }
60
63
 
61
- // A column's `icon` is drawn before its header, and carried onto its query
62
- // field by the table and onto its column-manager option by the vue table,
63
- // so the search and the manager draw it beside the column's label.
64
64
  declare module "@zoobzio/table" {
65
65
  interface ActionDescriptor {
66
66
  icon?: IconAlias;
67
67
  }
68
- interface DataTableColumn<T> {
68
+ }
69
+
70
+ // A table column's `icon`, on its `meta`, is drawn before its header, and
71
+ // carried onto its query field by the table and onto its column-manager
72
+ // option by the vue table, so the search and the manager draw it beside
73
+ // the column's label.
74
+ declare module "@tanstack/table-core" {
75
+ interface ColumnMeta<
76
+ in out TFeatures extends TableFeatures,
77
+ in out TData extends RowData,
78
+ TValue extends CellData = CellData,
79
+ > {
69
80
  icon?: IconAlias;
70
81
  }
71
82
  }
@@ -85,10 +96,16 @@ declare module "@zoobzio/query" {
85
96
  }
86
97
  }
87
98
 
99
+ // A browser column's `icon` is carried onto its query field by the browser
100
+ // and onto its sort item by the vue browser, so the search and the sort
101
+ // menu draw it beside the column's label.
88
102
  declare module "@zoobzio/browser" {
89
103
  interface ActionDescriptor {
90
104
  icon?: IconAlias;
91
105
  }
106
+ interface BrowserColumn<T> {
107
+ icon?: IconAlias;
108
+ }
92
109
  }
93
110
 
94
111
  declare module "#app" {
@@ -97,7 +114,14 @@ declare module "#app" {
97
114
  $logger: (name?: string) => Logger;
98
115
  }
99
116
  interface RuntimeNuxtHooks
100
- extends BrowserHooks, CodeHooks, EditorHooks, FormHooks, TableHooks {}
117
+ extends
118
+ BrowserHooks,
119
+ CalendarHooks,
120
+ CodeHooks,
121
+ EditorHooks,
122
+ FormHooks,
123
+ TableHooks,
124
+ ViewsHooks {}
101
125
  }
102
126
 
103
127
  export {};
@@ -1,14 +1,17 @@
1
1
  // The vue autocomplete with the layer's Scroller as its viewport, the
2
2
  // `remove` icon on each chip, an option's icon (or `search` for a literal)
3
- // before its label and an arrow after a field's, and its placeholder
4
- // resolved.
3
+ // before its label and an arrow after a field's, and its texts in the
4
+ // visitor's locale: the placeholder, and the empty, loading, and more
5
+ // states of its panel.
5
6
  import type { QueryOption } from "@zoobzio/vue/types/components/autocomplete";
7
+ import type { Text } from "@zoobzio/kit";
6
8
  import type { VNode } from "vue";
7
9
 
8
10
  import Core from "@zoobzio/vue/components/autocomplete.vue";
9
11
 
10
12
  import { icon, iconOf } from "./icon";
11
- import { textIf } from "./text";
13
+ import { h } from "vue";
14
+ import { textIf, textIn } from "./text";
12
15
  import { wrap } from "@zoobzio/vue/utils/wrap";
13
16
  import Scroller from "./scroller";
14
17
 
@@ -20,6 +23,19 @@ const arrow = (option: QueryOption): VNode[] => {
20
23
  return [icon(option.active ? "expand" : "next")];
21
24
  };
22
25
 
26
+ /**
27
+ * A state of the panel, as the component's own default renders it, with
28
+ * its text in the visitor's locale. A state that reports a lookup is a
29
+ * status.
30
+ */
31
+ const state = (value: Text, status?: boolean): VNode[] => [
32
+ h(
33
+ "div",
34
+ { class: "f-group", role: status ? "status" : undefined },
35
+ textIn("span", "f-span", value),
36
+ ),
37
+ ];
38
+
23
39
  export default wrap(Core, {
24
40
  props: (props) => ({ ...props, placeholder: textIf(props.placeholder) }),
25
41
  pt: { viewport: { as: Scroller } },
@@ -27,5 +43,8 @@ export default wrap(Core, {
27
43
  chipAppend: () => [icon("remove")],
28
44
  itemPrepend: ({ option }) => lead(option),
29
45
  itemArrow: ({ option }) => arrow(option),
46
+ empty: ({ empty }) => (empty ? state("autocomplete.empty") : []),
47
+ loading: () => state("autocomplete.loading", true),
48
+ more: () => state("autocomplete.more", true),
30
49
  },
31
50
  });
@@ -1,35 +1,61 @@
1
1
  // The vue browser with the layer's parts behind its own: the layer's
2
- // Breadcrumb as its trail, NuxtLink under the files' `link`, the layer's
3
- // Menu for file and folder actions (so an action's `icon` draws), the
4
- // layer's Checkbox for the row checkboxes. Its Fab slots draw the `refresh`
5
- // and `actions` icons, a folder draws `folder` before its name, a bulk
6
- // action its own `icon`. Its own text — the refresh and actions labels, the
7
- // empty states, the clear button — reads in the visitor's locale, and a
8
- // date, number, currency, file size or boolean cell formats through the
9
- // app's prosary service, a date or a datetime in the browser's time zone.
2
+ // TableSearch as its search (the Autocomplete with the `magic` icon, the
3
+ // `/` key hint, and the `/` key focusing it), the layer's Menu for the sort
4
+ // options and for file and folder actions (so a column's or an action's
5
+ // `icon` draws), the layer's Breadcrumb as its trail, NuxtLink under the
6
+ // files' `link`, the layer's Checkbox for the file, folder and select-all
7
+ // checkboxes. Its Fab slots draw the `sort`, `refresh` and `actions`
8
+ // icons: the sort trigger draws `sort` until the files sort by a column,
9
+ // then `sort-asc` or `sort-desc`, which the column's item in the menu draws
10
+ // too. The root crumb draws `folder-open`, a crumb below it its own `icon`,
11
+ // a folder draws `folder` before its name, a bulk action its own `icon`.
12
+ // Its own text — the search's placeholder, the sort, refresh and actions
13
+ // labels, the listing's counts, the empty states, the clear button — reads
14
+ // in the visitor's locale, and a date, number, currency, file size or
15
+ // boolean cell, a file's or a folder's, formats through the app's prosary
16
+ // service, a date or a datetime in the browser's time zone.
10
17
  import type {
11
18
  BrowserFileCellContext,
12
19
  BrowserFilesPassthrough,
13
20
  } from "@zoobzio/vue/types/components/browser-files";
14
- import type { BrowserFoldersPassthrough } from "@zoobzio/vue/types/components/browser-folders";
21
+ import type {
22
+ BrowserFolderCellContext,
23
+ BrowserFoldersPassthrough,
24
+ } from "@zoobzio/vue/types/components/browser-folders";
25
+ import type { BrowserHeadPassthrough } from "@zoobzio/vue/types/components/browser-head";
26
+ import type { Service } from "@zoobzio/browser";
15
27
 
16
28
  import Core from "@zoobzio/vue/components/browser.vue";
17
29
 
18
30
  import NuxtLink from "#app/components/nuxt-link";
19
- import { h } from "vue";
20
31
  import { layer } from "@zoobzio/vue/utils/passthrough";
21
32
  import { wrap } from "@zoobzio/vue/utils/wrap";
22
33
  import Breadcrumb from "./breadcrumb";
23
34
  import Checkbox from "./checkbox";
24
35
  import Menu from "./menu";
36
+ import TableSearch from "./table-search";
25
37
  import { icon, iconOf, iconPart } from "./icon";
26
- import { cellSlots } from "./cell";
38
+ import { cellSlots, folderCellSlots } from "./cell";
27
39
  import { text, textSlot } from "./text";
28
40
 
41
+ // The direction the files sort in, as its icon.
42
+ const direction = (browser: Service<unknown>) =>
43
+ browser.sortDirection === "asc" ? "sort-asc" : "sort-desc";
44
+
29
45
  export default wrap(Core, {
30
46
  pt: (pt) => ({
31
47
  ...pt,
32
- breadcrumb: { as: Breadcrumb, ...pt?.breadcrumb },
48
+ search: {
49
+ as: TableSearch,
50
+ placeholder: text("browser.search"),
51
+ ...pt?.search,
52
+ },
53
+ sortMenu: { as: Menu, ...pt?.sortMenu },
54
+ sortTrigger: { label: text("browser.sort"), ...pt?.sortTrigger },
55
+ head: layer<BrowserHeadPassthrough>(pt?.head, {
56
+ breadcrumb: { as: Breadcrumb },
57
+ selectAllCheckbox: { as: Checkbox },
58
+ }),
33
59
  refresh: { label: text("browser.refresh"), ...pt?.refresh },
34
60
  files: layer<BrowserFilesPassthrough<unknown>>(pt?.files, {
35
61
  link: () => ({ as: NuxtLink }),
@@ -38,12 +64,33 @@ export default wrap(Core, {
38
64
  actionsMenu: { as: Menu },
39
65
  }),
40
66
  folders: layer<BrowserFoldersPassthrough>(pt?.folders, {
67
+ rowCheckbox: { as: Checkbox },
41
68
  actionsTrigger: { label: text("browser.actions") },
42
69
  actionsMenu: { as: Menu },
43
70
  }),
44
71
  }),
45
72
  slots: {
46
73
  ...cellSlots<BrowserFileCellContext<unknown>>(({ browser }) => browser),
74
+ ...folderCellSlots<BrowserFolderCellContext<unknown>>(
75
+ ({ browser }) => browser,
76
+ ),
77
+ sort: ({ browser, settings }) =>
78
+ iconPart(
79
+ settings.sortTrigger,
80
+ browser.sortField === null ? "sort" : direction(browser),
81
+ ),
82
+ sortPrepend: ({ item }) => iconOf(item.icon),
83
+ sortAppend: ({ browser, item }) =>
84
+ browser.sortField === item.key ? [icon(direction(browser))] : [],
85
+ crumbPrepend: ({ item, index }) =>
86
+ index === 0 ? [icon("folder-open")] : iconOf(item.icon),
87
+ summary: ({ browser }) =>
88
+ textSlot(
89
+ text("browser.summary", {
90
+ folders: browser.folders.length,
91
+ files: browser.files.length,
92
+ }),
93
+ ),
47
94
  refresh: ({ settings }) => iconPart(settings.refresh, "refresh"),
48
95
  actions: ({ settings }) => iconPart(settings.actionsTrigger, "actions"),
49
96
  folderActions: ({ settings }) =>
@@ -51,13 +98,8 @@ export default wrap(Core, {
51
98
  folderPrepend: () => [icon("folder")],
52
99
  bulkActionPrepend: ({ action }) => iconOf(action.icon),
53
100
  bulkClear: () => textSlot("browser.clear"),
54
- empty: () => [
55
- h(
56
- "div",
57
- { class: "f-group f-data-browser-empty" },
58
- text("browser.empty"),
59
- ),
60
- ],
101
+ empty: ({ browser }) =>
102
+ textSlot(browser.isFiltered ? "browser.noMatches" : "browser.empty"),
61
103
  noFiles: () => textSlot("browser.noFiles"),
62
104
  },
63
105
  });
@@ -1,13 +1,54 @@
1
- // The vue calendar with the `prev` and `next` icons before its month
2
- // controls.
1
+ // The vue calendar with its toolbar dressed: each tool is named in the
2
+ // visitor's locale, the name its accessible name and its tooltip, and the
3
+ // two steps draw their icons in place of their labels; today and the views
4
+ // keep their names as text. An untitled occurrence and the empty agenda
5
+ // read in the visitor's locale too.
6
+ import type {
7
+ CalendarPassthrough,
8
+ CalendarTool,
9
+ } from "@zoobzio/vue/types/components/calendar";
10
+ import type { VNode } from "vue";
11
+
3
12
  import Core from "@zoobzio/vue/components/calendar.vue";
4
13
 
5
- import { icon } from "./icon";
14
+ import { h } from "vue";
15
+ import { layer } from "@zoobzio/vue/utils/passthrough";
6
16
  import { wrap } from "@zoobzio/vue/utils/wrap";
17
+ import { iconOf } from "./icon";
18
+ import { text, textIn, textSlot } from "./text";
19
+ import { toolIcon, toolText } from "../utils/calendar";
20
+
21
+ /**
22
+ * The layer under the calendar's `pt.tool`: the resolved label as the
23
+ * Fab's accessible name, and as the button's `title`, so an icon-only
24
+ * button still says what it does on hover.
25
+ */
26
+ const toolLayer = (tool: CalendarTool): { label: string; title: string } => {
27
+ const label = text(toolText(tool.key) ?? tool.label);
28
+ return { label, title: label };
29
+ };
30
+
31
+ /**
32
+ * The content of a tool's button: its icon where the layer names one, so
33
+ * the button is icon-only, and the resolved label in a span otherwise.
34
+ */
35
+ const toolLabel = (tool: CalendarTool): VNode[] => {
36
+ const name = toolIcon(tool.key);
37
+ return name
38
+ ? iconOf(name)
39
+ : textIn("span", "f-span", toolText(tool.key) ?? tool.label);
40
+ };
7
41
 
8
42
  export default wrap(Core, {
43
+ pt: (pt) => layer<CalendarPassthrough>(pt, { tool: toolLayer }),
9
44
  slots: {
10
- prevPrepend: () => [icon("prev")],
11
- nextPrepend: () => [icon("next")],
45
+ toolLabel: ({ tool }) => toolLabel(tool),
46
+ // A title is the entry's own text, never a message; only the name of
47
+ // an entry without one is the layer's.
48
+ occurrenceLabel: ({ occurrence }) =>
49
+ occurrence.entry.title
50
+ ? [h("span", { class: "f-span" }, occurrence.entry.title)]
51
+ : textIn("span", "f-span", "calendar.untitled"),
52
+ empty: () => textSlot("calendar.empty"),
12
53
  },
13
54
  });
@@ -88,18 +88,22 @@ const boolean = ({ value }: Cell): VNode[] => {
88
88
  ];
89
89
  };
90
90
 
91
+ /** A slot over a formatter: the scope's value in its service's formats. */
92
+ const slot =
93
+ <S>(serviceOf: (scope: S) => Formats) =>
94
+ (format: (cell: Cell) => VNode[]) =>
95
+ (scope: S & { value: unknown }): VNode[] => {
96
+ const { currency, timeZone } = serviceOf(scope);
97
+ return format({ value: scope.value, currency, timeZone });
98
+ };
99
+
91
100
  /**
92
101
  * The `cell:<type>` slot defaults, over a reader of the service from the
93
102
  * slot's scope, for its currency and its time zone: `table` for the table
94
103
  * body, `browser` for the browser's files.
95
104
  */
96
105
  export const cellSlots = <S>(serviceOf: (scope: S) => Formats) => {
97
- const cell =
98
- (format: (cell: Cell) => VNode[]) =>
99
- (scope: S & { value: unknown }): VNode[] => {
100
- const { currency, timeZone } = serviceOf(scope);
101
- return format({ value: scope.value, currency, timeZone });
102
- };
106
+ const cell = slot(serviceOf);
103
107
  return {
104
108
  "cell:date": cell(date),
105
109
  "cell:datetime": cell(datetime),
@@ -109,3 +113,19 @@ export const cellSlots = <S>(serviceOf: (scope: S) => Formats) => {
109
113
  "cell:boolean": cell(boolean),
110
114
  };
111
115
  };
116
+
117
+ /**
118
+ * The `folderCell:<type>` slot defaults of the browser's folders: a
119
+ * folder's value under a column formats as a file's does.
120
+ */
121
+ export const folderCellSlots = <S>(serviceOf: (scope: S) => Formats) => {
122
+ const cell = slot(serviceOf);
123
+ return {
124
+ "folderCell:date": cell(date),
125
+ "folderCell:datetime": cell(datetime),
126
+ "folderCell:number": cell(number),
127
+ "folderCell:currency": cell(currency),
128
+ "folderCell:filesize": cell(filesize),
129
+ "folderCell:boolean": cell(boolean),
130
+ };
131
+ };
@@ -1,5 +1,5 @@
1
1
  // The vue date filters with the layer's Command behind its field and
2
- // operator steps, the layer's Calendar and RangeCalendar behind its value
2
+ // operator steps, the layer's DateGrid and DateRangeGrid behind its value
3
3
  // step, the `calendar` icon as its trigger's content, and its text — the
4
4
  // trigger, the steps, the operators, the placeholders, the apply button —
5
5
  // in the visitor's locale. The fields' labels resolve in the Command.
@@ -9,9 +9,9 @@ import { createTextVNode, h } from "vue";
9
9
  import { iconPart } from "./icon";
10
10
  import { text, textSlot } from "./text";
11
11
  import { wrap } from "@zoobzio/vue/utils/wrap";
12
- import Calendar from "./calendar";
12
+ import DateGrid from "./date-grid";
13
13
  import Command from "./command";
14
- import RangeCalendar from "./range-calendar";
14
+ import DateRangeGrid from "./date-range-grid";
15
15
 
16
16
  export default wrap(Core, {
17
17
  pt: (pt) => ({
@@ -38,8 +38,8 @@ export default wrap(Core, {
38
38
  ],
39
39
  ...pt?.operatorCommand,
40
40
  },
41
- calendar: { as: Calendar, ...pt?.calendar },
42
- rangeCalendar: { as: RangeCalendar, ...pt?.rangeCalendar },
41
+ calendar: { as: DateGrid, ...pt?.calendar },
42
+ rangeCalendar: { as: DateRangeGrid, ...pt?.rangeCalendar },
43
43
  }),
44
44
  slots: {
45
45
  trigger: ({ settings }) => iconPart(settings.trigger, "calendar"),
@@ -1,6 +1,6 @@
1
- // The vue range calendar with the `prev` and `next` icons before its month
1
+ // The vue date grid with the `prev` and `next` icons before its month
2
2
  // controls.
3
- import Core from "@zoobzio/vue/components/range-calendar.vue";
3
+ import Core from "@zoobzio/vue/components/date-grid.vue";
4
4
 
5
5
  import { icon } from "./icon";
6
6
  import { wrap } from "@zoobzio/vue/utils/wrap";
@@ -0,0 +1,13 @@
1
+ // The vue date range grid with the `prev` and `next` icons before its month
2
+ // controls.
3
+ import Core from "@zoobzio/vue/components/date-range-grid.vue";
4
+
5
+ import { icon } from "./icon";
6
+ import { wrap } from "@zoobzio/vue/utils/wrap";
7
+
8
+ export default wrap(Core, {
9
+ slots: {
10
+ prevPrepend: () => [icon("prev")],
11
+ nextPrepend: () => [icon("next")],
12
+ },
13
+ });
@@ -9,6 +9,7 @@ import { wrap } from "@zoobzio/vue/utils/wrap";
9
9
  import Checkbox from "./checkbox";
10
10
  import DatePicker from "./date-picker";
11
11
  import FileInput from "./file-input";
12
+ import ImageInput from "./image-input";
12
13
  import MultiSelect from "./multi-select";
13
14
  import RichText from "./rich-text";
14
15
  import Select from "./select";
@@ -29,6 +30,7 @@ export default wrap(Core, {
29
30
  datePicker: { as: DatePicker },
30
31
  tagsInput: { as: TagsInput },
31
32
  fileInput: { as: FileInput },
33
+ imageInput: { as: ImageInput },
32
34
  richText: { as: RichText },
33
35
  },
34
36
  slots: {