@primate/solid 0.0.2 → 0.1.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 +1 -1
- package/src/client/client.js +3 -3
- package/src/client/exports.js +0 -1
- package/src/client/hydrate.js +4 -1
- package/src/client/liveview.js +5 -6
- package/src/module.js +17 -16
- package/src/client/create-root2.js +0 -22
package/package.json
CHANGED
package/src/client/client.js
CHANGED
|
@@ -7,13 +7,13 @@ const {groups: {code: hydration_script}} = generateHydrationScript()
|
|
|
7
7
|
|
|
8
8
|
export default ({names, data}, options) => `
|
|
9
9
|
import * as components from "app";
|
|
10
|
-
import {hydrate_solid} from "app";
|
|
10
|
+
import {hydrate_solid, render_solid} from "app";
|
|
11
11
|
|
|
12
|
-
window._$HY = {
|
|
12
|
+
window._$HY = {events: [], completed: new WeakSet(), r: {}};
|
|
13
13
|
|
|
14
14
|
${hydration_script}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
let dispose = hydrate_solid(() => components.${rootname}({
|
|
17
17
|
components: [${names.map(name => `components.${name}`).join(", ")}],
|
|
18
18
|
data: JSON.parse(${JSON.stringify(JSON.stringify(data))}),
|
|
19
19
|
}), globalThis.window.document.body);
|
package/src/client/exports.js
CHANGED
package/src/client/hydrate.js
CHANGED
package/src/client/liveview.js
CHANGED
|
@@ -3,10 +3,9 @@ import rootname from "./rootname.js";
|
|
|
3
3
|
export default `
|
|
4
4
|
const {liveview} = components;
|
|
5
5
|
window.addEventListener("DOMContentLoaded", _ => liveview((props, update) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
);
|
|
6
|
+
dispose();
|
|
7
|
+
dispose = render_solid(() => components.${rootname}({
|
|
8
|
+
components: props.names.map(name => components[name]),
|
|
9
|
+
data: props.data,
|
|
10
|
+
}), globalThis.window.document.body);
|
|
12
11
|
}));`;
|
package/src/module.js
CHANGED
|
@@ -6,7 +6,7 @@ import solid from "babel-preset-solid";
|
|
|
6
6
|
import {renderToString} from "solid-js/web";
|
|
7
7
|
import {tryreturn} from "runtime-compat/async";
|
|
8
8
|
import errors from "./errors.js";
|
|
9
|
-
import {client, create_root,
|
|
9
|
+
import {client, create_root, rootname, hydrate} from "./client/exports.js";
|
|
10
10
|
|
|
11
11
|
// do not hard-depend on node
|
|
12
12
|
const packager = import.meta.runtime?.packager ?? "package.json";
|
|
@@ -45,7 +45,7 @@ const type = "module";
|
|
|
45
45
|
|
|
46
46
|
const load = async path =>
|
|
47
47
|
tryreturn(async () => (await import(`${path}.js`)).default)
|
|
48
|
-
.orelse(
|
|
48
|
+
.orelse(error => {console.log(error);return errors.MissingComponent.throw(path.name, path)});
|
|
49
49
|
|
|
50
50
|
const make_component = base => async (name, props) =>
|
|
51
51
|
({name, component: await load(base.join(name)), props});
|
|
@@ -108,11 +108,6 @@ const options = {
|
|
|
108
108
|
}],
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
const endings = {
|
|
112
|
-
solid: ".solid",
|
|
113
|
-
js: ".solid.js",
|
|
114
|
-
};
|
|
115
|
-
|
|
116
111
|
const transform = {
|
|
117
112
|
async server(file) {
|
|
118
113
|
return (await transformAsync(file, {presets: [options.server]})).code;
|
|
@@ -127,22 +122,28 @@ export default ({
|
|
|
127
122
|
extension = "jsx",
|
|
128
123
|
} = {}) => {
|
|
129
124
|
const env = {};
|
|
125
|
+
const copy_re = new RegExp(`^.*.(?:${extension})$`, "u");
|
|
126
|
+
const collect_re = new RegExp(`^.*.${extension}$`, "u");
|
|
127
|
+
const extensions = {
|
|
128
|
+
from: `.${extension}`,
|
|
129
|
+
to: `.${extension}.js`,
|
|
130
|
+
};
|
|
130
131
|
|
|
131
132
|
return {
|
|
132
133
|
name: "@primate/solid",
|
|
133
|
-
init(app, next) {
|
|
134
|
+
init(app, next/*0.21 compat, remove >0.21*/ = () => null) {
|
|
134
135
|
env.source = app.build.paths.components;
|
|
135
136
|
|
|
136
137
|
return next(app);
|
|
137
138
|
},
|
|
138
139
|
register(app, next) {
|
|
139
|
-
app.register(
|
|
140
|
+
app.register(extension, handler);
|
|
140
141
|
return next(app);
|
|
141
142
|
},
|
|
142
143
|
async compile(app, next) {
|
|
143
144
|
// copy components to build/components
|
|
144
|
-
await app.copy(app.paths.components, env.source,
|
|
145
|
-
const components = await env.source.collect(
|
|
145
|
+
await app.copy(app.paths.components, env.source, copy_re);
|
|
146
|
+
const components = await env.source.collect(collect_re);
|
|
146
147
|
const target = app.build.paths.server.join(app.config.build.app);
|
|
147
148
|
await target.file.create();
|
|
148
149
|
|
|
@@ -151,10 +152,10 @@ export default ({
|
|
|
151
152
|
const code = await transform.server(file);
|
|
152
153
|
const to = target.join(`${component.path}.js`.replace(env.source, ""));
|
|
153
154
|
await to.directory.file.create();
|
|
154
|
-
await to.file.write(code.replaceAll(
|
|
155
|
+
await to.file.write(code.replaceAll(extensions.from, extensions.to));
|
|
155
156
|
}));
|
|
156
157
|
|
|
157
|
-
const root = await transform.server(
|
|
158
|
+
const root = await transform.server(create_root(app.layoutDepth,
|
|
158
159
|
dynamicProps));
|
|
159
160
|
const to = app.build.paths.server.join(filename);
|
|
160
161
|
await to.file.write(root);
|
|
@@ -166,7 +167,7 @@ export default ({
|
|
|
166
167
|
await target.file.create();
|
|
167
168
|
|
|
168
169
|
// create client components
|
|
169
|
-
const components = await env.source.collect(
|
|
170
|
+
const components = await env.source.collect(collect_re);
|
|
170
171
|
await Promise.all(components.map(async component => {
|
|
171
172
|
const name = component.path.replace(`${env.source}/`, "");
|
|
172
173
|
const file = await component.file.read();
|
|
@@ -178,7 +179,7 @@ export default ({
|
|
|
178
179
|
{
|
|
179
180
|
const src = `${path}.js`.replace(`${env.source}`, _ => build);
|
|
180
181
|
await app.publish({src,
|
|
181
|
-
code: code.replaceAll(
|
|
182
|
+
code: code.replaceAll(extensions.from, extensions.to),
|
|
182
183
|
type});
|
|
183
184
|
}
|
|
184
185
|
const imported = await normalize(name);
|
|
@@ -195,7 +196,7 @@ export default ({
|
|
|
195
196
|
app.bootstrap({type: "script", code: hydrate});
|
|
196
197
|
|
|
197
198
|
{
|
|
198
|
-
const code = await transform.client(
|
|
199
|
+
const code = await transform.client(create_root(app.layoutDepth,
|
|
199
200
|
dynamicProps));
|
|
200
201
|
const src = new Path(app.config.http.static.root, filename);
|
|
201
202
|
await app.publish({src, code, type});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export default (length, data) => {
|
|
2
|
-
const n = length - 1;
|
|
3
|
-
const body = Array.from({length: n}, (_, i) => i - 1)
|
|
4
|
-
.reduceRight((child, _, i) => `<Show
|
|
5
|
-
when={components[${i + 1}] !== undefined}
|
|
6
|
-
fallback={
|
|
7
|
-
<>
|
|
8
|
-
<Dynamic component={components[${i}]} ${data}={data[${i}]} />
|
|
9
|
-
</>
|
|
10
|
-
}
|
|
11
|
-
>
|
|
12
|
-
<Dynamic component={components[${i}]} ${data}={data[${i}]}>${child}</Dynamic>
|
|
13
|
-
</Show>
|
|
14
|
-
`, `<Dynamic component={components[${n}]} ${data}={data[${n}]} />`);
|
|
15
|
-
|
|
16
|
-
return `
|
|
17
|
-
import {Dynamic, Show} from "solid-js/web";
|
|
18
|
-
export default function Root({components, data} = {}) {
|
|
19
|
-
return ${body};
|
|
20
|
-
};
|
|
21
|
-
`;
|
|
22
|
-
};
|