@mdaemon/html-editor 1.0.13 → 1.2.0

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.mjs CHANGED
@@ -14314,9 +14314,9 @@ function createInnerSelectionForWholeDocList(tr2) {
14314
14314
  if (!list) {
14315
14315
  return null;
14316
14316
  }
14317
- const from2 = 1;
14318
- const to = list.nodeSize - 1;
14319
- return TextSelection.create(doc2, from2, to);
14317
+ const $start = doc2.resolve(1);
14318
+ const $end = doc2.resolve(list.nodeSize - 1);
14319
+ return TextSelection.between($start, $end);
14320
14320
  }
14321
14321
  var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr: tr2, state, dispatch, chain, commands, can }) => {
14322
14322
  const { extensions, splittableMarks } = editor.extensionManager;
@@ -14896,6 +14896,7 @@ var Extendable = class {
14896
14896
  });
14897
14897
  extension.name = this.name;
14898
14898
  extension.parent = this.parent;
14899
+ this.child = null;
14899
14900
  return extension;
14900
14901
  }
14901
14902
  extend(extendedConfig = {}) {
@@ -15423,6 +15424,36 @@ var ExtensionManager = class {
15423
15424
  })
15424
15425
  );
15425
15426
  }
15427
+ /**
15428
+ * Destroy the extension manager and clean up all extension references
15429
+ * to prevent memory leaks through parent/child extension chains.
15430
+ *
15431
+ * Walks each extension's full parent chain and nulls every forward
15432
+ * `parent.child → current` link where the parent still points to the
15433
+ * current node. This breaks the retention path from module-scope
15434
+ * singleton roots through deep extend() chains.
15435
+ *
15436
+ * Only ancestor `.child` links matching the current chain are cleared.
15437
+ * The `.parent` pointer on ancestors is never touched — extensions
15438
+ * may be shared across live editors, so their own backward references
15439
+ * and non-matching forward links must remain intact.
15440
+ */
15441
+ destroy() {
15442
+ this.extensions.forEach((extension) => {
15443
+ let current = extension;
15444
+ while (current.parent) {
15445
+ const parent = current.parent;
15446
+ if (parent.child === current) {
15447
+ parent.child = null;
15448
+ }
15449
+ current = parent;
15450
+ }
15451
+ });
15452
+ this.extensions = [];
15453
+ this.baseExtensions = [];
15454
+ this.schema = null;
15455
+ this.editor = null;
15456
+ }
15426
15457
  /**
15427
15458
  * Go through all extensions, create extension storages & setup marks
15428
15459
  * & bind editor event listener.
@@ -15828,12 +15859,23 @@ var Paste = Extension.create({
15828
15859
  });
15829
15860
  var Tabindex = Extension.create({
15830
15861
  name: "tabindex",
15862
+ addOptions() {
15863
+ return {
15864
+ value: void 0
15865
+ };
15866
+ },
15831
15867
  addProseMirrorPlugins() {
15832
15868
  return [
15833
15869
  new Plugin({
15834
15870
  key: new PluginKey("tabindex"),
15835
15871
  props: {
15836
- attributes: () => this.editor.isEditable ? { tabindex: "0" } : {}
15872
+ attributes: () => {
15873
+ var _a;
15874
+ if (!this.editor.isEditable && this.options.value === void 0) {
15875
+ return {};
15876
+ }
15877
+ return { tabindex: (_a = this.options.value) != null ? _a : "0" };
15878
+ }
15837
15879
  }
15838
15880
  })
15839
15881
  ];
@@ -16164,6 +16206,7 @@ var Editor = class extends EventEmitter {
16164
16206
  this.className = "tiptap";
16165
16207
  this.editorView = null;
16166
16208
  this.isFocused = false;
16209
+ this.destroyed = false;
16167
16210
  this.isInitialized = false;
16168
16211
  this.extensionStorage = {};
16169
16212
  this.instanceId = Math.random().toString(36).slice(2, 9);
@@ -16446,7 +16489,7 @@ var Editor = class extends EventEmitter {
16446
16489
  * Creates an extension manager.
16447
16490
  */
16448
16491
  createExtensionManager() {
16449
- var _a, _b;
16492
+ var _a, _b, _c, _d;
16450
16493
  const coreExtensions = this.options.enableCoreExtensions ? [
16451
16494
  Editable,
16452
16495
  ClipboardTextSerializer.configure({
@@ -16455,7 +16498,9 @@ var Editor = class extends EventEmitter {
16455
16498
  Commands,
16456
16499
  FocusEvents,
16457
16500
  Keymap,
16458
- Tabindex,
16501
+ Tabindex.configure({
16502
+ value: (_d = (_c = this.options.coreExtensionOptions) == null ? void 0 : _c.tabindex) == null ? void 0 : _d.value
16503
+ }),
16459
16504
  Drop,
16460
16505
  Paste,
16461
16506
  Delete,
@@ -16692,9 +16737,18 @@ var Editor = class extends EventEmitter {
16692
16737
  * Destroy the editor.
16693
16738
  */
16694
16739
  destroy() {
16740
+ if (this.destroyed) {
16741
+ return;
16742
+ }
16743
+ this.destroyed = true;
16695
16744
  this.emit("destroy");
16696
16745
  this.unmount();
16697
16746
  this.removeAllListeners();
16747
+ this.extensionManager.destroy();
16748
+ this.extensionManager = null;
16749
+ this.schema = null;
16750
+ this.commandManager = null;
16751
+ this.extensionStorage = {};
16698
16752
  }
16699
16753
  /**
16700
16754
  * Check if the editor is already destroyed.
@@ -20459,6 +20513,25 @@ var BulletList = Node3.create({
20459
20513
  return [inputRule];
20460
20514
  }
20461
20515
  });
20516
+ function isSameLineOrderedListToken(token) {
20517
+ var _a, _b;
20518
+ const nestedToken = (_a = token.tokens) == null ? void 0 : _a[0];
20519
+ return Boolean(
20520
+ token.text && ((_b = token.tokens) == null ? void 0 : _b.length) === 1 && (nestedToken == null ? void 0 : nestedToken.type) === "list" && nestedToken.ordered && nestedToken.raw === token.text
20521
+ );
20522
+ }
20523
+ function parseSameLineOrderedListText(text, helpers) {
20524
+ if (helpers.tokenizeInline) {
20525
+ return helpers.parseInline(helpers.tokenizeInline(text));
20526
+ }
20527
+ return helpers.parseInline([
20528
+ {
20529
+ type: "text",
20530
+ raw: text,
20531
+ text
20532
+ }
20533
+ ]);
20534
+ }
20462
20535
  var ListItem = Node3.create({
20463
20536
  name: "listItem",
20464
20537
  addOptions() {
@@ -20489,6 +20562,17 @@ var ListItem = Node3.create({
20489
20562
  const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren;
20490
20563
  let content = [];
20491
20564
  if (token.tokens && token.tokens.length > 0) {
20565
+ if (isSameLineOrderedListToken(token)) {
20566
+ return {
20567
+ type: "listItem",
20568
+ content: [
20569
+ {
20570
+ type: "paragraph",
20571
+ content: parseSameLineOrderedListText(token.text || "", helpers)
20572
+ }
20573
+ ]
20574
+ };
20575
+ }
20492
20576
  const hasParagraphTokens = token.tokens.some((t) => t.type === "paragraph");
20493
20577
  if (hasParagraphTokens) {
20494
20578
  content = parseBlockChildren(token.tokens);
@@ -20793,6 +20877,36 @@ var ListKeymap = Extension.create({
20793
20877
  });
20794
20878
  var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
20795
20879
  var INDENTED_LINE_REGEX = /^\s/;
20880
+ function isBlockContentLine(line) {
20881
+ const trimmedLine = line.trimStart();
20882
+ return /^[-+*]\s+/.test(trimmedLine) || /^\d+\.\s+/.test(trimmedLine) || /^>\s?/.test(trimmedLine) || /^```/.test(trimmedLine) || /^~~~/.test(trimmedLine);
20883
+ }
20884
+ function splitItemContent(contentLines) {
20885
+ const paragraphLines = [];
20886
+ const blockLines = [];
20887
+ let reachedBlockBoundary = false;
20888
+ contentLines.forEach((line) => {
20889
+ if (reachedBlockBoundary) {
20890
+ blockLines.push(line);
20891
+ return;
20892
+ }
20893
+ if (line.trim() === "") {
20894
+ reachedBlockBoundary = true;
20895
+ blockLines.push(line);
20896
+ return;
20897
+ }
20898
+ if (paragraphLines.length > 0 && isBlockContentLine(line)) {
20899
+ reachedBlockBoundary = true;
20900
+ blockLines.push(line);
20901
+ return;
20902
+ }
20903
+ paragraphLines.push(line);
20904
+ });
20905
+ return {
20906
+ paragraphLines,
20907
+ blockLines
20908
+ };
20909
+ }
20796
20910
  function collectOrderedListItems(lines) {
20797
20911
  const listItems = [];
20798
20912
  let currentLineIndex = 0;
@@ -20805,9 +20919,10 @@ function collectOrderedListItems(lines) {
20805
20919
  }
20806
20920
  const [, indent, number, content] = match;
20807
20921
  const indentLevel = indent.length;
20808
- let itemContent = content;
20922
+ const itemContentLines = [content];
20809
20923
  let nextLineIndex = currentLineIndex + 1;
20810
20924
  const itemLines = [line];
20925
+ let sawBlankLine = false;
20811
20926
  while (nextLineIndex < lines.length) {
20812
20927
  const nextLine = lines[nextLineIndex];
20813
20928
  const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
@@ -20816,21 +20931,27 @@ function collectOrderedListItems(lines) {
20816
20931
  }
20817
20932
  if (nextLine.trim() === "") {
20818
20933
  itemLines.push(nextLine);
20819
- itemContent += "\n";
20934
+ itemContentLines.push("");
20935
+ sawBlankLine = true;
20820
20936
  nextLineIndex += 1;
20821
20937
  } else if (nextLine.match(INDENTED_LINE_REGEX)) {
20822
20938
  itemLines.push(nextLine);
20823
- itemContent += `
20824
- ${nextLine.slice(indentLevel + 2)}`;
20939
+ itemContentLines.push(nextLine.slice(indentLevel + 2));
20825
20940
  nextLineIndex += 1;
20826
20941
  } else {
20827
- break;
20942
+ if (sawBlankLine) {
20943
+ break;
20944
+ }
20945
+ itemLines.push(nextLine);
20946
+ itemContentLines.push(nextLine);
20947
+ nextLineIndex += 1;
20828
20948
  }
20829
20949
  }
20830
20950
  listItems.push({
20831
20951
  indent: indentLevel,
20832
20952
  number: parseInt(number, 10),
20833
- content: itemContent.trim(),
20953
+ content: itemContentLines.join("\n").trim(),
20954
+ contentLines: itemContentLines,
20834
20955
  raw: itemLines.join("\n")
20835
20956
  });
20836
20957
  consumed = nextLineIndex;
@@ -20839,14 +20960,13 @@ ${nextLine.slice(indentLevel + 2)}`;
20839
20960
  return [listItems, consumed];
20840
20961
  }
20841
20962
  function buildNestedStructure(items, baseIndent, lexer) {
20842
- var _a;
20843
20963
  const result = [];
20844
20964
  let currentIndex = 0;
20845
20965
  while (currentIndex < items.length) {
20846
20966
  const item = items[currentIndex];
20847
20967
  if (item.indent === baseIndent) {
20848
- const contentLines = item.content.split("\n");
20849
- const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
20968
+ const { paragraphLines, blockLines } = splitItemContent(item.contentLines);
20969
+ const mainText = paragraphLines.join("\n").trim();
20850
20970
  const tokens = [];
20851
20971
  if (mainText) {
20852
20972
  tokens.push({
@@ -20855,7 +20975,7 @@ function buildNestedStructure(items, baseIndent, lexer) {
20855
20975
  tokens: lexer.inlineTokens(mainText)
20856
20976
  });
20857
20977
  }
20858
- const additionalContent = contentLines.slice(1).join("\n").trim();
20978
+ const additionalContent = blockLines.join("\n").trim();
20859
20979
  if (additionalContent) {
20860
20980
  const blockTokens = lexer.blockTokens(additionalContent);
20861
20981
  tokens.push(...blockTokens);
@@ -25855,6 +25975,14 @@ var Table = Node3.create({
25855
25975
  })
25856
25976
  ];
25857
25977
  },
25978
+ addNodeView() {
25979
+ const isResizable = this.options.resizable && this.editor.isEditable;
25980
+ const View = this.options.View;
25981
+ if (isResizable || !View) {
25982
+ return null;
25983
+ }
25984
+ return ({ node, view }) => new View(node, this.options.cellMinWidth, view);
25985
+ },
25858
25986
  extendNodeSchema(extension) {
25859
25987
  const context = {
25860
25988
  name: extension.name,
@@ -42740,6 +42868,15 @@ class LinkEditor {
42740
42868
  }
42741
42869
  }
42742
42870
  }
42871
+ const DEFAULT_BUTTON_PRIORITY = {
42872
+ bold: 1,
42873
+ italic: 1,
42874
+ underline: 1,
42875
+ undo: 1,
42876
+ redo: 1,
42877
+ link: 1,
42878
+ forecolor: 1
42879
+ };
42743
42880
  const DEFAULT_COLORS = [
42744
42881
  { value: "#000000", label: "Black" },
42745
42882
  { value: "#434343", label: "Dark Gray 4" },
@@ -42804,7 +42941,8 @@ class Toolbar {
42804
42941
  this.options = options;
42805
42942
  this.state = {
42806
42943
  isFullscreen: false,
42807
- showMoreButtons: false
42944
+ showMoreButtons: false,
42945
+ isNarrow: false
42808
42946
  };
42809
42947
  this.render();
42810
42948
  this.bindEvents();
@@ -42839,12 +42977,79 @@ class Toolbar {
42839
42977
  if (this.resizeObserver) {
42840
42978
  this.resizeObserver.disconnect();
42841
42979
  }
42980
+ const editorRoot = this.container.closest(".md-editor");
42842
42981
  this.resizeObserver = new ResizeObserver(() => {
42843
42982
  if (!this.buttonsEl || !this.toggleBtn) return;
42844
- const hasOverflow = this.buttonsEl.scrollHeight > this.buttonsEl.clientHeight;
42845
- this.toggleBtn.style.display = hasOverflow || this.state.showMoreButtons ? "" : "none";
42983
+ if (editorRoot) {
42984
+ const width = editorRoot.offsetWidth;
42985
+ const breakpoint = this.options.narrowBreakpoint;
42986
+ const wasNarrow = this.state.isNarrow;
42987
+ this.state.isNarrow = width <= breakpoint;
42988
+ editorRoot.classList.toggle("md-editor-narrow", this.state.isNarrow);
42989
+ if (this.state.isNarrow) {
42990
+ this.toggleBtn.style.display = "none";
42991
+ if (this.state.showMoreButtons) {
42992
+ this.state.showMoreButtons = false;
42993
+ this.buttonsEl.classList.remove("md-toolbar-expanded");
42994
+ this.toggleBtn.classList.remove("md-toolbar-btn-active");
42995
+ }
42996
+ this.updateScrollIndicators();
42997
+ if (!wasNarrow) {
42998
+ this.bindScrollIndicators();
42999
+ }
43000
+ } else {
43001
+ if (wasNarrow) {
43002
+ this.unbindScrollIndicators();
43003
+ }
43004
+ const hasOverflow = this.buttonsEl.scrollHeight > this.buttonsEl.clientHeight;
43005
+ this.toggleBtn.style.display = hasOverflow || this.state.showMoreButtons ? "" : "none";
43006
+ }
43007
+ } else {
43008
+ const hasOverflow = this.buttonsEl.scrollHeight > this.buttonsEl.clientHeight;
43009
+ this.toggleBtn.style.display = hasOverflow || this.state.showMoreButtons ? "" : "none";
43010
+ }
42846
43011
  });
42847
43012
  this.resizeObserver.observe(this.buttonsEl);
43013
+ if (editorRoot) {
43014
+ this.resizeObserver.observe(editorRoot);
43015
+ }
43016
+ }
43017
+ scrollHandler = null;
43018
+ bindScrollIndicators() {
43019
+ if (!this.buttonsEl) return;
43020
+ this.scrollHandler = () => this.updateScrollIndicators();
43021
+ this.buttonsEl.addEventListener("scroll", this.scrollHandler, { passive: true });
43022
+ }
43023
+ unbindScrollIndicators() {
43024
+ if (this.buttonsEl && this.scrollHandler) {
43025
+ this.buttonsEl.removeEventListener("scroll", this.scrollHandler);
43026
+ this.scrollHandler = null;
43027
+ }
43028
+ this.container.classList.remove("md-toolbar-scroll-start", "md-toolbar-scroll-middle", "md-toolbar-scroll-end");
43029
+ }
43030
+ updateScrollIndicators() {
43031
+ if (!this.buttonsEl) return;
43032
+ const { scrollLeft, scrollWidth, clientWidth } = this.buttonsEl;
43033
+ const maxScroll = scrollWidth - clientWidth;
43034
+ if (maxScroll <= 1) {
43035
+ this.container.classList.remove("md-toolbar-scroll-start", "md-toolbar-scroll-middle", "md-toolbar-scroll-end");
43036
+ return;
43037
+ }
43038
+ const atStart = scrollLeft <= 1;
43039
+ const atEnd = scrollLeft >= maxScroll - 1;
43040
+ this.container.classList.remove("md-toolbar-scroll-start", "md-toolbar-scroll-middle", "md-toolbar-scroll-end");
43041
+ if (atStart) {
43042
+ this.container.classList.add("md-toolbar-scroll-start");
43043
+ } else if (atEnd) {
43044
+ this.container.classList.add("md-toolbar-scroll-end");
43045
+ } else {
43046
+ this.container.classList.add("md-toolbar-scroll-middle");
43047
+ }
43048
+ }
43049
+ getButtonPriority(name) {
43050
+ const overrides = this.options.priorityOverrides;
43051
+ if (overrides[name] !== void 0) return overrides[name];
43052
+ return DEFAULT_BUTTON_PRIORITY[name] ?? 2;
42848
43053
  }
42849
43054
  renderGroups(buttonsStr, parent) {
42850
43055
  const groups = buttonsStr.split("|").map((g) => g.trim()).filter(Boolean);
@@ -42852,13 +43057,18 @@ class Toolbar {
42852
43057
  const groupEl = document.createElement("div");
42853
43058
  groupEl.className = "md-toolbar-group";
42854
43059
  const buttons = group.split(" ").filter(Boolean);
43060
+ let groupMinPriority = 2;
42855
43061
  buttons.forEach((buttonName) => {
42856
43062
  const buttonEl = this.createButton(buttonName);
42857
43063
  if (buttonEl) {
43064
+ const priority = this.getButtonPriority(buttonName);
43065
+ buttonEl.setAttribute("data-priority", String(priority));
43066
+ if (priority < groupMinPriority) groupMinPriority = priority;
42858
43067
  groupEl.appendChild(buttonEl);
42859
43068
  this.buttonElements.set(buttonName, buttonEl);
42860
43069
  }
42861
43070
  });
43071
+ groupEl.setAttribute("data-priority", String(groupMinPriority));
42862
43072
  parent.appendChild(groupEl);
42863
43073
  if (index < groups.length - 1) {
42864
43074
  const separator = document.createElement("div");
@@ -43532,6 +43742,7 @@ class Toolbar {
43532
43742
  this.resizeObserver.disconnect();
43533
43743
  this.resizeObserver = null;
43534
43744
  }
43745
+ this.unbindScrollIndicators();
43535
43746
  this.unbindEvents();
43536
43747
  this.charMap?.destroy();
43537
43748
  this.emojiPicker?.destroy();
@@ -43820,6 +44031,384 @@ const Mention = Node3.create({
43820
44031
  ];
43821
44032
  }
43822
44033
  });
44034
+ const WORD_MARKERS = [
44035
+ 'xmlns:o="urn:schemas-microsoft-com:office:office"',
44036
+ 'xmlns:w="urn:schemas-microsoft-com:office:word"',
44037
+ 'class="Mso',
44038
+ "class=Mso",
44039
+ 'style="mso-',
44040
+ "style='mso-"
44041
+ ];
44042
+ const EXCEL_MARKERS = [
44043
+ 'xmlns:x="urn:schemas-microsoft-com:office:excel"',
44044
+ "ProgId content=Excel.Sheet",
44045
+ 'ProgId content="Excel.Sheet"'
44046
+ ];
44047
+ function isWordContent(html) {
44048
+ return WORD_MARKERS.some((marker) => html.includes(marker));
44049
+ }
44050
+ function isExcelContent(html) {
44051
+ return EXCEL_MARKERS.some((marker) => html.includes(marker));
44052
+ }
44053
+ function isOfficeContent(html) {
44054
+ return isWordContent(html) || isExcelContent(html);
44055
+ }
44056
+ function removeConditionalComments(html) {
44057
+ return html.replace(/<!--\[if[^\]]*\]>[\s\S]*?<!\[endif\]-->/gi, "");
44058
+ }
44059
+ const OFFICE_NS_TAG_PATTERN = /(?:<\/?)(?:o|w|v|m|x|st\d):/i;
44060
+ function removeOfficeElements(doc2) {
44061
+ const allElements = Array.from(doc2.body.querySelectorAll("*"));
44062
+ for (const el2 of allElements) {
44063
+ const tagName = el2.tagName.toLowerCase();
44064
+ if (OFFICE_NS_TAG_PATTERN.test(`<${tagName}`)) {
44065
+ const parent = el2.parentNode;
44066
+ if (parent) {
44067
+ while (el2.firstChild) {
44068
+ parent.insertBefore(el2.firstChild, el2);
44069
+ }
44070
+ parent.removeChild(el2);
44071
+ }
44072
+ }
44073
+ }
44074
+ const remaining = Array.from(doc2.body.querySelectorAll("*"));
44075
+ for (const el2 of remaining) {
44076
+ const attrs = Array.from(el2.attributes);
44077
+ for (const attr of attrs) {
44078
+ if (attr.name.startsWith("xmlns:") || attr.name === "xmlns") {
44079
+ el2.removeAttribute(attr.name);
44080
+ }
44081
+ }
44082
+ }
44083
+ }
44084
+ function parseListStyles(doc2) {
44085
+ const styleMap = /* @__PURE__ */ new Map();
44086
+ const styleEls = doc2.querySelectorAll("style");
44087
+ for (const styleEl of Array.from(styleEls)) {
44088
+ const css2 = styleEl.textContent ?? "";
44089
+ const listRulePattern = /@list\s+(l\d+):level(\d+)\s*\{([^}]*)\}/gi;
44090
+ let match;
44091
+ while ((match = listRulePattern.exec(css2)) !== null) {
44092
+ const listId = match[1];
44093
+ const level = match[2];
44094
+ const body = match[3];
44095
+ const key = `${listId}:level${level}`;
44096
+ const formatMatch = /mso-level-number-format:\s*([^;]+)/i.exec(body);
44097
+ if (formatMatch) {
44098
+ const format = formatMatch[1].trim().toLowerCase();
44099
+ styleMap.set(key, format !== "bullet");
44100
+ } else {
44101
+ styleMap.set(key, true);
44102
+ }
44103
+ }
44104
+ }
44105
+ return styleMap;
44106
+ }
44107
+ function parseListStyle(style2) {
44108
+ const match = /mso-list:\s*(l\d+)\s+level(\d+)\s+/i.exec(style2);
44109
+ if (!match) return null;
44110
+ return {
44111
+ listId: match[1],
44112
+ level: parseInt(match[2], 10),
44113
+ isOrdered: false
44114
+ // Will be resolved from style rules
44115
+ };
44116
+ }
44117
+ function convertWordLists(doc2) {
44118
+ const listStyles = parseListStyles(doc2);
44119
+ const listParagraphs = Array.from(doc2.body.querySelectorAll('[class*="MsoList"]'));
44120
+ if (listParagraphs.length === 0) return;
44121
+ const groups = [];
44122
+ let currentGroup = [];
44123
+ for (const p of listParagraphs) {
44124
+ const el2 = p;
44125
+ const style2 = el2.getAttribute("style") ?? "";
44126
+ if (!parseListStyle(style2)) continue;
44127
+ if (currentGroup.length > 0) {
44128
+ const lastEl = currentGroup[currentGroup.length - 1];
44129
+ let nextSibling = lastEl.nextElementSibling;
44130
+ while (nextSibling && nextSibling !== el2 && nextSibling.textContent?.trim() === "") {
44131
+ nextSibling = nextSibling.nextElementSibling;
44132
+ }
44133
+ if (nextSibling !== el2) {
44134
+ groups.push(currentGroup);
44135
+ currentGroup = [];
44136
+ }
44137
+ }
44138
+ currentGroup.push(el2);
44139
+ }
44140
+ if (currentGroup.length > 0) {
44141
+ groups.push(currentGroup);
44142
+ }
44143
+ for (const group of groups) {
44144
+ convertListGroup(doc2, group, listStyles);
44145
+ }
44146
+ }
44147
+ function convertListGroup(doc2, paragraphs, listStyles) {
44148
+ if (paragraphs.length === 0) return;
44149
+ const rootInfo = parseListStyle(paragraphs[0].getAttribute("style") ?? "");
44150
+ if (!rootInfo) return;
44151
+ const parent = paragraphs[0].parentNode;
44152
+ if (!parent) return;
44153
+ const rootKey = `${rootInfo.listId}:level${rootInfo.level}`;
44154
+ const isRootOrdered = listStyles.get(rootKey) ?? false;
44155
+ const rootList = doc2.createElement(isRootOrdered ? "ol" : "ul");
44156
+ const stack = [{ element: rootList, level: rootInfo.level }];
44157
+ for (const p of paragraphs) {
44158
+ const style2 = p.getAttribute("style") ?? "";
44159
+ const info = parseListStyle(style2);
44160
+ if (!info) continue;
44161
+ const key = `${info.listId}:level${info.level}`;
44162
+ const isOrdered = listStyles.get(key) ?? false;
44163
+ while (stack.length > 1 && stack[stack.length - 1].level >= info.level) {
44164
+ stack.pop();
44165
+ }
44166
+ if (info.level > stack[stack.length - 1].level) {
44167
+ const currentList = stack[stack.length - 1].element;
44168
+ let lastLi = currentList.lastElementChild;
44169
+ if (!lastLi || lastLi.tagName.toLowerCase() !== "li") {
44170
+ lastLi = doc2.createElement("li");
44171
+ currentList.appendChild(lastLi);
44172
+ }
44173
+ const subList = doc2.createElement(isOrdered ? "ol" : "ul");
44174
+ lastLi.appendChild(subList);
44175
+ stack.push({ element: subList, level: info.level });
44176
+ }
44177
+ const li = doc2.createElement("li");
44178
+ removeListMarkers(p);
44179
+ while (p.firstChild) {
44180
+ li.appendChild(p.firstChild);
44181
+ }
44182
+ const cleanedStyle = cleanMsoStyles(style2);
44183
+ if (cleanedStyle) {
44184
+ li.setAttribute("style", cleanedStyle);
44185
+ }
44186
+ stack[stack.length - 1].element.appendChild(li);
44187
+ }
44188
+ parent.insertBefore(rootList, paragraphs[0]);
44189
+ for (const p of paragraphs) {
44190
+ p.remove();
44191
+ }
44192
+ }
44193
+ function removeListMarkers(el2) {
44194
+ const spans = Array.from(el2.querySelectorAll("span"));
44195
+ for (const span of spans) {
44196
+ const style2 = span.getAttribute("style") ?? "";
44197
+ if (/mso-list:\s*Ignore/i.test(style2)) {
44198
+ span.remove();
44199
+ }
44200
+ }
44201
+ }
44202
+ const MSO_PROPERTY_PATTERN = /\bmso-[^:]+:[^;]+;?\s*/gi;
44203
+ const MSO_CLASS_PATTERN = /\bMso\w*|\bxl\d+/g;
44204
+ function cleanMsoStyles(style2) {
44205
+ let cleaned = style2.replace(MSO_PROPERTY_PATTERN, "");
44206
+ cleaned = cleaned.replace(/;\s*;/g, ";").replace(/^\s*;\s*/, "").replace(/\s*;\s*$/, "").trim();
44207
+ return cleaned || "";
44208
+ }
44209
+ function cleanFontFamily(value) {
44210
+ const first2 = value.split(",")[0].trim();
44211
+ return first2.replace(/^["']|["']$/g, "");
44212
+ }
44213
+ function cleanElementStyles(doc2) {
44214
+ const allElements = Array.from(doc2.body.querySelectorAll("*"));
44215
+ for (const el2 of allElements) {
44216
+ const className = el2.getAttribute("class");
44217
+ if (className) {
44218
+ const cleaned = className.replace(MSO_CLASS_PATTERN, "").trim();
44219
+ if (cleaned) {
44220
+ el2.setAttribute("class", cleaned);
44221
+ } else {
44222
+ el2.removeAttribute("class");
44223
+ }
44224
+ }
44225
+ const style2 = el2.getAttribute("style");
44226
+ if (style2) {
44227
+ let cleaned = cleanMsoStyles(style2);
44228
+ const fontFamilyMatch = /font-family:\s*([^;]+)/i.exec(cleaned);
44229
+ if (fontFamilyMatch) {
44230
+ const cleanedFont = cleanFontFamily(fontFamilyMatch[1]);
44231
+ cleaned = cleaned.replace(fontFamilyMatch[0], `font-family: ${cleanedFont}`);
44232
+ }
44233
+ if (cleaned) {
44234
+ el2.setAttribute("style", cleaned);
44235
+ } else {
44236
+ el2.removeAttribute("style");
44237
+ }
44238
+ }
44239
+ const attrsToRemove = Array.from(el2.attributes).filter(
44240
+ (attr) => attr.name.startsWith("v:") || attr.name.startsWith("o:") || attr.name === "lang"
44241
+ );
44242
+ for (const attr of attrsToRemove) {
44243
+ el2.removeAttribute(attr.name);
44244
+ }
44245
+ }
44246
+ }
44247
+ function removeEmptyWrappers(doc2) {
44248
+ let changed = true;
44249
+ while (changed) {
44250
+ changed = false;
44251
+ const spans = Array.from(doc2.body.querySelectorAll("span"));
44252
+ for (const span of spans) {
44253
+ if (span.attributes.length === 0) {
44254
+ const parent = span.parentNode;
44255
+ if (parent) {
44256
+ while (span.firstChild) {
44257
+ parent.insertBefore(span.firstChild, span);
44258
+ }
44259
+ parent.removeChild(span);
44260
+ changed = true;
44261
+ }
44262
+ }
44263
+ }
44264
+ }
44265
+ const emptyParas = Array.from(doc2.body.querySelectorAll("p"));
44266
+ for (const p of emptyParas) {
44267
+ if (p.innerHTML.trim() === "" && doc2.body.children.length > 1) {
44268
+ p.remove();
44269
+ }
44270
+ }
44271
+ }
44272
+ function normalizeExcelTables(doc2) {
44273
+ const tables = Array.from(doc2.body.querySelectorAll("table"));
44274
+ for (const table of tables) {
44275
+ removeExcelAttributes(table);
44276
+ const cells = Array.from(table.querySelectorAll("td, th"));
44277
+ for (const cell of cells) {
44278
+ removeExcelAttributes(cell);
44279
+ const style2 = cell.getAttribute("style");
44280
+ if (style2) {
44281
+ const cleaned = cleanMsoStyles(style2);
44282
+ if (cleaned) {
44283
+ cell.setAttribute("style", cleaned);
44284
+ } else {
44285
+ cell.removeAttribute("style");
44286
+ }
44287
+ }
44288
+ }
44289
+ const rows = Array.from(table.querySelectorAll("tr"));
44290
+ for (const row of rows) {
44291
+ removeExcelAttributes(row);
44292
+ }
44293
+ }
44294
+ }
44295
+ const EXCEL_ATTRS = [
44296
+ "x:num",
44297
+ "x:str",
44298
+ "x:fmla",
44299
+ "x:autofilter",
44300
+ "mso-number-format"
44301
+ ];
44302
+ function removeExcelAttributes(el2) {
44303
+ for (const attr of EXCEL_ATTRS) {
44304
+ el2.removeAttribute(attr);
44305
+ }
44306
+ const className = el2.getAttribute("class");
44307
+ if (className) {
44308
+ const cleaned = className.replace(MSO_CLASS_PATTERN, "").trim();
44309
+ if (cleaned) {
44310
+ el2.setAttribute("class", cleaned);
44311
+ } else {
44312
+ el2.removeAttribute("class");
44313
+ }
44314
+ }
44315
+ }
44316
+ const DANGEROUS_TAGS = [
44317
+ "script",
44318
+ "iframe",
44319
+ "object",
44320
+ "embed",
44321
+ "applet",
44322
+ "form",
44323
+ "input",
44324
+ "textarea",
44325
+ "select",
44326
+ "button"
44327
+ ];
44328
+ const EVENT_ATTR_PATTERN = /^on/i;
44329
+ const DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript|data\s*:(?!image))/i;
44330
+ function sanitize(doc2) {
44331
+ for (const tag of DANGEROUS_TAGS) {
44332
+ const elements = Array.from(doc2.body.querySelectorAll(tag));
44333
+ for (const el2 of elements) {
44334
+ el2.remove();
44335
+ }
44336
+ }
44337
+ const allElements = Array.from(doc2.body.querySelectorAll("*"));
44338
+ for (const el2 of allElements) {
44339
+ const attrs = Array.from(el2.attributes);
44340
+ for (const attr of attrs) {
44341
+ if (EVENT_ATTR_PATTERN.test(attr.name)) {
44342
+ el2.removeAttribute(attr.name);
44343
+ continue;
44344
+ }
44345
+ if ((attr.name === "href" || attr.name === "src" || attr.name === "action") && DANGEROUS_URL_PATTERN.test(attr.value)) {
44346
+ el2.removeAttribute(attr.name);
44347
+ }
44348
+ }
44349
+ const src = el2.getAttribute("src");
44350
+ if (src && src.startsWith("file://")) {
44351
+ el2.removeAttribute("src");
44352
+ }
44353
+ const href = el2.getAttribute("href");
44354
+ if (href && href.startsWith("file://")) {
44355
+ el2.removeAttribute("href");
44356
+ }
44357
+ }
44358
+ }
44359
+ function removeStyleBlocks(doc2) {
44360
+ const styles = Array.from(doc2.querySelectorAll("style"));
44361
+ for (const s of styles) {
44362
+ s.remove();
44363
+ }
44364
+ }
44365
+ function removeHeadElements(doc2) {
44366
+ const selectors = ["meta", "link", "title", "xml"];
44367
+ for (const selector of selectors) {
44368
+ const elements = Array.from(doc2.body.querySelectorAll(selector));
44369
+ for (const el2 of elements) {
44370
+ el2.remove();
44371
+ }
44372
+ }
44373
+ }
44374
+ function transformOfficeHTML(html) {
44375
+ if (!isOfficeContent(html)) {
44376
+ return html;
44377
+ }
44378
+ let cleaned = removeConditionalComments(html);
44379
+ const parser = new DOMParser();
44380
+ const doc2 = parser.parseFromString(cleaned, "text/html");
44381
+ removeHeadElements(doc2);
44382
+ if (isWordContent(html)) {
44383
+ convertWordLists(doc2);
44384
+ }
44385
+ removeOfficeElements(doc2);
44386
+ if (isExcelContent(html)) {
44387
+ normalizeExcelTables(doc2);
44388
+ }
44389
+ cleanElementStyles(doc2);
44390
+ removeStyleBlocks(doc2);
44391
+ removeEmptyWrappers(doc2);
44392
+ sanitize(doc2);
44393
+ return doc2.body.innerHTML;
44394
+ }
44395
+ const PasteFromOffice = Extension.create({
44396
+ name: "pasteFromOffice",
44397
+ addOptions() {
44398
+ return {
44399
+ enabled: true
44400
+ };
44401
+ },
44402
+ addStorage() {
44403
+ return {};
44404
+ },
44405
+ transformPastedHTML(html) {
44406
+ if (!this.options.enabled) {
44407
+ return html;
44408
+ }
44409
+ return transformOfficeHTML(html);
44410
+ }
44411
+ });
43823
44412
  const en = {
43824
44413
  "Bold": "Bold",
43825
44414
  "Italic": "Italic",
@@ -46188,7 +46777,10 @@ class HTMLEditor {
46188
46777
  entity_encoding: config.entity_encoding ?? "raw",
46189
46778
  valid_children: config.valid_children,
46190
46779
  convert_unsafe_embeds: config.convert_unsafe_embeds ?? true,
46191
- format_empty_lines: config.format_empty_lines ?? true
46780
+ format_empty_lines: config.format_empty_lines ?? true,
46781
+ toolbar_narrow_breakpoint: config.toolbar_narrow_breakpoint,
46782
+ toolbar_priority: config.toolbar_priority,
46783
+ paste_from_office: config.paste_from_office ?? true
46192
46784
  };
46193
46785
  }
46194
46786
  createEditor() {
@@ -46266,7 +46858,9 @@ class HTMLEditor {
46266
46858
  sticky: this.config.toolbar_sticky ?? true,
46267
46859
  customButtons: this.customButtons,
46268
46860
  config: this.config,
46269
- iconSet
46861
+ iconSet,
46862
+ narrowBreakpoint: this.config.toolbar_narrow_breakpoint ?? 768,
46863
+ priorityOverrides: this.config.toolbar_priority ?? {}
46270
46864
  });
46271
46865
  if (this.config.auto_focus) {
46272
46866
  setTimeout(() => this.focus(), 10);
@@ -46389,6 +46983,9 @@ class HTMLEditor {
46389
46983
  }),
46390
46984
  TextDirection
46391
46985
  ];
46986
+ if (this.config.paste_from_office !== false) {
46987
+ extensions.push(PasteFromOffice);
46988
+ }
46392
46989
  if (!this.config.basicEditor) {
46393
46990
  extensions.push(
46394
46991
  Image.configure({
@@ -46614,6 +47211,7 @@ export {
46614
47211
  LineHeight,
46615
47212
  LinkEditor,
46616
47213
  Mention,
47214
+ PasteFromOffice,
46617
47215
  SearchReplace,
46618
47216
  SignatureBlock,
46619
47217
  SourceEditor,