@hufe921/canvas-editor 0.9.63 → 0.9.64

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,20 @@
1
+ ## [0.9.64](https://github.com/Hufe921/canvas-editor/compare/v0.9.63...v0.9.64) (2024-01-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * error inserting image within control #422 ([ea4ac33](https://github.com/Hufe921/canvas-editor/commit/ea4ac339c7de962845f639a1c5ac24d8e3640485)), closes [#422](https://github.com/Hufe921/canvas-editor/issues/422)
7
+ * render error when row element is empty #420 ([8999f28](https://github.com/Hufe921/canvas-editor/commit/8999f283bb87d92fe58b1aa8330bf4d9d75b9064)), closes [#420](https://github.com/Hufe921/canvas-editor/issues/420)
8
+ * zone tip position error in firefox browser #423 ([3cf911c](https://github.com/Hufe921/canvas-editor/commit/3cf911c501a0c0af85d994d5b50c657c6cd77692)), closes [#423](https://github.com/Hufe921/canvas-editor/issues/423)
9
+
10
+
11
+ ### Features
12
+
13
+ * add executeSetControlProperties api #391 ([3ffb6b9](https://github.com/Hufe921/canvas-editor/commit/3ffb6b94b57a0d0fe81cc778a26d4e2a234e24ab)), closes [#391](https://github.com/Hufe921/canvas-editor/issues/391)
14
+ * copy and paste original elements #397 (#426) ([2fc16de](https://github.com/Hufe921/canvas-editor/commit/2fc16de4e15578cdd181c4186b4cf978924b5207)), closes [#397](https://github.com/Hufe921/canvas-editor/issues/397) [#426](https://github.com/Hufe921/canvas-editor/issues/426)
15
+
16
+
17
+
1
18
  ## [0.9.63](https://github.com/Hufe921/canvas-editor/compare/v0.9.62...v0.9.63) (2024-01-19)
2
19
 
3
20
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.63";
26
+ const version = "0.9.64";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -327,6 +327,7 @@ const defaultCursorOption = {
327
327
  };
328
328
  const EDITOR_COMPONENT = "editor-component";
329
329
  const EDITOR_PREFIX = "ce";
330
+ const EDITOR_CLIPBOARD = `${EDITOR_PREFIX}-clipboard`;
330
331
  var MoveDirection;
331
332
  (function(MoveDirection2) {
332
333
  MoveDirection2["UP"] = "top";
@@ -3747,6 +3748,10 @@ function formatElementList(elementList, options) {
3747
3748
  }
3748
3749
  i--;
3749
3750
  } else if (el.type === ElementType.CONTROL) {
3751
+ if (!el.control) {
3752
+ i++;
3753
+ continue;
3754
+ }
3750
3755
  const { prefix, postfix, value, placeholder, code, type, valueSets } = el.control;
3751
3756
  const { editorOptions: { control: controlOption, checkbox: checkboxOption } } = options;
3752
3757
  const controlId = getUUID();
@@ -4549,35 +4554,81 @@ ${listIndex + 1}.${buildText(listElementList)}${isLast ? `
4549
4554
  }
4550
4555
  return buildText(zipElementList(elementList));
4551
4556
  }
4552
- function pastHTML(host, htmlText) {
4557
+ function setClipboardData(data2) {
4558
+ localStorage.setItem(EDITOR_CLIPBOARD, JSON.stringify({
4559
+ text: data2.text,
4560
+ elementList: data2.elementList
4561
+ }));
4562
+ }
4563
+ function getClipboardData() {
4564
+ const clipboardText = localStorage.getItem(EDITOR_CLIPBOARD);
4565
+ return clipboardText ? JSON.parse(clipboardText) : null;
4566
+ }
4567
+ function removeClipboardData() {
4568
+ localStorage.removeItem(EDITOR_CLIPBOARD);
4569
+ }
4570
+ function writeClipboardItem(text, html, elementList) {
4571
+ if (!text && !html && !elementList.length)
4572
+ return;
4573
+ const plainText = new Blob([text], { type: "text/plain" });
4574
+ const htmlText = new Blob([html], { type: "text/html" });
4575
+ if (window.ClipboardItem) {
4576
+ const item = new ClipboardItem({
4577
+ [plainText.type]: plainText,
4578
+ [htmlText.type]: htmlText
4579
+ });
4580
+ window.navigator.clipboard.write([item]);
4581
+ } else {
4582
+ const fakeElement = document.createElement("div");
4583
+ fakeElement.setAttribute("contenteditable", "true");
4584
+ fakeElement.innerHTML = html;
4585
+ document.body.append(fakeElement);
4586
+ const selection = window.getSelection();
4587
+ const range = document.createRange();
4588
+ range.selectNodeContents(fakeElement);
4589
+ selection == null ? void 0 : selection.removeAllRanges();
4590
+ selection == null ? void 0 : selection.addRange(range);
4591
+ document.execCommand("copy");
4592
+ fakeElement.remove();
4593
+ }
4594
+ setClipboardData({ text, elementList });
4595
+ }
4596
+ function writeElementList(elementList, options) {
4597
+ const clipboardDom = createDomFromElementList(elementList, options);
4598
+ document.body.append(clipboardDom);
4599
+ const text = clipboardDom.innerText;
4600
+ clipboardDom.remove();
4601
+ const html = clipboardDom.innerHTML;
4602
+ if (!text && !html && !elementList.length)
4603
+ return;
4604
+ writeClipboardItem(text, html, zipElementList(elementList));
4605
+ }
4606
+ function pasteElement(host, elementList) {
4553
4607
  const draw = host.getDraw();
4554
4608
  const isReadonly = draw.isReadonly();
4555
4609
  if (isReadonly)
4556
4610
  return;
4557
4611
  const rangeManager = draw.getRange();
4558
4612
  const { startIndex } = rangeManager.getRange();
4559
- const elementList = draw.getElementList();
4560
- const pasteElementList = getElementListByHTML(htmlText, {
4561
- innerWidth: draw.getOriginalInnerWidth()
4562
- });
4613
+ const originalElementList = draw.getElementList();
4563
4614
  if (~startIndex && !rangeManager.getIsSelectAll()) {
4564
- const anchorElement = elementList[startIndex];
4615
+ const anchorElement = originalElementList[startIndex];
4565
4616
  if ((anchorElement == null ? void 0 : anchorElement.titleId) || (anchorElement == null ? void 0 : anchorElement.listId)) {
4566
4617
  let start = 0;
4567
- while (start < pasteElementList.length) {
4568
- const pasteElement = pasteElementList[start];
4569
- if (anchorElement.titleId && /^\n/.test(pasteElement.value)) {
4618
+ while (start < elementList.length) {
4619
+ const pasteElement2 = elementList[start];
4620
+ if (anchorElement.titleId && /^\n/.test(pasteElement2.value)) {
4570
4621
  break;
4571
4622
  }
4572
- if (VIRTUAL_ELEMENT_TYPE.includes(pasteElement.type)) {
4573
- pasteElementList.splice(start, 1);
4574
- if (pasteElement.valueList) {
4575
- for (let v = 0; v < pasteElement.valueList.length; v++) {
4576
- const element = pasteElement.valueList[v];
4623
+ if (VIRTUAL_ELEMENT_TYPE.includes(pasteElement2.type)) {
4624
+ elementList.splice(start, 1);
4625
+ if (pasteElement2.valueList) {
4626
+ for (let v = 0; v < pasteElement2.valueList.length; v++) {
4627
+ const element = pasteElement2.valueList[v];
4577
4628
  if (element.value === ZERO || element.value === "\n") {
4578
4629
  continue;
4579
4630
  }
4580
- pasteElementList.splice(start, 0, element);
4631
+ elementList.splice(start, 0, element);
4581
4632
  start++;
4582
4633
  }
4583
4634
  }
@@ -4586,11 +4637,21 @@ function pastHTML(host, htmlText) {
4586
4637
  start++;
4587
4638
  }
4588
4639
  }
4589
- formatElementContext(elementList, pasteElementList, startIndex, {
4640
+ formatElementContext(originalElementList, elementList, startIndex, {
4590
4641
  isBreakWhenWrap: true
4591
4642
  });
4592
4643
  }
4593
- draw.insertElementList(pasteElementList);
4644
+ draw.insertElementList(elementList);
4645
+ }
4646
+ function pasteHTML(host, htmlText) {
4647
+ const draw = host.getDraw();
4648
+ const isReadonly = draw.isReadonly();
4649
+ if (isReadonly)
4650
+ return;
4651
+ const elementList = getElementListByHTML(htmlText, {
4652
+ innerWidth: draw.getOriginalInnerWidth()
4653
+ });
4654
+ pasteElement(host, elementList);
4594
4655
  }
4595
4656
  function pasteImage(host, file) {
4596
4657
  const draw = host.getDraw();
@@ -4633,6 +4694,13 @@ function pasteByEvent(host, evt) {
4633
4694
  paste(evt);
4634
4695
  return;
4635
4696
  }
4697
+ const clipboardText = clipboardData.getData("text");
4698
+ const editorClipboardData = getClipboardData();
4699
+ if (clipboardText === (editorClipboardData == null ? void 0 : editorClipboardData.text)) {
4700
+ pasteElement(host, editorClipboardData.elementList);
4701
+ return;
4702
+ }
4703
+ removeClipboardData();
4636
4704
  let isHTML = false;
4637
4705
  for (let i = 0; i < clipboardData.items.length; i++) {
4638
4706
  const item = clipboardData.items[i];
@@ -4652,7 +4720,7 @@ function pasteByEvent(host, evt) {
4652
4720
  }
4653
4721
  if (item.type === "text/html" && isHTML) {
4654
4722
  item.getAsString((htmlText) => {
4655
- pastHTML(host, htmlText);
4723
+ pasteHTML(host, htmlText);
4656
4724
  });
4657
4725
  break;
4658
4726
  }
@@ -4701,7 +4769,7 @@ async function pasteByApi(host, options) {
4701
4769
  const htmlTextBlob = await item.getType("text/html");
4702
4770
  const htmlText = await htmlTextBlob.text();
4703
4771
  if (htmlText) {
4704
- pastHTML(host, htmlText);
4772
+ pasteHTML(host, htmlText);
4705
4773
  }
4706
4774
  } else if (item.types.some((type) => type.startsWith("image/"))) {
4707
4775
  const type = item.types.find((type2) => type2.startsWith("image/"));
@@ -5901,41 +5969,6 @@ function removeComposingInput(host) {
5901
5969
  rangeManager.setRange(startIndex, startIndex);
5902
5970
  host.compositionInfo = null;
5903
5971
  }
5904
- function writeClipboardItem(text, html) {
5905
- if (!text || !html)
5906
- return;
5907
- const plainText = new Blob([text], { type: "text/plain" });
5908
- const htmlText = new Blob([html], { type: "text/html" });
5909
- if (window.ClipboardItem) {
5910
- const item = new ClipboardItem({
5911
- [plainText.type]: plainText,
5912
- [htmlText.type]: htmlText
5913
- });
5914
- window.navigator.clipboard.write([item]);
5915
- } else {
5916
- const fakeElement = document.createElement("div");
5917
- fakeElement.setAttribute("contenteditable", "true");
5918
- fakeElement.innerHTML = html;
5919
- document.body.append(fakeElement);
5920
- const selection = window.getSelection();
5921
- const range = document.createRange();
5922
- range.selectNodeContents(fakeElement);
5923
- selection == null ? void 0 : selection.removeAllRanges();
5924
- selection == null ? void 0 : selection.addRange(range);
5925
- document.execCommand("copy");
5926
- fakeElement.remove();
5927
- }
5928
- }
5929
- function writeElementList(elementList, options) {
5930
- const clipboardDom = createDomFromElementList(elementList, options);
5931
- document.body.append(clipboardDom);
5932
- const text = clipboardDom.innerText;
5933
- clipboardDom.remove();
5934
- const html = clipboardDom.innerHTML;
5935
- if (!text || !html)
5936
- return;
5937
- writeClipboardItem(text, html);
5938
- }
5939
5972
  function cut(host) {
5940
5973
  const draw = host.getDraw();
5941
5974
  const rangeManager = draw.getRange();
@@ -6638,6 +6671,7 @@ class Position {
6638
6671
  return { x, y, index: index2 };
6639
6672
  }
6640
6673
  computePositionList() {
6674
+ var _a;
6641
6675
  this.positionList = [];
6642
6676
  const innerWidth = this.draw.getInnerWidth();
6643
6677
  const pageRowList = this.draw.getPageRowList();
@@ -6649,7 +6683,7 @@ class Position {
6649
6683
  let startRowIndex = 0;
6650
6684
  for (let i = 0; i < pageRowList.length; i++) {
6651
6685
  const rowList = pageRowList[i];
6652
- const startIndex = rowList[0].startIndex;
6686
+ const startIndex = (_a = rowList[0]) == null ? void 0 : _a.startIndex;
6653
6687
  this.computePageRowPosition({
6654
6688
  positionList: this.positionList,
6655
6689
  rowList,
@@ -9600,6 +9634,17 @@ class Control {
9600
9634
  }
9601
9635
  return false;
9602
9636
  }
9637
+ isRangeCanInput() {
9638
+ const { startIndex, endIndex } = this.getRange();
9639
+ if (!~startIndex && !~endIndex)
9640
+ return false;
9641
+ if (startIndex === endIndex)
9642
+ return true;
9643
+ const elementList = this.getElementList();
9644
+ const startElement = elementList[startIndex];
9645
+ const endElement = elementList[endIndex];
9646
+ return !startElement.controlId && !endElement.controlId || (!startElement.controlId || startElement.controlComponent === ControlComponent.POSTFIX) && endElement.controlComponent === ControlComponent.POSTFIX || !!startElement.controlId && endElement.controlId === startElement.controlId && endElement.controlComponent !== ControlComponent.POSTFIX;
9647
+ }
9603
9648
  isDisabledControl() {
9604
9649
  var _a, _b;
9605
9650
  return !!((_b = (_a = this.activeControl) == null ? void 0 : _a.getElement().control) == null ? void 0 : _b.disabled);
@@ -10066,6 +10111,55 @@ class Control {
10066
10111
  setExtension(elementList);
10067
10112
  }
10068
10113
  }
10114
+ setPropertiesByConceptId(payload) {
10115
+ var _a;
10116
+ const isReadonly = this.draw.isReadonly();
10117
+ if (isReadonly)
10118
+ return;
10119
+ const { conceptId, properties } = payload;
10120
+ let isExistUpdate = false;
10121
+ const pageComponentData = {
10122
+ header: this.draw.getHeaderElementList(),
10123
+ main: this.draw.getOriginalMainElementList(),
10124
+ footer: this.draw.getFooterElementList()
10125
+ };
10126
+ for (const key in pageComponentData) {
10127
+ const elementList = pageComponentData[key];
10128
+ let i = 0;
10129
+ while (i < elementList.length) {
10130
+ const element = elementList[i];
10131
+ i++;
10132
+ if (((_a = element == null ? void 0 : element.control) == null ? void 0 : _a.conceptId) !== conceptId)
10133
+ continue;
10134
+ isExistUpdate = true;
10135
+ element.control = __spreadProps(__spreadValues(__spreadValues({}, element.control), properties), {
10136
+ value: element.control.value
10137
+ });
10138
+ let newEndIndex = i;
10139
+ while (newEndIndex < elementList.length) {
10140
+ const nextElement = elementList[newEndIndex];
10141
+ if (nextElement.controlId !== element.controlId)
10142
+ break;
10143
+ newEndIndex++;
10144
+ }
10145
+ i = newEndIndex;
10146
+ }
10147
+ }
10148
+ if (!isExistUpdate)
10149
+ return;
10150
+ for (const key in pageComponentData) {
10151
+ const pageComponentKey = key;
10152
+ const elementList = zipElementList(pageComponentData[pageComponentKey]);
10153
+ pageComponentData[pageComponentKey] = elementList;
10154
+ formatElementList(elementList, {
10155
+ editorOptions: this.options
10156
+ });
10157
+ }
10158
+ this.draw.setEditorData(pageComponentData);
10159
+ this.draw.render({
10160
+ isSetCursor: false
10161
+ });
10162
+ }
10069
10163
  }
10070
10164
  class CheckboxParticle {
10071
10165
  constructor(draw) {
@@ -11519,6 +11613,8 @@ class ZoneTip {
11519
11613
  this.pageContainer.addEventListener("mousemove", throttle((evt) => {
11520
11614
  if (this.isDisableMouseMove)
11521
11615
  return;
11616
+ if (!evt.offsetY)
11617
+ return;
11522
11618
  if (evt.target instanceof HTMLCanvasElement) {
11523
11619
  const mousemoveZone = this.zone.getZoneByY(evt.offsetY);
11524
11620
  if (!watchZones.includes(mousemoveZone)) {
@@ -12564,8 +12660,8 @@ class Draw {
12564
12660
  insertElementList(payload) {
12565
12661
  if (!payload.length)
12566
12662
  return;
12567
- const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside();
12568
- if (isPartRangeInControlOutside)
12663
+ const isRangeCanInput = this.control.isRangeCanInput();
12664
+ if (!isRangeCanInput)
12569
12665
  return;
12570
12666
  const { startIndex, endIndex } = this.range.getRange();
12571
12667
  if (!~startIndex && !~endIndex)
@@ -12575,7 +12671,11 @@ class Draw {
12575
12671
  editorOptions: this.options
12576
12672
  });
12577
12673
  let curIndex = -1;
12578
- const activeControl = this.control.getActiveControl();
12674
+ let activeControl = this.control.getActiveControl();
12675
+ if (!activeControl && this.control.isRangeWithinControl()) {
12676
+ this.control.initControl();
12677
+ activeControl = this.control.getActiveControl();
12678
+ }
12579
12679
  if (activeControl && !this.control.isRangInPostfix()) {
12580
12680
  curIndex = activeControl.setValue(payload, void 0, {
12581
12681
  isIgnoreDisabledRule: true
@@ -13517,7 +13617,7 @@ class Draw {
13517
13617
  this.blockParticle.clear();
13518
13618
  }
13519
13619
  _drawPage(payload) {
13520
- var _a;
13620
+ var _a, _b;
13521
13621
  const { elementList, positionList, rowList, pageNo } = payload;
13522
13622
  const { inactiveAlpha, pageMode, header, footer, pageNumber } = this.options;
13523
13623
  const innerWidth = this.getInnerWidth();
@@ -13529,7 +13629,7 @@ class Draw {
13529
13629
  this.margin.render(ctx, pageNo);
13530
13630
  }
13531
13631
  this.control.renderHighlightList(ctx, pageNo);
13532
- const index2 = rowList[0].startIndex;
13632
+ const index2 = (_a = rowList[0]) == null ? void 0 : _a.startIndex;
13533
13633
  this.drawRow(ctx, {
13534
13634
  elementList,
13535
13635
  positionList,
@@ -13556,7 +13656,7 @@ class Draw {
13556
13656
  if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
13557
13657
  this.waterMark.render(ctx);
13558
13658
  }
13559
- if (this.elementList.length <= 1 && !((_a = this.elementList[0]) == null ? void 0 : _a.listId)) {
13659
+ if (this.elementList.length <= 1 && !((_b = this.elementList[0]) == null ? void 0 : _b.listId)) {
13560
13660
  this.placeholder.render(ctx);
13561
13661
  }
13562
13662
  }
@@ -13800,6 +13900,7 @@ class Command {
13800
13900
  __publicField(this, "executeSetZone");
13801
13901
  __publicField(this, "executeSetControlValue");
13802
13902
  __publicField(this, "executeSetControlExtension");
13903
+ __publicField(this, "executeSetControlProperties");
13803
13904
  __publicField(this, "executeSetControlHighlight");
13804
13905
  __publicField(this, "getCatalog");
13805
13906
  __publicField(this, "getImage");
@@ -13922,6 +14023,7 @@ class Command {
13922
14023
  this.getContainer = adapt.getContainer.bind(adapt);
13923
14024
  this.executeSetControlValue = adapt.setControlValue.bind(adapt);
13924
14025
  this.executeSetControlExtension = adapt.setControlExtension.bind(adapt);
14026
+ this.executeSetControlProperties = adapt.setControlProperties.bind(adapt);
13925
14027
  this.executeSetControlHighlight = adapt.setControlHighlight.bind(adapt);
13926
14028
  this.getControlValue = adapt.getControlValue.bind(adapt);
13927
14029
  }
@@ -15473,26 +15575,19 @@ class CommandAdapt {
15473
15575
  const isDisabled = this.draw.isReadonly() || this.control.isDisabledControl();
15474
15576
  if (isDisabled)
15475
15577
  return;
15476
- const activeControl = this.control.getActiveControl();
15477
- if (activeControl)
15478
- return;
15479
15578
  const { startIndex, endIndex } = this.range.getRange();
15480
15579
  if (!~startIndex && !~endIndex)
15481
15580
  return;
15482
- const elementList = this.draw.getElementList();
15483
15581
  const { value, width, height } = payload;
15484
- const element = {
15485
- value,
15486
- width,
15487
- height,
15488
- id: getUUID(),
15489
- type: ElementType.IMAGE
15490
- };
15491
- const curIndex = startIndex + 1;
15492
- formatElementContext(elementList, [element], startIndex);
15493
- this.draw.spliceElementList(elementList, curIndex, startIndex === endIndex ? 0 : endIndex - startIndex, element);
15494
- this.range.setRange(curIndex, curIndex);
15495
- this.draw.render({ curIndex });
15582
+ this.draw.insertElementList([
15583
+ {
15584
+ value,
15585
+ width,
15586
+ height,
15587
+ id: getUUID(),
15588
+ type: ElementType.IMAGE
15589
+ }
15590
+ ]);
15496
15591
  }
15497
15592
  search(payload) {
15498
15593
  this.searchManager.setSearchKeyword(payload);
@@ -15975,6 +16070,12 @@ class CommandAdapt {
15975
16070
  return;
15976
16071
  this.draw.getControl().setExtensionByConceptId(payload);
15977
16072
  }
16073
+ setControlProperties(payload) {
16074
+ const isReadonly = this.draw.isReadonly();
16075
+ if (isReadonly)
16076
+ return;
16077
+ this.draw.getControl().setPropertiesByConceptId(payload);
16078
+ }
15978
16079
  setControlHighlight(payload) {
15979
16080
  this.draw.getControl().setHighlightList(payload);
15980
16081
  }