@agile_jy/word-editor 0.0.1-beta.2 → 0.0.1-beta.21

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.
@@ -0,0 +1,38 @@
1
+ import './dialog.css';
2
+ export interface IDialogData {
3
+ type: string;
4
+ label?: string;
5
+ name: string;
6
+ value?: string;
7
+ options?: {
8
+ label: string;
9
+ value: string;
10
+ }[];
11
+ placeholder?: string;
12
+ width?: number;
13
+ height?: number;
14
+ required?: boolean;
15
+ searchable?: boolean;
16
+ }
17
+ export interface IDialogConfirm {
18
+ name: string;
19
+ value: string;
20
+ }
21
+ export interface IDialogOptions {
22
+ onClose?: () => void;
23
+ onCancel?: () => void;
24
+ onConfirm?: (payload: IDialogConfirm[]) => void;
25
+ title: string;
26
+ data: IDialogData[];
27
+ }
28
+ export declare class Dialog {
29
+ private options;
30
+ private mask;
31
+ private container;
32
+ private inputList;
33
+ private searchDropdowns;
34
+ constructor(options: IDialogOptions);
35
+ private _render;
36
+ private _createSearchableSelect;
37
+ private _dispose;
38
+ }
@@ -97,6 +97,8 @@ export declare class Command {
97
97
  executeLocationCatalog: CommandAdapt['locationCatalog'];
98
98
  executeWordTool: CommandAdapt['wordTool'];
99
99
  executeSetHTML: CommandAdapt['setHTML'];
100
+ executeSetHtmlDocx: CommandAdapt['setHtmlDocx'];
101
+ executeImportDocx: CommandAdapt['importDocx'];
100
102
  executeSetGroup: CommandAdapt['setGroup'];
101
103
  executeDeleteGroup: CommandAdapt['deleteGroup'];
102
104
  executeLocationGroup: CommandAdapt['locationGroup'];
@@ -10,7 +10,7 @@ import { ICatalog } from '../../interface/Catalog';
10
10
  import { DeepRequired } from '../../interface/Common';
11
11
  import { IGetControlValueOption, IGetControlValueResult, ILocationControlOption, IRemoveControlOption, ISetControlExtensionOption, ISetControlHighlightOption, ISetControlProperties, ISetControlValueOption } from '../../interface/Control';
12
12
  import { IAppendElementListOption, IDrawImagePayload, IForceUpdateOption, IGetImageOption, IGetValueOption, IPainterOption } from '../../interface/Draw';
13
- import { IEditorData, IEditorHTML, IEditorOption, IEditorResult, IEditorText, IFocusOption, ISetValueOption, IUpdateOption } from '../../interface/Editor';
13
+ import { IEditorData, IEditorHTML, IEditorOption, IEditorResult, IEditorText, IFocusOption, IImportDocxOption, ISetHtmlDocxOption, ISetValueOption, IUpdateOption } from '../../interface/Editor';
14
14
  import { IDeleteElementByIdOption, IElement, IElementPosition, IGetElementByIdOption, IImageCaption, IImageCrop, IInsertElementListOption, IUpdateElementByIdOption } from '../../interface/Element';
15
15
  import { ICopyOption, IPasteOption, IPositionContextByEventOption, IPositionContextByEventResult } from '../../interface/Event';
16
16
  import { IMargin } from '../../interface/Margin';
@@ -157,6 +157,14 @@ export declare class CommandAdapt {
157
157
  locationCatalog(titleId: string): void;
158
158
  wordTool(): void;
159
159
  setHTML(payload: Partial<IEditorHTML>): void;
160
+ /**
161
+ * 解析 docx-preview 已挂载 DOM:纸张/页边距 + 段落版式,section 间插分页符
162
+ */
163
+ setHtmlDocx(payload: ISetHtmlDocxOption): void;
164
+ /**
165
+ * 导入 Word/HTML 字符串:挂载临时 DOM 后走 setHtmlDocx
166
+ */
167
+ importDocx(payload: IImportDocxOption): void;
160
168
  setGroup(): string | null;
161
169
  deleteGroup(groupId: string): void;
162
170
  getGroupIds(): Promise<string[]>;
@@ -1,6 +1,7 @@
1
1
  import './assets/css/index.css';
2
- import { IEditorData, IEditorOption, IEditorResult } from './interface/Editor';
2
+ import { IEditorData, IEditorOption, IEditorResult, IImportDocxOption } from './interface/Editor';
3
3
  import { IElement, IFormInputImage, IUpdateElementByIdOption } from './interface/Element';
4
+ import { IFormImageProperties, ISignatureImage, ISealImage, IRiskCopyImage } from '../utils';
4
5
  import { Command } from './core/command/Command';
5
6
  import { Listener } from './core/listener/Listener';
6
7
  import { RowFlex } from './dataset/enum/Row';
@@ -40,7 +41,9 @@ import { AreaMode } from './dataset/enum/Area';
40
41
  import { IBadge } from './interface/Badge';
41
42
  import { WatermarkType } from './dataset/enum/Watermark';
42
43
  import { INTERNAL_SHORTCUT_KEY } from './dataset/constant/Shortcut';
43
- import { formInputPropertiesConfigDialog, formCheckboxPropertiesConfigDialog, formRadioPropertiesConfigDialog } from '../utils';
44
+ import { formInputPropertiesConfigDialog, formCheckboxPropertiesConfigDialog, formRadioPropertiesConfigDialog, formImagePropertiesConfigDialog, formSignatureConfigDialog, formSealConfigDialog, formRiskCopyConfigDialog } from '../utils';
45
+ import { Dialog, type IDialogData, type IDialogConfirm, type IDialogOptions } from '../components/dialog/Dialog';
46
+ import docxPlugin from '../plugins/docx';
44
47
  export default class Editor {
45
48
  command: Command;
46
49
  version: string;
@@ -54,6 +57,10 @@ export default class Editor {
54
57
  showFormInputConfig(el?: IElement | null): void;
55
58
  showFormCheckboxConfig(el?: IElement | null): void;
56
59
  showFormRadioConfig(el?: IElement | null): void;
60
+ showFormImageConfig(el?: IElement | null): void;
61
+ showFormSignatureConfig(el?: IElement | null): void;
62
+ showFormSealConfig(el?: IElement | null): void;
63
+ showFormRiskCopyConfig(el?: IElement | null): void;
57
64
  /**
58
65
  * 设置外部扩展参数
59
66
  * @param key 参数键名
@@ -91,5 +98,5 @@ export default class Editor {
91
98
  export { splitText, createDomFromElementList, getElementListByHTML, getTextFromElementList };
92
99
  export { EDITOR_COMPONENT, LETTER_CLASS, INTERNAL_CONTEXT_MENU_KEY, INTERNAL_SHORTCUT_KEY, EDITOR_CLIPBOARD };
93
100
  export { Editor, RowFlex, VerticalAlign, EditorZone, EditorMode, ElementType, ControlType, EditorComponent, PageMode, RenderMode, ImageDisplay, Command, KeyMap, BlockType, PaperDirection, TableBorder, TdBorder, TdSlash, MaxHeightRatio, NumberType, TitleLevel, ListType, ListStyle, WordBreak, ControlIndentation, ControlComponent, BackgroundRepeat, BackgroundSize, TextDecorationStyle, LineNumberType, LocationPosition, AreaMode, ControlState, FlexDirection, WatermarkType };
94
- export type { IElement, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, IBadge, IGetElementListByHTMLOption, IFormInputImage, IUpdateElementByIdOption };
95
- export { formInputPropertiesConfigDialog, formCheckboxPropertiesConfigDialog, formRadioPropertiesConfigDialog };
101
+ export type { IElement, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, IBadge, IGetElementListByHTMLOption, IFormInputImage, IUpdateElementByIdOption, IFormImageProperties, ISignatureImage, ISealImage, IRiskCopyImage, IDialogData, IDialogConfirm, IDialogOptions, IImportDocxOption };
102
+ export { Dialog, docxPlugin, formInputPropertiesConfigDialog, formCheckboxPropertiesConfigDialog, formRadioPropertiesConfigDialog, formImagePropertiesConfigDialog, formSignatureConfigDialog, formSealConfigDialog, formRiskCopyConfigDialog };
@@ -114,6 +114,19 @@ export interface IEditorHTML {
114
114
  header: string;
115
115
  main: string;
116
116
  footer: string;
117
+ container?: HTMLDivElement;
118
+ }
119
+ /** docx-preview 已挂载 DOM 导入 */
120
+ export interface ISetHtmlDocxOption {
121
+ container: HTMLElement;
122
+ /** 页边距 [上, 右, 下, 左],传入则覆盖 DOM 解析结果 */
123
+ margins?: IMargin;
124
+ }
125
+ /** executeImportDocx(docx 插件)入参 */
126
+ export interface IImportDocxOption {
127
+ html: string;
128
+ /** 页边距 [上, 右, 下, 左],传入则覆盖 DOM 解析结果 */
129
+ margins?: IMargin;
117
130
  }
118
131
  export type IEditorText = IEditorHTML;
119
132
  export type IUpdateOption = Omit<IEditorOption, 'mode' | 'width' | 'height' | 'scale' | 'pageGap' | 'pageMode' | 'paperDirection' | 'historyMaxRecordCount' | 'scrollContainerSelector'>;
@@ -36,7 +36,21 @@ export interface IElementStyle {
36
36
  rowFlex?: RowFlex;
37
37
  rowMargin?: number;
38
38
  letterSpacing?: number;
39
+ wordSpacing?: number;
39
40
  textDecoration?: ITextDecoration;
41
+ verticalAlign?: string;
42
+ /** 首行缩进(px) */
43
+ textIndent?: number;
44
+ /** 段落左缩进(px) */
45
+ marginLeft?: number;
46
+ /** 段落右缩进(px) */
47
+ marginRight?: number;
48
+ /** 段前距(px) */
49
+ marginTop?: number;
50
+ /** 段落最小高度(px),空段落/空格行占位 */
51
+ minHeight?: number;
52
+ /** CSS white-space,如 pre-wrap */
53
+ whiteSpace?: string;
40
54
  }
41
55
  export interface IElementRule {
42
56
  hide?: boolean;
@@ -161,6 +175,9 @@ export interface IFormInputImage {
161
175
  txtRowAutoFlag?: string;
162
176
  txtEditFlag?: string;
163
177
  elemProp?: string;
178
+ rowNum?: string;
179
+ colNum?: string;
180
+ lineHeight?: string;
164
181
  }
165
182
  export type IImageElement = IImageBasic & IImageRule & IFormImage;
166
183
  export interface IBlockElement {
@@ -2,4 +2,6 @@ export interface IPageBreak {
2
2
  font?: string;
3
3
  fontSize?: number;
4
4
  lineDash?: number[];
5
+ /** 是否绘制分页符标记线,默认 true */
6
+ visible?: boolean;
5
7
  }
@@ -0,0 +1,24 @@
1
+ import { IElement } from '../interface/Element';
2
+ import { IMargin } from '../interface/Margin';
3
+ export interface IDocxPaperMeta {
4
+ width: number;
5
+ height: number;
6
+ margins: IMargin;
7
+ }
8
+ export interface IParseDocxDomResult {
9
+ paper: IDocxPaperMeta;
10
+ main: IElement[];
11
+ }
12
+ /** 读取 docx section 纸张与页边距(computed px) */
13
+ export declare function parseDocxPaperMeta(section: HTMLElement): IDocxPaperMeta;
14
+ /**
15
+ * 直接解析 docx-preview / 导出 HTML 已挂载 DOM:
16
+ * - 首页 section.docx 或 .ce-export-page → 纸张/页边距
17
+ * - 多 section 拼接,section 之间插入分页符以尽量保留原分页
18
+ */
19
+ export declare function parseDocxDom(container: HTMLElement): IParseDocxDomResult;
20
+ /**
21
+ * 将 HTML 字符串挂到临时 DOM,供 setHtmlDocx / importDocx 解析
22
+ * (缩进 / 段距 / 行距 / 分页符 / 纸张)
23
+ */
24
+ export declare function mountHtmlForDocx(html: string, margins?: IMargin): HTMLElement;
@@ -2,7 +2,7 @@ import { LocationPosition } from '../dataset/enum/Common';
2
2
  import { RowFlex } from '../dataset/enum/Row';
3
3
  import { DeepRequired } from '../interface/Common';
4
4
  import { IEditorOption } from '../interface/Editor';
5
- import { IElement } from '../interface/Element';
5
+ import { IElement, IElementPosition } from '../interface/Element';
6
6
  export declare function unzipElementList(elementList: IElement[]): IElement[];
7
7
  interface IFormatElementListOption {
8
8
  isHandleFirstElement?: boolean;
@@ -24,6 +24,11 @@ export declare function zipElementList(payload: IElement[], options?: IZipElemen
24
24
  export declare function convertTextAlignToRowFlex(node: HTMLElement): RowFlex;
25
25
  export declare function convertRowFlexToTextAlign(rowFlex: RowFlex): RowFlex.LEFT | RowFlex.CENTER | RowFlex.RIGHT | RowFlex.JUSTIFY | "justify";
26
26
  export declare function convertRowFlexToJustifyContent(rowFlex: RowFlex): "center" | "flex-start" | "flex-end" | "space-between";
27
+ export interface IElementListGroupRowFlex {
28
+ rowFlex: RowFlex | null;
29
+ data: IElement[];
30
+ }
31
+ export declare function groupElementListByRowFlex(elementList: IElement[]): IElementListGroupRowFlex[];
27
32
  export declare function isTextLikeElement(element: IElement): boolean;
28
33
  export declare function isTextElement(element: IElement): boolean;
29
34
  export declare function getElementListText(elementList: IElement[]): string;
@@ -36,15 +41,20 @@ export interface IFormatElementContextOption {
36
41
  export declare function formatElementContext(sourceElementList: IElement[], formatElementList: IElement[], anchorIndex: number, options?: IFormatElementContextOption): void;
37
42
  export declare function convertElementToDom(element: IElement, options: DeepRequired<IEditorOption>): HTMLElement;
38
43
  export declare function splitListElement(elementList: IElement[]): Map<number, IElement[]>;
39
- export interface IElementListGroupRowFlex {
40
- rowFlex: RowFlex | null;
41
- data: IElement[];
42
- }
43
- export declare function groupElementListByRowFlex(elementList: IElement[]): IElementListGroupRowFlex[];
44
+ /**
45
+ * 导出前:把页面坐标的 imgFloatPosition 换算为相对段落的 CSS left/top
46
+ * (data-img-float-position 仍保留页面坐标,供编辑器往返)
47
+ */
48
+ export declare function attachHtmlFloatOffset(elementList: IElement[], positionList: IElementPosition[], scale?: number): void;
49
+ export declare function clearHtmlFloatOffset(): void;
50
+ /** 从 img DOM 还原环绕属性(导入) */
51
+ export declare function applyImageWrapFromDom(img: HTMLImageElement, element: IElement): void;
44
52
  export declare function createDomFromElementList(elementList: IElement[], options?: IEditorOption): HTMLDivElement;
45
53
  export declare function convertTextNodeToElement(textNode: Element | Node): IElement | null;
46
54
  export interface IGetElementListByHTMLOption {
47
55
  innerWidth: number;
56
+ container?: HTMLDivElement;
57
+ _visitedNodes?: WeakSet<Node>;
48
58
  }
49
59
  export declare function getElementListByHTML(htmlText: string, options: IGetElementListByHTMLOption): IElement[];
50
60
  export declare function getTextFromElementList(elementList: IElement[]): string;
@@ -54,4 +64,14 @@ export declare function replaceHTMLElementTag(oldDom: HTMLElement, tagName: keyo
54
64
  export declare function pickSurroundElementList(elementList: IElement[]): IElement[];
55
65
  export declare function deleteSurroundElementList(elementList: IElement[], pageNo: number): void;
56
66
  export declare function getNonHideElementIndex(elementList: IElement[], index: number, position?: LocationPosition): number;
67
+ /**
68
+ * 将 DOM 元素转换为符合 XHTML 规范的 HTML 字符串
69
+ * 利用浏览器原生 XMLSerializer 确保标签闭合规范
70
+ * @param dom DOM 元素
71
+ * @param options.keepRoot 为 true 时保留根节点(如 .ce-export-page 纸张容器)
72
+ * @returns 符合 XHTML 规范的 HTML 字符串
73
+ */
74
+ export declare function convertToXHTML(dom: HTMLElement, options?: {
75
+ keepRoot?: boolean;
76
+ }): string;
57
77
  export {};
@@ -0,0 +1,2 @@
1
+ /** @deprecated 逻辑已迁至 editor/utils/docxHtml + CommandAdapt.importDocx */
2
+ export type { IImportDocxOption } from '../../editor/interface/Editor';
@@ -0,0 +1,8 @@
1
+ import type Editor from '../../editor';
2
+ export type { IImportDocxOption } from '../../editor/interface/Editor';
3
+ /**
4
+ * 兼容旧用法:executeImportDocx 已内置到 Command,无需再挂载。
5
+ * 保留插件导出,避免旧代码 instance.use(docxPlugin) 报错。
6
+ */
7
+ export default function docxPlugin(_editor: Editor): void;
8
+ export { docxPlugin };
@@ -0,0 +1 @@
1
+ export declare function saveAs(blob: Blob, name: string): void;
package/package.json CHANGED
@@ -1,77 +1,77 @@
1
- {
2
- "name": "@agile_jy/word-editor",
3
- "author": "JIANGYONG",
4
- "license": "MIT",
5
- "version": "0.0.1-beta.2",
6
- "description": "rich text editor by canvas/svg",
7
- "publishConfig": {
8
- "registry": "https://registry.npmjs.org/",
9
- "access": "public"
10
- },
11
- "files": [
12
- "dist",
13
- "README.md",
14
- "CHANGELOG.md",
15
- "LICENSE",
16
- "package.json"
17
- ],
18
- "typings": "./dist/src/editor/index.d.ts",
19
- "main": "./dist/canvas-editor.umd.js",
20
- "module": "./dist/canvas-editor.es.js",
21
- "homepage": "https://github.com/Hufe921/canvas-editor",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/Hufe921/canvas-editor.git"
25
- },
26
- "keywords": [
27
- "canvas-editor",
28
- "editor",
29
- "wysiwyg",
30
- "emr"
31
- ],
32
- "engines": {
33
- "node": ">=16.9.1"
34
- },
35
- "type": "module",
36
- "scripts": {
37
- "dev": "vite",
38
- "lib": "npm run lint && tsc && vite build --mode lib",
39
- "build": "npm run lint && tsc && vite build --mode app",
40
- "serve": "vite preview",
41
- "lint": "eslint .",
42
- "cypress:open": "cypress open",
43
- "cypress:run": "cypress run",
44
- "type:check": "tsc --noEmit",
45
- "docs:dev": "vitepress dev docs",
46
- "docs:build": "vitepress build docs",
47
- "docs:preview": "vitepress preview docs",
48
- "postinstall": "simple-git-hooks",
49
- "release": "node scripts/release.js"
50
- },
51
- "devDependencies": {
52
- "@rollup/plugin-typescript": "^10.0.1",
53
- "@types/node": "16.18.96",
54
- "@types/prismjs": "^1.26.0",
55
- "@typescript-eslint/eslint-plugin": "5.62.0",
56
- "@typescript-eslint/parser": "5.62.0",
57
- "cypress": "13.6.0",
58
- "cypress-file-upload": "^5.0.8",
59
- "eslint": "7.32.0",
60
- "simple-git-hooks": "^2.8.1",
61
- "typescript": "4.9.5",
62
- "vite": "^2.4.2",
63
- "vite-plugin-css-injected-by-js": "^2.1.1",
64
- "vitepress": "1.0.0-beta.6",
65
- "@types/color": "^3.0.4"
66
- },
67
- "dependencies": {
68
- "color": "^4.2.3",
69
- "prismjs": "^1.27.0",
70
- "docx": "^8.2.2",
71
- "mammoth": "^1.6.0"
72
- },
73
- "simple-git-hooks": {
74
- "pre-commit": "npm run lint && npm run type:check",
75
- "commit-msg": "node scripts/verifyCommit.js"
76
- }
77
- }
1
+ {
2
+ "name": "@agile_jy/word-editor",
3
+ "author": "JIANGYONG",
4
+ "license": "MIT",
5
+ "version": "0.0.1-beta.21",
6
+ "description": "rich text editor by canvas/svg",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/",
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "CHANGELOG.md",
15
+ "LICENSE",
16
+ "package.json"
17
+ ],
18
+ "typings": "./dist/src/editor/index.d.ts",
19
+ "main": "./dist/canvas-editor.umd.js",
20
+ "module": "./dist/canvas-editor.es.js",
21
+ "homepage": "https://github.com/Hufe921/canvas-editor",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Hufe921/canvas-editor.git"
25
+ },
26
+ "keywords": [
27
+ "canvas-editor",
28
+ "editor",
29
+ "wysiwyg",
30
+ "emr"
31
+ ],
32
+ "engines": {
33
+ "node": ">=16.9.1"
34
+ },
35
+ "type": "module",
36
+ "scripts": {
37
+ "dev": "vite",
38
+ "lib": "npm run lint && tsc && vite build --mode lib",
39
+ "build": "npm run lint && tsc && vite build --mode app",
40
+ "serve": "vite preview",
41
+ "lint": "eslint .",
42
+ "cypress:open": "cypress open",
43
+ "cypress:run": "cypress run",
44
+ "type:check": "tsc --noEmit",
45
+ "docs:dev": "vitepress dev docs",
46
+ "docs:build": "vitepress build docs",
47
+ "docs:preview": "vitepress preview docs",
48
+ "postinstall": "simple-git-hooks",
49
+ "release": "node scripts/release.js"
50
+ },
51
+ "devDependencies": {
52
+ "@rollup/plugin-typescript": "^10.0.1",
53
+ "@types/color": "^3.0.4",
54
+ "@types/node": "16.18.96",
55
+ "@types/prismjs": "^1.26.0",
56
+ "@typescript-eslint/eslint-plugin": "5.62.0",
57
+ "@typescript-eslint/parser": "5.62.0",
58
+ "cypress": "13.6.0",
59
+ "cypress-file-upload": "^5.0.8",
60
+ "eslint": "7.32.0",
61
+ "simple-git-hooks": "^2.8.1",
62
+ "typescript": "4.9.5",
63
+ "vite": "^2.4.2",
64
+ "vite-plugin-css-injected-by-js": "^2.1.1",
65
+ "vitepress": "1.0.0-beta.6"
66
+ },
67
+ "dependencies": {
68
+ "color": "^4.2.3",
69
+ "docx": "^8.2.2",
70
+ "mammoth": "^1.6.0",
71
+ "prismjs": "^1.27.0"
72
+ },
73
+ "simple-git-hooks": {
74
+ "pre-commit": "npm run lint && npm run type:check",
75
+ "commit-msg": "node scripts/verifyCommit.js"
76
+ }
77
+ }