inertia-angular 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.
- package/.npmignore +2 -0
- package/LICENSE +22 -0
- package/fesm2022/inertia-angular-server.mjs +59 -0
- package/fesm2022/inertia-angular-server.mjs.map +1 -0
- package/fesm2022/inertia-angular.mjs +2172 -0
- package/fesm2022/inertia-angular.mjs.map +1 -0
- package/package.json +62 -0
- package/readme.md +173 -0
- package/resources/boost/guidelines/core.blade.php +9 -0
- package/types/inertia-angular-server.d.ts +18 -0
- package/types/inertia-angular.d.ts +498 -0
package/.npmignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Jonathan Reinink <jonathan@reinink.ca>
|
|
4
|
+
Copyright (c) Gerard Porto <gporto@gmail.com>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export { default as createServer } from '@inertiajs/core/server';
|
|
2
|
+
import { DOCUMENT } from '@angular/common';
|
|
3
|
+
import { createApplication, provideClientHydration } from '@angular/platform-browser';
|
|
4
|
+
import { renderApplication, provideServerRendering } from '@angular/platform-server';
|
|
5
|
+
import { buildSSRBody, resolveServerHead } from '@inertiajs/core';
|
|
6
|
+
import { provideInertiaApp, App } from 'inertia-angular';
|
|
7
|
+
|
|
8
|
+
function resolveComponent(resolve, name, page) {
|
|
9
|
+
return Promise.resolve(resolve(name, page)).then((module) => 'default' in module
|
|
10
|
+
? module.default
|
|
11
|
+
: module);
|
|
12
|
+
}
|
|
13
|
+
async function renderAngularApp(page, options) {
|
|
14
|
+
const id = options.id ?? 'app';
|
|
15
|
+
const component = await resolveComponent(options.resolve, page.component, page);
|
|
16
|
+
let inertiaHead = [];
|
|
17
|
+
const props = {
|
|
18
|
+
initialPage: page,
|
|
19
|
+
initialComponent: component,
|
|
20
|
+
resolveComponent: (name, currentPage) => resolveComponent(options.resolve, name, currentPage ?? page),
|
|
21
|
+
...(options.title ? { titleCallback: options.title } : {}),
|
|
22
|
+
...(options.layout ? { defaultLayout: options.layout } : {}),
|
|
23
|
+
...(options.serverHead !== undefined ? { serverHead: options.serverHead } : {}),
|
|
24
|
+
onHeadUpdate: (elements) => {
|
|
25
|
+
inertiaHead = elements;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const document = options.document ?? `<!doctype html><html><head></head><body>${buildSSRBody(id, page, '')}</body></html>`;
|
|
29
|
+
const html = await renderApplication(async (context) => {
|
|
30
|
+
const application = await createApplication({
|
|
31
|
+
providers: [
|
|
32
|
+
provideServerRendering(),
|
|
33
|
+
provideClientHydration(),
|
|
34
|
+
provideInertiaApp(props, options.withApp?.({ ssr: true, page }) ?? []),
|
|
35
|
+
],
|
|
36
|
+
}, context);
|
|
37
|
+
const host = application.injector.get(DOCUMENT).getElementById(id);
|
|
38
|
+
if (!host)
|
|
39
|
+
throw new Error(`Unable to find the Inertia root element #${id} in the server document.`);
|
|
40
|
+
application.bootstrap(App, { hostElement: host });
|
|
41
|
+
return application;
|
|
42
|
+
}, { document, url: page.url });
|
|
43
|
+
const headMatch = html.match(/<head[^>]*>([\s\S]*?)<\/head>/i);
|
|
44
|
+
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
45
|
+
const angularHead = headMatch?.[1]?.trim();
|
|
46
|
+
const head = [
|
|
47
|
+
...resolveServerHead(page, options.serverHead),
|
|
48
|
+
...inertiaHead,
|
|
49
|
+
...(angularHead ? [angularHead] : []),
|
|
50
|
+
].filter((element, index, elements) => elements.indexOf(element) === index);
|
|
51
|
+
return { head, body: bodyMatch?.[1]?.trim() ?? '' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generated bundle index. Do not edit.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export { renderAngularApp };
|
|
59
|
+
//# sourceMappingURL=inertia-angular-server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inertia-angular-server.mjs","sources":["../../server/src/render.ts","../../server/src/inertia-angular-server.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common'\nimport { createApplication, provideClientHydration } from '@angular/platform-browser'\nimport { provideServerRendering, renderApplication } from '@angular/platform-server'\nimport { buildSSRBody, resolveServerHead, type InertiaAppSSRResponse, type Page, type PageProps } from '@inertiajs/core'\nimport {\n App,\n provideInertiaApp,\n type AngularWithApp,\n type ComponentResolver,\n type InertiaAppProps,\n type ResolvedComponent,\n} from 'inertia-angular'\n\nexport interface RenderAngularAppOptions<SharedProps extends PageProps = PageProps> {\n id?: string\n resolve: ComponentResolver\n title?: (title: string, page: Page) => string\n layout?: (name: string, page: Page) => unknown\n serverHead?: boolean | string | ((page: Page) => string[] | null | undefined)\n withApp?: AngularWithApp<SharedProps>\n document?: string\n}\n\nfunction resolveComponent(resolve: ComponentResolver, name: string, page: Page): Promise<ResolvedComponent> {\n return Promise.resolve(resolve(name, page)).then((module) =>\n 'default' in (module as { default?: ResolvedComponent })\n ? (module as { default: ResolvedComponent }).default\n : (module as ResolvedComponent),\n )\n}\n\nexport async function renderAngularApp<SharedProps extends PageProps = PageProps>(\n page: Page<SharedProps>,\n options: RenderAngularAppOptions<SharedProps>,\n): Promise<InertiaAppSSRResponse> {\n const id = options.id ?? 'app'\n const component = await resolveComponent(options.resolve, page.component, page)\n let inertiaHead: string[] = []\n const props: InertiaAppProps<SharedProps> = {\n initialPage: page,\n initialComponent: component,\n resolveComponent: (name, currentPage) => resolveComponent(options.resolve, name, currentPage ?? page),\n ...(options.title ? { titleCallback: options.title } : {}),\n ...(options.layout ? { defaultLayout: options.layout } : {}),\n ...(options.serverHead !== undefined ? { serverHead: options.serverHead } : {}),\n onHeadUpdate: (elements) => {\n inertiaHead = elements\n },\n }\n const document =\n options.document ?? `<!doctype html><html><head></head><body>${buildSSRBody(id, page, '')}</body></html>`\n const html = await renderApplication(\n async (context) => {\n const application = await createApplication(\n {\n providers: [\n provideServerRendering(),\n provideClientHydration(),\n provideInertiaApp(props, options.withApp?.({ ssr: true, page }) ?? []),\n ],\n },\n context,\n )\n const host = application.injector.get(DOCUMENT).getElementById(id)\n if (!host) throw new Error(`Unable to find the Inertia root element #${id} in the server document.`)\n application.bootstrap(App, { hostElement: host })\n return application\n },\n { document, url: page.url },\n )\n const headMatch = html.match(/<head[^>]*>([\\s\\S]*?)<\\/head>/i)\n const bodyMatch = html.match(/<body[^>]*>([\\s\\S]*?)<\\/body>/i)\n const angularHead = headMatch?.[1]?.trim()\n const head = [\n ...resolveServerHead(page, options.serverHead),\n ...inertiaHead,\n ...(angularHead ? [angularHead] : []),\n ].filter((element, index, elements) => elements.indexOf(element) === index)\n\n return { head, body: bodyMatch?.[1]?.trim() ?? '' }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAuBA,SAAS,gBAAgB,CAAC,OAA0B,EAAE,IAAY,EAAE,IAAU,EAAA;IAC5E,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KACtD,SAAS,IAAK;UACT,MAAyC,CAAC;UAC1C,MAA4B,CAClC;AACH;AAEO,eAAe,gBAAgB,CACpC,IAAuB,EACvB,OAA6C,EAAA;AAE7C,IAAA,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,KAAK;AAC9B,IAAA,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC;IAC/E,IAAI,WAAW,GAAa,EAAE;AAC9B,IAAA,MAAM,KAAK,GAAiC;AAC1C,QAAA,WAAW,EAAE,IAAI;AACjB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,gBAAgB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,IAAI,IAAI,CAAC;AACrG,QAAA,IAAI,OAAO,CAAC,KAAK,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;AAC1D,QAAA,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAC5D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC;AAC/E,QAAA,YAAY,EAAE,CAAC,QAAQ,KAAI;YACzB,WAAW,GAAG,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