@zoobzio/nuxt 0.0.4 → 0.0.5
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 +13 -3
- package/app/app.d.ts +4 -1
- package/app/factories/code.ts +48 -0
- package/app/factories/editor.ts +48 -0
- package/app/stores/code.ts +15 -0
- package/app/stores/editor.ts +15 -0
- package/app/types/code.ts +25 -0
- package/app/types/editor.ts +25 -0
- package/modules/imports/constant.ts +27 -0
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -90,14 +90,22 @@ the same path composes the same way.
|
|
|
90
90
|
|
|
91
91
|
## Stores and factories
|
|
92
92
|
|
|
93
|
-
The data components of `@zoobzio/vue` (`Table`, `Form`, `Browser
|
|
94
|
-
headless service through their `service` prop and own no
|
|
95
|
-
own. The layer carries that state for Nuxt, split in two tiers:
|
|
93
|
+
The data components of `@zoobzio/vue` (`Table`, `Form`, `Browser`,
|
|
94
|
+
`Editor`, `Code`) render a headless service through their `service` prop and own no
|
|
95
|
+
state of their own. The layer carries that state for Nuxt, split in two tiers:
|
|
96
96
|
|
|
97
97
|
- **Stores** (`stores/`, `access<Name>`) back one service's state container
|
|
98
98
|
with a `useState` record keyed by id (`table-<id>`). The record's value is
|
|
99
99
|
a reactive proxy, so the service's writes are tracked; every instance
|
|
100
100
|
under the same id shares it, and it survives SSR hydration.
|
|
101
|
+
The editor's record holds its revision and flags, never the document:
|
|
102
|
+
`load` the document on both sides, in setup, so the server's static copy
|
|
103
|
+
and the client's editor hold the same document. The editor component
|
|
104
|
+
renders that copy as HTML on the server and mounts the editor over it
|
|
105
|
+
only when the user interacts, so no `ClientOnly` is needed.
|
|
106
|
+
The code editor's record is the same shape with a cursor in place of the
|
|
107
|
+
active marks; its component renders the text in a `pre` on the server and
|
|
108
|
+
mounts the CodeMirror view in its place when the user interacts.
|
|
101
109
|
- **Factories** (`factories/`, `create<Name>`) take an id and the options
|
|
102
110
|
and return an id-scoped composable. Call the factory at module scope and
|
|
103
111
|
the composable in setup: each call builds a service over the id's store
|
|
@@ -150,6 +158,8 @@ options is a second, independent state.
|
|
|
150
158
|
| `createTable` | `accessTable` | `table:updated`, `table:filtered` |
|
|
151
159
|
| `createForm` | `accessForm` | `form:initialized`, `form:submitted`, `form:rejected`, `form:restored`, `form:reset`, `form:failed` |
|
|
152
160
|
| `createBrowser` | `accessBrowser` | `browser:updated`, `browser:navigated` |
|
|
161
|
+
| `createEditor` | `accessEditor` | `editor:loaded`, `editor:updated`, `editor:mounted`, `editor:unmounted` |
|
|
162
|
+
| `createCode` | `accessCode` | `code:loaded`, `code:updated`, `code:mounted`, `code:unmounted` |
|
|
153
163
|
|
|
154
164
|
Every relayed payload carries the service's `id`. `useHooks` subscribes
|
|
155
165
|
for one instance: each listener fires for events with that id only, and
|
package/app/app.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BrowserHooks } from "./types/browser";
|
|
2
|
+
import type { CodeHooks } from "./types/code";
|
|
3
|
+
import type { EditorHooks } from "./types/editor";
|
|
2
4
|
import type { FormHooks } from "./types/form";
|
|
3
5
|
import type { Logger } from "./types/log";
|
|
4
6
|
import type { TableHooks } from "./types/table";
|
|
@@ -8,7 +10,8 @@ declare module "#app" {
|
|
|
8
10
|
$log: Logger;
|
|
9
11
|
$logger: (name?: string) => Logger;
|
|
10
12
|
}
|
|
11
|
-
interface RuntimeNuxtHooks
|
|
13
|
+
interface RuntimeNuxtHooks
|
|
14
|
+
extends BrowserHooks, CodeHooks, EditorHooks, FormHooks, TableHooks {}
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CodeOptions, UseCode } from "../types/code";
|
|
2
|
+
import type { Actions, Config, Service } from "@zoobzio/code";
|
|
3
|
+
|
|
4
|
+
import { useNuxtApp } from "#app";
|
|
5
|
+
import { CodeService } from "@zoobzio/code";
|
|
6
|
+
import { accessCode } from "../stores/code";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the id-scoped composable of a code editor. Call it at module
|
|
10
|
+
* scope: the options split once into the headless config (the feature set)
|
|
11
|
+
* and the actions (the reader, the writer, the extensions), and `id` keys
|
|
12
|
+
* everything that follows. Each call of the composable, in setup, builds a
|
|
13
|
+
* service over the id's shared store and relays its domain events onto the
|
|
14
|
+
* app logger and the Nuxt hook bus under the `code:` prefix. The machine
|
|
15
|
+
* itself is `@zoobzio/code`; the Vue code editor renders it through its
|
|
16
|
+
* `service` prop.
|
|
17
|
+
*/
|
|
18
|
+
export const createCode = <I, O>(
|
|
19
|
+
id: string,
|
|
20
|
+
options: CodeOptions<I, O>,
|
|
21
|
+
): UseCode<I, O> => {
|
|
22
|
+
const { read, write, extensions, ...config } = options;
|
|
23
|
+
const wiring: Actions<I, O> = { read, write, extensions };
|
|
24
|
+
const features: Config = config;
|
|
25
|
+
return (): Service<I, O> => {
|
|
26
|
+
const nuxt = useNuxtApp();
|
|
27
|
+
const log = nuxt.$logger(id);
|
|
28
|
+
const state = accessCode(id);
|
|
29
|
+
const service = new CodeService<I, O>(id, features, state, wiring);
|
|
30
|
+
service.on("loaded", (event) => {
|
|
31
|
+
log.debug("Code loaded", event);
|
|
32
|
+
nuxt.callHook("code:loaded", event);
|
|
33
|
+
});
|
|
34
|
+
service.on("updated", (event) => {
|
|
35
|
+
log.debug("Code updated", event);
|
|
36
|
+
nuxt.callHook("code:updated", event);
|
|
37
|
+
});
|
|
38
|
+
service.on("mounted", (event) => {
|
|
39
|
+
log.debug("Code mounted", event);
|
|
40
|
+
nuxt.callHook("code:mounted", event);
|
|
41
|
+
});
|
|
42
|
+
service.on("unmounted", (event) => {
|
|
43
|
+
log.debug("Code unmounted", event);
|
|
44
|
+
nuxt.callHook("code:unmounted", event);
|
|
45
|
+
});
|
|
46
|
+
return service;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EditorOptions, UseEditor } from "../types/editor";
|
|
2
|
+
import type { Actions, Config, Service } from "@zoobzio/editor";
|
|
3
|
+
|
|
4
|
+
import { useNuxtApp } from "#app";
|
|
5
|
+
import { EditorService } from "@zoobzio/editor";
|
|
6
|
+
import { accessEditor } from "../stores/editor";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the id-scoped composable of an editor. Call it at module scope:
|
|
10
|
+
* the options split once into the headless config (the feature set) and
|
|
11
|
+
* the actions (the reader, the writer, the extensions), and `id` keys
|
|
12
|
+
* everything that follows. Each call of the composable, in setup, builds a
|
|
13
|
+
* service over the id's shared store and relays its domain events onto the
|
|
14
|
+
* app logger and the Nuxt hook bus under the `editor:` prefix. The machine
|
|
15
|
+
* itself is `@zoobzio/editor`; the Vue editor renders it through its
|
|
16
|
+
* `service` prop.
|
|
17
|
+
*/
|
|
18
|
+
export const createEditor = <I, O>(
|
|
19
|
+
id: string,
|
|
20
|
+
options: EditorOptions<I, O>,
|
|
21
|
+
): UseEditor<I, O> => {
|
|
22
|
+
const { read, write, extensions, ...config } = options;
|
|
23
|
+
const wiring: Actions<I, O> = { read, write, extensions };
|
|
24
|
+
const features: Config = config;
|
|
25
|
+
return (): Service<I, O> => {
|
|
26
|
+
const nuxt = useNuxtApp();
|
|
27
|
+
const log = nuxt.$logger(id);
|
|
28
|
+
const state = accessEditor(id);
|
|
29
|
+
const service = new EditorService<I, O>(id, features, state, wiring);
|
|
30
|
+
service.on("loaded", (event) => {
|
|
31
|
+
log.debug("Editor loaded", event);
|
|
32
|
+
nuxt.callHook("editor:loaded", event);
|
|
33
|
+
});
|
|
34
|
+
service.on("updated", (event) => {
|
|
35
|
+
log.debug("Editor updated", event);
|
|
36
|
+
nuxt.callHook("editor:updated", event);
|
|
37
|
+
});
|
|
38
|
+
service.on("mounted", (event) => {
|
|
39
|
+
log.debug("Editor mounted", event);
|
|
40
|
+
nuxt.callHook("editor:mounted", event);
|
|
41
|
+
});
|
|
42
|
+
service.on("unmounted", (event) => {
|
|
43
|
+
log.debug("Editor unmounted", event);
|
|
44
|
+
nuxt.callHook("editor:unmounted", event);
|
|
45
|
+
});
|
|
46
|
+
return service;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { State } from "@zoobzio/code";
|
|
2
|
+
|
|
3
|
+
import { useState } from "#app";
|
|
4
|
+
import { createCodeState } from "@zoobzio/code";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Nuxt backing for a code editor's state container: one `useState`
|
|
8
|
+
* record keyed `code-<id>`. Its value is a reactive proxy, so the
|
|
9
|
+
* service's field writes are tracked; instances sharing an id share the
|
|
10
|
+
* container across the app, and it survives SSR hydration. The document is
|
|
11
|
+
* not in the container: each service holds its own editor, and `load` must
|
|
12
|
+
* run where the editor runs.
|
|
13
|
+
*/
|
|
14
|
+
export const accessCode = (id: string): State =>
|
|
15
|
+
useState<State>(`code-${id}`, () => createCodeState()).value;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { State } from "@zoobzio/editor";
|
|
2
|
+
|
|
3
|
+
import { useState } from "#app";
|
|
4
|
+
import { createEditorState } from "@zoobzio/editor";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Nuxt backing for an editor's state container: one `useState` record
|
|
8
|
+
* keyed `editor-<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. The document is not in
|
|
11
|
+
* the container: each service holds its own editor, and `load` must run
|
|
12
|
+
* where the editor runs.
|
|
13
|
+
*/
|
|
14
|
+
export const accessEditor = (id: string): State =>
|
|
15
|
+
useState<State>(`editor-${id}`, () => createEditorState()).value;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Hooks } from "./hooks";
|
|
2
|
+
import type { Actions, Config, Events, Service } from "@zoobzio/code";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What `createCode` takes: the headless config (the feature set) and the
|
|
6
|
+
* actions (the reader, the writer, and the CodeMirror extensions). Config
|
|
7
|
+
* and actions share no key, so they sit side by side. The container
|
|
8
|
+
* carries nothing a consumer would seed: its fields follow the document,
|
|
9
|
+
* which the service holds and `load` sets.
|
|
10
|
+
*/
|
|
11
|
+
export type CodeOptions<I, O> = Config & Actions<I, O>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The Nuxt hooks a code editor relays: `code:loaded`, `code:updated`,
|
|
15
|
+
* `code:mounted`, and `code:unmounted`, each carrying the service's
|
|
16
|
+
* payload with its scoping `id`.
|
|
17
|
+
*/
|
|
18
|
+
export type CodeHooks = Hooks<"code", Events>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The id-scoped composable `createCode` returns. Call it in setup; every
|
|
22
|
+
* call yields a service over the same shared container, each with an
|
|
23
|
+
* editor of its own.
|
|
24
|
+
*/
|
|
25
|
+
export type UseCode<I, O> = () => Service<I, O>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Hooks } from "./hooks";
|
|
2
|
+
import type { Actions, Config, Events, Service } from "@zoobzio/editor";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What `createEditor` takes: the headless config (the feature set) and the
|
|
6
|
+
* actions (the reader, the writer, and any extensions). Config and actions
|
|
7
|
+
* share no key, so they sit side by side. The container carries nothing a
|
|
8
|
+
* consumer would seed: its fields follow the document, which the service
|
|
9
|
+
* holds and `load` sets.
|
|
10
|
+
*/
|
|
11
|
+
export type EditorOptions<I, O> = Config & Actions<I, O>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The Nuxt hooks an editor relays: `editor:loaded`, `editor:updated`,
|
|
15
|
+
* `editor:mounted`, and `editor:unmounted`, each carrying the service's
|
|
16
|
+
* payload with its scoping `id`.
|
|
17
|
+
*/
|
|
18
|
+
export type EditorHooks = Hooks<"editor", Events>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The id-scoped composable `createEditor` returns. Call it in setup; every
|
|
22
|
+
* call yields a service over the same shared container, each with an
|
|
23
|
+
* editor of its own.
|
|
24
|
+
*/
|
|
25
|
+
export type UseEditor<I, O> = () => Service<I, O>;
|
|
@@ -9,12 +9,14 @@ export const COMPONENTS = [
|
|
|
9
9
|
"browser-folders",
|
|
10
10
|
"calendar",
|
|
11
11
|
"checkbox",
|
|
12
|
+
"code",
|
|
12
13
|
"command",
|
|
13
14
|
"date-filters",
|
|
14
15
|
"date-picker",
|
|
15
16
|
"date-range-picker",
|
|
16
17
|
"dialog",
|
|
17
18
|
"directory",
|
|
19
|
+
"editor",
|
|
18
20
|
"fab",
|
|
19
21
|
"facets",
|
|
20
22
|
"form",
|
|
@@ -68,12 +70,14 @@ export const DEFINITIONS = [
|
|
|
68
70
|
"browser",
|
|
69
71
|
"calendar",
|
|
70
72
|
"checkbox",
|
|
73
|
+
"code",
|
|
71
74
|
"command",
|
|
72
75
|
"date-filters",
|
|
73
76
|
"date-picker",
|
|
74
77
|
"date-range-picker",
|
|
75
78
|
"dialog",
|
|
76
79
|
"directory",
|
|
80
|
+
"editor",
|
|
77
81
|
"fab",
|
|
78
82
|
"facets",
|
|
79
83
|
"form",
|
|
@@ -114,9 +118,13 @@ export const LAYER = {
|
|
|
114
118
|
],
|
|
115
119
|
"constants/log": ["LOG_ROOT_NAME", "LOG_LEVELS"],
|
|
116
120
|
"factories/browser": ["createBrowser"],
|
|
121
|
+
"factories/code": ["createCode"],
|
|
122
|
+
"factories/editor": ["createEditor"],
|
|
117
123
|
"factories/form": ["createForm"],
|
|
118
124
|
"factories/table": ["createTable"],
|
|
119
125
|
"stores/browser": ["accessBrowser"],
|
|
126
|
+
"stores/code": ["accessCode"],
|
|
127
|
+
"stores/editor": ["accessEditor"],
|
|
120
128
|
"stores/form": ["accessForm"],
|
|
121
129
|
"stores/log": ["accessLogs"],
|
|
122
130
|
"stores/notification": ["accessNotifications"],
|
|
@@ -138,6 +146,8 @@ export const LAYER_TYPES = {
|
|
|
138
146
|
"BrowserHooks",
|
|
139
147
|
"UseBrowser",
|
|
140
148
|
],
|
|
149
|
+
"types/code": ["CodeOptions", "CodeHooks", "UseCode"],
|
|
150
|
+
"types/editor": ["EditorOptions", "EditorHooks", "UseEditor"],
|
|
141
151
|
"types/error": ["ErrorData", "ErrorOptions", "AppError"],
|
|
142
152
|
"types/form": ["FormInitial", "FormOptions", "FormHooks", "UseForm"],
|
|
143
153
|
"types/hook": [
|
|
@@ -266,6 +276,14 @@ export const VUE_TYPES = {
|
|
|
266
276
|
"CheckboxSlots",
|
|
267
277
|
"CheckboxDefinition",
|
|
268
278
|
],
|
|
279
|
+
"components/code": [
|
|
280
|
+
"CodePassthrough",
|
|
281
|
+
"CodeProps",
|
|
282
|
+
"CodeEmits",
|
|
283
|
+
"CodeContext",
|
|
284
|
+
"CodeSlots",
|
|
285
|
+
"CodeDefinition",
|
|
286
|
+
],
|
|
269
287
|
"components/command": [
|
|
270
288
|
"CommandOption",
|
|
271
289
|
"CommandGroup",
|
|
@@ -337,6 +355,15 @@ export const VUE_TYPES = {
|
|
|
337
355
|
"DirectorySlots",
|
|
338
356
|
"DirectoryDefinition",
|
|
339
357
|
],
|
|
358
|
+
"components/editor": [
|
|
359
|
+
"EditorTool",
|
|
360
|
+
"EditorPassthrough",
|
|
361
|
+
"EditorProps",
|
|
362
|
+
"EditorEmits",
|
|
363
|
+
"EditorContext",
|
|
364
|
+
"EditorSlots",
|
|
365
|
+
"EditorDefinition",
|
|
366
|
+
],
|
|
340
367
|
"components/fab": [
|
|
341
368
|
"FabProps",
|
|
342
369
|
"FabEmits",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoobzio/nuxt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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": {
|
|
@@ -40,19 +40,22 @@
|
|
|
40
40
|
"ltrl-http": "^0.0.20",
|
|
41
41
|
"objectively": "^0.3.0",
|
|
42
42
|
"reka-ui": "^2.6.0",
|
|
43
|
-
"@zoobzio/
|
|
44
|
-
"@zoobzio/
|
|
45
|
-
"@zoobzio/table": "0.0.
|
|
46
|
-
"@zoobzio/
|
|
43
|
+
"@zoobzio/code": "0.0.5",
|
|
44
|
+
"@zoobzio/browser": "0.0.5",
|
|
45
|
+
"@zoobzio/table": "0.0.5",
|
|
46
|
+
"@zoobzio/form": "0.0.5",
|
|
47
|
+
"@zoobzio/editor": "0.0.5",
|
|
48
|
+
"@zoobzio/vue": "0.0.5"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
51
|
+
"@codemirror/state": "^6.7.6",
|
|
49
52
|
"@vitejs/plugin-vue": "^6.0.6",
|
|
50
53
|
"@vue/test-utils": "^2.4.8",
|
|
51
54
|
"happy-dom": "^20.9.0",
|
|
52
55
|
"nuxt": "^4.5.0",
|
|
53
56
|
"vue": "^3.5.24",
|
|
54
57
|
"vue-tsc": "^2.1.10",
|
|
55
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.6.5"
|
|
56
59
|
},
|
|
57
60
|
"scripts": {
|
|
58
61
|
"dev": "nuxi dev",
|