@bireturn/word-editor 1.0.3 → 1.0.4
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 +298 -298
- package/package.json +55 -55
- package/lib/components/VirtualTable/index.d.ts +0 -19
- package/lib/components/VirtualTable/src/context-menu.d.ts +0 -16
- package/lib/components/VirtualTable/src/tool.d.ts +0 -15
- package/lib/composables/useDocumentData.d.ts +0 -10
- package/lib/composables/useEditor.d.ts +0 -5
- package/lib/core/command/CommandManager.d.ts +0 -16
- package/lib/core/command/commands/DeleteCommand.d.ts +0 -14
- package/lib/core/command/commands/FormatCommand.d.ts +0 -30
- package/lib/core/command/commands/InsertParagraphCommand.d.ts +0 -12
- package/lib/core/command/commands/InsertTextCommand.d.ts +0 -18
- package/lib/core/editor/Editor.d.ts +0 -46
- package/lib/core/editor/EditorOptions.d.ts +0 -1
- package/lib/core/history/HistoryManager.d.ts +0 -15
- package/lib/core/input/InputHandler.d.ts +0 -20
- package/lib/core/model/DocumentModel.d.ts +0 -38
- package/lib/core/selection/SelectionManager.d.ts +0 -26
- package/lib/index.d.ts +0 -10
- package/lib/types/command.d.ts +0 -57
- package/lib/types/document.d.ts +0 -105
- package/lib/types/index.d.ts +0 -4
- package/lib/types/plugin.d.ts +0 -12
- package/lib/types/selection.d.ts +0 -17
- package/lib/utils/catalog.d.ts +0 -29
- package/lib/utils/nanoid.d.ts +0 -1
- package/lib/utils/titleIndex.d.ts +0 -11
- package/lib/word-editor.css +0 -1
- package/lib/word-editor.es.js +0 -2819
- package/lib/word-editor.umd.js +0 -2
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@bireturn/word-editor",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "类 Word 的 Web 富文本编辑器,基于canvas-editor的数据结构渲染",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"files": [
|
|
7
|
-
"lib"
|
|
8
|
-
],
|
|
9
|
-
"main": "./lib/word-editor.umd.js",
|
|
10
|
-
"module": "./lib/word-editor.es.js",
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"types": "./lib/index.d.ts",
|
|
15
|
-
"import": "./lib/word-editor.es.js",
|
|
16
|
-
"require": "./lib/word-editor.umd.js"
|
|
17
|
-
},
|
|
18
|
-
"./style.css": "./lib/word-editor.css"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"dev": "vite",
|
|
22
|
-
"build": "vue-tsc && vite build",
|
|
23
|
-
"build:lib": "vite build --mode lib",
|
|
24
|
-
"preview": "vite preview",
|
|
25
|
-
"lint": "eslint . --ext .vue,.ts,.tsx --fix",
|
|
26
|
-
"type-check": "vue-tsc --noEmit"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"vue": "^3.4.0"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@vueuse/core": "^10.7.0",
|
|
33
|
-
"lodash-es": "^4.18.1",
|
|
34
|
-
"lucide-vue-next": "^1.0.0",
|
|
35
|
-
"pinia": "^2.1.7",
|
|
36
|
-
"vue-virtual-scroller": "^2.0.0-beta.8"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/node": "^20.11.0",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
41
|
-
"@typescript-eslint/parser": "^7.0.0",
|
|
42
|
-
"@vitejs/plugin-vue": "^5.0.3",
|
|
43
|
-
"@vitejs/plugin-vue-jsx": "^5.1.5",
|
|
44
|
-
"@vue/tsconfig": "^0.5.1",
|
|
45
|
-
"eslint": "^8.57.0",
|
|
46
|
-
"eslint-plugin-vue": "^9.21.0",
|
|
47
|
-
"less": "^4.6.4",
|
|
48
|
-
"typescript": "^5.3.3",
|
|
49
|
-
"vite": "^5.1.0",
|
|
50
|
-
"vite-plugin-dts": "^5.0.2",
|
|
51
|
-
"vite-plugin-mock-dev-server": "^2.1.1",
|
|
52
|
-
"vue": "^3.5.38",
|
|
53
|
-
"vue-tsc": "^2.0.0"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@bireturn/word-editor",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "类 Word 的 Web 富文本编辑器,基于canvas-editor的数据结构渲染",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"main": "./lib/word-editor.umd.js",
|
|
10
|
+
"module": "./lib/word-editor.es.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"import": "./lib/word-editor.es.js",
|
|
16
|
+
"require": "./lib/word-editor.umd.js"
|
|
17
|
+
},
|
|
18
|
+
"./style.css": "./lib/word-editor.css"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite",
|
|
22
|
+
"build": "vue-tsc && vite build",
|
|
23
|
+
"build:lib": "vite build --mode lib",
|
|
24
|
+
"preview": "vite preview",
|
|
25
|
+
"lint": "eslint . --ext .vue,.ts,.tsx --fix",
|
|
26
|
+
"type-check": "vue-tsc --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": "^3.4.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@vueuse/core": "^10.7.0",
|
|
33
|
+
"lodash-es": "^4.18.1",
|
|
34
|
+
"lucide-vue-next": "^1.0.0",
|
|
35
|
+
"pinia": "^2.1.7",
|
|
36
|
+
"vue-virtual-scroller": "^2.0.0-beta.8"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20.11.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
41
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
42
|
+
"@vitejs/plugin-vue": "^5.0.3",
|
|
43
|
+
"@vitejs/plugin-vue-jsx": "^5.1.5",
|
|
44
|
+
"@vue/tsconfig": "^0.5.1",
|
|
45
|
+
"eslint": "^8.57.0",
|
|
46
|
+
"eslint-plugin-vue": "^9.21.0",
|
|
47
|
+
"less": "^4.6.4",
|
|
48
|
+
"typescript": "^5.3.3",
|
|
49
|
+
"vite": "^5.1.0",
|
|
50
|
+
"vite-plugin-dts": "^5.0.2",
|
|
51
|
+
"vite-plugin-mock-dev-server": "^2.1.1",
|
|
52
|
+
"vue": "^3.5.38",
|
|
53
|
+
"vue-tsc": "^2.0.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { default as VirtualTable } from './src/VirtualTable.vue';
|
|
2
|
-
import { default as VirtualTableColumn } from './src/VirtualTableColumn.vue';
|
|
3
|
-
export { VirtualTable, VirtualTableColumn };
|
|
4
|
-
declare const _default: {
|
|
5
|
-
VirtualTable: any;
|
|
6
|
-
VirtualTableColumn: any;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
export interface VirtualTableInstance {
|
|
10
|
-
recalculateAllHeights: () => void;
|
|
11
|
-
forceItemUpdate: (item: any) => void;
|
|
12
|
-
isEditByRow: (row: any) => boolean;
|
|
13
|
-
getParentRow: (row: any) => any | null;
|
|
14
|
-
getRowById: (id: string | number) => any | null;
|
|
15
|
-
scrollToRow: (row: any) => void;
|
|
16
|
-
setCurrentRow: (row: any) => void;
|
|
17
|
-
setAllTreeExpand: (expand: boolean) => void;
|
|
18
|
-
setTreeExpand: (row: any, expand: boolean) => void;
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建组件实例对象
|
|
3
|
-
* 返回的实例和调用 getCurrentComponent() 返回的一致
|
|
4
|
-
* @param {*} Component
|
|
5
|
-
*/
|
|
6
|
-
export declare function createComponent(Component: any, props: any, children: any): import('vue').ComponentInternalInstance | null;
|
|
7
|
-
/**
|
|
8
|
-
* 销毁组件实例对象
|
|
9
|
-
* @param {*} ComponnetInstance 通过createComponent方法得到的组件实例对象
|
|
10
|
-
*/
|
|
11
|
-
export declare function unmountComponent(ComponnetInstance: any): void;
|
|
12
|
-
export declare const ContextMenu: (options: any) => any;
|
|
13
|
-
declare const _default: {
|
|
14
|
-
ContextMenu: (options: any) => any;
|
|
15
|
-
};
|
|
16
|
-
export default _default;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将树形结构数据按主子关系排序
|
|
3
|
-
* @param {Array} list - 原始数据列表,每个元素应包含 node_id 和 parent_id
|
|
4
|
-
* @param {string|number|null} [rootParentId] - 可选参数,指定根节点的 parent_id 值
|
|
5
|
-
* @return {Array} - 排序后的数组,保持树形结构顺序
|
|
6
|
-
*/
|
|
7
|
-
export declare function sortTreeList(list: any, rootParentId: any, treeConfig?: any): Array<any>;
|
|
8
|
-
/**
|
|
9
|
-
* 获取节点的父节点,直到找到具有className的节点,在container容器内查找
|
|
10
|
-
* @param target
|
|
11
|
-
* @param className
|
|
12
|
-
* @param container
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare function getParentNode(target: any, className: any, container: any): any;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function useDocumentData(): {
|
|
2
|
-
docData: import('..').DocumentModel;
|
|
3
|
-
flatParagraphs: import('vue').ComputedRef<{
|
|
4
|
-
id: string;
|
|
5
|
-
paragraph: import('..').Paragraph;
|
|
6
|
-
sectionIndex: number;
|
|
7
|
-
paragraphIndex: number;
|
|
8
|
-
}[]>;
|
|
9
|
-
sections: import('..').Section[];
|
|
10
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { InjectionKey } from 'vue';
|
|
2
|
-
import { Editor, EditorOptions } from '../core/editor/Editor';
|
|
3
|
-
export declare const EditorKey: InjectionKey<Editor>;
|
|
4
|
-
export declare function createEditor(options?: EditorOptions): Editor;
|
|
5
|
-
export declare function useEditor(): Editor;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CommandName, CommandPayloadMap, ICommand } from '../../types/command';
|
|
2
|
-
import { DocumentModel } from '../model/DocumentModel';
|
|
3
|
-
import { SelectionManager } from '../selection/SelectionManager';
|
|
4
|
-
import { HistoryManager } from '../history/HistoryManager';
|
|
5
|
-
type CommandFactory<N extends CommandName> = (payload: CommandPayloadMap[N]) => ICommand | null;
|
|
6
|
-
export declare class CommandManager {
|
|
7
|
-
private docModel;
|
|
8
|
-
private selectionManager;
|
|
9
|
-
private historyManager;
|
|
10
|
-
private _factories;
|
|
11
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager, historyManager: HistoryManager);
|
|
12
|
-
private _registerBuiltinCommands;
|
|
13
|
-
register<N extends CommandName>(name: N, factory: CommandFactory<N>): void;
|
|
14
|
-
exec<N extends CommandName>(name: N, payload?: CommandPayloadMap[N]): void;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ICommand } from '../../../types/command';
|
|
2
|
-
import { DocumentModel } from '../../model/DocumentModel';
|
|
3
|
-
import { SelectionManager } from '../../selection/SelectionManager';
|
|
4
|
-
type DeleteDirection = 'backward' | 'forward';
|
|
5
|
-
export declare class DeleteCommand implements ICommand {
|
|
6
|
-
private docModel;
|
|
7
|
-
private selectionManager;
|
|
8
|
-
readonly name: 'deleteBackward' | 'deleteForward';
|
|
9
|
-
private _deletedText;
|
|
10
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager, direction: DeleteDirection);
|
|
11
|
-
execute(): void;
|
|
12
|
-
undo(): void;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ICommand, CommandName } from '../../../types/command';
|
|
2
|
-
import { DocumentModel } from '../../model/DocumentModel';
|
|
3
|
-
import { SelectionManager } from '../../selection/SelectionManager';
|
|
4
|
-
import { ParagraphFormat } from '../../../types/document';
|
|
5
|
-
type FormatCommandName = Extract<CommandName, 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript' | 'fontSize' | 'fontFamily' | 'color' | 'backgroundColor' | 'textAlign' | 'lineHeight' | 'heading'>;
|
|
6
|
-
export declare class FormatCommand implements ICommand {
|
|
7
|
-
private docModel;
|
|
8
|
-
private selectionManager;
|
|
9
|
-
private _value?;
|
|
10
|
-
readonly name: FormatCommandName;
|
|
11
|
-
private _prevFormat;
|
|
12
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager, name: FormatCommandName, _value?: unknown | undefined);
|
|
13
|
-
execute(): void;
|
|
14
|
-
undo(): void;
|
|
15
|
-
private _isToggle;
|
|
16
|
-
private _getFormatKey;
|
|
17
|
-
private _getCurrentValue;
|
|
18
|
-
}
|
|
19
|
-
/** 段落格式命令 */
|
|
20
|
-
export declare class ParagraphFormatCommand implements ICommand {
|
|
21
|
-
private docModel;
|
|
22
|
-
private selectionManager;
|
|
23
|
-
private _formatKey;
|
|
24
|
-
private _value;
|
|
25
|
-
readonly name: CommandName;
|
|
26
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager, _formatKey: keyof ParagraphFormat, _value: unknown);
|
|
27
|
-
execute(): void;
|
|
28
|
-
undo(): void;
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ICommand } from '../../../types/command';
|
|
2
|
-
import { DocumentModel } from '../../model/DocumentModel';
|
|
3
|
-
import { SelectionManager } from '../../selection/SelectionManager';
|
|
4
|
-
export declare class InsertParagraphCommand implements ICommand {
|
|
5
|
-
private docModel;
|
|
6
|
-
private selectionManager;
|
|
7
|
-
readonly name: "insertParagraph";
|
|
8
|
-
private _insertedParagraphId;
|
|
9
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager);
|
|
10
|
-
execute(): void;
|
|
11
|
-
undo(): void;
|
|
12
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ICommand } from '../../../types/command';
|
|
2
|
-
import { DocumentModel } from '../../model/DocumentModel';
|
|
3
|
-
import { SelectionManager } from '../../selection/SelectionManager';
|
|
4
|
-
import { ModelPoint } from '../../../types/selection';
|
|
5
|
-
import { ElementFormat } from '../../../types/document';
|
|
6
|
-
export declare class InsertTextCommand implements ICommand {
|
|
7
|
-
private docModel;
|
|
8
|
-
private selectionManager;
|
|
9
|
-
readonly name: "insertText";
|
|
10
|
-
private _point;
|
|
11
|
-
private _text;
|
|
12
|
-
private _format;
|
|
13
|
-
constructor(docModel: DocumentModel, selectionManager: SelectionManager, point: ModelPoint, text: string, format?: ElementFormat);
|
|
14
|
-
execute(): void;
|
|
15
|
-
undo(): void;
|
|
16
|
-
canMergeWith(other: ICommand): boolean;
|
|
17
|
-
merge(other: ICommand): void;
|
|
18
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { DocumentModel } from '../model/DocumentModel';
|
|
2
|
-
import { SelectionManager } from '../selection/SelectionManager';
|
|
3
|
-
import { HistoryManager } from '../history/HistoryManager';
|
|
4
|
-
import { CommandManager } from '../command/CommandManager';
|
|
5
|
-
import { InputHandler } from '../input/InputHandler';
|
|
6
|
-
import { CommandName, CommandPayloadMap } from '../../types/command';
|
|
7
|
-
import { IPlugin } from '../../types/plugin';
|
|
8
|
-
import { DocumentModel as IDocumentModel } from '../../types/document';
|
|
9
|
-
export interface EditorOptions {
|
|
10
|
-
/** 初始文档数据 */
|
|
11
|
-
initialDocument?: Partial<IDocumentModel>;
|
|
12
|
-
/** 是否只读 */
|
|
13
|
-
readonly?: boolean;
|
|
14
|
-
/** 插件列表 */
|
|
15
|
-
plugins?: IPlugin[];
|
|
16
|
-
}
|
|
17
|
-
export declare class Editor {
|
|
18
|
-
readonly docModel: DocumentModel;
|
|
19
|
-
readonly selection: SelectionManager;
|
|
20
|
-
readonly history: HistoryManager;
|
|
21
|
-
readonly commands: CommandManager;
|
|
22
|
-
readonly input: InputHandler;
|
|
23
|
-
private _readonly;
|
|
24
|
-
private _plugins;
|
|
25
|
-
private _inputEl;
|
|
26
|
-
constructor(options?: EditorOptions);
|
|
27
|
-
/**
|
|
28
|
-
* 执行命令(外部调用入口)
|
|
29
|
-
* @example editor.exec('bold')
|
|
30
|
-
* @example editor.exec('fontSize', 18)
|
|
31
|
-
* @example editor.exec('insertText', 'hello')
|
|
32
|
-
*/
|
|
33
|
-
exec<N extends CommandName>(name: N, payload?: CommandPayloadMap[N]): void;
|
|
34
|
-
/** 挂载输入层到指定 DOM 元素 */
|
|
35
|
-
mount(el: HTMLElement): void;
|
|
36
|
-
/** 卸载输入层 */
|
|
37
|
-
unmount(): void;
|
|
38
|
-
/** 安装插件 */
|
|
39
|
-
use(plugin: IPlugin): this;
|
|
40
|
-
/** 获取序列化后的文档 JSON */
|
|
41
|
-
getJSON(): string;
|
|
42
|
-
/** 从 JSON 加载文档(清空历史) */
|
|
43
|
-
loadJSON(json: string): void;
|
|
44
|
-
get isReadonly(): boolean;
|
|
45
|
-
private _isReadCommand;
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { DocumentModel as IDocumentModel } from '../../types/document';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ICommand } from '../../types/command';
|
|
2
|
-
export declare class HistoryManager {
|
|
3
|
-
private _undoStack;
|
|
4
|
-
private _redoStack;
|
|
5
|
-
get canUndo(): boolean;
|
|
6
|
-
get canRedo(): boolean;
|
|
7
|
-
/**
|
|
8
|
-
* 推入命令(执行后调用)
|
|
9
|
-
* 支持合并连续同类命令(如连续输入文字)
|
|
10
|
-
*/
|
|
11
|
-
push(command: ICommand): void;
|
|
12
|
-
undo(): boolean;
|
|
13
|
-
redo(): boolean;
|
|
14
|
-
clear(): void;
|
|
15
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CommandManager } from '../command/CommandManager';
|
|
2
|
-
import { SelectionManager as ISelectionManager } from '../selection/SelectionManager';
|
|
3
|
-
export declare class InputHandler {
|
|
4
|
-
private _el;
|
|
5
|
-
private _commandManager;
|
|
6
|
-
private _selectionManager;
|
|
7
|
-
private _composing;
|
|
8
|
-
private _boundKeydown;
|
|
9
|
-
private _boundBeforeInput;
|
|
10
|
-
private _boundCompositionStart;
|
|
11
|
-
private _boundCompositionEnd;
|
|
12
|
-
private _boundSelectionChange;
|
|
13
|
-
constructor(commandManager: CommandManager, selectionManager: ISelectionManager);
|
|
14
|
-
attach(el: HTMLElement): void;
|
|
15
|
-
detach(): void;
|
|
16
|
-
private _onKeydown;
|
|
17
|
-
private _onBeforeInput;
|
|
18
|
-
private _onCompositionEnd;
|
|
19
|
-
private _onSelectionChange;
|
|
20
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { DocumentModel as IDocumentModel, Paragraph, Section, IElement, TextElement, ElementFormat, ParagraphFormat } from '../../types';
|
|
2
|
-
import { ModelPoint } from '../../types/selection';
|
|
3
|
-
export declare class DocumentModel {
|
|
4
|
-
readonly data: IDocumentModel;
|
|
5
|
-
constructor(initialData?: Partial<IDocumentModel>);
|
|
6
|
-
createEmptySection(): Section;
|
|
7
|
-
createEmptyParagraph(format?: ParagraphFormat): Paragraph;
|
|
8
|
-
createTextElement(value: string, format?: ElementFormat): TextElement;
|
|
9
|
-
getSectionCount(): number;
|
|
10
|
-
getParagraphCount(sectionIndex?: number): number;
|
|
11
|
-
/** 获取所有段落(展开所有 section) */
|
|
12
|
-
getAllParagraphs(): Array<{
|
|
13
|
-
paragraph: Paragraph;
|
|
14
|
-
sectionIndex: number;
|
|
15
|
-
paragraphIndex: number;
|
|
16
|
-
}>;
|
|
17
|
-
getParagraphAt(sectionIndex: number, paragraphIndex: number): Paragraph | null;
|
|
18
|
-
getElementAt(point: ModelPoint): IElement | null;
|
|
19
|
-
/** 在指定位置插入文本(拆分/合并 text element) */
|
|
20
|
-
insertText(point: ModelPoint, text: string, format?: ElementFormat): void;
|
|
21
|
-
/** 删除指定范围内容 */
|
|
22
|
-
deleteAt(point: ModelPoint, length: number): void;
|
|
23
|
-
/** 在段落后插入新段落 */
|
|
24
|
-
insertParagraph(sectionIndex: number, afterIndex: number, format?: ParagraphFormat): Paragraph;
|
|
25
|
-
/** 合并两个相邻段落 */
|
|
26
|
-
mergeParagraphs(sectionIndex: number, upperIndex: number): void;
|
|
27
|
-
/** 更新段落格式 */
|
|
28
|
-
updateParagraphFormat(sectionIndex: number, paragraphIndex: number, format: Partial<ParagraphFormat>): void;
|
|
29
|
-
/** 更新元素格式 */
|
|
30
|
-
updateElementFormat(point: ModelPoint, format: Partial<ElementFormat>): void;
|
|
31
|
-
/** 批量更新选区内元素格式 */
|
|
32
|
-
updateRangeFormat(from: ModelPoint, to: ModelPoint, format: Partial<ElementFormat>): void;
|
|
33
|
-
private bumpVersion;
|
|
34
|
-
/** 序列化为 JSON */
|
|
35
|
-
toJSON(): string;
|
|
36
|
-
/** 从 JSON 恢复 */
|
|
37
|
-
static fromJSON(json: string): DocumentModel;
|
|
38
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ModelPoint, ModelSelection } from '../../types/selection';
|
|
2
|
-
import { DocumentModel } from '../model/DocumentModel';
|
|
3
|
-
export declare class SelectionManager {
|
|
4
|
-
private _selection;
|
|
5
|
-
private _docModel;
|
|
6
|
-
constructor(docModel: DocumentModel);
|
|
7
|
-
get selection(): ModelSelection;
|
|
8
|
-
/** 是否有选区(非光标) */
|
|
9
|
-
readonly hasSelection: import('vue').ComputedRef<boolean>;
|
|
10
|
-
setCursor(point: ModelPoint): void;
|
|
11
|
-
setSelection(anchor: ModelPoint, focus: ModelPoint): void;
|
|
12
|
-
collapse(toFocus?: boolean): void;
|
|
13
|
-
selectAll(): void;
|
|
14
|
-
/** 光标向前移动一个字符 */
|
|
15
|
-
moveForward(extend?: boolean): void;
|
|
16
|
-
/** 光标向后移动一个字符 */
|
|
17
|
-
moveBackward(extend?: boolean): void;
|
|
18
|
-
private _applyMove;
|
|
19
|
-
private _getNextParagraphPoint;
|
|
20
|
-
private _getPrevParagraphPoint;
|
|
21
|
-
/**
|
|
22
|
-
* 从 DOM element 的 data-* 属性解析模型坐标
|
|
23
|
-
* 渲染时每个元素需附带 data-si/data-pi/data-ei 属性
|
|
24
|
-
*/
|
|
25
|
-
static domToModelPoint(domNode: Node, domOffset: number): ModelPoint | null;
|
|
26
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { App, DefineComponent } from 'vue';
|
|
2
|
-
export { Editor } from './core/editor/Editor';
|
|
3
|
-
export type { EditorOptions } from './core/editor/Editor';
|
|
4
|
-
export { createEditor, useEditor, EditorKey } from './composables/useEditor';
|
|
5
|
-
export declare const EditorContainer: DefineComponent<Record<string, unknown>>;
|
|
6
|
-
export type * from './types';
|
|
7
|
-
declare const _default: {
|
|
8
|
-
install(app: App): void;
|
|
9
|
-
};
|
|
10
|
-
export default _default;
|
package/lib/types/command.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ElementFormat, ParagraphFormat } from './document';
|
|
2
|
-
/** 所有可执行命令名称 */
|
|
3
|
-
export type CommandName = 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript' | 'fontSize' | 'fontFamily' | 'color' | 'backgroundColor' | 'textAlign' | 'lineHeight' | 'indent' | 'outdent' | 'heading' | 'bulletList' | 'orderedList' | 'insertText' | 'insertParagraph' | 'insertImage' | 'insertTable' | 'insertSeparator' | 'deleteContent' | 'deleteForward' | 'deleteBackward' | 'undo' | 'redo' | 'selectAll' | 'setSelection';
|
|
4
|
-
/** 命令参数映射 */
|
|
5
|
-
export interface CommandPayloadMap {
|
|
6
|
-
bold: undefined;
|
|
7
|
-
italic: undefined;
|
|
8
|
-
underline: undefined;
|
|
9
|
-
strikethrough: undefined;
|
|
10
|
-
superscript: undefined;
|
|
11
|
-
subscript: undefined;
|
|
12
|
-
fontSize: number;
|
|
13
|
-
fontFamily: string;
|
|
14
|
-
color: string;
|
|
15
|
-
backgroundColor: string;
|
|
16
|
-
textAlign: ElementFormat['color'];
|
|
17
|
-
lineHeight: number;
|
|
18
|
-
indent: undefined;
|
|
19
|
-
outdent: undefined;
|
|
20
|
-
heading: ParagraphFormat['heading'];
|
|
21
|
-
bulletList: undefined;
|
|
22
|
-
orderedList: undefined;
|
|
23
|
-
insertText: string;
|
|
24
|
-
insertParagraph: undefined;
|
|
25
|
-
insertImage: {
|
|
26
|
-
url: string;
|
|
27
|
-
width: number;
|
|
28
|
-
height: number;
|
|
29
|
-
alt?: string;
|
|
30
|
-
};
|
|
31
|
-
insertTable: {
|
|
32
|
-
rows: number;
|
|
33
|
-
cols: number;
|
|
34
|
-
};
|
|
35
|
-
insertSeparator: undefined;
|
|
36
|
-
deleteContent: undefined;
|
|
37
|
-
deleteForward: undefined;
|
|
38
|
-
deleteBackward: undefined;
|
|
39
|
-
undo: undefined;
|
|
40
|
-
redo: undefined;
|
|
41
|
-
selectAll: undefined;
|
|
42
|
-
setSelection: import('./selection').ModelSelection;
|
|
43
|
-
}
|
|
44
|
-
/** 命令执行结果 */
|
|
45
|
-
export interface CommandResult {
|
|
46
|
-
success: boolean;
|
|
47
|
-
error?: string;
|
|
48
|
-
}
|
|
49
|
-
/** 命令接口(Command Pattern) */
|
|
50
|
-
export interface ICommand {
|
|
51
|
-
name: CommandName;
|
|
52
|
-
execute(): void;
|
|
53
|
-
undo(): void;
|
|
54
|
-
/** 是否可以与相邻同类命令合并(用于连续输入合并) */
|
|
55
|
-
canMergeWith?(other: ICommand): boolean;
|
|
56
|
-
merge?(other: ICommand): void;
|
|
57
|
-
}
|
package/lib/types/document.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
export type ElementType = 'text' | 'image' | 'table' | 'hyperlink' | 'separator';
|
|
2
|
-
export type TextAlign = 'left' | 'center' | 'right' | 'justify';
|
|
3
|
-
export type VerticalAlign = 'top' | 'middle' | 'bottom';
|
|
4
|
-
export type ListType = 'bullet' | 'ordered' | 'none';
|
|
5
|
-
/** 行内元素格式属性 */
|
|
6
|
-
export interface ElementFormat {
|
|
7
|
-
bold?: boolean;
|
|
8
|
-
italic?: boolean;
|
|
9
|
-
underline?: boolean;
|
|
10
|
-
strikethrough?: boolean;
|
|
11
|
-
fontSize?: number;
|
|
12
|
-
fontFamily?: string;
|
|
13
|
-
color?: string;
|
|
14
|
-
backgroundColor?: string;
|
|
15
|
-
superscript?: boolean;
|
|
16
|
-
subscript?: boolean;
|
|
17
|
-
}
|
|
18
|
-
/** 基础元素接口 */
|
|
19
|
-
export interface BaseElement {
|
|
20
|
-
id: string;
|
|
21
|
-
type: ElementType;
|
|
22
|
-
format?: ElementFormat;
|
|
23
|
-
}
|
|
24
|
-
/** 文本元素 */
|
|
25
|
-
export interface TextElement extends BaseElement {
|
|
26
|
-
type: 'text';
|
|
27
|
-
value: string;
|
|
28
|
-
}
|
|
29
|
-
/** 图片元素 */
|
|
30
|
-
export interface ImageElement extends BaseElement {
|
|
31
|
-
type: 'image';
|
|
32
|
-
url: string;
|
|
33
|
-
width: number;
|
|
34
|
-
height: number;
|
|
35
|
-
alt?: string;
|
|
36
|
-
}
|
|
37
|
-
/** 超链接元素 */
|
|
38
|
-
export interface HyperlinkElement extends BaseElement {
|
|
39
|
-
type: 'hyperlink';
|
|
40
|
-
url: string;
|
|
41
|
-
children: TextElement[];
|
|
42
|
-
}
|
|
43
|
-
/** 分隔线元素 */
|
|
44
|
-
export interface SeparatorElement extends BaseElement {
|
|
45
|
-
type: 'separator';
|
|
46
|
-
}
|
|
47
|
-
/** 表格单元格 */
|
|
48
|
-
export interface TableCell {
|
|
49
|
-
id: string;
|
|
50
|
-
rowspan?: number;
|
|
51
|
-
colspan?: number;
|
|
52
|
-
children: Paragraph[];
|
|
53
|
-
}
|
|
54
|
-
/** 表格行 */
|
|
55
|
-
export interface TableRow {
|
|
56
|
-
id: string;
|
|
57
|
-
height?: number;
|
|
58
|
-
cells: TableCell[];
|
|
59
|
-
}
|
|
60
|
-
/** 表格元素 */
|
|
61
|
-
export interface TableElement extends BaseElement {
|
|
62
|
-
type: 'table';
|
|
63
|
-
rows: TableRow[];
|
|
64
|
-
colWidths: number[];
|
|
65
|
-
}
|
|
66
|
-
export type IElement = TextElement | ImageElement | HyperlinkElement | SeparatorElement | TableElement;
|
|
67
|
-
/** 段落格式 */
|
|
68
|
-
export interface ParagraphFormat {
|
|
69
|
-
textAlign?: TextAlign;
|
|
70
|
-
lineHeight?: number;
|
|
71
|
-
marginTop?: number;
|
|
72
|
-
marginBottom?: number;
|
|
73
|
-
paddingLeft?: number;
|
|
74
|
-
paddingRight?: number;
|
|
75
|
-
listType?: ListType;
|
|
76
|
-
listLevel?: number;
|
|
77
|
-
listIndex?: number;
|
|
78
|
-
heading?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | null;
|
|
79
|
-
}
|
|
80
|
-
/** 段落(块级容器) */
|
|
81
|
-
export interface Paragraph {
|
|
82
|
-
id: string;
|
|
83
|
-
type: 'paragraph';
|
|
84
|
-
format?: ParagraphFormat;
|
|
85
|
-
children: IElement[];
|
|
86
|
-
}
|
|
87
|
-
/** 节(用于分页/分栏)*/
|
|
88
|
-
export interface Section {
|
|
89
|
-
id: string;
|
|
90
|
-
paragraphs: Paragraph[];
|
|
91
|
-
pageBreakBefore?: boolean;
|
|
92
|
-
}
|
|
93
|
-
/** 文档根节点 */
|
|
94
|
-
export interface DocumentModel {
|
|
95
|
-
id: string;
|
|
96
|
-
version: number;
|
|
97
|
-
sections: Section[];
|
|
98
|
-
defaultFormat?: ElementFormat;
|
|
99
|
-
pageWidth?: number;
|
|
100
|
-
pageHeight?: number;
|
|
101
|
-
marginTop?: number;
|
|
102
|
-
marginBottom?: number;
|
|
103
|
-
marginLeft?: number;
|
|
104
|
-
marginRight?: number;
|
|
105
|
-
}
|
package/lib/types/index.d.ts
DELETED
package/lib/types/plugin.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Editor } from '../core/editor/Editor';
|
|
2
|
-
export interface IPlugin {
|
|
3
|
-
name: string;
|
|
4
|
-
version?: string;
|
|
5
|
-
/** 插件安装时调用,注册命令/事件/渲染扩展 */
|
|
6
|
-
install(editor: Editor): void;
|
|
7
|
-
/** 插件卸载时调用,清理副作用 */
|
|
8
|
-
uninstall?(editor: Editor): void;
|
|
9
|
-
}
|
|
10
|
-
export interface PluginOptions {
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
}
|
package/lib/types/selection.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** 模型坐标中的点 */
|
|
2
|
-
export interface ModelPoint {
|
|
3
|
-
sectionIndex: number;
|
|
4
|
-
paragraphIndex: number;
|
|
5
|
-
elementIndex: number;
|
|
6
|
-
/** 在文本节点内的字符偏移量 */
|
|
7
|
-
offset: number;
|
|
8
|
-
}
|
|
9
|
-
/** 选区(start <= end,逻辑上) */
|
|
10
|
-
export interface ModelSelection {
|
|
11
|
-
anchor: ModelPoint;
|
|
12
|
-
focus: ModelPoint;
|
|
13
|
-
/** 是否折叠(光标,非选区) */
|
|
14
|
-
isCollapsed: boolean;
|
|
15
|
-
}
|
|
16
|
-
/** 光标样式 */
|
|
17
|
-
export type CursorStyle = 'text' | 'crosshair' | 'default';
|