@zoobzio/nuxt 0.1.7 → 0.1.8

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
@@ -146,7 +146,11 @@ names no icon of its own (the text literal, the one that opens the quote
146
146
  free text is typed in); `remove` on a tag's and a file's remove
147
147
  button and after an autocomplete chip's label; `close` on a toast's; `top` on a scroller's back-to-top; `check`
148
148
  in a checkbox; the editor's and rich text's tools by key (`bold`,
149
- `heading`, `bullet-list`, `undo`, …, see `EDITOR_TOOL_ICONS`); and on
149
+ `bullet-list`, `undo`, …, see `EDITOR_TOOL_ICONS`), each drawn in place
150
+ of the button's text so the toolbar is icon-only, with the tool's label in
151
+ the visitor's locale as the button's accessible name and its `title`, and
152
+ `expand` after the block type dropdown's text, which reads in the
153
+ visitor's locale as its entries do; and on
150
154
  the table and browser, `refresh`, `columns`, `actions`, `drag`,
151
155
  `sort-asc` or `sort-desc` after a sorted header, `folder` before a
152
156
  folder, `magic` before the table's search, `next` after an autocomplete
@@ -330,7 +334,10 @@ state of their own. The layer carries that state for Nuxt, split in two tiers:
330
334
  `load` the document on both sides, in setup, so the server's static copy
331
335
  and the client's editor hold the same document. The editor component
332
336
  renders that copy as HTML on the server and mounts the editor over it
333
- only when the user interacts, so no `ClientOnly` is needed.
337
+ only when the user interacts, so no `ClientOnly` is needed. The layer's
338
+ `nuxt.config` defines `navigator` for the server build as the runtime's
339
+ own, since Nuxt's default (`undefined`) crashed tiptap as the editor
340
+ was constructed on the server in a production build.
334
341
  The code editor's record is the same shape with a cursor in place of the
335
342
  active marks; its component renders the text in a `pre` on the server and
336
343
  mounts the CodeMirror view in its place when the user interacts.
@@ -0,0 +1,63 @@
1
+ // The tool glue the editor and rich text wrappers share: the layer under
2
+ // `pt.tool` that names each button in the visitor's locale, the label slot
3
+ // that draws its icon, and the block type dropdown's trigger and items in
4
+ // the visitor's locale. It sits with the wrappers, as `icon.ts` and
5
+ // `text.ts` do, because it renders through them; `utils/editor` holds the
6
+ // lookups alone, which the factories reach without a Nuxt app.
7
+ import type {
8
+ EditorBlock,
9
+ EditorTool,
10
+ } from "@zoobzio/vue/types/components/editor";
11
+ import type { VNode } from "vue";
12
+
13
+ import { icon, iconOf } from "./icon";
14
+ import { text, textIn, textSlot } from "./text";
15
+ import { toolIcon, toolText } from "../utils/editor";
16
+
17
+ /**
18
+ * The label of a tool as the visitor reads it: the contract's message for
19
+ * a tool the layer names, the tool's own label otherwise.
20
+ */
21
+ const labelOf = (tool: EditorTool): string =>
22
+ text(toolText(tool.key) ?? tool.label);
23
+
24
+ /**
25
+ * The layer under the editor's `pt.tool`: the resolved label as the Fab's
26
+ * accessible name, and as the button's `title`, so an icon-only button
27
+ * still says what it does on hover.
28
+ */
29
+ export const toolLayer = (
30
+ tool: EditorTool,
31
+ ): { label: string; title: string } => {
32
+ const label = labelOf(tool);
33
+ return { label, title: label };
34
+ };
35
+
36
+ /**
37
+ * The content of a tool's button: its icon where the layer names one, so
38
+ * the button is icon-only, and the resolved label as text otherwise.
39
+ */
40
+ export const toolLabel = (tool: EditorTool): VNode[] => {
41
+ const name = toolIcon(tool.key);
42
+ return name ? iconOf(name) : textSlot(toolText(tool.key) ?? tool.label);
43
+ };
44
+
45
+ /**
46
+ * The text of a block type as the visitor reads it: the contract's message
47
+ * for the paragraph and the headings, the entry's own label otherwise.
48
+ */
49
+ const blockText = (block: EditorBlock): VNode[] =>
50
+ textSlot(toolText(block.value) ?? block.label);
51
+
52
+ /**
53
+ * The trigger of the block type dropdown: the block at the selection by
54
+ * name, in a span as the editor's own trigger renders it.
55
+ */
56
+ export const blockLabel = (block: EditorBlock): VNode[] =>
57
+ textIn("span", "f-span", toolText(block.value) ?? block.label);
58
+
59
+ /** The `expand` icon after the trigger's text, as a select's trigger draws it. */
60
+ export const blockAppend = (): VNode[] => [icon("expand")];
61
+
62
+ /** One entry of the block type dropdown, by name. */
63
+ export const blockItemLabel = (item: EditorBlock): VNode[] => blockText(item);
@@ -1,15 +1,29 @@
1
- // The vue editor with each tool's icon before its label, and the label in
2
- // the visitor's locale.
1
+ // The vue editor as an icon toolbar: each tool draws its icon in place of
2
+ // its label, and the label, in the visitor's locale, stays the button's
3
+ // accessible name and its tooltip. A tool the layer has no icon for keeps
4
+ // its label as text. The block type dropdown reads its trigger and its
5
+ // entries in the visitor's locale, with the `expand` icon after the
6
+ // trigger's text.
7
+ import type { EditorPassthrough } from "@zoobzio/vue/types/components/editor";
8
+
3
9
  import Core from "@zoobzio/vue/components/editor.vue";
4
10
 
5
- import { iconOf } from "./icon";
6
- import { textSlot } from "./text";
11
+ import { layer } from "@zoobzio/vue/utils/passthrough";
7
12
  import { wrap } from "@zoobzio/vue/utils/wrap";
8
- import { toolIcon, toolText } from "../utils/editor";
13
+ import {
14
+ blockAppend,
15
+ blockItemLabel,
16
+ blockLabel,
17
+ toolLabel,
18
+ toolLayer,
19
+ } from "./editor-tool";
9
20
 
10
21
  export default wrap(Core, {
22
+ pt: (pt) => layer<EditorPassthrough>(pt, { tool: toolLayer }),
11
23
  slots: {
12
- toolPrepend: ({ tool }) => iconOf(toolIcon(tool.key)),
13
- toolLabel: ({ tool }) => textSlot(toolText(tool.key) ?? tool.label),
24
+ toolLabel: ({ tool }) => toolLabel(tool),
25
+ blockLabel: ({ block }) => blockLabel(block),
26
+ blockAppend: () => blockAppend(),
27
+ blockItemLabel: ({ item }) => blockItemLabel(item),
14
28
  },
15
29
  });
@@ -1,15 +1,27 @@
1
- // The vue rich text with each tool's icon before its label, and the label
2
- // in the visitor's locale.
1
+ // The vue rich text as an icon toolbar, as the editor: each tool draws its
2
+ // icon in place of its label, the label, in the visitor's locale, stays
3
+ // the button's accessible name and its tooltip, and the block type
4
+ // dropdown reads in the visitor's locale.
5
+ import type { RichTextPassthrough } from "@zoobzio/vue/types/components/rich-text";
6
+
3
7
  import Core from "@zoobzio/vue/components/rich-text.vue";
4
8
 
5
- import { iconOf } from "./icon";
6
- import { textSlot } from "./text";
9
+ import { layer } from "@zoobzio/vue/utils/passthrough";
7
10
  import { wrap } from "@zoobzio/vue/utils/wrap";
8
- import { toolIcon, toolText } from "../utils/editor";
11
+ import {
12
+ blockAppend,
13
+ blockItemLabel,
14
+ blockLabel,
15
+ toolLabel,
16
+ toolLayer,
17
+ } from "./editor-tool";
9
18
 
10
19
  export default wrap(Core, {
20
+ pt: (pt) => layer<RichTextPassthrough>(pt, { tool: toolLayer }),
11
21
  slots: {
12
- toolPrepend: ({ tool }) => iconOf(toolIcon(tool.key)),
13
- toolLabel: ({ tool }) => textSlot(toolText(tool.key) ?? tool.label),
22
+ toolLabel: ({ tool }) => toolLabel(tool),
23
+ blockLabel: ({ block }) => blockLabel(block),
24
+ blockAppend: () => blockAppend(),
25
+ blockItemLabel: ({ item }) => blockItemLabel(item),
14
26
  },
15
27
  });
@@ -3,9 +3,9 @@ import type { AppMessage } from "../types/text";
3
3
 
4
4
  /**
5
5
  * The icon of each editor tool, by the tool's key: the marks, the blocks,
6
- * and history. A heading tool's key carries its level (`heading-2`), and
7
- * every level draws the one `heading` icon beside its `H<n>` label. The
8
- * editor and rich text wrappers draw these in `toolPrepend`.
6
+ * and history. The headings have none: they are the entries of the block
7
+ * type dropdown, read by name. The editor and rich text wrappers draw
8
+ * these as each button's content, in place of the label text.
9
9
  */
10
10
  export const EDITOR_TOOL_ICONS: Readonly<Record<string, IconAlias>> = {
11
11
  bold: "bold",
@@ -13,7 +13,6 @@ export const EDITOR_TOOL_ICONS: Readonly<Record<string, IconAlias>> = {
13
13
  underline: "underline",
14
14
  strike: "strike",
15
15
  code: "code",
16
- heading: "heading",
17
16
  bulletList: "bullet-list",
18
17
  orderedList: "ordered-list",
19
18
  blockquote: "blockquote",
@@ -25,10 +24,12 @@ export const EDITOR_TOOL_ICONS: Readonly<Record<string, IconAlias>> = {
25
24
 
26
25
  /**
27
26
  * The message of each editor tool's label, by the tool's key: the marks,
28
- * the blocks, and history. A heading tool is not here: its message takes
27
+ * the blocks, and history, and `paragraph`, the block type dropdown's
28
+ * entry that is no tool. A heading tool is not here: its message takes
29
29
  * the level its key carries, which `toolText` reads.
30
30
  */
31
31
  export const EDITOR_TOOL_TEXT: Readonly<Record<string, AppMessage>> = {
32
+ paragraph: "editor.paragraph",
32
33
  bold: "editor.bold",
33
34
  italic: "editor.italic",
34
35
  underline: "editor.underline",
@@ -4,17 +4,18 @@ import type { AppMessage } from "../types/text";
4
4
  import { EDITOR_TOOL_ICONS, EDITOR_TOOL_TEXT } from "../constants/editor";
5
5
 
6
6
  /**
7
- * The icon of an editor tool, by its key. A heading tool's key carries its
8
- * level (`heading-2`), and every level draws the one `heading` icon.
7
+ * The icon of an editor tool, by its key. A heading has none: it is an
8
+ * entry of the block type dropdown. A tool the layer does not name — one
9
+ * an app adds — has none either.
9
10
  */
10
11
  export const toolIcon = (key: string): IconAlias | undefined =>
11
- EDITOR_TOOL_ICONS[/^heading-\d+$/.test(key) ? "heading" : key];
12
+ EDITOR_TOOL_ICONS[key];
12
13
 
13
14
  /**
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.
15
+ * The text of an editor tool, or of a block type, by its key, as a message
16
+ * of the contract. A heading's key carries its level (`heading-2`), which
17
+ * the one `editor.heading` message takes as its value. A tool the layer
18
+ * does not name — one an app adds — has none, and its own label stands.
18
19
  */
19
20
  export const toolText = (key: string): AppMessage | undefined => {
20
21
  const heading = /^heading-(\d+)$/.exec(key);
@@ -405,6 +405,10 @@ export const VUE_TYPES = {
405
405
  ],
406
406
  "components/editor": [
407
407
  "EditorTool",
408
+ "EditorToolKind",
409
+ "EditorToolGroup",
410
+ "EditorGroup",
411
+ "EditorBlock",
408
412
  "EditorPassthrough",
409
413
  "EditorProps",
410
414
  "EditorEmits",
package/nuxt.config.ts CHANGED
@@ -26,6 +26,24 @@ export default defineNuxtConfig({
26
26
  },
27
27
 
28
28
  vite: {
29
- optimizeDeps: { exclude: ["@zoobzio/nuxt", "@zoobzio/vue"] },
29
+ optimizeDeps: {
30
+ // `objectively` is left out of the dev pre-bundle: Vite keys a
31
+ // pre-bundled dependency by its bare name, and @untheme and
32
+ // @icon-sheets pin older versions than this layer and @zoobzio/vue
33
+ // import, so whichever version Vite met first was served to every
34
+ // importer. Served as source instead, each import resolves to its
35
+ // own version. It is dependency-free ESM, so nothing else is lost.
36
+ exclude: ["@zoobzio/nuxt", "@zoobzio/vue", "objectively"],
37
+ },
38
+ $server: {
39
+ define: {
40
+ // Nuxt's server build replaces `navigator` with `undefined`. Tiptap
41
+ // reads `navigator.platform` while it builds its keymap, as the
42
+ // editor is constructed, so a page that holds an editor crashed on
43
+ // the server in a production build. The runtime's own navigator
44
+ // stands in, and an inert one where the runtime has none.
45
+ navigator: '(globalThis.navigator ?? { platform: "", userAgent: "" })',
46
+ },
47
+ },
30
48
  },
31
49
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoobzio/nuxt",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
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": {
@@ -46,17 +46,17 @@
46
46
  "prosary": "0.0.10",
47
47
  "reka-ui": "^2.6.0",
48
48
  "untheme": "^0.6.1",
49
- "@zoobzio/browser": "0.1.7",
50
- "@zoobzio/code": "0.1.7",
51
- "@zoobzio/editor": "0.1.7",
52
- "@zoobzio/form": "0.1.7",
53
- "@zoobzio/icons": "0.1.7",
54
- "@zoobzio/kit": "0.1.7",
55
- "@zoobzio/prose": "0.1.7",
56
- "@zoobzio/query": "0.1.7",
57
- "@zoobzio/table": "0.1.7",
58
- "@zoobzio/theme": "0.1.7",
59
- "@zoobzio/vue": "0.1.7"
49
+ "@zoobzio/browser": "0.1.8",
50
+ "@zoobzio/editor": "0.1.8",
51
+ "@zoobzio/form": "0.1.8",
52
+ "@zoobzio/code": "0.1.8",
53
+ "@zoobzio/icons": "0.1.8",
54
+ "@zoobzio/prose": "0.1.8",
55
+ "@zoobzio/kit": "0.1.8",
56
+ "@zoobzio/query": "0.1.8",
57
+ "@zoobzio/table": "0.1.8",
58
+ "@zoobzio/theme": "0.1.8",
59
+ "@zoobzio/vue": "0.1.8"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@codemirror/state": "^6.7.6",