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