@hailin-zheng/editor-core 2.2.15 → 2.2.17
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/index-cjs.js +183 -90
- package/index-cjs.js.map +1 -1
- package/index.js +183 -90
- package/index.js.map +1 -1
- package/med_editor/doc-editor.d.ts +25 -0
- package/med_editor/framework/document-change.d.ts +7 -0
- package/med_editor/framework/element-serialize.d.ts +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
@@ -3846,17 +3846,18 @@ class InlineGroupInputElement extends InlineGroupElement {
|
|
3846
3846
|
endDecorate;
|
3847
3847
|
constructor(type) {
|
3848
3848
|
super(type);
|
3849
|
-
//行内块不允许换行
|
3850
|
-
this.addEvent('ElementKeyDown', (evt) => {
|
3851
|
-
|
3852
|
-
|
3853
|
-
|
3854
|
-
|
3855
|
-
|
3856
|
-
|
3857
|
-
|
3858
|
-
|
3859
|
-
}
|
3849
|
+
// //行内块不允许换行
|
3850
|
+
// this.addEvent<KeyboradElementEvent>('ElementKeyDown', (evt) => {
|
3851
|
+
// const { selectionState, sourceEvent, source } = evt;
|
3852
|
+
// const { startControl, startOffset } = selectionState;
|
3853
|
+
// if (IsInSideInlineGroupInputElement(startControl as LeafElement, startOffset)) {
|
3854
|
+
// if (sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
|
3855
|
+
// //this.removeNullText();
|
3856
|
+
// } else if (!sourceEvent.shiftKey && sourceEvent.keyCode === 13) {
|
3857
|
+
// evt.isCancel = true;
|
3858
|
+
// }
|
3859
|
+
// }
|
3860
|
+
// }, true);
|
3860
3861
|
this.addEvent('GotCursor', (evt) => {
|
3861
3862
|
const { startControl, startOffset } = evt.selectionState;
|
3862
3863
|
if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
|
@@ -4452,7 +4453,7 @@ class PSymbolElement extends LeafElement {
|
|
4452
4453
|
}
|
4453
4454
|
createRenderObject() {
|
4454
4455
|
const symbol = new PSymbolRenderObject(this);
|
4455
|
-
symbol.rect.height = this.defaultHeight;
|
4456
|
+
symbol.rect.height = Math.ceil(this.defaultHeight * TEXT_HEIGHT_FACTOR);
|
4456
4457
|
symbol.rect.width = 1;
|
4457
4458
|
return symbol;
|
4458
4459
|
}
|
@@ -4474,12 +4475,20 @@ class PSymbolRenderObject extends LeafRenderObject {
|
|
4474
4475
|
if (!event.options.showEnterSymbol || event.mode === 'print') {
|
4475
4476
|
return null;
|
4476
4477
|
}
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4478
|
+
const font = `14px 宋体`;
|
4479
|
+
const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(font);
|
4480
|
+
let y = this.rect.y;
|
4481
|
+
//基线处理
|
4482
|
+
y += actualFontBoundingBoxAscent ?? 0;
|
4483
|
+
//行高处理
|
4484
|
+
y += (this.rect.height - 14) / 2;
|
4485
|
+
return ElementUtil.createSvgText('↵', {
|
4486
|
+
'font-family': '宋体',
|
4487
|
+
'font-size': 14,
|
4480
4488
|
x: this.rect.x,
|
4481
|
-
y:
|
4482
|
-
fill: 'green'
|
4489
|
+
y: y,
|
4490
|
+
fill: 'green'
|
4491
|
+
});
|
4483
4492
|
}
|
4484
4493
|
//绘制段落符号
|
4485
4494
|
clone() {
|
@@ -8698,7 +8707,7 @@ class BreakElement extends LeafElement {
|
|
8698
8707
|
}
|
8699
8708
|
createRenderObject() {
|
8700
8709
|
const symbol = new BreakRenderObject(this);
|
8701
|
-
symbol.rect.height = 14;
|
8710
|
+
symbol.rect.height = Math.ceil(14 * TEXT_HEIGHT_FACTOR);
|
8702
8711
|
symbol.rect.width = 7;
|
8703
8712
|
return symbol;
|
8704
8713
|
}
|
@@ -8719,12 +8728,26 @@ class BreakRenderObject extends LeafRenderObject {
|
|
8719
8728
|
if (!event.options.showEnterSymbol || event.mode === 'print') {
|
8720
8729
|
return null;
|
8721
8730
|
}
|
8722
|
-
return ElementUtil.createSvgText('↓',
|
8723
|
-
|
8724
|
-
|
8725
|
-
|
8726
|
-
|
8727
|
-
|
8731
|
+
// return ElementUtil.createSvgText( '↓',{ 'dominant-baseline': 'hanging',
|
8732
|
+
// 'font-family': 'Courier',
|
8733
|
+
// 'font-size': this.rect.height,
|
8734
|
+
// x: this.rect.x + 4,
|
8735
|
+
// y: this.rect.y,
|
8736
|
+
// fill: 'green'});
|
8737
|
+
const font = `14px 宋体`;
|
8738
|
+
const actualFontBoundingBoxAscent = event.renderCtx.mainContext.getActualFontBoundingBoxAscent(font);
|
8739
|
+
let y = 0;
|
8740
|
+
//基线处理
|
8741
|
+
y += actualFontBoundingBoxAscent ?? 0;
|
8742
|
+
//行高处理
|
8743
|
+
y += (this.parent.rect.height - 14) / 2;
|
8744
|
+
return ElementUtil.createSvgText('↓', {
|
8745
|
+
'font-family': '宋体',
|
8746
|
+
'font-size': 14,
|
8747
|
+
x: this.rect.x,
|
8748
|
+
y: y,
|
8749
|
+
fill: 'green'
|
8750
|
+
});
|
8728
8751
|
}
|
8729
8752
|
clone() {
|
8730
8753
|
const render = new BreakRenderObject(this.element);
|
@@ -8770,13 +8793,15 @@ class DataElementGroupElement extends InlineGroupInputElement {
|
|
8770
8793
|
val += '';
|
8771
8794
|
}
|
8772
8795
|
if (val) {
|
8773
|
-
const items = val.split('
|
8796
|
+
const items = val.split('\n');
|
8774
8797
|
if (items.length) {
|
8775
8798
|
items.forEach((item, index) => {
|
8776
|
-
|
8777
|
-
|
8778
|
-
|
8779
|
-
|
8799
|
+
if (item) {
|
8800
|
+
const valueText = new TextGroupElement();
|
8801
|
+
this.props.valueTextProps.clone(valueText.props);
|
8802
|
+
valueText.text = item + '';
|
8803
|
+
this.addChild(valueText, this.length - 1);
|
8804
|
+
}
|
8780
8805
|
if (index < items.length - 1) {
|
8781
8806
|
const brElement = new BreakElement();
|
8782
8807
|
this.addChild(brElement, this.length - 1);
|
@@ -9172,13 +9197,15 @@ class DataElementText extends DataElementInlineGroup {
|
|
9172
9197
|
val += '';
|
9173
9198
|
}
|
9174
9199
|
if (val) {
|
9175
|
-
const items = val.split('
|
9200
|
+
const items = val.split('\n');
|
9176
9201
|
if (items.length) {
|
9177
9202
|
items.forEach((item, index) => {
|
9178
|
-
|
9179
|
-
|
9180
|
-
|
9181
|
-
|
9203
|
+
if (item) {
|
9204
|
+
const valueText = new TextGroupElement();
|
9205
|
+
this.props.valueTextProps.clone(valueText.props);
|
9206
|
+
valueText.text = item + '';
|
9207
|
+
this.addChild(valueText, this.length - 1);
|
9208
|
+
}
|
9182
9209
|
if (index < items.length - 1) {
|
9183
9210
|
const brElement = new BreakElement();
|
9184
9211
|
this.addChild(brElement, this.length - 1);
|
@@ -10855,9 +10882,22 @@ class ElementSerialize {
|
|
10855
10882
|
const { startCol, endCol } = tbRegion;
|
10856
10883
|
const cloneTb = ElementUtil.cloneRange(range, false, 'copy');
|
10857
10884
|
cloneTb.props.cols = cloneTb.props.cols.slice(startCol, endCol + 1);
|
10858
|
-
return cloneTb;
|
10885
|
+
return [cloneTb];
|
10859
10886
|
}
|
10860
|
-
|
10887
|
+
//元素全选的情况下
|
10888
|
+
// if (range.isFullSelected) {
|
10889
|
+
// const ele = ElementUtil.cloneRange(range, false, 'copy');
|
10890
|
+
// return ele ? [ele] : null;
|
10891
|
+
// }
|
10892
|
+
//元素部分选中的情况下,只获取选中的部分元素
|
10893
|
+
const selectedEle = range.selectedChildren.map(item => ElementUtil.cloneRange(item, false, 'copy'));
|
10894
|
+
const list = [];
|
10895
|
+
selectedEle.forEach(item => {
|
10896
|
+
if (item) {
|
10897
|
+
list.push(item);
|
10898
|
+
}
|
10899
|
+
});
|
10900
|
+
return list;
|
10861
10901
|
}
|
10862
10902
|
/**
|
10863
10903
|
* 选中的文本
|
@@ -10865,18 +10905,19 @@ class ElementSerialize {
|
|
10865
10905
|
* @param viewOptions
|
10866
10906
|
*/
|
10867
10907
|
static getSelectedText(ss, viewOptions) {
|
10868
|
-
const
|
10869
|
-
if (
|
10870
|
-
return this.serializeString(
|
10908
|
+
const selectedStructs = this.getSelectedStruct(ss, viewOptions);
|
10909
|
+
if (selectedStructs) {
|
10910
|
+
return selectedStructs.map(item => this.serializeString(item)).join('');
|
10871
10911
|
}
|
10872
10912
|
else {
|
10873
10913
|
return '';
|
10874
10914
|
}
|
10875
10915
|
}
|
10876
10916
|
static getSelectedJSON(ss, viewOptions) {
|
10877
|
-
const
|
10878
|
-
if (
|
10879
|
-
return JSON.stringify(this.serialize(
|
10917
|
+
const selectedStructs = this.getSelectedStruct(ss, viewOptions);
|
10918
|
+
if (selectedStructs) {
|
10919
|
+
//return JSON.stringify(this.serialize(selectedStructs, viewOptions));
|
10920
|
+
return JSON.stringify(selectedStructs.map(item => this.serialize(item, viewOptions)).filter(item => item));
|
10880
10921
|
}
|
10881
10922
|
else {
|
10882
10923
|
return '';
|
@@ -16793,7 +16834,7 @@ class DocumentEvent {
|
|
16793
16834
|
this.moveCursorToRightHandle(nextEle, ElementUtil.fixedOffset(nextEle, -1));
|
16794
16835
|
return;
|
16795
16836
|
}
|
16796
|
-
this.selectionState.resetRange(nextEle,
|
16837
|
+
this.selectionState.resetRange(nextEle, 0);
|
16797
16838
|
return;
|
16798
16839
|
}
|
16799
16840
|
}
|
@@ -17991,6 +18032,9 @@ class DocumentChange {
|
|
17991
18032
|
const { startControl } = this.selectionState;
|
17992
18033
|
const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
|
17993
18034
|
const breakPara = this.splitCurrentParagraph();
|
18035
|
+
if (!breakPara) {
|
18036
|
+
return;
|
18037
|
+
}
|
17994
18038
|
//选中的是一个元素
|
17995
18039
|
if (breakPara === paragraph) {
|
17996
18040
|
const clonePara = paragraph.clone(false);
|
@@ -18012,6 +18056,9 @@ class DocumentChange {
|
|
18012
18056
|
*/
|
18013
18057
|
insertLayoutContainer(ele) {
|
18014
18058
|
const breakPara = this.splitCurrentParagraph();
|
18059
|
+
if (!breakPara) {
|
18060
|
+
return;
|
18061
|
+
}
|
18015
18062
|
breakPara.parent.addChild(ele, breakPara.getIndex());
|
18016
18063
|
this.selectionState.resetRange(ele, 0);
|
18017
18064
|
}
|
@@ -18021,6 +18068,11 @@ class DocumentChange {
|
|
18021
18068
|
*/
|
18022
18069
|
splitCurrentParagraph() {
|
18023
18070
|
const { startControl, startOffset } = this.selectionState;
|
18071
|
+
//内联数据块不能拆分两部分
|
18072
|
+
if (!this.allowSplitParagraph()) {
|
18073
|
+
console.warn("内联数据块不能拆分!");
|
18074
|
+
return null;
|
18075
|
+
}
|
18024
18076
|
const paragraph = ElementUtil.getParentByType(startControl, ParagraphElement);
|
18025
18077
|
const paraContainer = paragraph.parent;
|
18026
18078
|
//如果选中的是段落第一个元素
|
@@ -18441,67 +18493,53 @@ class DocumentChange {
|
|
18441
18493
|
}
|
18442
18494
|
return;
|
18443
18495
|
}
|
18444
|
-
|
18445
|
-
|
18446
|
-
|
18496
|
+
let data = JSON.parse(pasteData.doc);
|
18497
|
+
const pasteEles = [];
|
18498
|
+
data = Array.isArray(data) ? data : [data];
|
18499
|
+
data.forEach(item => {
|
18500
|
+
const ele = this.eleReader.readElement(item);
|
18501
|
+
if (ele) {
|
18502
|
+
pasteEles.push(ele);
|
18503
|
+
}
|
18504
|
+
else {
|
18505
|
+
console.log('粘贴反序列化数据失败', item);
|
18506
|
+
}
|
18507
|
+
});
|
18508
|
+
if (!pasteEles.length) {
|
18447
18509
|
return;
|
18448
18510
|
}
|
18449
18511
|
//表单模式:如果复制的是单格式的文本,需要序列化为纯文本处理
|
18450
18512
|
if (this.viewOptions.docMode === DocMode.FormEdit) {
|
18451
|
-
const pasteString = ElementSerialize.serializeString(
|
18513
|
+
const pasteString = pasteEles.map(item => ElementSerialize.serializeString(item, { all: false })).join('');
|
18452
18514
|
if (pasteString) {
|
18453
18515
|
this.pastePlainText(pasteString);
|
18454
18516
|
}
|
18455
18517
|
return;
|
18456
18518
|
}
|
18457
|
-
|
18458
|
-
|
18459
|
-
|
18460
|
-
children.push(...ElementUtil.getChildrenElements(pasteElement));
|
18461
|
-
}
|
18462
|
-
else if (pasteElement instanceof InlineGroupElement) {
|
18463
|
-
//当前粘贴的元素为数据元,并且在数据元内部粘贴
|
18464
|
-
if (IsInSideDataElement(startControl, startOffset) && pasteElement instanceof DataElementInlineGroup) {
|
18465
|
-
const pasteChildren = pasteElement.getInnerItems().map(item => item.clone(true));
|
18466
|
-
children.push(...pasteChildren);
|
18467
|
-
}
|
18468
|
-
else {
|
18469
|
-
children.push(pasteElement);
|
18470
|
-
}
|
18471
|
-
}
|
18472
|
-
if (!children.length) {
|
18473
|
-
throw new Error('段落子元素为空');
|
18474
|
-
}
|
18475
|
-
const lastEle = this.insertElement(startControl, startOffset, children);
|
18476
|
-
this.selectionState.resetRange(lastEle, -1);
|
18477
|
-
return;
|
18519
|
+
//复制的内容为表格,且操作位于单元格内
|
18520
|
+
if (pasteEles[0] instanceof TableElement && ElementUtil.getParentByType(startControl, TableCellElement) && pasteEles.length === 1) {
|
18521
|
+
this.pasteTableToCell(pasteEles[0]);
|
18478
18522
|
}
|
18479
|
-
|
18523
|
+
//复制的为表格或者段落
|
18524
|
+
else if (pasteEles[0] instanceof BlockContainerElement || pasteEles[0] instanceof ParagraphElement) {
|
18480
18525
|
const children = [];
|
18481
|
-
|
18482
|
-
children.push(pasteElement);
|
18483
|
-
if (ElementUtil.getParentByType(startControl, TableCellElement)) {
|
18484
|
-
this.pasteTableToCell(pasteElement);
|
18485
|
-
return;
|
18486
|
-
}
|
18487
|
-
}
|
18488
|
-
else {
|
18489
|
-
children.push(...ElementUtil.getChildrenElements(pasteElement));
|
18490
|
-
}
|
18491
|
-
//复制的内容全部为段落,执行黏贴操作
|
18492
|
-
// if (children.every(item => item instanceof ParagraphElement)) {
|
18493
|
-
// const targetParagraph = this.splitCurrentParagraph();
|
18494
|
-
// children.forEach((item, i) => {
|
18495
|
-
// targetParagraph.parent.addChild(item, targetParagraph.getIndex());
|
18496
|
-
// });
|
18497
|
-
// this.selectionState.resetRange(children[children.length - 1], -1);
|
18498
|
-
// }
|
18526
|
+
children.push(...pasteEles);
|
18499
18527
|
const targetParagraph = this.splitCurrentParagraph();
|
18528
|
+
if (!targetParagraph) {
|
18529
|
+
return;
|
18530
|
+
}
|
18500
18531
|
children.forEach((item, i) => {
|
18501
18532
|
targetParagraph.parent.addChild(item, targetParagraph.getIndex());
|
18502
18533
|
});
|
18503
18534
|
this.selectionState.resetRange(children[children.length - 1], -1);
|
18504
18535
|
}
|
18536
|
+
//符合段落内的元素约定
|
18537
|
+
else {
|
18538
|
+
const children = [];
|
18539
|
+
children.push(...pasteEles);
|
18540
|
+
const lastEle = this.insertElement(startControl, startOffset, children);
|
18541
|
+
this.selectionState.resetRange(lastEle, -1);
|
18542
|
+
}
|
18505
18543
|
}
|
18506
18544
|
/**
|
18507
18545
|
* 复制单元格向另一个单元格粘贴
|
@@ -18597,6 +18635,9 @@ class DocumentChange {
|
|
18597
18635
|
}
|
18598
18636
|
else {
|
18599
18637
|
const breakPara = this.splitCurrentParagraph();
|
18638
|
+
if (!breakPara) {
|
18639
|
+
return;
|
18640
|
+
}
|
18600
18641
|
for (let i = 0; i < textItems.length; i++) {
|
18601
18642
|
const newPara = breakPara.clone(false);
|
18602
18643
|
const inputTextProps = this.getDefaultTextPropsByOptions();
|
@@ -18608,6 +18649,20 @@ class DocumentChange {
|
|
18608
18649
|
this.selectionState.resetRange(breakPara, 0);
|
18609
18650
|
}
|
18610
18651
|
}
|
18652
|
+
/**
|
18653
|
+
* 当前光标位置是否允许分割生成两个段落
|
18654
|
+
*/
|
18655
|
+
allowSplitParagraph(target) {
|
18656
|
+
if (!target) {
|
18657
|
+
target = this.selectionState;
|
18658
|
+
}
|
18659
|
+
const { startControl, startOffset } = target;
|
18660
|
+
//内联数据块不能拆分两部分
|
18661
|
+
if (IsInSideInlineGroupInputElement(startControl, startOffset)) {
|
18662
|
+
return false;
|
18663
|
+
}
|
18664
|
+
return true;
|
18665
|
+
}
|
18611
18666
|
/**
|
18612
18667
|
* 向当前光标追加文本
|
18613
18668
|
* @param appendStr
|
@@ -21653,8 +21708,13 @@ class DocEditor {
|
|
21653
21708
|
return ElementSerialize.getSelectedJSON(this.selectionState, this.viewOptions);
|
21654
21709
|
}
|
21655
21710
|
getSelectedText() {
|
21656
|
-
const
|
21657
|
-
|
21711
|
+
const selectedEles = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
|
21712
|
+
if (!selectedEles) {
|
21713
|
+
return '';
|
21714
|
+
}
|
21715
|
+
return selectedEles.map(ele => {
|
21716
|
+
return ElementSerialize.serializeString(ele);
|
21717
|
+
}).join('');
|
21658
21718
|
}
|
21659
21719
|
/**
|
21660
21720
|
* 执行编辑器内部复制事件
|
@@ -22285,7 +22345,7 @@ class DocEditor {
|
|
22285
22345
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
22286
22346
|
}
|
22287
22347
|
version() {
|
22288
|
-
return "2.2.
|
22348
|
+
return "2.2.17";
|
22289
22349
|
}
|
22290
22350
|
switchPageHeaderEditor() {
|
22291
22351
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
@@ -22599,6 +22659,39 @@ class DocEditor {
|
|
22599
22659
|
}
|
22600
22660
|
return res;
|
22601
22661
|
}
|
22662
|
+
/**
|
22663
|
+
* 返回当前光标处是否允许截断段落生成新的段落
|
22664
|
+
* @returns
|
22665
|
+
*/
|
22666
|
+
allowSplitParagraph() {
|
22667
|
+
return this.documentChange.allowSplitParagraph();
|
22668
|
+
}
|
22669
|
+
/**
|
22670
|
+
* 设置元素属性(attribute)
|
22671
|
+
* @param ele
|
22672
|
+
* @param attr
|
22673
|
+
* @param value
|
22674
|
+
*/
|
22675
|
+
setEleAttribute(ele, attr, value) {
|
22676
|
+
ElementUtil.setEleAttribute(ele, attr, value);
|
22677
|
+
}
|
22678
|
+
/**
|
22679
|
+
* 获取元素属性(attribute)
|
22680
|
+
* @param ele
|
22681
|
+
* @param attr
|
22682
|
+
* @returns
|
22683
|
+
*/
|
22684
|
+
getEleAttribute(ele, attr) {
|
22685
|
+
return ElementUtil.getEleAttribute(ele, attr);
|
22686
|
+
}
|
22687
|
+
/**
|
22688
|
+
* 删除元素属性(attribute)
|
22689
|
+
* @param ele
|
22690
|
+
* @param attr
|
22691
|
+
*/
|
22692
|
+
removeEleAttribute(ele, attr) {
|
22693
|
+
ElementUtil.removeEleAttribute(ele, attr);
|
22694
|
+
}
|
22602
22695
|
}
|
22603
22696
|
|
22604
22697
|
/**
|