@primate/vue 0.11.0 → 0.13.0

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,16 @@
1
+ import Runtime from "#Runtime";
2
+ import type BuildApp from "@primate/core/BuildApp";
3
+ import type NextBuild from "@primate/core/NextBuild";
4
+ export default class Default extends Runtime {
5
+ compile: {
6
+ client: (text: string, _: unknown, root: boolean) => {
7
+ js: string;
8
+ };
9
+ server: (text: string) => string;
10
+ };
11
+ root: {
12
+ create: (depth: number, i18n_active: boolean) => string;
13
+ };
14
+ build(app: BuildApp, next: NextBuild): Promise<BuildApp>;
15
+ }
16
+ //# sourceMappingURL=Default.d.ts.map
@@ -0,0 +1,23 @@
1
+ import compile from "#compile";
2
+ import create_root from "#create-root";
3
+ import Runtime from "#Runtime";
4
+ export default class Default extends Runtime {
5
+ compile = {
6
+ client: (text, _, root) => ({ js: root ? text : compile.server(text) }),
7
+ server: (text) => compile.server(text),
8
+ };
9
+ root = {
10
+ create: create_root,
11
+ };
12
+ async build(app, next) {
13
+ const filename = `${this.rootname}.js`;
14
+ const rootCode = this.root.create(app.depth(), app.i18n_active);
15
+ // Write directly without passing through compile.server
16
+ const path = app.runpath("server", filename);
17
+ await path.write(rootCode);
18
+ app.addRoot(path);
19
+ this.publish(app);
20
+ return next(app);
21
+ }
22
+ }
23
+ //# sourceMappingURL=Default.js.map
@@ -0,0 +1,11 @@
1
+ import FrontendModule from "@primate/core/frontend/Module";
2
+ import type Render from "@primate/core/frontend/Render";
3
+ import { type Renderer } from "vue";
4
+ export default class Runtime extends FrontendModule<Renderer> {
5
+ name: string;
6
+ defaultExtensions: string[];
7
+ layouts: boolean;
8
+ client: boolean;
9
+ render: Render<Renderer>;
10
+ }
11
+ //# sourceMappingURL=Runtime.d.ts.map
@@ -0,0 +1,16 @@
1
+ import FrontendModule from "@primate/core/frontend/Module";
2
+ import { createSSRApp } from "vue";
3
+ import { renderToString } from "vue/server-renderer";
4
+ export default class Runtime extends FrontendModule {
5
+ name = "vue";
6
+ defaultExtensions = [".vue"];
7
+ layouts = true;
8
+ client = true;
9
+ render = async (view, props) => {
10
+ const app = createSSRApp(view, { p: { ...props } });
11
+ const html = await renderToString(app);
12
+ return { body: `<div id="app">${html}</div>` };
13
+ };
14
+ }
15
+ ;
16
+ //# sourceMappingURL=Runtime.js.map
@@ -0,0 +1,11 @@
1
+ import type ValidateUpdater from "@primate/core/client/ValidateUpdater";
2
+ import type ValidationError from "@primate/core/client/ValidationError";
3
+ import { type Ref } from "vue";
4
+ type Validated<T> = {
5
+ error: Ref<null | ValidationError>;
6
+ loading: Ref<boolean>;
7
+ update: (updater: ValidateUpdater<T>) => Promise<void>;
8
+ value: Ref<T>;
9
+ };
10
+ export type { Validated as default };
11
+ //# sourceMappingURL=Validated.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Validated.js.map
@@ -0,0 +1,11 @@
1
+ import type ClientData from "@primate/core/client/Data";
2
+ import type Dict from "@rcompat/type/Dict";
3
+ type Data = ClientData<{
4
+ views: string[];
5
+ props: Dict[];
6
+ }>;
7
+ export default class VueClient {
8
+ static mount(_view: string, data: ClientData<Data>): void;
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,34 @@
1
+ import spa from "@primate/core/client/spa";
2
+ import { createSSRApp } from "vue";
3
+ import root from "vue:root";
4
+ import * as views from "vue:views";
5
+ export default class VueClient {
6
+ static mount(_view, data) {
7
+ const resolve = (names) => names.map((n) => views[n]);
8
+ let app = createSSRApp(root, {
9
+ p: {
10
+ views: resolve(data.views),
11
+ props: data.props,
12
+ request: data.request,
13
+ update: undefined,
14
+ },
15
+ });
16
+ app.mount("#app");
17
+ if (data.spa) {
18
+ window.addEventListener("DOMContentLoaded", () => spa((next, update) => {
19
+ app.unmount();
20
+ app = createSSRApp(root, {
21
+ p: {
22
+ views: resolve(next.views),
23
+ props: next.props,
24
+ request: next.request,
25
+ update,
26
+ },
27
+ });
28
+ app.mount("#app");
29
+ update?.();
30
+ }));
31
+ }
32
+ }
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ import type Validated from "#client/Validated";
2
+ declare const _default: <T>(initial: T) => {
3
+ delete: (url: string, options?: {
4
+ headers?: import("@rcompat/type/Dict").default<string>;
5
+ map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
6
+ path?: import("@rcompat/type/JSONPointer").default;
7
+ } | undefined) => Validated<T>;
8
+ patch: (url: string, options?: {
9
+ headers?: import("@rcompat/type/Dict").default<string>;
10
+ map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
11
+ path?: import("@rcompat/type/JSONPointer").default;
12
+ } | undefined) => Validated<T>;
13
+ post: (url: string, options?: {
14
+ headers?: import("@rcompat/type/Dict").default<string>;
15
+ map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
16
+ path?: import("@rcompat/type/JSONPointer").default;
17
+ } | undefined) => Validated<T>;
18
+ put: (url: string, options?: {
19
+ headers?: import("@rcompat/type/Dict").default<string>;
20
+ map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
21
+ path?: import("@rcompat/type/JSONPointer").default;
22
+ } | undefined) => Validated<T>;
23
+ };
24
+ export default _default;
25
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,29 @@
1
+ import toValidated from "@primate/core/client/toValidated";
2
+ import validate from "@primate/core/client/validate";
3
+ import { ref } from "vue";
4
+ function useValidate(init) {
5
+ const value = ref(init.initial);
6
+ const loading = ref(false);
7
+ const error = ref(null);
8
+ async function update(updater) {
9
+ const previous = value.value;
10
+ const next = updater(previous);
11
+ value.value = next;
12
+ loading.value = true;
13
+ error.value = null;
14
+ try {
15
+ await validate(init, next);
16
+ }
17
+ catch (e) {
18
+ // rollback
19
+ value.value = previous;
20
+ error.value = e;
21
+ }
22
+ finally {
23
+ loading.value = false;
24
+ }
25
+ }
26
+ return { error, loading, update, value };
27
+ }
28
+ export default toValidated(useValidate);
29
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ server(text: string): string;
3
+ };
4
+ export default _default;
5
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1,50 @@
1
+ import typescript from "@rcompat/build/preset/typescript";
2
+ import transform from "@rcompat/build/sync/transform";
3
+ import { compileScript, compileTemplate, parse, } from "vue/compiler-sfc";
4
+ const genDefaultAs = "__SCRIPT__";
5
+ const id_size = 8;
6
+ const analyze = ({ script, scriptSetup }) => {
7
+ return {
8
+ has_script: script !== null || scriptSetup !== null,
9
+ inline: scriptSetup !== null,
10
+ is_typescript: script?.lang === "ts" || scriptSetup?.lang === "ts",
11
+ };
12
+ };
13
+ export default {
14
+ server(text) {
15
+ const id = crypto.randomUUID().slice(0, id_size);
16
+ const { descriptor } = parse(text);
17
+ const { has_script, inline, is_typescript } = analyze(descriptor);
18
+ let module;
19
+ if (inline) {
20
+ // For <script setup>, compile with inlineTemplate to get both script and render
21
+ const script = compileScript(descriptor, {
22
+ genDefaultAs,
23
+ id,
24
+ inlineTemplate: true,
25
+ });
26
+ module = `
27
+ ${script.content}
28
+ export default { ...__SCRIPT__ };
29
+ `;
30
+ }
31
+ else {
32
+ // For regular components, compile template and script separately
33
+ const template = compileTemplate({
34
+ filename: "",
35
+ id,
36
+ source: descriptor.template?.content ?? "",
37
+ });
38
+ const script = has_script
39
+ ? compileScript(descriptor, { genDefaultAs, id, inlineTemplate: false })
40
+ : { content: `const ${genDefaultAs} = {}` };
41
+ module = `
42
+ ${template.code}
43
+ ${script.content}
44
+ export default { ...__SCRIPT__, render };
45
+ `;
46
+ }
47
+ return is_typescript ? transform(module, typescript).code : module;
48
+ },
49
+ };
50
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1,3 @@
1
+ declare const _default: (depth: number, i18n_active: boolean) => string;
2
+ export default _default;
3
+ //# sourceMappingURL=create-root.d.ts.map
@@ -0,0 +1,54 @@
1
+ export default (depth, i18n_active) => {
2
+ const n = depth - 1;
3
+ const build_view = (index) => {
4
+ // anchor case: render the deepest view
5
+ if (index === n)
6
+ return `h(p.views[${index}], p.props[${index}] || {})`;
7
+ else {
8
+ // recursive case: render view with child
9
+ const child = build_view(index + 1);
10
+ return `h(p.views[${index}], p.props[${index}] || {}, () => [${child}])`;
11
+ }
12
+ };
13
+ const body = depth > 0 ? build_view(0) : "h(\"div\")";
14
+ const vueImports = `import {
15
+ defineComponent, h${i18n_active ? ", ref, onMounted, onUnmounted" : ""}
16
+ } from "vue";`;
17
+ const i18nImports = i18n_active
18
+ ? `
19
+ import t from "#i18n";
20
+ import sInternal from "primate/s/internal";`
21
+ : "";
22
+ const i18nSetup = i18n_active
23
+ ? `
24
+ const initialLocale = props.p?.request?.context?.i18n?.locale;
25
+ if (initialLocale) t[sInternal].init(initialLocale);
26
+
27
+ onMounted(() => { t[sInternal].restore(); });
28
+
29
+ if (typeof window !== "undefined") {
30
+ const version = ref(t[sInternal].version);
31
+ const removeDepend = t[sInternal].depend(() => { void version.value; });
32
+ const unsubscribe = t.onChange(() => {
33
+ version.value = t[sInternal].version;
34
+ });
35
+ onUnmounted(() => { unsubscribe?.(); removeDepend?.(); });
36
+ }`
37
+ : "";
38
+ return `
39
+ ${vueImports}
40
+ ${i18nImports}
41
+ export default defineComponent({
42
+ name: "root",
43
+ props: { p: { type: Object, required: true } },
44
+ setup(props) {
45
+ ${i18nSetup}
46
+ return () => {
47
+ const p = props.p;
48
+ return ${body};
49
+ };
50
+ },
51
+ });
52
+ `;
53
+ };
54
+ //# sourceMappingURL=create-root.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/Validated";
2
+ //# sourceMappingURL=Validated.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Validated.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/index";
2
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/index";
2
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1,4 @@
1
+ import Default from "#Default";
2
+ declare const _default: (options?: typeof Default.input) => Default;
3
+ export default _default;
4
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1,3 @@
1
+ import Default from "#Default";
2
+ export default (options) => new Default(options);
3
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1,4 @@
1
+ import Runtime from "#Runtime";
2
+ declare const _default: (options?: typeof Runtime.input) => Runtime;
3
+ export default _default;
4
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,3 @@
1
+ import Runtime from "#Runtime";
2
+ export default (options) => new Runtime(options);
3
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/validate";
2
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#client/validate";
2
+ //# sourceMappingURL=validate.js.map
package/package.json CHANGED
@@ -1,46 +1,49 @@
1
1
  {
2
2
  "name": "@primate/vue",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Primate Vue frontend",
5
- "homepage": "https://primatejs.com/modules/vue",
6
- "bugs": "https://github.com/primatejs/primate/issues",
5
+ "homepage": "https://primate.run/docs/frontend/vue",
6
+ "bugs": "https://github.com/primate-run/primate/issues",
7
7
  "license": "MIT",
8
8
  "files": [
9
- "src/**/*.js",
10
- "!src/**/*.spec.js"
9
+ "/lib/**/*.js",
10
+ "/lib/**/*.d.ts",
11
+ "!/**/*.spec.*"
11
12
  ],
12
13
  "repository": {
13
14
  "type": "git",
14
- "url": "https://github.com/primatejs/primate",
15
+ "url": "https://github.com/primate-run/primate",
15
16
  "directory": "packages/vue"
16
17
  },
17
18
  "dependencies": {
18
- "@rcompat/build": "^0.6.0",
19
- "@primate/frontend": "^0.16.4"
19
+ "@rcompat/build": "^0.14.0",
20
+ "@primate/core": "^0.3.0"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "vue": "3",
23
- "primate": "^0.32.6"
24
+ "primate": "^0.34.0"
24
25
  },
25
26
  "type": "module",
26
27
  "imports": {
27
28
  "#*": {
28
- "livetypes": "./src/private/*.js",
29
- "default": "./src/private/*.js"
30
- },
31
- "#build": {
32
- "livetypes": "./src/private/build/index.js",
33
- "default": "./src/private/build/index.js"
34
- },
35
- "#serve": {
36
- "livetypes": "./src/private/serve/index.js",
37
- "default": "./src/private/serve/index.js"
29
+ "apekit": "./src/private/*.ts",
30
+ "default": "./lib/private/*.js"
38
31
  }
39
32
  },
40
33
  "exports": {
41
34
  ".": {
42
- "runtime": "./src/public/runtime.js",
43
- "default": "./src/public/default.js"
35
+ "browser": "./lib/public/browser.js",
36
+ "runtime": "./lib/public/runtime.js",
37
+ "default": "./lib/public/default.js"
38
+ },
39
+ "./*": {
40
+ "apekit": "./src/public/*.ts",
41
+ "default": "./lib/public/*.js"
44
42
  }
43
+ },
44
+ "scripts": {
45
+ "build": "npm run clean && tsc",
46
+ "clean": "rm -rf ./lib",
47
+ "lint": "eslint ."
45
48
  }
46
49
  }
@@ -1,18 +0,0 @@
1
- import name from "#name";
2
- import compile from "@primate/frontend/core/compile";
3
- import server from "./server.js";
4
-
5
- export default extension => async (app, next) => {
6
- app.register(extension, {
7
- ...await compile({
8
- app,
9
- extension,
10
- name,
11
- compile: { server },
12
- }),
13
- // no support for hydration
14
- client: _ => _,
15
- });
16
-
17
- return next(app);
18
- };
@@ -1,37 +0,0 @@
1
- import { compileScript, compileTemplate, parse } from "vue/compiler-sfc";
2
- import transform from "@rcompat/build/transform";
3
-
4
- const genDefaultAs = "__SCRIPT__";
5
- const id_size = 8;
6
-
7
- const analyze = ({ script, scriptSetup }) => {
8
- return {
9
- inline: scriptSetup !== null,
10
- has_script: script !== null || scriptSetup !== null,
11
- is_typescript: script?.lang === "ts" || scriptSetup?.lang === "ts",
12
- };
13
- };
14
- const options = { loader: "ts" };
15
-
16
- export default async text => {
17
- const id = crypto.randomUUID().slice(0, id_size);
18
- const { descriptor } = parse(text);
19
- const { inline, has_script, is_typescript } = analyze(descriptor);
20
-
21
- const template = compileTemplate({
22
- id,
23
- source: descriptor.template.content,
24
- });
25
- const script = has_script
26
- ? compileScript(descriptor, { id, inlineTemplate: inline, genDefaultAs })
27
- : { content: `const ${genDefaultAs} = {}` };
28
-
29
- const module = `
30
- ${inline ? "" : template.code}
31
- ${script.content}
32
-
33
- export default { ...__SCRIPT__, ${inline ? "" : "render"} };
34
- `;
35
-
36
- return is_typescript ? (await transform(module, options)).code : module;
37
- };
@@ -1 +0,0 @@
1
- export default ".vue";
@@ -1 +0,0 @@
1
- export default "vue";
@@ -1 +0,0 @@
1
- export default "@primate/vue";
@@ -1,8 +0,0 @@
1
- import { createSSRApp } from "vue";
2
- import { renderToString } from "vue/server-renderer";
3
-
4
- export default (name, props = {}, options = {}) => async app => {
5
- const component = createSSRApp(await app.get_component(name), props);
6
-
7
- return app.view({ body: await renderToString(component), ...options });
8
- };
@@ -1,7 +0,0 @@
1
- import handler from "./handler.js";
2
-
3
- export default extension => (app, next) => {
4
- app.register(extension, handler);
5
-
6
- return next(app);
7
- };
@@ -1,10 +0,0 @@
1
- import build from "#build";
2
- import default_extension from "#extension";
3
- import pkgname from "#name";
4
- import serve from "#serve";
5
-
6
- export default ({ extension = default_extension } = {}) => ({
7
- name: pkgname,
8
- build: build(extension),
9
- serve: serve(extension),
10
- });
@@ -1,8 +0,0 @@
1
- import pkgname from "#pkgname";
2
- import serve from "#serve";
3
- import default_extension from "#extension";
4
-
5
- export default ({ extension = default_extension } = {}) => ({
6
- name: pkgname,
7
- serve: serve(extension),
8
- });