@hailin-zheng/editor-core 2.2.5 → 2.2.7

Sign up to get free protection for your applications and to get access to all the features.
package/editor.css CHANGED
@@ -17,7 +17,7 @@
17
17
  }
18
18
 
19
19
  .data-list > div {
20
- padding: 10px 6px;
20
+ padding: 6px 4px;
21
21
  display: flex;
22
22
  align-items: center;
23
23
  gap: 10px;
package/index-cjs.js CHANGED
@@ -1746,7 +1746,7 @@ class ViewOptions {
1746
1746
  showCharRect;
1747
1747
  //数据元交互修饰模式
1748
1748
  dataEleDecoratorMode = 'outline';
1749
- dataEleDecoratorColor = '#0050b3';
1749
+ dataEleDecoratorColor = '#ddd';
1750
1750
  showTabChar;
1751
1751
  showSpaceChar;
1752
1752
  showLineBreak;
@@ -2528,6 +2528,10 @@ class DataEleListProps extends DataEleBaseTextProps {
2528
2528
  super();
2529
2529
  }
2530
2530
  options = [];
2531
+ /**
2532
+ * 是否保存选项到病历文件里面
2533
+ */
2534
+ saveOptions = true;
2531
2535
  dropDownStyle;
2532
2536
  /**
2533
2537
  * 是否允许多选
@@ -2858,28 +2862,14 @@ class ValidateProps {
2858
2862
  return clone;
2859
2863
  }
2860
2864
  }
2861
- class DataElementGroupProps extends INotifyPropertyChanged {
2862
- id;
2863
- name;
2864
- hidden;
2865
+ class DataElementGroupProps extends DataEleBaseProps {
2865
2866
  clone(dest) {
2866
- dest = dest ?? new DataElementGroupProps();
2867
- dest.id = this.id;
2868
- dest.name = this.name;
2869
- dest.hidden = this.hidden;
2867
+ const clone = dest ?? new DataElementGroupProps();
2868
+ super.cloneBaseProps(clone);
2870
2869
  }
2871
- getSerializeProps() {
2870
+ getSerializeProps(options) {
2872
2871
  const props = {};
2873
- if (this.id) {
2874
- props.id = this.id;
2875
- }
2876
- if (this.name) {
2877
- props.name = this.name;
2878
- }
2879
- if (this.hidden) {
2880
- props.hidden = this.hidden;
2881
- }
2882
- return props;
2872
+ return this.getBaseProps(props, options);
2883
2873
  }
2884
2874
  }
2885
2875
  class DataElementBarcodeProps {
@@ -2962,6 +2952,9 @@ class DataDecorateRenderObject extends LeafRenderObject {
2962
2952
  if (event.mode === 'print') {
2963
2953
  return null;
2964
2954
  }
2955
+ // if(this.element.parent.parent.type==='data-group'){
2956
+ // return null;
2957
+ // }
2965
2958
  const element = this.element;
2966
2959
  const lineWidth = 3;
2967
2960
  let path = '';
@@ -3962,19 +3955,83 @@ class DataElementInlineGroup extends InlineGroupInputElement {
3962
3955
  expressFn;
3963
3956
  beginMeasure(data) {
3964
3957
  super.beginMeasure(data);
3965
- if (!this.props.expression || !data.viewOptions.enableDyExpression) {
3958
+ // if (!this.props.expression || !data.options.enableDyExpression) {
3959
+ // return;
3960
+ // }
3961
+ // try {
3962
+ // if (!this.expressFn) {
3963
+ // const code = parser(this.props.expression);
3964
+ // this.expressFn = new Function(`with(this){ ${code} }`);
3965
+ // }
3966
+ // this.expressFn.bind(data.execute)();
3967
+ // //this.expressFn();
3968
+ // } catch (e) {
3969
+ // this.expressFn = new Function();
3970
+ // }
3971
+ }
3972
+ parserExpress;
3973
+ /**
3974
+ * 解析可见性表达式
3975
+ * @param ele
3976
+ * @param execute
3977
+ * @private
3978
+ */
3979
+ parseEleExpression(data) {
3980
+ const execute = data.execute;
3981
+ //不存在表达式,或者不启用表达式,不做处理
3982
+ if (!this.props.expression || !data.options.enableDyExpression)
3966
3983
  return;
3967
- }
3984
+ //存在表达式,并且已经解析过,不再做处理
3985
+ if (this.parserExpress)
3986
+ return;
3987
+ const reactiveMode = data.renderCtx.drawMode !== 'print';
3968
3988
  try {
3969
- if (!this.expressFn) {
3970
- const code = parser(this.props.expression);
3971
- this.expressFn = new Function(`with(this){ ${code} }`);
3989
+ const depIdItems = [];
3990
+ const depEleMap = new Map();
3991
+ let compliedCode = parser(this.props.expression, depIdItems);
3992
+ compliedCode = addReturn(compliedCode);
3993
+ if (depIdItems.length) {
3994
+ depIdItems.forEach(dep => {
3995
+ const refCtx = execute.getObject(dep);
3996
+ if (refCtx.ref) {
3997
+ const refEle = refCtx.ref.item;
3998
+ depEleMap.set(dep, refCtx);
3999
+ //当前有可能是checkbox数组
4000
+ const refEles = Array.isArray(refEle) ? refEle : [refEle];
4001
+ reactiveMode && refEles.forEach(item => {
4002
+ //求值依赖元素更改的时候,发布当前元素重新计算的指令
4003
+ item.onChangeSubject.subscribe(() => {
4004
+ this.pubOnChange('self');
4005
+ });
4006
+ });
4007
+ }
4008
+ });
3972
4009
  }
3973
- this.expressFn.bind(data.execute)();
3974
- //this.expressFn();
4010
+ this.parserExpress = { compliedCode, func: new Function(`with(this){ ${compliedCode} }`), depItems: depEleMap };
3975
4011
  }
3976
4012
  catch (e) {
3977
- this.expressFn = new Function();
4013
+ console.error('解析表达式出错,parseEleExpression', this.props.expression);
4014
+ }
4015
+ }
4016
+ /**
4017
+ * 元素可见行求值
4018
+ * @param ele
4019
+ * @param executeCtx
4020
+ * @private
4021
+ */
4022
+ evalEleExpr(executeCtx) {
4023
+ if (this.parserExpress && this.parserExpress.func) {
4024
+ try {
4025
+ executeCtx.setCurrentCtx(this, this.parserExpress.depItems);
4026
+ const func = this.parserExpress.func.bind(executeCtx);
4027
+ func();
4028
+ }
4029
+ catch (e) {
4030
+ console.error(e, "表达式执行出错:evalVisibleExpr", this.parserExpress.compliedCode);
4031
+ }
4032
+ finally {
4033
+ executeCtx.clearCurrentCtx();
4034
+ }
3978
4035
  }
3979
4036
  }
3980
4037
  /**
@@ -8609,7 +8666,7 @@ class DataElementGroupElement extends InlineGroupInputElement {
8609
8666
  return {
8610
8667
  type: this.type,
8611
8668
  props: {
8612
- ...this.props.getSerializeProps()
8669
+ ...this.props.getSerializeProps(viewOptions)
8613
8670
  }
8614
8671
  };
8615
8672
  }
@@ -8631,9 +8688,7 @@ class DataElementGroupFactory extends DataElementBaseFactory {
8631
8688
  createElement(data) {
8632
8689
  const props = data.props;
8633
8690
  const ele = new DataElementGroupElement();
8634
- ele.props.id = props.id;
8635
- ele.props.name = props.name;
8636
- ele.props.hidden = Boolean(props.hidden);
8691
+ ElementUtil.readEleBaseProps(ele.props, props);
8637
8692
  return ele;
8638
8693
  }
8639
8694
  }
@@ -8938,7 +8993,11 @@ class DataElementText extends DataElementInlineGroup {
8938
8993
  super('data-ele-text');
8939
8994
  this.props = new DataEleBaseTextProps();
8940
8995
  }
8941
- createRenderObject() {
8996
+ createRenderObject(data) {
8997
+ if (data.options.enableDyExpression) {
8998
+ this.parseEleExpression(data);
8999
+ this.evalEleExpr(data.execute);
9000
+ }
8942
9001
  return new DataElementTextRenderObject(this);
8943
9002
  }
8944
9003
  serialize(viewOptions) {
@@ -13896,7 +13955,7 @@ class ParagraphMeasure {
13896
13955
  }
13897
13956
  }
13898
13957
  arrangeInlineGroupElement(parentLine, ele) {
13899
- const { options, renderCtx } = this;
13958
+ const { options, renderCtx, execute } = this;
13900
13959
  let render = this.createRenderObject(ele);
13901
13960
  //记录多行情况下的渲染对象,用于计算总长度,生成fill-null-space
13902
13961
  const inlineGroupRenders = [];
@@ -13932,7 +13991,7 @@ class ParagraphMeasure {
13932
13991
  isCloseToBody: parentLine.isCloseToBody,
13933
13992
  applyNewLine() {
13934
13993
  parentLine.applyNewLine();
13935
- render = ele.createRenderObject({ options, renderCtx });
13994
+ render = ele.createRenderObject({ options, renderCtx, execute });
13936
13995
  parentLine.add(render);
13937
13996
  inlineGroupRenders.push(render);
13938
13997
  },
@@ -14267,7 +14326,8 @@ class ParagraphMeasure {
14267
14326
  }
14268
14327
  return element.createRenderObject({
14269
14328
  options: this.options,
14270
- renderCtx: this.renderCtx
14329
+ renderCtx: this.renderCtx,
14330
+ execute: this.execute
14271
14331
  });
14272
14332
  }
14273
14333
  }
@@ -14426,8 +14486,9 @@ class DocumentArrange {
14426
14486
  this.pMeasure = new ParagraphMeasure(this.options, this.renderCtx, this.execute);
14427
14487
  const data = {
14428
14488
  doc,
14429
- viewOptions: this.options,
14489
+ options: this.options,
14430
14490
  execute: this.execute,
14491
+ renderCtx: this.renderCtx,
14431
14492
  createParaFn: () => this.createDefaultPara()
14432
14493
  };
14433
14494
  this.reset(data);
@@ -14630,7 +14691,7 @@ class DocumentArrange {
14630
14691
  if (this.options.textRowLineMode && ele instanceof TableElement && ele.cacheRender) {
14631
14692
  const cacheRender = ele.cacheRender;
14632
14693
  clearChildrenRenderCache(ele);
14633
- textLineRenderMode(cacheRender, { options: this.options, renderCtx: this.renderCtx });
14694
+ textLineRenderMode(cacheRender, { options: this.options, renderCtx: this.renderCtx, execute: this.execute });
14634
14695
  }
14635
14696
  }
14636
14697
  getDocInnerRect(documentRender) {
@@ -17070,6 +17131,8 @@ class DocumentChange {
17070
17131
  if (text.props.fontSize !== this.viewOptions.currentFontSize || text.props.fontName !== this.viewOptions.currentFontName) {
17071
17132
  //创建新输入项
17072
17133
  const newInput = this.createNewInputText();
17134
+ this.viewOptions.currentFontName = newInput.props.fontName;
17135
+ this.viewOptions.currentFontSize = newInput.props.fontSize;
17073
17136
  //插入到文档
17074
17137
  this.insertElement(element, offset, [newInput]);
17075
17138
  this.correctInputEle(newInput, '', 0, data);
@@ -19446,7 +19509,7 @@ class EditorCalendarVNode {
19446
19509
  data: {
19447
19510
  style: {
19448
19511
  position: 'absolute',
19449
- left: (position.x - 10) + 'px',
19512
+ left: (position.x) + 'px',
19450
19513
  top: position.y + 5 + position.height + 'px',
19451
19514
  'min-width': '100px',
19452
19515
  'background-color': 'white',
@@ -19582,6 +19645,9 @@ class EditorCalendarVNode {
19582
19645
  on: {
19583
19646
  click: () => {
19584
19647
  this.onClickDayItem(day.date);
19648
+ },
19649
+ dblclick: () => {
19650
+ this.onSave();
19585
19651
  }
19586
19652
  }
19587
19653
  },
@@ -19639,12 +19705,7 @@ class EditorCalendarVNode {
19639
19705
  data: {
19640
19706
  on: {
19641
19707
  click: () => {
19642
- if (!this.selectedDate.value) {
19643
- this.onSetValue.next(new Date());
19644
- }
19645
- else {
19646
- this.onSetValue.next(moment__default["default"](this.selectedDate.value + ' ' + this.selectedTime.value).toDate());
19647
- }
19708
+ this.onSave();
19648
19709
  }
19649
19710
  }
19650
19711
  },
@@ -19664,6 +19725,14 @@ class EditorCalendarVNode {
19664
19725
  ]
19665
19726
  };
19666
19727
  }
19728
+ onSave() {
19729
+ if (!this.selectedDate.value) {
19730
+ this.onSetValue.next(new Date());
19731
+ }
19732
+ else {
19733
+ this.onSetValue.next(moment__default["default"](this.selectedDate.value + ' ' + this.selectedTime.value).toDate());
19734
+ }
19735
+ }
19667
19736
  navigateToToday() {
19668
19737
  this.currYear.value = new Date().getFullYear();
19669
19738
  this.currMonth.value = new Date().getMonth();
@@ -20376,7 +20445,6 @@ class DocEditor {
20376
20445
  beforeRenderSubject = new Subject();
20377
20446
  afterRenderSubject = new Subject();
20378
20447
  onBeforeSetCursorSubject = new Subject();
20379
- contentChanged = new Subject();
20380
20448
  onPatchVNodeSubject = new Subject();
20381
20449
  selectionState;
20382
20450
  onDblClickEvent = new Subject();
@@ -20668,10 +20736,12 @@ class DocEditor {
20668
20736
  }
20669
20737
  loadDoc(data) {
20670
20738
  suppressTracking(() => {
20671
- this.adjustPageLayout();
20672
- this.elementReader.read(data);
20673
- this.refreshDocument();
20674
- this.historyMange.clear();
20739
+ this.noEffectChange(() => {
20740
+ this.adjustPageLayout();
20741
+ this.elementReader.read(data);
20742
+ this.refreshDocument();
20743
+ this.historyMange.clear();
20744
+ });
20675
20745
  });
20676
20746
  }
20677
20747
  /**
@@ -20689,7 +20759,6 @@ class DocEditor {
20689
20759
  suppressTracking(() => {
20690
20760
  this.documentPaginator.rePages();
20691
20761
  });
20692
- this.contentChanged.next();
20693
20762
  }
20694
20763
  this.updateSelection();
20695
20764
  this.setCursor();
@@ -21592,7 +21661,7 @@ class DocEditor {
21592
21661
  const scaleFitContainer = {
21593
21662
  sel: 'div#scale-fit-container',
21594
21663
  data: {
21595
- style: { overflow: 'hidden', height: '0px', }
21664
+ style: { height: '0px', }
21596
21665
  },
21597
21666
  children: [docContent]
21598
21667
  };
@@ -21754,7 +21823,7 @@ class DocEditor {
21754
21823
  data: {
21755
21824
  style: {
21756
21825
  position: 'absolute',
21757
- left: (position.x - 10) + 'px',
21826
+ left: (position.x) + 'px',
21758
21827
  top: position.y + 5 + position.height + 'px',
21759
21828
  },
21760
21829
  hook: {
@@ -21920,7 +21989,7 @@ class DocEditor {
21920
21989
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
21921
21990
  }
21922
21991
  version() {
21923
- return "2.2.5";
21992
+ return "2.2.7";
21924
21993
  }
21925
21994
  switchPageHeaderEditor() {
21926
21995
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -22223,6 +22292,13 @@ class DocEditor {
22223
22292
  this.documentChange.appendText(text, this.docCtx.suggestions.currentMatchedText);
22224
22293
  }
22225
22294
  }
22295
+ parser(code, returnProcess = false) {
22296
+ const res = parser(code);
22297
+ if (returnProcess) {
22298
+ return addReturn(res);
22299
+ }
22300
+ return res;
22301
+ }
22226
22302
  }
22227
22303
 
22228
22304
  /**