@hufe921/canvas-editor 0.9.98 → 0.9.100

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/canvas-editor.es.js +311 -76
  3. package/dist/canvas-editor.es.js.map +1 -1
  4. package/dist/canvas-editor.umd.js +31 -31
  5. package/dist/canvas-editor.umd.js.map +1 -1
  6. package/dist/src/editor/core/command/Command.d.ts +2 -0
  7. package/dist/src/editor/core/command/CommandAdapt.d.ts +5 -2
  8. package/dist/src/editor/core/draw/Draw.d.ts +3 -0
  9. package/dist/src/editor/core/draw/control/Control.d.ts +1 -0
  10. package/dist/src/editor/core/draw/control/number/NumberControl.d.ts +3 -0
  11. package/dist/src/editor/core/draw/frame/Badge.d.ts +14 -0
  12. package/dist/src/editor/core/draw/interactive/Area.d.ts +1 -0
  13. package/dist/src/editor/core/event/CanvasEvent.d.ts +2 -1
  14. package/dist/src/editor/dataset/constant/Badge.d.ts +2 -0
  15. package/dist/src/editor/dataset/enum/Common.d.ts +4 -0
  16. package/dist/src/editor/dataset/enum/Control.d.ts +2 -1
  17. package/dist/src/editor/index.d.ts +4 -3
  18. package/dist/src/editor/interface/Badge.d.ts +15 -0
  19. package/dist/src/editor/interface/Control.d.ts +7 -1
  20. package/dist/src/editor/interface/Editor.d.ts +2 -0
  21. package/dist/src/editor/interface/Element.d.ts +4 -1
  22. package/dist/src/editor/utils/ua.d.ts +1 -0
  23. package/package.json +1 -1
  24. /package/dist/src/editor/core/draw/particle/{PageBreak.d.ts → PageBreakParticle.d.ts} +0 -0
  25. /package/dist/src/editor/core/draw/particle/{Separator.d.ts → SeparatorParticle.d.ts} +0 -0
  26. /package/dist/src/editor/core/draw/particle/{Subscript.d.ts → SubscriptParticle.d.ts} +0 -0
  27. /package/dist/src/editor/core/draw/particle/{Superscript.d.ts → SuperscriptParticle.d.ts} +0 -0
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.98";
26
+ const version = "0.9.100";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -48,6 +48,11 @@ var LocationPosition;
48
48
  LocationPosition2["BEFORE"] = "before";
49
49
  LocationPosition2["AFTER"] = "after";
50
50
  })(LocationPosition || (LocationPosition = {}));
51
+ var FlexDirection;
52
+ (function(FlexDirection2) {
53
+ FlexDirection2["ROW"] = "row";
54
+ FlexDirection2["COLUMN"] = "column";
55
+ })(FlexDirection || (FlexDirection = {}));
51
56
  const ZERO = "\u200B";
52
57
  const WRAP = "\n";
53
58
  const NBSP = " ";
@@ -407,6 +412,9 @@ var MoveDirection;
407
412
  MoveDirection2["LEFT"] = "left";
408
413
  MoveDirection2["RIGHT"] = "right";
409
414
  })(MoveDirection || (MoveDirection = {}));
415
+ const isApple = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent);
416
+ const isIOS = typeof navigator !== "undefined" && /iPad|iPhone/.test(navigator.userAgent);
417
+ const isMobile = /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
410
418
  var ElementType;
411
419
  (function(ElementType2) {
412
420
  ElementType2["TEXT"] = "text";
@@ -647,8 +655,8 @@ class ImageParticle {
647
655
  const { scale } = this.options;
648
656
  const width = element.width * scale;
649
657
  const height = element.height * scale;
650
- if (this.imageCache.has(element.id)) {
651
- const img = this.imageCache.get(element.id);
658
+ if (this.imageCache.has(element.value)) {
659
+ const img = this.imageCache.get(element.value);
652
660
  ctx.drawImage(img, x, y, width, height);
653
661
  } else {
654
662
  const imageLoadPromise = new Promise((resolve, reject) => {
@@ -656,7 +664,7 @@ class ImageParticle {
656
664
  img.setAttribute("crossOrigin", "Anonymous");
657
665
  img.src = element.value;
658
666
  img.onload = () => {
659
- this.imageCache.set(element.id, img);
667
+ this.imageCache.set(element.value, img);
660
668
  resolve(element);
661
669
  if (element.imgDisplay === ImageDisplay.FLOAT_BOTTOM) {
662
670
  this.draw.render({
@@ -672,7 +680,7 @@ class ImageParticle {
672
680
  const fallbackImage = this.getFallbackImage(width, height);
673
681
  fallbackImage.onload = () => {
674
682
  ctx.drawImage(fallbackImage, x, y, width, height);
675
- this.imageCache.set(element.id, fallbackImage);
683
+ this.imageCache.set(element.value, fallbackImage);
676
684
  };
677
685
  reject(error);
678
686
  };
@@ -3771,6 +3779,7 @@ var ControlType;
3771
3779
  ControlType2["CHECKBOX"] = "checkbox";
3772
3780
  ControlType2["RADIO"] = "radio";
3773
3781
  ControlType2["DATE"] = "date";
3782
+ ControlType2["NUMBER"] = "number";
3774
3783
  })(ControlType || (ControlType = {}));
3775
3784
  var ControlComponent;
3776
3785
  (function(ControlComponent2) {
@@ -3990,6 +3999,10 @@ var RenderMode;
3990
3999
  RenderMode2["SPEED"] = "speed";
3991
4000
  RenderMode2["COMPATIBILITY"] = "compatibility";
3992
4001
  })(RenderMode || (RenderMode = {}));
4002
+ const defaultBadgeOption = {
4003
+ top: 0,
4004
+ left: 5
4005
+ };
3993
4006
  function mergeOption(options = {}) {
3994
4007
  const tableOptions = __spreadValues(__spreadValues({}, defaultTableOption), options.table);
3995
4008
  const headerOptions = __spreadValues(__spreadValues({}, defaultHeaderOption), options.header);
@@ -4010,6 +4023,7 @@ function mergeOption(options = {}) {
4010
4023
  const separatorOptions = __spreadValues(__spreadValues({}, defaultSeparatorOption), options.separator);
4011
4024
  const lineNumberOptions = __spreadValues(__spreadValues({}, defaultLineNumberOption), options.lineNumber);
4012
4025
  const pageBorderOptions = __spreadValues(__spreadValues({}, defaultPageBorderOption), options.pageBorder);
4026
+ const badgeOptions = __spreadValues(__spreadValues({}, defaultBadgeOption), options.badge);
4013
4027
  return __spreadProps(__spreadValues({
4014
4028
  mode: EditorMode.EDIT,
4015
4029
  defaultType: "TEXT",
@@ -4070,7 +4084,8 @@ function mergeOption(options = {}) {
4070
4084
  lineBreak: lineBreakOptions,
4071
4085
  separator: separatorOptions,
4072
4086
  lineNumber: lineNumberOptions,
4073
- pageBorder: pageBorderOptions
4087
+ pageBorder: pageBorderOptions,
4088
+ badge: badgeOptions
4074
4089
  });
4075
4090
  }
4076
4091
  function unzipElementList(elementList) {
@@ -4179,13 +4194,13 @@ function formatElementList(elementList, options) {
4179
4194
  }
4180
4195
  i--;
4181
4196
  } else if (el.type === ElementType.TABLE) {
4182
- const tableId = getUUID();
4197
+ const tableId = el.id || getUUID();
4183
4198
  el.id = tableId;
4184
4199
  if (el.trList) {
4185
4200
  const { defaultTrMinHeight } = editorOptions.table;
4186
4201
  for (let t = 0; t < el.trList.length; t++) {
4187
4202
  const tr = el.trList[t];
4188
- const trId = getUUID();
4203
+ const trId = tr.id || getUUID();
4189
4204
  tr.id = trId;
4190
4205
  if (!tr.minHeight || tr.minHeight < defaultTrMinHeight) {
4191
4206
  tr.minHeight = defaultTrMinHeight;
@@ -4195,7 +4210,7 @@ function formatElementList(elementList, options) {
4195
4210
  }
4196
4211
  for (let d = 0; d < tr.tdList.length; d++) {
4197
4212
  const td = tr.tdList[d];
4198
- const tdId = getUUID();
4213
+ const tdId = td.id || getUUID();
4199
4214
  td.id = tdId;
4200
4215
  formatElementList(td.value, __spreadProps(__spreadValues({}, options), {
4201
4216
  isHandleFirstElement: true,
@@ -4440,14 +4455,14 @@ function formatElementList(elementList, options) {
4440
4455
  el.value = ZERO;
4441
4456
  }
4442
4457
  if (el.type === ElementType.IMAGE || el.type === ElementType.BLOCK) {
4443
- el.id = getUUID();
4458
+ el.id = el.id || getUUID();
4444
4459
  }
4445
4460
  if (el.type === ElementType.LATEX) {
4446
4461
  const { svg, width, height } = LaTexParticle.convertLaTextToSVG(el.value);
4447
4462
  el.width = el.width || width;
4448
4463
  el.height = el.height || height;
4449
4464
  el.laTexSVG = svg;
4450
- el.id = getUUID();
4465
+ el.id = el.id || getUUID();
4451
4466
  }
4452
4467
  i++;
4453
4468
  }
@@ -5735,6 +5750,8 @@ class Cursor {
5735
5750
  }
5736
5751
  }
5737
5752
  focus() {
5753
+ if (isMobile && this.draw.isReadonly())
5754
+ return;
5738
5755
  const agentCursorDom = this.cursorAgent.getAgentCursorDom();
5739
5756
  if (document.activeElement !== agentCursorDom) {
5740
5757
  agentCursorDom.focus();
@@ -5833,8 +5850,6 @@ var MouseEventButton;
5833
5850
  MouseEventButton2[MouseEventButton2["CENTER"] = 1] = "CENTER";
5834
5851
  MouseEventButton2[MouseEventButton2["RIGHT"] = 2] = "RIGHT";
5835
5852
  })(MouseEventButton || (MouseEventButton = {}));
5836
- const isApple = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent);
5837
- const isIOS = typeof navigator !== "undefined" && /iPad|iPhone/.test(navigator.userAgent);
5838
5853
  function isMod(evt) {
5839
5854
  return isApple ? evt.metaKey : evt.ctrlKey;
5840
5855
  }
@@ -7379,7 +7394,7 @@ function keydown(evt, host) {
7379
7394
  }
7380
7395
  }
7381
7396
  function input(data2, host) {
7382
- var _a;
7397
+ var _a, _b;
7383
7398
  const draw = host.getDraw();
7384
7399
  if (draw.isReadonly() || draw.isDisabled())
7385
7400
  return;
@@ -7393,6 +7408,7 @@ function input(data2, host) {
7393
7408
  const rangeManager = draw.getRange();
7394
7409
  if (!rangeManager.getIsCanInput())
7395
7410
  return;
7411
+ const defaultStyle = rangeManager.getDefaultStyle() || ((_b = host.compositionInfo) == null ? void 0 : _b.defaultStyle) || null;
7396
7412
  removeComposingInput(host);
7397
7413
  if (!isComposing) {
7398
7414
  const cursor = draw.getCursor();
@@ -7408,11 +7424,11 @@ function input(data2, host) {
7408
7424
  return;
7409
7425
  const isDesignMode = draw.isDesignMode();
7410
7426
  const inputData = splitText(text).map((value) => {
7411
- var _a2, _b;
7427
+ var _a2, _b2;
7412
7428
  const newElement = {
7413
7429
  value
7414
7430
  };
7415
- if (isDesignMode || !((_a2 = copyElement.title) == null ? void 0 : _a2.disabled) && !((_b = copyElement.control) == null ? void 0 : _b.disabled)) {
7431
+ if (isDesignMode || !((_a2 = copyElement.title) == null ? void 0 : _a2.disabled) && !((_b2 = copyElement.control) == null ? void 0 : _b2.disabled)) {
7416
7432
  const nextElement = elementList[endIndex + 1];
7417
7433
  if (!copyElement.type || copyElement.type === TEXT || copyElement.type === HYPERLINK && (nextElement == null ? void 0 : nextElement.type) === HYPERLINK || copyElement.type === DATE && (nextElement == null ? void 0 : nextElement.type) === DATE || copyElement.type === SUBSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUBSCRIPT || copyElement.type === SUPERSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUPERSCRIPT) {
7418
7434
  EDITOR_ELEMENT_COPY_ATTR.forEach((attr) => {
@@ -7424,6 +7440,14 @@ function input(data2, host) {
7424
7440
  }
7425
7441
  });
7426
7442
  }
7443
+ if (defaultStyle) {
7444
+ EDITOR_ELEMENT_STYLE_ATTR.forEach((attr) => {
7445
+ const value2 = defaultStyle[attr];
7446
+ if (value2 !== void 0) {
7447
+ newElement[attr] = value2;
7448
+ }
7449
+ });
7450
+ }
7427
7451
  if (isComposing) {
7428
7452
  newElement.underline = true;
7429
7453
  }
@@ -7457,7 +7481,8 @@ function input(data2, host) {
7457
7481
  elementList,
7458
7482
  value: text,
7459
7483
  startIndex: curIndex - inputData.length,
7460
- endIndex: curIndex
7484
+ endIndex: curIndex,
7485
+ defaultStyle
7461
7486
  };
7462
7487
  }
7463
7488
  }
@@ -7821,7 +7846,8 @@ function dragover(evt, host) {
7821
7846
  cursor.drawCursor({
7822
7847
  width: dragWidth,
7823
7848
  color: dragColor,
7824
- isBlink: false
7849
+ isBlink: false,
7850
+ isFocus: false
7825
7851
  });
7826
7852
  }
7827
7853
  var drag = {
@@ -10546,10 +10572,12 @@ class TableTool {
10546
10572
  if (!isTable)
10547
10573
  return;
10548
10574
  this.dispose();
10549
- const { scale } = this.options;
10550
10575
  const elementList = this.draw.getOriginalElementList();
10551
10576
  const positionList = this.position.getOriginalPositionList();
10552
10577
  const element = elementList[index2];
10578
+ if (element.tableToolDisabled && !this.draw.isDesignMode())
10579
+ return;
10580
+ const { scale } = this.options;
10553
10581
  const position = positionList[index2];
10554
10582
  const { colgroup, trList } = element;
10555
10583
  const { coordinate: { leftTop } } = position;
@@ -12574,6 +12602,8 @@ class DateControl {
12574
12602
  this.destroy();
12575
12603
  }
12576
12604
  }
12605
+ class NumberControl extends TextControl {
12606
+ }
12577
12607
  class Control {
12578
12608
  constructor(draw) {
12579
12609
  __publicField(this, "controlBorder");
@@ -12781,9 +12811,32 @@ class Control {
12781
12811
  getActiveControl() {
12782
12812
  return this.activeControl;
12783
12813
  }
12814
+ getControlElementList(context = {}) {
12815
+ const elementList = context.elementList || this.getElementList();
12816
+ const { startIndex } = context.range || this.getRange();
12817
+ const startElement = elementList[startIndex];
12818
+ const data2 = [];
12819
+ let preIndex = startIndex;
12820
+ while (preIndex > 0) {
12821
+ const preElement = elementList[preIndex];
12822
+ if (preElement.controlId !== startElement.controlId)
12823
+ break;
12824
+ data2.unshift(preElement);
12825
+ preIndex--;
12826
+ }
12827
+ let nextIndex = startIndex + 1;
12828
+ while (nextIndex < elementList.length) {
12829
+ const nextElement = elementList[nextIndex];
12830
+ if (nextElement.controlId !== startElement.controlId)
12831
+ break;
12832
+ data2.push(nextElement);
12833
+ nextIndex++;
12834
+ }
12835
+ return data2;
12836
+ }
12784
12837
  updateActiveControlValue() {
12785
12838
  if (this.activeControl) {
12786
- this.activeControlValue = this.activeControl.getValue();
12839
+ this.activeControlValue = this.getControlElementList();
12787
12840
  }
12788
12841
  }
12789
12842
  initControl() {
@@ -12824,6 +12877,8 @@ class Control {
12824
12877
  const dateControl = new DateControl(element, this);
12825
12878
  this.activeControl = dateControl;
12826
12879
  dateControl.awake();
12880
+ } else if (control.type === ControlType.NUMBER) {
12881
+ this.activeControl = new NumberControl(element, this);
12827
12882
  }
12828
12883
  this.updateActiveControlValue();
12829
12884
  const isSubscribeControlChange = this.eventBus.isSubscribe("controlChange");
@@ -13125,13 +13180,13 @@ class Control {
13125
13180
  const nextElement = elementList[j];
13126
13181
  if (nextElement.controlId !== element.controlId)
13127
13182
  break;
13128
- if ((type === ControlType.TEXT || type === ControlType.DATE) && nextElement.controlComponent === ControlComponent.VALUE) {
13183
+ if ((type === ControlType.TEXT || type === ControlType.DATE || type === ControlType.NUMBER) && nextElement.controlComponent === ControlComponent.VALUE) {
13129
13184
  textControlValue += nextElement.value;
13130
13185
  textControlElementList.push(omitObject(nextElement, CONTROL_CONTEXT_ATTR));
13131
13186
  }
13132
13187
  j++;
13133
13188
  }
13134
- if (type === ControlType.TEXT || type === ControlType.DATE) {
13189
+ if (type === ControlType.TEXT || type === ControlType.DATE || type === ControlType.NUMBER) {
13135
13190
  result.push(__spreadProps(__spreadValues({}, element.control), {
13136
13191
  zone: zone2,
13137
13192
  value: textControlValue || null,
@@ -13261,6 +13316,19 @@ class Control {
13261
13316
  } else {
13262
13317
  date.clearSelect(controlContext, controlRule);
13263
13318
  }
13319
+ } else if (type === ControlType.NUMBER) {
13320
+ const formatValue = Array.isArray(value) ? value : [{ value }];
13321
+ formatElementList(formatValue, {
13322
+ isHandleFirstElement: false,
13323
+ editorOptions: this.options
13324
+ });
13325
+ const text = new NumberControl(element, this);
13326
+ this.activeControl = text;
13327
+ if (value) {
13328
+ text.setValue(formatValue, controlContext, controlRule);
13329
+ } else {
13330
+ text.clearValue(controlContext, controlRule);
13331
+ }
13264
13332
  }
13265
13333
  this.activeControl = null;
13266
13334
  let newEndIndex = i;
@@ -16180,6 +16248,7 @@ class TableOperate {
16180
16248
  }
16181
16249
  const mergeTdIdList = [];
16182
16250
  const anchorTd = rowCol[0][0];
16251
+ const anchorElement = anchorTd.value[0];
16183
16252
  for (let t = 0; t < rowCol.length; t++) {
16184
16253
  const tr = rowCol[t];
16185
16254
  for (let d = 0; d < tr.length; d++) {
@@ -16187,6 +16256,11 @@ class TableOperate {
16187
16256
  const isAnchorTd = t === 0 && d === 0;
16188
16257
  if (!isAnchorTd) {
16189
16258
  mergeTdIdList.push(td.id);
16259
+ for (let d2 = 0; d2 < td.value.length; d2++) {
16260
+ const tdElement = td.value[d2];
16261
+ cloneProperty(TABLE_CONTEXT_ATTR, anchorElement, tdElement);
16262
+ anchorTd.value.push(tdElement);
16263
+ }
16190
16264
  }
16191
16265
  if (t === 0 && d !== 0) {
16192
16266
  anchorTd.colspan += td.colspan;
@@ -16456,6 +16530,9 @@ class Area {
16456
16530
  this.range = draw.getRange();
16457
16531
  this.position = draw.getPosition();
16458
16532
  }
16533
+ getAreaInfo() {
16534
+ return this.areaInfoMap;
16535
+ }
16459
16536
  getActiveAreaId() {
16460
16537
  if (!this.areaInfoMap.size)
16461
16538
  return null;
@@ -16610,6 +16687,72 @@ class Area {
16610
16687
  });
16611
16688
  }
16612
16689
  }
16690
+ class Badge {
16691
+ constructor(draw) {
16692
+ __publicField(this, "draw");
16693
+ __publicField(this, "options");
16694
+ __publicField(this, "imageCache");
16695
+ __publicField(this, "mainBadge");
16696
+ __publicField(this, "areaBadgeMap");
16697
+ this.draw = draw;
16698
+ this.options = draw.getOptions();
16699
+ this.imageCache = new Map();
16700
+ this.mainBadge = null;
16701
+ this.areaBadgeMap = new Map();
16702
+ }
16703
+ setMainBadge(payload) {
16704
+ this.mainBadge = payload;
16705
+ }
16706
+ setAreaBadgeMap(payload) {
16707
+ this.areaBadgeMap.clear();
16708
+ payload.forEach((areaBadge) => {
16709
+ this.areaBadgeMap.set(areaBadge.areaId, areaBadge.badge);
16710
+ });
16711
+ }
16712
+ _drawImage(ctx, x, y, width, height, value) {
16713
+ if (this.imageCache.has(value)) {
16714
+ const img = this.imageCache.get(value);
16715
+ ctx.drawImage(img, x, y, width, height);
16716
+ } else {
16717
+ const img = new Image();
16718
+ img.setAttribute("crossOrigin", "Anonymous");
16719
+ img.src = value;
16720
+ img.onload = () => {
16721
+ this.imageCache.set(value, img);
16722
+ ctx.drawImage(img, x, y, width, height);
16723
+ };
16724
+ }
16725
+ }
16726
+ render(ctx, pageNo) {
16727
+ if (pageNo === 0 && this.mainBadge) {
16728
+ const { scale, badge } = this.options;
16729
+ const { left: left2, top, width, height, value } = this.mainBadge;
16730
+ const headerTop = this.draw.getMargins()[0] + this.draw.getHeader().getExtraHeight();
16731
+ const x = (left2 || badge.left) * scale;
16732
+ const y = (top || badge.top) * scale + headerTop;
16733
+ this._drawImage(ctx, x, y, width * scale, height * scale, value);
16734
+ }
16735
+ if (this.areaBadgeMap.size) {
16736
+ const areaInfo = this.draw.getArea().getAreaInfo();
16737
+ if (areaInfo.size) {
16738
+ const { scale, badge } = this.options;
16739
+ for (const areaItem of areaInfo) {
16740
+ const { positionList } = areaItem[1];
16741
+ const firstPosition = positionList[0];
16742
+ if (firstPosition.pageNo !== pageNo)
16743
+ continue;
16744
+ const badgeItem = this.areaBadgeMap.get(areaItem[0]);
16745
+ if (!badgeItem)
16746
+ continue;
16747
+ const { left: left2, top, width, height, value } = badgeItem;
16748
+ const x = (left2 || badge.left) * scale;
16749
+ const y = (top || badge.top) * scale + firstPosition.coordinate.leftTop[1];
16750
+ this._drawImage(ctx, x, y, width * scale, height * scale, value);
16751
+ }
16752
+ }
16753
+ }
16754
+ }
16755
+ }
16613
16756
  class Draw {
16614
16757
  constructor(rootContainer, options, data2, listener, eventBus, override) {
16615
16758
  __publicField(this, "container");
@@ -16633,6 +16776,7 @@ class Draw {
16633
16776
  __publicField(this, "range");
16634
16777
  __publicField(this, "margin");
16635
16778
  __publicField(this, "background");
16779
+ __publicField(this, "badge");
16636
16780
  __publicField(this, "search");
16637
16781
  __publicField(this, "group");
16638
16782
  __publicField(this, "area");
@@ -16701,6 +16845,7 @@ class Draw {
16701
16845
  this.range = new RangeManager(this);
16702
16846
  this.margin = new Margin(this);
16703
16847
  this.background = new Background(this);
16848
+ this.badge = new Badge(this);
16704
16849
  this.search = new Search(this);
16705
16850
  this.group = new Group(this);
16706
16851
  this.area = new Area(this);
@@ -16996,6 +17141,9 @@ class Draw {
16996
17141
  getArea() {
16997
17142
  return this.area;
16998
17143
  }
17144
+ getBadge() {
17145
+ return this.badge;
17146
+ }
16999
17147
  getHistoryManager() {
17000
17148
  return this.historyManager;
17001
17149
  }
@@ -17535,7 +17683,7 @@ class Draw {
17535
17683
  return defaultBasicRowMarginHeight * ((_a = el.rowMargin) != null ? _a : defaultRowMargin) * scale;
17536
17684
  }
17537
17685
  computeRowList(payload) {
17538
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
17686
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
17539
17687
  const { innerWidth, elementList, isPagingMode = false, isFromTable = false, startX = 0, startY = 0, pageHeight = 0, mainOuterHeight = 0, surroundElementList = [] } = payload;
17540
17688
  const { defaultSize, defaultRowMargin, scale, table: { tdPadding, defaultTrMinHeight }, defaultTabWidth } = this.options;
17541
17689
  const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
@@ -17913,7 +18061,7 @@ class Draw {
17913
18061
  x = surroundPosition.x;
17914
18062
  curRowWidth += surroundPosition.rowIncreaseWidth;
17915
18063
  x += metrics.width;
17916
- const isForceBreak = element.type === ElementType.SEPARATOR || element.type === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.BLOCK || element.type === ElementType.BLOCK || (preElement == null ? void 0 : preElement.imgDisplay) === ImageDisplay.INLINE || element.imgDisplay === ImageDisplay.INLINE || (preElement == null ? void 0 : preElement.listId) !== element.listId || (preElement == null ? void 0 : preElement.areaId) !== element.areaId || i !== 0 && element.value === ZERO;
18064
+ const isForceBreak = element.type === ElementType.SEPARATOR || element.type === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.BLOCK || element.type === ElementType.BLOCK || (preElement == null ? void 0 : preElement.imgDisplay) === ImageDisplay.INLINE || element.imgDisplay === ImageDisplay.INLINE || (preElement == null ? void 0 : preElement.listId) !== element.listId || (preElement == null ? void 0 : preElement.areaId) !== element.areaId || ((_i = element.control) == null ? void 0 : _i.flexDirection) === FlexDirection.COLUMN && (element.controlComponent === ControlComponent.CHECKBOX || element.controlComponent === ControlComponent.RADIO) && (preElement == null ? void 0 : preElement.controlComponent) === ControlComponent.VALUE || i !== 0 && element.value === ZERO;
17917
18065
  const isWidthNotEnough = curRowWidth > availableWidth;
17918
18066
  const isWrap = isForceBreak || isWidthNotEnough;
17919
18067
  if (isWrap) {
@@ -17924,10 +18072,10 @@ class Draw {
17924
18072
  elementList: [rowElement],
17925
18073
  ascent,
17926
18074
  rowIndex: curRow.rowIndex + 1,
17927
- rowFlex: ((_i = elementList[i]) == null ? void 0 : _i.rowFlex) || ((_j = elementList[i + 1]) == null ? void 0 : _j.rowFlex),
18075
+ rowFlex: ((_j = elementList[i]) == null ? void 0 : _j.rowFlex) || ((_k = elementList[i + 1]) == null ? void 0 : _k.rowFlex),
17928
18076
  isPageBreak: element.type === ElementType.PAGE_BREAK
17929
18077
  };
17930
- if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_k = rowElement.control) == null ? void 0 : _k.indentation) === ControlIndentation.VALUE_START) {
18078
+ if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_l = rowElement.control) == null ? void 0 : _l.indentation) === ControlIndentation.VALUE_START) {
17931
18079
  const preStartIndex = curRow.elementList.findIndex((el) => el.controlId === rowElement.controlId && el.controlComponent !== ControlComponent.PREFIX);
17932
18080
  if (~preStartIndex) {
17933
18081
  const preRowPositionList = this.position.computeRowPosition({
@@ -17945,11 +18093,11 @@ class Draw {
17945
18093
  row.offsetX = listStyleMap.get(element.listId);
17946
18094
  row.listIndex = listIndex;
17947
18095
  }
17948
- row.offsetY = !isFromTable && ((_l = element.area) == null ? void 0 : _l.top) && element.areaId !== ((_m = elementList[i - 1]) == null ? void 0 : _m.areaId) ? element.area.top * scale : 0;
18096
+ row.offsetY = !isFromTable && ((_m = element.area) == null ? void 0 : _m.top) && element.areaId !== ((_n = elementList[i - 1]) == null ? void 0 : _n.areaId) ? element.area.top * scale : 0;
17949
18097
  rowList.push(row);
17950
18098
  } else {
17951
18099
  curRow.width += metrics.width;
17952
- if (i === 0 && (getIsBlockElement(elementList[1]) || !!((_n = elementList[1]) == null ? void 0 : _n.areaId))) {
18100
+ if (i === 0 && (getIsBlockElement(elementList[1]) || !!((_o = elementList[1]) == null ? void 0 : _o.areaId))) {
17953
18101
  curRow.height = defaultBasicRowMarginHeight;
17954
18102
  curRow.ascent = defaultBasicRowMarginHeight;
17955
18103
  } else if (curRow.height < height) {
@@ -17961,7 +18109,7 @@ class Draw {
17961
18109
  if (isWrap || i === elementList.length - 1) {
17962
18110
  curRow.isWidthNotEnough = isWidthNotEnough && !isForceBreak;
17963
18111
  if (!curRow.isSurround && ((preElement == null ? void 0 : preElement.rowFlex) === RowFlex.JUSTIFY || (preElement == null ? void 0 : preElement.rowFlex) === RowFlex.ALIGNMENT && curRow.isWidthNotEnough)) {
17964
- const rowElementList = ((_o = curRow.elementList[0]) == null ? void 0 : _o.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
18112
+ const rowElementList = ((_p = curRow.elementList[0]) == null ? void 0 : _p.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
17965
18113
  const gap = (availableWidth - curRow.width) / (rowElementList.length - 1);
17966
18114
  for (let e = 0; e < rowElementList.length - 1; e++) {
17967
18115
  const el = rowElementList[e];
@@ -18309,6 +18457,9 @@ class Draw {
18309
18457
  if (!isPrintMode) {
18310
18458
  this.area.render(ctx, pageNo);
18311
18459
  }
18460
+ if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
18461
+ this.waterMark.render(ctx);
18462
+ }
18312
18463
  if (!isPrintMode) {
18313
18464
  this.margin.render(ctx, pageNo);
18314
18465
  }
@@ -18347,9 +18498,6 @@ class Draw {
18347
18498
  if (!isPrintMode && this.search.getSearchKeyword()) {
18348
18499
  this.search.render(ctx, pageNo);
18349
18500
  }
18350
- if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
18351
- this.waterMark.render(ctx);
18352
- }
18353
18501
  if (this.elementList.length <= 1 && !((_b = this.elementList[0]) == null ? void 0 : _b.listId)) {
18354
18502
  this.placeholder.render(ctx);
18355
18503
  }
@@ -18359,6 +18507,7 @@ class Draw {
18359
18507
  if (!pageBorder.disabled) {
18360
18508
  this.pageBorder.render(ctx);
18361
18509
  }
18510
+ this.badge.render(ctx, pageNo);
18362
18511
  }
18363
18512
  _disconnectLazyRender() {
18364
18513
  var _a;
@@ -18641,6 +18790,8 @@ class Command {
18641
18790
  __publicField(this, "executePaperSize");
18642
18791
  __publicField(this, "executePaperDirection");
18643
18792
  __publicField(this, "executeSetPaperMargin");
18793
+ __publicField(this, "executeSetMainBadge");
18794
+ __publicField(this, "executeSetAreaBadge");
18644
18795
  __publicField(this, "executeInsertElementList");
18645
18796
  __publicField(this, "executeInsertArea");
18646
18797
  __publicField(this, "executeSetAreaProperties");
@@ -18765,6 +18916,8 @@ class Command {
18765
18916
  this.executePaperSize = adapt.paperSize.bind(adapt);
18766
18917
  this.executePaperDirection = adapt.paperDirection.bind(adapt);
18767
18918
  this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt);
18919
+ this.executeSetMainBadge = adapt.setMainBadge.bind(adapt);
18920
+ this.executeSetAreaBadge = adapt.setAreaBadge.bind(adapt);
18768
18921
  this.getAreaValue = adapt.getAreaValue.bind(adapt);
18769
18922
  this.executeInsertArea = adapt.insertArea.bind(adapt);
18770
18923
  this.executeSetAreaProperties = adapt.setAreaProperties.bind(adapt);
@@ -20079,7 +20232,6 @@ class CommandAdapt {
20079
20232
  const element = elementList[startIndex];
20080
20233
  if (!element || element.type !== ElementType.IMAGE)
20081
20234
  return;
20082
- element.id = getUUID();
20083
20235
  element.value = payload;
20084
20236
  this.draw.render({
20085
20237
  isSetCursor: false
@@ -20338,6 +20490,20 @@ class CommandAdapt {
20338
20490
  setPaperMargin(payload) {
20339
20491
  return this.draw.setPaperMargin(payload);
20340
20492
  }
20493
+ setMainBadge(payload) {
20494
+ this.draw.getBadge().setMainBadge(payload);
20495
+ this.draw.render({
20496
+ isCompute: false,
20497
+ isSubmitHistory: false
20498
+ });
20499
+ }
20500
+ setAreaBadge(payload) {
20501
+ this.draw.getBadge().setAreaBadgeMap(payload);
20502
+ this.draw.render({
20503
+ isCompute: false,
20504
+ isSubmitHistory: false
20505
+ });
20506
+ }
20341
20507
  insertElementList(payload) {
20342
20508
  if (!payload.length)
20343
20509
  return;
@@ -20365,35 +20531,51 @@ class CommandAdapt {
20365
20531
  const { id, conceptId } = payload;
20366
20532
  if (!id && !conceptId)
20367
20533
  return;
20368
- function getElementIndexById(elementList) {
20369
- for (let e = 0; e < elementList.length; e++) {
20370
- const element = elementList[e];
20371
- if (id && element.id === id || conceptId && element.conceptId === conceptId) {
20372
- return e;
20534
+ const updateElementInfoList = [];
20535
+ function getElementInfoById(elementList) {
20536
+ let i = 0;
20537
+ while (i < elementList.length) {
20538
+ const element = elementList[i];
20539
+ i++;
20540
+ if (element.type === ElementType.TABLE) {
20541
+ const trList = element.trList;
20542
+ for (let r = 0; r < trList.length; r++) {
20543
+ const tr = trList[r];
20544
+ for (let d = 0; d < tr.tdList.length; d++) {
20545
+ const td = tr.tdList[d];
20546
+ getElementInfoById(td.value);
20547
+ }
20548
+ }
20549
+ }
20550
+ if (id && (element.id === id || element.controlId === id) || conceptId && element.conceptId === conceptId) {
20551
+ updateElementInfoList.push({
20552
+ elementList,
20553
+ index: i - 1
20554
+ });
20373
20555
  }
20374
20556
  }
20375
- return -1;
20376
20557
  }
20377
- const getElementListFnList = [
20378
- this.draw.getOriginalMainElementList,
20379
- this.draw.getHeaderElementList,
20380
- this.draw.getFooterElementList
20558
+ const data2 = [
20559
+ this.draw.getOriginalMainElementList(),
20560
+ this.draw.getHeaderElementList(),
20561
+ this.draw.getFooterElementList()
20381
20562
  ];
20382
- for (const getElementList of getElementListFnList) {
20383
- const elementList = getElementList.call(this.draw);
20384
- const elementIndex = getElementIndexById(elementList);
20385
- if (~elementIndex) {
20386
- elementList[elementIndex] = __spreadValues(__spreadValues({}, elementList[elementIndex]), payload.properties);
20387
- formatElementList(zipElementList([elementList[elementIndex]]), {
20388
- isHandleFirstElement: false,
20389
- editorOptions: this.options
20390
- });
20391
- this.draw.render({
20392
- isSetCursor: false
20393
- });
20394
- break;
20395
- }
20563
+ for (const elementList of data2) {
20564
+ getElementInfoById(elementList);
20565
+ }
20566
+ if (!updateElementInfoList.length)
20567
+ return;
20568
+ for (let i = 0; i < updateElementInfoList.length; i++) {
20569
+ const { elementList, index: index2 } = updateElementInfoList[i];
20570
+ elementList[index2] = __spreadValues(__spreadValues({}, elementList[index2]), payload.properties);
20571
+ formatElementList(zipElementList([elementList[index2]]), {
20572
+ isHandleFirstElement: false,
20573
+ editorOptions: this.options
20574
+ });
20396
20575
  }
20576
+ this.draw.render({
20577
+ isSetCursor: false
20578
+ });
20397
20579
  }
20398
20580
  getElementById(payload) {
20399
20581
  const { id, conceptId } = payload;
@@ -20405,7 +20587,17 @@ class CommandAdapt {
20405
20587
  while (i < elementList.length) {
20406
20588
  const element = elementList[i];
20407
20589
  i++;
20408
- if (id && element.controlId !== id || conceptId && element.conceptId !== conceptId) {
20590
+ if (element.type === ElementType.TABLE) {
20591
+ const trList = element.trList;
20592
+ for (let r = 0; r < trList.length; r++) {
20593
+ const tr = trList[r];
20594
+ for (let d = 0; d < tr.tdList.length; d++) {
20595
+ const td = tr.tdList[d];
20596
+ getElement(td.value);
20597
+ }
20598
+ }
20599
+ }
20600
+ if (id && element.controlId !== id && element.id !== id || conceptId && element.conceptId !== conceptId) {
20409
20601
  continue;
20410
20602
  }
20411
20603
  result.push(element);
@@ -20426,22 +20618,62 @@ class CommandAdapt {
20426
20618
  setValue(payload, options) {
20427
20619
  this.draw.setValue(payload, options);
20428
20620
  }
20429
- removeControl() {
20430
- const { startIndex, endIndex } = this.range.getRange();
20431
- if (startIndex !== endIndex)
20432
- return;
20433
- const elementList = this.draw.getElementList();
20434
- const element = elementList[startIndex];
20435
- if (!element.controlId)
20436
- return;
20437
- const control = this.draw.getControl();
20438
- const newIndex = control.removeControl(startIndex);
20439
- if (newIndex === null)
20440
- return;
20441
- this.range.setRange(newIndex, newIndex);
20442
- this.draw.render({
20443
- curIndex: newIndex
20444
- });
20621
+ removeControl(payload) {
20622
+ if ((payload == null ? void 0 : payload.id) || (payload == null ? void 0 : payload.conceptId)) {
20623
+ const { id, conceptId } = payload;
20624
+ let isExistRemove = false;
20625
+ const remove = (elementList) => {
20626
+ let i = elementList.length - 1;
20627
+ while (i >= 0) {
20628
+ const element = elementList[i];
20629
+ if (element.type === ElementType.TABLE) {
20630
+ const trList = element.trList;
20631
+ for (let r = 0; r < trList.length; r++) {
20632
+ const tr = trList[r];
20633
+ for (let d = 0; d < tr.tdList.length; d++) {
20634
+ const td = tr.tdList[d];
20635
+ remove(td.value);
20636
+ }
20637
+ }
20638
+ }
20639
+ i--;
20640
+ if (!element.control || id && element.controlId !== id || conceptId && element.control.conceptId !== conceptId) {
20641
+ continue;
20642
+ }
20643
+ isExistRemove = true;
20644
+ elementList.splice(i + 1, 1);
20645
+ }
20646
+ };
20647
+ const data2 = [
20648
+ this.draw.getHeaderElementList(),
20649
+ this.draw.getOriginalMainElementList(),
20650
+ this.draw.getFooterElementList()
20651
+ ];
20652
+ for (const elementList of data2) {
20653
+ remove(elementList);
20654
+ }
20655
+ if (isExistRemove) {
20656
+ this.draw.render({
20657
+ isSetCursor: false
20658
+ });
20659
+ }
20660
+ } else {
20661
+ const { startIndex, endIndex } = this.range.getRange();
20662
+ if (startIndex !== endIndex)
20663
+ return;
20664
+ const elementList = this.draw.getElementList();
20665
+ const element = elementList[startIndex];
20666
+ if (!element.controlId)
20667
+ return;
20668
+ const control = this.draw.getControl();
20669
+ const newIndex = control.removeControl(startIndex);
20670
+ if (newIndex === null)
20671
+ return;
20672
+ this.range.setRange(newIndex, newIndex);
20673
+ this.draw.render({
20674
+ curIndex: newIndex
20675
+ });
20676
+ }
20445
20677
  }
20446
20678
  setLocale(payload) {
20447
20679
  this.i18n.setLocale(payload);
@@ -20454,7 +20686,7 @@ class CommandAdapt {
20454
20686
  }
20455
20687
  locationCatalog(titleId) {
20456
20688
  var _a;
20457
- const elementList = this.draw.getMainElementList();
20689
+ const elementList = this.draw.getOriginalMainElementList();
20458
20690
  let newIndex = -1;
20459
20691
  for (let e = 0; e < elementList.length; e++) {
20460
20692
  const element = elementList[e];
@@ -20465,6 +20697,9 @@ class CommandAdapt {
20465
20697
  }
20466
20698
  if (!~newIndex)
20467
20699
  return;
20700
+ this.position.setPositionContext({
20701
+ isTable: false
20702
+ });
20468
20703
  this.range.setRange(newIndex, newIndex);
20469
20704
  this.draw.render({
20470
20705
  curIndex: newIndex,
@@ -21996,5 +22231,5 @@ class Editor {
21996
22231
  this.use = plugin.use.bind(plugin);
21997
22232
  }
21998
22233
  }
21999
- export { AreaMode, BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlState, ControlType, EDITOR_CLIPBOARD, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, LocationPosition, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, createDomFromElementList, Editor as default, getElementListByHTML, getTextFromElementList, splitText };
22234
+ export { AreaMode, BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlState, ControlType, EDITOR_CLIPBOARD, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, FlexDirection, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, LocationPosition, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, createDomFromElementList, Editor as default, getElementListByHTML, getTextFromElementList, splitText };
22000
22235
  //# sourceMappingURL=canvas-editor.es.js.map