vditor 3.8.10 → 3.8.13
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 +3 -2
- package/dist/index.css +2 -2
- package/dist/index.min.js +1 -15469
- package/dist/js/highlight.js/solidity.min.js +73 -0
- package/dist/js/highlight.js/styles/abap.css +7 -7
- package/dist/js/highlight.js/styles/algol.css +7 -6
- package/dist/js/highlight.js/styles/algol_nu.css +7 -7
- package/dist/js/highlight.js/styles/arduino.css +7 -5
- package/dist/js/highlight.js/styles/autumn.css +7 -5
- package/dist/js/highlight.js/styles/borland.css +7 -6
- package/dist/js/highlight.js/styles/bw.css +7 -6
- package/dist/js/highlight.js/styles/colorful.css +7 -5
- package/dist/js/highlight.js/styles/dracula.css +9 -8
- package/dist/js/highlight.js/styles/emacs.css +7 -6
- package/dist/js/highlight.js/styles/friendly.css +7 -6
- package/dist/js/highlight.js/styles/fruity.css +7 -5
- package/dist/js/highlight.js/styles/github.css +7 -6
- package/dist/js/highlight.js/styles/igor.css +7 -5
- package/dist/js/highlight.js/styles/lovelace.css +7 -6
- package/dist/js/highlight.js/styles/manni.css +7 -6
- package/dist/js/highlight.js/styles/monokai.css +7 -6
- package/dist/js/highlight.js/styles/monokailight.css +7 -6
- package/dist/js/highlight.js/styles/murphy.css +7 -7
- package/dist/js/highlight.js/styles/native.css +7 -6
- package/dist/js/highlight.js/styles/paraiso-dark.css +7 -6
- package/dist/js/highlight.js/styles/paraiso-light.css +7 -6
- package/dist/js/highlight.js/styles/pastie.css +7 -7
- package/dist/js/highlight.js/styles/perldoc.css +7 -6
- package/dist/js/highlight.js/styles/pygments.css +7 -6
- package/dist/js/highlight.js/styles/rainbow_dash.css +7 -6
- package/dist/js/highlight.js/styles/rrt.css +7 -6
- package/dist/js/highlight.js/styles/solarized-dark.css +7 -6
- package/dist/js/highlight.js/styles/solarized-dark256.css +7 -6
- package/dist/js/highlight.js/styles/solarized-light.css +7 -6
- package/dist/js/highlight.js/styles/swapoff.css +7 -7
- package/dist/js/highlight.js/styles/tango.css +7 -7
- package/dist/js/highlight.js/styles/trac.css +7 -6
- package/dist/js/highlight.js/styles/vim.css +7 -6
- package/dist/js/highlight.js/styles/vs.css +7 -6
- package/dist/js/highlight.js/styles/xcode.css +7 -6
- package/dist/js/highlight.js/yul.min.js +30 -0
- package/dist/js/katex/mhchem.min.js +1 -0
- package/dist/js/lute/lute.min.js +47 -46
- package/dist/method.min.js +1 -2370
- package/dist/ts/toolbar/Emoji.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +17 -11
- 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/markdown/mathRender.ts +29 -27
- package/src/ts/sv/index.ts +6 -0
- package/src/ts/toolbar/Emoji.ts +19 -20
- package/src/ts/ui/initUI.ts +4 -0
- 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/fixBrowserBehavior.ts +1248 -1245
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +12 -18
- package/src/ts/wysiwyg/index.ts +2 -0
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vditor",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.13",
|
|
4
4
|
"description": "♏ 易于使用的 Markdown 编辑器,为适配不同的应用场景而生",
|
|
5
5
|
"author": "Vanessa <v@b3log.org> (http://vanessa.b3log.org)",
|
|
6
6
|
"homepage": "https://b3log.org/vditor",
|
|
@@ -23,30 +23,36 @@
|
|
|
23
23
|
"@babel/preset-env": "^7.14.2",
|
|
24
24
|
"@types/diff-match-patch": "^1.0.32",
|
|
25
25
|
"@types/jest": "^26.0.23",
|
|
26
|
+
"@types/node": "^17.0.19",
|
|
26
27
|
"@types/puppeteer": "^2.1.5",
|
|
27
|
-
"
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
29
|
+
"@typescript-eslint/parser": "^5.12.0",
|
|
30
|
+
"autoprefixer": "^10.4.2",
|
|
28
31
|
"babel-loader": "^8.2.2",
|
|
29
32
|
"clean-webpack-plugin": "^4.0.0-alpha.0",
|
|
30
33
|
"copy-webpack-plugin": "^6.4.1",
|
|
31
34
|
"css-loader": "^5.2.4",
|
|
32
|
-
"
|
|
35
|
+
"eslint": "^8.9.0",
|
|
36
|
+
"eslint-plugin-jest": "^26.1.1",
|
|
37
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
38
|
+
"file-loader": "^6.2.0",
|
|
33
39
|
"html-webpack-plugin": "^5.3.1",
|
|
34
40
|
"identity-obj-proxy": "^3.0.0",
|
|
35
41
|
"jest": "^26.6.3",
|
|
36
|
-
"mini-css-extract-plugin": "^
|
|
37
|
-
"
|
|
42
|
+
"mini-css-extract-plugin": "^2.6.0",
|
|
43
|
+
"postcss": "^8.4.12",
|
|
38
44
|
"postcss-loader": "^5.2.0",
|
|
45
|
+
"prettier": "^2.5.1",
|
|
39
46
|
"puppeteer": "^1.20.0",
|
|
40
|
-
"sass-loader": "^12.
|
|
47
|
+
"sass-loader": "^12.6.0",
|
|
41
48
|
"style-loader": "^1.3.0",
|
|
42
|
-
"terser-webpack-plugin": "^5.
|
|
49
|
+
"terser-webpack-plugin": "^5.3.0",
|
|
43
50
|
"ts-jest": "^26.5.6",
|
|
44
51
|
"ts-loader": "^6.2.2",
|
|
45
|
-
"tslint": "^5.20.1",
|
|
46
52
|
"typescript": "^3.9.9",
|
|
47
|
-
"webpack": "^5.
|
|
53
|
+
"webpack": "^5.66.0",
|
|
48
54
|
"webpack-bundle-analyzer": "^3.9.0",
|
|
49
|
-
"webpack-cli": "^4.
|
|
55
|
+
"webpack-cli": "^4.9.1",
|
|
50
56
|
"webpack-dev-server": "^4.1.0"
|
|
51
57
|
},
|
|
52
58
|
"license": "MIT",
|
|
@@ -55,7 +61,7 @@
|
|
|
55
61
|
"url": "https://github.com/Vanessa219/vditor/issues"
|
|
56
62
|
},
|
|
57
63
|
"scripts": {
|
|
58
|
-
"lint": "
|
|
64
|
+
"lint": "eslint --fix --ext src/**/*.ts",
|
|
59
65
|
"test:watch": "jest --watch",
|
|
60
66
|
"test": "jest --coverage",
|
|
61
67
|
"start": "webpack serve --config webpack.start.js",
|
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
|
};
|
|
@@ -42,33 +42,35 @@ export const mathRender = (element: HTMLElement, options?: { cdn?: string, math?
|
|
|
42
42
|
if (options.math.engine === "KaTeX") {
|
|
43
43
|
addStyle(`${options.cdn}/dist/js/katex/katex.min.css`, "vditorKatexStyle");
|
|
44
44
|
addScript(`${options.cdn}/dist/js/katex/katex.min.js`, "vditorKatexScript").then(() => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
mathElement.parentElement.classList.contains("vditor-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
addScript(`${options.cdn}/dist/js/katex/mhchem.min.js`, "vditorKatexChemScript").then(() => {
|
|
46
|
+
mathElements.forEach((mathElement) => {
|
|
47
|
+
if (mathElement.parentElement.classList.contains("vditor-wysiwyg__pre") ||
|
|
48
|
+
mathElement.parentElement.classList.contains("vditor-ir__marker--pre")) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (mathElement.getAttribute("data-math")) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const math = code160to32(mathRenderAdapter.getCode(mathElement));
|
|
55
|
+
mathElement.setAttribute("data-math", math);
|
|
56
|
+
try {
|
|
57
|
+
mathElement.innerHTML = katex.renderToString(math, {
|
|
58
|
+
displayMode: mathElement.tagName === "DIV",
|
|
59
|
+
output: "html",
|
|
60
|
+
});
|
|
61
|
+
} catch (e) {
|
|
62
|
+
mathElement.innerHTML = e.message;
|
|
63
|
+
mathElement.className = "language-math vditor-reset--error";
|
|
64
|
+
}
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
mathElement.addEventListener("copy", (event: ClipboardEvent) => {
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
const vditorMathElement = (event.currentTarget as HTMLElement).closest(".language-math");
|
|
70
|
+
event.clipboardData.setData("text/html", vditorMathElement.innerHTML);
|
|
71
|
+
event.clipboardData.setData("text/plain",
|
|
72
|
+
vditorMathElement.getAttribute("data-math"));
|
|
73
|
+
});
|
|
72
74
|
});
|
|
73
75
|
});
|
|
74
76
|
});
|
|
@@ -88,7 +90,7 @@ export const mathRender = (element: HTMLElement, options?: { cdn?: string, math?
|
|
|
88
90
|
if (!window.MathJax) {
|
|
89
91
|
window.MathJax = {
|
|
90
92
|
loader: {
|
|
91
|
-
paths: {
|
|
93
|
+
paths: {mathjax: `${options.cdn}/dist/js/mathjax`},
|
|
92
94
|
},
|
|
93
95
|
startup: {
|
|
94
96
|
typeset: false,
|
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/toolbar/Emoji.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {getEventName} from "../util/compatibility";
|
|
2
2
|
import {execAfterRender} from "../util/fixBrowserBehavior";
|
|
3
|
+
import {hasClosestByTag} from "../util/hasClosestByHeadings";
|
|
3
4
|
import {getEditorRange, insertHTML, setSelectionFocus} from "../util/selection";
|
|
4
5
|
import {MenuItem} from "./MenuItem";
|
|
5
6
|
import {toggleSubMenu} from "./setToolbar";
|
|
@@ -23,26 +24,24 @@ data-value=":${key}: " data-key=":${key}:" class="vditor-emojis__icon" src="${em
|
|
|
23
24
|
data-key="${key}"><span class="vditor-emojis__icon">${emojiValue}</span></button>`;
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
-
const tailHTML = `<div class="vditor-emojis__tail">
|
|
28
|
-
<span class="vditor-emojis__tip"></span><span>${vditor.options.hint.emojiTail || ""}</span>
|
|
29
|
-
</div>`;
|
|
30
|
-
|
|
31
27
|
panelElement.innerHTML = `<div class="vditor-emojis" style="max-height: ${
|
|
32
28
|
vditor.options.height === "auto" ? "auto" : vditor.options.height as number - 80
|
|
33
|
-
}px">${commonEmojiHTML}</div
|
|
29
|
+
}px">${commonEmojiHTML}</div><div class="vditor-emojis__tail">
|
|
30
|
+
<span class="vditor-emojis__tip"></span><span>${vditor.options.hint.emojiTail || ""}</span>
|
|
31
|
+
</div>`;
|
|
34
32
|
|
|
35
33
|
this.element.appendChild(panelElement);
|
|
36
34
|
|
|
37
|
-
toggleSubMenu(vditor, panelElement, this.element.
|
|
38
|
-
this.
|
|
35
|
+
toggleSubMenu(vditor, panelElement, this.element.firstElementChild, menuItem.level);
|
|
36
|
+
this.bindEvent(vditor);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
private bindEvent(vditor: IVditor) {
|
|
40
|
+
this.element.lastElementChild.addEventListener(getEventName(), (event: Event & { target: Element }) => {
|
|
41
|
+
const btnElement = hasClosestByTag(event.target, "BUTTON");
|
|
42
|
+
if (btnElement) {
|
|
44
43
|
event.preventDefault();
|
|
45
|
-
const value =
|
|
44
|
+
const value = btnElement.getAttribute("data-value");
|
|
46
45
|
const range = getEditorRange(vditor);
|
|
47
46
|
let html = value;
|
|
48
47
|
if (vditor.currentMode === "wysiwyg") {
|
|
@@ -61,15 +60,15 @@ data-value=":${key}: " data-key=":${key}:" class="vditor-emojis__icon" src="${em
|
|
|
61
60
|
}
|
|
62
61
|
range.collapse(false);
|
|
63
62
|
setSelectionFocus(range);
|
|
64
|
-
|
|
63
|
+
(this.element.lastElementChild as HTMLElement).style.display = "none";
|
|
65
64
|
execAfterRender(vditor);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
this.element.lastElementChild.addEventListener("mouseover", (event: Event & { target: Element }) => {
|
|
68
|
+
const btnElement = hasClosestByTag(event.target, "BUTTON");
|
|
69
|
+
if (btnElement) {
|
|
70
|
+
this.element.querySelector(".vditor-emojis__tip").innerHTML = btnElement.getAttribute("data-key");
|
|
71
|
+
}
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
74
|
}
|
package/src/ts/ui/initUI.ts
CHANGED
|
@@ -14,6 +14,10 @@ declare global {
|
|
|
14
14
|
export const initUI = (vditor: IVditor) => {
|
|
15
15
|
vditor.element.innerHTML = "";
|
|
16
16
|
vditor.element.classList.add("vditor");
|
|
17
|
+
// 支持 RTL
|
|
18
|
+
if (vditor.options.rtl) {
|
|
19
|
+
vditor.element.setAttribute("dir", "rtl")
|
|
20
|
+
}
|
|
17
21
|
setTheme(vditor);
|
|
18
22
|
setContentTheme(vditor.options.preview.theme.current, vditor.options.preview.theme.path);
|
|
19
23
|
if (typeof vditor.options.height === "number") {
|
package/src/ts/undo/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {execAfterRender} from "../util/fixBrowserBehavior";
|
|
|
6
6
|
import {highlightToolbar} from "../util/highlightToolbar";
|
|
7
7
|
import {processCodeRender} from "../util/processCode";
|
|
8
8
|
import {setRangeByWbr, setSelectionFocus} from "../util/selection";
|
|
9
|
+
import {renderToc} from "../util/toc";
|
|
9
10
|
|
|
10
11
|
interface IUndo {
|
|
11
12
|
hasUndo: boolean;
|
|
@@ -165,6 +166,8 @@ class Undo {
|
|
|
165
166
|
scrollCenter(vditor);
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
renderToc(vditor);
|
|
170
|
+
|
|
168
171
|
execAfterRender(vditor, {
|
|
169
172
|
enableAddUndoStack: false,
|
|
170
173
|
enableHint: false,
|
package/src/ts/upload/index.ts
CHANGED
|
@@ -108,7 +108,7 @@ const genUploadedLabel = (responseText: string, vditor: IVditor) => {
|
|
|
108
108
|
if (type.indexOf(".wav") === 0 || type.indexOf(".mp3") === 0 || type.indexOf(".ogg") === 0) {
|
|
109
109
|
if (vditor.currentMode === "wysiwyg") {
|
|
110
110
|
succFileText += `<div class="vditor-wysiwyg__block" data-type="html-block"
|
|
111
|
-
data-block="0"><pre><code><audio controls="controls" src="${path}"></audio></code></pre>\n`;
|
|
111
|
+
data-block="0"><pre><code><audio controls="controls" src="${path}"></audio></code></pre><pre class="vditor-wysiwyg__preview" data-render="1"><audio controls="controls" src="${path}"></audio></pre></div>\n`;
|
|
112
112
|
} else if (vditor.currentMode === "ir") {
|
|
113
113
|
succFileText += `<audio controls="controls" src="${path}"></audio>\n`;
|
|
114
114
|
} else {
|
package/src/ts/util/Options.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { merge } from "./merge";
|
|
|
4
4
|
export class Options {
|
|
5
5
|
public options: IOptions;
|
|
6
6
|
private defaultOptions: IOptions = {
|
|
7
|
+
rtl: false,
|
|
7
8
|
after: undefined,
|
|
8
9
|
cache: {
|
|
9
10
|
enable: true,
|
|
@@ -148,6 +149,10 @@ export class Options {
|
|
|
148
149
|
if (this.options.comment) {
|
|
149
150
|
this.defaultOptions.comment = this.options.comment;
|
|
150
151
|
}
|
|
152
|
+
// 支持不够完善,我先注释了,后期再打开
|
|
153
|
+
// if (this.options.rtl) {
|
|
154
|
+
// this.defaultOptions.rtl = this.options.rtl;
|
|
155
|
+
// }
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
const mergedOptions = merge(this.defaultOptions, this.options);
|