@hailin-zheng/editor-core 2.2.6 → 2.2.7

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.js CHANGED
@@ -1717,7 +1717,7 @@ class ViewOptions {
1717
1717
  showCharRect;
1718
1718
  //数据元交互修饰模式
1719
1719
  dataEleDecoratorMode = 'outline';
1720
- dataEleDecoratorColor = '#0050b3';
1720
+ dataEleDecoratorColor = '#ddd';
1721
1721
  showTabChar;
1722
1722
  showSpaceChar;
1723
1723
  showLineBreak;
@@ -2499,6 +2499,10 @@ class DataEleListProps extends DataEleBaseTextProps {
2499
2499
  super();
2500
2500
  }
2501
2501
  options = [];
2502
+ /**
2503
+ * 是否保存选项到病历文件里面
2504
+ */
2505
+ saveOptions = true;
2502
2506
  dropDownStyle;
2503
2507
  /**
2504
2508
  * 是否允许多选
@@ -2829,28 +2833,14 @@ class ValidateProps {
2829
2833
  return clone;
2830
2834
  }
2831
2835
  }
2832
- class DataElementGroupProps extends INotifyPropertyChanged {
2833
- id;
2834
- name;
2835
- hidden;
2836
+ class DataElementGroupProps extends DataEleBaseProps {
2836
2837
  clone(dest) {
2837
- dest = dest ?? new DataElementGroupProps();
2838
- dest.id = this.id;
2839
- dest.name = this.name;
2840
- dest.hidden = this.hidden;
2838
+ const clone = dest ?? new DataElementGroupProps();
2839
+ super.cloneBaseProps(clone);
2841
2840
  }
2842
- getSerializeProps() {
2841
+ getSerializeProps(options) {
2843
2842
  const props = {};
2844
- if (this.id) {
2845
- props.id = this.id;
2846
- }
2847
- if (this.name) {
2848
- props.name = this.name;
2849
- }
2850
- if (this.hidden) {
2851
- props.hidden = this.hidden;
2852
- }
2853
- return props;
2843
+ return this.getBaseProps(props, options);
2854
2844
  }
2855
2845
  }
2856
2846
  class DataElementBarcodeProps {
@@ -2933,6 +2923,9 @@ class DataDecorateRenderObject extends LeafRenderObject {
2933
2923
  if (event.mode === 'print') {
2934
2924
  return null;
2935
2925
  }
2926
+ // if(this.element.parent.parent.type==='data-group'){
2927
+ // return null;
2928
+ // }
2936
2929
  const element = this.element;
2937
2930
  const lineWidth = 3;
2938
2931
  let path = '';
@@ -3933,19 +3926,83 @@ class DataElementInlineGroup extends InlineGroupInputElement {
3933
3926
  expressFn;
3934
3927
  beginMeasure(data) {
3935
3928
  super.beginMeasure(data);
3936
- if (!this.props.expression || !data.viewOptions.enableDyExpression) {
3929
+ // if (!this.props.expression || !data.options.enableDyExpression) {
3930
+ // return;
3931
+ // }
3932
+ // try {
3933
+ // if (!this.expressFn) {
3934
+ // const code = parser(this.props.expression);
3935
+ // this.expressFn = new Function(`with(this){ ${code} }`);
3936
+ // }
3937
+ // this.expressFn.bind(data.execute)();
3938
+ // //this.expressFn();
3939
+ // } catch (e) {
3940
+ // this.expressFn = new Function();
3941
+ // }
3942
+ }
3943
+ parserExpress;
3944
+ /**
3945
+ * 解析可见性表达式
3946
+ * @param ele
3947
+ * @param execute
3948
+ * @private
3949
+ */
3950
+ parseEleExpression(data) {
3951
+ const execute = data.execute;
3952
+ //不存在表达式,或者不启用表达式,不做处理
3953
+ if (!this.props.expression || !data.options.enableDyExpression)
3937
3954
  return;
3938
- }
3955
+ //存在表达式,并且已经解析过,不再做处理
3956
+ if (this.parserExpress)
3957
+ return;
3958
+ const reactiveMode = data.renderCtx.drawMode !== 'print';
3939
3959
  try {
3940
- if (!this.expressFn) {
3941
- const code = parser(this.props.expression);
3942
- this.expressFn = new Function(`with(this){ ${code} }`);
3960
+ const depIdItems = [];
3961
+ const depEleMap = new Map();
3962
+ let compliedCode = parser(this.props.expression, depIdItems);
3963
+ compliedCode = addReturn(compliedCode);
3964
+ if (depIdItems.length) {
3965
+ depIdItems.forEach(dep => {
3966
+ const refCtx = execute.getObject(dep);
3967
+ if (refCtx.ref) {
3968
+ const refEle = refCtx.ref.item;
3969
+ depEleMap.set(dep, refCtx);
3970
+ //当前有可能是checkbox数组
3971
+ const refEles = Array.isArray(refEle) ? refEle : [refEle];
3972
+ reactiveMode && refEles.forEach(item => {
3973
+ //求值依赖元素更改的时候,发布当前元素重新计算的指令
3974
+ item.onChangeSubject.subscribe(() => {
3975
+ this.pubOnChange('self');
3976
+ });
3977
+ });
3978
+ }
3979
+ });
3943
3980
  }
3944
- this.expressFn.bind(data.execute)();
3945
- //this.expressFn();
3981
+ this.parserExpress = { compliedCode, func: new Function(`with(this){ ${compliedCode} }`), depItems: depEleMap };
3946
3982
  }
3947
3983
  catch (e) {
3948
- this.expressFn = new Function();
3984
+ console.error('解析表达式出错,parseEleExpression', this.props.expression);
3985
+ }
3986
+ }
3987
+ /**
3988
+ * 元素可见行求值
3989
+ * @param ele
3990
+ * @param executeCtx
3991
+ * @private
3992
+ */
3993
+ evalEleExpr(executeCtx) {
3994
+ if (this.parserExpress && this.parserExpress.func) {
3995
+ try {
3996
+ executeCtx.setCurrentCtx(this, this.parserExpress.depItems);
3997
+ const func = this.parserExpress.func.bind(executeCtx);
3998
+ func();
3999
+ }
4000
+ catch (e) {
4001
+ console.error(e, "表达式执行出错:evalVisibleExpr", this.parserExpress.compliedCode);
4002
+ }
4003
+ finally {
4004
+ executeCtx.clearCurrentCtx();
4005
+ }
3949
4006
  }
3950
4007
  }
3951
4008
  /**
@@ -8580,7 +8637,7 @@ class DataElementGroupElement extends InlineGroupInputElement {
8580
8637
  return {
8581
8638
  type: this.type,
8582
8639
  props: {
8583
- ...this.props.getSerializeProps()
8640
+ ...this.props.getSerializeProps(viewOptions)
8584
8641
  }
8585
8642
  };
8586
8643
  }
@@ -8602,9 +8659,7 @@ class DataElementGroupFactory extends DataElementBaseFactory {
8602
8659
  createElement(data) {
8603
8660
  const props = data.props;
8604
8661
  const ele = new DataElementGroupElement();
8605
- ele.props.id = props.id;
8606
- ele.props.name = props.name;
8607
- ele.props.hidden = Boolean(props.hidden);
8662
+ ElementUtil.readEleBaseProps(ele.props, props);
8608
8663
  return ele;
8609
8664
  }
8610
8665
  }
@@ -8909,7 +8964,11 @@ class DataElementText extends DataElementInlineGroup {
8909
8964
  super('data-ele-text');
8910
8965
  this.props = new DataEleBaseTextProps();
8911
8966
  }
8912
- createRenderObject() {
8967
+ createRenderObject(data) {
8968
+ if (data.options.enableDyExpression) {
8969
+ this.parseEleExpression(data);
8970
+ this.evalEleExpr(data.execute);
8971
+ }
8913
8972
  return new DataElementTextRenderObject(this);
8914
8973
  }
8915
8974
  serialize(viewOptions) {
@@ -13867,7 +13926,7 @@ class ParagraphMeasure {
13867
13926
  }
13868
13927
  }
13869
13928
  arrangeInlineGroupElement(parentLine, ele) {
13870
- const { options, renderCtx } = this;
13929
+ const { options, renderCtx, execute } = this;
13871
13930
  let render = this.createRenderObject(ele);
13872
13931
  //记录多行情况下的渲染对象,用于计算总长度,生成fill-null-space
13873
13932
  const inlineGroupRenders = [];
@@ -13903,7 +13962,7 @@ class ParagraphMeasure {
13903
13962
  isCloseToBody: parentLine.isCloseToBody,
13904
13963
  applyNewLine() {
13905
13964
  parentLine.applyNewLine();
13906
- render = ele.createRenderObject({ options, renderCtx });
13965
+ render = ele.createRenderObject({ options, renderCtx, execute });
13907
13966
  parentLine.add(render);
13908
13967
  inlineGroupRenders.push(render);
13909
13968
  },
@@ -14238,7 +14297,8 @@ class ParagraphMeasure {
14238
14297
  }
14239
14298
  return element.createRenderObject({
14240
14299
  options: this.options,
14241
- renderCtx: this.renderCtx
14300
+ renderCtx: this.renderCtx,
14301
+ execute: this.execute
14242
14302
  });
14243
14303
  }
14244
14304
  }
@@ -14397,8 +14457,9 @@ class DocumentArrange {
14397
14457
  this.pMeasure = new ParagraphMeasure(this.options, this.renderCtx, this.execute);
14398
14458
  const data = {
14399
14459
  doc,
14400
- viewOptions: this.options,
14460
+ options: this.options,
14401
14461
  execute: this.execute,
14462
+ renderCtx: this.renderCtx,
14402
14463
  createParaFn: () => this.createDefaultPara()
14403
14464
  };
14404
14465
  this.reset(data);
@@ -14601,7 +14662,7 @@ class DocumentArrange {
14601
14662
  if (this.options.textRowLineMode && ele instanceof TableElement && ele.cacheRender) {
14602
14663
  const cacheRender = ele.cacheRender;
14603
14664
  clearChildrenRenderCache(ele);
14604
- textLineRenderMode(cacheRender, { options: this.options, renderCtx: this.renderCtx });
14665
+ textLineRenderMode(cacheRender, { options: this.options, renderCtx: this.renderCtx, execute: this.execute });
14605
14666
  }
14606
14667
  }
14607
14668
  getDocInnerRect(documentRender) {
@@ -19419,7 +19480,7 @@ class EditorCalendarVNode {
19419
19480
  data: {
19420
19481
  style: {
19421
19482
  position: 'absolute',
19422
- left: (position.x - 10) + 'px',
19483
+ left: (position.x) + 'px',
19423
19484
  top: position.y + 5 + position.height + 'px',
19424
19485
  'min-width': '100px',
19425
19486
  'background-color': 'white',
@@ -19555,6 +19616,9 @@ class EditorCalendarVNode {
19555
19616
  on: {
19556
19617
  click: () => {
19557
19618
  this.onClickDayItem(day.date);
19619
+ },
19620
+ dblclick: () => {
19621
+ this.onSave();
19558
19622
  }
19559
19623
  }
19560
19624
  },
@@ -19612,12 +19676,7 @@ class EditorCalendarVNode {
19612
19676
  data: {
19613
19677
  on: {
19614
19678
  click: () => {
19615
- if (!this.selectedDate.value) {
19616
- this.onSetValue.next(new Date());
19617
- }
19618
- else {
19619
- this.onSetValue.next(moment(this.selectedDate.value + ' ' + this.selectedTime.value).toDate());
19620
- }
19679
+ this.onSave();
19621
19680
  }
19622
19681
  }
19623
19682
  },
@@ -19637,6 +19696,14 @@ class EditorCalendarVNode {
19637
19696
  ]
19638
19697
  };
19639
19698
  }
19699
+ onSave() {
19700
+ if (!this.selectedDate.value) {
19701
+ this.onSetValue.next(new Date());
19702
+ }
19703
+ else {
19704
+ this.onSetValue.next(moment(this.selectedDate.value + ' ' + this.selectedTime.value).toDate());
19705
+ }
19706
+ }
19640
19707
  navigateToToday() {
19641
19708
  this.currYear.value = new Date().getFullYear();
19642
19709
  this.currMonth.value = new Date().getMonth();
@@ -20349,7 +20416,6 @@ class DocEditor {
20349
20416
  beforeRenderSubject = new Subject();
20350
20417
  afterRenderSubject = new Subject();
20351
20418
  onBeforeSetCursorSubject = new Subject();
20352
- contentChanged = new Subject();
20353
20419
  onPatchVNodeSubject = new Subject();
20354
20420
  selectionState;
20355
20421
  onDblClickEvent = new Subject();
@@ -20641,10 +20707,12 @@ class DocEditor {
20641
20707
  }
20642
20708
  loadDoc(data) {
20643
20709
  suppressTracking(() => {
20644
- this.adjustPageLayout();
20645
- this.elementReader.read(data);
20646
- this.refreshDocument();
20647
- this.historyMange.clear();
20710
+ this.noEffectChange(() => {
20711
+ this.adjustPageLayout();
20712
+ this.elementReader.read(data);
20713
+ this.refreshDocument();
20714
+ this.historyMange.clear();
20715
+ });
20648
20716
  });
20649
20717
  }
20650
20718
  /**
@@ -20662,7 +20730,6 @@ class DocEditor {
20662
20730
  suppressTracking(() => {
20663
20731
  this.documentPaginator.rePages();
20664
20732
  });
20665
- this.contentChanged.next();
20666
20733
  }
20667
20734
  this.updateSelection();
20668
20735
  this.setCursor();
@@ -21565,7 +21632,7 @@ class DocEditor {
21565
21632
  const scaleFitContainer = {
21566
21633
  sel: 'div#scale-fit-container',
21567
21634
  data: {
21568
- style: { overflow: 'hidden', height: '0px', }
21635
+ style: { height: '0px', }
21569
21636
  },
21570
21637
  children: [docContent]
21571
21638
  };
@@ -21727,7 +21794,7 @@ class DocEditor {
21727
21794
  data: {
21728
21795
  style: {
21729
21796
  position: 'absolute',
21730
- left: (position.x - 10) + 'px',
21797
+ left: (position.x) + 'px',
21731
21798
  top: position.y + 5 + position.height + 'px',
21732
21799
  },
21733
21800
  hook: {
@@ -21893,7 +21960,7 @@ class DocEditor {
21893
21960
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
21894
21961
  }
21895
21962
  version() {
21896
- return "2.2.6";
21963
+ return "2.2.7";
21897
21964
  }
21898
21965
  switchPageHeaderEditor() {
21899
21966
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -22196,6 +22263,13 @@ class DocEditor {
22196
22263
  this.documentChange.appendText(text, this.docCtx.suggestions.currentMatchedText);
22197
22264
  }
22198
22265
  }
22266
+ parser(code, returnProcess = false) {
22267
+ const res = parser(code);
22268
+ if (returnProcess) {
22269
+ return addReturn(res);
22270
+ }
22271
+ return res;
22272
+ }
22199
22273
  }
22200
22274
 
22201
22275
  /**