@sitecore-jss/sitecore-jss-angular 16.0.0-canary.8 → 16.0.1

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