@harbour-enterprises/superdoc 0.13.3-next.8 → 0.13.3

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.
Files changed (37) hide show
  1. package/dist/chunks/{super-editor.es-D-Cmbg-l.cjs → super-editor.es-D6IwM8Ss.cjs} +612 -866
  2. package/dist/chunks/{super-editor.es-CgHzvMwt.es.js → super-editor.es-Dr2PHXQw.es.js} +612 -866
  3. package/dist/style.css +2 -2
  4. package/dist/super-editor/ai-writer.es.js +2 -2
  5. package/dist/super-editor/chunks/{converter-qUhgLszU.js → converter-BAzy5pWu.js} +56 -635
  6. package/dist/super-editor/chunks/{docx-zipper-C8g7C4cg.js → docx-zipper-CHpW7qj4.js} +1 -1
  7. package/dist/super-editor/chunks/{editor-BxfImSXL.js → editor-DkYKMWgz.js} +597 -275
  8. package/dist/super-editor/chunks/{toolbar-BgNg8Xpu.js → toolbar-DUmK-BBL.js} +2 -2
  9. package/dist/super-editor/converter.es.js +2 -2
  10. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  11. package/dist/super-editor/core/InputRule.d.ts +0 -7
  12. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  13. package/dist/super-editor/core/helpers/annotator.d.ts +0 -4
  14. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  18. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  19. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  20. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +1 -6
  21. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  22. package/dist/super-editor/extensions/table/table.d.ts.map +1 -1
  23. package/dist/super-editor/file-zipper.es.js +1 -1
  24. package/dist/super-editor/style.css +2 -2
  25. package/dist/super-editor/super-editor.es.js +7 -7
  26. package/dist/super-editor/toolbar.es.js +2 -2
  27. package/dist/super-editor.cjs +1 -1
  28. package/dist/super-editor.es.js +1 -1
  29. package/dist/superdoc.cjs +2 -2
  30. package/dist/superdoc.es.js +3 -3
  31. package/dist/superdoc.umd.js +613 -867
  32. package/dist/superdoc.umd.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/super-editor/extensions/table/tableHelpers/cellAround.d.ts +0 -2
  35. package/dist/super-editor/extensions/table/tableHelpers/cellAround.d.ts.map +0 -1
  36. package/dist/super-editor/extensions/table/tableHelpers/cellWrapping.d.ts +0 -2
  37. package/dist/super-editor/extensions/table/tableHelpers/cellWrapping.d.ts.map +0 -1
@@ -10958,7 +10958,7 @@ class NodeRange {
10958
10958
  }
10959
10959
  }
10960
10960
  const emptyAttrs = /* @__PURE__ */ Object.create(null);
10961
- let Node$1$1 = class Node2 {
10961
+ let Node$2 = class Node2 {
10962
10962
  /**
10963
10963
  @internal
10964
10964
  */
@@ -11359,8 +11359,8 @@ let Node$1$1 = class Node2 {
11359
11359
  return node2;
11360
11360
  }
11361
11361
  };
11362
- Node$1$1.prototype.text = void 0;
11363
- class TextNode extends Node$1$1 {
11362
+ Node$2.prototype.text = void 0;
11363
+ class TextNode extends Node$2 {
11364
11364
  /**
11365
11365
  @internal
11366
11366
  */
@@ -11947,7 +11947,7 @@ let NodeType$1 = class NodeType {
11947
11947
  create(attrs = null, content, marks) {
11948
11948
  if (this.isText)
11949
11949
  throw new Error("NodeType.create can't construct text nodes");
11950
- return new Node$1$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
11950
+ return new Node$2(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
11951
11951
  }
11952
11952
  /**
11953
11953
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
@@ -11957,7 +11957,7 @@ let NodeType$1 = class NodeType {
11957
11957
  createChecked(attrs = null, content, marks) {
11958
11958
  content = Fragment.from(content);
11959
11959
  this.checkContent(content);
11960
- return new Node$1$1(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
11960
+ return new Node$2(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
11961
11961
  }
11962
11962
  /**
11963
11963
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
@@ -11980,7 +11980,7 @@ let NodeType$1 = class NodeType {
11980
11980
  let after = matched && matched.fillBefore(Fragment.empty, true);
11981
11981
  if (!after)
11982
11982
  return null;
11983
- return new Node$1$1(this, attrs, content.append(after), Mark$1.setFrom(marks));
11983
+ return new Node$2(this, attrs, content.append(after), Mark$1.setFrom(marks));
11984
11984
  }
11985
11985
  /**
11986
11986
  Returns true if the given fragment is valid content for this node
@@ -12217,7 +12217,7 @@ let Schema$1 = class Schema {
12217
12217
  bound.
12218
12218
  */
12219
12219
  nodeFromJSON(json) {
12220
- return Node$1$1.fromJSON(this, json);
12220
+ return Node$2.fromJSON(this, json);
12221
12221
  }
12222
12222
  /**
12223
12223
  Deserialize a mark from its JSON representation. This method is
@@ -15777,7 +15777,7 @@ class EditorState {
15777
15777
  let instance = new EditorState($config);
15778
15778
  $config.fields.forEach((field) => {
15779
15779
  if (field.name == "doc") {
15780
- instance.doc = Node$1$1.fromJSON(config.schema, json.doc);
15780
+ instance.doc = Node$2.fromJSON(config.schema, json.doc);
15781
15781
  } else if (field.name == "selection") {
15782
15782
  instance.selection = Selection.fromJSON(instance.doc, json.selection);
15783
15783
  } else if (field.name == "storedMarks") {
@@ -18838,583 +18838,6 @@ const createColGroup = (node2, cellMinWidth, overrideCol, overrideValue) => {
18838
18838
  colgroupValues
18839
18839
  };
18840
18840
  };
18841
- function chainableEditorState(transaction, state2) {
18842
- let { selection, doc: doc2, storedMarks } = transaction;
18843
- return {
18844
- ...state2,
18845
- apply: state2.apply.bind(state2),
18846
- applyTransaction: state2.applyTransaction.bind(state2),
18847
- plugins: state2.plugins,
18848
- schema: state2.schema,
18849
- reconfigure: state2.reconfigure.bind(state2),
18850
- toJSON: state2.toJSON.bind(state2),
18851
- get storedMarks() {
18852
- return storedMarks;
18853
- },
18854
- get selection() {
18855
- return selection;
18856
- },
18857
- get doc() {
18858
- return doc2;
18859
- },
18860
- get tr() {
18861
- selection = transaction.selection;
18862
- doc2 = transaction.doc;
18863
- storedMarks = transaction.storedMarks;
18864
- return transaction;
18865
- }
18866
- };
18867
- }
18868
- class CommandService {
18869
- constructor(props) {
18870
- __publicField$2(this, "editor");
18871
- __publicField$2(this, "rawCommands");
18872
- this.editor = props.editor;
18873
- this.rawCommands = this.editor.extensionService.commands;
18874
- }
18875
- /**
18876
- * Static method for creating a service.
18877
- * @param args Arguments for the constructor.
18878
- */
18879
- static create(...args) {
18880
- return new CommandService(...args);
18881
- }
18882
- /**
18883
- * Get editor state.
18884
- */
18885
- get state() {
18886
- return this.editor.state;
18887
- }
18888
- /**
18889
- * Get all commands with wrapped command method.
18890
- */
18891
- get commands() {
18892
- const { editor, state: state2 } = this;
18893
- const { view } = editor;
18894
- const { tr } = state2;
18895
- const props = this.createProps(tr);
18896
- const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
18897
- const method = (...args) => {
18898
- const fn2 = command2(...args)(props);
18899
- if (!tr.getMeta("preventDispatch")) {
18900
- view.dispatch(tr);
18901
- }
18902
- return fn2;
18903
- };
18904
- return [name, method];
18905
- });
18906
- return Object.fromEntries(entries);
18907
- }
18908
- /**
18909
- * Create a chain of commands to call multiple commands at once.
18910
- */
18911
- get chain() {
18912
- return () => this.createChain();
18913
- }
18914
- /**
18915
- * Check if a command or a chain of commands can be executed. Without executing it.
18916
- */
18917
- get can() {
18918
- return () => this.createCan();
18919
- }
18920
- /**
18921
- * Creates a chain of commands.
18922
- * @param startTr Start transaction.
18923
- * @param shouldDispatch Should dispatch or not.
18924
- */
18925
- createChain(startTr, shouldDispatch = true) {
18926
- const { editor, state: state2, rawCommands } = this;
18927
- const { view } = editor;
18928
- const callbacks2 = [];
18929
- const hasStartTr = !!startTr;
18930
- const tr = startTr || state2.tr;
18931
- const run2 = () => {
18932
- if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
18933
- view.dispatch(tr);
18934
- }
18935
- return callbacks2.every((cb) => cb === true);
18936
- };
18937
- const entries = Object.entries(rawCommands).map(([name, command2]) => {
18938
- const chainedCommand = (...args) => {
18939
- const props = this.createProps(tr, shouldDispatch);
18940
- const callback = command2(...args)(props);
18941
- callbacks2.push(callback);
18942
- return chain;
18943
- };
18944
- return [name, chainedCommand];
18945
- });
18946
- const chain = {
18947
- ...Object.fromEntries(entries),
18948
- run: run2
18949
- };
18950
- return chain;
18951
- }
18952
- /**
18953
- * Creates a can check for commands.
18954
- * @param startTr Start transaction.
18955
- */
18956
- createCan(startTr) {
18957
- const { rawCommands, state: state2 } = this;
18958
- const dispatch = false;
18959
- const tr = startTr || state2.tr;
18960
- const props = this.createProps(tr, dispatch);
18961
- const commands2 = Object.fromEntries(
18962
- Object.entries(rawCommands).map(([name, command2]) => {
18963
- return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
18964
- })
18965
- );
18966
- return {
18967
- ...commands2,
18968
- chain: () => this.createChain(tr, dispatch)
18969
- };
18970
- }
18971
- /**
18972
- * Creates default props for the command method.
18973
- * @param {*} tr Transaction.
18974
- * @param {*} shouldDispatch Check if should dispatch.
18975
- * @returns Object with props.
18976
- */
18977
- createProps(tr, shouldDispatch = true) {
18978
- const { editor, state: state2, rawCommands } = this;
18979
- const { view } = editor;
18980
- const props = {
18981
- tr,
18982
- editor,
18983
- view,
18984
- state: chainableEditorState(tr, state2),
18985
- dispatch: shouldDispatch ? () => void 0 : void 0,
18986
- chain: () => this.createChain(tr, shouldDispatch),
18987
- can: () => this.createCan(tr),
18988
- get commands() {
18989
- return Object.fromEntries(
18990
- Object.entries(rawCommands).map(([name, command2]) => {
18991
- return [name, (...args) => command2(...args)(props)];
18992
- })
18993
- );
18994
- }
18995
- };
18996
- return props;
18997
- }
18998
- }
18999
- function getHTMLFromFragment(fragment, schema) {
19000
- const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
19001
- const temporaryDocument = document.implementation.createHTMLDocument();
19002
- const container = temporaryDocument.createElement("div");
19003
- container.appendChild(documentFragment);
19004
- return container.innerHTML;
19005
- }
19006
- const getTextContentFromNodes = ($from, maxMatch = 500) => {
19007
- let textBefore = "";
19008
- const sliceEndPos = $from.parentOffset;
19009
- $from.parent.nodesBetween(
19010
- Math.max(0, sliceEndPos - maxMatch),
19011
- sliceEndPos,
19012
- (node2, pos, parent, index2) => {
19013
- const chunk = node2.type.spec.toText?.({
19014
- node: node2,
19015
- pos,
19016
- parent,
19017
- index: index2
19018
- }) || node2.textContent || "%leaf%";
19019
- textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
19020
- }
19021
- );
19022
- return textBefore;
19023
- };
19024
- const handleDocxPaste = (html, editor, view, plugin2) => {
19025
- const { converter } = editor;
19026
- if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
19027
- let cleanedHtml = convertEmToPt(html);
19028
- cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
19029
- const tempDiv = document.createElement("div");
19030
- tempDiv.innerHTML = cleanedHtml;
19031
- const paragraphs = tempDiv.querySelectorAll("p");
19032
- paragraphs.forEach((p) => {
19033
- const innerHTML3 = p.innerHTML;
19034
- if (!innerHTML3.includes("<!--[if !supportLists]")) return;
19035
- const styleAttr = p.getAttribute("style") || "";
19036
- const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
19037
- if (msoListMatch) {
19038
- const [, abstractId, level] = msoListMatch;
19039
- const listNumId = getListNumIdFromAbstract(abstractId, editor);
19040
- if (!listNumId) return;
19041
- const abstractDefinition = getListAbstractDefinition(abstractId, editor);
19042
- const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
19043
- p.setAttribute("data-num-id", listNumId);
19044
- p.setAttribute("data-list-level", level - 1);
19045
- p.setAttribute("data-start", start2);
19046
- p.setAttribute("data-lvl-text", lvlText);
19047
- p.setAttribute("data-num-fmt", numFmt);
19048
- }
19049
- extractAndRemoveConditionalPrefix(p);
19050
- });
19051
- transformWordLists(tempDiv);
19052
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
19053
- tempDiv.remove();
19054
- const { dispatch } = editor.view;
19055
- if (!dispatch) return false;
19056
- dispatch(view.state.tr.replaceSelectionWith(doc2, true));
19057
- return true;
19058
- };
19059
- const getLevelDefinition = (abstractDefinition, level) => {
19060
- if (!abstractDefinition || !abstractDefinition.elements) return null;
19061
- const levelElement = abstractDefinition.elements.find((el) => {
19062
- return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
19063
- });
19064
- if (!levelElement) return null;
19065
- const { elements } = levelElement;
19066
- const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
19067
- const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
19068
- const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
19069
- return { lvlText, start: start2, numFmt, elements };
19070
- };
19071
- const getListNumIdFromAbstract = (abstractId, editor) => {
19072
- const { definitions } = editor?.converter?.numbering;
19073
- if (!definitions) return null;
19074
- const matchedDefinition = Object.values(definitions).find((def) => {
19075
- return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
19076
- });
19077
- return matchedDefinition?.attributes?.["w:numId"];
19078
- };
19079
- const getListAbstractDefinition = (abstractId, editor) => {
19080
- const { abstracts = {} } = editor?.converter?.numbering;
19081
- return abstracts[abstractId] || null;
19082
- };
19083
- const transformWordLists = (container) => {
19084
- const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
19085
- const listMap = /* @__PURE__ */ new Map();
19086
- const listLevels = {};
19087
- for (const p of paragraphs) {
19088
- const listId = p.getAttribute("data-num-id");
19089
- const level = parseInt(p.getAttribute("data-list-level"));
19090
- const numFmt = p.getAttribute("data-num-fmt");
19091
- const start2 = p.getAttribute("data-start");
19092
- const lvlText = p.getAttribute("data-lvl-text");
19093
- if (!listMap.has(listId)) listMap.set(listId, []);
19094
- listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
19095
- }
19096
- for (const [id, items] of listMap.entries()) {
19097
- if (!listLevels[id]) {
19098
- listLevels[id] = {
19099
- stack: [],
19100
- counts: {},
19101
- prevLevel: null
19102
- };
19103
- }
19104
- const parentStack = [];
19105
- items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
19106
- const listLevel = generateListNestingPath(listLevels, id, level);
19107
- const li = document.createElement("li");
19108
- li.innerHTML = p.innerHTML;
19109
- li.setAttribute("data-list-level", JSON.stringify(listLevel));
19110
- li.setAttribute("data-num-id", id);
19111
- li.setAttribute("data-lvl-text", lvlText);
19112
- li.setAttribute("data-num-fmt", numFmt);
19113
- if (p.hasAttribute("data-font-family")) {
19114
- li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
19115
- }
19116
- if (p.hasAttribute("data-font-size")) {
19117
- li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
19118
- }
19119
- const parentNode2 = p.parentNode;
19120
- let listForLevel = parentStack[level];
19121
- if (!listForLevel) {
19122
- const newList = document.createElement("ol");
19123
- newList.setAttribute("data-list-id", id);
19124
- newList.level = level;
19125
- if (level > 0) {
19126
- const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
19127
- if (parentLi) parentLi.appendChild(newList);
19128
- } else {
19129
- parentNode2.insertBefore(newList, p);
19130
- }
19131
- parentStack[level] = newList;
19132
- parentStack.length = level + 1;
19133
- listForLevel = newList;
19134
- }
19135
- listForLevel.appendChild(li);
19136
- p.remove();
19137
- });
19138
- }
19139
- };
19140
- function generateListNestingPath(listLevels, listId, currentLevel) {
19141
- const levelState = listLevels[listId];
19142
- if (!levelState.stack) levelState.stack = [];
19143
- if (levelState.prevLevel === void 0) levelState.prevLevel = null;
19144
- if (levelState.prevLevel === null) {
19145
- levelState.stack = Array(currentLevel).fill(1).concat(1);
19146
- } else {
19147
- if (currentLevel > levelState.prevLevel) {
19148
- levelState.stack.push(1);
19149
- } else if (currentLevel === levelState.prevLevel) {
19150
- levelState.stack[levelState.stack.length - 1]++;
19151
- } else {
19152
- levelState.stack = levelState.stack.slice(0, currentLevel + 1);
19153
- levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
19154
- }
19155
- }
19156
- levelState.prevLevel = currentLevel;
19157
- return [...levelState.stack];
19158
- }
19159
- function extractAndRemoveConditionalPrefix(p) {
19160
- const nodes = Array.from(p.childNodes);
19161
- let fontFamily2 = null;
19162
- let fontSize2 = null;
19163
- let start2 = -1, end2 = -1;
19164
- nodes.forEach((node2, index2) => {
19165
- if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
19166
- start2 = index2;
19167
- }
19168
- if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
19169
- end2 = index2;
19170
- }
19171
- });
19172
- if (start2 !== -1 && end2 !== -1) {
19173
- for (let i = start2 + 1; i < end2; i++) {
19174
- const node2 = nodes[i];
19175
- if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
19176
- fontFamily2 = fontFamily2 || node2.style.fontFamily;
19177
- fontSize2 = fontSize2 || node2.style.fontSize;
19178
- }
19179
- }
19180
- for (let i = end2; i >= start2; i--) {
19181
- p.removeChild(p.childNodes[i]);
19182
- }
19183
- if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
19184
- if (fontSize2) p.setAttribute("data-font-size", fontSize2);
19185
- }
19186
- }
19187
- class InputRule {
19188
- constructor(config) {
19189
- __publicField$2(this, "match");
19190
- __publicField$2(this, "handler");
19191
- this.match = config.match;
19192
- this.handler = config.handler;
19193
- }
19194
- }
19195
- const inputRuleMatcherHandler = (text, match) => {
19196
- if (isRegExp(match)) {
19197
- return match.exec(text);
19198
- }
19199
- const inputRuleMatch = match(text);
19200
- if (!inputRuleMatch) {
19201
- return null;
19202
- }
19203
- const result = [inputRuleMatch.text];
19204
- result.index = inputRuleMatch.index;
19205
- result.input = text;
19206
- result.data = inputRuleMatch.data;
19207
- if (inputRuleMatch.replaceWith) {
19208
- if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
19209
- console.warn(
19210
- '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
19211
- );
19212
- }
19213
- result.push(inputRuleMatch.replaceWith);
19214
- }
19215
- return result;
19216
- };
19217
- const run = (config) => {
19218
- const {
19219
- editor,
19220
- from: from2,
19221
- to,
19222
- text,
19223
- rules,
19224
- plugin: plugin2
19225
- } = config;
19226
- const { view } = editor;
19227
- if (view.composing) {
19228
- return false;
19229
- }
19230
- const $from = view.state.doc.resolve(from2);
19231
- if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
19232
- return false;
19233
- }
19234
- let matched = false;
19235
- const textBefore = getTextContentFromNodes($from) + text;
19236
- rules.forEach((rule) => {
19237
- if (matched) {
19238
- return;
19239
- }
19240
- const match = inputRuleMatcherHandler(textBefore, rule.match);
19241
- if (!match) {
19242
- return;
19243
- }
19244
- const tr = view.state.tr;
19245
- const state2 = chainableEditorState(tr, view.state);
19246
- const range2 = {
19247
- from: from2 - (match[0].length - text.length),
19248
- to
19249
- };
19250
- const { commands: commands2, chain, can } = new CommandService({
19251
- editor,
19252
- state: state2
19253
- });
19254
- const handler = rule.handler({
19255
- state: state2,
19256
- range: range2,
19257
- match,
19258
- commands: commands2,
19259
- chain,
19260
- can
19261
- });
19262
- if (handler === null || !tr.steps.length) {
19263
- return;
19264
- }
19265
- tr.setMeta(plugin2, {
19266
- transform: tr,
19267
- from: from2,
19268
- to,
19269
- text
19270
- });
19271
- view.dispatch(tr);
19272
- matched = true;
19273
- });
19274
- return matched;
19275
- };
19276
- const inputRulesPlugin = ({ editor, rules }) => {
19277
- const plugin2 = new Plugin({
19278
- key: new PluginKey("inputRulesPlugin"),
19279
- state: {
19280
- init() {
19281
- return null;
19282
- },
19283
- apply(tr, prev, state2) {
19284
- const stored = tr.getMeta(plugin2);
19285
- if (stored) {
19286
- return stored;
19287
- }
19288
- const simulatedInputMeta = tr.getMeta("applyInputRules");
19289
- const isSimulatedInput = !!simulatedInputMeta;
19290
- if (isSimulatedInput) {
19291
- setTimeout(() => {
19292
- let { text } = simulatedInputMeta;
19293
- if (typeof text !== "string") {
19294
- text = getHTMLFromFragment(Fragment.from(text), state2.schema);
19295
- }
19296
- const { from: from2 } = simulatedInputMeta;
19297
- const to = from2 + text.length;
19298
- run({
19299
- editor,
19300
- from: from2,
19301
- to,
19302
- text,
19303
- rules,
19304
- plugin: plugin2
19305
- });
19306
- });
19307
- }
19308
- return tr.selectionSet || tr.docChanged ? null : prev;
19309
- }
19310
- },
19311
- props: {
19312
- handleTextInput(view, from2, to, text) {
19313
- return run({
19314
- editor,
19315
- from: from2,
19316
- to,
19317
- text,
19318
- rules,
19319
- plugin: plugin2
19320
- });
19321
- },
19322
- // add support for input rules to trigger on enter
19323
- // this is useful for example for code blocks
19324
- handleKeyDown(view, event) {
19325
- if (event.key !== "Enter") {
19326
- return false;
19327
- }
19328
- const { $cursor } = view.state.selection;
19329
- if ($cursor) {
19330
- return run({
19331
- editor,
19332
- from: $cursor.pos,
19333
- to: $cursor.pos,
19334
- text: "\n",
19335
- rules,
19336
- plugin: plugin2
19337
- });
19338
- }
19339
- return false;
19340
- },
19341
- // Paste handler
19342
- handlePaste(view, event, slice2) {
19343
- const clipboard = event.clipboardData;
19344
- const html = clipboard.getData("text/html");
19345
- clipboard.getData("text/plain");
19346
- const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
19347
- if (fieldAnnotationContent.length) {
19348
- return false;
19349
- }
19350
- let source;
19351
- if (!html) {
19352
- source = "plain-text";
19353
- } else if (isWordHtml(html)) {
19354
- source = "word-html";
19355
- } else {
19356
- source = "browser-html";
19357
- }
19358
- switch (source) {
19359
- case "plain-text":
19360
- break;
19361
- case "word-html":
19362
- if (editor.options.mode === "docx") {
19363
- return handleDocxPaste(html, editor, view, plugin2);
19364
- }
19365
- case "browser-html":
19366
- return handleHtmlPaste$1(html, editor);
19367
- }
19368
- return false;
19369
- }
19370
- },
19371
- isInputRules: true
19372
- });
19373
- return plugin2;
19374
- };
19375
- function isWordHtml(html) {
19376
- return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
19377
- }
19378
- const handleHtmlPaste$1 = (html, editor, plugin2) => {
19379
- const htmlWithPtSizing = convertEmToPt(html);
19380
- const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
19381
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
19382
- const { dispatch } = editor.view;
19383
- if (!dispatch) return false;
19384
- dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
19385
- return true;
19386
- };
19387
- const convertEmToPt = (html) => {
19388
- return html.replace(
19389
- /font-size\s*:\s*([\d.]+)em/gi,
19390
- (_, emValue) => {
19391
- const em = parseFloat(emValue);
19392
- const pt = Math.round(em * 12 * 100) / 100;
19393
- return `font-size: ${pt}pt`;
19394
- }
19395
- );
19396
- };
19397
- function cleanHtmlUnnecessaryTags(html) {
19398
- return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
19399
- }
19400
- function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
19401
- const container = document.createElement("div");
19402
- container.innerHTML = html;
19403
- const walkAndClean = (node2) => {
19404
- for (const child of [...node2.children]) {
19405
- if (forbiddenTags.includes(child.tagName.toLowerCase())) {
19406
- child.remove();
19407
- continue;
19408
- }
19409
- if (child.hasAttribute("linebreaktype")) {
19410
- child.removeAttribute("linebreaktype");
19411
- }
19412
- walkAndClean(child);
19413
- }
19414
- };
19415
- walkAndClean(container);
19416
- return container;
19417
- }
19418
18841
  function exportSchemaToJson(params2) {
19419
18842
  const { type: type2 } = params2.node || {};
19420
18843
  const router = {
@@ -20533,7 +19956,7 @@ function translateImageNode(params2, imageSize) {
20533
19956
  attributes: {
20534
19957
  relativeFrom: attrs.anchorData.hRelativeFrom
20535
19958
  },
20536
- ...attrs.marginOffset.left !== void 0 && {
19959
+ ...attrs.marginOffset.left && {
20537
19960
  elements: [{
20538
19961
  name: "wp:posOffset",
20539
19962
  elements: [{
@@ -20557,7 +19980,7 @@ function translateImageNode(params2, imageSize) {
20557
19980
  attributes: {
20558
19981
  relativeFrom: attrs.anchorData.vRelativeFrom
20559
19982
  },
20560
- ...attrs.marginOffset.top !== void 0 && {
19983
+ ...attrs.marginOffset.top && {
20561
19984
  elements: [{
20562
19985
  name: "wp:posOffset",
20563
19986
  elements: [{
@@ -20758,11 +20181,12 @@ function prepareHtmlAnnotation(params2) {
20758
20181
  node: { attrs = {}, marks = [] },
20759
20182
  editorSchema
20760
20183
  } = params2;
20761
- const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
20184
+ const parser = new window.DOMParser();
20185
+ const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
20762
20186
  const marksFromAttrs = translateFieldAttrsToMarks(attrs);
20763
20187
  const allMarks = [...marks, ...marksFromAttrs];
20764
20188
  let state2 = EditorState.create({
20765
- doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
20189
+ doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtml)
20766
20190
  });
20767
20191
  if (allMarks.length) {
20768
20192
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
@@ -21596,10 +21020,10 @@ function handleImageImport(node2, currentFileName, params2) {
21596
21020
  const hRelativeFrom = positionHTag?.attributes.relativeFrom;
21597
21021
  const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
21598
21022
  const positionVTag = node2.elements.find((el) => el.name === "wp:positionV");
21599
- const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
21023
+ const positionV = positionVTag?.elements.find((el) => el.name === "wp:posOffset");
21600
21024
  const positionVValue = emuToPixels(positionV?.elements[0]?.text);
21601
21025
  const vRelativeFrom = positionVTag?.attributes.relativeFrom;
21602
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
21026
+ const alignV = positionVTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
21603
21027
  const simplePos = node2.elements.find((el) => el.name === "wp:simplePos");
21604
21028
  const wrapSquare = node2.elements.find((el) => el.name === "wp:wrapSquare");
21605
21029
  const wrapTopAndBottom = node2.elements.find((el) => el.name === "wp:wrapTopAndBottom");
@@ -23989,7 +23413,7 @@ const _SuperConverter = class _SuperConverter2 {
23989
23413
  return;
23990
23414
  }
23991
23415
  }
23992
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.3-next.8") {
23416
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.3") {
23993
23417
  const customLocation = "docProps/custom.xml";
23994
23418
  if (!docx[customLocation]) {
23995
23419
  docx[customLocation] = generateCustomXml();
@@ -24456,7 +23880,7 @@ function storeSuperdocVersion(docx) {
24456
23880
  function generateCustomXml() {
24457
23881
  return DEFAULT_CUSTOM_XML;
24458
23882
  }
24459
- function generateSuperdocVersion(pid = 2, version2 = "0.13.3-next.8") {
23883
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.3") {
24460
23884
  return {
24461
23885
  type: "element",
24462
23886
  name: "property",
@@ -28178,6 +27602,164 @@ createMarksSchema_fn = function(markExtensions, attributes, editor) {
28178
27602
  };
28179
27603
  __privateAdd$1(_Schema, _Schema_static);
28180
27604
  let Schema2 = _Schema;
27605
+ function chainableEditorState(transaction, state2) {
27606
+ let { selection, doc: doc2, storedMarks } = transaction;
27607
+ return {
27608
+ ...state2,
27609
+ apply: state2.apply.bind(state2),
27610
+ applyTransaction: state2.applyTransaction.bind(state2),
27611
+ plugins: state2.plugins,
27612
+ schema: state2.schema,
27613
+ reconfigure: state2.reconfigure.bind(state2),
27614
+ toJSON: state2.toJSON.bind(state2),
27615
+ get storedMarks() {
27616
+ return storedMarks;
27617
+ },
27618
+ get selection() {
27619
+ return selection;
27620
+ },
27621
+ get doc() {
27622
+ return doc2;
27623
+ },
27624
+ get tr() {
27625
+ selection = transaction.selection;
27626
+ doc2 = transaction.doc;
27627
+ storedMarks = transaction.storedMarks;
27628
+ return transaction;
27629
+ }
27630
+ };
27631
+ }
27632
+ class CommandService {
27633
+ constructor(props) {
27634
+ __publicField$1(this, "editor");
27635
+ __publicField$1(this, "rawCommands");
27636
+ this.editor = props.editor;
27637
+ this.rawCommands = this.editor.extensionService.commands;
27638
+ }
27639
+ /**
27640
+ * Static method for creating a service.
27641
+ * @param args Arguments for the constructor.
27642
+ */
27643
+ static create(...args) {
27644
+ return new CommandService(...args);
27645
+ }
27646
+ /**
27647
+ * Get editor state.
27648
+ */
27649
+ get state() {
27650
+ return this.editor.state;
27651
+ }
27652
+ /**
27653
+ * Get all commands with wrapped command method.
27654
+ */
27655
+ get commands() {
27656
+ const { editor, state: state2 } = this;
27657
+ const { view } = editor;
27658
+ const { tr } = state2;
27659
+ const props = this.createProps(tr);
27660
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
27661
+ const method = (...args) => {
27662
+ const fn2 = command2(...args)(props);
27663
+ if (!tr.getMeta("preventDispatch")) {
27664
+ view.dispatch(tr);
27665
+ }
27666
+ return fn2;
27667
+ };
27668
+ return [name, method];
27669
+ });
27670
+ return Object.fromEntries(entries);
27671
+ }
27672
+ /**
27673
+ * Create a chain of commands to call multiple commands at once.
27674
+ */
27675
+ get chain() {
27676
+ return () => this.createChain();
27677
+ }
27678
+ /**
27679
+ * Check if a command or a chain of commands can be executed. Without executing it.
27680
+ */
27681
+ get can() {
27682
+ return () => this.createCan();
27683
+ }
27684
+ /**
27685
+ * Creates a chain of commands.
27686
+ * @param startTr Start transaction.
27687
+ * @param shouldDispatch Should dispatch or not.
27688
+ */
27689
+ createChain(startTr, shouldDispatch = true) {
27690
+ const { editor, state: state2, rawCommands } = this;
27691
+ const { view } = editor;
27692
+ const callbacks2 = [];
27693
+ const hasStartTr = !!startTr;
27694
+ const tr = startTr || state2.tr;
27695
+ const run2 = () => {
27696
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
27697
+ view.dispatch(tr);
27698
+ }
27699
+ return callbacks2.every((cb) => cb === true);
27700
+ };
27701
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
27702
+ const chainedCommand = (...args) => {
27703
+ const props = this.createProps(tr, shouldDispatch);
27704
+ const callback = command2(...args)(props);
27705
+ callbacks2.push(callback);
27706
+ return chain;
27707
+ };
27708
+ return [name, chainedCommand];
27709
+ });
27710
+ const chain = {
27711
+ ...Object.fromEntries(entries),
27712
+ run: run2
27713
+ };
27714
+ return chain;
27715
+ }
27716
+ /**
27717
+ * Creates a can check for commands.
27718
+ * @param startTr Start transaction.
27719
+ */
27720
+ createCan(startTr) {
27721
+ const { rawCommands, state: state2 } = this;
27722
+ const dispatch = false;
27723
+ const tr = startTr || state2.tr;
27724
+ const props = this.createProps(tr, dispatch);
27725
+ const commands2 = Object.fromEntries(
27726
+ Object.entries(rawCommands).map(([name, command2]) => {
27727
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
27728
+ })
27729
+ );
27730
+ return {
27731
+ ...commands2,
27732
+ chain: () => this.createChain(tr, dispatch)
27733
+ };
27734
+ }
27735
+ /**
27736
+ * Creates default props for the command method.
27737
+ * @param {*} tr Transaction.
27738
+ * @param {*} shouldDispatch Check if should dispatch.
27739
+ * @returns Object with props.
27740
+ */
27741
+ createProps(tr, shouldDispatch = true) {
27742
+ const { editor, state: state2, rawCommands } = this;
27743
+ const { view } = editor;
27744
+ const props = {
27745
+ tr,
27746
+ editor,
27747
+ view,
27748
+ state: chainableEditorState(tr, state2),
27749
+ dispatch: shouldDispatch ? () => void 0 : void 0,
27750
+ chain: () => this.createChain(tr, shouldDispatch),
27751
+ can: () => this.createCan(tr),
27752
+ get commands() {
27753
+ return Object.fromEntries(
27754
+ Object.entries(rawCommands).map(([name, command2]) => {
27755
+ return [name, (...args) => command2(...args)(props)];
27756
+ })
27757
+ );
27758
+ }
27759
+ };
27760
+ return props;
27761
+ }
27762
+ }
28181
27763
  const first = (commands2) => (props) => {
28182
27764
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
28183
27765
  for (let i = 0; i < items.length; i += 1) {
@@ -38414,6 +37996,409 @@ function isExtensionRulesEnabled(extension, enabled) {
38414
37996
  }
38415
37997
  return enabled;
38416
37998
  }
37999
+ function getHTMLFromFragment(fragment, schema) {
38000
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
38001
+ const temporaryDocument = document.implementation.createHTMLDocument();
38002
+ const container = temporaryDocument.createElement("div");
38003
+ container.appendChild(documentFragment);
38004
+ return container.innerHTML;
38005
+ }
38006
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
38007
+ let textBefore = "";
38008
+ const sliceEndPos = $from.parentOffset;
38009
+ $from.parent.nodesBetween(
38010
+ Math.max(0, sliceEndPos - maxMatch),
38011
+ sliceEndPos,
38012
+ (node2, pos, parent, index2) => {
38013
+ const chunk = node2.type.spec.toText?.({
38014
+ node: node2,
38015
+ pos,
38016
+ parent,
38017
+ index: index2
38018
+ }) || node2.textContent || "%leaf%";
38019
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
38020
+ }
38021
+ );
38022
+ return textBefore;
38023
+ };
38024
+ const handleDocxPaste = (html, editor, view, plugin2) => {
38025
+ const { converter } = editor;
38026
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
38027
+ let cleanedHtml = convertEmToPt(html);
38028
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
38029
+ const tempDiv = document.createElement("div");
38030
+ tempDiv.innerHTML = cleanedHtml;
38031
+ const paragraphs = tempDiv.querySelectorAll("p");
38032
+ paragraphs.forEach((p) => {
38033
+ const innerHTML3 = p.innerHTML;
38034
+ if (!innerHTML3.includes("<!--[if !supportLists]")) return;
38035
+ const styleAttr = p.getAttribute("style") || "";
38036
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
38037
+ if (msoListMatch) {
38038
+ const [, abstractId, level] = msoListMatch;
38039
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
38040
+ if (!listNumId) return;
38041
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
38042
+ const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
38043
+ p.setAttribute("data-num-id", listNumId);
38044
+ p.setAttribute("data-list-level", level - 1);
38045
+ p.setAttribute("data-start", start2);
38046
+ p.setAttribute("data-lvl-text", lvlText);
38047
+ p.setAttribute("data-num-fmt", numFmt);
38048
+ }
38049
+ extractAndRemoveConditionalPrefix(p);
38050
+ });
38051
+ transformWordLists(tempDiv);
38052
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
38053
+ tempDiv.remove();
38054
+ const { dispatch } = editor.view;
38055
+ if (!dispatch) return false;
38056
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
38057
+ return true;
38058
+ };
38059
+ const getLevelDefinition = (abstractDefinition, level) => {
38060
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
38061
+ const levelElement = abstractDefinition.elements.find((el) => {
38062
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
38063
+ });
38064
+ if (!levelElement) return null;
38065
+ const { elements } = levelElement;
38066
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
38067
+ const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
38068
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
38069
+ return { lvlText, start: start2, numFmt, elements };
38070
+ };
38071
+ const getListNumIdFromAbstract = (abstractId, editor) => {
38072
+ const { definitions } = editor?.converter?.numbering;
38073
+ if (!definitions) return null;
38074
+ const matchedDefinition = Object.values(definitions).find((def) => {
38075
+ return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
38076
+ });
38077
+ return matchedDefinition?.attributes?.["w:numId"];
38078
+ };
38079
+ const getListAbstractDefinition = (abstractId, editor) => {
38080
+ const { abstracts = {} } = editor?.converter?.numbering;
38081
+ return abstracts[abstractId] || null;
38082
+ };
38083
+ const transformWordLists = (container) => {
38084
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
38085
+ const listMap = /* @__PURE__ */ new Map();
38086
+ const listLevels = {};
38087
+ for (const p of paragraphs) {
38088
+ const listId = p.getAttribute("data-num-id");
38089
+ const level = parseInt(p.getAttribute("data-list-level"));
38090
+ const numFmt = p.getAttribute("data-num-fmt");
38091
+ const start2 = p.getAttribute("data-start");
38092
+ const lvlText = p.getAttribute("data-lvl-text");
38093
+ if (!listMap.has(listId)) listMap.set(listId, []);
38094
+ listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
38095
+ }
38096
+ for (const [id, items] of listMap.entries()) {
38097
+ if (!listLevels[id]) {
38098
+ listLevels[id] = {
38099
+ stack: [],
38100
+ counts: {},
38101
+ prevLevel: null
38102
+ };
38103
+ }
38104
+ const parentStack = [];
38105
+ items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
38106
+ const listLevel = generateListNestingPath(listLevels, id, level);
38107
+ const li = document.createElement("li");
38108
+ li.innerHTML = p.innerHTML;
38109
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
38110
+ li.setAttribute("data-num-id", id);
38111
+ li.setAttribute("data-lvl-text", lvlText);
38112
+ li.setAttribute("data-num-fmt", numFmt);
38113
+ if (p.hasAttribute("data-font-family")) {
38114
+ li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
38115
+ }
38116
+ if (p.hasAttribute("data-font-size")) {
38117
+ li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
38118
+ }
38119
+ const parentNode2 = p.parentNode;
38120
+ let listForLevel = parentStack[level];
38121
+ if (!listForLevel) {
38122
+ const newList = document.createElement("ol");
38123
+ newList.setAttribute("data-list-id", id);
38124
+ newList.level = level;
38125
+ if (level > 0) {
38126
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
38127
+ if (parentLi) parentLi.appendChild(newList);
38128
+ } else {
38129
+ parentNode2.insertBefore(newList, p);
38130
+ }
38131
+ parentStack[level] = newList;
38132
+ parentStack.length = level + 1;
38133
+ listForLevel = newList;
38134
+ }
38135
+ listForLevel.appendChild(li);
38136
+ p.remove();
38137
+ });
38138
+ }
38139
+ };
38140
+ function generateListNestingPath(listLevels, listId, currentLevel) {
38141
+ const levelState = listLevels[listId];
38142
+ if (!levelState.stack) levelState.stack = [];
38143
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
38144
+ if (levelState.prevLevel === null) {
38145
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
38146
+ } else {
38147
+ if (currentLevel > levelState.prevLevel) {
38148
+ levelState.stack.push(1);
38149
+ } else if (currentLevel === levelState.prevLevel) {
38150
+ levelState.stack[levelState.stack.length - 1]++;
38151
+ } else {
38152
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
38153
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
38154
+ }
38155
+ }
38156
+ levelState.prevLevel = currentLevel;
38157
+ return [...levelState.stack];
38158
+ }
38159
+ function extractAndRemoveConditionalPrefix(p) {
38160
+ const nodes = Array.from(p.childNodes);
38161
+ let fontFamily2 = null;
38162
+ let fontSize2 = null;
38163
+ let start2 = -1, end2 = -1;
38164
+ nodes.forEach((node2, index2) => {
38165
+ if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
38166
+ start2 = index2;
38167
+ }
38168
+ if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
38169
+ end2 = index2;
38170
+ }
38171
+ });
38172
+ if (start2 !== -1 && end2 !== -1) {
38173
+ for (let i = start2 + 1; i < end2; i++) {
38174
+ const node2 = nodes[i];
38175
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
38176
+ fontFamily2 = fontFamily2 || node2.style.fontFamily;
38177
+ fontSize2 = fontSize2 || node2.style.fontSize;
38178
+ }
38179
+ }
38180
+ for (let i = end2; i >= start2; i--) {
38181
+ p.removeChild(p.childNodes[i]);
38182
+ }
38183
+ if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
38184
+ if (fontSize2) p.setAttribute("data-font-size", fontSize2);
38185
+ }
38186
+ }
38187
+ class InputRule {
38188
+ constructor(config) {
38189
+ __publicField$1(this, "match");
38190
+ __publicField$1(this, "handler");
38191
+ this.match = config.match;
38192
+ this.handler = config.handler;
38193
+ }
38194
+ }
38195
+ const inputRuleMatcherHandler = (text, match) => {
38196
+ if (isRegExp(match)) {
38197
+ return match.exec(text);
38198
+ }
38199
+ const inputRuleMatch = match(text);
38200
+ if (!inputRuleMatch) {
38201
+ return null;
38202
+ }
38203
+ const result = [inputRuleMatch.text];
38204
+ result.index = inputRuleMatch.index;
38205
+ result.input = text;
38206
+ result.data = inputRuleMatch.data;
38207
+ if (inputRuleMatch.replaceWith) {
38208
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
38209
+ console.warn(
38210
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
38211
+ );
38212
+ }
38213
+ result.push(inputRuleMatch.replaceWith);
38214
+ }
38215
+ return result;
38216
+ };
38217
+ const run = (config) => {
38218
+ const {
38219
+ editor,
38220
+ from: from2,
38221
+ to,
38222
+ text,
38223
+ rules,
38224
+ plugin: plugin2
38225
+ } = config;
38226
+ const { view } = editor;
38227
+ if (view.composing) {
38228
+ return false;
38229
+ }
38230
+ const $from = view.state.doc.resolve(from2);
38231
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
38232
+ return false;
38233
+ }
38234
+ let matched = false;
38235
+ const textBefore = getTextContentFromNodes($from) + text;
38236
+ rules.forEach((rule) => {
38237
+ if (matched) {
38238
+ return;
38239
+ }
38240
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
38241
+ if (!match) {
38242
+ return;
38243
+ }
38244
+ const tr = view.state.tr;
38245
+ const state2 = chainableEditorState(tr, view.state);
38246
+ const range2 = {
38247
+ from: from2 - (match[0].length - text.length),
38248
+ to
38249
+ };
38250
+ const { commands: commands2, chain, can } = new CommandService({
38251
+ editor,
38252
+ state: state2
38253
+ });
38254
+ const handler = rule.handler({
38255
+ state: state2,
38256
+ range: range2,
38257
+ match,
38258
+ commands: commands2,
38259
+ chain,
38260
+ can
38261
+ });
38262
+ if (handler === null || !tr.steps.length) {
38263
+ return;
38264
+ }
38265
+ tr.setMeta(plugin2, {
38266
+ transform: tr,
38267
+ from: from2,
38268
+ to,
38269
+ text
38270
+ });
38271
+ view.dispatch(tr);
38272
+ matched = true;
38273
+ });
38274
+ return matched;
38275
+ };
38276
+ const inputRulesPlugin = ({ editor, rules }) => {
38277
+ const plugin2 = new Plugin({
38278
+ key: new PluginKey("inputRulesPlugin"),
38279
+ state: {
38280
+ init() {
38281
+ return null;
38282
+ },
38283
+ apply(tr, prev, state2) {
38284
+ const stored = tr.getMeta(plugin2);
38285
+ if (stored) {
38286
+ return stored;
38287
+ }
38288
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
38289
+ const isSimulatedInput = !!simulatedInputMeta;
38290
+ if (isSimulatedInput) {
38291
+ setTimeout(() => {
38292
+ let { text } = simulatedInputMeta;
38293
+ if (typeof text !== "string") {
38294
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
38295
+ }
38296
+ const { from: from2 } = simulatedInputMeta;
38297
+ const to = from2 + text.length;
38298
+ run({
38299
+ editor,
38300
+ from: from2,
38301
+ to,
38302
+ text,
38303
+ rules,
38304
+ plugin: plugin2
38305
+ });
38306
+ });
38307
+ }
38308
+ return tr.selectionSet || tr.docChanged ? null : prev;
38309
+ }
38310
+ },
38311
+ props: {
38312
+ handleTextInput(view, from2, to, text) {
38313
+ return run({
38314
+ editor,
38315
+ from: from2,
38316
+ to,
38317
+ text,
38318
+ rules,
38319
+ plugin: plugin2
38320
+ });
38321
+ },
38322
+ // add support for input rules to trigger on enter
38323
+ // this is useful for example for code blocks
38324
+ handleKeyDown(view, event) {
38325
+ if (event.key !== "Enter") {
38326
+ return false;
38327
+ }
38328
+ const { $cursor } = view.state.selection;
38329
+ if ($cursor) {
38330
+ return run({
38331
+ editor,
38332
+ from: $cursor.pos,
38333
+ to: $cursor.pos,
38334
+ text: "\n",
38335
+ rules,
38336
+ plugin: plugin2
38337
+ });
38338
+ }
38339
+ return false;
38340
+ },
38341
+ // Paste handler
38342
+ handlePaste(view, event, slice2) {
38343
+ const clipboard = event.clipboardData;
38344
+ const html = clipboard.getData("text/html");
38345
+ clipboard.getData("text/plain");
38346
+ const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
38347
+ if (fieldAnnotationContent.length) {
38348
+ return false;
38349
+ }
38350
+ let source;
38351
+ if (!html) {
38352
+ source = "plain-text";
38353
+ } else if (isWordHtml(html)) {
38354
+ source = "word-html";
38355
+ } else {
38356
+ source = "browser-html";
38357
+ }
38358
+ switch (source) {
38359
+ case "plain-text":
38360
+ break;
38361
+ case "word-html":
38362
+ if (editor.options.mode === "docx") {
38363
+ return handleDocxPaste(html, editor, view, plugin2);
38364
+ }
38365
+ case "browser-html":
38366
+ return handleHtmlPaste$1(html, editor);
38367
+ }
38368
+ return false;
38369
+ }
38370
+ },
38371
+ isInputRules: true
38372
+ });
38373
+ return plugin2;
38374
+ };
38375
+ function isWordHtml(html) {
38376
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
38377
+ }
38378
+ const handleHtmlPaste$1 = (html, editor, plugin2) => {
38379
+ const cleanedHtml = convertEmToPt(html);
38380
+ const tempDiv = document.createElement("div");
38381
+ tempDiv.innerHTML = cleanedHtml;
38382
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
38383
+ tempDiv.remove();
38384
+ const { dispatch } = editor.view;
38385
+ if (!dispatch) return false;
38386
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
38387
+ return true;
38388
+ };
38389
+ const convertEmToPt = (html) => {
38390
+ return html.replace(
38391
+ /font-size\s*:\s*([\d.]+)em/gi,
38392
+ (_, emValue) => {
38393
+ const em = parseFloat(emValue);
38394
+ const pt = Math.round(em * 12 * 100) / 100;
38395
+ return `font-size: ${pt}pt`;
38396
+ }
38397
+ );
38398
+ };
38399
+ function cleanHtmlUnnecessaryTags(html) {
38400
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
38401
+ }
38417
38402
  const _ExtensionService = class _ExtensionService2 {
38418
38403
  constructor(extensions, userExtensions, editor) {
38419
38404
  __privateAdd$1(this, _ExtensionService_instances);
@@ -39284,16 +39269,14 @@ const broadcastEditorEvents = (editor, sectionEditor) => {
39284
39269
  });
39285
39270
  });
39286
39271
  };
39287
- const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
39272
+ const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
39288
39273
  editor.converter.headerEditors.forEach((item) => {
39289
39274
  item.editor.setEditable(isEditMode, false);
39290
39275
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
39291
- item.editor.view.dom.setAttribute("documentmode", documentMode);
39292
39276
  });
39293
39277
  editor.converter.footerEditors.forEach((item) => {
39294
39278
  item.editor.setEditable(isEditMode, false);
39295
39279
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
39296
- item.editor.view.dom.setAttribute("documentmode", documentMode);
39297
39280
  });
39298
39281
  if (isEditMode) {
39299
39282
  const pm = document.querySelector(".ProseMirror");
@@ -40374,19 +40357,6 @@ const deleteHeaderFooterFieldAnnotations = ({ editor, fieldIdOrArray }) => {
40374
40357
  );
40375
40358
  });
40376
40359
  };
40377
- const resetHeaderFooterFieldAnnotations = ({ editor }) => {
40378
- if (!editor) return;
40379
- const sectionEditors = getAllHeaderFooterEditors(editor);
40380
- sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
40381
- sectionEditor.commands.resetFieldAnnotations();
40382
- onHeaderFooterDataUpdate(
40383
- { editor: sectionEditor },
40384
- editor,
40385
- sectionId,
40386
- type2
40387
- );
40388
- });
40389
- };
40390
40360
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
40391
40361
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
40392
40362
  const { doc: doc2 } = editor.state;
@@ -40457,7 +40427,6 @@ const AnnotatorHelpers = {
40457
40427
  getAllHeaderFooterEditors,
40458
40428
  updateHeaderFooterFieldAnnotations,
40459
40429
  deleteHeaderFooterFieldAnnotations,
40460
- resetHeaderFooterFieldAnnotations,
40461
40430
  cleanUpListsWithAnnotations
40462
40431
  };
40463
40432
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -40826,12 +40795,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40826
40795
  this.commands.toggleTrackChangesShowOriginal();
40827
40796
  this.setEditable(false, false);
40828
40797
  this.setOptions({ documentMode: "viewing" });
40829
- toggleHeaderFooterEditMode({
40830
- editor: this,
40831
- focusedSectionEditor: null,
40832
- isEditMode: false,
40833
- documentMode: cleanedMode
40834
- });
40798
+ toggleHeaderFooterEditMode(this, null, false);
40835
40799
  } else if (cleanedMode === "suggesting") {
40836
40800
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
40837
40801
  this.commands.disableTrackChangesShowOriginal();
@@ -40844,12 +40808,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40844
40808
  this.commands.disableTrackChanges();
40845
40809
  this.setEditable(true, false);
40846
40810
  this.setOptions({ documentMode: "editing" });
40847
- toggleHeaderFooterEditMode({
40848
- editor: this,
40849
- focusedSectionEditor: null,
40850
- isEditMode: false,
40851
- documentMode: cleanedMode
40852
- });
40811
+ toggleHeaderFooterEditMode(this, null, false);
40853
40812
  }
40854
40813
  }
40855
40814
  /**
@@ -41301,7 +41260,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41301
41260
  * @returns {Object | void} Migration results
41302
41261
  */
41303
41262
  processCollaborationMigrations() {
41304
- console.debug("[checkVersionMigrations] Current editor version", "0.13.3-next.8");
41263
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.3");
41305
41264
  if (!this.options.ydoc) return;
41306
41265
  const metaMap = this.options.ydoc.getMap("meta");
41307
41266
  let docVersion = metaMap.get("version");
@@ -41692,12 +41651,7 @@ createView_fn = function() {
41692
41651
  event.stopPropagation();
41693
41652
  if (!this.options.editable) {
41694
41653
  this.setEditable(true, false);
41695
- toggleHeaderFooterEditMode({
41696
- editor: this,
41697
- focusedSectionEditor: null,
41698
- isEditMode: false,
41699
- documentMode: this.options.documentMode
41700
- });
41654
+ toggleHeaderFooterEditMode(this, null, false);
41701
41655
  const pm = document.querySelector(".ProseMirror");
41702
41656
  pm.classList.remove("header-footer-edit");
41703
41657
  pm.setAttribute("aria-readonly", false);
@@ -44517,16 +44471,7 @@ const HardBreak = Node$1.create({
44517
44471
  };
44518
44472
  },
44519
44473
  parseDOM() {
44520
- return [{
44521
- tag: 'span[linebreaktype="page"]',
44522
- getAttrs: (dom) => {
44523
- if (!(dom instanceof HTMLElement)) return false;
44524
- return {
44525
- pageBreakSource: dom.getAttribute("pagebreaksource") || null,
44526
- pageBreakType: dom.getAttribute("linebreaktype") || null
44527
- };
44528
- }
44529
- }];
44474
+ return [{ tag: "span" }];
44530
44475
  },
44531
44476
  renderDOM({ htmlAttributes }) {
44532
44477
  return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -44956,13 +44901,13 @@ function tableNodeTypes(schema) {
44956
44901
  return result;
44957
44902
  }
44958
44903
  var tableEditingKey = new PluginKey("selectingCells");
44959
- function cellAround$1($pos) {
44904
+ function cellAround($pos) {
44960
44905
  for (let d = $pos.depth - 1; d > 0; d--)
44961
44906
  if ($pos.node(d).type.spec.tableRole == "row")
44962
44907
  return $pos.node(0).resolve($pos.before(d + 1));
44963
44908
  return null;
44964
44909
  }
44965
- function cellWrapping$1($pos) {
44910
+ function cellWrapping($pos) {
44966
44911
  for (let d = $pos.depth; d > 0; d--) {
44967
44912
  const role = $pos.node(d).type.spec.tableRole;
44968
44913
  if (role === "cell" || role === "header_cell") return $pos.node(d);
@@ -44982,7 +44927,7 @@ function selectionCell(state2) {
44982
44927
  } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
44983
44928
  return sel.$anchor;
44984
44929
  }
44985
- const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
44930
+ const $cell = cellAround(sel.$head) || cellNear(sel.$head);
44986
44931
  if ($cell) {
44987
44932
  return $cell;
44988
44933
  }
@@ -45721,22 +45666,22 @@ function mergeCells(state2, dispatch) {
45721
45666
  }
45722
45667
  return true;
45723
45668
  }
45724
- function splitCell$1(state2, dispatch) {
45669
+ function splitCell(state2, dispatch) {
45725
45670
  const nodeTypes = tableNodeTypes(state2.schema);
45726
45671
  return splitCellWithType(({ node: node2 }) => {
45727
45672
  return nodeTypes[node2.type.spec.tableRole];
45728
45673
  })(state2, dispatch);
45729
45674
  }
45730
- function splitCellWithType(getCellType2) {
45675
+ function splitCellWithType(getCellType) {
45731
45676
  return (state2, dispatch) => {
45732
45677
  var _a;
45733
45678
  const sel = state2.selection;
45734
45679
  let cellNode;
45735
45680
  let cellPos;
45736
45681
  if (!(sel instanceof CellSelection)) {
45737
- cellNode = cellWrapping$1(sel.$from);
45682
+ cellNode = cellWrapping(sel.$from);
45738
45683
  if (!cellNode) return false;
45739
- cellPos = (_a = cellAround$1(sel.$from)) == null ? void 0 : _a.pos;
45684
+ cellPos = (_a = cellAround(sel.$from)) == null ? void 0 : _a.pos;
45740
45685
  } else {
45741
45686
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
45742
45687
  cellNode = sel.$anchorCell.nodeAfter;
@@ -45770,13 +45715,13 @@ function splitCellWithType(getCellType2) {
45770
45715
  if (col == rect.left && row == rect.top) continue;
45771
45716
  tr.insert(
45772
45717
  lastCell = tr.mapping.map(pos + rect.tableStart, 1),
45773
- getCellType2({ node: cellNode, row, col }).createAndFill(attrs[i])
45718
+ getCellType({ node: cellNode, row, col }).createAndFill(attrs[i])
45774
45719
  );
45775
45720
  }
45776
45721
  }
45777
45722
  tr.setNodeMarkup(
45778
45723
  cellPos,
45779
- getCellType2({ node: cellNode, row: rect.top, col: rect.left }),
45724
+ getCellType({ node: cellNode, row: rect.top, col: rect.left }),
45780
45725
  attrs[0]
45781
45726
  );
45782
45727
  if (sel instanceof CellSelection)
@@ -46309,7 +46254,7 @@ function shiftArrow(axis, dir) {
46309
46254
  };
46310
46255
  }
46311
46256
  function handleTripleClick(view, pos) {
46312
- const doc2 = view.state.doc, $cell = cellAround$1(doc2.resolve(pos));
46257
+ const doc2 = view.state.doc, $cell = cellAround(doc2.resolve(pos));
46313
46258
  if (!$cell) return false;
46314
46259
  view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
46315
46260
  return true;
@@ -46361,7 +46306,7 @@ function handleMouseDown(view, startEvent) {
46361
46306
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
46362
46307
  setCellSelection(view.state.selection.$anchorCell, startEvent);
46363
46308
  startEvent.preventDefault();
46364
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
46309
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
46365
46310
  setCellSelection($anchor, startEvent);
46366
46311
  startEvent.preventDefault();
46367
46312
  } else if (!startDOMCell) {
@@ -46432,7 +46377,7 @@ function cellUnderMouse(view, event) {
46432
46377
  top: event.clientY
46433
46378
  });
46434
46379
  if (!mousePos) return null;
46435
- return mousePos ? cellAround$1(view.state.doc.resolve(mousePos.pos)) : null;
46380
+ return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
46436
46381
  }
46437
46382
  var TableView = class {
46438
46383
  constructor(node2, defaultCellMinWidth) {
@@ -46697,7 +46642,7 @@ function edgeCell(view, event, side, handleWidth) {
46697
46642
  });
46698
46643
  if (!found2) return -1;
46699
46644
  const { pos } = found2;
46700
- const $cell = cellAround$1(view.state.doc.resolve(pos));
46645
+ const $cell = cellAround(view.state.doc.resolve(pos));
46701
46646
  if (!$cell) return -1;
46702
46647
  if (side == "right") return $cell.pos;
46703
46648
  const map22 = TableMap.get($cell.node(-1)), start2 = $cell.start(-1);
@@ -46859,19 +46804,6 @@ const createCellBorders = ({
46859
46804
  right: { size: size2, color }
46860
46805
  };
46861
46806
  };
46862
- function cellAround($pos) {
46863
- for (let d = $pos.depth - 1; d > 0; d--)
46864
- if ($pos.node(d).type.spec.tableRole == "row")
46865
- return $pos.node(0).resolve($pos.before(d + 1));
46866
- return null;
46867
- }
46868
- function cellWrapping($pos) {
46869
- for (let d = $pos.depth; d > 0; d--) {
46870
- const role = $pos.node(d).type.spec.tableRole;
46871
- if (role === "cell" || role === "header_cell") return $pos.node(d);
46872
- }
46873
- return null;
46874
- }
46875
46807
  const Table = Node$1.create({
46876
46808
  name: "table",
46877
46809
  content: "tableRow+",
@@ -46969,7 +46901,9 @@ const Table = Node$1.create({
46969
46901
  addCommands() {
46970
46902
  return {
46971
46903
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = false } = {}) => ({ tr, dispatch, editor }) => {
46972
- const node2 = createTable(editor.schema, rows, cols, withHeaderRow);
46904
+ const zeroWidthText = editor.schema.text("​");
46905
+ const emptyPar = getNodeType("paragraph", editor.schema).create(null, zeroWidthText);
46906
+ const node2 = createTable(editor.schema, rows, cols, withHeaderRow, emptyPar);
46973
46907
  if (dispatch) {
46974
46908
  const offset2 = tr.selection.from + 1;
46975
46909
  tr.replaceSelectionWith(node2).scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(offset2)));
@@ -47000,81 +46934,8 @@ const Table = Node$1.create({
47000
46934
  mergeCells: () => ({ state: state2, dispatch }) => {
47001
46935
  return mergeCells(state2, dispatch);
47002
46936
  },
47003
- splitCell: () => ({ state: state2, dispatch, commands: commands2 }) => {
47004
- if (splitCell$1(state2, dispatch)) {
47005
- return true;
47006
- }
47007
- return commands2.splitSingleCell();
47008
- },
47009
- splitSingleCell: () => ({ state: state2, dispatch, tr }) => {
47010
- const sel = state2.selection;
47011
- let cellNode;
47012
- let cellPos;
47013
- if (!(sel instanceof CellSelection)) {
47014
- cellNode = cellWrapping(sel.$from);
47015
- if (!cellNode) return false;
47016
- cellPos = cellAround(sel.$from)?.pos;
47017
- } else {
47018
- if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
47019
- cellNode = sel.$anchorCell.nodeAfter;
47020
- cellPos = sel.$anchorCell.pos;
47021
- }
47022
- if (cellNode == null || cellPos == null) {
47023
- return false;
47024
- }
47025
- if (cellNode.attrs.colspan != 1 || cellNode.attrs.rowspan != 1) {
47026
- return false;
47027
- }
47028
- if (dispatch) {
47029
- let rect = selectedRect(state2);
47030
- let currentRow = rect.top;
47031
- let currentCol = rect.left;
47032
- let baseAttrs = { ...cellNode.attrs };
47033
- let currentColWidth2 = baseAttrs.colwidth;
47034
- let newCellWidth = null;
47035
- if (currentColWidth2 && currentColWidth2[0]) {
47036
- newCellWidth = Math.ceil(currentColWidth2[0] / 2);
47037
- }
47038
- if (newCellWidth) {
47039
- tr.setNodeMarkup(tr.mapping.map(cellPos, 1), null, { ...baseAttrs, colwidth: [newCellWidth] });
47040
- }
47041
- const newCellAttrs = { ...baseAttrs, colwidth: newCellWidth ? [newCellWidth] : null };
47042
- const newCell = getCellType({ node: cellNode, state: state2 }).createAndFill(newCellAttrs);
47043
- tr.insert(tr.mapping.map(cellPos + cellNode.nodeSize, 1), newCell);
47044
- for (let row = 0; row < rect.map.height; row++) {
47045
- if (row === currentRow) continue;
47046
- let rowCells = /* @__PURE__ */ new Set();
47047
- for (let col = 0; col < rect.map.width; col++) {
47048
- let cellIndex = rect.map.map[row * rect.map.width + col];
47049
- if (cellIndex != null) rowCells.add(cellIndex);
47050
- }
47051
- [...rowCells].forEach((cellIndex) => {
47052
- let cellRect = rect.map.findCell(cellIndex);
47053
- if (cellRect.left <= currentCol && cellRect.right > currentCol) {
47054
- let cellPos2 = tr.mapping.map(rect.tableStart + cellIndex, 1);
47055
- let cell = tr.doc.nodeAt(cellPos2);
47056
- if (cell) {
47057
- let newColspan = (cell.attrs.colspan || 1) + 1;
47058
- let updatedColwidth = cell.attrs.colwidth;
47059
- if (updatedColwidth && newCellWidth) {
47060
- let originalColIndex = currentCol - cellRect.left;
47061
- updatedColwidth = [
47062
- ...updatedColwidth.slice(0, originalColIndex),
47063
- newCellWidth,
47064
- // current cell width
47065
- newCellWidth,
47066
- // new cell width
47067
- ...updatedColwidth.slice(originalColIndex + 1)
47068
- ];
47069
- }
47070
- let cellAttrs = { ...cell.attrs, colspan: newColspan, colwidth: updatedColwidth };
47071
- tr.setNodeMarkup(cellPos2, null, cellAttrs);
47072
- }
47073
- }
47074
- });
47075
- }
47076
- }
47077
- return true;
46937
+ splitCell: () => ({ state: state2, dispatch }) => {
46938
+ return splitCell(state2, dispatch);
47078
46939
  },
47079
46940
  mergeOrSplit: () => ({ state: state2, dispatch }) => {
47080
46941
  if (mergeCells(state2, dispatch)) {
@@ -47196,10 +47057,6 @@ const Table = Node$1.create({
47196
47057
  };
47197
47058
  }
47198
47059
  });
47199
- function getCellType({ node: node2, state: state2 }) {
47200
- const nodeTypes = tableNodeTypes(state2.schema);
47201
- return nodeTypes[node2.type.spec.tableRole];
47202
- }
47203
47060
  const TableHeader = Node$1.create({
47204
47061
  name: "tableHeader",
47205
47062
  content: "block+",
@@ -48022,18 +47879,8 @@ const FieldAnnotation = Node$1.create({
48022
47879
  };
48023
47880
  }
48024
47881
  },
48025
- defaultDisplayLabel: {
48026
- default: "",
48027
- parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
48028
- renderDOM: (attrs) => {
48029
- if (!attrs.defaultDisplayLabel) return {};
48030
- return {
48031
- "data-default-display-label": attrs.defaultDisplayLabel
48032
- };
48033
- }
48034
- },
48035
47882
  displayLabel: {
48036
- default: "",
47883
+ default: "Text field",
48037
47884
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
48038
47885
  renderDOM: (attrs) => {
48039
47886
  if (!attrs.displayLabel) return {};
@@ -48349,7 +48196,6 @@ const FieldAnnotation = Node$1.create({
48349
48196
  return renderer();
48350
48197
  },
48351
48198
  addCommands() {
48352
- const annotationTypes = this.options.types;
48353
48199
  return {
48354
48200
  /**
48355
48201
  * Add field annotation.
@@ -48371,12 +48217,7 @@ const FieldAnnotation = Node$1.create({
48371
48217
  let currentMarks = $pos.marks();
48372
48218
  currentMarks = currentMarks.length ? [...currentMarks] : null;
48373
48219
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
48374
- let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
48375
- let node2 = schema.nodes[this.name].create({
48376
- ...attrs,
48377
- ...formatAttrs,
48378
- defaultDisplayLabel
48379
- }, null, null);
48220
+ let node2 = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
48380
48221
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
48381
48222
  if (editorFocus) {
48382
48223
  this.editor.view.focus();
@@ -48384,9 +48225,9 @@ const FieldAnnotation = Node$1.create({
48384
48225
  }
48385
48226
  return true;
48386
48227
  },
48387
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
48228
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
48388
48229
  const { from: from2 } = state2.selection;
48389
- return commands2.addFieldAnnotation(from2, attrs, editorFocus);
48230
+ commands2.addFieldAnnotation(from2, attrs, editorFocus);
48390
48231
  },
48391
48232
  /**
48392
48233
  * Replace field annotation.
@@ -48396,113 +48237,24 @@ const FieldAnnotation = Node$1.create({
48396
48237
  * from: 20,
48397
48238
  * to: 45,
48398
48239
  * attrs: {
48399
- * fieldType: 'TEXTINPUT'
48400
- * fieldColor: '#980043'
48240
+ * fieldType: 'TEXTINPUT'
48241
+ * fieldColor: '#980043'
48401
48242
  * }
48402
48243
  * ])
48403
48244
  */
48404
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
48245
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
48405
48246
  if (!dispatch) return true;
48247
+ tr.setMeta("fieldAnnotationReplace", true);
48406
48248
  fieldsArray.forEach((annotation) => {
48407
48249
  let { from: from2, to, attrs } = annotation;
48408
48250
  let { schema } = editor;
48409
48251
  let newPosFrom = tr.mapping.map(from2);
48410
48252
  let newPosTo = tr.mapping.map(to);
48411
- let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
48412
- let node2 = schema.nodes[this.name].create({
48413
- ...attrs,
48414
- defaultDisplayLabel
48415
- }, null, null);
48253
+ let node2 = schema.nodes[this.name].create({ ...attrs }, null, null);
48416
48254
  tr.replaceWith(newPosFrom, newPosTo, node2);
48417
48255
  });
48418
48256
  return true;
48419
48257
  },
48420
- /**
48421
- * Replace annotations with a label (as text node) in selection.
48422
- * @param options Additional options.
48423
- * @example
48424
- * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
48425
- */
48426
- replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
48427
- return commands2.replaceFieldAnnotationsWithLabel(null, {
48428
- ...options2,
48429
- isInSelection: true
48430
- });
48431
- },
48432
- /**
48433
- * Replace annotations with a label (as text node).
48434
- * @param fieldIdOrArray The field ID or array of field IDs.
48435
- * @param options.isInSelection Find in selection instead of field IDs.
48436
- * @param options.addToHistory Add to history or not.
48437
- * @param options.types Annotation types to replace.
48438
- * @example
48439
- * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
48440
- */
48441
- replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
48442
- isInSelection = false,
48443
- addToHistory = false,
48444
- types: types2 = annotationTypes
48445
- } = {}) => ({ dispatch, state: state2, tr }) => {
48446
- let { from: from2, to } = state2.selection;
48447
- let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
48448
- annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
48449
- if (!annotations.length) {
48450
- return true;
48451
- }
48452
- if (!addToHistory) {
48453
- tr.setMeta("addToHistory", false);
48454
- }
48455
- if (dispatch) {
48456
- annotations.forEach((annotation) => {
48457
- let { pos, node: node2 } = annotation;
48458
- let newPosFrom = tr.mapping.map(pos);
48459
- let newPosTo = tr.mapping.map(pos + node2.nodeSize);
48460
- let currentNode = tr.doc.nodeAt(newPosFrom);
48461
- let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
48462
- let $newPosFrom = tr.doc.resolve(newPosFrom);
48463
- let currentMarks = $newPosFrom.marks();
48464
- currentMarks = currentMarks.length ? [...currentMarks] : null;
48465
- if (nodeEqual) {
48466
- let label = node2.attrs.displayLabel || " ";
48467
- let textNode = state2.schema.text(label, currentMarks);
48468
- tr.replaceWith(newPosFrom, newPosTo, textNode);
48469
- }
48470
- });
48471
- }
48472
- return true;
48473
- },
48474
- /**
48475
- * Resets all annotations to default values.
48476
- * @example
48477
- * editor.commands.resetFieldAnnotations()
48478
- */
48479
- resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
48480
- let annotations = getAllFieldAnnotations(state2);
48481
- if (!annotations.length) {
48482
- return true;
48483
- }
48484
- tr.setMeta("fieldAnnotationUpdate", true);
48485
- if (dispatch) {
48486
- annotations.forEach(({ pos, node: node2 }) => {
48487
- let newPos = tr.mapping.map(pos);
48488
- let currentNode = tr.doc.nodeAt(newPos);
48489
- let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
48490
- if (nodeEqual) {
48491
- let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
48492
- tr.setNodeMarkup(newPos, void 0, {
48493
- ...node2.attrs,
48494
- // reset displayLabel to default.
48495
- displayLabel,
48496
- // reset attrs ​​for specific types.
48497
- imageSrc: null,
48498
- rawHtml: null,
48499
- linkUrl: null
48500
- });
48501
- }
48502
- });
48503
- }
48504
- return true;
48505
- },
48506
48258
  /**
48507
48259
  * Update annotations associated with a field.
48508
48260
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -54908,12 +54660,7 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
54908
54660
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
54909
54661
  if (editor.options.documentMode !== "editing") return;
54910
54662
  editor.setEditable(false, false);
54911
- toggleHeaderFooterEditMode({
54912
- editor,
54913
- focusedSectionEditor: currentFocusedSectionEditor,
54914
- isEditMode: true,
54915
- documentMode: editor.options.documentMode
54916
- });
54663
+ toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
54917
54664
  };
54918
54665
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
54919
54666
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -55493,7 +55240,6 @@ const nodeResizer = (nodeNames = ["image"]) => {
55493
55240
  if (tr.getMeta(NodeResizerKey)) {
55494
55241
  return oldState;
55495
55242
  }
55496
- if (typeof document === "undefined") return oldState;
55497
55243
  const decorations = [];
55498
55244
  const { selection } = newState;
55499
55245
  if (nodeNames.includes(selection.node?.type.name)) {