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