@primate/angular 0.7.0 → 0.8.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 +3 -1
- package/lib/private/client/app.js +4 -1
- package/lib/private/client/form.d.ts +4 -3
- package/lib/private/client/form.js +20 -10
- package/lib/private/default.d.ts +1 -1
- package/lib/private/init.js +1 -1
- package/lib/private/runtime.d.ts +1 -1
- package/lib/public/browser.d.ts +1 -0
- package/lib/public/browser.js +1 -0
- package/lib/public/runtime.d.ts +1 -0
- package/lib/public/runtime.js +1 -0
- package/package.json +13 -14
- package/lib/public/client.d.ts +0 -3
- package/lib/public/client.js +0 -2
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export default class AngularApp {
|
|
|
9
9
|
static #app;
|
|
10
10
|
static #root;
|
|
11
11
|
static async mount(_view, data) {
|
|
12
|
+
const interactive = !data.ssr || data.csr;
|
|
13
|
+
if (!interactive)
|
|
14
|
+
return;
|
|
12
15
|
if (data.mode === "production")
|
|
13
16
|
enableProdMode();
|
|
14
17
|
const providers = [];
|
|
@@ -30,7 +33,7 @@ export default class AngularApp {
|
|
|
30
33
|
this.#root = this.#app.components[0];
|
|
31
34
|
this.#root.instance.p = props;
|
|
32
35
|
this.#app.tick();
|
|
33
|
-
if (data.
|
|
36
|
+
if (data.csr) {
|
|
34
37
|
const start = () => client.boot((next, update) => {
|
|
35
38
|
this.#root.instance.p = root.toProps(next, update);
|
|
36
39
|
this.#app.tick();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Signal } from "@angular/core";
|
|
2
|
-
import type { FormInit } from "@primate/core/client";
|
|
2
|
+
import type { ClientMethod, FormInit } from "@primate/core/client";
|
|
3
3
|
import type { Dict } from "@rcompat/type";
|
|
4
4
|
type Field<T> = {
|
|
5
5
|
name: string;
|
|
6
6
|
value: T;
|
|
7
|
-
errors: Signal<
|
|
7
|
+
errors: Signal<string[]>;
|
|
8
8
|
error: Signal<string | null>;
|
|
9
9
|
};
|
|
10
10
|
type FormView<Values extends Dict> = {
|
|
@@ -12,12 +12,13 @@ type FormView<Values extends Dict> = {
|
|
|
12
12
|
submitting: Signal<boolean>;
|
|
13
13
|
submitted: Signal<boolean>;
|
|
14
14
|
submit: (event?: Event) => Promise<void>;
|
|
15
|
-
errors: Signal<
|
|
15
|
+
errors: Signal<string[]>;
|
|
16
16
|
field: <K extends keyof Values & string>(name: K) => Field<Values[K]>;
|
|
17
17
|
};
|
|
18
18
|
type Initial<Values extends Dict> = FormInit & {
|
|
19
19
|
initial?: Values;
|
|
20
20
|
};
|
|
21
|
+
declare function form<Values extends Dict>(action: ClientMethod<Values>, init?: Initial<Values>): FormView<Values>;
|
|
21
22
|
declare function form<Values extends Dict>(init: Initial<Values>): FormView<Values>;
|
|
22
23
|
declare function form(init?: FormInit): FormView<Dict>;
|
|
23
24
|
export default form;
|
|
@@ -8,30 +8,40 @@ function try_destroy_ref() {
|
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function form(
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
function form(action_or_init, maybe_init) {
|
|
12
|
+
const is_action = typeof action_or_init === "function";
|
|
13
|
+
const { initial, ...form_init } = (is_action ? (maybe_init ?? {}) : (action_or_init ?? {}));
|
|
14
|
+
const action = is_action ? action_or_init : undefined;
|
|
15
|
+
const contentType = is_action
|
|
16
|
+
? action_or_init.contentType
|
|
17
|
+
: undefined;
|
|
18
|
+
const controller = core.createForm({
|
|
19
|
+
...form_init,
|
|
20
|
+
...(action !== undefined && {
|
|
21
|
+
action: action,
|
|
22
|
+
contentType,
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
14
25
|
const values = (initial ?? {});
|
|
15
26
|
const snap = signal(controller.read());
|
|
16
|
-
const
|
|
17
|
-
try_destroy_ref()?.onDestroy(
|
|
27
|
+
const unsubscribe = controller.subscribe(next => snap.set(next));
|
|
28
|
+
try_destroy_ref()?.onDestroy(unsubscribe);
|
|
18
29
|
const submitting = computed(() => snap().submitting);
|
|
19
30
|
const submitted = computed(() => snap().submitted);
|
|
20
31
|
const errors = computed(() => snap().errors.form);
|
|
21
32
|
const cache = new Map();
|
|
22
33
|
function field(name) {
|
|
23
|
-
const
|
|
24
|
-
const cached = cache.get(key);
|
|
34
|
+
const cached = cache.get(name);
|
|
25
35
|
if (cached)
|
|
26
36
|
return cached;
|
|
27
|
-
const form_errors = computed(() => snap().errors.fields[
|
|
37
|
+
const form_errors = computed(() => snap().errors.fields[name] ?? []);
|
|
28
38
|
const view = {
|
|
29
|
-
name
|
|
39
|
+
name,
|
|
30
40
|
value: values[name],
|
|
31
41
|
errors: form_errors,
|
|
32
42
|
error: computed(() => form_errors()[0] ?? null),
|
|
33
43
|
};
|
|
34
|
-
cache.set(
|
|
44
|
+
cache.set(name, view);
|
|
35
45
|
return view;
|
|
36
46
|
}
|
|
37
47
|
return {
|
package/lib/private/default.d.ts
CHANGED
package/lib/private/init.js
CHANGED
|
@@ -24,7 +24,7 @@ const module = {
|
|
|
24
24
|
document: `<${root}></${root}>`,
|
|
25
25
|
});
|
|
26
26
|
const headMatch = html.match(/<head>(.*?)<\/head>/s);
|
|
27
|
-
const bodyRegex = new RegExp(
|
|
27
|
+
const bodyRegex = new RegExp(`(<${root}(?:\\s[^>]*)?>[\\s\\S]*?<\\/${root}>)`);
|
|
28
28
|
const bodyMatch = html.match(bodyRegex);
|
|
29
29
|
return {
|
|
30
30
|
body: bodyMatch?.[1] || html,
|
package/lib/private/runtime.d.ts
CHANGED
package/lib/public/browser.d.ts
CHANGED
package/lib/public/browser.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Angular for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/angular",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
],
|
|
19
19
|
"types": "lib/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@angular/common": "^21.2.
|
|
22
|
-
"@angular/compiler": "^21.2.
|
|
23
|
-
"@angular/core": "^21.2.
|
|
24
|
-
"@angular/platform-browser": "^21.2.
|
|
25
|
-
"@angular/platform-server": "^21.2.
|
|
26
|
-
"@angular/ssr": "^21.2.
|
|
27
|
-
"typescript": "^
|
|
28
|
-
"@primate/core": "^0.
|
|
21
|
+
"@angular/common": "^21.2.11",
|
|
22
|
+
"@angular/compiler": "^21.2.11",
|
|
23
|
+
"@angular/core": "^21.2.11",
|
|
24
|
+
"@angular/platform-browser": "^21.2.11",
|
|
25
|
+
"@angular/platform-server": "^21.2.11",
|
|
26
|
+
"@angular/ssr": "^21.2.9",
|
|
27
|
+
"typescript": "^6.0.3",
|
|
28
|
+
"@primate/core": "^0.7.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rcompat/type": "^0.
|
|
32
|
-
"@primate/test": "^0.0.0"
|
|
31
|
+
"@rcompat/type": "^0.17.0"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
35
|
-
"primate": "^0.
|
|
34
|
+
"primate": "^0.38.0"
|
|
36
35
|
},
|
|
37
36
|
"imports": {
|
|
38
37
|
"#*": {
|
|
@@ -43,6 +42,7 @@
|
|
|
43
42
|
"exports": {
|
|
44
43
|
".": {
|
|
45
44
|
"types": "./lib/index.d.ts",
|
|
45
|
+
"@primate/runtime": "./src/public/runtime.ts",
|
|
46
46
|
"@primate/source": "./src/public/default.ts",
|
|
47
47
|
"browser": "./lib/public/browser.js",
|
|
48
48
|
"runtime": "./lib/public/runtime.js",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "npm run clean && tsc && cp src/types/{app,index}.d.ts lib",
|
|
58
58
|
"clean": "rm -rf ./lib",
|
|
59
|
-
"lint": "eslint ."
|
|
60
|
-
"test": "npx proby"
|
|
59
|
+
"lint": "eslint ."
|
|
61
60
|
}
|
|
62
61
|
}
|
package/lib/public/client.d.ts
DELETED
package/lib/public/client.js
DELETED