vditor 3.8.13 → 3.8.16

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.
Files changed (33) hide show
  1. package/README.md +11 -11
  2. package/dist/index.css +1807 -2
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/js/lute/lute.min.js +47 -47
  6. package/dist/method.min.js +1 -1
  7. package/dist/types/index.d.ts +4 -2
  8. package/package.json +3 -2
  9. package/src/assets/{scss/_content.scss → less/_content.less} +8 -9
  10. package/src/assets/{scss/_hint.scss → less/_hint.less} +0 -0
  11. package/src/assets/{scss/_ir.scss → less/_ir.less} +4 -4
  12. package/src/assets/{scss/_panel.scss → less/_panel.less} +4 -4
  13. package/src/assets/{scss/_reset.scss → less/_reset.less} +13 -13
  14. package/src/assets/{scss/_sv.scss → less/_sv.less} +1 -2
  15. package/src/assets/{scss/_toolbar.scss → less/_toolbar.less} +3 -3
  16. package/src/assets/{scss/_tooltipped.scss → less/_tooltipped.less} +15 -15
  17. package/src/assets/{scss/_wysiwyg.scss → less/_wysiwyg.less} +3 -3
  18. package/src/assets/{scss/index.scss → less/index.less} +27 -22
  19. package/src/index.ts +6 -3
  20. package/src/ts/constants.ts +1 -1
  21. package/src/ts/ir/input.ts +23 -14
  22. package/src/ts/sv/inputEvent.ts +16 -15
  23. package/src/ts/sv/process.ts +20 -8
  24. package/src/ts/tip/index.ts +13 -5
  25. package/src/ts/toolbar/Info.ts +1 -1
  26. package/src/ts/ui/initUI.ts +159 -155
  27. package/src/ts/ui/setContentTheme.ts +1 -1
  28. package/src/ts/upload/index.ts +3 -0
  29. package/src/ts/util/editorCommonEvent.ts +2 -2
  30. package/src/ts/util/fixBrowserBehavior.ts +1272 -1247
  31. package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +4 -0
  32. package/src/ts/wysiwyg/index.ts +4 -0
  33. package/src/ts/wysiwyg/input.ts +16 -14
@@ -158,11 +158,11 @@
158
158
 
159
159
  span[data-type="link-ref"],
160
160
  sup[data-type="footnotes-ref"] {
161
- color: $blurColor;
161
+ color: @blurColor;
162
162
  }
163
163
 
164
164
  span[data-type="toc-h"] {
165
- color: $blurColor;
165
+ color: @blurColor;
166
166
  text-decoration: underline;
167
167
  }
168
168
 
@@ -177,7 +177,7 @@
177
177
  }
178
178
  }
179
179
 
180
- @media screen and (max-width: $max-width) {
180
+ @media screen and (max-width: @max-width) {
181
181
  .vditor-wysiwyg {
182
182
  h1:before,
183
183
  h2:before,
@@ -1,23 +1,28 @@
1
- $errorColor: #d23f31 !default;
2
- $blurColor: #4285f4 !default;
1
+ @errorColor: #d23f31;
2
+ @blurColor: #4285f4;
3
3
 
4
- $font-family-base: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", "Hiragino Sans GB", "Microsoft Yahei", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols" !default;
5
- $font-family-code: mononoki, Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols" !default;
4
+ @font-family-base: "Helvetica Neue", "Luxi Sans", "DejaVu Sans",
5
+ "Hiragino Sans GB", "Microsoft Yahei", sans-serif, "Apple Color Emoji",
6
+ "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji",
7
+ "EmojiSymbols";
8
+ @font-family-code: mononoki, Consolas, "Liberation Mono", Menlo, Courier,
9
+ monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji",
10
+ "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
6
11
 
7
- $transition: all .15s ease-in-out !default;
12
+ @transition: all 0.15s ease-in-out;
8
13
 
9
- $max-width: 520px !default;
14
+ @max-width: 520px;
10
15
 
11
16
  .vditor {
12
17
  --border-color: #d1d5da;
13
18
  --second-color: rgba(88, 96, 105, 0.36);
14
19
 
15
20
  --panel-background-color: #fff;
16
- --panel-shadow: 0 1px 2px rgba(0, 0, 0, .2);
21
+ --panel-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
17
22
 
18
23
  --toolbar-background-color: #f6f8fa;
19
24
  --toolbar-icon-color: #586069;
20
- --toolbar-icon-hover-color: #{$blurColor};
25
+ --toolbar-icon-hover-color: @blurColor;
21
26
  --toolbar-height: 35px;
22
27
  --toolbar-divider-margin-top: 8px;
23
28
 
@@ -29,7 +34,7 @@ $max-width: 520px !default;
29
34
  --resize-hover-icon-color: var(--panel-background-color);
30
35
  --resize-hover-background-color: var(--toolbar-icon-hover-color);
31
36
 
32
- --count-background-color:rgba(27, 31, 35, .05);
37
+ --count-background-color: rgba(27, 31, 35, 0.05);
33
38
  --heading-border-color: #eaecef;
34
39
  --blockquote-color: #6a737d;
35
40
 
@@ -42,10 +47,10 @@ $max-width: 520px !default;
42
47
 
43
48
  &--dark {
44
49
  --border-color: #141414;
45
- --second-color: rgba(185, 185, 185, .36);
50
+ --second-color: rgba(185, 185, 185, 0.36);
46
51
 
47
52
  --panel-background-color: #24292e;
48
- --panel-shadow: 0 1px 2px rgba(255, 255, 255, .2);
53
+ --panel-shadow: 0 1px 2px rgba(255, 255, 255, 0.2);
49
54
 
50
55
  --toolbar-background-color: #1d2125;
51
56
  --toolbar-icon-color: #b9b9b9;
@@ -57,9 +62,9 @@ $max-width: 520px !default;
57
62
  --resize-icon-color: var(--border-color);
58
63
  --resize-background-color: var(--second-color);
59
64
  --resize-hover-icon-color: var(--toolbar-icon-hover-color);
60
- --resize-hover-background-color: rgba(185, 185, 185, .86);
65
+ --resize-hover-background-color: rgba(185, 185, 185, 0.86);
61
66
 
62
- --count-background-color: #{rgba($blurColor, .36)};
67
+ --count-background-color: rgba(@blurColor, 0.36);
63
68
  --heading-border-color: var(--textarea-text-color);
64
69
  --blockquote-color: var(--toolbar-icon-color);
65
70
 
@@ -72,12 +77,12 @@ $max-width: 520px !default;
72
77
  }
73
78
  }
74
79
 
75
- @import "tooltipped";
76
- @import "panel";
77
- @import "toolbar";
78
- @import "content";
79
- @import "hint";
80
- @import "reset";
81
- @import "wysiwyg";
82
- @import "ir";
83
- @import "sv";
80
+ @import "_tooltipped";
81
+ @import "_panel";
82
+ @import "_toolbar";
83
+ @import "_content";
84
+ @import "_hint";
85
+ @import "_reset";
86
+ @import "_wysiwyg";
87
+ @import "_ir";
88
+ @import "_sv";
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./assets/scss/index.scss";
1
+ import "./assets/less/index.less";
2
2
  import VditorMethod from "./method";
3
3
  import {Constants, VDITOR_VERSION} from "./ts/constants";
4
4
  import {DevTools} from "./ts/devtools/index";
@@ -276,7 +276,7 @@ class Vditor extends VditorMethod {
276
276
  /** 设置编辑器内容 */
277
277
  public setValue(markdown: string, clearStack = false) {
278
278
  if (this.vditor.currentMode === "sv") {
279
- this.vditor.sv.element.innerHTML = this.vditor.lute.SpinVditorSVDOM(markdown);
279
+ this.vditor.sv.element.innerHTML = `<div data-block='0'>${this.vditor.lute.SpinVditorSVDOM(markdown)}</div>`;
280
280
  processSVAfterRender(this.vditor, {
281
281
  enableAddUndoStack: true,
282
282
  enableHint: false,
@@ -327,7 +327,10 @@ class Vditor extends VditorMethod {
327
327
  this.vditor.element.innerHTML = this.vditor.originalInnerHTML;
328
328
  this.vditor.element.classList.remove("vditor");
329
329
  this.vditor.element.removeAttribute("style");
330
- document.getElementById("vditorIconScript").remove();
330
+ const iconScript = document.getElementById("vditorIconScript")
331
+ if (iconScript) {
332
+ iconScript.remove();
333
+ }
331
334
  this.clearCache();
332
335
 
333
336
  UIUnbindListener();
@@ -29,7 +29,7 @@ export abstract class Constants {
29
29
  // ext
30
30
  "solidity", "yul"
31
31
  ];
32
- public static readonly CDN = `https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}`;
32
+ public static readonly CDN = `https://unpkg.com/vditor@${VDITOR_VERSION}`;
33
33
  public static readonly MARKDOWN_OPTIONS = {
34
34
  autoSpace: false,
35
35
  codeBlockPreview: true,
@@ -11,6 +11,7 @@ import {processCodeRender} from "../util/processCode";
11
11
  import {getSelectPosition, setRangeByWbr} from "../util/selection";
12
12
  import {renderToc} from "../util/toc";
13
13
  import {processAfterRender} from "./process";
14
+ import {getMarkdown} from "../markdown/getMarkdown";
14
15
 
15
16
  export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?: InputEvent) => {
16
17
  let blockElement = hasClosestBlock(range.startContainer);
@@ -51,6 +52,9 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?
51
52
  }
52
53
 
53
54
  if (startSpace) {
55
+ if (typeof vditor.options.input === "function") {
56
+ vditor.options.input(getMarkdown(vditor));
57
+ }
54
58
  return;
55
59
  }
56
60
  if (endSpace) {
@@ -63,6 +67,9 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?
63
67
  // FireFox https://github.com/Vanessa219/vditor/issues/239
64
68
  previousNode.classList.remove("vditor-ir__node--expand");
65
69
  }
70
+ if (typeof vditor.options.input === "function") {
71
+ vditor.options.input(getMarkdown(vditor));
72
+ }
66
73
  return;
67
74
  }
68
75
  }
@@ -141,21 +148,23 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?
141
148
  html = blockElement.previousElementSibling.outerHTML + html;
142
149
  blockElement.previousElementSibling.remove();
143
150
  }
144
- // 添加链接引用
145
- vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => {
146
- if (item && !(blockElement as HTMLElement).isEqualNode(item)) {
147
- html += item.outerHTML;
148
- item.remove();
149
- }
150
- });
151
+ if (!blockElement.innerText.startsWith("```")) {
152
+ // 添加链接引用
153
+ vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item) => {
154
+ if (item && !(blockElement as HTMLElement).isEqualNode(item)) {
155
+ html += item.outerHTML;
156
+ item.remove();
157
+ }
158
+ });
151
159
 
152
- // 添加脚注
153
- vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => {
154
- if (item && !(blockElement as HTMLElement).isEqualNode(item)) {
155
- html += item.outerHTML;
156
- item.remove();
157
- }
158
- });
160
+ // 添加脚注
161
+ vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach((item) => {
162
+ if (item && !(blockElement as HTMLElement).isEqualNode(item)) {
163
+ html += item.outerHTML;
164
+ item.remove();
165
+ }
166
+ });
167
+ }
159
168
  } else {
160
169
  html = blockElement.innerHTML;
161
170
  }
@@ -140,22 +140,23 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => {
140
140
  html = blockElement.previousElementSibling.textContent + html;
141
141
  blockElement.previousElementSibling.remove();
142
142
  }
143
+ if (!blockElement.innerText.startsWith("```")) {
144
+ // 添加链接引用
145
+ vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item, index) => {
146
+ if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
147
+ html += "\n" + item.parentElement.textContent;
148
+ item.parentElement.remove();
149
+ }
150
+ });
143
151
 
144
- // 添加链接引用
145
- vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((item, index) => {
146
- if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
147
- html += "\n" + item.parentElement.textContent;
148
- item.parentElement.remove();
149
- }
150
- });
151
-
152
- // 添加脚注
153
- vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((item, index) => {
154
- if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
155
- html += "\n" + item.parentElement.textContent;
156
- item.parentElement.remove();
157
- }
158
- });
152
+ // 添加脚注
153
+ vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((item, index) => {
154
+ if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
155
+ html += "\n" + item.parentElement.textContent;
156
+ item.parentElement.remove();
157
+ }
158
+ });
159
+ }
159
160
  }
160
161
  html = processSpinVditorSVDOM(html, vditor);
161
162
  if (isSVElement) {
@@ -16,13 +16,19 @@ export const processPaste = (vditor: IVditor, text: string) => {
16
16
  if (!blockElement) {
17
17
  blockElement = vditor.sv.element;
18
18
  }
19
- const html = "<div data-block='0'>" +
20
- vditor.lute.Md2VditorSVDOM(blockElement.textContent).replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
21
- "</div>";
19
+ let spinHTML = vditor.lute.SpinVditorSVDOM(blockElement.textContent)
20
+ if (spinHTML.indexOf('data-type="footnotes-link"') > -1 ||
21
+ spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) {
22
+ spinHTML = "<div data-block='0'>" + spinHTML + "</div>";
23
+ } else {
24
+ spinHTML = "<div data-block='0'>" +
25
+ spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
26
+ "</div>";
27
+ }
22
28
  if (blockElement.isEqualNode(vditor.sv.element)) {
23
- blockElement.innerHTML = html;
29
+ blockElement.innerHTML = spinHTML;
24
30
  } else {
25
- blockElement.outerHTML = html;
31
+ blockElement.outerHTML = spinHTML;
26
32
  }
27
33
  setRangeByWbr(vditor.sv.element, range);
28
34
 
@@ -49,9 +55,15 @@ export const getSideByType = (spanNode: Node, type: string, isPrevious = true) =
49
55
 
50
56
  export const processSpinVditorSVDOM = (html: string, vditor: IVditor) => {
51
57
  log("SpinVditorSVDOM", html, "argument", vditor.options.debugger);
52
- html = "<div data-block='0'>" +
53
- vditor.lute.SpinVditorSVDOM(html).replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
54
- "</div>";
58
+ const spinHTML = vditor.lute.SpinVditorSVDOM(html)
59
+ if (spinHTML.indexOf('data-type="footnotes-link"') > -1 ||
60
+ spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) {
61
+ html = "<div data-block='0'>" + spinHTML + "</div>";
62
+ } else {
63
+ html = "<div data-block='0'>" +
64
+ spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
65
+ "</div>";
66
+ }
55
67
  log("SpinVditorSVDOM", html, "result", vditor.options.debugger);
56
68
  return html;
57
69
  };
@@ -8,20 +8,28 @@ export class Tip {
8
8
 
9
9
  public show(text: string, time: number = 6000) {
10
10
  this.element.className = "vditor-tip vditor-tip--show";
11
-
12
11
  if (time === 0) {
13
12
  this.element.innerHTML = `<div class="vditor-tip__content">${text}
14
13
  <div class="vditor-tip__close">X</div></div>`;
15
14
  this.element.querySelector(".vditor-tip__close").addEventListener("click", () => {
16
15
  this.hide();
17
16
  });
18
- return;
17
+ } else {
18
+ this.element.innerHTML = `<div class="vditor-tip__content">${text}</div>`;
19
+ setTimeout(() => {
20
+ this.hide();
21
+ }, time);
19
22
  }
20
23
 
21
- this.element.innerHTML = `<div class="vditor-tip__content">${text}</div>`;
24
+ // 需在动画结束后才能确定位置
25
+ this.element.removeAttribute("style")
22
26
  setTimeout(() => {
23
- this.hide();
24
- }, time);
27
+ const rect = this.element.getBoundingClientRect();
28
+ if (rect.top < 46) {
29
+ this.element.style.position = "fixed"
30
+ this.element.style.top = "46px"
31
+ }
32
+ }, 150);
25
33
  }
26
34
 
27
35
  public hide() {
@@ -12,7 +12,7 @@ export class Info extends MenuItem {
12
12
  <em>下一代的 Markdown 编辑器,为未来而构建</em>
13
13
  </p>
14
14
  <div style="display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center">
15
- <img src="https://cdn.jsdelivr.net/npm/vditor/src/assets/images/logo.png" style="margin: 0 auto;height: 68px"/>
15
+ <img src="https://unpkg.com/vditor/dist/images/logo.png" style="margin: 0 auto;height: 68px"/>
16
16
  <div>&nbsp;&nbsp;</div>
17
17
  <div style="flex: 1;min-width: 250px">
18
18
  Vditor 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。