@dotcms/uve 0.0.1-beta.11 → 0.0.1-beta.12
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.
- package/index.cjs.js +67 -166
- package/index.esm.js +65 -161
- package/internal.cjs.js +360 -16
- package/internal.esm.js +354 -17
- package/package.json +1 -1
- package/src/index.d.ts +1 -1
- package/src/internal/constants.d.ts +3 -3
- package/src/internal/events.d.ts +66 -0
- package/src/internal.d.ts +1 -0
- package/src/lib/core/core.utils.d.ts +11 -7
- package/src/lib/editor/internal.d.ts +8 -0
- package/src/lib/editor/public.d.ts +38 -0
- package/src/lib/types/editor/internal.d.ts +39 -0
- package/src/lib/types/editor/public.d.ts +55 -12
- package/src/lib/types/events/internal.d.ts +3 -1
- package/src/script/sdk-editor.d.ts +6 -0
- package/src/script/utils.d.ts +4 -0
- package/types.cjs.js +27 -0
- package/types.esm.js +28 -1
package/internal.esm.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { UVEEventType } from './types.esm.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Actions received from the dotcms editor
|
|
3
5
|
*
|
|
@@ -23,7 +25,9 @@ var __DOTCMS_UVE_EVENT__;
|
|
|
23
25
|
*/
|
|
24
26
|
__DOTCMS_UVE_EVENT__["UVE_SCROLL_INSIDE_IFRAME"] = "uve-scroll-inside-iframe";
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* TODO:
|
|
29
|
+
* Set the page data - This is used to catch the "changes" event.
|
|
30
|
+
* We must to re-check the name late.
|
|
27
31
|
*/
|
|
28
32
|
__DOTCMS_UVE_EVENT__["UVE_SET_PAGE_DATA"] = "uve-set-page-data";
|
|
29
33
|
/**
|
|
@@ -32,27 +36,360 @@ var __DOTCMS_UVE_EVENT__;
|
|
|
32
36
|
__DOTCMS_UVE_EVENT__["UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS"] = "uve-copy-contentlet-inline-editing-success";
|
|
33
37
|
})(__DOTCMS_UVE_EVENT__ || (__DOTCMS_UVE_EVENT__ = {}));
|
|
34
38
|
|
|
35
|
-
// TODO: WE NEED TO LOOK FOR ALL THE NOTIFY_CLIENT EVENTS AND ADD THEM TO THE UVE_EVENTS CONSTANT WHEN WE MIGRATE THE EDITOR TO THE NEW UVE LIBRARY
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
40
|
+
* Calculates the bounding information for each page element within the given containers.
|
|
38
41
|
*
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
42
|
+
* @export
|
|
43
|
+
* @param {HTMLDivElement[]} containers - An array of HTMLDivElement representing the containers.
|
|
44
|
+
* @return {DotCMSContainerBound[]} An array of objects containing the bounding information for each page element.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const containers = document.querySelectorAll('.container');
|
|
48
|
+
* const bounds = getDotCMSPageBounds(containers);
|
|
49
|
+
* console.log(bounds);
|
|
50
|
+
* ```
|
|
41
51
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
function getDotCMSPageBounds(containers) {
|
|
53
|
+
return containers.map(container => {
|
|
54
|
+
const containerRect = container.getBoundingClientRect();
|
|
55
|
+
const contentlets = Array.from(container.querySelectorAll('[data-dot-object="contentlet"]'));
|
|
56
|
+
return {
|
|
57
|
+
x: containerRect.x,
|
|
58
|
+
y: containerRect.y,
|
|
59
|
+
width: containerRect.width,
|
|
60
|
+
height: containerRect.height,
|
|
61
|
+
payload: JSON.stringify({
|
|
62
|
+
container: getDotCMSContainerData(container)
|
|
63
|
+
}),
|
|
64
|
+
contentlets: getDotCMSContentletsBound(containerRect, contentlets)
|
|
48
65
|
};
|
|
49
|
-
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the bounding information for each contentlet inside a container.
|
|
70
|
+
*
|
|
71
|
+
* @export
|
|
72
|
+
* @param {DOMRect} containerRect - The bounding rectangle of the container.
|
|
73
|
+
* @param {HTMLDivElement[]} contentlets - An array of HTMLDivElement representing the contentlets.
|
|
74
|
+
* @return {DotCMSContentletBound[]} An array of objects containing the bounding information for each contentlet.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const containerRect = container.getBoundingClientRect();
|
|
78
|
+
* const contentlets = container.querySelectorAll('.contentlet');
|
|
79
|
+
* const bounds = getDotCMSContentletsBound(containerRect, contentlets);
|
|
80
|
+
* console.log(bounds); // Element bounds within the container
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function getDotCMSContentletsBound(containerRect, contentlets) {
|
|
84
|
+
return contentlets.map(contentlet => {
|
|
85
|
+
const contentletRect = contentlet.getBoundingClientRect();
|
|
50
86
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
x: 0,
|
|
88
|
+
y: contentletRect.y - containerRect.y,
|
|
89
|
+
width: contentletRect.width,
|
|
90
|
+
height: contentletRect.height,
|
|
91
|
+
payload: JSON.stringify({
|
|
92
|
+
container: contentlet.dataset?.['dotContainer'] ? JSON.parse(contentlet.dataset?.['dotContainer']) : getClosestDotCMSContainerData(contentlet),
|
|
93
|
+
contentlet: {
|
|
94
|
+
identifier: contentlet.dataset?.['dotIdentifier'],
|
|
95
|
+
title: contentlet.dataset?.['dotTitle'],
|
|
96
|
+
inode: contentlet.dataset?.['dotInode'],
|
|
97
|
+
contentType: contentlet.dataset?.['dotType']
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get container data from VTLS.
|
|
105
|
+
*
|
|
106
|
+
* @export
|
|
107
|
+
* @param {HTMLElement} container - The container element.
|
|
108
|
+
* @return {object} An object containing the container data.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const container = document.querySelector('.container');
|
|
112
|
+
* const data = getContainerData(container);
|
|
113
|
+
* console.log(data);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
function getDotCMSContainerData(container) {
|
|
117
|
+
return {
|
|
118
|
+
acceptTypes: container.dataset?.['dotAcceptTypes'] || '',
|
|
119
|
+
identifier: container.dataset?.['dotIdentifier'] || '',
|
|
120
|
+
maxContentlets: container.dataset?.['maxContentlets'] || '',
|
|
121
|
+
uuid: container.dataset?.['dotUuid'] || ''
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the closest container data from the contentlet.
|
|
126
|
+
*
|
|
127
|
+
* @export
|
|
128
|
+
* @param {Element} element - The contentlet element.
|
|
129
|
+
* @return {object | null} An object containing the closest container data or null if no container is found.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const contentlet = document.querySelector('.contentlet');
|
|
133
|
+
* const data = getClosestDotCMSContainerData(contentlet);
|
|
134
|
+
* console.log(data);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
function getClosestDotCMSContainerData(element) {
|
|
138
|
+
// Find the closest ancestor element with data-dot-object="container" attribute
|
|
139
|
+
const container = element.closest('[data-dot-object="container"]');
|
|
140
|
+
// If a container element is found
|
|
141
|
+
if (container) {
|
|
142
|
+
// Return the dataset of the container element
|
|
143
|
+
return getDotCMSContainerData(container);
|
|
144
|
+
} else {
|
|
145
|
+
// If no container element is found, return null
|
|
146
|
+
console.warn('No container found for the contentlet');
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Find the closest contentlet element based on HTMLElement.
|
|
152
|
+
*
|
|
153
|
+
* @export
|
|
154
|
+
* @param {HTMLElement | null} element - The starting element.
|
|
155
|
+
* @return {HTMLElement | null} The closest contentlet element or null if not found.
|
|
156
|
+
* @example
|
|
157
|
+
* const element = document.querySelector('.some-element');
|
|
158
|
+
* const contentlet = findDotCMSElement(element);
|
|
159
|
+
* console.log(contentlet);
|
|
160
|
+
*/
|
|
161
|
+
function findDotCMSElement(element) {
|
|
162
|
+
if (!element) return null;
|
|
163
|
+
if (element?.dataset?.['dotObject'] === 'contentlet' || element?.dataset?.['dotObject'] === 'container' && element.children.length === 0) {
|
|
164
|
+
return element;
|
|
165
|
+
}
|
|
166
|
+
return findDotCMSElement(element?.['parentElement']);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Find VTL data within a target element.
|
|
170
|
+
*
|
|
171
|
+
* @export
|
|
172
|
+
* @param {HTMLElement} target - The target element to search within.
|
|
173
|
+
* @return {Array<{ inode: string, name: string }> | null} An array of objects containing VTL data or null if none found.
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const target = document.querySelector('.target-element');
|
|
177
|
+
* const vtlData = findDotCMSVTLData(target);
|
|
178
|
+
* console.log(vtlData);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
function findDotCMSVTLData(target) {
|
|
182
|
+
const vltElements = target.querySelectorAll('[data-dot-object="vtl-file"]');
|
|
183
|
+
if (!vltElements.length) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return Array.from(vltElements).map(vltElement => {
|
|
187
|
+
return {
|
|
188
|
+
inode: vltElement.dataset?.['dotInode'],
|
|
189
|
+
name: vltElement.dataset?.['dotUrl']
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Check if the scroll position is at the bottom of the page.
|
|
195
|
+
*
|
|
196
|
+
* @export
|
|
197
|
+
* @return {boolean} True if the scroll position is at the bottom, otherwise false.
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* if (dotCMSScrollIsInBottom()) {
|
|
201
|
+
* console.log('Scrolled to the bottom');
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
function computeScrollIsInBottom() {
|
|
206
|
+
const documentHeight = document.documentElement.scrollHeight;
|
|
207
|
+
const viewportHeight = window.innerHeight;
|
|
208
|
+
const scrollY = window.scrollY;
|
|
209
|
+
return scrollY + viewportHeight >= documentHeight;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Subscribes to content changes in the UVE editor
|
|
214
|
+
*
|
|
215
|
+
* @param {UVEEventHandler} callback - Function to be called when content changes are detected
|
|
216
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
217
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
218
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
function onContentChanges(callback) {
|
|
222
|
+
const messageCallback = event => {
|
|
223
|
+
if (event.data.name === __DOTCMS_UVE_EVENT__.UVE_SET_PAGE_DATA) {
|
|
224
|
+
callback(event.data.payload);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
window.addEventListener('message', messageCallback);
|
|
228
|
+
return {
|
|
229
|
+
unsubscribe: () => {
|
|
230
|
+
window.removeEventListener('message', messageCallback);
|
|
231
|
+
},
|
|
232
|
+
event: UVEEventType.CONTENT_CHANGES
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Subscribes to page reload events in the UVE editor
|
|
237
|
+
*
|
|
238
|
+
* @param {UVEEventHandler} callback - Function to be called when page reload is triggered
|
|
239
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
240
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
241
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
function onPageReload(callback) {
|
|
245
|
+
const messageCallback = event => {
|
|
246
|
+
if (event.data.name === __DOTCMS_UVE_EVENT__.UVE_RELOAD_PAGE) {
|
|
247
|
+
callback();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
window.addEventListener('message', messageCallback);
|
|
251
|
+
return {
|
|
252
|
+
unsubscribe: () => {
|
|
253
|
+
window.removeEventListener('message', messageCallback);
|
|
254
|
+
},
|
|
255
|
+
event: UVEEventType.PAGE_RELOAD
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Subscribes to request bounds events in the UVE editor
|
|
260
|
+
*
|
|
261
|
+
* @param {UVEEventHandler} callback - Function to be called when bounds are requested
|
|
262
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
263
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
264
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
function onRequestBounds(callback) {
|
|
268
|
+
const messageCallback = event => {
|
|
269
|
+
if (event.data.name === __DOTCMS_UVE_EVENT__.UVE_REQUEST_BOUNDS) {
|
|
270
|
+
const containers = Array.from(document.querySelectorAll('[data-dot-object="container"]'));
|
|
271
|
+
const positionData = getDotCMSPageBounds(containers);
|
|
272
|
+
callback(positionData);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
window.addEventListener('message', messageCallback);
|
|
276
|
+
return {
|
|
277
|
+
unsubscribe: () => {
|
|
278
|
+
window.removeEventListener('message', messageCallback);
|
|
279
|
+
},
|
|
280
|
+
event: UVEEventType.REQUEST_BOUNDS
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Subscribes to iframe scroll events in the UVE editor
|
|
285
|
+
*
|
|
286
|
+
* @param {UVEEventHandler} callback - Function to be called when iframe scroll occurs
|
|
287
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
288
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
289
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
290
|
+
* @internal
|
|
291
|
+
*/
|
|
292
|
+
function onIframeScroll(callback) {
|
|
293
|
+
const messageCallback = event => {
|
|
294
|
+
if (event.data.name === __DOTCMS_UVE_EVENT__.UVE_SCROLL_INSIDE_IFRAME) {
|
|
295
|
+
const direction = event.data.direction;
|
|
296
|
+
callback(direction);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
window.addEventListener('message', messageCallback);
|
|
300
|
+
return {
|
|
301
|
+
unsubscribe: () => {
|
|
302
|
+
window.removeEventListener('message', messageCallback);
|
|
303
|
+
},
|
|
304
|
+
event: UVEEventType.IFRAME_SCROLL
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Subscribes to contentlet hover events in the UVE editor
|
|
309
|
+
*
|
|
310
|
+
* @param {UVEEventHandler} callback - Function to be called when a contentlet is hovered
|
|
311
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
312
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
313
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
314
|
+
* @internal
|
|
315
|
+
*/
|
|
316
|
+
function onContentletHovered(callback) {
|
|
317
|
+
const pointerMoveCallback = event => {
|
|
318
|
+
const foundElement = findDotCMSElement(event.target);
|
|
319
|
+
if (!foundElement) return;
|
|
320
|
+
const {
|
|
321
|
+
x,
|
|
322
|
+
y,
|
|
323
|
+
width,
|
|
324
|
+
height
|
|
325
|
+
} = foundElement.getBoundingClientRect();
|
|
326
|
+
const isContainer = foundElement.dataset?.['dotObject'] === 'container';
|
|
327
|
+
const contentletForEmptyContainer = {
|
|
328
|
+
identifier: 'TEMP_EMPTY_CONTENTLET',
|
|
329
|
+
title: 'TEMP_EMPTY_CONTENTLET',
|
|
330
|
+
contentType: 'TEMP_EMPTY_CONTENTLET_TYPE',
|
|
331
|
+
inode: 'TEMPY_EMPTY_CONTENTLET_INODE',
|
|
332
|
+
widgetTitle: 'TEMP_EMPTY_CONTENTLET',
|
|
333
|
+
baseType: 'TEMP_EMPTY_CONTENTLET',
|
|
334
|
+
onNumberOfPages: 1
|
|
335
|
+
};
|
|
336
|
+
const contentlet = {
|
|
337
|
+
identifier: foundElement.dataset?.['dotIdentifier'],
|
|
338
|
+
title: foundElement.dataset?.['dotTitle'],
|
|
339
|
+
inode: foundElement.dataset?.['dotInode'],
|
|
340
|
+
contentType: foundElement.dataset?.['dotType'],
|
|
341
|
+
baseType: foundElement.dataset?.['dotBasetype'],
|
|
342
|
+
widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
|
|
343
|
+
onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
|
|
55
344
|
};
|
|
345
|
+
const vtlFiles = findDotCMSVTLData(foundElement);
|
|
346
|
+
const contentletPayload = {
|
|
347
|
+
container:
|
|
348
|
+
// Here extract dot-container from contentlet if it is Headless
|
|
349
|
+
// or search in parent container if it is VTL
|
|
350
|
+
foundElement.dataset?.['dotContainer'] ? JSON.parse(foundElement.dataset?.['dotContainer']) : getClosestDotCMSContainerData(foundElement),
|
|
351
|
+
contentlet: isContainer ? contentletForEmptyContainer : contentlet,
|
|
352
|
+
vtlFiles
|
|
353
|
+
};
|
|
354
|
+
const contentletHoveredPayload = {
|
|
355
|
+
x,
|
|
356
|
+
y,
|
|
357
|
+
width,
|
|
358
|
+
height,
|
|
359
|
+
payload: contentletPayload
|
|
360
|
+
};
|
|
361
|
+
callback(contentletHoveredPayload);
|
|
362
|
+
};
|
|
363
|
+
document.addEventListener('pointermove', pointerMoveCallback);
|
|
364
|
+
return {
|
|
365
|
+
unsubscribe: () => {
|
|
366
|
+
document.removeEventListener('pointermove', pointerMoveCallback);
|
|
367
|
+
},
|
|
368
|
+
event: UVEEventType.CONTENTLET_HOVERED
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Events that can be subscribed to in the UVE
|
|
374
|
+
*
|
|
375
|
+
* @internal
|
|
376
|
+
* @type {Record<UVEEventType, UVEEventSubscriber>}
|
|
377
|
+
*/
|
|
378
|
+
const __UVE_EVENTS__ = {
|
|
379
|
+
[UVEEventType.CONTENT_CHANGES]: callback => {
|
|
380
|
+
return onContentChanges(callback);
|
|
381
|
+
},
|
|
382
|
+
[UVEEventType.PAGE_RELOAD]: callback => {
|
|
383
|
+
return onPageReload(callback);
|
|
384
|
+
},
|
|
385
|
+
[UVEEventType.REQUEST_BOUNDS]: callback => {
|
|
386
|
+
return onRequestBounds(callback);
|
|
387
|
+
},
|
|
388
|
+
[UVEEventType.IFRAME_SCROLL]: callback => {
|
|
389
|
+
return onIframeScroll(callback);
|
|
390
|
+
},
|
|
391
|
+
[UVEEventType.CONTENTLET_HOVERED]: callback => {
|
|
392
|
+
return onContentletHovered(callback);
|
|
56
393
|
}
|
|
57
394
|
};
|
|
58
395
|
/**
|
|
@@ -70,4 +407,4 @@ const __UVE_EVENT_ERROR_FALLBACK__ = event => {
|
|
|
70
407
|
};
|
|
71
408
|
};
|
|
72
409
|
|
|
73
|
-
export { __DOTCMS_UVE_EVENT__, __UVE_EVENTS__, __UVE_EVENT_ERROR_FALLBACK__ };
|
|
410
|
+
export { __DOTCMS_UVE_EVENT__, __UVE_EVENTS__, __UVE_EVENT_ERROR_FALLBACK__, computeScrollIsInBottom, findDotCMSElement, findDotCMSVTLData, getClosestDotCMSContainerData, getDotCMSContainerData, getDotCMSContentletsBound, getDotCMSPageBounds };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './lib/core/core.utils';
|
|
2
|
-
export * from './lib/
|
|
2
|
+
export * from './lib/editor/public';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UVEEventSubscriber, UVEEventType } from '../lib/types/editor/public';
|
|
2
2
|
/**
|
|
3
3
|
* Events that can be subscribed to in the UVE
|
|
4
4
|
*
|
|
5
5
|
* @internal
|
|
6
|
-
* @type {Record<
|
|
6
|
+
* @type {Record<UVEEventType, UVEEventSubscriber>}
|
|
7
7
|
*/
|
|
8
|
-
export declare const __UVE_EVENTS__: Record<
|
|
8
|
+
export declare const __UVE_EVENTS__: Record<UVEEventType, UVEEventSubscriber>;
|
|
9
9
|
/**
|
|
10
10
|
* Default UVE event
|
|
11
11
|
*
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { UVEEventHandler, UVEEventType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to content changes in the UVE editor
|
|
4
|
+
*
|
|
5
|
+
* @param {UVEEventHandler} callback - Function to be called when content changes are detected
|
|
6
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
7
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
8
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function onContentChanges(callback: UVEEventHandler): {
|
|
12
|
+
unsubscribe: () => void;
|
|
13
|
+
event: UVEEventType;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Subscribes to page reload events in the UVE editor
|
|
17
|
+
*
|
|
18
|
+
* @param {UVEEventHandler} callback - Function to be called when page reload is triggered
|
|
19
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
20
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
21
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function onPageReload(callback: UVEEventHandler): {
|
|
25
|
+
unsubscribe: () => void;
|
|
26
|
+
event: UVEEventType;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Subscribes to request bounds events in the UVE editor
|
|
30
|
+
*
|
|
31
|
+
* @param {UVEEventHandler} callback - Function to be called when bounds are requested
|
|
32
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
33
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
34
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function onRequestBounds(callback: UVEEventHandler): {
|
|
38
|
+
unsubscribe: () => void;
|
|
39
|
+
event: UVEEventType;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Subscribes to iframe scroll events in the UVE editor
|
|
43
|
+
*
|
|
44
|
+
* @param {UVEEventHandler} callback - Function to be called when iframe scroll occurs
|
|
45
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
46
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
47
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function onIframeScroll(callback: UVEEventHandler): {
|
|
51
|
+
unsubscribe: () => void;
|
|
52
|
+
event: UVEEventType;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Subscribes to contentlet hover events in the UVE editor
|
|
56
|
+
*
|
|
57
|
+
* @param {UVEEventHandler} callback - Function to be called when a contentlet is hovered
|
|
58
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
59
|
+
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
60
|
+
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare function onContentletHovered(callback: UVEEventHandler): {
|
|
64
|
+
unsubscribe: () => void;
|
|
65
|
+
event: UVEEventType;
|
|
66
|
+
};
|
package/src/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UVEState, UVEEventSubscription, UVEEventType, UVEEventPayloadMap } from '../types/editor/public';
|
|
2
2
|
/**
|
|
3
3
|
* Gets the current state of the Universal Visual Editor (UVE).
|
|
4
4
|
*
|
|
@@ -31,15 +31,19 @@ export declare function getUVEState(): UVEState | undefined;
|
|
|
31
31
|
/**
|
|
32
32
|
* Creates a subscription to a UVE event.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
34
|
+
* @param eventType - The type of event to subscribe to
|
|
35
|
+
* @param callback - The callback function that will be called when the event occurs
|
|
36
|
+
* @returns An event subscription that can be used to unsubscribe
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```ts
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* // Subscribe to page changes
|
|
41
|
+
* const subscription = createUVESubscription(UVEEventType.CONTENT_CHANGES, (changes) => {
|
|
42
|
+
* console.log('Content changes:', changes);
|
|
42
43
|
* });
|
|
44
|
+
*
|
|
45
|
+
* // Later, unsubscribe when no longer needed
|
|
46
|
+
* subscription.unsubscribe();
|
|
43
47
|
* ```
|
|
44
48
|
*/
|
|
45
|
-
export declare function createUVESubscription(
|
|
49
|
+
export declare function createUVESubscription<T extends UVEEventType>(eventType: T, callback: (payload: UVEEventPayloadMap[T] extends undefined ? void : UVEEventPayloadMap[T]) => void): UVEEventSubscription;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DotCMSContainerBound } from '@dotcms/uve/internal';
|
|
2
|
+
/**
|
|
3
|
+
* Sets the bounds of the containers in the editor.
|
|
4
|
+
* Retrieves the containers from the DOM and sends their position data to the editor.
|
|
5
|
+
* @private
|
|
6
|
+
* @memberof DotCMSPageEditor
|
|
7
|
+
*/
|
|
8
|
+
export declare function setBounds(bounds: DotCMSContainerBound[]): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DotCMSReorderMenuConfig, DotCMSUVEMessage } from '../types/editor/internal';
|
|
2
|
+
import { Contentlet } from '../types/editor/public';
|
|
3
|
+
import { DotCMSInlineEditingPayload, DotCMSInlineEditingType } from '../types/events/public';
|
|
4
|
+
/**
|
|
5
|
+
* Post message to dotcms page editor
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {DotCMSUVEMessage<T>} message
|
|
10
|
+
*/
|
|
11
|
+
export declare function sendMessageToEditor<T = unknown>(message: DotCMSUVEMessage<T>): void;
|
|
12
|
+
/**
|
|
13
|
+
* You can use this function to edit a contentlet in the editor.
|
|
14
|
+
*
|
|
15
|
+
* Calling this function inside the editor, will prompt the UVE to open a dialog to edit the contentlet.
|
|
16
|
+
*
|
|
17
|
+
* @export
|
|
18
|
+
* @template T
|
|
19
|
+
* @param {Contentlet<T>} contentlet - The contentlet to edit.
|
|
20
|
+
*/
|
|
21
|
+
export declare function editContentlet<T>(contentlet: Contentlet<T>): void;
|
|
22
|
+
export declare function reorderMenu(config?: DotCMSReorderMenuConfig): void;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes the inline editing in the editor.
|
|
25
|
+
*
|
|
26
|
+
* @export
|
|
27
|
+
* @param {INLINE_EDITING_EVENT_KEY} type
|
|
28
|
+
* @param {InlineEditEventData} eventData
|
|
29
|
+
* @return {*}
|
|
30
|
+
*
|
|
31
|
+
* * @example
|
|
32
|
+
* ```html
|
|
33
|
+
* <div onclick="initInlineEditing('BLOCK_EDITOR', { inode, languageId, contentType, fieldName, content })">
|
|
34
|
+
* ${My Content}
|
|
35
|
+
* </div>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function initInlineEditing(type: DotCMSInlineEditingType, data?: DotCMSInlineEditingPayload): void;
|
|
@@ -42,6 +42,45 @@ export interface DotCMSUVE {
|
|
|
42
42
|
lastScrollYPosition: number;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
+
* Main fields of a Contentlet (Inherited from the Content Type).
|
|
46
|
+
*/
|
|
47
|
+
export interface ContentTypeMainFields {
|
|
48
|
+
hostName: string;
|
|
49
|
+
modDate: string;
|
|
50
|
+
publishDate: string;
|
|
51
|
+
title: string;
|
|
52
|
+
baseType: string;
|
|
53
|
+
inode: string;
|
|
54
|
+
archived: boolean;
|
|
55
|
+
ownerName: string;
|
|
56
|
+
host: string;
|
|
57
|
+
working: boolean;
|
|
58
|
+
locked: boolean;
|
|
59
|
+
stInode: string;
|
|
60
|
+
contentType: string;
|
|
61
|
+
live: boolean;
|
|
62
|
+
owner: string;
|
|
63
|
+
identifier: string;
|
|
64
|
+
publishUserName: string;
|
|
65
|
+
publishUser: string;
|
|
66
|
+
languageId: number;
|
|
67
|
+
creationDate: string;
|
|
68
|
+
url: string;
|
|
69
|
+
titleImage: string;
|
|
70
|
+
modUserName: string;
|
|
71
|
+
hasLiveVersion: boolean;
|
|
72
|
+
folder: string;
|
|
73
|
+
hasTitleImage: boolean;
|
|
74
|
+
sortOrder: number;
|
|
75
|
+
modUser: string;
|
|
76
|
+
__icon__: string;
|
|
77
|
+
contentTypeIcon: string;
|
|
78
|
+
variant: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Bound information for a contentlet.
|
|
82
|
+
*
|
|
83
|
+
* @interface ContentletBound
|
|
45
84
|
* Bound information for a contentlet.
|
|
46
85
|
*
|
|
47
86
|
* @interface DotCMSContentletBound
|