@hailin-zheng/editor-core 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/editor.css +2 -1
- package/index-cjs.js +159 -50
- package/index-cjs.js.map +1 -1
- package/index.js +158 -51
- package/index.js.map +1 -1
- package/med_editor/framework/document-context.d.ts +1 -1
- package/med_editor/framework/element-props.d.ts +0 -1
- package/med_editor/framework/impl/data-element/data-element-base-impl.d.ts +13 -0
- package/package.json +1 -1
package/editor.css
CHANGED
@@ -219,6 +219,7 @@
|
|
219
219
|
background: #fff;
|
220
220
|
cursor: default;
|
221
221
|
user-select: none;
|
222
|
+
font-size: 12px;
|
222
223
|
}
|
223
224
|
|
224
225
|
.editor-calendar-header {
|
@@ -522,7 +523,7 @@
|
|
522
523
|
}
|
523
524
|
.editor-input-cursor{
|
524
525
|
position: absolute;
|
525
|
-
width:
|
526
|
+
width: 1.6px;
|
526
527
|
padding: 0;
|
527
528
|
border: none;
|
528
529
|
outline: none;
|
package/index-cjs.js
CHANGED
@@ -833,28 +833,21 @@ function getDocCtx(ele) {
|
|
833
833
|
if (!doc) {
|
834
834
|
return null;
|
835
835
|
}
|
836
|
-
|
837
|
-
if (!options || !options.enableTrackHistory) {
|
838
|
-
return null;
|
839
|
-
}
|
840
|
-
return {
|
841
|
-
doc,
|
842
|
-
options: doc['viewOptions']
|
843
|
-
};
|
836
|
+
return doc;
|
844
837
|
}
|
845
838
|
function insertEle(ele) {
|
846
839
|
if (ele.type === 'psym') {
|
847
840
|
return;
|
848
841
|
}
|
849
|
-
const
|
850
|
-
if (!
|
842
|
+
const docCtx = getDocCtx(ele);
|
843
|
+
if (!docCtx) {
|
851
844
|
return;
|
852
845
|
}
|
853
846
|
// const serializeObj = getEleSerializeFunc(ele, options);
|
854
847
|
// if (!serializeObj) {
|
855
848
|
// return;
|
856
849
|
// }
|
857
|
-
appendToOps(
|
850
|
+
appendToOps(docCtx, ele, {
|
858
851
|
//如果当前插入的为单元格,由于新插入的单元格,内部的内容没有补足,导致后续计算索引会出现问题
|
859
852
|
//之前为ele.clone(true);
|
860
853
|
insert: ele
|
@@ -864,11 +857,11 @@ function removeEle(ele) {
|
|
864
857
|
if (ele.type === 'psym') {
|
865
858
|
return;
|
866
859
|
}
|
867
|
-
const
|
868
|
-
if (!
|
860
|
+
const docCtx = getDocCtx(ele);
|
861
|
+
if (!docCtx) {
|
869
862
|
return;
|
870
863
|
}
|
871
|
-
appendToOps(
|
864
|
+
appendToOps(docCtx, ele, {
|
872
865
|
delete: ele.clone(true),
|
873
866
|
});
|
874
867
|
}
|
@@ -891,15 +884,15 @@ function getOpsLog(ele, ops) {
|
|
891
884
|
};
|
892
885
|
}
|
893
886
|
function inputText(ele, startIndex, input) {
|
894
|
-
const
|
895
|
-
if (!
|
887
|
+
const docCtx = getDocCtx(ele);
|
888
|
+
if (!docCtx) {
|
896
889
|
return;
|
897
890
|
}
|
898
891
|
if (!input) {
|
899
892
|
return;
|
900
893
|
}
|
901
894
|
//处理修复:如果当前的文字刚插入,这时候输入的文字内容已经被序列化到操作日志中了,就不需要生成操作日志
|
902
|
-
let array = docOpsMap.get(
|
895
|
+
let array = docOpsMap.get(docCtx);
|
903
896
|
if (array) {
|
904
897
|
const lastLog = array[array.length - 1];
|
905
898
|
if (lastLog && 'insert' in lastLog.ops) {
|
@@ -908,7 +901,7 @@ function inputText(ele, startIndex, input) {
|
|
908
901
|
}
|
909
902
|
}
|
910
903
|
}
|
911
|
-
appendToOps(
|
904
|
+
appendToOps(docCtx, ele, {
|
912
905
|
insText: {
|
913
906
|
index: startIndex,
|
914
907
|
length: input.length
|
@@ -917,14 +910,14 @@ function inputText(ele, startIndex, input) {
|
|
917
910
|
});
|
918
911
|
}
|
919
912
|
function removeText(ele, index, length, content) {
|
920
|
-
const
|
921
|
-
if (!
|
913
|
+
const docCtx = getDocCtx(ele);
|
914
|
+
if (!docCtx) {
|
922
915
|
return;
|
923
916
|
}
|
924
917
|
if (!length) {
|
925
918
|
return;
|
926
919
|
}
|
927
|
-
appendToOps(
|
920
|
+
appendToOps(docCtx, ele, {
|
928
921
|
delText: {
|
929
922
|
index,
|
930
923
|
length
|
@@ -939,15 +932,15 @@ function removeText(ele, index, length, content) {
|
|
939
932
|
* @returns
|
940
933
|
*/
|
941
934
|
function formatEle(ele, props) {
|
942
|
-
const
|
943
|
-
if (!
|
935
|
+
const docCtx = getDocCtx(ele);
|
936
|
+
if (!docCtx) {
|
944
937
|
return;
|
945
938
|
}
|
946
939
|
const updateKeys = Object.keys(props);
|
947
940
|
if (!updateKeys.length) {
|
948
941
|
return;
|
949
942
|
}
|
950
|
-
appendToOps(
|
943
|
+
appendToOps(docCtx, ele, {
|
951
944
|
format: getExactDiffProps(ele.props, props)
|
952
945
|
});
|
953
946
|
}
|
@@ -959,11 +952,11 @@ function formatEle(ele, props) {
|
|
959
952
|
* @param newValue
|
960
953
|
*/
|
961
954
|
function logUpdateEleProps(ele, p, oldValue, newValue) {
|
962
|
-
const
|
963
|
-
if (!
|
955
|
+
const docCtx = getDocCtx(ele);
|
956
|
+
if (!docCtx) {
|
964
957
|
return;
|
965
958
|
}
|
966
|
-
appendToOps(
|
959
|
+
appendToOps(docCtx, ele, {
|
967
960
|
format: {
|
968
961
|
[p]: {
|
969
962
|
oldValue,
|
@@ -2409,7 +2402,6 @@ class DataEleBaseProps extends INotifyPropertyChanged {
|
|
2409
2402
|
printable;
|
2410
2403
|
secretBrowse;
|
2411
2404
|
editable = true;
|
2412
|
-
deleteable;
|
2413
2405
|
minLength;
|
2414
2406
|
underline;
|
2415
2407
|
expression;
|
@@ -2425,7 +2417,6 @@ class DataEleBaseProps extends INotifyPropertyChanged {
|
|
2425
2417
|
target.fieldName = source.fieldName;
|
2426
2418
|
target.required = source.required;
|
2427
2419
|
target.editable = source.editable;
|
2428
|
-
target.deleteable = source.deleteable;
|
2429
2420
|
target.secretBrowse = source.secretBrowse;
|
2430
2421
|
target.printable = source.printable;
|
2431
2422
|
target.minLength = source.minLength;
|
@@ -2455,9 +2446,6 @@ class DataEleBaseProps extends INotifyPropertyChanged {
|
|
2455
2446
|
if (!this.editable) {
|
2456
2447
|
props['editable'] = this.editable;
|
2457
2448
|
}
|
2458
|
-
if (this.deleteable) {
|
2459
|
-
props["deleteable"] = this.deleteable;
|
2460
|
-
}
|
2461
2449
|
if (this.minLength) {
|
2462
2450
|
props["minLength"] = this.minLength;
|
2463
2451
|
}
|
@@ -3681,7 +3669,8 @@ class DocumentRenderObject extends BlockContainerRenderObject {
|
|
3681
3669
|
width: this.rect.width,
|
3682
3670
|
height: this.rect.height - 1,
|
3683
3671
|
viewBox: `0 0 ${this.rect.width} ${this.rect.height - 1}`,
|
3684
|
-
overflow: "hidden"
|
3672
|
+
overflow: "hidden",
|
3673
|
+
"shape-rendering": "optimizeSpeed"
|
3685
3674
|
},
|
3686
3675
|
},
|
3687
3676
|
children: [
|
@@ -3973,6 +3962,7 @@ class DataElementRenderObject extends InlineGroupRenderObject {
|
|
3973
3962
|
}
|
3974
3963
|
});
|
3975
3964
|
}
|
3965
|
+
renderErrorTip(event, this);
|
3976
3966
|
return node;
|
3977
3967
|
}
|
3978
3968
|
}
|
@@ -4028,6 +4018,11 @@ class DataElementBaseFactory extends ElementFactory {
|
|
4028
4018
|
}
|
4029
4019
|
}
|
4030
4020
|
}
|
4021
|
+
/**
|
4022
|
+
* 渲染数据元背景修饰
|
4023
|
+
* @param event
|
4024
|
+
* @param r
|
4025
|
+
*/
|
4031
4026
|
function exportDecoratorHTML(event, r) {
|
4032
4027
|
const canPaint = r.element.isMouseenter || r.element.isFocused;
|
4033
4028
|
if (!canPaint) {
|
@@ -4072,10 +4067,12 @@ function exportDecoratorHTML(event, r) {
|
|
4072
4067
|
const sharpPoints1 = CommonUtil.resharpPoints(rightPoints);
|
4073
4068
|
const sharpPoints = CommonUtil.resharpPoints([...leftPoints.reverse()]);
|
4074
4069
|
const path = [...sharpPoints, ...sharpPoints1, sharpPoints[0]].map((item, index) => ((index === 0) ? 'M' : "L") + item.x + " " + item.y).join(" ");
|
4075
|
-
event.highlights.push(ElementUtil.createSvgPath({
|
4070
|
+
event.highlights.push(ElementUtil.createSvgPath({
|
4071
|
+
d: path,
|
4076
4072
|
stroke: color,
|
4077
4073
|
fill: 'none',
|
4078
|
-
'stroke-width': 1
|
4074
|
+
'stroke-width': 1
|
4075
|
+
}));
|
4079
4076
|
return;
|
4080
4077
|
}
|
4081
4078
|
}
|
@@ -4090,6 +4087,110 @@ function exportDecoratorHTML(event, r) {
|
|
4090
4087
|
}
|
4091
4088
|
}
|
4092
4089
|
}
|
4090
|
+
/**
|
4091
|
+
* 渲染数据源验证错误提示框
|
4092
|
+
*/
|
4093
|
+
function renderErrorTip(event, r) {
|
4094
|
+
if (!event.options.enableDataEleInputValidate || event.mode === 'print') {
|
4095
|
+
return;
|
4096
|
+
}
|
4097
|
+
const ele = r.element;
|
4098
|
+
//元素调用内部验证
|
4099
|
+
ele.onChangedValidate();
|
4100
|
+
if (!ele.errorTip) {
|
4101
|
+
return;
|
4102
|
+
}
|
4103
|
+
//渲染底部波浪线
|
4104
|
+
renderUnderWavyLine(event, r, 'red');
|
4105
|
+
if (ele.paintRenders.indexOf(r) !== 0) {
|
4106
|
+
return;
|
4107
|
+
}
|
4108
|
+
const { x, y } = event.globalPos;
|
4109
|
+
const docRender = ElementUtil.getParentRender(r, DocumentRenderObject);
|
4110
|
+
const content = ele.errorTip;
|
4111
|
+
let left = ele.isFocused ? -10 : 5;
|
4112
|
+
//显示在文档的右测
|
4113
|
+
left += docRender.rect.x + docRender.rect.width + 20;
|
4114
|
+
let sel = 'div.tg-container';
|
4115
|
+
if (ele.isFocused) {
|
4116
|
+
sel += '.tg-container--selected';
|
4117
|
+
}
|
4118
|
+
const node = {
|
4119
|
+
sel,
|
4120
|
+
key: ele.props.id,
|
4121
|
+
data: {
|
4122
|
+
style: {
|
4123
|
+
left: `${left}px`,
|
4124
|
+
top: `${y}px`
|
4125
|
+
},
|
4126
|
+
dataset: {
|
4127
|
+
key: ele.key
|
4128
|
+
}
|
4129
|
+
},
|
4130
|
+
children: [{
|
4131
|
+
sel: 'div.header',
|
4132
|
+
data: {},
|
4133
|
+
children: [{
|
4134
|
+
sel: 'span.header-user',
|
4135
|
+
data: {},
|
4136
|
+
text: ele.props.caption,
|
4137
|
+
}]
|
4138
|
+
}, {
|
4139
|
+
sel: 'div.content',
|
4140
|
+
data: {},
|
4141
|
+
text: content
|
4142
|
+
}]
|
4143
|
+
};
|
4144
|
+
event.addChangeTips(node);
|
4145
|
+
const triangleTipX = x + r.rect.width / 2;
|
4146
|
+
const tipLineAWidth = docRender.rect.x + docRender.rect.width - triangleTipX;
|
4147
|
+
const tipLineA = {
|
4148
|
+
sel: 'div.doc-triangle-line',
|
4149
|
+
data: {
|
4150
|
+
style: {
|
4151
|
+
left: `${triangleTipX}px`,
|
4152
|
+
top: `${y + r.rect.height}px`,
|
4153
|
+
width: tipLineAWidth + 'px'
|
4154
|
+
}
|
4155
|
+
}
|
4156
|
+
};
|
4157
|
+
const tipLineB = {
|
4158
|
+
sel: 'div.doc-triangle-line',
|
4159
|
+
data: {
|
4160
|
+
style: {
|
4161
|
+
left: `${triangleTipX + tipLineAWidth}px`,
|
4162
|
+
top: `${y + r.rect.height}px`,
|
4163
|
+
width: 20 + 'px'
|
4164
|
+
},
|
4165
|
+
dataset: {
|
4166
|
+
key: ele.key
|
4167
|
+
}
|
4168
|
+
}
|
4169
|
+
};
|
4170
|
+
const triangleTip = {
|
4171
|
+
sel: `div.doc-triangle`,
|
4172
|
+
data: {
|
4173
|
+
style: {
|
4174
|
+
left: `${triangleTipX}px`,
|
4175
|
+
top: `${y + r.rect.height * 2 / 3}px`
|
4176
|
+
}
|
4177
|
+
}
|
4178
|
+
};
|
4179
|
+
event.addChangeTips(triangleTip);
|
4180
|
+
event.addChangeTips(tipLineA);
|
4181
|
+
event.addChangeTips(tipLineB);
|
4182
|
+
}
|
4183
|
+
/**
|
4184
|
+
* 渲染底部波浪线
|
4185
|
+
*/
|
4186
|
+
function renderUnderWavyLine(event, r, color) {
|
4187
|
+
const { x, y } = event.relativePagePos;
|
4188
|
+
let d = `M ${x} ${y + r.rect.height - 2} q 1.5,2, `;
|
4189
|
+
const width = r.rect.width;
|
4190
|
+
d += Array(Math.ceil(width / 3)).fill("3,0").join(' t ');
|
4191
|
+
const path = ElementUtil.createSvgPath({ d, fill: 'none', stroke: color });
|
4192
|
+
event.highlights.push(path);
|
4193
|
+
}
|
4093
4194
|
/**
|
4094
4195
|
* 获取渲染元素相对稳当的位置
|
4095
4196
|
* @param render
|
@@ -6860,6 +6961,9 @@ class CommentElement extends LeafElement {
|
|
6860
6961
|
}
|
6861
6962
|
class CommentRenderObject extends LeafRenderObject {
|
6862
6963
|
exportSVG(event) {
|
6964
|
+
if (event.mode === 'print') {
|
6965
|
+
return;
|
6966
|
+
}
|
6863
6967
|
const renderPos = { ...event.relativePagePos };
|
6864
6968
|
const paraLinePos = ElementUtil.getParaLinePos(this, { x: renderPos.x, y: renderPos.y });
|
6865
6969
|
const color = '#ff4d4f';
|
@@ -8366,9 +8470,6 @@ class DataElementDate extends DataElementInlineGroup {
|
|
8366
8470
|
this.onChangedValidate();
|
8367
8471
|
}
|
8368
8472
|
isValid(val, format) {
|
8369
|
-
if (!format) {
|
8370
|
-
format = this.props.format ?? 'YYYY-MM-DD';
|
8371
|
-
}
|
8372
8473
|
const date = moment__default["default"](val, format);
|
8373
8474
|
return date.isValid();
|
8374
8475
|
}
|
@@ -8383,8 +8484,7 @@ class DataElementDate extends DataElementInlineGroup {
|
|
8383
8484
|
if (res) {
|
8384
8485
|
return res;
|
8385
8486
|
}
|
8386
|
-
const
|
8387
|
-
const date = moment__default["default"](this.getValue(), format, true);
|
8487
|
+
const date = moment__default["default"](this.getValue(), true);
|
8388
8488
|
if (!date.isValid()) {
|
8389
8489
|
return '日期格式不正确';
|
8390
8490
|
}
|
@@ -10754,7 +10854,6 @@ class ElementUtil {
|
|
10754
10854
|
dest.printable = props.printable ?? true;
|
10755
10855
|
dest.required = props.required;
|
10756
10856
|
dest.secretBrowse = props.secretBrowse;
|
10757
|
-
dest.deleteable = props.deleteable;
|
10758
10857
|
dest.underline = props.underline;
|
10759
10858
|
dest.expression = props.expression;
|
10760
10859
|
dest.hidden = props.hidden;
|
@@ -12902,7 +13001,8 @@ class EditorContext {
|
|
12902
13001
|
docChange;
|
12903
13002
|
clearPrevDocCb;
|
12904
13003
|
//绘制结束之后回调函数
|
12905
|
-
nextViewFn;
|
13004
|
+
//nextViewFn!: (() => void) | null;
|
13005
|
+
nextViewFns = [];
|
12906
13006
|
constructor(selectionState, viewOptions) {
|
12907
13007
|
this.selectionState = selectionState;
|
12908
13008
|
this.viewOptions = viewOptions;
|
@@ -12913,7 +13013,12 @@ class EditorContext {
|
|
12913
13013
|
});
|
12914
13014
|
}
|
12915
13015
|
onNextView(cb) {
|
12916
|
-
|
13016
|
+
if (!cb) {
|
13017
|
+
this.nextViewFns.length = 0;
|
13018
|
+
return;
|
13019
|
+
}
|
13020
|
+
//this.nextViewFn = cb;
|
13021
|
+
this.nextViewFns.push(cb);
|
12917
13022
|
}
|
12918
13023
|
get document() {
|
12919
13024
|
return this._document;
|
@@ -18478,6 +18583,7 @@ class ElementTrackManage {
|
|
18478
18583
|
*/
|
18479
18584
|
generateTrack() {
|
18480
18585
|
if (!this.docCtx.viewOptions.enableTrackHistory) {
|
18586
|
+
clearTraces(this.docCtx.document);
|
18481
18587
|
return;
|
18482
18588
|
}
|
18483
18589
|
const ops = generatePatch(this.docCtx.document);
|
@@ -20267,10 +20373,11 @@ class DocEditor {
|
|
20267
20373
|
this.readDocChangeLog();
|
20268
20374
|
this.refreshDocument();
|
20269
20375
|
this.flushTask = null;
|
20270
|
-
|
20271
|
-
|
20376
|
+
//回调
|
20377
|
+
let cbs = [...this.docCtx.nextViewFns];
|
20378
|
+
if (cbs.length) {
|
20272
20379
|
this.docCtx.onNextView(null);
|
20273
|
-
cb();
|
20380
|
+
cbs.forEach(cb => cb());
|
20274
20381
|
return;
|
20275
20382
|
}
|
20276
20383
|
this.historyMange.generateTrack();
|
@@ -20431,7 +20538,7 @@ class DocEditor {
|
|
20431
20538
|
this.editInput.style.left = position.x + 'px';
|
20432
20539
|
this.editInput.style.top = position.y + 'px';
|
20433
20540
|
this.editInput.style.height = position.height + 'px';
|
20434
|
-
this.editInput.style.width = "
|
20541
|
+
this.editInput.style.width = "1.6px";
|
20435
20542
|
this.editInput.readOnly = false;
|
20436
20543
|
this.setCursorVisibility(true);
|
20437
20544
|
//判断光标位置是否被可见,如果不可见,需要将其设置到可见区域
|
@@ -21252,14 +21359,14 @@ class DocEditor {
|
|
21252
21359
|
if (this.viewOptions.reviewWindowWidth > 0) {
|
21253
21360
|
this.viewOptions.reviewWindowWidth = 0;
|
21254
21361
|
//刷新页面
|
21255
|
-
this.adjustPageLayout();
|
21362
|
+
this.docCtx.onNextView(() => { this.adjustPageLayout(); });
|
21256
21363
|
}
|
21257
21364
|
}
|
21258
21365
|
else {
|
21259
21366
|
if (this.viewOptions.reviewWindowWidth === 0) {
|
21260
21367
|
this.viewOptions.reviewWindowWidth = 250;
|
21261
21368
|
//刷新页面
|
21262
|
-
this.adjustPageLayout();
|
21369
|
+
this.docCtx.onNextView(() => { this.adjustPageLayout(); });
|
21263
21370
|
}
|
21264
21371
|
}
|
21265
21372
|
}
|
@@ -21534,7 +21641,7 @@ class DocEditor {
|
|
21534
21641
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
21535
21642
|
}
|
21536
21643
|
version() {
|
21537
|
-
return "2.2.
|
21644
|
+
return "2.2.1";
|
21538
21645
|
}
|
21539
21646
|
switchPageHeaderEditor() {
|
21540
21647
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
@@ -27272,6 +27379,8 @@ exports.parser = parser;
|
|
27272
27379
|
exports.reactiveMap = reactiveMap;
|
27273
27380
|
exports.removeEle = removeEle;
|
27274
27381
|
exports.removeText = removeText;
|
27382
|
+
exports.renderErrorTip = renderErrorTip;
|
27383
|
+
exports.renderUnderWavyLine = renderUnderWavyLine;
|
27275
27384
|
exports.runTextLineRender = runTextLineRender;
|
27276
27385
|
exports.setChildrenModifyFlag = setChildrenModifyFlag;
|
27277
27386
|
exports.setDataElementProps = setDataElementProps;
|