aden-editor-vue 0.1.6 → 0.1.7

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/dist/index.cjs CHANGED
@@ -4703,6 +4703,7 @@ var _Toolbar = class _Toolbar2 {
4703
4703
  }
4704
4704
  this.highlightPanel(id, panel);
4705
4705
  panel.style.display = "block";
4706
+ this.positionPanel(panel, btn);
4706
4707
  btn.classList.add("active");
4707
4708
  this.openPanel = panel;
4708
4709
  });
@@ -4783,6 +4784,7 @@ var _Toolbar = class _Toolbar2 {
4783
4784
  hoverC = 0;
4784
4785
  repaint();
4785
4786
  panel.style.display = "block";
4787
+ this.positionPanel(panel, btn);
4786
4788
  btn.classList.add("active");
4787
4789
  this.openPanel = panel;
4788
4790
  });
@@ -4863,6 +4865,7 @@ var _Toolbar = class _Toolbar2 {
4863
4865
  }
4864
4866
  this.closePanel();
4865
4867
  panel.style.display = "block";
4868
+ this.positionPanel(panel, btn);
4866
4869
  btn.classList.add("active");
4867
4870
  this.openPanel = panel;
4868
4871
  });
@@ -4911,6 +4914,7 @@ var _Toolbar = class _Toolbar2 {
4911
4914
  }
4912
4915
  this.closePanel();
4913
4916
  panel.style.display = "block";
4917
+ this.positionPanel(panel, btn);
4914
4918
  btn.classList.add("active");
4915
4919
  this.openPanel = panel;
4916
4920
  });
@@ -4924,6 +4928,17 @@ var _Toolbar = class _Toolbar2 {
4924
4928
  parentBtn == null ? void 0 : parentBtn.classList.remove("active");
4925
4929
  this.openPanel = null;
4926
4930
  }
4931
+ /** Position popovers in the viewport so toolbar rows' horizontal scrollers don't clip them. */
4932
+ positionPanel(panel, anchor) {
4933
+ const rect = anchor.getBoundingClientRect();
4934
+ const margin = 8;
4935
+ const panelRect = panel.getBoundingClientRect();
4936
+ const left = Math.max(margin, Math.min(rect.left, window.innerWidth - panelRect.width - margin));
4937
+ const below = rect.bottom + 5;
4938
+ const top = below + panelRect.height <= window.innerHeight - margin ? below : Math.max(margin, rect.top - panelRect.height - 5);
4939
+ panel.style.left = `${left}px`;
4940
+ panel.style.top = `${top}px`;
4941
+ }
4927
4942
  // =========================================================================
4928
4943
  // 状态同步
4929
4944
  // =========================================================================
@@ -4937,7 +4952,7 @@ var _Toolbar = class _Toolbar2 {
4937
4952
  }
4938
4953
  /** 根据当前选区点亮按钮、更新下拉标签、刷新字数。 */
4939
4954
  syncState() {
4940
- var _a, _b, _c, _d, _e, _f, _g, _h;
4955
+ var _a, _b, _c, _d, _e, _f, _g;
4941
4956
  const marks = safeActiveMarks(this.editor);
4942
4957
  const has = (t) => marks.some((m) => m.type === t);
4943
4958
  const setActive = (id, on) => {
@@ -5009,9 +5024,6 @@ var _Toolbar = class _Toolbar2 {
5009
5024
  const isActiveOnMark = markType ? marksOfCursor(this.editor).some((m) => m.type === markType) : false;
5010
5025
  btn.toggleAttribute("disabled", collapsed && !isActiveOnMark);
5011
5026
  }
5012
- for (const id of _Toolbar2.SELECTION_REQUIRED_DROPDOWNS) {
5013
- (_h = this.buttons.get(id)) == null ? void 0 : _h.toggleAttribute("disabled", collapsed);
5014
- }
5015
5027
  this.updateStat();
5016
5028
  }
5017
5029
  /** 高亮下拉里的当前值。 */
@@ -5203,8 +5215,8 @@ var TOOLBAR_CSS = `
5203
5215
  .aden-tb-dropdown { position: relative; }
5204
5216
 
5205
5217
  .aden-tb-panel {
5206
- position: absolute;
5207
- top: calc(100% + 5px);
5218
+ position: fixed;
5219
+ top: 0;
5208
5220
  left: 0;
5209
5221
  min-width: 108px;
5210
5222
  max-height: 340px;
@@ -9681,7 +9693,7 @@ var WebAdapter = class {
9681
9693
  knownFiles.add(key);
9682
9694
  images.push(file);
9683
9695
  }
9684
- if (isOfficeClipboardHtml(pasteHtml2)) {
9696
+ if (shouldPreserveRichHtmlPaste(pasteHtml2)) {
9685
9697
  e.preventDefault();
9686
9698
  void this.pasteOfficeHtml(pasteHtml2, images);
9687
9699
  return;
@@ -10204,6 +10216,7 @@ var WebAdapter = class {
10204
10216
  async pasteOfficeHtml(html, files) {
10205
10217
  const template = document.createElement("template");
10206
10218
  let safe = sanitizeWordHtml(html);
10219
+ if (safe.missingImages && !files.length) files = await this.readClipboardImageFiles();
10207
10220
  template.innerHTML = safe.html;
10208
10221
  const imageEls = Array.from(template.content.querySelectorAll("img[data-aden-missing-image]"));
10209
10222
  for (let i = 0; i < Math.min(imageEls.length, files.length); i += 1) {
@@ -10230,6 +10243,25 @@ var WebAdapter = class {
10230
10243
  safe = sanitizeWordHtml(template.innerHTML);
10231
10244
  this.runCommand((cmd) => cmd.pasteHtmlFragment(this.editor, safe.html, safe.text));
10232
10245
  }
10246
+ async readClipboardImageFiles() {
10247
+ var _a, _b;
10248
+ try {
10249
+ const read = (_a = navigator.clipboard) == null ? void 0 : _a.read;
10250
+ if (typeof read !== "function") return [];
10251
+ const items = await read.call(navigator.clipboard);
10252
+ const files = [];
10253
+ for (const item of items) {
10254
+ const imageType = item.types.find((type) => type.startsWith("image/"));
10255
+ if (!imageType) continue;
10256
+ const blob = await item.getType(imageType);
10257
+ const extension = ((_b = imageType.split("/")[1]) == null ? void 0 : _b.replace("jpeg", "jpg")) || "png";
10258
+ files.push(new File([blob], `clipboard-image.${extension}`, { type: imageType }));
10259
+ }
10260
+ return files;
10261
+ } catch {
10262
+ return [];
10263
+ }
10264
+ }
10233
10265
  // =========================================================================
10234
10266
  // 表格
10235
10267
  // =========================================================================
@@ -10760,8 +10792,8 @@ var WebAdapter = class {
10760
10792
  function countNonWhitespace(text) {
10761
10793
  return text.replace(/\s/g, "").length;
10762
10794
  }
10763
- function isOfficeClipboardHtml(html) {
10764
- return /mso-[\w-]+|class=["'][^"']*\bMso\w*|Microsoft Word|urn:schemas-microsoft-com|w:worddocument|v:(?:shape|imagedata)|StartFragment/i.test(html);
10795
+ function shouldPreserveRichHtmlPaste(html) {
10796
+ return /<(?:table|img|style)\b|\bstyle\s*=|\bclass\s*=|mso-[\w-]+|Microsoft Word|urn:schemas-microsoft-com|w:worddocument|v:(?:shape|imagedata)|StartFragment/i.test(html);
10765
10797
  }
10766
10798
  function truncateTextAtLimit(text, remaining) {
10767
10799
  let used = 0;