@hailin-zheng/editor-core 2.2.41 → 2.2.42
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/editor.css +41 -0
- package/index-cjs.js +241 -119
- package/index-cjs.js.map +1 -1
- package/index.js +241 -119
- package/index.js.map +1 -1
- package/med_editor/doc-editor.d.ts +3 -2
- package/med_editor/framework/util/common-util.d.ts +1 -0
- package/med_editor/framework/vnode/editor-list-vnode.d.ts +18 -0
- package/package.json +1 -1
package/index.js
CHANGED
@@ -878,6 +878,25 @@ class CommonUtil {
|
|
878
878
|
const keyCombination = modifiers.length > 0 ? `${modifiers}+${key}` : key;
|
879
879
|
return keyCombination;
|
880
880
|
}
|
881
|
+
static resizePosition(elm, position, scale) {
|
882
|
+
const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
|
883
|
+
if (parent) {
|
884
|
+
const parentRect = parent.getBoundingClientRect();
|
885
|
+
const elmRect = elm.getBoundingClientRect();
|
886
|
+
parseInt(elm.style.top);
|
887
|
+
// elmRect.width /= scale;
|
888
|
+
// elmRect.height /= scale;
|
889
|
+
// parentRect.width /= scale;
|
890
|
+
// parentRect.height /= scale;
|
891
|
+
if (elmRect.top < parentRect.top) {
|
892
|
+
elm.style.top = (position.y - elmRect.height / scale) + 'px';
|
893
|
+
}
|
894
|
+
if (elmRect.left < parentRect.left) {
|
895
|
+
elm.style.left = (position.x - 10) + 'px';
|
896
|
+
}
|
897
|
+
return;
|
898
|
+
}
|
899
|
+
}
|
881
900
|
}
|
882
901
|
|
883
902
|
const docOpsMap = new Map();
|
@@ -21903,6 +21922,220 @@ class SearchPanel {
|
|
21903
21922
|
}
|
21904
21923
|
}
|
21905
21924
|
|
21925
|
+
class EditorListVNode {
|
21926
|
+
editor;
|
21927
|
+
currentEle;
|
21928
|
+
currentOpenStatus;
|
21929
|
+
currentOptions = [];
|
21930
|
+
changed;
|
21931
|
+
constructor(editor) {
|
21932
|
+
this.editor = editor;
|
21933
|
+
this.currentOpenStatus = createSignal('init');
|
21934
|
+
this.changed = createSignal(null);
|
21935
|
+
}
|
21936
|
+
clear() {
|
21937
|
+
this.currentEle = null;
|
21938
|
+
this.currentOptions.length = 0;
|
21939
|
+
this.currentOpenStatus.value = 'init';
|
21940
|
+
}
|
21941
|
+
init() {
|
21942
|
+
const editor = this.editor;
|
21943
|
+
const dataEle = editor.getCurrentDataElement();
|
21944
|
+
//不是下拉数据元
|
21945
|
+
if (!dataEle || !(dataEle instanceof DataElementList) || !dataEle.props.editable) {
|
21946
|
+
this.clear();
|
21947
|
+
return;
|
21948
|
+
}
|
21949
|
+
if (this.currentEle && this.currentEle !== dataEle) {
|
21950
|
+
this.clear();
|
21951
|
+
}
|
21952
|
+
if (this.currentEle === dataEle) {
|
21953
|
+
return;
|
21954
|
+
}
|
21955
|
+
this.currentEle = dataEle;
|
21956
|
+
const options = dataEle.props.options.map((item) => ({ checked: false, ...item }));
|
21957
|
+
const values = dataEle.getValue().split(";");
|
21958
|
+
options.filter((item) => values.includes(item.code + '')).forEach((item) => (item.checked = true));
|
21959
|
+
this.currentOptions.push(...options);
|
21960
|
+
this.currentOpenStatus.value = 'open';
|
21961
|
+
}
|
21962
|
+
render() {
|
21963
|
+
// const editor = this.editor;
|
21964
|
+
// if (editor.viewOptions.docMode === DocMode.View || !editor.selectionState.editable || editor['documentEvent'].ismousedown) {
|
21965
|
+
// return null;
|
21966
|
+
// }
|
21967
|
+
// this.init();
|
21968
|
+
// const dataEle = editor.getCurrentDataElement();
|
21969
|
+
// if (dataEle && dataEle instanceof DataElementList && dataEle.props.editable) {
|
21970
|
+
// const position = editor.getDataElementPosition(dataEle.startDecorate) as Rect;
|
21971
|
+
// const options = dataEle.props.options.map((item) => ({ checked: false, ...item }));
|
21972
|
+
// const values = dataEle.getValue().split(";");
|
21973
|
+
// options.filter((item) => values.includes(item.code + '')).forEach((item) => (item.checked = true));
|
21974
|
+
// const multiSelect = dataEle.props.multiSelect;
|
21975
|
+
// } else {
|
21976
|
+
// return null;
|
21977
|
+
// }
|
21978
|
+
this.init();
|
21979
|
+
if (!this.currentEle) {
|
21980
|
+
return null;
|
21981
|
+
}
|
21982
|
+
const editor = this.editor;
|
21983
|
+
const multiSelect = this.currentEle.props.multiSelect;
|
21984
|
+
const position = editor.getDataElementPosition(this.currentEle.startDecorate);
|
21985
|
+
const onChangeHandler = (code) => {
|
21986
|
+
if (!multiSelect) {
|
21987
|
+
this.currentOptions.forEach((item) => {
|
21988
|
+
if (item.code === code && code !== null) {
|
21989
|
+
if (this.currentEle.props.required) {
|
21990
|
+
item.checked = true;
|
21991
|
+
}
|
21992
|
+
else {
|
21993
|
+
item.checked = !item.checked;
|
21994
|
+
}
|
21995
|
+
}
|
21996
|
+
else {
|
21997
|
+
item.checked = false;
|
21998
|
+
}
|
21999
|
+
});
|
22000
|
+
onSave();
|
22001
|
+
}
|
22002
|
+
else {
|
22003
|
+
this.currentOptions.forEach((item) => {
|
22004
|
+
if (item.code === code && code !== null) {
|
22005
|
+
item.checked = !item.checked;
|
22006
|
+
}
|
22007
|
+
});
|
22008
|
+
}
|
22009
|
+
this.changed.onChange();
|
22010
|
+
// const values = options.filter(item => item.checked).map(item => item.code);
|
22011
|
+
// dataEle.setValue(values);
|
22012
|
+
// editor.setDataElemEndFocus(dataEle);
|
22013
|
+
// if (!multiSelect) {
|
22014
|
+
// editor.selectionState.resetRange(dataEle.endDecorate, 1);
|
22015
|
+
// }
|
22016
|
+
};
|
22017
|
+
const onSave = () => {
|
22018
|
+
const values = this.currentOptions.filter(item => item.checked).map(item => item.code);
|
22019
|
+
this.currentEle.setValue(values);
|
22020
|
+
editor.setDataElemEndFocus(this.currentEle);
|
22021
|
+
if (!multiSelect) {
|
22022
|
+
editor.selectionState.resetRange(this.currentEle.endDecorate, 1);
|
22023
|
+
}
|
22024
|
+
};
|
22025
|
+
const itemsVNode = this.currentOptions.map(item => {
|
22026
|
+
const ckbVNode = {
|
22027
|
+
sel: multiSelect ? 'div.editor-list-checkbox' : 'div.editor-list-radiobox',
|
22028
|
+
data: {}
|
22029
|
+
};
|
22030
|
+
if (item.checked) {
|
22031
|
+
ckbVNode.sel += '.checked';
|
22032
|
+
//ckbVNode.data.attrs['checked'] = true;
|
22033
|
+
}
|
22034
|
+
return {
|
22035
|
+
sel: 'div', data: {
|
22036
|
+
on: {
|
22037
|
+
click: () => {
|
22038
|
+
onChangeHandler(item.code);
|
22039
|
+
}
|
22040
|
+
}
|
22041
|
+
}, children: [ckbVNode, {
|
22042
|
+
sel: 'label',
|
22043
|
+
data: {},
|
22044
|
+
text: item.value
|
22045
|
+
}]
|
22046
|
+
};
|
22047
|
+
});
|
22048
|
+
const downArrowVNode = {
|
22049
|
+
sel: 'div.data-list-arrow',
|
22050
|
+
data: {
|
22051
|
+
style: {
|
22052
|
+
left: '-28px',
|
22053
|
+
top: (-position.height - 5) + 'px'
|
22054
|
+
},
|
22055
|
+
on: {
|
22056
|
+
click: () => {
|
22057
|
+
if (this.currentOpenStatus.value === 'open') {
|
22058
|
+
this.currentOpenStatus.value = 'close';
|
22059
|
+
}
|
22060
|
+
else if (this.currentOpenStatus.value === 'close') {
|
22061
|
+
this.currentOpenStatus.value = 'open';
|
22062
|
+
}
|
22063
|
+
}
|
22064
|
+
}
|
22065
|
+
},
|
22066
|
+
children: []
|
22067
|
+
};
|
22068
|
+
const footerVNode = {
|
22069
|
+
sel: 'div.data-list-footer',
|
22070
|
+
data: {},
|
22071
|
+
children: [{
|
22072
|
+
sel: 'div.data-list-footer-btn',
|
22073
|
+
data: {
|
22074
|
+
on: {
|
22075
|
+
click: () => {
|
22076
|
+
this.currentOpenStatus.value = 'close';
|
22077
|
+
onSave();
|
22078
|
+
}
|
22079
|
+
}
|
22080
|
+
},
|
22081
|
+
text: '确定'
|
22082
|
+
},
|
22083
|
+
{
|
22084
|
+
sel: 'div.data-list-footer-btn',
|
22085
|
+
data: {
|
22086
|
+
on: {
|
22087
|
+
click: () => {
|
22088
|
+
this.currentOpenStatus.value = 'close';
|
22089
|
+
}
|
22090
|
+
}
|
22091
|
+
},
|
22092
|
+
text: '取消'
|
22093
|
+
}, {
|
22094
|
+
sel: 'div.data-list-footer-btn',
|
22095
|
+
data: {
|
22096
|
+
on: {
|
22097
|
+
click: () => {
|
22098
|
+
this.currentEle.setValue(null);
|
22099
|
+
editor.selectionState.resetRange(this.currentEle.endDecorate, 1);
|
22100
|
+
}
|
22101
|
+
}
|
22102
|
+
},
|
22103
|
+
text: '清除'
|
22104
|
+
}
|
22105
|
+
]
|
22106
|
+
};
|
22107
|
+
return {
|
22108
|
+
sel: 'div.data-list-container',
|
22109
|
+
data: {
|
22110
|
+
style: {
|
22111
|
+
position: 'absolute',
|
22112
|
+
left: (position.x) + 'px',
|
22113
|
+
top: position.y + 5 + position.height + 'px',
|
22114
|
+
},
|
22115
|
+
hook: {
|
22116
|
+
insert: (vnode) => {
|
22117
|
+
const elm = vnode.elm;
|
22118
|
+
CommonUtil.resizePosition(elm, position, editor.viewOptions.scale);
|
22119
|
+
},
|
22120
|
+
update: (oldVnode, vnode) => {
|
22121
|
+
const elm = vnode.elm;
|
22122
|
+
CommonUtil.resizePosition(elm, position, editor.viewOptions.scale);
|
22123
|
+
}
|
22124
|
+
},
|
22125
|
+
},
|
22126
|
+
children: [
|
22127
|
+
multiSelect ? downArrowVNode : undefined,
|
22128
|
+
this.currentOpenStatus.value === 'open' ? {
|
22129
|
+
sel: 'div#data-list.data-list',
|
22130
|
+
data: {},
|
22131
|
+
children: [...itemsVNode]
|
22132
|
+
} : undefined,
|
22133
|
+
this.currentOpenStatus.value === 'open' && multiSelect ? footerVNode : undefined
|
22134
|
+
]
|
22135
|
+
};
|
22136
|
+
}
|
22137
|
+
}
|
22138
|
+
|
21906
22139
|
class DocEditor {
|
21907
22140
|
svgContainer;
|
21908
22141
|
//设置vue 不允许代理
|
@@ -22030,6 +22263,7 @@ class DocEditor {
|
|
22030
22263
|
const calendarFunc = this.renderCalendar();
|
22031
22264
|
const menuFunc = this.renderContextmenu();
|
22032
22265
|
const suggestionFunc = this.renderSuggestions();
|
22266
|
+
const listVNode = this.renderDataListVNode();
|
22033
22267
|
const ruleFunc = new DocRule(this.docCtx);
|
22034
22268
|
const onSizeChange = () => {
|
22035
22269
|
this.adjustPageLayout();
|
@@ -22061,7 +22295,6 @@ class DocEditor {
|
|
22061
22295
|
on: this.documentInput.getEventListener()
|
22062
22296
|
}
|
22063
22297
|
};
|
22064
|
-
const listVNode = this.renderDataListVNode();
|
22065
22298
|
const dropContainer = {
|
22066
22299
|
sel: 'div.absolute-container',
|
22067
22300
|
data: {
|
@@ -22225,7 +22458,9 @@ class DocEditor {
|
|
22225
22458
|
* 载入文档
|
22226
22459
|
* @param data json对象、json字符串、DocumentElement对象
|
22227
22460
|
*/
|
22228
|
-
loadDoc(data) {
|
22461
|
+
loadDoc(data, options) {
|
22462
|
+
options = options || {};
|
22463
|
+
options.autoScrollToTop = options.autoScrollToTop ?? true;
|
22229
22464
|
suppressTracking(() => {
|
22230
22465
|
this.noEffectChange(() => {
|
22231
22466
|
this.adjustPageLayout();
|
@@ -22233,7 +22468,7 @@ class DocEditor {
|
|
22233
22468
|
this.refreshDocument();
|
22234
22469
|
this.historyMange.clear();
|
22235
22470
|
this.documentEvent.clear();
|
22236
|
-
this.scrollToPosition({ x: 0, y: 0 });
|
22471
|
+
options.autoScrollToTop && this.scrollToPosition({ x: 0, y: 0 });
|
22237
22472
|
});
|
22238
22473
|
});
|
22239
22474
|
}
|
@@ -23302,126 +23537,13 @@ class DocEditor {
|
|
23302
23537
|
* @private
|
23303
23538
|
*/
|
23304
23539
|
renderDataListVNode() {
|
23305
|
-
const
|
23540
|
+
const dataList = new EditorListVNode(this);
|
23306
23541
|
return {
|
23307
23542
|
render() {
|
23308
|
-
|
23309
|
-
return null;
|
23310
|
-
}
|
23311
|
-
const dataEle = editor.getCurrentDataElement();
|
23312
|
-
if (dataEle && dataEle instanceof DataElementList && dataEle.props.editable) {
|
23313
|
-
const position = editor.getDataElementPosition(dataEle.startDecorate);
|
23314
|
-
const options = dataEle.props.options.map((item) => ({ checked: false, ...item }));
|
23315
|
-
const values = dataEle.getValue().split(";");
|
23316
|
-
options.filter((item) => values.includes(item.code + '')).forEach((item) => (item.checked = true));
|
23317
|
-
const multiSelect = dataEle.props.multiSelect;
|
23318
|
-
const onChangeHandler = (code) => {
|
23319
|
-
if (!multiSelect) {
|
23320
|
-
options.forEach((item) => {
|
23321
|
-
if (item.code === code && code !== null) {
|
23322
|
-
if (dataEle.props.required) {
|
23323
|
-
item.checked = true;
|
23324
|
-
}
|
23325
|
-
else {
|
23326
|
-
item.checked = !item.checked;
|
23327
|
-
}
|
23328
|
-
}
|
23329
|
-
else {
|
23330
|
-
item.checked = false;
|
23331
|
-
}
|
23332
|
-
});
|
23333
|
-
}
|
23334
|
-
else {
|
23335
|
-
options.forEach((item) => {
|
23336
|
-
if (item.code === code && code !== null) {
|
23337
|
-
item.checked = !item.checked;
|
23338
|
-
}
|
23339
|
-
});
|
23340
|
-
}
|
23341
|
-
const values = options.filter(item => item.checked).map(item => item.code);
|
23342
|
-
dataEle.setValue(values);
|
23343
|
-
editor.setDataElemEndFocus(dataEle);
|
23344
|
-
if (!multiSelect) {
|
23345
|
-
editor.selectionState.resetRange(dataEle.endDecorate, 1);
|
23346
|
-
}
|
23347
|
-
};
|
23348
|
-
const itemsVNode = options.map(item => {
|
23349
|
-
const ckbVNode = {
|
23350
|
-
sel: multiSelect ? 'div.editor-list-checkbox' : 'div.editor-list-radiobox',
|
23351
|
-
data: {}
|
23352
|
-
};
|
23353
|
-
if (item.checked) {
|
23354
|
-
ckbVNode.sel += '.checked';
|
23355
|
-
//ckbVNode.data.attrs['checked'] = true;
|
23356
|
-
}
|
23357
|
-
return {
|
23358
|
-
sel: 'div', data: {
|
23359
|
-
on: {
|
23360
|
-
click: () => {
|
23361
|
-
onChangeHandler(item.code);
|
23362
|
-
}
|
23363
|
-
}
|
23364
|
-
}, children: [ckbVNode, {
|
23365
|
-
sel: 'label',
|
23366
|
-
data: {},
|
23367
|
-
text: item.value
|
23368
|
-
}]
|
23369
|
-
};
|
23370
|
-
});
|
23371
|
-
return {
|
23372
|
-
sel: 'div.data-list-container',
|
23373
|
-
data: {
|
23374
|
-
style: {
|
23375
|
-
position: 'absolute',
|
23376
|
-
left: (position.x) + 'px',
|
23377
|
-
top: position.y + 5 + position.height + 'px',
|
23378
|
-
},
|
23379
|
-
hook: {
|
23380
|
-
insert: (vnode) => {
|
23381
|
-
const elm = vnode.elm;
|
23382
|
-
editor.resizePosition(elm, position);
|
23383
|
-
},
|
23384
|
-
update: (oldVnode, vnode) => {
|
23385
|
-
const elm = vnode.elm;
|
23386
|
-
editor.resizePosition(elm, position);
|
23387
|
-
}
|
23388
|
-
},
|
23389
|
-
},
|
23390
|
-
children: [
|
23391
|
-
{
|
23392
|
-
sel: 'div#data-list.data-list',
|
23393
|
-
data: {},
|
23394
|
-
children: [...itemsVNode]
|
23395
|
-
}
|
23396
|
-
]
|
23397
|
-
};
|
23398
|
-
}
|
23399
|
-
else {
|
23400
|
-
return null;
|
23401
|
-
}
|
23543
|
+
return dataList.render();
|
23402
23544
|
}
|
23403
23545
|
};
|
23404
23546
|
}
|
23405
|
-
resizePosition(elm, position) {
|
23406
|
-
const parent = CommonUtil.findParent(elm, (item) => item.className === 'scroll-container');
|
23407
|
-
const scale = this.viewOptions.scale;
|
23408
|
-
if (parent) {
|
23409
|
-
const parentRect = parent.getBoundingClientRect();
|
23410
|
-
const elmRect = elm.getBoundingClientRect();
|
23411
|
-
parseInt(elm.style.top);
|
23412
|
-
// elmRect.width /= scale;
|
23413
|
-
// elmRect.height /= scale;
|
23414
|
-
// parentRect.width /= scale;
|
23415
|
-
// parentRect.height /= scale;
|
23416
|
-
if (elmRect.top < parentRect.top) {
|
23417
|
-
elm.style.top = (position.y - elmRect.height / scale) + 'px';
|
23418
|
-
}
|
23419
|
-
if (elmRect.left < parentRect.left) {
|
23420
|
-
elm.style.left = (position.x - 10) + 'px';
|
23421
|
-
}
|
23422
|
-
return;
|
23423
|
-
}
|
23424
|
-
}
|
23425
23547
|
renderCalendar() {
|
23426
23548
|
const calendar = new EditorCalendarVNode(this.viewOptions);
|
23427
23549
|
const editor = this;
|
@@ -23528,7 +23650,7 @@ class DocEditor {
|
|
23528
23650
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
23529
23651
|
}
|
23530
23652
|
version() {
|
23531
|
-
return "2.2.
|
23653
|
+
return "2.2.42";
|
23532
23654
|
}
|
23533
23655
|
switchPageHeaderEditor() {
|
23534
23656
|
this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
|