@primate/svelte 0.22.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/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 +2 -8
- package/lib/private/client/app.js +19 -20
- package/lib/private/client/form.d.ts +4 -2
- package/lib/private/client/form.js +16 -4
- 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 +33 -0
- package/lib/private/client/root.js +20 -0
- package/lib/private/create-root.js +9 -3
- package/lib/private/default.d.ts +7 -0
- package/lib/private/{Default.js → default.js} +19 -14
- package/lib/private/init.d.ts +5 -0
- package/lib/private/init.js +14 -0
- package/lib/private/request/store.d.ts +4 -0
- package/lib/private/request/store.js +3 -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 +13 -9
- package/lib/private/Default.d.ts +0 -18
- package/lib/private/Runtime.d.ts +0 -12
- package/lib/private/Runtime.js +0 -14
package/lib/app.d.ts
ADDED
package/lib/index.d.ts
ADDED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { Dict } from "@rcompat/type";
|
|
3
|
-
type Data = ClientData<{
|
|
4
|
-
views: string[];
|
|
5
|
-
props: Dict[];
|
|
6
|
-
}>;
|
|
1
|
+
import type Data from "#client/Data";
|
|
7
2
|
export default class SvelteApp {
|
|
8
|
-
static mount(_view: string, data:
|
|
3
|
+
static mount(_view: string, data: Data): void;
|
|
9
4
|
}
|
|
10
|
-
export {};
|
|
11
5
|
//# sourceMappingURL=app.d.ts.map
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as views from "svelte:views";
|
|
5
|
-
const make_props = (data) => ({
|
|
6
|
-
views: data.views.map(name => views[name]),
|
|
7
|
-
props: data.props,
|
|
8
|
-
request: {
|
|
9
|
-
...data.request,
|
|
10
|
-
url: new URL(location.href),
|
|
11
|
-
},
|
|
12
|
-
update: () => undefined,
|
|
13
|
-
});
|
|
1
|
+
import root from "#client/root";
|
|
2
|
+
import client from "@primate/core/client";
|
|
3
|
+
import RootView from "svelte:root";
|
|
14
4
|
export default class SvelteApp {
|
|
15
5
|
static mount(_view, data) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const interactive = !data.ssr || data.csr;
|
|
7
|
+
if (!interactive)
|
|
8
|
+
return;
|
|
9
|
+
const Root = root[data.ssr ? "ssr" : "csr"](RootView, {
|
|
10
|
+
props: { p: root.toProps(data) },
|
|
20
11
|
target: document.body,
|
|
21
12
|
});
|
|
22
|
-
data.
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
if (data.csr) {
|
|
14
|
+
const start = () => client.boot((_data, update) => {
|
|
15
|
+
Root.p = { ...root.toProps(_data), update };
|
|
16
|
+
});
|
|
17
|
+
if (document.readyState === "loading") {
|
|
18
|
+
window.addEventListener("DOMContentLoaded", start, { once: true });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
start();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
//# sourceMappingURL=app.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ClientMethod, FormInit } from "@primate/core/client";
|
|
2
2
|
import type { Dict } from "@rcompat/type";
|
|
3
|
-
import {
|
|
3
|
+
import type { Readable } from "svelte/store";
|
|
4
4
|
type SvelteFormView<Values extends Dict> = {
|
|
5
5
|
id: string;
|
|
6
6
|
submitting: boolean;
|
|
7
|
+
submitted: boolean;
|
|
7
8
|
submit: (event?: Event) => Promise<void>;
|
|
8
9
|
errors: readonly string[];
|
|
9
10
|
field: <K extends keyof Values & string>(name: K) => {
|
|
@@ -16,6 +17,7 @@ type SvelteFormView<Values extends Dict> = {
|
|
|
16
17
|
type Initial<Values extends Dict> = FormInit & {
|
|
17
18
|
initial?: Values;
|
|
18
19
|
};
|
|
20
|
+
declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): Readable<SvelteFormView<Values>>;
|
|
19
21
|
declare function form<Values extends Dict>(init: Initial<Values>): Readable<SvelteFormView<Values>>;
|
|
20
22
|
declare function form(init?: FormInit): Readable<SvelteFormView<Dict>>;
|
|
21
23
|
export default form;
|
|
@@ -1,14 +1,26 @@
|
|
|
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;
|
|
9
20
|
return {
|
|
10
21
|
id: snapshot.id,
|
|
11
22
|
submitting: snapshot.submitting,
|
|
23
|
+
submitted: snapshot.submitted,
|
|
12
24
|
submit: controller.submit,
|
|
13
25
|
errors: form_errors,
|
|
14
26
|
field(name) {
|
|
@@ -28,7 +40,7 @@ function form(init) {
|
|
|
28
40
|
submit: controller.submit,
|
|
29
41
|
});
|
|
30
42
|
const { subscribe, set } = writable(initial_view);
|
|
31
|
-
controller.subscribe(
|
|
43
|
+
controller.subscribe(snapshot => {
|
|
32
44
|
set(make_view({
|
|
33
45
|
...snapshot,
|
|
34
46
|
submit: controller.submit,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Data from "#client/Data";
|
|
2
|
+
import type { Dict } from "@rcompat/type";
|
|
3
|
+
import { hydrate, mount } from "svelte";
|
|
4
|
+
import type { Component } from "svelte";
|
|
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): {
|
|
15
|
+
views: Component<{}, {}, string>[];
|
|
16
|
+
props: Dict[];
|
|
17
|
+
request: {
|
|
18
|
+
url: URL;
|
|
19
|
+
context: Dict;
|
|
20
|
+
cookies: Dict<string>;
|
|
21
|
+
headers: Dict<string>;
|
|
22
|
+
path: Dict<string>;
|
|
23
|
+
query: Dict<string>;
|
|
24
|
+
};
|
|
25
|
+
update: () => undefined;
|
|
26
|
+
};
|
|
27
|
+
declare const root: {
|
|
28
|
+
toProps: typeof toProps;
|
|
29
|
+
ssr: typeof hydrate;
|
|
30
|
+
csr: typeof mount;
|
|
31
|
+
};
|
|
32
|
+
export default root;
|
|
33
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hydrate, mount } from "svelte";
|
|
2
|
+
import * as views from "svelte:views";
|
|
3
|
+
function toProps(data) {
|
|
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: () => undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const root = {
|
|
15
|
+
toProps,
|
|
16
|
+
ssr: hydrate,
|
|
17
|
+
csr: mount,
|
|
18
|
+
};
|
|
19
|
+
export default root;
|
|
20
|
+
//# sourceMappingURL=root.js.map
|
|
@@ -3,13 +3,13 @@ export default (depth, i18n_active) => {
|
|
|
3
3
|
const body = Array.from({ length: n }, (_, i) => i - 1)
|
|
4
4
|
.reduceRight((child, _, i) => `
|
|
5
5
|
{#if p.views[${i + 1}]}
|
|
6
|
-
<svelte:component this={p.views[${i}]}
|
|
6
|
+
<svelte:component this={p.views[${i}]} {...p.props[${i}]}>
|
|
7
7
|
${child}
|
|
8
8
|
</svelte:component>
|
|
9
9
|
{:else}
|
|
10
|
-
<svelte:component this={p.views[${i}]}
|
|
10
|
+
<svelte:component this={p.views[${i}]} {...p.props[${i}]}/>
|
|
11
11
|
{/if}
|
|
12
|
-
`, `<svelte:component this={p.views[${n}]}
|
|
12
|
+
`, `<svelte:component this={p.views[${n}]} {...p.props[${n}]}/>`);
|
|
13
13
|
const i18nImports = i18n_active
|
|
14
14
|
? `
|
|
15
15
|
import t from "#i18n";
|
|
@@ -30,15 +30,21 @@ export default (depth, i18n_active) => {
|
|
|
30
30
|
<script>
|
|
31
31
|
import { afterUpdate, setContext } from "svelte";
|
|
32
32
|
import context_name from "@primate/svelte/context-name";
|
|
33
|
+
import { request } from "@primate/svelte/app";
|
|
33
34
|
${i18nImports}
|
|
34
35
|
|
|
35
36
|
export let p;
|
|
36
37
|
|
|
37
38
|
setContext(context_name, p.request.context);
|
|
38
39
|
|
|
40
|
+
const { context, path, ...public_request } = p.request;
|
|
41
|
+
request.set(public_request);
|
|
42
|
+
|
|
39
43
|
${i18nInit}
|
|
40
44
|
|
|
41
45
|
afterUpdate(() => {
|
|
46
|
+
const { context, path, ...public_request } = p.request;
|
|
47
|
+
request.set(public_request);
|
|
42
48
|
p.update?.();
|
|
43
49
|
});
|
|
44
50
|
</script>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import create_root from "#create-root";
|
|
2
|
-
import
|
|
2
|
+
import init from "#init";
|
|
3
|
+
import frontend from "@primate/core/frontend";
|
|
3
4
|
import esbuild from "esbuild";
|
|
4
5
|
import { compile, compileModule } from "svelte/compiler";
|
|
5
6
|
const strip = (code) => {
|
|
@@ -8,29 +9,33 @@ const strip = (code) => {
|
|
|
8
9
|
format: "esm",
|
|
9
10
|
}).code;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const options = {
|
|
13
|
+
experimental: { async: true },
|
|
14
|
+
};
|
|
15
|
+
export default frontend({
|
|
16
|
+
...init,
|
|
17
|
+
root: {
|
|
13
18
|
create: create_root,
|
|
14
|
-
}
|
|
15
|
-
css
|
|
19
|
+
},
|
|
20
|
+
css: {
|
|
16
21
|
filter: /\.sveltecss$/,
|
|
17
|
-
}
|
|
18
|
-
compile
|
|
22
|
+
},
|
|
23
|
+
compile: {
|
|
19
24
|
client: (text, file) => {
|
|
20
25
|
const accessors = true;
|
|
21
26
|
const { css, js } = file.path.endsWith(".js") || file.path.endsWith(".ts")
|
|
22
27
|
// runes in .svelte.[j|t]s
|
|
23
|
-
? compileModule(strip(text), { generate: "client" })
|
|
24
|
-
: compile(text, { accessors, generate: "client" });
|
|
28
|
+
? compileModule(strip(text), { generate: "client", ...options })
|
|
29
|
+
: compile(text, { accessors, generate: "client", ...options });
|
|
25
30
|
return { css: css?.code ?? "", js: js.code };
|
|
26
31
|
},
|
|
27
32
|
server: (text, file) => {
|
|
28
33
|
const { js } = file?.path.endsWith(".js") || file?.path.endsWith(".ts")
|
|
29
34
|
// runes in .svelte.[j|t]s
|
|
30
|
-
? compileModule(strip(text), { generate: "server" })
|
|
31
|
-
: compile(text, { generate: "server" });
|
|
35
|
+
? compileModule(strip(text), { generate: "server", ...options })
|
|
36
|
+
: compile(text, { generate: "server", ...options });
|
|
32
37
|
return js.code;
|
|
33
38
|
},
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { render } from "svelte/server";
|
|
2
|
+
const module = {
|
|
3
|
+
name: "svelte",
|
|
4
|
+
extensions: [".svelte.js", ".svelte.ts", ".svelte"],
|
|
5
|
+
layouts: true,
|
|
6
|
+
client: true,
|
|
7
|
+
async render(view, props) {
|
|
8
|
+
const { body, head } = await render(view, { props: { p: { ...props } } });
|
|
9
|
+
return { body, head };
|
|
10
|
+
},
|
|
11
|
+
conditions: ["svelte"],
|
|
12
|
+
};
|
|
13
|
+
export default module;
|
|
14
|
+
//# 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/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",
|
|
@@ -16,37 +16,41 @@
|
|
|
16
16
|
"/lib/**/*.d.ts",
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
|
+
"types": "lib/index.d.ts",
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"@rcompat/fs": "^0.
|
|
21
|
-
"esbuild": "^0.
|
|
22
|
-
"@primate/core": "^0.
|
|
21
|
+
"@rcompat/fs": "^0.33.2",
|
|
22
|
+
"esbuild": "^0.28.0",
|
|
23
|
+
"@primate/core": "^0.7.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@rcompat/type": "^0.
|
|
26
|
+
"@rcompat/type": "^0.17.0"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"svelte": "5",
|
|
29
|
-
"primate": "^0.
|
|
30
|
+
"primate": "^0.38.0"
|
|
30
31
|
},
|
|
31
32
|
"imports": {
|
|
32
33
|
"#*": {
|
|
33
|
-
"
|
|
34
|
+
"@primate/source": "./src/private/*.ts",
|
|
34
35
|
"default": "./lib/private/*.js"
|
|
35
36
|
}
|
|
36
37
|
},
|
|
37
38
|
"exports": {
|
|
38
39
|
".": {
|
|
40
|
+
"types": "./lib/index.d.ts",
|
|
41
|
+
"@primate/runtime": "./src/public/runtime.ts",
|
|
42
|
+
"@primate/source": "./src/public/default.ts",
|
|
39
43
|
"browser": "./lib/public/browser.js",
|
|
40
44
|
"runtime": "./lib/public/runtime.js",
|
|
41
45
|
"default": "./lib/public/default.js"
|
|
42
46
|
},
|
|
43
47
|
"./*": {
|
|
44
|
-
"
|
|
48
|
+
"@primate/source": "./src/public/*.ts",
|
|
45
49
|
"default": "./lib/public/*.js"
|
|
46
50
|
}
|
|
47
51
|
},
|
|
48
52
|
"scripts": {
|
|
49
|
-
"build": "npm run clean && tsc",
|
|
53
|
+
"build": "npm run clean && tsc && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
|
|
50
54
|
"clean": "rm -rf ./lib",
|
|
51
55
|
"lint": "eslint ."
|
|
52
56
|
}
|
package/lib/private/Default.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
import type { FileRef } from "@rcompat/fs";
|
|
3
|
-
export default class Default extends Runtime {
|
|
4
|
-
root: {
|
|
5
|
-
create: (depth: number, i18n_active: boolean) => string;
|
|
6
|
-
};
|
|
7
|
-
css: {
|
|
8
|
-
filter: RegExp;
|
|
9
|
-
};
|
|
10
|
-
compile: {
|
|
11
|
-
client: (text: string, file: FileRef) => {
|
|
12
|
-
css: string;
|
|
13
|
-
js: string;
|
|
14
|
-
};
|
|
15
|
-
server: (text: string, file?: FileRef) => string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=Default.d.ts.map
|
package/lib/private/Runtime.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
-
import type Render from "@primate/core/frontend/Render";
|
|
3
|
-
import type { Component } from "svelte";
|
|
4
|
-
export default class Runtime extends FrontendModule<Component> {
|
|
5
|
-
name: string;
|
|
6
|
-
defaultExtensions: string[];
|
|
7
|
-
layouts: boolean;
|
|
8
|
-
client: boolean;
|
|
9
|
-
render: Render<Component>;
|
|
10
|
-
conditions: string[];
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=Runtime.d.ts.map
|
package/lib/private/Runtime.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
-
import { render } from "svelte/server";
|
|
3
|
-
export default class Runtime extends FrontendModule {
|
|
4
|
-
name = "svelte";
|
|
5
|
-
defaultExtensions = [".svelte.js", ".svelte.ts", ".svelte"];
|
|
6
|
-
layouts = true;
|
|
7
|
-
client = true;
|
|
8
|
-
render = (view, props) => {
|
|
9
|
-
const { head, html } = render(view, { props: { p: { ...props } } });
|
|
10
|
-
return { body: html, head };
|
|
11
|
-
};
|
|
12
|
-
conditions = ["svelte"];
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=Runtime.js.map
|