@ones-editor/editor 3.0.13 → 3.0.14-beta.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.
|
@@ -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
|
@@ -83078,6 +83078,9 @@ ${docStr}
|
|
|
83078
83078
|
const blocks = this.docObject.blocks[containerId];
|
|
83079
83079
|
const blockData = blocks[updateIndex];
|
|
83080
83080
|
assert(logger$C, !blockData.deleted, `block has already deleted: ${containerId}/${blockIndex}`);
|
|
83081
|
+
if (!Array.isArray(blockData.text)) {
|
|
83082
|
+
blockData.text = [];
|
|
83083
|
+
}
|
|
83081
83084
|
const text2 = blockData.text;
|
|
83082
83085
|
assert(logger$C, text2, `no text for block: ${JSON.stringify(blockData)}`);
|
|
83083
83086
|
const newText = updateBlockText(text2, actions2, user);
|
|
@@ -92986,58 +92989,138 @@ ${data2.plantumlText}
|
|
|
92986
92989
|
StatusBox
|
|
92987
92990
|
];
|
|
92988
92991
|
const safetyOffset = 2;
|
|
92992
|
+
function isPointInElement(elem, x, y) {
|
|
92993
|
+
const rect = elem.getBoundingClientRect();
|
|
92994
|
+
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
|
|
92995
|
+
}
|
|
92996
|
+
function getImagePreviewTarget(elem) {
|
|
92997
|
+
if (elem instanceof HTMLImageElement && elem.classList.contains("editor-image")) {
|
|
92998
|
+
return elem;
|
|
92999
|
+
}
|
|
93000
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93001
|
+
if (imageContainer instanceof HTMLElement) {
|
|
93002
|
+
const img = imageContainer.querySelector("img.editor-image");
|
|
93003
|
+
return img instanceof HTMLElement ? img : imageContainer;
|
|
93004
|
+
}
|
|
93005
|
+
const imageBox = elem.closest('span[data-type="editor-box"][data-box-type="image"]');
|
|
93006
|
+
if (imageBox instanceof HTMLElement) {
|
|
93007
|
+
const img = imageBox.querySelector("img");
|
|
93008
|
+
return img instanceof HTMLElement ? img : imageBox;
|
|
93009
|
+
}
|
|
93010
|
+
return null;
|
|
93011
|
+
}
|
|
93012
|
+
function getScrollSnapshots(elem) {
|
|
93013
|
+
const snapshots = [{
|
|
93014
|
+
element: null,
|
|
93015
|
+
isWindow: true,
|
|
93016
|
+
scrollTop: window.scrollY,
|
|
93017
|
+
scrollLeft: window.scrollX
|
|
93018
|
+
}];
|
|
93019
|
+
const added = /* @__PURE__ */ new Set();
|
|
93020
|
+
let current = elem;
|
|
93021
|
+
while (current) {
|
|
93022
|
+
const style2 = window.getComputedStyle(current);
|
|
93023
|
+
const overflow = `${style2.overflow}${style2.overflowY}${style2.overflowX}`;
|
|
93024
|
+
const canScroll = current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth;
|
|
93025
|
+
if (canScroll || /(auto|scroll|overlay)/.test(overflow)) {
|
|
93026
|
+
snapshots.push({
|
|
93027
|
+
element: current,
|
|
93028
|
+
isWindow: false,
|
|
93029
|
+
scrollTop: current.scrollTop,
|
|
93030
|
+
scrollLeft: current.scrollLeft
|
|
93031
|
+
});
|
|
93032
|
+
added.add(current);
|
|
93033
|
+
}
|
|
93034
|
+
current = current.parentElement;
|
|
93035
|
+
}
|
|
93036
|
+
const scrollingElement = document.scrollingElement;
|
|
93037
|
+
if (scrollingElement instanceof HTMLElement && !added.has(scrollingElement)) {
|
|
93038
|
+
snapshots.push({
|
|
93039
|
+
element: scrollingElement,
|
|
93040
|
+
isWindow: false,
|
|
93041
|
+
scrollTop: scrollingElement.scrollTop,
|
|
93042
|
+
scrollLeft: scrollingElement.scrollLeft
|
|
93043
|
+
});
|
|
93044
|
+
}
|
|
93045
|
+
return snapshots;
|
|
93046
|
+
}
|
|
92989
93047
|
class ImagePreviewHandler {
|
|
92990
93048
|
constructor(editor, onPreview) {
|
|
92991
93049
|
__publicField(this, "lastClickPosition");
|
|
92992
|
-
__publicField(this, "
|
|
92993
|
-
|
|
92994
|
-
|
|
92995
|
-
if (!
|
|
92996
|
-
return;
|
|
93050
|
+
__publicField(this, "lastPreviewCandidates", []);
|
|
93051
|
+
__publicField(this, "lastScrollSnapshots", []);
|
|
93052
|
+
__publicField(this, "previewFromCandidates", (candidates) => {
|
|
93053
|
+
if (!candidates.length) {
|
|
93054
|
+
return false;
|
|
92997
93055
|
}
|
|
92998
|
-
const
|
|
92999
|
-
|
|
93000
|
-
|
|
93001
|
-
|
|
93002
|
-
if (
|
|
93003
|
-
|
|
93004
|
-
|
|
93056
|
+
for (const elem of candidates) {
|
|
93057
|
+
if (this.previewFromImageBox(elem)) {
|
|
93058
|
+
return true;
|
|
93059
|
+
}
|
|
93060
|
+
if (this.previewFromImageContainer(elem)) {
|
|
93061
|
+
return true;
|
|
93062
|
+
}
|
|
93063
|
+
if (this.previewFromEmbedBlock(elem)) {
|
|
93064
|
+
return true;
|
|
93005
93065
|
}
|
|
93006
93066
|
}
|
|
93007
|
-
|
|
93008
|
-
|
|
93009
|
-
|
|
93010
|
-
|
|
93011
|
-
|
|
93067
|
+
return false;
|
|
93068
|
+
});
|
|
93069
|
+
__publicField(this, "captureScrollSnapshots", () => {
|
|
93070
|
+
this.lastScrollSnapshots = getScrollSnapshots(this.editor.rootElement);
|
|
93071
|
+
});
|
|
93072
|
+
__publicField(this, "restoreScrollSnapshots", () => {
|
|
93073
|
+
if (!this.lastScrollSnapshots.length) {
|
|
93012
93074
|
return;
|
|
93013
93075
|
}
|
|
93014
|
-
|
|
93015
|
-
|
|
93016
|
-
if (
|
|
93017
|
-
|
|
93018
|
-
}
|
|
93019
|
-
}
|
|
93020
|
-
if (elem.hasAttribute("data-src")) {
|
|
93021
|
-
const img = elem.querySelector("img");
|
|
93022
|
-
if (img) {
|
|
93023
|
-
this.onPreview(this.editor, img);
|
|
93076
|
+
this.lastScrollSnapshots.forEach((snapshot2) => {
|
|
93077
|
+
var _a;
|
|
93078
|
+
if (snapshot2.isWindow) {
|
|
93079
|
+
window.scrollTo(snapshot2.scrollLeft, snapshot2.scrollTop);
|
|
93024
93080
|
return;
|
|
93025
93081
|
}
|
|
93026
|
-
|
|
93027
|
-
|
|
93028
|
-
|
|
93029
|
-
|
|
93082
|
+
(_a = snapshot2.element) == null ? void 0 : _a.scrollTo(snapshot2.scrollLeft, snapshot2.scrollTop);
|
|
93083
|
+
});
|
|
93084
|
+
});
|
|
93085
|
+
__publicField(this, "scheduleRestoreScrollSnapshots", () => {
|
|
93086
|
+
this.restoreScrollSnapshots();
|
|
93087
|
+
window.requestAnimationFrame(() => {
|
|
93088
|
+
this.restoreScrollSnapshots();
|
|
93089
|
+
window.requestAnimationFrame(this.restoreScrollSnapshots);
|
|
93090
|
+
});
|
|
93091
|
+
window.setTimeout(this.restoreScrollSnapshots, 50);
|
|
93092
|
+
window.setTimeout(this.restoreScrollSnapshots, 200);
|
|
93093
|
+
});
|
|
93094
|
+
__publicField(this, "handleImagePreview", (e2) => {
|
|
93095
|
+
const candidates = this.getPreviewCandidateElements(e2);
|
|
93096
|
+
this.previewFromCandidates(candidates);
|
|
93030
93097
|
});
|
|
93031
93098
|
__publicField(this, "handleMouseUp", (e2) => {
|
|
93032
|
-
if (!this.lastClickPosition)
|
|
93099
|
+
if (!this.lastClickPosition) {
|
|
93033
93100
|
return;
|
|
93101
|
+
}
|
|
93034
93102
|
const { x, y } = this.lastClickPosition;
|
|
93035
93103
|
const deltaX = Math.abs(e2.x - x);
|
|
93036
93104
|
const deltaY = Math.abs(e2.y - y);
|
|
93105
|
+
const previewCandidates = this.lastPreviewCandidates;
|
|
93037
93106
|
this.lastClickPosition = void 0;
|
|
93107
|
+
this.lastPreviewCandidates = [];
|
|
93038
93108
|
if (deltaX < safetyOffset && deltaY < safetyOffset) {
|
|
93109
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93110
|
+
if (this.previewFromCandidates(previewCandidates)) {
|
|
93111
|
+
window.setTimeout(() => {
|
|
93112
|
+
this.lastScrollSnapshots = [];
|
|
93113
|
+
}, 250);
|
|
93114
|
+
return;
|
|
93115
|
+
}
|
|
93039
93116
|
this.handleImagePreview(e2);
|
|
93117
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93118
|
+
window.setTimeout(() => {
|
|
93119
|
+
this.lastScrollSnapshots = [];
|
|
93120
|
+
}, 250);
|
|
93121
|
+
return;
|
|
93040
93122
|
}
|
|
93123
|
+
this.lastScrollSnapshots = [];
|
|
93041
93124
|
});
|
|
93042
93125
|
__publicField(this, "handleMouseDown", (e2) => {
|
|
93043
93126
|
const { x, y } = e2;
|
|
@@ -93054,9 +93137,16 @@ ${data2.plantumlText}
|
|
|
93054
93137
|
return;
|
|
93055
93138
|
}
|
|
93056
93139
|
this.lastClickPosition = { x, y };
|
|
93140
|
+
this.lastPreviewCandidates = this.getPreviewCandidateElements(e2);
|
|
93141
|
+
if (this.lastPreviewCandidates.some((candidate) => this.isPreviewableImageElement(candidate))) {
|
|
93142
|
+
this.captureScrollSnapshots();
|
|
93143
|
+
e2.preventDefault();
|
|
93144
|
+
e2.stopPropagation();
|
|
93145
|
+
this.scheduleRestoreScrollSnapshots();
|
|
93146
|
+
}
|
|
93057
93147
|
});
|
|
93058
93148
|
__publicField(this, "destroy", () => {
|
|
93059
|
-
this.editor.rootElement.removeEventListener("mousedown", this.handleMouseDown);
|
|
93149
|
+
this.editor.rootElement.removeEventListener("mousedown", this.handleMouseDown, { capture: true });
|
|
93060
93150
|
this.editor.rootElement.removeEventListener("mouseup", this.handleMouseUp);
|
|
93061
93151
|
});
|
|
93062
93152
|
this.editor = editor;
|
|
@@ -93064,6 +93154,131 @@ ${data2.plantumlText}
|
|
|
93064
93154
|
editor.rootElement.addEventListener("mousedown", this.handleMouseDown, { capture: true });
|
|
93065
93155
|
editor.rootElement.addEventListener("mouseup", this.handleMouseUp);
|
|
93066
93156
|
}
|
|
93157
|
+
getPreviewCandidateElements(e2) {
|
|
93158
|
+
var _a, _b;
|
|
93159
|
+
const candidates = [];
|
|
93160
|
+
const addCandidate = (target) => {
|
|
93161
|
+
if (!(target instanceof HTMLElement)) {
|
|
93162
|
+
return;
|
|
93163
|
+
}
|
|
93164
|
+
if (!this.editor.rootElement.contains(target)) {
|
|
93165
|
+
return;
|
|
93166
|
+
}
|
|
93167
|
+
if (candidates.includes(target)) {
|
|
93168
|
+
return;
|
|
93169
|
+
}
|
|
93170
|
+
candidates.push(target);
|
|
93171
|
+
};
|
|
93172
|
+
const addElementStackHit = (target) => {
|
|
93173
|
+
if (!(target instanceof HTMLElement)) {
|
|
93174
|
+
return;
|
|
93175
|
+
}
|
|
93176
|
+
if (!this.editor.rootElement.contains(target)) {
|
|
93177
|
+
return;
|
|
93178
|
+
}
|
|
93179
|
+
addCandidate(getImagePreviewTarget(target));
|
|
93180
|
+
};
|
|
93181
|
+
if (typeof document !== "undefined") {
|
|
93182
|
+
(_a = document.elementsFromPoint) == null ? void 0 : _a.call(document, e2.clientX, e2.clientY).forEach(addElementStackHit);
|
|
93183
|
+
addElementStackHit(document.elementFromPoint(e2.clientX, e2.clientY));
|
|
93184
|
+
}
|
|
93185
|
+
this.editor.rootElement.querySelectorAll('img.editor-image, span[data-type="editor-box"][data-box-type="image"] img').forEach((elem) => {
|
|
93186
|
+
if (elem instanceof HTMLElement && isPointInElement(elem, e2.clientX, e2.clientY)) {
|
|
93187
|
+
addCandidate(elem);
|
|
93188
|
+
}
|
|
93189
|
+
});
|
|
93190
|
+
this.editor.rootElement.querySelectorAll(".image-container[data-src]").forEach((elem) => {
|
|
93191
|
+
if (elem instanceof HTMLElement && isPointInElement(elem, e2.clientX, e2.clientY)) {
|
|
93192
|
+
addCandidate(elem);
|
|
93193
|
+
}
|
|
93194
|
+
});
|
|
93195
|
+
addCandidate(e2.target);
|
|
93196
|
+
(_b = e2.composedPath) == null ? void 0 : _b.call(e2).forEach(addCandidate);
|
|
93197
|
+
return candidates;
|
|
93198
|
+
}
|
|
93199
|
+
previewFromImageBox(elem) {
|
|
93200
|
+
const imageBox = getParentBox(elem);
|
|
93201
|
+
const boxType = imageBox && getBoxTypeFromElement(imageBox);
|
|
93202
|
+
const img = elem instanceof HTMLImageElement ? elem : imageBox == null ? void 0 : imageBox.querySelector("img");
|
|
93203
|
+
if (!imageBox || boxType !== "image" || !img) {
|
|
93204
|
+
return false;
|
|
93205
|
+
}
|
|
93206
|
+
const imgData = this.editor.getBoxData(imageBox);
|
|
93207
|
+
if (!imgData.link) {
|
|
93208
|
+
this.onPreview(this.editor, img);
|
|
93209
|
+
}
|
|
93210
|
+
return true;
|
|
93211
|
+
}
|
|
93212
|
+
previewFromImageContainer(elem) {
|
|
93213
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93214
|
+
if (!(imageContainer instanceof HTMLElement)) {
|
|
93215
|
+
return false;
|
|
93216
|
+
}
|
|
93217
|
+
if (!this.editor.rootElement.contains(imageContainer)) {
|
|
93218
|
+
return false;
|
|
93219
|
+
}
|
|
93220
|
+
const block = getParentBlock(imageContainer);
|
|
93221
|
+
if (block && isEmbedBlock(block) && getEmbedType(block) === "image") {
|
|
93222
|
+
const imageData = this.editor.getBlockData(block);
|
|
93223
|
+
if (imageData.link) {
|
|
93224
|
+
return true;
|
|
93225
|
+
}
|
|
93226
|
+
}
|
|
93227
|
+
const img = elem instanceof HTMLImageElement ? elem : imageContainer.querySelector("img");
|
|
93228
|
+
if (img) {
|
|
93229
|
+
this.onPreview(this.editor, img);
|
|
93230
|
+
}
|
|
93231
|
+
return true;
|
|
93232
|
+
}
|
|
93233
|
+
previewFromEmbedBlock(elem) {
|
|
93234
|
+
var _a;
|
|
93235
|
+
const block = getParentBlock(elem);
|
|
93236
|
+
if (!block) {
|
|
93237
|
+
return false;
|
|
93238
|
+
}
|
|
93239
|
+
if (!isEmbedBlock(block)) {
|
|
93240
|
+
return false;
|
|
93241
|
+
}
|
|
93242
|
+
if (getEmbedType(block) === "image") {
|
|
93243
|
+
const imageData = this.editor.getBlockData(block);
|
|
93244
|
+
if (imageData.link) {
|
|
93245
|
+
return true;
|
|
93246
|
+
}
|
|
93247
|
+
}
|
|
93248
|
+
if (elem.hasAttribute("data-src")) {
|
|
93249
|
+
const img = elem.querySelector("img");
|
|
93250
|
+
if (img) {
|
|
93251
|
+
this.onPreview(this.editor, img);
|
|
93252
|
+
}
|
|
93253
|
+
return true;
|
|
93254
|
+
}
|
|
93255
|
+
if (elem.tagName === "IMG" && ((_a = elem.parentElement) == null ? void 0 : _a.hasAttribute("data-src"))) {
|
|
93256
|
+
this.onPreview(this.editor, elem);
|
|
93257
|
+
return true;
|
|
93258
|
+
}
|
|
93259
|
+
return false;
|
|
93260
|
+
}
|
|
93261
|
+
isPreviewableImageElement(elem) {
|
|
93262
|
+
const imageBox = getParentBox(elem);
|
|
93263
|
+
const boxType = imageBox && getBoxTypeFromElement(imageBox);
|
|
93264
|
+
const imageBoxImg = elem instanceof HTMLImageElement ? elem : imageBox == null ? void 0 : imageBox.querySelector("img");
|
|
93265
|
+
if (imageBox && boxType === "image" && imageBoxImg) {
|
|
93266
|
+
const imgData = this.editor.getBoxData(imageBox);
|
|
93267
|
+
return !imgData.link;
|
|
93268
|
+
}
|
|
93269
|
+
const imageContainer = elem.closest(".image-container[data-src]");
|
|
93270
|
+
if (imageContainer instanceof HTMLElement) {
|
|
93271
|
+
const block = getParentBlock(imageContainer);
|
|
93272
|
+
if (block && isEmbedBlock(block) && getEmbedType(block) === "image") {
|
|
93273
|
+
const imageData = this.editor.getBlockData(block);
|
|
93274
|
+
if (imageData.link) {
|
|
93275
|
+
return false;
|
|
93276
|
+
}
|
|
93277
|
+
}
|
|
93278
|
+
return Boolean(elem instanceof HTMLImageElement ? elem : imageContainer.querySelector("img"));
|
|
93279
|
+
}
|
|
93280
|
+
return false;
|
|
93281
|
+
}
|
|
93067
93282
|
}
|
|
93068
93283
|
function createHistoryEditor(root2, doc2, options) {
|
|
93069
93284
|
var _a, _b, _c, _d, _e;
|
|
@@ -96857,7 +97072,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
96857
97072
|
}
|
|
96858
97073
|
}
|
|
96859
97074
|
});
|
|
96860
|
-
editor.version = "3.0.
|
|
97075
|
+
editor.version = "3.0.14-beta.1";
|
|
96861
97076
|
return editor;
|
|
96862
97077
|
}
|
|
96863
97078
|
function isDoc(doc2) {
|
|
@@ -96991,7 +97206,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
96991
97206
|
OnesEditorDropTarget.register(editor);
|
|
96992
97207
|
OnesEditorTocProvider.register(editor);
|
|
96993
97208
|
OnesEditorExclusiveBlock.register(editor);
|
|
96994
|
-
editor.version = "3.0.
|
|
97209
|
+
editor.version = "3.0.14-beta.1";
|
|
96995
97210
|
return editor;
|
|
96996
97211
|
}
|
|
96997
97212
|
async function showDocVersions(editor, options, serverUrl) {
|