aden-editor-vue 0.1.5 → 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/README.md CHANGED
@@ -41,6 +41,8 @@ const content = ref('<p>欢迎使用 AdenEditor</p>');
41
41
 
42
42
  默认工具栏和样式会自动加载。未传 `options` 时,文字编辑、列表、引用、表格等内置功能仍可直接使用;无需单独导入 CSS,也无需自己处理创建、挂载和卸载。
43
43
 
44
+ 从 Word 复制的 Office HTML 会以可编辑的富文本片段导入,尽量保留 Word 的段落、表格、内联格式和可安全转换的样式;这不是嵌入 Word 文档。Word 剪贴板若只提供本机临时图片路径、没有提供图片文件数据,浏览器无法读取该路径,编辑器会提示重新复制图片或配置 `uploadImage`。
45
+
44
46
  ## 保存内容
45
47
 
46
48
  `v-model` 的值是 HTML,适合接入常见的 HTML 内容字段。若需保存完整编辑器文档结构,可通过组件 `ref` 获取 JSON:
package/dist/index.cjs CHANGED
@@ -224,6 +224,9 @@ function normalizeBlockAttrs(type, raw) {
224
224
  case "language":
225
225
  if (/^[a-zA-Z0-9_+-]{1,32}$/.test(String(value))) clean.language = String(value);
226
226
  break;
227
+ case "htmlContent":
228
+ clean.htmlContent = String(value).slice(0, 2e6).replace(/<(script|iframe|object|embed|form|input|button|style|link|meta|base)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, "").replace(/<(script|iframe|object|embed|form|input|button|style|link|meta|base)\b[^>]*\/?\s*>/gi, "").replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/(href|src)\s*=\s*(["'])\s*javascript:[\s\S]*?\2/gi, '$1="#"');
229
+ break;
227
230
  case "ratio": {
228
231
  const n = Number(value);
229
232
  if (Number.isFinite(n) && n > 0 && n <= 10) clean.ratio = n;
@@ -338,6 +341,7 @@ var init_schema = __esm({
338
341
  isTextBlock: false,
339
342
  allowedAttrs: ["align", "tableWidth", "bordered", "headerRow", "headerCol"]
340
343
  },
344
+ html_fragment: { isTextBlock: true, allowedAttrs: ["htmlContent"] },
341
345
  todo_item: { isTextBlock: true, allowedAttrs: ["checked", "indent"] },
342
346
  attachment: {
343
347
  isTextBlock: false,
@@ -1069,7 +1073,7 @@ function wrapMarks(text, marks) {
1069
1073
  return out;
1070
1074
  }
1071
1075
  function blockToHtml(block) {
1072
- var _a, _b, _c, _d, _e;
1076
+ var _a, _b, _c, _d, _e, _f;
1073
1077
  const attrs = block.attrs && typeof block.attrs === "object" ? block.attrs : {};
1074
1078
  const content = Array.isArray(block.content) ? block.content : [];
1075
1079
  const inner = content.filter((n) => n && typeof n.text === "string").map((n) => wrapMarks(n.text, Array.isArray(n.marks) ? n.marks : [])).join("");
@@ -1112,13 +1116,15 @@ function blockToHtml(block) {
1112
1116
  }
1113
1117
  case "table":
1114
1118
  return tableToHtml(block);
1119
+ case "html_fragment":
1120
+ return String((_d = attrs.htmlContent) != null ? _d : "");
1115
1121
  case "todo_item": {
1116
1122
  const checked = attrs.checked ? ' data-checked="true"' : "";
1117
1123
  return `<ul class="aden-todo-list"><li${checked}>${inner}</li></ul>`;
1118
1124
  }
1119
1125
  case "attachment": {
1120
- const name = String((_d = attrs.fileName) != null ? _d : "\u9644\u4EF6");
1121
- const url = sanitizeUrl(String((_e = attrs.fileUrl) != null ? _e : ""), "media");
1126
+ const name = String((_e = attrs.fileName) != null ? _e : "\u9644\u4EF6");
1127
+ const url = sanitizeUrl(String((_f = attrs.fileUrl) != null ? _f : ""), "media");
1122
1128
  const size = Number(attrs.fileSize) || 0;
1123
1129
  const sizeAttr = size ? ` data-size="${size}"` : "";
1124
1130
  if (!url) return `<p>[\u9644\u4EF6] ${escapeHtml(name)}</p>`;
@@ -2570,6 +2576,28 @@ function pasteHtml(editor, html) {
2570
2576
  "paste"
2571
2577
  );
2572
2578
  }
2579
+ function pasteHtmlFragment(editor, html, plainText = "") {
2580
+ if (!html) return;
2581
+ const state = editor.getState();
2582
+ const { blockId, offset } = state.selection.anchor;
2583
+ const idx = indexOfBlock(state.doc, blockId);
2584
+ const cur = state.doc.blocks[idx];
2585
+ if (!cur) return;
2586
+ const [left, right] = splitAt(cur, offset);
2587
+ const blocks = state.doc.blocks.slice();
2588
+ const fragment = createBlock("html_fragment", { htmlContent: html }, plainText ? [{ type: "text", text: plainText, marks: [] }] : []);
2589
+ const tailBlock = { ...cur, id: genId(), content: normalizeContent(right) };
2590
+ blocks[idx] = { ...cur, content: normalizeContent(left) };
2591
+ blocks.splice(idx + 1, 0, fragment, tailBlock);
2592
+ editor.commit(
2593
+ () => ({
2594
+ ...state,
2595
+ doc: { ...state.doc, blocks },
2596
+ selection: { anchor: { blockId: fragment.id, offset: 0 }, head: { blockId: fragment.id, offset: 0 } }
2597
+ }),
2598
+ "paste"
2599
+ );
2600
+ }
2573
2601
  var MAX_INDENT;
2574
2602
  var init_commands = __esm({
2575
2603
  "packages/core/src/command/commands.ts"() {
@@ -2945,6 +2973,7 @@ __export2(src_exports, {
2945
2973
  normalizeKey: () => normalizeKey,
2946
2974
  normalizeTable: () => normalizeTable,
2947
2975
  pasteHtml: () => pasteHtml,
2976
+ pasteHtmlFragment: () => pasteHtmlFragment,
2948
2977
  pastePlainText: () => pastePlainText,
2949
2978
  reconcileMarks: () => reconcileMarks,
2950
2979
  removeAttachment: () => removeAttachment,
@@ -3921,6 +3950,9 @@ var EDITOR_CSS = `
3921
3950
 
3922
3951
  /* \u6BB5\u843D */
3923
3952
  .aden-editor .aden-block-paragraph { margin-bottom: 6px; }
3953
+ .aden-editor .aden-block-html_fragment { display: block; margin: 0; padding: 0; }
3954
+ .aden-editor .aden-imported-html { display: block; width: 100%; min-width: 0; overflow-x: auto; }
3955
+ .aden-editor .aden-imported-html img { max-width: 100%; height: auto; }
3924
3956
 
3925
3957
  /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
3926
3958
  \u6807\u9898\uFF1A\u516D\u7EA7\u7684\u5B57\u53F7/\u884C\u9AD8/\u95F4\u8DDD\u68AF\u5EA6
@@ -4671,6 +4703,7 @@ var _Toolbar = class _Toolbar2 {
4671
4703
  }
4672
4704
  this.highlightPanel(id, panel);
4673
4705
  panel.style.display = "block";
4706
+ this.positionPanel(panel, btn);
4674
4707
  btn.classList.add("active");
4675
4708
  this.openPanel = panel;
4676
4709
  });
@@ -4751,6 +4784,7 @@ var _Toolbar = class _Toolbar2 {
4751
4784
  hoverC = 0;
4752
4785
  repaint();
4753
4786
  panel.style.display = "block";
4787
+ this.positionPanel(panel, btn);
4754
4788
  btn.classList.add("active");
4755
4789
  this.openPanel = panel;
4756
4790
  });
@@ -4831,6 +4865,7 @@ var _Toolbar = class _Toolbar2 {
4831
4865
  }
4832
4866
  this.closePanel();
4833
4867
  panel.style.display = "block";
4868
+ this.positionPanel(panel, btn);
4834
4869
  btn.classList.add("active");
4835
4870
  this.openPanel = panel;
4836
4871
  });
@@ -4879,6 +4914,7 @@ var _Toolbar = class _Toolbar2 {
4879
4914
  }
4880
4915
  this.closePanel();
4881
4916
  panel.style.display = "block";
4917
+ this.positionPanel(panel, btn);
4882
4918
  btn.classList.add("active");
4883
4919
  this.openPanel = panel;
4884
4920
  });
@@ -4892,6 +4928,17 @@ var _Toolbar = class _Toolbar2 {
4892
4928
  parentBtn == null ? void 0 : parentBtn.classList.remove("active");
4893
4929
  this.openPanel = null;
4894
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
+ }
4895
4942
  // =========================================================================
4896
4943
  // 状态同步
4897
4944
  // =========================================================================
@@ -4905,7 +4952,7 @@ var _Toolbar = class _Toolbar2 {
4905
4952
  }
4906
4953
  /** 根据当前选区点亮按钮、更新下拉标签、刷新字数。 */
4907
4954
  syncState() {
4908
- var _a, _b, _c, _d, _e, _f, _g, _h;
4955
+ var _a, _b, _c, _d, _e, _f, _g;
4909
4956
  const marks = safeActiveMarks(this.editor);
4910
4957
  const has = (t) => marks.some((m) => m.type === t);
4911
4958
  const setActive = (id, on) => {
@@ -4977,9 +5024,6 @@ var _Toolbar = class _Toolbar2 {
4977
5024
  const isActiveOnMark = markType ? marksOfCursor(this.editor).some((m) => m.type === markType) : false;
4978
5025
  btn.toggleAttribute("disabled", collapsed && !isActiveOnMark);
4979
5026
  }
4980
- for (const id of _Toolbar2.SELECTION_REQUIRED_DROPDOWNS) {
4981
- (_h = this.buttons.get(id)) == null ? void 0 : _h.toggleAttribute("disabled", collapsed);
4982
- }
4983
5027
  this.updateStat();
4984
5028
  }
4985
5029
  /** 高亮下拉里的当前值。 */
@@ -5171,8 +5215,8 @@ var TOOLBAR_CSS = `
5171
5215
  .aden-tb-dropdown { position: relative; }
5172
5216
 
5173
5217
  .aden-tb-panel {
5174
- position: absolute;
5175
- top: calc(100% + 5px);
5218
+ position: fixed;
5219
+ top: 0;
5176
5220
  left: 0;
5177
5221
  min-width: 108px;
5178
5222
  max-height: 340px;
@@ -5834,6 +5878,220 @@ function marksFromStyle(el) {
5834
5878
  function sanitizeHrefForDom(href) {
5835
5879
  return sanitizeUrl(href, "link");
5836
5880
  }
5881
+ init_src();
5882
+ var ALLOWED_TAGS = /* @__PURE__ */ new Set([
5883
+ "a",
5884
+ "b",
5885
+ "blockquote",
5886
+ "br",
5887
+ "caption",
5888
+ "code",
5889
+ "col",
5890
+ "colgroup",
5891
+ "dd",
5892
+ "del",
5893
+ "div",
5894
+ "dl",
5895
+ "dt",
5896
+ "em",
5897
+ "figcaption",
5898
+ "figure",
5899
+ "h1",
5900
+ "h2",
5901
+ "h3",
5902
+ "h4",
5903
+ "h5",
5904
+ "h6",
5905
+ "hr",
5906
+ "i",
5907
+ "img",
5908
+ "li",
5909
+ "ol",
5910
+ "p",
5911
+ "pre",
5912
+ "s",
5913
+ "small",
5914
+ "span",
5915
+ "strong",
5916
+ "sub",
5917
+ "sup",
5918
+ "table",
5919
+ "tbody",
5920
+ "td",
5921
+ "tfoot",
5922
+ "th",
5923
+ "thead",
5924
+ "tr",
5925
+ "u",
5926
+ "ul"
5927
+ ]);
5928
+ var DROP_CONTENT_TAGS = /* @__PURE__ */ new Set(["script", "style", "iframe", "object", "embed", "form", "input", "button", "meta", "link", "base", "svg", "math"]);
5929
+ var STYLE_PROPERTIES = /* @__PURE__ */ new Set([
5930
+ "background",
5931
+ "background-color",
5932
+ "border",
5933
+ "border-bottom",
5934
+ "border-bottom-color",
5935
+ "border-bottom-style",
5936
+ "border-bottom-width",
5937
+ "border-collapse",
5938
+ "border-color",
5939
+ "border-left",
5940
+ "border-left-color",
5941
+ "border-left-style",
5942
+ "border-left-width",
5943
+ "border-right",
5944
+ "border-right-color",
5945
+ "border-right-style",
5946
+ "border-right-width",
5947
+ "border-spacing",
5948
+ "border-style",
5949
+ "border-top",
5950
+ "border-top-color",
5951
+ "border-top-style",
5952
+ "border-top-width",
5953
+ "border-width",
5954
+ "color",
5955
+ "direction",
5956
+ "display",
5957
+ "font-family",
5958
+ "font-size",
5959
+ "font-style",
5960
+ "font-variant",
5961
+ "font-weight",
5962
+ "height",
5963
+ "line-height",
5964
+ "list-style-type",
5965
+ "margin",
5966
+ "margin-bottom",
5967
+ "margin-left",
5968
+ "margin-right",
5969
+ "margin-top",
5970
+ "padding",
5971
+ "padding-bottom",
5972
+ "padding-left",
5973
+ "padding-right",
5974
+ "padding-top",
5975
+ "page-break-after",
5976
+ "page-break-before",
5977
+ "text-align",
5978
+ "text-decoration",
5979
+ "text-indent",
5980
+ "text-transform",
5981
+ "vertical-align",
5982
+ "white-space",
5983
+ "width"
5984
+ ]);
5985
+ function sanitizeWordHtml(input) {
5986
+ var _a, _b, _c;
5987
+ const source = input.slice(0, 2e6);
5988
+ const template = document.createElement("template");
5989
+ template.innerHTML = source;
5990
+ inlineOfficeStyles(template.content);
5991
+ for (const element of Array.from(template.content.querySelectorAll("*"))) {
5992
+ const rawTag = element.tagName.toLowerCase();
5993
+ const tag = rawTag.includes(":") ? rawTag.split(":").pop() : rawTag;
5994
+ if (DROP_CONTENT_TAGS.has(tag)) {
5995
+ element.remove();
5996
+ continue;
5997
+ }
5998
+ if (tag === "imagedata") {
5999
+ const image = document.createElement("img");
6000
+ image.setAttribute("data-aden-missing-image", "true");
6001
+ const src = (_b = (_a = element.getAttribute("src")) != null ? _a : element.getAttribute("o:href")) != null ? _b : "";
6002
+ const safeSrc = sanitizeUrl(src, "media");
6003
+ if (safeSrc) image.src = safeSrc;
6004
+ element.replaceWith(image);
6005
+ continue;
6006
+ }
6007
+ if (!ALLOWED_TAGS.has(tag)) {
6008
+ element.replaceWith(...Array.from(element.childNodes));
6009
+ continue;
6010
+ }
6011
+ if (rawTag !== tag) {
6012
+ const replacement = document.createElement(tag);
6013
+ for (const attribute of Array.from(element.attributes)) replacement.setAttribute(attribute.name, attribute.value);
6014
+ replacement.append(...Array.from(element.childNodes));
6015
+ element.replaceWith(replacement);
6016
+ continue;
6017
+ }
6018
+ for (const attribute of Array.from(element.attributes)) {
6019
+ const name = attribute.name.toLowerCase();
6020
+ if (name.startsWith("on") || name === "srcset" || name === "srcdoc" || name === "class" || name === "id" || name.startsWith("data-") && name !== "data-aden-missing-image") {
6021
+ if (name !== "data-aden-missing-image") element.removeAttribute(attribute.name);
6022
+ continue;
6023
+ }
6024
+ if (name === "style") {
6025
+ const clean = sanitizeInlineStyle(attribute.value);
6026
+ if (clean) element.setAttribute("style", clean);
6027
+ else element.removeAttribute("style");
6028
+ continue;
6029
+ }
6030
+ if (name === "src") {
6031
+ const safe = sanitizeUrl(attribute.value, "media");
6032
+ if (safe) element.setAttribute("src", safe);
6033
+ else {
6034
+ element.removeAttribute("src");
6035
+ if (tag === "img") element.setAttribute("data-aden-missing-image", "true");
6036
+ }
6037
+ continue;
6038
+ }
6039
+ if (name === "href") {
6040
+ const safe = sanitizeUrl(attribute.value, "link");
6041
+ if (safe) element.setAttribute("href", safe);
6042
+ else element.removeAttribute("href");
6043
+ continue;
6044
+ }
6045
+ if (!["alt", "title", "width", "height", "colspan", "rowspan", "align", "valign", "bgcolor", "scope", "start", "type", "dir", "lang", "data-aden-missing-image"].includes(name)) {
6046
+ element.removeAttribute(attribute.name);
6047
+ }
6048
+ }
6049
+ if (tag === "a" && element.getAttribute("target") === "_blank") element.setAttribute("rel", "noopener noreferrer");
6050
+ if (tag === "img" && element.hasAttribute("data-aden-missing-image") && !element.hasAttribute("alt")) {
6051
+ element.setAttribute("alt", "Word \u56FE\u7247\u672A\u80FD\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6");
6052
+ }
6053
+ }
6054
+ const missingImages = template.content.querySelectorAll("img[data-aden-missing-image]").length;
6055
+ return { html: template.innerHTML, text: (_c = template.content.textContent) != null ? _c : "", missingImages };
6056
+ }
6057
+ function inlineOfficeStyles(root) {
6058
+ var _a, _b;
6059
+ const styleElements = Array.from(root.querySelectorAll("style"));
6060
+ for (const styleElement of styleElements) {
6061
+ const css = (_a = styleElement.textContent) != null ? _a : "";
6062
+ const rules = /([^{}]+)\{([^{}]*)\}/g;
6063
+ let rule;
6064
+ while (rule = rules.exec(css)) {
6065
+ const declarations = sanitizeInlineStyle(rule[2]);
6066
+ if (!declarations) continue;
6067
+ for (const rawSelector of rule[1].split(",")) {
6068
+ const selector = rawSelector.trim();
6069
+ if (!/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(selector)) continue;
6070
+ try {
6071
+ for (const element of Array.from(root.querySelectorAll(selector))) {
6072
+ const current = (_b = element.getAttribute("style")) != null ? _b : "";
6073
+ element.setAttribute("style", sanitizeInlineStyle(`${declarations};${current}`));
6074
+ }
6075
+ } catch {
6076
+ }
6077
+ }
6078
+ }
6079
+ styleElement.remove();
6080
+ }
6081
+ }
6082
+ function sanitizeInlineStyle(raw) {
6083
+ const declarations = [];
6084
+ for (const declaration of raw.split(";")) {
6085
+ const separator = declaration.indexOf(":");
6086
+ if (separator < 1) continue;
6087
+ const property = declaration.slice(0, separator).trim().toLowerCase();
6088
+ const value = sanitizeStyleValue(declaration.slice(separator + 1));
6089
+ if (!STYLE_PROPERTIES.has(property) || !value || /url\s*\(|expression\s*\(|javascript:|[{}<>]/i.test(value)) continue;
6090
+ 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;
6091
+ declarations.push(`${property}:${value}`);
6092
+ }
6093
+ return declarations.join(";");
6094
+ }
5837
6095
  function parseBlockContent(el) {
5838
6096
  const content = [];
5839
6097
  const walk = (node, marks) => {
@@ -5868,6 +6126,16 @@ function parseBlockEl(el, base) {
5868
6126
  if (type === "divider" || type === "image" || type === "video" || type === "table") {
5869
6127
  return base;
5870
6128
  }
6129
+ if (type === "html_fragment") {
6130
+ const content = el.querySelector(".aden-imported-html");
6131
+ if (!content) return base;
6132
+ const safe = sanitizeWordHtml(content.innerHTML);
6133
+ return {
6134
+ ...base,
6135
+ attrs: { ...base.attrs, htmlContent: safe.html },
6136
+ content: parseBlockContent(content)
6137
+ };
6138
+ }
5871
6139
  if (type === "code_block") {
5872
6140
  const text = (_b = el.textContent) != null ? _b : "";
5873
6141
  return { ...base, content: text ? [{ type: "text", text, marks: [] }] : [] };
@@ -6977,7 +7245,7 @@ function blockSignature(block) {
6977
7245
  return JSON.stringify([block.type, block.attrs, block.content, (_a = block.table) != null ? _a : null]);
6978
7246
  }
6979
7247
  function createBlockEl(block, ctx) {
6980
- var _a, _b, _c, _d, _e, _f, _g, _h;
7248
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
6981
7249
  const el = document.createElement("div");
6982
7250
  el.setAttribute("data-block-id", block.id);
6983
7251
  el.setAttribute("data-block-type", block.type);
@@ -7049,6 +7317,14 @@ function createBlockEl(block, ctx) {
7049
7317
  );
7050
7318
  return el;
7051
7319
  }
7320
+ case "html_fragment": {
7321
+ const content = document.createElement("div");
7322
+ content.className = "aden-imported-html";
7323
+ content.contentEditable = ctx.readonly ? "false" : "true";
7324
+ content.innerHTML = sanitizeWordHtml(String((_j = (_i = block.attrs) == null ? void 0 : _i.htmlContent) != null ? _j : "")).html;
7325
+ el.appendChild(content);
7326
+ return el;
7327
+ }
7052
7328
  case "code_block":
7053
7329
  el.appendChild(renderCodeBlock(block));
7054
7330
  return el;
@@ -7599,6 +7875,27 @@ var ImageController = class {
7599
7875
  if (this.destroyed || this.opts.isReadonly()) return;
7600
7876
  await this.startReplacementUpload(blockId, file);
7601
7877
  }
7878
+ /** Import an image embedded in Office clipboard HTML as an upload or durable data URL. */
7879
+ async importClipboardFile(file) {
7880
+ var _a, _b, _c;
7881
+ const check = validateFile(file, {
7882
+ accept: (_a = this.opts.accept) != null ? _a : DEFAULT_ACCEPT,
7883
+ maxSize: (_b = this.opts.maxSize) != null ? _b : 10 * 1024 * 1024,
7884
+ label: "\u56FE\u7247"
7885
+ });
7886
+ if (!check.ok) throw new Error(check.message);
7887
+ try {
7888
+ const rawUrl = await ((_c = this.opts.upload) != null ? _c : fileToDataUrl)(file);
7889
+ const url = this.opts.upload ? sanitizePersistentMediaUrl(rawUrl) : sanitizeUrl(rawUrl, "media");
7890
+ if (!url) throw new Error("\u4E0A\u4F20\u63A5\u53E3\u672A\u8FD4\u56DE\u53EF\u8BBF\u95EE\u7684\u56FE\u7247\u5730\u5740");
7891
+ return url;
7892
+ } catch (error) {
7893
+ const cause = (error == null ? void 0 : error.message) || "\u672A\u77E5\u9519\u8BEF";
7894
+ const message = this.opts.upload ? `Word \u56FE\u7247\u4E0A\u4F20\u5931\u8D25\uFF1A${cause}\u3002\u8BF7\u68C0\u67E5 uploadImage \u63A5\u53E3\u914D\u7F6E` : `Word \u56FE\u7247\u8BFB\u53D6\u5931\u8D25\uFF1A${cause}\u3002\u8BF7\u914D\u7F6E uploadImage \u56FE\u7247\u4E0A\u4F20\u63A5\u53E3\u540E\u91CD\u8BD5`;
7895
+ showToast(message, 6500);
7896
+ throw new Error(message);
7897
+ }
7898
+ }
7602
7899
  /** 替换指定图片块(网络地址)。 */
7603
7900
  replaceWithUrl(blockId, url) {
7604
7901
  if (this.destroyed || this.opts.isReadonly()) return false;
@@ -9396,6 +9693,11 @@ var WebAdapter = class {
9396
9693
  knownFiles.add(key);
9397
9694
  images.push(file);
9398
9695
  }
9696
+ if (shouldPreserveRichHtmlPaste(pasteHtml2)) {
9697
+ e.preventDefault();
9698
+ void this.pasteOfficeHtml(pasteHtml2, images);
9699
+ return;
9700
+ }
9399
9701
  if (images.length) {
9400
9702
  e.preventDefault();
9401
9703
  const existingImageIds2 = new Set(
@@ -9911,6 +10213,55 @@ var WebAdapter = class {
9911
10213
  cur = cur.nextElementSibling;
9912
10214
  }
9913
10215
  }
10216
+ async pasteOfficeHtml(html, files) {
10217
+ const template = document.createElement("template");
10218
+ let safe = sanitizeWordHtml(html);
10219
+ if (safe.missingImages && !files.length) files = await this.readClipboardImageFiles();
10220
+ template.innerHTML = safe.html;
10221
+ const imageEls = Array.from(template.content.querySelectorAll("img[data-aden-missing-image]"));
10222
+ for (let i = 0; i < Math.min(imageEls.length, files.length); i += 1) {
10223
+ try {
10224
+ imageEls[i].src = await this.imageCtrl.importClipboardFile(files[i]);
10225
+ imageEls[i].removeAttribute("data-aden-missing-image");
10226
+ } catch {
10227
+ }
10228
+ }
10229
+ if (imageEls.length === 0 && !template.content.querySelector("img")) {
10230
+ for (const file of files) {
10231
+ try {
10232
+ const image = document.createElement("img");
10233
+ image.src = await this.imageCtrl.importClipboardFile(file);
10234
+ image.alt = file.name || "Word \u56FE\u7247";
10235
+ template.content.appendChild(image);
10236
+ } catch {
10237
+ }
10238
+ }
10239
+ }
10240
+ if (safe.missingImages > files.length) {
10241
+ showToast("Word \u5185\u5BB9\u4E2D\u6709\u56FE\u7247\u672A\u80FD\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6\u3002\u8BF7\u91CD\u65B0\u590D\u5236\u56FE\u7247\uFF0C\u6216\u914D\u7F6E uploadImage \u4E0A\u4F20\u63A5\u53E3\u540E\u518D\u8BD5\u3002", 6500);
10242
+ }
10243
+ safe = sanitizeWordHtml(template.innerHTML);
10244
+ this.runCommand((cmd) => cmd.pasteHtmlFragment(this.editor, safe.html, safe.text));
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
+ }
9914
10265
  // =========================================================================
9915
10266
  // 表格
9916
10267
  // =========================================================================
@@ -10441,6 +10792,9 @@ var WebAdapter = class {
10441
10792
  function countNonWhitespace(text) {
10442
10793
  return text.replace(/\s/g, "").length;
10443
10794
  }
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);
10797
+ }
10444
10798
  function truncateTextAtLimit(text, remaining) {
10445
10799
  let used = 0;
10446
10800
  let result = "";