@sitecore-jss/sitecore-jss-angular 19.0.2 → 19.0.3-canary.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/LICENSE.txt +202 -202
- package/README.md +5 -5
- package/dist/README.md +5 -5
- package/dist/bundles/sitecore-jss-sitecore-jss-angular.umd.js +1363 -1363
- package/dist/components/date.directive.d.ts +17 -17
- package/dist/components/file.directive.d.ts +14 -14
- package/dist/components/generic-link.directive.d.ts +18 -18
- package/dist/components/image.directive.d.ts +32 -32
- package/dist/components/link.directive.d.ts +22 -22
- package/dist/components/missing-component.component.d.ts +4 -4
- package/dist/components/placeholder-loading.directive.d.ts +5 -5
- package/dist/components/placeholder.component.d.ts +45 -45
- package/dist/components/placeholder.token.d.ts +30 -30
- package/dist/components/raw.component.d.ts +9 -9
- package/dist/components/render-component.component.d.ts +31 -31
- package/dist/components/render-each.directive.d.ts +5 -5
- package/dist/components/render-empty.directive.d.ts +5 -5
- package/dist/components/rendering-field.d.ts +40 -40
- package/dist/components/rendering.d.ts +5 -5
- package/dist/components/rich-text.directive.d.ts +12 -12
- package/dist/components/router-link.directive.d.ts +16 -16
- package/dist/components/text.directive.d.ts +13 -13
- package/dist/esm2015/components/date.directive.js +52 -52
- package/dist/esm2015/components/file.directive.js +44 -44
- package/dist/esm2015/components/generic-link.directive.js +57 -57
- package/dist/esm2015/components/image.directive.js +122 -122
- package/dist/esm2015/components/link.directive.js +101 -101
- package/dist/esm2015/components/missing-component.component.js +12 -12
- package/dist/esm2015/components/placeholder-loading.directive.js +14 -14
- package/dist/esm2015/components/placeholder.component.js +191 -191
- package/dist/esm2015/components/placeholder.token.js +20 -20
- package/dist/esm2015/components/raw.component.js +36 -36
- package/dist/esm2015/components/render-component.component.js +88 -88
- package/dist/esm2015/components/render-each.directive.js +14 -14
- package/dist/esm2015/components/render-empty.directive.js +14 -14
- package/dist/esm2015/components/rendering-field.js +1 -1
- package/dist/esm2015/components/rendering.js +7 -7
- package/dist/esm2015/components/rich-text.directive.js +40 -40
- package/dist/esm2015/components/router-link.directive.js +43 -43
- package/dist/esm2015/components/text.directive.js +53 -53
- package/dist/esm2015/jss-component-factory.service.js +87 -87
- package/dist/esm2015/lib.module.js +110 -110
- package/dist/esm2015/public_api.js +13 -13
- package/dist/esm2015/sitecore-jss-sitecore-jss-angular.js +12 -12
- package/dist/fesm2015/sitecore-jss-sitecore-jss-angular.js +1027 -1027
- package/dist/jss-component-factory.service.d.ts +21 -21
- package/dist/lib.module.d.ts +24 -24
- package/dist/package.json +2 -2
- package/dist/public_api.d.ts +14 -14
- package/dist/sitecore-jss-sitecore-jss-angular.d.ts +12 -12
- package/package.json +3 -3
- package/typings/README.md +2 -2
|
@@ -7,898 +7,898 @@ import { Observable } from 'rxjs';
|
|
|
7
7
|
import { takeWhile } from 'rxjs/operators';
|
|
8
8
|
import { DatePipe, CommonModule } from '@angular/common';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* File fields cannot be managed via the EE. We never output "editable."
|
|
12
|
-
*/
|
|
13
|
-
class FileDirective {
|
|
14
|
-
constructor(viewContainer, templateRef) {
|
|
15
|
-
this.viewContainer = viewContainer;
|
|
16
|
-
this.templateRef = templateRef;
|
|
17
|
-
}
|
|
18
|
-
ngOnChanges(changes) {
|
|
19
|
-
if (changes.field) {
|
|
20
|
-
if (!this.viewRef) {
|
|
21
|
-
this.viewContainer.clear();
|
|
22
|
-
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
23
|
-
}
|
|
24
|
-
this.updateView();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
updateView() {
|
|
28
|
-
const field = this.field;
|
|
29
|
-
if (!field || (!field.value && !field.src)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const file = field.src ? field : field.value;
|
|
33
|
-
this.viewRef.rootNodes.forEach((node) => {
|
|
34
|
-
if (!file)
|
|
35
|
-
return;
|
|
36
|
-
node.href = file.src;
|
|
37
|
-
if (node.innerHTML === '') {
|
|
38
|
-
node.innerHTML = file.title || file.displayName;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
FileDirective.decorators = [
|
|
44
|
-
{ type: Directive, args: [{ selector: '[scFile]' },] }
|
|
45
|
-
];
|
|
46
|
-
FileDirective.ctorParameters = () => [
|
|
47
|
-
{ type: ViewContainerRef },
|
|
48
|
-
{ type: TemplateRef }
|
|
49
|
-
];
|
|
50
|
-
FileDirective.propDecorators = {
|
|
51
|
-
field: [{ type: Input, args: ['scFile',] }]
|
|
10
|
+
/**
|
|
11
|
+
* File fields cannot be managed via the EE. We never output "editable."
|
|
12
|
+
*/
|
|
13
|
+
class FileDirective {
|
|
14
|
+
constructor(viewContainer, templateRef) {
|
|
15
|
+
this.viewContainer = viewContainer;
|
|
16
|
+
this.templateRef = templateRef;
|
|
17
|
+
}
|
|
18
|
+
ngOnChanges(changes) {
|
|
19
|
+
if (changes.field) {
|
|
20
|
+
if (!this.viewRef) {
|
|
21
|
+
this.viewContainer.clear();
|
|
22
|
+
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
23
|
+
}
|
|
24
|
+
this.updateView();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
updateView() {
|
|
28
|
+
const field = this.field;
|
|
29
|
+
if (!field || (!field.value && !field.src)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const file = field.src ? field : field.value;
|
|
33
|
+
this.viewRef.rootNodes.forEach((node) => {
|
|
34
|
+
if (!file)
|
|
35
|
+
return;
|
|
36
|
+
node.href = file.src;
|
|
37
|
+
if (node.innerHTML === '') {
|
|
38
|
+
node.innerHTML = file.title || file.displayName;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
FileDirective.decorators = [
|
|
44
|
+
{ type: Directive, args: [{ selector: '[scFile]' },] }
|
|
45
|
+
];
|
|
46
|
+
FileDirective.ctorParameters = () => [
|
|
47
|
+
{ type: ViewContainerRef },
|
|
48
|
+
{ type: TemplateRef }
|
|
49
|
+
];
|
|
50
|
+
FileDirective.propDecorators = {
|
|
51
|
+
field: [{ type: Input, args: ['scFile',] }]
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
class ImageDirective {
|
|
55
|
-
constructor(viewContainer, templateRef, renderer, elementRef) {
|
|
56
|
-
this.viewContainer = viewContainer;
|
|
57
|
-
this.templateRef = templateRef;
|
|
58
|
-
this.renderer = renderer;
|
|
59
|
-
this.elementRef = elementRef;
|
|
60
|
-
this.inlineRef = null;
|
|
61
|
-
this.editable = true;
|
|
62
|
-
this.urlParams = {};
|
|
63
|
-
this.attrs = {};
|
|
64
|
-
}
|
|
65
|
-
ngOnChanges(changes) {
|
|
66
|
-
if (changes.field || changes.editable || changes.urlParams || changes.attrs) {
|
|
67
|
-
this.viewContainer.clear();
|
|
68
|
-
if (this.inlineRef) {
|
|
69
|
-
this.inlineRef.remove();
|
|
70
|
-
this.inlineRef = null;
|
|
71
|
-
}
|
|
72
|
-
this.updateView();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
updateView() {
|
|
76
|
-
const overrideAttrs = Object.assign(Object.assign({}, this.getElementAttrs()), this.attrs);
|
|
77
|
-
const media = this.field;
|
|
78
|
-
if (!media || (!media.editable && !media.value && !media.src)) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
let attrs = {};
|
|
82
|
-
// we likely have an experience editor value, should be a string
|
|
83
|
-
if (this.editable && media.editable) {
|
|
84
|
-
const foundImg = mediaApi.findEditorImageTag(media.editable);
|
|
85
|
-
if (!foundImg) {
|
|
86
|
-
return this.renderInlineWrapper(media.editable);
|
|
87
|
-
}
|
|
88
|
-
attrs = this.getImageAttrs(foundImg.attrs, overrideAttrs, this.urlParams);
|
|
89
|
-
if (!attrs) {
|
|
90
|
-
return this.renderInlineWrapper(media.editable);
|
|
91
|
-
}
|
|
92
|
-
const tempImg = this.renderer.createElement('img');
|
|
93
|
-
Object.entries(attrs).forEach(([key, attrValue]) => tempImg.setAttribute(key, attrValue));
|
|
94
|
-
const editableMarkup = media.editable.replace(foundImg.imgTag, tempImg.outerHTML);
|
|
95
|
-
return this.renderInlineWrapper(editableMarkup);
|
|
96
|
-
}
|
|
97
|
-
// some wise-guy/gal is passing in a 'raw' image object value
|
|
98
|
-
const img = media.src ? media : media.value;
|
|
99
|
-
if (!img) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
attrs = this.getImageAttrs(img, overrideAttrs, this.urlParams);
|
|
103
|
-
if (attrs) {
|
|
104
|
-
this.renderTemplate(attrs);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
getImageAttrs(fieldAttrs, parsedAttrs, imageParams) {
|
|
108
|
-
const combinedAttrs = Object.assign(Object.assign({}, fieldAttrs), parsedAttrs);
|
|
109
|
-
// eslint-disable-next-line prefer-const
|
|
110
|
-
let { src, srcSet } = combinedAttrs, otherAttrs = __rest(combinedAttrs, ["src", "srcSet"]);
|
|
111
|
-
if (!src) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
const newAttrs = Object.assign({}, otherAttrs);
|
|
115
|
-
// update image URL for jss handler and image rendering params
|
|
116
|
-
src = mediaApi.updateImageUrl(src, imageParams, this.mediaUrlPrefix);
|
|
117
|
-
if (srcSet) {
|
|
118
|
-
// replace with HTML-formatted srcset, including updated image URLs
|
|
119
|
-
newAttrs.srcSet = mediaApi.getSrcSet(src, srcSet, imageParams, this.mediaUrlPrefix);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
newAttrs.src = src;
|
|
123
|
-
}
|
|
124
|
-
return newAttrs;
|
|
125
|
-
}
|
|
126
|
-
renderTemplate(imageProps) {
|
|
127
|
-
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
128
|
-
viewRef.rootNodes.forEach((node) => {
|
|
129
|
-
Object.entries(imageProps).forEach(([key, imgPropVal]) => this.renderer.setAttribute(node, key, imgPropVal));
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
getElementAttrs() {
|
|
133
|
-
const view = this.templateRef.createEmbeddedView(null);
|
|
134
|
-
const element = view.rootNodes[0];
|
|
135
|
-
if (!element) {
|
|
136
|
-
return {};
|
|
137
|
-
}
|
|
138
|
-
const attrs = {};
|
|
139
|
-
for (let i = 0; i < element.attributes.length; i++) {
|
|
140
|
-
const attr = element.attributes.item(i);
|
|
141
|
-
if (attr) {
|
|
142
|
-
attrs[attr.name] = attr.value;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return attrs;
|
|
146
|
-
}
|
|
147
|
-
renderInlineWrapper(editable) {
|
|
148
|
-
const span = this.renderer.createElement('span');
|
|
149
|
-
span.className = 'sc-image-wrapper';
|
|
150
|
-
span.innerHTML = editable;
|
|
151
|
-
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
152
|
-
this.renderer.insertBefore(parentNode, span, this.elementRef.nativeElement);
|
|
153
|
-
parentNode.removeChild(this.elementRef.nativeElement);
|
|
154
|
-
this.inlineRef = span;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
ImageDirective.decorators = [
|
|
158
|
-
{ type: Directive, args: [{ selector: '[scImage]' },] }
|
|
159
|
-
];
|
|
160
|
-
ImageDirective.ctorParameters = () => [
|
|
161
|
-
{ type: ViewContainerRef },
|
|
162
|
-
{ type: TemplateRef },
|
|
163
|
-
{ type: Renderer2 },
|
|
164
|
-
{ type: ElementRef }
|
|
165
|
-
];
|
|
166
|
-
ImageDirective.propDecorators = {
|
|
167
|
-
field: [{ type: Input, args: ['scImage',] }],
|
|
168
|
-
editable: [{ type: Input, args: ['scImageEditable',] }],
|
|
169
|
-
mediaUrlPrefix: [{ type: Input, args: ['scImageMediaUrlPrefix',] }],
|
|
170
|
-
urlParams: [{ type: Input, args: ['scImageUrlParams',] }],
|
|
171
|
-
attrs: [{ type: Input, args: ['scImageAttrs',] }]
|
|
54
|
+
class ImageDirective {
|
|
55
|
+
constructor(viewContainer, templateRef, renderer, elementRef) {
|
|
56
|
+
this.viewContainer = viewContainer;
|
|
57
|
+
this.templateRef = templateRef;
|
|
58
|
+
this.renderer = renderer;
|
|
59
|
+
this.elementRef = elementRef;
|
|
60
|
+
this.inlineRef = null;
|
|
61
|
+
this.editable = true;
|
|
62
|
+
this.urlParams = {};
|
|
63
|
+
this.attrs = {};
|
|
64
|
+
}
|
|
65
|
+
ngOnChanges(changes) {
|
|
66
|
+
if (changes.field || changes.editable || changes.urlParams || changes.attrs) {
|
|
67
|
+
this.viewContainer.clear();
|
|
68
|
+
if (this.inlineRef) {
|
|
69
|
+
this.inlineRef.remove();
|
|
70
|
+
this.inlineRef = null;
|
|
71
|
+
}
|
|
72
|
+
this.updateView();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
updateView() {
|
|
76
|
+
const overrideAttrs = Object.assign(Object.assign({}, this.getElementAttrs()), this.attrs);
|
|
77
|
+
const media = this.field;
|
|
78
|
+
if (!media || (!media.editable && !media.value && !media.src)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let attrs = {};
|
|
82
|
+
// we likely have an experience editor value, should be a string
|
|
83
|
+
if (this.editable && media.editable) {
|
|
84
|
+
const foundImg = mediaApi.findEditorImageTag(media.editable);
|
|
85
|
+
if (!foundImg) {
|
|
86
|
+
return this.renderInlineWrapper(media.editable);
|
|
87
|
+
}
|
|
88
|
+
attrs = this.getImageAttrs(foundImg.attrs, overrideAttrs, this.urlParams);
|
|
89
|
+
if (!attrs) {
|
|
90
|
+
return this.renderInlineWrapper(media.editable);
|
|
91
|
+
}
|
|
92
|
+
const tempImg = this.renderer.createElement('img');
|
|
93
|
+
Object.entries(attrs).forEach(([key, attrValue]) => tempImg.setAttribute(key, attrValue));
|
|
94
|
+
const editableMarkup = media.editable.replace(foundImg.imgTag, tempImg.outerHTML);
|
|
95
|
+
return this.renderInlineWrapper(editableMarkup);
|
|
96
|
+
}
|
|
97
|
+
// some wise-guy/gal is passing in a 'raw' image object value
|
|
98
|
+
const img = media.src ? media : media.value;
|
|
99
|
+
if (!img) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
attrs = this.getImageAttrs(img, overrideAttrs, this.urlParams);
|
|
103
|
+
if (attrs) {
|
|
104
|
+
this.renderTemplate(attrs);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
getImageAttrs(fieldAttrs, parsedAttrs, imageParams) {
|
|
108
|
+
const combinedAttrs = Object.assign(Object.assign({}, fieldAttrs), parsedAttrs);
|
|
109
|
+
// eslint-disable-next-line prefer-const
|
|
110
|
+
let { src, srcSet } = combinedAttrs, otherAttrs = __rest(combinedAttrs, ["src", "srcSet"]);
|
|
111
|
+
if (!src) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const newAttrs = Object.assign({}, otherAttrs);
|
|
115
|
+
// update image URL for jss handler and image rendering params
|
|
116
|
+
src = mediaApi.updateImageUrl(src, imageParams, this.mediaUrlPrefix);
|
|
117
|
+
if (srcSet) {
|
|
118
|
+
// replace with HTML-formatted srcset, including updated image URLs
|
|
119
|
+
newAttrs.srcSet = mediaApi.getSrcSet(src, srcSet, imageParams, this.mediaUrlPrefix);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
newAttrs.src = src;
|
|
123
|
+
}
|
|
124
|
+
return newAttrs;
|
|
125
|
+
}
|
|
126
|
+
renderTemplate(imageProps) {
|
|
127
|
+
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
128
|
+
viewRef.rootNodes.forEach((node) => {
|
|
129
|
+
Object.entries(imageProps).forEach(([key, imgPropVal]) => this.renderer.setAttribute(node, key, imgPropVal));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
getElementAttrs() {
|
|
133
|
+
const view = this.templateRef.createEmbeddedView(null);
|
|
134
|
+
const element = view.rootNodes[0];
|
|
135
|
+
if (!element) {
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
const attrs = {};
|
|
139
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
140
|
+
const attr = element.attributes.item(i);
|
|
141
|
+
if (attr) {
|
|
142
|
+
attrs[attr.name] = attr.value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return attrs;
|
|
146
|
+
}
|
|
147
|
+
renderInlineWrapper(editable) {
|
|
148
|
+
const span = this.renderer.createElement('span');
|
|
149
|
+
span.className = 'sc-image-wrapper';
|
|
150
|
+
span.innerHTML = editable;
|
|
151
|
+
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
152
|
+
this.renderer.insertBefore(parentNode, span, this.elementRef.nativeElement);
|
|
153
|
+
parentNode.removeChild(this.elementRef.nativeElement);
|
|
154
|
+
this.inlineRef = span;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
ImageDirective.decorators = [
|
|
158
|
+
{ type: Directive, args: [{ selector: '[scImage]' },] }
|
|
159
|
+
];
|
|
160
|
+
ImageDirective.ctorParameters = () => [
|
|
161
|
+
{ type: ViewContainerRef },
|
|
162
|
+
{ type: TemplateRef },
|
|
163
|
+
{ type: Renderer2 },
|
|
164
|
+
{ type: ElementRef }
|
|
165
|
+
];
|
|
166
|
+
ImageDirective.propDecorators = {
|
|
167
|
+
field: [{ type: Input, args: ['scImage',] }],
|
|
168
|
+
editable: [{ type: Input, args: ['scImageEditable',] }],
|
|
169
|
+
mediaUrlPrefix: [{ type: Input, args: ['scImageMediaUrlPrefix',] }],
|
|
170
|
+
urlParams: [{ type: Input, args: ['scImageUrlParams',] }],
|
|
171
|
+
attrs: [{ type: Input, args: ['scImageAttrs',] }]
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
class LinkDirective {
|
|
175
|
-
constructor(viewContainer, templateRef, renderer, elementRef) {
|
|
176
|
-
this.viewContainer = viewContainer;
|
|
177
|
-
this.templateRef = templateRef;
|
|
178
|
-
this.renderer = renderer;
|
|
179
|
-
this.elementRef = elementRef;
|
|
180
|
-
this.inlineRef = null;
|
|
181
|
-
this.editable = true;
|
|
182
|
-
this.attrs = {};
|
|
183
|
-
}
|
|
184
|
-
ngOnChanges(changes) {
|
|
185
|
-
if (changes.field || changes.editable || changes.attrs) {
|
|
186
|
-
this.viewContainer.clear();
|
|
187
|
-
if (this.inlineRef) {
|
|
188
|
-
this.inlineRef.remove();
|
|
189
|
-
this.inlineRef = null;
|
|
190
|
-
}
|
|
191
|
-
this.updateView();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
updateView() {
|
|
195
|
-
var _a, _b;
|
|
196
|
-
const field = this.field;
|
|
197
|
-
if (this.editable && field && field.editableFirstPart && field.editableLastPart) {
|
|
198
|
-
this.renderInlineWrapper(field.editableFirstPart, field.editableLastPart);
|
|
199
|
-
}
|
|
200
|
-
else if (field && (field.href || field.value)) {
|
|
201
|
-
const props = field.href ? field : field.value;
|
|
202
|
-
const linkText = field.text || ((_a = field.value) === null || _a === void 0 ? void 0 : _a.text) || field.href || ((_b = field.value) === null || _b === void 0 ? void 0 : _b.href);
|
|
203
|
-
const mergedAttrs = Object.assign(Object.assign({}, props), this.attrs);
|
|
204
|
-
this.renderTemplate(mergedAttrs, linkText);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
renderTemplate(props, linkText) {
|
|
208
|
-
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
209
|
-
viewRef.rootNodes.forEach((node) => {
|
|
210
|
-
Object.entries(props).forEach(([key, propValue]) => {
|
|
211
|
-
if (typeof propValue !== 'string')
|
|
212
|
-
return;
|
|
213
|
-
if (key === 'href') {
|
|
214
|
-
const isInvalidLink = !propValue || /^https?:\/\/$/.test(propValue);
|
|
215
|
-
if (isInvalidLink) {
|
|
216
|
-
if (!node.href) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
propValue = node.href;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (key === 'class' && node.className) {
|
|
223
|
-
propValue += ` ${node.className}`;
|
|
224
|
-
}
|
|
225
|
-
this.renderer.setAttribute(node, key, propValue);
|
|
226
|
-
});
|
|
227
|
-
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
228
|
-
node.textContent = linkText;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
renderInlineWrapper(editableFirstPart, editableLastPart) {
|
|
233
|
-
const span = this.renderer.createElement('span');
|
|
234
|
-
span.className = 'sc-link-wrapper';
|
|
235
|
-
span.innerHTML = editableFirstPart + editableLastPart;
|
|
236
|
-
// assign attributes from template to inline wrapper
|
|
237
|
-
const attrs = Object.assign(Object.assign({}, this.getElementAttrs()), this.attrs);
|
|
238
|
-
Object.entries(attrs).forEach(([key, attrValue]) => this.renderer.setAttribute(span, key, attrValue));
|
|
239
|
-
this.viewContainer.createEmbeddedView(this.templateRef);
|
|
240
|
-
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
241
|
-
this.renderer.insertBefore(parentNode, span, this.elementRef.nativeElement);
|
|
242
|
-
this.inlineRef = span;
|
|
243
|
-
}
|
|
244
|
-
getElementAttrs() {
|
|
245
|
-
const view = this.templateRef.createEmbeddedView(null);
|
|
246
|
-
const element = view.rootNodes[0];
|
|
247
|
-
if (!element) {
|
|
248
|
-
return {};
|
|
249
|
-
}
|
|
250
|
-
const attrs = {};
|
|
251
|
-
for (let i = 0; i < element.attributes.length; i++) {
|
|
252
|
-
const attr = element.attributes.item(i);
|
|
253
|
-
if (attr) {
|
|
254
|
-
attrs[attr.name] = attr.value;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return attrs;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
LinkDirective.decorators = [
|
|
261
|
-
{ type: Directive, args: [{ selector: '[scLink]' },] }
|
|
262
|
-
];
|
|
263
|
-
LinkDirective.ctorParameters = () => [
|
|
264
|
-
{ type: ViewContainerRef },
|
|
265
|
-
{ type: TemplateRef },
|
|
266
|
-
{ type: Renderer2 },
|
|
267
|
-
{ type: ElementRef }
|
|
268
|
-
];
|
|
269
|
-
LinkDirective.propDecorators = {
|
|
270
|
-
editable: [{ type: Input, args: ['scLinkEditable',] }],
|
|
271
|
-
attrs: [{ type: Input, args: ['scLinkAttrs',] }],
|
|
272
|
-
field: [{ type: Input, args: ['scLink',] }]
|
|
174
|
+
class LinkDirective {
|
|
175
|
+
constructor(viewContainer, templateRef, renderer, elementRef) {
|
|
176
|
+
this.viewContainer = viewContainer;
|
|
177
|
+
this.templateRef = templateRef;
|
|
178
|
+
this.renderer = renderer;
|
|
179
|
+
this.elementRef = elementRef;
|
|
180
|
+
this.inlineRef = null;
|
|
181
|
+
this.editable = true;
|
|
182
|
+
this.attrs = {};
|
|
183
|
+
}
|
|
184
|
+
ngOnChanges(changes) {
|
|
185
|
+
if (changes.field || changes.editable || changes.attrs) {
|
|
186
|
+
this.viewContainer.clear();
|
|
187
|
+
if (this.inlineRef) {
|
|
188
|
+
this.inlineRef.remove();
|
|
189
|
+
this.inlineRef = null;
|
|
190
|
+
}
|
|
191
|
+
this.updateView();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
updateView() {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
const field = this.field;
|
|
197
|
+
if (this.editable && field && field.editableFirstPart && field.editableLastPart) {
|
|
198
|
+
this.renderInlineWrapper(field.editableFirstPart, field.editableLastPart);
|
|
199
|
+
}
|
|
200
|
+
else if (field && (field.href || field.value)) {
|
|
201
|
+
const props = field.href ? field : field.value;
|
|
202
|
+
const linkText = field.text || ((_a = field.value) === null || _a === void 0 ? void 0 : _a.text) || field.href || ((_b = field.value) === null || _b === void 0 ? void 0 : _b.href);
|
|
203
|
+
const mergedAttrs = Object.assign(Object.assign({}, props), this.attrs);
|
|
204
|
+
this.renderTemplate(mergedAttrs, linkText);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
renderTemplate(props, linkText) {
|
|
208
|
+
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
209
|
+
viewRef.rootNodes.forEach((node) => {
|
|
210
|
+
Object.entries(props).forEach(([key, propValue]) => {
|
|
211
|
+
if (typeof propValue !== 'string')
|
|
212
|
+
return;
|
|
213
|
+
if (key === 'href') {
|
|
214
|
+
const isInvalidLink = !propValue || /^https?:\/\/$/.test(propValue);
|
|
215
|
+
if (isInvalidLink) {
|
|
216
|
+
if (!node.href) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
propValue = node.href;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (key === 'class' && node.className) {
|
|
223
|
+
propValue += ` ${node.className}`;
|
|
224
|
+
}
|
|
225
|
+
this.renderer.setAttribute(node, key, propValue);
|
|
226
|
+
});
|
|
227
|
+
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
228
|
+
node.textContent = linkText;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
renderInlineWrapper(editableFirstPart, editableLastPart) {
|
|
233
|
+
const span = this.renderer.createElement('span');
|
|
234
|
+
span.className = 'sc-link-wrapper';
|
|
235
|
+
span.innerHTML = editableFirstPart + editableLastPart;
|
|
236
|
+
// assign attributes from template to inline wrapper
|
|
237
|
+
const attrs = Object.assign(Object.assign({}, this.getElementAttrs()), this.attrs);
|
|
238
|
+
Object.entries(attrs).forEach(([key, attrValue]) => this.renderer.setAttribute(span, key, attrValue));
|
|
239
|
+
this.viewContainer.createEmbeddedView(this.templateRef);
|
|
240
|
+
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
241
|
+
this.renderer.insertBefore(parentNode, span, this.elementRef.nativeElement);
|
|
242
|
+
this.inlineRef = span;
|
|
243
|
+
}
|
|
244
|
+
getElementAttrs() {
|
|
245
|
+
const view = this.templateRef.createEmbeddedView(null);
|
|
246
|
+
const element = view.rootNodes[0];
|
|
247
|
+
if (!element) {
|
|
248
|
+
return {};
|
|
249
|
+
}
|
|
250
|
+
const attrs = {};
|
|
251
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
252
|
+
const attr = element.attributes.item(i);
|
|
253
|
+
if (attr) {
|
|
254
|
+
attrs[attr.name] = attr.value;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return attrs;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
LinkDirective.decorators = [
|
|
261
|
+
{ type: Directive, args: [{ selector: '[scLink]' },] }
|
|
262
|
+
];
|
|
263
|
+
LinkDirective.ctorParameters = () => [
|
|
264
|
+
{ type: ViewContainerRef },
|
|
265
|
+
{ type: TemplateRef },
|
|
266
|
+
{ type: Renderer2 },
|
|
267
|
+
{ type: ElementRef }
|
|
268
|
+
];
|
|
269
|
+
LinkDirective.propDecorators = {
|
|
270
|
+
editable: [{ type: Input, args: ['scLinkEditable',] }],
|
|
271
|
+
attrs: [{ type: Input, args: ['scLinkAttrs',] }],
|
|
272
|
+
field: [{ type: Input, args: ['scLink',] }]
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
-
class RouterLinkDirective extends LinkDirective {
|
|
276
|
-
constructor(viewContainer, templateRef, renderer, elementRef, router) {
|
|
277
|
-
super(viewContainer, templateRef, renderer, elementRef);
|
|
278
|
-
this.router = router;
|
|
279
|
-
this.editable = true;
|
|
280
|
-
this.attrs = {};
|
|
281
|
-
}
|
|
282
|
-
renderTemplate(props, linkText) {
|
|
283
|
-
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
284
|
-
viewRef.rootNodes.forEach((node) => {
|
|
285
|
-
Object.entries(props).forEach(([key, propValue]) => {
|
|
286
|
-
this.renderer.setAttribute(node, key, propValue);
|
|
287
|
-
if (key === 'href') {
|
|
288
|
-
this.renderer.listen(node, 'click', (event) => {
|
|
289
|
-
this.router.navigate([propValue]);
|
|
290
|
-
event.preventDefault();
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
295
|
-
node.textContent = linkText;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
RouterLinkDirective.decorators = [
|
|
301
|
-
{ type: Directive, args: [{ selector: '[scRouterLink]' },] }
|
|
302
|
-
];
|
|
303
|
-
RouterLinkDirective.ctorParameters = () => [
|
|
304
|
-
{ type: ViewContainerRef },
|
|
305
|
-
{ type: TemplateRef },
|
|
306
|
-
{ type: Renderer2 },
|
|
307
|
-
{ type: ElementRef },
|
|
308
|
-
{ type: Router }
|
|
309
|
-
];
|
|
310
|
-
RouterLinkDirective.propDecorators = {
|
|
311
|
-
editable: [{ type: Input, args: ['scRouterLinkEditable',] }],
|
|
312
|
-
attrs: [{ type: Input, args: ['scRouterLinkAttrs',] }],
|
|
313
|
-
field: [{ type: Input, args: ['scRouterLink',] }]
|
|
275
|
+
class RouterLinkDirective extends LinkDirective {
|
|
276
|
+
constructor(viewContainer, templateRef, renderer, elementRef, router) {
|
|
277
|
+
super(viewContainer, templateRef, renderer, elementRef);
|
|
278
|
+
this.router = router;
|
|
279
|
+
this.editable = true;
|
|
280
|
+
this.attrs = {};
|
|
281
|
+
}
|
|
282
|
+
renderTemplate(props, linkText) {
|
|
283
|
+
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
284
|
+
viewRef.rootNodes.forEach((node) => {
|
|
285
|
+
Object.entries(props).forEach(([key, propValue]) => {
|
|
286
|
+
this.renderer.setAttribute(node, key, propValue);
|
|
287
|
+
if (key === 'href') {
|
|
288
|
+
this.renderer.listen(node, 'click', (event) => {
|
|
289
|
+
this.router.navigate([propValue]);
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
295
|
+
node.textContent = linkText;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
RouterLinkDirective.decorators = [
|
|
301
|
+
{ type: Directive, args: [{ selector: '[scRouterLink]' },] }
|
|
302
|
+
];
|
|
303
|
+
RouterLinkDirective.ctorParameters = () => [
|
|
304
|
+
{ type: ViewContainerRef },
|
|
305
|
+
{ type: TemplateRef },
|
|
306
|
+
{ type: Renderer2 },
|
|
307
|
+
{ type: ElementRef },
|
|
308
|
+
{ type: Router }
|
|
309
|
+
];
|
|
310
|
+
RouterLinkDirective.propDecorators = {
|
|
311
|
+
editable: [{ type: Input, args: ['scRouterLinkEditable',] }],
|
|
312
|
+
attrs: [{ type: Input, args: ['scRouterLinkAttrs',] }],
|
|
313
|
+
field: [{ type: Input, args: ['scRouterLink',] }]
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
-
class GenericLinkDirective extends LinkDirective {
|
|
317
|
-
constructor(viewContainer, templateRef, renderer, elementRef, router) {
|
|
318
|
-
super(viewContainer, templateRef, renderer, elementRef);
|
|
319
|
-
this.router = router;
|
|
320
|
-
this.editable = true;
|
|
321
|
-
this.attrs = {};
|
|
322
|
-
}
|
|
323
|
-
renderTemplate(props, linkText) {
|
|
324
|
-
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
325
|
-
viewRef.rootNodes.forEach((node) => {
|
|
326
|
-
Object.entries(props).forEach(([key, propValue]) => {
|
|
327
|
-
if (key === 'href' && !this.isAbsoluteUrl(propValue)) {
|
|
328
|
-
const urlTree = this.router.createUrlTree([propValue], this.extras);
|
|
329
|
-
this.renderer.setAttribute(node, key, this.router.serializeUrl(urlTree));
|
|
330
|
-
this.renderer.listen(node, 'click', (event) => {
|
|
331
|
-
this.router.navigate([propValue], this.extras);
|
|
332
|
-
event.preventDefault();
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
this.renderer.setAttribute(node, key, propValue);
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
340
|
-
node.textContent = linkText;
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
isAbsoluteUrl(url) {
|
|
345
|
-
if (url === null) {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
if (typeof url !== 'string') {
|
|
349
|
-
throw new TypeError('Expected a string');
|
|
350
|
-
}
|
|
351
|
-
return /^[a-z][a-z0-9+.-]*:/.test(url);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
GenericLinkDirective.decorators = [
|
|
355
|
-
{ type: Directive, args: [{ selector: '[scGenericLink]' },] }
|
|
356
|
-
];
|
|
357
|
-
GenericLinkDirective.ctorParameters = () => [
|
|
358
|
-
{ type: ViewContainerRef },
|
|
359
|
-
{ type: TemplateRef },
|
|
360
|
-
{ type: Renderer2 },
|
|
361
|
-
{ type: ElementRef },
|
|
362
|
-
{ type: Router }
|
|
363
|
-
];
|
|
364
|
-
GenericLinkDirective.propDecorators = {
|
|
365
|
-
editable: [{ type: Input, args: ['scGenericLinkEditable',] }],
|
|
366
|
-
attrs: [{ type: Input, args: ['scGenericLinkAttrs',] }],
|
|
367
|
-
field: [{ type: Input, args: ['scGenericLink',] }],
|
|
368
|
-
extras: [{ type: Input, args: ['scGenericLinkExtras',] }]
|
|
316
|
+
class GenericLinkDirective extends LinkDirective {
|
|
317
|
+
constructor(viewContainer, templateRef, renderer, elementRef, router) {
|
|
318
|
+
super(viewContainer, templateRef, renderer, elementRef);
|
|
319
|
+
this.router = router;
|
|
320
|
+
this.editable = true;
|
|
321
|
+
this.attrs = {};
|
|
322
|
+
}
|
|
323
|
+
renderTemplate(props, linkText) {
|
|
324
|
+
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
325
|
+
viewRef.rootNodes.forEach((node) => {
|
|
326
|
+
Object.entries(props).forEach(([key, propValue]) => {
|
|
327
|
+
if (key === 'href' && !this.isAbsoluteUrl(propValue)) {
|
|
328
|
+
const urlTree = this.router.createUrlTree([propValue], this.extras);
|
|
329
|
+
this.renderer.setAttribute(node, key, this.router.serializeUrl(urlTree));
|
|
330
|
+
this.renderer.listen(node, 'click', (event) => {
|
|
331
|
+
this.router.navigate([propValue], this.extras);
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
this.renderer.setAttribute(node, key, propValue);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
if (node.childNodes && node.childNodes.length === 0 && linkText) {
|
|
340
|
+
node.textContent = linkText;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
isAbsoluteUrl(url) {
|
|
345
|
+
if (url === null) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (typeof url !== 'string') {
|
|
349
|
+
throw new TypeError('Expected a string');
|
|
350
|
+
}
|
|
351
|
+
return /^[a-z][a-z0-9+.-]*:/.test(url);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
GenericLinkDirective.decorators = [
|
|
355
|
+
{ type: Directive, args: [{ selector: '[scGenericLink]' },] }
|
|
356
|
+
];
|
|
357
|
+
GenericLinkDirective.ctorParameters = () => [
|
|
358
|
+
{ type: ViewContainerRef },
|
|
359
|
+
{ type: TemplateRef },
|
|
360
|
+
{ type: Renderer2 },
|
|
361
|
+
{ type: ElementRef },
|
|
362
|
+
{ type: Router }
|
|
363
|
+
];
|
|
364
|
+
GenericLinkDirective.propDecorators = {
|
|
365
|
+
editable: [{ type: Input, args: ['scGenericLinkEditable',] }],
|
|
366
|
+
attrs: [{ type: Input, args: ['scGenericLinkAttrs',] }],
|
|
367
|
+
field: [{ type: Input, args: ['scGenericLink',] }],
|
|
368
|
+
extras: [{ type: Input, args: ['scGenericLinkExtras',] }]
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
-
/** Registers a statically loaded component */
|
|
372
|
-
class ComponentNameAndType {
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* @param {unknown} object
|
|
376
|
-
*/
|
|
377
|
-
function instanceOfComponentNameAndType(object) {
|
|
378
|
-
return typeof object === 'object' && object !== null && 'type' in object;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* @param {unknown} object
|
|
382
|
-
*/
|
|
383
|
-
function instanceOfComponentNameAndModule(object) {
|
|
384
|
-
return typeof object === 'object' && object !== null && 'module' in object;
|
|
385
|
-
}
|
|
386
|
-
const PLACEHOLDER_COMPONENTS = new InjectionToken('Sc.placeholder.components');
|
|
387
|
-
const PLACEHOLDER_LAZY_COMPONENTS = new InjectionToken('Sc.placeholder.lazyComponents');
|
|
388
|
-
const PLACEHOLDER_MISSING_COMPONENT_COMPONENT = new InjectionToken('Sc.placeholder.missingComponentComponent');
|
|
371
|
+
/** Registers a statically loaded component */
|
|
372
|
+
class ComponentNameAndType {
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* @param {unknown} object
|
|
376
|
+
*/
|
|
377
|
+
function instanceOfComponentNameAndType(object) {
|
|
378
|
+
return typeof object === 'object' && object !== null && 'type' in object;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @param {unknown} object
|
|
382
|
+
*/
|
|
383
|
+
function instanceOfComponentNameAndModule(object) {
|
|
384
|
+
return typeof object === 'object' && object !== null && 'module' in object;
|
|
385
|
+
}
|
|
386
|
+
const PLACEHOLDER_COMPONENTS = new InjectionToken('Sc.placeholder.components');
|
|
387
|
+
const PLACEHOLDER_LAZY_COMPONENTS = new InjectionToken('Sc.placeholder.lazyComponents');
|
|
388
|
+
const PLACEHOLDER_MISSING_COMPONENT_COMPONENT = new InjectionToken('Sc.placeholder.missingComponentComponent');
|
|
389
389
|
const DYNAMIC_COMPONENT = new InjectionToken('Sc.placeholder.dynamicComponent');
|
|
390
390
|
|
|
391
|
-
class RawComponent {
|
|
392
|
-
constructor(renderer, elementRef) {
|
|
393
|
-
this.renderer = renderer;
|
|
394
|
-
this.elementRef = elementRef;
|
|
395
|
-
}
|
|
396
|
-
ngOnInit() {
|
|
397
|
-
const el = this.renderer.createElement(this.rendering.name);
|
|
398
|
-
const contents = this.renderer.createText(this.rendering.contents || '');
|
|
399
|
-
const attributes = this.rendering.attributes;
|
|
400
|
-
for (const attr in attributes) {
|
|
401
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
402
|
-
if (attributes.hasOwnProperty(attr)) {
|
|
403
|
-
const value = attributes[attr];
|
|
404
|
-
this.renderer.setAttribute(el, attr, value || '');
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
this.renderer.appendChild(el, contents);
|
|
408
|
-
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
409
|
-
this.renderer.insertBefore(parentNode, el, this.elementRef.nativeElement);
|
|
410
|
-
parentNode.removeChild(this.elementRef.nativeElement);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
RawComponent.decorators = [
|
|
414
|
-
{ type: Component, args: [{
|
|
415
|
-
selector: 'sc-raw',
|
|
416
|
-
template: ''
|
|
417
|
-
},] }
|
|
418
|
-
];
|
|
419
|
-
RawComponent.ctorParameters = () => [
|
|
420
|
-
{ type: Renderer2 },
|
|
421
|
-
{ type: ElementRef }
|
|
422
|
-
];
|
|
423
|
-
RawComponent.propDecorators = {
|
|
424
|
-
rendering: [{ type: Input }]
|
|
391
|
+
class RawComponent {
|
|
392
|
+
constructor(renderer, elementRef) {
|
|
393
|
+
this.renderer = renderer;
|
|
394
|
+
this.elementRef = elementRef;
|
|
395
|
+
}
|
|
396
|
+
ngOnInit() {
|
|
397
|
+
const el = this.renderer.createElement(this.rendering.name);
|
|
398
|
+
const contents = this.renderer.createText(this.rendering.contents || '');
|
|
399
|
+
const attributes = this.rendering.attributes;
|
|
400
|
+
for (const attr in attributes) {
|
|
401
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
402
|
+
if (attributes.hasOwnProperty(attr)) {
|
|
403
|
+
const value = attributes[attr];
|
|
404
|
+
this.renderer.setAttribute(el, attr, value || '');
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
this.renderer.appendChild(el, contents);
|
|
408
|
+
const parentNode = this.renderer.parentNode(this.elementRef.nativeElement);
|
|
409
|
+
this.renderer.insertBefore(parentNode, el, this.elementRef.nativeElement);
|
|
410
|
+
parentNode.removeChild(this.elementRef.nativeElement);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
RawComponent.decorators = [
|
|
414
|
+
{ type: Component, args: [{
|
|
415
|
+
selector: 'sc-raw',
|
|
416
|
+
template: ''
|
|
417
|
+
},] }
|
|
418
|
+
];
|
|
419
|
+
RawComponent.ctorParameters = () => [
|
|
420
|
+
{ type: Renderer2 },
|
|
421
|
+
{ type: ElementRef }
|
|
422
|
+
];
|
|
423
|
+
RawComponent.propDecorators = {
|
|
424
|
+
rendering: [{ type: Input }]
|
|
425
425
|
};
|
|
426
426
|
|
|
427
|
-
/**
|
|
428
|
-
* @param {HtmlElementRendering | ComponentRendering} rendering
|
|
429
|
-
*/
|
|
430
|
-
function isRawRendering(rendering) {
|
|
431
|
-
return (!rendering.componentName &&
|
|
432
|
-
rendering.name !== undefined);
|
|
427
|
+
/**
|
|
428
|
+
* @param {HtmlElementRendering | ComponentRendering} rendering
|
|
429
|
+
*/
|
|
430
|
+
function isRawRendering(rendering) {
|
|
431
|
+
return (!rendering.componentName &&
|
|
432
|
+
rendering.name !== undefined);
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
class JssComponentFactoryService {
|
|
436
|
-
constructor(injector, compiler, components, lazyComponents) {
|
|
437
|
-
this.injector = injector;
|
|
438
|
-
this.compiler = compiler;
|
|
439
|
-
this.components = components;
|
|
440
|
-
this.lazyComponents = lazyComponents;
|
|
441
|
-
this.componentMap = new Map();
|
|
442
|
-
this.lazyComponentMap = new Map();
|
|
443
|
-
this.components.forEach((c) => this.componentMap.set(c.name, c.type));
|
|
444
|
-
if (this.lazyComponents) {
|
|
445
|
-
this.lazyComponents.forEach((c) => this.lazyComponentMap.set(c.path, c));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
loadModuleFactory(lazyComponent) {
|
|
449
|
-
return lazyComponent.loadChildren().then((loaded) => {
|
|
450
|
-
if (loaded instanceof NgModuleFactory) {
|
|
451
|
-
return loaded;
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
return this.compiler.compileModuleAsync(loaded);
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
getComponent(component) {
|
|
459
|
-
const loadedComponent = this.componentMap.get(component.componentName);
|
|
460
|
-
if (loadedComponent) {
|
|
461
|
-
return Promise.resolve({
|
|
462
|
-
componentDefinition: component,
|
|
463
|
-
componentImplementation: this.componentMap.get(component.componentName),
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
const lazyComponent = this.lazyComponentMap.get(component.componentName);
|
|
467
|
-
if (lazyComponent) {
|
|
468
|
-
return this.loadModuleFactory(lazyComponent).then((ngModuleFactory) => {
|
|
469
|
-
let componentType = null;
|
|
470
|
-
const moduleRef = ngModuleFactory.create(this.injector);
|
|
471
|
-
const dynamicComponentType = moduleRef.injector.get(DYNAMIC_COMPONENT);
|
|
472
|
-
if (!dynamicComponentType) {
|
|
473
|
-
throw new Error(`JssComponentFactoryService: Lazy load module for component "${lazyComponent.path}" missing DYNAMIC_COMPONENT provider. Missing JssModule.forChild()?`);
|
|
474
|
-
}
|
|
475
|
-
if (component.componentName in dynamicComponentType) {
|
|
476
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
477
|
-
componentType = dynamicComponentType[component.componentName];
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
if (typeof dynamicComponentType === 'function') {
|
|
481
|
-
componentType = dynamicComponentType;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
throw new Error(`JssComponentFactoryService: Lazy load module for component "${lazyComponent.path}" missing DYNAMIC_COMPONENT provider. Missing JssModule.forChild()?`);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
componentDefinition: component,
|
|
489
|
-
componentImplementation: componentType,
|
|
490
|
-
componentFactory: moduleRef.componentFactoryResolver.resolveComponentFactory(componentType),
|
|
491
|
-
};
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return Promise.resolve({
|
|
495
|
-
componentDefinition: component,
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
getComponents(components) {
|
|
499
|
-
// acquire all components and keep them in order while handling their potential async-ness
|
|
500
|
-
return Promise.all(components.map((component) => isRawRendering(component) ? this.getRawComponent(component) : this.getComponent(component)));
|
|
501
|
-
}
|
|
502
|
-
getRawComponent(component) {
|
|
503
|
-
return Promise.resolve({
|
|
504
|
-
componentImplementation: RawComponent,
|
|
505
|
-
componentDefinition: component,
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
JssComponentFactoryService.decorators = [
|
|
510
|
-
{ type: Injectable }
|
|
511
|
-
];
|
|
512
|
-
JssComponentFactoryService.ctorParameters = () => [
|
|
513
|
-
{ type: Injector },
|
|
514
|
-
{ type: Compiler },
|
|
515
|
-
{ type: Array, decorators: [{ type: Inject, args: [PLACEHOLDER_COMPONENTS,] }] },
|
|
516
|
-
{ type: Array, decorators: [{ type: Inject, args: [PLACEHOLDER_LAZY_COMPONENTS,] }] }
|
|
435
|
+
class JssComponentFactoryService {
|
|
436
|
+
constructor(injector, compiler, components, lazyComponents) {
|
|
437
|
+
this.injector = injector;
|
|
438
|
+
this.compiler = compiler;
|
|
439
|
+
this.components = components;
|
|
440
|
+
this.lazyComponents = lazyComponents;
|
|
441
|
+
this.componentMap = new Map();
|
|
442
|
+
this.lazyComponentMap = new Map();
|
|
443
|
+
this.components.forEach((c) => this.componentMap.set(c.name, c.type));
|
|
444
|
+
if (this.lazyComponents) {
|
|
445
|
+
this.lazyComponents.forEach((c) => this.lazyComponentMap.set(c.path, c));
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
loadModuleFactory(lazyComponent) {
|
|
449
|
+
return lazyComponent.loadChildren().then((loaded) => {
|
|
450
|
+
if (loaded instanceof NgModuleFactory) {
|
|
451
|
+
return loaded;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
return this.compiler.compileModuleAsync(loaded);
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
getComponent(component) {
|
|
459
|
+
const loadedComponent = this.componentMap.get(component.componentName);
|
|
460
|
+
if (loadedComponent) {
|
|
461
|
+
return Promise.resolve({
|
|
462
|
+
componentDefinition: component,
|
|
463
|
+
componentImplementation: this.componentMap.get(component.componentName),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
const lazyComponent = this.lazyComponentMap.get(component.componentName);
|
|
467
|
+
if (lazyComponent) {
|
|
468
|
+
return this.loadModuleFactory(lazyComponent).then((ngModuleFactory) => {
|
|
469
|
+
let componentType = null;
|
|
470
|
+
const moduleRef = ngModuleFactory.create(this.injector);
|
|
471
|
+
const dynamicComponentType = moduleRef.injector.get(DYNAMIC_COMPONENT);
|
|
472
|
+
if (!dynamicComponentType) {
|
|
473
|
+
throw new Error(`JssComponentFactoryService: Lazy load module for component "${lazyComponent.path}" missing DYNAMIC_COMPONENT provider. Missing JssModule.forChild()?`);
|
|
474
|
+
}
|
|
475
|
+
if (component.componentName in dynamicComponentType) {
|
|
476
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
477
|
+
componentType = dynamicComponentType[component.componentName];
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
if (typeof dynamicComponentType === 'function') {
|
|
481
|
+
componentType = dynamicComponentType;
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
throw new Error(`JssComponentFactoryService: Lazy load module for component "${lazyComponent.path}" missing DYNAMIC_COMPONENT provider. Missing JssModule.forChild()?`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
componentDefinition: component,
|
|
489
|
+
componentImplementation: componentType,
|
|
490
|
+
componentFactory: moduleRef.componentFactoryResolver.resolveComponentFactory(componentType),
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return Promise.resolve({
|
|
495
|
+
componentDefinition: component,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
getComponents(components) {
|
|
499
|
+
// acquire all components and keep them in order while handling their potential async-ness
|
|
500
|
+
return Promise.all(components.map((component) => isRawRendering(component) ? this.getRawComponent(component) : this.getComponent(component)));
|
|
501
|
+
}
|
|
502
|
+
getRawComponent(component) {
|
|
503
|
+
return Promise.resolve({
|
|
504
|
+
componentImplementation: RawComponent,
|
|
505
|
+
componentDefinition: component,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
JssComponentFactoryService.decorators = [
|
|
510
|
+
{ type: Injectable }
|
|
511
|
+
];
|
|
512
|
+
JssComponentFactoryService.ctorParameters = () => [
|
|
513
|
+
{ type: Injector },
|
|
514
|
+
{ type: Compiler },
|
|
515
|
+
{ type: Array, decorators: [{ type: Inject, args: [PLACEHOLDER_COMPONENTS,] }] },
|
|
516
|
+
{ type: Array, decorators: [{ type: Inject, args: [PLACEHOLDER_LAZY_COMPONENTS,] }] }
|
|
517
517
|
];
|
|
518
518
|
|
|
519
|
-
class PlaceholderLoadingDirective {
|
|
520
|
-
constructor(templateRef) {
|
|
521
|
-
this.templateRef = templateRef;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
PlaceholderLoadingDirective.decorators = [
|
|
525
|
-
{ type: Directive, args: [{
|
|
526
|
-
selector: '[scPlaceholderLoading]',
|
|
527
|
-
},] }
|
|
528
|
-
];
|
|
529
|
-
PlaceholderLoadingDirective.ctorParameters = () => [
|
|
530
|
-
{ type: TemplateRef }
|
|
519
|
+
class PlaceholderLoadingDirective {
|
|
520
|
+
constructor(templateRef) {
|
|
521
|
+
this.templateRef = templateRef;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
PlaceholderLoadingDirective.decorators = [
|
|
525
|
+
{ type: Directive, args: [{
|
|
526
|
+
selector: '[scPlaceholderLoading]',
|
|
527
|
+
},] }
|
|
528
|
+
];
|
|
529
|
+
PlaceholderLoadingDirective.ctorParameters = () => [
|
|
530
|
+
{ type: TemplateRef }
|
|
531
531
|
];
|
|
532
532
|
|
|
533
|
-
class RenderEachDirective {
|
|
534
|
-
constructor(templateRef) {
|
|
535
|
-
this.templateRef = templateRef;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
RenderEachDirective.decorators = [
|
|
539
|
-
{ type: Directive, args: [{
|
|
540
|
-
selector: '[renderEach]',
|
|
541
|
-
},] }
|
|
542
|
-
];
|
|
543
|
-
RenderEachDirective.ctorParameters = () => [
|
|
544
|
-
{ type: TemplateRef }
|
|
533
|
+
class RenderEachDirective {
|
|
534
|
+
constructor(templateRef) {
|
|
535
|
+
this.templateRef = templateRef;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
RenderEachDirective.decorators = [
|
|
539
|
+
{ type: Directive, args: [{
|
|
540
|
+
selector: '[renderEach]',
|
|
541
|
+
},] }
|
|
542
|
+
];
|
|
543
|
+
RenderEachDirective.ctorParameters = () => [
|
|
544
|
+
{ type: TemplateRef }
|
|
545
545
|
];
|
|
546
546
|
|
|
547
|
-
class RenderEmptyDirective {
|
|
548
|
-
constructor(templateRef) {
|
|
549
|
-
this.templateRef = templateRef;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
RenderEmptyDirective.decorators = [
|
|
553
|
-
{ type: Directive, args: [{
|
|
554
|
-
selector: '[renderEmpty]',
|
|
555
|
-
},] }
|
|
556
|
-
];
|
|
557
|
-
RenderEmptyDirective.ctorParameters = () => [
|
|
558
|
-
{ type: TemplateRef }
|
|
547
|
+
class RenderEmptyDirective {
|
|
548
|
+
constructor(templateRef) {
|
|
549
|
+
this.templateRef = templateRef;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
RenderEmptyDirective.decorators = [
|
|
553
|
+
{ type: Directive, args: [{
|
|
554
|
+
selector: '[renderEmpty]',
|
|
555
|
+
},] }
|
|
556
|
+
];
|
|
557
|
+
RenderEmptyDirective.ctorParameters = () => [
|
|
558
|
+
{ type: TemplateRef }
|
|
559
559
|
];
|
|
560
560
|
|
|
561
|
-
/* eslint-disable @angular-eslint/no-conflicting-lifecycle */
|
|
562
|
-
/**
|
|
563
|
-
* @param {ComponentRendering} rendering
|
|
564
|
-
* @param {string} name
|
|
565
|
-
*/
|
|
566
|
-
function getPlaceholder(rendering, name) {
|
|
567
|
-
if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) {
|
|
568
|
-
return rendering.placeholders[name];
|
|
569
|
-
}
|
|
570
|
-
return null;
|
|
571
|
-
}
|
|
572
|
-
class PlaceholderComponent {
|
|
573
|
-
constructor(componentFactoryResolver, differs, componentFactory, changeDetectorRef, elementRef, renderer, missingComponentComponent) {
|
|
574
|
-
this.componentFactoryResolver = componentFactoryResolver;
|
|
575
|
-
this.differs = differs;
|
|
576
|
-
this.componentFactory = componentFactory;
|
|
577
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
578
|
-
this.elementRef = elementRef;
|
|
579
|
-
this.renderer = renderer;
|
|
580
|
-
this.missingComponentComponent = missingComponentComponent;
|
|
581
|
-
this._componentInstances = [];
|
|
582
|
-
this.destroyed = false;
|
|
583
|
-
this.parentStyleAttribute = '';
|
|
584
|
-
this.isLoading = true;
|
|
585
|
-
this.loaded = new EventEmitter();
|
|
586
|
-
}
|
|
587
|
-
set inputs(value) {
|
|
588
|
-
this._inputs = value;
|
|
589
|
-
if (!this._differ && value) {
|
|
590
|
-
this._differ = this.differs.find(value).create();
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
ngOnInit() {
|
|
594
|
-
// just to ensure the element exists
|
|
595
|
-
const elem = this.elementRef.nativeElement;
|
|
596
|
-
if (elem) {
|
|
597
|
-
const attributes = elem.attributes;
|
|
598
|
-
for (let i = 0; i < attributes.length; i++) {
|
|
599
|
-
const attr = attributes.item(i);
|
|
600
|
-
if (attr && attr.name.indexOf('_ngcontent') !== -1) {
|
|
601
|
-
this.parentStyleAttribute = attr.name;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
ngOnDestroy() {
|
|
607
|
-
this.destroyed = true;
|
|
608
|
-
this._componentInstances = [];
|
|
609
|
-
}
|
|
610
|
-
ngOnChanges(changes) {
|
|
611
|
-
if (changes.rendering || changes.renderings) {
|
|
612
|
-
this._render();
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
ngDoCheck() {
|
|
616
|
-
if (!this._differ || !this._inputs || this._componentInstances.length === 0) {
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
const changes = this._differ.diff(this._inputs);
|
|
620
|
-
if (!changes) {
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
const updates = {};
|
|
624
|
-
changes.forEachRemovedItem((change) => (updates[change.key] = null));
|
|
625
|
-
changes.forEachAddedItem((change) => (updates[change.key] = change.currentValue));
|
|
626
|
-
changes.forEachChangedItem((change) => (updates[change.key] = change.currentValue));
|
|
627
|
-
this._componentInstances.forEach((componentInstance) => this._setComponentInputs(componentInstance, updates));
|
|
628
|
-
}
|
|
629
|
-
_setComponentInputs(componentInstance, inputs) {
|
|
630
|
-
Object.entries(inputs).forEach(([input, inputValue]) => (componentInstance[input] = inputValue));
|
|
631
|
-
}
|
|
632
|
-
_subscribeComponentOutputs(componentInstance, outputs) {
|
|
633
|
-
Object.keys(outputs)
|
|
634
|
-
.filter((output) => componentInstance[output] && componentInstance[output] instanceof Observable)
|
|
635
|
-
.forEach((output) => componentInstance[output]
|
|
636
|
-
.pipe(takeWhile(() => !this.destroyed))
|
|
637
|
-
.subscribe(outputs[output]));
|
|
638
|
-
}
|
|
639
|
-
_render() {
|
|
640
|
-
this._componentInstances = [];
|
|
641
|
-
this.view.clear();
|
|
642
|
-
if (!this.rendering && !this.renderings) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
if (!this.name && !this.renderings) {
|
|
646
|
-
console.warn('Placeholder name was not specified, and explicit renderings array was not passed. Placeholder requires either name and rendering, or renderings.');
|
|
647
|
-
this.isLoading = false;
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const placeholder = this.renderings || getPlaceholder(this.rendering, this.name || '');
|
|
651
|
-
if (!placeholder) {
|
|
652
|
-
console.warn(`Placeholder '${this.name}' was not found in the current rendering data`, JSON.stringify(this.rendering, null, 2));
|
|
653
|
-
this.isLoading = false;
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
// if the placeholder is empty (contains only raw renderings), then we may need to use the empty template if it's defined
|
|
657
|
-
const placeholderIsEmpty = placeholder.every((rendering) => isRawRendering(rendering));
|
|
658
|
-
if (this.renderEmptyTemplate && placeholderIsEmpty) {
|
|
659
|
-
this.view.createEmbeddedView(this.renderEmptyTemplate.templateRef, {
|
|
660
|
-
renderings: placeholder,
|
|
661
|
-
});
|
|
662
|
-
this.isLoading = false;
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
this.componentFactory
|
|
666
|
-
.getComponents(placeholder)
|
|
667
|
-
.then((components) => components.forEach((rendering, index) => {
|
|
668
|
-
if (this.renderEachTemplate && !isRawRendering(rendering.componentDefinition)) {
|
|
669
|
-
this._renderTemplatedComponent(rendering.componentDefinition, index);
|
|
670
|
-
}
|
|
671
|
-
else {
|
|
672
|
-
this._renderEmbeddedComponent(rendering, index);
|
|
673
|
-
}
|
|
674
|
-
this.isLoading = false;
|
|
675
|
-
}))
|
|
676
|
-
.then(() => {
|
|
677
|
-
this.changeDetectorRef.markForCheck();
|
|
678
|
-
this.loaded.emit(this.name);
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
_renderTemplatedComponent(rendering, index) {
|
|
683
|
-
// the render-each template takes care of all component mapping etc
|
|
684
|
-
// generally using <sc-render-component> which is about like _renderEmbeddedComponent()
|
|
685
|
-
// as a separate component
|
|
686
|
-
this.view.createEmbeddedView(this.renderEachTemplate.templateRef, {
|
|
687
|
-
rendering,
|
|
688
|
-
index,
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
_renderEmbeddedComponent(rendering, index) {
|
|
692
|
-
if (!rendering.componentImplementation) {
|
|
693
|
-
const componentName = rendering.componentDefinition.componentName;
|
|
561
|
+
/* eslint-disable @angular-eslint/no-conflicting-lifecycle */
|
|
562
|
+
/**
|
|
563
|
+
* @param {ComponentRendering} rendering
|
|
564
|
+
* @param {string} name
|
|
565
|
+
*/
|
|
566
|
+
function getPlaceholder(rendering, name) {
|
|
567
|
+
if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) {
|
|
568
|
+
return rendering.placeholders[name];
|
|
569
|
+
}
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
class PlaceholderComponent {
|
|
573
|
+
constructor(componentFactoryResolver, differs, componentFactory, changeDetectorRef, elementRef, renderer, missingComponentComponent) {
|
|
574
|
+
this.componentFactoryResolver = componentFactoryResolver;
|
|
575
|
+
this.differs = differs;
|
|
576
|
+
this.componentFactory = componentFactory;
|
|
577
|
+
this.changeDetectorRef = changeDetectorRef;
|
|
578
|
+
this.elementRef = elementRef;
|
|
579
|
+
this.renderer = renderer;
|
|
580
|
+
this.missingComponentComponent = missingComponentComponent;
|
|
581
|
+
this._componentInstances = [];
|
|
582
|
+
this.destroyed = false;
|
|
583
|
+
this.parentStyleAttribute = '';
|
|
584
|
+
this.isLoading = true;
|
|
585
|
+
this.loaded = new EventEmitter();
|
|
586
|
+
}
|
|
587
|
+
set inputs(value) {
|
|
588
|
+
this._inputs = value;
|
|
589
|
+
if (!this._differ && value) {
|
|
590
|
+
this._differ = this.differs.find(value).create();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
ngOnInit() {
|
|
594
|
+
// just to ensure the element exists
|
|
595
|
+
const elem = this.elementRef.nativeElement;
|
|
596
|
+
if (elem) {
|
|
597
|
+
const attributes = elem.attributes;
|
|
598
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
599
|
+
const attr = attributes.item(i);
|
|
600
|
+
if (attr && attr.name.indexOf('_ngcontent') !== -1) {
|
|
601
|
+
this.parentStyleAttribute = attr.name;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
ngOnDestroy() {
|
|
607
|
+
this.destroyed = true;
|
|
608
|
+
this._componentInstances = [];
|
|
609
|
+
}
|
|
610
|
+
ngOnChanges(changes) {
|
|
611
|
+
if (changes.rendering || changes.renderings) {
|
|
612
|
+
this._render();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
ngDoCheck() {
|
|
616
|
+
if (!this._differ || !this._inputs || this._componentInstances.length === 0) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const changes = this._differ.diff(this._inputs);
|
|
620
|
+
if (!changes) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const updates = {};
|
|
624
|
+
changes.forEachRemovedItem((change) => (updates[change.key] = null));
|
|
625
|
+
changes.forEachAddedItem((change) => (updates[change.key] = change.currentValue));
|
|
626
|
+
changes.forEachChangedItem((change) => (updates[change.key] = change.currentValue));
|
|
627
|
+
this._componentInstances.forEach((componentInstance) => this._setComponentInputs(componentInstance, updates));
|
|
628
|
+
}
|
|
629
|
+
_setComponentInputs(componentInstance, inputs) {
|
|
630
|
+
Object.entries(inputs).forEach(([input, inputValue]) => (componentInstance[input] = inputValue));
|
|
631
|
+
}
|
|
632
|
+
_subscribeComponentOutputs(componentInstance, outputs) {
|
|
633
|
+
Object.keys(outputs)
|
|
634
|
+
.filter((output) => componentInstance[output] && componentInstance[output] instanceof Observable)
|
|
635
|
+
.forEach((output) => componentInstance[output]
|
|
636
|
+
.pipe(takeWhile(() => !this.destroyed))
|
|
637
|
+
.subscribe(outputs[output]));
|
|
638
|
+
}
|
|
639
|
+
_render() {
|
|
640
|
+
this._componentInstances = [];
|
|
641
|
+
this.view.clear();
|
|
642
|
+
if (!this.rendering && !this.renderings) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (!this.name && !this.renderings) {
|
|
646
|
+
console.warn('Placeholder name was not specified, and explicit renderings array was not passed. Placeholder requires either name and rendering, or renderings.');
|
|
647
|
+
this.isLoading = false;
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const placeholder = this.renderings || getPlaceholder(this.rendering, this.name || '');
|
|
651
|
+
if (!placeholder) {
|
|
652
|
+
console.warn(`Placeholder '${this.name}' was not found in the current rendering data`, JSON.stringify(this.rendering, null, 2));
|
|
653
|
+
this.isLoading = false;
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
// if the placeholder is empty (contains only raw renderings), then we may need to use the empty template if it's defined
|
|
657
|
+
const placeholderIsEmpty = placeholder.every((rendering) => isRawRendering(rendering));
|
|
658
|
+
if (this.renderEmptyTemplate && placeholderIsEmpty) {
|
|
659
|
+
this.view.createEmbeddedView(this.renderEmptyTemplate.templateRef, {
|
|
660
|
+
renderings: placeholder,
|
|
661
|
+
});
|
|
662
|
+
this.isLoading = false;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
this.componentFactory
|
|
666
|
+
.getComponents(placeholder)
|
|
667
|
+
.then((components) => components.forEach((rendering, index) => {
|
|
668
|
+
if (this.renderEachTemplate && !isRawRendering(rendering.componentDefinition)) {
|
|
669
|
+
this._renderTemplatedComponent(rendering.componentDefinition, index);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
this._renderEmbeddedComponent(rendering, index);
|
|
673
|
+
}
|
|
674
|
+
this.isLoading = false;
|
|
675
|
+
}))
|
|
676
|
+
.then(() => {
|
|
677
|
+
this.changeDetectorRef.markForCheck();
|
|
678
|
+
this.loaded.emit(this.name);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
_renderTemplatedComponent(rendering, index) {
|
|
683
|
+
// the render-each template takes care of all component mapping etc
|
|
684
|
+
// generally using <sc-render-component> which is about like _renderEmbeddedComponent()
|
|
685
|
+
// as a separate component
|
|
686
|
+
this.view.createEmbeddedView(this.renderEachTemplate.templateRef, {
|
|
687
|
+
rendering,
|
|
688
|
+
index,
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
_renderEmbeddedComponent(rendering, index) {
|
|
692
|
+
if (!rendering.componentImplementation) {
|
|
693
|
+
const componentName = rendering.componentDefinition.componentName;
|
|
694
694
|
console.error(`Placeholder ${this.name} contains unknown component ${componentName}.`, `Ensure component is mapped, like:
|
|
695
695
|
JssModule.withComponents([
|
|
696
696
|
{ name: '${componentName}', type: ${componentName}Component }
|
|
697
|
-
])`);
|
|
698
|
-
rendering.componentImplementation = this.missingComponentComponent;
|
|
699
|
-
}
|
|
700
|
-
const componentFactory = rendering.componentFactory ||
|
|
701
|
-
this.componentFactoryResolver.resolveComponentFactory(rendering.componentImplementation);
|
|
702
|
-
// apply the parent style attribute _ngcontent
|
|
703
|
-
// work-around for https://github.com/angular/angular/issues/12215
|
|
704
|
-
const createdComponentRef = this.view.createComponent(componentFactory, index);
|
|
705
|
-
if (this.parentStyleAttribute) {
|
|
706
|
-
this.renderer.setAttribute(createdComponentRef.location.nativeElement, this.parentStyleAttribute, '');
|
|
707
|
-
}
|
|
708
|
-
const componentInstance = createdComponentRef.instance;
|
|
709
|
-
componentInstance.rendering = rendering.componentDefinition;
|
|
710
|
-
if (this._inputs) {
|
|
711
|
-
this._setComponentInputs(componentInstance, this._inputs);
|
|
712
|
-
}
|
|
713
|
-
if (this.outputs) {
|
|
714
|
-
this._subscribeComponentOutputs(componentInstance, this.outputs);
|
|
715
|
-
}
|
|
716
|
-
this._componentInstances.push(componentInstance);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
PlaceholderComponent.decorators = [
|
|
720
|
-
{ type: Component, args: [{
|
|
721
|
-
selector: 'sc-placeholder,[sc-placeholder]',
|
|
697
|
+
])`);
|
|
698
|
+
rendering.componentImplementation = this.missingComponentComponent;
|
|
699
|
+
}
|
|
700
|
+
const componentFactory = rendering.componentFactory ||
|
|
701
|
+
this.componentFactoryResolver.resolveComponentFactory(rendering.componentImplementation);
|
|
702
|
+
// apply the parent style attribute _ngcontent
|
|
703
|
+
// work-around for https://github.com/angular/angular/issues/12215
|
|
704
|
+
const createdComponentRef = this.view.createComponent(componentFactory, index);
|
|
705
|
+
if (this.parentStyleAttribute) {
|
|
706
|
+
this.renderer.setAttribute(createdComponentRef.location.nativeElement, this.parentStyleAttribute, '');
|
|
707
|
+
}
|
|
708
|
+
const componentInstance = createdComponentRef.instance;
|
|
709
|
+
componentInstance.rendering = rendering.componentDefinition;
|
|
710
|
+
if (this._inputs) {
|
|
711
|
+
this._setComponentInputs(componentInstance, this._inputs);
|
|
712
|
+
}
|
|
713
|
+
if (this.outputs) {
|
|
714
|
+
this._subscribeComponentOutputs(componentInstance, this.outputs);
|
|
715
|
+
}
|
|
716
|
+
this._componentInstances.push(componentInstance);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
PlaceholderComponent.decorators = [
|
|
720
|
+
{ type: Component, args: [{
|
|
721
|
+
selector: 'sc-placeholder,[sc-placeholder]',
|
|
722
722
|
template: `
|
|
723
723
|
<ng-template
|
|
724
724
|
*ngIf="isLoading"
|
|
725
725
|
[ngTemplateOutlet]="placeholderLoading?.templateRef"
|
|
726
726
|
></ng-template>
|
|
727
727
|
<ng-template #view></ng-template>
|
|
728
|
-
`
|
|
729
|
-
},] }
|
|
730
|
-
];
|
|
731
|
-
PlaceholderComponent.ctorParameters = () => [
|
|
732
|
-
{ type: ComponentFactoryResolver },
|
|
733
|
-
{ type: KeyValueDiffers },
|
|
734
|
-
{ type: JssComponentFactoryService },
|
|
735
|
-
{ type: ChangeDetectorRef },
|
|
736
|
-
{ type: ElementRef },
|
|
737
|
-
{ type: Renderer2 },
|
|
738
|
-
{ type: Type, decorators: [{ type: Inject, args: [PLACEHOLDER_MISSING_COMPONENT_COMPONENT,] }] }
|
|
739
|
-
];
|
|
740
|
-
PlaceholderComponent.propDecorators = {
|
|
741
|
-
name: [{ type: Input }],
|
|
742
|
-
rendering: [{ type: Input }],
|
|
743
|
-
renderings: [{ type: Input }],
|
|
744
|
-
outputs: [{ type: Input }],
|
|
745
|
-
loaded: [{ type: Output }],
|
|
746
|
-
view: [{ type: ViewChild, args: ['view', { read: ViewContainerRef, static: true },] }],
|
|
747
|
-
renderEachTemplate: [{ type: ContentChild, args: [RenderEachDirective, { static: true },] }],
|
|
748
|
-
renderEmptyTemplate: [{ type: ContentChild, args: [RenderEmptyDirective, { static: true },] }],
|
|
749
|
-
placeholderLoading: [{ type: ContentChild, args: [PlaceholderLoadingDirective, { static: true },] }],
|
|
750
|
-
inputs: [{ type: Input }]
|
|
728
|
+
`
|
|
729
|
+
},] }
|
|
730
|
+
];
|
|
731
|
+
PlaceholderComponent.ctorParameters = () => [
|
|
732
|
+
{ type: ComponentFactoryResolver },
|
|
733
|
+
{ type: KeyValueDiffers },
|
|
734
|
+
{ type: JssComponentFactoryService },
|
|
735
|
+
{ type: ChangeDetectorRef },
|
|
736
|
+
{ type: ElementRef },
|
|
737
|
+
{ type: Renderer2 },
|
|
738
|
+
{ type: Type, decorators: [{ type: Inject, args: [PLACEHOLDER_MISSING_COMPONENT_COMPONENT,] }] }
|
|
739
|
+
];
|
|
740
|
+
PlaceholderComponent.propDecorators = {
|
|
741
|
+
name: [{ type: Input }],
|
|
742
|
+
rendering: [{ type: Input }],
|
|
743
|
+
renderings: [{ type: Input }],
|
|
744
|
+
outputs: [{ type: Input }],
|
|
745
|
+
loaded: [{ type: Output }],
|
|
746
|
+
view: [{ type: ViewChild, args: ['view', { read: ViewContainerRef, static: true },] }],
|
|
747
|
+
renderEachTemplate: [{ type: ContentChild, args: [RenderEachDirective, { static: true },] }],
|
|
748
|
+
renderEmptyTemplate: [{ type: ContentChild, args: [RenderEmptyDirective, { static: true },] }],
|
|
749
|
+
placeholderLoading: [{ type: ContentChild, args: [PlaceholderLoadingDirective, { static: true },] }],
|
|
750
|
+
inputs: [{ type: Input }]
|
|
751
751
|
};
|
|
752
752
|
|
|
753
|
-
class RichTextDirective {
|
|
754
|
-
constructor(viewContainer, templateRef) {
|
|
755
|
-
this.viewContainer = viewContainer;
|
|
756
|
-
this.templateRef = templateRef;
|
|
757
|
-
this.editable = true;
|
|
758
|
-
}
|
|
759
|
-
ngOnChanges(changes) {
|
|
760
|
-
if (changes.field || changes.editable) {
|
|
761
|
-
if (!this.viewRef) {
|
|
762
|
-
this.viewContainer.clear();
|
|
763
|
-
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
764
|
-
}
|
|
765
|
-
this.updateView();
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
updateView() {
|
|
769
|
-
const field = this.field;
|
|
770
|
-
if (!field || (!field.editable && !field.value)) {
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
const html = field.editable && this.editable ? field.editable : field.value;
|
|
774
|
-
this.viewRef.rootNodes.forEach((node) => {
|
|
775
|
-
node.innerHTML = html;
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
RichTextDirective.decorators = [
|
|
780
|
-
{ type: Directive, args: [{
|
|
781
|
-
selector: '[scRichText]',
|
|
782
|
-
},] }
|
|
783
|
-
];
|
|
784
|
-
RichTextDirective.ctorParameters = () => [
|
|
785
|
-
{ type: ViewContainerRef },
|
|
786
|
-
{ type: TemplateRef }
|
|
787
|
-
];
|
|
788
|
-
RichTextDirective.propDecorators = {
|
|
789
|
-
editable: [{ type: Input, args: ['scRichTextEditable',] }],
|
|
790
|
-
field: [{ type: Input, args: ['scRichText',] }]
|
|
753
|
+
class RichTextDirective {
|
|
754
|
+
constructor(viewContainer, templateRef) {
|
|
755
|
+
this.viewContainer = viewContainer;
|
|
756
|
+
this.templateRef = templateRef;
|
|
757
|
+
this.editable = true;
|
|
758
|
+
}
|
|
759
|
+
ngOnChanges(changes) {
|
|
760
|
+
if (changes.field || changes.editable) {
|
|
761
|
+
if (!this.viewRef) {
|
|
762
|
+
this.viewContainer.clear();
|
|
763
|
+
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
764
|
+
}
|
|
765
|
+
this.updateView();
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
updateView() {
|
|
769
|
+
const field = this.field;
|
|
770
|
+
if (!field || (!field.editable && !field.value)) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
const html = field.editable && this.editable ? field.editable : field.value;
|
|
774
|
+
this.viewRef.rootNodes.forEach((node) => {
|
|
775
|
+
node.innerHTML = html;
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
RichTextDirective.decorators = [
|
|
780
|
+
{ type: Directive, args: [{
|
|
781
|
+
selector: '[scRichText]',
|
|
782
|
+
},] }
|
|
783
|
+
];
|
|
784
|
+
RichTextDirective.ctorParameters = () => [
|
|
785
|
+
{ type: ViewContainerRef },
|
|
786
|
+
{ type: TemplateRef }
|
|
787
|
+
];
|
|
788
|
+
RichTextDirective.propDecorators = {
|
|
789
|
+
editable: [{ type: Input, args: ['scRichTextEditable',] }],
|
|
790
|
+
field: [{ type: Input, args: ['scRichText',] }]
|
|
791
791
|
};
|
|
792
792
|
|
|
793
|
-
class TextDirective {
|
|
794
|
-
constructor(viewContainer, templateRef) {
|
|
795
|
-
this.viewContainer = viewContainer;
|
|
796
|
-
this.templateRef = templateRef;
|
|
797
|
-
this.editable = true;
|
|
798
|
-
this.encode = true;
|
|
799
|
-
}
|
|
800
|
-
ngOnChanges(changes) {
|
|
801
|
-
if (changes.field || changes.editable || changes.encode) {
|
|
802
|
-
if (!this.viewRef) {
|
|
803
|
-
this.viewContainer.clear();
|
|
804
|
-
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
805
|
-
}
|
|
806
|
-
this.updateView();
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
updateView() {
|
|
810
|
-
const field = this.field;
|
|
811
|
-
let editable = this.editable;
|
|
812
|
-
if (!field || (!field.editable && (field.value === undefined || field.value === ''))) {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
// can't use editable value if we want to output unencoded
|
|
816
|
-
if (!this.encode) {
|
|
817
|
-
editable = false;
|
|
818
|
-
}
|
|
819
|
-
const html = field.editable && editable ? field.editable : field.value;
|
|
820
|
-
const setDangerously = (field.editable && editable) || !this.encode;
|
|
821
|
-
this.viewRef.rootNodes.forEach((node) => {
|
|
822
|
-
if (setDangerously) {
|
|
823
|
-
node.innerHTML = html;
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
node.textContent = html;
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
TextDirective.decorators = [
|
|
832
|
-
{ type: Directive, args: [{
|
|
833
|
-
selector: '[scText]',
|
|
834
|
-
},] }
|
|
835
|
-
];
|
|
836
|
-
TextDirective.ctorParameters = () => [
|
|
837
|
-
{ type: ViewContainerRef },
|
|
838
|
-
{ type: TemplateRef }
|
|
839
|
-
];
|
|
840
|
-
TextDirective.propDecorators = {
|
|
841
|
-
editable: [{ type: Input, args: ['scTextEditable',] }],
|
|
842
|
-
encode: [{ type: Input, args: ['scTextEncode',] }],
|
|
843
|
-
field: [{ type: Input, args: ['scText',] }]
|
|
793
|
+
class TextDirective {
|
|
794
|
+
constructor(viewContainer, templateRef) {
|
|
795
|
+
this.viewContainer = viewContainer;
|
|
796
|
+
this.templateRef = templateRef;
|
|
797
|
+
this.editable = true;
|
|
798
|
+
this.encode = true;
|
|
799
|
+
}
|
|
800
|
+
ngOnChanges(changes) {
|
|
801
|
+
if (changes.field || changes.editable || changes.encode) {
|
|
802
|
+
if (!this.viewRef) {
|
|
803
|
+
this.viewContainer.clear();
|
|
804
|
+
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
805
|
+
}
|
|
806
|
+
this.updateView();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
updateView() {
|
|
810
|
+
const field = this.field;
|
|
811
|
+
let editable = this.editable;
|
|
812
|
+
if (!field || (!field.editable && (field.value === undefined || field.value === ''))) {
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
// can't use editable value if we want to output unencoded
|
|
816
|
+
if (!this.encode) {
|
|
817
|
+
editable = false;
|
|
818
|
+
}
|
|
819
|
+
const html = field.editable && editable ? field.editable : field.value;
|
|
820
|
+
const setDangerously = (field.editable && editable) || !this.encode;
|
|
821
|
+
this.viewRef.rootNodes.forEach((node) => {
|
|
822
|
+
if (setDangerously) {
|
|
823
|
+
node.innerHTML = html;
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
node.textContent = html;
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
TextDirective.decorators = [
|
|
832
|
+
{ type: Directive, args: [{
|
|
833
|
+
selector: '[scText]',
|
|
834
|
+
},] }
|
|
835
|
+
];
|
|
836
|
+
TextDirective.ctorParameters = () => [
|
|
837
|
+
{ type: ViewContainerRef },
|
|
838
|
+
{ type: TemplateRef }
|
|
839
|
+
];
|
|
840
|
+
TextDirective.propDecorators = {
|
|
841
|
+
editable: [{ type: Input, args: ['scTextEditable',] }],
|
|
842
|
+
encode: [{ type: Input, args: ['scTextEncode',] }],
|
|
843
|
+
field: [{ type: Input, args: ['scText',] }]
|
|
844
844
|
};
|
|
845
845
|
|
|
846
|
-
class DateDirective {
|
|
847
|
-
constructor(viewContainer, templateRef, datePipe) {
|
|
848
|
-
this.viewContainer = viewContainer;
|
|
849
|
-
this.templateRef = templateRef;
|
|
850
|
-
this.datePipe = datePipe;
|
|
851
|
-
this.editable = true;
|
|
852
|
-
}
|
|
853
|
-
ngOnChanges(changes) {
|
|
854
|
-
if (changes.field || changes.format) {
|
|
855
|
-
if (!this.viewRef) {
|
|
856
|
-
this.viewContainer.clear();
|
|
857
|
-
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
858
|
-
}
|
|
859
|
-
this.updateView();
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
updateView() {
|
|
863
|
-
const field = this.field;
|
|
864
|
-
if (!field || (!field.editable && !field.value)) {
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
const html = field.editable && this.editable ? field.editable : field.value;
|
|
868
|
-
const setDangerously = field.editable && this.editable;
|
|
869
|
-
this.viewRef.rootNodes.forEach((node) => {
|
|
870
|
-
if (setDangerously) {
|
|
871
|
-
node.innerHTML = html;
|
|
872
|
-
}
|
|
873
|
-
else {
|
|
874
|
-
node.textContent = this.datePipe.transform(html, this.format, this.timezone, this.locale);
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
DateDirective.decorators = [
|
|
880
|
-
{ type: Directive, args: [{
|
|
881
|
-
selector: '[scDate]',
|
|
882
|
-
},] }
|
|
883
|
-
];
|
|
884
|
-
DateDirective.ctorParameters = () => [
|
|
885
|
-
{ type: ViewContainerRef },
|
|
886
|
-
{ type: TemplateRef },
|
|
887
|
-
{ type: DatePipe }
|
|
888
|
-
];
|
|
889
|
-
DateDirective.propDecorators = {
|
|
890
|
-
format: [{ type: Input, args: ['scDateFormat',] }],
|
|
891
|
-
timezone: [{ type: Input, args: ['scDateTimezone',] }],
|
|
892
|
-
locale: [{ type: Input, args: ['scDateLocale',] }],
|
|
893
|
-
editable: [{ type: Input, args: ['scDateEditable',] }],
|
|
894
|
-
field: [{ type: Input, args: ['scDate',] }]
|
|
846
|
+
class DateDirective {
|
|
847
|
+
constructor(viewContainer, templateRef, datePipe) {
|
|
848
|
+
this.viewContainer = viewContainer;
|
|
849
|
+
this.templateRef = templateRef;
|
|
850
|
+
this.datePipe = datePipe;
|
|
851
|
+
this.editable = true;
|
|
852
|
+
}
|
|
853
|
+
ngOnChanges(changes) {
|
|
854
|
+
if (changes.field || changes.format) {
|
|
855
|
+
if (!this.viewRef) {
|
|
856
|
+
this.viewContainer.clear();
|
|
857
|
+
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
|
|
858
|
+
}
|
|
859
|
+
this.updateView();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
updateView() {
|
|
863
|
+
const field = this.field;
|
|
864
|
+
if (!field || (!field.editable && !field.value)) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
const html = field.editable && this.editable ? field.editable : field.value;
|
|
868
|
+
const setDangerously = field.editable && this.editable;
|
|
869
|
+
this.viewRef.rootNodes.forEach((node) => {
|
|
870
|
+
if (setDangerously) {
|
|
871
|
+
node.innerHTML = html;
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
node.textContent = this.datePipe.transform(html, this.format, this.timezone, this.locale);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
DateDirective.decorators = [
|
|
880
|
+
{ type: Directive, args: [{
|
|
881
|
+
selector: '[scDate]',
|
|
882
|
+
},] }
|
|
883
|
+
];
|
|
884
|
+
DateDirective.ctorParameters = () => [
|
|
885
|
+
{ type: ViewContainerRef },
|
|
886
|
+
{ type: TemplateRef },
|
|
887
|
+
{ type: DatePipe }
|
|
888
|
+
];
|
|
889
|
+
DateDirective.propDecorators = {
|
|
890
|
+
format: [{ type: Input, args: ['scDateFormat',] }],
|
|
891
|
+
timezone: [{ type: Input, args: ['scDateTimezone',] }],
|
|
892
|
+
locale: [{ type: Input, args: ['scDateLocale',] }],
|
|
893
|
+
editable: [{ type: Input, args: ['scDateEditable',] }],
|
|
894
|
+
field: [{ type: Input, args: ['scDate',] }]
|
|
895
895
|
};
|
|
896
896
|
|
|
897
|
-
class MissingComponentComponent {
|
|
898
|
-
}
|
|
899
|
-
MissingComponentComponent.decorators = [
|
|
900
|
-
{ type: Component, args: [{
|
|
901
|
-
selector: 'sc-missing-component',
|
|
897
|
+
class MissingComponentComponent {
|
|
898
|
+
}
|
|
899
|
+
MissingComponentComponent.decorators = [
|
|
900
|
+
{ type: Component, args: [{
|
|
901
|
+
selector: 'sc-missing-component',
|
|
902
902
|
template: `
|
|
903
903
|
<div
|
|
904
904
|
style="background: darkorange; outline: 5px solid orange; padding: 10px; color: white; max-width: 500px;"
|
|
@@ -906,193 +906,193 @@ MissingComponentComponent.decorators = [
|
|
|
906
906
|
<h2>{{ rendering.componentName }}</h2>
|
|
907
907
|
<p>JSS component is missing Angular component implementation.</p>
|
|
908
908
|
</div>
|
|
909
|
-
`
|
|
910
|
-
},] }
|
|
911
|
-
];
|
|
912
|
-
MissingComponentComponent.propDecorators = {
|
|
913
|
-
rendering: [{ type: Input }]
|
|
909
|
+
`
|
|
910
|
+
},] }
|
|
911
|
+
];
|
|
912
|
+
MissingComponentComponent.propDecorators = {
|
|
913
|
+
rendering: [{ type: Input }]
|
|
914
914
|
};
|
|
915
915
|
|
|
916
|
-
/**
|
|
917
|
-
* Renders a single JSS component given a rendering definition.
|
|
918
|
-
* Useful inside templated placeholders.
|
|
919
|
-
*/
|
|
920
|
-
class RenderComponentComponent {
|
|
921
|
-
constructor(componentFactoryResolver, differs, componentFactory, missingComponentComponent) {
|
|
922
|
-
this.componentFactoryResolver = componentFactoryResolver;
|
|
923
|
-
this.differs = differs;
|
|
924
|
-
this.componentFactory = componentFactory;
|
|
925
|
-
this.missingComponentComponent = missingComponentComponent;
|
|
926
|
-
this.destroyed = false;
|
|
927
|
-
}
|
|
928
|
-
set inputs(value) {
|
|
929
|
-
this._inputs = value;
|
|
930
|
-
if (!this._differ && value) {
|
|
931
|
-
this._differ = this.differs.find(value).create();
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
ngOnChanges(changes) {
|
|
935
|
-
if (changes.rendering) {
|
|
936
|
-
this._render();
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
_setComponentInputs(componentInstance, inputs) {
|
|
940
|
-
Object.entries(inputs).forEach(([input, inputValue]) => (componentInstance[input] = inputValue));
|
|
941
|
-
}
|
|
942
|
-
_subscribeComponentOutputs(componentInstance, outputs) {
|
|
943
|
-
Object.keys(outputs)
|
|
944
|
-
.filter((output) => componentInstance[output] && componentInstance[output] instanceof Observable)
|
|
945
|
-
.forEach((output) => componentInstance[output]
|
|
946
|
-
.pipe(takeWhile(() => !this.destroyed))
|
|
947
|
-
.subscribe(outputs[output]));
|
|
948
|
-
}
|
|
949
|
-
_render() {
|
|
950
|
-
this.view.clear();
|
|
951
|
-
if (!this.rendering) {
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
const resolveComponent = isRawRendering(this.rendering)
|
|
955
|
-
? Promise.resolve({
|
|
956
|
-
componentImplementation: RawComponent,
|
|
957
|
-
componentDefinition: this.rendering,
|
|
958
|
-
})
|
|
959
|
-
: this.componentFactory.getComponent(this.rendering);
|
|
960
|
-
resolveComponent.then((rendering) => {
|
|
961
|
-
if (!rendering.componentImplementation) {
|
|
962
|
-
const componentName = rendering.componentDefinition.componentName;
|
|
916
|
+
/**
|
|
917
|
+
* Renders a single JSS component given a rendering definition.
|
|
918
|
+
* Useful inside templated placeholders.
|
|
919
|
+
*/
|
|
920
|
+
class RenderComponentComponent {
|
|
921
|
+
constructor(componentFactoryResolver, differs, componentFactory, missingComponentComponent) {
|
|
922
|
+
this.componentFactoryResolver = componentFactoryResolver;
|
|
923
|
+
this.differs = differs;
|
|
924
|
+
this.componentFactory = componentFactory;
|
|
925
|
+
this.missingComponentComponent = missingComponentComponent;
|
|
926
|
+
this.destroyed = false;
|
|
927
|
+
}
|
|
928
|
+
set inputs(value) {
|
|
929
|
+
this._inputs = value;
|
|
930
|
+
if (!this._differ && value) {
|
|
931
|
+
this._differ = this.differs.find(value).create();
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
ngOnChanges(changes) {
|
|
935
|
+
if (changes.rendering) {
|
|
936
|
+
this._render();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
_setComponentInputs(componentInstance, inputs) {
|
|
940
|
+
Object.entries(inputs).forEach(([input, inputValue]) => (componentInstance[input] = inputValue));
|
|
941
|
+
}
|
|
942
|
+
_subscribeComponentOutputs(componentInstance, outputs) {
|
|
943
|
+
Object.keys(outputs)
|
|
944
|
+
.filter((output) => componentInstance[output] && componentInstance[output] instanceof Observable)
|
|
945
|
+
.forEach((output) => componentInstance[output]
|
|
946
|
+
.pipe(takeWhile(() => !this.destroyed))
|
|
947
|
+
.subscribe(outputs[output]));
|
|
948
|
+
}
|
|
949
|
+
_render() {
|
|
950
|
+
this.view.clear();
|
|
951
|
+
if (!this.rendering) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
const resolveComponent = isRawRendering(this.rendering)
|
|
955
|
+
? Promise.resolve({
|
|
956
|
+
componentImplementation: RawComponent,
|
|
957
|
+
componentDefinition: this.rendering,
|
|
958
|
+
})
|
|
959
|
+
: this.componentFactory.getComponent(this.rendering);
|
|
960
|
+
resolveComponent.then((rendering) => {
|
|
961
|
+
if (!rendering.componentImplementation) {
|
|
962
|
+
const componentName = rendering.componentDefinition.componentName;
|
|
963
963
|
console.error(`Attempted to render unknown component ${componentName}.`, `Ensure component is mapped, like:
|
|
964
964
|
JssModule.withComponents([
|
|
965
965
|
{ name: '${componentName}', type: ${componentName}Component }
|
|
966
|
-
])`);
|
|
967
|
-
rendering.componentImplementation = this.missingComponentComponent;
|
|
968
|
-
}
|
|
969
|
-
const componentFactory = rendering.componentFactory ||
|
|
970
|
-
this.componentFactoryResolver.resolveComponentFactory(rendering.componentImplementation);
|
|
971
|
-
const componentInstance = this.view.createComponent(componentFactory, 0).instance;
|
|
972
|
-
componentInstance.rendering = rendering.componentDefinition;
|
|
973
|
-
if (this._inputs) {
|
|
974
|
-
this._setComponentInputs(componentInstance, this._inputs);
|
|
975
|
-
}
|
|
976
|
-
if (this.outputs) {
|
|
977
|
-
this._subscribeComponentOutputs(componentInstance, this.outputs);
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
RenderComponentComponent.decorators = [
|
|
983
|
-
{ type: Component, args: [{
|
|
984
|
-
selector: 'sc-render-component',
|
|
966
|
+
])`);
|
|
967
|
+
rendering.componentImplementation = this.missingComponentComponent;
|
|
968
|
+
}
|
|
969
|
+
const componentFactory = rendering.componentFactory ||
|
|
970
|
+
this.componentFactoryResolver.resolveComponentFactory(rendering.componentImplementation);
|
|
971
|
+
const componentInstance = this.view.createComponent(componentFactory, 0).instance;
|
|
972
|
+
componentInstance.rendering = rendering.componentDefinition;
|
|
973
|
+
if (this._inputs) {
|
|
974
|
+
this._setComponentInputs(componentInstance, this._inputs);
|
|
975
|
+
}
|
|
976
|
+
if (this.outputs) {
|
|
977
|
+
this._subscribeComponentOutputs(componentInstance, this.outputs);
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
RenderComponentComponent.decorators = [
|
|
983
|
+
{ type: Component, args: [{
|
|
984
|
+
selector: 'sc-render-component',
|
|
985
985
|
template: `
|
|
986
986
|
<ng-template #view></ng-template>
|
|
987
|
-
`
|
|
988
|
-
},] }
|
|
989
|
-
];
|
|
990
|
-
RenderComponentComponent.ctorParameters = () => [
|
|
991
|
-
{ type: ComponentFactoryResolver },
|
|
992
|
-
{ type: KeyValueDiffers },
|
|
993
|
-
{ type: JssComponentFactoryService },
|
|
994
|
-
{ type: Type, decorators: [{ type: Inject, args: [PLACEHOLDER_MISSING_COMPONENT_COMPONENT,] }] }
|
|
995
|
-
];
|
|
996
|
-
RenderComponentComponent.propDecorators = {
|
|
997
|
-
rendering: [{ type: Input }],
|
|
998
|
-
outputs: [{ type: Input }],
|
|
999
|
-
view: [{ type: ViewChild, args: ['view', { read: ViewContainerRef, static: true },] }],
|
|
1000
|
-
inputs: [{ type: Input }]
|
|
987
|
+
`
|
|
988
|
+
},] }
|
|
989
|
+
];
|
|
990
|
+
RenderComponentComponent.ctorParameters = () => [
|
|
991
|
+
{ type: ComponentFactoryResolver },
|
|
992
|
+
{ type: KeyValueDiffers },
|
|
993
|
+
{ type: JssComponentFactoryService },
|
|
994
|
+
{ type: Type, decorators: [{ type: Inject, args: [PLACEHOLDER_MISSING_COMPONENT_COMPONENT,] }] }
|
|
995
|
+
];
|
|
996
|
+
RenderComponentComponent.propDecorators = {
|
|
997
|
+
rendering: [{ type: Input }],
|
|
998
|
+
outputs: [{ type: Input }],
|
|
999
|
+
view: [{ type: ViewChild, args: ['view', { read: ViewContainerRef, static: true },] }],
|
|
1000
|
+
inputs: [{ type: Input }]
|
|
1001
1001
|
};
|
|
1002
1002
|
|
|
1003
|
-
class JssModule {
|
|
1004
|
-
/**
|
|
1005
|
-
* Instantiates the JSS module with no component factory.
|
|
1006
|
-
* Useful for using it from libraries. Most of the time you'd want withComponents()
|
|
1007
|
-
* @returns {ModuleWithProviders<JssModule>} module
|
|
1008
|
-
*/
|
|
1009
|
-
static forRoot() {
|
|
1010
|
-
return {
|
|
1011
|
-
ngModule: JssModule,
|
|
1012
|
-
providers: [DatePipe, JssComponentFactoryService],
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Instantiates a module for a lazy-loaded JSS component
|
|
1017
|
-
* @param {Type<unknown>} component
|
|
1018
|
-
* @returns {ModuleWithProviders<JssModule>} module
|
|
1019
|
-
*/
|
|
1020
|
-
static forChild(component) {
|
|
1021
|
-
return {
|
|
1022
|
-
ngModule: JssModule,
|
|
1023
|
-
providers: [
|
|
1024
|
-
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: component, multi: true },
|
|
1025
|
-
{ provide: ROUTES, useValue: [], multi: true },
|
|
1026
|
-
{ provide: DYNAMIC_COMPONENT, useValue: component },
|
|
1027
|
-
],
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Instantiates the JSS module and specifies the mapping from component name to component implementation.
|
|
1032
|
-
* Appropriate when defining the set of JSS components that your app is aware of.
|
|
1033
|
-
* @param {ComponentNameAndType[]} components
|
|
1034
|
-
* @param {ComponentNameAndModule[]} [lazyComponents]
|
|
1035
|
-
* @returns {ModuleWithProviders<JssModule>} module
|
|
1036
|
-
*/
|
|
1037
|
-
static withComponents(components, lazyComponents) {
|
|
1038
|
-
return {
|
|
1039
|
-
ngModule: JssModule,
|
|
1040
|
-
providers: [
|
|
1041
|
-
{
|
|
1042
|
-
provide: ANALYZE_FOR_ENTRY_COMPONENTS,
|
|
1043
|
-
useValue: components,
|
|
1044
|
-
multi: true,
|
|
1045
|
-
},
|
|
1046
|
-
{ provide: PLACEHOLDER_COMPONENTS, useValue: components },
|
|
1047
|
-
{ provide: PLACEHOLDER_LAZY_COMPONENTS, useValue: lazyComponents || [] },
|
|
1048
|
-
{ provide: ROUTES, useValue: lazyComponents || [], multi: true },
|
|
1049
|
-
{ provide: PLACEHOLDER_MISSING_COMPONENT_COMPONENT, useValue: MissingComponentComponent },
|
|
1050
|
-
...JssModule.forRoot().providers,
|
|
1051
|
-
],
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
JssModule.decorators = [
|
|
1056
|
-
{ type: NgModule, args: [{
|
|
1057
|
-
imports: [CommonModule],
|
|
1058
|
-
declarations: [
|
|
1059
|
-
FileDirective,
|
|
1060
|
-
ImageDirective,
|
|
1061
|
-
LinkDirective,
|
|
1062
|
-
RouterLinkDirective,
|
|
1063
|
-
GenericLinkDirective,
|
|
1064
|
-
DateDirective,
|
|
1065
|
-
RenderEachDirective,
|
|
1066
|
-
RenderEmptyDirective,
|
|
1067
|
-
PlaceholderLoadingDirective,
|
|
1068
|
-
RenderComponentComponent,
|
|
1069
|
-
PlaceholderComponent,
|
|
1070
|
-
RawComponent,
|
|
1071
|
-
RichTextDirective,
|
|
1072
|
-
TextDirective,
|
|
1073
|
-
MissingComponentComponent,
|
|
1074
|
-
],
|
|
1075
|
-
exports: [
|
|
1076
|
-
FileDirective,
|
|
1077
|
-
ImageDirective,
|
|
1078
|
-
DateDirective,
|
|
1079
|
-
LinkDirective,
|
|
1080
|
-
RouterLinkDirective,
|
|
1081
|
-
GenericLinkDirective,
|
|
1082
|
-
RenderEachDirective,
|
|
1083
|
-
RenderEmptyDirective,
|
|
1084
|
-
RenderComponentComponent,
|
|
1085
|
-
PlaceholderComponent,
|
|
1086
|
-
PlaceholderLoadingDirective,
|
|
1087
|
-
RichTextDirective,
|
|
1088
|
-
TextDirective,
|
|
1089
|
-
],
|
|
1090
|
-
entryComponents: [RawComponent, MissingComponentComponent],
|
|
1091
|
-
},] }
|
|
1003
|
+
class JssModule {
|
|
1004
|
+
/**
|
|
1005
|
+
* Instantiates the JSS module with no component factory.
|
|
1006
|
+
* Useful for using it from libraries. Most of the time you'd want withComponents()
|
|
1007
|
+
* @returns {ModuleWithProviders<JssModule>} module
|
|
1008
|
+
*/
|
|
1009
|
+
static forRoot() {
|
|
1010
|
+
return {
|
|
1011
|
+
ngModule: JssModule,
|
|
1012
|
+
providers: [DatePipe, JssComponentFactoryService],
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Instantiates a module for a lazy-loaded JSS component
|
|
1017
|
+
* @param {Type<unknown>} component
|
|
1018
|
+
* @returns {ModuleWithProviders<JssModule>} module
|
|
1019
|
+
*/
|
|
1020
|
+
static forChild(component) {
|
|
1021
|
+
return {
|
|
1022
|
+
ngModule: JssModule,
|
|
1023
|
+
providers: [
|
|
1024
|
+
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: component, multi: true },
|
|
1025
|
+
{ provide: ROUTES, useValue: [], multi: true },
|
|
1026
|
+
{ provide: DYNAMIC_COMPONENT, useValue: component },
|
|
1027
|
+
],
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Instantiates the JSS module and specifies the mapping from component name to component implementation.
|
|
1032
|
+
* Appropriate when defining the set of JSS components that your app is aware of.
|
|
1033
|
+
* @param {ComponentNameAndType[]} components
|
|
1034
|
+
* @param {ComponentNameAndModule[]} [lazyComponents]
|
|
1035
|
+
* @returns {ModuleWithProviders<JssModule>} module
|
|
1036
|
+
*/
|
|
1037
|
+
static withComponents(components, lazyComponents) {
|
|
1038
|
+
return {
|
|
1039
|
+
ngModule: JssModule,
|
|
1040
|
+
providers: [
|
|
1041
|
+
{
|
|
1042
|
+
provide: ANALYZE_FOR_ENTRY_COMPONENTS,
|
|
1043
|
+
useValue: components,
|
|
1044
|
+
multi: true,
|
|
1045
|
+
},
|
|
1046
|
+
{ provide: PLACEHOLDER_COMPONENTS, useValue: components },
|
|
1047
|
+
{ provide: PLACEHOLDER_LAZY_COMPONENTS, useValue: lazyComponents || [] },
|
|
1048
|
+
{ provide: ROUTES, useValue: lazyComponents || [], multi: true },
|
|
1049
|
+
{ provide: PLACEHOLDER_MISSING_COMPONENT_COMPONENT, useValue: MissingComponentComponent },
|
|
1050
|
+
...JssModule.forRoot().providers,
|
|
1051
|
+
],
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
JssModule.decorators = [
|
|
1056
|
+
{ type: NgModule, args: [{
|
|
1057
|
+
imports: [CommonModule],
|
|
1058
|
+
declarations: [
|
|
1059
|
+
FileDirective,
|
|
1060
|
+
ImageDirective,
|
|
1061
|
+
LinkDirective,
|
|
1062
|
+
RouterLinkDirective,
|
|
1063
|
+
GenericLinkDirective,
|
|
1064
|
+
DateDirective,
|
|
1065
|
+
RenderEachDirective,
|
|
1066
|
+
RenderEmptyDirective,
|
|
1067
|
+
PlaceholderLoadingDirective,
|
|
1068
|
+
RenderComponentComponent,
|
|
1069
|
+
PlaceholderComponent,
|
|
1070
|
+
RawComponent,
|
|
1071
|
+
RichTextDirective,
|
|
1072
|
+
TextDirective,
|
|
1073
|
+
MissingComponentComponent,
|
|
1074
|
+
],
|
|
1075
|
+
exports: [
|
|
1076
|
+
FileDirective,
|
|
1077
|
+
ImageDirective,
|
|
1078
|
+
DateDirective,
|
|
1079
|
+
LinkDirective,
|
|
1080
|
+
RouterLinkDirective,
|
|
1081
|
+
GenericLinkDirective,
|
|
1082
|
+
RenderEachDirective,
|
|
1083
|
+
RenderEmptyDirective,
|
|
1084
|
+
RenderComponentComponent,
|
|
1085
|
+
PlaceholderComponent,
|
|
1086
|
+
PlaceholderLoadingDirective,
|
|
1087
|
+
RichTextDirective,
|
|
1088
|
+
TextDirective,
|
|
1089
|
+
],
|
|
1090
|
+
entryComponents: [RawComponent, MissingComponentComponent],
|
|
1091
|
+
},] }
|
|
1092
1092
|
];
|
|
1093
1093
|
|
|
1094
|
-
/**
|
|
1095
|
-
* Generated bundle index. Do not edit.
|
|
1094
|
+
/**
|
|
1095
|
+
* Generated bundle index. Do not edit.
|
|
1096
1096
|
*/
|
|
1097
1097
|
|
|
1098
1098
|
export { ComponentNameAndType, DYNAMIC_COMPONENT, FileDirective, GenericLinkDirective, ImageDirective, JssModule, LinkDirective, PlaceholderComponent, PlaceholderLoadingDirective, RichTextDirective, RouterLinkDirective, TextDirective, isRawRendering, PLACEHOLDER_COMPONENTS as ɵb, PLACEHOLDER_LAZY_COMPONENTS as ɵc, PLACEHOLDER_MISSING_COMPONENT_COMPONENT as ɵd, RenderEachDirective as ɵe, RenderEmptyDirective as ɵf, JssComponentFactoryService as ɵg, DateDirective as ɵh, RenderComponentComponent as ɵi, RawComponent as ɵj, MissingComponentComponent as ɵk };
|