@primate/vue 0.10.3 → 0.11.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Primate Vue frontend",
|
|
5
5
|
"homepage": "https://primatejs.com/modules/vue",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -15,24 +15,25 @@
|
|
|
15
15
|
"directory": "packages/vue"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@
|
|
18
|
+
"@rcompat/build": "^0.6.0",
|
|
19
|
+
"@primate/frontend": "^0.16.4"
|
|
19
20
|
},
|
|
20
21
|
"peerDependencies": {
|
|
21
22
|
"vue": "3",
|
|
22
|
-
"primate": "^0.32.
|
|
23
|
+
"primate": "^0.32.6"
|
|
23
24
|
},
|
|
24
25
|
"type": "module",
|
|
25
26
|
"imports": {
|
|
26
27
|
"#*": {
|
|
27
|
-
"
|
|
28
|
+
"livetypes": "./src/private/*.js",
|
|
28
29
|
"default": "./src/private/*.js"
|
|
29
30
|
},
|
|
30
31
|
"#build": {
|
|
31
|
-
"
|
|
32
|
+
"livetypes": "./src/private/build/index.js",
|
|
32
33
|
"default": "./src/private/build/index.js"
|
|
33
34
|
},
|
|
34
35
|
"#serve": {
|
|
35
|
-
"
|
|
36
|
+
"livetypes": "./src/private/serve/index.js",
|
|
36
37
|
"default": "./src/private/serve/index.js"
|
|
37
38
|
}
|
|
38
39
|
},
|
|
@@ -1,6 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compileScript, compileTemplate, parse } from "vue/compiler-sfc";
|
|
2
|
+
import transform from "@rcompat/build/transform";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
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,11 +1,8 @@
|
|
|
1
1
|
import { createSSRApp } from "vue";
|
|
2
|
-
import
|
|
2
|
+
import { renderToString } from "vue/server-renderer";
|
|
3
3
|
|
|
4
4
|
export default (name, props = {}, options = {}) => async app => {
|
|
5
|
-
const component = createSSRApp(
|
|
6
|
-
render: (await app.get_component(name)).render,
|
|
7
|
-
data: () => props,
|
|
8
|
-
});
|
|
5
|
+
const component = createSSRApp(await app.get_component(name), props);
|
|
9
6
|
|
|
10
|
-
return app.view({ body: await
|
|
7
|
+
return app.view({ body: await renderToString(component), ...options });
|
|
11
8
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { renderToString as default } from "vue/server-renderer";
|