@molecule/app-angular 3.3.0 → 3.5.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.
Files changed (115) hide show
  1. package/README.md +3889 -1267
  2. package/dist/hooks/external-store.d.ts +32 -0
  3. package/dist/hooks/external-store.d.ts.map +1 -0
  4. package/dist/hooks/external-store.js +62 -0
  5. package/dist/hooks/external-store.js.map +1 -0
  6. package/dist/hooks/index.d.ts +24 -0
  7. package/dist/hooks/index.d.ts.map +1 -0
  8. package/dist/hooks/index.js +24 -0
  9. package/dist/hooks/index.js.map +1 -0
  10. package/dist/hooks/use-ai-models.d.ts +46 -0
  11. package/dist/hooks/use-ai-models.d.ts.map +1 -0
  12. package/dist/hooks/use-ai-models.js +142 -0
  13. package/dist/hooks/use-ai-models.js.map +1 -0
  14. package/dist/hooks/use-async.d.ts +125 -0
  15. package/dist/hooks/use-async.d.ts.map +1 -0
  16. package/dist/hooks/use-async.js +189 -0
  17. package/dist/hooks/use-async.js.map +1 -0
  18. package/dist/hooks/use-auth-flows.d.ts +207 -0
  19. package/dist/hooks/use-auth-flows.d.ts.map +1 -0
  20. package/dist/hooks/use-auth-flows.js +460 -0
  21. package/dist/hooks/use-auth-flows.js.map +1 -0
  22. package/dist/hooks/use-auth.d.ts +80 -0
  23. package/dist/hooks/use-auth.d.ts.map +1 -0
  24. package/dist/hooks/use-auth.js +89 -0
  25. package/dist/hooks/use-auth.js.map +1 -0
  26. package/dist/hooks/use-forms.d.ts +177 -0
  27. package/dist/hooks/use-forms.d.ts.map +1 -0
  28. package/dist/hooks/use-forms.js +185 -0
  29. package/dist/hooks/use-forms.js.map +1 -0
  30. package/dist/hooks/use-http.d.ts +155 -0
  31. package/dist/hooks/use-http.d.ts.map +1 -0
  32. package/dist/hooks/use-http.js +212 -0
  33. package/dist/hooks/use-http.js.map +1 -0
  34. package/dist/hooks/use-ide.d.ts +208 -0
  35. package/dist/hooks/use-ide.d.ts.map +1 -0
  36. package/dist/hooks/use-ide.js +217 -0
  37. package/dist/hooks/use-ide.js.map +1 -0
  38. package/dist/hooks/use-logger.d.ts +40 -0
  39. package/dist/hooks/use-logger.d.ts.map +1 -0
  40. package/dist/hooks/use-logger.js +56 -0
  41. package/dist/hooks/use-logger.js.map +1 -0
  42. package/dist/hooks/use-native.d.ts +213 -0
  43. package/dist/hooks/use-native.d.ts.map +1 -0
  44. package/dist/hooks/use-native.js +158 -0
  45. package/dist/hooks/use-native.js.map +1 -0
  46. package/dist/hooks/use-profile-form.d.ts +113 -0
  47. package/dist/hooks/use-profile-form.d.ts.map +1 -0
  48. package/dist/hooks/use-profile-form.js +253 -0
  49. package/dist/hooks/use-profile-form.js.map +1 -0
  50. package/dist/hooks/use-router.d.ts +212 -0
  51. package/dist/hooks/use-router.d.ts.map +1 -0
  52. package/dist/hooks/use-router.js +251 -0
  53. package/dist/hooks/use-router.js.map +1 -0
  54. package/dist/hooks/use-storage.d.ts +128 -0
  55. package/dist/hooks/use-storage.d.ts.map +1 -0
  56. package/dist/hooks/use-storage.js +217 -0
  57. package/dist/hooks/use-storage.js.map +1 -0
  58. package/dist/hooks/use-store.d.ts +74 -0
  59. package/dist/hooks/use-store.d.ts.map +1 -0
  60. package/dist/hooks/use-store.js +103 -0
  61. package/dist/hooks/use-store.js.map +1 -0
  62. package/dist/hooks/use-theme.d.ts +59 -0
  63. package/dist/hooks/use-theme.d.ts.map +1 -0
  64. package/dist/hooks/use-theme.js +117 -0
  65. package/dist/hooks/use-theme.js.map +1 -0
  66. package/dist/hooks/use-translation.d.ts +86 -0
  67. package/dist/hooks/use-translation.d.ts.map +1 -0
  68. package/dist/hooks/use-translation.js +146 -0
  69. package/dist/hooks/use-translation.js.map +1 -0
  70. package/dist/hooks/use-verify-payment-return.d.ts +86 -0
  71. package/dist/hooks/use-verify-payment-return.d.ts.map +1 -0
  72. package/dist/hooks/use-verify-payment-return.js +167 -0
  73. package/dist/hooks/use-verify-payment-return.js.map +1 -0
  74. package/dist/hooks/use-version.d.ts +49 -0
  75. package/dist/hooks/use-version.d.ts.map +1 -0
  76. package/dist/hooks/use-version.js +70 -0
  77. package/dist/hooks/use-version.js.map +1 -0
  78. package/dist/i18n-reactive.d.ts +2 -5
  79. package/dist/i18n-reactive.d.ts.map +1 -1
  80. package/dist/i18n-reactive.js.map +1 -1
  81. package/dist/index.d.ts +2 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +2 -0
  84. package/dist/index.js.map +1 -1
  85. package/dist/inject.d.ts +24 -0
  86. package/dist/inject.d.ts.map +1 -0
  87. package/dist/inject.js +33 -0
  88. package/dist/inject.js.map +1 -0
  89. package/dist/providers.d.ts +24 -0
  90. package/dist/providers.d.ts.map +1 -1
  91. package/dist/providers.js +44 -3
  92. package/dist/providers.js.map +1 -1
  93. package/dist/services/change-password.service.d.ts +4 -1
  94. package/dist/services/change-password.service.d.ts.map +1 -1
  95. package/dist/services/change-password.service.js +3 -0
  96. package/dist/services/change-password.service.js.map +1 -1
  97. package/dist/services/password-reset.service.d.ts +4 -1
  98. package/dist/services/password-reset.service.d.ts.map +1 -1
  99. package/dist/services/password-reset.service.js +3 -0
  100. package/dist/services/password-reset.service.js.map +1 -1
  101. package/dist/session-ready.d.ts +41 -0
  102. package/dist/session-ready.d.ts.map +1 -0
  103. package/dist/session-ready.js +79 -0
  104. package/dist/session-ready.js.map +1 -0
  105. package/dist/site.d.ts +51 -0
  106. package/dist/site.d.ts.map +1 -0
  107. package/dist/site.js +69 -0
  108. package/dist/site.js.map +1 -0
  109. package/dist/tokens.d.ts +15 -0
  110. package/dist/tokens.d.ts.map +1 -1
  111. package/dist/tokens.js +12 -0
  112. package/dist/tokens.js.map +1 -1
  113. package/dist/types.d.ts +14 -1
  114. package/dist/types.d.ts.map +1 -1
  115. package/package.json +6 -6
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Angular functions for HTTP requests, mirroring `useHttpClient`, `useHttp`,
3
+ * `useGet`, `usePost`, `usePut`, `usePatch` and `useDelete` from
4
+ * `@molecule/app-react`.
5
+ *
6
+ * Like React — whose component instance survives an argument change — the
7
+ * request state survives this site's re-creation (an argument change to the
8
+ * hook): the destroyed instance parks it at the site and the next instance
9
+ * adopts it. See `site.ts`.
10
+ *
11
+ * @module
12
+ */
13
+ import { DestroyRef, ElementRef, inject, signal, } from '@angular/core';
14
+ import { t } from '@molecule/app-i18n';
15
+ import { injectProvider } from '../inject.js';
16
+ import { adoptLane, captureSite, parkLane } from '../site.js';
17
+ import { HTTP_CLIENT } from '../tokens.js';
18
+ /**
19
+ * The HTTP client registered by `provideMolecule({ http })` or `provideHttp`.
20
+ * Call it in an injection context.
21
+ *
22
+ * @returns The HTTP client.
23
+ * @throws {Error} When no HTTP client is registered.
24
+ */
25
+ export function useHttpClient() {
26
+ return injectProvider(HTTP_CLIENT, 'useHttpOutsideProvider', 'useHttpClient must be used within an HttpProvider');
27
+ }
28
+ /**
29
+ * Builds a fresh lane.
30
+ *
31
+ * @param immediate - Whether the first mount starts loading at once.
32
+ * @returns The lane.
33
+ */
34
+ function buildLane(immediate) {
35
+ return {
36
+ data: signal(null),
37
+ loading: signal(immediate),
38
+ error: signal(null),
39
+ latestRequest: 0,
40
+ mounted: true,
41
+ immediateRan: false,
42
+ };
43
+ }
44
+ /**
45
+ * HTTP requests with state management. Call it in an injection context (a
46
+ * component field initializer or constructor).
47
+ *
48
+ * `execute` keeps one identity while `method`, `url` and the HTTP client stay
49
+ * the same — across the hook's own loading/data updates and inline options or
50
+ * callbacks. The current headers, body, `signal` and callbacks are read when
51
+ * `execute` is called. Changing `method`, `url` or the client selects a
52
+ * different request.
53
+ *
54
+ * The newest request owns the state: an older request that answers after a
55
+ * newer one (or after `reset`) cannot repopulate the displayed state, though
56
+ * its own callbacks still report its outcome.
57
+ *
58
+ * @param method - HTTP method.
59
+ * @param url - Request URL.
60
+ * @param options - Request options, read at call time.
61
+ * @returns The request state as signals and the execute/reset functions.
62
+ */
63
+ export function useHttp(method, url, options) {
64
+ const client = useHttpClient();
65
+ const immediate = options?.immediate ?? false;
66
+ const destroyRef = inject(DestroyRef);
67
+ const host = inject(ElementRef).nativeElement;
68
+ // This site's lane: adopted from the destroyed instance on an argument
69
+ // change (its pending requests, state and request counter continue), fresh
70
+ // on a new mount. One lane kind for the whole family — the verb hooks are
71
+ // spellings of useHttp over the same implementation, like React's.
72
+ const adopted = adoptLane('useHttp');
73
+ const lane = adopted ?? buildLane(options?.immediate ?? false);
74
+ lane.mounted = true;
75
+ // The site's container, recorded once the host is attached (see captureSite);
76
+ // the lane parks only while that container is still in the document.
77
+ let site = null;
78
+ captureSite(host, (captured) => {
79
+ site = captured;
80
+ });
81
+ destroyRef.onDestroy(() => {
82
+ lane.mounted = false;
83
+ parkLane('useHttp', lane, site);
84
+ });
85
+ const execute = async () => {
86
+ if (!lane.mounted)
87
+ return null;
88
+ // Options describe the request being sent; method/url/client decide WHICH
89
+ // request execute performs. Reading them here keeps the action stable.
90
+ const { immediate: _immediate, onSuccess, onError, ...requestConfig } = options ?? {};
91
+ const request = ++lane.latestRequest;
92
+ // Callbacks report THIS request's outcome (a submit's onSuccess still runs);
93
+ // only the newest request may change what the hook shows.
94
+ const ownsState = () => lane.mounted && request === lane.latestRequest;
95
+ lane.loading.set(true);
96
+ lane.error.set(null);
97
+ try {
98
+ let response;
99
+ switch (method) {
100
+ case 'GET':
101
+ response = await client.get(url, requestConfig);
102
+ break;
103
+ case 'POST':
104
+ response = await client.post(url, requestConfig.data, requestConfig);
105
+ break;
106
+ case 'PUT':
107
+ response = await client.put(url, requestConfig.data, requestConfig);
108
+ break;
109
+ case 'PATCH':
110
+ response = await client.patch(url, requestConfig.data, requestConfig);
111
+ break;
112
+ case 'DELETE':
113
+ response = await client.delete(url, requestConfig);
114
+ break;
115
+ default:
116
+ throw new Error(t('angular.error.unsupportedMethod', { method }, { defaultValue: 'Unsupported method: {{method}}' }));
117
+ }
118
+ if (lane.mounted) {
119
+ if (ownsState()) {
120
+ lane.data.set(response.data);
121
+ lane.loading.set(false);
122
+ lane.error.set(null);
123
+ }
124
+ onSuccess?.(response.data);
125
+ }
126
+ return response.data;
127
+ }
128
+ catch (error) {
129
+ const err = error instanceof Error ? error : new Error(String(error));
130
+ if (lane.mounted) {
131
+ if (ownsState()) {
132
+ lane.data.set(null);
133
+ lane.loading.set(false);
134
+ lane.error.set(err);
135
+ }
136
+ onError?.(err);
137
+ }
138
+ return null;
139
+ }
140
+ };
141
+ const reset = () => {
142
+ lane.latestRequest++;
143
+ lane.data.set(null);
144
+ lane.loading.set(false);
145
+ lane.error.set(null);
146
+ };
147
+ // Execute immediately if requested — mount only, as it has always been. An
148
+ // adopted site (an argument change re-created the host) has already run it;
149
+ // React runs this once per mount, so a later url change does not repeat it.
150
+ if (!adopted && immediate) {
151
+ lane.immediateRan = true;
152
+ void execute();
153
+ }
154
+ return {
155
+ data: lane.data.asReadonly(),
156
+ loading: lane.loading.asReadonly(),
157
+ error: lane.error.asReadonly(),
158
+ execute,
159
+ reset,
160
+ };
161
+ }
162
+ /**
163
+ * GET requests.
164
+ *
165
+ * @param url - Request URL to fetch from.
166
+ * @param options - HTTP request options including callbacks and request config.
167
+ * @returns Request state (data, loading, error) and controls (execute, reset).
168
+ */
169
+ export function useGet(url, options) {
170
+ return useHttp('GET', url, options);
171
+ }
172
+ /**
173
+ * POST requests, with the body in `options.data`.
174
+ *
175
+ * @param url - Request URL to post to.
176
+ * @param options - HTTP request options including body data and callbacks.
177
+ * @returns Request state (data, loading, error) and controls (execute, reset).
178
+ */
179
+ export function usePost(url, options) {
180
+ return useHttp('POST', url, options);
181
+ }
182
+ /**
183
+ * PUT requests, with the replacement body.
184
+ *
185
+ * @param url - Request URL to send the PUT request to.
186
+ * @param options - HTTP request options including body data and callbacks.
187
+ * @returns Request state (data, loading, error) and controls (execute, reset).
188
+ */
189
+ export function usePut(url, options) {
190
+ return useHttp('PUT', url, options);
191
+ }
192
+ /**
193
+ * PATCH requests, with the partial body.
194
+ *
195
+ * @param url - Request URL to send the PATCH request to.
196
+ * @param options - HTTP request options including partial body data and callbacks.
197
+ * @returns Request state (data, loading, error) and controls (execute, reset).
198
+ */
199
+ export function usePatch(url, options) {
200
+ return useHttp('PATCH', url, options);
201
+ }
202
+ /**
203
+ * DELETE requests; a body travels in `options.data`.
204
+ *
205
+ * @param url - Request URL of the resource to delete.
206
+ * @param options - HTTP request options including callbacks.
207
+ * @returns Request state (data, loading, error) and controls (execute, reset).
208
+ */
209
+ export function useDelete(url, options) {
210
+ return useHttp('DELETE', url, options);
211
+ }
212
+ //# sourceMappingURL=use-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-http.js","sourceRoot":"","sources":["../../src/hooks/use-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,UAAU,EACV,UAAU,EACV,MAAM,EAEN,MAAM,GAEP,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,cAAc,CACnB,WAAW,EACX,wBAAwB,EACxB,mDAAmD,CACpD,CAAA;AACH,CAAC;AAiGD;;;;;GAKG;AACH,SAAS,SAAS,CAAI,SAAkB;IACtC,OAAO;QACL,IAAI,EAAE,MAAM,CAAW,IAAI,CAAC;QAC5B,OAAO,EAAE,MAAM,CAAU,SAAS,CAAC;QACnC,KAAK,EAAE,MAAM,CAAe,IAAI,CAAC;QACjC,aAAa,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,KAAK;KACpB,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UA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QACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;QAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;QAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QAC9B,OAAO;QACP,KAAK;KACN,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAI,GAAW,EAAE,OAA2B;IAChE,OAAO,OAAO,CAAI,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAI,GAAW,EAAE,OAA2B;IACjE,OAAO,OAAO,CAAI,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAI,GAAW,EAAE,OAA2B;IAChE,OAAO,OAAO,CAAI,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAI,GAAW,EAAE,OAA2B;IAClE,OAAO,OAAO,CAAI,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAI,GAAW,EAAE,OAA2B;IACnE,OAAO,OAAO,CAAI,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AAC3C,CAAC"}
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Angular functions for the IDE services, mirroring `useWorkspace`,
3
+ * `useWorkspaceProvider`, `useEditor`, `useEditorProvider`, `usePreview` and
4
+ * `usePreviewProvider` from `@molecule/app-react`.
5
+ *
6
+ * @module
7
+ */
8
+ import { type Signal } from '@angular/core';
9
+ import type { DiffFile, EditorFile, EditorProvider, EditorTab, FixWithAIRequest } from '@molecule/app-code-editor';
10
+ import type { PanelId, WorkspaceProvider, WorkspaceState } from '@molecule/app-ide';
11
+ import type { DeviceFrame, PreviewProvider, PreviewState } from '@molecule/app-live-preview';
12
+ /**
13
+ * The workspace provider registered by `provideMolecule({ workspace })` or
14
+ * `provideWorkspace`. Call it in an injection context.
15
+ *
16
+ * @returns The workspace provider.
17
+ * @throws {Error} When no workspace provider is registered.
18
+ */
19
+ export declare function useWorkspaceProvider(): WorkspaceProvider;
20
+ /**
21
+ * IDE workspace layout management. Call it in an injection context (a
22
+ * component field initializer or constructor).
23
+ *
24
+ * @returns The workspace state as signals and the layout actions.
25
+ */
26
+ export declare function useWorkspace(): {
27
+ /** The current panel layout. */
28
+ readonly layout: Signal<WorkspaceState['layout']>;
29
+ /** The active panel id, or `null`. */
30
+ readonly activePanel: Signal<WorkspaceState['activePanel']>;
31
+ /** The collapsed panel ids. */
32
+ readonly collapsedPanels: Signal<WorkspaceState['collapsedPanels']>;
33
+ /**
34
+ * Shows or hides one panel.
35
+ *
36
+ * @param panelId - The panel to toggle.
37
+ */
38
+ togglePanel: (panelId: PanelId) => void;
39
+ /**
40
+ * Rewrites one panel's size.
41
+ *
42
+ * @param panelId - The panel to resize.
43
+ * @param size - The new size.
44
+ */
45
+ resizePanel: (panelId: PanelId, size: number) => void;
46
+ /**
47
+ * Sets the active panel.
48
+ *
49
+ * @param panelId - The panel to activate.
50
+ */
51
+ setActivePanel: (panelId: PanelId) => void;
52
+ /** Restores the default layout. */
53
+ resetLayout: () => void;
54
+ };
55
+ /**
56
+ * The editor provider registered by `provideMolecule({ editor })` or
57
+ * `provideEditor`. Call it in an injection context.
58
+ *
59
+ * @returns The editor provider.
60
+ * @throws {Error} When no editor provider is registered.
61
+ */
62
+ export declare function useEditorProvider(): EditorProvider;
63
+ /**
64
+ * What {@link useEditor} returns: the tab list and active file as signals and
65
+ * every editor action as a plain function.
66
+ */
67
+ export interface UseEditorResult {
68
+ /** The provider's tab list. */
69
+ readonly tabs: Signal<EditorTab[]>;
70
+ /** The path of the active tab, or `null` when no tab is active. */
71
+ readonly activeFile: Signal<string | null>;
72
+ /**
73
+ * Opens a file (and makes it active).
74
+ *
75
+ * @param file - The file to open.
76
+ */
77
+ openFile: (file: EditorFile) => void;
78
+ /**
79
+ * Closes a file's tab.
80
+ *
81
+ * @param path - The path to close.
82
+ */
83
+ closeFile: (path: string) => void;
84
+ /**
85
+ * Reads the active tab's content.
86
+ *
87
+ * @returns The content, or `null` with no active tab.
88
+ */
89
+ getContent: () => string | null;
90
+ /**
91
+ * Writes one tab's content.
92
+ *
93
+ * @param path - The tab's path.
94
+ * @param content - The new content.
95
+ */
96
+ setContent: (path: string, content: string) => void;
97
+ /**
98
+ * Activates one tab.
99
+ *
100
+ * @param path - The tab to activate.
101
+ */
102
+ setActiveTab: (path: string) => void;
103
+ /**
104
+ * Mounts the editor into an element.
105
+ *
106
+ * @param element - The host element.
107
+ * @param config - The editor config.
108
+ * @returns Whatever the provider's mount returns.
109
+ */
110
+ mount: (...args: Parameters<EditorProvider['mount']>) => ReturnType<EditorProvider['mount']>;
111
+ /** Disposes the editor. */
112
+ dispose: () => void;
113
+ /** Focuses the editor. */
114
+ focus: () => void;
115
+ /**
116
+ * Opens a diff tab.
117
+ *
118
+ * @param file - The diff to show.
119
+ */
120
+ openDiff: (file: DiffFile) => void;
121
+ /** Closes the diff tab. */
122
+ closeDiff: () => void;
123
+ /**
124
+ * Converts a preview tab into a normal one.
125
+ *
126
+ * @param path - The tab to pin.
127
+ */
128
+ pinTab: (path: string) => void;
129
+ /**
130
+ * Adds a type definition file to the editor's language service.
131
+ *
132
+ * @param content - The declaration content.
133
+ * @param filePath - The virtual file path.
134
+ */
135
+ addExtraLib: (content: string, filePath: string) => void;
136
+ /**
137
+ * Subscribes to fix-with-AI requests.
138
+ *
139
+ * @param callback - Called for every request.
140
+ * @returns A function that removes the subscription.
141
+ */
142
+ onFixWithAI: (callback: (request: FixWithAIRequest) => void) => () => void;
143
+ }
144
+ /**
145
+ * Code editor management. Call it in an injection context (a component field
146
+ * initializer or constructor).
147
+ *
148
+ * `tabs` and `activeFile` always come from the provider's own tab list:
149
+ * `activeFile` is the path of the tab marked `isActive`, or `null` when no
150
+ * tab is. They are read at mount (tabs opened before the component mounted
151
+ * show at once), on every provider change event, and after each action that
152
+ * changes the tab list (`openFile`, `closeFile`, `setActiveTab`, `openDiff`,
153
+ * `closeDiff`, `pinTab`).
154
+ *
155
+ * @returns Editor state as signals and the editor actions.
156
+ */
157
+ export declare function useEditor(): UseEditorResult;
158
+ /**
159
+ * The preview provider registered by `provideMolecule({ preview })` or
160
+ * `providePreview`. Call it in an injection context.
161
+ *
162
+ * @returns The preview provider.
163
+ * @throws {Error} When no preview provider is registered.
164
+ */
165
+ export declare function usePreviewProvider(): PreviewProvider;
166
+ /**
167
+ * What {@link usePreview} returns: the preview state as a signal and every
168
+ * preview action as a plain function.
169
+ */
170
+ export interface UsePreviewResult {
171
+ /** The preview state (url, device, connection, history flags). */
172
+ readonly state: Signal<PreviewState>;
173
+ /**
174
+ * Loads a new document.
175
+ *
176
+ * @param url - The url to load.
177
+ */
178
+ setUrl: (url: string) => void;
179
+ /** Reloads the current document. */
180
+ refresh: () => void;
181
+ /**
182
+ * Switches the device frame.
183
+ *
184
+ * @param device - The device frame to show.
185
+ */
186
+ setDevice: (device: DeviceFrame) => void;
187
+ /** Opens the current url outside the preview. */
188
+ openExternal: () => void;
189
+ /**
190
+ * Records an in-app navigation without reloading.
191
+ *
192
+ * @param url - The displayed url.
193
+ * @param isReplace - Whether the current history entry is replaced.
194
+ */
195
+ recordNavigation: (url: string, isReplace?: boolean) => void;
196
+ /** Goes back one navigation entry. */
197
+ back: () => void;
198
+ /** Goes forward one navigation entry. */
199
+ forward: () => void;
200
+ }
201
+ /**
202
+ * Live preview management. Call it in an injection context (a component field
203
+ * initializer or constructor).
204
+ *
205
+ * @returns The preview state as a signal and the preview actions.
206
+ */
207
+ export declare function usePreview(): UsePreviewResult;
208
+ //# sourceMappingURL=use-ide.d.ts.map
@@ -0,0 +1 @@
1
+ {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AED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,IAAI,eAAe,CAkF3C;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CAMpD;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAA;IACpC;;;;OAIG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,oCAAoC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;IACxC,iDAAiD;IACjD,YAAY,EAAE,MAAM,IAAI,CAAA;IACxB;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5D,sCAAsC;IACtC,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CA0C7C"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Angular functions for the IDE services, mirroring `useWorkspace`,
3
+ * `useWorkspaceProvider`, `useEditor`, `useEditorProvider`, `usePreview` and
4
+ * `usePreviewProvider` from `@molecule/app-react`.
5
+ *
6
+ * @module
7
+ */
8
+ import { computed, DestroyRef, inject, signal } from '@angular/core';
9
+ import { injectProvider } from '../inject.js';
10
+ import { EDITOR_PROVIDER, PREVIEW_PROVIDER, WORKSPACE_PROVIDER } from '../tokens.js';
11
+ import { useExternalStore } from './external-store.js';
12
+ /**
13
+ * The workspace provider registered by `provideMolecule({ workspace })` or
14
+ * `provideWorkspace`. Call it in an injection context.
15
+ *
16
+ * @returns The workspace provider.
17
+ * @throws {Error} When no workspace provider is registered.
18
+ */
19
+ export function useWorkspaceProvider() {
20
+ return injectProvider(WORKSPACE_PROVIDER, 'useWorkspaceOutsideProvider', 'useWorkspaceProvider must be used within a WorkspaceProvider');
21
+ }
22
+ /**
23
+ * IDE workspace layout management. Call it in an injection context (a
24
+ * component field initializer or constructor).
25
+ *
26
+ * @returns The workspace state as signals and the layout actions.
27
+ */
28
+ export function useWorkspace() {
29
+ const provider = useWorkspaceProvider();
30
+ // Snapshot cache: a bond without getState builds its answers fresh, and the
31
+ // emitted state is cached here so the read after a notification returns the
32
+ // emitted object (React's cachedRef).
33
+ let cached = null;
34
+ const read = () => {
35
+ // A bond with getState answers with the full state, the same object until it changes.
36
+ const full = provider.getState?.();
37
+ if (full)
38
+ return full;
39
+ const layout = provider.getLayout();
40
+ // Without getState, only the layout is readable before the first subscribe
41
+ // callback; the rest starts at the core's initial values. Use a lightweight cache comparison.
42
+ const prev = cached;
43
+ if (prev && prev.layout === layout) {
44
+ return prev;
45
+ }
46
+ const next = {
47
+ layout,
48
+ activePanel: null,
49
+ collapsedPanels: new Set(),
50
+ isFullscreen: false,
51
+ };
52
+ cached = next;
53
+ return next;
54
+ };
55
+ const state = useExternalStore(read, (onStoreChange) => {
56
+ return provider.subscribe((next) => {
57
+ cached = next;
58
+ onStoreChange();
59
+ });
60
+ });
61
+ const togglePanel = (panelId) => provider.togglePanel(panelId);
62
+ const resizePanel = (panelId, size) => provider.resizePanel(panelId, size);
63
+ const setActivePanel = (panelId) => provider.setActivePanel(panelId);
64
+ const resetLayout = () => provider.resetLayout();
65
+ return {
66
+ layout: computed(() => state().layout),
67
+ activePanel: computed(() => state().activePanel),
68
+ collapsedPanels: computed(() => state().collapsedPanels),
69
+ togglePanel,
70
+ resizePanel,
71
+ setActivePanel,
72
+ resetLayout,
73
+ };
74
+ }
75
+ /**
76
+ * The editor provider registered by `provideMolecule({ editor })` or
77
+ * `provideEditor`. Call it in an injection context.
78
+ *
79
+ * @returns The editor provider.
80
+ * @throws {Error} When no editor provider is registered.
81
+ */
82
+ export function useEditorProvider() {
83
+ return injectProvider(EDITOR_PROVIDER, 'useEditorOutsideProvider', 'useEditorProvider must be used within an EditorProvider');
84
+ }
85
+ /**
86
+ * Code editor management. Call it in an injection context (a component field
87
+ * initializer or constructor).
88
+ *
89
+ * `tabs` and `activeFile` always come from the provider's own tab list:
90
+ * `activeFile` is the path of the tab marked `isActive`, or `null` when no
91
+ * tab is. They are read at mount (tabs opened before the component mounted
92
+ * show at once), on every provider change event, and after each action that
93
+ * changes the tab list (`openFile`, `closeFile`, `setActiveTab`, `openDiff`,
94
+ * `closeDiff`, `pinTab`).
95
+ *
96
+ * @returns Editor state as signals and the editor actions.
97
+ */
98
+ export function useEditor() {
99
+ const provider = useEditorProvider();
100
+ const destroyRef = inject(DestroyRef);
101
+ const tabs = signal(provider.getTabs(), /* @ts-ignore */
102
+ ...(ngDevMode ? [{ debugName: "tabs" }] : /* istanbul ignore next */ []));
103
+ const activeFile = computed(() => tabs().find((tab) => tab.isActive)?.path ?? null, /* @ts-ignore */
104
+ ...(ngDevMode ? [{ debugName: "activeFile" }] : /* istanbul ignore next */ []));
105
+ // Re-reads the provider's tab list, which also carries the active tab.
106
+ const syncTabs = () => tabs.set(provider.getTabs());
107
+ // Subscribe to changes to update tabs and active file. Read once on
108
+ // subscribing too: a change between the first read and this subscription, or
109
+ // a replaced provider, sends no event this subscription could see.
110
+ const unsubscribe = provider.onChange(syncTabs);
111
+ syncTabs();
112
+ destroyRef.onDestroy(unsubscribe);
113
+ const openFile = (file) => {
114
+ provider.openFile(file);
115
+ syncTabs();
116
+ };
117
+ const closeFile = (path) => {
118
+ provider.closeFile(path);
119
+ syncTabs();
120
+ };
121
+ const getContent = () => provider.getContent();
122
+ const setContent = (path, content) => provider.setContent(path, content);
123
+ const setActiveTab = (path) => {
124
+ provider.setActiveTab(path);
125
+ syncTabs();
126
+ };
127
+ const mount = (...args) => provider.mount(...args);
128
+ const dispose = () => provider.dispose();
129
+ const focus = () => provider.focus();
130
+ const openDiff = (file) => {
131
+ provider.openDiff?.(file);
132
+ syncTabs();
133
+ };
134
+ const closeDiff = () => {
135
+ provider.closeDiff?.();
136
+ syncTabs();
137
+ };
138
+ const pinTab = (path) => {
139
+ provider.pinTab?.(path);
140
+ syncTabs();
141
+ };
142
+ const addExtraLib = (content, filePath) => {
143
+ provider.addExtraLib?.(content, filePath);
144
+ };
145
+ const onFixWithAI = (callback) => {
146
+ return provider.onFixWithAI?.(callback) ?? (() => { });
147
+ };
148
+ return {
149
+ tabs: tabs.asReadonly(),
150
+ activeFile,
151
+ openFile,
152
+ closeFile,
153
+ getContent,
154
+ setContent,
155
+ setActiveTab,
156
+ mount,
157
+ dispose,
158
+ focus,
159
+ openDiff,
160
+ closeDiff,
161
+ pinTab,
162
+ addExtraLib,
163
+ onFixWithAI,
164
+ };
165
+ }
166
+ /**
167
+ * The preview provider registered by `provideMolecule({ preview })` or
168
+ * `providePreview`. Call it in an injection context.
169
+ *
170
+ * @returns The preview provider.
171
+ * @throws {Error} When no preview provider is registered.
172
+ */
173
+ export function usePreviewProvider() {
174
+ return injectProvider(PREVIEW_PROVIDER, 'usePreviewOutsideProvider', 'usePreviewProvider must be used within a PreviewProvider');
175
+ }
176
+ /**
177
+ * Live preview management. Call it in an injection context (a component field
178
+ * initializer or constructor).
179
+ *
180
+ * @returns The preview state as a signal and the preview actions.
181
+ */
182
+ export function usePreview() {
183
+ const provider = usePreviewProvider();
184
+ // Snapshot cache: a provider that builds its answers fresh keeps the
185
+ // snapshot stable between notifications (React's cachedRef).
186
+ let cached = null;
187
+ const read = () => {
188
+ const next = provider.getState();
189
+ const prev = cached;
190
+ if (prev &&
191
+ prev.url === next.url &&
192
+ prev.currentUrl === next.currentUrl &&
193
+ prev.isLoading === next.isLoading &&
194
+ prev.device === next.device &&
195
+ prev.error === next.error &&
196
+ prev.isConnected === next.isConnected &&
197
+ prev.canGoBack === next.canGoBack &&
198
+ prev.canGoForward === next.canGoForward &&
199
+ prev.loadNonce === next.loadNonce) {
200
+ return prev;
201
+ }
202
+ cached = next;
203
+ return next;
204
+ };
205
+ const state = useExternalStore(read, (onStoreChange) => {
206
+ return provider.subscribe(() => onStoreChange());
207
+ });
208
+ const setUrl = (url) => provider.setUrl(url);
209
+ const refresh = () => provider.refresh();
210
+ const setDevice = (device) => provider.setDevice(device);
211
+ const openExternal = () => provider.openExternal();
212
+ const recordNavigation = (url, isReplace) => provider.recordNavigation(url, isReplace);
213
+ const back = () => provider.back();
214
+ const forward = () => provider.forward();
215
+ return { state, setUrl, refresh, setDevice, openExternal, recordNavigation, back, forward };
216
+ }
217
+ //# sourceMappingURL=use-ide.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-ide.js","sourceRoot":"","sources":["../../src/hooks/use-ide.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,EAAE,MAAM,eAAe,CAAA;AAYjF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,cAAc,CACnB,kBAAkB,EAClB,6BAA6B,EAC7B,8DAA8D,CAC/D,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IA6B1B,MAAM,QAAQ,GAAG,oBAAoB,EAAE,CAAA;IAEvC,4EAA4E;IAC5E,4EAA4E;IAC5E,sCAAsC;IACtC,IAAI,MAAM,GAA0B,IAAI,CAAA;IAExC,MAAM,IAAI,GAAG,GAAmB,EAAE;QAChC,sFAAsF;QACtF,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAA;QAClC,IAAI,IAAI;YAAE,OAAO,IAAI,CAAA;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