@hailin-zheng/editor-core 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/package.json +1 -1
- package/lib/doc-ruler.d.ts +0 -51
- package/lib/doc-ruler.js +0 -313
- package/lib/doc-ruler.js.map +0 -1
- package/lib/framework/common-util.d.ts +0 -63
- package/lib/framework/common-util.js +0 -178
- package/lib/framework/common-util.js.map +0 -1
- package/lib/framework/document-change.d.ts +0 -265
- package/lib/framework/document-change.js +0 -1342
- package/lib/framework/document-change.js.map +0 -1
- package/lib/framework/document-combine.d.ts +0 -24
- package/lib/framework/document-combine.js +0 -40
- package/lib/framework/document-combine.js.map +0 -1
- package/lib/framework/document-comment.d.ts +0 -46
- package/lib/framework/document-comment.js +0 -148
- package/lib/framework/document-comment.js.map +0 -1
- package/lib/framework/document-context.d.ts +0 -149
- package/lib/framework/document-context.js +0 -330
- package/lib/framework/document-context.js.map +0 -1
- package/lib/framework/document-eval-func.d.ts +0 -18
- package/lib/framework/document-eval-func.js +0 -48
- package/lib/framework/document-eval-func.js.map +0 -1
- package/lib/framework/document-event.d.ts +0 -213
- package/lib/framework/document-event.js +0 -1054
- package/lib/framework/document-event.js.map +0 -1
- package/lib/framework/document-history.d.ts +0 -26
- package/lib/framework/document-history.js +0 -65
- package/lib/framework/document-history.js.map +0 -1
- package/lib/framework/document-images-loader.d.ts +0 -16
- package/lib/framework/document-images-loader.js +0 -66
- package/lib/framework/document-images-loader.js.map +0 -1
- package/lib/framework/document-input-cursor.d.ts +0 -78
- package/lib/framework/document-input-cursor.js +0 -239
- package/lib/framework/document-input-cursor.js.map +0 -1
- package/lib/framework/document-paint.d.ts +0 -34
- package/lib/framework/document-paint.js +0 -103
- package/lib/framework/document-paint.js.map +0 -1
- package/lib/framework/document-print-offscreen.d.ts +0 -38
- package/lib/framework/document-print-offscreen.js +0 -128
- package/lib/framework/document-print-offscreen.js.map +0 -1
- package/lib/framework/document-print.d.ts +0 -60
- package/lib/framework/document-print.js +0 -203
- package/lib/framework/document-print.js.map +0 -1
- package/lib/framework/document-segmenter.d.ts +0 -2
- package/lib/framework/document-segmenter.js +0 -106
- package/lib/framework/document-segmenter.js.map +0 -1
- package/lib/framework/document-selection.d.ts +0 -89
- package/lib/framework/document-selection.js +0 -358
- package/lib/framework/document-selection.js.map +0 -1
- package/lib/framework/document-template.d.ts +0 -4
- package/lib/framework/document-template.js +0 -20
- package/lib/framework/document-template.js.map +0 -1
- package/lib/framework/document-textline-mode.d.ts +0 -7
- package/lib/framework/document-textline-mode.js +0 -30
- package/lib/framework/document-textline-mode.js.map +0 -1
- package/lib/framework/element-define.d.ts +0 -319
- package/lib/framework/element-define.js +0 -579
- package/lib/framework/element-define.js.map +0 -1
- package/lib/framework/element-event-define.d.ts +0 -99
- package/lib/framework/element-event-define.js +0 -108
- package/lib/framework/element-event-define.js.map +0 -1
- package/lib/framework/element-measure.d.ts +0 -97
- package/lib/framework/element-measure.js +0 -551
- package/lib/framework/element-measure.js.map +0 -1
- package/lib/framework/element-paint.d.ts +0 -42
- package/lib/framework/element-paint.js +0 -170
- package/lib/framework/element-paint.js.map +0 -1
- package/lib/framework/element-props.d.ts +0 -301
- package/lib/framework/element-props.js +0 -809
- package/lib/framework/element-props.js.map +0 -1
- package/lib/framework/element-reader.d.ts +0 -19
- package/lib/framework/element-reader.js +0 -151
- package/lib/framework/element-reader.js.map +0 -1
- package/lib/framework/element-render-cut.d.ts +0 -55
- package/lib/framework/element-render-cut.js +0 -449
- package/lib/framework/element-render-cut.js.map +0 -1
- package/lib/framework/element-serialize.d.ts +0 -30
- package/lib/framework/element-serialize.js +0 -113
- package/lib/framework/element-serialize.js.map +0 -1
- package/lib/framework/element-util.d.ts +0 -369
- package/lib/framework/element-util.js +0 -1463
- package/lib/framework/element-util.js.map +0 -1
- package/lib/framework/impl/checkbox/checkbox-impl.d.ts +0 -24
- package/lib/framework/impl/checkbox/checkbox-impl.js +0 -64
- package/lib/framework/impl/checkbox/checkbox-impl.js.map +0 -1
- package/lib/framework/impl/comments/comment-content-impl.d.ts +0 -40
- package/lib/framework/impl/comments/comment-content-impl.js +0 -105
- package/lib/framework/impl/comments/comment-content-impl.js.map +0 -1
- package/lib/framework/impl/comments/comment-element-impl.d.ts +0 -21
- package/lib/framework/impl/comments/comment-element-impl.js +0 -62
- package/lib/framework/impl/comments/comment-element-impl.js.map +0 -1
- package/lib/framework/impl/comments/comments-container-impl.d.ts +0 -22
- package/lib/framework/impl/comments/comments-container-impl.js +0 -62
- package/lib/framework/impl/comments/comments-container-impl.js.map +0 -1
- package/lib/framework/impl/comments/comments-util.d.ts +0 -12
- package/lib/framework/impl/comments/comments-util.js +0 -67
- package/lib/framework/impl/comments/comments-util.js.map +0 -1
- package/lib/framework/impl/comments/validate-msg-impl.d.ts +0 -21
- package/lib/framework/impl/comments/validate-msg-impl.js +0 -83
- package/lib/framework/impl/comments/validate-msg-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-decorate-impl.d.ts +0 -30
- package/lib/framework/impl/data-element/data-decorate-impl.js +0 -91
- package/lib/framework/impl/data-element/data-decorate-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-barcode.d.ts +0 -31
- package/lib/framework/impl/data-element/data-element-barcode.js +0 -115
- package/lib/framework/impl/data-element/data-element-barcode.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-base-impl.d.ts +0 -68
- package/lib/framework/impl/data-element/data-element-base-impl.js +0 -205
- package/lib/framework/impl/data-element/data-element-base-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-check-impl.d.ts +0 -35
- package/lib/framework/impl/data-element/data-element-check-impl.js +0 -133
- package/lib/framework/impl/data-element/data-element-check-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-date-impl.d.ts +0 -23
- package/lib/framework/impl/data-element/data-element-date-impl.js +0 -111
- package/lib/framework/impl/data-element/data-element-date-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-group-impl.d.ts +0 -23
- package/lib/framework/impl/data-element/data-element-group-impl.js +0 -130
- package/lib/framework/impl/data-element/data-element-group-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-image-impl.d.ts +0 -30
- package/lib/framework/impl/data-element/data-element-image-impl.js +0 -137
- package/lib/framework/impl/data-element/data-element-image-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-list-impl.d.ts +0 -22
- package/lib/framework/impl/data-element/data-element-list-impl.js +0 -131
- package/lib/framework/impl/data-element/data-element-list-impl.js.map +0 -1
- package/lib/framework/impl/data-element/data-element-text-impl.d.ts +0 -23
- package/lib/framework/impl/data-element/data-element-text-impl.js +0 -103
- package/lib/framework/impl/data-element/data-element-text-impl.js.map +0 -1
- package/lib/framework/impl/decorate/fill-null-space-imple.d.ts +0 -21
- package/lib/framework/impl/decorate/fill-null-space-imple.js +0 -43
- package/lib/framework/impl/decorate/fill-null-space-imple.js.map +0 -1
- package/lib/framework/impl/document/doc-body-impl.d.ts +0 -27
- package/lib/framework/impl/document/doc-body-impl.js +0 -79
- package/lib/framework/impl/document/doc-body-impl.js.map +0 -1
- package/lib/framework/impl/document/doc-body-part-impl.d.ts +0 -30
- package/lib/framework/impl/document/doc-body-part-impl.js +0 -94
- package/lib/framework/impl/document/doc-body-part-impl.js.map +0 -1
- package/lib/framework/impl/document/doc-container-impl.d.ts +0 -16
- package/lib/framework/impl/document/doc-container-impl.js +0 -21
- package/lib/framework/impl/document/doc-container-impl.js.map +0 -1
- package/lib/framework/impl/document/doc-footer-impl.d.ts +0 -26
- package/lib/framework/impl/document/doc-footer-impl.js +0 -77
- package/lib/framework/impl/document/doc-footer-impl.js.map +0 -1
- package/lib/framework/impl/document/doc-header-impl.d.ts +0 -26
- package/lib/framework/impl/document/doc-header-impl.js +0 -83
- package/lib/framework/impl/document/doc-header-impl.js.map +0 -1
- package/lib/framework/impl/document/doc-impl.d.ts +0 -61
- package/lib/framework/impl/document/doc-impl.js +0 -209
- package/lib/framework/impl/document/doc-impl.js.map +0 -1
- package/lib/framework/impl/media-formula/menstrual-history.d.ts +0 -35
- package/lib/framework/impl/media-formula/menstrual-history.js +0 -153
- package/lib/framework/impl/media-formula/menstrual-history.js.map +0 -1
- package/lib/framework/impl/paragraph/p-impl.d.ts +0 -45
- package/lib/framework/impl/paragraph/p-impl.js +0 -156
- package/lib/framework/impl/paragraph/p-impl.js.map +0 -1
- package/lib/framework/impl/picture/image-impl.d.ts +0 -31
- package/lib/framework/impl/picture/image-impl.js +0 -124
- package/lib/framework/impl/picture/image-impl.js.map +0 -1
- package/lib/framework/impl/radio/radio-impl.d.ts +0 -22
- package/lib/framework/impl/radio/radio-impl.js +0 -72
- package/lib/framework/impl/radio/radio-impl.js.map +0 -1
- package/lib/framework/impl/symbol/br-symbol-impl.d.ts +0 -22
- package/lib/framework/impl/symbol/br-symbol-impl.js +0 -54
- package/lib/framework/impl/symbol/br-symbol-impl.js.map +0 -1
- package/lib/framework/impl/symbol/p-symbol-impl.d.ts +0 -19
- package/lib/framework/impl/symbol/p-symbol-impl.js +0 -54
- package/lib/framework/impl/symbol/p-symbol-impl.js.map +0 -1
- package/lib/framework/impl/table/table-cell-impl.d.ts +0 -37
- package/lib/framework/impl/table/table-cell-impl.js +0 -145
- package/lib/framework/impl/table/table-cell-impl.js.map +0 -1
- package/lib/framework/impl/table/table-impl.d.ts +0 -55
- package/lib/framework/impl/table/table-impl.js +0 -363
- package/lib/framework/impl/table/table-impl.js.map +0 -1
- package/lib/framework/impl/table/table-row-impl.d.ts +0 -26
- package/lib/framework/impl/table/table-row-impl.js +0 -75
- package/lib/framework/impl/table/table-row-impl.js.map +0 -1
- package/lib/framework/impl/table/table-split-cell-patch.d.ts +0 -20
- package/lib/framework/impl/table/table-split-cell-patch.js +0 -89
- package/lib/framework/impl/table/table-split-cell-patch.js.map +0 -1
- package/lib/framework/impl/table/table-split-cell.d.ts +0 -90
- package/lib/framework/impl/table/table-split-cell.js +0 -464
- package/lib/framework/impl/table/table-split-cell.js.map +0 -1
- package/lib/framework/impl/table/table-util.d.ts +0 -150
- package/lib/framework/impl/table/table-util.js +0 -678
- package/lib/framework/impl/table/table-util.js.map +0 -1
- package/lib/framework/impl/text/text-impl.d.ts +0 -32
- package/lib/framework/impl/text/text-impl.js +0 -149
- package/lib/framework/impl/text/text-impl.js.map +0 -1
- package/lib/framework/impl/text/track-run-impl.d.ts +0 -27
- package/lib/framework/impl/text/track-run-impl.js +0 -112
- package/lib/framework/impl/text/track-run-impl.js.map +0 -1
- package/lib/framework/notify.d.ts +0 -13
- package/lib/framework/notify.js +0 -116
- package/lib/framework/notify.js.map +0 -1
- package/lib/framework/range-util.d.ts +0 -40
- package/lib/framework/range-util.js +0 -312
- package/lib/framework/range-util.js.map +0 -1
- package/lib/framework/render-context.d.ts +0 -91
- package/lib/framework/render-context.js +0 -384
- package/lib/framework/render-context.js.map +0 -1
- package/lib/framework/render-define.d.ts +0 -109
- package/lib/framework/render-define.js +0 -195
- package/lib/framework/render-define.js.map +0 -1
- package/lib/framework/selection-overlays.d.ts +0 -30
- package/lib/framework/selection-overlays.js +0 -124
- package/lib/framework/selection-overlays.js.map +0 -1
- package/lib/texteditor.d.ts +0 -318
- package/lib/texteditor.js +0 -913
- package/lib/texteditor.js.map +0 -1
- package/lib/util/subject.d.ts +0 -34
- package/lib/util/subject.js +0 -88
- package/lib/util/subject.js.map +0 -1
- package/lib/util/table-bind.d.ts +0 -5
- package/lib/util/table-bind.js +0 -6
- package/lib/util/table-bind.js.map +0 -1
@@ -1,1342 +0,0 @@
|
|
1
|
-
import { SelectionRange } from "./document-selection";
|
2
|
-
import { ElementUtil } from "./element-util";
|
3
|
-
import { BlockContainerElement, BlockContentElement, BranchElement, DocMode, InlineGroupElement, LeafElement } from "./element-define";
|
4
|
-
import { TextGroupElement } from "./impl/text/text-impl";
|
5
|
-
import { PSymbolElement } from "./impl/symbol/p-symbol-impl";
|
6
|
-
import { ParagraphElement } from "./impl/paragraph/p-impl";
|
7
|
-
import { RangeUtil } from "./range-util";
|
8
|
-
import { TableElement } from "./impl/table/table-impl";
|
9
|
-
import { DocumentEvent } from "./document-event";
|
10
|
-
import { KeyboradElementEvent } from "./element-event-define";
|
11
|
-
import { ElementSerialize } from "./element-serialize";
|
12
|
-
import { BreakElement } from "./impl/symbol/br-symbol-impl";
|
13
|
-
import { DataDecorateElement } from "./impl/data-element/data-decorate-impl";
|
14
|
-
import { DataElementInlineGroup, InlineGroupInputElement, IsInSideDataElement, IsInSideInlineGroupInputElement } from "./impl/data-element/data-element-base-impl";
|
15
|
-
import { CommentElement } from "./impl/comments/comment-element-impl";
|
16
|
-
import { nanoid } from "nanoid";
|
17
|
-
import { CommContentElement } from "./impl/comments/comment-content-impl";
|
18
|
-
import { ValidateElement } from "@/med_editor/framework/impl/comments/validate-msg-impl";
|
19
|
-
import { CommonUtil } from "./common-util";
|
20
|
-
import { TrackRunElement, TrackRunTypeEnum } from "./impl/text/track-run-impl";
|
21
|
-
import { DocumentBodyElement } from "@/med_editor/framework/impl/document/doc-body-impl";
|
22
|
-
/**
|
23
|
-
* 文档内容改变
|
24
|
-
*/
|
25
|
-
export class DocumentChange {
|
26
|
-
selectionState;
|
27
|
-
viewOptions;
|
28
|
-
eleReader;
|
29
|
-
docCtx;
|
30
|
-
docComment;
|
31
|
-
constructor(selectionState, viewOptions, eleReader, docCtx, docComment) {
|
32
|
-
this.selectionState = selectionState;
|
33
|
-
this.viewOptions = viewOptions;
|
34
|
-
this.eleReader = eleReader;
|
35
|
-
this.docCtx = docCtx;
|
36
|
-
this.docComment = docComment;
|
37
|
-
}
|
38
|
-
newInput(data) {
|
39
|
-
const { startControl, startOffset, collapsed, enableTrackChanges } = this.selectionState;
|
40
|
-
if (!collapsed) {
|
41
|
-
this.onInputBySelection(data);
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
//判断是否需要创建新的留痕区域
|
45
|
-
if (enableTrackChanges && !this.isInCorrectTrackRegion(startControl, TrackRunTypeEnum.Inserted)) {
|
46
|
-
this.newInputTrackChanges(data, startControl, startOffset);
|
47
|
-
return;
|
48
|
-
}
|
49
|
-
//当前输入节点是在留痕区域中,但是当前关闭了审阅模式,需要拆分留痕区域,创建新输入节点
|
50
|
-
if (!enableTrackChanges && this.isInTrackBlock(startControl)) {
|
51
|
-
const newInput = this.splitTrackElement(startControl, startOffset);
|
52
|
-
const comp = data.compositionStartInfo;
|
53
|
-
comp.element = newInput;
|
54
|
-
comp.offset = 0;
|
55
|
-
this.inputTextGroup(newInput, data);
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
if (!(startControl instanceof TextGroupElement)) {
|
59
|
-
if (!data.compositionStartInfo) {
|
60
|
-
throw new Error('compositionStartInfo is null');
|
61
|
-
}
|
62
|
-
const siblingTextEle = startOffset === 1 ? ElementUtil.getNextSiblingElement(startControl) : ElementUtil.getPrevSiblingElement(startControl);
|
63
|
-
if (siblingTextEle instanceof TextGroupElement) {
|
64
|
-
data.compositionStartInfo.offset = startOffset === 0 ? siblingTextEle.text.length : 0;
|
65
|
-
this.inputTextGroup(siblingTextEle, data);
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
const inputTextProps = this.getDefaultTextProps(startControl, startOffset);
|
69
|
-
const newTextGroup = ElementUtil.getNewTextGroup(inputTextProps);
|
70
|
-
startControl.parent.addChild(newTextGroup, startControl.getIndex() + startOffset);
|
71
|
-
this.inputTextGroup(newTextGroup, data);
|
72
|
-
}
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
this.inputTextGroup(startControl, data);
|
76
|
-
}
|
77
|
-
/**
|
78
|
-
* 选中区域后进行输入
|
79
|
-
* 需要处理将选中的区域删除后,进行输入的情况
|
80
|
-
*/
|
81
|
-
onInputBySelection(data) {
|
82
|
-
this.onRangeDelete();
|
83
|
-
this.selectionState.afterSelectionChanged = (newVal) => {
|
84
|
-
const { startControl, startOffset, editable } = newVal;
|
85
|
-
if (!editable) {
|
86
|
-
return false;
|
87
|
-
}
|
88
|
-
const comp = data.compositionStartInfo;
|
89
|
-
comp.element = startControl;
|
90
|
-
comp.offset = startOffset;
|
91
|
-
this.newInput(data);
|
92
|
-
return true;
|
93
|
-
};
|
94
|
-
}
|
95
|
-
/**
|
96
|
-
* 当前元素是否在正确的留痕区域(ins-run、del-run),情况分为以下情况
|
97
|
-
* 1.留痕块类型为新增,但是留痕块的创建者为其他用户,此时需要拆分留痕区域
|
98
|
-
* 2.留痕块为当前用户创建,但是创建时间大于有效的时间,此时需要拆分留痕区域
|
99
|
-
* @param startControl
|
100
|
-
* @param trackType
|
101
|
-
* @returns
|
102
|
-
*/
|
103
|
-
isInCorrectTrackRegion(startControl, trackType) {
|
104
|
-
const parent = startControl.parent;
|
105
|
-
return parent instanceof TrackRunElement
|
106
|
-
&& parent.props.userId === this.viewOptions.editUser.id
|
107
|
-
&& parent.type === trackType
|
108
|
-
&& CommonUtil.getNowDiffSeconds(parent.props.date) <= this.viewOptions.trackChangePeriod;
|
109
|
-
}
|
110
|
-
/**
|
111
|
-
* 当前元素是否在留痕区域(ins-run、del-run)中
|
112
|
-
* @param target
|
113
|
-
* @param trackType
|
114
|
-
* @returns
|
115
|
-
*/
|
116
|
-
isInTrackBlock(target, trackType = null) {
|
117
|
-
return target.parent instanceof TrackRunElement && (trackType === null || target.parent.type === trackType);
|
118
|
-
}
|
119
|
-
/**
|
120
|
-
* 留痕输入
|
121
|
-
* @param data
|
122
|
-
* @param startControl
|
123
|
-
* @param startOffset
|
124
|
-
* @returns
|
125
|
-
*/
|
126
|
-
newInputTrackChanges(data, startControl, startOffset) {
|
127
|
-
const userId = this.viewOptions.editUser.id;
|
128
|
-
const compInfo = data.compositionStartInfo;
|
129
|
-
if (this.isInCorrectTrackRegion(startControl, TrackRunTypeEnum.Inserted)) {
|
130
|
-
return;
|
131
|
-
}
|
132
|
-
if (this.isInTrackBlock(startControl)) {
|
133
|
-
const newInput = this.createNewTrackInput(startControl, startOffset, TrackRunTypeEnum.Inserted);
|
134
|
-
compInfo.offset = 0;
|
135
|
-
compInfo.element = newInput;
|
136
|
-
this.inputTextGroup(newInput, data);
|
137
|
-
return;
|
138
|
-
}
|
139
|
-
else {
|
140
|
-
const { trackElement, newTextGroup } = this.createTextTrackElement(startControl, null, TrackRunTypeEnum.Inserted);
|
141
|
-
this.insertElement(startControl, startOffset, [trackElement]);
|
142
|
-
compInfo.offset = 0;
|
143
|
-
compInfo.element = newTextGroup;
|
144
|
-
this.inputTextGroup(newTextGroup, data);
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
}
|
148
|
-
/**
|
149
|
-
* 创建新的留痕块,并返回留痕块输入定位文本
|
150
|
-
* @param startControl
|
151
|
-
* @param startOffset
|
152
|
-
* @param trackType
|
153
|
-
* @returns
|
154
|
-
*/
|
155
|
-
createNewTrackInput(startControl, startOffset, trackType) {
|
156
|
-
const textProps = this.getDefaultTextProps(startControl, startOffset);
|
157
|
-
const currTrackEle = startControl.parent;
|
158
|
-
if (startControl instanceof TextGroupElement && startOffset > 0 && startOffset < startControl.textMeasures.length) {
|
159
|
-
const splitText = startControl.spliceText(startOffset, startControl.textMeasures.length, true);
|
160
|
-
startControl.parent.addChild(splitText, startControl.getIndex() + 1);
|
161
|
-
startOffset = startControl.textMeasures.length;
|
162
|
-
}
|
163
|
-
startOffset = startOffset > 0 ? 1 : 0;
|
164
|
-
const index = startControl.getIndex() + startOffset;
|
165
|
-
//切割留痕块
|
166
|
-
if (index > 0 && index < currTrackEle.length) {
|
167
|
-
const splitTrack = currTrackEle.split(startControl.getIndex() + startOffset);
|
168
|
-
currTrackEle.parent.addChild(splitTrack, currTrackEle.getIndex() + 1);
|
169
|
-
const { trackElement, newTextGroup } = this.createTextTrackElement(startControl, textProps, trackType);
|
170
|
-
currTrackEle.parent.addChild(trackElement, currTrackEle.getIndex() + 1);
|
171
|
-
return newTextGroup;
|
172
|
-
}
|
173
|
-
else {
|
174
|
-
const { trackElement, newTextGroup } = this.createTextTrackElement(startControl, textProps, trackType);
|
175
|
-
currTrackEle.parent.addChild(trackElement, currTrackEle.getIndex() + (index === 0 ? 0 : 1));
|
176
|
-
return newTextGroup;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
/**
|
180
|
-
* 获取当前输入节点的文本属性
|
181
|
-
* @param startControl
|
182
|
-
* @returns
|
183
|
-
*/
|
184
|
-
getDefaultTextProps(startControl, offset) {
|
185
|
-
const para = ElementUtil.getParentByType(startControl, ParagraphElement);
|
186
|
-
let textProps = para.props.textProps;
|
187
|
-
if (startControl instanceof TextGroupElement) {
|
188
|
-
textProps = startControl.props;
|
189
|
-
}
|
190
|
-
const dataEle = ElementUtil.getDataElement(startControl);
|
191
|
-
if (dataEle && IsInSideDataElement(startControl, offset)) {
|
192
|
-
return dataEle.props.valueTextProps;
|
193
|
-
}
|
194
|
-
return textProps;
|
195
|
-
}
|
196
|
-
/**
|
197
|
-
* 当前元素位于留痕区域内,但是当前编辑模式为非留痕模式,需要将当前留痕元素分割开来,插入新普通文本元素对象,并返回
|
198
|
-
* @param startControl
|
199
|
-
* @param startOffset
|
200
|
-
* @returns
|
201
|
-
*/
|
202
|
-
splitTrackElement(startControl, startOffset) {
|
203
|
-
if (!(startControl.parent instanceof TrackRunElement) && startControl instanceof TextGroupElement) {
|
204
|
-
return startControl;
|
205
|
-
}
|
206
|
-
const textProps = this.getDefaultTextProps(startControl, startOffset);
|
207
|
-
const currTrackEle = startControl.parent;
|
208
|
-
if (startControl instanceof TextGroupElement && startOffset > 0 && startOffset < startControl.textMeasures.length) {
|
209
|
-
const splitText = startControl.spliceText(startOffset, startControl.textMeasures.length, true);
|
210
|
-
startControl.parent.addChild(splitText, startControl.getIndex() + 1);
|
211
|
-
startOffset = startControl.textMeasures.length;
|
212
|
-
}
|
213
|
-
startOffset = startOffset > 0 ? 1 : 0;
|
214
|
-
const index = startControl.getIndex() + startOffset;
|
215
|
-
if (index > 0 && index < currTrackEle.length) {
|
216
|
-
const splitTrack = currTrackEle.split(startControl.getIndex() + startOffset);
|
217
|
-
currTrackEle.parent.addChild(splitTrack, currTrackEle.getIndex() + 1);
|
218
|
-
const newInput = ElementUtil.getNewTextGroup(textProps);
|
219
|
-
currTrackEle.parent.addChild(newInput, currTrackEle.getIndex() + 1);
|
220
|
-
return this.splitTrackElement(newInput, 0);
|
221
|
-
}
|
222
|
-
else {
|
223
|
-
const newInput = ElementUtil.getNewTextGroup(textProps);
|
224
|
-
currTrackEle.parent.addChild(newInput, currTrackEle.getIndex() + (index === 0 ? 0 : 1));
|
225
|
-
return this.splitTrackElement(newInput, 0);
|
226
|
-
}
|
227
|
-
}
|
228
|
-
/**
|
229
|
-
* 创建插入(ins-run) 留痕,并且返回留痕的文本元素对象
|
230
|
-
* @param startControl
|
231
|
-
* @returns
|
232
|
-
*/
|
233
|
-
createTextTrackElement(startControl, textProps, trackType) {
|
234
|
-
const para = ElementUtil.getParentByType(startControl, ParagraphElement);
|
235
|
-
const trackElement = this.createTrackElement(trackType);
|
236
|
-
textProps = textProps || para.props.textProps;
|
237
|
-
const newTextGroup = ElementUtil.getNewTextGroup(textProps);
|
238
|
-
newTextGroup.props.color = '#ff4d4f';
|
239
|
-
trackElement.addChild(newTextGroup);
|
240
|
-
return {
|
241
|
-
trackElement,
|
242
|
-
newTextGroup
|
243
|
-
};
|
244
|
-
}
|
245
|
-
createTrackElement(trackType) {
|
246
|
-
const trackElement = new TrackRunElement(trackType);
|
247
|
-
trackElement.props.userId = this.viewOptions.editUser.id;
|
248
|
-
trackElement.props.userName = this.viewOptions.editUser.name;
|
249
|
-
trackElement.props.date = CommonUtil.formatNow('YYYY-MM-DD HH:mm:ss');
|
250
|
-
trackElement.props.id = nanoid(5);
|
251
|
-
return trackElement;
|
252
|
-
}
|
253
|
-
inputTextGroup(text, data) {
|
254
|
-
const prevInputData = data.prevInputData || '';
|
255
|
-
const prevInputDataLength = prevInputData.length;
|
256
|
-
if (!data.compositionStartInfo) {
|
257
|
-
throw new Error('compositionStartInfo is null');
|
258
|
-
}
|
259
|
-
const { element, offset } = data.compositionStartInfo;
|
260
|
-
let startInputOffset = offset;
|
261
|
-
//startInputOffset -= prevInputDataLength;
|
262
|
-
if (!(element instanceof TextGroupElement)) {
|
263
|
-
//当前选中元素位于输入元素是起始还是结束位置,如果位于起始位置,则输入偏移量为0,否则为未变更之前的内容length
|
264
|
-
if (ElementUtil.getNextSiblingElement(element) === text) {
|
265
|
-
startInputOffset = 0;
|
266
|
-
}
|
267
|
-
else {
|
268
|
-
startInputOffset = text.textMeasures.length - prevInputDataLength;
|
269
|
-
}
|
270
|
-
}
|
271
|
-
text.splice(startInputOffset, prevInputDataLength, data.data);
|
272
|
-
//输入后撤销,导致文本组内为空
|
273
|
-
if (!text.text.length) {
|
274
|
-
this.removeEmptyText(text);
|
275
|
-
}
|
276
|
-
else {
|
277
|
-
this.selectionState.resetRange(text, startInputOffset + data.data.length);
|
278
|
-
}
|
279
|
-
}
|
280
|
-
/**
|
281
|
-
* backspace,向前删除
|
282
|
-
*/
|
283
|
-
onBackspace(evt) {
|
284
|
-
const { startControl, startOffset, collapsed } = this.selectionState;
|
285
|
-
if (!startControl) {
|
286
|
-
throw new Error('startControl is null');
|
287
|
-
}
|
288
|
-
const eventElement = new KeyboradElementEvent(this.docCtx);
|
289
|
-
eventElement.key = 'backspace';
|
290
|
-
eventElement.source = startControl;
|
291
|
-
eventElement.sourceEvent = evt;
|
292
|
-
eventElement.sourceOffset = startOffset;
|
293
|
-
const res = DocumentEvent.invokeEvent('BackspaceKey', startControl, eventElement, 'Capture', this.docCtx);
|
294
|
-
if (res && res.isCancel) {
|
295
|
-
return;
|
296
|
-
}
|
297
|
-
this.docComment.updateComments();
|
298
|
-
if (collapsed) {
|
299
|
-
this.onBackspaceElement(startControl, startOffset);
|
300
|
-
}
|
301
|
-
else {
|
302
|
-
this.onRangeDelete();
|
303
|
-
}
|
304
|
-
}
|
305
|
-
/**
|
306
|
-
* delete,向后删除
|
307
|
-
* @param evt
|
308
|
-
*/
|
309
|
-
onDeleteKeyHandler(evt) {
|
310
|
-
const { startControl, startOffset, collapsed } = this.selectionState;
|
311
|
-
const eventElement = new KeyboradElementEvent(this.docCtx);
|
312
|
-
eventElement.key = 'delete';
|
313
|
-
eventElement.source = startControl;
|
314
|
-
eventElement.sourceEvent = evt;
|
315
|
-
eventElement.sourceOffset = startOffset;
|
316
|
-
const res = DocumentEvent.invokeEvent('DeleteKey', startControl, eventElement, 'Capture', this.docCtx);
|
317
|
-
if (res && res.isCancel) {
|
318
|
-
return;
|
319
|
-
}
|
320
|
-
if (collapsed) {
|
321
|
-
this.onKeyDeleteElement(startControl, startOffset);
|
322
|
-
}
|
323
|
-
else {
|
324
|
-
this.onRangeDelete();
|
325
|
-
}
|
326
|
-
}
|
327
|
-
/**
|
328
|
-
* 根据选择范围删除
|
329
|
-
*/
|
330
|
-
onRangeDelete() {
|
331
|
-
const { selectedRange } = this.selectionState;
|
332
|
-
if (!selectedRange) {
|
333
|
-
throw new Error('selectionRange is null');
|
334
|
-
}
|
335
|
-
//用于刷新后定位光标
|
336
|
-
let startPointElement;
|
337
|
-
let startPointOffset = 0;
|
338
|
-
if (selectedRange.isFullSelected) {
|
339
|
-
//某个容器的内容被全部选中
|
340
|
-
if (selectedRange.target instanceof BlockContainerElement) {
|
341
|
-
startPointElement = selectedRange.target;
|
342
|
-
startPointOffset = 0;
|
343
|
-
}
|
344
|
-
//内容块被选中,需要向上寻找内容块容器
|
345
|
-
else if (selectedRange.target instanceof BlockContentElement) {
|
346
|
-
const parentContainer = ElementUtil.getParent(selectedRange.target, (item) => item instanceof BlockContainerElement);
|
347
|
-
if (parentContainer) {
|
348
|
-
startPointElement = parentContainer;
|
349
|
-
startPointOffset = 0;
|
350
|
-
}
|
351
|
-
else {
|
352
|
-
throw new Error('未能向上寻找到定位的内容块容器');
|
353
|
-
}
|
354
|
-
}
|
355
|
-
else {
|
356
|
-
throw new Error('未知条件区间');
|
357
|
-
}
|
358
|
-
}
|
359
|
-
else {
|
360
|
-
const startRange = RangeUtil.getStartRangeTarget(selectedRange);
|
361
|
-
const endRange = RangeUtil.getEndRangeTarget(selectedRange);
|
362
|
-
if (startRange.isFullSelected) {
|
363
|
-
startPointElement = ElementUtil.getRecursionPrevSiblingElement(startRange.target, false, true);
|
364
|
-
startPointOffset = -1;
|
365
|
-
//判断结束选区和开始选区是否在一个段落中,尽量落在同一段落中
|
366
|
-
if (!startPointElement || ElementUtil.isInSameParagraph(startRange.target, endRange.target)) {
|
367
|
-
if (!endRange.isFullSelected) {
|
368
|
-
startPointElement = endRange.target;
|
369
|
-
startPointOffset = 0;
|
370
|
-
}
|
371
|
-
}
|
372
|
-
}
|
373
|
-
else {
|
374
|
-
startPointElement = startRange.target;
|
375
|
-
startPointOffset = startRange.startOffset;
|
376
|
-
}
|
377
|
-
}
|
378
|
-
if (this.viewOptions.docMode === DocMode.FormEdit) {
|
379
|
-
this.deleteRangeInFormEdit(selectedRange);
|
380
|
-
}
|
381
|
-
else {
|
382
|
-
this.deleteRange(selectedRange);
|
383
|
-
}
|
384
|
-
this.selectionState.resetRange(startPointElement, startPointOffset);
|
385
|
-
return { cursorEle: startPointElement, cursorOffset: startPointOffset };
|
386
|
-
}
|
387
|
-
/**
|
388
|
-
* backspace删除
|
389
|
-
* @param control
|
390
|
-
* @param offset
|
391
|
-
* @returns
|
392
|
-
*/
|
393
|
-
onBackspaceElement(control, offset) {
|
394
|
-
this.selectionState.clear();
|
395
|
-
if (offset === 0) {
|
396
|
-
const prevEle = ElementUtil.getRecursionPrevSiblingElement(control, false, true);
|
397
|
-
if (!prevEle) {
|
398
|
-
this.selectionState.resetRange(control, 0);
|
399
|
-
return;
|
400
|
-
}
|
401
|
-
if (ElementUtil.isInSameParagraph(control, prevEle)) {
|
402
|
-
if (ElementUtil.getPrevSiblingElement(control) === prevEle) {
|
403
|
-
this.onBackspaceElement(prevEle, ElementUtil.getElementEndOffset(prevEle));
|
404
|
-
}
|
405
|
-
else {
|
406
|
-
this.selectionState.resetRange(prevEle, -1);
|
407
|
-
}
|
408
|
-
}
|
409
|
-
else {
|
410
|
-
//需要判断是否是兄弟段落,兄弟段落,需要合并
|
411
|
-
const prevPara = ElementUtil.getParentByType(prevEle, ParagraphElement);
|
412
|
-
const currPara = ElementUtil.getParentByType(control, ParagraphElement);
|
413
|
-
//表明是紧挨着的两个段落,要进行段落合并
|
414
|
-
if (ElementUtil.getPrevSiblingElement(currPara) === prevPara) {
|
415
|
-
if (this.selectionState.enableTrackChanges) {
|
416
|
-
this.selectionState.resetRange(prevEle, -1);
|
417
|
-
return;
|
418
|
-
}
|
419
|
-
this.combineParagraph(prevPara, currPara, control);
|
420
|
-
}
|
421
|
-
else {
|
422
|
-
//不是紧挨着的段落,则前一个段落是位于另一个容器里,例如:处于单元格内的段落
|
423
|
-
//则不向前定位
|
424
|
-
this.selectionState.resetRange(control, offset);
|
425
|
-
}
|
426
|
-
}
|
427
|
-
}
|
428
|
-
else {
|
429
|
-
if (control instanceof TextGroupElement) {
|
430
|
-
this.onDeleteText(control, offset - 1, 1);
|
431
|
-
if (!control.textMeasures.length) {
|
432
|
-
this.removeEmptyText(control);
|
433
|
-
}
|
434
|
-
else {
|
435
|
-
this.selectionState.resetRange(control, offset - 1);
|
436
|
-
}
|
437
|
-
}
|
438
|
-
else {
|
439
|
-
if (control.parent instanceof InlineGroupInputElement && control instanceof DataDecorateElement) {
|
440
|
-
const dataEle = control.parent;
|
441
|
-
//空数据元,并且当前光标处于数据元开始位置
|
442
|
-
if (this.canDeleteInlineGroup(dataEle)) {
|
443
|
-
this.setCurosrForDeleteAction(dataEle);
|
444
|
-
dataEle.remove();
|
445
|
-
return;
|
446
|
-
}
|
447
|
-
if (control.isPrefix && this.viewOptions.docMode === DocMode.FormEdit) {
|
448
|
-
if (this.jumpToPrevDataElement(dataEle)) {
|
449
|
-
return;
|
450
|
-
}
|
451
|
-
}
|
452
|
-
}
|
453
|
-
if (control.isDecorate) {
|
454
|
-
this.onBackspaceElement(control, 0);
|
455
|
-
return;
|
456
|
-
}
|
457
|
-
this.removeElement(control);
|
458
|
-
}
|
459
|
-
}
|
460
|
-
}
|
461
|
-
/**
|
462
|
-
* 跳到上一个数据元中
|
463
|
-
* @param currEle
|
464
|
-
*/
|
465
|
-
jumpToPrevDataElement(currEle) {
|
466
|
-
if (this.viewOptions.docMode !== DocMode.FormEdit) {
|
467
|
-
return false;
|
468
|
-
}
|
469
|
-
const prevEle = ElementUtil.getPrevDataElement(this.docCtx, currEle);
|
470
|
-
if (!prevEle) {
|
471
|
-
return false;
|
472
|
-
}
|
473
|
-
if (prevEle) {
|
474
|
-
this.selectionState.resetRange(prevEle.endDecorate, 0);
|
475
|
-
return true;
|
476
|
-
}
|
477
|
-
return false;
|
478
|
-
}
|
479
|
-
/**
|
480
|
-
* delete删除
|
481
|
-
* @param control
|
482
|
-
* @param offset
|
483
|
-
* @returns
|
484
|
-
*/
|
485
|
-
onKeyDeleteElement(control, offset) {
|
486
|
-
this.selectionState.clear();
|
487
|
-
if (offset === ElementUtil.getElementEndOffset(control)) {
|
488
|
-
const nextEle = ElementUtil.getRecursionNextSiblingElement(control, false, true);
|
489
|
-
if (!nextEle) {
|
490
|
-
this.selectionState.resetRange(control, -1);
|
491
|
-
return;
|
492
|
-
}
|
493
|
-
if (ElementUtil.isInSameParagraph(control, nextEle)) {
|
494
|
-
if (ElementUtil.getNextSiblingElement(control) === nextEle) {
|
495
|
-
this.onKeyDeleteElement(nextEle, 0);
|
496
|
-
}
|
497
|
-
else {
|
498
|
-
this.selectionState.resetRange(nextEle, 0);
|
499
|
-
}
|
500
|
-
}
|
501
|
-
else {
|
502
|
-
//需要判断是否是兄弟段落,兄弟段落,需要合并
|
503
|
-
const nextPara = ElementUtil.getParentByType(nextEle, ParagraphElement);
|
504
|
-
const currPara = ElementUtil.getParentByType(control, ParagraphElement);
|
505
|
-
//表明是紧挨着的两个段落,要进行段落合并
|
506
|
-
if (ElementUtil.getNextSiblingElement(currPara) === nextPara) {
|
507
|
-
if (this.selectionState.enableTrackChanges) {
|
508
|
-
this.selectionState.resetRange(nextEle, 0);
|
509
|
-
return;
|
510
|
-
}
|
511
|
-
this.combineParagraph(nextPara, currPara, control);
|
512
|
-
}
|
513
|
-
else {
|
514
|
-
//不是紧挨着的段落,则前一个段落是位于另一个容器里,例如:处于单元格内的段落
|
515
|
-
//则不向前定位
|
516
|
-
this.selectionState.resetRange(control, offset);
|
517
|
-
}
|
518
|
-
}
|
519
|
-
}
|
520
|
-
else {
|
521
|
-
if (control instanceof TextGroupElement) {
|
522
|
-
this.onDeleteText(control, offset, 1);
|
523
|
-
if (!control.textMeasures.length) {
|
524
|
-
this.removeEmptyText(control);
|
525
|
-
}
|
526
|
-
else {
|
527
|
-
this.selectionState.resetRange(control, offset);
|
528
|
-
}
|
529
|
-
}
|
530
|
-
else {
|
531
|
-
if (control.parent instanceof DataElementInlineGroup && control instanceof DataDecorateElement) {
|
532
|
-
const dataEle = control.parent;
|
533
|
-
//空数据元,并且当前光标处于数据元开始位置
|
534
|
-
if (control.isPrefix) {
|
535
|
-
if (this.canDeleteInlineGroup(dataEle)) {
|
536
|
-
this.setCurosrForDeleteAction(dataEle);
|
537
|
-
dataEle.remove();
|
538
|
-
}
|
539
|
-
else {
|
540
|
-
this.selectionState.resetRange(control, -1);
|
541
|
-
}
|
542
|
-
return;
|
543
|
-
}
|
544
|
-
else if (!control.isPrefix && dataEle.length === 2) {
|
545
|
-
this.selectionState.resetRange(dataEle.endDecorate, -1);
|
546
|
-
return;
|
547
|
-
}
|
548
|
-
}
|
549
|
-
if (control.isDecorate) {
|
550
|
-
//this.onKeyDeleteElement(control, -1);
|
551
|
-
return;
|
552
|
-
}
|
553
|
-
this.removeElement(control);
|
554
|
-
}
|
555
|
-
}
|
556
|
-
}
|
557
|
-
/**
|
558
|
-
* 判断是否可以删除数据组
|
559
|
-
* @param dataEle
|
560
|
-
* @private
|
561
|
-
*/
|
562
|
-
canDeleteInlineGroup(dataEle) {
|
563
|
-
if (this.viewOptions.docMode === DocMode.FormEdit) {
|
564
|
-
return false;
|
565
|
-
}
|
566
|
-
return dataEle.length === 2;
|
567
|
-
}
|
568
|
-
onDeleteText(text, offset, len) {
|
569
|
-
if (this.selectionState.enableTrackChanges) {
|
570
|
-
this.updateDeletedTrackText(text, offset, len);
|
571
|
-
}
|
572
|
-
else {
|
573
|
-
text.splice(offset, len);
|
574
|
-
}
|
575
|
-
}
|
576
|
-
onDeleteItem(item) {
|
577
|
-
if (this.selectionState.enableTrackChanges) {
|
578
|
-
//删除符号不进行留痕
|
579
|
-
if (item.type === 'psym') {
|
580
|
-
return;
|
581
|
-
}
|
582
|
-
this.onTrackDeleteElement(item);
|
583
|
-
}
|
584
|
-
else {
|
585
|
-
item.remove();
|
586
|
-
item.destroy();
|
587
|
-
}
|
588
|
-
}
|
589
|
-
/**
|
590
|
-
* 当前元素是否在留痕元素内
|
591
|
-
* @param target
|
592
|
-
* @param trackType
|
593
|
-
* @returns
|
594
|
-
*/
|
595
|
-
isInCurrentUserTrack(target, trackType) {
|
596
|
-
if (target.parent instanceof TrackRunElement && target.parent.type === trackType && target.parent.props.userId === this.viewOptions.editUser.id) {
|
597
|
-
return true;
|
598
|
-
}
|
599
|
-
return false;
|
600
|
-
}
|
601
|
-
isInTrackElement(target, trackType) {
|
602
|
-
if (target.parent instanceof TrackRunElement && target.parent.type === trackType) {
|
603
|
-
return true;
|
604
|
-
}
|
605
|
-
return false;
|
606
|
-
}
|
607
|
-
/**
|
608
|
-
* 留痕除文本以外的其他元素
|
609
|
-
* @param control
|
610
|
-
*/
|
611
|
-
onTrackDeleteElement(target) {
|
612
|
-
const parent = target.parent;
|
613
|
-
if (this.isInTrackElement(target, TrackRunTypeEnum.Deleted)) {
|
614
|
-
return;
|
615
|
-
}
|
616
|
-
//当前用户增加的内容,内容直接删除不需要留痕
|
617
|
-
if (this.isInCurrentUserTrack(target, TrackRunTypeEnum.Inserted)) {
|
618
|
-
target.remove();
|
619
|
-
this.removeEmtpyInlineBlock(parent);
|
620
|
-
return;
|
621
|
-
}
|
622
|
-
//target.remove();
|
623
|
-
const trackEle = this.getNextTrackElement(target, TrackRunTypeEnum.Deleted);
|
624
|
-
trackEle.addChild(target.clone(true), 0);
|
625
|
-
target.remove();
|
626
|
-
this.removeEmtpyInlineBlock(parent);
|
627
|
-
}
|
628
|
-
/**
|
629
|
-
* 更新文本删除留痕
|
630
|
-
*/
|
631
|
-
updateDeletedTrackText(target, offset, len) {
|
632
|
-
if (this.isInTrackElement(target, TrackRunTypeEnum.Deleted)) {
|
633
|
-
return;
|
634
|
-
}
|
635
|
-
//当前用户增加的内容,当前用户删除时不需要留痕
|
636
|
-
if (this.isInCurrentUserTrack(target, TrackRunTypeEnum.Inserted)) {
|
637
|
-
target.splice(offset, len);
|
638
|
-
return;
|
639
|
-
}
|
640
|
-
//全部被删除
|
641
|
-
if (offset === 0 && len === target.textMeasures.length) {
|
642
|
-
const trackInputText = this.getNextTrackInputElement(target, TrackRunTypeEnum.Deleted);
|
643
|
-
trackInputText.text = target.text + trackInputText.text;
|
644
|
-
target.splice(0, target.textMeasures.length);
|
645
|
-
//target.remove();
|
646
|
-
return;
|
647
|
-
}
|
648
|
-
const { leftElement } = this.splitText(target, offset + len);
|
649
|
-
target = leftElement;
|
650
|
-
let trackText = this.getNextTrackInputElement(target, TrackRunTypeEnum.Deleted);
|
651
|
-
const spText = target.spliceText(target.textMeasures.length - len, target.textMeasures.length, true);
|
652
|
-
trackText.splice(0, 0, spText?.text);
|
653
|
-
}
|
654
|
-
getNextTrackInputElement(target, trackType) {
|
655
|
-
const trackElement = ElementUtil.getNextSiblingTrackElement(target, trackType, this.viewOptions.editUser.id);
|
656
|
-
if (trackElement) {
|
657
|
-
const firstEle = trackElement.getChild(0);
|
658
|
-
if (firstEle && firstEle instanceof TextGroupElement) {
|
659
|
-
return firstEle;
|
660
|
-
}
|
661
|
-
else {
|
662
|
-
const newInput = new TextGroupElement();
|
663
|
-
trackElement.addChild(newInput, 0);
|
664
|
-
target.props.clone(newInput.props);
|
665
|
-
return newInput;
|
666
|
-
}
|
667
|
-
}
|
668
|
-
else {
|
669
|
-
const { trackElement, newTextGroup } = this.createTextTrackElement(target, target.props, TrackRunTypeEnum.Deleted);
|
670
|
-
target.parent.addChild(trackElement, target.getIndex() + 1);
|
671
|
-
return newTextGroup;
|
672
|
-
}
|
673
|
-
}
|
674
|
-
getNextTrackElement(target, trackType) {
|
675
|
-
let trackElement = ElementUtil.getNextSiblingTrackElement(target, trackType, this.viewOptions.editUser.id);
|
676
|
-
if (!trackElement) {
|
677
|
-
trackElement = this.createTrackElement(trackType);
|
678
|
-
target.parent.addChild(trackElement, target.getIndex() + 1);
|
679
|
-
}
|
680
|
-
return trackElement;
|
681
|
-
}
|
682
|
-
/**
|
683
|
-
* 删除元素并定位光标
|
684
|
-
* @param control
|
685
|
-
* @returns
|
686
|
-
*/
|
687
|
-
removeElement(control) {
|
688
|
-
const prevEle = ElementUtil.getRecursionPrevSiblingElement(control, false, true);
|
689
|
-
if (!prevEle) {
|
690
|
-
const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true);
|
691
|
-
if (nextEle) {
|
692
|
-
this.selectionState.resetRange(nextEle, 0);
|
693
|
-
control.remove();
|
694
|
-
return;
|
695
|
-
}
|
696
|
-
return;
|
697
|
-
}
|
698
|
-
if (ElementUtil.isInSameParagraph(control, prevEle)) {
|
699
|
-
this.selectionState.resetRange(prevEle, -1);
|
700
|
-
control.remove();
|
701
|
-
return;
|
702
|
-
}
|
703
|
-
else {
|
704
|
-
const nextEle = ElementUtil.getRecursionNextSiblingElement(control, true, true);
|
705
|
-
if (nextEle && ElementUtil.getPrevSiblingElement(nextEle) === control) {
|
706
|
-
this.selectionState.resetRange(nextEle, 0);
|
707
|
-
control.remove();
|
708
|
-
return;
|
709
|
-
}
|
710
|
-
else {
|
711
|
-
this.selectionState.resetRange(prevEle, -1);
|
712
|
-
control.remove();
|
713
|
-
return;
|
714
|
-
}
|
715
|
-
}
|
716
|
-
}
|
717
|
-
/**
|
718
|
-
* 回车事件
|
719
|
-
*/
|
720
|
-
onEnter() {
|
721
|
-
const { startControl } = this.selectionState;
|
722
|
-
const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
|
723
|
-
const breakPara = this.splitCurrentParagraph();
|
724
|
-
//选中的是一个元素
|
725
|
-
if (breakPara === paragraph) {
|
726
|
-
const clonePara = paragraph.clone(false);
|
727
|
-
breakPara.parent.addChild(clonePara, breakPara.getIndex());
|
728
|
-
}
|
729
|
-
this.selectionState.resetRange(breakPara, 0);
|
730
|
-
}
|
731
|
-
/**
|
732
|
-
* 插入表格
|
733
|
-
* @param tb
|
734
|
-
* @returns
|
735
|
-
*/
|
736
|
-
insertTable(tb) {
|
737
|
-
const breakPara = this.splitCurrentParagraph();
|
738
|
-
breakPara.parent.addChild(tb, breakPara.getIndex());
|
739
|
-
this.selectionState.resetRange(tb, 0);
|
740
|
-
}
|
741
|
-
/**
|
742
|
-
* 分割当前段落用于插入表格或者粘贴的内容
|
743
|
-
* @param insertItems 分割后插入的内容,内容需要是block或者表格对象
|
744
|
-
*/
|
745
|
-
splitCurrentParagraph() {
|
746
|
-
const { startControl, startOffset } = this.selectionState;
|
747
|
-
const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
|
748
|
-
const paraContainer = paragraph.parent;
|
749
|
-
//如果选中的是段落第一个元素
|
750
|
-
const firstLeaf = ElementUtil.getFirstLeafElement(paragraph);
|
751
|
-
if ((startControl === firstLeaf && startOffset === 0) || (startControl === firstLeaf && startControl instanceof PSymbolElement)) {
|
752
|
-
//this.selectionState.resetRange(paragraph, 0);
|
753
|
-
return paragraph;
|
754
|
-
}
|
755
|
-
const last = ElementUtil.getLastLeafElement(paragraph);
|
756
|
-
const selectedParaRange = RangeUtil.getSelctionRange(startControl, startOffset, last, 1, paragraph);
|
757
|
-
selectedParaRange.isFullSelected = false;
|
758
|
-
const breakPara = ElementUtil.cloneRange(selectedParaRange, true);
|
759
|
-
ElementUtil.fixParagraphContent(paragraph);
|
760
|
-
ElementUtil.fixParagraphContent(breakPara);
|
761
|
-
paraContainer.addChild(breakPara, paragraph.getIndex() + 1);
|
762
|
-
//paraContainer.addChild(tb, breakPara.getIndex());
|
763
|
-
//this.selectionState.resetRange(breakPara, 0);
|
764
|
-
return breakPara;
|
765
|
-
}
|
766
|
-
/**
|
767
|
-
* 合并段落
|
768
|
-
*/
|
769
|
-
combineParagraph(prevPara, currPara, currElement) {
|
770
|
-
const prevParaLength = prevPara.length;
|
771
|
-
for (let i = 0; i < currPara.length; i++) {
|
772
|
-
const child = currPara.getChild(i).clone(true);
|
773
|
-
prevPara.addChild(child);
|
774
|
-
}
|
775
|
-
//currPara.remove();
|
776
|
-
const currParaContainer = currPara.parent;
|
777
|
-
currPara.destroy();
|
778
|
-
currParaContainer.removeChild(currPara);
|
779
|
-
this.selectionState.resetRange(prevPara.getChild(prevParaLength), 0);
|
780
|
-
}
|
781
|
-
/**
|
782
|
-
* 删除选中的区域内容
|
783
|
-
* @param range
|
784
|
-
*/
|
785
|
-
deleteRange(range) {
|
786
|
-
const { selectedChildren } = range;
|
787
|
-
for (let i = selectedChildren.length - 1; i >= 0; i--) {
|
788
|
-
const childRange = selectedChildren[i];
|
789
|
-
const { target: childTarget, isFullSelected: childFullSelected } = childRange;
|
790
|
-
if (childTarget instanceof LeafElement && !childTarget.isDecorate) {
|
791
|
-
if (childFullSelected) {
|
792
|
-
this.onDeleteItem(childTarget);
|
793
|
-
}
|
794
|
-
else if (childTarget instanceof TextGroupElement) {
|
795
|
-
const { startOffset, endOffset } = childRange;
|
796
|
-
this.onDeleteText(childTarget, startOffset, endOffset - startOffset);
|
797
|
-
}
|
798
|
-
}
|
799
|
-
else if (childTarget instanceof BranchElement) {
|
800
|
-
//留痕模式
|
801
|
-
if (this.selectionState.enableTrackChanges) {
|
802
|
-
this.deleteRange(childRange);
|
803
|
-
}
|
804
|
-
else {
|
805
|
-
//表格全选状态时,执行删除操作
|
806
|
-
if (childTarget instanceof TableElement && childFullSelected) {
|
807
|
-
childTarget.remove();
|
808
|
-
childTarget.destroy();
|
809
|
-
}
|
810
|
-
//段落全选状态时,执行删除操作
|
811
|
-
else if (childTarget instanceof BlockContentElement && childFullSelected) {
|
812
|
-
childTarget.remove();
|
813
|
-
childTarget.destroy();
|
814
|
-
}
|
815
|
-
else if (childTarget instanceof InlineGroupElement && childFullSelected) {
|
816
|
-
childTarget.remove();
|
817
|
-
childTarget.destroy();
|
818
|
-
}
|
819
|
-
else {
|
820
|
-
this.deleteRange(childRange);
|
821
|
-
}
|
822
|
-
}
|
823
|
-
}
|
824
|
-
}
|
825
|
-
}
|
826
|
-
/**
|
827
|
-
* 表单区域删除处理
|
828
|
-
* @param range
|
829
|
-
* @returns
|
830
|
-
*/
|
831
|
-
deleteRangeInFormEdit(range) {
|
832
|
-
const dataElement = ElementUtil.getDataElement(range.target);
|
833
|
-
//在数据元内删除,调用普通的删除处理
|
834
|
-
if (dataElement) {
|
835
|
-
this.deleteRange(range);
|
836
|
-
return;
|
837
|
-
}
|
838
|
-
//在数据元外删除
|
839
|
-
else {
|
840
|
-
this.loopForDelDataEleRange(range);
|
841
|
-
}
|
842
|
-
}
|
843
|
-
/**
|
844
|
-
* 表单模式:删除选中的区域内容
|
845
|
-
*/
|
846
|
-
loopForDelDataEleRange(range) {
|
847
|
-
const { selectedChildren } = range;
|
848
|
-
for (let i = selectedChildren.length - 1; i >= 0; i--) {
|
849
|
-
const childRange = selectedChildren[i];
|
850
|
-
const { target: childTarget } = childRange;
|
851
|
-
if (childTarget instanceof BranchElement) {
|
852
|
-
if (childTarget instanceof DataElementInlineGroup) {
|
853
|
-
const dataEleProps = childTarget.props;
|
854
|
-
//数据元可编辑
|
855
|
-
if (dataEleProps.editable) {
|
856
|
-
this.deleteRange(childRange);
|
857
|
-
}
|
858
|
-
}
|
859
|
-
else {
|
860
|
-
this.loopForDelDataEleRange(childRange);
|
861
|
-
}
|
862
|
-
}
|
863
|
-
}
|
864
|
-
}
|
865
|
-
/**
|
866
|
-
* 向目标移动元素
|
867
|
-
* @param sourceElement
|
868
|
-
* @param moveElement
|
869
|
-
*/
|
870
|
-
moveElement(targetElement, targetOffset, moveElement, moveOffset, ss) {
|
871
|
-
moveElement.remove();
|
872
|
-
if (targetElement instanceof TextGroupElement) {
|
873
|
-
const { leftElement, rightElement } = this.splitText(targetElement, targetOffset);
|
874
|
-
if (leftElement) {
|
875
|
-
leftElement.parent.addChild(moveElement, leftElement.getIndex() + 1);
|
876
|
-
}
|
877
|
-
else if (rightElement) {
|
878
|
-
rightElement.parent.addChild(moveElement, rightElement.getIndex());
|
879
|
-
}
|
880
|
-
}
|
881
|
-
else {
|
882
|
-
targetElement.parent.addChild(moveElement, targetElement.getIndex() + targetOffset);
|
883
|
-
}
|
884
|
-
ss.resetRange(moveElement, moveOffset);
|
885
|
-
}
|
886
|
-
/**
|
887
|
-
* 向指定的目标插入元素
|
888
|
-
* @param targetElement
|
889
|
-
* @param targetOffset
|
890
|
-
* @param destEleArray
|
891
|
-
*/
|
892
|
-
insertElement(targetElement, targetOffset, destEleArray) {
|
893
|
-
let lastEle;
|
894
|
-
if (targetElement instanceof TextGroupElement) {
|
895
|
-
const { leftElement, rightElement } = this.splitText(targetElement, targetOffset);
|
896
|
-
if (leftElement) {
|
897
|
-
for (let i = 0; i < destEleArray.length; i++) {
|
898
|
-
lastEle = destEleArray[i];
|
899
|
-
leftElement.parent.addChild(lastEle, leftElement.getIndex() + 1 + i);
|
900
|
-
}
|
901
|
-
}
|
902
|
-
else if (rightElement) {
|
903
|
-
for (let i = 0; i < destEleArray.length; i++) {
|
904
|
-
lastEle = destEleArray[i];
|
905
|
-
rightElement.parent.addChild(lastEle, rightElement.getIndex());
|
906
|
-
}
|
907
|
-
}
|
908
|
-
}
|
909
|
-
else {
|
910
|
-
for (let i = 0; i < destEleArray.length; i++) {
|
911
|
-
lastEle = destEleArray[i];
|
912
|
-
targetElement.parent.addChild(lastEle, targetElement.getIndex() + targetOffset);
|
913
|
-
}
|
914
|
-
}
|
915
|
-
return lastEle;
|
916
|
-
}
|
917
|
-
/**
|
918
|
-
* 根据开始位置和结束位置,将字符切割成指定的区间
|
919
|
-
* @param splitTextUnit
|
920
|
-
* @param start
|
921
|
-
* @param end
|
922
|
-
* @returns
|
923
|
-
*/
|
924
|
-
static splitTextGroupByRange(text, start, end) {
|
925
|
-
end = end === -1 ? text.textMeasures.length : end;
|
926
|
-
if (start === end) {
|
927
|
-
return null;
|
928
|
-
}
|
929
|
-
if (start === 0 && end === text.textMeasures.length) {
|
930
|
-
return text;
|
931
|
-
}
|
932
|
-
if (start === text.textMeasures.length) {
|
933
|
-
return null;
|
934
|
-
}
|
935
|
-
let lastTextGroup = text.spliceText(end, -1, true);
|
936
|
-
let middleTextGroup = text.spliceText(start, -1, true);
|
937
|
-
if (lastTextGroup) {
|
938
|
-
text.parent.addChild(lastTextGroup, text.getIndex() + 1);
|
939
|
-
}
|
940
|
-
if (!middleTextGroup) {
|
941
|
-
throw new Error('middleText is null');
|
942
|
-
}
|
943
|
-
text.parent.addChild(middleTextGroup, text.getIndex() + 1);
|
944
|
-
if (text.textMeasures.length === 0) {
|
945
|
-
text.remove();
|
946
|
-
text.destroy();
|
947
|
-
}
|
948
|
-
return middleTextGroup;
|
949
|
-
}
|
950
|
-
splitText(text, offset) {
|
951
|
-
offset = offset == -1 ? text.textMeasures.length : offset;
|
952
|
-
if (offset === text.textMeasures.length) {
|
953
|
-
return {
|
954
|
-
leftElement: text,
|
955
|
-
rightElement: null
|
956
|
-
};
|
957
|
-
}
|
958
|
-
if (offset === 0) {
|
959
|
-
return {
|
960
|
-
leftElement: null,
|
961
|
-
rightElement: text
|
962
|
-
};
|
963
|
-
}
|
964
|
-
const rightText = text.spliceText(offset, -1, true);
|
965
|
-
if (rightText) {
|
966
|
-
text.parent.addChild(rightText, text.getIndex() + 1);
|
967
|
-
}
|
968
|
-
let leftText = text;
|
969
|
-
if (text.textMeasures.length === 0) {
|
970
|
-
text.remove();
|
971
|
-
leftText = null;
|
972
|
-
}
|
973
|
-
return {
|
974
|
-
leftElement: leftText,
|
975
|
-
rightElement: rightText
|
976
|
-
};
|
977
|
-
}
|
978
|
-
/**
|
979
|
-
* 设置选中的文本样式
|
980
|
-
* @param ss
|
981
|
-
* @param setterFunc
|
982
|
-
* @returns
|
983
|
-
*/
|
984
|
-
static setTextStyle(ss, setterFunc) {
|
985
|
-
const range = ss.selectedRange;
|
986
|
-
if (!range || ss.collapsed) {
|
987
|
-
return;
|
988
|
-
}
|
989
|
-
const newSelectionRange = new SelectionRange();
|
990
|
-
const startRange = ElementUtil.getFirstSelectedRange(range);
|
991
|
-
const endRange = ElementUtil.getLastSelectedRange(range);
|
992
|
-
this.recursionSetRangeTextStyle(range, setterFunc);
|
993
|
-
if (startRange === endRange) {
|
994
|
-
if (startRange.isFullSelected) {
|
995
|
-
newSelectionRange.setStart(startRange.target, 0);
|
996
|
-
newSelectionRange.setEnd(startRange.target, -1);
|
997
|
-
}
|
998
|
-
if (startRange.target instanceof TextGroupElement) {
|
999
|
-
const startSelectedOffset = ss.startOffset;
|
1000
|
-
const endSelectedOffset = ss.endOffset;
|
1001
|
-
const middleElement = this.splitTextGroupByRange(startRange.target, startSelectedOffset, endSelectedOffset);
|
1002
|
-
if (middleElement) {
|
1003
|
-
setterFunc(middleElement.props);
|
1004
|
-
newSelectionRange.setStart(middleElement, 0);
|
1005
|
-
newSelectionRange.setEnd(middleElement, -1);
|
1006
|
-
}
|
1007
|
-
}
|
1008
|
-
}
|
1009
|
-
else {
|
1010
|
-
if (startRange.isFullSelected) {
|
1011
|
-
newSelectionRange.setStart(startRange.target, 0);
|
1012
|
-
}
|
1013
|
-
else {
|
1014
|
-
if (startRange.target instanceof TextGroupElement) {
|
1015
|
-
const middleElement = this.splitTextGroupByRange(startRange.target, startRange.startOffset, -1);
|
1016
|
-
if (middleElement) {
|
1017
|
-
setterFunc(middleElement.props);
|
1018
|
-
newSelectionRange.setStart(middleElement, 0);
|
1019
|
-
}
|
1020
|
-
else {
|
1021
|
-
newSelectionRange.setStart(startRange.target, 0);
|
1022
|
-
}
|
1023
|
-
}
|
1024
|
-
else {
|
1025
|
-
newSelectionRange.setStart(startRange.target, startRange.startOffset);
|
1026
|
-
}
|
1027
|
-
}
|
1028
|
-
if (endRange.isFullSelected) {
|
1029
|
-
newSelectionRange.setEnd(endRange.target, -1);
|
1030
|
-
}
|
1031
|
-
else {
|
1032
|
-
if (endRange.target instanceof TextGroupElement) {
|
1033
|
-
const middleElement = this.splitTextGroupByRange(endRange.target, 0, endRange.endOffset);
|
1034
|
-
if (middleElement) {
|
1035
|
-
setterFunc(middleElement.props);
|
1036
|
-
newSelectionRange.setEnd(middleElement, -1);
|
1037
|
-
}
|
1038
|
-
else {
|
1039
|
-
newSelectionRange.setStart(endRange.target, 0);
|
1040
|
-
}
|
1041
|
-
}
|
1042
|
-
else {
|
1043
|
-
newSelectionRange.setEnd(endRange.target, endRange.endOffset);
|
1044
|
-
}
|
1045
|
-
}
|
1046
|
-
}
|
1047
|
-
ss.addRange(newSelectionRange);
|
1048
|
-
}
|
1049
|
-
static recursionSetRangeTextStyle(range, setterFunc) {
|
1050
|
-
RangeUtil.recursionTraversalRangeHandler(range, (itemRange) => {
|
1051
|
-
if (itemRange.target instanceof TextGroupElement && itemRange.isFullSelected) {
|
1052
|
-
setterFunc(itemRange.target.props);
|
1053
|
-
}
|
1054
|
-
});
|
1055
|
-
}
|
1056
|
-
static setParaAlign(ss, setterFunc) {
|
1057
|
-
if (ss.collapsed && ss.startControl) {
|
1058
|
-
const para = ElementUtil.getParentByType(ss.startControl, ParagraphElement);
|
1059
|
-
if (para) {
|
1060
|
-
setterFunc(para.props);
|
1061
|
-
}
|
1062
|
-
}
|
1063
|
-
else {
|
1064
|
-
const range = ss.selectedRange;
|
1065
|
-
if (!range) {
|
1066
|
-
return;
|
1067
|
-
}
|
1068
|
-
RangeUtil.recursionTraversalRangeHandler(range, (itemRange) => {
|
1069
|
-
if (itemRange.target instanceof ParagraphElement) {
|
1070
|
-
setterFunc(itemRange.target.props);
|
1071
|
-
}
|
1072
|
-
});
|
1073
|
-
}
|
1074
|
-
}
|
1075
|
-
/**
|
1076
|
-
* 复制
|
1077
|
-
* @param evt
|
1078
|
-
* @returns
|
1079
|
-
*/
|
1080
|
-
onCopy(evt) {
|
1081
|
-
evt.preventDefault();
|
1082
|
-
const copySerializeStr = ElementSerialize.getSelectedJSON(this.selectionState, this.viewOptions);
|
1083
|
-
if (!copySerializeStr) {
|
1084
|
-
return;
|
1085
|
-
}
|
1086
|
-
evt.clipboardData?.setData('doc/plain', copySerializeStr);
|
1087
|
-
const copyStr = ElementSerialize.getSelectedText(this.selectionState, this.viewOptions);
|
1088
|
-
evt.clipboardData?.setData('text/plain', copyStr);
|
1089
|
-
}
|
1090
|
-
/**
|
1091
|
-
* 剪切
|
1092
|
-
* @param evt
|
1093
|
-
*/
|
1094
|
-
onCut(evt) {
|
1095
|
-
this.onCopy(evt);
|
1096
|
-
this.onRangeDelete();
|
1097
|
-
}
|
1098
|
-
/**
|
1099
|
-
* 粘贴
|
1100
|
-
* @param evt
|
1101
|
-
* @returns
|
1102
|
-
*/
|
1103
|
-
onPaste(evt) {
|
1104
|
-
evt.preventDefault();
|
1105
|
-
let pasteText = evt.clipboardData?.getData('text/plain');
|
1106
|
-
const pasteData = evt.clipboardData?.getData('doc/plain');
|
1107
|
-
if (!pasteData) {
|
1108
|
-
if (pasteText) {
|
1109
|
-
this.pastePlainText(pasteText);
|
1110
|
-
}
|
1111
|
-
return;
|
1112
|
-
}
|
1113
|
-
const pasteElement = this.eleReader.readElement(JSON.parse(pasteData));
|
1114
|
-
if (!pasteElement) {
|
1115
|
-
console.log('粘贴反序列化数据失败', pasteData);
|
1116
|
-
return;
|
1117
|
-
}
|
1118
|
-
const { collapsed } = this.selectionState;
|
1119
|
-
let { startControl, startOffset } = this.selectionState;
|
1120
|
-
if (!collapsed) {
|
1121
|
-
//TODO:如果一个容器内的元素被全部删除,则返回 null
|
1122
|
-
// const { cursorEle, cursorOffset } = this.onRangeDelete();
|
1123
|
-
// startControl = cursorEle;
|
1124
|
-
// startOffset = cursorOffset;
|
1125
|
-
}
|
1126
|
-
if (!startControl) {
|
1127
|
-
return;
|
1128
|
-
}
|
1129
|
-
//表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
|
1130
|
-
if (this.viewOptions.docMode === DocMode.FormEdit) {
|
1131
|
-
const pasteString = ElementSerialize.serializeString(pasteElement, { all: false });
|
1132
|
-
if (pasteString) {
|
1133
|
-
this.pastePlainText(pasteString);
|
1134
|
-
}
|
1135
|
-
return;
|
1136
|
-
}
|
1137
|
-
if (pasteElement instanceof ParagraphElement || pasteElement instanceof InlineGroupElement) {
|
1138
|
-
const children = [];
|
1139
|
-
if (pasteElement instanceof ParagraphElement) {
|
1140
|
-
children.push(...ElementUtil.getChildrenElements(pasteElement));
|
1141
|
-
}
|
1142
|
-
else if (pasteElement instanceof InlineGroupElement) {
|
1143
|
-
children.push(pasteElement);
|
1144
|
-
}
|
1145
|
-
if (!children.length) {
|
1146
|
-
throw new Error('段落子元素为空');
|
1147
|
-
}
|
1148
|
-
const lastEle = this.insertElement(startControl, startOffset, children);
|
1149
|
-
this.selectionState.resetRange(lastEle, -1);
|
1150
|
-
return;
|
1151
|
-
}
|
1152
|
-
console.log('粘贴:' + pasteData);
|
1153
|
-
}
|
1154
|
-
insertSoftBr() {
|
1155
|
-
let { startControl, startOffset } = this.selectionState;
|
1156
|
-
const lastEle = this.insertElement(startControl, startOffset, [new BreakElement()]);
|
1157
|
-
const focusEle = ElementUtil.getNextSiblingElement(lastEle);
|
1158
|
-
if (focusEle) {
|
1159
|
-
this.selectionState.resetRange(focusEle, 0);
|
1160
|
-
}
|
1161
|
-
}
|
1162
|
-
/**
|
1163
|
-
* 处理黏贴的纯文本
|
1164
|
-
* @param text
|
1165
|
-
*/
|
1166
|
-
pastePlainText(text) {
|
1167
|
-
const textItems = text.split(/\r?\n/);
|
1168
|
-
const { startControl, startOffset } = this.selectionState;
|
1169
|
-
if (this.viewOptions.docMode === DocMode.FormEdit || textItems.length === 1 || IsInSideInlineGroupInputElement(startControl, startOffset)) {
|
1170
|
-
text = text.replace(/[\n\r]/g, '');
|
1171
|
-
this.newInput({
|
1172
|
-
data: text,
|
1173
|
-
compositionStartInfo: {
|
1174
|
-
element: startControl,
|
1175
|
-
offset: startOffset
|
1176
|
-
}
|
1177
|
-
});
|
1178
|
-
}
|
1179
|
-
else {
|
1180
|
-
const breakPara = this.splitCurrentParagraph();
|
1181
|
-
for (let i = 0; i < textItems.length; i++) {
|
1182
|
-
const newPara = breakPara.clone(false);
|
1183
|
-
const inputTextProps = newPara.props.textProps;
|
1184
|
-
const newTextEle = ElementUtil.getNewTextGroup(inputTextProps);
|
1185
|
-
newTextEle.text = textItems[i];
|
1186
|
-
newPara.addChild(newTextEle, 0);
|
1187
|
-
breakPara.parent.addChild(newPara, breakPara.getIndex());
|
1188
|
-
}
|
1189
|
-
this.selectionState.resetRange(breakPara, 0);
|
1190
|
-
}
|
1191
|
-
}
|
1192
|
-
/**
|
1193
|
-
* 设置当前段落项目符号类型
|
1194
|
-
*/
|
1195
|
-
setParagraphNumberType() {
|
1196
|
-
const { startControl } = this.selectionState;
|
1197
|
-
if (!startControl) {
|
1198
|
-
return;
|
1199
|
-
}
|
1200
|
-
const para = ElementUtil.getParentByType(startControl, ParagraphElement);
|
1201
|
-
if (para.props.numberType >= 0) {
|
1202
|
-
para.props.numberType = -1;
|
1203
|
-
para.props.indent = 0;
|
1204
|
-
}
|
1205
|
-
else {
|
1206
|
-
para.props.numberType = 0;
|
1207
|
-
para.props.indent = 15;
|
1208
|
-
}
|
1209
|
-
}
|
1210
|
-
/**
|
1211
|
-
* 插入批注
|
1212
|
-
*/
|
1213
|
-
insertComment() {
|
1214
|
-
const { startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
|
1215
|
-
if (collapsed || !startControl || !endControl) {
|
1216
|
-
return;
|
1217
|
-
}
|
1218
|
-
const id = nanoid(5);
|
1219
|
-
const startCommMark = new CommentElement();
|
1220
|
-
startCommMark.props.id = id;
|
1221
|
-
startCommMark.props.markType = 'start';
|
1222
|
-
const endCommMark = new CommentElement();
|
1223
|
-
endCommMark.props.id = id;
|
1224
|
-
endCommMark.props.markType = 'end';
|
1225
|
-
this.insertElement(endControl, endOffset, [endCommMark]);
|
1226
|
-
this.insertElement(startControl, startOffset, [startCommMark]);
|
1227
|
-
const commContent = new CommContentElement();
|
1228
|
-
commContent.props.id = id;
|
1229
|
-
commContent.props.createId = this.viewOptions.editUser.id;
|
1230
|
-
commContent.props.createName = this.viewOptions.editUser.name;
|
1231
|
-
commContent.props.createDate = new Date();
|
1232
|
-
const pos = this.docComment.getCommMarkIndex(startCommMark);
|
1233
|
-
if (pos < 0) {
|
1234
|
-
throw new Error('获取插入的批注位置不正确');
|
1235
|
-
}
|
1236
|
-
this.docCtx.document.commentsContainerElement.addChild(commContent, pos);
|
1237
|
-
this.selectionState.clear();
|
1238
|
-
this.docComment.afterCommentsChanged();
|
1239
|
-
}
|
1240
|
-
validate() {
|
1241
|
-
const dataEleList = this.docCtx.document.treeFilter(item => item instanceof DataElementInlineGroup);
|
1242
|
-
const errorEleList = dataEleList.map(item => ({ error: item.validate(), ele: item })).filter(item => item.error);
|
1243
|
-
if (!errorEleList.length) {
|
1244
|
-
return true;
|
1245
|
-
}
|
1246
|
-
errorEleList.forEach(item => {
|
1247
|
-
const id = nanoid(5);
|
1248
|
-
const startCommMark = new CommentElement();
|
1249
|
-
startCommMark.props.id = id;
|
1250
|
-
startCommMark.props.markType = 'start';
|
1251
|
-
const endCommMark = new CommentElement();
|
1252
|
-
endCommMark.props.id = id;
|
1253
|
-
endCommMark.props.markType = 'end';
|
1254
|
-
item.ele.addChild(startCommMark, 0);
|
1255
|
-
item.ele.addChild(endCommMark, item.ele.length);
|
1256
|
-
const caption = CommonUtil.nullToString(item.ele.props.caption);
|
1257
|
-
const validateElement = new ValidateElement();
|
1258
|
-
validateElement.props.title = caption + '验证';
|
1259
|
-
validateElement.props.id = id;
|
1260
|
-
validateElement.setContent(item.error);
|
1261
|
-
const pos = this.docComment.getCommMarkIndex(startCommMark);
|
1262
|
-
this.docCtx.document.commentsContainerElement.addChild(validateElement, pos);
|
1263
|
-
});
|
1264
|
-
this.docCtx.selectionState.clear();
|
1265
|
-
this.docComment.afterCommentsChanged();
|
1266
|
-
return false;
|
1267
|
-
}
|
1268
|
-
/**
|
1269
|
-
* 移除空字符串
|
1270
|
-
* @param text
|
1271
|
-
*/
|
1272
|
-
removeEmptyText(text) {
|
1273
|
-
//const nextLeafElementInPara = ElementUtil.getRecursionNextSiblingElement(text, true, true); getComputedStyle
|
1274
|
-
this.setCurosrForDeleteAction(text);
|
1275
|
-
const parent = text.parent;
|
1276
|
-
text.remove();
|
1277
|
-
this.removeEmtpyInlineBlock(parent);
|
1278
|
-
}
|
1279
|
-
setCurosrForDeleteAction(control) {
|
1280
|
-
const cursorInfo = this.getCursorElementByDeleteAction(control);
|
1281
|
-
if (cursorInfo) {
|
1282
|
-
this.selectionState.resetRange(cursorInfo.ele, cursorInfo.offset);
|
1283
|
-
}
|
1284
|
-
else {
|
1285
|
-
this.selectionState.clear();
|
1286
|
-
}
|
1287
|
-
}
|
1288
|
-
getCursorElementByDeleteAction(control) {
|
1289
|
-
const prevLeafElementInPara = ElementUtil.getRecursionPrevSiblingElement(control, false, true);
|
1290
|
-
//判断是否为同一段落
|
1291
|
-
if (prevLeafElementInPara && ElementUtil.isInSameParagraph(prevLeafElementInPara, control)) {
|
1292
|
-
return {
|
1293
|
-
ele: prevLeafElementInPara,
|
1294
|
-
offset: ElementUtil.getElementEndOffset(prevLeafElementInPara)
|
1295
|
-
};
|
1296
|
-
}
|
1297
|
-
//同一段落其他元素
|
1298
|
-
const nextLeafElementInPara = ElementUtil.getRecursionNextSiblingElement(control, true, true);
|
1299
|
-
if (nextLeafElementInPara) {
|
1300
|
-
return {
|
1301
|
-
ele: nextLeafElementInPara,
|
1302
|
-
offset: 0
|
1303
|
-
};
|
1304
|
-
}
|
1305
|
-
//上一段落
|
1306
|
-
if (prevLeafElementInPara) {
|
1307
|
-
return {
|
1308
|
-
ele: prevLeafElementInPara,
|
1309
|
-
offset: prevLeafElementInPara instanceof PSymbolElement ? 0 : ElementUtil.getElementEndOffset(prevLeafElementInPara)
|
1310
|
-
};
|
1311
|
-
}
|
1312
|
-
return null;
|
1313
|
-
}
|
1314
|
-
/**
|
1315
|
-
* 移除空行内标签
|
1316
|
-
* @param ele
|
1317
|
-
*/
|
1318
|
-
removeEmtpyInlineBlock(ele) {
|
1319
|
-
if (ele instanceof InlineGroupElement && ele.length === 0) {
|
1320
|
-
const parent = ele.parent;
|
1321
|
-
ele.remove();
|
1322
|
-
this.removeEmtpyInlineBlock(parent);
|
1323
|
-
}
|
1324
|
-
}
|
1325
|
-
/**
|
1326
|
-
* 插入强制换页符号
|
1327
|
-
*/
|
1328
|
-
insertPageBreakPara() {
|
1329
|
-
const { startControl } = this.selectionState;
|
1330
|
-
const currPara = ElementUtil.getParentByType(startControl, ParagraphElement);
|
1331
|
-
if (!currPara) {
|
1332
|
-
return;
|
1333
|
-
}
|
1334
|
-
if (currPara.parent instanceof DocumentBodyElement) {
|
1335
|
-
const pageBreak = new ParagraphElement();
|
1336
|
-
pageBreak.props.pageBreak = true;
|
1337
|
-
pageBreak.props.textAlign = 'center';
|
1338
|
-
pageBreak.parent.addChild(pageBreak);
|
1339
|
-
}
|
1340
|
-
}
|
1341
|
-
}
|
1342
|
-
//# sourceMappingURL=document-change.js.map
|