vditor 3.8.17 → 3.9.0

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.
@@ -24,7 +24,7 @@ export class Outline {
24
24
  return html;
25
25
  }
26
26
 
27
- public toggle(vditor: IVditor, show = true) {
27
+ public toggle(vditor: IVditor, show = true, focus = true) {
28
28
  const btnElement = vditor.toolbar.elements.outline?.firstElementChild;
29
29
  if (show && window.innerWidth >= Constants.MOBILE_WIDTH) {
30
30
  this.element.style.display = "block";
@@ -34,12 +34,10 @@ export class Outline {
34
34
  this.element.style.display = "none";
35
35
  btnElement?.classList.remove("vditor-menu--current");
36
36
  }
37
- if (getSelection().rangeCount > 0) {
37
+ if (focus && getSelection().rangeCount > 0) {
38
38
  const range = getSelection().getRangeAt(0);
39
39
  if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
40
40
  setSelectionFocus(range);
41
- } else {
42
- vditor[vditor.currentMode].element.focus();
43
41
  }
44
42
  }
45
43
  setPadding(vditor);
@@ -8,6 +8,7 @@ import {highlightRender} from "../markdown/highlightRender";
8
8
  import {mathRender} from "../markdown/mathRender";
9
9
  import {mediaRender} from "../markdown/mediaRender";
10
10
  import {mermaidRender} from "../markdown/mermaidRender";
11
+ import {markmapRender} from "../markdown/markmapRender";
11
12
  import {mindmapRender} from "../markdown/mindmapRender";
12
13
  import {plantumlRender} from "../markdown/plantumlRender";
13
14
  import {getEventName} from "../util/compatibility";
@@ -51,8 +52,21 @@ export class Preview {
51
52
  }
52
53
  return;
53
54
  }
55
+ if (event.target.tagName === "A") {
56
+ if (vditor.options.link.click) {
57
+ vditor.options.link.click(event.target);
58
+ } else if (vditor.options.link.isOpen) {
59
+ window.open(event.target.getAttribute("href"));
60
+ }
61
+ event.preventDefault();
62
+ return;
63
+ }
54
64
  if (event.target.tagName === "IMG") {
55
- previewImage(event.target as HTMLImageElement, vditor.options.lang, vditor.options.theme);
65
+ if (vditor.options.image.preview) {
66
+ vditor.options.image.preview(event.target)
67
+ } else if (vditor.options.image.isPreview) {
68
+ previewImage(event.target as HTMLImageElement, vditor.options.lang, vditor.options.theme);
69
+ }
56
70
  }
57
71
  });
58
72
 
@@ -211,6 +225,7 @@ export class Preview {
211
225
  highlightRender(vditor.options.preview.hljs, vditor.preview.element.lastElementChild as HTMLElement,
212
226
  vditor.options.cdn);
213
227
  mermaidRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
228
+ markmapRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
214
229
  flowchartRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn);
215
230
  graphvizRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn);
216
231
  chartRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
@@ -145,7 +145,7 @@ export const setEditMode = (vditor: IVditor, type: string, event: Event | string
145
145
  vditor.toolbar.elements["edit-mode"].querySelector(`button[data-mode="${vditor.currentMode}"]`).classList.add("vditor-menu--current");
146
146
  }
147
147
 
148
- vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable);
148
+ vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable, typeof event !== "string");
149
149
  };
150
150
 
151
151
  export class EditMode extends MenuItem {
@@ -81,7 +81,7 @@ export const initUI = (vditor: IVditor) => {
81
81
  if (vditor.toolbar.elements.export) {
82
82
  // for export pdf
83
83
  vditor.element.insertAdjacentHTML("beforeend",
84
- '<iframe style="width: 100%;height: 0;border: 0"></iframe>');
84
+ '<iframe id="vditorExportIframe" style="width: 100%;height: 0;border: 0"></iframe>');
85
85
  }
86
86
 
87
87
  setEditMode(vditor, vditor.options.mode, afterRender(vditor));
@@ -1,5 +1,5 @@
1
- import { Constants } from "../constants";
2
- import { merge } from "./merge";
1
+ import {Constants} from "../constants";
2
+ import {merge} from "./merge";
3
3
 
4
4
  export class Options {
5
5
  public options: IOptions;
@@ -59,6 +59,12 @@ export class Options {
59
59
  mode: "both",
60
60
  theme: Constants.THEME_OPTIONS,
61
61
  },
62
+ link: {
63
+ isOpen: true,
64
+ },
65
+ image: {
66
+ isPreview: true,
67
+ },
62
68
  resize: {
63
69
  enable: false,
64
70
  position: "bottom",
@@ -29,7 +29,11 @@ export const focusEvent = (vditor: IVditor, editorElement: HTMLElement) => {
29
29
  export const dblclickEvent = (vditor: IVditor, editorElement: HTMLElement) => {
30
30
  editorElement.addEventListener("dblclick", (event: MouseEvent & { target: HTMLElement }) => {
31
31
  if (event.target.tagName === "IMG") {
32
- previewImage(event.target as HTMLImageElement, vditor.options.lang, vditor.options.theme);
32
+ if (vditor.options.image.preview) {
33
+ vditor.options.image.preview(event.target);
34
+ } else if (vditor.options.image.isPreview) {
35
+ previewImage(event.target as HTMLImageElement, vditor.options.lang, vditor.options.theme);
36
+ }
33
37
  }
34
38
  });
35
39
  };
@@ -49,6 +49,10 @@ export const fixCJKPosition = (range: Range, vditor: IVditor, event: KeyboardEve
49
49
  const pLiElement = hasClosestByMatchTag(range.startContainer, "P") ||
50
50
  hasClosestByMatchTag(range.startContainer, "LI");
51
51
  if (pLiElement && getSelectPosition(pLiElement, vditor[vditor.currentMode].element, range).start === 0) {
52
+
53
+ // https://github.com/Vanessa219/vditor/issues/1289 WKWebView切换输入法产生六分之一空格,造成光标错位
54
+ pLiElement.nodeValue = pLiElement.nodeValue.replace(/\u2006/g, '');
55
+
52
56
  const zwspNode = document.createTextNode(Constants.ZWSP);
53
57
  range.insertNode(zwspNode);
54
58
  range.setStartAfter(zwspNode);
@@ -6,6 +6,7 @@ import {graphvizRender} from "../markdown/graphvizRender";
6
6
  import {highlightRender} from "../markdown/highlightRender";
7
7
  import {mathRender} from "../markdown/mathRender";
8
8
  import {mermaidRender} from "../markdown/mermaidRender";
9
+ import {markmapRender} from "../markdown/markmapRender";
9
10
  import {mindmapRender} from "../markdown/mindmapRender";
10
11
  import {plantumlRender} from "../markdown/plantumlRender";
11
12
 
@@ -69,6 +70,8 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>
69
70
  abcRender(previewPanel, vditor.options.cdn);
70
71
  } else if (language === "mermaid") {
71
72
  mermaidRender(previewPanel, vditor.options.cdn, vditor.options.theme);
73
+ } else if (language === "markmap") {
74
+ markmapRender(previewPanel, vditor.options.cdn, vditor.options.theme);
72
75
  } else if (language === "flowchart") {
73
76
  flowchartRender(previewPanel, vditor.options.cdn);
74
77
  } else if (language === "echarts") {
@@ -425,7 +425,13 @@ class WYSIWYG {
425
425
 
426
426
  // 打开链接
427
427
  if (event.target.tagName === "A") {
428
- window.open(event.target.getAttribute("href"));
428
+ if (vditor.options.link.click) {
429
+ vditor.options.link.click(event.target);
430
+ } else if (vditor.options.link.isOpen) {
431
+ window.open(event.target.getAttribute("href"));
432
+ }
433
+ event.preventDefault();
434
+ return;
429
435
  }
430
436
 
431
437
  const range = getEditorRange(vditor);