@primate/vue 0.16.0 → 0.17.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/index.d.ts +2 -1
- package/lib/private/client/app.js +4 -1
- package/lib/private/client/form.d.ts +4 -3
- package/lib/private/client/form.js +17 -6
- package/lib/private/compile.d.ts +4 -0
- package/lib/private/compile.js +46 -36
- package/lib/private/create-root.d.ts +1 -2
- package/lib/private/create-root.js +17 -18
- package/lib/private/default.d.ts +1 -1
- package/lib/private/default.js +4 -1
- package/lib/private/runtime.d.ts +1 -1
- package/lib/public/browser.d.ts +1 -0
- package/lib/public/browser.js +1 -0
- package/lib/public/runtime.d.ts +1 -0
- package/lib/public/runtime.js +1 -0
- package/package.json +7 -7
- package/lib/public/client.d.ts +0 -2
- package/lib/public/client.js +0 -2
package/lib/index.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import root from "#client/root";
|
|
|
2
2
|
import client from "@primate/core/client";
|
|
3
3
|
export default class VueApp {
|
|
4
4
|
static mount(_view, data) {
|
|
5
|
+
const interactive = !data.ssr || data.csr;
|
|
6
|
+
if (!interactive)
|
|
7
|
+
return;
|
|
5
8
|
let app = root[data.ssr ? "ssr" : "csr"](root.toProps(data));
|
|
6
9
|
app.mount("#app");
|
|
7
|
-
if (data.
|
|
10
|
+
if (data.csr) {
|
|
8
11
|
const start = () => client.boot((next, update) => {
|
|
9
12
|
app.unmount();
|
|
10
13
|
app = root.csr(root.toProps(next, update));
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import type { FormInit } from "@primate/core/client";
|
|
1
|
+
import type { ClientMethod, FormInit } from "@primate/core/client";
|
|
2
2
|
import type { Dict } from "@rcompat/type";
|
|
3
3
|
type FormView<Values extends Dict> = {
|
|
4
4
|
id: string;
|
|
5
5
|
submitting: boolean;
|
|
6
6
|
submitted: boolean;
|
|
7
7
|
submit: (event?: Event) => Promise<void>;
|
|
8
|
-
errors:
|
|
8
|
+
errors: string[];
|
|
9
9
|
field: <K extends keyof Values & string>(name: K) => {
|
|
10
10
|
name: string;
|
|
11
11
|
value: Values[K];
|
|
12
12
|
error: string | null;
|
|
13
|
-
errors:
|
|
13
|
+
errors: string[];
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
type Initial<Values extends Dict> = FormInit & {
|
|
17
17
|
initial?: Values;
|
|
18
18
|
};
|
|
19
|
+
declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): FormView<Values>;
|
|
19
20
|
declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
|
|
20
21
|
declare function form(init?: FormInit): FormView<Dict>;
|
|
21
22
|
export default form;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import core from "@primate/core/client";
|
|
2
2
|
import { onUnmounted, shallowRef } from "vue";
|
|
3
|
-
function form(
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
function form(action_or_init, maybe_init) {
|
|
4
|
+
const is_action = typeof action_or_init === "function";
|
|
5
|
+
const { initial, ...form_init } = (is_action ? (maybe_init ?? {}) : (action_or_init ?? {}));
|
|
6
|
+
const action = is_action ? action_or_init : undefined;
|
|
7
|
+
const contentType = is_action
|
|
8
|
+
? action_or_init.contentType
|
|
9
|
+
: undefined;
|
|
10
|
+
const controller = core.createForm({
|
|
11
|
+
...form_init,
|
|
12
|
+
...action !== undefined && {
|
|
13
|
+
action: action,
|
|
14
|
+
contentType,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const values = initial ?? {};
|
|
7
18
|
const snapshot = shallowRef(controller.read());
|
|
8
|
-
const
|
|
19
|
+
const unsubscribe = controller.subscribe(next => {
|
|
9
20
|
snapshot.value = next;
|
|
10
21
|
});
|
|
11
|
-
onUnmounted(
|
|
22
|
+
onUnmounted(unsubscribe);
|
|
12
23
|
return {
|
|
13
24
|
get id() {
|
|
14
25
|
return snapshot.value.id;
|
package/lib/private/compile.d.ts
CHANGED
package/lib/private/compile.js
CHANGED
|
@@ -1,51 +1,61 @@
|
|
|
1
1
|
import presets from "@primate/core/build/presets";
|
|
2
2
|
import transform from "@primate/core/build/transform";
|
|
3
|
-
import { compileScript, compileTemplate, parse, } from "vue/compiler-sfc";
|
|
3
|
+
import { compileScript, compileStyle, compileTemplate, parse, } from "vue/compiler-sfc";
|
|
4
4
|
const genDefaultAs = "__SCRIPT__";
|
|
5
5
|
const id_size = 8;
|
|
6
6
|
const analyze = ({ script, scriptSetup }) => {
|
|
7
7
|
return {
|
|
8
8
|
has_script: script !== null || scriptSetup !== null,
|
|
9
9
|
inline: scriptSetup !== null,
|
|
10
|
-
|
|
10
|
+
is_ts: script?.lang === "ts" || scriptSetup?.lang === "ts",
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
+
const compile_sfc = (text) => {
|
|
14
|
+
const id = crypto.randomUUID().slice(0, id_size);
|
|
15
|
+
const { descriptor } = parse(text);
|
|
16
|
+
const { has_script, inline, is_ts } = analyze(descriptor);
|
|
17
|
+
let module;
|
|
18
|
+
if (inline) {
|
|
19
|
+
const script = compileScript(descriptor, {
|
|
20
|
+
genDefaultAs,
|
|
21
|
+
id,
|
|
22
|
+
inlineTemplate: true,
|
|
23
|
+
});
|
|
24
|
+
module = `
|
|
25
|
+
${script.content}
|
|
26
|
+
export default { ...__SCRIPT__ };
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const template = compileTemplate({
|
|
31
|
+
filename: "",
|
|
32
|
+
id,
|
|
33
|
+
source: descriptor.template?.content ?? "",
|
|
34
|
+
});
|
|
35
|
+
const script = has_script
|
|
36
|
+
? compileScript(descriptor, { genDefaultAs, id, inlineTemplate: false })
|
|
37
|
+
: { content: `const ${genDefaultAs} = {}` };
|
|
38
|
+
module = `
|
|
39
|
+
${template.code}
|
|
40
|
+
${script.content}
|
|
41
|
+
export default { ...__SCRIPT__, render };
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
const js = is_ts ? transform(module, presets.typescript).code : module;
|
|
45
|
+
const css = descriptor.styles.map(style => compileStyle({
|
|
46
|
+
filename: "",
|
|
47
|
+
id,
|
|
48
|
+
source: style.content,
|
|
49
|
+
scoped: style.scoped ?? false,
|
|
50
|
+
}).code).join("\n");
|
|
51
|
+
return { js, css };
|
|
52
|
+
};
|
|
13
53
|
export default {
|
|
54
|
+
client(text) {
|
|
55
|
+
return compile_sfc(text);
|
|
56
|
+
},
|
|
14
57
|
server(text) {
|
|
15
|
-
|
|
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
|
|
21
|
-
// render
|
|
22
|
-
const script = compileScript(descriptor, {
|
|
23
|
-
genDefaultAs,
|
|
24
|
-
id,
|
|
25
|
-
inlineTemplate: true,
|
|
26
|
-
});
|
|
27
|
-
module = `
|
|
28
|
-
${script.content}
|
|
29
|
-
export default { ...__SCRIPT__ };
|
|
30
|
-
`;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// For regular components, compile template and script separately
|
|
34
|
-
const template = compileTemplate({
|
|
35
|
-
filename: "",
|
|
36
|
-
id,
|
|
37
|
-
source: descriptor.template?.content ?? "",
|
|
38
|
-
});
|
|
39
|
-
const script = has_script
|
|
40
|
-
? compileScript(descriptor, { genDefaultAs, id, inlineTemplate: false })
|
|
41
|
-
: { content: `const ${genDefaultAs} = {}` };
|
|
42
|
-
module = `
|
|
43
|
-
${template.code}
|
|
44
|
-
${script.content}
|
|
45
|
-
export default { ...__SCRIPT__, render };
|
|
46
|
-
`;
|
|
47
|
-
}
|
|
48
|
-
return is_typescript ? transform(module, presets.typescript).code : module;
|
|
58
|
+
return compile_sfc(text).js;
|
|
49
59
|
},
|
|
50
60
|
};
|
|
51
61
|
//# sourceMappingURL=compile.js.map
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
export default (depth, i18n_active)
|
|
2
|
-
const n = depth;
|
|
1
|
+
export default function createRoot(depth, i18n_active) {
|
|
3
2
|
const build_view = (index) => {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
if (index > depth)
|
|
4
|
+
return `h("div")`;
|
|
5
|
+
if (index === depth)
|
|
6
6
|
return `h(p.views[${index}], p.props[${index}] || {})`;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const child = build_view(index + 1);
|
|
10
|
-
return `h(p.views[${index}], p.props[${index}] || {}, () => [${child}])`;
|
|
11
|
-
}
|
|
7
|
+
const child = build_view(index + 1);
|
|
8
|
+
return `h(p.views[${index}], p.props[${index}] || {}, () => [${child}])`;
|
|
12
9
|
};
|
|
13
|
-
const body =
|
|
14
|
-
const
|
|
10
|
+
const body = `h(Suspense, null, { default: () => ${build_view(0)} })`;
|
|
11
|
+
const vue_imports = `
|
|
15
12
|
import {
|
|
16
|
-
defineComponent, h
|
|
13
|
+
defineComponent, h, Suspense
|
|
14
|
+
${i18n_active ? ", ref, onMounted, onUnmounted" : ""}
|
|
17
15
|
} from "vue";
|
|
18
16
|
import { setRequest } from "@primate/vue/app";
|
|
19
17
|
`;
|
|
20
|
-
const
|
|
18
|
+
const i18n_imports = i18n_active
|
|
21
19
|
? `
|
|
22
20
|
import t from "#i18n";
|
|
23
21
|
import sInternal from "primate/s/internal";`
|
|
24
22
|
: "";
|
|
25
|
-
const
|
|
23
|
+
const i18n_setup = i18n_active
|
|
26
24
|
? `
|
|
27
25
|
const initialLocale = props.p?.request?.context?.i18n?.locale;
|
|
28
26
|
if (initialLocale) t[sInternal].init(initialLocale);
|
|
@@ -39,13 +37,13 @@ if (typeof window !== "undefined") {
|
|
|
39
37
|
}`
|
|
40
38
|
: "";
|
|
41
39
|
return `
|
|
42
|
-
${
|
|
43
|
-
${
|
|
40
|
+
${vue_imports}
|
|
41
|
+
${i18n_imports}
|
|
44
42
|
export default defineComponent({
|
|
45
43
|
name: "root",
|
|
46
44
|
props: { p: { type: Object, required: true } },
|
|
47
45
|
setup(props) {
|
|
48
|
-
${
|
|
46
|
+
${i18n_setup}
|
|
49
47
|
return () => {
|
|
50
48
|
const p = props.p;
|
|
51
49
|
setRequest(props.p.request);
|
|
@@ -54,5 +52,6 @@ export default defineComponent({
|
|
|
54
52
|
},
|
|
55
53
|
});
|
|
56
54
|
`;
|
|
57
|
-
}
|
|
55
|
+
}
|
|
56
|
+
;
|
|
58
57
|
//# sourceMappingURL=create-root.js.map
|
package/lib/private/default.d.ts
CHANGED
package/lib/private/default.js
CHANGED
|
@@ -7,8 +7,11 @@ export default frontend({
|
|
|
7
7
|
root: {
|
|
8
8
|
create: create_root,
|
|
9
9
|
},
|
|
10
|
+
css: {
|
|
11
|
+
filter: /\.vuecss$/,
|
|
12
|
+
},
|
|
10
13
|
compile: {
|
|
11
|
-
client: (text, _, root) =>
|
|
14
|
+
client: (text, _, root) => root ? { js: text, css: "" } : compile.client(text),
|
|
12
15
|
server: (text, file) => file.path.startsWith("root:") ? text : compile.server(text),
|
|
13
16
|
},
|
|
14
17
|
});
|
package/lib/private/runtime.d.ts
CHANGED
package/lib/public/browser.d.ts
CHANGED
package/lib/public/browser.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Vue for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/vue",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
],
|
|
19
19
|
"types": "lib/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@
|
|
21
|
+
"@rcompat/fs": "^0.33.2",
|
|
22
|
+
"@primate/core": "^0.7.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@rcompat/type": "^0.
|
|
25
|
-
"@primate/test": "^0.0.0"
|
|
25
|
+
"@rcompat/type": "^0.17.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"vue": "3",
|
|
29
|
-
"primate": "^0.
|
|
29
|
+
"primate": "^0.38.0"
|
|
30
30
|
},
|
|
31
31
|
"imports": {
|
|
32
32
|
"#*": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
39
|
"types": "./lib/index.d.ts",
|
|
40
|
+
"@primate/runtime": "./src/public/runtime.ts",
|
|
40
41
|
"@primate/source": "./src/public/default.ts",
|
|
41
42
|
"browser": "./lib/public/browser.js",
|
|
42
43
|
"runtime": "./lib/public/runtime.js",
|
|
@@ -50,7 +51,6 @@
|
|
|
50
51
|
"scripts": {
|
|
51
52
|
"build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
|
|
52
53
|
"clean": "rm -rf ./lib",
|
|
53
|
-
"lint": "eslint ."
|
|
54
|
-
"test": "npx proby"
|
|
54
|
+
"lint": "eslint ."
|
|
55
55
|
}
|
|
56
56
|
}
|
package/lib/public/client.d.ts
DELETED
package/lib/public/client.js
DELETED