@primate/svelte 0.21.3 → 0.22.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.
@@ -1,5 +1,5 @@
1
1
  import Runtime from "#Runtime";
2
- import type FileRef from "@rcompat/fs/FileRef";
2
+ import type { FileRef } from "@rcompat/fs";
3
3
  export default class Default extends Runtime {
4
4
  root: {
5
5
  create: (depth: number, i18n_active: boolean) => string;
@@ -1,6 +1,13 @@
1
1
  import create_root from "#create-root";
2
2
  import Runtime from "#Runtime";
3
+ import esbuild from "esbuild";
3
4
  import { compile, compileModule } from "svelte/compiler";
5
+ const strip = (code) => {
6
+ return esbuild.transformSync(code, {
7
+ loader: "ts",
8
+ format: "esm",
9
+ }).code;
10
+ };
4
11
  export default class Default extends Runtime {
5
12
  root = {
6
13
  create: create_root,
@@ -13,14 +20,14 @@ export default class Default extends Runtime {
13
20
  const accessors = true;
14
21
  const { css, js } = file.path.endsWith(".js") || file.path.endsWith(".ts")
15
22
  // runes in .svelte.[j|t]s
16
- ? compileModule(text, { generate: "client" })
23
+ ? compileModule(strip(text), { generate: "client" })
17
24
  : compile(text, { accessors, generate: "client" });
18
25
  return { css: css?.code ?? "", js: js.code };
19
26
  },
20
27
  server: (text, file) => {
21
28
  const { js } = file?.path.endsWith(".js") || file?.path.endsWith(".ts")
22
29
  // runes in .svelte.[j|t]s
23
- ? compileModule(text, { generate: "server" })
30
+ ? compileModule(strip(text), { generate: "server" })
24
31
  : compile(text, { generate: "server" });
25
32
  return js.code;
26
33
  },
@@ -1,11 +1,11 @@
1
1
  import type ClientData from "@primate/core/client/Data";
2
- import type Dict from "@rcompat/type/Dict";
2
+ import type { Dict } from "@rcompat/type";
3
3
  type Data = ClientData<{
4
4
  views: string[];
5
5
  props: Dict[];
6
6
  }>;
7
- export default class SvelteClient {
7
+ export default class SvelteApp {
8
8
  static mount(_view: string, data: ClientData<Data>): void;
9
9
  }
10
10
  export {};
11
- //# sourceMappingURL=index.d.ts.map
11
+ //# sourceMappingURL=app.d.ts.map
@@ -11,7 +11,7 @@ const make_props = (data) => ({
11
11
  },
12
12
  update: () => undefined,
13
13
  });
14
- export default class SvelteClient {
14
+ export default class SvelteApp {
15
15
  static mount(_view, data) {
16
16
  const _root = (data.ssr ? hydrate : mount)(root, {
17
17
  props: {
@@ -24,4 +24,4 @@ export default class SvelteClient {
24
24
  }));
25
25
  }
26
26
  }
27
- //# sourceMappingURL=index.js.map
27
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,34 @@
1
+ import { type ValidateUpdater, type ValidationError } from "@primate/core/client";
2
+ import { type Readable } from "svelte/store";
3
+ type ValidateState<T> = {
4
+ error: null | ValidationError;
5
+ loading: boolean;
6
+ value: T;
7
+ };
8
+ type Validated<T> = {
9
+ update: (updater: ValidateUpdater<T>) => Promise<void>;
10
+ } & Readable<ValidateState<T>>;
11
+ declare const field: <T>(initial: T) => {
12
+ delete: (url: string, options?: {
13
+ headers?: import("@rcompat/type").Dict<string>;
14
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
15
+ path?: import("@rcompat/type").JSONPointer;
16
+ } | undefined) => Validated<T>;
17
+ patch: (url: string, options?: {
18
+ headers?: import("@rcompat/type").Dict<string>;
19
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
20
+ path?: import("@rcompat/type").JSONPointer;
21
+ } | undefined) => Validated<T>;
22
+ post: (url: string, options?: {
23
+ headers?: import("@rcompat/type").Dict<string>;
24
+ map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
25
+ path?: import("@rcompat/type").JSONPointer;
26
+ } | undefined) => Validated<T>;
27
+ put: (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) => Validated<T>;
32
+ };
33
+ export default field;
34
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1,32 @@
1
+ import client from "@primate/core/client";
2
+ import { writable } from "svelte/store";
3
+ function useValidate(init) {
4
+ let current = init.initial;
5
+ const { set, subscribe, update } = writable({
6
+ error: null,
7
+ loading: false,
8
+ value: current,
9
+ });
10
+ async function $update(updater) {
11
+ let previous;
12
+ update((s) => {
13
+ previous = s.value;
14
+ const next_value = updater(s.value);
15
+ current = next_value;
16
+ return { ...s, error: null, loading: true, value: next_value };
17
+ });
18
+ try {
19
+ await client.validateField(init, current);
20
+ update((s) => ({ ...s, loading: false }));
21
+ }
22
+ catch (e) {
23
+ // rollback
24
+ current = previous;
25
+ set({ error: e, loading: false, value: previous });
26
+ }
27
+ }
28
+ return { subscribe, update: $update };
29
+ }
30
+ const field = client.toValidated(useValidate);
31
+ export default field;
32
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1,22 @@
1
+ import { type FormInit } from "@primate/core/client";
2
+ import type { Dict } from "@rcompat/type";
3
+ import { type Readable } from "svelte/store";
4
+ type SvelteFormView<Values extends Dict> = {
5
+ id: string;
6
+ submitting: boolean;
7
+ submit: (event?: Event) => Promise<void>;
8
+ errors: readonly string[];
9
+ field: <K extends keyof Values & string>(name: K) => {
10
+ name: string;
11
+ value: Values[K];
12
+ error: string | null;
13
+ errors: readonly string[];
14
+ };
15
+ };
16
+ type Initial<Values extends Dict> = FormInit & {
17
+ initial?: Values;
18
+ };
19
+ declare function form<Values extends Dict>(init: Initial<Values>): Readable<SvelteFormView<Values>>;
20
+ declare function form(init?: FormInit): Readable<SvelteFormView<Dict>>;
21
+ export default form;
22
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1,40 @@
1
+ import client from "@primate/core/client";
2
+ import { writable } from "svelte/store";
3
+ function form(init) {
4
+ const { initial, ...form_init } = init ?? {};
5
+ const controller = client.createForm(form_init);
6
+ const values = initial ?? {};
7
+ const make_view = (snapshot) => {
8
+ const form_errors = snapshot.errors.form;
9
+ return {
10
+ id: snapshot.id,
11
+ submitting: snapshot.submitting,
12
+ submit: controller.submit,
13
+ errors: form_errors,
14
+ field(name) {
15
+ const key = name;
16
+ const errors = snapshot.errors.fields[key] ?? [];
17
+ return {
18
+ name: key,
19
+ value: values[name],
20
+ error: errors[0] ?? null,
21
+ errors,
22
+ };
23
+ },
24
+ };
25
+ };
26
+ const initial_view = make_view({
27
+ ...controller.read(),
28
+ submit: controller.submit,
29
+ });
30
+ const { subscribe, set } = writable(initial_view);
31
+ controller.subscribe((snapshot) => {
32
+ set(make_view({
33
+ ...snapshot,
34
+ submit: controller.submit,
35
+ }));
36
+ });
37
+ return { subscribe };
38
+ }
39
+ export default form;
40
+ //# sourceMappingURL=form.js.map
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.js.map
@@ -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=client.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=client.js.map
package/package.json CHANGED
@@ -1,29 +1,33 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.21.3",
4
- "description": "Primate Svelte frontend",
3
+ "version": "0.22.0",
4
+ "description": "Svelte for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/svelte",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
7
+ "type": "module",
7
8
  "license": "MIT",
8
- "files": [
9
- "/lib/**/*.js",
10
- "/lib/**/*.d.ts",
11
- "!/**/*.spec.*"
12
- ],
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/primate-run/primate",
16
12
  "directory": "packages/svelte"
17
13
  },
14
+ "files": [
15
+ "/lib/**/*.js",
16
+ "/lib/**/*.d.ts",
17
+ "!/**/*.spec.*"
18
+ ],
18
19
  "dependencies": {
19
- "@rcompat/fs": "^0.22.3",
20
- "@primate/core": "^0.4.5"
20
+ "@rcompat/fs": "^0.25.2",
21
+ "esbuild": "^0.27.3",
22
+ "@primate/core": "^0.5.0"
23
+ },
24
+ "devDependencies": {
25
+ "@rcompat/type": "^0.9.0"
21
26
  },
22
27
  "peerDependencies": {
23
28
  "svelte": "5",
24
- "primate": "^0.35.1"
29
+ "primate": "^0.36.0"
25
30
  },
26
- "type": "module",
27
31
  "imports": {
28
32
  "#*": {
29
33
  "apekit": "./src/private/*.ts",
@@ -1,8 +0,0 @@
1
- import type ValidationError from "@primate/core/client/ValidationError";
2
- type ValidateState<T> = {
3
- error: null | ValidationError;
4
- loading: boolean;
5
- value: T;
6
- };
7
- export type { ValidateState as default };
8
- //# sourceMappingURL=ValidateState.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ValidateState.js.map
@@ -1,8 +0,0 @@
1
- import type ValidateState from "#client/ValidateState";
2
- import type ValidateUpdater from "@primate/core/client/ValidateUpdater";
3
- import type { Readable } from "svelte/store";
4
- type Validated<T> = {
5
- update: (updater: ValidateUpdater<T>) => Promise<void>;
6
- } & Readable<ValidateState<T>>;
7
- export type { Validated as default };
8
- //# sourceMappingURL=Validated.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Validated.js.map
@@ -1,25 +0,0 @@
1
- import type Validated from "#client/Validated";
2
- declare const _default: <T>(initial: T) => {
3
- delete: (url: string, options?: {
4
- headers?: import("@rcompat/type/Dict").default<string>;
5
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
6
- path?: import("@rcompat/type/JSONPointer").default;
7
- } | undefined) => Validated<T>;
8
- patch: (url: string, options?: {
9
- headers?: import("@rcompat/type/Dict").default<string>;
10
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
11
- path?: import("@rcompat/type/JSONPointer").default;
12
- } | undefined) => Validated<T>;
13
- post: (url: string, options?: {
14
- headers?: import("@rcompat/type/Dict").default<string>;
15
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
16
- path?: import("@rcompat/type/JSONPointer").default;
17
- } | undefined) => Validated<T>;
18
- put: (url: string, options?: {
19
- headers?: import("@rcompat/type/Dict").default<string>;
20
- map?: ((v: T) => import("@rcompat/type/JSONValue").default) | undefined;
21
- path?: import("@rcompat/type/JSONPointer").default;
22
- } | undefined) => Validated<T>;
23
- };
24
- export default _default;
25
- //# sourceMappingURL=validate.d.ts.map
@@ -1,28 +0,0 @@
1
- import toValidated from "@primate/core/client/toValidated";
2
- import validate from "@primate/core/client/validate";
3
- import { get, writable } from "svelte/store";
4
- function useValidate(init) {
5
- const { set, subscribe, update } = writable({
6
- error: null,
7
- loading: false,
8
- value: init.initial,
9
- });
10
- async function $update(updater) {
11
- let previous;
12
- update((s) => {
13
- previous = s.value;
14
- return { ...s, error: null, loading: true, value: updater(s.value) };
15
- });
16
- try {
17
- await validate(init, get({ subscribe }).value);
18
- update(s => ({ ...s, loading: false }));
19
- }
20
- catch (e) {
21
- // rollback
22
- set({ error: e, loading: false, value: previous });
23
- }
24
- }
25
- return { subscribe, update: $update };
26
- }
27
- export default toValidated(useValidate);
28
- //# sourceMappingURL=validate.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/Validated";
2
- //# sourceMappingURL=Validated.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Validated.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/validate";
2
- //# sourceMappingURL=validate.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/validate";
2
- //# sourceMappingURL=validate.js.map