@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/controls/NodeEvent.d.ts
CHANGED
@@ -26,6 +26,8 @@ export declare class NodeEvent {
|
|
26
26
|
*/
|
27
27
|
onWheelHandler(evt: WheelEvent): void;
|
28
28
|
onContextMenuHandler(evt: MouseEvent): void;
|
29
|
+
onCopyHandler(evt: ClipboardEvent): void;
|
30
|
+
onKeydownHandler(evt: KeyboardEvent): void;
|
29
31
|
getHitNode(hitPos: Position, parentPos: Position): IHitInfo | null;
|
30
32
|
getMouseHitNode(node: NodeCore, hitPos: Position, parentPos: Position): IHitInfo | null;
|
31
33
|
invokeNodeFocusedEvent(prevNode: NodeCore | null, prevParents: Array<NodeCore>, currNode: NodeCore | null): void;
|
@@ -36,7 +36,7 @@ export declare class SurfaceView extends NodeItems {
|
|
36
36
|
invokeInput(data: string): void;
|
37
37
|
invokeKeydown(evt: KeyboardEvent): void;
|
38
38
|
setInputPosition({ x, y, height }: Omit<Rect, 'width'>): void;
|
39
|
-
|
39
|
+
setInputFocus(state?: boolean): void;
|
40
40
|
hiddenInput(): void;
|
41
41
|
endInput(): void;
|
42
42
|
}
|
package/index-cjs.js
CHANGED
@@ -1958,7 +1958,7 @@ class TableRowProps extends INotifyPropertyChanged {
|
|
1958
1958
|
class TableProps extends INotifyPropertyChanged {
|
1959
1959
|
id;
|
1960
1960
|
cols;
|
1961
|
-
|
1961
|
+
align;
|
1962
1962
|
border = 'all';
|
1963
1963
|
allowBreakRow;
|
1964
1964
|
clone(dest) {
|
@@ -1966,7 +1966,7 @@ class TableProps extends INotifyPropertyChanged {
|
|
1966
1966
|
super.cloneAttachedProperty(clone);
|
1967
1967
|
clone.id = this.id;
|
1968
1968
|
clone.cols = [...this.cols];
|
1969
|
-
clone.
|
1969
|
+
clone.align = this.align;
|
1970
1970
|
clone.border = this.border;
|
1971
1971
|
return clone;
|
1972
1972
|
}
|
@@ -1974,7 +1974,7 @@ class TableProps extends INotifyPropertyChanged {
|
|
1974
1974
|
return {
|
1975
1975
|
id: this.id,
|
1976
1976
|
cols: this.cols,
|
1977
|
-
alignment: this.
|
1977
|
+
alignment: this.align,
|
1978
1978
|
border: this.border
|
1979
1979
|
};
|
1980
1980
|
}
|
@@ -3202,7 +3202,7 @@ class DataElementRenderObject extends InlineGroupRenderObject {
|
|
3202
3202
|
textProps.fontSize = 16;
|
3203
3203
|
textProps.fontName = viewOptions.defaultFontName;
|
3204
3204
|
textProps.color = '#fff';
|
3205
|
-
const titleWidth = render.contentContext.
|
3205
|
+
const titleWidth = render.contentContext.measureText2(caption, textProps);
|
3206
3206
|
const x = position.x;
|
3207
3207
|
const y = position.y - 20;
|
3208
3208
|
render.contentContext.fillRect(x, y, titleWidth + 10, 20, 'blue');
|
@@ -4840,7 +4840,9 @@ class TableElement extends BlockContainerElement {
|
|
4840
4840
|
return clone;
|
4841
4841
|
}
|
4842
4842
|
createRenderObject() {
|
4843
|
-
|
4843
|
+
const render = new TableRenderObject(this);
|
4844
|
+
render.rect.width = this.props.cols.reduce((prev, curr) => curr + prev, 0);
|
4845
|
+
return render;
|
4844
4846
|
}
|
4845
4847
|
beginMeasure(data) {
|
4846
4848
|
super.beginMeasure(data);
|
@@ -4929,7 +4931,7 @@ class TableFactory extends ElementFactory {
|
|
4929
4931
|
tbProps.border = props.border || 'all';
|
4930
4932
|
tbProps.cols = [];
|
4931
4933
|
tbProps.id = props.id;
|
4932
|
-
tbProps.
|
4934
|
+
tbProps.align = props.align;
|
4933
4935
|
for (const col of cols) {
|
4934
4936
|
if (typeof col === 'object') {
|
4935
4937
|
tbProps.cols.push(col.width);
|
@@ -5086,7 +5088,7 @@ class TextGroupElement extends LeafElement {
|
|
5086
5088
|
return this.textMeasures.map(item => item.char).join('');
|
5087
5089
|
}
|
5088
5090
|
createRenderObject(data) {
|
5089
|
-
if (!this.isMeasure || this.modifyFlag !== exports.ModifyFlag.None) {
|
5091
|
+
if (!this.isMeasure || this.modifyFlag !== exports.ModifyFlag.None || !this.cacheRender) {
|
5090
5092
|
data.renderCtx.contentContext.measureTextUnits(this.textMeasures, this.props);
|
5091
5093
|
this.isMeasure = true;
|
5092
5094
|
}
|
@@ -5582,7 +5584,7 @@ class ElementUtil {
|
|
5582
5584
|
line.rect.x = innerRect.x;
|
5583
5585
|
}
|
5584
5586
|
line.rect.y = innerRect.height + innerRect.y + line.margin.top;
|
5585
|
-
|
5587
|
+
this.setHorizontalAlign(line, innerRect);
|
5586
5588
|
innerRect.height += line.rect.height + line.margin.top + line.margin.bottom;
|
5587
5589
|
}
|
5588
5590
|
render.updateRenderHeight(innerRect);
|
@@ -5590,8 +5592,7 @@ class ElementUtil {
|
|
5590
5592
|
}
|
5591
5593
|
static remeasureTableRow(rowRender, foreceColIndex = -1) {
|
5592
5594
|
const rowEle = rowRender.element;
|
5593
|
-
|
5594
|
-
let maxCellHeight = rowMinHeight;
|
5595
|
+
let maxCellHeight = rowEle.props.minHeight > 19 ? rowEle.props.minHeight : 19;
|
5595
5596
|
//限制行最小高度
|
5596
5597
|
maxCellHeight = maxCellHeight < 19 ? 19 : maxCellHeight;
|
5597
5598
|
//获取行内非纵向合并单元格的最高单元格高度
|
@@ -5673,11 +5674,24 @@ class ElementUtil {
|
|
5673
5674
|
}
|
5674
5675
|
}
|
5675
5676
|
/**
|
5676
|
-
*
|
5677
|
-
* @param tbRender
|
5677
|
+
* 设置原色横向排列方式
|
5678
5678
|
* @private
|
5679
|
-
|
5680
|
-
|
5679
|
+
* @param render
|
5680
|
+
* @param limitRect
|
5681
|
+
*/
|
5682
|
+
static setHorizontalAlign(render, limitRect) {
|
5683
|
+
if (render.element && render.element.props && render.element.props.align) {
|
5684
|
+
const align = render.element.props.align;
|
5685
|
+
if (align) {
|
5686
|
+
const remainSpace = limitRect.width - render.rect.width;
|
5687
|
+
if (align === 'center') {
|
5688
|
+
render.rect.x = Math.floor(remainSpace / 2);
|
5689
|
+
}
|
5690
|
+
else if (align === 'end') {
|
5691
|
+
render.rect.x = remainSpace;
|
5692
|
+
}
|
5693
|
+
}
|
5694
|
+
}
|
5681
5695
|
// const {alignment} = tbRender.element.props;
|
5682
5696
|
// if (!alignment) {
|
5683
5697
|
// return;
|
@@ -7090,6 +7104,10 @@ class PaintContent {
|
|
7090
7104
|
const textMeasure = this.ctx.measureText(text);
|
7091
7105
|
return { width: textMeasure.width, height: textProps.fontSize };
|
7092
7106
|
}
|
7107
|
+
measureText2(text, font) {
|
7108
|
+
this.ctx.font = font.fontSize + 'px ' + font.fontName;
|
7109
|
+
return this.ctx.measureText(text).width;
|
7110
|
+
}
|
7093
7111
|
measureTextUnits(units, textProps) {
|
7094
7112
|
this.ctx.font = textProps.getFont();
|
7095
7113
|
const letterSpace = textProps.letterSpace ?? 0;
|
@@ -11764,8 +11782,7 @@ class DocumentArrange {
|
|
11764
11782
|
item.rect.y = bodyInnerLimitRect.height + item.margin.top;
|
11765
11783
|
pageBodyRender.addChild(item);
|
11766
11784
|
bodyInnerLimitRect.height += item.rect.height + item.margin.top + item.margin.bottom;
|
11767
|
-
|
11768
|
-
//bodyInnerLimitRect.prevMargin = item.margin.bottom;
|
11785
|
+
ElementUtil.setHorizontalAlign(item, bodyInnerLimitRect);
|
11769
11786
|
ElementUtil.updateRenderHeightByInnerRect(pageBodyRender, bodyInnerLimitRect);
|
11770
11787
|
};
|
11771
11788
|
for (let i = 0; i < doc.bodyElement.length; i++) {
|
@@ -13726,6 +13743,9 @@ class DocumentEvent {
|
|
13726
13743
|
this.editor.addEventListener('contextmenu', evt => {
|
13727
13744
|
this.contextMenu.next(evt.sourceEvt);
|
13728
13745
|
});
|
13746
|
+
this.editor.addEventListener('keydown', evt => {
|
13747
|
+
this.onKeydown(evt.sourceEvt);
|
13748
|
+
});
|
13729
13749
|
this.documentInput.onLeftEvent.subscribe(() => {
|
13730
13750
|
this.moveCursorToLeft();
|
13731
13751
|
});
|
@@ -14159,6 +14179,10 @@ class DocumentEvent {
|
|
14159
14179
|
mouseDblClickHandle(nodeEvt) {
|
14160
14180
|
const docEvent = new MouseElementEvent(this.docCtx);
|
14161
14181
|
this.setEventViewPos(nodeEvt.sourceHitPos, docEvent);
|
14182
|
+
const hitInfo = this.getHitInfo(docEvent);
|
14183
|
+
if (!hitInfo) {
|
14184
|
+
return;
|
14185
|
+
}
|
14162
14186
|
//需要先处理是否开启页眉页脚编辑功能
|
14163
14187
|
const hitRegion = this.getHitRegion(docEvent);
|
14164
14188
|
if ((hitRegion === 'footer' || hitRegion === 'header') && !this.docCtx.document.headerEditState) {
|
@@ -14169,7 +14193,7 @@ class DocumentEvent {
|
|
14169
14193
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|
14170
14194
|
return;
|
14171
14195
|
}
|
14172
|
-
const hitInfo = this.getHitInfo(docEvent);
|
14196
|
+
//const hitInfo = this.getHitInfo(docEvent);
|
14173
14197
|
if (hitInfo) {
|
14174
14198
|
docEvent.source = hitInfo.element;
|
14175
14199
|
docEvent.sourceRender = hitInfo.render;
|
@@ -14779,9 +14803,8 @@ class DocumentEvent {
|
|
14779
14803
|
}
|
14780
14804
|
/**
|
14781
14805
|
* 获取点击的文档区域
|
14782
|
-
* @param docRender
|
14783
|
-
* @param pos
|
14784
14806
|
* @returns
|
14807
|
+
* @param docEvent
|
14785
14808
|
*/
|
14786
14809
|
getHitRegion(docEvent) {
|
14787
14810
|
const hitDocInfo = this.getHitDocPage(docEvent);
|
@@ -14812,6 +14835,30 @@ class DocumentEvent {
|
|
14812
14835
|
return null;
|
14813
14836
|
}
|
14814
14837
|
}
|
14838
|
+
onKeydown(evt) {
|
14839
|
+
const copy = () => {
|
14840
|
+
const input = document.createElement('input');
|
14841
|
+
document.body.appendChild(input);
|
14842
|
+
input.select();
|
14843
|
+
input.focus();
|
14844
|
+
input.addEventListener('copy', evt2 => {
|
14845
|
+
document.body.removeChild(input);
|
14846
|
+
const execCopy = this.editor['execCopy'];
|
14847
|
+
execCopy.call(this.editor, evt2);
|
14848
|
+
});
|
14849
|
+
document.execCommand('copy');
|
14850
|
+
};
|
14851
|
+
if (navigator.appVersion.indexOf('Mac') >= 0) {
|
14852
|
+
if (evt.metaKey && evt.keyCode === 67) {
|
14853
|
+
copy();
|
14854
|
+
}
|
14855
|
+
}
|
14856
|
+
else {
|
14857
|
+
if (evt.ctrlKey && evt.keyCode === 67) {
|
14858
|
+
copy();
|
14859
|
+
}
|
14860
|
+
}
|
14861
|
+
}
|
14815
14862
|
}
|
14816
14863
|
|
14817
14864
|
/**
|
@@ -16925,6 +16972,9 @@ class ElementTrackManage {
|
|
16925
16972
|
* 执行撤销
|
16926
16973
|
*/
|
16927
16974
|
undo() {
|
16975
|
+
if (!this.canUndo) {
|
16976
|
+
return;
|
16977
|
+
}
|
16928
16978
|
suppressTracking(() => {
|
16929
16979
|
this.index--;
|
16930
16980
|
this.executeCommand('undo');
|
@@ -16946,6 +16996,9 @@ class ElementTrackManage {
|
|
16946
16996
|
* 执行重做
|
16947
16997
|
*/
|
16948
16998
|
redo() {
|
16999
|
+
if (!this.canRedo) {
|
17000
|
+
return;
|
17001
|
+
}
|
16949
17002
|
suppressTracking(() => {
|
16950
17003
|
this.executeCommand('redo');
|
16951
17004
|
this.index++;
|
@@ -18104,7 +18157,7 @@ class NodeEvent {
|
|
18104
18157
|
this.canvas = canvas;
|
18105
18158
|
this.setAppState(null);
|
18106
18159
|
canvas.addEventListener('mousedown', evt => {
|
18107
|
-
evt.preventDefault();
|
18160
|
+
//evt.preventDefault();
|
18108
18161
|
this.setActiveAppContext(() => this.onMousedownHandler(evt));
|
18109
18162
|
});
|
18110
18163
|
canvas.addEventListener('mousemove', evt => {
|
@@ -18120,6 +18173,9 @@ class NodeEvent {
|
|
18120
18173
|
canvas.addEventListener('wheel', evt => {
|
18121
18174
|
this.setActiveAppContext(() => this.onWheelHandler(evt));
|
18122
18175
|
});
|
18176
|
+
canvas.addEventListener('click', evt => {
|
18177
|
+
this.root.setInputFocus(true);
|
18178
|
+
});
|
18123
18179
|
canvas.addEventListener('dblclick', evt => {
|
18124
18180
|
this.setActiveAppContext(() => this.onDblClickHandler(evt));
|
18125
18181
|
});
|
@@ -18422,6 +18478,30 @@ class NodeEvent {
|
|
18422
18478
|
};
|
18423
18479
|
invokeEvent(onContextMenuEvent, 'contextmenu', this.appState.sourceNode);
|
18424
18480
|
}
|
18481
|
+
onCopyHandler(evt) {
|
18482
|
+
if (this.appState.sourceNode) {
|
18483
|
+
const onCopyEvent = {
|
18484
|
+
source: this.appState.sourceNode,
|
18485
|
+
cancelable: true,
|
18486
|
+
isCancel: false,
|
18487
|
+
target: this.appState.sourceNode,
|
18488
|
+
sourceEvt: evt
|
18489
|
+
};
|
18490
|
+
invokeEvent(onCopyEvent, 'copy', this.appState.sourceNode);
|
18491
|
+
}
|
18492
|
+
}
|
18493
|
+
onKeydownHandler(evt) {
|
18494
|
+
if (this.appState.sourceNode) {
|
18495
|
+
const onKeydownEvent = {
|
18496
|
+
source: this.appState.sourceNode,
|
18497
|
+
cancelable: true,
|
18498
|
+
isCancel: false,
|
18499
|
+
target: this.appState.sourceNode,
|
18500
|
+
sourceEvt: evt
|
18501
|
+
};
|
18502
|
+
invokeEvent(onKeydownEvent, 'keydown', this.appState.sourceNode);
|
18503
|
+
}
|
18504
|
+
}
|
18425
18505
|
getHitNode(hitPos, parentPos) {
|
18426
18506
|
if (this.root.popNodes.length) {
|
18427
18507
|
for (let i = this.root.popNodes.length - 1; i >= 0; i--) {
|
@@ -18971,6 +19051,7 @@ class SurfaceView extends NodeItems {
|
|
18971
19051
|
this.invokeKeydown(evt);
|
18972
19052
|
});
|
18973
19053
|
this.input.addEventListener('copy', evt => {
|
19054
|
+
console.log('copy了');
|
18974
19055
|
this.invokeClipboardEvent(evt, 'copy');
|
18975
19056
|
});
|
18976
19057
|
this.input.addEventListener('paste', evt => {
|
@@ -19029,6 +19110,7 @@ class SurfaceView extends NodeItems {
|
|
19029
19110
|
return;
|
19030
19111
|
}
|
19031
19112
|
this.input.style.display = '';
|
19113
|
+
this.input.readOnly = false;
|
19032
19114
|
const left = Math.floor(x) + 'px';
|
19033
19115
|
const top = Math.floor(y) + 'px';
|
19034
19116
|
if (left !== this.input.style.left || top !== this.input.style.top) {
|
@@ -19042,9 +19124,10 @@ class SurfaceView extends NodeItems {
|
|
19042
19124
|
state ? this.input.focus() : this.input.blur();
|
19043
19125
|
}
|
19044
19126
|
hiddenInput() {
|
19045
|
-
this.input.style.display = 'none';
|
19046
|
-
this.input.style.left = '
|
19047
|
-
this.input.style.top = '
|
19127
|
+
//this.input.style.display = 'none';
|
19128
|
+
this.input.style.left = '-2px';
|
19129
|
+
this.input.style.top = '-2px';
|
19130
|
+
this.input.readOnly = true;
|
19048
19131
|
}
|
19049
19132
|
endInput() {
|
19050
19133
|
}
|
@@ -20408,7 +20491,7 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20408
20491
|
*/
|
20409
20492
|
setCursor() {
|
20410
20493
|
const { startControl, startOffset } = this.selectionState;
|
20411
|
-
if (!this.canSetCursor()) {
|
20494
|
+
if (!this.canSetCursor() || !this.documentEvent.startHitInfo) {
|
20412
20495
|
this.selectionState.editable = false;
|
20413
20496
|
this.documentInput.setCursorVisibility(false);
|
20414
20497
|
return false;
|
@@ -20873,6 +20956,13 @@ class CanvasTextEditor extends AbsolutePanel {
|
|
20873
20956
|
const copySerializeStr = ElementSerialize.getSelectedStruct(this.selectionState, this.viewOptions);
|
20874
20957
|
return ElementSerialize.serializeString(copySerializeStr);
|
20875
20958
|
}
|
20959
|
+
/**
|
20960
|
+
* 执行编辑器内部复制事件
|
20961
|
+
* @param evt
|
20962
|
+
*/
|
20963
|
+
execCopy(evt) {
|
20964
|
+
this.documentChange.onCopy(evt);
|
20965
|
+
}
|
20876
20966
|
/**
|
20877
20967
|
* 设置纸张方向
|
20878
20968
|
* @param orientation
|