@zoobzio/nuxt 0.1.2 → 0.1.3

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 (47) hide show
  1. package/README.md +60 -1
  2. package/app/app.d.ts +14 -0
  3. package/app/app.vue +4 -8
  4. package/app/components/accordion.ts +4 -2
  5. package/app/components/autocomplete.ts +6 -10
  6. package/app/components/breadcrumb.ts +8 -2
  7. package/app/components/browser.ts +30 -6
  8. package/app/components/cell.ts +101 -0
  9. package/app/components/code.ts +28 -0
  10. package/app/components/command.ts +10 -1
  11. package/app/components/date-filters.ts +42 -9
  12. package/app/components/dialog.ts +13 -0
  13. package/app/components/directory.ts +4 -2
  14. package/app/components/editor.ts +8 -4
  15. package/app/components/fab.ts +9 -0
  16. package/app/components/facets.ts +14 -4
  17. package/app/components/form-field.ts +4 -3
  18. package/app/components/form.ts +20 -2
  19. package/app/components/hero.ts +8 -1
  20. package/app/components/keywords.ts +35 -8
  21. package/app/components/listbox.ts +9 -0
  22. package/app/components/menu.ts +9 -3
  23. package/app/components/multi-select.ts +10 -2
  24. package/app/components/pagination.ts +33 -3
  25. package/app/components/radio.ts +9 -0
  26. package/app/components/rich-text.ts +8 -4
  27. package/app/components/segmented-control.ts +4 -2
  28. package/app/components/select.ts +9 -1
  29. package/app/components/table.ts +22 -4
  30. package/app/components/tabs.ts +4 -2
  31. package/app/components/tags-input.ts +7 -1
  32. package/app/components/text.ts +71 -0
  33. package/app/components/toast.ts +8 -1
  34. package/app/components/tree.ts +4 -2
  35. package/app/composables/request.ts +6 -3
  36. package/app/constants/editor.ts +21 -0
  37. package/app/error.vue +8 -4
  38. package/app/factories/browser.ts +13 -4
  39. package/app/factories/form.ts +11 -4
  40. package/app/factories/table.ts +15 -4
  41. package/app/plugins/locale.ts +19 -0
  42. package/app/types/text.ts +12 -0
  43. package/app/utils/editor.ts +14 -1
  44. package/app/utils/text.ts +90 -0
  45. package/modules/imports/constant.ts +8 -1
  46. package/nuxt.config.ts +3 -1
  47. package/package.json +14 -10
@@ -5,6 +5,7 @@ import { useNuxtApp } from "#app";
5
5
  import { TableService } from "@zoobzio/table";
6
6
  import { accessTable } from "../stores/table";
7
7
  import { split } from "../utils/actions";
8
+ import { resolveTexts } from "../utils/text";
8
9
 
9
10
  /**
10
11
  * Builds the id-scoped composable of a table. Call it at module scope: the
@@ -12,8 +13,12 @@ import { split } from "../utils/actions";
12
13
  * wiring (the fetch and the handlers), and `id` keys everything that
13
14
  * follows. Each call of the composable, in setup, builds a service over
14
15
  * the id's shared store and relays its domain events onto the app logger and the Nuxt hook
15
- * bus as `table:updated` and `table:filtered`. The machine itself is
16
- * `@zoobzio/table`; the Vue table renders it through its `service` prop.
16
+ * bus as `table:updated` and `table:filtered`. The columns' and the
17
+ * actions' labels resolve through the app's prosary service as the service
18
+ * is built, so a label that is a key of the app's contract reaches the
19
+ * machine — and the search that matches a typed prefix against it — as
20
+ * the visitor reads it. The machine itself is `@zoobzio/table`; the Vue
21
+ * table renders it through its `service` prop.
17
22
  */
18
23
  export const createTable = <T>(
19
24
  id: string,
@@ -35,8 +40,14 @@ export const createTable = <T>(
35
40
  return (): Service<T> => {
36
41
  const nuxt = useNuxtApp();
37
42
  const log = nuxt.$logger(id);
38
- const state = accessTable(id, config, initial);
39
- const service = new TableService(id, config, state, wiring);
43
+ const resolved: Config<T> = {
44
+ ...config,
45
+ columns: resolveTexts(nuxt.$prosary, config.columns),
46
+ actions: resolveTexts(nuxt.$prosary, config.actions),
47
+ bulkActions: resolveTexts(nuxt.$prosary, config.bulkActions),
48
+ };
49
+ const state = accessTable(id, resolved, initial);
50
+ const service = new TableService(id, resolved, state, wiring);
40
51
  service.on("updated", (event) => {
41
52
  log.debug("Table updated", event);
42
53
  nuxt.callHook("table:updated", event);
@@ -0,0 +1,19 @@
1
+ import { defineNuxtPlugin, reloadNuxtApp } from "#app";
2
+
3
+ /**
4
+ * Reloads the app when the visitor switches locale. The wrappers resolve
5
+ * text on each render and follow a switch on their own; the services do
6
+ * not, as a factory resolves the labels of its columns, actions and fields
7
+ * once, when the service is built. The prosary module writes the new
8
+ * locale to its cookie before it raises the hook, so the reload renders
9
+ * the app in the locale chosen, from the server on.
10
+ */
11
+ export default defineNuxtPlugin({
12
+ name: "@zoobzio/nuxt/locale",
13
+ dependsOn: ["prosary"],
14
+ setup: (nuxtApp) => {
15
+ nuxtApp.hook("prosary:locale", () => {
16
+ reloadNuxtApp();
17
+ });
18
+ },
19
+ });
@@ -0,0 +1,12 @@
1
+ import type { Contract } from "#build/prosary/index.mjs";
2
+ import type { Message } from "prosary";
3
+
4
+ /**
5
+ * A message of the app's contract, as data: its key alone when it takes no
6
+ * values, or the key with its values. `@prosary/nuxt` builds the contract
7
+ * at build time from the prose build the layer names, so inside the layer
8
+ * it is `@zoobzio/prose` and inside an app it is the app's own build, which
9
+ * extends it. What `Text` widens to under the layer, so a column, an
10
+ * action, an item or a field takes any key of the app.
11
+ */
12
+ export type AppMessage = Message<Contract>;
@@ -1,6 +1,7 @@
1
1
  import type { IconAlias } from "../types/icon";
2
+ import type { AppMessage } from "../types/text";
2
3
 
3
- import { EDITOR_TOOL_ICONS } from "../constants/editor";
4
+ import { EDITOR_TOOL_ICONS, EDITOR_TOOL_TEXT } from "../constants/editor";
4
5
 
5
6
  /**
6
7
  * The icon of an editor tool, by its key. A heading tool's key carries its
@@ -8,3 +9,15 @@ import { EDITOR_TOOL_ICONS } from "../constants/editor";
8
9
  */
9
10
  export const toolIcon = (key: string): IconAlias | undefined =>
10
11
  EDITOR_TOOL_ICONS[/^heading-\d+$/.test(key) ? "heading" : key];
12
+
13
+ /**
14
+ * The text of an editor tool, by its key, as a message of the contract. A
15
+ * heading tool's key carries its level (`heading-2`), which the one
16
+ * `editor.heading` message takes as its value. A tool the layer does not
17
+ * name — one an app adds — has none, and its own label stands.
18
+ */
19
+ export const toolText = (key: string): AppMessage | undefined => {
20
+ const heading = /^heading-(\d+)$/.exec(key);
21
+ if (heading) return ["editor.heading", { level: Number(heading[1]) }];
22
+ return EDITOR_TOOL_TEXT[key];
23
+ };
@@ -0,0 +1,90 @@
1
+ import type { Contract } from "#build/prosary/index.mjs";
2
+ import type { Text } from "@zoobzio/kit";
3
+ import type { Prosary } from "prosary";
4
+
5
+ /**
6
+ * The app's prosary service, over its contract: what `@prosary/nuxt`
7
+ * provides as `$prosary` (and names `AppProsary` on `#imports`).
8
+ */
9
+ type AppProsary = Prosary<Contract>;
10
+
11
+ /**
12
+ * The properties that carry text in the data the components and the
13
+ * services take: what {@link resolveTexts} resolves, wherever it finds one.
14
+ */
15
+ const TEXT_KEYS: ReadonlySet<string> = new Set([
16
+ "label",
17
+ "description",
18
+ "title",
19
+ "placeholder",
20
+ "hint",
21
+ "text",
22
+ ]);
23
+
24
+ /**
25
+ * Whether a value is a message of the app's contract: a key it declares,
26
+ * or such a key with its values. Any other string is data — a file name, a
27
+ * value — and stands as it is.
28
+ */
29
+ const isMessage = (
30
+ service: AppProsary,
31
+ value: unknown,
32
+ ): value is Parameters<AppProsary["format"]>[0] =>
33
+ typeof value === "string"
34
+ ? service.schema.check.key(value)
35
+ : Array.isArray(value) && service.schema.check.key(value[0]);
36
+
37
+ /**
38
+ * A plain object: what the data the components take is made of, as against
39
+ * a Date, a class instance or a DOM node, which pass through untouched.
40
+ */
41
+ const plain = (value: unknown): value is Record<string, unknown> => {
42
+ if (typeof value !== "object" || value === null) return false;
43
+ const proto: unknown = Object.getPrototypeOf(value);
44
+ return proto === Object.prototype || proto === null;
45
+ };
46
+
47
+ /**
48
+ * Resolves one text through the app's prosary service: a message of the
49
+ * contract — a key, or a key with its values — formats in the active
50
+ * locale, and any other string stands as it is. What the components
51
+ * render is always a string; what reaches them is resolved here, at the
52
+ * layer's boundary.
53
+ *
54
+ * @param service - The app's prosary service.
55
+ * @param text - A plain string, a key of the contract, or a key with its
56
+ * values. Any other value renders in its string form.
57
+ * @returns The string to render.
58
+ */
59
+ export const resolveText = (
60
+ service: AppProsary,
61
+ text: Text | unknown,
62
+ ): string => (isMessage(service, text) ? service.format(text) : String(text));
63
+
64
+ /**
65
+ * Resolves every text in a value: the `label`, `description`, `title`,
66
+ * `placeholder`, `hint` and `text` of each plain object, at any depth of
67
+ * arrays and plain objects, so the options of a select, the groups of a
68
+ * menu, the nodes of a tree or the columns of a table all resolve in one
69
+ * call. Anything else — a function, a Date, a service — is kept as it is.
70
+ * The result is a copy; the value given is never written.
71
+ *
72
+ * @param service - The app's prosary service.
73
+ * @param value - The data to resolve.
74
+ * @returns The data, with every text a string.
75
+ */
76
+ export function resolveTexts<T>(service: AppProsary, value: T): T;
77
+ export function resolveTexts(service: AppProsary, value: unknown): unknown {
78
+ if (Array.isArray(value)) {
79
+ return value.map((item: unknown) => resolveTexts(service, item));
80
+ }
81
+ if (!plain(value)) return value;
82
+ const out: Record<string, unknown> = {};
83
+ for (const [key, item] of Object.entries(value)) {
84
+ out[key] =
85
+ TEXT_KEYS.has(key) && (typeof item === "string" || Array.isArray(item))
86
+ ? resolveText(service, item)
87
+ : resolveTexts(service, item);
88
+ }
89
+ return out;
90
+ }
@@ -62,21 +62,26 @@ export const WRAPPED = [
62
62
  "browser",
63
63
  "calendar",
64
64
  "checkbox",
65
+ "code",
65
66
  "command",
66
67
  "date-filters",
67
68
  "date-picker",
68
69
  "date-range-picker",
70
+ "dialog",
69
71
  "directory",
70
72
  "editor",
73
+ "fab",
71
74
  "facets",
72
75
  "file-input",
73
76
  "form",
74
77
  "form-field",
75
78
  "hero",
76
79
  "keywords",
80
+ "listbox",
77
81
  "menu",
78
82
  "multi-select",
79
83
  "pagination",
84
+ "radio",
80
85
  "range-calendar",
81
86
  "rich-text",
82
87
  "scroller",
@@ -142,7 +147,7 @@ export const LAYER = {
142
147
  "composables/log": ["useLogger"],
143
148
  "composables/notification": ["useNotifications"],
144
149
  "composables/request": ["useRequest", "useLazyRequest"],
145
- "constants/editor": ["EDITOR_TOOL_ICONS"],
150
+ "constants/editor": ["EDITOR_TOOL_ICONS", "EDITOR_TOOL_TEXT"],
146
151
  "constants/error": [
147
152
  "ERROR_DEFAULT_STATUS_CODE",
148
153
  "ERROR_NOT_FOUND_STATUS_CODE",
@@ -161,6 +166,7 @@ export const LAYER = {
161
166
  "stores/log": ["accessLogs"],
162
167
  "stores/notification": ["accessNotifications"],
163
168
  "stores/table": ["accessTable"],
169
+ "utils/text": ["resolveText", "resolveTexts"],
164
170
  } as const satisfies Record<string, readonly string[]>;
165
171
 
166
172
  // Type-only exports, registered the same way so `import type { TableOptions }
@@ -196,6 +202,7 @@ export const LAYER_TYPES = {
196
202
  "types/log": ["LogLevel", "LogLine", "LogEmit", "Logger"],
197
203
  "types/notification": ["Notification"],
198
204
  "types/request": ["RequestOptions"],
205
+ "types/text": ["AppMessage"],
199
206
  "types/table": [
200
207
  "TableAction",
201
208
  "TableBulkAction",
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", "@untheme/nuxt"],
7
+ modules: ["@icon-sheets/nuxt", "@untheme/nuxt", "@prosary/nuxt"],
8
8
 
9
9
  imports: { autoImport: false, scan: false },
10
10
 
@@ -17,6 +17,8 @@ export default defineNuxtConfig({
17
17
 
18
18
  untheme: { preset: "@zoobzio/theme" },
19
19
 
20
+ prosary: { build: "@zoobzio/prose" },
21
+
20
22
  css: [fileURLToPath(new URL("./app/assets/css/reset.css", import.meta.url))],
21
23
 
22
24
  build: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoobzio/nuxt",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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,21 +38,25 @@
38
38
  "dependencies": {
39
39
  "@icon-sheets/nuxt": "0.0.8",
40
40
  "@nuxt/kit": "^4.5.0",
41
+ "@prosary/nuxt": "0.0.9",
41
42
  "@untheme/nuxt": "^0.6.1",
42
43
  "@vueuse/core": "^14.3.0",
43
44
  "ltrl-http": "^0.0.20",
44
45
  "objectively": "^0.3.0",
46
+ "prosary": "0.0.9",
45
47
  "reka-ui": "^2.6.0",
46
48
  "untheme": "^0.6.1",
47
- "@zoobzio/browser": "0.1.2",
48
- "@zoobzio/editor": "0.1.2",
49
- "@zoobzio/form": "0.1.2",
50
- "@zoobzio/code": "0.1.2",
51
- "@zoobzio/icons": "0.1.2",
52
- "@zoobzio/query": "0.1.2",
53
- "@zoobzio/theme": "0.1.2",
54
- "@zoobzio/vue": "0.1.2",
55
- "@zoobzio/table": "0.1.2"
49
+ "@zoobzio/browser": "0.1.3",
50
+ "@zoobzio/code": "0.1.3",
51
+ "@zoobzio/editor": "0.1.3",
52
+ "@zoobzio/icons": "0.1.3",
53
+ "@zoobzio/prose": "0.1.3",
54
+ "@zoobzio/kit": "0.1.3",
55
+ "@zoobzio/table": "0.1.3",
56
+ "@zoobzio/theme": "0.1.3",
57
+ "@zoobzio/vue": "0.1.3",
58
+ "@zoobzio/query": "0.1.3",
59
+ "@zoobzio/form": "0.1.3"
56
60
  },
57
61
  "devDependencies": {
58
62
  "@codemirror/state": "^6.7.6",