@primate/solid 0.8.0 → 0.10.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/app.d.ts +5 -0
- package/lib/index.d.ts +3 -0
- package/lib/private/client/Data.d.ts +5 -0
- package/lib/private/client/Data.js +2 -0
- package/lib/private/client/Payload.d.ts +7 -0
- package/lib/private/client/Payload.js +2 -0
- package/lib/private/client/app.d.ts +11 -8
- package/lib/private/client/app.js +20 -20
- package/lib/private/client/form.d.ts +5 -3
- package/lib/private/client/form.js +26 -9
- package/lib/{public/client.d.ts → private/client/index.d.ts} +1 -1
- package/lib/{public/client.js → private/client/index.js} +1 -1
- package/lib/private/client/root.d.ts +21 -0
- package/lib/private/client/root.js +20 -0
- package/lib/private/create-root.js +5 -3
- package/lib/private/default.d.ts +7 -0
- package/lib/private/{Default.js → default.js} +10 -8
- package/lib/private/init.d.ts +5 -0
- package/lib/private/{Runtime.js → init.js} +10 -10
- package/lib/private/request/store.d.ts +4 -0
- package/lib/private/request/store.js +4 -0
- package/lib/private/runtime.d.ts +7 -0
- package/lib/private/runtime.js +4 -0
- package/lib/public/app.d.ts +2 -0
- package/lib/public/app.js +2 -0
- package/lib/public/browser.d.ts +1 -0
- package/lib/public/browser.js +1 -0
- package/lib/public/default.d.ts +1 -3
- package/lib/public/default.js +1 -2
- package/lib/public/runtime.d.ts +2 -3
- package/lib/public/runtime.js +2 -2
- package/package.json +23 -11
- package/lib/private/Default.d.ts +0 -13
- package/lib/private/Runtime.d.ts +0 -11
package/lib/app.d.ts
ADDED
package/lib/index.d.ts
ADDED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type Data from "#client/Data";
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
_$HY: {
|
|
5
|
+
completed: WeakSet<object>;
|
|
6
|
+
events: unknown[];
|
|
7
|
+
r: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
7
11
|
export default class SolidApp {
|
|
8
|
-
static mount(_view: string, data:
|
|
12
|
+
static mount(_view: string, data: Data): void;
|
|
9
13
|
}
|
|
10
|
-
export {};
|
|
11
14
|
//# sourceMappingURL=app.d.ts.map
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import root from "#client/root";
|
|
2
|
+
import client from "@primate/core/client";
|
|
2
3
|
import SolidHead from "@primate/solid/Head";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import * as views from "solid:views";
|
|
6
|
-
// @ts-expect-error solid hydration
|
|
7
|
-
globalThis._$HY = { completed: new WeakSet(), events: [], r: {} };
|
|
4
|
+
import Root from "solid:root";
|
|
5
|
+
window._$HY = { completed: new WeakSet(), events: [], r: {} };
|
|
8
6
|
const { body } = globalThis.window.document;
|
|
9
7
|
SolidHead.clear();
|
|
10
|
-
const make_props = (data) => ({
|
|
11
|
-
views: data.views.map(name => views[name]),
|
|
12
|
-
props: data.props,
|
|
13
|
-
request: {
|
|
14
|
-
...data.request,
|
|
15
|
-
url: new URL(location.href),
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
8
|
export default class SolidApp {
|
|
19
9
|
static mount(_view, data) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const interactive = !data.ssr || data.csr;
|
|
11
|
+
if (!interactive)
|
|
12
|
+
return;
|
|
13
|
+
const mount = () => Root(root.toProps(data));
|
|
14
|
+
let dispose = root[data.ssr ? "ssr" : "csr"](mount, body);
|
|
15
|
+
if (data.csr) {
|
|
16
|
+
const start = () => client.boot((_data, update) => {
|
|
24
17
|
dispose();
|
|
25
|
-
dispose =
|
|
26
|
-
|
|
18
|
+
dispose = root.csr(() => Root(root.toProps(_data, update)), body);
|
|
19
|
+
update?.();
|
|
20
|
+
});
|
|
21
|
+
if (document.readyState === "loading") {
|
|
22
|
+
window.addEventListener("DOMContentLoaded", start, { once: true });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
start();
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
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
|
+
submitted: boolean;
|
|
6
7
|
submit: (event?: Event) => Promise<void>;
|
|
7
|
-
errors:
|
|
8
|
+
errors: string[];
|
|
8
9
|
field: <K extends keyof Values & string>(name: K) => {
|
|
9
10
|
name: string;
|
|
10
11
|
value: Values[K];
|
|
11
12
|
error: string | null;
|
|
12
|
-
errors:
|
|
13
|
+
errors: string[];
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
type Initial<Values extends Dict> = FormInit & {
|
|
16
17
|
initial?: Values;
|
|
17
18
|
};
|
|
19
|
+
declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): FormView<Values>;
|
|
18
20
|
declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
|
|
19
21
|
declare function form(init?: FormInit): FormView<Dict>;
|
|
20
22
|
export default form;
|
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import core from "@primate/core/client";
|
|
2
2
|
import { createSignal, onCleanup } from "solid-js";
|
|
3
|
-
function form(
|
|
4
|
-
const
|
|
5
|
-
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
|
+
});
|
|
6
17
|
const values = initial ?? {};
|
|
7
18
|
const [snapshot, setSnapshot] = createSignal(controller.read());
|
|
8
|
-
const
|
|
9
|
-
onCleanup(
|
|
19
|
+
const unsubscribe = controller.subscribe(next => setSnapshot(next));
|
|
20
|
+
onCleanup(unsubscribe);
|
|
10
21
|
return {
|
|
11
|
-
id
|
|
22
|
+
get id() {
|
|
23
|
+
return snapshot().id;
|
|
24
|
+
},
|
|
12
25
|
get submitting() {
|
|
13
26
|
return snapshot().submitting;
|
|
14
27
|
},
|
|
15
|
-
|
|
28
|
+
get submitted() {
|
|
29
|
+
return snapshot().submitted;
|
|
30
|
+
},
|
|
31
|
+
submit(event) {
|
|
32
|
+
return controller.submit(event);
|
|
33
|
+
},
|
|
16
34
|
get errors() {
|
|
17
35
|
return snapshot().errors.form;
|
|
18
36
|
},
|
|
@@ -25,8 +43,7 @@ function form(init) {
|
|
|
25
43
|
return snapshot().errors.fields[key] ?? [];
|
|
26
44
|
},
|
|
27
45
|
get error() {
|
|
28
|
-
|
|
29
|
-
return errors[0] ?? null;
|
|
46
|
+
return (snapshot().errors.fields[key] ?? [])[0] ?? null;
|
|
30
47
|
},
|
|
31
48
|
};
|
|
32
49
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type Data from "#client/Data";
|
|
2
|
+
import type { Dict } from "@rcompat/type";
|
|
3
|
+
import { type Component } from "solid-js";
|
|
4
|
+
import { render } from "solid-js/web";
|
|
5
|
+
type ViewComponent = Component<any>;
|
|
6
|
+
export type RootProps = {
|
|
7
|
+
views: ViewComponent[];
|
|
8
|
+
props: Dict[];
|
|
9
|
+
request: Data["request"] & {
|
|
10
|
+
url: URL;
|
|
11
|
+
};
|
|
12
|
+
update?: () => void;
|
|
13
|
+
};
|
|
14
|
+
declare function toProps(data: Data, update?: () => void): RootProps;
|
|
15
|
+
declare const root: {
|
|
16
|
+
toProps: typeof toProps;
|
|
17
|
+
csr: typeof render;
|
|
18
|
+
ssr: typeof import("solid-js/web/types/client.js").hydrate;
|
|
19
|
+
};
|
|
20
|
+
export default root;
|
|
21
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hydrate, render } from "solid-js/web";
|
|
2
|
+
import * as Views from "solid:views";
|
|
3
|
+
function toProps(data, update) {
|
|
4
|
+
return {
|
|
5
|
+
views: data.views.map(name => Views[name]),
|
|
6
|
+
props: data.props,
|
|
7
|
+
request: {
|
|
8
|
+
...data.request,
|
|
9
|
+
url: new URL(data.request.url),
|
|
10
|
+
},
|
|
11
|
+
update,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const root = {
|
|
15
|
+
toProps,
|
|
16
|
+
csr: render,
|
|
17
|
+
ssr: hydrate,
|
|
18
|
+
};
|
|
19
|
+
export default root;
|
|
20
|
+
//# sourceMappingURL=root.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export default (length, i18n_active) => {
|
|
2
2
|
const n = length;
|
|
3
3
|
const body = Array.from({ length: n }, (_, i) => i - 1).reduceRight((child, _, i) => `views[${i + 1}] !== undefined
|
|
4
|
-
? createComponent(views[${i}], {
|
|
4
|
+
? createComponent(views[${i}], { ...props[${i}],
|
|
5
5
|
get children() { return ${child}; }
|
|
6
6
|
})
|
|
7
|
-
: createComponent(views[${i}],
|
|
8
|
-
`, `createComponent(views[${n}],
|
|
7
|
+
: createComponent(views[${i}], props[${i}])
|
|
8
|
+
`, `createComponent(views[${n}], props[${n}])`);
|
|
9
9
|
const i18n_imports = i18n_active
|
|
10
10
|
? `
|
|
11
11
|
import I18nBridge from "@primate/solid/i18n/Bridge";
|
|
@@ -17,10 +17,12 @@ export default (length, i18n_active) => {
|
|
|
17
17
|
return `
|
|
18
18
|
import { createSignal } from "solid-js";
|
|
19
19
|
import { createComponent } from "solid-js/web";
|
|
20
|
+
import { setRequest } from "@primate/solid/app";
|
|
20
21
|
import AppContext from "@primate/solid/context/app";
|
|
21
22
|
import HeadContext from "@primate/solid/context/head";${i18n_imports}
|
|
22
23
|
|
|
23
24
|
export default ({ views, props, request, push_heads: value }) => {
|
|
25
|
+
setRequest(request);
|
|
24
26
|
const [context, setContext] = createSignal(request.context);
|
|
25
27
|
const $value = { context, setContext };
|
|
26
28
|
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import create_root from "#create-root";
|
|
2
|
-
import
|
|
2
|
+
import init from "#init";
|
|
3
3
|
import { transformSync } from "@babel/core";
|
|
4
4
|
import build_presets from "@primate/core/build/presets";
|
|
5
5
|
import transform from "@primate/core/build/transform";
|
|
6
|
+
import frontend from "@primate/core/frontend";
|
|
6
7
|
// @ts-expect-error no declaration file
|
|
7
8
|
import solid from "babel-preset-solid";
|
|
8
9
|
function compile(text, presets) {
|
|
9
10
|
return transformSync(transform(text, build_presets.solid).code, { presets })?.code ?? "";
|
|
10
11
|
}
|
|
11
|
-
export default
|
|
12
|
-
|
|
12
|
+
export default frontend({
|
|
13
|
+
...init,
|
|
14
|
+
root: {
|
|
13
15
|
create: create_root,
|
|
14
|
-
}
|
|
15
|
-
compile
|
|
16
|
+
},
|
|
17
|
+
compile: {
|
|
16
18
|
client: (text) => {
|
|
17
19
|
const presets = [[solid, { generate: "dom", hydratable: true }]];
|
|
18
20
|
return { js: compile(text, presets) };
|
|
@@ -21,6 +23,6 @@ export default class Default extends Runtime {
|
|
|
21
23
|
const presets = [[solid, { generate: "ssr", hydratable: true }]];
|
|
22
24
|
return compile(text, presets);
|
|
23
25
|
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
1
|
import { renderToString } from "solid-js/web";
|
|
3
|
-
|
|
4
|
-
name
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
render
|
|
2
|
+
const module = {
|
|
3
|
+
name: "solid",
|
|
4
|
+
extensions: [".jsx", ".tsx"],
|
|
5
|
+
layouts: true,
|
|
6
|
+
client: true,
|
|
7
|
+
render(view, props) {
|
|
9
8
|
const heads = [];
|
|
10
9
|
const push_heads = (sub_heads) => {
|
|
11
10
|
heads.push(...sub_heads);
|
|
@@ -17,6 +16,7 @@ export default class Runtime extends FrontendModule {
|
|
|
17
16
|
}
|
|
18
17
|
const head = heads.join("\n");
|
|
19
18
|
return { body, head };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export default module;
|
|
22
|
+
//# sourceMappingURL=init.js.map
|
package/lib/public/browser.d.ts
CHANGED
package/lib/public/browser.js
CHANGED
package/lib/public/default.d.ts
CHANGED
package/lib/public/default.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export default
|
|
1
|
+
export { default as client } from "#client/index";
|
|
2
|
+
export { default } from "#runtime";
|
|
3
3
|
//# sourceMappingURL=runtime.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/solid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "SolidJS for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/solid",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -16,46 +16,58 @@
|
|
|
16
16
|
"/lib/**/*.d.ts",
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
|
+
"types": "lib/index.d.ts",
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@rcompat/type": "^0.
|
|
21
|
+
"@rcompat/type": "^0.17.0",
|
|
21
22
|
"@types/babel__core": "^7.20.5"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@babel/core": "^7.28.6",
|
|
25
|
-
"@rcompat/fs": "^0.
|
|
26
|
-
"@rcompat/runtime": "^0.
|
|
27
|
-
"babel-preset-solid": "^1.9.
|
|
28
|
-
"@primate/core": "^0.
|
|
26
|
+
"@rcompat/fs": "^0.33.2",
|
|
27
|
+
"@rcompat/runtime": "^0.16.0",
|
|
28
|
+
"babel-preset-solid": "^1.9.12",
|
|
29
|
+
"@primate/core": "^0.7.0"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"solid-js": "1",
|
|
32
|
-
"primate": "^0.
|
|
33
|
+
"primate": "^0.38.0"
|
|
33
34
|
},
|
|
34
35
|
"imports": {
|
|
36
|
+
"#i18n/Bridge.default": {
|
|
37
|
+
"@primate/source": "./src/private/i18n/Bridge.default.tsx",
|
|
38
|
+
"default": "./lib/private/i18n/Bridge.default.js"
|
|
39
|
+
},
|
|
35
40
|
"#*": {
|
|
36
|
-
"
|
|
41
|
+
"@primate/source": "./src/private/*.ts",
|
|
37
42
|
"default": "./lib/private/*.js"
|
|
38
43
|
},
|
|
39
44
|
"#HeadImpl": {
|
|
40
|
-
"
|
|
45
|
+
"@primate/source": "./src/private/Head/default.ts",
|
|
41
46
|
"browser": "./lib/private/Head/browser.js",
|
|
42
47
|
"default": "./lib/private/Head/default.js"
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
"exports": {
|
|
46
51
|
".": {
|
|
52
|
+
"types": "./lib/index.d.ts",
|
|
53
|
+
"@primate/runtime": "./src/public/runtime.ts",
|
|
54
|
+
"@primate/source": "./src/public/default.ts",
|
|
47
55
|
"browser": "./lib/public/browser.js",
|
|
48
56
|
"runtime": "./lib/public/runtime.js",
|
|
49
57
|
"default": "./lib/public/default.js"
|
|
50
58
|
},
|
|
51
|
-
"./*":
|
|
59
|
+
"./*": {
|
|
60
|
+
"@primate/source": "./src/public/*.ts",
|
|
61
|
+
"default": "./lib/public/*.js"
|
|
62
|
+
},
|
|
52
63
|
"./i18n/Bridge": {
|
|
64
|
+
"@primate/source": "./src/public/i18n/Bridge/default.ts",
|
|
53
65
|
"browser": "./lib/public/i18n/Bridge/browser.js",
|
|
54
66
|
"default": "./lib/public/i18n/Bridge/default.js"
|
|
55
67
|
}
|
|
56
68
|
},
|
|
57
69
|
"scripts": {
|
|
58
|
-
"build": "npm run clean && tsc",
|
|
70
|
+
"build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
|
|
59
71
|
"postbuild": "node scripts/compile-jsx.js",
|
|
60
72
|
"clean": "rm -rf ./lib",
|
|
61
73
|
"lint": "eslint ."
|
package/lib/private/Default.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
export default class Default extends Runtime {
|
|
3
|
-
root: {
|
|
4
|
-
create: (length: number, i18n_active: boolean) => string;
|
|
5
|
-
};
|
|
6
|
-
compile: {
|
|
7
|
-
client: (text: string) => {
|
|
8
|
-
js: string;
|
|
9
|
-
};
|
|
10
|
-
server: (text: string) => string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=Default.d.ts.map
|
package/lib/private/Runtime.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
-
import type Render from "@primate/core/frontend/Render";
|
|
3
|
-
import type { Component } from "solid-js";
|
|
4
|
-
export default class Runtime extends FrontendModule<Component> {
|
|
5
|
-
name: string;
|
|
6
|
-
defaultExtensions: string[];
|
|
7
|
-
client: boolean;
|
|
8
|
-
layouts: boolean;
|
|
9
|
-
render: Render<Component>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=Runtime.d.ts.map
|