@hailin-zheng/editor-core 1.1.10 → 1.1.12
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/index-cjs.js +105 -25
- package/index-cjs.js.map +1 -1
- package/index.js +105 -25
- 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;
|
@@ -9712,6 +9730,7 @@ class SelectionState {
|
|
9712
9730
|
selectedRange;
|
9713
9731
|
editable = true;
|
9714
9732
|
renderContainer;
|
9733
|
+
//光标所在的位置,当前位置时相对文档的位置,而非DOM页面中的位置
|
9715
9734
|
cursorPos;
|
9716
9735
|
//当前选区的上下文是否支持留痕修改
|
9717
9736
|
enableTrackChanges = false;
|
@@ -11734,8 +11753,7 @@ class DocumentArrange {
|
|
11734
11753
|
item.rect.y = bodyInnerLimitRect.height + item.margin.top;
|
11735
11754
|
pageBodyRender.addChild(item);
|
11736
11755
|
bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
|
11737
|
-
|
11738
|
-
//bodyInnerLimitRect.prevMargin = item.margin.bottom;
|
11756
|
+
ElementUtil.setHorizontalAlign(item, bodyInnerLimitRect);
|
11739
11757
|
ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
|
11740
11758
|
};
|
11741
11759
|
for (let i = 0; i < doc.bodyElement.length; i++) {
|
@@ -13696,6 +13714,9 @@ class DocumentEvent {
|
|
13696
13714
|
this.editor.addEventListener('contextmenu', evt => {
|
13697
13715
|
this.contextMenu.next(evt.sourceEvt);
|
13698
13716
|
});
|
13717
|
+
this.editor.addEventListener('keydown', evt => {
|
13718
|
+
this.onKeydown(evt.sourceEvt);
|
13719
|
+
});
|
13699
13720
|
this.documentInput.onLeftEvent.subscribe(() => {
|
13700
13721
|
this.moveCursorToLeft();
|
13701
13722
|
});
|
@@ -14129,6 +14150,10 @@ class DocumentEvent {
|
|
14129
14150
|
mouseDblClickHandle(nodeEvt) {
|
14130
14151
|
const docEvent = new MouseElementEvent(this.docCtx);
|
14131
14152
|
this.setEventViewPos(nodeEvt.sourceHitPos, docEvent);
|
14153
|
+
const hitInfo = this.getHitInfo(docEvent);
|
14154
|
+
if (!hitInfo) {
|
14155
|
+
return;
|
14156
|
+
}
|
14132
14157
|
//需要先处理是否开启页眉页脚编辑功能
|
14133
14158
|
const hitRegion = this.getHitRegion(docEvent);
|
14134
14159
|
if ((hitRegion === 'footer' || hitRegion === 'header') && !this.docCtx.document.headerEditState) {
|
@@ -14139,7 +14164,7 @@ class DocumentEvent {
|
|
14139
14164
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
14140
14165
|
return;
|
14141
14166
|
}
|
14142
|
-
const hitInfo = this.getHitInfo(docEvent);
|
14167
|
+
//const hitInfo = this.getHitInfo(docEvent);
|
14143
14168
|
if (hitInfo) {
|
14144
14169
|
docEvent.source = hitInfo.element;
|
14145
14170
|
docEvent.sourceRender = hitInfo.render;
|
@@ -14708,7 +14733,7 @@ class DocumentEvent {
|
|
14708
14733
|
return;
|
14709
14734
|
}
|
14710
14735
|
let { x, y } = this.selectionState.cursorPos;
|
14711
|
-
y -= this.viewOptions.pageOffset.y;
|
14736
|
+
//y -= this.viewOptions.pageOffset.y;
|
14712
14737
|
for (let i = 0; i < 50; i++) {
|
14713
14738
|
const docEvent = new MouseElementEvent(this.docCtx);
|
14714
14739
|
docEvent.globalX = x;
|
@@ -14749,9 +14774,8 @@ class DocumentEvent {
|
|
14749
14774
|
}
|
14750
14775
|
/**
|
14751
14776
|
* 获取点击的文档区域
|
14752
|
-
* @param docRender
|
14753
|
-
* @param pos
|
14754
14777
|
* @returns
|
14778
|
+
* @param docEvent
|
14755
14779
|
*/
|
14756
14780
|
getHitRegion(docEvent) {
|
14757
14781
|
const hitDocInfo = this.getHitDocPage(docEvent);
|
@@ -14782,6 +14806,30 @@ class DocumentEvent {
|
|
14782
14806
|
return null;
|
14783
14807
|
}
|
14784
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
|
+
}
|
14785
14833
|
}
|
14786
14834
|
|
14787
14835
|
/**
|
@@ -14893,7 +14941,6 @@ class DocumentInput {
|
|
14893
14941
|
* @param visibility
|
14894
14942
|
*/
|
14895
14943
|
setCursorVisibility(visibility) {
|
14896
|
-
//this.cursorWrapper.style.display = visibility ? 'block' : 'none';
|
14897
14944
|
if (visibility) {
|
14898
14945
|
this.setInputFocus(true);
|
14899
14946
|
}
|
@@ -18075,7 +18122,7 @@ class NodeEvent {
|
|
18075
18122
|
this.canvas = canvas;
|
18076
18123
|
this.setAppState(null);
|
18077
18124
|
canvas.addEventListener('mousedown', evt => {
|
18078
|
-
evt.preventDefault();
|
18125
|
+
//evt.preventDefault();
|
18079
18126
|
this.setActiveAppContext(() => this.onMousedownHandler(evt));
|
18080
18127
|
});
|
18081
18128
|
canvas.addEventListener('mousemove', evt => {
|
@@ -18097,6 +18144,9 @@ class NodeEvent {
|
|
18097
18144
|
canvas.addEventListener('contextmenu', evt => {
|
18098
18145
|
this.setActiveAppContext(() => this.onContextMenuHandler(evt));
|
18099
18146
|
});
|
18147
|
+
canvas.addEventListener('keydown', evt => {
|
18148
|
+
this.setActiveAppContext(() => this.onKeydownHandler(evt));
|
18149
|
+
});
|
18100
18150
|
this.root.addEventListener('preGotFocus', (evt) => {
|
18101
18151
|
this.invokeNodeFocusedEvent(this.prevNode, this.prevFocusNodes, evt.source);
|
18102
18152
|
}, true);
|
@@ -18393,6 +18443,30 @@ class NodeEvent {
|
|
18393
18443
|
};
|
18394
18444
|
invokeEvent(onContextMenuEvent, 'contextmenu', this.appState.sourceNode);
|
18395
18445
|
}
|
18446
|
+
onCopyHandler(evt) {
|
18447
|
+
if (this.appState.sourceNode) {
|
18448
|
+
const onCopyEvent = {
|
18449
|
+
source: this.appState.sourceNode,
|
18450
|
+
cancelable: true,
|
18451
|
+
isCancel: false,
|
18452
|
+
target: this.appState.sourceNode,
|
18453
|
+
sourceEvt: evt
|
18454
|
+
};
|
18455
|
+
invokeEvent(onCopyEvent, 'copy', this.appState.sourceNode);
|
18456
|
+
}
|
18457
|
+
}
|
18458
|
+
onKeydownHandler(evt) {
|
18459
|
+
if (this.appState.sourceNode) {
|
18460
|
+
const onKeydownEvent = {
|
18461
|
+
source: this.appState.sourceNode,
|
18462
|
+
cancelable: true,
|
18463
|
+
isCancel: false,
|
18464
|
+
target: this.appState.sourceNode,
|
18465
|
+
sourceEvt: evt
|
18466
|
+
};
|
18467
|
+
invokeEvent(onKeydownEvent, 'keydown', this.appState.sourceNode);
|
18468
|
+
}
|
18469
|
+
}
|
18396
18470
|
getHitNode(hitPos, parentPos) {
|
18397
18471
|
if (this.root.popNodes.length) {
|
18398
18472
|
for (let i = this.root.popNodes.length - 1; i >= 0; i--) {
|
@@ -20387,8 +20461,6 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20387
20461
|
const { startRegion, hitDocIndex } = this.documentEvent.startHitInfo;
|
20388
20462
|
const cursorPos = DocumentCursor.getElementCursorPos(startControl, startOffset, startRegion, hitDocIndex);
|
20389
20463
|
this.docCtx.cursorRect = ElementUtil.cloneRect(cursorPos.rect);
|
20390
|
-
this.transToAbsolutePos(ElementUtil.cloneRect(cursorPos.rect));
|
20391
|
-
//this.documentInput.setCursorPosition(abPos);
|
20392
20464
|
const focusEvent = {
|
20393
20465
|
target: this,
|
20394
20466
|
source: this,
|
@@ -20846,6 +20918,13 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20846
20918
|
const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
|
20847
20919
|
return ElementSerialize.serializeString(copySerializeStr);
|
20848
20920
|
}
|
20921
|
+
/**
|
20922
|
+
* 执行编辑器内部复制事件
|
20923
|
+
* @param evt
|
20924
|
+
*/
|
20925
|
+
execCopy(evt) {
|
20926
|
+
this.documentChange.onCopy(evt);
|
20927
|
+
}
|
20849
20928
|
/**
|
20850
20929
|
* 设置纸张方向
|
20851
20930
|
* @param orientation
|
@@ -21145,11 +21224,12 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
21145
21224
|
drawCaret(e) {
|
21146
21225
|
const appCtx = getCurrentActiveAppContext();
|
21147
21226
|
if (appCtx) {
|
21148
|
-
|
21227
|
+
let caretPos = this.selectionState.cursorPos;
|
21149
21228
|
if (!caretPos) {
|
21150
21229
|
appCtx.root.hiddenInput();
|
21151
21230
|
return;
|
21152
21231
|
}
|
21232
|
+
caretPos = ElementUtil.cloneRect(caretPos);
|
21153
21233
|
caretPos.x += this.border + this.padding + e.renderPos.x;
|
21154
21234
|
caretPos.y += this.border + this.padding + e.renderPos.y;
|
21155
21235
|
appCtx.root.setInputPosition(caretPos);
|