@dotcms/uve 26.11.17-1 → 26.11.18-1
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/package.json +3 -3
- package/public.cjs.js +137 -2
- package/public.esm.js +137 -2
- package/src/internal/events.d.ts +16 -0
- package/src/script/utils.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/uve",
|
|
3
|
-
"version": "26.11.
|
|
3
|
+
"version": "26.11.18-1",
|
|
4
4
|
"description": "Official JavaScript library for interacting with Universal Visual Editor (UVE)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/dotCMS/core.git#main"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@dotcms/types": "26.11.
|
|
10
|
+
"@dotcms/types": "26.11.18-1"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@dotcms/types": "26.11.
|
|
13
|
+
"@dotcms/types": "26.11.18-1"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"dotCMS",
|
package/public.cjs.js
CHANGED
|
@@ -653,6 +653,10 @@ function onAutoBounds(callback) {
|
|
|
653
653
|
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
654
654
|
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
655
655
|
* @internal
|
|
656
|
+
* @deprecated Use `onIframeScrollVelocity`, which receives the speed the page scrolls at every
|
|
657
|
+
* frame during a drag. Still subscribed, so the one-step request the editor keeps sending for
|
|
658
|
+
* pages on an older `@dotcms/uve` is still handled; `registerUVEEvents` ignores it once a
|
|
659
|
+
* velocity arrives.
|
|
656
660
|
*/
|
|
657
661
|
function onIframeScroll(callback) {
|
|
658
662
|
const messageCallback = event => {
|
|
@@ -671,6 +675,30 @@ function onIframeScroll(callback) {
|
|
|
671
675
|
event: types.UVEEventType.IFRAME_SCROLL
|
|
672
676
|
};
|
|
673
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* Subscribes to the scroll velocity the UVE editor sets during a drag. The callback gets the
|
|
680
|
+
* message's `velocity` as sent; the caller validates it.
|
|
681
|
+
*
|
|
682
|
+
* @param {UVEEventHandler} callback - Function called with each velocity the editor sends
|
|
683
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
684
|
+
* @internal
|
|
685
|
+
*/
|
|
686
|
+
function onIframeScrollVelocity(callback) {
|
|
687
|
+
const messageCallback = event => {
|
|
688
|
+
if (event.data?.name === internal.__DOTCMS_UVE_EVENT__.UVE_SCROLL_VELOCITY) {
|
|
689
|
+
callback(event.data.velocity);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
// Native binder: survives the iframe rewrite under Zone.js. See getNativeEventBinder.
|
|
693
|
+
const nativeWindow = getNativeEventBinder(window);
|
|
694
|
+
nativeWindow.addEventListener('message', messageCallback);
|
|
695
|
+
return {
|
|
696
|
+
unsubscribe: () => {
|
|
697
|
+
nativeWindow.removeEventListener('message', messageCallback);
|
|
698
|
+
},
|
|
699
|
+
event: types.UVEEventType.IFRAME_SCROLL_VELOCITY
|
|
700
|
+
};
|
|
701
|
+
}
|
|
674
702
|
/**
|
|
675
703
|
* Listens for scroll-to-section requests from the UVE editor.
|
|
676
704
|
*
|
|
@@ -893,6 +921,9 @@ const __UVE_EVENTS__ = {
|
|
|
893
921
|
[types.UVEEventType.IFRAME_SCROLL]: callback => {
|
|
894
922
|
return onIframeScroll(callback);
|
|
895
923
|
},
|
|
924
|
+
[types.UVEEventType.IFRAME_SCROLL_VELOCITY]: callback => {
|
|
925
|
+
return onIframeScrollVelocity(callback);
|
|
926
|
+
},
|
|
896
927
|
[types.UVEEventType.CONTENTLET_HOVERED]: callback => {
|
|
897
928
|
return onContentletHovered(callback);
|
|
898
929
|
},
|
|
@@ -1237,15 +1268,99 @@ const isValidBlocks = blocks => {
|
|
|
1237
1268
|
};
|
|
1238
1269
|
};
|
|
1239
1270
|
|
|
1271
|
+
/** One frame at 60fps, in ms: the unit the editor's scroll velocity is expressed in. */
|
|
1272
|
+
const FRAME_MS = 1000 / 60;
|
|
1273
|
+
/** The fastest the page scrolls during a drag, in px per 60fps frame. */
|
|
1274
|
+
const MAX_SCROLL_VELOCITY = 40;
|
|
1275
|
+
/**
|
|
1276
|
+
* The longest frame a scroll step accounts for, so a frame delayed by a busy or hidden tab does
|
|
1277
|
+
* not jump the page.
|
|
1278
|
+
*/
|
|
1279
|
+
const MAX_FRAME_MS = 4 * FRAME_MS;
|
|
1280
|
+
/** A velocity the page can use: a finite number, clamped to the maximum; anything else is 0. */
|
|
1281
|
+
function toScrollVelocity(velocity) {
|
|
1282
|
+
if (typeof velocity !== 'number' || !Number.isFinite(velocity)) {
|
|
1283
|
+
return 0;
|
|
1284
|
+
}
|
|
1285
|
+
return Math.max(-MAX_SCROLL_VELOCITY, Math.min(MAX_SCROLL_VELOCITY, velocity));
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Scrolls the page continuously during a drag, at the velocity the editor sets, one instant step
|
|
1289
|
+
* per animation frame scaled by how long the frame took. It stops at velocity 0, at the top when
|
|
1290
|
+
* scrolling up, at the bottom when scrolling down, and on `stop()`.
|
|
1291
|
+
*/
|
|
1292
|
+
function createDragScroller() {
|
|
1293
|
+
let velocity = 0;
|
|
1294
|
+
let frameId = null;
|
|
1295
|
+
let lastFrameTime = null;
|
|
1296
|
+
const halt = () => {
|
|
1297
|
+
if (frameId !== null) {
|
|
1298
|
+
cancelAnimationFrame(frameId);
|
|
1299
|
+
}
|
|
1300
|
+
frameId = null;
|
|
1301
|
+
lastFrameTime = null;
|
|
1302
|
+
};
|
|
1303
|
+
const step = time => {
|
|
1304
|
+
frameId = null;
|
|
1305
|
+
if (velocity === 0) {
|
|
1306
|
+
halt();
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
// At the top or bottom, wait instead of stopping: the editor sends a velocity only when
|
|
1310
|
+
// it changes, so a loop that stopped would stay still if the page then grew.
|
|
1311
|
+
if (velocity < 0 && window.scrollY <= 0 || velocity > 0 && computeScrollIsInBottom()) {
|
|
1312
|
+
// The first step after waiting is one frame's, not the whole wait's.
|
|
1313
|
+
lastFrameTime = null;
|
|
1314
|
+
frameId = requestAnimationFrame(step);
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
const elapsed = lastFrameTime === null ? FRAME_MS : time - lastFrameTime;
|
|
1318
|
+
lastFrameTime = time;
|
|
1319
|
+
window.scrollBy({
|
|
1320
|
+
left: 0,
|
|
1321
|
+
top: velocity * (Math.min(elapsed, MAX_FRAME_MS) / FRAME_MS),
|
|
1322
|
+
behavior: 'instant'
|
|
1323
|
+
});
|
|
1324
|
+
// Report where the page is now, in this frame. The scroll event's own report comes a
|
|
1325
|
+
// frame later, and the editor shifts bounds that arrive in between from the last report.
|
|
1326
|
+
sendMessageToUVE({
|
|
1327
|
+
action: types.DotCMSUVEAction.IFRAME_SCROLL,
|
|
1328
|
+
payload: {
|
|
1329
|
+
scrollY: window.scrollY
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
frameId = requestAnimationFrame(step);
|
|
1333
|
+
};
|
|
1334
|
+
return {
|
|
1335
|
+
setVelocity: next => {
|
|
1336
|
+
velocity = toScrollVelocity(next);
|
|
1337
|
+
if (velocity === 0) {
|
|
1338
|
+
halt();
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
if (frameId === null) {
|
|
1342
|
+
frameId = requestAnimationFrame(step);
|
|
1343
|
+
}
|
|
1344
|
+
},
|
|
1345
|
+
stop: () => {
|
|
1346
|
+
velocity = 0;
|
|
1347
|
+
halt();
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1240
1351
|
/**
|
|
1241
1352
|
* Sets up scroll event handlers for the window to notify the editor about scroll events.
|
|
1242
1353
|
* Adds listeners for both 'scroll' and 'scrollend' events, sending appropriate messages
|
|
1243
1354
|
* to the editor when these events occur.
|
|
1244
1355
|
*/
|
|
1245
1356
|
function scrollHandler() {
|
|
1357
|
+
// The scroll offset lets the editor keep its drop targets aligned while a drag scrolls the page.
|
|
1246
1358
|
const scrollCallback = () => {
|
|
1247
1359
|
sendMessageToUVE({
|
|
1248
|
-
action: types.DotCMSUVEAction.IFRAME_SCROLL
|
|
1360
|
+
action: types.DotCMSUVEAction.IFRAME_SCROLL,
|
|
1361
|
+
payload: {
|
|
1362
|
+
scrollY: window.scrollY
|
|
1363
|
+
}
|
|
1249
1364
|
});
|
|
1250
1365
|
};
|
|
1251
1366
|
const scrollEndCallback = () => {
|
|
@@ -1294,6 +1409,7 @@ function addClassToEmptyContentlets() {
|
|
|
1294
1409
|
* - Page reload events that refresh the window
|
|
1295
1410
|
* - Bounds request events to update editor boundaries
|
|
1296
1411
|
* - Iframe scroll events to handle smooth scrolling within bounds
|
|
1412
|
+
* - Scroll velocity events, which scroll the page every frame during a drag
|
|
1297
1413
|
* - Contentlet hover events to notify the editor
|
|
1298
1414
|
*
|
|
1299
1415
|
* @remarks
|
|
@@ -1305,7 +1421,19 @@ function registerUVEEvents() {
|
|
|
1305
1421
|
const pageReloadSubscription = createUVESubscription(types.UVEEventType.PAGE_RELOAD, () => {
|
|
1306
1422
|
window.location.reload();
|
|
1307
1423
|
});
|
|
1424
|
+
// Both live per registration, so a later registration starts with a fresh flag and no loop.
|
|
1425
|
+
const dragScroller = createDragScroller();
|
|
1426
|
+
// Once the editor sends a velocity, it drives the scroll, and its one-step direction requests,
|
|
1427
|
+
// which it keeps sending for older pages, are ignored.
|
|
1428
|
+
let editorSendsVelocity = false;
|
|
1429
|
+
const iframeScrollVelocitySubscription = createUVESubscription(types.UVEEventType.IFRAME_SCROLL_VELOCITY, velocity => {
|
|
1430
|
+
editorSendsVelocity = true;
|
|
1431
|
+
dragScroller.setVelocity(velocity);
|
|
1432
|
+
});
|
|
1308
1433
|
const iframeScrollSubscription = createUVESubscription(types.UVEEventType.IFRAME_SCROLL, direction => {
|
|
1434
|
+
if (editorSendsVelocity) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1309
1437
|
if (window.scrollY === 0 && direction === 'up' || computeScrollIsInBottom() && direction === 'down') {
|
|
1310
1438
|
// If the iframe scroll is at the top or bottom, do not send anything.
|
|
1311
1439
|
// This avoids losing the scrollend event.
|
|
@@ -1347,7 +1475,14 @@ function registerUVEEvents() {
|
|
|
1347
1475
|
setBounds(bounds);
|
|
1348
1476
|
});
|
|
1349
1477
|
return {
|
|
1350
|
-
subscriptions: [pageReloadSubscription,
|
|
1478
|
+
subscriptions: [pageReloadSubscription, {
|
|
1479
|
+
...iframeScrollVelocitySubscription,
|
|
1480
|
+
unsubscribe: () => {
|
|
1481
|
+
iframeScrollVelocitySubscription.unsubscribe();
|
|
1482
|
+
dragScroller.stop();
|
|
1483
|
+
editorSendsVelocity = false;
|
|
1484
|
+
}
|
|
1485
|
+
}, iframeScrollSubscription, contentletHoveredSubscription, contentletClickedSubscription, scrollToSectionSubscription, autoBoundsSubscription]
|
|
1351
1486
|
};
|
|
1352
1487
|
}
|
|
1353
1488
|
/**
|
package/public.esm.js
CHANGED
|
@@ -651,6 +651,10 @@ function onAutoBounds(callback) {
|
|
|
651
651
|
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
652
652
|
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
653
653
|
* @internal
|
|
654
|
+
* @deprecated Use `onIframeScrollVelocity`, which receives the speed the page scrolls at every
|
|
655
|
+
* frame during a drag. Still subscribed, so the one-step request the editor keeps sending for
|
|
656
|
+
* pages on an older `@dotcms/uve` is still handled; `registerUVEEvents` ignores it once a
|
|
657
|
+
* velocity arrives.
|
|
654
658
|
*/
|
|
655
659
|
function onIframeScroll(callback) {
|
|
656
660
|
const messageCallback = event => {
|
|
@@ -669,6 +673,30 @@ function onIframeScroll(callback) {
|
|
|
669
673
|
event: UVEEventType.IFRAME_SCROLL
|
|
670
674
|
};
|
|
671
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* Subscribes to the scroll velocity the UVE editor sets during a drag. The callback gets the
|
|
678
|
+
* message's `velocity` as sent; the caller validates it.
|
|
679
|
+
*
|
|
680
|
+
* @param {UVEEventHandler} callback - Function called with each velocity the editor sends
|
|
681
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
682
|
+
* @internal
|
|
683
|
+
*/
|
|
684
|
+
function onIframeScrollVelocity(callback) {
|
|
685
|
+
const messageCallback = event => {
|
|
686
|
+
if (event.data?.name === __DOTCMS_UVE_EVENT__.UVE_SCROLL_VELOCITY) {
|
|
687
|
+
callback(event.data.velocity);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
// Native binder: survives the iframe rewrite under Zone.js. See getNativeEventBinder.
|
|
691
|
+
const nativeWindow = getNativeEventBinder(window);
|
|
692
|
+
nativeWindow.addEventListener('message', messageCallback);
|
|
693
|
+
return {
|
|
694
|
+
unsubscribe: () => {
|
|
695
|
+
nativeWindow.removeEventListener('message', messageCallback);
|
|
696
|
+
},
|
|
697
|
+
event: UVEEventType.IFRAME_SCROLL_VELOCITY
|
|
698
|
+
};
|
|
699
|
+
}
|
|
672
700
|
/**
|
|
673
701
|
* Listens for scroll-to-section requests from the UVE editor.
|
|
674
702
|
*
|
|
@@ -891,6 +919,9 @@ const __UVE_EVENTS__ = {
|
|
|
891
919
|
[UVEEventType.IFRAME_SCROLL]: callback => {
|
|
892
920
|
return onIframeScroll(callback);
|
|
893
921
|
},
|
|
922
|
+
[UVEEventType.IFRAME_SCROLL_VELOCITY]: callback => {
|
|
923
|
+
return onIframeScrollVelocity(callback);
|
|
924
|
+
},
|
|
894
925
|
[UVEEventType.CONTENTLET_HOVERED]: callback => {
|
|
895
926
|
return onContentletHovered(callback);
|
|
896
927
|
},
|
|
@@ -1235,15 +1266,99 @@ const isValidBlocks = blocks => {
|
|
|
1235
1266
|
};
|
|
1236
1267
|
};
|
|
1237
1268
|
|
|
1269
|
+
/** One frame at 60fps, in ms: the unit the editor's scroll velocity is expressed in. */
|
|
1270
|
+
const FRAME_MS = 1000 / 60;
|
|
1271
|
+
/** The fastest the page scrolls during a drag, in px per 60fps frame. */
|
|
1272
|
+
const MAX_SCROLL_VELOCITY = 40;
|
|
1273
|
+
/**
|
|
1274
|
+
* The longest frame a scroll step accounts for, so a frame delayed by a busy or hidden tab does
|
|
1275
|
+
* not jump the page.
|
|
1276
|
+
*/
|
|
1277
|
+
const MAX_FRAME_MS = 4 * FRAME_MS;
|
|
1278
|
+
/** A velocity the page can use: a finite number, clamped to the maximum; anything else is 0. */
|
|
1279
|
+
function toScrollVelocity(velocity) {
|
|
1280
|
+
if (typeof velocity !== 'number' || !Number.isFinite(velocity)) {
|
|
1281
|
+
return 0;
|
|
1282
|
+
}
|
|
1283
|
+
return Math.max(-MAX_SCROLL_VELOCITY, Math.min(MAX_SCROLL_VELOCITY, velocity));
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Scrolls the page continuously during a drag, at the velocity the editor sets, one instant step
|
|
1287
|
+
* per animation frame scaled by how long the frame took. It stops at velocity 0, at the top when
|
|
1288
|
+
* scrolling up, at the bottom when scrolling down, and on `stop()`.
|
|
1289
|
+
*/
|
|
1290
|
+
function createDragScroller() {
|
|
1291
|
+
let velocity = 0;
|
|
1292
|
+
let frameId = null;
|
|
1293
|
+
let lastFrameTime = null;
|
|
1294
|
+
const halt = () => {
|
|
1295
|
+
if (frameId !== null) {
|
|
1296
|
+
cancelAnimationFrame(frameId);
|
|
1297
|
+
}
|
|
1298
|
+
frameId = null;
|
|
1299
|
+
lastFrameTime = null;
|
|
1300
|
+
};
|
|
1301
|
+
const step = time => {
|
|
1302
|
+
frameId = null;
|
|
1303
|
+
if (velocity === 0) {
|
|
1304
|
+
halt();
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
// At the top or bottom, wait instead of stopping: the editor sends a velocity only when
|
|
1308
|
+
// it changes, so a loop that stopped would stay still if the page then grew.
|
|
1309
|
+
if (velocity < 0 && window.scrollY <= 0 || velocity > 0 && computeScrollIsInBottom()) {
|
|
1310
|
+
// The first step after waiting is one frame's, not the whole wait's.
|
|
1311
|
+
lastFrameTime = null;
|
|
1312
|
+
frameId = requestAnimationFrame(step);
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
const elapsed = lastFrameTime === null ? FRAME_MS : time - lastFrameTime;
|
|
1316
|
+
lastFrameTime = time;
|
|
1317
|
+
window.scrollBy({
|
|
1318
|
+
left: 0,
|
|
1319
|
+
top: velocity * (Math.min(elapsed, MAX_FRAME_MS) / FRAME_MS),
|
|
1320
|
+
behavior: 'instant'
|
|
1321
|
+
});
|
|
1322
|
+
// Report where the page is now, in this frame. The scroll event's own report comes a
|
|
1323
|
+
// frame later, and the editor shifts bounds that arrive in between from the last report.
|
|
1324
|
+
sendMessageToUVE({
|
|
1325
|
+
action: DotCMSUVEAction.IFRAME_SCROLL,
|
|
1326
|
+
payload: {
|
|
1327
|
+
scrollY: window.scrollY
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
frameId = requestAnimationFrame(step);
|
|
1331
|
+
};
|
|
1332
|
+
return {
|
|
1333
|
+
setVelocity: next => {
|
|
1334
|
+
velocity = toScrollVelocity(next);
|
|
1335
|
+
if (velocity === 0) {
|
|
1336
|
+
halt();
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
if (frameId === null) {
|
|
1340
|
+
frameId = requestAnimationFrame(step);
|
|
1341
|
+
}
|
|
1342
|
+
},
|
|
1343
|
+
stop: () => {
|
|
1344
|
+
velocity = 0;
|
|
1345
|
+
halt();
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1238
1349
|
/**
|
|
1239
1350
|
* Sets up scroll event handlers for the window to notify the editor about scroll events.
|
|
1240
1351
|
* Adds listeners for both 'scroll' and 'scrollend' events, sending appropriate messages
|
|
1241
1352
|
* to the editor when these events occur.
|
|
1242
1353
|
*/
|
|
1243
1354
|
function scrollHandler() {
|
|
1355
|
+
// The scroll offset lets the editor keep its drop targets aligned while a drag scrolls the page.
|
|
1244
1356
|
const scrollCallback = () => {
|
|
1245
1357
|
sendMessageToUVE({
|
|
1246
|
-
action: DotCMSUVEAction.IFRAME_SCROLL
|
|
1358
|
+
action: DotCMSUVEAction.IFRAME_SCROLL,
|
|
1359
|
+
payload: {
|
|
1360
|
+
scrollY: window.scrollY
|
|
1361
|
+
}
|
|
1247
1362
|
});
|
|
1248
1363
|
};
|
|
1249
1364
|
const scrollEndCallback = () => {
|
|
@@ -1292,6 +1407,7 @@ function addClassToEmptyContentlets() {
|
|
|
1292
1407
|
* - Page reload events that refresh the window
|
|
1293
1408
|
* - Bounds request events to update editor boundaries
|
|
1294
1409
|
* - Iframe scroll events to handle smooth scrolling within bounds
|
|
1410
|
+
* - Scroll velocity events, which scroll the page every frame during a drag
|
|
1295
1411
|
* - Contentlet hover events to notify the editor
|
|
1296
1412
|
*
|
|
1297
1413
|
* @remarks
|
|
@@ -1303,7 +1419,19 @@ function registerUVEEvents() {
|
|
|
1303
1419
|
const pageReloadSubscription = createUVESubscription(UVEEventType.PAGE_RELOAD, () => {
|
|
1304
1420
|
window.location.reload();
|
|
1305
1421
|
});
|
|
1422
|
+
// Both live per registration, so a later registration starts with a fresh flag and no loop.
|
|
1423
|
+
const dragScroller = createDragScroller();
|
|
1424
|
+
// Once the editor sends a velocity, it drives the scroll, and its one-step direction requests,
|
|
1425
|
+
// which it keeps sending for older pages, are ignored.
|
|
1426
|
+
let editorSendsVelocity = false;
|
|
1427
|
+
const iframeScrollVelocitySubscription = createUVESubscription(UVEEventType.IFRAME_SCROLL_VELOCITY, velocity => {
|
|
1428
|
+
editorSendsVelocity = true;
|
|
1429
|
+
dragScroller.setVelocity(velocity);
|
|
1430
|
+
});
|
|
1306
1431
|
const iframeScrollSubscription = createUVESubscription(UVEEventType.IFRAME_SCROLL, direction => {
|
|
1432
|
+
if (editorSendsVelocity) {
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1307
1435
|
if (window.scrollY === 0 && direction === 'up' || computeScrollIsInBottom() && direction === 'down') {
|
|
1308
1436
|
// If the iframe scroll is at the top or bottom, do not send anything.
|
|
1309
1437
|
// This avoids losing the scrollend event.
|
|
@@ -1345,7 +1473,14 @@ function registerUVEEvents() {
|
|
|
1345
1473
|
setBounds(bounds);
|
|
1346
1474
|
});
|
|
1347
1475
|
return {
|
|
1348
|
-
subscriptions: [pageReloadSubscription,
|
|
1476
|
+
subscriptions: [pageReloadSubscription, {
|
|
1477
|
+
...iframeScrollVelocitySubscription,
|
|
1478
|
+
unsubscribe: () => {
|
|
1479
|
+
iframeScrollVelocitySubscription.unsubscribe();
|
|
1480
|
+
dragScroller.stop();
|
|
1481
|
+
editorSendsVelocity = false;
|
|
1482
|
+
}
|
|
1483
|
+
}, iframeScrollSubscription, contentletHoveredSubscription, contentletClickedSubscription, scrollToSectionSubscription, autoBoundsSubscription]
|
|
1349
1484
|
};
|
|
1350
1485
|
}
|
|
1351
1486
|
/**
|
package/src/internal/events.d.ts
CHANGED
|
@@ -53,11 +53,27 @@ export declare function onAutoBounds(callback: UVEEventHandler): {
|
|
|
53
53
|
* @returns {Function} .unsubscribe - Function to remove the event listener
|
|
54
54
|
* @returns {UVEEventType} .event - The event type being subscribed to
|
|
55
55
|
* @internal
|
|
56
|
+
* @deprecated Use `onIframeScrollVelocity`, which receives the speed the page scrolls at every
|
|
57
|
+
* frame during a drag. Still subscribed, so the one-step request the editor keeps sending for
|
|
58
|
+
* pages on an older `@dotcms/uve` is still handled; `registerUVEEvents` ignores it once a
|
|
59
|
+
* velocity arrives.
|
|
56
60
|
*/
|
|
57
61
|
export declare function onIframeScroll(callback: UVEEventHandler): {
|
|
58
62
|
unsubscribe: () => void;
|
|
59
63
|
event: UVEEventType;
|
|
60
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Subscribes to the scroll velocity the UVE editor sets during a drag. The callback gets the
|
|
67
|
+
* message's `velocity` as sent; the caller validates it.
|
|
68
|
+
*
|
|
69
|
+
* @param {UVEEventHandler} callback - Function called with each velocity the editor sends
|
|
70
|
+
* @returns {Object} Object containing unsubscribe function and event type
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export declare function onIframeScrollVelocity(callback: UVEEventHandler): {
|
|
74
|
+
unsubscribe: () => void;
|
|
75
|
+
event: UVEEventType;
|
|
76
|
+
};
|
|
61
77
|
/**
|
|
62
78
|
* Listens for scroll-to-section requests from the UVE editor.
|
|
63
79
|
*
|
package/src/script/utils.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function addClassToEmptyContentlets(): void;
|
|
|
24
24
|
* - Page reload events that refresh the window
|
|
25
25
|
* - Bounds request events to update editor boundaries
|
|
26
26
|
* - Iframe scroll events to handle smooth scrolling within bounds
|
|
27
|
+
* - Scroll velocity events, which scroll the page every frame during a drag
|
|
27
28
|
* - Contentlet hover events to notify the editor
|
|
28
29
|
*
|
|
29
30
|
* @remarks
|