@analogjs/astro-angular 0.1.0-beta.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/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # @analogjs/astro-angular
2
+
3
+ An [Angular](https://angular.io) integration for rendering components in [Astro](https://astro.build)
4
+
5
+ ## Setup
6
+
7
+ ### Using the Astro CLI
8
+
9
+ Use the `astro add` command to install the integration
10
+
11
+ ```sh
12
+ astro add @analogjs/astro-angular
13
+ ```
14
+
15
+ This command:
16
+
17
+ - Installs the `@analogjs/astro-angular` package.
18
+ - Adds the `@analogjs/astro-angular` integration to the `astro.config.mjs` file.
19
+ - Installs the necessary dependencies to render Angular components on the server and client, and common Angular dependencies, such as `@angular/common` and `@angular/forms`.
20
+
21
+ ### Setting up the TypeScript config
22
+
23
+ The integration needs a `tsconfig.app.json` at the root of the project for compilation.
24
+
25
+ Create a `tsconfig.app.json` in the root of the project.
26
+
27
+ ```json
28
+ {
29
+ "extends": "./tsconfig.json",
30
+ "compileOnSave": false,
31
+ "compilerOptions": {
32
+ "baseUrl": "./",
33
+ "outDir": "./dist/out-tsc",
34
+ "forceConsistentCasingInFileNames": true,
35
+ "strict": true,
36
+ "noImplicitOverride": true,
37
+ "noPropertyAccessFromIndexSignature": true,
38
+ "noImplicitReturns": true,
39
+ "noFallthroughCasesInSwitch": true,
40
+ "sourceMap": true,
41
+ "declaration": false,
42
+ "downlevelIteration": true,
43
+ "experimentalDecorators": true,
44
+ "moduleResolution": "node",
45
+ "importHelpers": true,
46
+ "noEmit": false,
47
+ "target": "es2020",
48
+ "module": "es2020",
49
+ "lib": ["es2020", "dom"]
50
+ },
51
+ "angularCompilerOptions": {
52
+ "enableI18nLegacyMessageIdFormat": false,
53
+ "strictInjectionParameters": true,
54
+ "strictInputAccessModifiers": true,
55
+ "strictTemplates": true
56
+ },
57
+ "files": [],
58
+ "include": ["src/**/*.ts"]
59
+ }
60
+ ```
61
+
62
+ Go to [Defining A Component](#defining-a-component) to set up an Angular component
63
+ to use in an Astro component.
64
+
65
+ ## Manual Installation
66
+
67
+ The integration can also be installed manually
68
+
69
+ ### Install the Astro Integration
70
+
71
+ ```sh
72
+ yarn add @analogjs/astro-angular --dev
73
+ ```
74
+
75
+ ### Install the necessary Angular dependencies
76
+
77
+ ```sh
78
+ yarn add @angular-devkit/build-angular, @angular/animations, @angular/common, @angular/compiler-cli, @angular/compiler, @angular/core, @angular/language-service, @angular/forms, @angular/platform-browser, @angular/platform-browser-dynamic, @angular/platform-server, rxjs, zone.js, tslib --dev
79
+ ```
80
+
81
+ ### Adding the integration
82
+
83
+ Add the integration to the `astro.config.mjs`
84
+
85
+ ```js
86
+ import { defineConfig } from 'astro/config';
87
+ import angular from '@analogjs/astro-angular';
88
+
89
+ export default defineConfig({
90
+ integrations: [angular()],
91
+ });
92
+ ```
93
+
94
+ Go to [Defining A Component](#defining-a-component)
95
+
96
+ ## Defining A Component
97
+
98
+ The Astro Angular integration **only** supports rendering standalone components:
99
+
100
+ ```ts
101
+ import { CommonModule } from '@angular/common';
102
+ import { Component } from '@angular/core';
103
+
104
+ @Component({
105
+ selector: 'app-hello',
106
+ standalone: true,
107
+ imports: [CommonModule],
108
+ template: `
109
+ <p>Hello from Angular!!</p>
110
+
111
+ <p *ngIf="show">help</p>
112
+
113
+ <button (click)="toggle()">Toggle</button>
114
+ `,
115
+ })
116
+ export class HelloComponent {
117
+ show = false;
118
+
119
+ toggle() {
120
+ this.show = !this.show;
121
+ }
122
+ }
123
+ ```
124
+
125
+ Add the Angular component to the Astro component template. This only renders the HTML from the Angular component.
126
+
127
+ ```ts
128
+ ---
129
+ import { HelloComponent } from '../components/hello.component.ts';
130
+ ---
131
+
132
+ <HelloComponent />
133
+ ```
134
+
135
+ To hydrate the component on the client, use one of the Astro directives:
136
+
137
+ ```ts
138
+ ---
139
+ import { HelloComponent } from '../components/hello.component.ts';
140
+ ---
141
+
142
+ <HelloComponent client:visible />
143
+ ```
144
+
145
+ Find more information about [Client Directives](https://docs.astro.build/en/reference/directives-reference/#client-directives) in the Astro documentation.
146
+
147
+ ## Current Limitations
148
+
149
+ - Only standalone Angular components in version v14.2+ are supported
150
+ - Component Props/Inputs are not supported
151
+ - Component Outputs are not supported
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@analogjs/astro-angular",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "An Angular integration for Astro",
5
+ "type": "module",
6
+ "author": "Brandon Roberts <robertsbt@gmail.com>",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./client.js": "./src/client.js",
10
+ "./server.js": "./src/server.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "keywords": [
14
+ "angular",
15
+ "astro",
16
+ "astro-integration",
17
+ "astro-component",
18
+ "renderer"
19
+ ],
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/analogjs/analog/issues"
23
+ },
24
+ "homepage": "https://analogjs.org",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/analogjs/analog.git"
28
+ },
29
+ "dependencies": {
30
+ "@analogjs/vite-plugin-angular": "latest"
31
+ },
32
+ "peerDependencies": {
33
+ "@angular-devkit/build-angular": "^14.0.0",
34
+ "@angular/animations": "^14.0.0",
35
+ "@angular/common": "^14.0.0",
36
+ "@angular/compiler-cli": "^14.0.0",
37
+ "@angular/compiler": "^14.0.0",
38
+ "@angular/core": "^14.0.0",
39
+ "@angular/language-service": "^14.0.0",
40
+ "@angular/forms": "^14.0.0",
41
+ "@angular/platform-browser": "^14.0.0",
42
+ "@angular/platform-browser-dynamic": "^14.0.0",
43
+ "@angular/platform-server": "^14.0.0",
44
+ "rxjs": "^7.5.0",
45
+ "zone.js": "~0.11.4",
46
+ "tslib": "^2.0.0"
47
+ },
48
+ "main": "./src/index.js",
49
+ "typings": "./src/index.d.ts"
50
+ }
@@ -0,0 +1,4 @@
1
+ import 'zone.js/dist/zone.js';
2
+ import type { ɵComponentType } from '@angular/core';
3
+ declare const _default: (element: HTMLElement) => (Component: ɵComponentType<unknown>, _props?: unknown, _childHTML?: unknown) => void;
4
+ export default _default;
package/src/client.js ADDED
@@ -0,0 +1,18 @@
1
+ import 'zone.js/dist/zone.js';
2
+ import { createApplication } from '@angular/platform-browser';
3
+ import { NgZone, createComponent } from '@angular/core';
4
+ export default (element) => {
5
+ return (Component, _props, _childHTML) => {
6
+ createApplication().then((appRef) => {
7
+ const zone = appRef.injector.get(NgZone);
8
+ zone.run(() => {
9
+ const componentRef = createComponent(Component, {
10
+ environmentInjector: appRef.injector,
11
+ hostElement: element,
12
+ });
13
+ appRef.attachView(componentRef.hostView);
14
+ });
15
+ });
16
+ };
17
+ };
18
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAkB,MAAM,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGxE,eAAe,CAAC,OAAoB,EAAE,EAAE;IACtC,OAAO,CACL,SAAkC,EAClC,MAAgB,EAChB,UAAoB,EACpB,EAAE;QACF,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAsB,EAAE,EAAE;YAClD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACzC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;gBACZ,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,EAAE;oBAC9C,mBAAmB,EAAE,MAAM,CAAC,QAAQ;oBACpC,WAAW,EAAE,OAAO;iBACrB,CAAC,CAAC;gBACH,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { AstroIntegration } from 'astro';
2
+ export default function (): AstroIntegration;
package/src/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import viteAngular from '@analogjs/vite-plugin-angular';
2
+ function getRenderer() {
3
+ return {
4
+ name: '@analogjs/astro-angular',
5
+ clientEntrypoint: '@analogjs/astro-angular/client.js',
6
+ serverEntrypoint: '@analogjs/astro-angular/server.js',
7
+ };
8
+ }
9
+ function getViteConfiguration() {
10
+ return {
11
+ optimizeDeps: {
12
+ include: [
13
+ '@angular/platform-browser',
14
+ '@angular/core',
15
+ '@analogjs/astro-angular/client.js',
16
+ ],
17
+ exclude: [
18
+ '@angular/platform-server',
19
+ '@analogjs/astro-angular/server.js',
20
+ ],
21
+ },
22
+ /**
23
+ *
24
+ * Why I am casting viteAngular as any
25
+ *
26
+ * The vite angular plugins is shipped as commonjs, while this astro
27
+ * integration is shipped using ESM and if you call the the default
28
+ * function, you get the following error: viteAngular is not a function.
29
+ * Attempt to use ESM for the angular vite plugin broke something, hence
30
+ * this workaround for now.
31
+ *
32
+ */
33
+ plugins: [viteAngular.default()],
34
+ };
35
+ }
36
+ export default function () {
37
+ return {
38
+ name: '@analogjs/astro-angular',
39
+ hooks: {
40
+ 'astro:config:setup': ({ addRenderer, updateConfig }) => {
41
+ addRenderer(getRenderer());
42
+ updateConfig({ vite: getViteConfiguration() });
43
+ },
44
+ },
45
+ };
46
+ }
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,+BAA+B,CAAC;AAGxD,SAAS,WAAW;IAClB,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,gBAAgB,EAAE,mCAAmC;QACrD,gBAAgB,EAAE,mCAAmC;KACtD,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB;IAC3B,OAAO;QACL,YAAY,EAAE;YACZ,OAAO,EAAE;gBACP,2BAA2B;gBAC3B,eAAe;gBACf,mCAAmC;aACpC;YACD,OAAO,EAAE;gBACP,0BAA0B;gBAC1B,mCAAmC;aACpC;SACF;QACD;;;;;;;;;;WAUG;QACH,OAAO,EAAE,CAAE,WAAmB,CAAC,OAAO,EAAE,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO;IACZ,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,EAAE;gBACtD,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC3B,YAAY,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,EAAE,CAAC,CAAC;YACjD,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import 'zone.js/dist/zone.js';
2
+ import type { ɵComponentType } from '@angular/core';
3
+ declare function check(Component: ɵComponentType<unknown>, _props: Record<string, unknown>, _children: unknown): boolean;
4
+ declare function renderToStaticMarkup(Component: ɵComponentType<unknown>, _props: Record<string, unknown>, _children: unknown): Promise<{
5
+ html: string;
6
+ }>;
7
+ declare const _default: {
8
+ check: typeof check;
9
+ renderToStaticMarkup: typeof renderToStaticMarkup;
10
+ };
11
+ export default _default;
package/src/server.js ADDED
@@ -0,0 +1,25 @@
1
+ import { __awaiter } from "tslib";
2
+ import 'zone.js/dist/zone.js';
3
+ import { renderApplication } from '@angular/platform-server';
4
+ function check(Component, _props, _children) {
5
+ return !!Component['ɵcmp'];
6
+ }
7
+ function renderToStaticMarkup(Component, _props, _children) {
8
+ return __awaiter(this, void 0, void 0, function* () {
9
+ const appId = getSelector(Component);
10
+ const document = `<${appId}></${appId}>`;
11
+ const html = yield renderApplication(Component, {
12
+ appId,
13
+ document,
14
+ });
15
+ return { html };
16
+ });
17
+ }
18
+ function getSelector(cmp) {
19
+ return cmp['ɵcmp'].selectors[0][0];
20
+ }
21
+ export default {
22
+ check,
23
+ renderToStaticMarkup,
24
+ };
25
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../packages/astro-angular/src/server.ts"],"names":[],"mappings":";AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,SAAS,KAAK,CACZ,SAAkC,EAClC,MAA+B,EAC/B,SAAkB;IAElB,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,SAAe,oBAAoB,CACjC,SAAkC,EAClC,MAA+B,EAC/B,SAAkB;;QAElB,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;QAEzC,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE;YAC9C,KAAK;YACL,QAAQ;SACT,CAAC,CAAC;QAEH,OAAO,EAAE,IAAI,EAAE,CAAC;IAClB,CAAC;CAAA;AAED,SAAS,WAAW,CAAC,GAAwB;IAC3C,OAAQ,GAAG,CAAC,MAAM,CAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,eAAe;IACb,KAAK;IACL,oBAAoB;CACrB,CAAC"}