@primate/svelte 0.23.0 → 0.24.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 -2
- package/lib/private/client/app.js +4 -1
- package/lib/private/client/form.d.ts +2 -1
- package/lib/private/client/form.js +15 -4
- package/lib/private/default.d.ts +1 -1
- package/lib/private/default.js +7 -4
- package/lib/private/init.js +3 -3
- 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
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./app.d.ts";
|
|
2
|
-
|
|
3
|
-
export { default } from "
|
|
2
|
+
export { default } from "#default";
|
|
3
|
+
export { default as client } from "#client/index";
|
|
@@ -3,11 +3,14 @@ import client from "@primate/core/client";
|
|
|
3
3
|
import RootView from "svelte:root";
|
|
4
4
|
export default class SvelteApp {
|
|
5
5
|
static mount(_view, data) {
|
|
6
|
+
const interactive = !data.ssr || data.csr;
|
|
7
|
+
if (!interactive)
|
|
8
|
+
return;
|
|
6
9
|
const Root = root[data.ssr ? "ssr" : "csr"](RootView, {
|
|
7
10
|
props: { p: root.toProps(data) },
|
|
8
11
|
target: document.body,
|
|
9
12
|
});
|
|
10
|
-
if (data.
|
|
13
|
+
if (data.csr) {
|
|
11
14
|
const start = () => client.boot((_data, update) => {
|
|
12
15
|
Root.p = { ...root.toProps(_data), update };
|
|
13
16
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
import type { Readable } from "svelte/store";
|
|
4
4
|
type SvelteFormView<Values extends Dict> = {
|
|
@@ -17,6 +17,7 @@ type SvelteFormView<Values extends Dict> = {
|
|
|
17
17
|
type Initial<Values extends Dict> = FormInit & {
|
|
18
18
|
initial?: Values;
|
|
19
19
|
};
|
|
20
|
+
declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): Readable<SvelteFormView<Values>>;
|
|
20
21
|
declare function form<Values extends Dict>(init: Initial<Values>): Readable<SvelteFormView<Values>>;
|
|
21
22
|
declare function form(init?: FormInit): Readable<SvelteFormView<Dict>>;
|
|
22
23
|
export default form;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import client from "@primate/core/client";
|
|
2
2
|
import { writable } from "svelte/store";
|
|
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 = client.createForm({
|
|
11
|
+
...form_init,
|
|
12
|
+
...(action !== undefined && {
|
|
13
|
+
action: action,
|
|
14
|
+
contentType,
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
6
17
|
const values = initial ?? {};
|
|
7
18
|
const make_view = (snapshot) => {
|
|
8
19
|
const form_errors = snapshot.errors.form;
|
|
@@ -29,7 +40,7 @@ function form(init) {
|
|
|
29
40
|
submit: controller.submit,
|
|
30
41
|
});
|
|
31
42
|
const { subscribe, set } = writable(initial_view);
|
|
32
|
-
controller.subscribe(
|
|
43
|
+
controller.subscribe(snapshot => {
|
|
33
44
|
set(make_view({
|
|
34
45
|
...snapshot,
|
|
35
46
|
submit: controller.submit,
|
package/lib/private/default.d.ts
CHANGED
package/lib/private/default.js
CHANGED
|
@@ -9,6 +9,9 @@ const strip = (code) => {
|
|
|
9
9
|
format: "esm",
|
|
10
10
|
}).code;
|
|
11
11
|
};
|
|
12
|
+
const options = {
|
|
13
|
+
experimental: { async: true },
|
|
14
|
+
};
|
|
12
15
|
export default frontend({
|
|
13
16
|
...init,
|
|
14
17
|
root: {
|
|
@@ -22,15 +25,15 @@ export default frontend({
|
|
|
22
25
|
const accessors = true;
|
|
23
26
|
const { css, js } = file.path.endsWith(".js") || file.path.endsWith(".ts")
|
|
24
27
|
// runes in .svelte.[j|t]s
|
|
25
|
-
? compileModule(strip(text), { generate: "client" })
|
|
26
|
-
: compile(text, { accessors, generate: "client" });
|
|
28
|
+
? compileModule(strip(text), { generate: "client", ...options })
|
|
29
|
+
: compile(text, { accessors, generate: "client", ...options });
|
|
27
30
|
return { css: css?.code ?? "", js: js.code };
|
|
28
31
|
},
|
|
29
32
|
server: (text, file) => {
|
|
30
33
|
const { js } = file?.path.endsWith(".js") || file?.path.endsWith(".ts")
|
|
31
34
|
// runes in .svelte.[j|t]s
|
|
32
|
-
? compileModule(strip(text), { generate: "server" })
|
|
33
|
-
: compile(text, { generate: "server" });
|
|
35
|
+
? compileModule(strip(text), { generate: "server", ...options })
|
|
36
|
+
: compile(text, { generate: "server", ...options });
|
|
34
37
|
return js.code;
|
|
35
38
|
},
|
|
36
39
|
},
|
package/lib/private/init.js
CHANGED
|
@@ -4,9 +4,9 @@ const module = {
|
|
|
4
4
|
extensions: [".svelte.js", ".svelte.ts", ".svelte"],
|
|
5
5
|
layouts: true,
|
|
6
6
|
client: true,
|
|
7
|
-
render(view, props) {
|
|
8
|
-
const {
|
|
9
|
-
return { body
|
|
7
|
+
async render(view, props) {
|
|
8
|
+
const { body, head } = await render(view, { props: { p: { ...props } } });
|
|
9
|
+
return { body, head };
|
|
10
10
|
},
|
|
11
11
|
conditions: ["svelte"],
|
|
12
12
|
};
|
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/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Svelte for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/svelte",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
],
|
|
19
19
|
"types": "lib/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@rcompat/fs": "^0.33.2",
|
|
21
22
|
"esbuild": "^0.28.0",
|
|
22
|
-
"@primate/core": "^0.
|
|
23
|
+
"@primate/core": "^0.7.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@rcompat/type": "^0.
|
|
26
|
-
"@primate/test": "^0.0.0"
|
|
26
|
+
"@rcompat/type": "^0.17.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"svelte": "5",
|
|
30
|
-
"primate": "^0.
|
|
30
|
+
"primate": "^0.38.0"
|
|
31
31
|
},
|
|
32
32
|
"imports": {
|
|
33
33
|
"#*": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|
|
40
40
|
"types": "./lib/index.d.ts",
|
|
41
|
+
"@primate/runtime": "./src/public/runtime.ts",
|
|
41
42
|
"@primate/source": "./src/public/default.ts",
|
|
42
43
|
"browser": "./lib/public/browser.js",
|
|
43
44
|
"runtime": "./lib/public/runtime.js",
|
|
@@ -51,7 +52,6 @@
|
|
|
51
52
|
"scripts": {
|
|
52
53
|
"build": "npm run clean && tsc && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
|
|
53
54
|
"clean": "rm -rf ./lib",
|
|
54
|
-
"lint": "eslint ."
|
|
55
|
-
"test": "npx proby"
|
|
55
|
+
"lint": "eslint ."
|
|
56
56
|
}
|
|
57
57
|
}
|
package/lib/public/client.d.ts
DELETED
package/lib/public/client.js
DELETED