vditor 4.0.2-alpha.1 → 4.0.2-alpha.10
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/README.md +75 -5
- package/dist/index.css +108 -29
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7328 -5406
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +18244 -0
- package/dist/js/graphviz/LICENSE.expat +21 -0
- package/dist/js/graphviz/LICENSE.graphviz +277 -0
- package/dist/js/graphviz/LICENSE.viz +21 -0
- package/dist/js/graphviz/README.md +10 -0
- package/dist/js/graphviz/viz.js +6 -330
- package/dist/js/i18n/de_DE.js +6 -0
- package/dist/js/i18n/en_US.js +6 -0
- package/dist/js/i18n/es_ES.js +6 -0
- package/dist/js/i18n/fr_FR.js +6 -0
- package/dist/js/i18n/ja_JP.js +6 -0
- package/dist/js/i18n/ko_KR.js +6 -0
- package/dist/js/i18n/pt_BR.js +6 -0
- package/dist/js/i18n/ru_RU.js +6 -0
- package/dist/js/i18n/sv_SE.js +6 -0
- package/dist/js/i18n/vi_VN.js +6 -0
- package/dist/js/i18n/zh_CN.js +6 -0
- package/dist/js/i18n/zh_TW.js +6 -0
- package/dist/js/icons/LICENSE-lucide.txt +46 -0
- package/dist/js/icons/ant.js +6 -0
- package/dist/js/icons/material.js +6 -0
- package/dist/js/lute/lute.min.js +21 -19
- package/dist/method.d.ts +3 -3
- package/dist/method.js +2125 -1847
- package/dist/method.min.js +1 -1
- package/dist/method.mjs +3243 -0
- package/dist/ts/constants.d.ts +2 -0
- package/dist/ts/find/index.d.ts +40 -0
- package/dist/ts/find/text.d.ts +4 -0
- package/dist/ts/hint/index.d.ts +4 -0
- package/dist/ts/ir/index.d.ts +1 -0
- package/dist/ts/markdown/codeCopy.d.ts +1 -0
- package/dist/ts/markdown/highlightRender.d.ts +1 -1
- package/dist/ts/markdown/mathRender.d.ts +24 -1
- package/dist/ts/markdown/outlineRender.d.ts +2 -1
- package/dist/ts/markdown/plantumlRender.d.ts +1 -1
- package/dist/ts/outline/index.d.ts +2 -0
- package/dist/ts/sv/index.d.ts +1 -0
- package/dist/ts/tip/index.d.ts +6 -1
- package/dist/ts/toolbar/Find.d.ts +5 -0
- package/dist/ts/undo/index.d.ts +1 -0
- package/dist/ts/upload/linkToImg.d.ts +1 -0
- package/dist/ts/util/addScript.d.ts +1 -2
- package/dist/ts/util/codeDOM.d.ts +2 -0
- package/dist/ts/util/codeSelection.d.ts +1 -0
- package/dist/ts/util/compatibility.d.ts +1 -1
- package/dist/ts/util/expandHTMLTags.d.ts +1 -0
- package/dist/ts/util/fixBrowserBehavior.d.ts +1 -0
- package/dist/ts/util/imageDrag.d.ts +1 -0
- package/dist/ts/util/notifyConfigChange.d.ts +1 -0
- package/dist/ts/util/pairedSymbols.d.ts +5 -0
- package/dist/ts/util/pasteIntoTable.d.ts +6 -0
- package/dist/ts/util/pasteLink.d.ts +1 -0
- package/dist/ts/util/processCode.d.ts +2 -0
- package/dist/ts/util/tableWheel.d.ts +1 -0
- package/dist/ts/util/taskNavigation.d.ts +1 -0
- package/dist/ts/wysiwyg/index.d.ts +1 -0
- package/dist/types/index.d.ts +84 -2
- package/package.json +3 -2
- package/src/assets/less/_find.less +84 -0
- package/src/assets/less/_hint.less +6 -0
- package/src/assets/less/_reset.less +29 -0
- package/src/assets/less/_tooltipped.less +2 -2
- package/src/assets/less/_wysiwyg.less +4 -0
- package/src/assets/less/index.less +3 -0
- package/src/index.ts +49 -6
- package/src/ts/constants.ts +4 -0
- package/src/ts/find/index.ts +310 -0
- package/src/ts/find/text.ts +208 -0
- package/src/ts/hint/index.ts +31 -8
- package/src/ts/ir/expandMarker.ts +3 -0
- package/src/ts/ir/index.ts +16 -3
- package/src/ts/ir/process.ts +7 -1
- package/src/ts/ir/processKeydown.ts +5 -0
- package/src/ts/markdown/chartRender.ts +28 -2
- package/src/ts/markdown/codeCopy.ts +41 -0
- package/src/ts/markdown/codeRender.ts +19 -8
- package/src/ts/markdown/graphvizRender.ts +51 -39
- package/src/ts/markdown/highlightRender.ts +25 -12
- package/src/ts/markdown/mathRender.ts +26 -38
- package/src/ts/markdown/mediaRender.ts +1 -1
- package/src/ts/markdown/mermaidRender.ts +4 -3
- package/src/ts/markdown/outlineRender.ts +44 -15
- package/src/ts/markdown/plantumlRender.ts +24 -5
- package/src/ts/markdown/previewRender.ts +5 -1
- package/src/ts/markdown/setLute.ts +10 -0
- package/src/ts/outline/index.ts +72 -0
- package/src/ts/preview/index.ts +1 -1
- package/src/ts/sv/index.ts +1 -0
- package/src/ts/sv/process.ts +7 -1
- package/src/ts/tip/index.ts +25 -9
- package/src/ts/toolbar/CodeTheme.ts +2 -0
- package/src/ts/toolbar/ContentTheme.ts +2 -0
- package/src/ts/toolbar/EditMode.ts +5 -0
- package/src/ts/toolbar/Find.ts +12 -0
- package/src/ts/toolbar/Headings.ts +4 -6
- package/src/ts/toolbar/Outline.ts +2 -0
- package/src/ts/toolbar/Record.ts +5 -0
- package/src/ts/toolbar/index.ts +5 -1
- package/src/ts/toolbar/setToolbar.ts +1 -1
- package/src/ts/ui/initUI.ts +10 -1
- package/src/ts/ui/setPreviewMode.ts +2 -0
- package/src/ts/undo/index.ts +41 -9
- package/src/ts/upload/index.ts +1 -1
- package/src/ts/upload/linkToImg.ts +91 -0
- package/src/ts/util/Options.ts +9 -0
- package/src/ts/util/addScript.ts +15 -24
- package/src/ts/util/codeDOM.ts +21 -0
- package/src/ts/util/codeSelection.ts +37 -0
- package/src/ts/util/compatibility.ts +2 -2
- package/src/ts/util/editorCommonEvent.ts +48 -5
- package/src/ts/util/expandHTMLTags.ts +36 -0
- package/src/ts/util/fixBrowserBehavior.ts +61 -61
- package/src/ts/util/imageDrag.ts +108 -0
- package/src/ts/util/notifyConfigChange.ts +16 -0
- package/src/ts/util/pairedSymbols.ts +109 -0
- package/src/ts/util/pasteIntoTable.ts +136 -0
- package/src/ts/util/pasteLink.ts +51 -0
- package/src/ts/util/processCode.ts +46 -9
- package/src/ts/util/selection.ts +11 -2
- package/src/ts/util/tableWheel.ts +31 -0
- package/src/ts/util/taskNavigation.ts +113 -0
- package/src/ts/util/toc.ts +9 -3
- package/src/ts/wysiwyg/afterRenderEvent.ts +7 -1
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +6 -5
- package/src/ts/wysiwyg/index.ts +20 -6
- package/src/ts/wysiwyg/processKeydown.ts +5 -0
- package/src/ts/wysiwyg/setHeading.ts +4 -0
- package/dist/js/graphviz/full.render.js +0 -90
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const setCodeHighlight = (code: Element, html: string) => {
|
|
2
|
+
const selection = getSelection();
|
|
3
|
+
const endpoints = [selection.anchorNode, selection.focusNode].map((node, index) => {
|
|
4
|
+
const offset = index === 0 ? selection.anchorOffset : selection.focusOffset;
|
|
5
|
+
if (!node || !code.contains(node)) {
|
|
6
|
+
return {node, offset, inside: false};
|
|
7
|
+
}
|
|
8
|
+
const range = document.createRange();
|
|
9
|
+
range.selectNodeContents(code);
|
|
10
|
+
range.setEnd(node, offset);
|
|
11
|
+
return {node, offset: range.toString().length, inside: true};
|
|
12
|
+
});
|
|
13
|
+
code.innerHTML = html;
|
|
14
|
+
if (!endpoints.some(endpoint => endpoint.inside)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 高亮会重建嵌套文本节点,按正文偏移恢复正向、反向及跨代码块选区。
|
|
19
|
+
endpoints.forEach(endpoint => {
|
|
20
|
+
if (!endpoint.inside) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const walker = document.createTreeWalker(code, NodeFilter.SHOW_TEXT);
|
|
24
|
+
let node = walker.nextNode();
|
|
25
|
+
while (node) {
|
|
26
|
+
if (endpoint.offset <= node.textContent.length) {
|
|
27
|
+
endpoint.node = node;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
endpoint.offset -= node.textContent.length;
|
|
31
|
+
node = walker.nextNode();
|
|
32
|
+
}
|
|
33
|
+
endpoint.node = code;
|
|
34
|
+
endpoint.offset = code.childNodes.length;
|
|
35
|
+
});
|
|
36
|
+
selection.setBaseAndExtent(endpoints[0].node, endpoints[0].offset, endpoints[1].node, endpoints[1].offset);
|
|
37
|
+
};
|
|
@@ -9,7 +9,7 @@ export const isFirefox = () => {
|
|
|
9
9
|
export const accessLocalStorage = () => {
|
|
10
10
|
try {
|
|
11
11
|
return typeof localStorage !== "undefined";
|
|
12
|
-
} catch
|
|
12
|
+
} catch {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
@@ -24,7 +24,7 @@ export const getEventName = () => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// 区别 mac 上的 ctrl 和 meta
|
|
27
|
-
export const isCtrl = (event: KeyboardEvent) => {
|
|
27
|
+
export const isCtrl = (event: Pick<KeyboardEvent, "ctrlKey" | "metaKey">) => {
|
|
28
28
|
if (navigator.platform.toUpperCase().indexOf("MAC") >= 0) {
|
|
29
29
|
// mac
|
|
30
30
|
if (event.metaKey && !event.ctrlKey) {
|
|
@@ -15,7 +15,10 @@ import {execAfterRender, paste} from "./fixBrowserBehavior";
|
|
|
15
15
|
import {getSelectText} from "./getSelectText";
|
|
16
16
|
import {hasClosestByAttribute, hasClosestByMatchTag} from "./hasClosest";
|
|
17
17
|
import {matchHotKey} from "./hotKey";
|
|
18
|
-
import {getCursorPosition, getEditorRange} from "./selection";
|
|
18
|
+
import {getCursorPosition, getEditorRange, setSelectionFocus} from "./selection";
|
|
19
|
+
import {deleteEmptyPair, wrapSelection} from "./pairedSymbols";
|
|
20
|
+
import {bindTaskNavigation} from "./taskNavigation";
|
|
21
|
+
import {bindImageDrag} from "./imageDrag";
|
|
19
22
|
|
|
20
23
|
export const focusEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
21
24
|
editorElement.addEventListener("focus", () => {
|
|
@@ -61,12 +64,16 @@ export const blurEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
|
61
64
|
export const dropEvent = (vditor: IVditor, editorElement: HTMLElement, pasteCode = (code: string) => {
|
|
62
65
|
document.execCommand("insertHTML", false, code);
|
|
63
66
|
}) => {
|
|
67
|
+
const dropImage = bindImageDrag(vditor, editorElement);
|
|
64
68
|
editorElement.addEventListener("dragstart", (event) => {
|
|
65
69
|
// 选中编辑器中的文字进行拖拽
|
|
66
70
|
event.dataTransfer.setData(Constants.DROP_EDITOR, Constants.DROP_EDITOR);
|
|
67
71
|
});
|
|
68
72
|
editorElement.addEventListener("drop",
|
|
69
|
-
(event:
|
|
73
|
+
(event: DragEvent & { target: HTMLElement }) => {
|
|
74
|
+
if (dropImage(event)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
70
77
|
if (event.dataTransfer.getData(Constants.DROP_EDITOR)) {
|
|
71
78
|
// 编辑器内选中文字拖拽
|
|
72
79
|
execAfterRender(vditor);
|
|
@@ -122,6 +129,33 @@ export const scrollCenter = (vditor: IVditor) => {
|
|
|
122
129
|
};
|
|
123
130
|
|
|
124
131
|
export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
132
|
+
bindTaskNavigation(vditor, editorElement);
|
|
133
|
+
editorElement.addEventListener("beforeinput", (event: InputEvent) => {
|
|
134
|
+
if (!event.cancelable || event.defaultPrevented || event.isComposing) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (event.inputType === "historyUndo" || event.inputType === "historyRedo") {
|
|
138
|
+
if (vditor[vditor.currentMode].composingLock) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
if (event.inputType === "historyUndo") {
|
|
143
|
+
vditor.undo.undo(vditor);
|
|
144
|
+
} else {
|
|
145
|
+
vditor.undo.redo(vditor);
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if ((event.inputType === "insertText" && wrapSelection(vditor, event.data)) ||
|
|
150
|
+
(["deleteContentBackward", "deleteContentForward"].includes(event.inputType) && deleteEmptyPair(vditor))) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
editorElement.addEventListener("keyup", (event: KeyboardEvent) => {
|
|
155
|
+
if (!event.isComposing && /^(Arrow(Up|Down|Left|Right)|Home|End|PageUp|PageDown)$/.test(event.key)) {
|
|
156
|
+
scrollCenter(vditor);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
125
159
|
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
|
126
160
|
if (!event.isComposing && vditor.options.keydown) {
|
|
127
161
|
vditor.options.keydown(event);
|
|
@@ -152,6 +186,15 @@ export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
|
152
186
|
}
|
|
153
187
|
}
|
|
154
188
|
|
|
189
|
+
if (!event.isComposing && !event.defaultPrevented && vditor.currentMode !== "sv" && matchHotKey("⌘A", event)) {
|
|
190
|
+
// 目录等不可编辑节点也属于正文,全选需覆盖整个编辑区。
|
|
191
|
+
const range = editorElement.ownerDocument.createRange();
|
|
192
|
+
range.selectNodeContents(editorElement);
|
|
193
|
+
setSelectionFocus(range);
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
155
198
|
if (vditor.options.ctrlEnter && matchHotKey("⌘Enter", event)) {
|
|
156
199
|
vditor.options.ctrlEnter(getMarkdown(vditor));
|
|
157
200
|
event.preventDefault();
|
|
@@ -159,14 +202,14 @@ export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
|
159
202
|
}
|
|
160
203
|
|
|
161
204
|
// undo
|
|
162
|
-
if (matchHotKey("⌘Z", event)
|
|
205
|
+
if (!event.isComposing && matchHotKey("⌘Z", event)) {
|
|
163
206
|
vditor.undo.undo(vditor);
|
|
164
207
|
event.preventDefault();
|
|
165
208
|
return;
|
|
166
209
|
}
|
|
167
210
|
|
|
168
211
|
// redo
|
|
169
|
-
if (matchHotKey("⌘Y", event)
|
|
212
|
+
if (!event.isComposing && matchHotKey("⌘Y", event)) {
|
|
170
213
|
vditor.undo.redo(vditor);
|
|
171
214
|
event.preventDefault();
|
|
172
215
|
return;
|
|
@@ -175,7 +218,7 @@ export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
|
|
|
175
218
|
// esc
|
|
176
219
|
if (event.key === "Escape") {
|
|
177
220
|
if (vditor.hint.element.style.display === "block") {
|
|
178
|
-
vditor.hint.
|
|
221
|
+
vditor.hint.hide();
|
|
179
222
|
} else if (vditor.options.esc && !event.isComposing) {
|
|
180
223
|
vditor.options.esc(getMarkdown(vditor));
|
|
181
224
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const voidTags = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta",
|
|
2
|
+
"param", "source", "track", "wbr"]);
|
|
3
|
+
|
|
4
|
+
export const expandHTMLTags = (root: HTMLElement, range: Range, className: string) => {
|
|
5
|
+
const stacks = new Map<Element, Array<{name: string; element: Element}>>();
|
|
6
|
+
root.querySelectorAll('[data-type="html-inline"]').forEach(element => {
|
|
7
|
+
const tag = element.textContent.replace(/[\u200b\ufeff]/g, "").trim();
|
|
8
|
+
const match = /^<(\/?)([a-z][\w:-]*)(?:\s[^]*)?>$/i.exec(tag);
|
|
9
|
+
if (!match || /\/\s*>$/.test(tag)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const name = match[2].toLowerCase();
|
|
13
|
+
if (voidTags.has(name)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const block = element.closest('[data-block="0"]') || root;
|
|
17
|
+
const stack = stacks.get(block) || [];
|
|
18
|
+
stacks.set(block, stack);
|
|
19
|
+
if (!match[1]) {
|
|
20
|
+
stack.push({name, element});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (stack[stack.length - 1]?.name !== name) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const opening = stack.pop().element;
|
|
27
|
+
const contents = document.createRange();
|
|
28
|
+
contents.setStartBefore(opening);
|
|
29
|
+
contents.setEndAfter(element);
|
|
30
|
+
if (contents.isPointInRange(range.startContainer, range.startOffset) &&
|
|
31
|
+
contents.isPointInRange(range.endContainer, range.endOffset)) {
|
|
32
|
+
opening.classList.add(className);
|
|
33
|
+
element.classList.add(className);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -3,11 +3,12 @@ import {input as IRInput} from "../ir/input";
|
|
|
3
3
|
import {processAfterRender} from "../ir/process";
|
|
4
4
|
import {processAfterRender as processSVAfterRender, processPaste} from "../sv/process";
|
|
5
5
|
import {uploadFiles} from "../upload/index";
|
|
6
|
-
import {
|
|
6
|
+
import {uploadLinkToImg} from "../upload/linkToImg";
|
|
7
7
|
import {afterRenderEvent} from "../wysiwyg/afterRenderEvent";
|
|
8
8
|
import {input} from "../wysiwyg/input";
|
|
9
9
|
import {isCtrl, isFirefox} from "./compatibility";
|
|
10
10
|
import {scrollCenter} from "./editorCommonEvent";
|
|
11
|
+
import {parseMarkdownTableRows, pasteIntoTable} from "./pasteIntoTable";
|
|
11
12
|
import {
|
|
12
13
|
getTopList,
|
|
13
14
|
hasClosestBlock,
|
|
@@ -16,9 +17,12 @@ import {
|
|
|
16
17
|
hasClosestByMatchTag,
|
|
17
18
|
} from "./hasClosest";
|
|
18
19
|
import {getLastNode} from "./hasClosest";
|
|
20
|
+
import {hasClosestByHeadings} from "./hasClosestByHeadings";
|
|
19
21
|
import {highlightToolbar} from "./highlightToolbar";
|
|
20
22
|
import {matchHotKey} from "./hotKey";
|
|
21
|
-
import {processCodeRender, processPasteCode} from "./processCode";
|
|
23
|
+
import {isPlainTextPaste, processCodeRender, processPasteCode} from "./processCode";
|
|
24
|
+
import {getPastedLink} from "./pasteLink";
|
|
25
|
+
import {renderToc} from "./toc";
|
|
22
26
|
import {
|
|
23
27
|
getEditorRange,
|
|
24
28
|
getSelectPosition,
|
|
@@ -40,6 +44,36 @@ export const fixGSKeyBackspace = (event: KeyboardEvent, vditor: IVditor, startCo
|
|
|
40
44
|
return true;
|
|
41
45
|
};
|
|
42
46
|
|
|
47
|
+
export const backspaceEmptyHeading = (event: KeyboardEvent, vditor: IVditor, range: Range) => {
|
|
48
|
+
if (event.key !== "Backspace" || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey ||
|
|
49
|
+
event.defaultPrevented || !range.collapsed) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const heading = hasClosestByHeadings(range.startContainer);
|
|
53
|
+
if (!heading) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const firstElement = heading.firstElementChild;
|
|
57
|
+
const marker = firstElement?.getAttribute("data-type") === "heading-marker" ? firstElement : null;
|
|
58
|
+
const empty = Array.from(heading.childNodes).every((node) => node === marker ||
|
|
59
|
+
node.nodeName === "BR" || node.nodeName === "WBR" ||
|
|
60
|
+
(node.nodeType === Node.TEXT_NODE && node.textContent.split(Constants.ZWSP).join("").trim() === ""));
|
|
61
|
+
if (!empty) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const paragraph = heading.ownerDocument.createElement("p");
|
|
66
|
+
paragraph.setAttribute("data-block", "0");
|
|
67
|
+
paragraph.innerHTML = `${Constants.ZWSP}<wbr>\n`;
|
|
68
|
+
heading.replaceWith(paragraph);
|
|
69
|
+
setRangeByWbr(paragraph, range);
|
|
70
|
+
renderToc(vditor);
|
|
71
|
+
highlightToolbar(vditor);
|
|
72
|
+
execAfterRender(vditor);
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
|
|
43
77
|
// https://github.com/Vanessa219/vditor/issues/361 代码块后输入中文
|
|
44
78
|
export const fixCJKPosition = (range: Range, vditor: IVditor, event: KeyboardEvent) => {
|
|
45
79
|
if (event.key === "Enter" || event.key === "Tab" || event.key === "Backspace" || event.key.indexOf("Arrow") > -1
|
|
@@ -1476,6 +1510,7 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1476
1510
|
}
|
|
1477
1511
|
}
|
|
1478
1512
|
const renderers: {
|
|
1513
|
+
HTML2Md?: ILuteRender,
|
|
1479
1514
|
HTML2VditorDOM?: ILuteRender,
|
|
1480
1515
|
HTML2VditorIRDOM?: ILuteRender,
|
|
1481
1516
|
Md2VditorDOM?: ILuteRender,
|
|
@@ -1498,62 +1533,15 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1498
1533
|
|
|
1499
1534
|
const src = node.TokensStr();
|
|
1500
1535
|
if (node.__internal_object__.Parent.Type === 34 && src && src.indexOf("file://") === -1 &&
|
|
1501
|
-
vditor.options.upload.linkToImgUrl) {
|
|
1502
|
-
|
|
1503
|
-
xhr.open("POST", vditor.options.upload.linkToImgUrl);
|
|
1504
|
-
if (vditor.options.upload.token) {
|
|
1505
|
-
xhr.setRequestHeader("X-Upload-Token", vditor.options.upload.token);
|
|
1506
|
-
}
|
|
1507
|
-
if (vditor.options.upload.withCredentials) {
|
|
1508
|
-
xhr.withCredentials = true;
|
|
1509
|
-
}
|
|
1510
|
-
setHeaders(vditor, xhr);
|
|
1511
|
-
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|
1512
|
-
xhr.onreadystatechange = () => {
|
|
1513
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
1514
|
-
if (xhr.status === 200) {
|
|
1515
|
-
let responseText = xhr.responseText;
|
|
1516
|
-
if (vditor.options.upload.linkToImgFormat) {
|
|
1517
|
-
responseText = vditor.options.upload.linkToImgFormat(xhr.responseText);
|
|
1518
|
-
}
|
|
1519
|
-
const responseJSON = JSON.parse(responseText);
|
|
1520
|
-
if (responseJSON.code !== 0) {
|
|
1521
|
-
vditor.tip.show(responseJSON.msg);
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
const original = responseJSON.data.originalURL;
|
|
1525
|
-
if (vditor.currentMode === "sv") {
|
|
1526
|
-
const selectionStart = vditor.sv.element.selectionStart;
|
|
1527
|
-
const selectionEnd = vditor.sv.element.selectionEnd;
|
|
1528
|
-
vditor.sv.element.value = vditor.sv.element.value.split(original)
|
|
1529
|
-
.join(responseJSON.data.url);
|
|
1530
|
-
vditor.sv.element.setSelectionRange(selectionStart, selectionEnd);
|
|
1531
|
-
} else {
|
|
1532
|
-
const imgElement: HTMLImageElement =
|
|
1533
|
-
vditor[vditor.currentMode].element.querySelector(`img[src="${original}"]`);
|
|
1534
|
-
imgElement.src = responseJSON.data.url;
|
|
1535
|
-
if (vditor.currentMode === "ir") {
|
|
1536
|
-
imgElement.previousElementSibling.previousElementSibling.innerHTML =
|
|
1537
|
-
responseJSON.data.url;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
execAfterRender(vditor);
|
|
1541
|
-
} else {
|
|
1542
|
-
vditor.tip.show(xhr.responseText);
|
|
1543
|
-
}
|
|
1544
|
-
if (vditor.options.upload.linkToImgCallback) {
|
|
1545
|
-
vditor.options.upload.linkToImgCallback(xhr.responseText);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
xhr.send(JSON.stringify({url: src}));
|
|
1536
|
+
(vditor.options.upload.linkToImgUrl || vditor.options.upload.linkToImgHandler)) {
|
|
1537
|
+
uploadLinkToImg(vditor, src, () => execAfterRender(vditor));
|
|
1550
1538
|
}
|
|
1551
1539
|
if (vditor.currentMode === "ir") {
|
|
1552
|
-
return [`<span class="vditor-ir__marker vditor-ir__marker--link">${Lute.EscapeHTMLStr(src)}</span>`, Lute.WalkContinue];
|
|
1540
|
+
return [`<span class="vditor-ir__marker vditor-ir__marker--link">${Lute.EscapeHTMLStr(src.replace(/ /g, "%20"))}</span>`, Lute.WalkContinue];
|
|
1553
1541
|
} else if (vditor.currentMode === "wysiwyg") {
|
|
1554
1542
|
return ["", Lute.WalkContinue];
|
|
1555
1543
|
} else {
|
|
1556
|
-
return [
|
|
1544
|
+
return [src, Lute.WalkContinue];
|
|
1557
1545
|
}
|
|
1558
1546
|
};
|
|
1559
1547
|
|
|
@@ -1571,6 +1559,10 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1571
1559
|
textHTML = doc.body.innerHTML;
|
|
1572
1560
|
}
|
|
1573
1561
|
textHTML = Lute.Sanitize(textHTML);
|
|
1562
|
+
const transfer = "clipboardData" in event ? event.clipboardData : event.dataTransfer;
|
|
1563
|
+
if (textPlain && isPlainTextPaste(textHTML, transfer.getData("vscode-editor-data"))) {
|
|
1564
|
+
textHTML = "";
|
|
1565
|
+
}
|
|
1574
1566
|
vditor.wysiwyg.getComments(vditor);
|
|
1575
1567
|
|
|
1576
1568
|
// process code
|
|
@@ -1582,7 +1574,7 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1582
1574
|
const cellElement = vditor.currentMode === "wysiwyg" &&
|
|
1583
1575
|
(hasClosestByMatchTag(getEditorRange(vditor).startContainer, "TD") ||
|
|
1584
1576
|
hasClosestByMatchTag(getEditorRange(vditor).startContainer, "TH"));
|
|
1585
|
-
if (cellElement && /[\r\n]/.test(textPlain)) {
|
|
1577
|
+
if (cellElement && !textHTML && /[\r\n]/.test(textPlain) && !parseMarkdownTableRows(textPlain)) {
|
|
1586
1578
|
// 表格单元格内的换行使用 br 表示,避免自旋时解析为新的表格行
|
|
1587
1579
|
insertHTML(Lute.EscapeHTMLStr(textPlain).replace(/\r\n|\r|\n/g, "<br>"), vditor);
|
|
1588
1580
|
} else if (codeElement) {
|
|
@@ -1622,7 +1614,9 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1622
1614
|
tempElement.querySelectorAll(".vditor-copy").forEach((e) => {
|
|
1623
1615
|
e.remove();
|
|
1624
1616
|
});
|
|
1625
|
-
if (vditor.
|
|
1617
|
+
if (pasteIntoTable(vditor, tempElement.innerHTML)) {
|
|
1618
|
+
// 单元格填充与普通粘贴共用后续规范化和撤销记录。
|
|
1619
|
+
} else if (vditor.currentMode === "ir") {
|
|
1626
1620
|
renderers.HTML2VditorIRDOM = {renderLinkDest};
|
|
1627
1621
|
vditor.lute.SetJSRenderers({renderers});
|
|
1628
1622
|
insertHTML(vditor.lute.HTML2VditorIRDOM(tempElement.innerHTML), vditor);
|
|
@@ -1631,6 +1625,8 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1631
1625
|
vditor.lute.SetJSRenderers({renderers});
|
|
1632
1626
|
insertHTML(vditor.lute.HTML2VditorDOM(tempElement.innerHTML), vditor);
|
|
1633
1627
|
} else {
|
|
1628
|
+
renderers.HTML2Md = {renderLinkDest};
|
|
1629
|
+
vditor.lute.SetJSRenderers({renderers});
|
|
1634
1630
|
processPaste(vditor, vditor.lute.HTML2Md(tempElement.innerHTML).trimRight());
|
|
1635
1631
|
}
|
|
1636
1632
|
vditor.outline.render(vditor);
|
|
@@ -1666,12 +1662,10 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1666
1662
|
}
|
|
1667
1663
|
}
|
|
1668
1664
|
} else if (textPlain.trim() !== "" && files.length === 0) {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}
|
|
1674
|
-
if (vditor.currentMode === "ir") {
|
|
1665
|
+
textPlain = getPastedLink(vditor, textPlain);
|
|
1666
|
+
if (pasteIntoTable(vditor, "", textPlain)) {
|
|
1667
|
+
// 单元格填充与普通粘贴共用后续规范化和撤销记录。
|
|
1668
|
+
} else if (vditor.currentMode === "ir") {
|
|
1675
1669
|
renderers.Md2VditorIRDOM = {renderLinkDest};
|
|
1676
1670
|
vditor.lute.SetJSRenderers({renderers});
|
|
1677
1671
|
insertHTML(Lute.Sanitize(vditor.lute.Md2VditorIRDOM(textPlain)), vditor);
|
|
@@ -1680,6 +1674,12 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
|
|
|
1680
1674
|
vditor.lute.SetJSRenderers({renderers});
|
|
1681
1675
|
insertHTML(Lute.Sanitize(vditor.lute.Md2VditorDOM(textPlain)), vditor);
|
|
1682
1676
|
} else {
|
|
1677
|
+
if (vditor.options.upload.linkToImgUrl || vditor.options.upload.linkToImgHandler ||
|
|
1678
|
+
vditor.options.upload.renderLinkDest) {
|
|
1679
|
+
renderers.Md2VditorDOM = {renderLinkDest};
|
|
1680
|
+
vditor.lute.SetJSRenderers({renderers});
|
|
1681
|
+
vditor.lute.Md2VditorDOM(textPlain);
|
|
1682
|
+
}
|
|
1683
1683
|
processPaste(vditor, textPlain);
|
|
1684
1684
|
}
|
|
1685
1685
|
vditor.outline.render(vditor);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {execAfterRender} from "./fixBrowserBehavior";
|
|
2
|
+
import {setSelectionFocus} from "./selection";
|
|
3
|
+
|
|
4
|
+
const getImageNode = (image: HTMLImageElement, mode: string): HTMLElement => {
|
|
5
|
+
if (mode === "ir") {
|
|
6
|
+
const node = image.closest<HTMLElement>("[data-type='img']");
|
|
7
|
+
if (!node) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const link = node.parentElement;
|
|
11
|
+
if (link.getAttribute("data-type") === "a" && Array.from(link.childNodes).every(child =>
|
|
12
|
+
child === node || (child.nodeType === Node.TEXT_NODE && !child.textContent.trim()) ||
|
|
13
|
+
(child instanceof HTMLElement && child.classList.contains("vditor-ir__marker")))) {
|
|
14
|
+
return link;
|
|
15
|
+
}
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
const link = image.parentElement;
|
|
19
|
+
return link.tagName === "A" && link.childNodes.length === 1 ? link : image;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const bindImageDrag = (vditor: IVditor, editor: HTMLElement) => {
|
|
23
|
+
let dragged: HTMLElement;
|
|
24
|
+
const editable = () => vditor.currentMode !== "sv" && vditor[vditor.currentMode].element === editor &&
|
|
25
|
+
editor.getAttribute("contenteditable") === "true";
|
|
26
|
+
const copy = (event: DragEvent) => event.ctrlKey || event.altKey || event.metaKey;
|
|
27
|
+
|
|
28
|
+
editor.addEventListener("dragstart", (event: DragEvent) => {
|
|
29
|
+
dragged = undefined;
|
|
30
|
+
if (!(event.target instanceof HTMLImageElement)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!editable() || event.target.closest("[contenteditable='false'], .vditor-ir__preview, .vditor-wysiwyg__preview")) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
dragged = getImageNode(event.target, vditor.currentMode);
|
|
38
|
+
if (dragged) {
|
|
39
|
+
event.dataTransfer.effectAllowed = "copyMove";
|
|
40
|
+
} else {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
editor.addEventListener("dragend", () => { dragged = undefined; });
|
|
45
|
+
editor.addEventListener("dragover", (event: DragEvent) => {
|
|
46
|
+
if (dragged && editable()) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
event.dataTransfer.dropEffect = copy(event) ? "copy" : "move";
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return (event: DragEvent) => {
|
|
53
|
+
if (!dragged) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const source = dragged;
|
|
57
|
+
dragged = undefined;
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
if (!editable() || !editor.contains(source)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
// 浏览器命中位置只用于定位,图片和 Markdown 标记作为同一个节点移动。
|
|
63
|
+
const doc = editor.ownerDocument as Document & {
|
|
64
|
+
caretPositionFromPoint?: (x: number, y: number) => {offsetNode: Node, offset: number} | null;
|
|
65
|
+
};
|
|
66
|
+
let range: Range;
|
|
67
|
+
if (doc.caretRangeFromPoint) {
|
|
68
|
+
range = doc.caretRangeFromPoint(event.clientX, event.clientY);
|
|
69
|
+
} else {
|
|
70
|
+
const position = doc.caretPositionFromPoint?.(event.clientX, event.clientY);
|
|
71
|
+
if (position) {
|
|
72
|
+
range = doc.createRange();
|
|
73
|
+
range.setStart(position.offsetNode, position.offset);
|
|
74
|
+
range.collapse(true);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!range || !editor.contains(range.startContainer) || source.contains(range.startContainer)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const target = range.startContainer instanceof Element ? range.startContainer : range.startContainer.parentElement;
|
|
81
|
+
if (target.closest("[contenteditable='false'], .vditor-ir__marker, .vditor-ir__preview, " +
|
|
82
|
+
".vditor-wysiwyg__block, .vditor-wysiwyg__preview, code, [data-type='code-block'], [data-type='img'], " +
|
|
83
|
+
"[data-type='math-inline'], [data-type='math-block'], [data-type='html-inline'], [data-type='html-block'], " +
|
|
84
|
+
"[data-type='link-ref-defs-block']")) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const sourceRange = doc.createRange();
|
|
89
|
+
sourceRange.selectNode(source);
|
|
90
|
+
setSelectionFocus(sourceRange);
|
|
91
|
+
vditor.undo.addToUndoStack(vditor);
|
|
92
|
+
const node = copy(event) ? source.cloneNode(true) : source;
|
|
93
|
+
if (range.startContainer === editor) {
|
|
94
|
+
const paragraph = doc.createElement("p");
|
|
95
|
+
paragraph.setAttribute("data-block", "0");
|
|
96
|
+
range.insertNode(paragraph);
|
|
97
|
+
range.selectNodeContents(paragraph);
|
|
98
|
+
}
|
|
99
|
+
range.insertNode(node);
|
|
100
|
+
range.setStartAfter(node);
|
|
101
|
+
range.collapse(true);
|
|
102
|
+
setSelectionFocus(range);
|
|
103
|
+
// 即使撤销延迟未到,也为一次拖拽保留完整的前后状态。
|
|
104
|
+
execAfterRender(vditor);
|
|
105
|
+
vditor.undo.addToUndoStack(vditor);
|
|
106
|
+
return true;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const notifyConfigChange = (vditor: IVditor) => {
|
|
2
|
+
vditor.options.configChange?.({
|
|
3
|
+
mode: vditor.currentMode,
|
|
4
|
+
theme: vditor.options.theme,
|
|
5
|
+
preview: {
|
|
6
|
+
mode: vditor.options.preview.mode,
|
|
7
|
+
theme: {current: vditor.options.preview.theme.current},
|
|
8
|
+
hljs: {style: vditor.options.preview.hljs.style},
|
|
9
|
+
},
|
|
10
|
+
outline: {
|
|
11
|
+
enable: vditor.options.outline.enable,
|
|
12
|
+
position: vditor.options.outline.position,
|
|
13
|
+
...(vditor.options.outline.width === undefined ? {} : {width: vditor.options.outline.width}),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {input as irInput} from "../ir/input";
|
|
2
|
+
import {processAfterRender} from "../sv/process";
|
|
3
|
+
import {input} from "../wysiwyg/input";
|
|
4
|
+
import {getEditorRange, setSelectionFocus} from "./selection";
|
|
5
|
+
|
|
6
|
+
export const pairedSymbols: {[key: string]: string} = {
|
|
7
|
+
"\"": "\"", "'": "'", "`": "`", "(": ")", "[": "]", "{": "}",
|
|
8
|
+
"“": "”", "‘": "’", "(": ")", "【": "】", "「": "」", "『": "』", "《": "》",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const wrapSelection = (vditor: IVditor, opening: string): boolean => {
|
|
12
|
+
if (!opening || opening.length !== 1) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const closing = pairedSymbols[opening];
|
|
16
|
+
if (!closing) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const editor = vditor[vditor.currentMode].element;
|
|
20
|
+
if (vditor.currentMode === "sv") {
|
|
21
|
+
const textarea = vditor.sv.element;
|
|
22
|
+
if (textarea.disabled || textarea.selectionStart === textarea.selectionEnd) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const start = textarea.selectionStart;
|
|
26
|
+
const end = textarea.selectionEnd;
|
|
27
|
+
textarea.setRangeText(opening + textarea.value.substring(start, end) + closing, start, end, "end");
|
|
28
|
+
processAfterRender(vditor);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const range = getEditorRange(vditor);
|
|
32
|
+
if (editor.getAttribute("contenteditable") !== "true" || range.toString() === "" ||
|
|
33
|
+
!editor.contains(range.startContainer) || !editor.contains(range.endContainer)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const contents = range.extractContents();
|
|
37
|
+
const fragment = document.createDocumentFragment();
|
|
38
|
+
const end = document.createTextNode(closing);
|
|
39
|
+
fragment.append(document.createTextNode(opening), contents, end);
|
|
40
|
+
range.insertNode(fragment);
|
|
41
|
+
range.setStartAfter(end);
|
|
42
|
+
range.collapse(true);
|
|
43
|
+
setSelectionFocus(range);
|
|
44
|
+
if (vditor.currentMode === "ir") {
|
|
45
|
+
irInput(vditor, range, true);
|
|
46
|
+
} else {
|
|
47
|
+
input(vditor, range);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const deleteEmptyPair = (vditor: IVditor): boolean => {
|
|
53
|
+
if (vditor.currentMode === "sv") {
|
|
54
|
+
const textarea = vditor.sv.element;
|
|
55
|
+
const offset = textarea.selectionStart;
|
|
56
|
+
if (textarea.disabled || offset !== textarea.selectionEnd || !isPair(textarea.value[offset - 1], textarea.value[offset])) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const depth = pairDepth(textarea.value.substring(0, offset), textarea.value.substring(offset));
|
|
60
|
+
textarea.setRangeText("", offset - depth, offset + depth, "end");
|
|
61
|
+
processAfterRender(vditor);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const editor = vditor[vditor.currentMode].element;
|
|
65
|
+
const range = getEditorRange(vditor).cloneRange();
|
|
66
|
+
if (editor.getAttribute("contenteditable") !== "true" || range.toString() !== "" || !editor.contains(range.startContainer)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
range.collapse(true);
|
|
70
|
+
const node = range.startContainer;
|
|
71
|
+
const offset = range.startOffset;
|
|
72
|
+
const isText = node.nodeType === Node.TEXT_NODE;
|
|
73
|
+
const left = isText ? (offset ? node : node.previousSibling) : node.childNodes[offset - 1];
|
|
74
|
+
const right = isText ? (offset < node.textContent.length ? node : node.nextSibling) : node.childNodes[offset];
|
|
75
|
+
if (left?.nodeType !== Node.TEXT_NODE || right?.nodeType !== Node.TEXT_NODE || left.parentNode !== right.parentNode) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const start = left === node ? offset - 1 : left.textContent.length - 1;
|
|
79
|
+
const end = right === node ? offset : 0;
|
|
80
|
+
if (!isPair(left.textContent[start], right.textContent[end])) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const depth = pairDepth(left.textContent.substring(0, start + 1), right.textContent.substring(end));
|
|
84
|
+
range.setStart(left, start - depth + 1);
|
|
85
|
+
range.setEnd(right, end + depth);
|
|
86
|
+
range.deleteContents();
|
|
87
|
+
setSelectionFocus(range);
|
|
88
|
+
if (vditor.currentMode === "ir") {
|
|
89
|
+
irInput(vditor, range, true);
|
|
90
|
+
} else {
|
|
91
|
+
input(vditor, range);
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const isPair = (opening: string, closing: string) => !!opening && !!closing &&
|
|
97
|
+
(pairedSymbols[opening] === closing || (["*", "~", "$"].includes(opening) && opening === closing));
|
|
98
|
+
|
|
99
|
+
const pairDepth = (left: string, right: string) => {
|
|
100
|
+
const marker = left[left.length - 1];
|
|
101
|
+
if (!["*", "~", "$", "`"].includes(marker)) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
let before = 0;
|
|
105
|
+
let after = 0;
|
|
106
|
+
while (left[left.length - before - 1] === marker) { before++; }
|
|
107
|
+
while (right[after] === marker) { after++; }
|
|
108
|
+
return Math.min(before, after);
|
|
109
|
+
};
|