@techie_doubts/tui.editor.2026 3.2.2
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 +176 -0
- package/dist/esm/i18n/ar.js +65 -0
- package/dist/esm/i18n/cs-cz.js +65 -0
- package/dist/esm/i18n/de-de.js +65 -0
- package/dist/esm/i18n/en-us.js +65 -0
- package/dist/esm/i18n/es-es.js +65 -0
- package/dist/esm/i18n/fi-fi.js +65 -0
- package/dist/esm/i18n/fr-fr.js +65 -0
- package/dist/esm/i18n/gl-es.js +65 -0
- package/dist/esm/i18n/hr-hr.js +65 -0
- package/dist/esm/i18n/i18n.js +116 -0
- package/dist/esm/i18n/it-it.js +65 -0
- package/dist/esm/i18n/ja-jp.js +65 -0
- package/dist/esm/i18n/ko-kr.js +65 -0
- package/dist/esm/i18n/nb-no.js +65 -0
- package/dist/esm/i18n/nl-nl.js +65 -0
- package/dist/esm/i18n/pl-pl.js +65 -0
- package/dist/esm/i18n/pt-br.js +65 -0
- package/dist/esm/i18n/ru-ru.js +66 -0
- package/dist/esm/i18n/sv-se.js +65 -0
- package/dist/esm/i18n/tr-tr.js +65 -0
- package/dist/esm/i18n/uk-ua.js +65 -0
- package/dist/esm/i18n/zh-cn.js +65 -0
- package/dist/esm/i18n/zh-tw.js +65 -0
- package/dist/esm/index.js +28323 -0
- package/dist/esm/indexViewer.js +12432 -0
- package/dist/i18n/ar.js +161 -0
- package/dist/i18n/cs-cz.js +161 -0
- package/dist/i18n/de-de.js +161 -0
- package/dist/i18n/es-es.js +161 -0
- package/dist/i18n/fi-fi.js +161 -0
- package/dist/i18n/fr-fr.js +161 -0
- package/dist/i18n/gl-es.js +161 -0
- package/dist/i18n/hr-hr.js +161 -0
- package/dist/i18n/it-it.js +161 -0
- package/dist/i18n/ja-jp.js +161 -0
- package/dist/i18n/ko-kr.js +161 -0
- package/dist/i18n/nb-no.js +161 -0
- package/dist/i18n/nl-nl.js +161 -0
- package/dist/i18n/pl-pl.js +161 -0
- package/dist/i18n/pt-br.js +161 -0
- package/dist/i18n/ru-ru.js +162 -0
- package/dist/i18n/sv-se.js +161 -0
- package/dist/i18n/tr-tr.js +161 -0
- package/dist/i18n/uk-ua.js +161 -0
- package/dist/i18n/zh-cn.js +161 -0
- package/dist/i18n/zh-tw.js +161 -0
- package/dist/td-editor-only.css +1148 -0
- package/dist/td-editor-viewer.css +591 -0
- package/dist/td-editor-viewer.js +13712 -0
- package/dist/td-editor.css +1777 -0
- package/dist/td-editor.js +29832 -0
- package/dist/theme/td-editor-dark.css +555 -0
- package/dist/theme/toastui-editor-dark.css +555 -0
- package/dist/toastui-editor-only.css +1148 -0
- package/dist/toastui-editor-viewer.css +591 -0
- package/dist/toastui-editor-viewer.js +13712 -0
- package/dist/toastui-editor.css +1777 -0
- package/dist/toastui-editor.js +29832 -0
- package/package.json +97 -0
- package/types/convertor.d.ts +142 -0
- package/types/editor.d.ts +383 -0
- package/types/event.d.ts +60 -0
- package/types/index.d.ts +70 -0
- package/types/map.d.ts +8 -0
- package/types/markdown.d.ts +60 -0
- package/types/plugin.d.ts +59 -0
- package/types/prosemirror-commands.d.ts +15 -0
- package/types/prosemirror-model.d.ts +15 -0
- package/types/prosemirror-transform.d.ts +35 -0
- package/types/spec.d.ts +43 -0
- package/types/toastmark.d.ts +361 -0
- package/types/toastui-editor-viewer.d.ts +39 -0
- package/types/ui.d.ts +171 -0
- package/types/wysiwyg.d.ts +46 -0
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@techie_doubts/tui.editor.2026",
|
|
3
|
+
"version": "3.2.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "GFM Markdown Wysiwyg Editor - Productive and Extensible",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"nhn",
|
|
10
|
+
"nhn cloud",
|
|
11
|
+
"toast",
|
|
12
|
+
"toastui",
|
|
13
|
+
"toast-ui",
|
|
14
|
+
"markdown",
|
|
15
|
+
"wysiwyg",
|
|
16
|
+
"editor",
|
|
17
|
+
"preview",
|
|
18
|
+
"gfm"
|
|
19
|
+
],
|
|
20
|
+
"main": "dist/td-editor.js",
|
|
21
|
+
"module": "dist/esm/",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/esm/index.js",
|
|
25
|
+
"require": "./dist/td-editor.js"
|
|
26
|
+
},
|
|
27
|
+
"./viewer": {
|
|
28
|
+
"import": "./dist/esm/indexViewer.js",
|
|
29
|
+
"require": "./dist/td-editor-viewer.js"
|
|
30
|
+
},
|
|
31
|
+
"./dist/i18n/*": {
|
|
32
|
+
"import": "./dist/esm/i18n/*.js",
|
|
33
|
+
"require": "./dist/i18n/*.js"
|
|
34
|
+
},
|
|
35
|
+
"./dist/td-editor-viewer": "./dist/td-editor-viewer.js",
|
|
36
|
+
"./dist/td-editor.css": "./dist/td-editor.css",
|
|
37
|
+
"./dist/td-editor-viewer.css": "./dist/td-editor-viewer.css",
|
|
38
|
+
"./dist/td-editor-only.css": "./dist/td-editor-only.css",
|
|
39
|
+
"./dist/theme/td-editor-dark.css": "./dist/theme/td-editor-dark.css",
|
|
40
|
+
"./td-editor.css": "./dist/td-editor.css",
|
|
41
|
+
"./td-editor-viewer.css": "./dist/td-editor-viewer.css",
|
|
42
|
+
"./td-editor-only.css": "./dist/td-editor-only.css",
|
|
43
|
+
"./td-editor-dark.css": "./dist/theme/td-editor-dark.css"
|
|
44
|
+
},
|
|
45
|
+
"types": "types/index.d.ts",
|
|
46
|
+
"files": [
|
|
47
|
+
"dist/*.js",
|
|
48
|
+
"dist/*.css",
|
|
49
|
+
"dist/theme",
|
|
50
|
+
"dist/esm",
|
|
51
|
+
"dist/i18n",
|
|
52
|
+
"types"
|
|
53
|
+
],
|
|
54
|
+
"author": "NHN Cloud FE Development Lab <dl_javascript@nhn.com>",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/nhn/tui.editor.git",
|
|
59
|
+
"directory": "apps/editor"
|
|
60
|
+
},
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/nhn/tui.editor/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://ui.toast.com",
|
|
65
|
+
"browserslist": "last 2 versions, not ie <= 10",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"lint": "eslint .",
|
|
68
|
+
"test:types": "tsc",
|
|
69
|
+
"test": "jest --watch",
|
|
70
|
+
"test:ci": "jest",
|
|
71
|
+
"serve": "webpack serve",
|
|
72
|
+
"serve:ie": "webpack serve",
|
|
73
|
+
"build:i18n": "cross-env webpack --config scripts/webpack.config.i18n.js && webpack --config scripts/webpack.config.i18n.js --env minify",
|
|
74
|
+
"build:prod": "cross-env webpack build && webpack build --env minify && node tsBannerGenerator.js",
|
|
75
|
+
"build": "npm run build:esm && npm run build:i18n && npm run build:prod",
|
|
76
|
+
"build:esm": "rollup -c",
|
|
77
|
+
"note": "tui-note --tag=$(git describe --tags)",
|
|
78
|
+
"ts2js": "tsc --outDir tmpdoc --sourceMap false --target ES2015 --noEmit false",
|
|
79
|
+
"doc:dev": "npm run ts2js && tuidoc --serv",
|
|
80
|
+
"doc": "npm run ts2js && tuidoc"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@techie_doubts/tui.release-notes.2026": "^2.0.1",
|
|
84
|
+
"@types/dompurify": "2.3.3",
|
|
85
|
+
"cross-env": "^6.0.3"
|
|
86
|
+
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"dompurify": "^2.3.3",
|
|
89
|
+
"prosemirror-commands": "1.5.0",
|
|
90
|
+
"prosemirror-history": "1.3.0",
|
|
91
|
+
"prosemirror-inputrules": "1.2.1",
|
|
92
|
+
"prosemirror-keymap": "1.2.0",
|
|
93
|
+
"prosemirror-model": "1.17.0",
|
|
94
|
+
"prosemirror-state": "1.3.4",
|
|
95
|
+
"prosemirror-view": "1.18.1"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { NodeType, MarkType, Schema, ProsemirrorNode, Mark } from 'prosemirror-model';
|
|
2
|
+
import { MdNode, MdNodeType, RendererOptions, HTMLToken, MdPos } from './toastmark';
|
|
3
|
+
import { WwNodeType, WwMarkType } from './wysiwyg';
|
|
4
|
+
|
|
5
|
+
export type Attrs = { [name: string]: any } | null;
|
|
6
|
+
|
|
7
|
+
export interface StackItem {
|
|
8
|
+
type: NodeType;
|
|
9
|
+
attrs: Attrs | null;
|
|
10
|
+
content: ProsemirrorNode[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ToWwConvertorState {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
top(): StackItem;
|
|
16
|
+
push(node: ProsemirrorNode): void;
|
|
17
|
+
addText(text: string): void;
|
|
18
|
+
openMark(mark: Mark): void;
|
|
19
|
+
closeMark(mark: MarkType): void;
|
|
20
|
+
addNode(type: NodeType, attrs?: Attrs, content?: ProsemirrorNode[]): ProsemirrorNode | null;
|
|
21
|
+
openNode(type: NodeType, attrs?: Attrs): void;
|
|
22
|
+
closeNode(): ProsemirrorNode | null;
|
|
23
|
+
convertNode(mdNode: MdNode, infoForPosSync: InfoForPosSync): ProsemirrorNode | null;
|
|
24
|
+
convertByDOMParser(root: HTMLElement): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ToWwConvertor = (
|
|
28
|
+
state: ToWwConvertorState,
|
|
29
|
+
node: MdNode,
|
|
30
|
+
context: {
|
|
31
|
+
entering: boolean;
|
|
32
|
+
skipChildren: () => void;
|
|
33
|
+
leaf: boolean;
|
|
34
|
+
options: Omit<RendererOptions, 'convertors'>;
|
|
35
|
+
getChildrenText: (mdNode: MdNode) => string;
|
|
36
|
+
origin?: () => HTMLToken | HTMLToken[] | null;
|
|
37
|
+
},
|
|
38
|
+
customAttrs?: { htmlAttrs?: Record<string, any>; classNames?: string[] }
|
|
39
|
+
) => void;
|
|
40
|
+
|
|
41
|
+
export type ToWwConvertorMap = Partial<Record<string, ToWwConvertor>>;
|
|
42
|
+
|
|
43
|
+
export type FirstDelimFn = (index: number) => string;
|
|
44
|
+
|
|
45
|
+
export interface ToMdConvertorState {
|
|
46
|
+
stopNewline: boolean;
|
|
47
|
+
inTable: boolean;
|
|
48
|
+
getDelim(): string;
|
|
49
|
+
setDelim(delim: string): void;
|
|
50
|
+
flushClose(size?: number): void;
|
|
51
|
+
wrapBlock(delim: string, firstDelim: string | null, node: ProsemirrorNode, fn: () => void): void;
|
|
52
|
+
ensureNewLine(): void;
|
|
53
|
+
write(content?: string): void;
|
|
54
|
+
closeBlock(node: ProsemirrorNode): void;
|
|
55
|
+
text(text: string, escaped?: boolean): void;
|
|
56
|
+
convertBlock(node: ProsemirrorNode, parent: ProsemirrorNode, index: number): void;
|
|
57
|
+
convertInline(parent: ProsemirrorNode): void;
|
|
58
|
+
convertList(node: ProsemirrorNode, delim: string, firstDelimFn: FirstDelimFn): void;
|
|
59
|
+
convertTableCell(node: ProsemirrorNode): void;
|
|
60
|
+
convertNode(parent: ProsemirrorNode, infoForPosSync?: InfoForPosSync): string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ToDOMAdaptor {
|
|
64
|
+
getToDOMNode(type: string): ((node: ProsemirrorNode | Mark) => Node) | null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type HTMLToWwConvertor = (state: ToWwConvertorState, node: MdNode, openTagName: string) => void;
|
|
68
|
+
|
|
69
|
+
export type HTMLToWwConvertorMap = Partial<Record<string, HTMLToWwConvertor>>;
|
|
70
|
+
|
|
71
|
+
export interface FlattenHTMLToWwConvertorMap {
|
|
72
|
+
[k: string]: HTMLToWwConvertor;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface NodeInfo {
|
|
76
|
+
node: ProsemirrorNode;
|
|
77
|
+
parent?: ProsemirrorNode;
|
|
78
|
+
index?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface MarkInfo {
|
|
82
|
+
node: Mark;
|
|
83
|
+
parent?: ProsemirrorNode;
|
|
84
|
+
index?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface ToMdConvertorReturnValues {
|
|
88
|
+
delim?: string | string[];
|
|
89
|
+
rawHTML?: string | string[] | null;
|
|
90
|
+
text?: string;
|
|
91
|
+
attrs?: Attrs;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type ToMdNodeTypeWriter = (
|
|
95
|
+
state: ToMdConvertorState,
|
|
96
|
+
nodeInfo: NodeInfo,
|
|
97
|
+
params: ToMdConvertorReturnValues
|
|
98
|
+
) => void;
|
|
99
|
+
|
|
100
|
+
export type ToMdNodeTypeWriterMap = Partial<Record<WwNodeType, ToMdNodeTypeWriter>>;
|
|
101
|
+
|
|
102
|
+
interface ToMdMarkTypeOption {
|
|
103
|
+
mixable?: boolean;
|
|
104
|
+
removedEnclosingWhitespace?: boolean;
|
|
105
|
+
escape?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type ToMdMarkTypeOptions = Partial<Record<WwMarkType, ToMdMarkTypeOption | null>>;
|
|
109
|
+
|
|
110
|
+
type ToMdNodeTypeConvertor = (state: ToMdConvertorState, nodeInfo: NodeInfo) => void;
|
|
111
|
+
|
|
112
|
+
export type ToMdNodeTypeConvertorMap = Partial<Record<WwNodeType, ToMdNodeTypeConvertor>>;
|
|
113
|
+
|
|
114
|
+
type ToMdMarkTypeConvertor = (
|
|
115
|
+
nodeInfo?: MarkInfo,
|
|
116
|
+
entering?: boolean
|
|
117
|
+
) => ToMdConvertorReturnValues & ToMdMarkTypeOption;
|
|
118
|
+
|
|
119
|
+
export type ToMdMarkTypeConvertorMap = Partial<Record<WwMarkType, ToMdMarkTypeConvertor>>;
|
|
120
|
+
|
|
121
|
+
interface ToMdConvertorContext {
|
|
122
|
+
origin?: () => ReturnType<ToMdConvertor>;
|
|
123
|
+
entering?: boolean;
|
|
124
|
+
inTable?: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type ToMdConvertor = (
|
|
128
|
+
nodeInfo: NodeInfo | MarkInfo,
|
|
129
|
+
context: ToMdConvertorContext
|
|
130
|
+
) => ToMdConvertorReturnValues;
|
|
131
|
+
|
|
132
|
+
export type ToMdConvertorMap = Partial<Record<WwNodeType | MdNodeType, ToMdConvertor>>;
|
|
133
|
+
|
|
134
|
+
export interface ToMdConvertors {
|
|
135
|
+
nodeTypeConvertors: ToMdNodeTypeConvertorMap;
|
|
136
|
+
markTypeConvertors: ToMdMarkTypeConvertorMap;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface InfoForPosSync {
|
|
140
|
+
node: MdNode | ProsemirrorNode | null;
|
|
141
|
+
setMappedPos: (pos: MdPos | number) => void;
|
|
142
|
+
}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Schema, NodeSpec, MarkSpec, Fragment } from 'prosemirror-model';
|
|
2
|
+
import { EditorView, Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import { EditorState, Plugin, PluginKey, Selection, TextSelection } from 'prosemirror-state';
|
|
4
|
+
import { undoInputRule, InputRule, inputRules } from 'prosemirror-inputrules';
|
|
5
|
+
import { keymap } from 'prosemirror-keymap';
|
|
6
|
+
import { Editor } from '@t/index';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
HTMLConvertor,
|
|
10
|
+
MdPos,
|
|
11
|
+
Sourcepos,
|
|
12
|
+
Context as MdContext,
|
|
13
|
+
HTMLToken,
|
|
14
|
+
HTMLConvertorMap,
|
|
15
|
+
} from './toastmark';
|
|
16
|
+
import { Emitter, Handler } from './event';
|
|
17
|
+
import { Context, EditorAllCommandMap, EditorCommandFn, SpecManager } from './spec';
|
|
18
|
+
import { ToMdConvertorMap } from './convertor';
|
|
19
|
+
import { ToolbarItemOptions, IndexList } from './ui';
|
|
20
|
+
import { CommandFn, PluginInfo } from './plugin';
|
|
21
|
+
import { HTMLMdNode } from './markdown';
|
|
22
|
+
|
|
23
|
+
export type PreviewStyle = 'tab' | 'vertical';
|
|
24
|
+
export type EditorType = 'markdown' | 'wysiwyg';
|
|
25
|
+
export type WidgetStyle = 'top' | 'bottom';
|
|
26
|
+
export interface WidgetRule {
|
|
27
|
+
rule: RegExp;
|
|
28
|
+
toDOM: (text: string) => HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type WidgetRuleMap = Record<string, WidgetRule>;
|
|
32
|
+
|
|
33
|
+
export interface EventMap {
|
|
34
|
+
load?: (param: Editor) => void;
|
|
35
|
+
change?: (editorType: EditorType) => void;
|
|
36
|
+
caretChange?: (editorType: EditorType) => void;
|
|
37
|
+
focus?: (editorType: EditorType) => void;
|
|
38
|
+
blur?: (editorType: EditorType) => void;
|
|
39
|
+
keydown?: (editorType: EditorType, ev: KeyboardEvent) => void;
|
|
40
|
+
keyup?: (editorType: EditorType, ev: KeyboardEvent) => void;
|
|
41
|
+
beforePreviewRender?: (html: string) => string;
|
|
42
|
+
beforeConvertWysiwygToMarkdown?: (markdownText: string) => string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type HookCallback = (url: string, text?: string) => void;
|
|
46
|
+
|
|
47
|
+
export type HookMap = {
|
|
48
|
+
addImageBlobHook?: (blob: Blob | File, callback: HookCallback) => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type AutolinkParser = (
|
|
52
|
+
content: string
|
|
53
|
+
) => {
|
|
54
|
+
url: string;
|
|
55
|
+
text: string;
|
|
56
|
+
range: [number, number];
|
|
57
|
+
}[];
|
|
58
|
+
|
|
59
|
+
export type ExtendedAutolinks = boolean | AutolinkParser;
|
|
60
|
+
|
|
61
|
+
export type LinkAttributeNames = 'rel' | 'target' | 'hreflang' | 'type';
|
|
62
|
+
|
|
63
|
+
// @TODO change option and type name from singular to plural
|
|
64
|
+
export type LinkAttributes = Partial<Record<LinkAttributeNames, string>>;
|
|
65
|
+
|
|
66
|
+
export type Sanitizer = (content: string) => string;
|
|
67
|
+
|
|
68
|
+
export type HTMLMdNodeConvertor = (
|
|
69
|
+
node: HTMLMdNode,
|
|
70
|
+
context: MdContext,
|
|
71
|
+
convertors?: HTMLConvertorMap
|
|
72
|
+
) => HTMLToken | HTMLToken[] | null;
|
|
73
|
+
|
|
74
|
+
export type HTMLMdNodeConvertorMap = Record<string, HTMLMdNodeConvertor>;
|
|
75
|
+
|
|
76
|
+
export type CustomHTMLRenderer = Partial<Record<string, HTMLConvertor | HTMLMdNodeConvertorMap>>;
|
|
77
|
+
|
|
78
|
+
export interface ViewerOptions {
|
|
79
|
+
el: HTMLElement;
|
|
80
|
+
initialValue?: string;
|
|
81
|
+
events?: EventMap;
|
|
82
|
+
plugins?: EditorPlugin[];
|
|
83
|
+
extendedAutolinks?: ExtendedAutolinks;
|
|
84
|
+
linkAttributes?: LinkAttributes;
|
|
85
|
+
customHTMLRenderer?: CustomHTMLRenderer;
|
|
86
|
+
referenceDefinition?: boolean;
|
|
87
|
+
customHTMLSanitizer?: Sanitizer;
|
|
88
|
+
frontMatter?: boolean;
|
|
89
|
+
usageStatistics?: boolean;
|
|
90
|
+
theme?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class Viewer {
|
|
94
|
+
static isViewer: boolean;
|
|
95
|
+
|
|
96
|
+
constructor(options: ViewerOptions);
|
|
97
|
+
|
|
98
|
+
setMarkdown(markdown: string): void;
|
|
99
|
+
|
|
100
|
+
on(type: string, handler: Handler): void;
|
|
101
|
+
|
|
102
|
+
off(type: string): void;
|
|
103
|
+
|
|
104
|
+
destroy(): void;
|
|
105
|
+
|
|
106
|
+
isViewer(): boolean;
|
|
107
|
+
|
|
108
|
+
isMarkdownMode(): boolean;
|
|
109
|
+
|
|
110
|
+
isWysiwygMode(): boolean;
|
|
111
|
+
|
|
112
|
+
addHook(type: string, handler: Handler): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface I18n {
|
|
116
|
+
setCode(code?: string): void;
|
|
117
|
+
|
|
118
|
+
setLanguage(codes: string | string[], data: Record<string, string>): void;
|
|
119
|
+
|
|
120
|
+
get(key: string, code?: string): string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface PluginContext {
|
|
124
|
+
eventEmitter: Emitter;
|
|
125
|
+
usageStatistics?: boolean;
|
|
126
|
+
i18n: I18n;
|
|
127
|
+
instance: Editor | Viewer;
|
|
128
|
+
pmState: {
|
|
129
|
+
Plugin: typeof Plugin;
|
|
130
|
+
PluginKey: typeof PluginKey;
|
|
131
|
+
Selection: typeof Selection;
|
|
132
|
+
TextSelection: typeof TextSelection;
|
|
133
|
+
};
|
|
134
|
+
pmView: { Decoration: typeof Decoration; DecorationSet: typeof DecorationSet };
|
|
135
|
+
pmModel: { Fragment: typeof Fragment };
|
|
136
|
+
pmRules: {
|
|
137
|
+
inputRules: typeof inputRules;
|
|
138
|
+
InputRule: typeof InputRule;
|
|
139
|
+
undoInputRule: typeof undoInputRule;
|
|
140
|
+
};
|
|
141
|
+
pmKeymap: {
|
|
142
|
+
keymap: typeof keymap;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type PluginFn = (context: PluginContext, options?: any) => PluginInfo | null;
|
|
147
|
+
export type EditorPlugin = PluginFn | [PluginFn, any];
|
|
148
|
+
type ContextInfo = {
|
|
149
|
+
eventEmitter: Emitter;
|
|
150
|
+
usageStatistics: boolean;
|
|
151
|
+
instance: Editor | Viewer;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type EditorPluginInfo = ContextInfo & {
|
|
155
|
+
plugin: EditorPlugin;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type EditorPluginsInfo = ContextInfo & {
|
|
159
|
+
plugins: EditorPlugin[];
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export interface EditorOptions {
|
|
163
|
+
el: HTMLElement;
|
|
164
|
+
height?: string;
|
|
165
|
+
minHeight?: string;
|
|
166
|
+
initialValue?: string;
|
|
167
|
+
previewStyle?: PreviewStyle;
|
|
168
|
+
initialEditType?: EditorType;
|
|
169
|
+
events?: EventMap;
|
|
170
|
+
hooks?: HookMap;
|
|
171
|
+
language?: string;
|
|
172
|
+
useCommandShortcut?: boolean;
|
|
173
|
+
usageStatistics?: boolean;
|
|
174
|
+
toolbarItems?: (string | ToolbarItemOptions)[][];
|
|
175
|
+
hideModeSwitch?: boolean;
|
|
176
|
+
plugins?: EditorPlugin[];
|
|
177
|
+
extendedAutolinks?: ExtendedAutolinks;
|
|
178
|
+
placeholder?: string;
|
|
179
|
+
linkAttributes?: LinkAttributes;
|
|
180
|
+
customHTMLRenderer?: CustomHTMLRenderer;
|
|
181
|
+
customMarkdownRenderer?: ToMdConvertorMap;
|
|
182
|
+
referenceDefinition?: boolean;
|
|
183
|
+
customHTMLSanitizer?: Sanitizer;
|
|
184
|
+
previewHighlight?: boolean;
|
|
185
|
+
frontMatter?: boolean;
|
|
186
|
+
widgetRules?: WidgetRule[];
|
|
187
|
+
theme?: string;
|
|
188
|
+
autofocus?: boolean;
|
|
189
|
+
viewer?: boolean;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface Slots {
|
|
193
|
+
mdEditor: HTMLElement;
|
|
194
|
+
mdPreview: HTMLElement;
|
|
195
|
+
wwEditor: HTMLElement;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class EditorCore {
|
|
199
|
+
constructor(options: EditorOptions);
|
|
200
|
+
|
|
201
|
+
public eventEmitter: Emitter;
|
|
202
|
+
|
|
203
|
+
public static factory(options: EditorOptions): EditorCore | Viewer;
|
|
204
|
+
|
|
205
|
+
public static setLanguage(code: string, data: Record<string, string>): void;
|
|
206
|
+
|
|
207
|
+
changePreviewStyle(style: PreviewStyle): void;
|
|
208
|
+
|
|
209
|
+
exec(name: string, payload?: Record<string, any>): void;
|
|
210
|
+
|
|
211
|
+
addCommand(type: EditorType, name: string, command: CommandFn): void;
|
|
212
|
+
|
|
213
|
+
on(type: string, handler: Handler): void;
|
|
214
|
+
|
|
215
|
+
off(type: string): void;
|
|
216
|
+
|
|
217
|
+
addHook(type: string, handler: Handler): void;
|
|
218
|
+
|
|
219
|
+
removeHook(type: string): void;
|
|
220
|
+
|
|
221
|
+
focus(): void;
|
|
222
|
+
|
|
223
|
+
blur(): void;
|
|
224
|
+
|
|
225
|
+
moveCursorToEnd(focus?: boolean): void;
|
|
226
|
+
|
|
227
|
+
moveCursorToStart(focus?: boolean): void;
|
|
228
|
+
|
|
229
|
+
setMarkdown(markdown: string, cursorToEnd?: boolean): void;
|
|
230
|
+
|
|
231
|
+
setHTML(html: string, cursorToEnd?: boolean): void;
|
|
232
|
+
|
|
233
|
+
getMarkdown(): string;
|
|
234
|
+
|
|
235
|
+
getHTML(): string;
|
|
236
|
+
|
|
237
|
+
insertText(text: string): void;
|
|
238
|
+
|
|
239
|
+
setSelection(start: EditorPos, end?: EditorPos): void;
|
|
240
|
+
|
|
241
|
+
replaceSelection(text: string, start?: EditorPos, end?: EditorPos): void;
|
|
242
|
+
|
|
243
|
+
deleteSelection(start?: EditorPos, end?: EditorPos): void;
|
|
244
|
+
|
|
245
|
+
getSelectedText(start?: EditorPos, end?: EditorPos): string;
|
|
246
|
+
|
|
247
|
+
getRangeInfoOfNode(pos?: EditorPos): NodeRangeInfo;
|
|
248
|
+
|
|
249
|
+
addWidget(node: Node, style: WidgetStyle, pos?: EditorPos): void;
|
|
250
|
+
|
|
251
|
+
replaceWithWidget(start: EditorPos, end: EditorPos, text: string): void;
|
|
252
|
+
|
|
253
|
+
setHeight(height: string): void;
|
|
254
|
+
|
|
255
|
+
getHeight(): string;
|
|
256
|
+
|
|
257
|
+
setMinHeight(minHeight: string): void;
|
|
258
|
+
|
|
259
|
+
getMinHeight(): string;
|
|
260
|
+
|
|
261
|
+
isMarkdownMode(): boolean;
|
|
262
|
+
|
|
263
|
+
isWysiwygMode(): boolean;
|
|
264
|
+
|
|
265
|
+
isViewer(): boolean;
|
|
266
|
+
|
|
267
|
+
getCurrentPreviewStyle(): PreviewStyle;
|
|
268
|
+
|
|
269
|
+
changeMode(mode: EditorType, isWithoutFocus?: boolean): void;
|
|
270
|
+
|
|
271
|
+
destroy(): void;
|
|
272
|
+
|
|
273
|
+
hide(): void;
|
|
274
|
+
|
|
275
|
+
show(): void;
|
|
276
|
+
|
|
277
|
+
setScrollTop(value: number): void;
|
|
278
|
+
|
|
279
|
+
getScrollTop(): number;
|
|
280
|
+
|
|
281
|
+
reset(): void;
|
|
282
|
+
|
|
283
|
+
getSelection(): SelectionPos;
|
|
284
|
+
|
|
285
|
+
setPlaceholder(placeholder: string): void;
|
|
286
|
+
|
|
287
|
+
getEditorElements(): Slots;
|
|
288
|
+
|
|
289
|
+
convertPosToMatchEditorMode(start: EditorPos, end?: EditorPos, mode?: EditorType): EditorPos[];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class Editor extends EditorCore {
|
|
293
|
+
insertToolbarItem({ groupIndex, itemIndex }: IndexList, item: string | ToolbarItemOptions): void;
|
|
294
|
+
|
|
295
|
+
removeToolbarItem(itemName: string): void;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export type SelectionPos = Sourcepos | [from: number, to: number];
|
|
299
|
+
export type EditorPos = MdPos | number;
|
|
300
|
+
export interface NodeRangeInfo {
|
|
301
|
+
range: SelectionPos;
|
|
302
|
+
type: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface Base {
|
|
306
|
+
el: HTMLElement;
|
|
307
|
+
|
|
308
|
+
editorType: EditorType;
|
|
309
|
+
|
|
310
|
+
eventEmitter: Emitter;
|
|
311
|
+
|
|
312
|
+
context: Context;
|
|
313
|
+
|
|
314
|
+
schema: Schema;
|
|
315
|
+
|
|
316
|
+
keymaps: Plugin[];
|
|
317
|
+
|
|
318
|
+
view: EditorView;
|
|
319
|
+
|
|
320
|
+
commands: EditorAllCommandMap;
|
|
321
|
+
|
|
322
|
+
specs: SpecManager;
|
|
323
|
+
|
|
324
|
+
placeholder: { text: string };
|
|
325
|
+
|
|
326
|
+
createSpecs(): SpecManager;
|
|
327
|
+
|
|
328
|
+
createContext(): Context;
|
|
329
|
+
|
|
330
|
+
createState(): EditorState;
|
|
331
|
+
|
|
332
|
+
createView(): EditorView;
|
|
333
|
+
|
|
334
|
+
createSchema(): Schema;
|
|
335
|
+
|
|
336
|
+
createKeymaps(useCommandShortcut: boolean): Plugin<any, any>[];
|
|
337
|
+
|
|
338
|
+
createCommands(): Record<string, EditorCommandFn<Record<string, any>>>;
|
|
339
|
+
|
|
340
|
+
focus(): void;
|
|
341
|
+
|
|
342
|
+
blur(): void;
|
|
343
|
+
|
|
344
|
+
destroy(): void;
|
|
345
|
+
|
|
346
|
+
moveCursorToStart(focus: boolean): void;
|
|
347
|
+
|
|
348
|
+
moveCursorToEnd(focus: boolean): void;
|
|
349
|
+
|
|
350
|
+
setScrollTop(top: number): void;
|
|
351
|
+
|
|
352
|
+
getScrollTop(): number;
|
|
353
|
+
|
|
354
|
+
setPlaceholder(text: string): void;
|
|
355
|
+
|
|
356
|
+
setHeight(height: number): void;
|
|
357
|
+
|
|
358
|
+
setMinHeight(minHeight: number): void;
|
|
359
|
+
|
|
360
|
+
getElement(): HTMLElement;
|
|
361
|
+
|
|
362
|
+
setSelection(start: EditorPos, end?: EditorPos): void;
|
|
363
|
+
|
|
364
|
+
replaceWithWidget(start: EditorPos, end: EditorPos, text: string): void;
|
|
365
|
+
|
|
366
|
+
addWidget(node: Node, style: WidgetStyle, pos?: EditorPos): void;
|
|
367
|
+
|
|
368
|
+
replaceSelection(text: string, start?: EditorPos, end?: EditorPos): void;
|
|
369
|
+
|
|
370
|
+
deleteSelection(start?: EditorPos, end?: EditorPos): void;
|
|
371
|
+
|
|
372
|
+
getSelectedText(start?: EditorPos, end?: EditorPos): string;
|
|
373
|
+
|
|
374
|
+
getSelection(): SelectionPos;
|
|
375
|
+
|
|
376
|
+
getRangeInfoOfNode(pos?: EditorPos): NodeRangeInfo;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export type SchemaMap = Record<string, NodeSpec | MarkSpec>;
|
|
380
|
+
export interface HTMLSchemaMap {
|
|
381
|
+
nodes: SchemaMap;
|
|
382
|
+
marks: SchemaMap;
|
|
383
|
+
}
|
package/types/event.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Mapable } from './map';
|
|
2
|
+
|
|
3
|
+
export interface Handler {
|
|
4
|
+
(...args: any[]): any;
|
|
5
|
+
namespace?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Emitter {
|
|
9
|
+
listen(type: string, handler: Handler): void;
|
|
10
|
+
emit(type: string, ...args: any[]): any[];
|
|
11
|
+
emitReduce(type: string, source: any, ...args: any[]): any;
|
|
12
|
+
addEventType(type: string): void;
|
|
13
|
+
removeEventHandler(type: string, handler?: Handler): void;
|
|
14
|
+
getEvents(): Mapable<string, Handler[] | undefined>;
|
|
15
|
+
holdEventInvoke(fn: Function): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface EmitterConstructor {
|
|
19
|
+
new (): Emitter;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type EventTypes =
|
|
23
|
+
| 'afterPreviewRender'
|
|
24
|
+
| 'updatePreview'
|
|
25
|
+
| 'changeMode'
|
|
26
|
+
| 'needChangeMode'
|
|
27
|
+
| 'changeTheme'
|
|
28
|
+
| 'command'
|
|
29
|
+
| 'changePreviewStyle'
|
|
30
|
+
| 'changePreviewTabPreview'
|
|
31
|
+
| 'changePreviewTabWrite'
|
|
32
|
+
| 'scroll'
|
|
33
|
+
| 'contextmenu'
|
|
34
|
+
| 'show'
|
|
35
|
+
| 'hide'
|
|
36
|
+
| 'changeLanguage'
|
|
37
|
+
| 'changeToolbarState'
|
|
38
|
+
| 'toggleScrollSync'
|
|
39
|
+
| 'mixinTableOffsetMapPrototype'
|
|
40
|
+
| 'setFocusedNode'
|
|
41
|
+
| 'removePopupWidget'
|
|
42
|
+
| 'query'
|
|
43
|
+
// provide event for user
|
|
44
|
+
| 'openPopup'
|
|
45
|
+
| 'closePopup'
|
|
46
|
+
| 'addImageBlobHook'
|
|
47
|
+
| 'beforePreviewRender'
|
|
48
|
+
| 'beforeConvertWysiwygToMarkdown'
|
|
49
|
+
| 'load'
|
|
50
|
+
| 'loadUI'
|
|
51
|
+
| 'change'
|
|
52
|
+
| 'caretChange'
|
|
53
|
+
| 'destroy'
|
|
54
|
+
| 'focus'
|
|
55
|
+
| 'blur'
|
|
56
|
+
| 'keydown'
|
|
57
|
+
| 'keyup'
|
|
58
|
+
| 'wwUserEdit'
|
|
59
|
+
| 'beforeExportHtml'
|
|
60
|
+
| 'afterExportHtml';
|