@harbour-enterprises/superdoc 0.13.2-rev9 → 0.13.2

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 (57) hide show
  1. package/dist/chunks/{eventemitter3-KKY27oz-.es.js → eventemitter3-BrspJk8q.es.js} +1 -1
  2. package/dist/chunks/{eventemitter3-CHxWXmuK.cjs → eventemitter3-DfVviFzP.cjs} +1 -1
  3. package/dist/chunks/{index-CweAXNfB.cjs → index-B4J7wgs6.cjs} +2 -2
  4. package/dist/chunks/{index-kOMfCfBT.cjs → index-Cdsq63Xq.cjs} +4 -4
  5. package/dist/chunks/{index-DS3W0eVB.es.js → index-Diu6UKHt.es.js} +4 -4
  6. package/dist/chunks/{index-BqLFjUHn.es.js → index-Hr3Um-Bg.es.js} +2 -2
  7. package/dist/chunks/{jszip-9bCX1h2W.cjs → jszip-BTAcmbVg.cjs} +1 -1
  8. package/dist/chunks/{jszip-Cl3s9njw.es.js → jszip-DckFs3A7.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-TaswSSDL.cjs → super-editor.es-BM89AzsN.cjs} +811 -1088
  10. package/dist/chunks/{super-editor.es-BE0HKCoV.es.js → super-editor.es-BNyzbCw0.es.js} +811 -1088
  11. package/dist/chunks/{url-B8LY3nwf.cjs → url-BIzg4y2i.cjs} +2 -2
  12. package/dist/chunks/{url-Bq00tGvm.es.js → url-CHayXMZH.es.js} +2 -2
  13. package/dist/chunks/{vue-BBJVqxjL.es.js → vue-Bi1uWinj.es.js} +3 -10
  14. package/dist/chunks/{vue-BBjMeYfo.cjs → vue-HIY1g7dm.cjs} +3 -10
  15. package/dist/chunks/{xml-js-BuAdLsHD.cjs → xml-js-BjqmFOSP.cjs} +102 -81
  16. package/dist/chunks/{xml-js-1F0lia4t.es.js → xml-js-CfClL-1b.es.js} +102 -81
  17. package/dist/style.css +1 -2
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-BvRopd2F.js → converter-CsK9KCaL.js} +55 -637
  20. package/dist/super-editor/chunks/{docx-zipper-CZ8M74hv.js → docx-zipper-6iKmmME2.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-D1rD0fdS.js → editor-Cxb-Zwyu.js} +685 -387
  22. package/dist/super-editor/chunks/{toolbar-CvP4K1yD.js → toolbar-QHIHaeEf.js} +3 -2
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +0 -7
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +0 -7
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +0 -4
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  31. package/dist/super-editor/docx-zipper.es.js +2 -2
  32. package/dist/super-editor/editor.es.js +3 -3
  33. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  34. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  35. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +1 -6
  39. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  41. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  42. package/dist/super-editor/file-zipper.es.js +1 -1
  43. package/dist/super-editor/style.css +1 -2
  44. package/dist/super-editor/super-editor.es.js +7 -7
  45. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  46. package/dist/super-editor/toolbar.es.js +2 -2
  47. package/dist/super-editor.cjs +2 -2
  48. package/dist/super-editor.es.js +2 -2
  49. package/dist/superdoc.cjs +9 -8
  50. package/dist/superdoc.es.js +10 -9
  51. package/dist/superdoc.umd.js +815 -1098
  52. package/dist/superdoc.umd.js.map +1 -1
  53. package/package.json +1 -1
  54. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +0 -2
  55. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +0 -1
  56. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +0 -3
  57. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +0 -1
@@ -10960,7 +10960,7 @@ class NodeRange {
10960
10960
  }
10961
10961
  }
10962
10962
  const emptyAttrs = /* @__PURE__ */ Object.create(null);
10963
- let Node$1 = class Node2 {
10963
+ class Node {
10964
10964
  /**
10965
10965
  @internal
10966
10966
  */
@@ -11090,14 +11090,14 @@ let Node$1 = class Node2 {
11090
11090
  copy(content = null) {
11091
11091
  if (content == this.content)
11092
11092
  return this;
11093
- return new Node2(this.type, this.attrs, content, this.marks);
11093
+ return new Node(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 Node2(this.type, this.attrs, this.content, marks);
11100
+ return marks == this.marks ? this : new Node(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 @@ let Node$1 = class Node2 {
11360
11360
  node2.type.checkAttrs(node2.attrs);
11361
11361
  return node2;
11362
11362
  }
11363
- };
11364
- Node$1.prototype.text = void 0;
11365
- class TextNode extends Node$1 {
11363
+ }
11364
+ Node.prototype.text = void 0;
11365
+ class TextNode extends Node {
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$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
11952
+ return new Node(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$1(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
11962
+ return new Node(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$1(this, attrs, content.append(after), Mark.setFrom(marks));
11985
+ return new Node(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$1.fromJSON(this, json);
12222
+ return Node.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$1.fromJSON(config.schema, json.doc);
15782
+ instance.doc = Node.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,583 +18840,6 @@ 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
- }
19420
18843
  function exportSchemaToJson(params) {
19421
18844
  const { type: type2 } = params.node || {};
19422
18845
  const router = {
@@ -19454,13 +18877,13 @@ function exportSchemaToJson(params) {
19454
18877
  function translateBodyNode(params) {
19455
18878
  let sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
19456
18879
  if (params.converter) {
19457
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
18880
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
19458
18881
  const hasDefaultHeader = params.converter.headerIds?.default;
19459
18882
  if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
19460
18883
  const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
19461
18884
  sectPr.elements.push(defaultHeader);
19462
18885
  }
19463
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
18886
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
19464
18887
  const hasDefaultFooter = params.converter.footerIds?.default;
19465
18888
  if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
19466
18889
  const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
@@ -20760,11 +20183,12 @@ function prepareHtmlAnnotation(params) {
20760
20183
  node: { attrs = {}, marks = [] },
20761
20184
  editorSchema
20762
20185
  } = params;
20763
- const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
20186
+ const parser = new window.DOMParser();
20187
+ const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
20764
20188
  const marksFromAttrs = translateFieldAttrsToMarks(attrs);
20765
20189
  const allMarks = [...marks, ...marksFromAttrs];
20766
20190
  let state2 = EditorState.create({
20767
- doc: DOMParser.fromSchema(editorSchema).parse(paragraphHtmlContainer)
20191
+ doc: DOMParser.fromSchema(editorSchema).parse(paragraphHtml)
20768
20192
  });
20769
20193
  if (allMarks.length) {
20770
20194
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
@@ -21893,7 +21317,7 @@ const isPropertiesElement = (element) => {
21893
21317
  };
21894
21318
  function hasTextNode(elements) {
21895
21319
  const runs = elements.filter((el) => el.name === "w:r");
21896
- const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
21320
+ const runsHaveText = runs.some((run) => run.elements.some((el) => el.name === "w:t"));
21897
21321
  return runsHaveText;
21898
21322
  }
21899
21323
  const handleTrackChangeNode = (params) => {
@@ -23052,8 +22476,8 @@ const handleAnnotationNode = (params) => {
23052
22476
  };
23053
22477
  const parseAnnotationMarks = (content = {}, type2) => {
23054
22478
  let mainContent = content;
23055
- const run2 = mainContent.elements?.find((el) => el.name === "w:r");
23056
- const rPr = run2?.elements?.find((el) => el.name === "w:rPr");
22479
+ const run = mainContent.elements?.find((el) => el.name === "w:r");
22480
+ const rPr = run?.elements?.find((el) => el.name === "w:rPr");
23057
22481
  if (!rPr) return {};
23058
22482
  const unknownMarks = [];
23059
22483
  const marks = parseMarks(rPr, unknownMarks) || [];
@@ -23345,8 +22769,8 @@ const handlePictNode = (params) => {
23345
22769
  return { nodes: [], consumed: 0 };
23346
22770
  }
23347
22771
  const [pNode] = nodes;
23348
- const run2 = pNode.elements?.find((el) => el.name === "w:r");
23349
- const pict = run2?.elements?.find((el) => el.name === "w:pict");
22772
+ const run = pNode.elements?.find((el) => el.name === "w:r");
22773
+ const pict = run?.elements?.find((el) => el.name === "w:pict");
23350
22774
  if (!pict) {
23351
22775
  return { nodes: [], consumed: 0 };
23352
22776
  }
@@ -23819,7 +23243,7 @@ function addDefaultStylesIfMissing(styles) {
23819
23243
  });
23820
23244
  return updatedStyles;
23821
23245
  }
23822
- const importHeadersFooters = (docx, converter, mainEditor) => {
23246
+ const importHeadersFooters = (docx, converter, editor) => {
23823
23247
  const rels = docx["word/_rels/document.xml.rels"];
23824
23248
  const relationships = rels.elements.find((el) => el.name === "Relationships");
23825
23249
  const { elements } = relationships;
@@ -23829,9 +23253,6 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
23829
23253
  const footers = elements.filter((el) => el.attributes["Type"] === footerType);
23830
23254
  const sectPr = findSectPr(docx["word/document.xml"]) || [];
23831
23255
  const allSectPrElements = sectPr.flatMap((el) => el.elements);
23832
- if (!mainEditor) return;
23833
- const editor = { ...mainEditor };
23834
- editor.options.annotations = true;
23835
23256
  headers.forEach((header) => {
23836
23257
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(header, docx);
23837
23258
  const sectPrHeader = allSectPrElements.find((el) => el.name === "w:headerReference" && el.attributes["r:id"] === rId);
@@ -23991,7 +23412,7 @@ const _SuperConverter = class _SuperConverter {
23991
23412
  return;
23992
23413
  }
23993
23414
  }
23994
- static updateDocumentVersion(docx = this.convertedXml, version = "0.13.2-rev9") {
23415
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.13.2") {
23995
23416
  const customLocation = "docProps/custom.xml";
23996
23417
  if (!docx[customLocation]) {
23997
23418
  docx[customLocation] = generateCustomXml();
@@ -24461,7 +23882,7 @@ function storeSuperdocVersion(docx) {
24461
23882
  function generateCustomXml() {
24462
23883
  return DEFAULT_CUSTOM_XML;
24463
23884
  }
24464
- function generateSuperdocVersion(pid = 2, version = "0.13.2-rev9") {
23885
+ function generateSuperdocVersion(pid = 2, version = "0.13.2") {
24465
23886
  return {
24466
23887
  type: "element",
24467
23888
  name: "property",
@@ -24485,44 +23906,41 @@ function generateSuperdocVersion(pid = 2, version = "0.13.2-rev9") {
24485
23906
  };
24486
23907
  }
24487
23908
  export {
24488
- kebabCase as $,
23909
+ Transform as $,
24489
23910
  AllSelection as A,
24490
23911
  Buffer2 as B,
24491
- TrackDeleteMarkName as C,
23912
+ TrackInsertMarkName as C,
24492
23913
  DOMParser as D,
24493
- TrackInsertMarkName as E,
23914
+ v4 as E,
24494
23915
  Fragment as F,
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,
23916
+ TrackFormatMarkName as G,
23917
+ comments_module_events as H,
23918
+ AddMarkStep as I,
23919
+ RemoveMarkStep as J,
23920
+ twipsToLines as K,
23921
+ pixelsToTwips as L,
24501
23922
  Mapping as M,
24502
23923
  NodeSelection as N,
24503
- pixelsToTwips as O,
23924
+ SuperConverter as O,
24504
23925
  PluginKey as P,
24505
- CommandService as Q,
23926
+ EditorState as Q,
24506
23927
  ReplaceAroundStep as R,
24507
23928
  Schema$1 as S,
24508
23929
  TextSelection as T,
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 _,
23930
+ hasSomeParentWithClass as U,
23931
+ parseSizeUnit as V,
23932
+ getLineHeightValueString as W,
23933
+ toKebabCase as X,
23934
+ kebabCase as Y,
23935
+ getColStyleDeclaration as Z,
23936
+ SelectionRange as _,
24516
23937
  Plugin as a,
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,
23938
+ createColGroup as a0,
23939
+ commonjsGlobal as a1,
23940
+ getDefaultExportFromCjs$1 as a2,
23941
+ getContentTypesFromXml as a3,
23942
+ xmljs as a4,
23943
+ vClickOutside as a5,
24526
23944
  canSplit as b,
24527
23945
  callOrGet as c,
24528
23946
  canJoin as d,
@@ -24541,11 +23959,11 @@ export {
24541
23959
  generateDocxRandomId as q,
24542
23960
  replaceStep as r,
24543
23961
  minMax as s,
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
23962
+ generateRandom32BitHex as t,
23963
+ DOMSerializer as u,
23964
+ Mark as v,
23965
+ dropPoint as w,
23966
+ process$1 as x,
23967
+ isRegExp as y,
23968
+ TrackDeleteMarkName as z
24551
23969
  };