@ethlete/contentful 1.0.1 → 1.0.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 (49) hide show
  1. package/esm2022/lib/components/audio/contentful-audio.component.mjs +65 -0
  2. package/esm2022/lib/components/file/contentful-file.component.mjs +54 -0
  3. package/esm2022/lib/components/image/contentful-image.component.mjs +137 -0
  4. package/esm2022/lib/components/rich-text-renderer/rich-text-renderer.component.mjs +113 -0
  5. package/esm2022/lib/components/video/contentful-video.component.mjs +57 -0
  6. package/{fesm2020 → fesm2022}/ethlete-contentful.mjs +23 -23
  7. package/{fesm2020 → fesm2022}/ethlete-contentful.mjs.map +1 -1
  8. package/lib/components/audio/contentful-audio.component.d.ts +1 -1
  9. package/lib/components/file/contentful-file.component.d.ts +1 -1
  10. package/lib/components/image/contentful-image.component.d.ts +1 -1
  11. package/lib/components/rich-text-renderer/rich-text-renderer.component.d.ts +1 -1
  12. package/lib/components/video/contentful-video.component.d.ts +1 -1
  13. package/package.json +9 -15
  14. package/esm2020/lib/components/audio/contentful-audio.component.mjs +0 -64
  15. package/esm2020/lib/components/file/contentful-file.component.mjs +0 -53
  16. package/esm2020/lib/components/image/contentful-image.component.mjs +0 -136
  17. package/esm2020/lib/components/rich-text-renderer/rich-text-renderer.component.mjs +0 -112
  18. package/esm2020/lib/components/video/contentful-video.component.mjs +0 -56
  19. package/fesm2015/ethlete-contentful.mjs +0 -753
  20. package/fesm2015/ethlete-contentful.mjs.map +0 -1
  21. /package/{esm2020 → esm2022}/ethlete-contentful.mjs +0 -0
  22. /package/{esm2020 → esm2022}/index.mjs +0 -0
  23. /package/{esm2020 → esm2022}/lib/components/audio/public-api.mjs +0 -0
  24. /package/{esm2020 → esm2022}/lib/components/file/public-api.mjs +0 -0
  25. /package/{esm2020 → esm2022}/lib/components/image/contentful-image.component.utils.mjs +0 -0
  26. /package/{esm2020 → esm2022}/lib/components/image/index.mjs +0 -0
  27. /package/{esm2020 → esm2022}/lib/components/image/public-api.mjs +0 -0
  28. /package/{esm2020 → esm2022}/lib/components/index.mjs +0 -0
  29. /package/{esm2020 → esm2022}/lib/components/public-api.mjs +0 -0
  30. /package/{esm2020 → esm2022}/lib/components/rich-text-renderer/index.mjs +0 -0
  31. /package/{esm2020 → esm2022}/lib/components/rich-text-renderer/public-api.mjs +0 -0
  32. /package/{esm2020 → esm2022}/lib/components/rich-text-renderer/rich-text-renderer.constants.mjs +0 -0
  33. /package/{esm2020 → esm2022}/lib/components/rich-text-renderer/rich-text-renderer.types.mjs +0 -0
  34. /package/{esm2020 → esm2022}/lib/components/rich-text-renderer/rich-text-renderer.util.mjs +0 -0
  35. /package/{esm2020 → esm2022}/lib/components/video/public-api.mjs +0 -0
  36. /package/{esm2020 → esm2022}/lib/constants/contentful.constants.mjs +0 -0
  37. /package/{esm2020 → esm2022}/lib/constants/index.mjs +0 -0
  38. /package/{esm2020 → esm2022}/lib/constants/public-api.mjs +0 -0
  39. /package/{esm2020 → esm2022}/lib/contentful.imports.mjs +0 -0
  40. /package/{esm2020 → esm2022}/lib/gql/asset.fragments.mjs +0 -0
  41. /package/{esm2020 → esm2022}/lib/gql/public-api.mjs +0 -0
  42. /package/{esm2020 → esm2022}/lib/public-api.mjs +0 -0
  43. /package/{esm2020 → esm2022}/lib/types/contentful.types.mjs +0 -0
  44. /package/{esm2020 → esm2022}/lib/types/index.mjs +0 -0
  45. /package/{esm2020 → esm2022}/lib/types/public-api.mjs +0 -0
  46. /package/{esm2020 → esm2022}/lib/utils/contentful-config.mjs +0 -0
  47. /package/{esm2020 → esm2022}/lib/utils/contentful.util.mjs +0 -0
  48. /package/{esm2020 → esm2022}/lib/utils/index.mjs +0 -0
  49. /package/{esm2020 → esm2022}/lib/utils/public-api.mjs +0 -0
@@ -1,753 +0,0 @@
1
- import { NgIf, NgClass, NgOptimizedImage, DOCUMENT } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, ChangeDetectorRef, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Renderer2, ElementRef, ComponentFactoryResolver, ApplicationRef, Injector } from '@angular/core';
4
- import { DomPortalOutlet, ComponentPortal } from '@angular/cdk/portal';
5
- import * as i1 from '@ethlete/cdk';
6
- import { PictureDataDirective, PictureComponent } from '@ethlete/cdk';
7
- import { BLOCKS, INLINES } from '@contentful/rich-text-types';
8
- import { gql } from '@ethlete/query';
9
-
10
- const CONTENTFUL_CONFIG = new InjectionToken('ContentfulConfig');
11
-
12
- const createContentfulConfig = (config = {}) => (Object.assign({
13
- useTailwindClasses: false,
14
- components: {
15
- audio: ContentfulAudioComponent,
16
- file: ContentfulFileComponent,
17
- image: ContentfulImageComponent,
18
- video: ContentfulVideoComponent,
19
- },
20
- customComponents: {},
21
- imageOptions: {
22
- srcsetSizes: ['375w', '1280w', '1920w', '2560w'],
23
- sizes: [],
24
- backgroundColor: null,
25
- },
26
- }, (config || {})));
27
-
28
- const RICH_TEXT_RENDERER_COMPONENT_DATA = new InjectionToken('RICH_TEXT_RENDERER_COMPONENT_DATA');
29
-
30
- const provideContentfulConfig = (contentfulConfig = {}) => {
31
- return { provide: CONTENTFUL_CONFIG, useValue: createContentfulConfig(contentfulConfig) };
32
- };
33
- const isContentfulImage = (v) => {
34
- return !!v && 'asset' in v && 'alt' in v && 'resizeBehavior' in v && 'focusArea' in v;
35
- };
36
- const isContentfulAsset = (v) => {
37
- return !!v && 'contentType' in v && 'description' in v && 'height' in v && 'url' in v && 'width' in v;
38
- };
39
-
40
- const generateDefaultContentfulImageSource = (data) => {
41
- const { url, contentType } = data;
42
- return {
43
- type: contentType,
44
- srcset: url,
45
- };
46
- };
47
- /**
48
- * Parses source set sizes into an object containing with and height. Eg.
49
- * - `"400"` - 400px width
50
- * - `"400x300"` - 400px width and 300px height
51
- * - `"400w"` - 400px width
52
- * - `"400h"` - 400px height
53
- * - `"400wx300h"` - 400px width and 300px height
54
- **/
55
- const parseContentfulImageSize = (size) => {
56
- let width = null;
57
- let height = null;
58
- if (size.includes('x')) {
59
- const [w, h] = size.split('x');
60
- width = w;
61
- height = h;
62
- }
63
- else if (size.includes('h')) {
64
- height = size;
65
- }
66
- else {
67
- width = size;
68
- }
69
- return {
70
- width: width ? parseInt(width, 10) : null,
71
- height: height ? parseInt(height, 10) : null,
72
- };
73
- };
74
- const generateContentfulImageSources = (data, srcsetSizes, backgroundColor) => {
75
- const assetData = isContentfulImage(data) ? data.asset : data;
76
- const imageData = isContentfulImage(data) ? data : null;
77
- if (!assetData) {
78
- return [];
79
- }
80
- const sources = [];
81
- const SOURCE_TYPES = ['image/avif', 'image/webp', 'image/png', 'image/jpg'];
82
- for (const type of SOURCE_TYPES) {
83
- const baseUrl = assetData.url;
84
- const sourceSets = [];
85
- const queryParams = [];
86
- // Set the format (e.g. 'fm=webp')
87
- queryParams.push(`fm=${type.split('/')[1]}`);
88
- if (backgroundColor) {
89
- queryParams.push(`bg=rgb:${backgroundColor}`);
90
- }
91
- if (imageData) {
92
- if (imageData.quality) {
93
- queryParams.push(`q=${imageData.quality}`);
94
- }
95
- if (imageData.focusArea) {
96
- queryParams.push(`f=${imageData.focusArea}`);
97
- }
98
- if (imageData.resizeBehavior) {
99
- queryParams.push(`fit=${imageData.resizeBehavior}`);
100
- }
101
- }
102
- if (srcsetSizes === null || srcsetSizes === void 0 ? void 0 : srcsetSizes.length) {
103
- const urlWithParams = `${baseUrl}?${queryParams.join('&')}`;
104
- for (const size of srcsetSizes) {
105
- const { width, height } = parseContentfulImageSize(size);
106
- if (width && height) {
107
- sourceSets.push(`${urlWithParams}&w=${width}&h=${height} ${width}w`);
108
- }
109
- else if (width) {
110
- sourceSets.push(`${urlWithParams}&w=${width} ${width}w`);
111
- }
112
- else if (height) {
113
- sourceSets.push(`${urlWithParams}&h=${height} ${height}h`);
114
- }
115
- }
116
- }
117
- sources.push({
118
- type,
119
- srcset: sourceSets.length ? sourceSets.join(', ') : `${baseUrl}?${queryParams.join('&')}`,
120
- });
121
- }
122
- return sources;
123
- };
124
-
125
- class ContentfulImageComponent {
126
- constructor() {
127
- this._richTextData = inject(RICH_TEXT_RENDERER_COMPONENT_DATA, {
128
- optional: true,
129
- });
130
- this.pictureData = inject(PictureDataDirective);
131
- this._cdr = inject(ChangeDetectorRef);
132
- this._data = null;
133
- this._sizes = [];
134
- this._srcsetSizes = [];
135
- this._backgroundColor = null;
136
- this.sources = [];
137
- }
138
- get data() {
139
- return this._data;
140
- }
141
- set data(v) {
142
- var _a, _b, _c, _d, _e;
143
- const assetData = isContentfulImage(v) ? v.asset : v;
144
- const imageData = isContentfulImage(v) ? v : null;
145
- if (assetData && !assetData.contentType) {
146
- this._data = null;
147
- console.warn('The provided asset is invalid', v);
148
- return;
149
- }
150
- if (assetData && !assetData.contentType.startsWith('image/')) {
151
- throw new Error('The provided asset is not an image');
152
- }
153
- this._data = v !== null && v !== void 0 ? v : null;
154
- this.pictureData.defaultSrc = assetData ? generateDefaultContentfulImageSource(assetData) : null;
155
- this.pictureData.alt = (_b = (_a = imageData === null || imageData === void 0 ? void 0 : imageData.alt) !== null && _a !== void 0 ? _a : assetData === null || assetData === void 0 ? void 0 : assetData.description) !== null && _b !== void 0 ? _b : null;
156
- this.pictureData.width = (_c = assetData === null || assetData === void 0 ? void 0 : assetData.width) !== null && _c !== void 0 ? _c : null;
157
- this.pictureData.height = (_d = assetData === null || assetData === void 0 ? void 0 : assetData.height) !== null && _d !== void 0 ? _d : null;
158
- this.pictureData.figcaption = (_e = imageData === null || imageData === void 0 ? void 0 : imageData.caption) !== null && _e !== void 0 ? _e : null;
159
- this.updateSizes();
160
- }
161
- get sizes() {
162
- return this._sizes;
163
- }
164
- set sizes(v) {
165
- var _a, _b;
166
- this._sizes = v;
167
- this.pictureData.sizes = (_b = (_a = this.sizes) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : null;
168
- }
169
- get srcsetSizes() {
170
- return this._srcsetSizes;
171
- }
172
- set srcsetSizes(v) {
173
- this._srcsetSizes = v;
174
- this.updateSizes();
175
- }
176
- get backgroundColor() {
177
- return this._backgroundColor;
178
- }
179
- set backgroundColor(v) {
180
- this._backgroundColor = v;
181
- this.updateSizes();
182
- }
183
- ngOnInit() {
184
- if (this._richTextData && !this.data) {
185
- this.data = this._richTextData;
186
- }
187
- }
188
- updateSizes() {
189
- this.sources = this._data ? generateContentfulImageSources(this._data, this.srcsetSizes, this.backgroundColor) : [];
190
- this._cdr.markForCheck();
191
- }
192
- }
193
- ContentfulImageComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulImageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
194
- ContentfulImageComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: ContentfulImageComponent, isStandalone: true, selector: "et-contentful-image", inputs: { data: "data", sizes: "sizes", srcsetSizes: "srcsetSizes", backgroundColor: "backgroundColor" }, host: { classAttribute: "et-contentful-image" }, hostDirectives: [{ directive: i1.PictureDataDirective, inputs: ["imgClass", "imgClass", "hasPriority", "hasPriority", "figureClass", "figureClass", "pictureClass", "pictureClass", "figcaptionClass", "figcaptionClass"] }], ngImport: i0, template: `
195
- <et-picture
196
- [imgClass]="pictureData.imgClass"
197
- [hasPriority]="pictureData.hasPriority"
198
- [figureClass]="pictureData.figureClass"
199
- [pictureClass]="pictureData.pictureClass"
200
- [figcaptionClass]="pictureData.figcaptionClass"
201
- [defaultSrc]="pictureData.defaultSrc"
202
- [alt]="pictureData.alt"
203
- [figcaption]="pictureData.figcaption"
204
- [width]="pictureData.width"
205
- [height]="pictureData.height"
206
- [sizes]="pictureData.sizes"
207
- [sources]="sources"
208
- />
209
- `, isInline: true, dependencies: [{ kind: "component", type: PictureComponent, selector: "et-picture", inputs: ["sources"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
210
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulImageComponent, decorators: [{
211
- type: Component,
212
- args: [{
213
- selector: 'et-contentful-image',
214
- template: `
215
- <et-picture
216
- [imgClass]="pictureData.imgClass"
217
- [hasPriority]="pictureData.hasPriority"
218
- [figureClass]="pictureData.figureClass"
219
- [pictureClass]="pictureData.pictureClass"
220
- [figcaptionClass]="pictureData.figcaptionClass"
221
- [defaultSrc]="pictureData.defaultSrc"
222
- [alt]="pictureData.alt"
223
- [figcaption]="pictureData.figcaption"
224
- [width]="pictureData.width"
225
- [height]="pictureData.height"
226
- [sizes]="pictureData.sizes"
227
- [sources]="sources"
228
- />
229
- `,
230
- changeDetection: ChangeDetectionStrategy.OnPush,
231
- encapsulation: ViewEncapsulation.None,
232
- standalone: true,
233
- imports: [NgIf, NgClass, NgOptimizedImage, PictureComponent],
234
- hostDirectives: [
235
- {
236
- directive: PictureDataDirective,
237
- // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
238
- inputs: ['imgClass', 'hasPriority', 'figureClass', 'pictureClass', 'figcaptionClass'],
239
- },
240
- ],
241
- host: {
242
- class: 'et-contentful-image',
243
- },
244
- }]
245
- }], propDecorators: { data: [{
246
- type: Input
247
- }], sizes: [{
248
- type: Input
249
- }], srcsetSizes: [{
250
- type: Input
251
- }], backgroundColor: [{
252
- type: Input
253
- }] } });
254
-
255
- const createRenderCommandsFromContentfulRichText = (options) => {
256
- const { data, config } = options;
257
- const commands = [];
258
- const resourceMap = createContentfulResourceMap(data.links);
259
- createContentfulRenderCommand(data.json, { children: commands, payload: data.json.nodeType }, resourceMap, config);
260
- return commands;
261
- };
262
- const createContentfulRenderCommand = (node, parent, resourceMap, config) => {
263
- var _a, _b, _c, _d, _e;
264
- const { nodeType, data: nodeData } = node;
265
- const { children, marks, value } = getContentfulNodeProps(node);
266
- const command = {
267
- payload: translateContentfulNodeTypeToHtmlTag(nodeType),
268
- data: value,
269
- attributes: Object.assign(Object.assign({}, (marks
270
- ? {
271
- class: transformContentfulMarks(marks, config.useTailwindClasses),
272
- }
273
- : {})), (nodeData['uri'] ? { href: nodeData['uri'], target: '_blank' } : {})),
274
- children: [],
275
- };
276
- const entryId = (_b = (_a = nodeData['target']) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id;
277
- if (nodeType === BLOCKS.EMBEDDED_ASSET) {
278
- const asset = resourceMap.assetsBlock.get(entryId);
279
- if (asset) {
280
- const isImage = asset.contentType.startsWith('image/');
281
- const isVideo = asset.contentType.startsWith('video/');
282
- const isAudio = asset.contentType.startsWith('audio/');
283
- command.data = asset;
284
- if (isImage) {
285
- command.payload = config.components.image;
286
- }
287
- else if (isVideo) {
288
- command.payload = config.components.video;
289
- }
290
- else if (isAudio) {
291
- command.payload = config.components.audio;
292
- }
293
- else {
294
- command.payload = config.components.file;
295
- }
296
- }
297
- else {
298
- console.warn(`No asset found for entry id "${entryId}"!`, nodeData);
299
- }
300
- }
301
- else if (nodeType === BLOCKS.EMBEDDED_ENTRY || nodeType === INLINES.EMBEDDED_ENTRY) {
302
- const entry = (_c = resourceMap.entriesBlock.get(entryId)) !== null && _c !== void 0 ? _c : resourceMap.entriesInline.get(entryId);
303
- if (entry) {
304
- const type = (_d = entry === null || entry === void 0 ? void 0 : entry.__typename) !== null && _d !== void 0 ? _d : 'ET_UNKNOWN';
305
- // "Image" is a special wrapper content model for contentful assets.
306
- // It must be created by the user.
307
- const component = type === 'Image' ? ContentfulImageComponent : (_e = config.customComponents) === null || _e === void 0 ? void 0 : _e[type];
308
- if (component) {
309
- command.payload = component;
310
- command.data = entry;
311
- }
312
- else {
313
- command.data = `ERROR: No component found for embedded entry "${type}" as "${nodeType}"!`;
314
- }
315
- }
316
- else {
317
- console.warn(`No entry found for entry id "${entryId}"!`, nodeData);
318
- }
319
- }
320
- if (children && (children.length !== 1 || children[0].nodeType !== 'text')) {
321
- children.forEach((child) => {
322
- createContentfulRenderCommand(child, command, resourceMap, config);
323
- });
324
- }
325
- parent.children.push(command);
326
- return command;
327
- };
328
- const getContentfulNodeProps = (node) => {
329
- var _a, _b;
330
- const children = 'content' in node ? node.content : null;
331
- let marks = null;
332
- let value = null;
333
- if (children && children.length === 1 && children[0].nodeType === 'text') {
334
- marks = ((_a = children[0].marks) === null || _a === void 0 ? void 0 : _a.length) ? children[0].marks : null;
335
- value = children[0].value;
336
- }
337
- else {
338
- marks = 'marks' in node ? (((_b = node.marks) === null || _b === void 0 ? void 0 : _b.length) ? node.marks : null) : null;
339
- value = 'value' in node ? node.value : null;
340
- }
341
- return {
342
- children,
343
- marks,
344
- value,
345
- };
346
- };
347
- const transformContentfulMarks = (marks, useTailwindClasses) => {
348
- return marks
349
- .map((mark) => {
350
- switch (mark.type) {
351
- case 'bold':
352
- return useTailwindClasses ? 'font-bold' : mark.type;
353
- case 'italic':
354
- return useTailwindClasses ? 'italic' : mark.type;
355
- case 'underline':
356
- return useTailwindClasses ? 'underline' : mark.type;
357
- case 'code':
358
- return useTailwindClasses ? 'font-mono' : mark.type;
359
- default:
360
- return mark.type;
361
- }
362
- })
363
- .join(' ');
364
- };
365
- const translateContentfulNodeTypeToHtmlTag = (nodeType) => {
366
- switch (nodeType) {
367
- case BLOCKS.HEADING_1:
368
- return 'h1';
369
- case BLOCKS.HEADING_2:
370
- return 'h2';
371
- case BLOCKS.HEADING_3:
372
- return 'h3';
373
- case BLOCKS.HEADING_4:
374
- return 'h4';
375
- case BLOCKS.HEADING_5:
376
- return 'h5';
377
- case BLOCKS.HEADING_6:
378
- return 'h6';
379
- case BLOCKS.PARAGRAPH:
380
- return 'p';
381
- case BLOCKS.UL_LIST:
382
- return 'ul';
383
- case BLOCKS.OL_LIST:
384
- return 'ol';
385
- case BLOCKS.LIST_ITEM:
386
- return 'li';
387
- case BLOCKS.HR:
388
- return 'hr';
389
- case BLOCKS.QUOTE:
390
- return 'blockquote';
391
- case BLOCKS.TABLE:
392
- return 'table';
393
- case BLOCKS.TABLE_ROW:
394
- return 'tr';
395
- case BLOCKS.TABLE_CELL:
396
- return 'td';
397
- case BLOCKS.TABLE_HEADER_CELL:
398
- return 'th';
399
- case BLOCKS.EMBEDDED_ASSET:
400
- return 'div';
401
- case INLINES.HYPERLINK:
402
- return 'a';
403
- case INLINES.ENTRY_HYPERLINK:
404
- return 'a';
405
- case INLINES.ASSET_HYPERLINK:
406
- return 'a';
407
- case 'text':
408
- return 'span';
409
- // Will be ignored by the renderer
410
- case 'document':
411
- return 'document';
412
- case BLOCKS.EMBEDDED_ENTRY:
413
- return 'div';
414
- case INLINES.EMBEDDED_ENTRY:
415
- return 'div';
416
- default:
417
- return 'div';
418
- }
419
- };
420
- const createContentfulResourceMap = (links) => {
421
- var _a, _b, _c;
422
- const resourceMap = {
423
- assetsBlock: createContentfulMap((_a = links === null || links === void 0 ? void 0 : links.assets) === null || _a === void 0 ? void 0 : _a.block),
424
- entriesInline: createContentfulMap((_b = links === null || links === void 0 ? void 0 : links.entries) === null || _b === void 0 ? void 0 : _b.inline),
425
- entriesBlock: createContentfulMap((_c = links === null || links === void 0 ? void 0 : links.entries) === null || _c === void 0 ? void 0 : _c.block),
426
- };
427
- return resourceMap;
428
- };
429
- const createContentfulMap = (links) => {
430
- var _a;
431
- const assetMap = new Map();
432
- if (links) {
433
- for (const link of links) {
434
- if (!((_a = link === null || link === void 0 ? void 0 : link.sys) === null || _a === void 0 ? void 0 : _a.id)) {
435
- console.warn('Link has no sys.id property. Please include it inside your query.', link);
436
- continue;
437
- }
438
- assetMap.set(link.sys.id, link);
439
- }
440
- }
441
- return assetMap;
442
- };
443
-
444
- class ContentfulRichTextRendererComponent {
445
- constructor() {
446
- var _a;
447
- this._richText = null;
448
- this._renderer = inject(Renderer2);
449
- this._elementRef = inject(ElementRef);
450
- this._componentFactoryResolver = inject(ComponentFactoryResolver);
451
- this._document = inject(DOCUMENT);
452
- this._appRef = inject(ApplicationRef);
453
- this._injector = inject(Injector);
454
- this._config = (_a = inject(CONTENTFUL_CONFIG, { optional: true })) !== null && _a !== void 0 ? _a : createContentfulConfig();
455
- }
456
- get richText() {
457
- return this._richText;
458
- }
459
- set richText(v) {
460
- this._richText = v !== null && v !== void 0 ? v : null;
461
- this.resetAndRender();
462
- }
463
- resetAndRender() {
464
- // clear childNodes to prevent appending new richtext elements to existing one
465
- const childElements = this._elementRef.nativeElement.childNodes;
466
- for (const child of childElements) {
467
- this._renderer.removeChild(this._elementRef.nativeElement, child);
468
- }
469
- if (!this._richText) {
470
- return;
471
- }
472
- const commands = createRenderCommandsFromContentfulRichText({ data: this._richText, config: this._config });
473
- this._render(commands);
474
- }
475
- _render(commands) {
476
- // create a document fragment to hold the elements while we create them
477
- const fragment = document.createDocumentFragment();
478
- const hostCommand = {
479
- payload: 'document',
480
- children: commands,
481
- };
482
- // loop over the commands
483
- this._executeCommand({ command: hostCommand, parent: fragment });
484
- // append the fragment to the host element
485
- this._renderer.appendChild(this._elementRef.nativeElement, fragment);
486
- }
487
- _executeCommand(data) {
488
- const { command, parent } = data;
489
- let element = null;
490
- if (command.payload !== 'document') {
491
- if (typeof command.payload === 'string') {
492
- element = this._renderer.createElement(command.payload);
493
- if (command.data) {
494
- this._renderer.setProperty(element, 'innerText', command.data);
495
- }
496
- if (command.attributes) {
497
- for (const [name, value] of Object.entries(command.attributes)) {
498
- this._renderer.setAttribute(element, name, value);
499
- }
500
- }
501
- this._renderer.appendChild(parent, element);
502
- }
503
- else {
504
- const injector = Injector.create({
505
- providers: [
506
- {
507
- provide: RICH_TEXT_RENDERER_COMPONENT_DATA,
508
- useValue: command.data,
509
- },
510
- ],
511
- parent: this._injector,
512
- });
513
- const portal = new DomPortalOutlet(parent, this._componentFactoryResolver, this._appRef, injector, this._document);
514
- const comp = new ComponentPortal(command.payload);
515
- const ref = comp.attach(portal);
516
- if (ref.instance instanceof ContentfulImageComponent) {
517
- ref.instance.sizes = this._config.imageOptions.sizes;
518
- ref.instance.srcsetSizes = this._config.imageOptions.srcsetSizes;
519
- ref.instance.backgroundColor = this._config.imageOptions.backgroundColor;
520
- }
521
- element = ref.location.nativeElement;
522
- }
523
- }
524
- // loop over the commands
525
- for (const childCommand of command.children) {
526
- this._executeCommand({ command: childCommand, parent: element !== null && element !== void 0 ? element : parent });
527
- }
528
- }
529
- }
530
- ContentfulRichTextRendererComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulRichTextRendererComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
531
- ContentfulRichTextRendererComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: ContentfulRichTextRendererComponent, isStandalone: true, selector: "et-contentful-rich-text-renderer", inputs: { richText: "richText" }, host: { classAttribute: "et-contentful-rich-text-renderer" }, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
532
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulRichTextRendererComponent, decorators: [{
533
- type: Component,
534
- args: [{
535
- selector: 'et-contentful-rich-text-renderer',
536
- template: ``,
537
- encapsulation: ViewEncapsulation.None,
538
- changeDetection: ChangeDetectionStrategy.OnPush,
539
- standalone: true,
540
- host: {
541
- class: 'et-contentful-rich-text-renderer',
542
- },
543
- }]
544
- }], propDecorators: { richText: [{
545
- type: Input
546
- }] } });
547
-
548
- class ContentfulAudioComponent {
549
- constructor() {
550
- this._richTextData = inject(RICH_TEXT_RENDERER_COMPONENT_DATA, { optional: true });
551
- this._data = null;
552
- this.audioClass = null;
553
- this.figureClass = null;
554
- this.figcaptionClass = null;
555
- }
556
- get data() {
557
- return this._data;
558
- }
559
- set data(v) {
560
- if (v && !v.contentType) {
561
- this._data = null;
562
- console.warn('The provided asset is invalid', v);
563
- return;
564
- }
565
- if (v && !v.contentType.startsWith('audio/')) {
566
- throw new Error('The provided asset is not an audio');
567
- }
568
- this._data = v !== null && v !== void 0 ? v : null;
569
- }
570
- ngOnInit() {
571
- if (this._richTextData && !this.data) {
572
- this.data = this._richTextData;
573
- }
574
- }
575
- }
576
- ContentfulAudioComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulAudioComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
577
- ContentfulAudioComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: ContentfulAudioComponent, isStandalone: true, selector: "et-contentful-audio", inputs: { data: "data", audioClass: "audioClass", figureClass: "figureClass", figcaptionClass: "figcaptionClass" }, ngImport: i0, template: `
578
- <figure *ngIf="data" [ngClass]="figureClass">
579
- <figcaption [ngClass]="figcaptionClass">{{ data.title }}</figcaption>
580
- <audio [ngClass]="audioClass" controls src="{{ data.url }}"></audio>
581
- </figure>
582
- `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
583
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulAudioComponent, decorators: [{
584
- type: Component,
585
- args: [{
586
- selector: 'et-contentful-audio',
587
- template: `
588
- <figure *ngIf="data" [ngClass]="figureClass">
589
- <figcaption [ngClass]="figcaptionClass">{{ data.title }}</figcaption>
590
- <audio [ngClass]="audioClass" controls src="{{ data.url }}"></audio>
591
- </figure>
592
- `,
593
- changeDetection: ChangeDetectionStrategy.OnPush,
594
- encapsulation: ViewEncapsulation.None,
595
- standalone: true,
596
- imports: [NgIf, NgClass],
597
- }]
598
- }], propDecorators: { data: [{
599
- type: Input
600
- }], audioClass: [{
601
- type: Input
602
- }], figureClass: [{
603
- type: Input
604
- }], figcaptionClass: [{
605
- type: Input
606
- }] } });
607
-
608
- class ContentfulFileComponent {
609
- constructor() {
610
- this._richTextData = inject(RICH_TEXT_RENDERER_COMPONENT_DATA, { optional: true });
611
- this._data = null;
612
- this.fileClass = null;
613
- }
614
- get data() {
615
- return this._data;
616
- }
617
- set data(v) {
618
- if (v && !v.contentType) {
619
- this._data = null;
620
- console.warn('The provided asset is invalid', v);
621
- return;
622
- }
623
- this._data = v !== null && v !== void 0 ? v : null;
624
- }
625
- ngOnInit() {
626
- if (this._richTextData && !this.data) {
627
- this.data = this._richTextData;
628
- }
629
- }
630
- }
631
- ContentfulFileComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulFileComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
632
- ContentfulFileComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: ContentfulFileComponent, isStandalone: true, selector: "et-contentful-file", inputs: { data: "data", fileClass: "fileClass" }, ngImport: i0, template: `
633
- <a *ngIf="data" [href]="data.url" [ngClass]="fileClass" class="underline" target="_blank">
634
- {{ data.title }} ({{ data.size }} Bytes)
635
- </a>
636
- `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
637
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulFileComponent, decorators: [{
638
- type: Component,
639
- args: [{
640
- selector: 'et-contentful-file',
641
- template: `
642
- <a *ngIf="data" [href]="data.url" [ngClass]="fileClass" class="underline" target="_blank">
643
- {{ data.title }} ({{ data.size }} Bytes)
644
- </a>
645
- `,
646
- changeDetection: ChangeDetectionStrategy.OnPush,
647
- encapsulation: ViewEncapsulation.None,
648
- standalone: true,
649
- imports: [NgIf, NgClass],
650
- }]
651
- }], propDecorators: { data: [{
652
- type: Input
653
- }], fileClass: [{
654
- type: Input
655
- }] } });
656
-
657
- class ContentfulVideoComponent {
658
- constructor() {
659
- this._richTextData = inject(RICH_TEXT_RENDERER_COMPONENT_DATA, { optional: true });
660
- this._data = null;
661
- this.videoClass = null;
662
- }
663
- get data() {
664
- return this._data;
665
- }
666
- set data(v) {
667
- if (v && !v.contentType) {
668
- this._data = null;
669
- console.warn('The provided asset is invalid', v);
670
- return;
671
- }
672
- if (v && !v.contentType.startsWith('video/')) {
673
- throw new Error('The provided asset is not an video');
674
- }
675
- this._data = v !== null && v !== void 0 ? v : null;
676
- }
677
- ngOnInit() {
678
- if (this._richTextData && !this.data) {
679
- this.data = this._richTextData;
680
- }
681
- }
682
- }
683
- ContentfulVideoComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulVideoComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
684
- ContentfulVideoComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: ContentfulVideoComponent, isStandalone: true, selector: "et-contentful-video", inputs: { data: "data", videoClass: "videoClass" }, ngImport: i0, template: `
685
- <video *ngIf="data" [ngClass]="videoClass" controls>
686
- <source src="{{ data.url }}" type="{{ data.contentType }}" />
687
- </video>
688
- `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
689
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ContentfulVideoComponent, decorators: [{
690
- type: Component,
691
- args: [{
692
- selector: 'et-contentful-video',
693
- template: `
694
- <video *ngIf="data" [ngClass]="videoClass" controls>
695
- <source src="{{ data.url }}" type="{{ data.contentType }}" />
696
- </video>
697
- `,
698
- changeDetection: ChangeDetectionStrategy.OnPush,
699
- encapsulation: ViewEncapsulation.None,
700
- standalone: true,
701
- imports: [NgIf, NgClass],
702
- }]
703
- }], propDecorators: { data: [{
704
- type: Input
705
- }], videoClass: [{
706
- type: Input
707
- }] } });
708
-
709
- const ContentfulImports = [
710
- ContentfulAudioComponent,
711
- ContentfulFileComponent,
712
- ContentfulImageComponent,
713
- ContentfulVideoComponent,
714
- ContentfulRichTextRendererComponent,
715
- ];
716
-
717
- const GQL_FRAGMENT_CONTENTFUL_ASSET = gql `
718
- fragment AssetData on Asset {
719
- sys {
720
- id
721
- }
722
- url
723
- title
724
- width
725
- height
726
- description
727
- contentType
728
- size
729
- }
730
- `;
731
- const GQL_FRAGMENT_CONTENTFUL_IMAGE = gql `
732
- fragment ImageData on Image {
733
- sys {
734
- id
735
- }
736
- asset {
737
- ...AssetData
738
- }
739
- alt
740
- caption
741
- resizeBehavior
742
- focusArea
743
- quality
744
- __typename
745
- }
746
- `;
747
-
748
- /**
749
- * Generated bundle index. Do not edit.
750
- */
751
-
752
- export { CONTENTFUL_CONFIG, ContentfulAudioComponent, ContentfulFileComponent, ContentfulImageComponent, ContentfulImports, ContentfulRichTextRendererComponent, ContentfulVideoComponent, GQL_FRAGMENT_CONTENTFUL_ASSET, GQL_FRAGMENT_CONTENTFUL_IMAGE, RICH_TEXT_RENDERER_COMPONENT_DATA, createContentfulConfig, createContentfulMap, createContentfulRenderCommand, createContentfulResourceMap, createRenderCommandsFromContentfulRichText, generateContentfulImageSources, generateDefaultContentfulImageSource, getContentfulNodeProps, isContentfulAsset, isContentfulImage, parseContentfulImageSize, provideContentfulConfig, transformContentfulMarks, translateContentfulNodeTypeToHtmlTag };
753
- //# sourceMappingURL=ethlete-contentful.mjs.map