@hailin-zheng/editor-core 2.2.2 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/editor.css +96 -12
- package/index-cjs.d.ts +1 -0
- package/index-cjs.js +757 -278
- package/index-cjs.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +752 -278
- package/index.js.map +1 -1
- package/med_editor/doc-editor.d.ts +37 -5
- package/med_editor/framework/document-change.d.ts +21 -2
- package/med_editor/framework/document-context.d.ts +5 -0
- package/med_editor/framework/document-input-cursor.d.ts +4 -15
- package/med_editor/framework/element-define.d.ts +7 -0
- package/med_editor/framework/element-event-define.d.ts +2 -5
- package/med_editor/framework/element-type-handler.d.ts +0 -1
- package/med_editor/framework/impl/data-element/data-container-impl.d.ts +25 -0
- package/med_editor/framework/impl/document/doc-body-impl.d.ts +0 -1
- package/med_editor/framework/impl/document/doc-impl.d.ts +1 -0
- package/med_editor/framework/impl/index.d.ts +1 -0
- package/med_editor/framework/impl/table/table-split-cell.d.ts +3 -2
- package/med_editor/framework/infrastructure/event-subject.d.ts +1 -0
- package/med_editor/framework/selection/document-selection.d.ts +1 -6
- package/med_editor/framework/suggestions/input-suggestions.d.ts +29 -0
- package/med_editor/framework/util/common-util.d.ts +1 -1
- package/package.json +1 -1
package/index-cjs.js
CHANGED
@@ -69,9 +69,9 @@ class ElementEvent {
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
class ContentMenuItem {
|
72
|
-
icon;
|
73
72
|
caption;
|
74
|
-
|
73
|
+
checked;
|
74
|
+
click = () => { };
|
75
75
|
subItems = [];
|
76
76
|
}
|
77
77
|
/**
|
@@ -1002,6 +1002,12 @@ function generatePatch(doc, clear = true) {
|
|
1002
1002
|
if ('insert' in op.ops) {
|
1003
1003
|
insertOpsMap.set(ele, op);
|
1004
1004
|
}
|
1005
|
+
//当前为新插入的元素
|
1006
|
+
if ('insText' in op.ops) {
|
1007
|
+
if (insertOpsMap.has(ele)) {
|
1008
|
+
continue;
|
1009
|
+
}
|
1010
|
+
}
|
1005
1011
|
// if ('insert' in op.ops) {
|
1006
1012
|
// op.ops.insert = ele.clone(true);
|
1007
1013
|
// const log = getOpsLog(ele, op.ops);
|
@@ -1057,7 +1063,11 @@ class Subscription {
|
|
1057
1063
|
class EventSourceCore {
|
1058
1064
|
closed = false;
|
1059
1065
|
subs = [];
|
1066
|
+
state = 'running';
|
1060
1067
|
next(data) {
|
1068
|
+
if (this.state === 'pause') {
|
1069
|
+
return;
|
1070
|
+
}
|
1061
1071
|
const subs = [...this.subs];
|
1062
1072
|
subs.forEach((sub) => {
|
1063
1073
|
sub.invoke(data);
|
@@ -1201,6 +1211,8 @@ class Rect {
|
|
1201
1211
|
width = 0;
|
1202
1212
|
height = 0;
|
1203
1213
|
}
|
1214
|
+
// 定义文本占用高度系数
|
1215
|
+
const TEXT_HEIGHT_FACTOR = 1.4;
|
1204
1216
|
/**
|
1205
1217
|
* 修改标志
|
1206
1218
|
*/
|
@@ -1703,6 +1715,7 @@ class PageOptions {
|
|
1703
1715
|
}
|
1704
1716
|
class ViewOptions {
|
1705
1717
|
copyRightInfo;
|
1718
|
+
trialVersion = false;
|
1706
1719
|
watermark;
|
1707
1720
|
drawLineRectColor = "rgb(0,0,0)";
|
1708
1721
|
drawCharRectColor = "rgb(0,0,0)";
|
@@ -1711,6 +1724,8 @@ class ViewOptions {
|
|
1711
1724
|
editorVersion = '';
|
1712
1725
|
defaultFontSize = 14;
|
1713
1726
|
defaultColor = "#000000";
|
1727
|
+
currentFontSize = 14;
|
1728
|
+
currentFontName = '宋体';
|
1714
1729
|
selectionOverlaysColor = 'rgb(131,175,155,0.5)';
|
1715
1730
|
dataEleOverlaysColor = 'rgb(131,175,155,0.5)';
|
1716
1731
|
dataEleFocusedBgColor = 'rgb(131,175,155,0.8)';
|
@@ -1761,6 +1776,7 @@ class ViewOptions {
|
|
1761
1776
|
//显示段落回车符号
|
1762
1777
|
showEnterSymbol = false;
|
1763
1778
|
enableVisibleExpression = false;
|
1779
|
+
shapeRendering = 'auto';
|
1764
1780
|
get fullPageView() {
|
1765
1781
|
return this._fullPageView;
|
1766
1782
|
}
|
@@ -1808,6 +1824,8 @@ class ViewOptions {
|
|
1808
1824
|
_showTrackChanges = true;
|
1809
1825
|
//是否显示审阅痕迹提示
|
1810
1826
|
_showTrackChangesTip = true;
|
1827
|
+
//是否开启留痕
|
1828
|
+
enableTrackChanges = false;
|
1811
1829
|
get showTrackChanges() {
|
1812
1830
|
return this._showTrackChanges;
|
1813
1831
|
}
|
@@ -1836,6 +1854,8 @@ class ViewOptions {
|
|
1836
1854
|
onChange = new Subject();
|
1837
1855
|
//打印模式,普通模式,续打模式
|
1838
1856
|
printMode = 'normal';
|
1857
|
+
//是否开启候选词输入联想
|
1858
|
+
enableSuggestions = false;
|
1839
1859
|
constructor() {
|
1840
1860
|
}
|
1841
1861
|
}
|
@@ -2918,7 +2938,7 @@ class DataDecorateElement extends LeafElement {
|
|
2918
2938
|
createRenderObject() {
|
2919
2939
|
const render = new DataDecorateRenderObject(this);
|
2920
2940
|
//render.rect.width = this.dProps.size / 2;
|
2921
|
-
render.rect.width =
|
2941
|
+
render.rect.width = 1;
|
2922
2942
|
render.rect.height = 14;
|
2923
2943
|
return render;
|
2924
2944
|
}
|
@@ -3655,6 +3675,7 @@ class DocumentRenderObject extends BlockContainerRenderObject {
|
|
3655
3675
|
};
|
3656
3676
|
const pageCorner = this.exportPageCornerHTML(event);
|
3657
3677
|
const pageNum = this.exportPageNumHTML(event);
|
3678
|
+
const copyright = this.exportCopyRight(event);
|
3658
3679
|
return {
|
3659
3680
|
sel: "svg",
|
3660
3681
|
isCompleted: true,
|
@@ -3665,11 +3686,11 @@ class DocumentRenderObject extends BlockContainerRenderObject {
|
|
3665
3686
|
height: this.rect.height - 1,
|
3666
3687
|
viewBox: `0 0 ${this.rect.width} ${this.rect.height - 1}`,
|
3667
3688
|
overflow: "hidden",
|
3668
|
-
"shape-rendering":
|
3689
|
+
"shape-rendering": event.options.shapeRendering
|
3669
3690
|
},
|
3670
3691
|
},
|
3671
3692
|
children: [
|
3672
|
-
pageCorner, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection
|
3693
|
+
pageCorner, copyright, highlight, ...CommonUtil.toArray(event.getChildNodes(this)), pageNum, selection
|
3673
3694
|
]
|
3674
3695
|
};
|
3675
3696
|
}
|
@@ -3701,6 +3722,41 @@ class DocumentRenderObject extends BlockContainerRenderObject {
|
|
3701
3722
|
pageCorner.children?.push(ElementUtil.getStrokeSvgPath(`M ${paddingPos.x + lineWidth} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y} L ${paddingPos.x} ${paddingPos.y + lineWidth}`, "grey", drawLineWidth));
|
3702
3723
|
return pageCorner;
|
3703
3724
|
}
|
3725
|
+
exportCopyRight(event) {
|
3726
|
+
if (!event.options.trialVersion) {
|
3727
|
+
return null;
|
3728
|
+
}
|
3729
|
+
const str = "\u6f14\u793a\u7248\u672c";
|
3730
|
+
const textProps = new TextProps();
|
3731
|
+
textProps.color = "#000";
|
3732
|
+
textProps.fontName = '仿宋';
|
3733
|
+
textProps.fontSize = 80;
|
3734
|
+
textProps.fontStyle = 'italic';
|
3735
|
+
event.renderCtx.contentContext.measureText(str, textProps);
|
3736
|
+
const getTextRotationAngle = (width, height) => {
|
3737
|
+
return Math.atan(height / width) * 180 / Math.PI;
|
3738
|
+
};
|
3739
|
+
const angle = getTextRotationAngle(this.rect.width, this.rect.height);
|
3740
|
+
return {
|
3741
|
+
sel: 'text',
|
3742
|
+
text: str,
|
3743
|
+
data: {
|
3744
|
+
ns: "http://www.w3.org/2000/svg",
|
3745
|
+
attrs: {
|
3746
|
+
transform: `rotate(${360 - angle})`,
|
3747
|
+
'transform-origin': 'center',
|
3748
|
+
'dominant-baseline': 'Hanging',
|
3749
|
+
'text-anchor': 'middle',
|
3750
|
+
'font-family': textProps.fontName,
|
3751
|
+
'font-size': textProps.fontSize,
|
3752
|
+
"stroke": textProps.color,
|
3753
|
+
'fill': '#fff',
|
3754
|
+
x: this.rect.width / 2,
|
3755
|
+
y: this.rect.height / 2,
|
3756
|
+
}
|
3757
|
+
},
|
3758
|
+
};
|
3759
|
+
}
|
3704
3760
|
}
|
3705
3761
|
class DocumentFactory extends ElementFactory {
|
3706
3762
|
match(type) {
|
@@ -4211,8 +4267,6 @@ function getCurrentParaGroupRenders(r) {
|
|
4211
4267
|
}
|
4212
4268
|
|
4213
4269
|
class DocumentBodyElement extends BlockContainerElement {
|
4214
|
-
//当前区域内是否留痕
|
4215
|
-
trackChanges = false;
|
4216
4270
|
constructor() {
|
4217
4271
|
super('body');
|
4218
4272
|
//this.editMode = EditMode.Free;
|
@@ -4337,7 +4391,6 @@ class TableCellElement extends BlockContainerElement {
|
|
4337
4391
|
//this.addPropValueChangedSub(this.props);
|
4338
4392
|
}
|
4339
4393
|
beginMeasure(data) {
|
4340
|
-
//不被合并的单元格
|
4341
4394
|
if (!this.length) {
|
4342
4395
|
this.addChild(data.createParaFn());
|
4343
4396
|
}
|
@@ -4707,7 +4760,7 @@ class TextGroupRenderObject extends LeafRenderObject {
|
|
4707
4760
|
}
|
4708
4761
|
measure() {
|
4709
4762
|
this.rect.width = this.textMeasures.reduce((prev, curr) => prev + curr.actualSize, 0);
|
4710
|
-
this.rect.height = Math.ceil(this.element.props.fontSize *
|
4763
|
+
this.rect.height = Math.ceil(this.element.props.fontSize * TEXT_HEIGHT_FACTOR);
|
4711
4764
|
// this.element.fontBoundingBox.fontBoundingBoxAscent + this.element.fontBoundingBox.fontBoundingBoxDescent;
|
4712
4765
|
}
|
4713
4766
|
exportSVG(event) {
|
@@ -6629,17 +6682,20 @@ class DocumentSelection {
|
|
6629
6682
|
ss.endOffset = range.endOffset;
|
6630
6683
|
ss.endControlIndex = ElementUtil.getControlIndex(range.endControl);
|
6631
6684
|
ss.ancestorCommonControl = DocumentSelection.getAncestorCommonControl(ss.startControl, ss.endControl);
|
6632
|
-
ss.enableTrackChanges = this.getEnableTrackChanges(range.startControl);
|
6633
6685
|
ss.rangeDirty = false;
|
6634
6686
|
return true;
|
6635
6687
|
}
|
6636
|
-
|
6637
|
-
|
6638
|
-
|
6639
|
-
|
6640
|
-
|
6641
|
-
|
6642
|
-
|
6688
|
+
isSelectionChanged() {
|
6689
|
+
if (!this.snapshotSelectionState) {
|
6690
|
+
return true;
|
6691
|
+
}
|
6692
|
+
if (this.selectionState.startControl !== this.snapshotSelectionState.startControl || this.selectionState.startOffset !== this.snapshotSelectionState.startOffset) {
|
6693
|
+
return true;
|
6694
|
+
}
|
6695
|
+
if (this.selectionState.endControl !== this.snapshotSelectionState.endControl || this.selectionState.endOffset !== this.snapshotSelectionState.endOffset) {
|
6696
|
+
return true;
|
6697
|
+
}
|
6698
|
+
return false;
|
6643
6699
|
}
|
6644
6700
|
/**
|
6645
6701
|
* 转换选区内容
|
@@ -6736,8 +6792,6 @@ class SelectionState {
|
|
6736
6792
|
renderContainer;
|
6737
6793
|
//光标所在的位置,当前位置时相对文档的位置,而非DOM页面中的位置
|
6738
6794
|
cursorPos;
|
6739
|
-
//当前选区的上下文是否支持留痕修改
|
6740
|
-
enableTrackChanges = false;
|
6741
6795
|
constructor() {
|
6742
6796
|
this.clear();
|
6743
6797
|
}
|
@@ -8445,7 +8499,10 @@ class DataElementDate extends DataElementInlineGroup {
|
|
8445
8499
|
this.props.value = '';
|
8446
8500
|
return;
|
8447
8501
|
}
|
8448
|
-
|
8502
|
+
let format = 'YYYY-MM-DD';
|
8503
|
+
if (this.props.format) {
|
8504
|
+
format = this.props.format;
|
8505
|
+
}
|
8449
8506
|
const date = moment__default["default"](val, format);
|
8450
8507
|
if (!date.isValid()) {
|
8451
8508
|
return;
|
@@ -8976,6 +9033,102 @@ class DataElementTextFactory extends DataElementBaseFactory {
|
|
8976
9033
|
}
|
8977
9034
|
}
|
8978
9035
|
|
9036
|
+
/**
|
9037
|
+
* 数据块容器,包裹多个段落
|
9038
|
+
*/
|
9039
|
+
class DataContainerElement extends BlockContainerElement {
|
9040
|
+
constructor() {
|
9041
|
+
super('data-container');
|
9042
|
+
this.props = new DataContainerProps();
|
9043
|
+
this.addEvent('GotCursor', (evt) => {
|
9044
|
+
this.isFocused = true;
|
9045
|
+
this.refreshView();
|
9046
|
+
});
|
9047
|
+
this.addEvent('LostCursor', (evt) => {
|
9048
|
+
this.isFocused = false;
|
9049
|
+
this.refreshView();
|
9050
|
+
});
|
9051
|
+
}
|
9052
|
+
createRenderObject() {
|
9053
|
+
return new DataContainerRenderObject(this);
|
9054
|
+
}
|
9055
|
+
beginMeasure(data) {
|
9056
|
+
if (!this.length) {
|
9057
|
+
this.addChild(data.createParaFn());
|
9058
|
+
}
|
9059
|
+
super.beginMeasure(data);
|
9060
|
+
}
|
9061
|
+
serialize() {
|
9062
|
+
const p = {
|
9063
|
+
type: this.type,
|
9064
|
+
props: {}
|
9065
|
+
};
|
9066
|
+
if (this.props.id) {
|
9067
|
+
p['id'] = this.props.id;
|
9068
|
+
}
|
9069
|
+
if (this.props.name) {
|
9070
|
+
p['name'] = this.props.name;
|
9071
|
+
}
|
9072
|
+
if (this.props.caption) {
|
9073
|
+
p['caption'] = this.props.caption;
|
9074
|
+
}
|
9075
|
+
return p;
|
9076
|
+
}
|
9077
|
+
clone(data) {
|
9078
|
+
const clone = new DataContainerElement();
|
9079
|
+
clone.props.id = this.props.id;
|
9080
|
+
clone.props.name = this.props.name;
|
9081
|
+
clone.props.caption = this.props.caption;
|
9082
|
+
cloneElementBase(this, clone);
|
9083
|
+
cloneChildren(this, clone, data);
|
9084
|
+
return clone;
|
9085
|
+
}
|
9086
|
+
}
|
9087
|
+
class DataContainerRenderObject extends MuiltBlockLineRenderObject {
|
9088
|
+
clone(cloneData = true) {
|
9089
|
+
const cloneRender = new DataContainerRenderObject(this.element);
|
9090
|
+
cloneRender.rect = ElementUtil.cloneRect(this.rect);
|
9091
|
+
if (cloneData) {
|
9092
|
+
for (let i = 0; i < this.length; i++) {
|
9093
|
+
cloneRender.addChild(this.getChild(i).clone());
|
9094
|
+
}
|
9095
|
+
}
|
9096
|
+
return cloneRender;
|
9097
|
+
}
|
9098
|
+
exportSVG(event) {
|
9099
|
+
const t = super.exportSVG(event);
|
9100
|
+
if (event.mode === 'view') {
|
9101
|
+
const border = ElementUtil.getStrokeSvgPath(ElementUtil.getRectPath(0, 0, this.rect.width, this.rect.height), '#000', 0.5);
|
9102
|
+
t.children = [border];
|
9103
|
+
}
|
9104
|
+
return t;
|
9105
|
+
}
|
9106
|
+
}
|
9107
|
+
class DataContainerFactory extends ElementFactory {
|
9108
|
+
match(type) {
|
9109
|
+
return type === 'data-container';
|
9110
|
+
}
|
9111
|
+
createElement(data) {
|
9112
|
+
const element = new DataContainerElement();
|
9113
|
+
const props = data.props;
|
9114
|
+
if (props?.id) {
|
9115
|
+
element.props.id = props.id;
|
9116
|
+
}
|
9117
|
+
if (props?.name) {
|
9118
|
+
element.props.name = props.name;
|
9119
|
+
}
|
9120
|
+
if (props?.caption) {
|
9121
|
+
element.props.caption = props.caption;
|
9122
|
+
}
|
9123
|
+
return element;
|
9124
|
+
}
|
9125
|
+
}
|
9126
|
+
class DataContainerProps {
|
9127
|
+
caption;
|
9128
|
+
id;
|
9129
|
+
name;
|
9130
|
+
}
|
9131
|
+
|
8979
9132
|
/**
|
8980
9133
|
* 当前数据元内容长度小于最小长度时,需要当前元素撑开以达到最小长度
|
8981
9134
|
*/
|
@@ -12933,6 +13086,29 @@ class PaintContent {
|
|
12933
13086
|
}
|
12934
13087
|
}
|
12935
13088
|
|
13089
|
+
/**
|
13090
|
+
* 处理文档输入联想
|
13091
|
+
*/
|
13092
|
+
class DocInputSuggestions {
|
13093
|
+
currentInputTextGroup;
|
13094
|
+
currentMatchedText = '';
|
13095
|
+
currentInputOffset = 0;
|
13096
|
+
suggestionsList = [];
|
13097
|
+
prepareSuggestions = [];
|
13098
|
+
selectedIndex = -1;
|
13099
|
+
clear() {
|
13100
|
+
this.prepareSuggestions.length = 0;
|
13101
|
+
this.currentInputTextGroup = undefined;
|
13102
|
+
this.selectedIndex = -1;
|
13103
|
+
this.currentInputOffset = 0;
|
13104
|
+
this.currentMatchedText = '';
|
13105
|
+
}
|
13106
|
+
destroy() {
|
13107
|
+
this.clear();
|
13108
|
+
this.suggestionsList.length = 0;
|
13109
|
+
}
|
13110
|
+
}
|
13111
|
+
|
12936
13112
|
/**
|
12937
13113
|
* 当前打开的文档的上下文信息,当前文档所有的属性设置都暴露在上下文中
|
12938
13114
|
*/
|
@@ -12951,6 +13127,10 @@ class EditorContext {
|
|
12951
13127
|
commentFlag = false;
|
12952
13128
|
//留痕元素存在的标志,用于判断文档空间进行布局
|
12953
13129
|
trackFlag = false;
|
13130
|
+
//suggestionsList: Array<ISuggestionData> = [];
|
13131
|
+
//currentSuggestionsList: Array<ISuggestionData> = [];
|
13132
|
+
suggestions = new DocInputSuggestions();
|
13133
|
+
onKeyDownEvent = new Subject();
|
12954
13134
|
constructor(selectionState, viewOptions) {
|
12955
13135
|
this.selectionState = selectionState;
|
12956
13136
|
this.viewOptions = viewOptions;
|
@@ -13001,6 +13181,7 @@ class EditorContext {
|
|
13001
13181
|
clear() {
|
13002
13182
|
this.selectionState.clear();
|
13003
13183
|
this.isDirty = false;
|
13184
|
+
this.suggestions.clear();
|
13004
13185
|
//this.clearEleDepMaps();
|
13005
13186
|
}
|
13006
13187
|
get defaultCtx() {
|
@@ -13043,6 +13224,7 @@ class EditorContext {
|
|
13043
13224
|
//this.ele_types_handlers.length = 0;
|
13044
13225
|
//this.imageLoader.clear();
|
13045
13226
|
this._document = null;
|
13227
|
+
this.suggestions.destroy();
|
13046
13228
|
}
|
13047
13229
|
/**
|
13048
13230
|
* 切换行打印模式
|
@@ -13063,6 +13245,7 @@ class EditorContext {
|
|
13063
13245
|
//删除旧节点
|
13064
13246
|
oldDataElement.remove();
|
13065
13247
|
}
|
13248
|
+
currentRefreshType = null;
|
13066
13249
|
get refreshType() {
|
13067
13250
|
if (!this._document) {
|
13068
13251
|
return null;
|
@@ -13520,6 +13703,10 @@ class ParagraphMeasure {
|
|
13520
13703
|
child.rect.width = tab - currTabX;
|
13521
13704
|
}
|
13522
13705
|
}
|
13706
|
+
//如果当前段落行只包含当前换行元素或者段落元素,则根据当前输入设置,自动将行高度撑开到理想高度font-size*1.4
|
13707
|
+
if (this.lineLength() === 1 && child.element && (child.element.type === 'br' || child.element.type === 'psym')) {
|
13708
|
+
child.rect.height = Math.ceil(options.defaultFontSize * TEXT_HEIGHT_FACTOR);
|
13709
|
+
}
|
13523
13710
|
this.arrange();
|
13524
13711
|
this.updateHeight(child);
|
13525
13712
|
},
|
@@ -15045,6 +15232,7 @@ class ElementReader {
|
|
15045
15232
|
this.addFactory(TabFactory);
|
15046
15233
|
this.addFactory(PermanentTeethFactory);
|
15047
15234
|
this.addFactory(SVGFactory);
|
15235
|
+
this.addFactory(DataContainerFactory);
|
15048
15236
|
// this.registerReadFunc<TrackRunProps>('ins-run', (data) => {
|
15049
15237
|
// const props = new TrackRunProps(data.type);
|
15050
15238
|
// props.userId = data.userId;
|
@@ -15203,26 +15391,37 @@ class DocumentEvent {
|
|
15203
15391
|
};
|
15204
15392
|
}
|
15205
15393
|
bindEvent() {
|
15206
|
-
this.
|
15207
|
-
this.
|
15208
|
-
|
15209
|
-
|
15210
|
-
|
15211
|
-
|
15212
|
-
|
15213
|
-
|
15214
|
-
|
15215
|
-
|
15216
|
-
|
15217
|
-
|
15218
|
-
|
15219
|
-
|
15220
|
-
|
15221
|
-
|
15222
|
-
|
15223
|
-
|
15224
|
-
|
15225
|
-
|
15394
|
+
this.docCtx.onKeyDownEvent.subscribe(evt => {
|
15395
|
+
if (!this.docCtx.selectionState.editable) {
|
15396
|
+
return;
|
15397
|
+
}
|
15398
|
+
const os = ElementUtil.getOSPlatform();
|
15399
|
+
if (evt.keyCode === 37) {
|
15400
|
+
this.moveCursorToLeft();
|
15401
|
+
}
|
15402
|
+
else if (evt.keyCode === 39) {
|
15403
|
+
this.moveCursorToRight();
|
15404
|
+
}
|
15405
|
+
else if (evt.keyCode === 38) {
|
15406
|
+
this.moveCursorToUpOrDown(true);
|
15407
|
+
}
|
15408
|
+
else if (evt.keyCode === 40) {
|
15409
|
+
this.moveCursorToUpOrDown(false);
|
15410
|
+
}
|
15411
|
+
else if (evt.keyCode === 36) {
|
15412
|
+
this.moveCursorToLineStart();
|
15413
|
+
}
|
15414
|
+
else if (evt.keyCode === 35) {
|
15415
|
+
this.moveCursorToLineEnd();
|
15416
|
+
}
|
15417
|
+
else if (evt.ctrlKey && evt.keyCode === 65 && os !== 'Mac') {
|
15418
|
+
evt.preventDefault();
|
15419
|
+
this.selectAll();
|
15420
|
+
}
|
15421
|
+
else if (evt.metaKey && evt.keyCode === 65 && os === 'Mac') {
|
15422
|
+
evt.preventDefault();
|
15423
|
+
this.selectAll();
|
15424
|
+
}
|
15226
15425
|
});
|
15227
15426
|
}
|
15228
15427
|
addSubEvent(sub) {
|
@@ -16412,15 +16611,15 @@ class DocumentInput {
|
|
16412
16611
|
//输入内容事件
|
16413
16612
|
onInputEvent = new Subject();
|
16414
16613
|
//backspace 键盘事件
|
16415
|
-
onBackspaceEvent = new Subject();
|
16614
|
+
//onBackspaceEvent: Subject<KeyboardEvent> = new Subject();
|
16416
16615
|
//delete 键盘事件
|
16417
|
-
onDeleteEvent = new Subject();
|
16616
|
+
//onDeleteEvent: Subject<KeyboardEvent> = new Subject();
|
16418
16617
|
//enter 键盘事件
|
16419
|
-
onEnterEvent = new Subject();
|
16618
|
+
//onEnterEvent: Subject<void> = new Subject();
|
16420
16619
|
//左键
|
16421
|
-
onLeftEvent = new Subject();
|
16620
|
+
//onLeftEvent: Subject<void> = new Subject();
|
16422
16621
|
//右键
|
16423
|
-
onRightEvent = new Subject();
|
16622
|
+
//onRightEvent: Subject<void> = new Subject();
|
16424
16623
|
//复制
|
16425
16624
|
onCopyEvent = new Subject();
|
16426
16625
|
//剪切
|
@@ -16428,30 +16627,31 @@ class DocumentInput {
|
|
16428
16627
|
//粘贴
|
16429
16628
|
onPasteEvent = new Subject();
|
16430
16629
|
//插入换行符
|
16431
|
-
onInsertBr = new Subject();
|
16630
|
+
//onInsertBr: Subject<void> = new Subject();
|
16432
16631
|
//ctrl+A 全选事件
|
16433
|
-
onSelectAllEvent = new Subject();
|
16632
|
+
//onSelectAllEvent: Subject<void> = new Subject();
|
16434
16633
|
//home 事件
|
16435
|
-
onHomeEvent = new Subject();
|
16634
|
+
//onHomeEvent: Subject<void> = new Subject();
|
16436
16635
|
//end 事件
|
16437
|
-
onEndEvent = new Subject();
|
16438
|
-
onUpEvent = new Subject();
|
16439
|
-
onDownEvent = new Subject();
|
16440
|
-
onTabKeyEvent = new Subject();
|
16636
|
+
//onEndEvent: Subject<void> = new Subject();
|
16637
|
+
//onUpEvent: Subject<void> = new Subject();
|
16638
|
+
//onDownEvent: Subject<void> = new Subject();
|
16639
|
+
//onTabKeyEvent: Subject<void> = new Subject();
|
16640
|
+
onKeyDownEvent = new Subject();
|
16441
16641
|
constructor(docCtx) {
|
16442
16642
|
this.docCtx = docCtx;
|
16443
16643
|
}
|
16444
16644
|
composition = false;
|
16445
16645
|
inputTargetStrPosition = -1;
|
16446
|
-
|
16646
|
+
inputTargetStrLength = 0;
|
16447
16647
|
inputEle;
|
16448
16648
|
correctInputEle(ele, str, pos) {
|
16449
16649
|
this.inputTargetStrPosition = pos;
|
16450
|
-
this.
|
16650
|
+
this.inputTargetStrLength = str ? str.length : 0;
|
16451
16651
|
this.inputEle = ele;
|
16452
16652
|
}
|
16453
16653
|
getEventListener() {
|
16454
|
-
|
16654
|
+
ElementUtil.getOSPlatform();
|
16455
16655
|
return {
|
16456
16656
|
input: (evt) => {
|
16457
16657
|
const target = evt.target;
|
@@ -16469,7 +16669,7 @@ class DocumentInput {
|
|
16469
16669
|
this.inputTargetStrPosition = startOffset;
|
16470
16670
|
this.inputEle = startControl;
|
16471
16671
|
if (startControl instanceof TextGroupElement) {
|
16472
|
-
this.
|
16672
|
+
this.inputTargetStrLength = startControl.text.length;
|
16473
16673
|
}
|
16474
16674
|
},
|
16475
16675
|
compositionupdate: (evt) => {
|
@@ -16489,60 +16689,48 @@ class DocumentInput {
|
|
16489
16689
|
this.composition = false;
|
16490
16690
|
this.inputEle = null;
|
16491
16691
|
this.inputTargetStrPosition = -1;
|
16492
|
-
this.
|
16692
|
+
this.inputTargetStrLength = 0;
|
16493
16693
|
},
|
16494
16694
|
keydown: (evt) => {
|
16695
|
+
this.onKeyDownEvent.next(evt);
|
16696
|
+
if (evt.defaultPrevented) {
|
16697
|
+
return;
|
16698
|
+
}
|
16495
16699
|
const keyEvent = new KeyboradElementEvent(this.docCtx);
|
16496
16700
|
keyEvent.sourceEvent = evt;
|
16497
16701
|
if (DocumentEvent.invokeEvent('ElementKeyDown', this.docCtx.selectionState.startControl, keyEvent, 'All')) {
|
16498
16702
|
return;
|
16499
16703
|
}
|
16500
|
-
if (!this.docCtx.selectionState.editable) {
|
16501
|
-
|
16502
|
-
}
|
16503
|
-
if (evt.keyCode === 8) {
|
16504
|
-
|
16505
|
-
}
|
16506
|
-
|
16507
|
-
|
16508
|
-
|
16509
|
-
else if (evt.keyCode ===
|
16510
|
-
|
16511
|
-
}
|
16512
|
-
|
16513
|
-
|
16514
|
-
}
|
16515
|
-
|
16516
|
-
|
16517
|
-
}
|
16518
|
-
|
16519
|
-
|
16520
|
-
|
16521
|
-
|
16522
|
-
|
16523
|
-
|
16524
|
-
|
16525
|
-
else if (evt.keyCode ===
|
16526
|
-
|
16527
|
-
|
16528
|
-
|
16529
|
-
|
16530
|
-
this.onDeleteEvent.next(evt);
|
16531
|
-
}
|
16532
|
-
else if (evt.ctrlKey && evt.keyCode === 65 && os !== 'Mac') {
|
16533
|
-
evt.preventDefault();
|
16534
|
-
this.onSelectAllEvent.next();
|
16535
|
-
}
|
16536
|
-
else if (evt.metaKey && evt.keyCode === 65 && os === 'Mac') {
|
16537
|
-
evt.preventDefault();
|
16538
|
-
this.onSelectAllEvent.next();
|
16539
|
-
}
|
16540
|
-
else if (evt.keyCode === 36) {
|
16541
|
-
this.onHomeEvent.next();
|
16542
|
-
}
|
16543
|
-
else if (evt.keyCode === 35) {
|
16544
|
-
this.onEndEvent.next();
|
16545
|
-
}
|
16704
|
+
// if (!this.docCtx.selectionState.editable) {
|
16705
|
+
// return;
|
16706
|
+
// }
|
16707
|
+
// if (evt.keyCode === 8) {
|
16708
|
+
// //this.onBackspaceEvent.next(evt);
|
16709
|
+
// } else if (evt.keyCode === 13 && !evt.shiftKey) {
|
16710
|
+
// //this.onEnterEvent.next();
|
16711
|
+
// } else if (evt.keyCode === 37) {
|
16712
|
+
// //this.onLeftEvent.next();
|
16713
|
+
// } else if (evt.keyCode === 39) {
|
16714
|
+
// //this.onRightEvent.next();
|
16715
|
+
// } else if (evt.keyCode === 9) {
|
16716
|
+
// // evt.preventDefault();
|
16717
|
+
// // this.onTabKeyEvent.next();
|
16718
|
+
// } else if (evt.keyCode === 13 && evt.shiftKey) {
|
16719
|
+
// // evt.preventDefault();
|
16720
|
+
// // this.onInsertBr.next();
|
16721
|
+
// } else if (evt.keyCode === 46) {
|
16722
|
+
// //this.onDeleteEvent.next(evt);
|
16723
|
+
// } else if (evt.ctrlKey && evt.keyCode === 65 && os !== 'Mac') {
|
16724
|
+
// // evt.preventDefault();
|
16725
|
+
// // this.onSelectAllEvent.next();
|
16726
|
+
// } else if (evt.metaKey && evt.keyCode === 65 && os === 'Mac') {
|
16727
|
+
// // evt.preventDefault();
|
16728
|
+
// // this.onSelectAllEvent.next();
|
16729
|
+
// } else if (evt.keyCode === 36) {
|
16730
|
+
// //this.onHomeEvent.next();
|
16731
|
+
// } else if (evt.keyCode === 35) {
|
16732
|
+
// //this.onEndEvent.next();
|
16733
|
+
// }
|
16546
16734
|
},
|
16547
16735
|
copy: (evt) => {
|
16548
16736
|
const event = new CopyElementEvent(this.docCtx);
|
@@ -16569,7 +16757,7 @@ class DocumentInput {
|
|
16569
16757
|
const { startControl, startOffset } = this.docCtx.selectionState;
|
16570
16758
|
this.onInputEvent.next({
|
16571
16759
|
data: data,
|
16572
|
-
|
16760
|
+
prevInputDataLength: this.inputTargetStrLength,
|
16573
16761
|
composition: this.composition,
|
16574
16762
|
compositionStartInfo: {
|
16575
16763
|
element: startControl,
|
@@ -16599,12 +16787,34 @@ class DocumentChange {
|
|
16599
16787
|
this.documentInput.onInputEvent.subscribe(data => {
|
16600
16788
|
this.newInput(data);
|
16601
16789
|
});
|
16602
|
-
this.
|
16603
|
-
this.
|
16604
|
-
|
16605
|
-
|
16606
|
-
|
16790
|
+
this.docCtx.onKeyDownEvent.subscribe(evt => {
|
16791
|
+
if (!this.docCtx.selectionState.editable) {
|
16792
|
+
return;
|
16793
|
+
}
|
16794
|
+
if (evt.keyCode === 8) {
|
16795
|
+
this.onBackspace(evt);
|
16796
|
+
}
|
16797
|
+
else if (evt.keyCode === 13 && !evt.shiftKey) {
|
16798
|
+
this.onEnter();
|
16799
|
+
}
|
16800
|
+
if (evt.keyCode === 13 && evt.shiftKey) {
|
16801
|
+
evt.preventDefault();
|
16802
|
+
this.insertSoftBr();
|
16803
|
+
}
|
16804
|
+
else if (evt.keyCode === 46) {
|
16805
|
+
this.onDeleteKeyHandler(evt);
|
16806
|
+
}
|
16807
|
+
if (evt.keyCode === 9) {
|
16808
|
+
evt.preventDefault();
|
16809
|
+
this.insertTabElement();
|
16810
|
+
}
|
16607
16811
|
});
|
16812
|
+
/* this.documentInput.onBackspaceEvent.subscribe((evt) => {
|
16813
|
+
this.onBackspace(evt)
|
16814
|
+
});*/
|
16815
|
+
// this.documentInput.onEnterEvent.subscribe(() => {
|
16816
|
+
// this.onEnter()
|
16817
|
+
// });
|
16608
16818
|
this.documentInput.onCopyEvent.subscribe((evt) => {
|
16609
16819
|
this.onCopy(evt);
|
16610
16820
|
});
|
@@ -16614,21 +16824,10 @@ class DocumentChange {
|
|
16614
16824
|
this.documentInput.onPasteEvent.subscribe((evt) => {
|
16615
16825
|
this.onPaste(evt);
|
16616
16826
|
});
|
16617
|
-
this.documentInput.onInsertBr.subscribe(() => {
|
16618
|
-
this.insertSoftBr();
|
16619
|
-
});
|
16620
|
-
this.documentInput.onDeleteEvent.subscribe((evt) => {
|
16621
|
-
this.onDeleteKeyHandler(evt);
|
16622
|
-
});
|
16623
|
-
this.documentInput.onTabKeyEvent.subscribe(() => {
|
16624
|
-
this.insertTabElement();
|
16625
|
-
});
|
16626
16827
|
}
|
16627
16828
|
newInput(data) {
|
16628
|
-
|
16629
|
-
|
16630
|
-
}
|
16631
|
-
const { startControl, startOffset, collapsed, enableTrackChanges } = this.selectionState;
|
16829
|
+
const { startControl, startOffset, collapsed } = this.selectionState;
|
16830
|
+
const enableTrackChanges = this.viewOptions.enableTrackChanges;
|
16632
16831
|
if (!collapsed) {
|
16633
16832
|
this.onInputBySelectRange(data);
|
16634
16833
|
return;
|
@@ -16647,12 +16846,7 @@ class DocumentChange {
|
|
16647
16846
|
//当前输入节点是在留痕区域中,但是当前关闭了审阅模式,需要拆分留痕区域,创建新输入节点
|
16648
16847
|
if (!enableTrackChanges && this.isInTrackBlock(startControl)) {
|
16649
16848
|
const newInput = this.splitTrackElement(startControl, startOffset);
|
16650
|
-
|
16651
|
-
comp.element = newInput;
|
16652
|
-
comp.offset = 0;
|
16653
|
-
//修正数据
|
16654
|
-
if (data.composition)
|
16655
|
-
this.documentInput.correctInputEle(newInput, newInput.text, 0);
|
16849
|
+
this.correctInputEle(newInput, newInput.text, 0, data);
|
16656
16850
|
this.inputTextGroup(newInput, data);
|
16657
16851
|
return;
|
16658
16852
|
}
|
@@ -16662,26 +16856,27 @@ class DocumentChange {
|
|
16662
16856
|
}
|
16663
16857
|
const siblingTextEle = startOffset === 1 ? ElementUtil.getNextSiblingElement(startControl) : ElementUtil.getPrevSiblingElement(startControl);
|
16664
16858
|
if (siblingTextEle instanceof TextGroupElement) {
|
16665
|
-
|
16666
|
-
|
16667
|
-
if (data.composition) {
|
16668
|
-
this.documentInput.correctInputEle(siblingTextEle, siblingTextEle.text, data.compositionStartInfo.offset);
|
16669
|
-
}
|
16859
|
+
const pos = startOffset === 0 ? siblingTextEle.text.length : 0;
|
16860
|
+
this.correctInputEle(siblingTextEle, siblingTextEle.text, pos, data);
|
16670
16861
|
this.inputTextGroup(siblingTextEle, data);
|
16671
16862
|
}
|
16672
16863
|
else {
|
16673
16864
|
const inputTextProps = this.getDefaultTextProps(startControl, startOffset);
|
16674
16865
|
const newTextGroup = ElementUtil.getNewTextGroup(inputTextProps);
|
16675
16866
|
startControl.parent.addChild(newTextGroup, startControl.getIndex() + startOffset);
|
16676
|
-
|
16677
|
-
this.documentInput.correctInputEle(newTextGroup, '', 0);
|
16678
|
-
}
|
16867
|
+
this.correctInputEle(newTextGroup, '', 0, data);
|
16679
16868
|
this.inputTextGroup(newTextGroup, data);
|
16680
16869
|
}
|
16681
16870
|
return;
|
16682
16871
|
}
|
16683
16872
|
this.inputTextGroup(startControl, data);
|
16684
16873
|
}
|
16874
|
+
correctInputEle(ele, str, pos, data) {
|
16875
|
+
this.documentInput.correctInputEle(ele, str, pos);
|
16876
|
+
data.compositionStartInfo.element = ele;
|
16877
|
+
data.compositionStartInfo.offset = pos;
|
16878
|
+
data.prevInputDataLength = str.length;
|
16879
|
+
}
|
16685
16880
|
/**
|
16686
16881
|
* 选中区域后进行输入
|
16687
16882
|
* 需要处理将选中的区域删除后,进行输入的情况
|
@@ -16739,24 +16934,20 @@ class DocumentChange {
|
|
16739
16934
|
*/
|
16740
16935
|
newInputTrackChanges(data, startControl, startOffset) {
|
16741
16936
|
this.viewOptions.editUser.id;
|
16742
|
-
|
16937
|
+
data.compositionStartInfo;
|
16743
16938
|
if (this.isInCorrectTrackRegion(startControl, exports.TrackRunTypeEnum.Inserted)) {
|
16744
16939
|
return;
|
16745
16940
|
}
|
16746
16941
|
if (this.isInTrackBlock(startControl)) {
|
16747
16942
|
const newInput = this.createNewTrackInput(startControl, startOffset, exports.TrackRunTypeEnum.Inserted);
|
16748
|
-
|
16749
|
-
compInfo.element = newInput;
|
16750
|
-
this.documentInput.correctInputEle(newInput, '', 0);
|
16943
|
+
this.correctInputEle(newInput, '', 0, data);
|
16751
16944
|
this.inputTextGroup(newInput, data);
|
16752
16945
|
return;
|
16753
16946
|
}
|
16754
16947
|
else {
|
16755
16948
|
const { trackElement, newTextGroup } = this.createTextTrackElement(startControl, null, exports.TrackRunTypeEnum.Inserted);
|
16756
16949
|
this.insertElement(startControl, startOffset, [trackElement]);
|
16757
|
-
|
16758
|
-
compInfo.element = newTextGroup;
|
16759
|
-
this.documentInput.correctInputEle(newTextGroup, '', 0);
|
16950
|
+
this.correctInputEle(newTextGroup, '', 0, data);
|
16760
16951
|
this.inputTextGroup(newTextGroup, data);
|
16761
16952
|
return;
|
16762
16953
|
}
|
@@ -16799,24 +16990,23 @@ class DocumentChange {
|
|
16799
16990
|
* @returns
|
16800
16991
|
*/
|
16801
16992
|
getDefaultTextProps(startControl, offset) {
|
16802
|
-
let textProps = this.getDefaultTextPropsByOptions();
|
16803
|
-
if (startControl instanceof TextGroupElement) {
|
16804
|
-
textProps = startControl.props;
|
16805
|
-
}
|
16806
16993
|
const dataEle = ElementUtil.getDataElement(startControl);
|
16807
16994
|
if (dataEle && IsInSideDataElement(startControl, offset)) {
|
16808
16995
|
return dataEle.props.valueTextProps;
|
16809
16996
|
}
|
16810
|
-
|
16997
|
+
else {
|
16998
|
+
return this.getDefaultTextPropsByOptions();
|
16999
|
+
}
|
16811
17000
|
}
|
16812
17001
|
/**
|
16813
17002
|
* 根据选项配置返回创建文本的默认文本属性
|
16814
17003
|
* @private
|
16815
17004
|
*/
|
16816
17005
|
getDefaultTextPropsByOptions() {
|
17006
|
+
const { defaultFontSize, defaultFontName, currentFontSize, currentFontName } = this.viewOptions;
|
16817
17007
|
const props = new TextProps();
|
16818
|
-
props.
|
16819
|
-
props.
|
17008
|
+
props.fontSize = currentFontSize > 0 ? currentFontSize : defaultFontSize;
|
17009
|
+
props.fontName = currentFontName ? currentFontName : defaultFontName;
|
16820
17010
|
props.color = this.viewOptions.defaultColor;
|
16821
17011
|
return props;
|
16822
17012
|
}
|
@@ -16879,15 +17069,20 @@ class DocumentChange {
|
|
16879
17069
|
return trackElement;
|
16880
17070
|
}
|
16881
17071
|
inputTextGroup(text, data) {
|
16882
|
-
const
|
16883
|
-
const prevInputDataLength = prevInputData.length;
|
16884
|
-
if (!data.compositionStartInfo) {
|
16885
|
-
throw new Error('compositionStartInfo is null');
|
16886
|
-
}
|
17072
|
+
const prevInputDataLength = data.prevInputDataLength ?? 0;
|
16887
17073
|
const { element, offset } = data.compositionStartInfo;
|
17074
|
+
//处理当前输入字体大小和名称;当前手动更改了字体信息,需要重新创建文本元素进行输入处理
|
17075
|
+
if (text.props.fontSize !== this.viewOptions.currentFontSize || text.props.fontName !== this.viewOptions.currentFontName) {
|
17076
|
+
//创建新输入项
|
17077
|
+
const newInput = this.createNewInputText();
|
17078
|
+
//插入到文档
|
17079
|
+
this.insertElement(element, offset, [newInput]);
|
17080
|
+
this.correctInputEle(newInput, '', 0, data);
|
17081
|
+
this.inputTextGroup(newInput, data);
|
17082
|
+
return;
|
17083
|
+
}
|
16888
17084
|
let startInputOffset = offset;
|
16889
17085
|
const deleteCount = data.composition ? text.textMeasures.length - prevInputDataLength : 0;
|
16890
|
-
//startInputOffset -= prevInputDataLength;
|
16891
17086
|
if (!(element instanceof TextGroupElement)) {
|
16892
17087
|
//当前选中元素位于输入元素是起始还是结束位置,如果位于起始位置,则输入偏移量为0,否则为未变更之前的内容length
|
16893
17088
|
if (ElementUtil.getNextSiblingElement(element) === text) {
|
@@ -17090,7 +17285,7 @@ class DocumentChange {
|
|
17090
17285
|
const currPara = ElementUtil.getParentByType(control, ParagraphElement);
|
17091
17286
|
//表明是紧挨着的两个段落,要进行段落合并
|
17092
17287
|
if (ElementUtil.getPrevSiblingElement(currPara) === prevPara) {
|
17093
|
-
if (this.
|
17288
|
+
if (this.viewOptions.enableTrackChanges) {
|
17094
17289
|
this.selectionState.resetRange(prevEle, -1);
|
17095
17290
|
return;
|
17096
17291
|
}
|
@@ -17181,7 +17376,7 @@ class DocumentChange {
|
|
17181
17376
|
const currPara = ElementUtil.getParentByType(control, ParagraphElement);
|
17182
17377
|
//表明是紧挨着的两个段落,要进行段落合并
|
17183
17378
|
if (ElementUtil.getNextSiblingElement(currPara) === nextPara) {
|
17184
|
-
if (this.
|
17379
|
+
if (this.viewOptions.enableTrackChanges) {
|
17185
17380
|
this.selectionState.resetRange(nextEle, 0);
|
17186
17381
|
return;
|
17187
17382
|
}
|
@@ -17243,7 +17438,7 @@ class DocumentChange {
|
|
17243
17438
|
return dataEle.length === 2;
|
17244
17439
|
}
|
17245
17440
|
onDeleteText(text, offset, len) {
|
17246
|
-
if (this.
|
17441
|
+
if (this.viewOptions.enableTrackChanges) {
|
17247
17442
|
this.updateDeletedTrackText(text, offset, len);
|
17248
17443
|
}
|
17249
17444
|
else {
|
@@ -17251,7 +17446,7 @@ class DocumentChange {
|
|
17251
17446
|
}
|
17252
17447
|
}
|
17253
17448
|
onDeleteItem(item) {
|
17254
|
-
if (this.
|
17449
|
+
if (this.viewOptions.enableTrackChanges) {
|
17255
17450
|
//删除符号不进行留痕
|
17256
17451
|
if (item.type === 'psym') {
|
17257
17452
|
return;
|
@@ -17342,6 +17537,16 @@ class DocumentChange {
|
|
17342
17537
|
return newTextGroup;
|
17343
17538
|
}
|
17344
17539
|
}
|
17540
|
+
/**
|
17541
|
+
* 创建一个待输入的文本元素
|
17542
|
+
* @private
|
17543
|
+
*/
|
17544
|
+
createNewInputText() {
|
17545
|
+
const { startControl, startOffset } = this.selectionState;
|
17546
|
+
const textProps = this.getDefaultTextProps(startControl, startOffset);
|
17547
|
+
const newInput = ElementUtil.getNewTextGroup(textProps);
|
17548
|
+
return newInput;
|
17549
|
+
}
|
17345
17550
|
getNextTrackElement(target, trackType) {
|
17346
17551
|
let trackElement = ElementUtil.getNextSiblingTrackElement(target, trackType, this.viewOptions.editUser.id);
|
17347
17552
|
if (!trackElement) {
|
@@ -17431,9 +17636,16 @@ class DocumentChange {
|
|
17431
17636
|
* @returns
|
17432
17637
|
*/
|
17433
17638
|
insertTable(tb) {
|
17639
|
+
this.insertLayoutContainer(tb);
|
17640
|
+
}
|
17641
|
+
/**
|
17642
|
+
* 插入布局容器,比如表格、数据容器等
|
17643
|
+
* @param ele
|
17644
|
+
*/
|
17645
|
+
insertLayoutContainer(ele) {
|
17434
17646
|
const breakPara = this.splitCurrentParagraph();
|
17435
|
-
breakPara.parent.addChild(
|
17436
|
-
this.selectionState.resetRange(
|
17647
|
+
breakPara.parent.addChild(ele, breakPara.getIndex());
|
17648
|
+
this.selectionState.resetRange(ele, 0);
|
17437
17649
|
}
|
17438
17650
|
/**
|
17439
17651
|
* 分割当前段落用于插入表格或者粘贴的内容
|
@@ -17495,7 +17707,7 @@ class DocumentChange {
|
|
17495
17707
|
}
|
17496
17708
|
else if (childTarget instanceof BranchElement) {
|
17497
17709
|
//留痕模式
|
17498
|
-
if (this.
|
17710
|
+
if (this.viewOptions.enableTrackChanges) {
|
17499
17711
|
this.deleteRange(childRange);
|
17500
17712
|
}
|
17501
17713
|
else {
|
@@ -18003,7 +18215,7 @@ class DocumentChange {
|
|
18003
18215
|
data: text,
|
18004
18216
|
compositionStartInfo: {
|
18005
18217
|
element: startControl,
|
18006
|
-
offset: startOffset
|
18218
|
+
offset: startOffset,
|
18007
18219
|
}
|
18008
18220
|
});
|
18009
18221
|
}
|
@@ -18020,6 +18232,31 @@ class DocumentChange {
|
|
18020
18232
|
this.selectionState.resetRange(breakPara, 0);
|
18021
18233
|
}
|
18022
18234
|
}
|
18235
|
+
/**
|
18236
|
+
* 向当前光标追加文本
|
18237
|
+
* @param appendStr
|
18238
|
+
* @param inputOffset
|
18239
|
+
* @param replaceLength
|
18240
|
+
* @private
|
18241
|
+
*/
|
18242
|
+
appendText(appendStr, replaceText) {
|
18243
|
+
const { startControl, startOffset } = this.selectionState;
|
18244
|
+
if (startControl instanceof TextGroupElement) {
|
18245
|
+
const data = {
|
18246
|
+
data: appendStr,
|
18247
|
+
prevInputDataLength: startControl.text.length - replaceText.length,
|
18248
|
+
composition: true,
|
18249
|
+
compositionStartInfo: {
|
18250
|
+
element: startControl,
|
18251
|
+
offset: startOffset - replaceText.length
|
18252
|
+
}
|
18253
|
+
};
|
18254
|
+
this.inputTextGroup(startControl, data);
|
18255
|
+
}
|
18256
|
+
else {
|
18257
|
+
console.warn("当前光标所在的元素类型不正确,不能进行追加文本操作");
|
18258
|
+
}
|
18259
|
+
}
|
18023
18260
|
/**
|
18024
18261
|
* 设置当前段落项目符号类型
|
18025
18262
|
*/
|
@@ -18047,7 +18284,7 @@ class DocumentChange {
|
|
18047
18284
|
/**
|
18048
18285
|
* 插入批注
|
18049
18286
|
*/
|
18050
|
-
insertComment() {
|
18287
|
+
insertComment(text) {
|
18051
18288
|
const { startControl, startOffset, endControl, endOffset, collapsed } = this.selectionState;
|
18052
18289
|
if (collapsed || !startControl || !endControl) {
|
18053
18290
|
return;
|
@@ -18064,7 +18301,7 @@ class DocumentChange {
|
|
18064
18301
|
endCommMark.props.markType = 'end';
|
18065
18302
|
this.insertElement(endControl, endOffset, [endCommMark]);
|
18066
18303
|
this.insertElement(startControl, startOffset, [startCommMark]);
|
18067
|
-
startCommMark.props.text =
|
18304
|
+
startCommMark.props.text = text;
|
18068
18305
|
// const commContent = new CommContentElement();
|
18069
18306
|
// commContent.props.id = id;
|
18070
18307
|
// commContent.props.createId = this.viewOptions.editUser.id;
|
@@ -18669,13 +18906,19 @@ class ElementTrackManage {
|
|
18669
18906
|
//前后是连续的操作
|
18670
18907
|
const { format: currFormat } = currOp.ops;
|
18671
18908
|
const { format: prevFormat } = prevOp.ops;
|
18909
|
+
//const applyProps = {};
|
18672
18910
|
Object.keys(currFormat).forEach(key => {
|
18673
18911
|
const currValue = currFormat[key].newValue;
|
18674
|
-
|
18675
|
-
if (CommonUtil.isEqual(currValue, prevValue)) {
|
18912
|
+
if (prevFormat[key] && CommonUtil.isEqual(currValue, prevFormat[key])) {
|
18676
18913
|
return;
|
18677
18914
|
}
|
18678
|
-
prevFormat[key]
|
18915
|
+
if (prevFormat[key]) {
|
18916
|
+
prevFormat[key].newValue = currValue;
|
18917
|
+
}
|
18918
|
+
else {
|
18919
|
+
prevFormat[key] = { oldValue: currFormat[key].oldValue, newValue: currValue };
|
18920
|
+
}
|
18921
|
+
//applyProps[key] = currValue;
|
18679
18922
|
});
|
18680
18923
|
return true;
|
18681
18924
|
}
|
@@ -20118,7 +20361,8 @@ function calculateDistance(a, b) {
|
|
20118
20361
|
|
20119
20362
|
class DocEditor {
|
20120
20363
|
svgContainer;
|
20121
|
-
|
20364
|
+
//设置vue 不允许代理
|
20365
|
+
__v_skip = true;
|
20122
20366
|
contentCtx;
|
20123
20367
|
viewOptions;
|
20124
20368
|
docCtx;
|
@@ -20152,10 +20396,18 @@ class DocEditor {
|
|
20152
20396
|
onDestroy = new Subject();
|
20153
20397
|
beforeNodePatch = new Subject();
|
20154
20398
|
afterNodePatch = new Subject();
|
20399
|
+
//文档内容输入改变的时候,触发此事件(输入、删除文字),可以监听该事件,实现候选词、联想词等功能
|
20400
|
+
onTextChanged = new Subject();
|
20401
|
+
//联想词处理:文档处理之前
|
20402
|
+
onSuggestionsProcess = new Subject();
|
20155
20403
|
//自定义事件传递消息
|
20156
20404
|
eventBus;
|
20157
20405
|
editInput;
|
20158
20406
|
scrollContainer;
|
20407
|
+
// //输入候选建议词列表
|
20408
|
+
// private suggestions: Array<ISuggestionData> = [];
|
20409
|
+
//光标keydown事件
|
20410
|
+
onKeyDownEvent = new Subject();
|
20159
20411
|
constructor(svgContainer) {
|
20160
20412
|
this.svgContainer = svgContainer;
|
20161
20413
|
this.createCanvasContext();
|
@@ -20210,6 +20462,17 @@ class DocEditor {
|
|
20210
20462
|
});
|
20211
20463
|
this.documentEvent.trackTipsChanged.subscribe(data => {
|
20212
20464
|
});
|
20465
|
+
this.documentInput.onKeyDownEvent.subscribe((evt) => {
|
20466
|
+
this.onKeyDownEvent.next(evt);
|
20467
|
+
if (evt.defaultPrevented) {
|
20468
|
+
return;
|
20469
|
+
}
|
20470
|
+
this.processKeyDownEvent(evt);
|
20471
|
+
if (evt.defaultPrevented) {
|
20472
|
+
return;
|
20473
|
+
}
|
20474
|
+
this.docCtx.onKeyDownEvent.next(evt);
|
20475
|
+
});
|
20213
20476
|
this.docCtx.docChange = this.documentChange;
|
20214
20477
|
this.docCtx.syncRefresh = () => {
|
20215
20478
|
this.flushToSchedule();
|
@@ -20226,14 +20489,19 @@ class DocEditor {
|
|
20226
20489
|
const docPagesFunc = this.getVNode();
|
20227
20490
|
const calendarFunc = this.renderCalendar();
|
20228
20491
|
const menuFunc = this.renderContextmenu();
|
20492
|
+
const suggestionFunc = this.renderSuggestions();
|
20229
20493
|
const ruleFunc = new DocRule(this.docCtx);
|
20230
20494
|
const onSizeChange = () => {
|
20231
20495
|
this.adjustPageLayout();
|
20232
20496
|
};
|
20233
|
-
window.addEventListener('resize', onSizeChange);
|
20497
|
+
// window.addEventListener('resize', onSizeChange);
|
20234
20498
|
this.onDestroy.subscribe(() => {
|
20235
|
-
|
20499
|
+
ro.unobserve(this.svgContainer);
|
20500
|
+
});
|
20501
|
+
const ro = new ResizeObserver(entries => {
|
20502
|
+
onSizeChange();
|
20236
20503
|
});
|
20504
|
+
ro.observe(this.svgContainer);
|
20237
20505
|
return {
|
20238
20506
|
render: () => {
|
20239
20507
|
const docContentVNode = docPagesFunc.render();
|
@@ -20262,7 +20530,7 @@ class DocEditor {
|
|
20262
20530
|
'transform': `scale(${this.viewOptions.scale})`
|
20263
20531
|
}
|
20264
20532
|
},
|
20265
|
-
children: [inputVNode, listVNode.render(), calendarFunc.render(), menuFunc.render()]
|
20533
|
+
children: [inputVNode, listVNode.render(), calendarFunc.render(), menuFunc.render(), suggestionFunc.render()]
|
20266
20534
|
};
|
20267
20535
|
return {
|
20268
20536
|
sel: 'div.svg-container',
|
@@ -20273,8 +20541,14 @@ class DocEditor {
|
|
20273
20541
|
hook: {
|
20274
20542
|
insert: (vNode) => {
|
20275
20543
|
this.svgContainer = vNode.elm;
|
20544
|
+
ro.observe(this.svgContainer);
|
20276
20545
|
this.updateViewOption();
|
20277
20546
|
}
|
20547
|
+
},
|
20548
|
+
on: {
|
20549
|
+
resize: () => {
|
20550
|
+
console.log('resize');
|
20551
|
+
}
|
20278
20552
|
}
|
20279
20553
|
},
|
20280
20554
|
children: [
|
@@ -20284,7 +20558,7 @@ class DocEditor {
|
|
20284
20558
|
style: {
|
20285
20559
|
overflow: 'auto',
|
20286
20560
|
position: 'relative',
|
20287
|
-
height:
|
20561
|
+
height: "100%"
|
20288
20562
|
},
|
20289
20563
|
on: {
|
20290
20564
|
scroll: (evt) => {
|
@@ -20292,6 +20566,9 @@ class DocEditor {
|
|
20292
20566
|
this.viewOptions.pageOffset.x = target.scrollLeft;
|
20293
20567
|
this.viewOptions.pageOffset.y = target.scrollTop;
|
20294
20568
|
this.onChange();
|
20569
|
+
},
|
20570
|
+
resize: () => {
|
20571
|
+
console.log('resize');
|
20295
20572
|
}
|
20296
20573
|
},
|
20297
20574
|
hook: {
|
@@ -20410,10 +20687,9 @@ class DocEditor {
|
|
20410
20687
|
if (this.docCtx.refreshType === null) {
|
20411
20688
|
return;
|
20412
20689
|
}
|
20413
|
-
|
20414
|
-
if (
|
20690
|
+
this.docCtx.currentRefreshType = this.docCtx.refreshType;
|
20691
|
+
if (this.docCtx.currentRefreshType) {
|
20415
20692
|
this.onBeforeRefreshDocument.next();
|
20416
|
-
this.documentSelection.clearSnapshot();
|
20417
20693
|
this.docComment.readComments();
|
20418
20694
|
suppressTracking(() => {
|
20419
20695
|
this.documentPaginator.rePages();
|
@@ -20433,14 +20709,33 @@ class DocEditor {
|
|
20433
20709
|
let ssChanged = false;
|
20434
20710
|
try {
|
20435
20711
|
//防止由于选区不正确导致的错误,导致后续的当前任务无法释放
|
20436
|
-
|
20712
|
+
this.documentSelection.updateSelectionState();
|
20713
|
+
ssChanged = this.documentSelection.isSelectionChanged();
|
20437
20714
|
}
|
20438
20715
|
catch (e) {
|
20439
20716
|
console.error(e);
|
20440
20717
|
}
|
20441
20718
|
this.selectionOverlays.getSelectionTreeData();
|
20719
|
+
ssChanged && this.updateInputFont();
|
20442
20720
|
ssChanged && this.selectionChanged.next(this.documentSelection.selectionState);
|
20443
20721
|
ssChanged && this.documentEvent.invokeCursor(this.selectionState.startControl);
|
20722
|
+
this.documentSelection.clearSnapshot();
|
20723
|
+
this.documentSelection.takeSnapshot();
|
20724
|
+
}
|
20725
|
+
/**
|
20726
|
+
* 根据当前选区,更新待输入文本字体信息
|
20727
|
+
* @private
|
20728
|
+
*/
|
20729
|
+
updateInputFont() {
|
20730
|
+
const { startControl } = this.selectionState;
|
20731
|
+
if (startControl instanceof TextGroupElement) {
|
20732
|
+
this.viewOptions.currentFontSize = startControl.props.fontSize;
|
20733
|
+
this.viewOptions.currentFontName = startControl.props.fontName;
|
20734
|
+
}
|
20735
|
+
else {
|
20736
|
+
this.viewOptions.currentFontSize = this.viewOptions.defaultFontSize;
|
20737
|
+
this.viewOptions.currentFontName = this.viewOptions.defaultFontName;
|
20738
|
+
}
|
20444
20739
|
}
|
20445
20740
|
hitInfoChanged(hitInfo) {
|
20446
20741
|
this.documentSelection.setSelectionState(hitInfo);
|
@@ -20736,6 +21031,9 @@ class DocEditor {
|
|
20736
21031
|
this.documentChange.insertTable(tb);
|
20737
21032
|
return tb;
|
20738
21033
|
}
|
21034
|
+
insertLayoutContainer(ele) {
|
21035
|
+
this.documentChange.insertLayoutContainer(ele);
|
21036
|
+
}
|
20739
21037
|
/**
|
20740
21038
|
* 插入软换行符
|
20741
21039
|
*/
|
@@ -20920,8 +21218,8 @@ class DocEditor {
|
|
20920
21218
|
/**
|
20921
21219
|
* 插入批注
|
20922
21220
|
*/
|
20923
|
-
insertComment() {
|
20924
|
-
this.documentChange.insertComment();
|
21221
|
+
insertComment(text) {
|
21222
|
+
this.documentChange.insertComment(text);
|
20925
21223
|
}
|
20926
21224
|
/**
|
20927
21225
|
* 清除所有批注
|
@@ -20986,16 +21284,12 @@ class DocEditor {
|
|
20986
21284
|
canRedo() {
|
20987
21285
|
return this.historyMange.canRedo;
|
20988
21286
|
}
|
20989
|
-
|
21287
|
+
/**
|
21288
|
+
* 切换文档留痕开关
|
21289
|
+
*/
|
21290
|
+
switchTrackChanges() {
|
20990
21291
|
this.selectionState.clear();
|
20991
|
-
|
20992
|
-
const body = eleCtx.treeFind(item => item instanceof DocumentBodyElement);
|
20993
|
-
if (body) {
|
20994
|
-
body.trackChanges = !body.trackChanges;
|
20995
|
-
}
|
20996
|
-
else {
|
20997
|
-
throw new Error('未找到doc-body');
|
20998
|
-
}
|
21292
|
+
this.viewOptions.enableTrackChanges = !this.viewOptions.enableTrackChanges;
|
20999
21293
|
}
|
21000
21294
|
get trackTipsChanged() {
|
21001
21295
|
return this.documentEvent.trackTipsChanged;
|
@@ -21340,14 +21634,18 @@ class DocEditor {
|
|
21340
21634
|
if (this.viewOptions.reviewWindowWidth > 0) {
|
21341
21635
|
this.viewOptions.reviewWindowWidth = 0;
|
21342
21636
|
//刷新页面
|
21343
|
-
this.docCtx.onNextView(() => {
|
21637
|
+
this.docCtx.onNextView(() => {
|
21638
|
+
this.adjustPageLayout();
|
21639
|
+
});
|
21344
21640
|
}
|
21345
21641
|
}
|
21346
21642
|
else {
|
21347
21643
|
if (this.viewOptions.reviewWindowWidth === 0) {
|
21348
21644
|
this.viewOptions.reviewWindowWidth = 250;
|
21349
21645
|
//刷新页面
|
21350
|
-
this.docCtx.onNextView(() => {
|
21646
|
+
this.docCtx.onNextView(() => {
|
21647
|
+
this.adjustPageLayout();
|
21648
|
+
});
|
21351
21649
|
}
|
21352
21650
|
}
|
21353
21651
|
}
|
@@ -21443,11 +21741,13 @@ class DocEditor {
|
|
21443
21741
|
//ckbVNode.data.attrs['checked'] = true;
|
21444
21742
|
}
|
21445
21743
|
return {
|
21446
|
-
sel: 'div', data: {
|
21744
|
+
sel: 'div', data: {
|
21745
|
+
on: {
|
21447
21746
|
click: () => {
|
21448
21747
|
onChangeHandler(item.code);
|
21449
21748
|
}
|
21450
|
-
}
|
21749
|
+
}
|
21750
|
+
}, children: [ckbVNode, {
|
21451
21751
|
sel: 'label',
|
21452
21752
|
data: {},
|
21453
21753
|
text: item.value
|
@@ -21455,18 +21755,12 @@ class DocEditor {
|
|
21455
21755
|
};
|
21456
21756
|
});
|
21457
21757
|
return {
|
21458
|
-
sel: 'div
|
21758
|
+
sel: 'div.data-list-container',
|
21459
21759
|
data: {
|
21460
21760
|
style: {
|
21461
21761
|
position: 'absolute',
|
21462
21762
|
left: (position.x - 10) + 'px',
|
21463
21763
|
top: position.y + 5 + position.height + 'px',
|
21464
|
-
'min-width': '100px',
|
21465
|
-
'background-color': 'white',
|
21466
|
-
'z-index': '1000',
|
21467
|
-
'border-radius': '5px',
|
21468
|
-
'box-shadow': '0 0 5px 0 rgba(0,0,0,0.2)',
|
21469
|
-
'user-select': 'none',
|
21470
21764
|
},
|
21471
21765
|
hook: {
|
21472
21766
|
insert: (vnode) => {
|
@@ -21563,6 +21857,44 @@ class DocEditor {
|
|
21563
21857
|
if (!editor.menusData) {
|
21564
21858
|
return null;
|
21565
21859
|
}
|
21860
|
+
const renderMenu = (menus) => {
|
21861
|
+
if (!menus) {
|
21862
|
+
return [];
|
21863
|
+
}
|
21864
|
+
return [
|
21865
|
+
{
|
21866
|
+
sel: 'ul.editor-overlays-menus',
|
21867
|
+
data: {},
|
21868
|
+
children: menus.map((menu) => renderMenuItem(menu))
|
21869
|
+
}
|
21870
|
+
];
|
21871
|
+
};
|
21872
|
+
const renderSubItems = (menu) => {
|
21873
|
+
if (!menu.subItems)
|
21874
|
+
return [];
|
21875
|
+
return renderMenu(menu.subItems);
|
21876
|
+
};
|
21877
|
+
const renderMenuItem = (menu) => {
|
21878
|
+
return {
|
21879
|
+
sel: 'li' + (menu.subItems && menu.subItems.length ? '.sub' : ''),
|
21880
|
+
data: {
|
21881
|
+
on: {
|
21882
|
+
click: () => {
|
21883
|
+
menu.click?.();
|
21884
|
+
editor.menusData = null;
|
21885
|
+
editor.onChange();
|
21886
|
+
}
|
21887
|
+
}
|
21888
|
+
},
|
21889
|
+
children: [{
|
21890
|
+
sel: 'span',
|
21891
|
+
data: {},
|
21892
|
+
text: menu.caption
|
21893
|
+
},
|
21894
|
+
...renderSubItems(menu)
|
21895
|
+
]
|
21896
|
+
};
|
21897
|
+
};
|
21566
21898
|
return {
|
21567
21899
|
sel: 'div.editor-contextmenu',
|
21568
21900
|
data: {
|
@@ -21571,27 +21903,7 @@ class DocEditor {
|
|
21571
21903
|
top: editor.menusData.position.y + 'px',
|
21572
21904
|
}
|
21573
21905
|
},
|
21574
|
-
children:
|
21575
|
-
{
|
21576
|
-
sel: 'ul.editor-overlays-menus',
|
21577
|
-
data: {},
|
21578
|
-
children: editor.menusData.menus.map((menu) => {
|
21579
|
-
return {
|
21580
|
-
sel: 'li',
|
21581
|
-
data: {
|
21582
|
-
on: {
|
21583
|
-
click: (evt) => {
|
21584
|
-
menu.eventObj["onClick"]();
|
21585
|
-
editor.menusData = null;
|
21586
|
-
editor.onChange();
|
21587
|
-
}
|
21588
|
-
}
|
21589
|
-
},
|
21590
|
-
text: menu.caption
|
21591
|
-
};
|
21592
|
-
})
|
21593
|
-
}
|
21594
|
-
]
|
21906
|
+
children: renderMenu(editor.menusData.menus)
|
21595
21907
|
};
|
21596
21908
|
}
|
21597
21909
|
};
|
@@ -21613,7 +21925,7 @@ class DocEditor {
|
|
21613
21925
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
21614
21926
|
}
|
21615
21927
|
version() {
|
21616
|
-
return "2.2.
|
21928
|
+
return "2.2.4";
|
21617
21929
|
}
|
21618
21930
|
switchPageHeaderEditor() {
|
21619
21931
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
@@ -21696,6 +22008,7 @@ class DocEditor {
|
|
21696
22008
|
readDocChangeLog() {
|
21697
22009
|
//获取文档的变更日志
|
21698
22010
|
const ops = generatePatch(this.docCtx.document, false);
|
22011
|
+
//1.处理批注删除不对称的问题
|
21699
22012
|
for (let i = 0; i < ops.length; i++) {
|
21700
22013
|
const op = ops[i];
|
21701
22014
|
if ('delete' in op.ops) {
|
@@ -21722,6 +22035,192 @@ class DocEditor {
|
|
21722
22035
|
}
|
21723
22036
|
}
|
21724
22037
|
}
|
22038
|
+
//处理文字输入
|
22039
|
+
if (this.viewOptions.enableSuggestions && ops.length && ops.every(op => 'delText' in op.ops || 'insText' in op.ops || ('insert' in op.ops && op.ops.insert.type === 'text'))) {
|
22040
|
+
this.processSuggestionsHandle();
|
22041
|
+
}
|
22042
|
+
else {
|
22043
|
+
this.docCtx.suggestions.clear();
|
22044
|
+
}
|
22045
|
+
}
|
22046
|
+
/**
|
22047
|
+
* 处理候选词
|
22048
|
+
* @private
|
22049
|
+
*/
|
22050
|
+
processSuggestionsHandle() {
|
22051
|
+
this.docCtx.suggestions.clear();
|
22052
|
+
//this.suggestionSelectIndex.value = -1;
|
22053
|
+
const sub = this.selectionChanged.subscribe(() => {
|
22054
|
+
this.createAutoCompleteOptions();
|
22055
|
+
});
|
22056
|
+
sub.once = true;
|
22057
|
+
}
|
22058
|
+
createAutoCompleteOptions() {
|
22059
|
+
if (!this.viewOptions.enableSuggestions || !this.selectionState.editable) {
|
22060
|
+
return;
|
22061
|
+
}
|
22062
|
+
if (this.selectionState.collapsed && this.selectionState.startControl instanceof TextGroupElement) {
|
22063
|
+
const { startControl, startOffset } = this.selectionState;
|
22064
|
+
const text = startControl.text;
|
22065
|
+
//根据标点符号分割文本
|
22066
|
+
let findText = text.substring(0, startOffset);
|
22067
|
+
//循环当前字符串,根据startOffset向前寻找,直到找到标点符号
|
22068
|
+
for (let i = startOffset; i >= 0; i--) {
|
22069
|
+
const char = text.charAt(i);
|
22070
|
+
if (char.match(/[\s,,。?!;:、]/)) {
|
22071
|
+
findText = text.substring(i + 1, startOffset);
|
22072
|
+
break;
|
22073
|
+
}
|
22074
|
+
}
|
22075
|
+
//结尾为标点符号
|
22076
|
+
if (!findText.length) {
|
22077
|
+
return;
|
22078
|
+
}
|
22079
|
+
const filterSuggestions = this.docCtx.suggestions.suggestionsList.filter(item => item.label.includes(findText));
|
22080
|
+
const data = {
|
22081
|
+
filterSuggestions,
|
22082
|
+
inputTextGroup: startControl,
|
22083
|
+
inputOffset: startOffset,
|
22084
|
+
findText
|
22085
|
+
};
|
22086
|
+
this.onSuggestionsProcess.next(data);
|
22087
|
+
this.docCtx.suggestions.prepareSuggestions.push(...data.filterSuggestions);
|
22088
|
+
this.docCtx.suggestions.currentInputTextGroup = data.inputTextGroup;
|
22089
|
+
this.docCtx.suggestions.currentInputOffset = data.inputOffset;
|
22090
|
+
this.docCtx.suggestions.currentMatchedText = data.findText;
|
22091
|
+
//this.suggestions.push('文本输入1', '文本输入2', '文本输入3');
|
22092
|
+
}
|
22093
|
+
}
|
22094
|
+
processKeyDownEvent(evt) {
|
22095
|
+
if (evt.keyCode === 38 || evt.keyCode === 40) {
|
22096
|
+
if (this.docCtx.suggestions.prepareSuggestions.length) {
|
22097
|
+
this.onSuggestionsKeydown(evt);
|
22098
|
+
}
|
22099
|
+
}
|
22100
|
+
else if (evt.keyCode === 27) {
|
22101
|
+
if (this.docCtx.suggestions.prepareSuggestions.length) {
|
22102
|
+
evt.preventDefault();
|
22103
|
+
this.docCtx.suggestions.clear();
|
22104
|
+
this.onPatchVNodeSubject.next();
|
22105
|
+
}
|
22106
|
+
}
|
22107
|
+
else if (evt.keyCode === 13) {
|
22108
|
+
if (this.docCtx.suggestions.prepareSuggestions.length) {
|
22109
|
+
evt.preventDefault();
|
22110
|
+
const suggestions = this.docCtx.suggestions;
|
22111
|
+
const suggestion = suggestions.prepareSuggestions[suggestions.selectedIndex];
|
22112
|
+
if (suggestion) {
|
22113
|
+
this.insertSuggestion(suggestion);
|
22114
|
+
suggestions.clear();
|
22115
|
+
this.onPatchVNodeSubject.next();
|
22116
|
+
}
|
22117
|
+
else {
|
22118
|
+
suggestions.clear();
|
22119
|
+
this.onPatchVNodeSubject.next();
|
22120
|
+
}
|
22121
|
+
}
|
22122
|
+
}
|
22123
|
+
}
|
22124
|
+
/**
|
22125
|
+
* 处理候选词,键盘选择定位
|
22126
|
+
* @private
|
22127
|
+
*/
|
22128
|
+
onSuggestionsKeydown(evt) {
|
22129
|
+
evt.preventDefault();
|
22130
|
+
let index = this.docCtx.suggestions.selectedIndex;
|
22131
|
+
if (evt.keyCode === 38) {
|
22132
|
+
index--;
|
22133
|
+
}
|
22134
|
+
else {
|
22135
|
+
index++;
|
22136
|
+
}
|
22137
|
+
if (index < 0) {
|
22138
|
+
index = this.docCtx.suggestions.prepareSuggestions.length - 1;
|
22139
|
+
}
|
22140
|
+
else if (index >= this.docCtx.suggestions.prepareSuggestions.length) {
|
22141
|
+
index = 0;
|
22142
|
+
}
|
22143
|
+
this.docCtx.suggestions.selectedIndex = index;
|
22144
|
+
this.onPatchVNodeSubject.next();
|
22145
|
+
}
|
22146
|
+
/**
|
22147
|
+
* 渲染联想、候选词
|
22148
|
+
* @private
|
22149
|
+
*/
|
22150
|
+
renderSuggestions() {
|
22151
|
+
const editor = this;
|
22152
|
+
return {
|
22153
|
+
render() {
|
22154
|
+
if (!editor.docCtx.suggestions.prepareSuggestions || !editor.viewOptions.enableSuggestions) {
|
22155
|
+
editor.docCtx.suggestions.clear();
|
22156
|
+
return null;
|
22157
|
+
}
|
22158
|
+
const cursorPos = editor.selectionState.cursorPos;
|
22159
|
+
if (!cursorPos) {
|
22160
|
+
return null;
|
22161
|
+
}
|
22162
|
+
const renderSuggestion = (suggestions) => {
|
22163
|
+
if (!suggestions || !suggestions.length) {
|
22164
|
+
return [];
|
22165
|
+
}
|
22166
|
+
return [
|
22167
|
+
{
|
22168
|
+
sel: 'ul.editor-suggestions',
|
22169
|
+
data: {
|
22170
|
+
hook: {
|
22171
|
+
insert: (vNode) => {
|
22172
|
+
const elm = vNode.elm;
|
22173
|
+
elm.focus();
|
22174
|
+
}
|
22175
|
+
},
|
22176
|
+
on: {
|
22177
|
+
keydown: (evt) => {
|
22178
|
+
console.log("ul.editor-suggestions", evt);
|
22179
|
+
}
|
22180
|
+
}
|
22181
|
+
},
|
22182
|
+
children: suggestions.map((suggestion, index) => renderSuggestionItem(suggestion, index))
|
22183
|
+
}
|
22184
|
+
];
|
22185
|
+
};
|
22186
|
+
const renderSuggestionItem = (suggestion, index) => {
|
22187
|
+
return {
|
22188
|
+
sel: 'li' + (index === editor.docCtx.suggestions.selectedIndex ? '.hovered' : ''),
|
22189
|
+
data: {
|
22190
|
+
on: {
|
22191
|
+
click: () => {
|
22192
|
+
editor.insertSuggestion(suggestion);
|
22193
|
+
}
|
22194
|
+
}
|
22195
|
+
},
|
22196
|
+
children: [{
|
22197
|
+
sel: 'span',
|
22198
|
+
data: {},
|
22199
|
+
text: suggestion.label
|
22200
|
+
}]
|
22201
|
+
};
|
22202
|
+
};
|
22203
|
+
return {
|
22204
|
+
sel: 'div.editor-suggestions-container',
|
22205
|
+
data: {
|
22206
|
+
style: {
|
22207
|
+
left: cursorPos.x + 'px',
|
22208
|
+
top: cursorPos.y + cursorPos.height + 'px',
|
22209
|
+
}
|
22210
|
+
},
|
22211
|
+
children: renderSuggestion(editor.docCtx.suggestions.prepareSuggestions)
|
22212
|
+
};
|
22213
|
+
}
|
22214
|
+
};
|
22215
|
+
}
|
22216
|
+
insertSuggestion(suggestion) {
|
22217
|
+
if (suggestion.action) {
|
22218
|
+
suggestion.action(suggestion);
|
22219
|
+
}
|
22220
|
+
else {
|
22221
|
+
const text = suggestion.value ? suggestion.value : suggestion.label;
|
22222
|
+
this.documentChange.appendText(text, this.docCtx.suggestions.currentMatchedText);
|
22223
|
+
}
|
21725
22224
|
}
|
21726
22225
|
}
|
21727
22226
|
|
@@ -26874,7 +27373,7 @@ class DocumentPrintOffscreenBase {
|
|
26874
27373
|
afterPrint = new Subject();
|
26875
27374
|
constructor() {
|
26876
27375
|
this.viewOptions = new ViewOptions();
|
26877
|
-
this.viewOptions.copyRightInfo = '
|
27376
|
+
this.viewOptions.copyRightInfo = '';
|
26878
27377
|
this.viewOptions.showCharRect = true;
|
26879
27378
|
this.viewOptions.drawCharRectColor = 'green';
|
26880
27379
|
this.viewOptions.showLineRect = true;
|
@@ -27033,27 +27532,25 @@ function runTextLineRender(ele, data) {
|
|
27033
27532
|
const deleteCurrentParagraph = (evt) => {
|
27034
27533
|
const { selectionState, ctx: { viewOptions }, currentElement } = evt;
|
27035
27534
|
evt.menus.push({
|
27036
|
-
|
27037
|
-
|
27038
|
-
|
27039
|
-
|
27040
|
-
|
27041
|
-
|
27042
|
-
if (nextFocusableEle) {
|
27043
|
-
|
27044
|
-
selectionState.resetRange(nextFocusableEle, 0);
|
27045
|
-
}
|
27046
|
-
else {
|
27047
|
-
selectionState.resetRange(parentContainer, 0);
|
27048
|
-
}
|
27535
|
+
caption: '删除段落', click: () => {
|
27536
|
+
selectionState.clear();
|
27537
|
+
const psymbol = ElementUtil.getLastLeafElement(currentElement);
|
27538
|
+
const nextFocusableEle = ElementUtil.getRecursionNextSiblingElement(psymbol, false, true, viewOptions);
|
27539
|
+
const parentContainer = currentElement.parent;
|
27540
|
+
if (nextFocusableEle) {
|
27541
|
+
if (nextFocusableEle.parent === parentContainer) {
|
27542
|
+
selectionState.resetRange(nextFocusableEle, 0);
|
27049
27543
|
}
|
27050
27544
|
else {
|
27051
27545
|
selectionState.resetRange(parentContainer, 0);
|
27052
|
-
//selectionState.clear();
|
27053
27546
|
}
|
27054
|
-
currentElement.remove();
|
27055
|
-
currentElement.destroy();
|
27056
27547
|
}
|
27548
|
+
else {
|
27549
|
+
selectionState.resetRange(parentContainer, 0);
|
27550
|
+
//selectionState.clear();
|
27551
|
+
}
|
27552
|
+
currentElement.remove();
|
27553
|
+
currentElement.destroy();
|
27057
27554
|
}
|
27058
27555
|
});
|
27059
27556
|
};
|
@@ -27077,39 +27574,24 @@ const deleteCurrentParagraph = (evt) => {
|
|
27077
27574
|
// }
|
27078
27575
|
// });
|
27079
27576
|
// };
|
27080
|
-
const setDataElementProps = (evt) => {
|
27081
|
-
evt.menus.push({
|
27082
|
-
icon: 'Settings', caption: '内容控制设置', eventObj: {
|
27083
|
-
onClick: (e) => {
|
27084
|
-
console.log('点击了');
|
27085
|
-
}
|
27086
|
-
}
|
27087
|
-
});
|
27088
|
-
};
|
27089
27577
|
const onTableContextmenu = (evt) => {
|
27090
27578
|
const { selectionState, ctx: { viewOptions }, currentElement } = evt;
|
27091
27579
|
if (TableUtil.canDeleteTable(selectionState)) {
|
27092
27580
|
evt.menus.push({
|
27093
|
-
|
27094
|
-
|
27095
|
-
|
27096
|
-
|
27097
|
-
|
27098
|
-
selectionState.resetRange(prevEle, -1);
|
27099
|
-
}
|
27100
|
-
currentElement.remove();
|
27101
|
-
currentElement.destroy();
|
27581
|
+
caption: '删除表格', click: () => {
|
27582
|
+
selectionState.clear();
|
27583
|
+
const prevEle = ElementUtil.getRecursionPrevSiblingElement(currentElement, false, true, viewOptions);
|
27584
|
+
if (prevEle) {
|
27585
|
+
selectionState.resetRange(prevEle, -1);
|
27102
27586
|
}
|
27587
|
+
currentElement.remove();
|
27588
|
+
currentElement.destroy();
|
27103
27589
|
}
|
27104
27590
|
});
|
27105
27591
|
}
|
27106
27592
|
if (TableUtil.canMergeCells(selectionState)) {
|
27107
27593
|
evt.menus.push({
|
27108
|
-
|
27109
|
-
onClick: (cevt) => {
|
27110
|
-
TableUtil.mergeCells(selectionState);
|
27111
|
-
}
|
27112
|
-
}
|
27594
|
+
caption: '合并单元格', click: () => { TableUtil.mergeCells(selectionState); }
|
27113
27595
|
});
|
27114
27596
|
}
|
27115
27597
|
if (TableUtil.canSplitCell(selectionState)) {
|
@@ -27121,27 +27603,19 @@ const onTableContextmenu = (evt) => {
|
|
27121
27603
|
// }
|
27122
27604
|
// });
|
27123
27605
|
evt.menus.push({
|
27124
|
-
|
27125
|
-
onClick: (cevt) => {
|
27126
|
-
TableUtil.restoreCell(selectionState);
|
27127
|
-
}
|
27128
|
-
}
|
27606
|
+
caption: '拆分单元格', click: () => { TableUtil.restoreCell(selectionState); }
|
27129
27607
|
});
|
27130
27608
|
}
|
27131
27609
|
evt.menus.push({
|
27132
|
-
|
27133
|
-
|
27134
|
-
|
27135
|
-
currentElement.refreshView();
|
27136
|
-
}
|
27610
|
+
caption: '上方插入段落', click: () => {
|
27611
|
+
currentElement.parent.addChild(ParagraphElement.createElement(), currentElement.getIndex());
|
27612
|
+
currentElement.refreshView();
|
27137
27613
|
}
|
27138
27614
|
});
|
27139
27615
|
evt.menus.push({
|
27140
|
-
|
27141
|
-
|
27142
|
-
|
27143
|
-
currentElement.refreshView();
|
27144
|
-
}
|
27616
|
+
caption: '下方插入段落', click: () => {
|
27617
|
+
currentElement.parent.addChild(ParagraphElement.createElement(), currentElement.getIndex() + 1);
|
27618
|
+
currentElement.refreshView();
|
27145
27619
|
}
|
27146
27620
|
});
|
27147
27621
|
evt.menus = removeDuplicatesEvent(evt.menus);
|
@@ -27193,6 +27667,10 @@ exports.ContextMenuElementEvent = ContextMenuElementEvent;
|
|
27193
27667
|
exports.CopyElementEvent = CopyElementEvent;
|
27194
27668
|
exports.DOMEventSource = DOMEventSource;
|
27195
27669
|
exports.DOMSubscription = DOMSubscription;
|
27670
|
+
exports.DataContainerElement = DataContainerElement;
|
27671
|
+
exports.DataContainerFactory = DataContainerFactory;
|
27672
|
+
exports.DataContainerProps = DataContainerProps;
|
27673
|
+
exports.DataContainerRenderObject = DataContainerRenderObject;
|
27196
27674
|
exports.DataDecorateElement = DataDecorateElement;
|
27197
27675
|
exports.DataDecorateProps = DataDecorateProps;
|
27198
27676
|
exports.DataDecorateRenderObject = DataDecorateRenderObject;
|
@@ -27234,6 +27712,7 @@ exports.DataElementTextRenderObject = DataElementTextRenderObject;
|
|
27234
27712
|
exports.DataImageRenderObject = DataImageRenderObject;
|
27235
27713
|
exports.DataRenderMH = DataRenderMH;
|
27236
27714
|
exports.DocEditor = DocEditor;
|
27715
|
+
exports.DocInputSuggestions = DocInputSuggestions;
|
27237
27716
|
exports.DocumentBodyElement = DocumentBodyElement;
|
27238
27717
|
exports.DocumentBodyFactory = DocumentBodyFactory;
|
27239
27718
|
exports.DocumentBodyPartElement = DocumentBodyPartElement;
|
@@ -27341,6 +27820,7 @@ exports.SelectionState = SelectionState;
|
|
27341
27820
|
exports.Subject = Subject;
|
27342
27821
|
exports.SubjectSubscription = SubjectSubscription;
|
27343
27822
|
exports.Subscription = Subscription;
|
27823
|
+
exports.TEXT_HEIGHT_FACTOR = TEXT_HEIGHT_FACTOR;
|
27344
27824
|
exports.TabElement = TabElement;
|
27345
27825
|
exports.TabFactory = TabFactory;
|
27346
27826
|
exports.TabRenderObject = TabRenderObject;
|
@@ -27403,7 +27883,6 @@ exports.renderErrorTip = renderErrorTip;
|
|
27403
27883
|
exports.renderUnderWavyLine = renderUnderWavyLine;
|
27404
27884
|
exports.runTextLineRender = runTextLineRender;
|
27405
27885
|
exports.setChildrenModifyFlag = setChildrenModifyFlag;
|
27406
|
-
exports.setDataElementProps = setDataElementProps;
|
27407
27886
|
exports.setNotifyChangedCallback = setNotifyChangedCallback;
|
27408
27887
|
exports.setTraceTrackingFlag = setTraceTrackingFlag;
|
27409
27888
|
exports.suppressTracking = suppressTracking;
|