@primate/svelte 0.15.1 → 0.15.3
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 +3 -3
- package/src/client/client.js +1 -5
- package/src/client/liveview.js +1 -1
- package/src/module.js +8 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/svelte",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "Primate Svelte module",
|
|
5
5
|
"homepage": "https://primatejs.com/modules/svelte",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"directory": "packages/svelte"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"runtime-compat": "^0.
|
|
20
|
-
"svelte": "^4.1.
|
|
19
|
+
"runtime-compat": "^0.25.1",
|
|
20
|
+
"svelte": "^4.1.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"primate": "0.21"
|
package/src/client/client.js
CHANGED
|
@@ -3,15 +3,11 @@ import liveview from "./liveview.js";
|
|
|
3
3
|
|
|
4
4
|
export default ({names, data}, options) => `
|
|
5
5
|
import * as components from "app";
|
|
6
|
-
const getComponents = names =>
|
|
7
|
-
Object.entries(components).filter(([name, component]) =>
|
|
8
|
-
names.includes(name))
|
|
9
|
-
.map(([, component]) => component);
|
|
10
6
|
let root = new components.${rootname}({
|
|
11
7
|
target: document.body,
|
|
12
8
|
hydrate: true,
|
|
13
9
|
props: {
|
|
14
|
-
components:
|
|
10
|
+
components: [${names.map(name => `components.${name}`).join(", ")}],
|
|
15
11
|
data: JSON.parse(${JSON.stringify(JSON.stringify(data))}),
|
|
16
12
|
},
|
|
17
13
|
});
|
package/src/client/liveview.js
CHANGED
|
@@ -8,7 +8,7 @@ window.addEventListener("DOMContentLoaded", _ => liveview((props, update) => {
|
|
|
8
8
|
target: document.body,
|
|
9
9
|
hydrate: true,
|
|
10
10
|
props: {
|
|
11
|
-
components:
|
|
11
|
+
components: props.names.map(name => components[name]),
|
|
12
12
|
data: props.data,
|
|
13
13
|
update,
|
|
14
14
|
},
|
package/src/module.js
CHANGED
|
@@ -11,6 +11,7 @@ const endings = {
|
|
|
11
11
|
js: ".svelte.js",
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const encoder = new TextEncoder();
|
|
14
15
|
const hash = async (string, algorithm = "sha-256") => {
|
|
15
16
|
const base = 16;
|
|
16
17
|
const target_pad_length = 2;
|
|
@@ -34,8 +35,6 @@ const load = async path =>
|
|
|
34
35
|
const make_component = base => async (name, props) =>
|
|
35
36
|
({name, component: await load(base.join(name)), props});
|
|
36
37
|
|
|
37
|
-
const encoder = new TextEncoder();
|
|
38
|
-
|
|
39
38
|
const handler = (name, props = {}, {status = Status.OK, page} = {}) =>
|
|
40
39
|
async (app, {layouts = [], as_layout} = {}, request) => {
|
|
41
40
|
const options = {
|
|
@@ -56,7 +55,6 @@ const handler = (name, props = {}, {status = Status.OK, page} = {}) =>
|
|
|
56
55
|
const data = components.map(component => component.props);
|
|
57
56
|
const names = await Promise.all(components.map(component =>
|
|
58
57
|
normalize(component.name)));
|
|
59
|
-
|
|
60
58
|
if (options.liveview && headers.get(app.liveview.header) !== undefined) {
|
|
61
59
|
return new Response(JSON.stringify({names, data}), {
|
|
62
60
|
status,
|
|
@@ -64,9 +62,10 @@ const handler = (name, props = {}, {status = Status.OK, page} = {}) =>
|
|
|
64
62
|
"Content-Type": MediaType.APPLICATION_JSON},
|
|
65
63
|
});
|
|
66
64
|
}
|
|
65
|
+
|
|
67
66
|
const root = paths.server.join(filename);
|
|
68
67
|
const imported = (await import(root)).default;
|
|
69
|
-
const {html} = imported.render({
|
|
68
|
+
const {html: body} = imported.render({
|
|
70
69
|
components: components.map(({component}) => component),
|
|
71
70
|
data,
|
|
72
71
|
});
|
|
@@ -74,10 +73,10 @@ const handler = (name, props = {}, {status = Status.OK, page} = {}) =>
|
|
|
74
73
|
const code = client({names, data}, options);
|
|
75
74
|
|
|
76
75
|
await app.publish({code, type, inline: true});
|
|
77
|
-
|
|
76
|
+
// needs to be called before app.render
|
|
78
77
|
const headers$ = await app.headers();
|
|
79
78
|
|
|
80
|
-
return new Response(await app.render({body
|
|
79
|
+
return new Response(await app.render({body, page}), {
|
|
81
80
|
status,
|
|
82
81
|
headers: {...headers$, "Content-Type": MediaType.TEXT_HTML},
|
|
83
82
|
});
|
|
@@ -89,7 +88,9 @@ const options = {
|
|
|
89
88
|
};
|
|
90
89
|
|
|
91
90
|
const {svelte, js} = endings;
|
|
92
|
-
export default ({
|
|
91
|
+
export default ({
|
|
92
|
+
dynamicProps = "data",
|
|
93
|
+
} = {}) => ({
|
|
93
94
|
name: "@primate/svelte",
|
|
94
95
|
register(app, next) {
|
|
95
96
|
app.register("svelte", handler);
|
|
@@ -123,13 +124,6 @@ export default ({dynamicProps = "data"} = {}) => ({
|
|
|
123
124
|
const components = await source.collect(/^.*.svelte$/u);
|
|
124
125
|
await app.import("svelte");
|
|
125
126
|
|
|
126
|
-
// liveview
|
|
127
|
-
if (app.liveview !== undefined) {
|
|
128
|
-
app.bootstrap({
|
|
129
|
-
type: "script",
|
|
130
|
-
code: "export {default as liveview} from \"@primate/liveview\";\n",
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
127
|
await Promise.all(components.map(async component => {
|
|
134
128
|
const name = component.path.replace(`${source}/`, "");
|
|
135
129
|
const file = await component.file.read();
|