@andmarruda/lpb-angular 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +33 -2
- package/fesm2022/andmarruda-lpb-angular.mjs +156 -0
- package/fesm2022/andmarruda-lpb-angular.mjs.map +1 -0
- package/index.d.ts +48 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Anderson Arruda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @andmarruda/lpb-angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Angular renderer of Laravel Page Builder pages — part of
|
|
4
|
+
[Laravel Page Builder](https://github.com/andmarruda/lpb). Renders the 48
|
|
5
|
+
built-in widgets through [`@andmarruda/lpb-core`](https://www.npmjs.com/package/@andmarruda/lpb-core)
|
|
6
|
+
and your own components for any widget name, with the page's scoped styles
|
|
7
|
+
and interactive behaviours.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @andmarruda/lpb-core @andmarruda/lpb-angular @angular/core @angular/common
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Component } from "@angular/core";
|
|
15
|
+
import { LpbPageComponent, readEmbeddedPayload } from "@andmarruda/lpb-angular";
|
|
16
|
+
|
|
17
|
+
@Component({
|
|
18
|
+
selector: "app-page",
|
|
19
|
+
standalone: true,
|
|
20
|
+
imports: [LpbPageComponent],
|
|
21
|
+
template: `<lpb-page [payload]="payload" [components]="{ hero: HeroComponent }" />`,
|
|
22
|
+
})
|
|
23
|
+
export class PageComponent {
|
|
24
|
+
payload = readEmbeddedPayload();
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add `@andmarruda/lpb-core/styles.css` to the application styles. Works with Angular
|
|
29
|
+
server rendering (Renderer2); for external frontends fetch with `LpbClient`.
|
|
30
|
+
|
|
31
|
+
Components receive the widget's `config` and `instance`; a component with
|
|
32
|
+
the name of a built-in widget replaces it.
|
|
33
|
+
|
|
34
|
+
MIT © Anderson Arruda
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, ElementRef, Renderer2, EnvironmentInjector, ApplicationRef, PLATFORM_ID, createComponent, Input, ChangeDetectionStrategy, ViewEncapsulation, Component } from '@angular/core';
|
|
4
|
+
import { DEFAULT_BREAKPOINTS, treeCss, renderBlocks, enhance } from '@andmarruda/lpb-core';
|
|
5
|
+
export { LpbClient, readEmbeddedPayload } from '@andmarruda/lpb-core';
|
|
6
|
+
|
|
7
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
8
|
+
/**
|
|
9
|
+
* Builds core virtual nodes with Renderer2, so it works in the browser and
|
|
10
|
+
* with Angular server rendering. Slots get an empty host element that the
|
|
11
|
+
* caller fills with an application component.
|
|
12
|
+
*/
|
|
13
|
+
function buildNodes(renderer, parent, nodes, onSlot, svg = false) {
|
|
14
|
+
for (const node of nodes) {
|
|
15
|
+
if (node.kind === 'text') {
|
|
16
|
+
renderer.appendChild(parent, renderer.createText(node.text));
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (node.kind === 'slot') {
|
|
20
|
+
const host = renderer.createElement('div');
|
|
21
|
+
renderer.setAttribute(host, 'class', node.className);
|
|
22
|
+
renderer.setAttribute(host, 'data-lpb-widget', node.instance.widget);
|
|
23
|
+
renderer.appendChild(parent, host);
|
|
24
|
+
onSlot(node, host);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const inSvg = svg || node.tag === 'svg';
|
|
28
|
+
const element = renderer.createElement(node.tag, inSvg ? SVG_NS : undefined);
|
|
29
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
30
|
+
if (value === null || value === undefined || value === false)
|
|
31
|
+
continue;
|
|
32
|
+
renderer.setAttribute(element, name, value === true ? '' : String(value));
|
|
33
|
+
}
|
|
34
|
+
if (node.html !== undefined) {
|
|
35
|
+
// Trusted: rich text is sanitised by the core; the html widget is raw by design
|
|
36
|
+
renderer.setProperty(element, 'innerHTML', node.html);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
buildNodes(renderer, element, node.children, onSlot, inSvg);
|
|
40
|
+
}
|
|
41
|
+
renderer.appendChild(parent, element);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Renders a page payload: blocks, built-in widgets (from @andmarruda/lpb-core) and the
|
|
47
|
+
* application's widget components (inputs: config, instance), with the
|
|
48
|
+
* page's scoped CSS.
|
|
49
|
+
*
|
|
50
|
+
* <lpb-page [payload]="page" [components]="{ hero: HeroComponent }" />
|
|
51
|
+
*/
|
|
52
|
+
class LpbPageComponent {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.payload = null;
|
|
55
|
+
/** Angular components by widget name: custom widgets or overrides of built-in ones. */
|
|
56
|
+
this.components = {};
|
|
57
|
+
this.breakpoints = DEFAULT_BREAKPOINTS;
|
|
58
|
+
/** Skip the interactive behaviours (e.g. inside an editor canvas). */
|
|
59
|
+
this.static = false;
|
|
60
|
+
this.host = inject((ElementRef));
|
|
61
|
+
this.renderer = inject(Renderer2);
|
|
62
|
+
this.injector = inject(EnvironmentInjector);
|
|
63
|
+
this.appRef = inject(ApplicationRef);
|
|
64
|
+
this.browser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
65
|
+
this.widgets = [];
|
|
66
|
+
this.cleanup = () => { };
|
|
67
|
+
this.viewReady = false;
|
|
68
|
+
}
|
|
69
|
+
ngOnChanges() {
|
|
70
|
+
this.render();
|
|
71
|
+
}
|
|
72
|
+
ngAfterViewInit() {
|
|
73
|
+
this.viewReady = true;
|
|
74
|
+
this.enhance();
|
|
75
|
+
}
|
|
76
|
+
ngOnDestroy() {
|
|
77
|
+
this.clear();
|
|
78
|
+
}
|
|
79
|
+
render() {
|
|
80
|
+
this.clear();
|
|
81
|
+
const element = this.host.nativeElement;
|
|
82
|
+
if (!this.payload)
|
|
83
|
+
return;
|
|
84
|
+
const blocks = this.payload.blocks ?? [];
|
|
85
|
+
const css = treeCss(blocks, this.breakpoints);
|
|
86
|
+
if (css) {
|
|
87
|
+
const style = this.renderer.createElement('style');
|
|
88
|
+
this.renderer.setAttribute(style, 'data-lpb-styles', '');
|
|
89
|
+
this.renderer.appendChild(style, this.renderer.createText(css));
|
|
90
|
+
this.renderer.appendChild(element, style);
|
|
91
|
+
}
|
|
92
|
+
const page = this.renderer.createElement('div');
|
|
93
|
+
this.renderer.setAttribute(page, 'class', 'lpb-page');
|
|
94
|
+
const nodes = renderBlocks(blocks, { components: Object.keys(this.components), renderers: this.renderers, resolveMedia: this.resolveMedia, apiBase: this.apiBase });
|
|
95
|
+
buildNodes(this.renderer, page, nodes, (slot, slotHost) => {
|
|
96
|
+
const type = this.components[slot.instance.widget];
|
|
97
|
+
if (!type)
|
|
98
|
+
return;
|
|
99
|
+
const ref = createComponent(type, { environmentInjector: this.injector });
|
|
100
|
+
ref.setInput('config', slot.instance.config);
|
|
101
|
+
ref.setInput('instance', slot.instance);
|
|
102
|
+
this.appRef.attachView(ref.hostView);
|
|
103
|
+
ref.changeDetectorRef.detectChanges();
|
|
104
|
+
this.renderer.appendChild(slotHost, ref.location.nativeElement);
|
|
105
|
+
this.widgets.push(ref);
|
|
106
|
+
});
|
|
107
|
+
this.renderer.appendChild(element, page);
|
|
108
|
+
if (this.viewReady)
|
|
109
|
+
this.enhance();
|
|
110
|
+
}
|
|
111
|
+
enhance() {
|
|
112
|
+
this.cleanup();
|
|
113
|
+
this.cleanup = this.browser && !this.static ? enhance(this.host.nativeElement.querySelector('.lpb-page')) : () => { };
|
|
114
|
+
}
|
|
115
|
+
clear() {
|
|
116
|
+
this.cleanup();
|
|
117
|
+
this.cleanup = () => { };
|
|
118
|
+
this.widgets.splice(0).forEach((ref) => { this.appRef.detachView(ref.hostView); ref.destroy(); });
|
|
119
|
+
const element = this.host.nativeElement;
|
|
120
|
+
while (element.firstChild)
|
|
121
|
+
this.renderer.removeChild(element, element.firstChild);
|
|
122
|
+
}
|
|
123
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: LpbPageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
124
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.34", type: LpbPageComponent, isStandalone: true, selector: "lpb-page", inputs: { payload: "payload", components: "components", renderers: "renderers", resolveMedia: "resolveMedia", apiBase: "apiBase", breakpoints: "breakpoints", static: "static" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
125
|
+
}
|
|
126
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: LpbPageComponent, decorators: [{
|
|
127
|
+
type: Component,
|
|
128
|
+
args: [{
|
|
129
|
+
selector: 'lpb-page',
|
|
130
|
+
standalone: true,
|
|
131
|
+
template: '',
|
|
132
|
+
encapsulation: ViewEncapsulation.None,
|
|
133
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
134
|
+
}]
|
|
135
|
+
}], propDecorators: { payload: [{
|
|
136
|
+
type: Input
|
|
137
|
+
}], components: [{
|
|
138
|
+
type: Input
|
|
139
|
+
}], renderers: [{
|
|
140
|
+
type: Input
|
|
141
|
+
}], resolveMedia: [{
|
|
142
|
+
type: Input
|
|
143
|
+
}], apiBase: [{
|
|
144
|
+
type: Input
|
|
145
|
+
}], breakpoints: [{
|
|
146
|
+
type: Input
|
|
147
|
+
}], static: [{
|
|
148
|
+
type: Input
|
|
149
|
+
}] } });
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Generated bundle index. Do not edit.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
export { LpbPageComponent, buildNodes };
|
|
156
|
+
//# sourceMappingURL=andmarruda-lpb-angular.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"andmarruda-lpb-angular.mjs","sources":["../../src/dom.ts","../../src/lpb-page.component.ts","../../src/andmarruda-lpb-angular.ts"],"sourcesContent":["import type { Renderer2 } from '@angular/core';\nimport type { SlotNode, VNode } from '@andmarruda/lpb-core';\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\n/**\n * Builds core virtual nodes with Renderer2, so it works in the browser and\n * with Angular server rendering. Slots get an empty host element that the\n * caller fills with an application component.\n */\nexport function buildNodes(renderer: Renderer2, parent: unknown, nodes: VNode[], onSlot: (slot: SlotNode, host: unknown) => void, svg = false): void {\n for (const node of nodes) {\n if (node.kind === 'text') {\n renderer.appendChild(parent, renderer.createText(node.text));\n continue;\n }\n if (node.kind === 'slot') {\n const host = renderer.createElement('div');\n renderer.setAttribute(host, 'class', node.className);\n renderer.setAttribute(host, 'data-lpb-widget', node.instance.widget);\n renderer.appendChild(parent, host);\n onSlot(node, host);\n continue;\n }\n\n const inSvg = svg || node.tag === 'svg';\n const element = renderer.createElement(node.tag, inSvg ? SVG_NS : undefined);\n for (const [name, value] of Object.entries(node.attrs)) {\n if (value === null || value === undefined || value === false) continue;\n renderer.setAttribute(element, name, value === true ? '' : String(value));\n }\n if (node.html !== undefined) {\n // Trusted: rich text is sanitised by the core; the html widget is raw by design\n renderer.setProperty(element, 'innerHTML', node.html);\n } else {\n buildNodes(renderer, element, node.children, onSlot, inSvg);\n }\n renderer.appendChild(parent, element);\n }\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n ChangeDetectionStrategy, Component, ElementRef, EnvironmentInjector, Input, PLATFORM_ID, Renderer2, ViewEncapsulation,\n createComponent, inject, type AfterViewInit, type ComponentRef, type OnChanges, type OnDestroy, type Type, ApplicationRef,\n} from '@angular/core';\nimport { DEFAULT_BREAKPOINTS, enhance, renderBlocks, treeCss, type Breakpoints, type Media, type PagePayload, type WidgetRenderer } from '@andmarruda/lpb-core';\nimport { buildNodes } from './dom';\n\n/**\n * Renders a page payload: blocks, built-in widgets (from @andmarruda/lpb-core) and the\n * application's widget components (inputs: config, instance), with the\n * page's scoped CSS.\n *\n * <lpb-page [payload]=\"page\" [components]=\"{ hero: HeroComponent }\" />\n */\n@Component({\n selector: 'lpb-page',\n standalone: true,\n template: '',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class LpbPageComponent implements OnChanges, AfterViewInit, OnDestroy {\n @Input() payload: Pick<PagePayload, 'blocks'> | null | undefined = null;\n /** Angular components by widget name: custom widgets or overrides of built-in ones. */\n @Input() components: Record<string, Type<unknown>> = {};\n @Input() renderers?: Record<string, WidgetRenderer>;\n @Input() resolveMedia?: (id: string | number) => Media | null;\n @Input() apiBase?: string;\n @Input() breakpoints: Breakpoints = DEFAULT_BREAKPOINTS;\n /** Skip the interactive behaviours (e.g. inside an editor canvas). */\n @Input() static = false;\n\n private readonly host = inject(ElementRef<HTMLElement>);\n private readonly renderer = inject(Renderer2);\n private readonly injector = inject(EnvironmentInjector);\n private readonly appRef = inject(ApplicationRef);\n private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));\n private widgets: ComponentRef<unknown>[] = [];\n private cleanup: () => void = () => {};\n private viewReady = false;\n\n ngOnChanges(): void {\n this.render();\n }\n\n ngAfterViewInit(): void {\n this.viewReady = true;\n this.enhance();\n }\n\n ngOnDestroy(): void {\n this.clear();\n }\n\n private render(): void {\n this.clear();\n const element = this.host.nativeElement;\n if (!this.payload) return;\n\n const blocks = this.payload.blocks ?? [];\n const css = treeCss(blocks, this.breakpoints);\n if (css) {\n const style = this.renderer.createElement('style');\n this.renderer.setAttribute(style, 'data-lpb-styles', '');\n this.renderer.appendChild(style, this.renderer.createText(css));\n this.renderer.appendChild(element, style);\n }\n\n const page = this.renderer.createElement('div');\n this.renderer.setAttribute(page, 'class', 'lpb-page');\n const nodes = renderBlocks(blocks, { components: Object.keys(this.components), renderers: this.renderers, resolveMedia: this.resolveMedia, apiBase: this.apiBase });\n buildNodes(this.renderer, page, nodes, (slot, slotHost) => {\n const type = this.components[slot.instance.widget];\n if (!type) return;\n const ref = createComponent(type, { environmentInjector: this.injector });\n ref.setInput('config', slot.instance.config);\n ref.setInput('instance', slot.instance);\n this.appRef.attachView(ref.hostView);\n ref.changeDetectorRef.detectChanges();\n this.renderer.appendChild(slotHost, ref.location.nativeElement);\n this.widgets.push(ref);\n });\n this.renderer.appendChild(element, page);\n if (this.viewReady) this.enhance();\n }\n\n private enhance(): void {\n this.cleanup();\n this.cleanup = this.browser && !this.static ? enhance(this.host.nativeElement.querySelector('.lpb-page')) : () => {};\n }\n\n private clear(): void {\n this.cleanup();\n this.cleanup = () => {};\n this.widgets.splice(0).forEach((ref) => { this.appRef.detachView(ref.hostView); ref.destroy(); });\n const element = this.host.nativeElement;\n while (element.firstChild) this.renderer.removeChild(element, element.firstChild);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAGA,MAAM,MAAM,GAAG,4BAA4B;AAE3C;;;;AAIG;AACG,SAAU,UAAU,CAAC,QAAmB,EAAE,MAAe,EAAE,KAAc,EAAE,MAA+C,EAAE,GAAG,GAAG,KAAK,EAAA;AAC3I,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;AACxB,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;AACxB,YAAA,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5D;QACF;AACA,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;YACxB,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;YAC1C,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;AACpD,YAAA,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AACpE,YAAA,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;AAClC,YAAA,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;YAClB;QACF;QAEA,MAAM,KAAK,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,KAAK,KAAK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AAChB,oBAAA,QAAQ,EAAE,EAAE;oBACZ,aAAa,EAAE,iBAAiB,CAAC,IAAI;oBACrC,eAAe,EAAE,uBAAuB,CAAC,MAAM;AAChD,iBAAA;;sBAEE;;sBAEA;;sBACA;;sBACA;;sBACA;;sBACA;;sBAEA;;;AC/BH;;AAEG;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { OnChanges, AfterViewInit, OnDestroy, Type, Renderer2 } from '@angular/core';
|
|
3
|
+
import { PagePayload, WidgetRenderer, Media, Breakpoints, VNode, SlotNode } from '@andmarruda/lpb-core';
|
|
4
|
+
export { LpbClient, readEmbeddedPayload } from '@andmarruda/lpb-core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders a page payload: blocks, built-in widgets (from @andmarruda/lpb-core) and the
|
|
8
|
+
* application's widget components (inputs: config, instance), with the
|
|
9
|
+
* page's scoped CSS.
|
|
10
|
+
*
|
|
11
|
+
* <lpb-page [payload]="page" [components]="{ hero: HeroComponent }" />
|
|
12
|
+
*/
|
|
13
|
+
declare class LpbPageComponent implements OnChanges, AfterViewInit, OnDestroy {
|
|
14
|
+
payload: Pick<PagePayload, 'blocks'> | null | undefined;
|
|
15
|
+
/** Angular components by widget name: custom widgets or overrides of built-in ones. */
|
|
16
|
+
components: Record<string, Type<unknown>>;
|
|
17
|
+
renderers?: Record<string, WidgetRenderer>;
|
|
18
|
+
resolveMedia?: (id: string | number) => Media | null;
|
|
19
|
+
apiBase?: string;
|
|
20
|
+
breakpoints: Breakpoints;
|
|
21
|
+
/** Skip the interactive behaviours (e.g. inside an editor canvas). */
|
|
22
|
+
static: boolean;
|
|
23
|
+
private readonly host;
|
|
24
|
+
private readonly renderer;
|
|
25
|
+
private readonly injector;
|
|
26
|
+
private readonly appRef;
|
|
27
|
+
private readonly browser;
|
|
28
|
+
private widgets;
|
|
29
|
+
private cleanup;
|
|
30
|
+
private viewReady;
|
|
31
|
+
ngOnChanges(): void;
|
|
32
|
+
ngAfterViewInit(): void;
|
|
33
|
+
ngOnDestroy(): void;
|
|
34
|
+
private render;
|
|
35
|
+
private enhance;
|
|
36
|
+
private clear;
|
|
37
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LpbPageComponent, never>;
|
|
38
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<LpbPageComponent, "lpb-page", never, { "payload": { "alias": "payload"; "required": false; }; "components": { "alias": "components"; "required": false; }; "renderers": { "alias": "renderers"; "required": false; }; "resolveMedia": { "alias": "resolveMedia"; "required": false; }; "apiBase": { "alias": "apiBase"; "required": false; }; "breakpoints": { "alias": "breakpoints"; "required": false; }; "static": { "alias": "static"; "required": false; }; }, {}, never, never, true, never>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds core virtual nodes with Renderer2, so it works in the browser and
|
|
43
|
+
* with Angular server rendering. Slots get an empty host element that the
|
|
44
|
+
* caller fills with an application component.
|
|
45
|
+
*/
|
|
46
|
+
declare function buildNodes(renderer: Renderer2, parent: unknown, nodes: VNode[], onSlot: (slot: SlotNode, host: unknown) => void, svg?: boolean): void;
|
|
47
|
+
|
|
48
|
+
export { LpbPageComponent, buildNodes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andmarruda/lpb-angular",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Angular renderer of Laravel Page Builder pages",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"laravel",
|
|
7
|
+
"page-builder",
|
|
8
|
+
"lpb",
|
|
9
|
+
"cms",
|
|
10
|
+
"angular"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Anderson Arruda",
|
|
14
|
+
"homepage": "https://github.com/andmarruda/lpb-frontend/tree/main/packages/angular#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/andmarruda/lpb-frontend.git",
|
|
18
|
+
"directory": "packages/angular"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/andmarruda/lpb-frontend/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@andmarruda/lpb-core": "0.0.1",
|
|
29
|
+
"tslib": "^2.6.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@angular/common": ">=18",
|
|
33
|
+
"@angular/core": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"module": "fesm2022/andmarruda-lpb-angular.mjs",
|
|
39
|
+
"typings": "index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
"./package.json": {
|
|
42
|
+
"default": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./index.d.ts",
|
|
46
|
+
"default": "./fesm2022/andmarruda-lpb-angular.mjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"sideEffects": false
|
|
6
50
|
}
|