@primate/angular 0.5.0 → 0.6.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/INITIAL_PROPS.d.ts +1 -1
- package/lib/private/client/Validated.d.ts +2 -3
- 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 +25 -0
- package/lib/private/client/{validate.js → field.js} +5 -5
- package/lib/private/client/form.d.ts +23 -0
- package/lib/private/client/form.js +47 -0
- package/lib/public/browser.d.ts +1 -1
- package/lib/public/browser.js +1 -1
- package/lib/public/client.d.ts +30 -0
- package/lib/public/client.js +5 -0
- package/package.json +20 -22
- package/lib/private/client/validate.d.ts +0 -25
- 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
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type ValidateUpdater from "@primate/core/client
|
|
3
|
-
import type ValidationError from "@primate/core/client/ValidationError";
|
|
1
|
+
import type { Signal } from "@angular/core";
|
|
2
|
+
import type { ValidateUpdater, ValidationError } from "@primate/core/client";
|
|
4
3
|
type Validated<T> = {
|
|
5
4
|
error: Signal<null | ValidationError>;
|
|
6
5
|
loading: Signal<boolean>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import "@angular/compiler";
|
|
2
2
|
import type ClientData from "@primate/core/client/Data";
|
|
3
3
|
import type Mode from "@primate/core/Mode";
|
|
4
|
-
import type Dict from "@rcompat/type
|
|
4
|
+
import type { Dict } from "@rcompat/type";
|
|
5
5
|
type Data = ClientData<{
|
|
6
6
|
views: string[];
|
|
7
7
|
props: Dict[];
|
|
8
8
|
mode: Mode;
|
|
9
9
|
}>;
|
|
10
|
-
export default class
|
|
10
|
+
export default class AngularApp {
|
|
11
11
|
#private;
|
|
12
12
|
static mount(_view: string, data: ClientData<Data>): Promise<void>;
|
|
13
13
|
}
|
|
14
14
|
export {};
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -14,7 +14,7 @@ const make_props = (data) => ({
|
|
|
14
14
|
},
|
|
15
15
|
update: () => undefined,
|
|
16
16
|
});
|
|
17
|
-
export default class
|
|
17
|
+
export default class AngularApp {
|
|
18
18
|
static #app;
|
|
19
19
|
static #root;
|
|
20
20
|
static async mount(_view, data) {
|
|
@@ -66,4 +66,4 @@ export default class AngularClient {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=
|
|
69
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type Validated from "#client/Validated";
|
|
2
|
+
declare const field: <T>(initial: T) => {
|
|
3
|
+
delete: (url: string, options?: {
|
|
4
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
5
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
6
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
7
|
+
} | undefined) => Validated<T>;
|
|
8
|
+
patch: (url: string, options?: {
|
|
9
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
10
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
11
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
12
|
+
} | undefined) => Validated<T>;
|
|
13
|
+
post: (url: string, options?: {
|
|
14
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
15
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
16
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
17
|
+
} | undefined) => Validated<T>;
|
|
18
|
+
put: (url: string, options?: {
|
|
19
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
20
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
21
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
22
|
+
} | undefined) => Validated<T>;
|
|
23
|
+
};
|
|
24
|
+
export default field;
|
|
25
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { signal } from "@angular/core";
|
|
2
|
-
import
|
|
3
|
-
import validate from "@primate/core/client/validate";
|
|
2
|
+
import client from "@primate/core/client";
|
|
4
3
|
function useValidate(init) {
|
|
5
4
|
const value = signal(init.initial);
|
|
6
5
|
const loading = signal(false);
|
|
@@ -12,7 +11,7 @@ function useValidate(init) {
|
|
|
12
11
|
loading.set(true);
|
|
13
12
|
error.set(null);
|
|
14
13
|
try {
|
|
15
|
-
await
|
|
14
|
+
await client.validateField(init, next);
|
|
16
15
|
}
|
|
17
16
|
catch (e) {
|
|
18
17
|
// rollback
|
|
@@ -25,5 +24,6 @@ function useValidate(init) {
|
|
|
25
24
|
}
|
|
26
25
|
return { error, loading, update, value };
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const field = client.toValidated(useValidate);
|
|
28
|
+
export default field;
|
|
29
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Signal } from "@angular/core";
|
|
2
|
+
import { type FormInit } from "@primate/core/client";
|
|
3
|
+
import type { Dict } from "@rcompat/type";
|
|
4
|
+
type Field<T> = {
|
|
5
|
+
name: string;
|
|
6
|
+
value: T;
|
|
7
|
+
errors: Signal<readonly string[]>;
|
|
8
|
+
error: Signal<string | null>;
|
|
9
|
+
};
|
|
10
|
+
type FormView<Values extends Dict> = {
|
|
11
|
+
id: string;
|
|
12
|
+
submitting: Signal<boolean>;
|
|
13
|
+
submit: (event?: Event) => Promise<void>;
|
|
14
|
+
errors: Signal<readonly string[]>;
|
|
15
|
+
field: <K extends keyof Values & string>(name: K) => Field<Values[K]>;
|
|
16
|
+
};
|
|
17
|
+
type Initial<Values extends Dict> = FormInit & {
|
|
18
|
+
initial?: Values;
|
|
19
|
+
};
|
|
20
|
+
declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
|
|
21
|
+
declare function form(init?: FormInit): FormView<Dict>;
|
|
22
|
+
export default form;
|
|
23
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DestroyRef, computed, inject, signal, } from "@angular/core";
|
|
2
|
+
import core from "@primate/core/client";
|
|
3
|
+
function try_destroy_ref() {
|
|
4
|
+
try {
|
|
5
|
+
return inject(DestroyRef);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function form(init) {
|
|
12
|
+
const { initial, ...form_init } = init ?? {};
|
|
13
|
+
const controller = core.createForm(form_init);
|
|
14
|
+
const values = initial ?? {};
|
|
15
|
+
const snap = signal(controller.read());
|
|
16
|
+
const unsub = controller.subscribe((next) => snap.set(next));
|
|
17
|
+
try_destroy_ref()?.onDestroy(unsub);
|
|
18
|
+
const submitting = computed(() => snap().submitting);
|
|
19
|
+
const errors = computed(() => snap().errors.form);
|
|
20
|
+
// cache per-field views so templates calling field("x") repeatedly
|
|
21
|
+
// don't recreate computed signals every change detection cycle
|
|
22
|
+
const cache = new Map();
|
|
23
|
+
function field(name) {
|
|
24
|
+
const key = name;
|
|
25
|
+
const cached = cache.get(key);
|
|
26
|
+
if (cached)
|
|
27
|
+
return cached;
|
|
28
|
+
const form_errors = computed(() => snap().errors.fields[key] ?? []);
|
|
29
|
+
const view = {
|
|
30
|
+
name: key,
|
|
31
|
+
value: values[name],
|
|
32
|
+
errors: form_errors,
|
|
33
|
+
error: computed(() => form_errors()[0] ?? null),
|
|
34
|
+
};
|
|
35
|
+
cache.set(key, view);
|
|
36
|
+
return view;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
id: controller.id,
|
|
40
|
+
submitting,
|
|
41
|
+
submit: (event) => controller.submit(event),
|
|
42
|
+
errors,
|
|
43
|
+
field,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export default form;
|
|
47
|
+
//# 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,30 @@
|
|
|
1
|
+
import type Validated from "#client/Validated";
|
|
2
|
+
import form from "#client/form";
|
|
3
|
+
declare const client: {
|
|
4
|
+
form: typeof form;
|
|
5
|
+
field: <T>(initial: T) => {
|
|
6
|
+
delete: (url: string, options?: {
|
|
7
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
8
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
9
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
10
|
+
} | undefined) => Validated<T>;
|
|
11
|
+
patch: (url: string, options?: {
|
|
12
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
13
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
14
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
15
|
+
} | undefined) => Validated<T>;
|
|
16
|
+
post: (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) => Validated<T>;
|
|
21
|
+
put: (url: string, options?: {
|
|
22
|
+
headers?: import("@rcompat/type").Dict<string>;
|
|
23
|
+
map?: ((v: T) => import("@rcompat/type").JSONValue) | undefined;
|
|
24
|
+
path?: import("@rcompat/type").JSONPointer;
|
|
25
|
+
} | undefined) => Validated<T>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export default client;
|
|
29
|
+
export type { Validated };
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/angular",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Angular for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/angular",
|
|
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/angular"
|
|
17
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"/lib/**/*.js",
|
|
16
|
+
"/lib/**/*.d.ts",
|
|
17
|
+
"!/**/*.spec.*"
|
|
18
|
+
],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@angular/common": "^21.
|
|
20
|
-
"@angular/compiler": "^21.
|
|
21
|
-
"@angular/core": "^21.
|
|
22
|
-
"@angular/platform-browser": "^21.
|
|
23
|
-
"@angular/platform-server": "^21.
|
|
24
|
-
"@angular/ssr": "^21.
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"@rcompat/
|
|
30
|
-
"typescript": "^5.9.2",
|
|
31
|
-
"@primate/core": "^0.4.0"
|
|
20
|
+
"@angular/common": "^21.1.4",
|
|
21
|
+
"@angular/compiler": "^21.1.4",
|
|
22
|
+
"@angular/core": "^21.1.4",
|
|
23
|
+
"@angular/platform-browser": "^21.1.4",
|
|
24
|
+
"@angular/platform-server": "^21.1.4",
|
|
25
|
+
"@angular/ssr": "^21.1.4",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"@primate/core": "^0.5.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@rcompat/type": "^0.9.0"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
34
|
-
"primate": "^0.
|
|
33
|
+
"primate": "^0.36.0"
|
|
35
34
|
},
|
|
36
|
-
"type": "module",
|
|
37
35
|
"imports": {
|
|
38
36
|
"#*": {
|
|
39
37
|
"apekit": "./src/private/*.ts",
|
|
@@ -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
|
package/lib/public/Validated.js
DELETED
package/lib/public/validate.d.ts
DELETED
package/lib/public/validate.js
DELETED