@hufe921/canvas-editor 0.9.84 → 0.9.86

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,48 @@
1
+ ## [0.9.86](https://github.com/Hufe921/canvas-editor/compare/v0.9.85...v0.9.86) (2024-07-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add control placeholder boundary error #686 ([fac5c5c](https://github.com/Hufe921/canvas-editor/commit/fac5c5c045a30cb5e0c46ef027c83f21e07bcaa8)), closes [#686](https://github.com/Hufe921/canvas-editor/issues/686)
7
+ * add control placeholder using default style #691 ([eb3ea5e](https://github.com/Hufe921/canvas-editor/commit/eb3ea5ed55cdedea0e281d45177c8661f674a280)), closes [#691](https://github.com/Hufe921/canvas-editor/issues/691)
8
+ * delete table col boundary error #688 ([3f0a49f](https://github.com/Hufe921/canvas-editor/commit/3f0a49f56be7060d328a63c994f571b0a35a3521)), closes [#688](https://github.com/Hufe921/canvas-editor/issues/688)
9
+ * refocus when cursor is not focused #685 ([0ac8ae7](https://github.com/Hufe921/canvas-editor/commit/0ac8ae7c4b0b47ee84a9c0f8c37ffde612849957)), closes [#685](https://github.com/Hufe921/canvas-editor/issues/685)
10
+ * remove title and list properties from getControlList return value #683 ([b024050](https://github.com/Hufe921/canvas-editor/commit/b024050b3ef7f787079a74b062e5d83085be1a5f)), closes [#683](https://github.com/Hufe921/canvas-editor/issues/683)
11
+
12
+
13
+ ### Features
14
+
15
+ * add executeInsertControl api ([e5b3d05](https://github.com/Hufe921/canvas-editor/commit/e5b3d05991a26dc186cdf63962ca3c7b50a32572))
16
+
17
+
18
+
19
+ ## [0.9.85](https://github.com/Hufe921/canvas-editor/compare/v0.9.84...v0.9.85) (2024-07-07)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * custom override method removes support for asynchronous #672 ([0e705d6](https://github.com/Hufe921/canvas-editor/commit/0e705d6a0bdb0922efd5c47edd8ca9eba9964199)), closes [#672](https://github.com/Hufe921/canvas-editor/issues/672)
25
+ * set control highlight and re render #678 ([24df9d3](https://github.com/Hufe921/canvas-editor/commit/24df9d3b006a8daf795ada677bfd0159e3ccc3f5)), closes [#678](https://github.com/Hufe921/canvas-editor/issues/678)
26
+
27
+
28
+ ### Chores
29
+
30
+ * update build.yml ([a40441d](https://github.com/Hufe921/canvas-editor/commit/a40441dc3994a41ae29c341a542be6e0e7dada2e))
31
+
32
+
33
+ ### Features
34
+
35
+ * add render mode #667 ([affd191](https://github.com/Hufe921/canvas-editor/commit/affd1911552a73a2b63a13f2c423121637830b99)), closes [#667](https://github.com/Hufe921/canvas-editor/issues/667)
36
+ * add title deletable property #670 ([b3d8413](https://github.com/Hufe921/canvas-editor/commit/b3d8413b35050eac626af1c57beaaf1b8d692a0e)), closes [#670](https://github.com/Hufe921/canvas-editor/issues/670)
37
+ * insert element boundary optimization #669 ([de44bd6](https://github.com/Hufe921/canvas-editor/commit/de44bd68ab01e5ffa8d6a8dc5d566b0cdb8d08e6)), closes [#669](https://github.com/Hufe921/canvas-editor/issues/669)
38
+
39
+
40
+ ### Tests
41
+
42
+ * update text test case ([c24da73](https://github.com/Hufe921/canvas-editor/commit/c24da737b15200775a7d4a5edf4e2224f6ec5429))
43
+
44
+
45
+
1
46
  ## [0.9.84](https://github.com/Hufe921/canvas-editor/compare/v0.9.83...v0.9.84) (2024-06-30)
2
47
 
3
48
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.84";
26
+ const version = "0.9.86";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -364,10 +364,6 @@ function isObjectEqual(obj1, obj2) {
364
364
  }
365
365
  return !obj1Keys.some((key) => obj2[key] !== obj1[key]);
366
366
  }
367
- function isPromiseFunction(fn) {
368
- var _a;
369
- return ((_a = fn == null ? void 0 : fn.constructor) == null ? void 0 : _a.name) === "AsyncFunction";
370
- }
371
367
  const CURSOR_AGENT_OFFSET_HEIGHT = 12;
372
368
  const defaultCursorOption = {
373
369
  width: 1,
@@ -4355,7 +4351,7 @@ function formatElementContext(sourceElementList, formatElementList2, anchorIndex
4355
4351
  let isBreakWarped = false;
4356
4352
  for (let e = 0; e < formatElementList2.length; e++) {
4357
4353
  const targetElement = formatElementList2[e];
4358
- if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) {
4354
+ if (isBreakWhenWrap && !copyElement.listId && START_LINE_BREAK_REG.test(targetElement.value)) {
4359
4355
  isBreakWarped = true;
4360
4356
  }
4361
4357
  if (isBreakWarped || !copyElement.listId && targetElement.type === ElementType.LIST) {
@@ -5060,7 +5056,7 @@ function pasteImage(host, file) {
5060
5056
  };
5061
5057
  };
5062
5058
  }
5063
- async function pasteByEvent(host, evt) {
5059
+ function pasteByEvent(host, evt) {
5064
5060
  const draw = host.getDraw();
5065
5061
  const isReadonly = draw.isReadonly();
5066
5062
  if (isReadonly)
@@ -5070,7 +5066,7 @@ async function pasteByEvent(host, evt) {
5070
5066
  return;
5071
5067
  const { paste } = draw.getOverride();
5072
5068
  if (paste) {
5073
- const overrideResult = isPromiseFunction(paste) ? await paste(evt) : paste(evt);
5069
+ const overrideResult = paste(evt);
5074
5070
  if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
5075
5071
  return;
5076
5072
  }
@@ -5123,7 +5119,7 @@ async function pasteByApi(host, options) {
5123
5119
  return;
5124
5120
  const { paste } = draw.getOverride();
5125
5121
  if (paste) {
5126
- const overrideResult = isPromiseFunction(paste) ? await paste() : paste();
5122
+ const overrideResult = paste();
5127
5123
  if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
5128
5124
  return;
5129
5125
  }
@@ -5294,8 +5290,10 @@ class Cursor {
5294
5290
  const agentCursorDom = this.cursorAgent.getAgentCursorDom();
5295
5291
  if (isFocus) {
5296
5292
  setTimeout(() => {
5297
- agentCursorDom.focus();
5298
- agentCursorDom.setSelectionRange(0, 0);
5293
+ if (document.activeElement !== agentCursorDom) {
5294
+ agentCursorDom.focus();
5295
+ agentCursorDom.setSelectionRange(0, 0);
5296
+ }
5299
5297
  });
5300
5298
  }
5301
5299
  const descent = metrics.boundingBoxDescent < 0 ? 0 : metrics.boundingBoxDescent;
@@ -5404,6 +5402,11 @@ var WordBreak;
5404
5402
  WordBreak2["BREAK_ALL"] = "break-all";
5405
5403
  WordBreak2["BREAK_WORD"] = "break-word";
5406
5404
  })(WordBreak || (WordBreak = {}));
5405
+ var RenderMode;
5406
+ (function(RenderMode2) {
5407
+ RenderMode2["SPEED"] = "speed";
5408
+ RenderMode2["COMPATIBILITY"] = "compatibility";
5409
+ })(RenderMode || (RenderMode = {}));
5407
5410
  var MouseEventButton;
5408
5411
  (function(MouseEventButton2) {
5409
5412
  MouseEventButton2[MouseEventButton2["LEFT"] = 0] = "LEFT";
@@ -6166,8 +6169,10 @@ function enter(evt, host) {
6166
6169
  if (evt.shiftKey && startElement.listId) {
6167
6170
  enterText.listWrap = true;
6168
6171
  }
6172
+ formatElementContext(elementList, [enterText], startIndex, {
6173
+ isBreakWhenWrap: true
6174
+ });
6169
6175
  if (!(endElement.titleId && endElement.titleId !== ((_b = elementList[endIndex + 1]) == null ? void 0 : _b.titleId))) {
6170
- formatElementContext(elementList, [enterText], startIndex);
6171
6176
  const copyElement = getAnchorElement(elementList, endIndex);
6172
6177
  if (copyElement) {
6173
6178
  const copyAttr = [...EDITOR_ROW_ATTR];
@@ -6982,11 +6987,11 @@ function cut(host) {
6982
6987
  rangeManager.setRange(curIndex, curIndex);
6983
6988
  draw.render({ curIndex });
6984
6989
  }
6985
- async function copy(host) {
6990
+ function copy(host) {
6986
6991
  const draw = host.getDraw();
6987
6992
  const { copy: copy2 } = draw.getOverride();
6988
6993
  if (copy2) {
6989
- const overrideResult = isPromiseFunction(copy2) ? await copy2() : copy2();
6994
+ const overrideResult = copy2();
6990
6995
  if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
6991
6996
  return;
6992
6997
  }
@@ -7034,12 +7039,12 @@ async function copy(host) {
7034
7039
  return;
7035
7040
  writeElementList(copyElementList, draw.getOptions());
7036
7041
  }
7037
- async function drop(evt, host) {
7042
+ function drop(evt, host) {
7038
7043
  var _a, _b;
7039
7044
  const draw = host.getDraw();
7040
7045
  const { drop: drop2 } = draw.getOverride();
7041
7046
  if (drop2) {
7042
- const overrideResult = isPromiseFunction(drop2) ? await drop2(evt) : drop2(evt);
7047
+ const overrideResult = drop2(evt);
7043
7048
  if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
7044
7049
  return;
7045
7050
  }
@@ -9250,6 +9255,14 @@ class TextParticle {
9250
9255
  }
9251
9256
  record(ctx, element, x, y) {
9252
9257
  this.ctx = ctx;
9258
+ if (this.options.renderMode === RenderMode.COMPATIBILITY) {
9259
+ this._setCurXY(x, y);
9260
+ this.text = element.value;
9261
+ this.curStyle = element.style;
9262
+ this.curColor = element.color;
9263
+ this.complete();
9264
+ return;
9265
+ }
9253
9266
  if (!this.text) {
9254
9267
  this._setCurXY(x, y);
9255
9268
  }
@@ -10882,7 +10895,7 @@ class TextControl {
10882
10895
  this.control.getDraw().spliceElementList(elementList, startIndex + 1, endIndex - startIndex);
10883
10896
  const value = this.getValue(context);
10884
10897
  if (!value.length) {
10885
- this.control.addPlaceholder(startIndex);
10898
+ this.control.addPlaceholder(startIndex, context);
10886
10899
  }
10887
10900
  return startIndex;
10888
10901
  }
@@ -12056,16 +12069,17 @@ class Control {
12056
12069
  if (!control.placeholder)
12057
12070
  return;
12058
12071
  const placeholderStrList = splitText(control.placeholder);
12072
+ const anchorElementStyleAttr = pickObject(startElement, CONTROL_STYLE_ATTR);
12059
12073
  for (let p = 0; p < placeholderStrList.length; p++) {
12060
12074
  const value = placeholderStrList[p];
12061
- const newElement = {
12075
+ const newElement = __spreadProps(__spreadValues({}, anchorElementStyleAttr), {
12062
12076
  value,
12063
12077
  controlId: startElement.controlId,
12064
12078
  type: ElementType.CONTROL,
12065
12079
  control: startElement.control,
12066
12080
  controlComponent: ControlComponent.PLACEHOLDER,
12067
12081
  color: this.controlOptions.placeholderColor
12068
- };
12082
+ });
12069
12083
  formatElementContext(elementList, [newElement], startIndex);
12070
12084
  this.draw.spliceElementList(elementList, startIndex + p + 1, 0, newElement);
12071
12085
  }
@@ -12398,7 +12412,11 @@ class Control {
12398
12412
  }
12399
12413
  }
12400
12414
  if (element.controlId) {
12401
- controlElementList.push(element);
12415
+ const controlElement = omitObject(element, [
12416
+ ...TITLE_CONTEXT_ATTR,
12417
+ ...LIST_CONTEXT_ATTR
12418
+ ]);
12419
+ controlElementList.push(controlElement);
12402
12420
  }
12403
12421
  }
12404
12422
  }
@@ -14951,7 +14969,8 @@ class Draw {
14951
14969
  if (!this.control.getActiveControl()) {
14952
14970
  let deleteIndex = endIndex - 1;
14953
14971
  while (deleteIndex >= start) {
14954
- if (((_c = (_b = elementList[deleteIndex]) == null ? void 0 : _b.control) == null ? void 0 : _c.deletable) !== false) {
14972
+ const deleteElement = elementList[deleteIndex];
14973
+ if (((_b = deleteElement == null ? void 0 : deleteElement.control) == null ? void 0 : _b.deletable) !== false && ((_c = deleteElement == null ? void 0 : deleteElement.title) == null ? void 0 : _c.deletable) !== false) {
14955
14974
  elementList.splice(deleteIndex, 1);
14956
14975
  }
14957
14976
  deleteIndex--;
@@ -16326,6 +16345,7 @@ class Command {
16326
16345
  __publicField(this, "executeSetControlProperties");
16327
16346
  __publicField(this, "executeSetControlHighlight");
16328
16347
  __publicField(this, "executeLocationControl");
16348
+ __publicField(this, "executeInsertControl");
16329
16349
  __publicField(this, "executeUpdateOptions");
16330
16350
  __publicField(this, "executeInsertTitle");
16331
16351
  __publicField(this, "getCatalog");
@@ -16464,6 +16484,7 @@ class Command {
16464
16484
  this.getControlValue = adapt.getControlValue.bind(adapt);
16465
16485
  this.getControlList = adapt.getControlList.bind(adapt);
16466
16486
  this.executeLocationControl = adapt.locationControl.bind(adapt);
16487
+ this.executeInsertControl = adapt.insertControl.bind(adapt);
16467
16488
  }
16468
16489
  }
16469
16490
  const defaultWatermarkOption = {
@@ -16603,6 +16624,7 @@ function mergeOption(options = {}) {
16603
16624
  marginIndicatorColor: "#BABABA",
16604
16625
  margins: [100, 120, 100, 120],
16605
16626
  pageMode: PageMode.PAGING,
16627
+ renderMode: RenderMode.SPEED,
16606
16628
  defaultHyperlinkColor: "#0000FF",
16607
16629
  paperDirection: PaperDirection.VERTICAL,
16608
16630
  inactiveAlpha: 0.6,
@@ -17654,27 +17676,15 @@ class CommandAdapt {
17654
17676
  const tr = curTrList[t];
17655
17677
  for (let d = 0; d < tr.tdList.length; d++) {
17656
17678
  const td = tr.tdList[d];
17657
- if (td.colspan > 1) {
17658
- const tdColIndex = td.colIndex;
17659
- if (tdColIndex <= curColIndex && tdColIndex + td.colspan - 1 >= curColIndex) {
17660
- td.colspan -= 1;
17679
+ if (td.colIndex <= curColIndex && td.colIndex + td.colspan > curColIndex) {
17680
+ if (td.colspan > 1) {
17681
+ td.colspan--;
17682
+ } else {
17683
+ tr.tdList.splice(d, 1);
17661
17684
  }
17662
17685
  }
17663
17686
  }
17664
17687
  }
17665
- for (let t = 0; t < curTrList.length; t++) {
17666
- const tr = curTrList[t];
17667
- let start = -1;
17668
- for (let d = 0; d < tr.tdList.length; d++) {
17669
- const td = tr.tdList[d];
17670
- if (td.colIndex === curColIndex) {
17671
- start = d;
17672
- }
17673
- }
17674
- if (~start) {
17675
- tr.tdList.splice(start, 1);
17676
- }
17677
- }
17678
17688
  (_a = element.colgroup) == null ? void 0 : _a.splice(curColIndex, 1);
17679
17689
  this.position.setPositionContext({
17680
17690
  isTable: false
@@ -18616,7 +18626,9 @@ class CommandAdapt {
18616
18626
  const cloneElementList = deepClone(payload);
18617
18627
  const { startIndex } = this.range.getRange();
18618
18628
  const elementList = this.draw.getElementList();
18619
- formatElementContext(elementList, cloneElementList, startIndex);
18629
+ formatElementContext(elementList, cloneElementList, startIndex, {
18630
+ isBreakWhenWrap: true
18631
+ });
18620
18632
  this.draw.insertElementList(cloneElementList);
18621
18633
  }
18622
18634
  appendElementList(elementList, options) {
@@ -18808,6 +18820,9 @@ class CommandAdapt {
18808
18820
  }
18809
18821
  setControlHighlight(payload) {
18810
18822
  this.draw.getControl().setHighlightList(payload);
18823
+ this.draw.render({
18824
+ isSubmitHistory: false
18825
+ });
18811
18826
  }
18812
18827
  updateOptions(payload) {
18813
18828
  const newOption = mergeOption(payload);
@@ -18893,6 +18908,24 @@ class CommandAdapt {
18893
18908
  }
18894
18909
  }
18895
18910
  }
18911
+ insertControl(payload) {
18912
+ const isReadonly = this.draw.isReadonly();
18913
+ if (isReadonly)
18914
+ return;
18915
+ const cloneElement = deepClone(payload);
18916
+ const { startIndex } = this.range.getRange();
18917
+ const elementList = this.draw.getElementList();
18918
+ const copyElement = getAnchorElement(elementList, startIndex);
18919
+ if (!copyElement)
18920
+ return;
18921
+ const cloneAttr = [
18922
+ ...TABLE_CONTEXT_ATTR,
18923
+ ...EDITOR_ROW_ATTR,
18924
+ ...LIST_CONTEXT_ATTR
18925
+ ];
18926
+ cloneProperty(cloneAttr, copyElement, cloneElement);
18927
+ this.draw.insertElementList([cloneElement]);
18928
+ }
18896
18929
  getContainer() {
18897
18930
  return this.draw.getContainer();
18898
18931
  }
@@ -20152,5 +20185,5 @@ class Editor {
20152
20185
  this.use = plugin.use.bind(plugin);
20153
20186
  }
20154
20187
  }
20155
- export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
20188
+ export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
20156
20189
  //# sourceMappingURL=canvas-editor.es.js.map