@hailin-zheng/editor-core 1.1.6 → 1.1.8

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
@@ -4172,15 +4172,10 @@ class TableUtil {
4172
4172
  const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
4173
4173
  if (vMergeEndIndex > rowIndex) {
4174
4174
  const nextRow = tb.getChild(rowIndex + 1);
4175
- nextRow.getChild(i).props.vMerge = vMergeEndIndex - rowIndex > 2 ? 'restart' : null;
4175
+ nextRow.getChild(i).props.vMerge = vMergeEndIndex - rowIndex > 1 ? 'restart' : null;
4176
4176
  }
4177
4177
  }
4178
4178
  else if (cell.props.vMerge === 'continue') {
4179
- // const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
4180
- // if (vMergeEndIndex > rowIndex) {
4181
- // const nextRow = tb.getChild<TableRowElement>(rowIndex + 1);
4182
- // nextRow.getChild<TableCellElement>(i).cellProps.vMerge = 'continue';
4183
- // }
4184
4179
  const vMergeStartIndex = this.getVMergeStartIndex(tb, rowIndex, i);
4185
4180
  const vMergeEndIndex = this.getVMergeEndIndex(tb, rowIndex, i);
4186
4181
  //当前单元格处于合并行的最后一行,并且合并的行数为2行
@@ -4293,6 +4288,13 @@ class TableUtil {
4293
4288
  currCell.props.vMerge = i === tbRegion.startRow ? 'restart' : 'continue';
4294
4289
  currCell.props.hMerge = 'restart';
4295
4290
  }
4291
+ //选择的行数一行,此时纵向合并不需要设置
4292
+ if (tbRegion.endRow === tbRegion.startRow) {
4293
+ currCell.props.vMerge = null;
4294
+ }
4295
+ if (tbRegion.startCol === tbRegion.endCol) {
4296
+ currCell.props.hMerge = null;
4297
+ }
4296
4298
  if (currCell !== startCell) {
4297
4299
  cellContents.push(...ElementUtil.getChildrenElements(currCell));
4298
4300
  currCell.clearItems();
@@ -4432,6 +4434,13 @@ class TableUtil {
4432
4434
  tb.pubOnChange('self');
4433
4435
  tb.refreshView();
4434
4436
  }
4437
+ /**
4438
+ * 在指定位置插入行
4439
+ * 动作:在指定行上方或者下方插入行
4440
+ * 原则:插入的行单元格尽量不纵向合并
4441
+ * @param ss
4442
+ * @param insertRowIndex
4443
+ */
4435
4444
  static insertRow(ss, insertRowIndex) {
4436
4445
  const startCell = ElementUtil.getParentByType(ss.startControl, TableCellElement);
4437
4446
  if (!startCell?.parent) {
@@ -4439,7 +4448,7 @@ class TableUtil {
4439
4448
  }
4440
4449
  const startRow = startCell.parent;
4441
4450
  const tb = startRow.parent;
4442
- const currRowIndex = startRow.getIndex();
4451
+ startRow.getIndex();
4443
4452
  insertRowIndex = insertRowIndex < 0 ? 0 : insertRowIndex;
4444
4453
  insertRowIndex = insertRowIndex > tb.length ? tb.length : insertRowIndex;
4445
4454
  const newRow = TableRowElement.createRow(tb.getColsCount());
@@ -4457,16 +4466,12 @@ class TableUtil {
4457
4466
  if (destCell.props.vMerge === 'continue') {
4458
4467
  //获取合并列的最后的行索引
4459
4468
  const vMergeEndRowIndex = this.getVMergeEndIndex(tb, insertRowIndex, i);
4460
- if (vMergeEndRowIndex > insertRowIndex || (vMergeEndRowIndex === insertRowIndex && currRowIndex < insertRowIndex)) {
4469
+ //当前单元格处于纵向合并的单元格之中
4470
+ if (vMergeEndRowIndex >= insertRowIndex) {
4461
4471
  newCell.props.vMerge = 'continue';
4462
- //newCell.cellProps.hMerge = destCell.cellProps.hMerge;
4463
4472
  }
4464
4473
  }
4465
- else if (destCell.props.vMerge === 'restart' && currRowIndex > insertRowIndex) {
4466
- //在上方新增行,目标行单元格属于合并的起点
4467
- newCell.props.vMerge = 'continue';
4468
- //newCell.cellProps.hMerge = destCell.cellProps.hMerge;
4469
- }
4474
+ newCell.props.hMerge = destCell.props.hMerge;
4470
4475
  }
4471
4476
  tb.addChild(newRow, insertRowIndex);
4472
4477
  tb.refreshView();
@@ -5167,6 +5172,11 @@ class TextGroupFactory extends ElementFactory {
5167
5172
  }
5168
5173
 
5169
5174
  class ElementSerialize {
5175
+ /**
5176
+ * 将当前文档对象构建并输出到标准的JSON对象
5177
+ * @param element
5178
+ * @param viewOptions
5179
+ */
5170
5180
  static serialize(element, viewOptions) {
5171
5181
  if (element instanceof BranchElement) {
5172
5182
  const result = element.serialize(viewOptions);
@@ -7967,7 +7977,7 @@ class DataElementDate extends DataElementInlineGroup {
7967
7977
  return res;
7968
7978
  }
7969
7979
  const format = this.props.format ?? 'YYYY-MM-DD';
7970
- const date = moment(this.getValue(), format);
7980
+ const date = moment(this.getValue(), format, true);
7971
7981
  if (!date.isValid()) {
7972
7982
  return '日期格式不正确';
7973
7983
  }
@@ -13682,24 +13692,6 @@ class DocumentEvent {
13682
13692
  this.editor.addEventListener('contextmenu', evt => {
13683
13693
  this.contextMenu.next(evt.sourceEvt);
13684
13694
  });
13685
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'mousedown').subscribe((evt) => {
13686
- // this.mousedown(evt);
13687
- // }));
13688
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'mouseup').subscribe((evt) => {
13689
- // this.mouseup(evt);
13690
- // }));
13691
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'click').subscribe((evt) => {
13692
- // this.mouseClickHandle(evt);
13693
- // }));
13694
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'contextmenu').subscribe((evt) => {
13695
- // this.contextMenu.next(evt);
13696
- // }));
13697
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'mousemove').subscribe((evt) => {
13698
- // this.mousemove(evt);
13699
- // }));
13700
- // this.addSubEvent(fromEvent<MouseEvent>(this.canvas, 'dblclick').subscribe((evt) => {
13701
- // this.mouseDblClickHandle(evt);
13702
- // }));
13703
13695
  this.documentInput.onLeftEvent.subscribe(() => {
13704
13696
  this.moveCursorToLeft();
13705
13697
  });
@@ -14443,17 +14435,27 @@ class DocumentEvent {
14443
14435
  const moveDistanceX = this.currentPos.x - mousedownPos.x;
14444
14436
  const moveDistanceY = this.currentPos.y - mousedownPos.y;
14445
14437
  const row = cellElement.parent;
14438
+ const minColWidth = 20;
14446
14439
  const table = row?.parent;
14447
14440
  if (!row || !table) {
14448
14441
  throw new Error('row | table is null');
14449
14442
  }
14450
14443
  const cellIndex = row.getChildIndex(cellElement);
14451
14444
  let cellWidth = table.getCellWidth(cellIndex);
14452
- table.getColsCount();
14453
14445
  if (['left', 'right'].includes(border)) {
14454
14446
  if (cellIndex === 0 && border === 'left') {
14455
14447
  return;
14456
14448
  }
14449
+ //当前操作的是表格的最后一列
14450
+ if (cellIndex === table.getColsCount() - 1 && border === 'right') {
14451
+ cellWidth += moveDistanceX;
14452
+ if (cellWidth < minColWidth) {
14453
+ return;
14454
+ }
14455
+ table.setCellWidth(cellIndex, cellWidth);
14456
+ this.edgeRenderInfo.mousedownPos = this.currentPos;
14457
+ return;
14458
+ }
14457
14459
  let resizeColWidth = 0;
14458
14460
  let resizeColIndex = 0;
14459
14461
  if (border === 'left') {
@@ -14471,14 +14473,13 @@ class DocumentEvent {
14471
14473
  }
14472
14474
  cellWidth += moveDistanceX;
14473
14475
  }
14474
- if (resizeColWidth < 20 || cellWidth < 20) {
14476
+ if (resizeColWidth < minColWidth || cellWidth < minColWidth) {
14475
14477
  return;
14476
14478
  }
14477
14479
  console.log(resizeColWidth, cellWidth);
14478
14480
  table.setCellWidth(resizeColIndex, resizeColWidth);
14479
14481
  table.setCellWidth(cellIndex, cellWidth);
14480
14482
  this.edgeRenderInfo.mousedownPos = this.currentPos;
14481
- table.pubOnChange('self');
14482
14483
  }
14483
14484
  else if (['bottom', 'top'].includes(border)) {
14484
14485
  let rowIndex = row.getIndex();
@@ -21142,6 +21143,36 @@ class CanvasTextEditor extends AbsolutePanel {
21142
21143
  appCtx.root.setInputPosition(caretPos);
21143
21144
  }
21144
21145
  }
21146
+ generatorDoc(data) {
21147
+ //根据传入的参数,动态生成病情信息的结构化报告
21148
+ const para = new ParagraphElement();
21149
+ //创建患者姓名文本标签
21150
+ const patNameLabel = new TextGroupElement();
21151
+ patNameLabel.text = "患者姓名:";
21152
+ //添加到段落中
21153
+ para.addChild(patNameLabel);
21154
+ //创建患者姓名数据元
21155
+ const patNameDataEle = new DataElementText();
21156
+ patNameDataEle.props.valueTextProps = new TextProps();
21157
+ patNameDataEle.props.valueTextProps.fontName = '宋体';
21158
+ patNameDataEle.props.valueTextProps.fontSize = 16;
21159
+ //数据元赋值
21160
+ patNameDataEle.setValue(data.patName);
21161
+ //添加到段落中
21162
+ para.addChild(patNameDataEle);
21163
+ //添加到正文中
21164
+ this.docCtx.document.bodyElement.addChild(para);
21165
+ }
21166
+ /**
21167
+ * 设置关键字
21168
+ * 匹配用户输入的关键字,回调到应用业务中处理
21169
+ */
21170
+ setKeywords(keys, cb) {
21171
+ }
21172
+ /**
21173
+ * 注册编辑器格式读取器
21174
+ */
21175
+ registerReaderFactory(handler) { }
21145
21176
  }
21146
21177
 
21147
21178
  /**