@hailin-zheng/editor-core 1.1.11 → 1.1.13
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/controls/NodeEvent.d.ts +2 -0
- package/controls/SurfaceView.d.ts +1 -1
- package/index-cjs.js +114 -24
- package/index-cjs.js.map +1 -1
- package/index.js +114 -24
- package/index.js.map +1 -1
- package/med_editor/framework/document-event.d.ts +2 -2
- package/med_editor/framework/element-props.d.ts +1 -1
- package/med_editor/framework/element-util.d.ts +4 -3
- package/med_editor/framework/render-context.d.ts +4 -0
- package/med_editor/texteditor.d.ts +5 -0
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1929,7 +1929,7 @@ class TableRowProps extends INotifyPropertyChanged {
|
|
1929
1929
|
class TableProps extends INotifyPropertyChanged {
|
1930
1930
|
id;
|
1931
1931
|
cols;
|
1932
|
-
|
1932
|
+
align;
|
1933
1933
|
border = 'all';
|
1934
1934
|
allowBreakRow;
|
1935
1935
|
clone(dest) {
|
@@ -1937,7 +1937,7 @@ class TableProps extends INotifyPropertyChanged {
|
|
1937
1937
|
super.cloneAttachedProperty(clone);
|
1938
1938
|
clone.id = this.id;
|
1939
1939
|
clone.cols = [...this.cols];
|
1940
|
-
clone.
|
1940
|
+
clone.align = this.align;
|
1941
1941
|
clone.border = this.border;
|
1942
1942
|
return clone;
|
1943
1943
|
}
|
@@ -1945,7 +1945,7 @@ class TableProps extends INotifyPropertyChanged {
|
|
1945
1945
|
return {
|
1946
1946
|
id: this.id,
|
1947
1947
|
cols: this.cols,
|
1948
|
-
alignment: this.
|
1948
|
+
alignment: this.align,
|
1949
1949
|
border: this.border
|
1950
1950
|
};
|
1951
1951
|
}
|
@@ -3173,7 +3173,7 @@ class DataElementRenderObject extends InlineGroupRenderObject {
|
|
3173
3173
|
textProps.fontSize = 16;
|
3174
3174
|
textProps.fontName = viewOptions.defaultFontName;
|
3175
3175
|
textProps.color = '#fff';
|
3176
|
-
const titleWidth = render.contentContext.
|
3176
|
+
const titleWidth = render.contentContext.measureText2(caption, textProps);
|
3177
3177
|
const x = position.x;
|
3178
3178
|
const y = position.y - 20;
|
3179
3179
|
render.contentContext.fillRect(x, y, titleWidth + 10, 20, 'blue');
|
@@ -4811,7 +4811,9 @@ class TableElement extends BlockContainerElement {
|
|
4811
4811
|
return clone;
|
4812
4812
|
}
|
4813
4813
|
createRenderObject() {
|
4814
|
-
|
4814
|
+
const render = new TableRenderObject(this);
|
4815
|
+
render.rect.width = this.props.cols.reduce((prev, curr) => curr + prev, 0);
|
4816
|
+
return render;
|
4815
4817
|
}
|
4816
4818
|
beginMeasure(data) {
|
4817
4819
|
super.beginMeasure(data);
|
@@ -4900,7 +4902,7 @@ class TableFactory extends ElementFactory {
|
|
4900
4902
|
tbProps.border = props.border || 'all';
|
4901
4903
|
tbProps.cols = [];
|
4902
4904
|
tbProps.id = props.id;
|
4903
|
-
tbProps.
|
4905
|
+
tbProps.align = props.align;
|
4904
4906
|
for (const col of cols) {
|
4905
4907
|
if (typeof col === 'object') {
|
4906
4908
|
tbProps.cols.push(col.width);
|
@@ -5057,7 +5059,7 @@ class TextGroupElement extends LeafElement {
|
|
5057
5059
|
return this.textMeasures.map(item => item.char).join('');
|
5058
5060
|
}
|
5059
5061
|
createRenderObject(data) {
|
5060
|
-
if (!this.isMeasure || this.modifyFlag !== ModifyFlag$1.None) {
|
5062
|
+
if (!this.isMeasure || this.modifyFlag !== ModifyFlag$1.None || !this.cacheRender) {
|
5061
5063
|
data.renderCtx.contentContext.measureTextUnits(this.textMeasures, this.props);
|
5062
5064
|
this.isMeasure = true;
|
5063
5065
|
}
|
@@ -5553,7 +5555,7 @@ class ElementUtil {
|
|
5553
5555
|
line.rect.x = innerRect.x;
|
5554
5556
|
}
|
5555
5557
|
line.rect.y = innerRect.height + innerRect.y + line.margin.top;
|
5556
|
-
|
5558
|
+
this.setHorizontalAlign(line, innerRect);
|
5557
5559
|
innerRect.height += line.rect.height + line.margin.top + line.margin.bottom;
|
5558
5560
|
}
|
5559
5561
|
render.updateRenderHeight(innerRect);
|
@@ -5561,8 +5563,7 @@ class ElementUtil {
|
|
5561
5563
|
}
|
5562
5564
|
static remeasureTableRow(rowRender, foreceColIndex = -1) {
|
5563
5565
|
const rowEle = rowRender.element;
|
5564
|
-
|
5565
|
-
let maxCellHeight = rowMinHeight;
|
5566
|
+
let maxCellHeight = rowEle.props.minHeight > 19 ? rowEle.props.minHeight : 19;
|
5566
5567
|
//限制行最小高度
|
5567
5568
|
maxCellHeight = maxCellHeight < 19 ? 19 : maxCellHeight;
|
5568
5569
|
//获取行内非纵向合并单元格的最高单元格高度
|
@@ -5644,11 +5645,24 @@ class ElementUtil {
|
|
5644
5645
|
}
|
5645
5646
|
}
|
5646
5647
|
/**
|
5647
|
-
*
|
5648
|
-
* @param tbRender
|
5648
|
+
* 设置原色横向排列方式
|
5649
5649
|
* @private
|
5650
|
-
|
5651
|
-
|
5650
|
+
* @param render
|
5651
|
+
* @param limitRect
|
5652
|
+
*/
|
5653
|
+
static setHorizontalAlign(render, limitRect) {
|
5654
|
+
if (render.element && render.element.props && render.element.props.align) {
|
5655
|
+
const align = render.element.props.align;
|
5656
|
+
if (align) {
|
5657
|
+
const remainSpace = limitRect.width - render.rect.width;
|
5658
|
+
if (align === 'center') {
|
5659
|
+
render.rect.x = Math.floor(remainSpace / 2);
|
5660
|
+
}
|
5661
|
+
else if (align === 'end') {
|
5662
|
+
render.rect.x = remainSpace;
|
5663
|
+
}
|
5664
|
+
}
|
5665
|
+
}
|
5652
5666
|
// const {alignment} = tbRender.element.props;
|
5653
5667
|
// if (!alignment) {
|
5654
5668
|
// return;
|
@@ -7061,6 +7075,10 @@ class PaintContent {
|
|
7061
7075
|
const textMeasure = this.ctx.measureText(text);
|
7062
7076
|
return { width: textMeasure.width, height: textProps.fontSize };
|
7063
7077
|
}
|
7078
|
+
measureText2(text, font) {
|
7079
|
+
this.ctx.font = font.fontSize + 'px ' + font.fontName;
|
7080
|
+
return this.ctx.measureText(text).width;
|
7081
|
+
}
|
7064
7082
|
measureTextUnits(units, textProps) {
|
7065
7083
|
this.ctx.font = textProps.getFont();
|
7066
7084
|
const letterSpace = textProps.letterSpace ?? 0;
|
@@ -11735,8 +11753,7 @@ class DocumentArrange {
|
|
11735
11753
|
item.rect.y = bodyInnerLimitRect.height + item.margin.top;
|
11736
11754
|
pageBodyRender.addChild(item);
|
11737
11755
|
bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
|
11738
|
-
|
11739
|
-
//bodyInnerLimitRect.prevMargin = item.margin.bottom;
|
11756
|
+
ElementUtil.setHorizontalAlign(item, bodyInnerLimitRect);
|
11740
11757
|
ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
|
11741
11758
|
};
|
11742
11759
|
for (let i = 0; i < doc.bodyElement.length; i++) {
|
@@ -13697,6 +13714,9 @@ class DocumentEvent {
|
|
13697
13714
|
this.editor.addEventListener('contextmenu', evt => {
|
13698
13715
|
this.contextMenu.next(evt.sourceEvt);
|
13699
13716
|
});
|
13717
|
+
this.editor.addEventListener('keydown', evt => {
|
13718
|
+
this.onKeydown(evt.sourceEvt);
|
13719
|
+
});
|
13700
13720
|
this.documentInput.onLeftEvent.subscribe(() => {
|
13701
13721
|
this.moveCursorToLeft();
|
13702
13722
|
});
|
@@ -14130,6 +14150,10 @@ class DocumentEvent {
|
|
14130
14150
|
mouseDblClickHandle(nodeEvt) {
|
14131
14151
|
const docEvent = new MouseElementEvent(this.docCtx);
|
14132
14152
|
this.setEventViewPos(nodeEvt.sourceHitPos, docEvent);
|
14153
|
+
const hitInfo = this.getHitInfo(docEvent);
|
14154
|
+
if (!hitInfo) {
|
14155
|
+
return;
|
14156
|
+
}
|
14133
14157
|
//需要先处理是否开启页眉页脚编辑功能
|
14134
14158
|
const hitRegion = this.getHitRegion(docEvent);
|
14135
14159
|
if ((hitRegion === 'footer' || hitRegion === 'header') && !this.docCtx.document.headerEditState) {
|
@@ -14140,7 +14164,7 @@ class DocumentEvent {
|
|
14140
14164
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
14141
14165
|
return;
|
14142
14166
|
}
|
14143
|
-
const hitInfo = this.getHitInfo(docEvent);
|
14167
|
+
//const hitInfo = this.getHitInfo(docEvent);
|
14144
14168
|
if (hitInfo) {
|
14145
14169
|
docEvent.source = hitInfo.element;
|
14146
14170
|
docEvent.sourceRender = hitInfo.render;
|
@@ -14750,9 +14774,8 @@ class DocumentEvent {
|
|
14750
14774
|
}
|
14751
14775
|
/**
|
14752
14776
|
* 获取点击的文档区域
|
14753
|
-
* @param docRender
|
14754
|
-
* @param pos
|
14755
14777
|
* @returns
|
14778
|
+
* @param docEvent
|
14756
14779
|
*/
|
14757
14780
|
getHitRegion(docEvent) {
|
14758
14781
|
const hitDocInfo = this.getHitDocPage(docEvent);
|
@@ -14783,6 +14806,30 @@ class DocumentEvent {
|
|
14783
14806
|
return null;
|
14784
14807
|
}
|
14785
14808
|
}
|
14809
|
+
onKeydown(evt) {
|
14810
|
+
const copy = () => {
|
14811
|
+
const input = document.createElement('input');
|
14812
|
+
document.body.appendChild(input);
|
14813
|
+
input.select();
|
14814
|
+
input.focus();
|
14815
|
+
input.addEventListener('copy', evt2 => {
|
14816
|
+
document.body.removeChild(input);
|
14817
|
+
const execCopy = this.editor['execCopy'];
|
14818
|
+
execCopy.call(this.editor, evt2);
|
14819
|
+
});
|
14820
|
+
document.execCommand('copy');
|
14821
|
+
};
|
14822
|
+
if (navigator.appVersion.indexOf('Mac') >= 0) {
|
14823
|
+
if (evt.metaKey && evt.keyCode === 67) {
|
14824
|
+
copy();
|
14825
|
+
}
|
14826
|
+
}
|
14827
|
+
else {
|
14828
|
+
if (evt.ctrlKey && evt.keyCode === 67) {
|
14829
|
+
copy();
|
14830
|
+
}
|
14831
|
+
}
|
14832
|
+
}
|
14786
14833
|
}
|
14787
14834
|
|
14788
14835
|
/**
|
@@ -16896,6 +16943,9 @@ class ElementTrackManage {
|
|
16896
16943
|
* 执行撤销
|
16897
16944
|
*/
|
16898
16945
|
undo() {
|
16946
|
+
if (!this.canUndo) {
|
16947
|
+
return;
|
16948
|
+
}
|
16899
16949
|
suppressTracking(() => {
|
16900
16950
|
this.index--;
|
16901
16951
|
this.executeCommand('undo');
|
@@ -16917,6 +16967,9 @@ class ElementTrackManage {
|
|
16917
16967
|
* 执行重做
|
16918
16968
|
*/
|
16919
16969
|
redo() {
|
16970
|
+
if (!this.canRedo) {
|
16971
|
+
return;
|
16972
|
+
}
|
16920
16973
|
suppressTracking(() => {
|
16921
16974
|
this.executeCommand('redo');
|
16922
16975
|
this.index++;
|
@@ -18075,7 +18128,7 @@ class NodeEvent {
|
|
18075
18128
|
this.canvas = canvas;
|
18076
18129
|
this.setAppState(null);
|
18077
18130
|
canvas.addEventListener('mousedown', evt => {
|
18078
|
-
evt.preventDefault();
|
18131
|
+
//evt.preventDefault();
|
18079
18132
|
this.setActiveAppContext(() => this.onMousedownHandler(evt));
|
18080
18133
|
});
|
18081
18134
|
canvas.addEventListener('mousemove', evt => {
|
@@ -18091,6 +18144,9 @@ class NodeEvent {
|
|
18091
18144
|
canvas.addEventListener('wheel', evt => {
|
18092
18145
|
this.setActiveAppContext(() => this.onWheelHandler(evt));
|
18093
18146
|
});
|
18147
|
+
canvas.addEventListener('click', evt => {
|
18148
|
+
this.root.setInputFocus(true);
|
18149
|
+
});
|
18094
18150
|
canvas.addEventListener('dblclick', evt => {
|
18095
18151
|
this.setActiveAppContext(() => this.onDblClickHandler(evt));
|
18096
18152
|
});
|
@@ -18393,6 +18449,30 @@ class NodeEvent {
|
|
18393
18449
|
};
|
18394
18450
|
invokeEvent(onContextMenuEvent, 'contextmenu', this.appState.sourceNode);
|
18395
18451
|
}
|
18452
|
+
onCopyHandler(evt) {
|
18453
|
+
if (this.appState.sourceNode) {
|
18454
|
+
const onCopyEvent = {
|
18455
|
+
source: this.appState.sourceNode,
|
18456
|
+
cancelable: true,
|
18457
|
+
isCancel: false,
|
18458
|
+
target: this.appState.sourceNode,
|
18459
|
+
sourceEvt: evt
|
18460
|
+
};
|
18461
|
+
invokeEvent(onCopyEvent, 'copy', this.appState.sourceNode);
|
18462
|
+
}
|
18463
|
+
}
|
18464
|
+
onKeydownHandler(evt) {
|
18465
|
+
if (this.appState.sourceNode) {
|
18466
|
+
const onKeydownEvent = {
|
18467
|
+
source: this.appState.sourceNode,
|
18468
|
+
cancelable: true,
|
18469
|
+
isCancel: false,
|
18470
|
+
target: this.appState.sourceNode,
|
18471
|
+
sourceEvt: evt
|
18472
|
+
};
|
18473
|
+
invokeEvent(onKeydownEvent, 'keydown', this.appState.sourceNode);
|
18474
|
+
}
|
18475
|
+
}
|
18396
18476
|
getHitNode(hitPos, parentPos) {
|
18397
18477
|
if (this.root.popNodes.length) {
|
18398
18478
|
for (let i = this.root.popNodes.length - 1; i >= 0; i--) {
|
@@ -18942,6 +19022,7 @@ class SurfaceView extends NodeItems {
|
|
18942
19022
|
this.invokeKeydown(evt);
|
18943
19023
|
});
|
18944
19024
|
this.input.addEventListener('copy', evt => {
|
19025
|
+
console.log('copy了');
|
18945
19026
|
this.invokeClipboardEvent(evt, 'copy');
|
18946
19027
|
});
|
18947
19028
|
this.input.addEventListener('paste', evt => {
|
@@ -19000,6 +19081,7 @@ class SurfaceView extends NodeItems {
|
|
19000
19081
|
return;
|
19001
19082
|
}
|
19002
19083
|
this.input.style.display = '';
|
19084
|
+
this.input.readOnly = false;
|
19003
19085
|
const left = Math.floor(x) + 'px';
|
19004
19086
|
const top = Math.floor(y) + 'px';
|
19005
19087
|
if (left !== this.input.style.left || top !== this.input.style.top) {
|
@@ -19013,9 +19095,10 @@ class SurfaceView extends NodeItems {
|
|
19013
19095
|
state ? this.input.focus() : this.input.blur();
|
19014
19096
|
}
|
19015
19097
|
hiddenInput() {
|
19016
|
-
this.input.style.display = 'none';
|
19017
|
-
this.input.style.left = '
|
19018
|
-
this.input.style.top = '
|
19098
|
+
//this.input.style.display = 'none';
|
19099
|
+
this.input.style.left = '-2px';
|
19100
|
+
this.input.style.top = '-2px';
|
19101
|
+
this.input.readOnly = true;
|
19019
19102
|
}
|
19020
19103
|
endInput() {
|
19021
19104
|
}
|
@@ -20379,7 +20462,7 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20379
20462
|
*/
|
20380
20463
|
setCursor() {
|
20381
20464
|
const { startControl, startOffset } = this.selectionState;
|
20382
|
-
if (!this.canSetCursor()) {
|
20465
|
+
if (!this.canSetCursor() || !this.documentEvent.startHitInfo) {
|
20383
20466
|
this.selectionState.editable = false;
|
20384
20467
|
this.documentInput.setCursorVisibility(false);
|
20385
20468
|
return false;
|
@@ -20844,6 +20927,13 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20844
20927
|
const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
|
20845
20928
|
return ElementSerialize.serializeString(copySerializeStr);
|
20846
20929
|
}
|
20930
|
+
/**
|
20931
|
+
* 执行编辑器内部复制事件
|
20932
|
+
* @param evt
|
20933
|
+
*/
|
20934
|
+
execCopy(evt) {
|
20935
|
+
this.documentChange.onCopy(evt);
|
20936
|
+
}
|
20847
20937
|
/**
|
20848
20938
|
* 设置纸张方向
|
20849
20939
|
* @param orientation
|