@dotcms/uve 0.0.1-beta.14 → 0.0.1-beta.16

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.
@@ -0,0 +1,767 @@
1
+ 'use strict';
2
+
3
+ var types = require('./types.cjs.js');
4
+
5
+ /**
6
+ * Actions received from the dotcms editor
7
+ *
8
+ * @export
9
+ * @enum {number}
10
+ */
11
+ exports.__DOTCMS_UVE_EVENT__ = void 0;
12
+ (function (__DOTCMS_UVE_EVENT__) {
13
+ /**
14
+ * Request to page to reload
15
+ */
16
+ __DOTCMS_UVE_EVENT__["UVE_RELOAD_PAGE"] = "uve-reload-page";
17
+ /**
18
+ * Request the bounds for the elements
19
+ */
20
+ __DOTCMS_UVE_EVENT__["UVE_REQUEST_BOUNDS"] = "uve-request-bounds";
21
+ /**
22
+ * Received pong from the editor
23
+ */
24
+ __DOTCMS_UVE_EVENT__["UVE_EDITOR_PONG"] = "uve-editor-pong";
25
+ /**
26
+ * Received scroll event trigger from the editor
27
+ */
28
+ __DOTCMS_UVE_EVENT__["UVE_SCROLL_INSIDE_IFRAME"] = "uve-scroll-inside-iframe";
29
+ /**
30
+ * TODO:
31
+ * Set the page data - This is used to catch the "changes" event.
32
+ * We must to re-check the name late.
33
+ */
34
+ __DOTCMS_UVE_EVENT__["UVE_SET_PAGE_DATA"] = "uve-set-page-data";
35
+ /**
36
+ * Copy contentlet inline editing success
37
+ */
38
+ __DOTCMS_UVE_EVENT__["UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS"] = "uve-copy-contentlet-inline-editing-success";
39
+ })(exports.__DOTCMS_UVE_EVENT__ || (exports.__DOTCMS_UVE_EVENT__ = {}));
40
+
41
+ /**
42
+ * Calculates the bounding information for each page element within the given containers.
43
+ *
44
+ * @export
45
+ * @param {HTMLDivElement[]} containers - An array of HTMLDivElement representing the containers.
46
+ * @return {DotCMSContainerBound[]} An array of objects containing the bounding information for each page element.
47
+ * @example
48
+ * ```ts
49
+ * const containers = document.querySelectorAll('.container');
50
+ * const bounds = getDotCMSPageBounds(containers);
51
+ * console.log(bounds);
52
+ * ```
53
+ */
54
+ function getDotCMSPageBounds(containers) {
55
+ return containers.map(container => {
56
+ const containerRect = container.getBoundingClientRect();
57
+ const contentlets = Array.from(container.querySelectorAll('[data-dot-object="contentlet"]'));
58
+ return {
59
+ x: containerRect.x,
60
+ y: containerRect.y,
61
+ width: containerRect.width,
62
+ height: containerRect.height,
63
+ payload: JSON.stringify({
64
+ container: getDotCMSContainerData(container)
65
+ }),
66
+ contentlets: getDotCMSContentletsBound(containerRect, contentlets)
67
+ };
68
+ });
69
+ }
70
+ /**
71
+ * Calculates the bounding information for each contentlet inside a container.
72
+ *
73
+ * @export
74
+ * @param {DOMRect} containerRect - The bounding rectangle of the container.
75
+ * @param {HTMLDivElement[]} contentlets - An array of HTMLDivElement representing the contentlets.
76
+ * @return {DotCMSContentletBound[]} An array of objects containing the bounding information for each contentlet.
77
+ * @example
78
+ * ```ts
79
+ * const containerRect = container.getBoundingClientRect();
80
+ * const contentlets = container.querySelectorAll('.contentlet');
81
+ * const bounds = getDotCMSContentletsBound(containerRect, contentlets);
82
+ * console.log(bounds); // Element bounds within the container
83
+ * ```
84
+ */
85
+ function getDotCMSContentletsBound(containerRect, contentlets) {
86
+ return contentlets.map(contentlet => {
87
+ const contentletRect = contentlet.getBoundingClientRect();
88
+ return {
89
+ x: 0,
90
+ y: contentletRect.y - containerRect.y,
91
+ width: contentletRect.width,
92
+ height: contentletRect.height,
93
+ payload: JSON.stringify({
94
+ container: contentlet.dataset?.['dotContainer'] ? JSON.parse(contentlet.dataset?.['dotContainer']) : getClosestDotCMSContainerData(contentlet),
95
+ contentlet: {
96
+ identifier: contentlet.dataset?.['dotIdentifier'],
97
+ title: contentlet.dataset?.['dotTitle'],
98
+ inode: contentlet.dataset?.['dotInode'],
99
+ contentType: contentlet.dataset?.['dotType']
100
+ }
101
+ })
102
+ };
103
+ });
104
+ }
105
+ /**
106
+ * Get container data from VTLS.
107
+ *
108
+ * @export
109
+ * @param {HTMLElement} container - The container element.
110
+ * @return {object} An object containing the container data.
111
+ * @example
112
+ * ```ts
113
+ * const container = document.querySelector('.container');
114
+ * const data = getContainerData(container);
115
+ * console.log(data);
116
+ * ```
117
+ */
118
+ function getDotCMSContainerData(container) {
119
+ return {
120
+ acceptTypes: container.dataset?.['dotAcceptTypes'] || '',
121
+ identifier: container.dataset?.['dotIdentifier'] || '',
122
+ maxContentlets: container.dataset?.['maxContentlets'] || '',
123
+ uuid: container.dataset?.['dotUuid'] || ''
124
+ };
125
+ }
126
+ /**
127
+ * Get the closest container data from the contentlet.
128
+ *
129
+ * @export
130
+ * @param {Element} element - The contentlet element.
131
+ * @return {object | null} An object containing the closest container data or null if no container is found.
132
+ * @example
133
+ * ```ts
134
+ * const contentlet = document.querySelector('.contentlet');
135
+ * const data = getClosestDotCMSContainerData(contentlet);
136
+ * console.log(data);
137
+ * ```
138
+ */
139
+ function getClosestDotCMSContainerData(element) {
140
+ // Find the closest ancestor element with data-dot-object="container" attribute
141
+ const container = element.closest('[data-dot-object="container"]');
142
+ // If a container element is found
143
+ if (container) {
144
+ // Return the dataset of the container element
145
+ return getDotCMSContainerData(container);
146
+ } else {
147
+ // If no container element is found, return null
148
+ console.warn('No container found for the contentlet');
149
+ return null;
150
+ }
151
+ }
152
+ /**
153
+ * Find the closest contentlet element based on HTMLElement.
154
+ *
155
+ * @export
156
+ * @param {HTMLElement | null} element - The starting element.
157
+ * @return {HTMLElement | null} The closest contentlet element or null if not found.
158
+ * @example
159
+ * const element = document.querySelector('.some-element');
160
+ * const contentlet = findDotCMSElement(element);
161
+ * console.log(contentlet);
162
+ */
163
+ function findDotCMSElement(element) {
164
+ if (!element) return null;
165
+ if (element?.dataset?.['dotObject'] === 'contentlet' || element?.dataset?.['dotObject'] === 'container' && element.children.length === 0) {
166
+ return element;
167
+ }
168
+ return findDotCMSElement(element?.['parentElement']);
169
+ }
170
+ /**
171
+ * Find VTL data within a target element.
172
+ *
173
+ * @export
174
+ * @param {HTMLElement} target - The target element to search within.
175
+ * @return {Array<{ inode: string, name: string }> | null} An array of objects containing VTL data or null if none found.
176
+ * @example
177
+ * ```ts
178
+ * const target = document.querySelector('.target-element');
179
+ * const vtlData = findDotCMSVTLData(target);
180
+ * console.log(vtlData);
181
+ * ```
182
+ */
183
+ function findDotCMSVTLData(target) {
184
+ const vltElements = target.querySelectorAll('[data-dot-object="vtl-file"]');
185
+ if (!vltElements.length) {
186
+ return null;
187
+ }
188
+ return Array.from(vltElements).map(vltElement => {
189
+ return {
190
+ inode: vltElement.dataset?.['dotInode'],
191
+ name: vltElement.dataset?.['dotUrl']
192
+ };
193
+ });
194
+ }
195
+ /**
196
+ * Check if the scroll position is at the bottom of the page.
197
+ *
198
+ * @export
199
+ * @return {boolean} True if the scroll position is at the bottom, otherwise false.
200
+ * @example
201
+ * ```ts
202
+ * if (dotCMSScrollIsInBottom()) {
203
+ * console.log('Scrolled to the bottom');
204
+ * }
205
+ * ```
206
+ */
207
+ function computeScrollIsInBottom() {
208
+ const documentHeight = document.documentElement.scrollHeight;
209
+ const viewportHeight = window.innerHeight;
210
+ const scrollY = window.scrollY;
211
+ return scrollY + viewportHeight >= documentHeight;
212
+ }
213
+ /**
214
+ *
215
+ *
216
+ * Combine classes into a single string.
217
+ *
218
+ * @param {string[]} classes
219
+ * @returns {string} Combined classes
220
+ */
221
+ const combineClasses = classes => classes.filter(Boolean).join(' ');
222
+ /**
223
+ *
224
+ *
225
+ * Calculates and returns the CSS Grid positioning classes for a column based on its configuration.
226
+ * Uses a 12-column grid system where columns are positioned using grid-column-start and grid-column-end.
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * const classes = getColumnPositionClasses({
231
+ * leftOffset: 1, // Starts at the first column
232
+ * width: 6 // Spans 6 columns
233
+ * });
234
+ * // Returns: { startClass: 'col-start-1', endClass: 'col-end-7' }
235
+ * ```
236
+ *
237
+ * @param {DotPageAssetLayoutColumn} column - Column configuration object
238
+ * @param {number} column.leftOffset - Starting position (0-based) in the grid
239
+ * @param {number} column.width - Number of columns to span
240
+ * @returns {{ startClass: string, endClass: string }} Object containing CSS class names for grid positioning
241
+ */
242
+ const getColumnPositionClasses = column => {
243
+ const {
244
+ leftOffset,
245
+ width
246
+ } = column;
247
+ const startClass = `${START_CLASS}${leftOffset}`;
248
+ const endClass = `${END_CLASS}${leftOffset + width}`;
249
+ return {
250
+ startClass,
251
+ endClass
252
+ };
253
+ };
254
+ /**
255
+ *
256
+ *
257
+ * Helper function that returns an object containing the dotCMS data attributes.
258
+ * @param {DotCMSContentlet} contentlet - The contentlet to get the attributes for
259
+ * @param {string} container - The container to get the attributes for
260
+ * @returns {DotContentletAttributes} The dotCMS data attributes
261
+ */
262
+ function getDotContentletAttributes(contentlet, container) {
263
+ return {
264
+ 'data-dot-identifier': contentlet?.identifier,
265
+ 'data-dot-basetype': contentlet?.baseType,
266
+ 'data-dot-title': contentlet?.['widgetTitle'] || contentlet?.title,
267
+ 'data-dot-inode': contentlet?.inode,
268
+ 'data-dot-type': contentlet?.contentType,
269
+ 'data-dot-container': container,
270
+ 'data-dot-on-number-of-pages': contentlet?.['onNumberOfPages']
271
+ };
272
+ }
273
+ /**
274
+ *
275
+ *
276
+ * Retrieves container data from a DotCMS page asset using the container reference.
277
+ * This function processes the container information and returns a standardized format
278
+ * for container editing.
279
+ *
280
+ * @param {DotCMSPageAsset} dotCMSPageAsset - The page asset containing all containers data
281
+ * @param {DotCMSColumnContainer} columContainer - The container reference from the layout
282
+ * @throws {Error} When page asset is invalid or container is not found
283
+ * @returns {EditableContainerData} Formatted container data for editing
284
+ *
285
+ * @example
286
+ * const containerData = getContainersData(pageAsset, containerRef);
287
+ * // Returns: { uuid: '123', identifier: 'cont1', acceptTypes: 'type1,type2', maxContentlets: 5 }
288
+ */
289
+ const getContainersData = (dotCMSPageAsset, columContainer) => {
290
+ const {
291
+ identifier,
292
+ uuid
293
+ } = columContainer;
294
+ const dotContainer = dotCMSPageAsset.containers[identifier];
295
+ if (!dotContainer) {
296
+ return null;
297
+ }
298
+ const {
299
+ containerStructures,
300
+ container
301
+ } = dotContainer;
302
+ const acceptTypes = containerStructures?.map(structure => structure.contentTypeVar).join(',') ?? '';
303
+ const variantId = container?.parentPermissionable?.variantId;
304
+ const maxContentlets = container?.maxContentlets ?? 0;
305
+ const path = container?.path;
306
+ return {
307
+ uuid,
308
+ variantId,
309
+ acceptTypes,
310
+ maxContentlets,
311
+ identifier: path ?? identifier
312
+ };
313
+ };
314
+ /**
315
+ *
316
+ *
317
+ * Retrieves the contentlets (content items) associated with a specific container.
318
+ * Handles different UUID formats and provides warning for missing contentlets.
319
+ *
320
+ * @param {DotCMSPageAsset} dotCMSPageAsset - The page asset containing all containers data
321
+ * @param {DotCMSColumnContainer} columContainer - The container reference from the layout
322
+ * @returns {DotCMSContentlet[]} Array of contentlets in the container
323
+ *
324
+ * @example
325
+ * const contentlets = getContentletsInContainer(pageAsset, containerRef);
326
+ * // Returns: [{ identifier: 'cont1', ... }, { identifier: 'cont2', ... }]
327
+ */
328
+ const getContentletsInContainer = (dotCMSPageAsset, columContainer) => {
329
+ const {
330
+ identifier,
331
+ uuid
332
+ } = columContainer;
333
+ const {
334
+ contentlets
335
+ } = dotCMSPageAsset.containers[identifier];
336
+ const contentletsInContainer = contentlets[`uuid-${uuid}`] || contentlets[`uuid-dotParser_${uuid}`] || [];
337
+ if (!contentletsInContainer) {
338
+ console.warn(`We couldn't find the contentlets for the container with the identifier ${identifier} and the uuid ${uuid} becareful by adding content to this container.\nWe recommend to change the container in the layout and add the content again.`);
339
+ }
340
+ return contentletsInContainer;
341
+ };
342
+ /**
343
+ *
344
+ *
345
+ * Generates the required DotCMS data attributes for a container element.
346
+ * These attributes are used by DotCMS for container identification and functionality.
347
+ *
348
+ * @param {EditableContainerData} params - Container data including uuid, identifier, acceptTypes, and maxContentlets
349
+ * @returns {DotContainerAttributes} Object containing all necessary data attributes
350
+ *
351
+ * @example
352
+ * const attributes = getDotContainerAttributes({
353
+ * uuid: '123',
354
+ * identifier: 'cont1',
355
+ * acceptTypes: 'type1,type2',
356
+ * maxContentlets: 5
357
+ * });
358
+ * // Returns: { 'data-dot-object': 'container', 'data-dot-identifier': 'cont1', ... }
359
+ */
360
+ function getDotContainerAttributes({
361
+ uuid,
362
+ identifier,
363
+ acceptTypes,
364
+ maxContentlets
365
+ }) {
366
+ return {
367
+ 'data-dot-object': 'container',
368
+ 'data-dot-accept-types': acceptTypes,
369
+ 'data-dot-identifier': identifier,
370
+ 'data-max-contentlets': maxContentlets.toString(),
371
+ 'data-dot-uuid': uuid
372
+ };
373
+ }
374
+
375
+ /**
376
+ * Post message to dotcms page editor
377
+ *
378
+ * @export
379
+ * @template T
380
+ * @param {DotCMSUVEMessage<T>} message
381
+ */
382
+ function sendMessageToUVE(message) {
383
+ window.parent.postMessage(message, '*');
384
+ }
385
+ /**
386
+ * You can use this function to edit a contentlet in the editor.
387
+ *
388
+ * Calling this function inside the editor, will prompt the UVE to open a dialog to edit the contentlet.
389
+ *
390
+ * @export
391
+ * @template T
392
+ * @param {Contentlet<T>} contentlet - The contentlet to edit.
393
+ */
394
+ function editContentlet(contentlet) {
395
+ sendMessageToUVE({
396
+ action: types.DotCMSUVEAction.EDIT_CONTENTLET,
397
+ payload: contentlet
398
+ });
399
+ }
400
+ /*
401
+ * Reorders the menu based on the provided configuration.
402
+ *
403
+ * @param {ReorderMenuConfig} [config] - Optional configuration for reordering the menu.
404
+ * @param {number} [config.startLevel=1] - The starting level of the menu to reorder.
405
+ * @param {number} [config.depth=2] - The depth of the menu to reorder.
406
+ *
407
+ * This function constructs a URL for the reorder menu page with the specified
408
+ * start level and depth, and sends a message to the editor to perform the reorder action.
409
+ */
410
+ function reorderMenu(config) {
411
+ const {
412
+ startLevel = 1,
413
+ depth = 2
414
+ } = config || {};
415
+ sendMessageToUVE({
416
+ action: types.DotCMSUVEAction.REORDER_MENU,
417
+ payload: {
418
+ startLevel,
419
+ depth
420
+ }
421
+ });
422
+ }
423
+ /**
424
+ * Initializes the inline editing in the editor.
425
+ *
426
+ * @export
427
+ * @param {INLINE_EDITING_EVENT_KEY} type
428
+ * @param {InlineEditEventData} eventData
429
+ * @return {*}
430
+ *
431
+ * * @example
432
+ * ```html
433
+ * <div onclick="initInlineEditing('BLOCK_EDITOR', { inode, languageId, contentType, fieldName, content })">
434
+ * ${My Content}
435
+ * </div>
436
+ * ```
437
+ */
438
+ function initInlineEditing(type, data) {
439
+ sendMessageToUVE({
440
+ action: types.DotCMSUVEAction.INIT_INLINE_EDITING,
441
+ payload: {
442
+ type,
443
+ data
444
+ }
445
+ });
446
+ }
447
+
448
+ /**
449
+ * Enum representing the different types of blocks available in the Block Editor
450
+ *
451
+ * @export
452
+ * @enum {string}
453
+ */
454
+ exports.Blocks = void 0;
455
+ (function (Blocks) {
456
+ /** Represents a paragraph block */
457
+ Blocks["PARAGRAPH"] = "paragraph";
458
+ /** Represents a heading block */
459
+ Blocks["HEADING"] = "heading";
460
+ /** Represents a text block */
461
+ Blocks["TEXT"] = "text";
462
+ /** Represents a bullet/unordered list block */
463
+ Blocks["BULLET_LIST"] = "bulletList";
464
+ /** Represents an ordered/numbered list block */
465
+ Blocks["ORDERED_LIST"] = "orderedList";
466
+ /** Represents a list item within a list block */
467
+ Blocks["LIST_ITEM"] = "listItem";
468
+ /** Represents a blockquote block */
469
+ Blocks["BLOCK_QUOTE"] = "blockquote";
470
+ /** Represents a code block */
471
+ Blocks["CODE_BLOCK"] = "codeBlock";
472
+ /** Represents a hard break (line break) */
473
+ Blocks["HARDBREAK"] = "hardBreak";
474
+ /** Represents a horizontal rule/divider */
475
+ Blocks["HORIZONTAL_RULE"] = "horizontalRule";
476
+ /** Represents a DotCMS image block */
477
+ Blocks["DOT_IMAGE"] = "dotImage";
478
+ /** Represents a DotCMS video block */
479
+ Blocks["DOT_VIDEO"] = "dotVideo";
480
+ /** Represents a table block */
481
+ Blocks["TABLE"] = "table";
482
+ /** Represents a DotCMS content block */
483
+ Blocks["DOT_CONTENT"] = "dotContent";
484
+ })(exports.Blocks || (exports.Blocks = {}));
485
+
486
+ /**
487
+ * Subscribes to content changes in the UVE editor
488
+ *
489
+ * @param {UVEEventHandler} callback - Function to be called when content changes are detected
490
+ * @returns {Object} Object containing unsubscribe function and event type
491
+ * @returns {Function} .unsubscribe - Function to remove the event listener
492
+ * @returns {UVEEventType} .event - The event type being subscribed to
493
+ * @internal
494
+ */
495
+ function onContentChanges(callback) {
496
+ const messageCallback = event => {
497
+ if (event.data.name === exports.__DOTCMS_UVE_EVENT__.UVE_SET_PAGE_DATA) {
498
+ callback(event.data.payload);
499
+ }
500
+ };
501
+ window.addEventListener('message', messageCallback);
502
+ return {
503
+ unsubscribe: () => {
504
+ window.removeEventListener('message', messageCallback);
505
+ },
506
+ event: types.UVEEventType.CONTENT_CHANGES
507
+ };
508
+ }
509
+ /**
510
+ * Subscribes to page reload events in the UVE editor
511
+ *
512
+ * @param {UVEEventHandler} callback - Function to be called when page reload is triggered
513
+ * @returns {Object} Object containing unsubscribe function and event type
514
+ * @returns {Function} .unsubscribe - Function to remove the event listener
515
+ * @returns {UVEEventType} .event - The event type being subscribed to
516
+ * @internal
517
+ */
518
+ function onPageReload(callback) {
519
+ const messageCallback = event => {
520
+ if (event.data.name === exports.__DOTCMS_UVE_EVENT__.UVE_RELOAD_PAGE) {
521
+ callback();
522
+ }
523
+ };
524
+ window.addEventListener('message', messageCallback);
525
+ return {
526
+ unsubscribe: () => {
527
+ window.removeEventListener('message', messageCallback);
528
+ },
529
+ event: types.UVEEventType.PAGE_RELOAD
530
+ };
531
+ }
532
+ /**
533
+ * Subscribes to request bounds events in the UVE editor
534
+ *
535
+ * @param {UVEEventHandler} callback - Function to be called when bounds are requested
536
+ * @returns {Object} Object containing unsubscribe function and event type
537
+ * @returns {Function} .unsubscribe - Function to remove the event listener
538
+ * @returns {UVEEventType} .event - The event type being subscribed to
539
+ * @internal
540
+ */
541
+ function onRequestBounds(callback) {
542
+ const messageCallback = event => {
543
+ if (event.data.name === exports.__DOTCMS_UVE_EVENT__.UVE_REQUEST_BOUNDS) {
544
+ const containers = Array.from(document.querySelectorAll('[data-dot-object="container"]'));
545
+ const positionData = getDotCMSPageBounds(containers);
546
+ callback(positionData);
547
+ }
548
+ };
549
+ window.addEventListener('message', messageCallback);
550
+ return {
551
+ unsubscribe: () => {
552
+ window.removeEventListener('message', messageCallback);
553
+ },
554
+ event: types.UVEEventType.REQUEST_BOUNDS
555
+ };
556
+ }
557
+ /**
558
+ * Subscribes to iframe scroll events in the UVE editor
559
+ *
560
+ * @param {UVEEventHandler} callback - Function to be called when iframe scroll occurs
561
+ * @returns {Object} Object containing unsubscribe function and event type
562
+ * @returns {Function} .unsubscribe - Function to remove the event listener
563
+ * @returns {UVEEventType} .event - The event type being subscribed to
564
+ * @internal
565
+ */
566
+ function onIframeScroll(callback) {
567
+ const messageCallback = event => {
568
+ if (event.data.name === exports.__DOTCMS_UVE_EVENT__.UVE_SCROLL_INSIDE_IFRAME) {
569
+ const direction = event.data.direction;
570
+ callback(direction);
571
+ }
572
+ };
573
+ window.addEventListener('message', messageCallback);
574
+ return {
575
+ unsubscribe: () => {
576
+ window.removeEventListener('message', messageCallback);
577
+ },
578
+ event: types.UVEEventType.IFRAME_SCROLL
579
+ };
580
+ }
581
+ /**
582
+ * Subscribes to contentlet hover events in the UVE editor
583
+ *
584
+ * @param {UVEEventHandler} callback - Function to be called when a contentlet is hovered
585
+ * @returns {Object} Object containing unsubscribe function and event type
586
+ * @returns {Function} .unsubscribe - Function to remove the event listener
587
+ * @returns {UVEEventType} .event - The event type being subscribed to
588
+ * @internal
589
+ */
590
+ function onContentletHovered(callback) {
591
+ const pointerMoveCallback = event => {
592
+ const foundElement = findDotCMSElement(event.target);
593
+ if (!foundElement) return;
594
+ const {
595
+ x,
596
+ y,
597
+ width,
598
+ height
599
+ } = foundElement.getBoundingClientRect();
600
+ const isContainer = foundElement.dataset?.['dotObject'] === 'container';
601
+ const contentletForEmptyContainer = {
602
+ identifier: 'TEMP_EMPTY_CONTENTLET',
603
+ title: 'TEMP_EMPTY_CONTENTLET',
604
+ contentType: 'TEMP_EMPTY_CONTENTLET_TYPE',
605
+ inode: 'TEMPY_EMPTY_CONTENTLET_INODE',
606
+ widgetTitle: 'TEMP_EMPTY_CONTENTLET',
607
+ baseType: 'TEMP_EMPTY_CONTENTLET',
608
+ onNumberOfPages: 1
609
+ };
610
+ const contentlet = {
611
+ identifier: foundElement.dataset?.['dotIdentifier'],
612
+ title: foundElement.dataset?.['dotTitle'],
613
+ inode: foundElement.dataset?.['dotInode'],
614
+ contentType: foundElement.dataset?.['dotType'],
615
+ baseType: foundElement.dataset?.['dotBasetype'],
616
+ widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
617
+ onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
618
+ };
619
+ const vtlFiles = findDotCMSVTLData(foundElement);
620
+ const contentletPayload = {
621
+ container:
622
+ // Here extract dot-container from contentlet if it is Headless
623
+ // or search in parent container if it is VTL
624
+ foundElement.dataset?.['dotContainer'] ? JSON.parse(foundElement.dataset?.['dotContainer']) : getClosestDotCMSContainerData(foundElement),
625
+ contentlet: isContainer ? contentletForEmptyContainer : contentlet,
626
+ vtlFiles
627
+ };
628
+ const contentletHoveredPayload = {
629
+ x,
630
+ y,
631
+ width,
632
+ height,
633
+ payload: contentletPayload
634
+ };
635
+ callback(contentletHoveredPayload);
636
+ };
637
+ document.addEventListener('pointermove', pointerMoveCallback);
638
+ return {
639
+ unsubscribe: () => {
640
+ document.removeEventListener('pointermove', pointerMoveCallback);
641
+ },
642
+ event: types.UVEEventType.CONTENTLET_HOVERED
643
+ };
644
+ }
645
+
646
+ /**
647
+ * Events that can be subscribed to in the UVE
648
+ *
649
+ * @internal
650
+ * @type {Record<UVEEventType, UVEEventSubscriber>}
651
+ */
652
+ const __UVE_EVENTS__ = {
653
+ [types.UVEEventType.CONTENT_CHANGES]: callback => {
654
+ return onContentChanges(callback);
655
+ },
656
+ [types.UVEEventType.PAGE_RELOAD]: callback => {
657
+ return onPageReload(callback);
658
+ },
659
+ [types.UVEEventType.REQUEST_BOUNDS]: callback => {
660
+ return onRequestBounds(callback);
661
+ },
662
+ [types.UVEEventType.IFRAME_SCROLL]: callback => {
663
+ return onIframeScroll(callback);
664
+ },
665
+ [types.UVEEventType.CONTENTLET_HOVERED]: callback => {
666
+ return onContentletHovered(callback);
667
+ }
668
+ };
669
+ /**
670
+ * Default UVE event
671
+ *
672
+ * @param {string} event - The event to subscribe to.
673
+ * @internal
674
+ */
675
+ const __UVE_EVENT_ERROR_FALLBACK__ = event => {
676
+ return {
677
+ unsubscribe: () => {
678
+ /* do nothing */
679
+ },
680
+ event
681
+ };
682
+ };
683
+ /**
684
+ * Development mode
685
+ *
686
+ * @internal
687
+ */
688
+ const DEVELOPMENT_MODE = 'development';
689
+ /**
690
+ * Production mode
691
+ *
692
+ * @internal
693
+ */
694
+ const PRODUCTION_MODE = 'production';
695
+ /**
696
+ * End class
697
+ *
698
+ * @internal
699
+ */
700
+ const END_CLASS = 'col-end-';
701
+ /**
702
+ * Start class
703
+ *
704
+ * @internal
705
+ */
706
+ const START_CLASS = 'col-start-';
707
+ /**
708
+ * Empty container style for React
709
+ *
710
+ * @internal
711
+ */
712
+ const EMPTY_CONTAINER_STYLE_REACT = {
713
+ width: '100%',
714
+ backgroundColor: '#ECF0FD',
715
+ display: 'flex',
716
+ justifyContent: 'center',
717
+ alignItems: 'center',
718
+ color: '#030E32',
719
+ height: '10rem'
720
+ };
721
+ /**
722
+ * Empty container style for Angular
723
+ *
724
+ * @internal
725
+ */
726
+ const EMPTY_CONTAINER_STYLE_ANGULAR = {
727
+ width: '100%',
728
+ 'background-color': '#ECF0FD',
729
+ display: 'flex',
730
+ 'justify-content': 'center',
731
+ 'align-items': 'center',
732
+ color: '#030E32',
733
+ height: '10rem'
734
+ };
735
+ /**
736
+ * Custom no component
737
+ *
738
+ * @internal
739
+ */
740
+ const CUSTOM_NO_COMPONENT = 'CustomNoComponent';
741
+
742
+ exports.CUSTOM_NO_COMPONENT = CUSTOM_NO_COMPONENT;
743
+ exports.DEVELOPMENT_MODE = DEVELOPMENT_MODE;
744
+ exports.EMPTY_CONTAINER_STYLE_ANGULAR = EMPTY_CONTAINER_STYLE_ANGULAR;
745
+ exports.EMPTY_CONTAINER_STYLE_REACT = EMPTY_CONTAINER_STYLE_REACT;
746
+ exports.END_CLASS = END_CLASS;
747
+ exports.PRODUCTION_MODE = PRODUCTION_MODE;
748
+ exports.START_CLASS = START_CLASS;
749
+ exports.__UVE_EVENTS__ = __UVE_EVENTS__;
750
+ exports.__UVE_EVENT_ERROR_FALLBACK__ = __UVE_EVENT_ERROR_FALLBACK__;
751
+ exports.combineClasses = combineClasses;
752
+ exports.computeScrollIsInBottom = computeScrollIsInBottom;
753
+ exports.editContentlet = editContentlet;
754
+ exports.findDotCMSElement = findDotCMSElement;
755
+ exports.findDotCMSVTLData = findDotCMSVTLData;
756
+ exports.getClosestDotCMSContainerData = getClosestDotCMSContainerData;
757
+ exports.getColumnPositionClasses = getColumnPositionClasses;
758
+ exports.getContainersData = getContainersData;
759
+ exports.getContentletsInContainer = getContentletsInContainer;
760
+ exports.getDotCMSContainerData = getDotCMSContainerData;
761
+ exports.getDotCMSContentletsBound = getDotCMSContentletsBound;
762
+ exports.getDotCMSPageBounds = getDotCMSPageBounds;
763
+ exports.getDotContainerAttributes = getDotContainerAttributes;
764
+ exports.getDotContentletAttributes = getDotContentletAttributes;
765
+ exports.initInlineEditing = initInlineEditing;
766
+ exports.reorderMenu = reorderMenu;
767
+ exports.sendMessageToUVE = sendMessageToUVE;