vditor 4.0.2-alpha.7 → 4.0.2-alpha.8
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 +69 -5
- package/dist/index.css +35 -29
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6484 -5444
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +17599 -0
- package/dist/js/graphviz/LICENSE.expat +21 -0
- package/dist/js/graphviz/LICENSE.graphviz +277 -0
- package/dist/js/graphviz/LICENSE.viz +21 -0
- package/dist/js/graphviz/README.md +10 -0
- package/dist/js/graphviz/viz.js +6 -330
- package/dist/js/lute/lute.min.js +3 -3
- package/dist/method.d.ts +2 -2
- package/dist/method.js +2017 -1903
- package/dist/method.min.js +1 -1
- package/dist/method.mjs +3243 -0
- package/dist/ts/constants.d.ts +2 -0
- package/dist/ts/ir/index.d.ts +1 -0
- package/dist/ts/markdown/mathRender.d.ts +24 -1
- package/dist/ts/markdown/outlineRender.d.ts +2 -1
- package/dist/ts/markdown/plantumlRender.d.ts +1 -1
- package/dist/ts/outline/index.d.ts +2 -0
- package/dist/ts/sv/index.d.ts +1 -0
- package/dist/ts/tip/index.d.ts +6 -1
- package/dist/ts/undo/index.d.ts +1 -0
- package/dist/ts/upload/linkToImg.d.ts +1 -0
- package/dist/ts/util/addScript.d.ts +1 -2
- package/dist/ts/util/compatibility.d.ts +1 -1
- package/dist/ts/util/expandHTMLTags.d.ts +1 -0
- package/dist/ts/util/imageDrag.d.ts +1 -0
- package/dist/ts/util/notifyConfigChange.d.ts +1 -0
- package/dist/ts/util/pairedSymbols.d.ts +5 -0
- package/dist/ts/util/pasteIntoTable.d.ts +6 -0
- package/dist/ts/util/pasteLink.d.ts +1 -0
- package/dist/ts/util/processCode.d.ts +1 -0
- package/dist/ts/util/tableWheel.d.ts +1 -0
- package/dist/ts/util/taskNavigation.d.ts +1 -0
- package/dist/ts/wysiwyg/index.d.ts +1 -0
- package/dist/types/index.d.ts +56 -1
- package/package.json +3 -2
- package/src/assets/less/_hint.less +6 -0
- package/src/assets/less/_reset.less +29 -0
- package/src/assets/less/_tooltipped.less +2 -2
- package/src/assets/less/_wysiwyg.less +4 -0
- package/src/index.ts +28 -6
- package/src/ts/constants.ts +4 -0
- package/src/ts/ir/expandMarker.ts +3 -0
- package/src/ts/ir/index.ts +11 -1
- package/src/ts/ir/process.ts +3 -0
- package/src/ts/markdown/chartRender.ts +28 -2
- package/src/ts/markdown/graphvizRender.ts +51 -39
- package/src/ts/markdown/highlightRender.ts +6 -2
- package/src/ts/markdown/mathRender.ts +26 -38
- package/src/ts/markdown/mediaRender.ts +1 -1
- package/src/ts/markdown/mermaidRender.ts +4 -3
- package/src/ts/markdown/outlineRender.ts +44 -15
- package/src/ts/markdown/plantumlRender.ts +24 -5
- package/src/ts/markdown/previewRender.ts +5 -1
- package/src/ts/markdown/setLute.ts +1 -0
- package/src/ts/outline/index.ts +72 -0
- package/src/ts/preview/index.ts +1 -1
- package/src/ts/sv/index.ts +1 -0
- package/src/ts/sv/process.ts +3 -0
- package/src/ts/tip/index.ts +25 -9
- package/src/ts/toolbar/CodeTheme.ts +2 -0
- package/src/ts/toolbar/ContentTheme.ts +2 -0
- package/src/ts/toolbar/EditMode.ts +4 -0
- package/src/ts/toolbar/Headings.ts +4 -6
- package/src/ts/toolbar/Outline.ts +2 -0
- package/src/ts/toolbar/Record.ts +5 -0
- package/src/ts/ui/initUI.ts +9 -1
- package/src/ts/ui/setPreviewMode.ts +2 -0
- package/src/ts/undo/index.ts +14 -4
- package/src/ts/upload/index.ts +1 -1
- package/src/ts/upload/linkToImg.ts +91 -0
- package/src/ts/util/Options.ts +2 -0
- package/src/ts/util/addScript.ts +15 -24
- package/src/ts/util/compatibility.ts +2 -2
- package/src/ts/util/editorCommonEvent.ts +47 -4
- package/src/ts/util/expandHTMLTags.ts +36 -0
- package/src/ts/util/fixBrowserBehavior.ts +29 -61
- package/src/ts/util/imageDrag.ts +108 -0
- package/src/ts/util/notifyConfigChange.ts +16 -0
- package/src/ts/util/pairedSymbols.ts +109 -0
- package/src/ts/util/pasteIntoTable.ts +136 -0
- package/src/ts/util/pasteLink.ts +51 -0
- package/src/ts/util/processCode.ts +33 -8
- package/src/ts/util/selection.ts +11 -2
- package/src/ts/util/tableWheel.ts +31 -0
- package/src/ts/util/taskNavigation.ts +113 -0
- package/src/ts/util/toc.ts +9 -3
- package/src/ts/wysiwyg/afterRenderEvent.ts +3 -0
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +5 -4
- package/src/ts/wysiwyg/index.ts +17 -6
- package/src/ts/wysiwyg/setHeading.ts +4 -0
- package/dist/js/graphviz/full.render.js +0 -90
package/dist/ts/constants.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare abstract class Constants {
|
|
|
18
18
|
codeBlockPreview: boolean;
|
|
19
19
|
fixTermTypo: boolean;
|
|
20
20
|
footnotes: boolean;
|
|
21
|
+
imgPathAllowSpace: boolean;
|
|
21
22
|
imageCaption: boolean;
|
|
22
23
|
linkBase: string;
|
|
23
24
|
linkPrefix: string;
|
|
@@ -37,6 +38,7 @@ export declare abstract class Constants {
|
|
|
37
38
|
style: string;
|
|
38
39
|
};
|
|
39
40
|
static readonly MATH_OPTIONS: IMath;
|
|
41
|
+
static readonly PLANTUML_OPTIONS: IPlantumlOptions;
|
|
40
42
|
static readonly THEME_OPTIONS: {
|
|
41
43
|
current: string;
|
|
42
44
|
list: {
|
package/dist/ts/ir/index.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
interface Window {
|
|
3
|
-
MathJax:
|
|
3
|
+
MathJax: {
|
|
4
|
+
loader?: {
|
|
5
|
+
paths: {
|
|
6
|
+
mathjax: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
startup: {
|
|
10
|
+
typeset?: boolean;
|
|
11
|
+
promise?: Promise<void>;
|
|
12
|
+
document?: {
|
|
13
|
+
clear(): void;
|
|
14
|
+
updateDocument(): void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
tex?: {
|
|
18
|
+
macros: object;
|
|
19
|
+
};
|
|
20
|
+
getMetricsFor?(element: Element): {
|
|
21
|
+
display?: boolean;
|
|
22
|
+
};
|
|
23
|
+
tex2svgPromise?(math: string, options: {
|
|
24
|
+
display?: boolean;
|
|
25
|
+
}): Promise<Element>;
|
|
26
|
+
};
|
|
4
27
|
}
|
|
5
28
|
}
|
|
6
29
|
export declare const mathRender: (element?: (HTMLElement | Document), options?: {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const getOutlineHeadings: (contentElement: HTMLElement, assignIDs?: boolean) => HTMLElement[];
|
|
2
|
+
export declare const outlineRender: (contentElement: HTMLElement, targetElement: Element, vditorOrClick?: IVditor | ((heading: HTMLElement, event: Event) => void)) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const plantumlRender: (element?: (HTMLElement | Document), cdn?: string) => void;
|
|
1
|
+
export declare const plantumlRender: (element?: (HTMLElement | Document), cdn?: string, plantuml?: IPlantumlOptions) => void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="./types" />
|
|
2
2
|
export declare class Outline {
|
|
3
3
|
element: HTMLElement;
|
|
4
|
+
resizeElement: HTMLElement;
|
|
4
5
|
constructor(outlineLabel: string);
|
|
6
|
+
bindResize(vditor: IVditor): void;
|
|
5
7
|
render(vditor: IVditor): string;
|
|
6
8
|
toggle(vditor: IVditor, show?: boolean, focus?: boolean): void;
|
|
7
9
|
}
|
package/dist/ts/sv/index.d.ts
CHANGED
package/dist/ts/tip/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/// <reference types="./types" />
|
|
1
2
|
export declare class Tip {
|
|
3
|
+
private tips?;
|
|
2
4
|
element: HTMLElement;
|
|
3
|
-
|
|
5
|
+
private timeoutId;
|
|
6
|
+
private positionTimeoutId;
|
|
7
|
+
private visible;
|
|
8
|
+
constructor(tips?: ICustomTips);
|
|
4
9
|
show(text: string, time?: number): void;
|
|
5
10
|
hide(): void;
|
|
6
11
|
}
|
package/dist/ts/undo/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare class Undo {
|
|
|
10
10
|
resetIcon(vditor: IVditor): void;
|
|
11
11
|
undo(vditor: IVditor): void;
|
|
12
12
|
redo(vditor: IVditor): void;
|
|
13
|
+
private flushPendingUndoStack;
|
|
13
14
|
recordFirstPosition(vditor: IVditor, event: KeyboardEvent): void;
|
|
14
15
|
addToUndoStack(vditor: IVditor): void;
|
|
15
16
|
private renderDiff;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const uploadLinkToImg: (vditor: IVditor, src: string, afterRender: () => void) => void;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const addScript: (path: string, id: string) => Promise<unknown>;
|
|
1
|
+
export declare const addScript: (path: string, id: string) => Promise<boolean>;
|
|
@@ -2,6 +2,6 @@ export declare const isSafari: () => boolean;
|
|
|
2
2
|
export declare const isFirefox: () => boolean;
|
|
3
3
|
export declare const accessLocalStorage: () => boolean;
|
|
4
4
|
export declare const getEventName: () => "click" | "touchstart";
|
|
5
|
-
export declare const isCtrl: (event: KeyboardEvent) => boolean;
|
|
5
|
+
export declare const isCtrl: (event: Pick<KeyboardEvent, "ctrlKey" | "metaKey">) => boolean;
|
|
6
6
|
export declare const updateHotkeyTip: (hotkey: string) => string;
|
|
7
7
|
export declare const isChrome: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const expandHTMLTags: (root: HTMLElement, range: Range, className: string) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const bindImageDrag: (vditor: IVditor, editor: HTMLElement) => (event: DragEvent) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const notifyConfigChange: (vditor: IVditor) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const parseMarkdownTableRows: (text: string) => string[][] | null;
|
|
2
|
+
export declare const pasteIntoTable: (vditor: IVditor, html: string, markdown?: string) => boolean;
|
|
3
|
+
export declare const buildTableSelectionClipboard: (vditor: IVditor, range: Range) => {
|
|
4
|
+
html: string;
|
|
5
|
+
plain: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPastedLink: (vditor: IVditor, text: string) => string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const isPlainTextPaste: (html: string, editorData: string) => boolean;
|
|
1
2
|
export declare const processPasteCode: (html: string, text: string, type?: string) => string | false;
|
|
2
3
|
export declare const highlightEditableCode: (previewPanel: HTMLElement, vditor: IVditor) => void;
|
|
3
4
|
export declare const processCodeRender: (previewPanel: HTMLElement, vditor: IVditor) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const bindTableWheel: (element: HTMLElement) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const bindTaskNavigation: (vditor: IVditor, root: HTMLElement) => void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -36,6 +36,12 @@ interface IObject {
|
|
|
36
36
|
[key: string]: string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
interface IOutlineItem {
|
|
40
|
+
text: string;
|
|
41
|
+
level: number;
|
|
42
|
+
id: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
interface ILuteNode {
|
|
40
46
|
TokensStr: () => string;
|
|
41
47
|
__internal_object__: {
|
|
@@ -216,6 +222,8 @@ declare class Lute {
|
|
|
216
222
|
|
|
217
223
|
public SetSup(enable: boolean): void;
|
|
218
224
|
|
|
225
|
+
public SetImgPathAllowSpace(enable: boolean): void;
|
|
226
|
+
|
|
219
227
|
public PutEmojis(emojis: IObject): void;
|
|
220
228
|
|
|
221
229
|
public GetEmojis(): IObject;
|
|
@@ -392,6 +400,9 @@ interface IUpload {
|
|
|
392
400
|
/** 剪切板中包含图片地址时,使用此 url 重新上传 */
|
|
393
401
|
linkToImgUrl?: string;
|
|
394
402
|
|
|
403
|
+
/** 自定义外链图片转存,返回替换 URL;空字符串保留原图,异常通过提示显示;优先于 linkToImgUrl */
|
|
404
|
+
linkToImgHandler?(url: string): string | Promise<string>;
|
|
405
|
+
|
|
395
406
|
/** 剪切板中包含图片地址时,使用此方法进行自定义 */
|
|
396
407
|
renderLinkDest?(vditor: IVditor, node: ILuteNode, entering: boolean): [string, number];
|
|
397
408
|
|
|
@@ -403,7 +414,7 @@ interface IUpload {
|
|
|
403
414
|
withCredentials?: boolean;
|
|
404
415
|
/** 请求头设置 */
|
|
405
416
|
headers?: IObject;
|
|
406
|
-
/**
|
|
417
|
+
/** 额外请求参数;linkToImgUrl 的 JSON 请求仅发送字符串值,url 字段由当前图片地址提供 */
|
|
407
418
|
extraData?: {[key: string]: string | Blob};
|
|
408
419
|
/** 是否允许多文件上传。默认值:true */
|
|
409
420
|
multiple?: boolean;
|
|
@@ -544,6 +555,8 @@ interface IMarkdownConfig {
|
|
|
544
555
|
sup?: boolean;
|
|
545
556
|
/** 支持下标 */
|
|
546
557
|
sub?: boolean;
|
|
558
|
+
/** 允许图片和链接路径包含未转义的空格。默认值: false */
|
|
559
|
+
imgPathAllowSpace?: boolean;
|
|
547
560
|
}
|
|
548
561
|
|
|
549
562
|
/** @link https://ld246.com/article/1549638745630#options-preview */
|
|
@@ -596,6 +609,15 @@ interface IPreviewActionCustom {
|
|
|
596
609
|
click: (key: string) => void;
|
|
597
610
|
}
|
|
598
611
|
|
|
612
|
+
interface IPlantumlOptions {
|
|
613
|
+
/** PlantUML 服务地址,需以 `/` 结尾。默认值: 'https://www.plantuml.com/plantuml/svg/' */
|
|
614
|
+
server?: string;
|
|
615
|
+
/** 自定义渲染。传入后不再请求 PlantUML 服务,可用于接入离线渲染引擎,实现方式参见
|
|
616
|
+
* https://github.com/Vanessa219/vditor#optionsplantuml
|
|
617
|
+
*/
|
|
618
|
+
renderer?: (code: string, element: HTMLElement) => void | Promise<void>;
|
|
619
|
+
}
|
|
620
|
+
|
|
599
621
|
interface IPreviewOptions {
|
|
600
622
|
mode: "dark" | "light";
|
|
601
623
|
customEmoji?: IObject;
|
|
@@ -615,6 +637,8 @@ interface IPreviewOptions {
|
|
|
615
637
|
theme?: IPreviewTheme;
|
|
616
638
|
icon?: "ant" | "material" | undefined;
|
|
617
639
|
render?: IPreviewRender;
|
|
640
|
+
/** @link https://github.com/Vanessa219/vditor#optionsplantuml */
|
|
641
|
+
plantuml?: IPlantumlOptions;
|
|
618
642
|
|
|
619
643
|
transform?(html: string): string;
|
|
620
644
|
|
|
@@ -679,6 +703,8 @@ interface IOutline {
|
|
|
679
703
|
enable: boolean;
|
|
680
704
|
/** 大纲位置:'left', 'right'。默认值: 'left' */
|
|
681
705
|
position: "left" | "right";
|
|
706
|
+
/** 大纲初始宽度(像素),拖拽时更新;未设置时沿用 CSS 宽度 */
|
|
707
|
+
width?: number;
|
|
682
708
|
}
|
|
683
709
|
|
|
684
710
|
interface IResize {
|
|
@@ -689,7 +715,27 @@ interface IResize {
|
|
|
689
715
|
}
|
|
690
716
|
|
|
691
717
|
/** @link https://ld246.com/article/1549638745630#options */
|
|
718
|
+
interface IEditorPreferences {
|
|
719
|
+
mode: "wysiwyg" | "ir" | "sv";
|
|
720
|
+
theme: "classic" | "dark";
|
|
721
|
+
preview: {
|
|
722
|
+
mode: "both" | "editor";
|
|
723
|
+
theme: {current: string};
|
|
724
|
+
hljs: {style: string};
|
|
725
|
+
};
|
|
726
|
+
outline: IOutline;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
interface ICustomTips {
|
|
730
|
+
show(text: string, time: number): void;
|
|
731
|
+
hide(): void;
|
|
732
|
+
}
|
|
733
|
+
|
|
692
734
|
interface IOptions {
|
|
735
|
+
/** 工具栏、模式快捷键及主题/预览 API 操作后的偏好快照;不在初始化或正文输入时调用 */
|
|
736
|
+
configChange?(preferences: IEditorPreferences): void;
|
|
737
|
+
/** 自定义消息提示;time 为 0 时保持显示,其他情况到期调用 hide */
|
|
738
|
+
tips?: ICustomTips;
|
|
693
739
|
/** RTL */
|
|
694
740
|
rtl?: boolean;
|
|
695
741
|
/** 历史记录间隔;0 表示在每次编辑完成时同步记录,输入法候选期间不记录中间态 */
|
|
@@ -761,10 +807,14 @@ interface IOptions {
|
|
|
761
807
|
mode?: "wysiwyg" | "sv" | "ir";
|
|
762
808
|
/** @link https://ld246.com/article/1549638745630#options-preview */
|
|
763
809
|
preview?: IPreview;
|
|
810
|
+
/** @link https://github.com/Vanessa219/vditor#optionsplantuml */
|
|
811
|
+
plantuml?: IPlantumlOptions;
|
|
764
812
|
/** @link https://ld246.com/article/1549638745630#options-link */
|
|
765
813
|
link?: {
|
|
766
814
|
/** 是否打开链接地址。默认值: true */
|
|
767
815
|
isOpen?: boolean;
|
|
816
|
+
/** 编辑区链接是否按住 Ctrl(macOS 为 ⌘)点击才跳转。默认值: false */
|
|
817
|
+
ctrlClick?: boolean;
|
|
768
818
|
/** 点击链接事件 */
|
|
769
819
|
click?: (bom: Element) => void;
|
|
770
820
|
},
|
|
@@ -854,6 +904,8 @@ interface IVditor {
|
|
|
854
904
|
};
|
|
855
905
|
outline: {
|
|
856
906
|
element: HTMLElement,
|
|
907
|
+
resizeElement: HTMLElement,
|
|
908
|
+
bindResize(vditor: IVditor): void,
|
|
857
909
|
render(vditor: IVditor): string,
|
|
858
910
|
toggle(vditor: IVditor, show?: boolean, focus?: boolean): void,
|
|
859
911
|
};
|
|
@@ -912,6 +964,7 @@ interface IVditor {
|
|
|
912
964
|
selectPopover: HTMLDivElement,
|
|
913
965
|
popover: HTMLDivElement,
|
|
914
966
|
afterRenderTimeoutId: number,
|
|
967
|
+
pendingUndoStack: boolean,
|
|
915
968
|
hlToolbarTimeoutId: number,
|
|
916
969
|
preventInput: boolean,
|
|
917
970
|
composingLock: boolean,
|
|
@@ -928,11 +981,13 @@ interface IVditor {
|
|
|
928
981
|
composingLock: boolean,
|
|
929
982
|
preventInput: boolean,
|
|
930
983
|
processTimeoutId: number,
|
|
984
|
+
pendingUndoStack: boolean,
|
|
931
985
|
hlToolbarTimeoutId: number,
|
|
932
986
|
};
|
|
933
987
|
sv?: {
|
|
934
988
|
element: HTMLTextAreaElement,
|
|
935
989
|
processTimeoutId: number,
|
|
990
|
+
pendingUndoStack: boolean,
|
|
936
991
|
composingLock: boolean,
|
|
937
992
|
};
|
|
938
993
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vditor",
|
|
3
|
-
"version": "4.0.2-alpha.
|
|
3
|
+
"version": "4.0.2-alpha.8",
|
|
4
4
|
"description": "♏ 易于使用的 Markdown 编辑器,为适配不同的应用场景而生",
|
|
5
5
|
"author": "Vanessa <v@b3log.org> (http://vanessa.b3log.org)",
|
|
6
6
|
"homepage": "https://b3log.org/vditor",
|
|
7
7
|
"jsdelivr": "dist/index.min.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.mjs",
|
|
9
10
|
"funding": "https://ld246.com/sponsor",
|
|
10
11
|
"files": [
|
|
11
12
|
"dist/*",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"ts-loader": "^9.5.1",
|
|
55
56
|
"typescript": "^4.9.5",
|
|
56
57
|
"typescript-eslint": "^8.9.0",
|
|
57
|
-
"webpack": "^5.
|
|
58
|
+
"webpack": "^5.104.1",
|
|
58
59
|
"webpack-bundle-analyzer": "^4.10.2",
|
|
59
60
|
"webpack-cli": "^5.1.4",
|
|
60
61
|
"webpack-dev-server": "^5.1.0"
|
|
@@ -322,6 +322,14 @@
|
|
|
322
322
|
overflow: auto;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
+
p.indent--2 {
|
|
326
|
+
text-indent: 2em;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
&--indent p[data-block="0"] {
|
|
330
|
+
text-indent: 2em;
|
|
331
|
+
}
|
|
332
|
+
|
|
325
333
|
kbd {
|
|
326
334
|
display: inline-block;
|
|
327
335
|
padding: 3px 5px;
|
|
@@ -603,11 +611,26 @@
|
|
|
603
611
|
|
|
604
612
|
&-outline {
|
|
605
613
|
width: 250px;
|
|
614
|
+
max-width: calc(100% - 140px);
|
|
615
|
+
flex-shrink: 0;
|
|
606
616
|
border-right: 1px solid var(--border-color);
|
|
607
617
|
background-color: var(--panel-background-color);
|
|
608
618
|
display: none;
|
|
609
619
|
overflow: auto;
|
|
610
620
|
|
|
621
|
+
&__resize {
|
|
622
|
+
display: none;
|
|
623
|
+
width: 5px;
|
|
624
|
+
flex-shrink: 0;
|
|
625
|
+
cursor: col-resize;
|
|
626
|
+
touch-action: none;
|
|
627
|
+
|
|
628
|
+
&:hover,
|
|
629
|
+
&:focus-visible {
|
|
630
|
+
background-color: var(--border-color);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
611
634
|
&--right {
|
|
612
635
|
border-right: 0;
|
|
613
636
|
border-left: 1px solid var(--border-color);
|
|
@@ -671,6 +694,12 @@
|
|
|
671
694
|
}
|
|
672
695
|
}
|
|
673
696
|
|
|
697
|
+
@media (pointer: coarse) {
|
|
698
|
+
.vditor-outline__resize {
|
|
699
|
+
width: 16px;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
674
703
|
.vditor-reset .callout,
|
|
675
704
|
.vditor-wysiwyg blockquote.callout,
|
|
676
705
|
.vditor-ir blockquote.callout {
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
&:hover::after,
|
|
62
62
|
&:active::before,
|
|
63
63
|
&:active::after,
|
|
64
|
-
&:focus::before,
|
|
65
|
-
&:focus::after {
|
|
64
|
+
&:focus:not(.vditor-menu--disabled)::before,
|
|
65
|
+
&:focus:not(.vditor-menu--disabled)::after {
|
|
66
66
|
display: inline-block;
|
|
67
67
|
text-decoration: none;
|
|
68
68
|
animation-name: tooltip-appear;
|
|
@@ -51,6 +51,10 @@
|
|
|
51
51
|
padding-right: 0 !important;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
&__kbd-marker:not(.vditor-wysiwyg__kbd-marker--expand) {
|
|
55
|
+
display: none;
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
&__block {
|
|
55
59
|
// Source visibility is serialized both by Lute and by CSSStyleDeclaration.
|
|
56
60
|
// Keep the preview laid out for asynchronous wrapped line-number measurements.
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {input as irInput} from "./ts/ir/input";
|
|
|
8
8
|
import {processAfterRender} from "./ts/ir/process";
|
|
9
9
|
import {getHTML} from "./ts/markdown/getHTML";
|
|
10
10
|
import {getMarkdown} from "./ts/markdown/getMarkdown";
|
|
11
|
+
import {getOutlineHeadings} from "./ts/markdown/outlineRender";
|
|
11
12
|
import {setLute} from "./ts/markdown/setLute";
|
|
12
13
|
import {Outline} from "./ts/outline/index";
|
|
13
14
|
import {Preview} from "./ts/preview/index";
|
|
@@ -25,15 +26,17 @@ import {setPreviewMode} from "./ts/ui/setPreviewMode";
|
|
|
25
26
|
import {setTheme} from "./ts/ui/setTheme";
|
|
26
27
|
import {Undo} from "./ts/undo/index";
|
|
27
28
|
import {Upload} from "./ts/upload/index";
|
|
28
|
-
import {addScript
|
|
29
|
+
import {addScript} from "./ts/util/addScript";
|
|
29
30
|
import {getSelectText} from "./ts/util/getSelectText";
|
|
30
31
|
import {Options} from "./ts/util/Options";
|
|
31
32
|
import {processCodeRender} from "./ts/util/processCode";
|
|
33
|
+
import {notifyConfigChange} from "./ts/util/notifyConfigChange";
|
|
32
34
|
import {getCursorPosition, getEditorRange, insertHTML} from "./ts/util/selection";
|
|
33
35
|
import {afterRenderEvent} from "./ts/wysiwyg/afterRenderEvent";
|
|
34
36
|
import {WYSIWYG} from "./ts/wysiwyg/index";
|
|
35
37
|
import {input} from "./ts/wysiwyg/input";
|
|
36
38
|
import {renderDomByMd} from "./ts/wysiwyg/renderDomByMd";
|
|
39
|
+
import {renderToc} from "./ts/util/toc";
|
|
37
40
|
import {execAfterRender, insertEmptyBlock} from "./ts/util/fixBrowserBehavior";
|
|
38
41
|
import {accessLocalStorage} from "./ts/util/compatibility";
|
|
39
42
|
|
|
@@ -88,8 +91,8 @@ class Vditor extends VditorMethod {
|
|
|
88
91
|
});
|
|
89
92
|
addScript(`${mergedOptions.cdn}/dist/js/i18n/${mergedOptions.lang}.js`, i18nScriptID).then(() => {
|
|
90
93
|
this.init(id as HTMLElement, mergedOptions);
|
|
91
|
-
})
|
|
92
|
-
this.showErrorTip(`
|
|
94
|
+
}, () => {
|
|
95
|
+
this.showErrorTip(`Failed to load ${mergedOptions.cdn}/dist/js/i18n/${mergedOptions.lang}.js`);
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
} else {
|
|
@@ -125,6 +128,7 @@ class Vditor extends VditorMethod {
|
|
|
125
128
|
this.vditor.options.preview.hljs.style = codeTheme;
|
|
126
129
|
setCodeTheme(codeTheme, this.vditor.options.cdn);
|
|
127
130
|
}
|
|
131
|
+
notifyConfigChange(this.vditor);
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
/** 获取 Markdown 内容 */
|
|
@@ -132,6 +136,18 @@ class Vditor extends VditorMethod {
|
|
|
132
136
|
return getMarkdown(this.vditor);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
public getOutline(): IOutlineItem[] {
|
|
140
|
+
const content = document.createElement("div");
|
|
141
|
+
content.innerHTML = getHTML(this.vditor);
|
|
142
|
+
const rendered = getOutlineHeadings(content);
|
|
143
|
+
const source = this.vditor.currentMode === "sv" ? content : this.vditor[this.vditor.currentMode].element;
|
|
144
|
+
return getOutlineHeadings(source, true).map((heading, index) => ({
|
|
145
|
+
text: (rendered[index] || heading).textContent.replace(/\u200b/g, ""),
|
|
146
|
+
level: Number(heading.tagName.substring(1)),
|
|
147
|
+
id: heading.id,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
/** 获取编辑器当前编辑模式 */
|
|
136
152
|
public getCurrentMode() {
|
|
137
153
|
return this.vditor.currentMode;
|
|
@@ -371,7 +387,11 @@ class Vditor extends VditorMethod {
|
|
|
371
387
|
});
|
|
372
388
|
}
|
|
373
389
|
|
|
374
|
-
this.vditor.
|
|
390
|
+
if (this.vditor.currentMode === "sv") {
|
|
391
|
+
this.vditor.outline.render(this.vditor);
|
|
392
|
+
} else {
|
|
393
|
+
renderToc(this.vditor);
|
|
394
|
+
}
|
|
375
395
|
|
|
376
396
|
if (!markdown) {
|
|
377
397
|
hidePanel(this.vditor, ["emoji", "headings", "submenu", "hint"]);
|
|
@@ -399,6 +419,7 @@ class Vditor extends VditorMethod {
|
|
|
399
419
|
/** 销毁编辑器 */
|
|
400
420
|
public destroy() {
|
|
401
421
|
this.vditor.hint.destroy();
|
|
422
|
+
this.vditor.tip.hide();
|
|
402
423
|
this.vditor.element.innerHTML = this.vditor.originalInnerHTML;
|
|
403
424
|
this.vditor.element.classList.remove("vditor");
|
|
404
425
|
this.vditor.element.removeAttribute("style");
|
|
@@ -529,7 +550,7 @@ class Vditor extends VditorMethod {
|
|
|
529
550
|
options: mergedOptions,
|
|
530
551
|
originalInnerHTML: id.innerHTML,
|
|
531
552
|
outline: new Outline(window.VditorI18n.outline),
|
|
532
|
-
tip: new Tip(),
|
|
553
|
+
tip: new Tip(mergedOptions.tips),
|
|
533
554
|
};
|
|
534
555
|
|
|
535
556
|
this.vditor.sv = new Editor(this.vditor);
|
|
@@ -567,6 +588,7 @@ class Vditor extends VditorMethod {
|
|
|
567
588
|
fixTermTypo: this.vditor.options.preview.markdown.fixTermTypo,
|
|
568
589
|
footnotes: this.vditor.options.preview.markdown.footnotes,
|
|
569
590
|
headingAnchor: false,
|
|
591
|
+
imgPathAllowSpace: this.vditor.options.preview.markdown.imgPathAllowSpace,
|
|
570
592
|
inlineMathDigit: this.vditor.options.preview.math.inlineDigit,
|
|
571
593
|
linkBase: this.vditor.options.preview.markdown.linkBase,
|
|
572
594
|
linkPrefix: this.vditor.options.preview.markdown.linkPrefix,
|
|
@@ -591,7 +613,7 @@ class Vditor extends VditorMethod {
|
|
|
591
613
|
}
|
|
592
614
|
if (mergedOptions.icon) {
|
|
593
615
|
// 防止初始化 2 个编辑器时加载 2 次
|
|
594
|
-
|
|
616
|
+
addScript(`${mergedOptions.cdn}/dist/js/icons/${mergedOptions.icon}.js`, "vditorIconScript");
|
|
595
617
|
}
|
|
596
618
|
});
|
|
597
619
|
}
|
package/src/ts/constants.ts
CHANGED
|
@@ -57,6 +57,7 @@ export abstract class Constants {
|
|
|
57
57
|
codeBlockPreview: true,
|
|
58
58
|
fixTermTypo: false,
|
|
59
59
|
footnotes: true,
|
|
60
|
+
imgPathAllowSpace: false,
|
|
60
61
|
imageCaption: false,
|
|
61
62
|
linkBase: "",
|
|
62
63
|
linkPrefix: "",
|
|
@@ -80,6 +81,9 @@ export abstract class Constants {
|
|
|
80
81
|
inlineDigit: false,
|
|
81
82
|
macros: {},
|
|
82
83
|
};
|
|
84
|
+
public static readonly PLANTUML_OPTIONS: IPlantumlOptions = {
|
|
85
|
+
server: "https://www.plantuml.com/plantuml/svg/",
|
|
86
|
+
};
|
|
83
87
|
public static readonly THEME_OPTIONS = {
|
|
84
88
|
current: "light",
|
|
85
89
|
list: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {hasClosestByClassName, hasTopClosestByClassName} from "../util/hasClosest";
|
|
2
2
|
import {setSelectionFocus} from "../util/selection";
|
|
3
|
+
import {expandHTMLTags} from "../util/expandHTMLTags";
|
|
3
4
|
|
|
4
5
|
const nextIsNode = (range: Range) => {
|
|
5
6
|
const startContainer = range.startContainer;
|
|
@@ -63,6 +64,8 @@ export const expandMarker = (range: Range, vditor: IVditor) => {
|
|
|
63
64
|
setSelectionFocus(range);
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
expandHTMLTags(vditor.ir.element, range, "vditor-ir__node--expand");
|
|
68
|
+
|
|
66
69
|
const nextNode = nextIsNode(range);
|
|
67
70
|
if (nextNode) {
|
|
68
71
|
nextNode.classList.add("vditor-ir__node--expand");
|
package/src/ts/ir/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {Constants} from "../constants";
|
|
2
2
|
import {isCtrl, isFirefox} from "../util/compatibility";
|
|
3
|
+
import {buildTableSelectionClipboard} from "../util/pasteIntoTable";
|
|
3
4
|
import {
|
|
4
5
|
blurEvent,
|
|
5
6
|
copyEvent, cutEvent, dblclickEvent,
|
|
@@ -49,6 +50,7 @@ class IR {
|
|
|
49
50
|
public range: Range;
|
|
50
51
|
public element: HTMLPreElement;
|
|
51
52
|
public processTimeoutId: number;
|
|
53
|
+
public pendingUndoStack = false;
|
|
52
54
|
public hlToolbarTimeoutId: number;
|
|
53
55
|
public composingLock: boolean = false;
|
|
54
56
|
public preventInput: boolean;
|
|
@@ -82,6 +84,13 @@ class IR {
|
|
|
82
84
|
event.stopPropagation();
|
|
83
85
|
event.preventDefault();
|
|
84
86
|
|
|
87
|
+
const tableClip = buildTableSelectionClipboard(vditor, range);
|
|
88
|
+
if (tableClip) {
|
|
89
|
+
event.clipboardData.setData("text/html", tableClip.html);
|
|
90
|
+
event.clipboardData.setData("text/plain", tableClip.plain);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
const tempElement = document.createElement("div");
|
|
86
95
|
tempElement.appendChild(range.cloneContents());
|
|
87
96
|
const copiedHeadings = tempElement.querySelectorAll<HTMLElement>("h1, h2, h3, h4, h5, h6");
|
|
@@ -182,7 +191,8 @@ class IR {
|
|
|
182
191
|
}
|
|
183
192
|
// 打开链接
|
|
184
193
|
const aElement = hasClosestByAttribute(event.target, "data-type", "a");
|
|
185
|
-
if (aElement && (
|
|
194
|
+
if (aElement && (vditor.options.link.ctrlClick ? isCtrl(event) :
|
|
195
|
+
!aElement.classList.contains("vditor-ir__node--expand"))) {
|
|
186
196
|
if (vditor.options.link.click) {
|
|
187
197
|
vditor.options.link.click(aElement.querySelector(":scope > .vditor-ir__marker--link"));
|
|
188
198
|
} else if (vditor.options.link.isOpen) {
|
package/src/ts/ir/process.ts
CHANGED
|
@@ -42,6 +42,7 @@ export const processAfterRender = (vditor: IVditor, options = {
|
|
|
42
42
|
enableHint: false,
|
|
43
43
|
enableInput: true,
|
|
44
44
|
}) => {
|
|
45
|
+
vditor.ir.pendingUndoStack = options.enableAddUndoStack && vditor.options.undoDelay !== 0;
|
|
45
46
|
renderImageCaptions(vditor.ir.element, "ir", vditor.options.preview.markdown.imageCaption);
|
|
46
47
|
if (options.enableAddUndoStack && vditor.options.undoDelay === 0) {
|
|
47
48
|
vditor.undo.addToUndoStack(vditor);
|
|
@@ -52,6 +53,8 @@ export const processAfterRender = (vditor: IVditor, options = {
|
|
|
52
53
|
|
|
53
54
|
clearTimeout(vditor.ir.processTimeoutId);
|
|
54
55
|
vditor.ir.processTimeoutId = window.setTimeout(() => {
|
|
56
|
+
vditor.ir.processTimeoutId = 0;
|
|
57
|
+
vditor.ir.pendingUndoStack = false;
|
|
55
58
|
if (vditor.ir.composingLock) {
|
|
56
59
|
return;
|
|
57
60
|
}
|