@analogjs/astro-angular 3.0.0-alpha.5 → 3.0.0-alpha.51

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 (45) hide show
  1. package/_virtual/_rolldown/runtime.js +33 -0
  2. package/package.json +34 -12
  3. package/src/client-ngh.d.ts +2 -0
  4. package/src/client-ngh.js +45 -0
  5. package/src/client-ngh.js.map +1 -0
  6. package/src/client.d.ts +2 -3
  7. package/src/client.js +41 -50
  8. package/src/client.js.map +1 -1
  9. package/src/context.d.ts +11 -0
  10. package/src/context.js +23 -0
  11. package/src/context.js.map +1 -0
  12. package/src/create-component.d.ts +5 -0
  13. package/src/create-component.js +31 -0
  14. package/src/create-component.js.map +1 -0
  15. package/src/id.d.ts +4 -0
  16. package/src/id.js +9 -0
  17. package/src/id.js.map +1 -0
  18. package/src/index.d.ts +15 -6
  19. package/src/index.js +66 -62
  20. package/src/index.js.map +1 -1
  21. package/src/middleware.d.ts +2 -0
  22. package/src/middleware.js +48 -0
  23. package/src/middleware.js.map +1 -0
  24. package/src/server-ngh.d.ts +2 -0
  25. package/src/server-ngh.js +64 -0
  26. package/src/server-ngh.js.map +1 -0
  27. package/src/server-providers.d.ts +8 -0
  28. package/src/server-providers.js +23 -0
  29. package/src/server-providers.js.map +1 -0
  30. package/src/server.d.ts +5 -6
  31. package/src/server.js +61 -56
  32. package/src/server.js.map +1 -1
  33. package/src/ssr-integrity.d.ts +1 -0
  34. package/src/ssr-integrity.js +10 -0
  35. package/src/ssr-integrity.js.map +1 -0
  36. package/src/test-setup.d.ts +3 -0
  37. package/src/utils.d.ts +0 -1
  38. package/src/utils.js +17 -10
  39. package/src/utils.js.map +1 -1
  40. package/src/vite-env.d.ts +1 -0
  41. package/README.md +0 -359
  42. package/src/client.d.ts.map +0 -1
  43. package/src/index.d.ts.map +0 -1
  44. package/src/server.d.ts.map +0 -1
  45. package/src/utils.d.ts.map +0 -1
package/README.md DELETED
@@ -1,359 +0,0 @@
1
- # @analogjs/astro-angular
2
-
3
- [Astro](https://astro.build) is a modern web framework designed for building fast, content-focused websites, compatible with all major frontend frameworks. Though primarily a static site generation (SSG) tool, it can also integrate dynamic components called "islands", which support partial hydration.
4
-
5
- This package allows rendering [Angular](https://angular.dev) components as islands in Astro.
6
-
7
- ## Setup
8
-
9
- ### Using the Astro CLI
10
-
11
- Use the `astro add` command to install the integration
12
-
13
- Using npm:
14
-
15
- ```sh
16
- npx astro add @analogjs/astro-angular
17
- ```
18
-
19
- Using pnpm:
20
-
21
- ```sh
22
- pnpm astro add @analogjs/astro-angular
23
- ```
24
-
25
- Using yarn:
26
-
27
- ```sh
28
- yarn astro add @analogjs/astro-angular
29
- ```
30
-
31
- This command:
32
-
33
- - Installs the `@analogjs/astro-angular` package.
34
- - Adds the `@analogjs/astro-angular` integration to the `astro.config.mjs` file.
35
- - Installs the necessary dependencies to render Angular components on the server and client, and common Angular dependencies, such as `@angular/common`.
36
-
37
- ### Setting up the TypeScript config
38
-
39
- The integration needs a `tsconfig.app.json` at the root of the project for compilation.
40
-
41
- Create a `tsconfig.app.json` in the root of the project.
42
-
43
- ```json
44
- {
45
- "extends": "./tsconfig.json",
46
- "compileOnSave": false,
47
- "compilerOptions": {
48
- "baseUrl": "./",
49
- "outDir": "./dist/out-tsc",
50
- "forceConsistentCasingInFileNames": true,
51
- "strict": true,
52
- "noImplicitOverride": true,
53
- "noPropertyAccessFromIndexSignature": true,
54
- "noImplicitReturns": true,
55
- "noFallthroughCasesInSwitch": true,
56
- "sourceMap": true,
57
- "declaration": false,
58
- "downlevelIteration": true,
59
- "experimentalDecorators": true,
60
- "moduleResolution": "node",
61
- "importHelpers": true,
62
- "noEmit": false,
63
- "target": "es2020",
64
- "module": "es2020",
65
- "lib": ["es2020", "dom"],
66
- "skipLibCheck": true
67
- },
68
- "angularCompilerOptions": {
69
- "enableI18nLegacyMessageIdFormat": false,
70
- "strictInjectionParameters": true,
71
- "strictInputAccessModifiers": true,
72
- "strictTemplates": true,
73
- "allowJs": false
74
- },
75
- "files": [],
76
- "include": ["src/**/*.ts", "src/**/*.tsx"]
77
- }
78
- ```
79
-
80
- Go to [Defining A Component](#defining-a-component) to set up an Angular component
81
- to use in an Astro component.
82
-
83
- ## Manual Installation
84
-
85
- The integration can also be installed manually
86
-
87
- ### Install the Astro Integration
88
-
89
- ```sh
90
- yarn add @analogjs/astro-angular
91
- ```
92
-
93
- ### Install the necessary Angular dependencies
94
-
95
- ```sh
96
- npm install @angular/build @angular/{animations,common,compiler-cli,compiler,core,language-service,forms,platform-browser,platform-server} rxjs tslib --save
97
- ```
98
-
99
- ### Adding the integration
100
-
101
- Add the integration to the `astro.config.mjs`
102
-
103
- ```js
104
- import { defineConfig } from 'astro/config';
105
- import angular from '@analogjs/astro-angular';
106
-
107
- export default defineConfig({
108
- integrations: [angular()],
109
- });
110
- ```
111
-
112
- Go to [Defining A Component](#defining-a-component)
113
-
114
- ## Configuration
115
-
116
- ### Configure Vite Angular Plugin
117
-
118
- Provide an option object to configure the `@analogjs/vite-plugin-angular` powering this plugin.
119
-
120
- ```js
121
- import { defineConfig } from 'astro/config';
122
- import angular from '@analogjs/astro-angular';
123
-
124
- export default defineConfig({
125
- integrations: [
126
- angular({
127
- vite: {
128
- inlineStylesExtension: 'scss|sass|less',
129
- },
130
- }),
131
- ],
132
- });
133
- ```
134
-
135
- ### Filtering File Transforms
136
-
137
- For better compatibility when integrating with other plugins such as [Starlight](https://starlight.astro.build), put the Angular components in a specific folder and use the `transformFilter` callback function to only transform those files.
138
-
139
- ```js
140
- import { defineConfig } from 'astro/config';
141
- import angular from '@analogjs/astro-angular';
142
-
143
- export default defineConfig({
144
- integrations: [
145
- angular({
146
- vite: {
147
- transformFilter: (_code, id) => {
148
- return id.includes('src/components'); // <- only transform Angular TypeScript files
149
- },
150
- },
151
- }),
152
- ],
153
- });
154
- ```
155
-
156
- ### Transforming Packages for SSR Compatibility
157
-
158
- To ensure Angular libraries are transformed during Astro's SSR process, add them to the `ssr.noExternal` array in the Vite config.
159
-
160
- ```js
161
- import { defineConfig } from 'astro/config';
162
-
163
- import angular from '@analogjs/astro-angular';
164
-
165
- export default defineConfig({
166
- integrations: [angular()],
167
- vite: {
168
- ssr: {
169
- // transform these packages during SSR. Globs supported
170
- noExternal: ['@rx-angular/**'],
171
- },
172
- },
173
- });
174
- ```
175
-
176
- ## Defining A Component
177
-
178
- The Astro Angular integration **only** supports rendering standalone components:
179
-
180
- ```ts
181
- import { Component, Input } from '@angular/core';
182
-
183
- @Component({
184
- selector: 'app-hello',
185
- template: `
186
- <p>Hello from Angular!!</p>
187
-
188
- @if (show()) {
189
- <p>{{ helpText() }}</p>
190
- }
191
-
192
- <button (click)="toggle()">Toggle</button>
193
- `,
194
- })
195
- export class HelloComponent {
196
- helpText = input('help');
197
-
198
- show = signal(false);
199
-
200
- toggle() {
201
- this.show.update((show) => !show);
202
- }
203
- }
204
- ```
205
-
206
- Add the Angular component to the Astro component template. This only renders the HTML from the Angular component.
207
-
208
- ```tsx
209
- ---
210
- import { HelloComponent } from '../components/hello.component';
211
-
212
- const helpText = "Helping binding";
213
- ---
214
-
215
- <HelloComponent />
216
- <HelloComponent helpText="Helping" />
217
- <HelloComponent helpText={helpText} />
218
- ```
219
-
220
- To hydrate the component on the client, use one of the Astro [client directives](https://docs.astro.build/en/reference/directives-reference/#client-directives):
221
-
222
- ```tsx
223
- ---
224
- import { HelloComponent } from '../components/hello.component';
225
- ---
226
-
227
- <HelloComponent client:visible />
228
- ```
229
-
230
- Find more information about [Client Directives](https://docs.astro.build/en/reference/directives-reference/#client-directives) in the Astro documentation.
231
-
232
- ### Listening to Component Outputs
233
-
234
- Outputs can be emitted by the Angular component are forwarded as HTML events to the Astro island.
235
- To enable this feature, add a client directive and a unique `[data-analog-id]` property to each Angular component:
236
-
237
- ```tsx
238
- ---
239
- import { HelloComponent } from '../components/hello.component';
240
- ---
241
-
242
- <HelloComponent client:visible data-analog-id="hello-component-1" />
243
- ```
244
-
245
- Then, listen to the event in the Astro component using the `addOutputListener` function:
246
-
247
- ```tsx
248
- ---
249
- import { HelloComponent } from '../components/hello.component';
250
- ---
251
-
252
- <HelloComponent client:visible data-analog-id="hello-component-1" />
253
-
254
- <script>
255
- import { addOutputListener } from '@analogjs/astro-angular/utils';
256
-
257
- addOutputListener('hello-component-1', 'outputName', (event) => {
258
- console.log(event.detail);
259
- });
260
- </script>
261
- ```
262
-
263
- ## Adding Component Providers
264
-
265
- Additional providers can be added to a component for static rendering and client hydration.
266
-
267
- These are `renderProviders` and `clientProviders` respectively. These providers are defined as static arrays on the Component class, and are registered when the component is rendered, and hydrated on the client.
268
-
269
- ```ts
270
- import { Component, OnInit, inject } from '@angular/core';
271
- import { provideHttpClient, HttpClient } from '@angular/common/http';
272
-
273
- interface Todo {
274
- id: number;
275
- title: string;
276
- completed: boolean;
277
- }
278
-
279
- @Component({
280
- selector: 'app-todos',
281
- template: `
282
- <h2>Todos</h2>
283
-
284
- <ul>
285
- @for (todo of todos(); track todo.id) {
286
- <li>
287
- {{ todo.title }}
288
- </li>
289
- }
290
- </ul>
291
- `,
292
- })
293
- export class TodosComponent implements OnInit {
294
- static clientProviders = [provideHttpClient()];
295
- static renderProviders = [TodosComponent.clientProviders];
296
-
297
- http = inject(HttpClient);
298
- todos = signal<Todo[]>([]);
299
-
300
- ngOnInit() {
301
- this.http
302
- .get<Todo[]>('https://jsonplaceholder.typicode.com/todos')
303
- .subscribe((todos) => this.todos.set(todos));
304
- }
305
- }
306
- ```
307
-
308
- ## Using Components in MDX pages
309
-
310
- To use components with MDX pages, you must install and configure MDX support by following the Astro integration of [@astrojs/mdx](https://docs.astro.build/en/guides/integrations-guide/mdx/). Your `astro.config.mjs` should now include the `@astrojs/mdx` integration.
311
-
312
- ```js
313
- import { defineConfig } from 'astro/config';
314
- import mdx from '@astrojs/mdx';
315
- import angular from '@analogjs/astro-angular';
316
-
317
- export default defineConfig({
318
- integrations: [mdx(), angular()],
319
- });
320
- ```
321
-
322
- Create an `.mdx` file inside the `src/pages` directory and add the Angular component import below the frontmatter.
323
-
324
- ```md
325
- ---
326
- layout: '../../layouts/BlogPost.astro'
327
- title: 'Using Angular in MDX'
328
- description: 'Lorem ipsum dolor sit amet'
329
- pubDate: 'Sep 22 2022'
330
- ---
331
-
332
- import { HelloComponent } from "../../components/hello.component.ts";
333
-
334
- <HelloComponent />
335
- <HelloComponent helpText="Helping" />
336
- ```
337
-
338
- To hydrate the component on the client, use one of the Astro [client directives](https://docs.astro.build/en/reference/directives-reference/#client-directives):
339
-
340
- ```md
341
- ---
342
- layout: '../../layouts/BlogPost.astro'
343
- title: 'Using Angular in MDX'
344
- description: 'Lorem ipsum dolor sit amet'
345
- pubDate: 'Sep 22 2022'
346
- ---
347
-
348
- import { HelloComponent } from "../../components/hello.component.ts";
349
-
350
- <HelloComponent client:load />
351
- <HelloComponent client:visible helpText="Helping" />
352
- ```
353
-
354
- > Important: In `.mdx` files the component import must end with the `.ts` suffix. Otherwise the dynamic import of the component will fail and the component won't be hydrated.
355
-
356
- ## Current Limitations
357
-
358
- - Only standalone Angular components in version v14.2+ are supported
359
- - Content projection to island components is not supported
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,QAAQ,EAER,cAAc,IAAI,aAAa,EAEhC,MAAM,eAAe,CAAC;yBAMrB,SAAS,WAAW,KACnB,CAAC,CACF,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG;IAClC,eAAe,CAAC,EAAE,CAAC,QAAQ,GAAG,oBAAoB,CAAC,EAAE,CAAC;CACvD,EACD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,CAAC,EAAE,OAAO,KACjB,IAAI,CAAC;AARV,wBA4EE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAoB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,OAAO,CAAC;AAG7E,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAsDD,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAqBnE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACpB,QAAQ,EACR,cAAc,IAAI,aAAa,EAChC,MAAM,eAAe,CAAC;AA2BvB,iBAAS,KAAK,CACZ,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,OAAO,GACjB,OAAO,CAET;AAwCD,iBAAe,oBAAoB,CACjC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG;IAClC,eAAe,EAAE,CAAC,QAAQ,GAAG,oBAAoB,CAAC,EAAE,CAAC;CACtD,EACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CA6B3B;AAED,QAAA,MAAM,QAAQ,EAAE;IACd,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;CAInD,CAAC;AACF,eAAe,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../packages/astro-angular/src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACzC,oBAAoB,GAAE,oBAAyB,GAC9C,MAAM,IAAI,CAeZ"}