@ones-editor/editor 3.0.16 → 3.0.17-beta.4
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.
|
@@ -3,7 +3,18 @@ export declare class ImagePreviewHandler implements OnesEditorCustom {
|
|
|
3
3
|
private editor;
|
|
4
4
|
private onPreview;
|
|
5
5
|
private lastClickPosition;
|
|
6
|
+
private lastPreviewCandidates;
|
|
7
|
+
private lastScrollSnapshots;
|
|
6
8
|
constructor(editor: OnesEditor, onPreview: (editor: OnesEditor, img: HTMLImageElement) => void);
|
|
9
|
+
getPreviewCandidateElements(e: MouseEvent): HTMLElement[];
|
|
10
|
+
previewFromImageBox(elem: HTMLElement): boolean;
|
|
11
|
+
previewFromImageContainer(elem: HTMLElement): boolean;
|
|
12
|
+
previewFromEmbedBlock(elem: HTMLElement): boolean;
|
|
13
|
+
isPreviewableImageElement(elem: HTMLElement): boolean;
|
|
14
|
+
previewFromCandidates: (candidates: HTMLElement[]) => boolean;
|
|
15
|
+
captureScrollSnapshots: () => void;
|
|
16
|
+
restoreScrollSnapshots: () => void;
|
|
17
|
+
scheduleRestoreScrollSnapshots: () => void;
|
|
7
18
|
handleImagePreview: (e: MouseEvent) => void;
|
|
8
19
|
handleMouseUp: (e: MouseEvent) => void;
|
|
9
20
|
handleMouseDown: (e: MouseEvent) => void;
|
package/dist/index.js
CHANGED
|
@@ -93228,58 +93228,138 @@ ${data2.plantumlText}
|
|
|
93228
93228
|
StatusBox
|
|
93229
93229
|
];
|
|
93230
93230
|
const safetyOffset = 2;
|
|
93231
|
+
function isPointInElement(elem, x, y) {
|
|
93232
|
+
const rect = elem.getBoundingClientRect();
|
|
93233
|
+
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
|
|
93234
|
+
}
|
|
93235
|
+
function getImagePreviewTarget(elem) {
|
|
93236
|
+
if (elem instanceof HTMLImageElement && elem.classList.contains("editor-image")) {
|
|
93237
|
+
return elem;
|
|
93238
|
+
}
|
|
93239
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93240
|
+
if (imageContainer instanceof HTMLElement) {
|
|
93241
|
+
const img = imageContainer.querySelector("img.editor-image");
|
|
93242
|
+
return img instanceof HTMLElement ? img : imageContainer;
|
|
93243
|
+
}
|
|
93244
|
+
const imageBox = elem.closest('span[data-type="editor-box"][data-box-type="image"]');
|
|
93245
|
+
if (imageBox instanceof HTMLElement) {
|
|
93246
|
+
const img = imageBox.querySelector("img");
|
|
93247
|
+
return img instanceof HTMLElement ? img : imageBox;
|
|
93248
|
+
}
|
|
93249
|
+
return null;
|
|
93250
|
+
}
|
|
93251
|
+
function getScrollSnapshots(elem) {
|
|
93252
|
+
const snapshots = [{
|
|
93253
|
+
element: null,
|
|
93254
|
+
isWindow: true,
|
|
93255
|
+
scrollTop: window.scrollY,
|
|
93256
|
+
scrollLeft: window.scrollX
|
|
93257
|
+
}];
|
|
93258
|
+
const added = /* @__PURE__ */ new Set();
|
|
93259
|
+
let current = elem;
|
|
93260
|
+
while (current) {
|
|
93261
|
+
const style2 = window.getComputedStyle(current);
|
|
93262
|
+
const overflow = `${style2.overflow}${style2.overflowY}${style2.overflowX}`;
|
|
93263
|
+
const canScroll = current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth;
|
|
93264
|
+
if (canScroll || /(auto|scroll|overlay)/.test(overflow)) {
|
|
93265
|
+
snapshots.push({
|
|
93266
|
+
element: current,
|
|
93267
|
+
isWindow: false,
|
|
93268
|
+
scrollTop: current.scrollTop,
|
|
93269
|
+
scrollLeft: current.scrollLeft
|
|
93270
|
+
});
|
|
93271
|
+
added.add(current);
|
|
93272
|
+
}
|
|
93273
|
+
current = current.parentElement;
|
|
93274
|
+
}
|
|
93275
|
+
const scrollingElement = document.scrollingElement;
|
|
93276
|
+
if (scrollingElement instanceof HTMLElement && !added.has(scrollingElement)) {
|
|
93277
|
+
snapshots.push({
|
|
93278
|
+
element: scrollingElement,
|
|
93279
|
+
isWindow: false,
|
|
93280
|
+
scrollTop: scrollingElement.scrollTop,
|
|
93281
|
+
scrollLeft: scrollingElement.scrollLeft
|
|
93282
|
+
});
|
|
93283
|
+
}
|
|
93284
|
+
return snapshots;
|
|
93285
|
+
}
|
|
93231
93286
|
class ImagePreviewHandler {
|
|
93232
93287
|
constructor(editor, onPreview) {
|
|
93233
93288
|
__publicField(this, "lastClickPosition");
|
|
93234
|
-
__publicField(this, "
|
|
93235
|
-
|
|
93236
|
-
|
|
93237
|
-
if (!
|
|
93238
|
-
return;
|
|
93289
|
+
__publicField(this, "lastPreviewCandidates", []);
|
|
93290
|
+
__publicField(this, "lastScrollSnapshots", []);
|
|
93291
|
+
__publicField(this, "previewFromCandidates", (candidates) => {
|
|
93292
|
+
if (!candidates.length) {
|
|
93293
|
+
return false;
|
|
93239
93294
|
}
|
|
93240
|
-
const
|
|
93241
|
-
|
|
93242
|
-
|
|
93243
|
-
|
|
93244
|
-
if (
|
|
93245
|
-
|
|
93246
|
-
|
|
93295
|
+
for (const elem of candidates) {
|
|
93296
|
+
if (this.previewFromImageBox(elem)) {
|
|
93297
|
+
return true;
|
|
93298
|
+
}
|
|
93299
|
+
if (this.previewFromImageContainer(elem)) {
|
|
93300
|
+
return true;
|
|
93301
|
+
}
|
|
93302
|
+
if (this.previewFromEmbedBlock(elem)) {
|
|
93303
|
+
return true;
|
|
93247
93304
|
}
|
|
93248
93305
|
}
|
|
93249
|
-
|
|
93250
|
-
|
|
93251
|
-
|
|
93252
|
-
|
|
93253
|
-
|
|
93306
|
+
return false;
|
|
93307
|
+
});
|
|
93308
|
+
__publicField(this, "captureScrollSnapshots", () => {
|
|
93309
|
+
this.lastScrollSnapshots = getScrollSnapshots(this.editor.rootElement);
|
|
93310
|
+
});
|
|
93311
|
+
__publicField(this, "restoreScrollSnapshots", () => {
|
|
93312
|
+
if (!this.lastScrollSnapshots.length) {
|
|
93254
93313
|
return;
|
|
93255
93314
|
}
|
|
93256
|
-
|
|
93257
|
-
|
|
93258
|
-
if (
|
|
93259
|
-
|
|
93260
|
-
}
|
|
93261
|
-
}
|
|
93262
|
-
if (elem.hasAttribute("data-src")) {
|
|
93263
|
-
const img = elem.querySelector("img");
|
|
93264
|
-
if (img) {
|
|
93265
|
-
this.onPreview(this.editor, img);
|
|
93315
|
+
this.lastScrollSnapshots.forEach((snapshot2) => {
|
|
93316
|
+
var _a;
|
|
93317
|
+
if (snapshot2.isWindow) {
|
|
93318
|
+
window.scrollTo(snapshot2.scrollLeft, snapshot2.scrollTop);
|
|
93266
93319
|
return;
|
|
93267
93320
|
}
|
|
93268
|
-
|
|
93269
|
-
|
|
93270
|
-
|
|
93271
|
-
|
|
93321
|
+
(_a = snapshot2.element) == null ? void 0 : _a.scrollTo(snapshot2.scrollLeft, snapshot2.scrollTop);
|
|
93322
|
+
});
|
|
93323
|
+
});
|
|
93324
|
+
__publicField(this, "scheduleRestoreScrollSnapshots", () => {
|
|
93325
|
+
this.restoreScrollSnapshots();
|
|
93326
|
+
window.requestAnimationFrame(() => {
|
|
93327
|
+
this.restoreScrollSnapshots();
|
|
93328
|
+
window.requestAnimationFrame(this.restoreScrollSnapshots);
|
|
93329
|
+
});
|
|
93330
|
+
window.setTimeout(this.restoreScrollSnapshots, 50);
|
|
93331
|
+
window.setTimeout(this.restoreScrollSnapshots, 200);
|
|
93332
|
+
});
|
|
93333
|
+
__publicField(this, "handleImagePreview", (e2) => {
|
|
93334
|
+
const candidates = this.getPreviewCandidateElements(e2);
|
|
93335
|
+
this.previewFromCandidates(candidates);
|
|
93272
93336
|
});
|
|
93273
93337
|
__publicField(this, "handleMouseUp", (e2) => {
|
|
93274
|
-
if (!this.lastClickPosition)
|
|
93338
|
+
if (!this.lastClickPosition) {
|
|
93275
93339
|
return;
|
|
93340
|
+
}
|
|
93276
93341
|
const { x, y } = this.lastClickPosition;
|
|
93277
93342
|
const deltaX = Math.abs(e2.x - x);
|
|
93278
93343
|
const deltaY = Math.abs(e2.y - y);
|
|
93344
|
+
const previewCandidates = this.lastPreviewCandidates;
|
|
93279
93345
|
this.lastClickPosition = void 0;
|
|
93346
|
+
this.lastPreviewCandidates = [];
|
|
93280
93347
|
if (deltaX < safetyOffset && deltaY < safetyOffset) {
|
|
93348
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93349
|
+
if (this.previewFromCandidates(previewCandidates)) {
|
|
93350
|
+
window.setTimeout(() => {
|
|
93351
|
+
this.lastScrollSnapshots = [];
|
|
93352
|
+
}, 250);
|
|
93353
|
+
return;
|
|
93354
|
+
}
|
|
93281
93355
|
this.handleImagePreview(e2);
|
|
93356
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93357
|
+
window.setTimeout(() => {
|
|
93358
|
+
this.lastScrollSnapshots = [];
|
|
93359
|
+
}, 250);
|
|
93360
|
+
return;
|
|
93282
93361
|
}
|
|
93362
|
+
this.lastScrollSnapshots = [];
|
|
93283
93363
|
});
|
|
93284
93364
|
__publicField(this, "handleMouseDown", (e2) => {
|
|
93285
93365
|
const { x, y } = e2;
|
|
@@ -93296,9 +93376,16 @@ ${data2.plantumlText}
|
|
|
93296
93376
|
return;
|
|
93297
93377
|
}
|
|
93298
93378
|
this.lastClickPosition = { x, y };
|
|
93379
|
+
this.lastPreviewCandidates = this.getPreviewCandidateElements(e2);
|
|
93380
|
+
if (this.lastPreviewCandidates.some((candidate) => this.isPreviewableImageElement(candidate))) {
|
|
93381
|
+
this.captureScrollSnapshots();
|
|
93382
|
+
e2.preventDefault();
|
|
93383
|
+
e2.stopPropagation();
|
|
93384
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93385
|
+
}
|
|
93299
93386
|
});
|
|
93300
93387
|
__publicField(this, "destroy", () => {
|
|
93301
|
-
this.editor.rootElement.removeEventListener("mousedown", this.handleMouseDown);
|
|
93388
|
+
this.editor.rootElement.removeEventListener("mousedown", this.handleMouseDown, { capture: true });
|
|
93302
93389
|
this.editor.rootElement.removeEventListener("mouseup", this.handleMouseUp);
|
|
93303
93390
|
});
|
|
93304
93391
|
this.editor = editor;
|
|
@@ -93306,6 +93393,131 @@ ${data2.plantumlText}
|
|
|
93306
93393
|
editor.rootElement.addEventListener("mousedown", this.handleMouseDown, { capture: true });
|
|
93307
93394
|
editor.rootElement.addEventListener("mouseup", this.handleMouseUp);
|
|
93308
93395
|
}
|
|
93396
|
+
getPreviewCandidateElements(e2) {
|
|
93397
|
+
var _a, _b;
|
|
93398
|
+
const candidates = [];
|
|
93399
|
+
const addCandidate = (target) => {
|
|
93400
|
+
if (!(target instanceof HTMLElement)) {
|
|
93401
|
+
return;
|
|
93402
|
+
}
|
|
93403
|
+
if (!this.editor.rootElement.contains(target)) {
|
|
93404
|
+
return;
|
|
93405
|
+
}
|
|
93406
|
+
if (candidates.includes(target)) {
|
|
93407
|
+
return;
|
|
93408
|
+
}
|
|
93409
|
+
candidates.push(target);
|
|
93410
|
+
};
|
|
93411
|
+
const addElementStackHit = (target) => {
|
|
93412
|
+
if (!(target instanceof HTMLElement)) {
|
|
93413
|
+
return;
|
|
93414
|
+
}
|
|
93415
|
+
if (!this.editor.rootElement.contains(target)) {
|
|
93416
|
+
return;
|
|
93417
|
+
}
|
|
93418
|
+
addCandidate(getImagePreviewTarget(target));
|
|
93419
|
+
};
|
|
93420
|
+
if (typeof document !== "undefined") {
|
|
93421
|
+
(_a = document.elementsFromPoint) == null ? void 0 : _a.call(document, e2.clientX, e2.clientY).forEach(addElementStackHit);
|
|
93422
|
+
addElementStackHit(document.elementFromPoint(e2.clientX, e2.clientY));
|
|
93423
|
+
}
|
|
93424
|
+
this.editor.rootElement.querySelectorAll('img.editor-image, span[data-type="editor-box"][data-box-type="image"] img').forEach((elem) => {
|
|
93425
|
+
if (elem instanceof HTMLElement && isPointInElement(elem, e2.clientX, e2.clientY)) {
|
|
93426
|
+
addCandidate(elem);
|
|
93427
|
+
}
|
|
93428
|
+
});
|
|
93429
|
+
this.editor.rootElement.querySelectorAll(".image-container[data-src]").forEach((elem) => {
|
|
93430
|
+
if (elem instanceof HTMLElement && isPointInElement(elem, e2.clientX, e2.clientY)) {
|
|
93431
|
+
addCandidate(elem);
|
|
93432
|
+
}
|
|
93433
|
+
});
|
|
93434
|
+
addCandidate(e2.target);
|
|
93435
|
+
(_b = e2.composedPath) == null ? void 0 : _b.call(e2).forEach(addCandidate);
|
|
93436
|
+
return candidates;
|
|
93437
|
+
}
|
|
93438
|
+
previewFromImageBox(elem) {
|
|
93439
|
+
const imageBox = getParentBox(elem);
|
|
93440
|
+
const boxType = imageBox && getBoxTypeFromElement(imageBox);
|
|
93441
|
+
const img = elem instanceof HTMLImageElement ? elem : imageBox == null ? void 0 : imageBox.querySelector("img");
|
|
93442
|
+
if (!imageBox || boxType !== "image" || !img) {
|
|
93443
|
+
return false;
|
|
93444
|
+
}
|
|
93445
|
+
const imgData = this.editor.getBoxData(imageBox);
|
|
93446
|
+
if (!imgData.link) {
|
|
93447
|
+
this.onPreview(this.editor, img);
|
|
93448
|
+
}
|
|
93449
|
+
return true;
|
|
93450
|
+
}
|
|
93451
|
+
previewFromImageContainer(elem) {
|
|
93452
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93453
|
+
if (!(imageContainer instanceof HTMLElement)) {
|
|
93454
|
+
return false;
|
|
93455
|
+
}
|
|
93456
|
+
if (!this.editor.rootElement.contains(imageContainer)) {
|
|
93457
|
+
return false;
|
|
93458
|
+
}
|
|
93459
|
+
const block = getParentBlock(imageContainer);
|
|
93460
|
+
if (block && isEmbedBlock(block) && getEmbedType(block) === "image") {
|
|
93461
|
+
const imageData = this.editor.getBlockData(block);
|
|
93462
|
+
if (imageData.link) {
|
|
93463
|
+
return true;
|
|
93464
|
+
}
|
|
93465
|
+
}
|
|
93466
|
+
const img = elem instanceof HTMLImageElement ? elem : imageContainer.querySelector("img");
|
|
93467
|
+
if (img) {
|
|
93468
|
+
this.onPreview(this.editor, img);
|
|
93469
|
+
}
|
|
93470
|
+
return true;
|
|
93471
|
+
}
|
|
93472
|
+
previewFromEmbedBlock(elem) {
|
|
93473
|
+
var _a;
|
|
93474
|
+
const block = getParentBlock(elem);
|
|
93475
|
+
if (!block) {
|
|
93476
|
+
return false;
|
|
93477
|
+
}
|
|
93478
|
+
if (!isEmbedBlock(block)) {
|
|
93479
|
+
return false;
|
|
93480
|
+
}
|
|
93481
|
+
if (getEmbedType(block) === "image") {
|
|
93482
|
+
const imageData = this.editor.getBlockData(block);
|
|
93483
|
+
if (imageData.link) {
|
|
93484
|
+
return true;
|
|
93485
|
+
}
|
|
93486
|
+
}
|
|
93487
|
+
if (elem.hasAttribute("data-src")) {
|
|
93488
|
+
const img = elem.querySelector("img");
|
|
93489
|
+
if (img) {
|
|
93490
|
+
this.onPreview(this.editor, img);
|
|
93491
|
+
}
|
|
93492
|
+
return true;
|
|
93493
|
+
}
|
|
93494
|
+
if (elem.tagName === "IMG" && ((_a = elem.parentElement) == null ? void 0 : _a.hasAttribute("data-src"))) {
|
|
93495
|
+
this.onPreview(this.editor, elem);
|
|
93496
|
+
return true;
|
|
93497
|
+
}
|
|
93498
|
+
return false;
|
|
93499
|
+
}
|
|
93500
|
+
isPreviewableImageElement(elem) {
|
|
93501
|
+
const imageBox = getParentBox(elem);
|
|
93502
|
+
const boxType = imageBox && getBoxTypeFromElement(imageBox);
|
|
93503
|
+
const imageBoxImg = elem instanceof HTMLImageElement ? elem : imageBox == null ? void 0 : imageBox.querySelector("img");
|
|
93504
|
+
if (imageBox && boxType === "image" && imageBoxImg) {
|
|
93505
|
+
const imgData = this.editor.getBoxData(imageBox);
|
|
93506
|
+
return !imgData.link;
|
|
93507
|
+
}
|
|
93508
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93509
|
+
if (imageContainer instanceof HTMLElement) {
|
|
93510
|
+
const block = getParentBlock(imageContainer);
|
|
93511
|
+
if (block && isEmbedBlock(block) && getEmbedType(block) === "image") {
|
|
93512
|
+
const imageData = this.editor.getBlockData(block);
|
|
93513
|
+
if (imageData.link) {
|
|
93514
|
+
return false;
|
|
93515
|
+
}
|
|
93516
|
+
}
|
|
93517
|
+
return Boolean(elem instanceof HTMLImageElement ? elem : imageContainer.querySelector("img"));
|
|
93518
|
+
}
|
|
93519
|
+
return false;
|
|
93520
|
+
}
|
|
93309
93521
|
}
|
|
93310
93522
|
function createHistoryEditor(root2, doc2, options) {
|
|
93311
93523
|
var _a, _b, _c, _d, _e;
|
|
@@ -97125,7 +97337,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97125
97337
|
}
|
|
97126
97338
|
}
|
|
97127
97339
|
});
|
|
97128
|
-
editor.version = "3.0.
|
|
97340
|
+
editor.version = "3.0.17-beta.4";
|
|
97129
97341
|
return editor;
|
|
97130
97342
|
}
|
|
97131
97343
|
function isDoc(doc2) {
|
|
@@ -97259,7 +97471,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97259
97471
|
OnesEditorDropTarget.register(editor);
|
|
97260
97472
|
OnesEditorTocProvider.register(editor);
|
|
97261
97473
|
OnesEditorExclusiveBlock.register(editor);
|
|
97262
|
-
editor.version = "3.0.
|
|
97474
|
+
editor.version = "3.0.17-beta.4";
|
|
97263
97475
|
return editor;
|
|
97264
97476
|
}
|
|
97265
97477
|
async function showDocVersions(editor, options, serverUrl) {
|
|
@@ -97394,7 +97606,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97394
97606
|
}
|
|
97395
97607
|
}
|
|
97396
97608
|
});
|
|
97397
|
-
editor.version = "3.0.
|
|
97609
|
+
editor.version = "3.0.17-beta.4";
|
|
97398
97610
|
return editor;
|
|
97399
97611
|
}
|
|
97400
97612
|
const emojis$1 = {
|