@hufe921/canvas-editor 0.9.12 → 0.9.13

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.
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.12";
26
+ const version = "0.9.13";
27
27
  const ZERO = "\u200B";
28
28
  const WRAP = "\n";
29
29
  var RowFlex;
@@ -187,6 +187,25 @@ const TEXTLIKE_ELEMENT_TYPE = [
187
187
  ElementType.CONTROL,
188
188
  ElementType.DATE
189
189
  ];
190
+ var ControlType;
191
+ (function(ControlType2) {
192
+ ControlType2["TEXT"] = "text";
193
+ ControlType2["SELECT"] = "select";
194
+ ControlType2["CHECKBOX"] = "checkbox";
195
+ })(ControlType || (ControlType = {}));
196
+ var ControlComponent;
197
+ (function(ControlComponent2) {
198
+ ControlComponent2["PREFIX"] = "prefix";
199
+ ControlComponent2["POSTFIX"] = "postfix";
200
+ ControlComponent2["PLACEHOLDER"] = "placeholder";
201
+ ControlComponent2["VALUE"] = "value";
202
+ ControlComponent2["CHECKBOX"] = "checkbox";
203
+ })(ControlComponent || (ControlComponent = {}));
204
+ var ImageDisplay;
205
+ (function(ImageDisplay2) {
206
+ ImageDisplay2["INLINE"] = "inline";
207
+ ImageDisplay2["BLOCK"] = "block";
208
+ })(ImageDisplay || (ImageDisplay = {}));
190
209
  class ImageParticle {
191
210
  constructor(draw) {
192
211
  __publicField(this, "options");
@@ -3178,25 +3197,6 @@ const defaultControlOption = {
3178
3197
  prefix: "{",
3179
3198
  postfix: "}"
3180
3199
  };
3181
- var ControlType;
3182
- (function(ControlType2) {
3183
- ControlType2["TEXT"] = "text";
3184
- ControlType2["SELECT"] = "select";
3185
- ControlType2["CHECKBOX"] = "checkbox";
3186
- })(ControlType || (ControlType = {}));
3187
- var ControlComponent;
3188
- (function(ControlComponent2) {
3189
- ControlComponent2["PREFIX"] = "prefix";
3190
- ControlComponent2["POSTFIX"] = "postfix";
3191
- ControlComponent2["PLACEHOLDER"] = "placeholder";
3192
- ControlComponent2["VALUE"] = "value";
3193
- ControlComponent2["CHECKBOX"] = "checkbox";
3194
- })(ControlComponent || (ControlComponent = {}));
3195
- var ImageDisplay;
3196
- (function(ImageDisplay2) {
3197
- ImageDisplay2["INLINE"] = "inline";
3198
- ImageDisplay2["BLOCK"] = "block";
3199
- })(ImageDisplay || (ImageDisplay = {}));
3200
3200
  function formatElementList(elementList, options) {
3201
3201
  var _a;
3202
3202
  const { isHandleFirstElement, editorOptions } = __spreadValues({
@@ -3580,7 +3580,7 @@ function writeClipboardItem(text, html) {
3580
3580
  function writeElementList(elementList, options) {
3581
3581
  const clipboardDom = document.createElement("div");
3582
3582
  function buildDomFromElementList(payload) {
3583
- var _a, _b, _c, _d;
3583
+ var _a, _b, _c, _d, _e;
3584
3584
  for (let e = 0; e < payload.length; e++) {
3585
3585
  const element = payload[e];
3586
3586
  if (element.type === ElementType.TABLE) {
@@ -3593,6 +3593,8 @@ function writeElementList(elementList, options) {
3593
3593
  const tdDom = document.createElement("td");
3594
3594
  tdDom.style.border = "1px solid";
3595
3595
  const td = tr.tdList[d];
3596
+ tdDom.colSpan = td.colspan;
3597
+ tdDom.rowSpan = td.rowspan;
3596
3598
  tdDom.innerText = ((_a = td.value[0]) == null ? void 0 : _a.value) || "";
3597
3599
  trDom.append(tdDom);
3598
3600
  }
@@ -3617,12 +3619,19 @@ function writeElementList(elementList, options) {
3617
3619
  } else if (element.type === ElementType.SEPARATOR) {
3618
3620
  const hr = document.createElement("hr");
3619
3621
  clipboardDom.append(hr);
3622
+ } else if (element.type === ElementType.CHECKBOX) {
3623
+ const checkbox = document.createElement("input");
3624
+ checkbox.type = "checkbox";
3625
+ if ((_b = element.checkbox) == null ? void 0 : _b.value) {
3626
+ checkbox.setAttribute("checked", "true");
3627
+ }
3628
+ clipboardDom.append(checkbox);
3620
3629
  } else if (!element.type || element.type === ElementType.LATEX || TEXTLIKE_ELEMENT_TYPE.includes(element.type)) {
3621
3630
  let text2 = "";
3622
3631
  if (element.type === ElementType.CONTROL) {
3623
- text2 = ((_c = (_b = element.control.value) == null ? void 0 : _b[0]) == null ? void 0 : _c.value) || "";
3632
+ text2 = ((_d = (_c = element.control.value) == null ? void 0 : _c[0]) == null ? void 0 : _d.value) || "";
3624
3633
  } else if (element.type === ElementType.DATE) {
3625
- text2 = ((_d = element.valueList) == null ? void 0 : _d.map((v) => v.value).join("")) || "";
3634
+ text2 = ((_e = element.valueList) == null ? void 0 : _e.map((v) => v.value).join("")) || "";
3626
3635
  } else {
3627
3636
  text2 = element.value;
3628
3637
  }
@@ -3660,13 +3669,14 @@ function writeElementList(elementList, options) {
3660
3669
  return;
3661
3670
  writeClipboardItem(text, html);
3662
3671
  }
3663
- function getElementListByHTML(htmlText) {
3672
+ function getElementListByHTML(htmlText, options) {
3664
3673
  const elementList = [];
3665
3674
  function findTextNode(dom) {
3675
+ var _a;
3666
3676
  if (dom.nodeType === 3) {
3667
3677
  const style = window.getComputedStyle(dom.parentNode);
3668
3678
  const value = dom.textContent;
3669
- if (value) {
3679
+ if (value && ((_a = dom.parentNode) == null ? void 0 : _a.nodeName) !== "STYLE") {
3670
3680
  elementList.push({
3671
3681
  value,
3672
3682
  color: style.color,
@@ -3696,6 +3706,72 @@ function getElementListByHTML(htmlText) {
3696
3706
  url: aElement.href
3697
3707
  });
3698
3708
  }
3709
+ } else if (node.nodeName === "HR") {
3710
+ elementList.push({
3711
+ value: "\n",
3712
+ type: ElementType.SEPARATOR
3713
+ });
3714
+ } else if (node.nodeName === "IMG") {
3715
+ const { src, width, height } = node;
3716
+ if (src && width && height) {
3717
+ elementList.push({
3718
+ width,
3719
+ height,
3720
+ value: src,
3721
+ type: ElementType.IMAGE
3722
+ });
3723
+ }
3724
+ } else if (node.nodeName === "TABLE") {
3725
+ const tableElement = node;
3726
+ const element = {
3727
+ type: ElementType.TABLE,
3728
+ value: "\n",
3729
+ colgroup: [],
3730
+ trList: []
3731
+ };
3732
+ let tdCount = 0;
3733
+ tableElement.querySelectorAll("tr").forEach((trElement, trIndex) => {
3734
+ const trHeightStr = window.getComputedStyle(trElement).height.replace("px", "");
3735
+ const tr = {
3736
+ height: Number(trHeightStr),
3737
+ tdList: []
3738
+ };
3739
+ trElement.querySelectorAll("td").forEach((tdElement) => {
3740
+ const colspan = tdElement.colSpan;
3741
+ const rowspan = tdElement.rowSpan;
3742
+ if (trIndex === 0) {
3743
+ tdCount += colspan;
3744
+ }
3745
+ const td = {
3746
+ colspan,
3747
+ rowspan,
3748
+ value: [{
3749
+ value: tdElement.innerText
3750
+ }]
3751
+ };
3752
+ tr.tdList.push(td);
3753
+ });
3754
+ element.trList.push(tr);
3755
+ });
3756
+ if (tdCount) {
3757
+ const width = Math.ceil(options.innerWidth / tdCount);
3758
+ for (let i = 0; i < tdCount; i++) {
3759
+ element.colgroup.push({
3760
+ width
3761
+ });
3762
+ }
3763
+ }
3764
+ if (element.colgroup) {
3765
+ elementList.push(element);
3766
+ }
3767
+ } else if (node.nodeName === "INPUT" && node.type === ControlComponent.CHECKBOX) {
3768
+ elementList.push({
3769
+ type: ElementType.CHECKBOX,
3770
+ value: "",
3771
+ checkbox: {
3772
+ value: node.checked
3773
+ }
3774
+ });
3699
3775
  } else {
3700
3776
  findTextNode(node);
3701
3777
  if (node.nodeType === 1 && n !== childNodes.length - 1) {
@@ -3778,7 +3854,9 @@ class CursorAgent {
3778
3854
  }
3779
3855
  if (item.type === "text/html" && isHTML) {
3780
3856
  item.getAsString((htmlText) => {
3781
- const elementList = getElementListByHTML(htmlText);
3857
+ const elementList = getElementListByHTML(htmlText, {
3858
+ innerWidth: this.draw.getOriginalInnerWidth()
3859
+ });
3782
3860
  this.draw.insertElementList(elementList);
3783
3861
  });
3784
3862
  }
@@ -4392,7 +4470,7 @@ function keydown(evt, host) {
4392
4470
  } else if (evt.key === KeyMap.Right) {
4393
4471
  if (isReadonly)
4394
4472
  return;
4395
- if (index2 < positionList.length - 1) {
4473
+ if (index2 < positionList.length) {
4396
4474
  const curIndex = endIndex + 1;
4397
4475
  let anchorStartIndex = curIndex;
4398
4476
  let anchorEndIndex = curIndex;
@@ -11375,11 +11453,11 @@ class ContextMenu {
11375
11453
  this._addEvent();
11376
11454
  }
11377
11455
  _addEvent() {
11378
- document.addEventListener("contextmenu", this._proxyContextMenuEvent);
11456
+ this.container.addEventListener("contextmenu", this._proxyContextMenuEvent);
11379
11457
  document.addEventListener("mousedown", this._handleEffect);
11380
11458
  }
11381
11459
  removeEvent() {
11382
- document.removeEventListener("contextmenu", this._proxyContextMenuEvent);
11460
+ this.container.removeEventListener("contextmenu", this._proxyContextMenuEvent);
11383
11461
  document.removeEventListener("mousedown", this._handleEffect);
11384
11462
  }
11385
11463
  _getContext() {