@molecule/app-angular 3.5.0 → 3.7.1

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.
Files changed (86) hide show
  1. package/README.md +323 -88
  2. package/dist/chat.d.ts.map +1 -1
  3. package/dist/chat.js +3 -2
  4. package/dist/chat.js.map +1 -1
  5. package/dist/hooks/index.d.ts +1 -0
  6. package/dist/hooks/index.d.ts.map +1 -1
  7. package/dist/hooks/index.js +1 -0
  8. package/dist/hooks/index.js.map +1 -1
  9. package/dist/hooks/use-ai-models.d.ts +10 -3
  10. package/dist/hooks/use-ai-models.d.ts.map +1 -1
  11. package/dist/hooks/use-ai-models.js +40 -15
  12. package/dist/hooks/use-ai-models.js.map +1 -1
  13. package/dist/hooks/use-async.d.ts +10 -6
  14. package/dist/hooks/use-async.d.ts.map +1 -1
  15. package/dist/hooks/use-async.js +38 -33
  16. package/dist/hooks/use-async.js.map +1 -1
  17. package/dist/hooks/use-auth-flows.d.ts +40 -21
  18. package/dist/hooks/use-auth-flows.d.ts.map +1 -1
  19. package/dist/hooks/use-auth-flows.js +59 -38
  20. package/dist/hooks/use-auth-flows.js.map +1 -1
  21. package/dist/hooks/use-auth.d.ts +7 -2
  22. package/dist/hooks/use-auth.d.ts.map +1 -1
  23. package/dist/hooks/use-auth.js +25 -10
  24. package/dist/hooks/use-auth.js.map +1 -1
  25. package/dist/hooks/use-forms.d.ts +10 -13
  26. package/dist/hooks/use-forms.d.ts.map +1 -1
  27. package/dist/hooks/use-forms.js +90 -54
  28. package/dist/hooks/use-forms.js.map +1 -1
  29. package/dist/hooks/use-http.d.ts +40 -32
  30. package/dist/hooks/use-http.d.ts.map +1 -1
  31. package/dist/hooks/use-http.js +80 -94
  32. package/dist/hooks/use-http.js.map +1 -1
  33. package/dist/hooks/use-ide.d.ts.map +1 -1
  34. package/dist/hooks/use-ide.js +3 -3
  35. package/dist/hooks/use-ide.js.map +1 -1
  36. package/dist/hooks/use-logger.d.ts.map +1 -1
  37. package/dist/hooks/use-logger.js +1 -1
  38. package/dist/hooks/use-logger.js.map +1 -1
  39. package/dist/hooks/use-native.d.ts +7 -2
  40. package/dist/hooks/use-native.d.ts.map +1 -1
  41. package/dist/hooks/use-native.js +27 -12
  42. package/dist/hooks/use-native.js.map +1 -1
  43. package/dist/hooks/use-optimistic-toggle.d.ts +65 -0
  44. package/dist/hooks/use-optimistic-toggle.d.ts.map +1 -0
  45. package/dist/hooks/use-optimistic-toggle.js +51 -0
  46. package/dist/hooks/use-optimistic-toggle.js.map +1 -0
  47. package/dist/hooks/use-router.d.ts +11 -4
  48. package/dist/hooks/use-router.d.ts.map +1 -1
  49. package/dist/hooks/use-router.js +22 -7
  50. package/dist/hooks/use-router.js.map +1 -1
  51. package/dist/hooks/use-storage.d.ts +20 -6
  52. package/dist/hooks/use-storage.d.ts.map +1 -1
  53. package/dist/hooks/use-storage.js +148 -66
  54. package/dist/hooks/use-storage.js.map +1 -1
  55. package/dist/hooks/use-store.d.ts +10 -3
  56. package/dist/hooks/use-store.d.ts.map +1 -1
  57. package/dist/hooks/use-store.js +49 -9
  58. package/dist/hooks/use-store.js.map +1 -1
  59. package/dist/hooks/use-theme.d.ts.map +1 -1
  60. package/dist/hooks/use-theme.js +1 -1
  61. package/dist/hooks/use-theme.js.map +1 -1
  62. package/dist/hooks/use-translation.d.ts +7 -2
  63. package/dist/hooks/use-translation.d.ts.map +1 -1
  64. package/dist/hooks/use-translation.js +11 -5
  65. package/dist/hooks/use-translation.js.map +1 -1
  66. package/dist/index.d.ts +6 -0
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +6 -0
  69. package/dist/index.js.map +1 -1
  70. package/dist/inject.d.ts +7 -2
  71. package/dist/inject.d.ts.map +1 -1
  72. package/dist/inject.js +51 -5
  73. package/dist/inject.js.map +1 -1
  74. package/dist/link.d.ts +63 -0
  75. package/dist/link.d.ts.map +1 -0
  76. package/dist/link.js +82 -0
  77. package/dist/link.js.map +1 -0
  78. package/dist/maybe-signal.d.ts +26 -0
  79. package/dist/maybe-signal.d.ts.map +1 -0
  80. package/dist/maybe-signal.js +20 -0
  81. package/dist/maybe-signal.js.map +1 -0
  82. package/package.json +4 -4
  83. package/dist/site.d.ts +0 -51
  84. package/dist/site.d.ts.map +0 -1
  85. package/dist/site.js +0 -69
  86. package/dist/site.js.map +0 -1
package/dist/index.js CHANGED
@@ -73,6 +73,10 @@
73
73
  * Molecule service whose token was never provided fails at DI time.
74
74
  * Per-concern helpers (`provideAuth`, `provideTheme`, ...) exist for
75
75
  * piecemeal setup.
76
+ * - In-app links use the `Link` directive (`<a molLink="/settings">`, `imports: [Link]`): it
77
+ * navigates through the molecule router with react-router `<Link>`'s click rules. A bare
78
+ * `<a href>` reloads the page; a hand-written `(click)` handler that calls `navigate()`
79
+ * breaks ctrl/cmd-click (new tab) unless it repeats those rules.
76
80
  *
77
81
  * @module
78
82
  */
@@ -80,6 +84,8 @@ export * from './agent-identity.js';
80
84
  export * from './chat.js';
81
85
  export * from './hooks/index.js';
82
86
  export * from './i18n-reactive.js';
87
+ export * from './link.js';
88
+ export * from './maybe-signal.js';
83
89
  export * from './providers.js';
84
90
  export * from './services/index.js';
85
91
  export * from './session-ready.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
package/dist/inject.d.ts CHANGED
@@ -4,6 +4,12 @@
4
4
  * @module
5
5
  */
6
6
  import { type InjectionToken } from '@angular/core';
7
+ /**
8
+ * The provider-missing error keys this package throws, one per hook that needs
9
+ * an injection token (the React hook's error-key suffix; the full key is
10
+ * `angular.error.<key>`).
11
+ */
12
+ export type ProviderErrorKey = 'useAuthOutsideProvider' | 'useEditorOutsideProvider' | 'useHttpOutsideProvider' | 'useLoggerOutsideProvider' | 'usePreviewOutsideProvider' | 'useRouterOutsideProvider' | 'useStorageOutsideProvider' | 'useThemeOutsideProvider' | 'useWorkspaceOutsideProvider';
7
13
  /**
8
14
  * Reads a service token registered by `provideMolecule` (or a `provide*`
9
15
  * helper), throwing React's provider-missing error when it is absent.
@@ -16,9 +22,8 @@ import { type InjectionToken } from '@angular/core';
16
22
  *
17
23
  * @param token - The injection token (`AUTH_CLIENT`, `THEME_PROVIDER`, …).
18
24
  * @param key - The error key's suffix after `angular.error.` (React's suffix).
19
- * @param defaultValue - React's English error text.
20
25
  * @returns The service.
21
26
  * @throws {Error} When no provider registered the token.
22
27
  */
23
- export declare function injectProvider<T>(token: InjectionToken<T>, key: string, defaultValue: string): T;
28
+ export declare function injectProvider<T>(token: InjectionToken<T>, key: ProviderErrorKey): T;
24
29
  //# sourceMappingURL=inject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAI3D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC,CAUhG"}
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAI3D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GACxB,wBAAwB,GACxB,0BAA0B,GAC1B,wBAAwB,GACxB,0BAA0B,GAC1B,2BAA2B,GAC3B,0BAA0B,GAC1B,2BAA2B,GAC3B,yBAAyB,GACzB,6BAA6B,CAAA;AAoDjC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,GAAG,CAAC,CAMpF"}
package/dist/inject.js CHANGED
@@ -5,6 +5,55 @@
5
5
  */
6
6
  import { inject } from '@angular/core';
7
7
  import { t } from '@molecule/app-i18n';
8
+ /**
9
+ * The localized provider-missing error text for one hook.
10
+ *
11
+ * Each key is one literal `t()` call with a literal key, so the locale bond's
12
+ * parity check can see every key and every non-English locale resolves it.
13
+ *
14
+ * @param key - The error key's suffix after `angular.error.` (React's suffix).
15
+ * @returns The localized error message.
16
+ */
17
+ const providerErrorMessage = (key) => {
18
+ switch (key) {
19
+ case 'useAuthOutsideProvider':
20
+ return t('angular.error.useAuthOutsideProvider', undefined, {
21
+ defaultValue: 'useAuthClient must be used within an AuthProvider',
22
+ });
23
+ case 'useEditorOutsideProvider':
24
+ return t('angular.error.useEditorOutsideProvider', undefined, {
25
+ defaultValue: 'useEditorProvider must be used within an EditorProvider',
26
+ });
27
+ case 'useHttpOutsideProvider':
28
+ return t('angular.error.useHttpOutsideProvider', undefined, {
29
+ defaultValue: 'useHttpClient must be used within an HttpProvider',
30
+ });
31
+ case 'useLoggerOutsideProvider':
32
+ return t('angular.error.useLoggerOutsideProvider', undefined, {
33
+ defaultValue: 'useLoggerProvider must be used within a LoggerProvider',
34
+ });
35
+ case 'usePreviewOutsideProvider':
36
+ return t('angular.error.usePreviewOutsideProvider', undefined, {
37
+ defaultValue: 'usePreviewProvider must be used within a PreviewProvider',
38
+ });
39
+ case 'useRouterOutsideProvider':
40
+ return t('angular.error.useRouterOutsideProvider', undefined, {
41
+ defaultValue: 'useRouterInstance must be used within a RouterProvider',
42
+ });
43
+ case 'useStorageOutsideProvider':
44
+ return t('angular.error.useStorageOutsideProvider', undefined, {
45
+ defaultValue: 'useStorageProvider must be used within a StorageProvider',
46
+ });
47
+ case 'useThemeOutsideProvider':
48
+ return t('angular.error.useThemeOutsideProvider', undefined, {
49
+ defaultValue: 'useThemeProvider must be used within a ThemeProvider',
50
+ });
51
+ case 'useWorkspaceOutsideProvider':
52
+ return t('angular.error.useWorkspaceOutsideProvider', undefined, {
53
+ defaultValue: 'useWorkspaceProvider must be used within a WorkspaceProvider',
54
+ });
55
+ }
56
+ };
8
57
  /**
9
58
  * Reads a service token registered by `provideMolecule` (or a `provide*`
10
59
  * helper), throwing React's provider-missing error when it is absent.
@@ -17,16 +66,13 @@ import { t } from '@molecule/app-i18n';
17
66
  *
18
67
  * @param token - The injection token (`AUTH_CLIENT`, `THEME_PROVIDER`, …).
19
68
  * @param key - The error key's suffix after `angular.error.` (React's suffix).
20
- * @param defaultValue - React's English error text.
21
69
  * @returns The service.
22
70
  * @throws {Error} When no provider registered the token.
23
71
  */
24
- export function injectProvider(token, key, defaultValue) {
72
+ export function injectProvider(token, key) {
25
73
  const provider = inject(token, { optional: true });
26
74
  if (!provider) {
27
- throw new Error(t(`angular.error.${key}`, undefined, {
28
- defaultValue,
29
- }));
75
+ throw new Error(providerErrorMessage(key));
30
76
  }
31
77
  return provider;
32
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAuB,MAAM,eAAe,CAAA;AAE3D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAI,KAAwB,EAAE,GAAW,EAAE,YAAoB;IAC3F,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,CAAC,CAAC,iBAAiB,GAAG,EAAE,EAAE,SAAS,EAAE;YACnC,YAAY;SACb,CAAC,CACH,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAuB,MAAM,eAAe,CAAA;AAE3D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAkBtC;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAAG,CAAC,GAAqB,EAAU,EAAE;IAC7D,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,wBAAwB;YAC3B,OAAO,CAAC,CAAC,sCAAsC,EAAE,SAAS,EAAE;gBAC1D,YAAY,EAAE,mDAAmD;aAClE,CAAC,CAAA;QACJ,KAAK,0BAA0B;YAC7B,OAAO,CAAC,CAAC,wCAAwC,EAAE,SAAS,EAAE;gBAC5D,YAAY,EAAE,yDAAyD;aACxE,CAAC,CAAA;QACJ,KAAK,wBAAwB;YAC3B,OAAO,CAAC,CAAC,sCAAsC,EAAE,SAAS,EAAE;gBAC1D,YAAY,EAAE,mDAAmD;aAClE,CAAC,CAAA;QACJ,KAAK,0BAA0B;YAC7B,OAAO,CAAC,CAAC,wCAAwC,EAAE,SAAS,EAAE;gBAC5D,YAAY,EAAE,wDAAwD;aACvE,CAAC,CAAA;QACJ,KAAK,2BAA2B;YAC9B,OAAO,CAAC,CAAC,yCAAyC,EAAE,SAAS,EAAE;gBAC7D,YAAY,EAAE,0DAA0D;aACzE,CAAC,CAAA;QACJ,KAAK,0BAA0B;YAC7B,OAAO,CAAC,CAAC,wCAAwC,EAAE,SAAS,EAAE;gBAC5D,YAAY,EAAE,wDAAwD;aACvE,CAAC,CAAA;QACJ,KAAK,2BAA2B;YAC9B,OAAO,CAAC,CAAC,yCAAyC,EAAE,SAAS,EAAE;gBAC7D,YAAY,EAAE,0DAA0D;aACzE,CAAC,CAAA;QACJ,KAAK,yBAAyB;YAC5B,OAAO,CAAC,CAAC,uCAAuC,EAAE,SAAS,EAAE;gBAC3D,YAAY,EAAE,sDAAsD;aACrE,CAAC,CAAA;QACJ,KAAK,6BAA6B;YAChC,OAAO,CAAC,CAAC,2CAA2C,EAAE,SAAS,EAAE;gBAC/D,YAAY,EAAE,8DAA8D;aAC7E,CAAC,CAAA;IACN,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAI,KAAwB,EAAE,GAAqB;IAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
package/dist/link.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `Link` (`<a molLink="/path">`): an in-app anchor for Angular, the counterpart
3
+ * of react-router's `<Link>`.
4
+ *
5
+ * @module
6
+ */
7
+ import { type OnInit } from '@angular/core';
8
+ import * as i0 from "@angular/core";
9
+ /**
10
+ * `<a molLink="/settings">`: sets the anchor's `href` and navigates in-app
11
+ * through the molecule router, with react-router `<Link>`'s rules
12
+ * (`followRouterLink` from `@molecule/app-routing`): a plain primary click
13
+ * navigates without a page load; a ctrl/cmd, shift or alt click, a `target`
14
+ * other than `_self`, a click the template's own `(click)` handler prevented,
15
+ * and a URL on another origin are left to the browser.
16
+ *
17
+ * Inputs: `molLink` (the destination: an app path or a URL), `replace` (replace
18
+ * the current history entry; when unset, a link to the location already shown
19
+ * replaces it and any other link pushes, as with react-router's `<Link>`), and
20
+ * `state` (stored with the new entry). Every other attribute (`class`,
21
+ * `target`, `rel`) is written on the anchor as usual.
22
+ *
23
+ * Use it for every internal link instead of an anchor with a `(click)` handler
24
+ * that calls `navigate()`. Needs the router from `provideMolecule({ router })`.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { Component } from '@angular/core'
29
+ * import { Link } from '@molecule/app-angular'
30
+ *
31
+ * @Component({
32
+ * selector: 'app-nav',
33
+ * standalone: true,
34
+ * imports: [Link],
35
+ * template: `
36
+ * <a molLink="/projects" class="nav-link">Projects</a>
37
+ * <a molLink="/login" [replace]="true" [state]="{ from: '/projects' }">Log in</a>
38
+ * `,
39
+ * })
40
+ * export class NavComponent {}
41
+ * ```
42
+ */
43
+ export declare class Link implements OnInit {
44
+ /** The destination: an app path (`/settings?tab=billing#plan`) or a URL. */
45
+ molLink: string;
46
+ /** Replace the current history entry instead of pushing one. */
47
+ replace?: boolean;
48
+ /** State stored with the new history entry. */
49
+ state?: unknown;
50
+ private readonly router;
51
+ private readonly element;
52
+ private readonly renderer;
53
+ private readonly destroyRef;
54
+ /**
55
+ * Starts handling clicks. The listener is added here, after the template
56
+ * created this anchor's own `(click)` listeners, so those run first and can
57
+ * prevent the navigation (react-router calls `onClick` first too).
58
+ */
59
+ ngOnInit(): void;
60
+ static ɵfac: i0.ɵɵFactoryDeclaration<Link, never>;
61
+ static ɵdir: i0.ɵɵDirectiveDeclaration<Link, "a[molLink]", never, { "molLink": { "alias": "molLink"; "required": false; }; "replace": { "alias": "replace"; "required": false; }; "state": { "alias": "state"; "required": false; }; }, {}, never, never, true, never>;
62
+ }
63
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA6C,KAAK,MAAM,EAAa,MAAM,eAAe,CAAA;;AAMjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAMa,IAAK,YAAW,MAAM;IACjC,4EAA4E;IAC5E,OAAO,SAAK;IACZ,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoD;IAC5E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;IAEhD;;;;OAIG;IACH,QAAQ,IAAI,IAAI;yCAlBL,IAAI;2CAAJ,IAAI;CA2BhB"}
package/dist/link.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `Link` (`<a molLink="/path">`): an in-app anchor for Angular, the counterpart
3
+ * of react-router's `<Link>`.
4
+ *
5
+ * @module
6
+ */
7
+ import { DestroyRef, Directive, ElementRef, inject, Renderer2 } from '@angular/core';
8
+ import { followRouterLink } from '@molecule/app-routing';
9
+ import { useRouterInstance } from './hooks/use-router.js';
10
+ import * as i0 from "@angular/core";
11
+ /**
12
+ * `<a molLink="/settings">`: sets the anchor's `href` and navigates in-app
13
+ * through the molecule router, with react-router `<Link>`'s rules
14
+ * (`followRouterLink` from `@molecule/app-routing`): a plain primary click
15
+ * navigates without a page load; a ctrl/cmd, shift or alt click, a `target`
16
+ * other than `_self`, a click the template's own `(click)` handler prevented,
17
+ * and a URL on another origin are left to the browser.
18
+ *
19
+ * Inputs: `molLink` (the destination: an app path or a URL), `replace` (replace
20
+ * the current history entry; when unset, a link to the location already shown
21
+ * replaces it and any other link pushes, as with react-router's `<Link>`), and
22
+ * `state` (stored with the new entry). Every other attribute (`class`,
23
+ * `target`, `rel`) is written on the anchor as usual.
24
+ *
25
+ * Use it for every internal link instead of an anchor with a `(click)` handler
26
+ * that calls `navigate()`. Needs the router from `provideMolecule({ router })`.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import { Component } from '@angular/core'
31
+ * import { Link } from '@molecule/app-angular'
32
+ *
33
+ * @Component({
34
+ * selector: 'app-nav',
35
+ * standalone: true,
36
+ * imports: [Link],
37
+ * template: `
38
+ * <a molLink="/projects" class="nav-link">Projects</a>
39
+ * <a molLink="/login" [replace]="true" [state]="{ from: '/projects' }">Log in</a>
40
+ * `,
41
+ * })
42
+ * export class NavComponent {}
43
+ * ```
44
+ */
45
+ export class Link {
46
+ constructor() {
47
+ /** The destination: an app path (`/settings?tab=billing#plan`) or a URL. */
48
+ this.molLink = '';
49
+ this.router = useRouterInstance();
50
+ this.element = inject(ElementRef);
51
+ this.renderer = inject(Renderer2);
52
+ this.destroyRef = inject(DestroyRef);
53
+ }
54
+ /**
55
+ * Starts handling clicks. The listener is added here, after the template
56
+ * created this anchor's own `(click)` listeners, so those run first and can
57
+ * prevent the navigation (react-router calls `onClick` first too).
58
+ */
59
+ ngOnInit() {
60
+ const stop = this.renderer.listen(this.element.nativeElement, 'click', (event) => {
61
+ followRouterLink(event, this.molLink, this.router, {
62
+ replace: this.replace,
63
+ state: this.state,
64
+ });
65
+ });
66
+ this.destroyRef.onDestroy(stop);
67
+ }
68
+ static { this.ɵfac = function Link_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || Link)(); }; }
69
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: Link, selectors: [["a", "molLink", ""]], hostVars: 1, hostBindings: function Link_HostBindings(rf, ctx) { if (rf & 2) {
70
+ i0.ɵɵattribute("href", ctx.molLink, i0.ɵɵsanitizeUrlOrResourceUrl);
71
+ } }, inputs: { molLink: "molLink", replace: "replace", state: "state" } }); }
72
+ }
73
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(Link, [{
74
+ type: Directive,
75
+ args: [{
76
+ selector: 'a[molLink]',
77
+ standalone: true,
78
+ inputs: ['molLink', 'replace', 'state'],
79
+ host: { '[attr.href]': 'molLink' },
80
+ }]
81
+ }], null, null); })();
82
+ //# sourceMappingURL=link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.js","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAe,SAAS,EAAE,MAAM,eAAe,CAAA;AAEjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAOH,MAAM,OAAO,IAAI;IANjB;QAOE,4EAA4E;QAC5E,YAAO,GAAG,EAAE,CAAA;QAMK,WAAM,GAAG,iBAAiB,EAAE,CAAA;QAC5B,YAAO,GAAG,MAAM,CAAgC,UAAU,CAAC,CAAA;QAC3D,aAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QAC5B,eAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;KAgBjD;IAdC;;;;OAIG;IACH,QAAQ;QACN,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC,KAAiB,EAAE,EAAE;YAC3F,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;gBACjD,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;qGA1BU,IAAI;oEAAJ,IAAI;;;;iFAAJ,IAAI;cANhB,SAAS;eAAC;gBACT,QAAQ,EAAE,YAAY;gBACtB,UAAU,EAAE,IAAI;gBAChB,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC;gBACvC,IAAI,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE;aACnC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A plain value or a signal holding it: what the injection-context hooks
3
+ * accept for every argument, so a hook can follow its arguments the way
4
+ * React's hook follows a re-render with new arguments.
5
+ *
6
+ * @module
7
+ */
8
+ import { type Signal } from '@angular/core';
9
+ /**
10
+ * A hook argument: the plain value, or a signal holding the value the hook
11
+ * should currently use. A signal holding `undefined` means the argument was
12
+ * omitted, exactly like a missing plain argument: the default applies.
13
+ *
14
+ * @template T - The argument's shape.
15
+ */
16
+ export type MaybeSignal<T> = T | Signal<T>;
17
+ /**
18
+ * Reads a hook argument's current value. Inside a `computed` or `effect` this
19
+ * TRACKS a signal argument, so the reader re-runs when the argument changes;
20
+ * outside one it is a plain read.
21
+ *
22
+ * @param value - The argument as the hook received it.
23
+ * @returns The argument's current value.
24
+ */
25
+ export declare function readMaybeSignal<T>(value: MaybeSignal<T>): T;
26
+ //# sourceMappingURL=maybe-signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maybe-signal.d.ts","sourceRoot":"","sources":["../src/maybe-signal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAE1C;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAE3D"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A plain value or a signal holding it: what the injection-context hooks
3
+ * accept for every argument, so a hook can follow its arguments the way
4
+ * React's hook follows a re-render with new arguments.
5
+ *
6
+ * @module
7
+ */
8
+ import { isSignal } from '@angular/core';
9
+ /**
10
+ * Reads a hook argument's current value. Inside a `computed` or `effect` this
11
+ * TRACKS a signal argument, so the reader re-runs when the argument changes;
12
+ * outside one it is a plain read.
13
+ *
14
+ * @param value - The argument as the hook received it.
15
+ * @returns The argument's current value.
16
+ */
17
+ export function readMaybeSignal(value) {
18
+ return isSignal(value) ? value() : value;
19
+ }
20
+ //# sourceMappingURL=maybe-signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maybe-signal.js","sourceRoot":"","sources":["../src/maybe-signal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAA;AAWrD;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAI,KAAqB;IACtD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-angular",
3
- "version": "3.5.0",
3
+ "version": "3.7.1",
4
4
  "description": "Angular framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "@molecule/app-auth": "^3.0.0",
28
28
  "@molecule/app-code-editor": "^1.0.1",
29
29
  "@molecule/app-device": "^1.0.1",
30
- "@molecule/app-forms": "^2.3.1",
30
+ "@molecule/app-forms": "^2.4.0",
31
31
  "@molecule/app-http": "^1.0.1",
32
32
  "@molecule/app-i18n": "^1.0.1",
33
33
  "@molecule/app-ide": "^1.0.1",
@@ -35,7 +35,7 @@
35
35
  "@molecule/app-logger": "^1.0.1",
36
36
  "@molecule/app-platform": "^1.0.1",
37
37
  "@molecule/app-push": "^1.0.1",
38
- "@molecule/app-routing": "^1.1.0",
38
+ "@molecule/app-routing": "^1.3.0",
39
39
  "@molecule/app-state": "^1.2.0",
40
40
  "@molecule/app-storage": "^1.1.1",
41
41
  "@molecule/app-theme": "^1.0.1",
@@ -63,7 +63,7 @@
63
63
  "@molecule/app-ai-chat": "1.8.0",
64
64
  "@molecule/app-ai-models": "1.4.4",
65
65
  "@molecule/app-framework-conformance": "0.0.0",
66
- "@molecule/app-utilities": "1.0.6",
66
+ "@molecule/app-utilities": "1.0.7",
67
67
  "@types/node": "26.6.5",
68
68
  "rxjs": "7.8.2",
69
69
  "typescript": "6.0.3",
package/dist/site.d.ts DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * Hook-site lanes: state a hook keeps across a re-mount of the same site.
3
- *
4
- * React keeps a hook's state for as long as its component instance lives; an
5
- * argument change RE-RENDERS the same instance, so an in-flight request, a
6
- * pending save or a form draft survives it. In Angular a hook function runs
7
- * once per component instantiation, and new arguments arrive by re-creating
8
- * the component — so the hooks whose state must survive an argument change
9
- * (`useHttp`, `useOptimisticValue`, `useForm`) keep that state in a LANE: a
10
- * module-level record the destroyed instance parks and the next instance of
11
- * the same hook kind adopts when it mounts in the same place.
12
- *
13
- * A lane is parked only while the site is plausibly being re-created: the
14
- * park records the host element's container, and a microtask — which runs
15
- * after the synchronously-removed container of a real unmount, but before the
16
- * awaited re-creation of an argument change — drops the lane when that
17
- * container has left the document. A site that went away starts fresh.
18
- *
19
- * @module
20
- */
21
- /**
22
- * Adopts this hook kind's parked lane, if the site was re-created rather than
23
- * closed.
24
- *
25
- * @param kind - The hook kind (`'useHttp'`); one lane per kind and site.
26
- * @returns The parked lane, or `undefined` when the site starts fresh.
27
- */
28
- export declare function adoptLane<T>(kind: string): T | undefined;
29
- /**
30
- * Parks this hook kind's lane for the next instance at the same site.
31
- *
32
- * @param kind - The hook kind (`'useHttp'`).
33
- * @param lane - The lane to hand over.
34
- * @param site - The site {@link captureSite} recorded (the host's container);
35
- * `null` drops the lane.
36
- */
37
- export declare function parkLane(kind: string, lane: unknown, site: Element | null): void;
38
- /**
39
- * Records the site's container element: the host's parent once the host is in
40
- * the document. A hook runs during component creation, BEFORE the caller
41
- * appends the host, and the host is detached again before `onDestroy` runs —
42
- * so the only reliable moment to read the parent is a microtask after mount.
43
- * The container (not the host) is the right anchor: it survives a re-mount of
44
- * the host at the same site and leaves the document only when the site closes.
45
- *
46
- * @param host - The host element (`inject(ElementRef).nativeElement`).
47
- * @param onSite - Receives the container once the host is attached (or `null`
48
- * when the host never gets one).
49
- */
50
- export declare function captureSite(host: HTMLElement, onSite: (site: Element | null) => void): void;
51
- //# sourceMappingURL=site.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAIxD;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAOhF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,CAE3F"}
package/dist/site.js DELETED
@@ -1,69 +0,0 @@
1
- /**
2
- * Hook-site lanes: state a hook keeps across a re-mount of the same site.
3
- *
4
- * React keeps a hook's state for as long as its component instance lives; an
5
- * argument change RE-RENDERS the same instance, so an in-flight request, a
6
- * pending save or a form draft survives it. In Angular a hook function runs
7
- * once per component instantiation, and new arguments arrive by re-creating
8
- * the component — so the hooks whose state must survive an argument change
9
- * (`useHttp`, `useOptimisticValue`, `useForm`) keep that state in a LANE: a
10
- * module-level record the destroyed instance parks and the next instance of
11
- * the same hook kind adopts when it mounts in the same place.
12
- *
13
- * A lane is parked only while the site is plausibly being re-created: the
14
- * park records the host element's container, and a microtask — which runs
15
- * after the synchronously-removed container of a real unmount, but before the
16
- * awaited re-creation of an argument change — drops the lane when that
17
- * container has left the document. A site that went away starts fresh.
18
- *
19
- * @module
20
- */
21
- /** One parked lane per hook kind; the newest park wins. */
22
- const parked = new Map();
23
- /**
24
- * Adopts this hook kind's parked lane, if the site was re-created rather than
25
- * closed.
26
- *
27
- * @param kind - The hook kind (`'useHttp'`); one lane per kind and site.
28
- * @returns The parked lane, or `undefined` when the site starts fresh.
29
- */
30
- export function adoptLane(kind) {
31
- const lane = parked.get(kind);
32
- if (lane !== undefined)
33
- parked.delete(kind);
34
- return lane;
35
- }
36
- /**
37
- * Parks this hook kind's lane for the next instance at the same site.
38
- *
39
- * @param kind - The hook kind (`'useHttp'`).
40
- * @param lane - The lane to hand over.
41
- * @param site - The site {@link captureSite} recorded (the host's container);
42
- * `null` drops the lane.
43
- */
44
- export function parkLane(kind, lane, site) {
45
- parked.set(kind, lane);
46
- queueMicrotask(() => {
47
- if (parked.get(kind) !== lane)
48
- return;
49
- // Adopted already, or a newer park replaced this one.
50
- if (!site || !site.isConnected)
51
- parked.delete(kind);
52
- });
53
- }
54
- /**
55
- * Records the site's container element: the host's parent once the host is in
56
- * the document. A hook runs during component creation, BEFORE the caller
57
- * appends the host, and the host is detached again before `onDestroy` runs —
58
- * so the only reliable moment to read the parent is a microtask after mount.
59
- * The container (not the host) is the right anchor: it survives a re-mount of
60
- * the host at the same site and leaves the document only when the site closes.
61
- *
62
- * @param host - The host element (`inject(ElementRef).nativeElement`).
63
- * @param onSite - Receives the container once the host is attached (or `null`
64
- * when the host never gets one).
65
- */
66
- export function captureSite(host, onSite) {
67
- queueMicrotask(() => onSite(host.parentElement));
68
- }
69
- //# sourceMappingURL=site.js.map
package/dist/site.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"site.js","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,2DAA2D;AAC3D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAI,IAAY;IACvC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3C,OAAO,IAAqB,CAAA;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,IAAa,EAAE,IAAoB;IACxE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IACtB,cAAc,CAAC,GAAG,EAAE;QAClB,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,OAAM;QACrC,sDAAsD;QACtD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACrD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,IAAiB,EAAE,MAAsC;IACnF,cAAc,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;AAClD,CAAC"}