@primate/svelte 0.22.0 → 0.23.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 ADDED
@@ -0,0 +1,5 @@
1
+ declare module "app:svelte" {
2
+ import type { RequestPublic } from "@primate/core";
3
+ import type { Writable } from "svelte/store";
4
+ export const request: Writable<RequestPublic>;
5
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import "./app.d.ts";
2
+
3
+ export { default } from "./public/default";
@@ -0,0 +1,5 @@
1
+ import type Payload from "#client/Payload";
2
+ import type { Data } from "@primate/core/client";
3
+ type SvelteData = Data<Payload>;
4
+ export type { SvelteData as default };
5
+ //# sourceMappingURL=Data.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Data.js.map
@@ -0,0 +1,7 @@
1
+ import type { Dict } from "@rcompat/type";
2
+ type Payload = {
3
+ views: string[];
4
+ props: Dict[];
5
+ };
6
+ export type { Payload as default };
7
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Payload.js.map
@@ -1,11 +1,5 @@
1
- import type ClientData from "@primate/core/client/Data";
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: ClientData<Data>): void;
3
+ static mount(_view: string, data: Data): void;
9
4
  }
10
- export {};
11
5
  //# sourceMappingURL=app.d.ts.map
@@ -1,27 +1,23 @@
1
- import spa from "@primate/core/client/spa";
2
- import { hydrate, mount } from "svelte";
3
- import root from "svelte:root";
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 _root = (data.ssr ? hydrate : mount)(root, {
17
- props: {
18
- p: make_props(data),
19
- },
6
+ const Root = root[data.ssr ? "ssr" : "csr"](RootView, {
7
+ props: { p: root.toProps(data) },
20
8
  target: document.body,
21
9
  });
22
- data.spa && window.addEventListener("DOMContentLoaded", () => spa((_data, update) => {
23
- _root.p = { ...make_props(_data), update };
24
- }));
10
+ if (data.spa) {
11
+ const start = () => client.boot((_data, update) => {
12
+ Root.p = { ...root.toProps(_data), update };
13
+ });
14
+ if (document.readyState === "loading") {
15
+ window.addEventListener("DOMContentLoaded", start, { once: true });
16
+ }
17
+ else {
18
+ start();
19
+ }
20
+ }
25
21
  }
26
22
  }
27
23
  //# sourceMappingURL=app.js.map
@@ -1,9 +1,10 @@
1
- import { type FormInit } from "@primate/core/client";
1
+ import type { FormInit } from "@primate/core/client";
2
2
  import type { Dict } from "@rcompat/type";
3
- import { type Readable } from "svelte/store";
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) => {
@@ -9,6 +9,7 @@ function form(init) {
9
9
  return {
10
10
  id: snapshot.id,
11
11
  submitting: snapshot.submitting,
12
+ submitted: snapshot.submitted,
12
13
  submit: controller.submit,
13
14
  errors: form_errors,
14
15
  field(name) {
@@ -0,0 +1,52 @@
1
+ import form from "#client/form";
2
+ declare const client: {
3
+ form: typeof form;
4
+ field: <T>(initial: T) => {
5
+ delete: (url: string, options?: {
6
+ headers?: import("@rcompat/type").Dict<string>;
7
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
8
+ path?: import("@rcompat/type").JSONPointer;
9
+ } | undefined) => {
10
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
11
+ } & import("svelte/store").Readable<{
12
+ error: null | import("@primate/core/client").ValidationError;
13
+ loading: boolean;
14
+ value: T;
15
+ }>;
16
+ patch: (url: string, options?: {
17
+ headers?: import("@rcompat/type").Dict<string>;
18
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
19
+ path?: import("@rcompat/type").JSONPointer;
20
+ } | undefined) => {
21
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
22
+ } & import("svelte/store").Readable<{
23
+ error: null | import("@primate/core/client").ValidationError;
24
+ loading: boolean;
25
+ value: T;
26
+ }>;
27
+ post: (url: string, options?: {
28
+ headers?: import("@rcompat/type").Dict<string>;
29
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
30
+ path?: import("@rcompat/type").JSONPointer;
31
+ } | undefined) => {
32
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
33
+ } & import("svelte/store").Readable<{
34
+ error: null | import("@primate/core/client").ValidationError;
35
+ loading: boolean;
36
+ value: T;
37
+ }>;
38
+ put: (url: string, options?: {
39
+ headers?: import("@rcompat/type").Dict<string>;
40
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
41
+ path?: import("@rcompat/type").JSONPointer;
42
+ } | undefined) => {
43
+ update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
44
+ } & import("svelte/store").Readable<{
45
+ error: null | import("@primate/core/client").ValidationError;
46
+ loading: boolean;
47
+ value: T;
48
+ }>;
49
+ };
50
+ };
51
+ export default client;
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import form from "#client/form";
2
+ import field from "#client/field";
3
+ const client = { form, field };
4
+ export default client;
5
+ //# sourceMappingURL=index.js.map
@@ -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}]} request={p.request} {...p.props[${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}]} request={p.request} {...p.props[${i}]}/>
10
+ <svelte:component this={p.views[${i}]} {...p.props[${i}]}/>
11
11
  {/if}
12
- `, `<svelte:component this={p.views[${n}]} request={p.request} {...p.props[${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>
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ spa?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=default.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import create_root from "#create-root";
2
- import Runtime from "#Runtime";
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,14 +9,15 @@ const strip = (code) => {
8
9
  format: "esm",
9
10
  }).code;
10
11
  };
11
- export default class Default extends Runtime {
12
- root = {
12
+ export default frontend({
13
+ ...init,
14
+ root: {
13
15
  create: create_root,
14
- };
15
- css = {
16
+ },
17
+ css: {
16
18
  filter: /\.sveltecss$/,
17
- };
18
- compile = {
19
+ },
20
+ compile: {
19
21
  client: (text, file) => {
20
22
  const accessors = true;
21
23
  const { css, js } = file.path.endsWith(".js") || file.path.endsWith(".ts")
@@ -31,6 +33,6 @@ export default class Default extends Runtime {
31
33
  : compile(text, { generate: "server" });
32
34
  return js.code;
33
35
  },
34
- };
35
- }
36
- //# sourceMappingURL=Default.js.map
36
+ },
37
+ });
38
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1,5 @@
1
+ import type { Init } from "@primate/core/frontend";
2
+ import type { Component } from "svelte";
3
+ declare const module: Init<Component>;
4
+ export default module;
5
+ //# sourceMappingURL=init.d.ts.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
+ render(view, props) {
8
+ const { head, html } = render(view, { props: { p: { ...props } } });
9
+ return { body: html, head };
10
+ },
11
+ conditions: ["svelte"],
12
+ };
13
+ export default module;
14
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,4 @@
1
+ import type { RequestPublic } from "@primate/core";
2
+ declare const _default: import("svelte/store").Writable<RequestPublic>;
3
+ export default _default;
4
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { writable } from "svelte/store";
2
+ export default writable();
3
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ spa?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,4 @@
1
+ import init from "#init";
2
+ import frontend from "@primate/core/frontend";
3
+ export default frontend(init);
4
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,2 @@
1
+ export { default as request } from "#request/store";
2
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default as request } from "#request/store";
2
+ //# sourceMappingURL=app.js.map
@@ -1,52 +1,2 @@
1
- import form from "#client/form";
2
- declare const client: {
3
- form: typeof form;
4
- field: <T>(initial: T) => {
5
- delete: (url: string, options?: {
6
- headers?: import("@rcompat/type").Dict<string>;
7
- map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
8
- path?: import("@rcompat/type").JSONPointer;
9
- } | undefined) => {
10
- update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
11
- } & import("svelte/store").Readable<{
12
- error: null | import("@primate/core/client").ValidationError;
13
- loading: boolean;
14
- value: T;
15
- }>;
16
- patch: (url: string, options?: {
17
- headers?: import("@rcompat/type").Dict<string>;
18
- map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
19
- path?: import("@rcompat/type").JSONPointer;
20
- } | undefined) => {
21
- update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
22
- } & import("svelte/store").Readable<{
23
- error: null | import("@primate/core/client").ValidationError;
24
- loading: boolean;
25
- value: T;
26
- }>;
27
- post: (url: string, options?: {
28
- headers?: import("@rcompat/type").Dict<string>;
29
- map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
30
- path?: import("@rcompat/type").JSONPointer;
31
- } | undefined) => {
32
- update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
33
- } & import("svelte/store").Readable<{
34
- error: null | import("@primate/core/client").ValidationError;
35
- loading: boolean;
36
- value: T;
37
- }>;
38
- put: (url: string, options?: {
39
- headers?: import("@rcompat/type").Dict<string>;
40
- map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
41
- path?: import("@rcompat/type").JSONPointer;
42
- } | undefined) => {
43
- update: (updater: import("@primate/core/client").ValidateUpdater<T>) => Promise<void>;
44
- } & import("svelte/store").Readable<{
45
- error: null | import("@primate/core/client").ValidationError;
46
- loading: boolean;
47
- value: T;
48
- }>;
49
- };
50
- };
51
- export default client;
1
+ export { default } from "#client/index";
52
2
  //# sourceMappingURL=client.d.ts.map
@@ -1,5 +1,2 @@
1
- import form from "#client/form";
2
- import field from "#client/field";
3
- const client = { form, field };
4
- export default client;
1
+ export { default } from "#client/index";
5
2
  //# sourceMappingURL=client.js.map
@@ -1,4 +1,2 @@
1
- import Default from "#Default";
2
- declare const _default: (options?: typeof Default.input) => Default;
3
- export default _default;
1
+ export { default } from "#default";
4
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,3 +1,2 @@
1
- import Default from "#Default";
2
- export default (options) => new Default(options);
1
+ export { default } from "#default";
3
2
  //# sourceMappingURL=default.js.map
@@ -1,4 +1,2 @@
1
- import Runtime from "#Runtime";
2
- declare const _default: (options?: typeof Runtime.input) => Runtime;
3
- export default _default;
1
+ export { default } from "#runtime";
4
2
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,3 +1,2 @@
1
- import Runtime from "#Runtime";
2
- export default (options) => new Runtime(options);
1
+ export { default } from "#runtime";
3
2
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.22.0",
3
+ "version": "0.23.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,38 +16,42 @@
16
16
  "/lib/**/*.d.ts",
17
17
  "!/**/*.spec.*"
18
18
  ],
19
+ "types": "lib/index.d.ts",
19
20
  "dependencies": {
20
- "@rcompat/fs": "^0.25.2",
21
- "esbuild": "^0.27.3",
22
- "@primate/core": "^0.5.0"
21
+ "esbuild": "^0.28.0",
22
+ "@primate/core": "^0.6.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@rcompat/type": "^0.9.0"
25
+ "@rcompat/type": "^0.11.1",
26
+ "@primate/test": "^0.0.0"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "svelte": "5",
29
- "primate": "^0.36.0"
30
+ "primate": "^0.37.0"
30
31
  },
31
32
  "imports": {
32
33
  "#*": {
33
- "apekit": "./src/private/*.ts",
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/source": "./src/public/default.ts",
39
42
  "browser": "./lib/public/browser.js",
40
43
  "runtime": "./lib/public/runtime.js",
41
44
  "default": "./lib/public/default.js"
42
45
  },
43
46
  "./*": {
44
- "apekit": "./src/public/*.ts",
47
+ "@primate/source": "./src/public/*.ts",
45
48
  "default": "./lib/public/*.js"
46
49
  }
47
50
  },
48
51
  "scripts": {
49
- "build": "npm run clean && tsc",
52
+ "build": "npm run clean && tsc && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
50
53
  "clean": "rm -rf ./lib",
51
- "lint": "eslint ."
54
+ "lint": "eslint .",
55
+ "test": "npx proby"
52
56
  }
53
57
  }
@@ -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
@@ -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
@@ -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