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