@hufe921/canvas-editor 0.9.100 → 0.9.101

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/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## [0.9.101](https://github.com/Hufe921/canvas-editor/compare/v0.9.100...v0.9.101) (2025-01-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * image asynchronous rendering boundary error #959 ([344a6e0](https://github.com/Hufe921/canvas-editor/commit/344a6e038862a290c810ab55b66ae7fcceffecae)), closes [#959](https://github.com/Hufe921/canvas-editor/issues/959)
7
+ * verify the range boundary error of control in the table #959 ([6d55698](https://github.com/Hufe921/canvas-editor/commit/6d55698987d7a4a119b0514560625db09884cd94)), closes [#959](https://github.com/Hufe921/canvas-editor/issues/959)
8
+
9
+
10
+ ### Features
11
+
12
+ * add isSubmitHistory option to setControlValue api #960 ([9c0b67f](https://github.com/Hufe921/canvas-editor/commit/9c0b67f184ebb35cc74dcacc10e44efc39c2c95d)), closes [#960](https://github.com/Hufe921/canvas-editor/issues/960)
13
+ * add option to executeReplace api #969 ([3fbaa3b](https://github.com/Hufe921/canvas-editor/commit/3fbaa3b7cc513336b8278221c639ea651e27155f)), closes [#969](https://github.com/Hufe921/canvas-editor/issues/969)
14
+ * add split table cell api #826 ([04c7194](https://github.com/Hufe921/canvas-editor/commit/04c7194a94845d54456798509846fc2f9a86f807)), closes [#826](https://github.com/Hufe921/canvas-editor/issues/826)
15
+ * not update default range style when unchanged #970 ([21a71c0](https://github.com/Hufe921/canvas-editor/commit/21a71c0cfabaf9e6f0a68ca5ddbe1df49d408ee8)), closes [#970](https://github.com/Hufe921/canvas-editor/issues/970)
16
+
17
+
18
+ ### Performance Improvements
19
+
20
+ * deep clone performance for control data #971 ([71d52de](https://github.com/Hufe921/canvas-editor/commit/71d52de30c63beca806c0a7af0c82c1244d59429)), closes [#971](https://github.com/Hufe921/canvas-editor/issues/971)
21
+
22
+
23
+
1
24
  ## [0.9.100](https://github.com/Hufe921/canvas-editor/compare/v0.9.99...v0.9.100) (2025-01-03)
2
25
 
3
26
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.100";
26
+ const version = "0.9.101";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -242,6 +242,9 @@ function isObject(type) {
242
242
  function isArray(type) {
243
243
  return Array.isArray(type);
244
244
  }
245
+ function isNumber(type) {
246
+ return Object.prototype.toString.call(type) === "[object Number]";
247
+ }
245
248
  function mergeObject(source, target) {
246
249
  if (isObject(source) && isObject(target)) {
247
250
  const objectTarget = target;
@@ -659,6 +662,7 @@ class ImageParticle {
659
662
  const img = this.imageCache.get(element.value);
660
663
  ctx.drawImage(img, x, y, width, height);
661
664
  } else {
665
+ const cacheRenderCount = this.draw.getRenderCount();
662
666
  const imageLoadPromise = new Promise((resolve, reject) => {
663
667
  const img = new Image();
664
668
  img.setAttribute("crossOrigin", "Anonymous");
@@ -666,6 +670,8 @@ class ImageParticle {
666
670
  img.onload = () => {
667
671
  this.imageCache.set(element.value, img);
668
672
  resolve(element);
673
+ if (cacheRenderCount !== this.draw.getRenderCount())
674
+ return;
669
675
  if (element.imgDisplay === ImageDisplay.FLOAT_BOTTOM) {
670
676
  this.draw.render({
671
677
  isCompute: false,
@@ -4299,7 +4305,7 @@ function formatElementList(elementList, options) {
4299
4305
  }
4300
4306
  }
4301
4307
  if (value && value.length || type === ControlType.CHECKBOX || type === ControlType.RADIO || type === ControlType.SELECT && code && (!value || !value.length)) {
4302
- let valueList = value || [];
4308
+ let valueList = value ? deepClone(value) : [];
4303
4309
  if (type === ControlType.CHECKBOX) {
4304
4310
  const codeList = code ? code.split(",") : [];
4305
4311
  if (Array.isArray(valueSets) && valueSets.length) {
@@ -7662,13 +7668,13 @@ function getWordRangeByCursor(host) {
7662
7668
  const LETTER_REG = draw.getLetterReg();
7663
7669
  let upCount = 0;
7664
7670
  let downCount = 0;
7665
- const isNumber = NUMBER_LIKE_REG.test(value);
7666
- if (isNumber || LETTER_REG.test(value)) {
7671
+ const isNumber2 = NUMBER_LIKE_REG.test(value);
7672
+ if (isNumber2 || LETTER_REG.test(value)) {
7667
7673
  const elementList = draw.getElementList();
7668
7674
  let upStartIndex = index2 - 1;
7669
7675
  while (upStartIndex > 0) {
7670
7676
  const value2 = elementList[upStartIndex].value;
7671
- if (isNumber && NUMBER_LIKE_REG.test(value2) || !isNumber && LETTER_REG.test(value2)) {
7677
+ if (isNumber2 && NUMBER_LIKE_REG.test(value2) || !isNumber2 && LETTER_REG.test(value2)) {
7672
7678
  upCount++;
7673
7679
  upStartIndex--;
7674
7680
  } else {
@@ -7678,7 +7684,7 @@ function getWordRangeByCursor(host) {
7678
7684
  let downStartIndex = index2 + 1;
7679
7685
  while (downStartIndex < elementList.length) {
7680
7686
  const value2 = elementList[downStartIndex].value;
7681
- if (isNumber && NUMBER_LIKE_REG.test(value2) || !isNumber && LETTER_REG.test(value2)) {
7687
+ if (isNumber2 && NUMBER_LIKE_REG.test(value2) || !isNumber2 && LETTER_REG.test(value2)) {
7682
7688
  downCount++;
7683
7689
  downStartIndex++;
7684
7690
  } else {
@@ -8799,6 +8805,9 @@ class RangeManager {
8799
8805
  return null;
8800
8806
  return __spreadValues(__spreadValues({}, anchorElement), this.defaultStyle);
8801
8807
  }
8808
+ getIsRangeChange(startIndex, endIndex, tableId, startTdIndex, endTdIndex, startTrIndex, endTrIndex) {
8809
+ return this.range.startIndex !== startIndex || this.range.endIndex !== endIndex || this.range.tableId !== tableId || this.range.startTdIndex !== startTdIndex || this.range.endTdIndex !== endTdIndex || this.range.startTrIndex !== startTrIndex || this.range.endTrIndex !== endTrIndex;
8810
+ }
8802
8811
  getIsCollapsed() {
8803
8812
  const { startIndex, endIndex } = this.range;
8804
8813
  return startIndex === endIndex;
@@ -9055,15 +9064,18 @@ class RangeManager {
9055
9064
  return !startElement.controlId && !endElement.controlId || (!startElement.controlId || startElement.controlComponent === ControlComponent.POSTFIX) && (!endElement.controlId || endElement.controlComponent === ControlComponent.POSTFIX) || !!startElement.controlId && endElement.controlId === startElement.controlId && endElement.controlComponent !== ControlComponent.PRE_TEXT && endElement.controlComponent !== ControlComponent.POST_TEXT && endElement.controlComponent !== ControlComponent.POSTFIX;
9056
9065
  }
9057
9066
  setRange(startIndex, endIndex, tableId, startTdIndex, endTdIndex, startTrIndex, endTrIndex) {
9058
- this.range.startIndex = startIndex;
9059
- this.range.endIndex = endIndex;
9060
- this.range.tableId = tableId;
9061
- this.range.startTdIndex = startTdIndex;
9062
- this.range.endTdIndex = endTdIndex;
9063
- this.range.startTrIndex = startTrIndex;
9064
- this.range.endTrIndex = endTrIndex;
9065
- this.range.isCrossRowCol = !!(startTdIndex || endTdIndex || startTrIndex || endTrIndex);
9066
- this.setDefaultStyle(null);
9067
+ const isChange = this.getIsRangeChange(startIndex, endIndex, tableId, startTdIndex, endTdIndex, startTrIndex, endTrIndex);
9068
+ if (isChange) {
9069
+ this.range.startIndex = startIndex;
9070
+ this.range.endIndex = endIndex;
9071
+ this.range.tableId = tableId;
9072
+ this.range.startTdIndex = startTdIndex;
9073
+ this.range.endTdIndex = endTdIndex;
9074
+ this.range.startTrIndex = startTrIndex;
9075
+ this.range.endTrIndex = endTrIndex;
9076
+ this.range.isCrossRowCol = !!(startTdIndex || endTdIndex || startTrIndex || endTrIndex);
9077
+ this.setDefaultStyle(null);
9078
+ }
9067
9079
  this.range.zone = this.draw.getZone().getZone();
9068
9080
  const control = this.draw.getControl();
9069
9081
  if (~startIndex && ~endIndex) {
@@ -12734,7 +12746,7 @@ class Control {
12734
12746
  const elementList = this.getElementList();
12735
12747
  const startElement = elementList[startIndex];
12736
12748
  const endElement = elementList[endIndex];
12737
- if (startElement.controlId && startElement.controlId === endElement.controlId && endElement.controlComponent !== ControlComponent.POSTFIX) {
12749
+ if ((startElement == null ? void 0 : startElement.controlId) && startElement.controlId === endElement.controlId && endElement.controlComponent !== ControlComponent.POSTFIX) {
12738
12750
  return true;
12739
12751
  }
12740
12752
  return false;
@@ -13228,7 +13240,7 @@ class Control {
13228
13240
  }
13229
13241
  setValueById(payload) {
13230
13242
  let isExistSet = false;
13231
- const { id, conceptId, areaId, value } = payload;
13243
+ const { id, conceptId, areaId, value, isSubmitHistory = true } = payload;
13232
13244
  if (!id && !conceptId)
13233
13245
  return;
13234
13246
  const setValue = (elementList) => {
@@ -13353,7 +13365,11 @@ class Control {
13353
13365
  setValue(elementList);
13354
13366
  }
13355
13367
  if (isExistSet) {
13368
+ if (!isSubmitHistory) {
13369
+ this.draw.getHistoryManager().recovery();
13370
+ }
13356
13371
  this.draw.render({
13372
+ isSubmitHistory,
13357
13373
  isSetCursor: false
13358
13374
  });
13359
13375
  }
@@ -13406,7 +13422,7 @@ class Control {
13406
13422
  }
13407
13423
  }
13408
13424
  setPropertiesById(payload) {
13409
- const { id, conceptId, areaId, properties } = payload;
13425
+ const { id, conceptId, areaId, properties, isSubmitHistory = true } = payload;
13410
13426
  if (!id && !conceptId)
13411
13427
  return;
13412
13428
  let isExistUpdate = false;
@@ -13474,7 +13490,11 @@ class Control {
13474
13490
  });
13475
13491
  }
13476
13492
  this.draw.setEditorData(pageComponentData);
13493
+ if (!isSubmitHistory) {
13494
+ this.draw.getHistoryManager().recovery();
13495
+ }
13477
13496
  this.draw.render({
13497
+ isSubmitHistory,
13478
13498
  isSetCursor: false
13479
13499
  });
13480
13500
  }
@@ -16354,6 +16374,115 @@ class TableOperate {
16354
16374
  this.draw.render();
16355
16375
  this.tableTool.render();
16356
16376
  }
16377
+ splitVerticalTableCell() {
16378
+ const positionContext = this.position.getPositionContext();
16379
+ if (!positionContext.isTable)
16380
+ return;
16381
+ const range = this.range.getRange();
16382
+ if (range.isCrossRowCol)
16383
+ return;
16384
+ const { index: index2, tdIndex, trIndex } = positionContext;
16385
+ const originalElementList = this.draw.getOriginalElementList();
16386
+ const element = originalElementList[index2];
16387
+ const curTrList = element.trList;
16388
+ const curTr = curTrList[trIndex];
16389
+ const curTd = curTr.tdList[tdIndex];
16390
+ element.colgroup.splice(tdIndex + 1, 0, {
16391
+ width: this.options.table.defaultColMinWidth
16392
+ });
16393
+ for (let t = 0; t < curTrList.length; t++) {
16394
+ const tr = curTrList[t];
16395
+ let d = 0;
16396
+ while (d < tr.tdList.length) {
16397
+ const td = tr.tdList[d];
16398
+ if (td.rowIndex !== curTd.rowIndex) {
16399
+ if (td.colIndex <= curTd.colIndex && td.colIndex + td.colspan > curTd.colIndex) {
16400
+ td.colspan++;
16401
+ }
16402
+ } else {
16403
+ if (td.id === curTd.id) {
16404
+ const tdId = getUUID();
16405
+ curTr.tdList.splice(d + curTd.colspan, 0, {
16406
+ id: tdId,
16407
+ rowspan: curTd.rowspan,
16408
+ colspan: 1,
16409
+ value: [
16410
+ {
16411
+ value: ZERO,
16412
+ size: 16,
16413
+ tableId: element.id,
16414
+ trId: tr.id,
16415
+ tdId
16416
+ }
16417
+ ]
16418
+ });
16419
+ d++;
16420
+ }
16421
+ }
16422
+ d++;
16423
+ }
16424
+ }
16425
+ this.draw.render();
16426
+ this.tableTool.render();
16427
+ }
16428
+ splitHorizontalTableCell() {
16429
+ const positionContext = this.position.getPositionContext();
16430
+ if (!positionContext.isTable)
16431
+ return;
16432
+ const range = this.range.getRange();
16433
+ if (range.isCrossRowCol)
16434
+ return;
16435
+ const { index: index2, tdIndex, trIndex } = positionContext;
16436
+ const originalElementList = this.draw.getOriginalElementList();
16437
+ const element = originalElementList[index2];
16438
+ const curTrList = element.trList;
16439
+ const curTr = curTrList[trIndex];
16440
+ const curTd = curTr.tdList[tdIndex];
16441
+ let appendTrIndex = -1;
16442
+ let t = 0;
16443
+ while (t < curTrList.length) {
16444
+ if (t === appendTrIndex) {
16445
+ t++;
16446
+ continue;
16447
+ }
16448
+ const tr = curTrList[t];
16449
+ let d = 0;
16450
+ while (d < tr.tdList.length) {
16451
+ const td = tr.tdList[d];
16452
+ if (td.id === curTd.id) {
16453
+ const trId = getUUID();
16454
+ const tdId = getUUID();
16455
+ curTrList.splice(t + curTd.rowspan, 0, {
16456
+ id: trId,
16457
+ height: this.options.table.defaultTrMinHeight,
16458
+ tdList: [
16459
+ {
16460
+ id: tdId,
16461
+ rowspan: 1,
16462
+ colspan: curTd.colspan,
16463
+ value: [
16464
+ {
16465
+ value: ZERO,
16466
+ size: 16,
16467
+ tableId: element.id,
16468
+ trId,
16469
+ tdId
16470
+ }
16471
+ ]
16472
+ }
16473
+ ]
16474
+ });
16475
+ appendTrIndex = t + curTd.rowspan;
16476
+ } else if (td.rowIndex >= curTd.rowIndex && td.rowIndex < curTd.rowIndex + curTd.rowspan && td.rowIndex + td.rowspan >= curTd.rowIndex + curTd.rowspan) {
16477
+ td.rowspan++;
16478
+ }
16479
+ d++;
16480
+ }
16481
+ t++;
16482
+ }
16483
+ this.draw.render();
16484
+ this.tableTool.render();
16485
+ }
16357
16486
  tableTdVerticalAlign(payload) {
16358
16487
  const rowCol = this.tableParticle.getRangeRowCol();
16359
16488
  if (!rowCol)
@@ -16760,6 +16889,7 @@ class Draw {
16760
16889
  __publicField(this, "pageList");
16761
16890
  __publicField(this, "ctxList");
16762
16891
  __publicField(this, "pageNo");
16892
+ __publicField(this, "renderCount");
16763
16893
  __publicField(this, "pagePixelRatio");
16764
16894
  __publicField(this, "mode");
16765
16895
  __publicField(this, "options");
@@ -16828,6 +16958,7 @@ class Draw {
16828
16958
  this.pageList = [];
16829
16959
  this.ctxList = [];
16830
16960
  this.pageNo = 0;
16961
+ this.renderCount = 0;
16831
16962
  this.pagePixelRatio = null;
16832
16963
  this.mode = options.mode;
16833
16964
  this.options = options;
@@ -17095,6 +17226,9 @@ class Draw {
17095
17226
  setPageNo(payload) {
17096
17227
  this.pageNo = payload;
17097
17228
  }
17229
+ getRenderCount() {
17230
+ return this.renderCount;
17231
+ }
17098
17232
  getPage(pageNo = -1) {
17099
17233
  return this.pageList[~pageNo ? pageNo : this.pageNo];
17100
17234
  }
@@ -17772,6 +17906,7 @@ class Draw {
17772
17906
  for (let t = 0; t < trList.length; t++) {
17773
17907
  const tr = trList[t];
17774
17908
  tr.height = tr.minHeight || defaultTrMinHeight;
17909
+ tr.minHeight = tr.height;
17775
17910
  }
17776
17911
  this.tableParticle.computeRowColInfo(element);
17777
17912
  for (let t = 0; t < trList.length; t++) {
@@ -18547,6 +18682,7 @@ class Draw {
18547
18682
  }
18548
18683
  }
18549
18684
  render(payload) {
18685
+ this.renderCount++;
18550
18686
  const { header, footer } = this.options;
18551
18687
  const { isSubmitHistory = true, isSetCursor = true, isCompute = true, isLazy = true, isInit = false, isSourceHistory = false, isFirstRender = false } = payload || {};
18552
18688
  let { curIndex } = payload || {};
@@ -18758,6 +18894,8 @@ class Command {
18758
18894
  __publicField(this, "executeDeleteTable");
18759
18895
  __publicField(this, "executeMergeTableCell");
18760
18896
  __publicField(this, "executeCancelMergeTableCell");
18897
+ __publicField(this, "executeSplitVerticalTableCell");
18898
+ __publicField(this, "executeSplitHorizontalTableCell");
18761
18899
  __publicField(this, "executeTableTdVerticalAlign");
18762
18900
  __publicField(this, "executeTableBorderType");
18763
18901
  __publicField(this, "executeTableBorderColor");
@@ -18884,6 +19022,8 @@ class Command {
18884
19022
  this.executeDeleteTable = adapt.deleteTable.bind(adapt);
18885
19023
  this.executeMergeTableCell = adapt.mergeTableCell.bind(adapt);
18886
19024
  this.executeCancelMergeTableCell = adapt.cancelMergeTableCell.bind(adapt);
19025
+ this.executeSplitVerticalTableCell = adapt.splitVerticalTableCell.bind(adapt);
19026
+ this.executeSplitHorizontalTableCell = adapt.splitHorizontalTableCell.bind(adapt);
18887
19027
  this.executeTableTdVerticalAlign = adapt.tableTdVerticalAlign.bind(adapt);
18888
19028
  this.executeTableBorderType = adapt.tableBorderType.bind(adapt);
18889
19029
  this.executeTableBorderColor = adapt.tableBorderColor.bind(adapt);
@@ -19810,6 +19950,18 @@ class CommandAdapt {
19810
19950
  return;
19811
19951
  this.tableOperate.cancelMergeTableCell();
19812
19952
  }
19953
+ splitVerticalTableCell() {
19954
+ const isReadonly = this.draw.isReadonly();
19955
+ if (isReadonly)
19956
+ return;
19957
+ this.tableOperate.splitVerticalTableCell();
19958
+ }
19959
+ splitHorizontalTableCell() {
19960
+ const isReadonly = this.draw.isReadonly();
19961
+ if (isReadonly)
19962
+ return;
19963
+ this.tableOperate.splitHorizontalTableCell();
19964
+ }
19813
19965
  tableTdVerticalAlign(payload) {
19814
19966
  const isReadonly = this.draw.isReadonly();
19815
19967
  if (isReadonly)
@@ -20111,14 +20263,27 @@ class CommandAdapt {
20111
20263
  getSearchNavigateInfo() {
20112
20264
  return this.searchManager.getSearchNavigateInfo();
20113
20265
  }
20114
- replace(payload) {
20266
+ replace(payload, option) {
20115
20267
  const isReadonly = this.draw.isReadonly();
20116
20268
  if (isReadonly)
20117
20269
  return;
20118
20270
  if (!payload || new RegExp(`${ZERO}`, "g").test(payload))
20119
20271
  return;
20120
- const matchList = this.draw.getSearch().getSearchMatchList();
20121
- if (!matchList.length)
20272
+ let matchList = this.draw.getSearch().getSearchMatchList();
20273
+ const replaceIndex = option == null ? void 0 : option.index;
20274
+ if (isNumber(replaceIndex)) {
20275
+ const matchGroup = [];
20276
+ matchList.forEach((match) => {
20277
+ const last = matchGroup[matchGroup.length - 1];
20278
+ if (!last || last[0].groupId !== match.groupId) {
20279
+ matchGroup.push([match]);
20280
+ } else {
20281
+ last.push(match);
20282
+ }
20283
+ });
20284
+ matchList = matchGroup[replaceIndex];
20285
+ }
20286
+ if (!(matchList == null ? void 0 : matchList.length))
20122
20287
  return;
20123
20288
  let pageDiffCount = 0;
20124
20289
  let tableDiffCount = 0;