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