@primate/vue 0.10.4 → 0.12.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.
- package/lib/private/Default.d.ts +16 -0
- package/lib/private/Default.js +23 -0
- package/lib/private/Runtime.d.ts +11 -0
- package/lib/private/Runtime.js +16 -0
- package/lib/private/client/Validated.d.ts +11 -0
- package/lib/private/client/Validated.js +2 -0
- package/lib/private/client/index.d.ts +11 -0
- package/lib/private/client/index.js +34 -0
- package/lib/private/client/validate.d.ts +25 -0
- package/lib/private/client/validate.js +29 -0
- package/lib/private/compile.d.ts +5 -0
- package/lib/private/compile.js +50 -0
- package/lib/private/create-root.d.ts +3 -0
- package/lib/private/create-root.js +56 -0
- package/lib/public/Validated.d.ts +2 -0
- package/lib/public/Validated.js +2 -0
- package/lib/public/browser.d.ts +2 -0
- package/lib/public/browser.js +2 -0
- package/lib/public/default.d.ts +4 -0
- package/lib/public/default.js +3 -0
- package/lib/public/runtime.d.ts +4 -0
- package/lib/public/runtime.js +3 -0
- package/lib/public/validate.d.ts +2 -0
- package/lib/public/validate.js +2 -0
- package/package.json +24 -20
- package/src/private/build/index.js +0 -18
- package/src/private/build/server.js +0 -6
- package/src/private/extension.js +0 -1
- package/src/private/name.js +0 -1
- package/src/private/pkgname.js +0 -1
- package/src/private/serve/handler.js +0 -11
- package/src/private/serve/index.js +0 -7
- package/src/private/serve/render.js +0 -1
- package/src/public/default.js +0 -10
- package/src/public/runtime.js +0 -8
|
@@ -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 (component, props) => {
|
|
10
|
+
const app = createSSRApp(component, { 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,11 @@
|
|
|
1
|
+
import type ClientData from "@primate/core/client/Data";
|
|
2
|
+
import type Dict from "@rcompat/type/Dict";
|
|
3
|
+
type Data = ClientData<{
|
|
4
|
+
components: string[];
|
|
5
|
+
props: Dict[];
|
|
6
|
+
}>;
|
|
7
|
+
export default class VueClient {
|
|
8
|
+
static mount(_component: 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 * as components from "vue:components";
|
|
4
|
+
import root from "vue:root";
|
|
5
|
+
export default class VueClient {
|
|
6
|
+
static mount(_component, data) {
|
|
7
|
+
const resolve = (names) => names.map((n) => components[n]);
|
|
8
|
+
let app = createSSRApp(root, {
|
|
9
|
+
p: {
|
|
10
|
+
components: resolve(data.components),
|
|
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
|
+
components: resolve(next.components),
|
|
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,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,56 @@
|
|
|
1
|
+
export default (depth, i18n_active) => {
|
|
2
|
+
const n = depth - 1;
|
|
3
|
+
// Build the nested component structure more carefully
|
|
4
|
+
const buildComponent = (index) => {
|
|
5
|
+
if (index === n) {
|
|
6
|
+
// Base case: render the deepest component
|
|
7
|
+
return `h(p.components[${index}], p.props[${index}] || {})`;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
// Recursive case: render component with child
|
|
11
|
+
const child = buildComponent(index + 1);
|
|
12
|
+
return `h(p.components[${index}], p.props[${index}] || {}, () => [${child}])`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const body = depth > 0 ? buildComponent(0) : "h(\"div\")";
|
|
16
|
+
const vueImports = `import {
|
|
17
|
+
defineComponent, h${i18n_active ? ", ref, onMounted, onUnmounted" : ""}
|
|
18
|
+
} from "vue";`;
|
|
19
|
+
const i18nImports = i18n_active
|
|
20
|
+
? `
|
|
21
|
+
import t from "#i18n";
|
|
22
|
+
import sInternal from "primate/s/internal";`
|
|
23
|
+
: "";
|
|
24
|
+
const i18nSetup = i18n_active
|
|
25
|
+
? `
|
|
26
|
+
const initialLocale = props.p?.request?.context?.i18n?.locale;
|
|
27
|
+
if (initialLocale) t[sInternal].init(initialLocale);
|
|
28
|
+
|
|
29
|
+
onMounted(() => { t[sInternal].restore(); });
|
|
30
|
+
|
|
31
|
+
if (typeof window !== "undefined") {
|
|
32
|
+
const version = ref(t[sInternal].version);
|
|
33
|
+
const removeDepend = t[sInternal].depend(() => { void version.value; });
|
|
34
|
+
const unsubscribe = t.onChange(() => {
|
|
35
|
+
version.value = t[sInternal].version;
|
|
36
|
+
});
|
|
37
|
+
onUnmounted(() => { unsubscribe?.(); removeDepend?.(); });
|
|
38
|
+
}`
|
|
39
|
+
: "";
|
|
40
|
+
return `
|
|
41
|
+
${vueImports}
|
|
42
|
+
${i18nImports}
|
|
43
|
+
export default defineComponent({
|
|
44
|
+
name: "root",
|
|
45
|
+
props: { p: { type: Object, required: true } },
|
|
46
|
+
setup(props) {
|
|
47
|
+
${i18nSetup}
|
|
48
|
+
return () => {
|
|
49
|
+
const p = props.p;
|
|
50
|
+
return ${body};
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
`;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=create-root.js.map
|
package/package.json
CHANGED
|
@@ -1,45 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Primate Vue frontend",
|
|
5
|
-
"homepage": "https://
|
|
6
|
-
"bugs": "https://github.com/
|
|
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
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"/lib/**/*.js",
|
|
10
|
+
"/lib/**/*.d.ts",
|
|
11
|
+
"!/**/*.spec.*"
|
|
11
12
|
],
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/primate-run/primate",
|
|
15
16
|
"directory": "packages/vue"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@
|
|
19
|
+
"@rcompat/build": "^0.14.0",
|
|
20
|
+
"@primate/core": "^0.2.0"
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"vue": "3",
|
|
22
|
-
"primate": "^0.
|
|
24
|
+
"primate": "^0.33.0"
|
|
23
25
|
},
|
|
24
26
|
"type": "module",
|
|
25
27
|
"imports": {
|
|
26
28
|
"#*": {
|
|
27
|
-
"
|
|
28
|
-
"default": "./
|
|
29
|
-
},
|
|
30
|
-
"#build": {
|
|
31
|
-
"livetypes": "./src/private/build/index.js",
|
|
32
|
-
"default": "./src/private/build/index.js"
|
|
33
|
-
},
|
|
34
|
-
"#serve": {
|
|
35
|
-
"livetypes": "./src/private/serve/index.js",
|
|
36
|
-
"default": "./src/private/serve/index.js"
|
|
29
|
+
"apekit": "./src/private/*.ts",
|
|
30
|
+
"default": "./lib/private/*.js"
|
|
37
31
|
}
|
|
38
32
|
},
|
|
39
33
|
"exports": {
|
|
40
34
|
".": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
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"
|
|
43
42
|
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "npm run clean && tsc",
|
|
46
|
+
"clean": "rm -rf ./lib",
|
|
47
|
+
"lint": "eslint ."
|
|
44
48
|
}
|
|
45
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
|
-
};
|
package/src/private/extension.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default ".vue";
|
package/src/private/name.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default "vue";
|
package/src/private/pkgname.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default "@primate/vue";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createSSRApp } from "vue";
|
|
2
|
-
import render from "./render.js";
|
|
3
|
-
|
|
4
|
-
export default (name, props = {}, options = {}) => async app => {
|
|
5
|
-
const component = createSSRApp({
|
|
6
|
-
render: (await app.get_component(name)).render,
|
|
7
|
-
data: () => props,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
return app.view({ body: await render(component), ...options });
|
|
11
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { renderToString as default } from "vue/server-renderer";
|
package/src/public/default.js
DELETED
|
@@ -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
|
-
});
|