vditor 3.8.5 → 3.8.9
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 +48 -45
- package/dist/index.css +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.min.js +722 -858
- package/dist/js/i18n/en_US.js +85 -0
- package/dist/js/i18n/ja_JP.js +85 -0
- package/dist/js/i18n/ko_KR.js +85 -0
- package/dist/js/i18n/ru_RU.js +85 -0
- package/dist/js/i18n/zh_CN.js +85 -0
- package/dist/js/i18n/zh_TW.js +85 -0
- package/dist/js/lute/lute.min.js +31 -28
- package/dist/method.d.ts +4 -1
- package/dist/method.min.js +157 -543
- package/dist/ts/markdown/adapterRender.d.ts +33 -0
- package/dist/ts/markdown/codeRender.d.ts +1 -2
- package/dist/ts/ui/initUI.d.ts +1 -0
- package/dist/ts/wysiwyg/index.d.ts +2 -0
- package/dist/types/index.d.ts +773 -0
- package/package.json +4 -4
- package/src/assets/.DS_Store +0 -0
- package/src/assets/scss/_content.scss +4 -0
- package/src/assets/scss/_reset.scss +11 -0
- package/src/index.ts +156 -97
- package/src/method.ts +6 -2
- package/src/ts/.DS_Store +0 -0
- package/src/ts/export/index.ts +7 -5
- package/src/ts/hint/index.ts +20 -11
- package/src/ts/markdown/abcRender.ts +3 -2
- package/src/ts/markdown/adapterRender.ts +33 -0
- package/src/ts/markdown/chartRender.ts +3 -2
- package/src/ts/markdown/codeRender.ts +5 -6
- package/src/ts/markdown/flowchartRender.ts +3 -2
- package/src/ts/markdown/graphvizRender.ts +13 -11
- package/src/ts/markdown/mathRender.ts +5 -4
- package/src/ts/markdown/mermaidRender.ts +4 -2
- package/src/ts/markdown/mindmapRender.ts +3 -2
- package/src/ts/markdown/plantumlRender.ts +3 -2
- package/src/ts/markdown/previewRender.ts +26 -4
- package/src/ts/preview/image.ts +2 -4
- package/src/ts/preview/index.ts +2 -5
- package/src/ts/toolbar/EditMode.ts +3 -4
- package/src/ts/toolbar/Headings.ts +6 -6
- package/src/ts/toolbar/Info.ts +1 -1
- package/src/ts/toolbar/MenuItem.ts +1 -3
- package/src/ts/toolbar/Record.ts +3 -4
- package/src/ts/ui/initUI.ts +19 -5
- package/src/ts/upload/index.ts +11 -11
- package/src/ts/util/Options.ts +255 -196
- package/src/ts/util/editorCommonEvent.ts +2 -2
- package/src/ts/util/fixBrowserBehavior.ts +10 -6
- package/src/ts/util/processCode.ts +1 -1
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +298 -138
- package/src/ts/wysiwyg/index.ts +9 -4
- package/CHANGELOG.md +0 -1053
- package/dist/images/.DS_Store +0 -0
- package/dist/js/.DS_Store +0 -0
- package/dist/js/lute/.DS_Store +0 -0
- package/dist/js/mathjax/.DS_Store +0 -0
- package/dist/ts/i18n/index.d.ts +0 -2
- package/src/ts/i18n/index.ts +0 -476
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {Constants} from "../constants";
|
|
2
|
-
import {i18n} from "../i18n";
|
|
3
2
|
import {disableToolbar} from "../toolbar/setToolbar";
|
|
4
3
|
import {enableToolbar} from "../toolbar/setToolbar";
|
|
5
4
|
import {removeCurrentToolbar} from "../toolbar/setToolbar";
|
|
@@ -19,16 +18,26 @@ import {
|
|
|
19
18
|
hasClosestByClassName,
|
|
20
19
|
hasClosestByMatchTag,
|
|
21
20
|
} from "../util/hasClosest";
|
|
22
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
hasClosestByHeadings,
|
|
23
|
+
hasClosestByTag,
|
|
24
|
+
} from "../util/hasClosestByHeadings";
|
|
23
25
|
import {processCodeRender} from "../util/processCode";
|
|
24
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
getEditorRange,
|
|
28
|
+
selectIsEditor,
|
|
29
|
+
setRangeByWbr,
|
|
30
|
+
setSelectionFocus,
|
|
31
|
+
} from "../util/selection";
|
|
25
32
|
import {afterRenderEvent} from "./afterRenderEvent";
|
|
26
33
|
import {removeBlockElement} from "./processKeydown";
|
|
27
34
|
|
|
28
35
|
export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
29
36
|
clearTimeout(vditor.wysiwyg.hlToolbarTimeoutId);
|
|
30
37
|
vditor.wysiwyg.hlToolbarTimeoutId = window.setTimeout(() => {
|
|
31
|
-
if (
|
|
38
|
+
if (
|
|
39
|
+
vditor.wysiwyg.element.getAttribute("contenteditable") === "false"
|
|
40
|
+
) {
|
|
32
41
|
return;
|
|
33
42
|
}
|
|
34
43
|
if (!selectIsEditor(vditor.wysiwyg.element)) {
|
|
@@ -43,8 +52,11 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
43
52
|
if (range.startContainer.nodeType === 3) {
|
|
44
53
|
typeElement = range.startContainer.parentElement;
|
|
45
54
|
} else {
|
|
46
|
-
typeElement = typeElement.childNodes[
|
|
47
|
-
typeElement.childNodes.length
|
|
55
|
+
typeElement = typeElement.childNodes[
|
|
56
|
+
range.startOffset >= typeElement.childNodes.length
|
|
57
|
+
? typeElement.childNodes.length - 1
|
|
58
|
+
: range.startOffset
|
|
59
|
+
] as HTMLElement;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
const footnotesElement = hasClosestByAttribute(typeElement, "data-type", "footnotes-block");
|
|
@@ -74,27 +86,40 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
74
86
|
setCurrentToolbar(vditor.toolbar.elements, ["quote"]);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
if (
|
|
89
|
+
if (
|
|
90
|
+
hasClosestByMatchTag(typeElement, "B") ||
|
|
91
|
+
hasClosestByMatchTag(typeElement, "STRONG")
|
|
92
|
+
) {
|
|
78
93
|
setCurrentToolbar(vditor.toolbar.elements, ["bold"]);
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
if (
|
|
96
|
+
if (
|
|
97
|
+
hasClosestByMatchTag(typeElement, "I") ||
|
|
98
|
+
hasClosestByMatchTag(typeElement, "EM")
|
|
99
|
+
) {
|
|
82
100
|
setCurrentToolbar(vditor.toolbar.elements, ["italic"]);
|
|
83
101
|
}
|
|
84
102
|
|
|
85
|
-
if (
|
|
103
|
+
if (
|
|
104
|
+
hasClosestByMatchTag(typeElement, "STRIKE") ||
|
|
105
|
+
hasClosestByMatchTag(typeElement, "S")
|
|
106
|
+
) {
|
|
86
107
|
setCurrentToolbar(vditor.toolbar.elements, ["strike"]);
|
|
87
108
|
}
|
|
88
109
|
|
|
89
110
|
// comments
|
|
90
|
-
vditor.wysiwyg.element
|
|
91
|
-
|
|
92
|
-
|
|
111
|
+
vditor.wysiwyg.element
|
|
112
|
+
.querySelectorAll(".vditor-comment--focus")
|
|
113
|
+
.forEach((item) => {
|
|
114
|
+
item.classList.remove("vditor-comment--focus");
|
|
115
|
+
});
|
|
93
116
|
const commentElement = hasClosestByClassName(typeElement, "vditor-comment");
|
|
94
117
|
if (commentElement) {
|
|
95
118
|
let ids = commentElement.getAttribute("data-cmtids").split(" ");
|
|
96
119
|
if (ids.length > 1 && commentElement.nextSibling.isSameNode(commentElement.nextElementSibling)) {
|
|
97
|
-
const nextIds = commentElement.nextElementSibling
|
|
120
|
+
const nextIds = commentElement.nextElementSibling
|
|
121
|
+
.getAttribute("data-cmtids")
|
|
122
|
+
.split(" ");
|
|
98
123
|
ids.find((id) => {
|
|
99
124
|
if (nextIds.includes(id)) {
|
|
100
125
|
ids = [id];
|
|
@@ -102,11 +127,13 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
102
127
|
}
|
|
103
128
|
});
|
|
104
129
|
}
|
|
105
|
-
vditor.wysiwyg.element
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
130
|
+
vditor.wysiwyg.element
|
|
131
|
+
.querySelectorAll(".vditor-comment")
|
|
132
|
+
.forEach((item) => {
|
|
133
|
+
if (item.getAttribute("data-cmtids").indexOf(ids[0]) > -1) {
|
|
134
|
+
item.classList.add("vditor-comment--focus");
|
|
135
|
+
}
|
|
136
|
+
});
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
const aElement = hasClosestByMatchTag(typeElement, "A");
|
|
@@ -117,12 +144,41 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
117
144
|
const headingElement = hasClosestByHeadings(typeElement) as HTMLElement;
|
|
118
145
|
if (hasClosestByMatchTag(typeElement, "CODE")) {
|
|
119
146
|
if (hasClosestByMatchTag(typeElement, "PRE")) {
|
|
120
|
-
disableToolbar(vditor.toolbar.elements, [
|
|
121
|
-
"
|
|
147
|
+
disableToolbar(vditor.toolbar.elements, [
|
|
148
|
+
"headings",
|
|
149
|
+
"bold",
|
|
150
|
+
"italic",
|
|
151
|
+
"strike",
|
|
152
|
+
"line",
|
|
153
|
+
"quote",
|
|
154
|
+
"list",
|
|
155
|
+
"ordered-list",
|
|
156
|
+
"check",
|
|
157
|
+
"code",
|
|
158
|
+
"inline-code",
|
|
159
|
+
"upload",
|
|
160
|
+
"link",
|
|
161
|
+
"table",
|
|
162
|
+
"record",
|
|
163
|
+
]);
|
|
122
164
|
setCurrentToolbar(vditor.toolbar.elements, ["code"]);
|
|
123
165
|
} else {
|
|
124
|
-
disableToolbar(vditor.toolbar.elements, [
|
|
125
|
-
"
|
|
166
|
+
disableToolbar(vditor.toolbar.elements, [
|
|
167
|
+
"headings",
|
|
168
|
+
"bold",
|
|
169
|
+
"italic",
|
|
170
|
+
"strike",
|
|
171
|
+
"line",
|
|
172
|
+
"quote",
|
|
173
|
+
"list",
|
|
174
|
+
"ordered-list",
|
|
175
|
+
"check",
|
|
176
|
+
"code",
|
|
177
|
+
"upload",
|
|
178
|
+
"link",
|
|
179
|
+
"table",
|
|
180
|
+
"record",
|
|
181
|
+
]);
|
|
126
182
|
setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]);
|
|
127
183
|
}
|
|
128
184
|
} else if (headingElement) {
|
|
@@ -164,6 +220,8 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
164
220
|
|
|
165
221
|
// table popover
|
|
166
222
|
if (tableElement) {
|
|
223
|
+
const lang: keyof II18n | "" = vditor.options.lang;
|
|
224
|
+
const options: IOptions = vditor.options;
|
|
167
225
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
168
226
|
const updateTable = () => {
|
|
169
227
|
const oldRow = tableElement.rows.length;
|
|
@@ -203,9 +261,13 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
203
261
|
}
|
|
204
262
|
for (let l = 0; l < rowDiff; l++) {
|
|
205
263
|
if (tableElement.querySelector("tbody")) {
|
|
206
|
-
tableElement
|
|
264
|
+
tableElement
|
|
265
|
+
.querySelector("tbody")
|
|
266
|
+
.insertAdjacentHTML("beforeend", rowHTML);
|
|
207
267
|
} else {
|
|
208
|
-
tableElement
|
|
268
|
+
tableElement
|
|
269
|
+
.querySelector("thead")
|
|
270
|
+
.insertAdjacentHTML("afterend", rowHTML + "</tr>");
|
|
209
271
|
}
|
|
210
272
|
}
|
|
211
273
|
} else {
|
|
@@ -249,11 +311,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
249
311
|
|
|
250
312
|
const left = document.createElement("button");
|
|
251
313
|
left.setAttribute("type", "button");
|
|
252
|
-
left.setAttribute("aria-label",
|
|
253
|
-
"<" + updateHotkeyTip("⇧⌘L") + ">");
|
|
314
|
+
left.setAttribute("aria-label", window.VditorI18n.alignLeft + "<" + updateHotkeyTip("⇧⌘L") + ">");
|
|
254
315
|
left.setAttribute("data-type", "left");
|
|
255
|
-
left.innerHTML =
|
|
256
|
-
|
|
316
|
+
left.innerHTML =
|
|
317
|
+
'<svg><use xlink:href="#vditor-icon-align-left"></use></svg>';
|
|
318
|
+
left.className =
|
|
319
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n" +
|
|
257
320
|
(alignType === "left" ? " vditor-icon--current" : "");
|
|
258
321
|
left.onclick = () => {
|
|
259
322
|
setAlign("left");
|
|
@@ -261,11 +324,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
261
324
|
|
|
262
325
|
const center = document.createElement("button");
|
|
263
326
|
center.setAttribute("type", "button");
|
|
264
|
-
center.setAttribute("aria-label",
|
|
265
|
-
"<" + updateHotkeyTip("⇧⌘C") + ">");
|
|
327
|
+
center.setAttribute("aria-label", window.VditorI18n.alignCenter + "<" + updateHotkeyTip("⇧⌘C") + ">");
|
|
266
328
|
center.setAttribute("data-type", "center");
|
|
267
|
-
center.innerHTML =
|
|
268
|
-
|
|
329
|
+
center.innerHTML =
|
|
330
|
+
'<svg><use xlink:href="#vditor-icon-align-center"></use></svg>';
|
|
331
|
+
center.className =
|
|
332
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n" +
|
|
269
333
|
(alignType === "center" ? " vditor-icon--current" : "");
|
|
270
334
|
center.onclick = () => {
|
|
271
335
|
setAlign("center");
|
|
@@ -273,11 +337,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
273
337
|
|
|
274
338
|
const right = document.createElement("button");
|
|
275
339
|
right.setAttribute("type", "button");
|
|
276
|
-
right.setAttribute("aria-label",
|
|
277
|
-
"<" + updateHotkeyTip("⇧⌘R") + ">");
|
|
340
|
+
right.setAttribute("aria-label", window.VditorI18n.alignRight + "<" + updateHotkeyTip("⇧⌘R") + ">");
|
|
278
341
|
right.setAttribute("data-type", "right");
|
|
279
|
-
right.innerHTML =
|
|
280
|
-
|
|
342
|
+
right.innerHTML =
|
|
343
|
+
'<svg><use xlink:href="#vditor-icon-align-right"></use></svg>';
|
|
344
|
+
right.className =
|
|
345
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n" +
|
|
281
346
|
(alignType === "right" ? " vditor-icon--current" : "");
|
|
282
347
|
right.onclick = () => {
|
|
283
348
|
setAlign("right");
|
|
@@ -285,14 +350,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
285
350
|
|
|
286
351
|
const insertRowElement = document.createElement("button");
|
|
287
352
|
insertRowElement.setAttribute("type", "button");
|
|
288
|
-
insertRowElement.setAttribute("aria-label",
|
|
289
|
-
"<" + updateHotkeyTip("⌘=") + ">");
|
|
353
|
+
insertRowElement.setAttribute("aria-label", window.VditorI18n.insertRowBelow + "<" + updateHotkeyTip("⌘=") + ">");
|
|
290
354
|
insertRowElement.setAttribute("data-type", "insertRow");
|
|
291
|
-
insertRowElement.innerHTML =
|
|
292
|
-
|
|
355
|
+
insertRowElement.innerHTML =
|
|
356
|
+
'<svg><use xlink:href="#vditor-icon-insert-row"></use></svg>';
|
|
357
|
+
insertRowElement.className =
|
|
358
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
293
359
|
insertRowElement.onclick = () => {
|
|
294
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
295
|
-
|
|
360
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
361
|
+
.startContainer;
|
|
362
|
+
const cellElement =
|
|
363
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
296
364
|
hasClosestByMatchTag(startContainer, "TH");
|
|
297
365
|
if (cellElement) {
|
|
298
366
|
insertRow(vditor, range, cellElement);
|
|
@@ -301,14 +369,18 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
301
369
|
|
|
302
370
|
const insertRowBElement = document.createElement("button");
|
|
303
371
|
insertRowBElement.setAttribute("type", "button");
|
|
304
|
-
insertRowBElement.setAttribute("aria-label",
|
|
305
|
-
"<" + updateHotkeyTip("⇧⌘F") + ">");
|
|
372
|
+
insertRowBElement.setAttribute("aria-label",
|
|
373
|
+
window.VditorI18n.insertRowAbove + "<" + updateHotkeyTip("⇧⌘F") + ">");
|
|
306
374
|
insertRowBElement.setAttribute("data-type", "insertRow");
|
|
307
|
-
insertRowBElement.innerHTML =
|
|
308
|
-
|
|
375
|
+
insertRowBElement.innerHTML =
|
|
376
|
+
'<svg><use xlink:href="#vditor-icon-insert-rowb"></use></svg>';
|
|
377
|
+
insertRowBElement.className =
|
|
378
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
309
379
|
insertRowBElement.onclick = () => {
|
|
310
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
311
|
-
|
|
380
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
381
|
+
.startContainer;
|
|
382
|
+
const cellElement =
|
|
383
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
312
384
|
hasClosestByMatchTag(startContainer, "TH");
|
|
313
385
|
if (cellElement) {
|
|
314
386
|
insertRowAbove(vditor, range, cellElement);
|
|
@@ -317,14 +389,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
317
389
|
|
|
318
390
|
const insertColumnElement = document.createElement("button");
|
|
319
391
|
insertColumnElement.setAttribute("type", "button");
|
|
320
|
-
insertColumnElement.setAttribute("aria-label",
|
|
321
|
-
"<" + updateHotkeyTip("⇧⌘=") + ">");
|
|
392
|
+
insertColumnElement.setAttribute("aria-label", window.VditorI18n.insertColumnRight + "<" + updateHotkeyTip("⇧⌘=") + ">");
|
|
322
393
|
insertColumnElement.setAttribute("data-type", "insertColumn");
|
|
323
|
-
insertColumnElement.innerHTML =
|
|
324
|
-
|
|
394
|
+
insertColumnElement.innerHTML =
|
|
395
|
+
'<svg><use xlink:href="#vditor-icon-insert-column"></use></svg>';
|
|
396
|
+
insertColumnElement.className =
|
|
397
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
325
398
|
insertColumnElement.onclick = () => {
|
|
326
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
327
|
-
|
|
399
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
400
|
+
.startContainer;
|
|
401
|
+
const cellElement =
|
|
402
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
328
403
|
hasClosestByMatchTag(startContainer, "TH");
|
|
329
404
|
if (cellElement) {
|
|
330
405
|
insertColumn(vditor, tableElement, cellElement);
|
|
@@ -333,14 +408,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
333
408
|
|
|
334
409
|
const insertColumnBElement = document.createElement("button");
|
|
335
410
|
insertColumnBElement.setAttribute("type", "button");
|
|
336
|
-
insertColumnBElement.setAttribute("aria-label",
|
|
337
|
-
"<" + updateHotkeyTip("⇧⌘G") + ">");
|
|
411
|
+
insertColumnBElement.setAttribute("aria-label", window.VditorI18n.insertColumnLeft + "<" + updateHotkeyTip("⇧⌘G") + ">");
|
|
338
412
|
insertColumnBElement.setAttribute("data-type", "insertColumn");
|
|
339
|
-
insertColumnBElement.innerHTML =
|
|
340
|
-
|
|
413
|
+
insertColumnBElement.innerHTML =
|
|
414
|
+
'<svg><use xlink:href="#vditor-icon-insert-columnb"></use></svg>';
|
|
415
|
+
insertColumnBElement.className =
|
|
416
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
341
417
|
insertColumnBElement.onclick = () => {
|
|
342
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
343
|
-
|
|
418
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
419
|
+
.startContainer;
|
|
420
|
+
const cellElement =
|
|
421
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
344
422
|
hasClosestByMatchTag(startContainer, "TH");
|
|
345
423
|
if (cellElement) {
|
|
346
424
|
insertColumn(vditor, tableElement, cellElement, "beforebegin");
|
|
@@ -349,14 +427,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
349
427
|
|
|
350
428
|
const deleteRowElement = document.createElement("button");
|
|
351
429
|
deleteRowElement.setAttribute("type", "button");
|
|
352
|
-
deleteRowElement.setAttribute("aria-label",
|
|
353
|
-
"<" + updateHotkeyTip("⌘-") + ">");
|
|
430
|
+
deleteRowElement.setAttribute("aria-label", window.VditorI18n["delete-row"] + "<" + updateHotkeyTip("⌘-") + ">");
|
|
354
431
|
deleteRowElement.setAttribute("data-type", "deleteRow");
|
|
355
|
-
deleteRowElement.innerHTML =
|
|
356
|
-
|
|
432
|
+
deleteRowElement.innerHTML =
|
|
433
|
+
'<svg><use xlink:href="#vditor-icon-delete-row"></use></svg>';
|
|
434
|
+
deleteRowElement.className =
|
|
435
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
357
436
|
deleteRowElement.onclick = () => {
|
|
358
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
359
|
-
|
|
437
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
438
|
+
.startContainer;
|
|
439
|
+
const cellElement =
|
|
440
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
360
441
|
hasClosestByMatchTag(startContainer, "TH");
|
|
361
442
|
if (cellElement) {
|
|
362
443
|
deleteRow(vditor, range, cellElement);
|
|
@@ -365,14 +446,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
365
446
|
|
|
366
447
|
const deleteColumnElement = document.createElement("button");
|
|
367
448
|
deleteColumnElement.setAttribute("type", "button");
|
|
368
|
-
deleteColumnElement.setAttribute("aria-label",
|
|
369
|
-
"<" + updateHotkeyTip("⇧⌘-") + ">");
|
|
449
|
+
deleteColumnElement.setAttribute("aria-label", window.VditorI18n["delete-column"] + "<" + updateHotkeyTip("⇧⌘-") + ">");
|
|
370
450
|
deleteColumnElement.setAttribute("data-type", "deleteColumn");
|
|
371
|
-
deleteColumnElement.innerHTML =
|
|
372
|
-
|
|
451
|
+
deleteColumnElement.innerHTML =
|
|
452
|
+
'<svg><use xlink:href="#vditor-icon-delete-column"></use></svg>';
|
|
453
|
+
deleteColumnElement.className =
|
|
454
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
373
455
|
deleteColumnElement.onclick = () => {
|
|
374
|
-
const startContainer = getSelection().getRangeAt(0)
|
|
375
|
-
|
|
456
|
+
const startContainer = getSelection().getRangeAt(0)
|
|
457
|
+
.startContainer;
|
|
458
|
+
const cellElement =
|
|
459
|
+
hasClosestByMatchTag(startContainer, "TD") ||
|
|
376
460
|
hasClosestByMatchTag(startContainer, "TH");
|
|
377
461
|
if (cellElement) {
|
|
378
462
|
deleteColumn(vditor, range, tableElement, cellElement);
|
|
@@ -380,7 +464,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
380
464
|
};
|
|
381
465
|
|
|
382
466
|
const inputWrap = document.createElement("span");
|
|
383
|
-
inputWrap.setAttribute("aria-label",
|
|
467
|
+
inputWrap.setAttribute("aria-label", window.VditorI18n.row);
|
|
384
468
|
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
385
469
|
const input = document.createElement("input");
|
|
386
470
|
inputWrap.appendChild(input);
|
|
@@ -389,7 +473,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
389
473
|
input.className = "vditor-input";
|
|
390
474
|
input.style.width = "42px";
|
|
391
475
|
input.style.textAlign = "center";
|
|
392
|
-
input.setAttribute("placeholder",
|
|
476
|
+
input.setAttribute("placeholder", window.VditorI18n.row);
|
|
393
477
|
input.value = tableElement.rows.length.toString();
|
|
394
478
|
input.oninput = () => {
|
|
395
479
|
updateTable();
|
|
@@ -408,7 +492,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
408
492
|
};
|
|
409
493
|
|
|
410
494
|
const input2Wrap = document.createElement("span");
|
|
411
|
-
input2Wrap.setAttribute("aria-label",
|
|
495
|
+
input2Wrap.setAttribute("aria-label", window.VditorI18n.column);
|
|
412
496
|
input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
413
497
|
const input2 = document.createElement("input");
|
|
414
498
|
input2Wrap.appendChild(input2);
|
|
@@ -417,7 +501,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
417
501
|
input2.className = "vditor-input";
|
|
418
502
|
input2.style.width = "42px";
|
|
419
503
|
input2.style.textAlign = "center";
|
|
420
|
-
input2.setAttribute("placeholder",
|
|
504
|
+
input2.setAttribute("placeholder", window.VditorI18n.column);
|
|
421
505
|
input2.value = tableElement.rows[0].cells.length.toString();
|
|
422
506
|
input2.oninput = () => {
|
|
423
507
|
updateTable();
|
|
@@ -462,16 +546,17 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
462
546
|
// footnote popover
|
|
463
547
|
const footnotesRefElement = hasClosestByAttribute(typeElement, "data-type", "footnotes-ref");
|
|
464
548
|
if (footnotesRefElement) {
|
|
549
|
+
const lang: keyof II18n | "" = vditor.options.lang;
|
|
550
|
+
const options: IOptions = vditor.options;
|
|
465
551
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
466
552
|
|
|
467
553
|
const inputWrap = document.createElement("span");
|
|
468
|
-
inputWrap.setAttribute("aria-label",
|
|
469
|
-
"<" + updateHotkeyTip("⌥Enter") + ">");
|
|
554
|
+
inputWrap.setAttribute("aria-label", window.VditorI18n.footnoteRef + "<" + updateHotkeyTip("⌥Enter") + ">");
|
|
470
555
|
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
471
556
|
const input = document.createElement("input");
|
|
472
557
|
inputWrap.appendChild(input);
|
|
473
558
|
input.className = "vditor-input";
|
|
474
|
-
input.setAttribute("placeholder",
|
|
559
|
+
input.setAttribute("placeholder", window.VditorI18n.footnoteRef + "<" + updateHotkeyTip("⌥Enter") + ">");
|
|
475
560
|
input.style.width = "120px";
|
|
476
561
|
input.value = footnotesRefElement.getAttribute("data-footnotes-label");
|
|
477
562
|
input.oninput = () => {
|
|
@@ -483,7 +568,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
483
568
|
if (event.isComposing) {
|
|
484
569
|
return;
|
|
485
570
|
}
|
|
486
|
-
if (
|
|
571
|
+
if (
|
|
572
|
+
!isCtrl(event) &&
|
|
573
|
+
!event.shiftKey &&
|
|
574
|
+
event.altKey &&
|
|
575
|
+
event.key === "Enter"
|
|
576
|
+
) {
|
|
487
577
|
range.selectNodeContents(footnotesRefElement);
|
|
488
578
|
range.collapse(false);
|
|
489
579
|
setSelectionFocus(range);
|
|
@@ -500,7 +590,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
500
590
|
|
|
501
591
|
let blockRenderElement = hasClosestByClassName(typeElement, "vditor-wysiwyg__block") as HTMLElement;
|
|
502
592
|
// block popover: math-inline, math-block, html-block, html-inline, code-block, html-entity
|
|
503
|
-
if (
|
|
593
|
+
if (
|
|
594
|
+
blockRenderElement &&
|
|
595
|
+
blockRenderElement.getAttribute("data-type").indexOf("block") > -1
|
|
596
|
+
) {
|
|
597
|
+
const lang: keyof II18n | "" = vditor.options.lang;
|
|
598
|
+
const options: IOptions = vditor.options;
|
|
504
599
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
505
600
|
genUp(range, blockRenderElement, vditor);
|
|
506
601
|
genDown(range, blockRenderElement, vditor);
|
|
@@ -508,20 +603,22 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
508
603
|
|
|
509
604
|
if (blockRenderElement.getAttribute("data-type") === "code-block") {
|
|
510
605
|
const languageWrap = document.createElement("span");
|
|
511
|
-
languageWrap.setAttribute("aria-label",
|
|
512
|
-
"<" + updateHotkeyTip("⌥Enter") + ">");
|
|
606
|
+
languageWrap.setAttribute("aria-label", window.VditorI18n.language + "<" + updateHotkeyTip("⌥Enter") + ">");
|
|
513
607
|
languageWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
514
608
|
const language = document.createElement("input");
|
|
515
609
|
languageWrap.appendChild(language);
|
|
516
610
|
|
|
517
|
-
const codeElement =
|
|
611
|
+
const codeElement =
|
|
612
|
+
blockRenderElement.firstElementChild.firstElementChild;
|
|
518
613
|
|
|
519
614
|
language.className = "vditor-input";
|
|
520
615
|
language.setAttribute("placeholder",
|
|
521
|
-
|
|
522
|
-
language.value =
|
|
523
|
-
codeElement.className.
|
|
524
|
-
|
|
616
|
+
window.VditorI18n.language + "<" + updateHotkeyTip("⌥Enter") + ">");
|
|
617
|
+
language.value =
|
|
618
|
+
codeElement.className.indexOf("language-") > -1
|
|
619
|
+
? codeElement.className.split("-")[1].split(" ")[0]
|
|
620
|
+
: "";
|
|
621
|
+
language.oninput = (e: InputEvent) => {
|
|
525
622
|
if (language.value.trim() !== "") {
|
|
526
623
|
codeElement.className = `language-${language.value}`;
|
|
527
624
|
} else {
|
|
@@ -529,10 +626,18 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
529
626
|
vditor.hint.recentLanguage = "";
|
|
530
627
|
}
|
|
531
628
|
if (blockRenderElement.lastElementChild.classList.contains("vditor-wysiwyg__preview")) {
|
|
532
|
-
blockRenderElement.lastElementChild.innerHTML =
|
|
629
|
+
blockRenderElement.lastElementChild.innerHTML =
|
|
630
|
+
blockRenderElement.firstElementChild.innerHTML;
|
|
533
631
|
processCodeRender(blockRenderElement.lastElementChild as HTMLElement, vditor);
|
|
534
632
|
}
|
|
535
633
|
afterRenderEvent(vditor);
|
|
634
|
+
// 当鼠标点选语言时,触发自定义input事件
|
|
635
|
+
if (e.detail === 1) {
|
|
636
|
+
// 选择语言后,输入焦点切换到代码输入框
|
|
637
|
+
range.setStart(codeElement.firstChild, 0);
|
|
638
|
+
range.collapse(true);
|
|
639
|
+
setSelectionFocus(range);
|
|
640
|
+
}
|
|
536
641
|
};
|
|
537
642
|
language.onkeydown = (event: KeyboardEvent) => {
|
|
538
643
|
if (event.isComposing) {
|
|
@@ -541,21 +646,35 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
541
646
|
if (removeBlockElement(vditor, event)) {
|
|
542
647
|
return;
|
|
543
648
|
}
|
|
544
|
-
if (
|
|
649
|
+
if (
|
|
650
|
+
event.key === "Escape" &&
|
|
651
|
+
vditor.hint.element.style.display === "block"
|
|
652
|
+
) {
|
|
545
653
|
vditor.hint.element.style.display = "none";
|
|
546
654
|
event.preventDefault();
|
|
547
655
|
return;
|
|
548
656
|
}
|
|
549
|
-
|
|
657
|
+
vditor.hint.select(event, vditor);
|
|
658
|
+
if (
|
|
659
|
+
!isCtrl(event) &&
|
|
660
|
+
!event.shiftKey &&
|
|
661
|
+
event.key === "Enter"
|
|
662
|
+
) {
|
|
550
663
|
range.setStart(codeElement.firstChild, 0);
|
|
551
664
|
range.collapse(true);
|
|
552
665
|
setSelectionFocus(range);
|
|
666
|
+
event.preventDefault();
|
|
667
|
+
event.stopPropagation();
|
|
553
668
|
}
|
|
554
|
-
vditor.hint.select(event, vditor);
|
|
555
669
|
};
|
|
556
670
|
language.onkeyup = (event: KeyboardEvent) => {
|
|
557
|
-
if (
|
|
558
|
-
|
|
671
|
+
if (
|
|
672
|
+
event.isComposing ||
|
|
673
|
+
event.key === "Enter" ||
|
|
674
|
+
event.key === "ArrowUp" ||
|
|
675
|
+
event.key === "Escape" ||
|
|
676
|
+
event.key === "ArrowDown"
|
|
677
|
+
) {
|
|
559
678
|
return;
|
|
560
679
|
}
|
|
561
680
|
const matchLangData: IHintData[] = [];
|
|
@@ -576,10 +695,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
576
695
|
setPopoverPosition(vditor, blockRenderElement);
|
|
577
696
|
} else {
|
|
578
697
|
if (!blockRenderElement) {
|
|
579
|
-
vditor.wysiwyg.element
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
698
|
+
vditor.wysiwyg.element
|
|
699
|
+
.querySelectorAll(".vditor-wysiwyg__preview")
|
|
700
|
+
.forEach((itemElement) => {
|
|
701
|
+
const previousElement = itemElement.previousElementSibling as HTMLElement;
|
|
702
|
+
previousElement.style.display = "none";
|
|
703
|
+
});
|
|
583
704
|
}
|
|
584
705
|
blockRenderElement = undefined;
|
|
585
706
|
}
|
|
@@ -603,7 +724,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
603
724
|
if (event.isComposing) {
|
|
604
725
|
return;
|
|
605
726
|
}
|
|
606
|
-
if (
|
|
727
|
+
if (
|
|
728
|
+
!isCtrl(event) &&
|
|
729
|
+
!event.shiftKey &&
|
|
730
|
+
event.altKey &&
|
|
731
|
+
event.key === "Enter"
|
|
732
|
+
) {
|
|
607
733
|
range.selectNodeContents(headingElement);
|
|
608
734
|
range.collapse(false);
|
|
609
735
|
setSelectionFocus(range);
|
|
@@ -625,10 +751,22 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
625
751
|
genAPopover(vditor, aElement);
|
|
626
752
|
}
|
|
627
753
|
|
|
628
|
-
if (
|
|
629
|
-
|
|
754
|
+
if (
|
|
755
|
+
!blockquoteElement &&
|
|
756
|
+
!liElement &&
|
|
757
|
+
!tableElement &&
|
|
758
|
+
!blockRenderElement &&
|
|
759
|
+
!aElement &&
|
|
760
|
+
!linkRefElement &&
|
|
761
|
+
!footnotesRefElement &&
|
|
762
|
+
!headingElement &&
|
|
763
|
+
!tocElement
|
|
764
|
+
) {
|
|
630
765
|
const blockElement = hasClosestByAttribute(typeElement, "data-block", "0");
|
|
631
|
-
if (
|
|
766
|
+
if (
|
|
767
|
+
blockElement &&
|
|
768
|
+
blockElement.parentElement.isEqualNode(vditor.wysiwyg.element)
|
|
769
|
+
) {
|
|
632
770
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
633
771
|
genUp(range, blockElement, vditor);
|
|
634
772
|
genDown(range, blockElement, vditor);
|
|
@@ -641,14 +779,15 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
|
|
|
641
779
|
}
|
|
642
780
|
|
|
643
781
|
// 反斜杠特殊处理
|
|
644
|
-
vditor.wysiwyg.element
|
|
645
|
-
|
|
646
|
-
|
|
782
|
+
vditor.wysiwyg.element
|
|
783
|
+
.querySelectorAll('span[data-type="backslash"] > span')
|
|
784
|
+
.forEach((item: HTMLElement) => {
|
|
785
|
+
item.style.display = "none";
|
|
786
|
+
});
|
|
647
787
|
const backslashElement = hasClosestByAttribute(range.startContainer, "data-type", "backslash");
|
|
648
788
|
if (backslashElement) {
|
|
649
789
|
backslashElement.querySelector("span").style.display = "inline";
|
|
650
790
|
}
|
|
651
|
-
|
|
652
791
|
}, 200);
|
|
653
792
|
};
|
|
654
793
|
|
|
@@ -660,7 +799,8 @@ const setPopoverPosition = (vditor: IVditor, element: HTMLElement) => {
|
|
|
660
799
|
}
|
|
661
800
|
vditor.wysiwyg.popover.style.left = "0";
|
|
662
801
|
vditor.wysiwyg.popover.style.display = "block";
|
|
663
|
-
vditor.wysiwyg.popover.style.top =
|
|
802
|
+
vditor.wysiwyg.popover.style.top =
|
|
803
|
+
Math.max(-8, targetElement.offsetTop - 21 - vditor.wysiwyg.element.scrollTop) + "px";
|
|
664
804
|
vditor.wysiwyg.popover.style.left =
|
|
665
805
|
Math.min(targetElement.offsetLeft, vditor.wysiwyg.element.clientWidth - vditor.wysiwyg.popover.clientWidth) + "px";
|
|
666
806
|
vditor.wysiwyg.popover.setAttribute("data-top", (targetElement.offsetTop - 21).toString());
|
|
@@ -684,14 +824,15 @@ export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement)
|
|
|
684
824
|
};
|
|
685
825
|
|
|
686
826
|
const inputWrap = document.createElement("span");
|
|
687
|
-
inputWrap.setAttribute("aria-label",
|
|
827
|
+
inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty);
|
|
688
828
|
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
689
829
|
const input = document.createElement("input");
|
|
690
830
|
inputWrap.appendChild(input);
|
|
691
831
|
input.className = "vditor-input";
|
|
692
|
-
input.setAttribute("placeholder",
|
|
832
|
+
input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty);
|
|
693
833
|
input.style.width = "120px";
|
|
694
|
-
input.value =
|
|
834
|
+
input.value =
|
|
835
|
+
linkRefElement.getAttribute("alt") || linkRefElement.textContent;
|
|
695
836
|
input.oninput = () => {
|
|
696
837
|
updateLinkRef();
|
|
697
838
|
};
|
|
@@ -703,12 +844,12 @@ export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement)
|
|
|
703
844
|
};
|
|
704
845
|
|
|
705
846
|
const input1Wrap = document.createElement("span");
|
|
706
|
-
input1Wrap.setAttribute("aria-label",
|
|
847
|
+
input1Wrap.setAttribute("aria-label", window.VditorI18n.linkRef);
|
|
707
848
|
input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
708
849
|
const input1 = document.createElement("input");
|
|
709
850
|
input1Wrap.appendChild(input1);
|
|
710
851
|
input1.className = "vditor-input";
|
|
711
|
-
input1.setAttribute("placeholder",
|
|
852
|
+
input1.setAttribute("placeholder", window.VditorI18n.linkRef);
|
|
712
853
|
input1.value = linkRefElement.getAttribute("data-link-label");
|
|
713
854
|
input1.oninput = () => {
|
|
714
855
|
updateLinkRef();
|
|
@@ -728,14 +869,17 @@ export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement)
|
|
|
728
869
|
|
|
729
870
|
const genUp = (range: Range, element: HTMLElement, vditor: IVditor) => {
|
|
730
871
|
const previousElement = element.previousElementSibling;
|
|
731
|
-
if (
|
|
872
|
+
if (
|
|
873
|
+
!previousElement ||
|
|
874
|
+
(!element.parentElement.isEqualNode(vditor.wysiwyg.element) &&
|
|
875
|
+
element.tagName !== "LI")
|
|
876
|
+
) {
|
|
732
877
|
return;
|
|
733
878
|
}
|
|
734
879
|
const upElement = document.createElement("button");
|
|
735
880
|
upElement.setAttribute("type", "button");
|
|
736
881
|
upElement.setAttribute("data-type", "up");
|
|
737
|
-
upElement.setAttribute("aria-label",
|
|
738
|
-
"<" + updateHotkeyTip("⇧⌘U") + ">");
|
|
882
|
+
upElement.setAttribute("aria-label", window.VditorI18n.up + "<" + updateHotkeyTip("⇧⌘U") + ">");
|
|
739
883
|
upElement.innerHTML = '<svg><use xlink:href="#vditor-icon-up"></use></svg>';
|
|
740
884
|
upElement.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
741
885
|
upElement.onclick = () => {
|
|
@@ -751,16 +895,21 @@ const genUp = (range: Range, element: HTMLElement, vditor: IVditor) => {
|
|
|
751
895
|
|
|
752
896
|
const genDown = (range: Range, element: HTMLElement, vditor: IVditor) => {
|
|
753
897
|
const nextElement = element.nextElementSibling;
|
|
754
|
-
if (
|
|
898
|
+
if (
|
|
899
|
+
!nextElement ||
|
|
900
|
+
(!element.parentElement.isEqualNode(vditor.wysiwyg.element) &&
|
|
901
|
+
element.tagName !== "LI")
|
|
902
|
+
) {
|
|
755
903
|
return;
|
|
756
904
|
}
|
|
757
905
|
const downElement = document.createElement("button");
|
|
758
906
|
downElement.setAttribute("type", "button");
|
|
759
907
|
downElement.setAttribute("data-type", "down");
|
|
760
|
-
downElement.setAttribute("aria-label",
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
downElement.className =
|
|
908
|
+
downElement.setAttribute("aria-label", window.VditorI18n.down + "<" + updateHotkeyTip("⇧⌘D") + ">");
|
|
909
|
+
downElement.innerHTML =
|
|
910
|
+
'<svg><use xlink:href="#vditor-icon-down"></use></svg>';
|
|
911
|
+
downElement.className =
|
|
912
|
+
"vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
764
913
|
downElement.onclick = () => {
|
|
765
914
|
range.insertNode(document.createElement("wbr"));
|
|
766
915
|
nextElement.insertAdjacentElement("afterend", element);
|
|
@@ -776,9 +925,9 @@ const genClose = (element: HTMLElement, vditor: IVditor) => {
|
|
|
776
925
|
const close = document.createElement("button");
|
|
777
926
|
close.setAttribute("type", "button");
|
|
778
927
|
close.setAttribute("data-type", "remove");
|
|
779
|
-
close.setAttribute("aria-label",
|
|
780
|
-
|
|
781
|
-
|
|
928
|
+
close.setAttribute("aria-label", window.VditorI18n.remove + "<" + updateHotkeyTip("⇧⌘X") + ">");
|
|
929
|
+
close.innerHTML =
|
|
930
|
+
'<svg><use xlink:href="#vditor-icon-trashcan"></use></svg>';
|
|
782
931
|
close.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
|
|
783
932
|
close.onclick = () => {
|
|
784
933
|
const range = getEditorRange(vditor);
|
|
@@ -791,8 +940,12 @@ const genClose = (element: HTMLElement, vditor: IVditor) => {
|
|
|
791
940
|
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", close);
|
|
792
941
|
};
|
|
793
942
|
|
|
794
|
-
const linkHotkey = (
|
|
795
|
-
|
|
943
|
+
const linkHotkey = (
|
|
944
|
+
vditor: IVditor,
|
|
945
|
+
element: HTMLElement,
|
|
946
|
+
event: KeyboardEvent,
|
|
947
|
+
nextInputElement: HTMLInputElement,
|
|
948
|
+
) => {
|
|
796
949
|
if (event.isComposing) {
|
|
797
950
|
return;
|
|
798
951
|
}
|
|
@@ -802,7 +955,12 @@ const linkHotkey = (vditor: IVditor, element: HTMLElement, event: KeyboardEvent,
|
|
|
802
955
|
event.preventDefault();
|
|
803
956
|
return;
|
|
804
957
|
}
|
|
805
|
-
if (
|
|
958
|
+
if (
|
|
959
|
+
!isCtrl(event) &&
|
|
960
|
+
!event.shiftKey &&
|
|
961
|
+
event.altKey &&
|
|
962
|
+
event.key === "Enter"
|
|
963
|
+
) {
|
|
806
964
|
const range = getEditorRange(vditor);
|
|
807
965
|
// firefox 不会打断 link https://github.com/Vanessa219/vditor/issues/193
|
|
808
966
|
element.insertAdjacentHTML("afterend", Constants.ZWSP);
|
|
@@ -814,6 +972,8 @@ const linkHotkey = (vditor: IVditor, element: HTMLElement, event: KeyboardEvent,
|
|
|
814
972
|
};
|
|
815
973
|
|
|
816
974
|
export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
975
|
+
const lang: keyof II18n | "" = vditor.options.lang;
|
|
976
|
+
const options: IOptions = vditor.options;
|
|
817
977
|
vditor.wysiwyg.popover.innerHTML = "";
|
|
818
978
|
|
|
819
979
|
const updateA = () => {
|
|
@@ -828,12 +988,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
828
988
|
item.removeAttribute("data-marker");
|
|
829
989
|
});
|
|
830
990
|
const inputWrap = document.createElement("span");
|
|
831
|
-
inputWrap.setAttribute("aria-label",
|
|
991
|
+
inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty);
|
|
832
992
|
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
833
993
|
const input = document.createElement("input");
|
|
834
994
|
inputWrap.appendChild(input);
|
|
835
995
|
input.className = "vditor-input";
|
|
836
|
-
input.setAttribute("placeholder",
|
|
996
|
+
input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty);
|
|
837
997
|
input.style.width = "120px";
|
|
838
998
|
input.value = aElement.innerHTML || "";
|
|
839
999
|
input.oninput = () => {
|
|
@@ -847,12 +1007,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
847
1007
|
};
|
|
848
1008
|
|
|
849
1009
|
const input1Wrap = document.createElement("span");
|
|
850
|
-
input1Wrap.setAttribute("aria-label",
|
|
1010
|
+
input1Wrap.setAttribute("aria-label", window.VditorI18n.link);
|
|
851
1011
|
input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
852
1012
|
const input1 = document.createElement("input");
|
|
853
1013
|
input1Wrap.appendChild(input1);
|
|
854
1014
|
input1.className = "vditor-input";
|
|
855
|
-
input1.setAttribute("placeholder",
|
|
1015
|
+
input1.setAttribute("placeholder", window.VditorI18n.link);
|
|
856
1016
|
input1.value = aElement.getAttribute("href") || "";
|
|
857
1017
|
input1.oninput = () => {
|
|
858
1018
|
updateA();
|
|
@@ -865,12 +1025,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
|
|
|
865
1025
|
};
|
|
866
1026
|
|
|
867
1027
|
const input2Wrap = document.createElement("span");
|
|
868
|
-
input2Wrap.setAttribute("aria-label",
|
|
1028
|
+
input2Wrap.setAttribute("aria-label", window.VditorI18n.tooltipText);
|
|
869
1029
|
input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
870
1030
|
const input2 = document.createElement("input");
|
|
871
1031
|
input2Wrap.appendChild(input2);
|
|
872
1032
|
input2.className = "vditor-input";
|
|
873
|
-
input2.setAttribute("placeholder",
|
|
1033
|
+
input2.setAttribute("placeholder", window.VditorI18n.tooltipText);
|
|
874
1034
|
input2.style.width = "60px";
|
|
875
1035
|
input2.value = aElement.getAttribute("title") || "";
|
|
876
1036
|
input2.oninput = () => {
|
|
@@ -900,12 +1060,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
|
|
|
900
1060
|
};
|
|
901
1061
|
|
|
902
1062
|
const inputWrap = document.createElement("span");
|
|
903
|
-
inputWrap.setAttribute("aria-label",
|
|
1063
|
+
inputWrap.setAttribute("aria-label", window.VditorI18n.imageURL);
|
|
904
1064
|
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
905
1065
|
const inputElement = document.createElement("input");
|
|
906
1066
|
inputWrap.appendChild(inputElement);
|
|
907
1067
|
inputElement.className = "vditor-input";
|
|
908
|
-
inputElement.setAttribute("placeholder",
|
|
1068
|
+
inputElement.setAttribute("placeholder", window.VditorI18n.imageURL);
|
|
909
1069
|
inputElement.value = imgElement.getAttribute("src") || "";
|
|
910
1070
|
inputElement.oninput = () => {
|
|
911
1071
|
updateImg();
|
|
@@ -915,12 +1075,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
|
|
|
915
1075
|
};
|
|
916
1076
|
|
|
917
1077
|
const altWrap = document.createElement("span");
|
|
918
|
-
altWrap.setAttribute("aria-label",
|
|
1078
|
+
altWrap.setAttribute("aria-label", window.VditorI18n.alternateText);
|
|
919
1079
|
altWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
920
1080
|
const alt = document.createElement("input");
|
|
921
1081
|
altWrap.appendChild(alt);
|
|
922
1082
|
alt.className = "vditor-input";
|
|
923
|
-
alt.setAttribute("placeholder",
|
|
1083
|
+
alt.setAttribute("placeholder", window.VditorI18n.alternateText);
|
|
924
1084
|
alt.style.width = "52px";
|
|
925
1085
|
alt.value = imgElement.getAttribute("alt") || "";
|
|
926
1086
|
alt.oninput = () => {
|
|
@@ -931,12 +1091,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
|
|
|
931
1091
|
};
|
|
932
1092
|
|
|
933
1093
|
const titleWrap = document.createElement("span");
|
|
934
|
-
titleWrap.setAttribute("aria-label",
|
|
1094
|
+
titleWrap.setAttribute("aria-label", window.VditorI18n.title);
|
|
935
1095
|
titleWrap.className = "vditor-tooltipped vditor-tooltipped__n";
|
|
936
1096
|
const title = document.createElement("input");
|
|
937
1097
|
titleWrap.appendChild(title);
|
|
938
1098
|
title.className = "vditor-input";
|
|
939
|
-
title.setAttribute("placeholder",
|
|
1099
|
+
title.setAttribute("placeholder", window.VditorI18n.title);
|
|
940
1100
|
title.value = imgElement.getAttribute("title") || "";
|
|
941
1101
|
title.oninput = () => {
|
|
942
1102
|
updateImg();
|