@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 CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./app.d.ts";
2
-
3
- export { default } from "./public/default";
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.spa) {
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(init) {
4
- const { initial, ...form_init } = init ?? {};
5
- const controller = client.createForm(form_init);
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((snapshot) => {
43
+ controller.subscribe(snapshot => {
33
44
  set(make_view({
34
45
  ...snapshot,
35
46
  submit: controller.submit,
@@ -1,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -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
  },
@@ -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 { head, html } = render(view, { props: { p: { ...props } } });
9
- return { body: html, head };
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
  };
@@ -1,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.js.map
@@ -1,2 +1,3 @@
1
+ export { default as client } from "#client/index";
1
2
  export { default } from "#runtime";
2
3
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,2 +1,3 @@
1
+ export { default as client } from "#client/index";
1
2
  export { default } from "#runtime";
2
3
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.23.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.6.0"
23
+ "@primate/core": "^0.7.0"
23
24
  },
24
25
  "devDependencies": {
25
- "@rcompat/type": "^0.11.1",
26
- "@primate/test": "^0.0.0"
26
+ "@rcompat/type": "^0.17.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "svelte": "5",
30
- "primate": "^0.37.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
  }
@@ -1,2 +0,0 @@
1
- export { default } from "#client/index";
2
- //# sourceMappingURL=client.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/index";
2
- //# sourceMappingURL=client.js.map