@hailin-zheng/editor-core 1.0.1 → 1.0.5
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/package.json +1 -1
- package/tsconfig.json +1 -1
- package/webpack.config.js +0 -1
- package/dist/doc-ruler.d.ts +0 -51
- package/dist/doc-ruler.js +0 -313
- package/dist/doc-ruler.js.map +0 -1
- package/dist/framework/common-util.d.ts +0 -63
- package/dist/framework/common-util.js +0 -178
- package/dist/framework/common-util.js.map +0 -1
- package/dist/framework/document-change.d.ts +0 -265
- package/dist/framework/document-change.js +0 -1342
- package/dist/framework/document-change.js.map +0 -1
- package/dist/framework/document-combine.d.ts +0 -24
- package/dist/framework/document-combine.js +0 -40
- package/dist/framework/document-combine.js.map +0 -1
- package/dist/framework/document-comment.d.ts +0 -46
- package/dist/framework/document-comment.js +0 -148
- package/dist/framework/document-comment.js.map +0 -1
- package/dist/framework/document-context.d.ts +0 -149
- package/dist/framework/document-context.js +0 -330
- package/dist/framework/document-context.js.map +0 -1
- package/dist/framework/document-eval-func.d.ts +0 -18
- package/dist/framework/document-eval-func.js +0 -48
- package/dist/framework/document-eval-func.js.map +0 -1
- package/dist/framework/document-event.d.ts +0 -213
- package/dist/framework/document-event.js +0 -1054
- package/dist/framework/document-event.js.map +0 -1
- package/dist/framework/document-history.d.ts +0 -26
- package/dist/framework/document-history.js +0 -65
- package/dist/framework/document-history.js.map +0 -1
- package/dist/framework/document-images-loader.d.ts +0 -16
- package/dist/framework/document-images-loader.js +0 -66
- package/dist/framework/document-images-loader.js.map +0 -1
- package/dist/framework/document-input-cursor.d.ts +0 -78
- package/dist/framework/document-input-cursor.js +0 -239
- package/dist/framework/document-input-cursor.js.map +0 -1
- package/dist/framework/document-paint.d.ts +0 -34
- package/dist/framework/document-paint.js +0 -103
- package/dist/framework/document-paint.js.map +0 -1
- package/dist/framework/document-print-offscreen.d.ts +0 -38
- package/dist/framework/document-print-offscreen.js +0 -128
- package/dist/framework/document-print-offscreen.js.map +0 -1
- package/dist/framework/document-print.d.ts +0 -60
- package/dist/framework/document-print.js +0 -203
- package/dist/framework/document-print.js.map +0 -1
- package/dist/framework/document-segmenter.d.ts +0 -2
- package/dist/framework/document-segmenter.js +0 -106
- package/dist/framework/document-segmenter.js.map +0 -1
- package/dist/framework/document-selection.d.ts +0 -89
- package/dist/framework/document-selection.js +0 -358
- package/dist/framework/document-selection.js.map +0 -1
- package/dist/framework/document-template.d.ts +0 -4
- package/dist/framework/document-template.js +0 -20
- package/dist/framework/document-template.js.map +0 -1
- package/dist/framework/document-textline-mode.d.ts +0 -7
- package/dist/framework/document-textline-mode.js +0 -30
- package/dist/framework/document-textline-mode.js.map +0 -1
- package/dist/framework/element-define.d.ts +0 -319
- package/dist/framework/element-define.js +0 -579
- package/dist/framework/element-define.js.map +0 -1
- package/dist/framework/element-event-define.d.ts +0 -99
- package/dist/framework/element-event-define.js +0 -108
- package/dist/framework/element-event-define.js.map +0 -1
- package/dist/framework/element-measure.d.ts +0 -97
- package/dist/framework/element-measure.js +0 -551
- package/dist/framework/element-measure.js.map +0 -1
- package/dist/framework/element-paint.d.ts +0 -42
- package/dist/framework/element-paint.js +0 -170
- package/dist/framework/element-paint.js.map +0 -1
- package/dist/framework/element-props.d.ts +0 -301
- package/dist/framework/element-props.js +0 -809
- package/dist/framework/element-props.js.map +0 -1
- package/dist/framework/element-reader.d.ts +0 -19
- package/dist/framework/element-reader.js +0 -151
- package/dist/framework/element-reader.js.map +0 -1
- package/dist/framework/element-render-cut.d.ts +0 -55
- package/dist/framework/element-render-cut.js +0 -449
- package/dist/framework/element-render-cut.js.map +0 -1
- package/dist/framework/element-serialize.d.ts +0 -30
- package/dist/framework/element-serialize.js +0 -113
- package/dist/framework/element-serialize.js.map +0 -1
- package/dist/framework/element-util.d.ts +0 -369
- package/dist/framework/element-util.js +0 -1463
- package/dist/framework/element-util.js.map +0 -1
- package/dist/framework/impl/checkbox/checkbox-impl.d.ts +0 -24
- package/dist/framework/impl/checkbox/checkbox-impl.js +0 -64
- package/dist/framework/impl/checkbox/checkbox-impl.js.map +0 -1
- package/dist/framework/impl/comments/comment-content-impl.d.ts +0 -40
- package/dist/framework/impl/comments/comment-content-impl.js +0 -105
- package/dist/framework/impl/comments/comment-content-impl.js.map +0 -1
- package/dist/framework/impl/comments/comment-element-impl.d.ts +0 -21
- package/dist/framework/impl/comments/comment-element-impl.js +0 -62
- package/dist/framework/impl/comments/comment-element-impl.js.map +0 -1
- package/dist/framework/impl/comments/comments-container-impl.d.ts +0 -22
- package/dist/framework/impl/comments/comments-container-impl.js +0 -62
- package/dist/framework/impl/comments/comments-container-impl.js.map +0 -1
- package/dist/framework/impl/comments/comments-util.d.ts +0 -12
- package/dist/framework/impl/comments/comments-util.js +0 -67
- package/dist/framework/impl/comments/comments-util.js.map +0 -1
- package/dist/framework/impl/comments/validate-msg-impl.d.ts +0 -21
- package/dist/framework/impl/comments/validate-msg-impl.js +0 -83
- package/dist/framework/impl/comments/validate-msg-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-decorate-impl.d.ts +0 -30
- package/dist/framework/impl/data-element/data-decorate-impl.js +0 -91
- package/dist/framework/impl/data-element/data-decorate-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-barcode.d.ts +0 -31
- package/dist/framework/impl/data-element/data-element-barcode.js +0 -115
- package/dist/framework/impl/data-element/data-element-barcode.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-base-impl.d.ts +0 -68
- package/dist/framework/impl/data-element/data-element-base-impl.js +0 -205
- package/dist/framework/impl/data-element/data-element-base-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-check-impl.d.ts +0 -35
- package/dist/framework/impl/data-element/data-element-check-impl.js +0 -133
- package/dist/framework/impl/data-element/data-element-check-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-date-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-date-impl.js +0 -111
- package/dist/framework/impl/data-element/data-element-date-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-group-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-group-impl.js +0 -130
- package/dist/framework/impl/data-element/data-element-group-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-image-impl.d.ts +0 -30
- package/dist/framework/impl/data-element/data-element-image-impl.js +0 -137
- package/dist/framework/impl/data-element/data-element-image-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-list-impl.d.ts +0 -22
- package/dist/framework/impl/data-element/data-element-list-impl.js +0 -131
- package/dist/framework/impl/data-element/data-element-list-impl.js.map +0 -1
- package/dist/framework/impl/data-element/data-element-text-impl.d.ts +0 -23
- package/dist/framework/impl/data-element/data-element-text-impl.js +0 -103
- package/dist/framework/impl/data-element/data-element-text-impl.js.map +0 -1
- package/dist/framework/impl/decorate/fill-null-space-imple.d.ts +0 -21
- package/dist/framework/impl/decorate/fill-null-space-imple.js +0 -43
- package/dist/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
- package/dist/framework/impl/document/doc-body-impl.d.ts +0 -27
- package/dist/framework/impl/document/doc-body-impl.js +0 -79
- package/dist/framework/impl/document/doc-body-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-body-part-impl.d.ts +0 -30
- package/dist/framework/impl/document/doc-body-part-impl.js +0 -94
- package/dist/framework/impl/document/doc-body-part-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-container-impl.d.ts +0 -16
- package/dist/framework/impl/document/doc-container-impl.js +0 -21
- package/dist/framework/impl/document/doc-container-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-footer-impl.d.ts +0 -26
- package/dist/framework/impl/document/doc-footer-impl.js +0 -77
- package/dist/framework/impl/document/doc-footer-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-header-impl.d.ts +0 -26
- package/dist/framework/impl/document/doc-header-impl.js +0 -83
- package/dist/framework/impl/document/doc-header-impl.js.map +0 -1
- package/dist/framework/impl/document/doc-impl.d.ts +0 -61
- package/dist/framework/impl/document/doc-impl.js +0 -209
- package/dist/framework/impl/document/doc-impl.js.map +0 -1
- package/dist/framework/impl/media-formula/menstrual-history.d.ts +0 -35
- package/dist/framework/impl/media-formula/menstrual-history.js +0 -153
- package/dist/framework/impl/media-formula/menstrual-history.js.map +0 -1
- package/dist/framework/impl/paragraph/p-impl.d.ts +0 -45
- package/dist/framework/impl/paragraph/p-impl.js +0 -156
- package/dist/framework/impl/paragraph/p-impl.js.map +0 -1
- package/dist/framework/impl/picture/image-impl.d.ts +0 -31
- package/dist/framework/impl/picture/image-impl.js +0 -124
- package/dist/framework/impl/picture/image-impl.js.map +0 -1
- package/dist/framework/impl/radio/radio-impl.d.ts +0 -22
- package/dist/framework/impl/radio/radio-impl.js +0 -72
- package/dist/framework/impl/radio/radio-impl.js.map +0 -1
- package/dist/framework/impl/symbol/br-symbol-impl.d.ts +0 -22
- package/dist/framework/impl/symbol/br-symbol-impl.js +0 -54
- package/dist/framework/impl/symbol/br-symbol-impl.js.map +0 -1
- package/dist/framework/impl/symbol/p-symbol-impl.d.ts +0 -19
- package/dist/framework/impl/symbol/p-symbol-impl.js +0 -54
- package/dist/framework/impl/symbol/p-symbol-impl.js.map +0 -1
- package/dist/framework/impl/table/table-cell-impl.d.ts +0 -37
- package/dist/framework/impl/table/table-cell-impl.js +0 -145
- package/dist/framework/impl/table/table-cell-impl.js.map +0 -1
- package/dist/framework/impl/table/table-impl.d.ts +0 -55
- package/dist/framework/impl/table/table-impl.js +0 -363
- package/dist/framework/impl/table/table-impl.js.map +0 -1
- package/dist/framework/impl/table/table-row-impl.d.ts +0 -26
- package/dist/framework/impl/table/table-row-impl.js +0 -75
- package/dist/framework/impl/table/table-row-impl.js.map +0 -1
- package/dist/framework/impl/table/table-split-cell-patch.d.ts +0 -20
- package/dist/framework/impl/table/table-split-cell-patch.js +0 -89
- package/dist/framework/impl/table/table-split-cell-patch.js.map +0 -1
- package/dist/framework/impl/table/table-split-cell.d.ts +0 -90
- package/dist/framework/impl/table/table-split-cell.js +0 -464
- package/dist/framework/impl/table/table-split-cell.js.map +0 -1
- package/dist/framework/impl/table/table-util.d.ts +0 -150
- package/dist/framework/impl/table/table-util.js +0 -678
- package/dist/framework/impl/table/table-util.js.map +0 -1
- package/dist/framework/impl/text/text-impl.d.ts +0 -32
- package/dist/framework/impl/text/text-impl.js +0 -149
- package/dist/framework/impl/text/text-impl.js.map +0 -1
- package/dist/framework/impl/text/track-run-impl.d.ts +0 -27
- package/dist/framework/impl/text/track-run-impl.js +0 -112
- package/dist/framework/impl/text/track-run-impl.js.map +0 -1
- package/dist/framework/notify.d.ts +0 -13
- package/dist/framework/notify.js +0 -116
- package/dist/framework/notify.js.map +0 -1
- package/dist/framework/range-util.d.ts +0 -40
- package/dist/framework/range-util.js +0 -312
- package/dist/framework/range-util.js.map +0 -1
- package/dist/framework/render-context.d.ts +0 -91
- package/dist/framework/render-context.js +0 -384
- package/dist/framework/render-context.js.map +0 -1
- package/dist/framework/render-define.d.ts +0 -109
- package/dist/framework/render-define.js +0 -195
- package/dist/framework/render-define.js.map +0 -1
- package/dist/framework/selection-overlays.d.ts +0 -30
- package/dist/framework/selection-overlays.js +0 -124
- package/dist/framework/selection-overlays.js.map +0 -1
- package/dist/texteditor.d.ts +0 -318
- package/dist/texteditor.js +0 -913
- package/dist/texteditor.js.map +0 -1
- package/dist/util/subject.d.ts +0 -34
- package/dist/util/subject.js +0 -88
- package/dist/util/subject.js.map +0 -1
- package/dist/util/table-bind.d.ts +0 -5
- package/dist/util/table-bind.js +0 -6
- package/dist/util/table-bind.js.map +0 -1
package/dist/texteditor.js
DELETED
@@ -1,913 +0,0 @@
|
|
1
|
-
import { RenderContenxt } from './framework/render-context';
|
2
|
-
import { ContextMenuElementEvent, EventMap } from './framework/element-event-define';
|
3
|
-
import { DocumentPaint } from './framework/document-paint';
|
4
|
-
import { ElementReader } from './framework/element-reader';
|
5
|
-
import { DocumentEvent } from './framework/document-event';
|
6
|
-
import { Subject } from 'rxjs';
|
7
|
-
import { DocumentInput } from './framework/document-input-cursor';
|
8
|
-
import { DocumentCursor, DocumentSelection } from './framework/document-selection';
|
9
|
-
import { ElementUtil } from './framework/element-util';
|
10
|
-
import { DocumentChange } from './framework/document-change';
|
11
|
-
import { SelectionOverlays } from './framework/selection-overlays';
|
12
|
-
import { BranchElement, DocMode, PageOptions, ViewOptions } from './framework/element-define';
|
13
|
-
import { ElementSerialize } from './framework/element-serialize';
|
14
|
-
import { TableElement } from './framework/impl/table/table-impl';
|
15
|
-
import { documentPrint } from './framework/document-print';
|
16
|
-
import { DocumentTemplate } from './framework/document-template';
|
17
|
-
import { IsInSideDataElement, validateDataEle } from './framework/impl/data-element/data-element-base-impl';
|
18
|
-
import { DocRule } from './doc-ruler';
|
19
|
-
import { TextGroupElement } from './framework/impl/text/text-impl';
|
20
|
-
import { ParagraphElement } from './framework/impl/paragraph/p-impl';
|
21
|
-
import { TableUtil } from './framework/impl/table/table-util';
|
22
|
-
import { EditorContext } from './framework/document-context';
|
23
|
-
import { DocumentRenderObject } from './framework/impl/document/doc-impl';
|
24
|
-
import { DocumentComment } from './framework/document-comment';
|
25
|
-
import { CommContentBaseElement } from './framework/impl/comments/comment-content-impl';
|
26
|
-
import { DocumentHistory } from './framework/document-history';
|
27
|
-
import { TableRowElement } from './framework/impl/table/table-row-impl';
|
28
|
-
import { getFocusTextSegment } from "@/med_editor/framework/document-segmenter";
|
29
|
-
import { saveAs } from 'file-saver';
|
30
|
-
import { DocumentBodyElement } from "@/med_editor/framework/impl/document/doc-body-impl";
|
31
|
-
export class CanvasTextEditor {
|
32
|
-
docScroll;
|
33
|
-
holdSpace;
|
34
|
-
ruleCanvas;
|
35
|
-
editCanvasContainer;
|
36
|
-
editCanvas;
|
37
|
-
editInput;
|
38
|
-
editCursor;
|
39
|
-
cursorWrapper;
|
40
|
-
scaleContainer;
|
41
|
-
contentCtx;
|
42
|
-
viewOptions;
|
43
|
-
docCtx;
|
44
|
-
docComment;
|
45
|
-
renderContext;
|
46
|
-
documentPaint;
|
47
|
-
elementReader;
|
48
|
-
documentEvent;
|
49
|
-
documentSelection;
|
50
|
-
documentInput;
|
51
|
-
documentChange;
|
52
|
-
selectionOverlays;
|
53
|
-
docRule;
|
54
|
-
docHistory;
|
55
|
-
eventMap = new EventMap();
|
56
|
-
selectionChanged = new Subject();
|
57
|
-
beforeRenderSubject = new Subject();
|
58
|
-
afterRenderSubject = new Subject();
|
59
|
-
selectionState;
|
60
|
-
//显示右键菜单
|
61
|
-
onContextMenuItemChanged = new Subject();
|
62
|
-
//显示数据元编辑框
|
63
|
-
onShowDataElementEditPanelEvent = new Subject();
|
64
|
-
onDblClickEvent = new Subject();
|
65
|
-
onClickEvent = new Subject();
|
66
|
-
onScrollViewEvent = new Subject();
|
67
|
-
//文档改变事件:内容及样式,业务模块需要根据此事件,来追踪当前文档是否改变的状态
|
68
|
-
onDocChangedEvent = new Subject();
|
69
|
-
constructor(docScroll, holdSpace, ruleCanvas, editCanvasContainer, editCanvas, editInput, editCursor, cursorWrapper, scaleContainer) {
|
70
|
-
this.docScroll = docScroll;
|
71
|
-
this.holdSpace = holdSpace;
|
72
|
-
this.ruleCanvas = ruleCanvas;
|
73
|
-
this.editCanvasContainer = editCanvasContainer;
|
74
|
-
this.editCanvas = editCanvas;
|
75
|
-
this.editInput = editInput;
|
76
|
-
this.editCursor = editCursor;
|
77
|
-
this.cursorWrapper = cursorWrapper;
|
78
|
-
this.scaleContainer = scaleContainer;
|
79
|
-
this.viewOptions = new ViewOptions();
|
80
|
-
this.documentSelection = new DocumentSelection();
|
81
|
-
this.docCtx = new EditorContext(this.documentSelection.selectionState, this.viewOptions);
|
82
|
-
this.viewOptions.copyRightInfo = '万达信息电子病历编辑器,www.wondersgroup.com';
|
83
|
-
this.viewOptions.drawCharRectColor = 'green';
|
84
|
-
this.viewOptions.showLineRect = true;
|
85
|
-
this.viewOptions.docSpace = 20;
|
86
|
-
this.viewOptions.reviewWindowWidth = 200;
|
87
|
-
this.viewOptions.defaultFontName = '宋体';
|
88
|
-
//整个画布的尺寸
|
89
|
-
this.viewOptions.viewSettings = {
|
90
|
-
width: 1000,
|
91
|
-
height: this.getContainerHeight().height
|
92
|
-
};
|
93
|
-
this.viewOptions.editUser = {
|
94
|
-
id: '6666',
|
95
|
-
name: '管理员'
|
96
|
-
};
|
97
|
-
this.viewOptions.fullPageView = false;
|
98
|
-
this.viewOptions.enableUndo = true;
|
99
|
-
this.createDocViewer();
|
100
|
-
this.docComment = new DocumentComment(this.docCtx);
|
101
|
-
this.contentCtx = editCanvas.getContext('2d');
|
102
|
-
this.renderContext = new RenderContenxt(this.contentCtx, this.viewOptions, this.docCtx);
|
103
|
-
this.setCanvasProps();
|
104
|
-
this.selectionState = this.documentSelection.selectionState;
|
105
|
-
this.selectionOverlays = new SelectionOverlays(this.documentSelection.selectionState);
|
106
|
-
this.documentPaint = new DocumentPaint(this.viewOptions, this.renderContext, this.docCtx, this.selectionOverlays.selectedSets);
|
107
|
-
this.elementReader = new ElementReader(this.docCtx, this.viewOptions, this.renderContext);
|
108
|
-
this.documentEvent = new DocumentEvent(editCanvas, this.documentPaint, this.viewOptions, this.documentSelection.selectionState, this.docCtx);
|
109
|
-
this.docRule = new DocRule(this.ruleCanvas, this.viewOptions, this.documentSelection.selectionState);
|
110
|
-
this.documentChange = new DocumentChange(this.documentSelection.selectionState, this.viewOptions, this.elementReader, this.docCtx, this.docComment);
|
111
|
-
this.docHistory = new DocumentHistory(this.docCtx, this.elementReader, this.onDocChangedEvent);
|
112
|
-
this.documentInput = new DocumentInput(editInput, editCursor, cursorWrapper, this.docCtx);
|
113
|
-
this.documentEvent.hitInfoChanged.subscribe((hitInfo) => {
|
114
|
-
this.hitInfoChanged(hitInfo);
|
115
|
-
});
|
116
|
-
this.documentEvent.clickEvent.subscribe((evt) => {
|
117
|
-
this.docClickHandle(evt);
|
118
|
-
});
|
119
|
-
this.documentEvent.dblClickEvent.subscribe((evt) => {
|
120
|
-
this.docDblClickHandle(evt);
|
121
|
-
});
|
122
|
-
this.documentEvent.changeCursor.subscribe((cursor) => {
|
123
|
-
this.changeCursor(cursor);
|
124
|
-
});
|
125
|
-
this.documentEvent.contextMenu.subscribe(evt => {
|
126
|
-
this.onContextMenu(evt);
|
127
|
-
});
|
128
|
-
this.documentEvent.trackTipsChanged.subscribe(data => {
|
129
|
-
});
|
130
|
-
this.documentInput.onInputEvent.subscribe(data => {
|
131
|
-
this.documentChange.newInput(data);
|
132
|
-
});
|
133
|
-
this.documentInput.onBackspaceEvent.subscribe((evt) => {
|
134
|
-
this.documentChange.onBackspace(evt);
|
135
|
-
});
|
136
|
-
this.documentInput.onEnterEvent.subscribe(() => {
|
137
|
-
this.documentChange.onEnter();
|
138
|
-
});
|
139
|
-
this.documentInput.onCopyEvent.subscribe((evt) => {
|
140
|
-
this.documentChange.onCopy(evt);
|
141
|
-
});
|
142
|
-
this.documentInput.onCutEvent.subscribe((evt) => {
|
143
|
-
this.documentChange.onCut(evt);
|
144
|
-
});
|
145
|
-
this.documentInput.onPasteEvent.subscribe((evt) => {
|
146
|
-
this.documentChange.onPaste(evt);
|
147
|
-
});
|
148
|
-
this.documentInput.onInsertBr.subscribe(() => {
|
149
|
-
this.documentChange.insertSoftBr();
|
150
|
-
});
|
151
|
-
this.documentInput.onLeftEvent.subscribe(() => {
|
152
|
-
this.documentEvent.moveCursorToLeft();
|
153
|
-
});
|
154
|
-
this.documentInput.onRightEvent.subscribe(() => {
|
155
|
-
this.documentEvent.moveCursorToRight();
|
156
|
-
});
|
157
|
-
this.documentInput.onDeleteEvent.subscribe((evt) => this.documentChange.onDeleteKeyHandler(evt));
|
158
|
-
this.documentInput.onSelectAllEvent.subscribe(() => {
|
159
|
-
this.documentEvent.selectAll();
|
160
|
-
});
|
161
|
-
this.documentInput.onHomeEvent.subscribe(() => {
|
162
|
-
this.documentEvent.moveCursorToLineStart();
|
163
|
-
});
|
164
|
-
this.documentInput.onEndEvent.subscribe(() => {
|
165
|
-
this.documentEvent.moveCursorToLineEnd();
|
166
|
-
});
|
167
|
-
this.documentInput.onUpEvent.subscribe(() => {
|
168
|
-
this.documentEvent.moveCursorToUpOrDown(true);
|
169
|
-
});
|
170
|
-
this.documentInput.onDownEvent.subscribe(() => {
|
171
|
-
this.documentEvent.moveCursorToUpOrDown(false);
|
172
|
-
});
|
173
|
-
this.docCtx.docChange = this.documentChange;
|
174
|
-
this.listenContainerHeight();
|
175
|
-
this.refreshDocRule();
|
176
|
-
this.docCtx.syncRefresh = () => {
|
177
|
-
this.flushToSchedule();
|
178
|
-
};
|
179
|
-
this.viewOptions.onChange.subscribe((type) => {
|
180
|
-
this.resetViewer(type);
|
181
|
-
});
|
182
|
-
}
|
183
|
-
/**
|
184
|
-
* 设置标尺
|
185
|
-
*/
|
186
|
-
refreshDocRule() {
|
187
|
-
let docLeft = 0; //CommonUtil.getOffsetX(this.editCanvas.parentElement as HTMLDivElement);
|
188
|
-
let pagePL = 0, pagePR = 0;
|
189
|
-
if (this.documentPaint.docContainer) {
|
190
|
-
docLeft += this.documentPaint.docContainer.rect.x;
|
191
|
-
}
|
192
|
-
if (this.docCtx.document?.props?.padding) {
|
193
|
-
const { left, right } = this.docCtx.document.props.padding;
|
194
|
-
pagePL = left;
|
195
|
-
pagePR = right;
|
196
|
-
}
|
197
|
-
this.docRule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
198
|
-
this.docRule.refreshRule();
|
199
|
-
}
|
200
|
-
createDocViewer() {
|
201
|
-
this.viewOptions.mmToPixelsRatio = this.measureMMToPixs();
|
202
|
-
const width = Math.floor(210 * this.viewOptions.mmToPixelsRatio);
|
203
|
-
const height = Math.floor(297 * this.viewOptions.mmToPixelsRatio);
|
204
|
-
this.viewOptions.docPageSettings = new PageOptions(width, height);
|
205
|
-
this.docScroll.onscroll = (evt) => {
|
206
|
-
this.scrollView(evt);
|
207
|
-
};
|
208
|
-
}
|
209
|
-
measureMMToPixs() {
|
210
|
-
const div = document.createElement('div');
|
211
|
-
div.style.width = '100mm';
|
212
|
-
document.body.appendChild(div);
|
213
|
-
const width = div.getBoundingClientRect().width;
|
214
|
-
document.body.removeChild(div);
|
215
|
-
return width / 100;
|
216
|
-
}
|
217
|
-
flushTask;
|
218
|
-
flushTaskThen = [];
|
219
|
-
//是否用于跟踪修改状态,在初始化、数据元赋值等情况不需要跟踪修改标志
|
220
|
-
trackChangeState = true;
|
221
|
-
flushToSchedule() {
|
222
|
-
if (this.docCtx.refreshType === 'content') {
|
223
|
-
//触发动态脚本
|
224
|
-
this.docCtx.dynamicFunc.invokedScripts();
|
225
|
-
this.triggerDocChange();
|
226
|
-
}
|
227
|
-
if (this.flushTask) {
|
228
|
-
return;
|
229
|
-
}
|
230
|
-
this.flushTask = () => {
|
231
|
-
this.refreshDocument();
|
232
|
-
this.flushTaskThen.forEach(item => item());
|
233
|
-
this.flushTaskThen.length = 0;
|
234
|
-
this.flushTask = null;
|
235
|
-
};
|
236
|
-
Promise.resolve().then(() => {
|
237
|
-
if (this.flushTask) {
|
238
|
-
this.flushTask();
|
239
|
-
}
|
240
|
-
});
|
241
|
-
}
|
242
|
-
/**
|
243
|
-
* 触发文档改变事件
|
244
|
-
* @returns
|
245
|
-
*/
|
246
|
-
triggerDocChange() {
|
247
|
-
if (!this.trackChangeState) {
|
248
|
-
return;
|
249
|
-
}
|
250
|
-
this.onDocChangedEvent.next();
|
251
|
-
}
|
252
|
-
/**
|
253
|
-
* fn函数执行时,不触发onDocChange
|
254
|
-
* @param fn
|
255
|
-
*/
|
256
|
-
noEffectChange(fn) {
|
257
|
-
const prev = this.trackChangeState;
|
258
|
-
this.trackChangeState = false;
|
259
|
-
try {
|
260
|
-
fn();
|
261
|
-
}
|
262
|
-
catch (e) {
|
263
|
-
console.error(e);
|
264
|
-
}
|
265
|
-
this.trackChangeState = prev;
|
266
|
-
}
|
267
|
-
loadDoc(data) {
|
268
|
-
this.elementReader.read(data);
|
269
|
-
this.refreshDocument();
|
270
|
-
this.refreshDocRule();
|
271
|
-
this.docHistory.clear();
|
272
|
-
}
|
273
|
-
/**
|
274
|
-
* 更新文档容器高度尺寸
|
275
|
-
*/
|
276
|
-
updateDocumentContainerSize() {
|
277
|
-
this.holdSpace.style.height = this.documentPaint.getDocumentContainerHeight() + 'px';
|
278
|
-
}
|
279
|
-
scrollView(evt) {
|
280
|
-
const target = evt.target;
|
281
|
-
const top = Math.floor(target.scrollTop);
|
282
|
-
this.editCanvasContainer.style.top = top + 'px';
|
283
|
-
this.cursorWrapper.style.transform = "translate(0,-" + top + "px)";
|
284
|
-
this.viewOptions.translateY = top;
|
285
|
-
this.documentPaint.refreshView();
|
286
|
-
this.documentEvent.onScrollView();
|
287
|
-
this.onScrollViewEvent.next(top);
|
288
|
-
}
|
289
|
-
refreshDocument() {
|
290
|
-
let rePaint = this.docCtx.refreshType === 'content';
|
291
|
-
if (rePaint) {
|
292
|
-
this.documentSelection.clearSnapshot();
|
293
|
-
this.docComment.readComments();
|
294
|
-
this.documentPaint.rePages();
|
295
|
-
this.beforeRenderSubject.next();
|
296
|
-
}
|
297
|
-
const ssChanged = this.documentSelection.updateSelectionState();
|
298
|
-
this.selectionOverlays.getSelectionTreeData();
|
299
|
-
this.documentPaint.refreshView(rePaint);
|
300
|
-
this.updateDocumentContainerSize();
|
301
|
-
this.setCursor();
|
302
|
-
ssChanged && this.selectionChanged.next(this.documentSelection.selectionState);
|
303
|
-
this.docRule.refreshRule();
|
304
|
-
}
|
305
|
-
hitInfoChanged(hitInfo) {
|
306
|
-
this.documentSelection.setSelectionState(hitInfo);
|
307
|
-
this.refreshDocument();
|
308
|
-
this.selectionChanged.next(this.documentSelection.selectionState);
|
309
|
-
}
|
310
|
-
/**
|
311
|
-
* 设置光标
|
312
|
-
*/
|
313
|
-
setCursor() {
|
314
|
-
const { startControl, startOffset } = this.selectionState;
|
315
|
-
if (!this.canSetCursor()) {
|
316
|
-
this.selectionState.editable = false;
|
317
|
-
this.documentInput.setCursorVisibility(false);
|
318
|
-
return;
|
319
|
-
}
|
320
|
-
if (this.selectionState.afterSelectionChanged) {
|
321
|
-
//需要重新刷新,不触发GotCusor事件
|
322
|
-
if (this.selectionState.afterSelectionChanged(this.selectionState)) {
|
323
|
-
this.selectionState.afterSelectionChanged = null;
|
324
|
-
return;
|
325
|
-
}
|
326
|
-
}
|
327
|
-
const { startRegion, hitDocIndex } = this.documentEvent.startHitInfo;
|
328
|
-
const cursorPos = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
|
329
|
-
this.docCtx.cursorRect = ElementUtil.cloneRect(cursorPos.rect);
|
330
|
-
this.documentInput.setCursorPosition(cursorPos.rect);
|
331
|
-
this.selectionState.cursorPos = cursorPos.rect;
|
332
|
-
this.documentEvent.invokeCursor(startControl);
|
333
|
-
}
|
334
|
-
/**
|
335
|
-
* 判断是否光标可以设置接受编辑
|
336
|
-
* @returns
|
337
|
-
*/
|
338
|
-
canSetCursor() {
|
339
|
-
const { startControl, startOffset, editable } = this.selectionState;
|
340
|
-
if (!startControl || !editable) {
|
341
|
-
return false;
|
342
|
-
}
|
343
|
-
if (this.viewOptions.docMode === DocMode.Design) {
|
344
|
-
return true;
|
345
|
-
}
|
346
|
-
//浏览模式
|
347
|
-
if (this.viewOptions.docMode === DocMode.View) {
|
348
|
-
return false;
|
349
|
-
}
|
350
|
-
//表单模式下,如果不在数据元素中,则不显示光标
|
351
|
-
if (this.viewOptions.docMode === DocMode.FormEdit) {
|
352
|
-
if (!IsInSideDataElement(startControl, startOffset)) {
|
353
|
-
return false;
|
354
|
-
}
|
355
|
-
}
|
356
|
-
if (!ElementUtil.verifyHitable(startControl)) {
|
357
|
-
return false;
|
358
|
-
}
|
359
|
-
//表单模式下,数据元不可编辑
|
360
|
-
if (this.viewOptions.docMode === DocMode.FormEdit && IsInSideDataElement(startControl, startOffset)) {
|
361
|
-
const dataEle = ElementUtil.getDataElement(startControl);
|
362
|
-
if (!dataEle.props.editable) {
|
363
|
-
return false;
|
364
|
-
}
|
365
|
-
}
|
366
|
-
return true;
|
367
|
-
}
|
368
|
-
/**
|
369
|
-
* 修改光标
|
370
|
-
* @param newCursor
|
371
|
-
*/
|
372
|
-
changeCursor(newCursor) {
|
373
|
-
this.editCanvas.style.cursor = newCursor;
|
374
|
-
this.viewOptions.cursor = newCursor;
|
375
|
-
}
|
376
|
-
/**
|
377
|
-
* 文档点击事件
|
378
|
-
*/
|
379
|
-
docClickHandle(evt) {
|
380
|
-
this.setCursor();
|
381
|
-
this.selectionOverlays.getSelectionTreeData();
|
382
|
-
this.onClickEvent.next(evt);
|
383
|
-
}
|
384
|
-
/**
|
385
|
-
* 文档双击事件
|
386
|
-
* 处理全选当前段落
|
387
|
-
*/
|
388
|
-
docDblClickHandle(evt) {
|
389
|
-
const res = getFocusTextSegment(this.selectionState);
|
390
|
-
if (res) {
|
391
|
-
this.refreshDocument();
|
392
|
-
}
|
393
|
-
this.onDblClickEvent.next(evt);
|
394
|
-
}
|
395
|
-
/**
|
396
|
-
* 获取当前光标所在的数据元
|
397
|
-
* @returns
|
398
|
-
*/
|
399
|
-
getCurrentDataElement() {
|
400
|
-
const selectionState = this.documentSelection.selectionState;
|
401
|
-
const { startControl } = selectionState;
|
402
|
-
if (startControl) {
|
403
|
-
if (!ElementUtil.verifyHitable(startControl)) {
|
404
|
-
return null;
|
405
|
-
}
|
406
|
-
return ElementUtil.getParent(startControl, validateDataEle);
|
407
|
-
}
|
408
|
-
return null;
|
409
|
-
}
|
410
|
-
/**
|
411
|
-
* 设置当前光标所在的数据元的值
|
412
|
-
* @param val
|
413
|
-
*/
|
414
|
-
setCurrentDataElementValue(val) {
|
415
|
-
const dataEle = this.getCurrentDataElement();
|
416
|
-
if (dataEle) {
|
417
|
-
dataEle?.setValue(val);
|
418
|
-
this.selectionState.clear();
|
419
|
-
}
|
420
|
-
}
|
421
|
-
/**
|
422
|
-
* 获取数据元位置
|
423
|
-
* @param element
|
424
|
-
* @returns
|
425
|
-
*/
|
426
|
-
getDataElementPosition(element) {
|
427
|
-
const startDecorateRender = this.documentPaint.elementPaint.getLeafElementPaintMap(element);
|
428
|
-
if (!startDecorateRender) {
|
429
|
-
console.error('未找到数据元开始渲染元素');
|
430
|
-
return;
|
431
|
-
}
|
432
|
-
const { x, height, y, width } = startDecorateRender.rect;
|
433
|
-
const pos = ElementUtil.getRenderAbsolutePaintPos(startDecorateRender);
|
434
|
-
const position = { x: pos.x + width, y: pos.y + height + 5, translateY: this.viewOptions.translateY };
|
435
|
-
return position;
|
436
|
-
}
|
437
|
-
/**
|
438
|
-
* 获取文档模型
|
439
|
-
* @returns
|
440
|
-
*/
|
441
|
-
getDocSchema() {
|
442
|
-
return ElementSerialize.serialize(this.docCtx.document, this.viewOptions);
|
443
|
-
}
|
444
|
-
getDocSchemaJSON() {
|
445
|
-
const res = JSON.stringify(this.getDocSchema());
|
446
|
-
return res;
|
447
|
-
}
|
448
|
-
/**
|
449
|
-
* 右键菜单
|
450
|
-
* @param evt
|
451
|
-
*/
|
452
|
-
onContextMenu(evt) {
|
453
|
-
evt.preventDefault();
|
454
|
-
const { selectionState } = this.documentSelection;
|
455
|
-
const { startControl } = selectionState;
|
456
|
-
if (!startControl) {
|
457
|
-
return;
|
458
|
-
}
|
459
|
-
const elementEvent = new ContextMenuElementEvent(this.docCtx);
|
460
|
-
elementEvent.source = startControl;
|
461
|
-
DocumentEvent.invokeEvent('ElementContextMenu', startControl, elementEvent, 'All', this.docCtx);
|
462
|
-
const position = { x: evt.offsetX + 10, y: evt.offsetY, translateY: this.viewOptions.translateY };
|
463
|
-
this.onContextMenuItemChanged.next({ pos: position, menus: elementEvent.menus });
|
464
|
-
}
|
465
|
-
resizeObserver = null;
|
466
|
-
listenContainerHeight() {
|
467
|
-
this.resizeObserver = new ResizeObserver(entries => {
|
468
|
-
this.updateDocHeight();
|
469
|
-
});
|
470
|
-
this.resizeObserver.observe(this.docScroll);
|
471
|
-
this.updateDocHeight();
|
472
|
-
}
|
473
|
-
updateDocHeight() {
|
474
|
-
const { width, height } = this.getContainerHeight();
|
475
|
-
this.viewOptions.viewSettings.width = width;
|
476
|
-
this.viewOptions.viewSettings.height = height;
|
477
|
-
if (width < this.viewOptions.ContentWidth) {
|
478
|
-
this.viewOptions.viewSettings.width = this.viewOptions.ContentWidth;
|
479
|
-
}
|
480
|
-
this.resetViewer();
|
481
|
-
}
|
482
|
-
resetViewer(type = undefined) {
|
483
|
-
const refreshType = type === 'force' ? 'content' : 'appearance';
|
484
|
-
if (refreshType === 'content') {
|
485
|
-
this.docCtx.document.pubOnChange('self');
|
486
|
-
}
|
487
|
-
this.setCanvasProps();
|
488
|
-
this.flushToSchedule();
|
489
|
-
this.flushTaskThen.push(() => {
|
490
|
-
this.refreshDocRule();
|
491
|
-
});
|
492
|
-
}
|
493
|
-
/**
|
494
|
-
* 缩放视图
|
495
|
-
* @param scale
|
496
|
-
* @returns
|
497
|
-
*/
|
498
|
-
scaleView(scale) {
|
499
|
-
scale = scale < 0.5 ? 0.5 : scale;
|
500
|
-
scale = scale > 2 ? 2 : scale;
|
501
|
-
this.viewOptions.scale = scale;
|
502
|
-
this.scaleContainer.style.transform = `scale(${scale})`;
|
503
|
-
this.scaleContainer.style.transformOrigin = "center top";
|
504
|
-
if (scale === 1) {
|
505
|
-
this.scaleContainer.style.transform = '';
|
506
|
-
this.scaleContainer.style.transformOrigin = '';
|
507
|
-
}
|
508
|
-
this.setCanvasProps();
|
509
|
-
this.refreshDocRule();
|
510
|
-
this.flushToSchedule();
|
511
|
-
return scale;
|
512
|
-
}
|
513
|
-
getContainerHeight() {
|
514
|
-
let { height, width } = this.docScroll.getBoundingClientRect();
|
515
|
-
// const div=this.docScroll.children[0] as HTMLElement;
|
516
|
-
// const { height, width } = div.getBoundingClientRect();
|
517
|
-
return { height: Math.floor(height), width: Math.floor(width) };
|
518
|
-
}
|
519
|
-
setCanvasProps() {
|
520
|
-
this.renderContext?.clear();
|
521
|
-
this.renderContext.setCanvasProps();
|
522
|
-
this.renderContext?.clear();
|
523
|
-
}
|
524
|
-
/**
|
525
|
-
* 在当前位置插入表格
|
526
|
-
* @param row
|
527
|
-
* @param col
|
528
|
-
*/
|
529
|
-
insertTable(rows, cols) {
|
530
|
-
const tb = TableElement.createTable(rows, cols);
|
531
|
-
this.documentChange.insertTable(tb);
|
532
|
-
}
|
533
|
-
/**
|
534
|
-
* 打印所有文档
|
535
|
-
*/
|
536
|
-
printAllPages() {
|
537
|
-
documentPrint.print(this.documentSelection.selectionState, this.viewOptions, this.docCtx);
|
538
|
-
}
|
539
|
-
/**
|
540
|
-
* 导出所有页到base64
|
541
|
-
*/
|
542
|
-
exportAllPagesToBase64(fileName) {
|
543
|
-
const imgs = documentPrint.exportCanvasNodes(this.documentSelection.selectionState, this.viewOptions, this.docCtx);
|
544
|
-
imgs.forEach((item, i) => item.toBlob(blog => {
|
545
|
-
if (blog) {
|
546
|
-
saveAs(blog, fileName + i + '.png');
|
547
|
-
}
|
548
|
-
}));
|
549
|
-
}
|
550
|
-
exportPDF() {
|
551
|
-
documentPrint.exportPDF('', this.documentSelection.selectionState, this.viewOptions, this.docCtx);
|
552
|
-
}
|
553
|
-
/**
|
554
|
-
* 清除文档
|
555
|
-
*/
|
556
|
-
clearDoc() {
|
557
|
-
if (this.docCtx.document) {
|
558
|
-
this.docCtx.document.destroy();
|
559
|
-
this.documentSelection.selectionState.clear();
|
560
|
-
this.documentEvent.clearHitInfo();
|
561
|
-
}
|
562
|
-
this.docCtx.clear();
|
563
|
-
}
|
564
|
-
/**
|
565
|
-
* 新建文档
|
566
|
-
* @param options
|
567
|
-
*/
|
568
|
-
createNewDoc(doc = null) {
|
569
|
-
//this.docCtx.clear();
|
570
|
-
const newDoc = doc ?? DocumentTemplate.createA4Doc();
|
571
|
-
// this.elementReader.setDocument(newDoc);
|
572
|
-
// this.refreshDocument('content');
|
573
|
-
this.loadDoc(ElementSerialize.serialize(newDoc, this.viewOptions));
|
574
|
-
}
|
575
|
-
destroy() {
|
576
|
-
this.docCtx.destroy();
|
577
|
-
this.documentEvent.clearSubEvent();
|
578
|
-
this.documentInput.destroy();
|
579
|
-
this.flushTask = null;
|
580
|
-
}
|
581
|
-
/**
|
582
|
-
* 获取选区文本属性
|
583
|
-
* @returns
|
584
|
-
*/
|
585
|
-
getSelectionTextGroupProps() {
|
586
|
-
const selectionState = this.selectionState;
|
587
|
-
const range = selectionState.selectedRange;
|
588
|
-
if (!range) {
|
589
|
-
if (selectionState.collapsed) {
|
590
|
-
if (selectionState.startControl instanceof TextGroupElement) {
|
591
|
-
return selectionState.startControl.props;
|
592
|
-
}
|
593
|
-
}
|
594
|
-
return null;
|
595
|
-
}
|
596
|
-
const startRange = ElementUtil.getFirstSelectedRange(range);
|
597
|
-
const endRange = ElementUtil.getLastSelectedRange(range);
|
598
|
-
if (startRange.target instanceof TextGroupElement) {
|
599
|
-
return startRange.target.props;
|
600
|
-
}
|
601
|
-
return null;
|
602
|
-
}
|
603
|
-
getSelectionParaProps() {
|
604
|
-
const selectionState = this.selectionState;
|
605
|
-
if (!selectionState || !selectionState.startControl) {
|
606
|
-
return null;
|
607
|
-
}
|
608
|
-
const para = ElementUtil.getParentByType(selectionState.startControl, ParagraphElement);
|
609
|
-
return para.props;
|
610
|
-
}
|
611
|
-
/**
|
612
|
-
* 设置文本字体大小
|
613
|
-
* @param fontSize
|
614
|
-
* @returns
|
615
|
-
*/
|
616
|
-
setTextFontSize(fontSize) {
|
617
|
-
if (isNaN(fontSize)) {
|
618
|
-
return;
|
619
|
-
}
|
620
|
-
const setterFunc = (textProps) => {
|
621
|
-
textProps.fontSize = fontSize;
|
622
|
-
};
|
623
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
624
|
-
}
|
625
|
-
/**
|
626
|
-
* 设置文本颜色
|
627
|
-
* @param color \
|
628
|
-
*/
|
629
|
-
setTextColor(color) {
|
630
|
-
color = color || "rgb(0,0,0)";
|
631
|
-
const setterFunc = (textProps) => {
|
632
|
-
textProps.color = color;
|
633
|
-
};
|
634
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
635
|
-
}
|
636
|
-
/**
|
637
|
-
* 设置文本字体名称
|
638
|
-
* @param font
|
639
|
-
*/
|
640
|
-
setTextFont(font) {
|
641
|
-
font = font || "宋体";
|
642
|
-
const setterFunc = (textProps) => {
|
643
|
-
textProps.fontName = font;
|
644
|
-
};
|
645
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
646
|
-
}
|
647
|
-
/**
|
648
|
-
* 应用选中文本格式,用于批量设置格式,例如:格式刷
|
649
|
-
* @param newStyle
|
650
|
-
*/
|
651
|
-
applyStyle(newStyle) {
|
652
|
-
const setterFunc = (textProps) => {
|
653
|
-
textProps.setPropsValue(newStyle, textProps);
|
654
|
-
};
|
655
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
656
|
-
}
|
657
|
-
/**
|
658
|
-
* 开启格式刷
|
659
|
-
*/
|
660
|
-
enableFormatBrush() {
|
661
|
-
const startControl = this.selectionState.startControl;
|
662
|
-
if (startControl instanceof TextGroupElement) {
|
663
|
-
const selectedStyle = startControl.props.clone(null);
|
664
|
-
const selectionOverlayColor = this.viewOptions.selectionOverlaysColor;
|
665
|
-
this.viewOptions.selectionOverlaysColor = "rgba(0,58,140,0.8)";
|
666
|
-
const cancelToken = {};
|
667
|
-
const sub = this.onClickEvent.subscribe(() => {
|
668
|
-
sub.unsubscribe();
|
669
|
-
this.applyStyle(selectedStyle);
|
670
|
-
this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
|
671
|
-
if (cancelToken.onFinish) {
|
672
|
-
cancelToken.onFinish();
|
673
|
-
}
|
674
|
-
});
|
675
|
-
cancelToken.cancel = () => {
|
676
|
-
sub.unsubscribe();
|
677
|
-
this.viewOptions.selectionOverlaysColor = selectionOverlayColor;
|
678
|
-
};
|
679
|
-
return cancelToken;
|
680
|
-
}
|
681
|
-
return null;
|
682
|
-
}
|
683
|
-
/**
|
684
|
-
* 设置文本背景颜色
|
685
|
-
* @param color
|
686
|
-
*/
|
687
|
-
setTextBackColor(color) {
|
688
|
-
const setterFunc = (textProps) => {
|
689
|
-
textProps.background = color;
|
690
|
-
};
|
691
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
692
|
-
}
|
693
|
-
/**
|
694
|
-
* 切换文本加粗、下划线、删除等文本样式
|
695
|
-
* @param isEffective
|
696
|
-
* @param style
|
697
|
-
* @param matchValue
|
698
|
-
*/
|
699
|
-
switchTextStyle(isEffective, style, matchValue, defaultValue = undefined) {
|
700
|
-
const setterFunc = (textProps) => {
|
701
|
-
if (isEffective) {
|
702
|
-
textProps[style] = defaultValue;
|
703
|
-
//delete textProps[style];
|
704
|
-
}
|
705
|
-
else {
|
706
|
-
textProps[style] = matchValue;
|
707
|
-
}
|
708
|
-
};
|
709
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
710
|
-
}
|
711
|
-
/**
|
712
|
-
* 修改字间距
|
713
|
-
*/
|
714
|
-
setLetterSpace(letterSpace) {
|
715
|
-
letterSpace = letterSpace <= 0 ? 0 : letterSpace;
|
716
|
-
const setterFunc = (textProps) => {
|
717
|
-
textProps.letterSpace = letterSpace;
|
718
|
-
};
|
719
|
-
DocumentChange.setTextStyle(this.selectionState, setterFunc);
|
720
|
-
}
|
721
|
-
/**
|
722
|
-
* 设置段落对齐
|
723
|
-
* @param align
|
724
|
-
*/
|
725
|
-
switchParaAlign(align) {
|
726
|
-
const setterFunc = (paraProps) => {
|
727
|
-
paraProps.textAlign = align;
|
728
|
-
};
|
729
|
-
DocumentChange.setParaAlign(this.selectionState, setterFunc);
|
730
|
-
}
|
731
|
-
combineCell() {
|
732
|
-
TableUtil.mergeCells(this.selectionState);
|
733
|
-
}
|
734
|
-
/**
|
735
|
-
* 切换当前段落项目符号状态
|
736
|
-
*/
|
737
|
-
setParagraphNumberType() {
|
738
|
-
this.documentChange.setParagraphNumberType();
|
739
|
-
}
|
740
|
-
/**
|
741
|
-
* 删除当前批注
|
742
|
-
* @param id
|
743
|
-
*/
|
744
|
-
removeComment(id) {
|
745
|
-
this.docComment.removeComment(id);
|
746
|
-
this.selectionState.clear();
|
747
|
-
}
|
748
|
-
/**
|
749
|
-
* 移除焦点所在的批注
|
750
|
-
*/
|
751
|
-
removeCurrentComment() {
|
752
|
-
const comment = ElementUtil.getParent(this.selectionState.startControl, (item => item instanceof CommContentBaseElement));
|
753
|
-
if (comment) {
|
754
|
-
this.removeComment(comment.props.id);
|
755
|
-
}
|
756
|
-
}
|
757
|
-
/**
|
758
|
-
* 插入批注
|
759
|
-
*/
|
760
|
-
insertComment() {
|
761
|
-
this.documentChange.insertComment();
|
762
|
-
}
|
763
|
-
/**
|
764
|
-
* 清除所有批注
|
765
|
-
*/
|
766
|
-
clearAllComments() {
|
767
|
-
this.docComment.clearAllComments();
|
768
|
-
}
|
769
|
-
cutTable() {
|
770
|
-
const row = ElementUtil.getParentByType(this.selectionState.startControl, TableRowElement);
|
771
|
-
const tb = row?.parent;
|
772
|
-
TableUtil.cutTable(tb, row.getIndex());
|
773
|
-
const para = new ParagraphElement();
|
774
|
-
tb.parent.addChild(para, tb.getIndex() + 1);
|
775
|
-
}
|
776
|
-
/**
|
777
|
-
* 初始化当前文档创建用户信息
|
778
|
-
* 一份文档只需要设置一次
|
779
|
-
*/
|
780
|
-
initCurrentDocUser(userId, userName, date) {
|
781
|
-
const doc = this.docCtx.document;
|
782
|
-
doc.props.createUserId = userId;
|
783
|
-
doc.props.createUserName = userName;
|
784
|
-
doc.props.createDate = date;
|
785
|
-
}
|
786
|
-
/**
|
787
|
-
* 验证文档内容
|
788
|
-
* @returns
|
789
|
-
*/
|
790
|
-
validate() {
|
791
|
-
this.docComment.clearAllValidates();
|
792
|
-
return this.documentChange.validate();
|
793
|
-
}
|
794
|
-
/**
|
795
|
-
* 撤销
|
796
|
-
*/
|
797
|
-
undo() {
|
798
|
-
this.docHistory.undo();
|
799
|
-
}
|
800
|
-
/**
|
801
|
-
* 恢复
|
802
|
-
*/
|
803
|
-
redo() {
|
804
|
-
this.docHistory.redo();
|
805
|
-
}
|
806
|
-
/**
|
807
|
-
* 是否可以撤销
|
808
|
-
*/
|
809
|
-
canUndo() {
|
810
|
-
return this.docHistory.canUndo;
|
811
|
-
}
|
812
|
-
/**
|
813
|
-
* 是否可以恢复
|
814
|
-
*/
|
815
|
-
canRedo() {
|
816
|
-
return this.docHistory.canRedo;
|
817
|
-
}
|
818
|
-
switchTrackChanges(eleCtx = null) {
|
819
|
-
eleCtx = eleCtx || this.docCtx.document;
|
820
|
-
const body = eleCtx.treeFind(item => item instanceof DocumentBodyElement);
|
821
|
-
if (body) {
|
822
|
-
body.trackChanges = !body.trackChanges;
|
823
|
-
}
|
824
|
-
else {
|
825
|
-
throw new Error('未找到doc-body');
|
826
|
-
}
|
827
|
-
}
|
828
|
-
get trackTipsChanged() {
|
829
|
-
return this.documentEvent.trackTipsChanged;
|
830
|
-
}
|
831
|
-
switchFullViewPage() {
|
832
|
-
this.viewOptions.fullPageView = !this.viewOptions.fullPageView;
|
833
|
-
}
|
834
|
-
getSelectedJSON() {
|
835
|
-
return ElementSerialize.getSelectedJSON(this.selectionState, this.viewOptions);
|
836
|
-
}
|
837
|
-
getSelectedText() {
|
838
|
-
const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
|
839
|
-
return ElementSerialize.serializeString(copySerializeStr);
|
840
|
-
}
|
841
|
-
/**
|
842
|
-
* 设置纸张方向
|
843
|
-
* @param orientation
|
844
|
-
*/
|
845
|
-
setPaperOrient(orientation) {
|
846
|
-
this.docCtx.document.props.orient = orientation;
|
847
|
-
this.viewOptions.docPageSettings.orient = orientation;
|
848
|
-
this.resetViewer('force');
|
849
|
-
this.selectionState.clear();
|
850
|
-
}
|
851
|
-
/**
|
852
|
-
* 设置纸张大小,单位为毫米(mm)
|
853
|
-
* @param width
|
854
|
-
* @param height
|
855
|
-
*/
|
856
|
-
setPaperSize(width, height) {
|
857
|
-
const docProps = this.docCtx.document.props;
|
858
|
-
docProps.width = width;
|
859
|
-
docProps.height = height;
|
860
|
-
width = Math.floor(width * this.viewOptions.mmToPixelsRatio);
|
861
|
-
height = Math.floor(height * this.viewOptions.mmToPixelsRatio);
|
862
|
-
this.viewOptions.docPageSettings = new PageOptions(width, height, docProps.orient);
|
863
|
-
this.resetViewer('force');
|
864
|
-
}
|
865
|
-
/**
|
866
|
-
* 插入强制换页符
|
867
|
-
*/
|
868
|
-
insertPageBreakPara() {
|
869
|
-
this.documentChange.insertPageBreakPara();
|
870
|
-
}
|
871
|
-
/**
|
872
|
-
* 显示当前元素到视图中
|
873
|
-
* @param element
|
874
|
-
*/
|
875
|
-
bringToView(element) {
|
876
|
-
const ele = element instanceof BranchElement ? ElementUtil.getFirstLeafElement(element) : element;
|
877
|
-
if (ele) {
|
878
|
-
const region = ElementUtil.getElementRegion(ele);
|
879
|
-
const renderObj = ele.paintRenders[0];
|
880
|
-
const docRender = ElementUtil.getParentRender(renderObj, DocumentRenderObject);
|
881
|
-
const index = docRender.getIndex();
|
882
|
-
const cursorPos = DocumentCursor.getElementCursorPos(ele, 0, region, index);
|
883
|
-
this.selectionState.surround(element);
|
884
|
-
if (cursorPos.rect.y - this.viewOptions.translateY > 0 && cursorPos.rect.y - this.viewOptions.translateY < this.viewOptions.viewPaintHeight) {
|
885
|
-
return;
|
886
|
-
}
|
887
|
-
this.docScroll.scrollTo(cursorPos.rect.x, cursorPos.rect.y - this.viewOptions.translateY);
|
888
|
-
}
|
889
|
-
}
|
890
|
-
/**
|
891
|
-
* 设置当前文档页边距
|
892
|
-
*/
|
893
|
-
setDocumentMargin(pageMargin) {
|
894
|
-
if (!this.docCtx.document) {
|
895
|
-
return;
|
896
|
-
}
|
897
|
-
this.docCtx.document.updateMargin(pageMargin);
|
898
|
-
}
|
899
|
-
/**
|
900
|
-
* 插入元素
|
901
|
-
* @param targetElement
|
902
|
-
* @param targetOffset
|
903
|
-
* @param destEleArray
|
904
|
-
* @returns
|
905
|
-
*/
|
906
|
-
insertElement(targetElement, targetOffset, destEleArray) {
|
907
|
-
if (!this.selectionState.editable) {
|
908
|
-
return null;
|
909
|
-
}
|
910
|
-
return this.documentChange.insertElement(targetElement, targetOffset, destEleArray);
|
911
|
-
}
|
912
|
-
}
|
913
|
-
//# sourceMappingURL=texteditor.js.map
|