vditor 3.8.11 → 3.8.14
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/dist/index.css +1807 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.min.js +1 -1
- package/dist/js/highlight.js/solidity.min.js +73 -0
- package/dist/js/highlight.js/styles/abap.css +89 -0
- package/dist/js/highlight.js/styles/algol.css +98 -0
- package/dist/js/highlight.js/styles/algol_nu.css +45 -0
- package/dist/js/highlight.js/styles/arduino.css +90 -0
- package/dist/js/highlight.js/styles/autumn.css +71 -0
- package/dist/js/highlight.js/styles/borland.css +88 -0
- package/dist/js/highlight.js/styles/bw.css +102 -0
- package/dist/js/highlight.js/styles/colorful.css +85 -0
- package/dist/js/highlight.js/styles/dracula.css +78 -0
- package/dist/js/highlight.js/styles/emacs.css +97 -0
- package/dist/js/highlight.js/styles/friendly.css +113 -0
- package/dist/js/highlight.js/styles/fruity.css +71 -0
- package/dist/js/highlight.js/styles/github.css +100 -0
- package/dist/js/highlight.js/styles/igor.css +85 -0
- package/dist/js/highlight.js/styles/lovelace.css +71 -0
- package/dist/js/highlight.js/styles/manni.css +69 -0
- package/dist/js/highlight.js/styles/monokai.css +71 -0
- package/dist/js/highlight.js/styles/monokailight.css +108 -0
- package/dist/js/highlight.js/styles/murphy.css +71 -0
- package/dist/js/highlight.js/styles/native.css +97 -0
- package/dist/js/highlight.js/styles/paraiso-dark.css +73 -0
- package/dist/js/highlight.js/styles/paraiso-light.css +72 -0
- package/dist/js/highlight.js/styles/pastie.css +108 -0
- package/dist/js/highlight.js/styles/perldoc.css +74 -0
- package/dist/js/highlight.js/styles/pygments.css +89 -0
- package/dist/js/highlight.js/styles/rainbow_dash.css +97 -0
- package/dist/js/highlight.js/styles/rrt.css +113 -0
- package/dist/js/highlight.js/styles/solarized-dark.css +85 -0
- package/dist/js/highlight.js/styles/solarized-dark256.css +84 -0
- package/dist/js/highlight.js/styles/solarized-light.css +84 -0
- package/dist/js/highlight.js/styles/swapoff.css +92 -0
- package/dist/js/highlight.js/styles/tango.css +99 -0
- package/dist/js/highlight.js/styles/trac.css +99 -0
- package/dist/js/highlight.js/styles/vim.css +83 -0
- package/dist/js/highlight.js/styles/vs.css +69 -0
- package/dist/js/highlight.js/styles/xcode.css +105 -0
- package/dist/js/highlight.js/yul.min.js +30 -0
- package/dist/js/lute/lute.min.js +47 -47
- package/dist/method.min.js +1 -1
- package/dist/ts/toolbar/Emoji.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +14 -7
- package/src/assets/{scss/_content.scss → less/_content.less} +8 -9
- package/src/assets/{scss/_hint.scss → less/_hint.less} +0 -0
- package/src/assets/{scss/_ir.scss → less/_ir.less} +4 -4
- package/src/assets/{scss/_panel.scss → less/_panel.less} +4 -4
- package/src/assets/{scss/_reset.scss → less/_reset.less} +13 -13
- package/src/assets/{scss/_sv.scss → less/_sv.less} +1 -2
- package/src/assets/{scss/_toolbar.scss → less/_toolbar.less} +3 -3
- package/src/assets/{scss/_tooltipped.scss → less/_tooltipped.less} +15 -15
- package/src/assets/{scss/_wysiwyg.scss → less/_wysiwyg.less} +3 -3
- package/src/assets/{scss/index.scss → less/index.less} +27 -22
- package/src/index.ts +6 -3
- package/src/ts/constants.ts +59 -56
- package/src/ts/ir/index.ts +5 -0
- package/src/ts/markdown/highlightRender.ts +65 -61
- package/src/ts/sv/index.ts +6 -0
- package/src/ts/tip/index.ts +13 -5
- package/src/ts/toolbar/Emoji.ts +19 -20
- package/src/ts/ui/initUI.ts +159 -151
- package/src/ts/undo/index.ts +3 -0
- package/src/ts/upload/index.ts +1 -1
- package/src/ts/util/Options.ts +5 -0
- package/src/ts/util/editorCommonEvent.ts +2 -2
- package/src/ts/util/fixBrowserBehavior.ts +1248 -1245
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +11 -16
- package/src/ts/wysiwyg/index.ts +2 -0
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
@keyframes tooltip-appear {
|
|
8
8
|
from {
|
|
9
|
-
opacity: 0
|
|
9
|
+
opacity: 0;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
to {
|
|
13
|
-
opacity: 1
|
|
13
|
+
opacity: 1;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
background: #3b3e43;
|
|
40
40
|
border-radius: 3px;
|
|
41
41
|
line-height: 16px;
|
|
42
|
-
opacity: 0
|
|
42
|
+
opacity: 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
&::before {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
pointer-events: none;
|
|
53
53
|
content: "";
|
|
54
54
|
border: 5px solid transparent;
|
|
55
|
-
opacity: 0
|
|
55
|
+
opacity: 0;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
&--hover::before,
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
&__sw::after {
|
|
77
77
|
top: 100%;
|
|
78
78
|
right: 50%;
|
|
79
|
-
margin-top: 5px
|
|
79
|
+
margin-top: 5px;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
&__s::before,
|
|
@@ -86,17 +86,17 @@
|
|
|
86
86
|
right: 50%;
|
|
87
87
|
bottom: -5px;
|
|
88
88
|
margin-right: -5px;
|
|
89
|
-
border-bottom-color: #3b3e43
|
|
89
|
+
border-bottom-color: #3b3e43;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
&__se::after {
|
|
93
93
|
right: auto;
|
|
94
94
|
left: 50%;
|
|
95
|
-
margin-left: -15px
|
|
95
|
+
margin-left: -15px;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
&__sw::after {
|
|
99
|
-
margin-right: -15px
|
|
99
|
+
margin-right: -15px;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
&__n::after,
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
&__nw::after {
|
|
105
105
|
right: 50%;
|
|
106
106
|
bottom: 100%;
|
|
107
|
-
margin-bottom: 5px
|
|
107
|
+
margin-bottom: 5px;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
&__n::before,
|
|
@@ -114,22 +114,22 @@
|
|
|
114
114
|
right: 50%;
|
|
115
115
|
bottom: auto;
|
|
116
116
|
margin-right: -5px;
|
|
117
|
-
border-top-color: #3b3e43
|
|
117
|
+
border-top-color: #3b3e43;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
&__ne::after {
|
|
121
121
|
right: auto;
|
|
122
122
|
left: 50%;
|
|
123
|
-
margin-left: -15px
|
|
123
|
+
margin-left: -15px;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
&__nw::after {
|
|
127
|
-
margin-right: -15px
|
|
127
|
+
margin-right: -15px;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
&__s::after,
|
|
131
131
|
&__n::after {
|
|
132
|
-
transform: translateX(50%)
|
|
132
|
+
transform: translateX(50%);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
&__w::after {
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
bottom: 50%;
|
|
152
152
|
left: 100%;
|
|
153
153
|
margin-left: 5px;
|
|
154
|
-
transform: translateY(50%)
|
|
154
|
+
transform: translateY(50%);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
&__e::before {
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
@media screen and (max-width:
|
|
166
|
+
@media screen and (max-width: @max-width) {
|
|
167
167
|
.vditor-tooltipped:before,
|
|
168
168
|
.vditor-tooltipped:after {
|
|
169
169
|
content: none;
|
|
@@ -158,11 +158,11 @@
|
|
|
158
158
|
|
|
159
159
|
span[data-type="link-ref"],
|
|
160
160
|
sup[data-type="footnotes-ref"] {
|
|
161
|
-
color:
|
|
161
|
+
color: @blurColor;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
span[data-type="toc-h"] {
|
|
165
|
-
color:
|
|
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:
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
@errorColor: #d23f31;
|
|
2
|
+
@blurColor: #4285f4;
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
12
|
+
@transition: all 0.15s ease-in-out;
|
|
8
13
|
|
|
9
|
-
|
|
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:
|
|
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:
|
|
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 "
|
|
76
|
-
@import "
|
|
77
|
-
@import "
|
|
78
|
-
@import "
|
|
79
|
-
@import "
|
|
80
|
-
@import "
|
|
81
|
-
@import "
|
|
82
|
-
@import "
|
|
83
|
-
@import "
|
|
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/
|
|
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")
|
|
330
|
+
const iconScript = document.getElementById("vditorIconScript")
|
|
331
|
+
if (iconScript) {
|
|
332
|
+
iconScript.remove();
|
|
333
|
+
}
|
|
331
334
|
this.clearCache();
|
|
332
335
|
|
|
333
336
|
UIUnbindListener();
|
package/src/ts/constants.ts
CHANGED
|
@@ -5,60 +5,63 @@ const _VDITOR_VERSION = VDITOR_VERSION;
|
|
|
5
5
|
export {_VDITOR_VERSION as VDITOR_VERSION};
|
|
6
6
|
|
|
7
7
|
export abstract class Constants {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
8
|
+
public static readonly ZWSP: string = "\u200b";
|
|
9
|
+
public static readonly DROP_EDITOR: string = "application/editor";
|
|
10
|
+
public static readonly MOBILE_WIDTH: number = 520;
|
|
11
|
+
public static readonly CLASS_MENU_DISABLED: string = "vditor-menu--disabled";
|
|
12
|
+
public static readonly EDIT_TOOLBARS: string[] = ["emoji", "headings", "bold", "italic", "strike", "link", "list",
|
|
13
|
+
"ordered-list", "outdent", "indent", "check", "line", "quote", "code", "inline-code", "insert-after",
|
|
14
|
+
"insert-before", "upload", "record", "table"];
|
|
15
|
+
public static readonly CODE_THEME: string[] = ["abap", "algol", "algol_nu", "arduino", "autumn", "borland", "bw",
|
|
16
|
+
"colorful", "dracula", "emacs", "friendly", "fruity", "github", "igor", "lovelace", "manni", "monokai",
|
|
17
|
+
"monokailight", "murphy", "native", "paraiso-dark", "paraiso-light", "pastie", "perldoc", "pygments",
|
|
18
|
+
"rainbow_dash", "rrt", "solarized-dark", "solarized-dark256", "solarized-light", "swapoff", "tango", "trac",
|
|
19
|
+
"vim", "vs", "xcode", "ant-design"];
|
|
20
|
+
public static readonly CODE_LANGUAGES: string[] = ["mermaid", "echarts", "mindmap", "plantuml", "abc", "graphviz", "flowchart", "apache",
|
|
21
|
+
"js", "ts", "html",
|
|
22
|
+
// common
|
|
23
|
+
"properties", "apache", "bash", "c", "csharp", "cpp", "css", "coffeescript", "diff", "go", "xml", "http",
|
|
24
|
+
"json", "java", "javascript", "kotlin", "less", "lua", "makefile", "markdown", "nginx", "objectivec", "php",
|
|
25
|
+
"php-template", "perl", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "sql", "shell",
|
|
26
|
+
"swift", "ini", "typescript", "vbnet", "yaml",
|
|
27
|
+
"ada", "clojure", "dart", "erb", "fortran", "gradle", "haskell", "julia", "julia-repl", "lisp", "matlab",
|
|
28
|
+
"pgsql", "powershell", "sql_more", "stata", "cmake", "mathematica",
|
|
29
|
+
// ext
|
|
30
|
+
"solidity", "yul"
|
|
31
|
+
];
|
|
32
|
+
public static readonly CDN = `https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}`;
|
|
33
|
+
public static readonly MARKDOWN_OPTIONS = {
|
|
34
|
+
autoSpace: false,
|
|
35
|
+
codeBlockPreview: true,
|
|
36
|
+
fixTermTypo: false,
|
|
37
|
+
footnotes: true,
|
|
38
|
+
linkBase: "",
|
|
39
|
+
linkPrefix: "",
|
|
40
|
+
listStyle: false,
|
|
41
|
+
mark: false,
|
|
42
|
+
mathBlockPreview: true,
|
|
43
|
+
paragraphBeginningSpace: false,
|
|
44
|
+
sanitize: true,
|
|
45
|
+
toc: false,
|
|
46
|
+
};
|
|
47
|
+
public static readonly HLJS_OPTIONS = {
|
|
48
|
+
enable: true,
|
|
49
|
+
lineNumber: false,
|
|
50
|
+
style: "github",
|
|
51
|
+
};
|
|
52
|
+
public static readonly MATH_OPTIONS: IMath = {
|
|
53
|
+
engine: "KaTeX",
|
|
54
|
+
inlineDigit: false,
|
|
55
|
+
macros: {},
|
|
56
|
+
};
|
|
57
|
+
public static readonly THEME_OPTIONS = {
|
|
58
|
+
current: "light",
|
|
59
|
+
list: {
|
|
60
|
+
"ant-design": "Ant Design",
|
|
61
|
+
"dark": "Dark",
|
|
62
|
+
"light": "Light",
|
|
63
|
+
"wechat": "WeChat",
|
|
64
|
+
},
|
|
65
|
+
path: `${Constants.CDN}/dist/css/content-theme`,
|
|
66
|
+
};
|
|
64
67
|
}
|
package/src/ts/ir/index.ts
CHANGED
|
@@ -92,6 +92,11 @@ class IR {
|
|
|
92
92
|
}
|
|
93
93
|
if (this.preventInput) {
|
|
94
94
|
this.preventInput = false;
|
|
95
|
+
processAfterRender(vditor, {
|
|
96
|
+
enableAddUndoStack: true,
|
|
97
|
+
enableHint: true,
|
|
98
|
+
enableInput: true,
|
|
99
|
+
});
|
|
95
100
|
return;
|
|
96
101
|
}
|
|
97
102
|
if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
|
|
@@ -3,80 +3,84 @@ import {addScript} from "../util/addScript";
|
|
|
3
3
|
import {addStyle} from "../util/addStyle";
|
|
4
4
|
|
|
5
5
|
declare const hljs: {
|
|
6
|
-
|
|
6
|
+
highlightElement(element: Element): void;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export const highlightRender = (hljsOption?: IHljs, element: HTMLElement | Document = document,
|
|
10
10
|
cdn = Constants.CDN) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
let style = hljsOption.style;
|
|
12
|
+
if (!Constants.CODE_THEME.includes(style)) {
|
|
13
|
+
style = "github";
|
|
14
|
+
}
|
|
15
|
+
const vditorHljsStyle = document.getElementById("vditorHljsStyle") as HTMLLinkElement;
|
|
16
|
+
const href = `${cdn}/dist/js/highlight.js/styles/${style}.css`;
|
|
17
|
+
if (vditorHljsStyle && vditorHljsStyle.href !== href) {
|
|
18
|
+
vditorHljsStyle.remove();
|
|
19
|
+
}
|
|
20
|
+
addStyle(`${cdn}/dist/js/highlight.js/styles/${style}.css`, "vditorHljsStyle");
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (hljsOption.enable === false) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const codes = element.querySelectorAll("pre > code");
|
|
27
|
+
if (codes.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
addScript(`${cdn}/dist/js/highlight.js/highlight.pack.js`, "vditorHljsScript").then(() => {
|
|
32
|
+
addScript(`${cdn}/dist/js/highlight.js/solidity.min.js`, "vditorHljsSolidityScript").then(() => {
|
|
33
|
+
addScript(`${cdn}/dist/js/highlight.js/yul.min.js`, "vditorHljsYulScript").then(() => {
|
|
32
34
|
element.querySelectorAll("pre > code").forEach((block) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// ir & wysiwyg 区域不渲染
|
|
36
|
+
if (block.parentElement.classList.contains("vditor-ir__marker--pre") ||
|
|
37
|
+
block.parentElement.classList.contains("vditor-wysiwyg__pre")) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
if (block.classList.contains("language-mermaid") || block.classList.contains("language-flowchart") ||
|
|
42
|
+
block.classList.contains("language-echarts") || block.classList.contains("language-mindmap") ||
|
|
43
|
+
block.classList.contains("language-plantuml") ||
|
|
44
|
+
block.classList.contains("language-abc") || block.classList.contains("language-graphviz") ||
|
|
45
|
+
block.classList.contains("language-math")) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
hljs.highlightElement(block);
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
if (!hljsOption.lineNumber) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
block.classList.add("vditor-linenumber");
|
|
55
|
+
let linenNumberTemp: HTMLDivElement = block.querySelector(".vditor-linenumber__temp");
|
|
56
|
+
if (!linenNumberTemp) {
|
|
57
|
+
linenNumberTemp = document.createElement("div");
|
|
58
|
+
linenNumberTemp.className = "vditor-linenumber__temp";
|
|
59
|
+
block.insertAdjacentElement("beforeend", linenNumberTemp);
|
|
60
|
+
}
|
|
61
|
+
const whiteSpace = getComputedStyle(block).whiteSpace;
|
|
62
|
+
let isSoftWrap = false;
|
|
63
|
+
if (whiteSpace === "pre-wrap" || whiteSpace === "pre-line") {
|
|
64
|
+
isSoftWrap = true;
|
|
65
|
+
}
|
|
66
|
+
let lineNumberHTML = "";
|
|
67
|
+
const lineList = block.textContent.split(/\r\n|\r|\n/g);
|
|
68
|
+
lineList.pop();
|
|
69
|
+
lineList.map((line) => {
|
|
70
|
+
let lineHeight = "";
|
|
71
|
+
if (isSoftWrap) {
|
|
72
|
+
linenNumberTemp.textContent = line || "\n";
|
|
73
|
+
lineHeight = ` style="height:${linenNumberTemp.getBoundingClientRect().height}px"`;
|
|
63
74
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
lineList.pop();
|
|
67
|
-
lineList.map((line) => {
|
|
68
|
-
let lineHeight = "";
|
|
69
|
-
if (isSoftWrap) {
|
|
70
|
-
linenNumberTemp.textContent = line || "\n";
|
|
71
|
-
lineHeight = ` style="height:${linenNumberTemp.getBoundingClientRect().height}px"`;
|
|
72
|
-
}
|
|
73
|
-
lineNumberHTML += `<span${lineHeight}></span>`;
|
|
74
|
-
});
|
|
75
|
+
lineNumberHTML += `<span${lineHeight}></span>`;
|
|
76
|
+
});
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
linenNumberTemp.style.display = "none";
|
|
79
|
+
lineNumberHTML = `<span class="vditor-linenumber__rows">${lineNumberHTML}</span>`;
|
|
80
|
+
block.insertAdjacentHTML("beforeend", lineNumberHTML);
|
|
79
81
|
});
|
|
80
|
-
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
});
|
|
81
85
|
|
|
82
86
|
};
|
package/src/ts/sv/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import {paste} from "../util/fixBrowserBehavior";
|
|
12
12
|
import {getSelectText} from "../util/getSelectText";
|
|
13
13
|
import {inputEvent} from "./inputEvent";
|
|
14
|
+
import {processAfterRender} from "./process";
|
|
14
15
|
|
|
15
16
|
class Editor {
|
|
16
17
|
public range: Range;
|
|
@@ -91,6 +92,11 @@ class Editor {
|
|
|
91
92
|
}
|
|
92
93
|
if (this.preventInput) {
|
|
93
94
|
this.preventInput = false;
|
|
95
|
+
processAfterRender(vditor, {
|
|
96
|
+
enableAddUndoStack: true,
|
|
97
|
+
enableHint: true,
|
|
98
|
+
enableInput: true,
|
|
99
|
+
});
|
|
94
100
|
return;
|
|
95
101
|
}
|
|
96
102
|
inputEvent(vditor, event);
|
package/src/ts/tip/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
24
|
+
// 需在动画结束后才能确定位置
|
|
25
|
+
this.element.removeAttribute("style")
|
|
22
26
|
setTimeout(() => {
|
|
23
|
-
this.
|
|
24
|
-
|
|
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() {
|