@harbour-enterprises/superdoc 0.13.2-rev1 → 0.13.2-rev10

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 (54) hide show
  1. package/dist/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-CHxWXmuK.cjs} +1 -1
  2. package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-KKY27oz-.es.js} +1 -1
  3. package/dist/chunks/{index-KzH9VKHh.es.js → index-BqLFjUHn.es.js} +2 -2
  4. package/dist/chunks/{index-B0t3i_io.cjs → index-CweAXNfB.cjs} +2 -2
  5. package/dist/chunks/{index-D_HUrFWV.es.js → index-DS3W0eVB.es.js} +4 -4
  6. package/dist/chunks/{index-Bk160jQ2.cjs → index-kOMfCfBT.cjs} +4 -4
  7. package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-9bCX1h2W.cjs} +1 -1
  8. package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-Cl3s9njw.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es--NMYzIh3.cjs → super-editor.es-Bdu65rjC.cjs} +1090 -816
  10. package/dist/chunks/{super-editor.es-DyTkLKR1.es.js → super-editor.es-BwWbNxcS.es.js} +1090 -816
  11. package/dist/chunks/{url-CWyTQ-Xy.cjs → url-B8LY3nwf.cjs} +2 -2
  12. package/dist/chunks/{url-DsBQArCl.es.js → url-Bq00tGvm.es.js} +2 -2
  13. package/dist/chunks/{vue-Bi1uWinj.es.js → vue-BBJVqxjL.es.js} +10 -3
  14. package/dist/chunks/{vue-HIY1g7dm.cjs → vue-BBjMeYfo.cjs} +10 -3
  15. package/dist/chunks/{xml-js-CdiD26MJ.es.js → xml-js-1F0lia4t.es.js} +2 -2
  16. package/dist/chunks/{xml-js-Bu1ZZzmb.cjs → xml-js-BuAdLsHD.cjs} +2 -2
  17. package/dist/style.css +2 -2
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-CJ9kHtZx.js → converter-lPrQA7b1.js} +632 -52
  20. package/dist/super-editor/chunks/{docx-zipper-scQqOWXA.js → docx-zipper-HvG9XskR.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-DM6yaxu_.js → editor-DbkiH8Up.js} +386 -685
  22. package/dist/super-editor/chunks/{toolbar-CIHbdcnv.js → toolbar-JdrfUR1G.js} +2 -3
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +7 -0
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +7 -0
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
  31. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
  32. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  33. package/dist/super-editor/docx-zipper.es.js +2 -2
  34. package/dist/super-editor/editor.es.js +3 -3
  35. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  39. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  41. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  42. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  43. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/style.css +2 -2
  46. package/dist/super-editor/super-editor.es.js +7 -7
  47. package/dist/super-editor/toolbar.es.js +2 -2
  48. package/dist/super-editor.cjs +2 -2
  49. package/dist/super-editor.es.js +2 -2
  50. package/dist/superdoc.cjs +8 -9
  51. package/dist/superdoc.es.js +9 -10
  52. package/dist/superdoc.umd.js +1101 -821
  53. package/dist/superdoc.umd.js.map +1 -1
  54. package/package.json +1 -1
@@ -10960,7 +10960,7 @@ class NodeRange {
10960
10960
  }
10961
10961
  }
10962
10962
  const emptyAttrs = /* @__PURE__ */ Object.create(null);
10963
- class Node {
10963
+ let Node$1 = class Node2 {
10964
10964
  /**
10965
10965
  @internal
10966
10966
  */
@@ -11090,14 +11090,14 @@ class Node {
11090
11090
  copy(content = null) {
11091
11091
  if (content == this.content)
11092
11092
  return this;
11093
- return new Node(this.type, this.attrs, content, this.marks);
11093
+ return new Node2(this.type, this.attrs, content, this.marks);
11094
11094
  }
11095
11095
  /**
11096
11096
  Create a copy of this node, with the given set of marks instead
11097
11097
  of the node's own marks.
11098
11098
  */
11099
11099
  mark(marks) {
11100
- return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks);
11100
+ return marks == this.marks ? this : new Node2(this.type, this.attrs, this.content, marks);
11101
11101
  }
11102
11102
  /**
11103
11103
  Create a copy of this node with only the content between the
@@ -11360,9 +11360,9 @@ class Node {
11360
11360
  node2.type.checkAttrs(node2.attrs);
11361
11361
  return node2;
11362
11362
  }
11363
- }
11364
- Node.prototype.text = void 0;
11365
- class TextNode extends Node {
11363
+ };
11364
+ Node$1.prototype.text = void 0;
11365
+ class TextNode extends Node$1 {
11366
11366
  /**
11367
11367
  @internal
11368
11368
  */
@@ -11949,7 +11949,7 @@ class NodeType {
11949
11949
  create(attrs = null, content, marks) {
11950
11950
  if (this.isText)
11951
11951
  throw new Error("NodeType.create can't construct text nodes");
11952
- return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
11952
+ return new Node$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
11953
11953
  }
11954
11954
  /**
11955
11955
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
@@ -11959,7 +11959,7 @@ class NodeType {
11959
11959
  createChecked(attrs = null, content, marks) {
11960
11960
  content = Fragment.from(content);
11961
11961
  this.checkContent(content);
11962
- return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
11962
+ return new Node$1(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
11963
11963
  }
11964
11964
  /**
11965
11965
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
@@ -11982,7 +11982,7 @@ class NodeType {
11982
11982
  let after = matched && matched.fillBefore(Fragment.empty, true);
11983
11983
  if (!after)
11984
11984
  return null;
11985
- return new Node(this, attrs, content.append(after), Mark.setFrom(marks));
11985
+ return new Node$1(this, attrs, content.append(after), Mark.setFrom(marks));
11986
11986
  }
11987
11987
  /**
11988
11988
  Returns true if the given fragment is valid content for this node
@@ -12219,7 +12219,7 @@ let Schema$1 = class Schema {
12219
12219
  bound.
12220
12220
  */
12221
12221
  nodeFromJSON(json) {
12222
- return Node.fromJSON(this, json);
12222
+ return Node$1.fromJSON(this, json);
12223
12223
  }
12224
12224
  /**
12225
12225
  Deserialize a mark from its JSON representation. This method is
@@ -15779,7 +15779,7 @@ class EditorState {
15779
15779
  let instance = new EditorState($config);
15780
15780
  $config.fields.forEach((field) => {
15781
15781
  if (field.name == "doc") {
15782
- instance.doc = Node.fromJSON(config.schema, json.doc);
15782
+ instance.doc = Node$1.fromJSON(config.schema, json.doc);
15783
15783
  } else if (field.name == "selection") {
15784
15784
  instance.selection = Selection.fromJSON(instance.doc, json.selection);
15785
15785
  } else if (field.name == "storedMarks") {
@@ -18840,6 +18840,583 @@ const createColGroup = (node2, cellMinWidth, overrideCol, overrideValue) => {
18840
18840
  colgroupValues
18841
18841
  };
18842
18842
  };
18843
+ function chainableEditorState(transaction, state2) {
18844
+ let { selection, doc: doc2, storedMarks } = transaction;
18845
+ return {
18846
+ ...state2,
18847
+ apply: state2.apply.bind(state2),
18848
+ applyTransaction: state2.applyTransaction.bind(state2),
18849
+ plugins: state2.plugins,
18850
+ schema: state2.schema,
18851
+ reconfigure: state2.reconfigure.bind(state2),
18852
+ toJSON: state2.toJSON.bind(state2),
18853
+ get storedMarks() {
18854
+ return storedMarks;
18855
+ },
18856
+ get selection() {
18857
+ return selection;
18858
+ },
18859
+ get doc() {
18860
+ return doc2;
18861
+ },
18862
+ get tr() {
18863
+ selection = transaction.selection;
18864
+ doc2 = transaction.doc;
18865
+ storedMarks = transaction.storedMarks;
18866
+ return transaction;
18867
+ }
18868
+ };
18869
+ }
18870
+ class CommandService {
18871
+ constructor(props) {
18872
+ __publicField(this, "editor");
18873
+ __publicField(this, "rawCommands");
18874
+ this.editor = props.editor;
18875
+ this.rawCommands = this.editor.extensionService.commands;
18876
+ }
18877
+ /**
18878
+ * Static method for creating a service.
18879
+ * @param args Arguments for the constructor.
18880
+ */
18881
+ static create(...args) {
18882
+ return new CommandService(...args);
18883
+ }
18884
+ /**
18885
+ * Get editor state.
18886
+ */
18887
+ get state() {
18888
+ return this.editor.state;
18889
+ }
18890
+ /**
18891
+ * Get all commands with wrapped command method.
18892
+ */
18893
+ get commands() {
18894
+ const { editor, state: state2 } = this;
18895
+ const { view } = editor;
18896
+ const { tr } = state2;
18897
+ const props = this.createProps(tr);
18898
+ const entries = Object.entries(this.rawCommands).map(([name, command]) => {
18899
+ const method = (...args) => {
18900
+ const fn = command(...args)(props);
18901
+ if (!tr.getMeta("preventDispatch")) {
18902
+ view.dispatch(tr);
18903
+ }
18904
+ return fn;
18905
+ };
18906
+ return [name, method];
18907
+ });
18908
+ return Object.fromEntries(entries);
18909
+ }
18910
+ /**
18911
+ * Create a chain of commands to call multiple commands at once.
18912
+ */
18913
+ get chain() {
18914
+ return () => this.createChain();
18915
+ }
18916
+ /**
18917
+ * Check if a command or a chain of commands can be executed. Without executing it.
18918
+ */
18919
+ get can() {
18920
+ return () => this.createCan();
18921
+ }
18922
+ /**
18923
+ * Creates a chain of commands.
18924
+ * @param startTr Start transaction.
18925
+ * @param shouldDispatch Should dispatch or not.
18926
+ */
18927
+ createChain(startTr, shouldDispatch = true) {
18928
+ const { editor, state: state2, rawCommands } = this;
18929
+ const { view } = editor;
18930
+ const callbacks = [];
18931
+ const hasStartTr = !!startTr;
18932
+ const tr = startTr || state2.tr;
18933
+ const run2 = () => {
18934
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
18935
+ view.dispatch(tr);
18936
+ }
18937
+ return callbacks.every((cb) => cb === true);
18938
+ };
18939
+ const entries = Object.entries(rawCommands).map(([name, command]) => {
18940
+ const chainedCommand = (...args) => {
18941
+ const props = this.createProps(tr, shouldDispatch);
18942
+ const callback = command(...args)(props);
18943
+ callbacks.push(callback);
18944
+ return chain;
18945
+ };
18946
+ return [name, chainedCommand];
18947
+ });
18948
+ const chain = {
18949
+ ...Object.fromEntries(entries),
18950
+ run: run2
18951
+ };
18952
+ return chain;
18953
+ }
18954
+ /**
18955
+ * Creates a can check for commands.
18956
+ * @param startTr Start transaction.
18957
+ */
18958
+ createCan(startTr) {
18959
+ const { rawCommands, state: state2 } = this;
18960
+ const dispatch = false;
18961
+ const tr = startTr || state2.tr;
18962
+ const props = this.createProps(tr, dispatch);
18963
+ const commands = Object.fromEntries(
18964
+ Object.entries(rawCommands).map(([name, command]) => {
18965
+ return [name, (...args) => command(...args)({ ...props, dispatch: void 0 })];
18966
+ })
18967
+ );
18968
+ return {
18969
+ ...commands,
18970
+ chain: () => this.createChain(tr, dispatch)
18971
+ };
18972
+ }
18973
+ /**
18974
+ * Creates default props for the command method.
18975
+ * @param {*} tr Transaction.
18976
+ * @param {*} shouldDispatch Check if should dispatch.
18977
+ * @returns Object with props.
18978
+ */
18979
+ createProps(tr, shouldDispatch = true) {
18980
+ const { editor, state: state2, rawCommands } = this;
18981
+ const { view } = editor;
18982
+ const props = {
18983
+ tr,
18984
+ editor,
18985
+ view,
18986
+ state: chainableEditorState(tr, state2),
18987
+ dispatch: shouldDispatch ? () => void 0 : void 0,
18988
+ chain: () => this.createChain(tr, shouldDispatch),
18989
+ can: () => this.createCan(tr),
18990
+ get commands() {
18991
+ return Object.fromEntries(
18992
+ Object.entries(rawCommands).map(([name, command]) => {
18993
+ return [name, (...args) => command(...args)(props)];
18994
+ })
18995
+ );
18996
+ }
18997
+ };
18998
+ return props;
18999
+ }
19000
+ }
19001
+ function getHTMLFromFragment(fragment, schema) {
19002
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
19003
+ const temporaryDocument = document.implementation.createHTMLDocument();
19004
+ const container = temporaryDocument.createElement("div");
19005
+ container.appendChild(documentFragment);
19006
+ return container.innerHTML;
19007
+ }
19008
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
19009
+ let textBefore = "";
19010
+ const sliceEndPos = $from.parentOffset;
19011
+ $from.parent.nodesBetween(
19012
+ Math.max(0, sliceEndPos - maxMatch),
19013
+ sliceEndPos,
19014
+ (node2, pos, parent, index) => {
19015
+ const chunk = node2.type.spec.toText?.({
19016
+ node: node2,
19017
+ pos,
19018
+ parent,
19019
+ index
19020
+ }) || node2.textContent || "%leaf%";
19021
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
19022
+ }
19023
+ );
19024
+ return textBefore;
19025
+ };
19026
+ const handleDocxPaste = (html, editor, view, plugin) => {
19027
+ const { converter } = editor;
19028
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin);
19029
+ let cleanedHtml = convertEmToPt(html);
19030
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
19031
+ const tempDiv = document.createElement("div");
19032
+ tempDiv.innerHTML = cleanedHtml;
19033
+ const paragraphs = tempDiv.querySelectorAll("p");
19034
+ paragraphs.forEach((p) => {
19035
+ const innerHTML = p.innerHTML;
19036
+ if (!innerHTML.includes("<!--[if !supportLists]")) return;
19037
+ const styleAttr = p.getAttribute("style") || "";
19038
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
19039
+ if (msoListMatch) {
19040
+ const [, abstractId, level] = msoListMatch;
19041
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
19042
+ if (!listNumId) return;
19043
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
19044
+ const { lvlText, start, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
19045
+ p.setAttribute("data-num-id", listNumId);
19046
+ p.setAttribute("data-list-level", level - 1);
19047
+ p.setAttribute("data-start", start);
19048
+ p.setAttribute("data-lvl-text", lvlText);
19049
+ p.setAttribute("data-num-fmt", numFmt);
19050
+ }
19051
+ extractAndRemoveConditionalPrefix(p);
19052
+ });
19053
+ transformWordLists(tempDiv);
19054
+ const doc2 = DOMParser.fromSchema(editor.schema).parse(tempDiv);
19055
+ tempDiv.remove();
19056
+ const { dispatch } = editor.view;
19057
+ if (!dispatch) return false;
19058
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
19059
+ return true;
19060
+ };
19061
+ const getLevelDefinition = (abstractDefinition, level) => {
19062
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
19063
+ const levelElement = abstractDefinition.elements.find((el) => {
19064
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
19065
+ });
19066
+ if (!levelElement) return null;
19067
+ const { elements } = levelElement;
19068
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
19069
+ const start = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
19070
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
19071
+ return { lvlText, start, numFmt, elements };
19072
+ };
19073
+ const getListNumIdFromAbstract = (abstractId, editor) => {
19074
+ const { definitions } = editor?.converter?.numbering;
19075
+ if (!definitions) return null;
19076
+ const matchedDefinition = Object.values(definitions).find((def) => {
19077
+ return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
19078
+ });
19079
+ return matchedDefinition?.attributes?.["w:numId"];
19080
+ };
19081
+ const getListAbstractDefinition = (abstractId, editor) => {
19082
+ const { abstracts = {} } = editor?.converter?.numbering;
19083
+ return abstracts[abstractId] || null;
19084
+ };
19085
+ const transformWordLists = (container) => {
19086
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
19087
+ const listMap = /* @__PURE__ */ new Map();
19088
+ const listLevels = {};
19089
+ for (const p of paragraphs) {
19090
+ const listId = p.getAttribute("data-num-id");
19091
+ const level = parseInt(p.getAttribute("data-list-level"));
19092
+ const numFmt = p.getAttribute("data-num-fmt");
19093
+ const start = p.getAttribute("data-start");
19094
+ const lvlText = p.getAttribute("data-lvl-text");
19095
+ if (!listMap.has(listId)) listMap.set(listId, []);
19096
+ listMap.get(listId).push({ p, level, numFmt, start, lvlText });
19097
+ }
19098
+ for (const [id, items] of listMap.entries()) {
19099
+ if (!listLevels[id]) {
19100
+ listLevels[id] = {
19101
+ stack: [],
19102
+ counts: {},
19103
+ prevLevel: null
19104
+ };
19105
+ }
19106
+ const parentStack = [];
19107
+ items.forEach(({ p, level, numFmt, start, lvlText }, index) => {
19108
+ const listLevel = generateListNestingPath(listLevels, id, level);
19109
+ const li = document.createElement("li");
19110
+ li.innerHTML = p.innerHTML;
19111
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
19112
+ li.setAttribute("data-num-id", id);
19113
+ li.setAttribute("data-lvl-text", lvlText);
19114
+ li.setAttribute("data-num-fmt", numFmt);
19115
+ if (p.hasAttribute("data-font-family")) {
19116
+ li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
19117
+ }
19118
+ if (p.hasAttribute("data-font-size")) {
19119
+ li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
19120
+ }
19121
+ const parentNode = p.parentNode;
19122
+ let listForLevel = parentStack[level];
19123
+ if (!listForLevel) {
19124
+ const newList = document.createElement("ol");
19125
+ newList.setAttribute("data-list-id", id);
19126
+ newList.level = level;
19127
+ if (level > 0) {
19128
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
19129
+ if (parentLi) parentLi.appendChild(newList);
19130
+ } else {
19131
+ parentNode.insertBefore(newList, p);
19132
+ }
19133
+ parentStack[level] = newList;
19134
+ parentStack.length = level + 1;
19135
+ listForLevel = newList;
19136
+ }
19137
+ listForLevel.appendChild(li);
19138
+ p.remove();
19139
+ });
19140
+ }
19141
+ };
19142
+ function generateListNestingPath(listLevels, listId, currentLevel) {
19143
+ const levelState = listLevels[listId];
19144
+ if (!levelState.stack) levelState.stack = [];
19145
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
19146
+ if (levelState.prevLevel === null) {
19147
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
19148
+ } else {
19149
+ if (currentLevel > levelState.prevLevel) {
19150
+ levelState.stack.push(1);
19151
+ } else if (currentLevel === levelState.prevLevel) {
19152
+ levelState.stack[levelState.stack.length - 1]++;
19153
+ } else {
19154
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
19155
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
19156
+ }
19157
+ }
19158
+ levelState.prevLevel = currentLevel;
19159
+ return [...levelState.stack];
19160
+ }
19161
+ function extractAndRemoveConditionalPrefix(p) {
19162
+ const nodes = Array.from(p.childNodes);
19163
+ let fontFamily = null;
19164
+ let fontSize2 = null;
19165
+ let start = -1, end = -1;
19166
+ nodes.forEach((node2, index) => {
19167
+ if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
19168
+ start = index;
19169
+ }
19170
+ if (start !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
19171
+ end = index;
19172
+ }
19173
+ });
19174
+ if (start !== -1 && end !== -1) {
19175
+ for (let i = start + 1; i < end; i++) {
19176
+ const node2 = nodes[i];
19177
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
19178
+ fontFamily = fontFamily || node2.style.fontFamily;
19179
+ fontSize2 = fontSize2 || node2.style.fontSize;
19180
+ }
19181
+ }
19182
+ for (let i = end; i >= start; i--) {
19183
+ p.removeChild(p.childNodes[i]);
19184
+ }
19185
+ if (fontFamily) p.setAttribute("data-font-family", fontFamily);
19186
+ if (fontSize2) p.setAttribute("data-font-size", fontSize2);
19187
+ }
19188
+ }
19189
+ class InputRule {
19190
+ constructor(config) {
19191
+ __publicField(this, "match");
19192
+ __publicField(this, "handler");
19193
+ this.match = config.match;
19194
+ this.handler = config.handler;
19195
+ }
19196
+ }
19197
+ const inputRuleMatcherHandler = (text, match) => {
19198
+ if (isRegExp(match)) {
19199
+ return match.exec(text);
19200
+ }
19201
+ const inputRuleMatch = match(text);
19202
+ if (!inputRuleMatch) {
19203
+ return null;
19204
+ }
19205
+ const result = [inputRuleMatch.text];
19206
+ result.index = inputRuleMatch.index;
19207
+ result.input = text;
19208
+ result.data = inputRuleMatch.data;
19209
+ if (inputRuleMatch.replaceWith) {
19210
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
19211
+ console.warn(
19212
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
19213
+ );
19214
+ }
19215
+ result.push(inputRuleMatch.replaceWith);
19216
+ }
19217
+ return result;
19218
+ };
19219
+ const run = (config) => {
19220
+ const {
19221
+ editor,
19222
+ from,
19223
+ to,
19224
+ text,
19225
+ rules,
19226
+ plugin
19227
+ } = config;
19228
+ const { view } = editor;
19229
+ if (view.composing) {
19230
+ return false;
19231
+ }
19232
+ const $from = view.state.doc.resolve(from);
19233
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
19234
+ return false;
19235
+ }
19236
+ let matched = false;
19237
+ const textBefore = getTextContentFromNodes($from) + text;
19238
+ rules.forEach((rule) => {
19239
+ if (matched) {
19240
+ return;
19241
+ }
19242
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
19243
+ if (!match) {
19244
+ return;
19245
+ }
19246
+ const tr = view.state.tr;
19247
+ const state2 = chainableEditorState(tr, view.state);
19248
+ const range2 = {
19249
+ from: from - (match[0].length - text.length),
19250
+ to
19251
+ };
19252
+ const { commands, chain, can } = new CommandService({
19253
+ editor,
19254
+ state: state2
19255
+ });
19256
+ const handler = rule.handler({
19257
+ state: state2,
19258
+ range: range2,
19259
+ match,
19260
+ commands,
19261
+ chain,
19262
+ can
19263
+ });
19264
+ if (handler === null || !tr.steps.length) {
19265
+ return;
19266
+ }
19267
+ tr.setMeta(plugin, {
19268
+ transform: tr,
19269
+ from,
19270
+ to,
19271
+ text
19272
+ });
19273
+ view.dispatch(tr);
19274
+ matched = true;
19275
+ });
19276
+ return matched;
19277
+ };
19278
+ const inputRulesPlugin = ({ editor, rules }) => {
19279
+ const plugin = new Plugin({
19280
+ key: new PluginKey("inputRulesPlugin"),
19281
+ state: {
19282
+ init() {
19283
+ return null;
19284
+ },
19285
+ apply(tr, prev, state2) {
19286
+ const stored = tr.getMeta(plugin);
19287
+ if (stored) {
19288
+ return stored;
19289
+ }
19290
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
19291
+ const isSimulatedInput = !!simulatedInputMeta;
19292
+ if (isSimulatedInput) {
19293
+ setTimeout(() => {
19294
+ let { text } = simulatedInputMeta;
19295
+ if (typeof text !== "string") {
19296
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
19297
+ }
19298
+ const { from } = simulatedInputMeta;
19299
+ const to = from + text.length;
19300
+ run({
19301
+ editor,
19302
+ from,
19303
+ to,
19304
+ text,
19305
+ rules,
19306
+ plugin
19307
+ });
19308
+ });
19309
+ }
19310
+ return tr.selectionSet || tr.docChanged ? null : prev;
19311
+ }
19312
+ },
19313
+ props: {
19314
+ handleTextInput(view, from, to, text) {
19315
+ return run({
19316
+ editor,
19317
+ from,
19318
+ to,
19319
+ text,
19320
+ rules,
19321
+ plugin
19322
+ });
19323
+ },
19324
+ // add support for input rules to trigger on enter
19325
+ // this is useful for example for code blocks
19326
+ handleKeyDown(view, event) {
19327
+ if (event.key !== "Enter") {
19328
+ return false;
19329
+ }
19330
+ const { $cursor } = view.state.selection;
19331
+ if ($cursor) {
19332
+ return run({
19333
+ editor,
19334
+ from: $cursor.pos,
19335
+ to: $cursor.pos,
19336
+ text: "\n",
19337
+ rules,
19338
+ plugin
19339
+ });
19340
+ }
19341
+ return false;
19342
+ },
19343
+ // Paste handler
19344
+ handlePaste(view, event, slice) {
19345
+ const clipboard = event.clipboardData;
19346
+ const html = clipboard.getData("text/html");
19347
+ clipboard.getData("text/plain");
19348
+ const fieldAnnotationContent = slice.content.content.filter((item) => item.type.name === "fieldAnnotation");
19349
+ if (fieldAnnotationContent.length) {
19350
+ return false;
19351
+ }
19352
+ let source;
19353
+ if (!html) {
19354
+ source = "plain-text";
19355
+ } else if (isWordHtml(html)) {
19356
+ source = "word-html";
19357
+ } else {
19358
+ source = "browser-html";
19359
+ }
19360
+ switch (source) {
19361
+ case "plain-text":
19362
+ break;
19363
+ case "word-html":
19364
+ if (editor.options.mode === "docx") {
19365
+ return handleDocxPaste(html, editor, view, plugin);
19366
+ }
19367
+ case "browser-html":
19368
+ return handleHtmlPaste$1(html, editor);
19369
+ }
19370
+ return false;
19371
+ }
19372
+ },
19373
+ isInputRules: true
19374
+ });
19375
+ return plugin;
19376
+ };
19377
+ function isWordHtml(html) {
19378
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
19379
+ }
19380
+ const handleHtmlPaste$1 = (html, editor, plugin) => {
19381
+ const htmlWithPtSizing = convertEmToPt(html);
19382
+ const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
19383
+ const doc2 = DOMParser.fromSchema(editor.schema).parse(cleanedHtml);
19384
+ const { dispatch } = editor.view;
19385
+ if (!dispatch) return false;
19386
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
19387
+ return true;
19388
+ };
19389
+ const convertEmToPt = (html) => {
19390
+ return html.replace(
19391
+ /font-size\s*:\s*([\d.]+)em/gi,
19392
+ (_, emValue) => {
19393
+ const em = parseFloat(emValue);
19394
+ const pt = Math.round(em * 12 * 100) / 100;
19395
+ return `font-size: ${pt}pt`;
19396
+ }
19397
+ );
19398
+ };
19399
+ function cleanHtmlUnnecessaryTags(html) {
19400
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
19401
+ }
19402
+ function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
19403
+ const container = document.createElement("div");
19404
+ container.innerHTML = html;
19405
+ const walkAndClean = (node2) => {
19406
+ for (const child of [...node2.children]) {
19407
+ if (forbiddenTags.includes(child.tagName.toLowerCase())) {
19408
+ child.remove();
19409
+ continue;
19410
+ }
19411
+ if (child.hasAttribute("linebreaktype")) {
19412
+ child.removeAttribute("linebreaktype");
19413
+ }
19414
+ walkAndClean(child);
19415
+ }
19416
+ };
19417
+ walkAndClean(container);
19418
+ return container;
19419
+ }
18843
19420
  function exportSchemaToJson(params) {
18844
19421
  const { type: type2 } = params.node || {};
18845
19422
  const router = {
@@ -20183,12 +20760,11 @@ function prepareHtmlAnnotation(params) {
20183
20760
  node: { attrs = {}, marks = [] },
20184
20761
  editorSchema
20185
20762
  } = params;
20186
- const parser = new window.DOMParser();
20187
- const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
20763
+ const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
20188
20764
  const marksFromAttrs = translateFieldAttrsToMarks(attrs);
20189
20765
  const allMarks = [...marks, ...marksFromAttrs];
20190
20766
  let state2 = EditorState.create({
20191
- doc: DOMParser.fromSchema(editorSchema).parse(paragraphHtml)
20767
+ doc: DOMParser.fromSchema(editorSchema).parse(paragraphHtmlContainer)
20192
20768
  });
20193
20769
  if (allMarks.length) {
20194
20770
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
@@ -21317,7 +21893,7 @@ const isPropertiesElement = (element) => {
21317
21893
  };
21318
21894
  function hasTextNode(elements) {
21319
21895
  const runs = elements.filter((el) => el.name === "w:r");
21320
- const runsHaveText = runs.some((run) => run.elements.some((el) => el.name === "w:t"));
21896
+ const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
21321
21897
  return runsHaveText;
21322
21898
  }
21323
21899
  const handleTrackChangeNode = (params) => {
@@ -22476,8 +23052,8 @@ const handleAnnotationNode = (params) => {
22476
23052
  };
22477
23053
  const parseAnnotationMarks = (content = {}, type2) => {
22478
23054
  let mainContent = content;
22479
- const run = mainContent.elements?.find((el) => el.name === "w:r");
22480
- const rPr = run?.elements?.find((el) => el.name === "w:rPr");
23055
+ const run2 = mainContent.elements?.find((el) => el.name === "w:r");
23056
+ const rPr = run2?.elements?.find((el) => el.name === "w:rPr");
22481
23057
  if (!rPr) return {};
22482
23058
  const unknownMarks = [];
22483
23059
  const marks = parseMarks(rPr, unknownMarks) || [];
@@ -22769,8 +23345,8 @@ const handlePictNode = (params) => {
22769
23345
  return { nodes: [], consumed: 0 };
22770
23346
  }
22771
23347
  const [pNode] = nodes;
22772
- const run = pNode.elements?.find((el) => el.name === "w:r");
22773
- const pict = run?.elements?.find((el) => el.name === "w:pict");
23348
+ const run2 = pNode.elements?.find((el) => el.name === "w:r");
23349
+ const pict = run2?.elements?.find((el) => el.name === "w:pict");
22774
23350
  if (!pict) {
22775
23351
  return { nodes: [], consumed: 0 };
22776
23352
  }
@@ -23253,6 +23829,7 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
23253
23829
  const footers = elements.filter((el) => el.attributes["Type"] === footerType);
23254
23830
  const sectPr = findSectPr(docx["word/document.xml"]) || [];
23255
23831
  const allSectPrElements = sectPr.flatMap((el) => el.elements);
23832
+ if (!mainEditor) return;
23256
23833
  const editor = { ...mainEditor };
23257
23834
  editor.options.annotations = true;
23258
23835
  headers.forEach((header) => {
@@ -23414,7 +23991,7 @@ const _SuperConverter = class _SuperConverter {
23414
23991
  return;
23415
23992
  }
23416
23993
  }
23417
- static updateDocumentVersion(docx = this.convertedXml, version = "0.13.2-rev1") {
23994
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.13.2-rev10") {
23418
23995
  const customLocation = "docProps/custom.xml";
23419
23996
  if (!docx[customLocation]) {
23420
23997
  docx[customLocation] = generateCustomXml();
@@ -23884,7 +24461,7 @@ function storeSuperdocVersion(docx) {
23884
24461
  function generateCustomXml() {
23885
24462
  return DEFAULT_CUSTOM_XML;
23886
24463
  }
23887
- function generateSuperdocVersion(pid = 2, version = "0.13.2-rev1") {
24464
+ function generateSuperdocVersion(pid = 2, version = "0.13.2-rev10") {
23888
24465
  return {
23889
24466
  type: "element",
23890
24467
  name: "property",
@@ -23908,41 +24485,44 @@ function generateSuperdocVersion(pid = 2, version = "0.13.2-rev1") {
23908
24485
  };
23909
24486
  }
23910
24487
  export {
23911
- Transform as $,
24488
+ kebabCase as $,
23912
24489
  AllSelection as A,
23913
24490
  Buffer2 as B,
23914
- TrackInsertMarkName as C,
24491
+ TrackDeleteMarkName as C,
23915
24492
  DOMParser as D,
23916
- v4 as E,
24493
+ TrackInsertMarkName as E,
23917
24494
  Fragment as F,
23918
- TrackFormatMarkName as G,
23919
- comments_module_events as H,
23920
- AddMarkStep as I,
23921
- RemoveMarkStep as J,
23922
- twipsToLines as K,
23923
- pixelsToTwips as L,
24495
+ v4 as G,
24496
+ TrackFormatMarkName as H,
24497
+ comments_module_events as I,
24498
+ AddMarkStep as J,
24499
+ RemoveMarkStep as K,
24500
+ twipsToLines as L,
23924
24501
  Mapping as M,
23925
24502
  NodeSelection as N,
23926
- SuperConverter as O,
24503
+ pixelsToTwips as O,
23927
24504
  PluginKey as P,
23928
- EditorState as Q,
24505
+ CommandService as Q,
23929
24506
  ReplaceAroundStep as R,
23930
24507
  Schema$1 as S,
23931
24508
  TextSelection as T,
23932
- hasSomeParentWithClass as U,
23933
- parseSizeUnit as V,
23934
- getLineHeightValueString as W,
23935
- toKebabCase as X,
23936
- kebabCase as Y,
23937
- getColStyleDeclaration as Z,
23938
- SelectionRange as _,
24509
+ SuperConverter as U,
24510
+ EditorState as V,
24511
+ hasSomeParentWithClass as W,
24512
+ parseSizeUnit as X,
24513
+ getLineHeightValueString as Y,
24514
+ InputRule as Z,
24515
+ toKebabCase as _,
23939
24516
  Plugin as a,
23940
- createColGroup as a0,
23941
- commonjsGlobal as a1,
23942
- getDefaultExportFromCjs$1 as a2,
23943
- getContentTypesFromXml as a3,
23944
- xmljs as a4,
23945
- vClickOutside as a5,
24517
+ getColStyleDeclaration as a0,
24518
+ SelectionRange as a1,
24519
+ Transform as a2,
24520
+ createColGroup as a3,
24521
+ commonjsGlobal as a4,
24522
+ getDefaultExportFromCjs$1 as a5,
24523
+ getContentTypesFromXml as a6,
24524
+ xmljs as a7,
24525
+ vClickOutside as a8,
23946
24526
  canSplit as b,
23947
24527
  callOrGet as c,
23948
24528
  canJoin as d,
@@ -23961,11 +24541,11 @@ export {
23961
24541
  generateDocxRandomId as q,
23962
24542
  replaceStep as r,
23963
24543
  minMax as s,
23964
- generateRandom32BitHex as t,
23965
- DOMSerializer as u,
23966
- Mark as v,
23967
- dropPoint as w,
23968
- process$1 as x,
23969
- isRegExp as y,
23970
- TrackDeleteMarkName as z
24544
+ chainableEditorState as t,
24545
+ generateRandom32BitHex as u,
24546
+ DOMSerializer as v,
24547
+ Mark as w,
24548
+ dropPoint as x,
24549
+ process$1 as y,
24550
+ inputRulesPlugin as z
23971
24551
  };