@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 CHANGED
@@ -1,3 +1,5 @@
1
1
  import "./app.d.ts";
2
+ export { default as client } from "#client/index";
3
+ export type { Validated } from "#client/index";
4
+ export { default } from "#default";
2
5
 
3
- export { default } from "./public/default";
@@ -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.spa) {
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<readonly string[]>;
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<readonly string[]>;
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(init) {
12
- const { initial, ...form_init } = (init ?? {});
13
- const controller = core.createForm(form_init);
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 unsub = controller.subscribe((next) => snap.set(next));
17
- try_destroy_ref()?.onDestroy(unsub);
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 key = name;
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[key] ?? []);
37
+ const form_errors = computed(() => snap().errors.fields[name] ?? []);
28
38
  const view = {
29
- name: key,
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(key, view);
44
+ cache.set(name, view);
35
45
  return view;
36
46
  }
37
47
  return {
@@ -1,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -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(`<${root}>([\\s\\S]*?)<\\/${root}>`);
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,
@@ -1,6 +1,6 @@
1
1
  declare const _default: (input?: {
2
2
  extensions?: string[] | undefined;
3
- spa?: boolean | undefined;
3
+ csr?: boolean | undefined;
4
4
  ssr?: boolean | undefined;
5
5
  } | undefined) => import("@primate/core/frontend").Module;
6
6
  export default _default;
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export { default } from "#client/app";
2
+ export { default as client } from "#client/index";
2
3
  //# sourceMappingURL=browser.js.map
@@ -1,2 +1,3 @@
1
+ export { default as client } from "#client/index";
1
2
  export { default } from "#runtime";
2
3
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,2 +1,3 @@
1
+ export { default as client } from "#client/index";
1
2
  export { default } from "#runtime";
2
3
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/angular",
3
- "version": "0.7.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.7",
22
- "@angular/compiler": "^21.2.7",
23
- "@angular/core": "^21.2.7",
24
- "@angular/platform-browser": "^21.2.7",
25
- "@angular/platform-server": "^21.2.7",
26
- "@angular/ssr": "^21.2.6",
27
- "typescript": "^5.9.3",
28
- "@primate/core": "^0.6.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.11.1",
32
- "@primate/test": "^0.0.0"
31
+ "@rcompat/type": "^0.17.0"
33
32
  },
34
33
  "peerDependencies": {
35
- "primate": "^0.37.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
  }
@@ -1,3 +0,0 @@
1
- export type * from "#client/index";
2
- export { default } from "#client/index";
3
- //# sourceMappingURL=client.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#client/index";
2
- //# sourceMappingURL=client.js.map