aden-editor-vue 0.1.6 → 0.1.8

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/README.md CHANGED
@@ -41,7 +41,7 @@ const content = ref('<p>欢迎使用 AdenEditor</p>');
41
41
 
42
42
  默认工具栏和样式会自动加载。未传 `options` 时,文字编辑、列表、引用、表格等内置功能仍可直接使用;无需单独导入 CSS,也无需自己处理创建、挂载和卸载。
43
43
 
44
- 从 Word 复制的 Office HTML 会以可编辑的富文本片段导入,尽量保留 Word 的段落、表格、内联格式和可安全转换的样式;这不是嵌入 Word 文档。Word 剪贴板若只提供本机临时图片路径、没有提供图片文件数据,浏览器无法读取该路径,编辑器会提示重新复制图片或配置 `uploadImage`。
44
+ 带 HTML 格式的粘贴会以可编辑的富文本片段导入,尽量保留段落、表格、内联格式和可安全转换的样式;Word 内容不是嵌入的 Word 文档。若剪贴板只提供本机临时图片路径、没有提供图片文件数据,浏览器无法读取该路径,编辑器会提示重新复制图片或配置 `uploadImage`。
45
45
 
46
46
  ## 保存内容
47
47
 
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;
@@ -5962,10 +5974,18 @@ var STYLE_PROPERTIES = /* @__PURE__ */ new Set([
5962
5974
  "padding-top",
5963
5975
  "page-break-after",
5964
5976
  "page-break-before",
5977
+ "page-break-inside",
5978
+ "orphans",
5979
+ "widows",
5980
+ "letter-spacing",
5981
+ "word-spacing",
5982
+ "word-break",
5983
+ "overflow-wrap",
5965
5984
  "text-align",
5966
5985
  "text-decoration",
5967
5986
  "text-indent",
5968
5987
  "text-transform",
5988
+ "text-justify",
5969
5989
  "vertical-align",
5970
5990
  "white-space",
5971
5991
  "width"
@@ -6054,7 +6074,7 @@ function inlineOfficeStyles(root) {
6054
6074
  if (!declarations) continue;
6055
6075
  for (const rawSelector of rule[1].split(",")) {
6056
6076
  const selector = rawSelector.trim();
6057
- if (!/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(selector)) continue;
6077
+ if (!/^(?:[a-z][\w-]*)?(?:\.[\w-]+)*(?:\s+(?:[a-z][\w-]*)?(?:\.[\w-]+)*)*$/i.test(selector)) continue;
6058
6078
  try {
6059
6079
  for (const element of Array.from(root.querySelectorAll(selector))) {
6060
6080
  const current = (_b = element.getAttribute("style")) != null ? _b : "";
@@ -6074,7 +6094,7 @@ function sanitizeInlineStyle(raw) {
6074
6094
  if (separator < 1) continue;
6075
6095
  const property = declaration.slice(0, separator).trim().toLowerCase();
6076
6096
  const value = sanitizeStyleValue(declaration.slice(separator + 1));
6077
- if (!STYLE_PROPERTIES.has(property) || !value || /url\s*\(|expression\s*\(|javascript:|[{}<>]/i.test(value)) continue;
6097
+ if (!(STYLE_PROPERTIES.has(property) || /^mso-[a-z0-9-]+$/i.test(property)) || !value || /url\s*\(|expression\s*\(|javascript:|[{}<>]/i.test(value)) continue;
6078
6098
  if (property === "display" && !/^(inline|inline-block|block|table|table-row|table-cell|table-caption|table-row-group|table-header-group|table-footer-group|list-item)$/i.test(value)) continue;
6079
6099
  declarations.push(`${property}:${value}`);
6080
6100
  }
@@ -9636,7 +9656,7 @@ var WebAdapter = class {
9636
9656
  }
9637
9657
  };
9638
9658
  this.handlePaste = (e) => {
9639
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
9659
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
9640
9660
  if (this.opts.readonly) return;
9641
9661
  const html = (_b = (_a2 = e.clipboardData) == null ? void 0 : _a2.getData("text/html")) != null ? _b : "";
9642
9662
  const text = (_d = (_c = e.clipboardData) == null ? void 0 : _c.getData("text/plain")) != null ? _d : "";
@@ -9681,9 +9701,17 @@ var WebAdapter = class {
9681
9701
  knownFiles.add(key);
9682
9702
  images.push(file);
9683
9703
  }
9684
- if (isOfficeClipboardHtml(pasteHtml2)) {
9704
+ const advertisesRichClipboard = Array.from((_l = clipboard == null ? void 0 : clipboard.types) != null ? _l : []).some(
9705
+ (type) => /text\/html|text\/rtf|application\/rtf/i.test(type)
9706
+ );
9707
+ if (!pasteHtml2 && advertisesRichClipboard) {
9708
+ e.preventDefault();
9709
+ void this.pasteRichClipboardFallback(text, images);
9710
+ return;
9711
+ }
9712
+ if (pasteHtml2) {
9685
9713
  e.preventDefault();
9686
- void this.pasteOfficeHtml(pasteHtml2, images);
9714
+ void this.pasteRichHtml(pasteHtml2, images);
9687
9715
  return;
9688
9716
  }
9689
9717
  if (images.length) {
@@ -10201,9 +10229,10 @@ var WebAdapter = class {
10201
10229
  cur = cur.nextElementSibling;
10202
10230
  }
10203
10231
  }
10204
- async pasteOfficeHtml(html, files) {
10232
+ async pasteRichHtml(html, files) {
10205
10233
  const template = document.createElement("template");
10206
10234
  let safe = sanitizeWordHtml(html);
10235
+ if (safe.missingImages && !files.length) files = await this.readClipboardImageFiles();
10207
10236
  template.innerHTML = safe.html;
10208
10237
  const imageEls = Array.from(template.content.querySelectorAll("img[data-aden-missing-image]"));
10209
10238
  for (let i = 0; i < Math.min(imageEls.length, files.length); i += 1) {
@@ -10230,6 +10259,46 @@ var WebAdapter = class {
10230
10259
  safe = sanitizeWordHtml(template.innerHTML);
10231
10260
  this.runCommand((cmd) => cmd.pasteHtmlFragment(this.editor, safe.html, safe.text));
10232
10261
  }
10262
+ async pasteRichClipboardFallback(plainText, files) {
10263
+ var _a;
10264
+ try {
10265
+ const read = (_a = navigator.clipboard) == null ? void 0 : _a.read;
10266
+ if (typeof read === "function") {
10267
+ const items = await read.call(navigator.clipboard);
10268
+ for (const item of items) {
10269
+ if (!item.types.includes("text/html")) continue;
10270
+ const html = await (await item.getType("text/html")).text();
10271
+ if (html) {
10272
+ await this.pasteRichHtml(html, files);
10273
+ return;
10274
+ }
10275
+ }
10276
+ }
10277
+ } catch {
10278
+ }
10279
+ showToast("\u672A\u80FD\u8BFB\u53D6 Word \u7684\u683C\u5F0F\u5316\u5185\u5BB9\uFF0C\u5F53\u524D\u526A\u8D34\u677F\u53EA\u63D0\u4F9B\u7EAF\u6587\u672C\uFF0C\u56E0\u6B64\u65E0\u6CD5\u4FDD\u7559\u539F\u6392\u7248\u3002\u8BF7\u5728 Word \u4E2D\u91CD\u65B0\u590D\u5236\u540E\u7C98\u8D34\uFF0C\u6216\u68C0\u67E5\u6D4F\u89C8\u5668\u526A\u8D34\u677F\u6743\u9650\u3002", 7e3);
10280
+ if (plainText) this.runCommand((cmd) => cmd.pastePlainText(this.editor, plainText));
10281
+ for (const file of files) void this.imageCtrl.insertFile(file);
10282
+ }
10283
+ async readClipboardImageFiles() {
10284
+ var _a, _b;
10285
+ try {
10286
+ const read = (_a = navigator.clipboard) == null ? void 0 : _a.read;
10287
+ if (typeof read !== "function") return [];
10288
+ const items = await read.call(navigator.clipboard);
10289
+ const files = [];
10290
+ for (const item of items) {
10291
+ const imageType = item.types.find((type) => type.startsWith("image/"));
10292
+ if (!imageType) continue;
10293
+ const blob = await item.getType(imageType);
10294
+ const extension = ((_b = imageType.split("/")[1]) == null ? void 0 : _b.replace("jpeg", "jpg")) || "png";
10295
+ files.push(new File([blob], `clipboard-image.${extension}`, { type: imageType }));
10296
+ }
10297
+ return files;
10298
+ } catch {
10299
+ return [];
10300
+ }
10301
+ }
10233
10302
  // =========================================================================
10234
10303
  // 表格
10235
10304
  // =========================================================================
@@ -10760,9 +10829,6 @@ var WebAdapter = class {
10760
10829
  function countNonWhitespace(text) {
10761
10830
  return text.replace(/\s/g, "").length;
10762
10831
  }
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);
10765
- }
10766
10832
  function truncateTextAtLimit(text, remaining) {
10767
10833
  let used = 0;
10768
10834
  let result = "";