@primate/svelte 0.21.4 → 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.
- package/lib/private/Default.d.ts +1 -1
- package/lib/private/client/{index.d.ts → app.d.ts} +3 -3
- package/lib/private/client/{index.js → app.js} +2 -2
- package/lib/private/client/field.d.ts +34 -0
- package/lib/private/client/field.js +32 -0
- package/lib/private/client/form.d.ts +22 -0
- package/lib/private/client/form.js +40 -0
- package/lib/public/browser.d.ts +1 -1
- package/lib/public/browser.js +1 -1
- package/lib/public/client.d.ts +52 -0
- package/lib/public/client.js +5 -0
- package/package.json +15 -12
- package/lib/private/client/ValidateState.d.ts +0 -8
- package/lib/private/client/ValidateState.js +0 -2
- package/lib/private/client/Validated.d.ts +0 -8
- package/lib/private/client/Validated.js +0 -2
- package/lib/private/client/validate.d.ts +0 -25
- package/lib/private/client/validate.js +0 -28
- package/lib/public/Validated.d.ts +0 -2
- package/lib/public/Validated.js +0 -2
- package/lib/public/validate.d.ts +0 -2
- package/lib/public/validate.js +0 -2
package/lib/private/Default.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type ClientData from "@primate/core/client/Data";
|
|
2
|
-
import type Dict from "@rcompat/type
|
|
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
|
|
7
|
+
export default class SvelteApp {
|
|
8
8
|
static mount(_view: string, data: ClientData<Data>): void;
|
|
9
9
|
}
|
|
10
10
|
export {};
|
|
11
|
-
//# sourceMappingURL=
|
|
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
|
|
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=
|
|
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
|
package/lib/public/browser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#client/
|
|
1
|
+
export { default } from "#client/app";
|
|
2
2
|
//# sourceMappingURL=browser.d.ts.map
|
package/lib/public/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#client/
|
|
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
|
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
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.
|
|
20
|
-
"esbuild": "^0.27.
|
|
21
|
-
"@primate/core": "^0.
|
|
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"
|
|
22
26
|
},
|
|
23
27
|
"peerDependencies": {
|
|
24
28
|
"svelte": "5",
|
|
25
|
-
"primate": "^0.
|
|
29
|
+
"primate": "^0.36.0"
|
|
26
30
|
},
|
|
27
|
-
"type": "module",
|
|
28
31
|
"imports": {
|
|
29
32
|
"#*": {
|
|
30
33
|
"apekit": "./src/private/*.ts",
|
|
@@ -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,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
|
package/lib/public/Validated.js
DELETED
package/lib/public/validate.d.ts
DELETED
package/lib/public/validate.js
DELETED