@hufe921/canvas-editor 0.9.83 → 0.9.84

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,19 @@
1
+ ## [0.9.84](https://github.com/Hufe921/canvas-editor/compare/v0.9.83...v0.9.84) (2024-06-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * merge table cell boundary error #661 ([146ac75](https://github.com/Hufe921/canvas-editor/commit/146ac75a002338f13c96900a2849062c29018606)), closes [#661](https://github.com/Hufe921/canvas-editor/issues/661)
7
+ * set default style for control using executeSetControlProperties #658 ([7b5079c](https://github.com/Hufe921/canvas-editor/commit/7b5079c9b638730f7ea609239b3cb91b915d4650)), closes [#658](https://github.com/Hufe921/canvas-editor/issues/658)
8
+
9
+
10
+ ### Features
11
+
12
+ * optimization of table operations in form mode #662 ([b740637](https://github.com/Hufe921/canvas-editor/commit/b74063741f413d5bf6f90c748761f64141405ca7)), closes [#662](https://github.com/Hufe921/canvas-editor/issues/662)
13
+ * override method with default interception behavior #663 ([9a4b4f9](https://github.com/Hufe921/canvas-editor/commit/9a4b4f9a4a70a344740212507e250d9bdea5dd32)), closes [#663](https://github.com/Hufe921/canvas-editor/issues/663)
14
+
15
+
16
+
1
17
  ## [0.9.83](https://github.com/Hufe921/canvas-editor/compare/v0.9.82...v0.9.83) (2024-06-21)
2
18
 
3
19
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.83";
26
+ const version = "0.9.84";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -364,6 +364,10 @@ 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
+ }
367
371
  const CURSOR_AGENT_OFFSET_HEIGHT = 12;
368
372
  const defaultCursorOption = {
369
373
  width: 1,
@@ -5056,7 +5060,7 @@ function pasteImage(host, file) {
5056
5060
  };
5057
5061
  };
5058
5062
  }
5059
- function pasteByEvent(host, evt) {
5063
+ async function pasteByEvent(host, evt) {
5060
5064
  const draw = host.getDraw();
5061
5065
  const isReadonly = draw.isReadonly();
5062
5066
  if (isReadonly)
@@ -5066,8 +5070,9 @@ function pasteByEvent(host, evt) {
5066
5070
  return;
5067
5071
  const { paste } = draw.getOverride();
5068
5072
  if (paste) {
5069
- paste(evt);
5070
- return;
5073
+ const overrideResult = isPromiseFunction(paste) ? await paste(evt) : paste(evt);
5074
+ if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
5075
+ return;
5071
5076
  }
5072
5077
  if (!getIsClipboardContainFile(clipboardData)) {
5073
5078
  const clipboardText = clipboardData.getData("text");
@@ -5118,8 +5123,9 @@ async function pasteByApi(host, options) {
5118
5123
  return;
5119
5124
  const { paste } = draw.getOverride();
5120
5125
  if (paste) {
5121
- paste();
5122
- return;
5126
+ const overrideResult = isPromiseFunction(paste) ? await paste() : paste();
5127
+ if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
5128
+ return;
5123
5129
  }
5124
5130
  const clipboardText = await navigator.clipboard.readText();
5125
5131
  const editorClipboardData = getClipboardData();
@@ -5353,6 +5359,51 @@ class Cursor {
5353
5359
  }
5354
5360
  }
5355
5361
  }
5362
+ var EditorComponent;
5363
+ (function(EditorComponent2) {
5364
+ EditorComponent2["COMPONENT"] = "component";
5365
+ EditorComponent2["MENU"] = "menu";
5366
+ EditorComponent2["MAIN"] = "main";
5367
+ EditorComponent2["FOOTER"] = "footer";
5368
+ EditorComponent2["CONTEXTMENU"] = "contextmenu";
5369
+ EditorComponent2["POPUP"] = "popup";
5370
+ EditorComponent2["CATALOG"] = "catalog";
5371
+ EditorComponent2["COMMENT"] = "comment";
5372
+ })(EditorComponent || (EditorComponent = {}));
5373
+ var EditorContext;
5374
+ (function(EditorContext2) {
5375
+ EditorContext2["PAGE"] = "page";
5376
+ EditorContext2["TABLE"] = "table";
5377
+ })(EditorContext || (EditorContext = {}));
5378
+ var EditorMode;
5379
+ (function(EditorMode2) {
5380
+ EditorMode2["EDIT"] = "edit";
5381
+ EditorMode2["CLEAN"] = "clean";
5382
+ EditorMode2["READONLY"] = "readonly";
5383
+ EditorMode2["FORM"] = "form";
5384
+ EditorMode2["PRINT"] = "print";
5385
+ })(EditorMode || (EditorMode = {}));
5386
+ var EditorZone;
5387
+ (function(EditorZone2) {
5388
+ EditorZone2["HEADER"] = "header";
5389
+ EditorZone2["MAIN"] = "main";
5390
+ EditorZone2["FOOTER"] = "footer";
5391
+ })(EditorZone || (EditorZone = {}));
5392
+ var PageMode;
5393
+ (function(PageMode2) {
5394
+ PageMode2["PAGING"] = "paging";
5395
+ PageMode2["CONTINUITY"] = "continuity";
5396
+ })(PageMode || (PageMode = {}));
5397
+ var PaperDirection;
5398
+ (function(PaperDirection2) {
5399
+ PaperDirection2["VERTICAL"] = "vertical";
5400
+ PaperDirection2["HORIZONTAL"] = "horizontal";
5401
+ })(PaperDirection || (PaperDirection = {}));
5402
+ var WordBreak;
5403
+ (function(WordBreak2) {
5404
+ WordBreak2["BREAK_ALL"] = "break-all";
5405
+ WordBreak2["BREAK_WORD"] = "break-word";
5406
+ })(WordBreak || (WordBreak = {}));
5356
5407
  var MouseEventButton;
5357
5408
  (function(MouseEventButton2) {
5358
5409
  MouseEventButton2[MouseEventButton2["LEFT"] = 0] = "LEFT";
@@ -5690,10 +5741,14 @@ function mousedown(evt, host) {
5690
5741
  const previewer = draw.getPreviewer();
5691
5742
  previewer.clearResizer();
5692
5743
  if (isDirectHitImage) {
5693
- previewer.drawResizer(curElement, positionList[curIndex], curElement.type === ElementType.LATEX ? {
5694
- mime: "svg",
5695
- srcKey: "laTexSVG"
5696
- } : {});
5744
+ const previewerDrawOption = {
5745
+ dragDisable: isReadonly || !curElement.controlId && draw.getMode() === EditorMode.FORM
5746
+ };
5747
+ if (curElement.type === ElementType.LATEX) {
5748
+ previewerDrawOption.mime = "svg";
5749
+ previewerDrawOption.srcKey = "laTexSVG";
5750
+ }
5751
+ previewer.drawResizer(curElement, positionList[curIndex], previewerDrawOption);
5697
5752
  draw.getCursor().drawCursor({
5698
5753
  isShow: false
5699
5754
  });
@@ -5704,7 +5759,7 @@ function mousedown(evt, host) {
5704
5759
  }
5705
5760
  const tableTool = draw.getTableTool();
5706
5761
  tableTool.dispose();
5707
- if (isTable && !isReadonly) {
5762
+ if (isTable && !isReadonly && draw.getMode() !== EditorMode.FORM) {
5708
5763
  tableTool.render();
5709
5764
  }
5710
5765
  const hyperlinkParticle = draw.getHyperlinkParticle();
@@ -5991,51 +6046,6 @@ function mousemove(evt, host) {
5991
6046
  isCompute: false
5992
6047
  });
5993
6048
  }
5994
- var EditorComponent;
5995
- (function(EditorComponent2) {
5996
- EditorComponent2["COMPONENT"] = "component";
5997
- EditorComponent2["MENU"] = "menu";
5998
- EditorComponent2["MAIN"] = "main";
5999
- EditorComponent2["FOOTER"] = "footer";
6000
- EditorComponent2["CONTEXTMENU"] = "contextmenu";
6001
- EditorComponent2["POPUP"] = "popup";
6002
- EditorComponent2["CATALOG"] = "catalog";
6003
- EditorComponent2["COMMENT"] = "comment";
6004
- })(EditorComponent || (EditorComponent = {}));
6005
- var EditorContext;
6006
- (function(EditorContext2) {
6007
- EditorContext2["PAGE"] = "page";
6008
- EditorContext2["TABLE"] = "table";
6009
- })(EditorContext || (EditorContext = {}));
6010
- var EditorMode;
6011
- (function(EditorMode2) {
6012
- EditorMode2["EDIT"] = "edit";
6013
- EditorMode2["CLEAN"] = "clean";
6014
- EditorMode2["READONLY"] = "readonly";
6015
- EditorMode2["FORM"] = "form";
6016
- EditorMode2["PRINT"] = "print";
6017
- })(EditorMode || (EditorMode = {}));
6018
- var EditorZone;
6019
- (function(EditorZone2) {
6020
- EditorZone2["HEADER"] = "header";
6021
- EditorZone2["MAIN"] = "main";
6022
- EditorZone2["FOOTER"] = "footer";
6023
- })(EditorZone || (EditorZone = {}));
6024
- var PageMode;
6025
- (function(PageMode2) {
6026
- PageMode2["PAGING"] = "paging";
6027
- PageMode2["CONTINUITY"] = "continuity";
6028
- })(PageMode || (PageMode = {}));
6029
- var PaperDirection;
6030
- (function(PaperDirection2) {
6031
- PaperDirection2["VERTICAL"] = "vertical";
6032
- PaperDirection2["HORIZONTAL"] = "horizontal";
6033
- })(PaperDirection || (PaperDirection = {}));
6034
- var WordBreak;
6035
- (function(WordBreak2) {
6036
- WordBreak2["BREAK_ALL"] = "break-all";
6037
- WordBreak2["BREAK_WORD"] = "break-word";
6038
- })(WordBreak || (WordBreak = {}));
6039
6049
  function backspace(evt, host) {
6040
6050
  const draw = host.getDraw();
6041
6051
  if (draw.isReadonly())
@@ -6972,12 +6982,13 @@ function cut(host) {
6972
6982
  rangeManager.setRange(curIndex, curIndex);
6973
6983
  draw.render({ curIndex });
6974
6984
  }
6975
- function copy(host) {
6985
+ async function copy(host) {
6976
6986
  const draw = host.getDraw();
6977
6987
  const { copy: copy2 } = draw.getOverride();
6978
6988
  if (copy2) {
6979
- copy2();
6980
- return;
6989
+ const overrideResult = isPromiseFunction(copy2) ? await copy2() : copy2();
6990
+ if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
6991
+ return;
6981
6992
  }
6982
6993
  const rangeManager = draw.getRange();
6983
6994
  let copyElementList = null;
@@ -7023,13 +7034,14 @@ function copy(host) {
7023
7034
  return;
7024
7035
  writeElementList(copyElementList, draw.getOptions());
7025
7036
  }
7026
- function drop(evt, host) {
7037
+ async function drop(evt, host) {
7027
7038
  var _a, _b;
7028
7039
  const draw = host.getDraw();
7029
7040
  const { drop: drop2 } = draw.getOverride();
7030
7041
  if (drop2) {
7031
- drop2(evt);
7032
- return;
7042
+ const overrideResult = isPromiseFunction(drop2) ? await drop2(evt) : drop2(evt);
7043
+ if ((overrideResult == null ? void 0 : overrideResult.preventDefault) !== false)
7044
+ return;
7033
7045
  }
7034
7046
  evt.preventDefault();
7035
7047
  const data2 = (_a = evt.dataTransfer) == null ? void 0 : _a.getData("text");
@@ -9768,6 +9780,8 @@ class TableParticle {
9768
9780
  td.height = height;
9769
9781
  td.rowIndex = t;
9770
9782
  td.colIndex = colIndex;
9783
+ td.trIndex = t;
9784
+ td.tdIndex = d;
9771
9785
  preX += width;
9772
9786
  if (isLastRowTd && !isLastTd) {
9773
9787
  preX = 0;
@@ -12327,6 +12341,12 @@ class Control {
12327
12341
  element.control = __spreadProps(__spreadValues(__spreadValues({}, element.control), properties), {
12328
12342
  value: element.control.value
12329
12343
  });
12344
+ CONTROL_STYLE_ATTR.forEach((key) => {
12345
+ const controlStyleProperty = properties[key];
12346
+ if (controlStyleProperty) {
12347
+ Reflect.set(element, key, controlStyleProperty);
12348
+ }
12349
+ });
12330
12350
  let newEndIndex = i;
12331
12351
  while (newEndIndex < elementList.length) {
12332
12352
  const nextElement = elementList[newEndIndex];
@@ -12937,7 +12957,7 @@ class Previewer {
12937
12957
  document.addEventListener("mousemove", mousemoveFn);
12938
12958
  document.addEventListener("mouseup", () => {
12939
12959
  var _a;
12940
- if (this.curElement) {
12960
+ if (this.curElement && !this.previewerDrawOption.dragDisable) {
12941
12961
  this.curElement.width = this.width;
12942
12962
  this.curElement.height = this.height;
12943
12963
  this.draw.render({
@@ -12955,7 +12975,7 @@ class Previewer {
12955
12975
  evt.preventDefault();
12956
12976
  }
12957
12977
  _mousemove(evt) {
12958
- if (!this.curElement)
12978
+ if (!this.curElement || this.previewerDrawOption.dragDisable)
12959
12979
  return;
12960
12980
  const { scale } = this.options;
12961
12981
  let dx = 0;
@@ -14630,6 +14650,7 @@ class Draw {
14630
14650
  this.setEditorData(this.printModeData);
14631
14651
  this.printModeData = null;
14632
14652
  }
14653
+ this.clearSideEffect();
14633
14654
  this.range.clearRange();
14634
14655
  this.mode = payload;
14635
14656
  this.render({
@@ -17775,7 +17796,11 @@ class CommandAdapt {
17775
17796
  d++;
17776
17797
  }
17777
17798
  }
17778
- const curIndex = startTd.value.length - 1;
17799
+ this.position.setPositionContext(__spreadProps(__spreadValues({}, positionContext), {
17800
+ trIndex: anchorTd.trIndex,
17801
+ tdIndex: anchorTd.tdIndex
17802
+ }));
17803
+ const curIndex = anchorTd.value.length - 1;
17779
17804
  this.range.setRange(curIndex, curIndex);
17780
17805
  this.draw.render();
17781
17806
  this.tableTool.render();
@@ -19098,7 +19123,7 @@ const controlMenus = [
19098
19123
  i18nPath: "contextmenu.control.delete",
19099
19124
  when: (payload) => {
19100
19125
  var _a;
19101
- return !payload.isReadonly && !payload.editorHasSelection && !!((_a = payload.startElement) == null ? void 0 : _a.controlId);
19126
+ return !payload.isReadonly && !payload.editorHasSelection && !!((_a = payload.startElement) == null ? void 0 : _a.controlId) && payload.options.mode !== EditorMode.FORM;
19102
19127
  },
19103
19128
  callback: (command) => {
19104
19129
  command.executeRemoveControl();
@@ -19295,7 +19320,7 @@ const tableMenus = [
19295
19320
  i18nPath: "contextmenu.table.border",
19296
19321
  icon: "border-all",
19297
19322
  when: (payload) => {
19298
- return !payload.isReadonly && payload.isInTable;
19323
+ return !payload.isReadonly && payload.isInTable && payload.options.mode !== EditorMode.FORM;
19299
19324
  },
19300
19325
  childMenus: [
19301
19326
  {
@@ -19394,7 +19419,7 @@ const tableMenus = [
19394
19419
  i18nPath: "contextmenu.table.verticalAlign",
19395
19420
  icon: "vertical-align",
19396
19421
  when: (payload) => {
19397
- return !payload.isReadonly && payload.isInTable;
19422
+ return !payload.isReadonly && payload.isInTable && payload.options.mode !== EditorMode.FORM;
19398
19423
  },
19399
19424
  childMenus: [
19400
19425
  {
@@ -19431,7 +19456,7 @@ const tableMenus = [
19431
19456
  i18nPath: "contextmenu.table.insertRowCol",
19432
19457
  icon: "insert-row-col",
19433
19458
  when: (payload) => {
19434
- return !payload.isReadonly && payload.isInTable;
19459
+ return !payload.isReadonly && payload.isInTable && payload.options.mode !== EditorMode.FORM;
19435
19460
  },
19436
19461
  childMenus: [
19437
19462
  {
@@ -19477,7 +19502,7 @@ const tableMenus = [
19477
19502
  i18nPath: "contextmenu.table.deleteRowCol",
19478
19503
  icon: "delete-row-col",
19479
19504
  when: (payload) => {
19480
- return !payload.isReadonly && payload.isInTable;
19505
+ return !payload.isReadonly && payload.isInTable && payload.options.mode !== EditorMode.FORM;
19481
19506
  },
19482
19507
  childMenus: [
19483
19508
  {
@@ -19514,7 +19539,7 @@ const tableMenus = [
19514
19539
  i18nPath: "contextmenu.table.mergeCell",
19515
19540
  icon: "merge-cell",
19516
19541
  when: (payload) => {
19517
- return !payload.isReadonly && payload.isCrossRowCol;
19542
+ return !payload.isReadonly && payload.isCrossRowCol && payload.options.mode !== EditorMode.FORM;
19518
19543
  },
19519
19544
  callback: (command) => {
19520
19545
  command.executeMergeTableCell();
@@ -19525,7 +19550,7 @@ const tableMenus = [
19525
19550
  i18nPath: "contextmenu.table.mergeCancelCell",
19526
19551
  icon: "merge-cancel-cell",
19527
19552
  when: (payload) => {
19528
- return !payload.isReadonly && payload.isInTable;
19553
+ return !payload.isReadonly && payload.isInTable && payload.options.mode !== EditorMode.FORM;
19529
19554
  },
19530
19555
  callback: (command) => {
19531
19556
  command.executeCancelMergeTableCell();
@@ -19647,7 +19672,8 @@ class ContextMenu {
19647
19672
  isInTable: isTable,
19648
19673
  trIndex: trIndex != null ? trIndex : null,
19649
19674
  tdIndex: tdIndex != null ? tdIndex : null,
19650
- tableElement
19675
+ tableElement,
19676
+ options: this.options
19651
19677
  };
19652
19678
  }
19653
19679
  _createContextMenuContainer() {