@sitecore-jss/sitecore-jss-angular 20.2.2 → 20.2.3-canary.2

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