@harbour-enterprises/superdoc 0.13.2-rev8 → 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 (54) 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-Bd4H2zrq.cjs → index-B4J7wgs6.cjs} +2 -2
  4. package/dist/chunks/{index-Bdjh4ZPT.cjs → index-Cdsq63Xq.cjs} +4 -4
  5. package/dist/chunks/{index-DuSTYEOs.es.js → index-Diu6UKHt.es.js} +4 -4
  6. package/dist/chunks/{index-B1TbritH.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-Cz-ceaxn.cjs → super-editor.es-BM89AzsN.cjs} +704 -859
  10. package/dist/chunks/{super-editor.es-BY5Eoi9A.es.js → super-editor.es-BNyzbCw0.es.js} +704 -859
  11. package/dist/chunks/{url-CJP-Jmfp.cjs → url-BIzg4y2i.cjs} +2 -2
  12. package/dist/chunks/{url-CLwIePTG.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-k_RETz76.cjs → xml-js-BjqmFOSP.cjs} +225 -239
  16. package/dist/chunks/{xml-js-Bp5Hoq_3.es.js → xml-js-CfClL-1b.es.js} +225 -239
  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-RV0QN3HE.js → converter-CsK9KCaL.js} +55 -637
  20. package/dist/super-editor/chunks/{docx-zipper-C5TBRQNB.js → docx-zipper-6iKmmME2.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-XlwZxMCI.js → editor-Cxb-Zwyu.js} +676 -256
  22. package/dist/super-editor/chunks/{toolbar-52_BMgdJ.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/super-converter/exporter.d.ts.map +1 -1
  29. package/dist/super-editor/docx-zipper.es.js +2 -2
  30. package/dist/super-editor/editor.es.js +3 -3
  31. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  32. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  33. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  34. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  35. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +1 -6
  36. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  39. package/dist/super-editor/file-zipper.es.js +1 -1
  40. package/dist/super-editor/style.css +1 -2
  41. package/dist/super-editor/super-editor.es.js +7 -7
  42. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  43. package/dist/super-editor/toolbar.es.js +2 -2
  44. package/dist/super-editor.cjs +2 -2
  45. package/dist/super-editor.es.js +2 -2
  46. package/dist/superdoc.cjs +9 -8
  47. package/dist/superdoc.es.js +10 -9
  48. package/dist/superdoc.umd.js +708 -869
  49. package/dist/superdoc.umd.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +0 -2
  52. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +0 -1
  53. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +0 -3
  54. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const vue = require("./vue-BBjMeYfo.cjs");
2
+ const vue = require("./vue-HIY1g7dm.cjs");
3
3
  const Y = require("yjs");
4
4
  function _interopNamespaceDefault(e) {
5
5
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -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
@@ -13743,7 +13743,7 @@ class ReplaceStep extends Step {
13743
13743
  }
13744
13744
  }
13745
13745
  Step.jsonID("replace", ReplaceStep);
13746
- let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
13746
+ class ReplaceAroundStep extends Step {
13747
13747
  /**
13748
13748
  Create a replace-around step with the given range and gap.
13749
13749
  `insert` should be the point in the slice into which the content
@@ -13783,7 +13783,7 @@ let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
13783
13783
  }
13784
13784
  invert(doc2) {
13785
13785
  let gap = this.gapTo - this.gapFrom;
13786
- return new ReplaceAroundStep2(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc2.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
13786
+ return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc2.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
13787
13787
  }
13788
13788
  map(mapping) {
13789
13789
  let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
@@ -13791,7 +13791,7 @@ let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
13791
13791
  let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
13792
13792
  if (from2.deletedAcross && to.deletedAcross || gapFrom < from2.pos || gapTo > to.pos)
13793
13793
  return null;
13794
- return new ReplaceAroundStep2(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
13794
+ return new ReplaceAroundStep(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
13795
13795
  }
13796
13796
  toJSON() {
13797
13797
  let json = {
@@ -13814,10 +13814,10 @@ let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
13814
13814
  static fromJSON(schema, json) {
13815
13815
  if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
13816
13816
  throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
13817
- return new ReplaceAroundStep2(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
13817
+ return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
13818
13818
  }
13819
- };
13820
- Step.jsonID("replaceAround", ReplaceAroundStep$1);
13819
+ }
13820
+ Step.jsonID("replaceAround", ReplaceAroundStep);
13821
13821
  function contentBetween(doc2, from2, to) {
13822
13822
  let $from = doc2.resolve(from2), dist2 = to - from2, depth = $from.depth;
13823
13823
  while (dist2 > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
@@ -13970,7 +13970,7 @@ function lift(tr, range2, target) {
13970
13970
  } else {
13971
13971
  end2++;
13972
13972
  }
13973
- tr.step(new ReplaceAroundStep$1(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
13973
+ tr.step(new ReplaceAroundStep(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
13974
13974
  }
13975
13975
  function findWrapping(range2, nodeType, attrs = null, innerRange = range2) {
13976
13976
  let around = findWrappingOutside(range2, nodeType);
@@ -14015,7 +14015,7 @@ function wrap(tr, range2, wrappers) {
14015
14015
  content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
14016
14016
  }
14017
14017
  let start2 = range2.start, end2 = range2.end;
14018
- tr.step(new ReplaceAroundStep$1(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
14018
+ tr.step(new ReplaceAroundStep(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
14019
14019
  }
14020
14020
  function setBlockType$1(tr, from2, to, type2, attrs) {
14021
14021
  if (!type2.isTextblock)
@@ -14037,7 +14037,7 @@ function setBlockType$1(tr, from2, to, type2, attrs) {
14037
14037
  clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type2, void 0, convertNewlines === null);
14038
14038
  let mapping = tr.mapping.slice(mapFrom);
14039
14039
  let startM = mapping.map(pos, 1), endM = mapping.map(pos + node2.nodeSize, 1);
14040
- tr.step(new ReplaceAroundStep$1(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type2.create(attrsHere, null, node2.marks)), 0, 0), 1, true));
14040
+ tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type2.create(attrsHere, null, node2.marks)), 0, 0), 1, true));
14041
14041
  if (convertNewlines === true)
14042
14042
  replaceNewlines(tr, node2, pos, mapFrom);
14043
14043
  return false;
@@ -14078,7 +14078,7 @@ function setNodeMarkup(tr, pos, type2, attrs, marks) {
14078
14078
  return tr.replaceWith(pos, pos + node2.nodeSize, newNode);
14079
14079
  if (!type2.validContent(node2.content))
14080
14080
  throw new RangeError("Invalid content for node type " + type2.name);
14081
- tr.step(new ReplaceAroundStep$1(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
14081
+ tr.step(new ReplaceAroundStep(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
14082
14082
  }
14083
14083
  function canSplit(doc2, pos, depth = 1, typesAfter) {
14084
14084
  let $pos = doc2.resolve(pos), base2 = $pos.depth - depth;
@@ -14279,7 +14279,7 @@ class Fitter {
14279
14279
  }
14280
14280
  let slice2 = new Slice(content, openStart, openEnd);
14281
14281
  if (moveInline > -1)
14282
- return new ReplaceAroundStep$1($from.pos, moveInline, this.$to.pos, this.$to.end(), slice2, placedSize);
14282
+ return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice2, placedSize);
14283
14283
  if (slice2.size || $from.pos != this.$to.pos)
14284
14284
  return new ReplaceStep($from.pos, $to.pos, slice2);
14285
14285
  return null;
@@ -15362,7 +15362,7 @@ function selectionToInsertionEnd$1(tr, startLen, bias) {
15362
15362
  if (last < startLen)
15363
15363
  return;
15364
15364
  let step = tr.steps[last];
15365
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1))
15365
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
15366
15366
  return;
15367
15367
  let map3 = tr.mapping.maps[last], end2;
15368
15368
  map3.forEach((_from, _to, _newFrom, newTo) => {
@@ -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 = {
@@ -19452,13 +18875,13 @@ function exportSchemaToJson(params2) {
19452
18875
  function translateBodyNode(params2) {
19453
18876
  let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
19454
18877
  if (params2.converter) {
19455
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
18878
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
19456
18879
  const hasDefaultHeader = params2.converter.headerIds?.default;
19457
18880
  if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
19458
18881
  const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
19459
18882
  sectPr.elements.push(defaultHeader);
19460
18883
  }
19461
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
18884
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
19462
18885
  const hasDefaultFooter = params2.converter.footerIds?.default;
19463
18886
  if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
19464
18887
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
@@ -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);
@@ -23817,7 +23241,7 @@ function addDefaultStylesIfMissing(styles) {
23817
23241
  });
23818
23242
  return updatedStyles;
23819
23243
  }
23820
- const importHeadersFooters = (docx, converter, mainEditor) => {
23244
+ const importHeadersFooters = (docx, converter, editor) => {
23821
23245
  const rels = docx["word/_rels/document.xml.rels"];
23822
23246
  const relationships = rels.elements.find((el) => el.name === "Relationships");
23823
23247
  const { elements } = relationships;
@@ -23827,9 +23251,6 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
23827
23251
  const footers = elements.filter((el) => el.attributes["Type"] === footerType);
23828
23252
  const sectPr = findSectPr(docx["word/document.xml"]) || [];
23829
23253
  const allSectPrElements = sectPr.flatMap((el) => el.elements);
23830
- if (!mainEditor) return;
23831
- const editor = { ...mainEditor };
23832
- editor.options.annotations = true;
23833
23254
  headers.forEach((header) => {
23834
23255
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(header, docx);
23835
23256
  const sectPrHeader = allSectPrElements.find((el) => el.name === "w:headerReference" && el.attributes["r:id"] === rId);
@@ -23989,7 +23410,7 @@ const _SuperConverter = class _SuperConverter2 {
23989
23410
  return;
23990
23411
  }
23991
23412
  }
23992
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-rev8") {
23413
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2") {
23993
23414
  const customLocation = "docProps/custom.xml";
23994
23415
  if (!docx[customLocation]) {
23995
23416
  docx[customLocation] = generateCustomXml();
@@ -24456,7 +23877,7 @@ function storeSuperdocVersion(docx) {
24456
23877
  function generateCustomXml() {
24457
23878
  return DEFAULT_CUSTOM_XML;
24458
23879
  }
24459
- function generateSuperdocVersion(pid = 2, version2 = "0.13.2-rev8") {
23880
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.2") {
24460
23881
  return {
24461
23882
  type: "element",
24462
23883
  name: "property",
@@ -26989,7 +26410,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
26989
26410
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
26990
26411
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
26991
26412
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
26992
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
26413
+ var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
26993
26414
  function getMarksFromSelection(state2) {
26994
26415
  const { from: from2, to, empty: empty2 } = state2.selection;
26995
26416
  const marks = [];
@@ -28178,6 +27599,164 @@ createMarksSchema_fn = function(markExtensions, attributes, editor) {
28178
27599
  };
28179
27600
  __privateAdd$1(_Schema, _Schema_static);
28180
27601
  let Schema2 = _Schema;
27602
+ function chainableEditorState(transaction, state2) {
27603
+ let { selection, doc: doc2, storedMarks } = transaction;
27604
+ return {
27605
+ ...state2,
27606
+ apply: state2.apply.bind(state2),
27607
+ applyTransaction: state2.applyTransaction.bind(state2),
27608
+ plugins: state2.plugins,
27609
+ schema: state2.schema,
27610
+ reconfigure: state2.reconfigure.bind(state2),
27611
+ toJSON: state2.toJSON.bind(state2),
27612
+ get storedMarks() {
27613
+ return storedMarks;
27614
+ },
27615
+ get selection() {
27616
+ return selection;
27617
+ },
27618
+ get doc() {
27619
+ return doc2;
27620
+ },
27621
+ get tr() {
27622
+ selection = transaction.selection;
27623
+ doc2 = transaction.doc;
27624
+ storedMarks = transaction.storedMarks;
27625
+ return transaction;
27626
+ }
27627
+ };
27628
+ }
27629
+ class CommandService {
27630
+ constructor(props) {
27631
+ __publicField$1(this, "editor");
27632
+ __publicField$1(this, "rawCommands");
27633
+ this.editor = props.editor;
27634
+ this.rawCommands = this.editor.extensionService.commands;
27635
+ }
27636
+ /**
27637
+ * Static method for creating a service.
27638
+ * @param args Arguments for the constructor.
27639
+ */
27640
+ static create(...args) {
27641
+ return new CommandService(...args);
27642
+ }
27643
+ /**
27644
+ * Get editor state.
27645
+ */
27646
+ get state() {
27647
+ return this.editor.state;
27648
+ }
27649
+ /**
27650
+ * Get all commands with wrapped command method.
27651
+ */
27652
+ get commands() {
27653
+ const { editor, state: state2 } = this;
27654
+ const { view } = editor;
27655
+ const { tr } = state2;
27656
+ const props = this.createProps(tr);
27657
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
27658
+ const method = (...args) => {
27659
+ const fn2 = command2(...args)(props);
27660
+ if (!tr.getMeta("preventDispatch")) {
27661
+ view.dispatch(tr);
27662
+ }
27663
+ return fn2;
27664
+ };
27665
+ return [name, method];
27666
+ });
27667
+ return Object.fromEntries(entries);
27668
+ }
27669
+ /**
27670
+ * Create a chain of commands to call multiple commands at once.
27671
+ */
27672
+ get chain() {
27673
+ return () => this.createChain();
27674
+ }
27675
+ /**
27676
+ * Check if a command or a chain of commands can be executed. Without executing it.
27677
+ */
27678
+ get can() {
27679
+ return () => this.createCan();
27680
+ }
27681
+ /**
27682
+ * Creates a chain of commands.
27683
+ * @param startTr Start transaction.
27684
+ * @param shouldDispatch Should dispatch or not.
27685
+ */
27686
+ createChain(startTr, shouldDispatch = true) {
27687
+ const { editor, state: state2, rawCommands } = this;
27688
+ const { view } = editor;
27689
+ const callbacks2 = [];
27690
+ const hasStartTr = !!startTr;
27691
+ const tr = startTr || state2.tr;
27692
+ const run2 = () => {
27693
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
27694
+ view.dispatch(tr);
27695
+ }
27696
+ return callbacks2.every((cb) => cb === true);
27697
+ };
27698
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
27699
+ const chainedCommand = (...args) => {
27700
+ const props = this.createProps(tr, shouldDispatch);
27701
+ const callback = command2(...args)(props);
27702
+ callbacks2.push(callback);
27703
+ return chain;
27704
+ };
27705
+ return [name, chainedCommand];
27706
+ });
27707
+ const chain = {
27708
+ ...Object.fromEntries(entries),
27709
+ run: run2
27710
+ };
27711
+ return chain;
27712
+ }
27713
+ /**
27714
+ * Creates a can check for commands.
27715
+ * @param startTr Start transaction.
27716
+ */
27717
+ createCan(startTr) {
27718
+ const { rawCommands, state: state2 } = this;
27719
+ const dispatch = false;
27720
+ const tr = startTr || state2.tr;
27721
+ const props = this.createProps(tr, dispatch);
27722
+ const commands2 = Object.fromEntries(
27723
+ Object.entries(rawCommands).map(([name, command2]) => {
27724
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
27725
+ })
27726
+ );
27727
+ return {
27728
+ ...commands2,
27729
+ chain: () => this.createChain(tr, dispatch)
27730
+ };
27731
+ }
27732
+ /**
27733
+ * Creates default props for the command method.
27734
+ * @param {*} tr Transaction.
27735
+ * @param {*} shouldDispatch Check if should dispatch.
27736
+ * @returns Object with props.
27737
+ */
27738
+ createProps(tr, shouldDispatch = true) {
27739
+ const { editor, state: state2, rawCommands } = this;
27740
+ const { view } = editor;
27741
+ const props = {
27742
+ tr,
27743
+ editor,
27744
+ view,
27745
+ state: chainableEditorState(tr, state2),
27746
+ dispatch: shouldDispatch ? () => void 0 : void 0,
27747
+ chain: () => this.createChain(tr, shouldDispatch),
27748
+ can: () => this.createCan(tr),
27749
+ get commands() {
27750
+ return Object.fromEntries(
27751
+ Object.entries(rawCommands).map(([name, command2]) => {
27752
+ return [name, (...args) => command2(...args)(props)];
27753
+ })
27754
+ );
27755
+ }
27756
+ };
27757
+ return props;
27758
+ }
27759
+ }
28181
27760
  const first = (commands2) => (props) => {
28182
27761
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
28183
27762
  for (let i = 0; i < items.length; i += 1) {
@@ -28539,7 +28118,7 @@ function deleteBarrier(state2, $cut, dispatch, dir) {
28539
28118
  for (let i = conn.length - 1; i >= 0; i--)
28540
28119
  wrap2 = Fragment.from(conn[i].create(null, wrap2));
28541
28120
  wrap2 = Fragment.from(before.copy(wrap2));
28542
- let tr = state2.tr.step(new ReplaceAroundStep$1($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
28121
+ let tr = state2.tr.step(new ReplaceAroundStep($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
28543
28122
  let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
28544
28123
  if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
28545
28124
  tr.join($joinAt.pos);
@@ -28570,7 +28149,7 @@ function deleteBarrier(state2, $cut, dispatch, dir) {
28570
28149
  let end2 = Fragment.empty;
28571
28150
  for (let i = wrap2.length - 1; i >= 0; i--)
28572
28151
  end2 = Fragment.from(wrap2[i].copy(end2));
28573
- let tr = state2.tr.step(new ReplaceAroundStep$1($cut.pos - wrap2.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap2.length, 0), 0, true));
28152
+ let tr = state2.tr.step(new ReplaceAroundStep($cut.pos - wrap2.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap2.length, 0), 0, true));
28574
28153
  dispatch(tr.scrollIntoView());
28575
28154
  }
28576
28155
  return true;
@@ -29143,7 +28722,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
29143
28722
  return;
29144
28723
  }
29145
28724
  const step = tr.steps[last];
29146
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
28725
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
29147
28726
  return;
29148
28727
  }
29149
28728
  const map22 = tr.mapping.maps[last];
@@ -29289,7 +28868,7 @@ function doWrapInList(tr, range2, wrappers, joinBefore, listType) {
29289
28868
  let content = Fragment.empty;
29290
28869
  for (let i = wrappers.length - 1; i >= 0; i--)
29291
28870
  content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
29292
- tr.step(new ReplaceAroundStep$1(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
28871
+ tr.step(new ReplaceAroundStep(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
29293
28872
  let found2 = 0;
29294
28873
  for (let i = 0; i < wrappers.length; i++)
29295
28874
  if (wrappers[i].type == listType)
@@ -29322,7 +28901,7 @@ function liftListItem$1(itemType) {
29322
28901
  function liftToOuterList(state2, dispatch, itemType, range2) {
29323
28902
  let tr = state2.tr, end2 = range2.end, endOfList = range2.$to.end(range2.depth);
29324
28903
  if (end2 < endOfList) {
29325
- tr.step(new ReplaceAroundStep$1(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
28904
+ tr.step(new ReplaceAroundStep(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
29326
28905
  range2 = new NodeRange(tr.doc.resolve(range2.$from.pos), tr.doc.resolve(endOfList), range2.depth);
29327
28906
  }
29328
28907
  const target = liftTarget(range2);
@@ -29349,7 +28928,7 @@ function liftOutOfList(state2, dispatch, range2) {
29349
28928
  if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
29350
28929
  return false;
29351
28930
  let start2 = $start.pos, end2 = start2 + item.nodeSize;
29352
- tr.step(new ReplaceAroundStep$1(start2 - (atStart ? 1 : 0), end2 + (atEnd ? 1 : 0), start2 + 1, end2 - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
28931
+ tr.step(new ReplaceAroundStep(start2 - (atStart ? 1 : 0), end2 + (atEnd ? 1 : 0), start2 + 1, end2 - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
29353
28932
  dispatch(tr.scrollIntoView());
29354
28933
  return true;
29355
28934
  }
@@ -29370,7 +28949,7 @@ function sinkListItem$1(itemType) {
29370
28949
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
29371
28950
  let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
29372
28951
  let before = range2.start, after = range2.end;
29373
- dispatch(state2.tr.step(new ReplaceAroundStep$1(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
28952
+ dispatch(state2.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
29374
28953
  }
29375
28954
  return true;
29376
28955
  };
@@ -36963,8 +36542,7 @@ const restoreRelativeSelection = (tr, relSel, binding) => {
36963
36542
  binding.mapping
36964
36543
  );
36965
36544
  if (anchor !== null && head !== null) {
36966
- const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
36967
- tr.setSelection(sel);
36545
+ tr.setSelection(TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head)));
36968
36546
  }
36969
36547
  }
36970
36548
  }
@@ -37745,7 +37323,7 @@ const setMeta = (view, key, value) => {
37745
37323
  };
37746
37324
  const absolutePositionToRelativePosition = (pos, type2, mapping) => {
37747
37325
  if (pos === 0) {
37748
- return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, type2.length === 0 ? -1 : 0);
37326
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, -1);
37749
37327
  }
37750
37328
  let n = type2._first === null ? null : (
37751
37329
  /** @type {Y.ContentType} */
@@ -37754,7 +37332,7 @@ const absolutePositionToRelativePosition = (pos, type2, mapping) => {
37754
37332
  while (n !== null && type2 !== n) {
37755
37333
  if (n instanceof Y__namespace.XmlText) {
37756
37334
  if (n._length >= pos) {
37757
- return Y__namespace.createRelativePositionFromTypeIndex(n, pos, type2.length === 0 ? -1 : 0);
37335
+ return Y__namespace.createRelativePositionFromTypeIndex(n, pos, -1);
37758
37336
  } else {
37759
37337
  pos -= n._length;
37760
37338
  }
@@ -37818,7 +37396,7 @@ const absolutePositionToRelativePosition = (pos, type2, mapping) => {
37818
37396
  return createRelativePosition(n._item.parent, n._item);
37819
37397
  }
37820
37398
  }
37821
- return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, type2.length === 0 ? -1 : 0);
37399
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, -1);
37822
37400
  };
37823
37401
  const createRelativePosition = (type2, item) => {
37824
37402
  let typeid = null;
@@ -38415,6 +37993,409 @@ function isExtensionRulesEnabled(extension, enabled) {
38415
37993
  }
38416
37994
  return enabled;
38417
37995
  }
37996
+ function getHTMLFromFragment(fragment, schema) {
37997
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
37998
+ const temporaryDocument = document.implementation.createHTMLDocument();
37999
+ const container = temporaryDocument.createElement("div");
38000
+ container.appendChild(documentFragment);
38001
+ return container.innerHTML;
38002
+ }
38003
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
38004
+ let textBefore = "";
38005
+ const sliceEndPos = $from.parentOffset;
38006
+ $from.parent.nodesBetween(
38007
+ Math.max(0, sliceEndPos - maxMatch),
38008
+ sliceEndPos,
38009
+ (node2, pos, parent, index2) => {
38010
+ const chunk = node2.type.spec.toText?.({
38011
+ node: node2,
38012
+ pos,
38013
+ parent,
38014
+ index: index2
38015
+ }) || node2.textContent || "%leaf%";
38016
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
38017
+ }
38018
+ );
38019
+ return textBefore;
38020
+ };
38021
+ const handleDocxPaste = (html, editor, view, plugin2) => {
38022
+ const { converter } = editor;
38023
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
38024
+ let cleanedHtml = convertEmToPt(html);
38025
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
38026
+ const tempDiv = document.createElement("div");
38027
+ tempDiv.innerHTML = cleanedHtml;
38028
+ const paragraphs = tempDiv.querySelectorAll("p");
38029
+ paragraphs.forEach((p) => {
38030
+ const innerHTML3 = p.innerHTML;
38031
+ if (!innerHTML3.includes("<!--[if !supportLists]")) return;
38032
+ const styleAttr = p.getAttribute("style") || "";
38033
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
38034
+ if (msoListMatch) {
38035
+ const [, abstractId, level] = msoListMatch;
38036
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
38037
+ if (!listNumId) return;
38038
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
38039
+ const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
38040
+ p.setAttribute("data-num-id", listNumId);
38041
+ p.setAttribute("data-list-level", level - 1);
38042
+ p.setAttribute("data-start", start2);
38043
+ p.setAttribute("data-lvl-text", lvlText);
38044
+ p.setAttribute("data-num-fmt", numFmt);
38045
+ }
38046
+ extractAndRemoveConditionalPrefix(p);
38047
+ });
38048
+ transformWordLists(tempDiv);
38049
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
38050
+ tempDiv.remove();
38051
+ const { dispatch } = editor.view;
38052
+ if (!dispatch) return false;
38053
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
38054
+ return true;
38055
+ };
38056
+ const getLevelDefinition = (abstractDefinition, level) => {
38057
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
38058
+ const levelElement = abstractDefinition.elements.find((el) => {
38059
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
38060
+ });
38061
+ if (!levelElement) return null;
38062
+ const { elements } = levelElement;
38063
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
38064
+ const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
38065
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
38066
+ return { lvlText, start: start2, numFmt, elements };
38067
+ };
38068
+ const getListNumIdFromAbstract = (abstractId, editor) => {
38069
+ const { definitions } = editor?.converter?.numbering;
38070
+ if (!definitions) return null;
38071
+ const matchedDefinition = Object.values(definitions).find((def) => {
38072
+ return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
38073
+ });
38074
+ return matchedDefinition?.attributes?.["w:numId"];
38075
+ };
38076
+ const getListAbstractDefinition = (abstractId, editor) => {
38077
+ const { abstracts = {} } = editor?.converter?.numbering;
38078
+ return abstracts[abstractId] || null;
38079
+ };
38080
+ const transformWordLists = (container) => {
38081
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
38082
+ const listMap = /* @__PURE__ */ new Map();
38083
+ const listLevels = {};
38084
+ for (const p of paragraphs) {
38085
+ const listId = p.getAttribute("data-num-id");
38086
+ const level = parseInt(p.getAttribute("data-list-level"));
38087
+ const numFmt = p.getAttribute("data-num-fmt");
38088
+ const start2 = p.getAttribute("data-start");
38089
+ const lvlText = p.getAttribute("data-lvl-text");
38090
+ if (!listMap.has(listId)) listMap.set(listId, []);
38091
+ listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
38092
+ }
38093
+ for (const [id, items] of listMap.entries()) {
38094
+ if (!listLevels[id]) {
38095
+ listLevels[id] = {
38096
+ stack: [],
38097
+ counts: {},
38098
+ prevLevel: null
38099
+ };
38100
+ }
38101
+ const parentStack = [];
38102
+ items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
38103
+ const listLevel = generateListNestingPath(listLevels, id, level);
38104
+ const li = document.createElement("li");
38105
+ li.innerHTML = p.innerHTML;
38106
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
38107
+ li.setAttribute("data-num-id", id);
38108
+ li.setAttribute("data-lvl-text", lvlText);
38109
+ li.setAttribute("data-num-fmt", numFmt);
38110
+ if (p.hasAttribute("data-font-family")) {
38111
+ li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
38112
+ }
38113
+ if (p.hasAttribute("data-font-size")) {
38114
+ li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
38115
+ }
38116
+ const parentNode2 = p.parentNode;
38117
+ let listForLevel = parentStack[level];
38118
+ if (!listForLevel) {
38119
+ const newList = document.createElement("ol");
38120
+ newList.setAttribute("data-list-id", id);
38121
+ newList.level = level;
38122
+ if (level > 0) {
38123
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
38124
+ if (parentLi) parentLi.appendChild(newList);
38125
+ } else {
38126
+ parentNode2.insertBefore(newList, p);
38127
+ }
38128
+ parentStack[level] = newList;
38129
+ parentStack.length = level + 1;
38130
+ listForLevel = newList;
38131
+ }
38132
+ listForLevel.appendChild(li);
38133
+ p.remove();
38134
+ });
38135
+ }
38136
+ };
38137
+ function generateListNestingPath(listLevels, listId, currentLevel) {
38138
+ const levelState = listLevels[listId];
38139
+ if (!levelState.stack) levelState.stack = [];
38140
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
38141
+ if (levelState.prevLevel === null) {
38142
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
38143
+ } else {
38144
+ if (currentLevel > levelState.prevLevel) {
38145
+ levelState.stack.push(1);
38146
+ } else if (currentLevel === levelState.prevLevel) {
38147
+ levelState.stack[levelState.stack.length - 1]++;
38148
+ } else {
38149
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
38150
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
38151
+ }
38152
+ }
38153
+ levelState.prevLevel = currentLevel;
38154
+ return [...levelState.stack];
38155
+ }
38156
+ function extractAndRemoveConditionalPrefix(p) {
38157
+ const nodes = Array.from(p.childNodes);
38158
+ let fontFamily2 = null;
38159
+ let fontSize2 = null;
38160
+ let start2 = -1, end2 = -1;
38161
+ nodes.forEach((node2, index2) => {
38162
+ if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
38163
+ start2 = index2;
38164
+ }
38165
+ if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
38166
+ end2 = index2;
38167
+ }
38168
+ });
38169
+ if (start2 !== -1 && end2 !== -1) {
38170
+ for (let i = start2 + 1; i < end2; i++) {
38171
+ const node2 = nodes[i];
38172
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
38173
+ fontFamily2 = fontFamily2 || node2.style.fontFamily;
38174
+ fontSize2 = fontSize2 || node2.style.fontSize;
38175
+ }
38176
+ }
38177
+ for (let i = end2; i >= start2; i--) {
38178
+ p.removeChild(p.childNodes[i]);
38179
+ }
38180
+ if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
38181
+ if (fontSize2) p.setAttribute("data-font-size", fontSize2);
38182
+ }
38183
+ }
38184
+ class InputRule {
38185
+ constructor(config) {
38186
+ __publicField$1(this, "match");
38187
+ __publicField$1(this, "handler");
38188
+ this.match = config.match;
38189
+ this.handler = config.handler;
38190
+ }
38191
+ }
38192
+ const inputRuleMatcherHandler = (text, match) => {
38193
+ if (isRegExp(match)) {
38194
+ return match.exec(text);
38195
+ }
38196
+ const inputRuleMatch = match(text);
38197
+ if (!inputRuleMatch) {
38198
+ return null;
38199
+ }
38200
+ const result = [inputRuleMatch.text];
38201
+ result.index = inputRuleMatch.index;
38202
+ result.input = text;
38203
+ result.data = inputRuleMatch.data;
38204
+ if (inputRuleMatch.replaceWith) {
38205
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
38206
+ console.warn(
38207
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
38208
+ );
38209
+ }
38210
+ result.push(inputRuleMatch.replaceWith);
38211
+ }
38212
+ return result;
38213
+ };
38214
+ const run = (config) => {
38215
+ const {
38216
+ editor,
38217
+ from: from2,
38218
+ to,
38219
+ text,
38220
+ rules,
38221
+ plugin: plugin2
38222
+ } = config;
38223
+ const { view } = editor;
38224
+ if (view.composing) {
38225
+ return false;
38226
+ }
38227
+ const $from = view.state.doc.resolve(from2);
38228
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
38229
+ return false;
38230
+ }
38231
+ let matched = false;
38232
+ const textBefore = getTextContentFromNodes($from) + text;
38233
+ rules.forEach((rule) => {
38234
+ if (matched) {
38235
+ return;
38236
+ }
38237
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
38238
+ if (!match) {
38239
+ return;
38240
+ }
38241
+ const tr = view.state.tr;
38242
+ const state2 = chainableEditorState(tr, view.state);
38243
+ const range2 = {
38244
+ from: from2 - (match[0].length - text.length),
38245
+ to
38246
+ };
38247
+ const { commands: commands2, chain, can } = new CommandService({
38248
+ editor,
38249
+ state: state2
38250
+ });
38251
+ const handler = rule.handler({
38252
+ state: state2,
38253
+ range: range2,
38254
+ match,
38255
+ commands: commands2,
38256
+ chain,
38257
+ can
38258
+ });
38259
+ if (handler === null || !tr.steps.length) {
38260
+ return;
38261
+ }
38262
+ tr.setMeta(plugin2, {
38263
+ transform: tr,
38264
+ from: from2,
38265
+ to,
38266
+ text
38267
+ });
38268
+ view.dispatch(tr);
38269
+ matched = true;
38270
+ });
38271
+ return matched;
38272
+ };
38273
+ const inputRulesPlugin = ({ editor, rules }) => {
38274
+ const plugin2 = new Plugin({
38275
+ key: new PluginKey("inputRulesPlugin"),
38276
+ state: {
38277
+ init() {
38278
+ return null;
38279
+ },
38280
+ apply(tr, prev, state2) {
38281
+ const stored = tr.getMeta(plugin2);
38282
+ if (stored) {
38283
+ return stored;
38284
+ }
38285
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
38286
+ const isSimulatedInput = !!simulatedInputMeta;
38287
+ if (isSimulatedInput) {
38288
+ setTimeout(() => {
38289
+ let { text } = simulatedInputMeta;
38290
+ if (typeof text !== "string") {
38291
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
38292
+ }
38293
+ const { from: from2 } = simulatedInputMeta;
38294
+ const to = from2 + text.length;
38295
+ run({
38296
+ editor,
38297
+ from: from2,
38298
+ to,
38299
+ text,
38300
+ rules,
38301
+ plugin: plugin2
38302
+ });
38303
+ });
38304
+ }
38305
+ return tr.selectionSet || tr.docChanged ? null : prev;
38306
+ }
38307
+ },
38308
+ props: {
38309
+ handleTextInput(view, from2, to, text) {
38310
+ return run({
38311
+ editor,
38312
+ from: from2,
38313
+ to,
38314
+ text,
38315
+ rules,
38316
+ plugin: plugin2
38317
+ });
38318
+ },
38319
+ // add support for input rules to trigger on enter
38320
+ // this is useful for example for code blocks
38321
+ handleKeyDown(view, event) {
38322
+ if (event.key !== "Enter") {
38323
+ return false;
38324
+ }
38325
+ const { $cursor } = view.state.selection;
38326
+ if ($cursor) {
38327
+ return run({
38328
+ editor,
38329
+ from: $cursor.pos,
38330
+ to: $cursor.pos,
38331
+ text: "\n",
38332
+ rules,
38333
+ plugin: plugin2
38334
+ });
38335
+ }
38336
+ return false;
38337
+ },
38338
+ // Paste handler
38339
+ handlePaste(view, event, slice2) {
38340
+ const clipboard = event.clipboardData;
38341
+ const html = clipboard.getData("text/html");
38342
+ clipboard.getData("text/plain");
38343
+ const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
38344
+ if (fieldAnnotationContent.length) {
38345
+ return false;
38346
+ }
38347
+ let source;
38348
+ if (!html) {
38349
+ source = "plain-text";
38350
+ } else if (isWordHtml(html)) {
38351
+ source = "word-html";
38352
+ } else {
38353
+ source = "browser-html";
38354
+ }
38355
+ switch (source) {
38356
+ case "plain-text":
38357
+ break;
38358
+ case "word-html":
38359
+ if (editor.options.mode === "docx") {
38360
+ return handleDocxPaste(html, editor, view, plugin2);
38361
+ }
38362
+ case "browser-html":
38363
+ return handleHtmlPaste$1(html, editor);
38364
+ }
38365
+ return false;
38366
+ }
38367
+ },
38368
+ isInputRules: true
38369
+ });
38370
+ return plugin2;
38371
+ };
38372
+ function isWordHtml(html) {
38373
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
38374
+ }
38375
+ const handleHtmlPaste$1 = (html, editor, plugin2) => {
38376
+ const cleanedHtml = convertEmToPt(html);
38377
+ const tempDiv = document.createElement("div");
38378
+ tempDiv.innerHTML = cleanedHtml;
38379
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
38380
+ tempDiv.remove();
38381
+ const { dispatch } = editor.view;
38382
+ if (!dispatch) return false;
38383
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
38384
+ return true;
38385
+ };
38386
+ const convertEmToPt = (html) => {
38387
+ return html.replace(
38388
+ /font-size\s*:\s*([\d.]+)em/gi,
38389
+ (_, emValue) => {
38390
+ const em = parseFloat(emValue);
38391
+ const pt = Math.round(em * 12 * 100) / 100;
38392
+ return `font-size: ${pt}pt`;
38393
+ }
38394
+ );
38395
+ };
38396
+ function cleanHtmlUnnecessaryTags(html) {
38397
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
38398
+ }
38418
38399
  const _ExtensionService = class _ExtensionService2 {
38419
38400
  constructor(extensions, userExtensions, editor) {
38420
38401
  __privateAdd$1(this, _ExtensionService_instances);
@@ -39253,7 +39234,6 @@ const createHeaderFooterEditor = ({
39253
39234
  mediaFiles: editor.storage.image.media,
39254
39235
  fonts: editor.options.fonts,
39255
39236
  isHeaderOrFooter: true,
39256
- isHeadless: editor.options.isHeadless,
39257
39237
  annotations: true,
39258
39238
  currentPageNumber,
39259
39239
  parentEditor: editor,
@@ -39261,15 +39241,13 @@ const createHeaderFooterEditor = ({
39261
39241
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
39262
39242
  });
39263
39243
  const pm = editorContainer.querySelector(".ProseMirror");
39264
- if (pm) {
39265
- pm.style.maxHeight = "100%";
39266
- pm.style.minHeight = "100%";
39267
- pm.style.outline = "none";
39268
- pm.style.border = "none";
39269
- pm.setAttribute("role", "textbox");
39270
- pm.setAttribute("aria-multiline", true);
39271
- pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
39272
- }
39244
+ pm.style.maxHeight = "100%";
39245
+ pm.style.minHeight = "100%";
39246
+ pm.style.outline = "none";
39247
+ pm.style.border = "none";
39248
+ pm.setAttribute("role", "textbox");
39249
+ pm.setAttribute("aria-multiline", true);
39250
+ pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
39273
39251
  return headerFooterEditor;
39274
39252
  };
39275
39253
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -39288,16 +39266,14 @@ const broadcastEditorEvents = (editor, sectionEditor) => {
39288
39266
  });
39289
39267
  });
39290
39268
  };
39291
- const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
39269
+ const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
39292
39270
  editor.converter.headerEditors.forEach((item) => {
39293
39271
  item.editor.setEditable(isEditMode, false);
39294
39272
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
39295
- item.editor.view.dom.setAttribute("documentmode", documentMode);
39296
39273
  });
39297
39274
  editor.converter.footerEditors.forEach((item) => {
39298
39275
  item.editor.setEditable(isEditMode, false);
39299
39276
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
39300
- item.editor.view.dom.setAttribute("documentmode", documentMode);
39301
39277
  });
39302
39278
  if (isEditMode) {
39303
39279
  const pm = document.querySelector(".ProseMirror");
@@ -40627,16 +40603,6 @@ const setWordSelection = (view, pos) => {
40627
40603
  const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
40628
40604
  dispatch(tr);
40629
40605
  };
40630
- const setImageNodeSelection = (view, pos) => {
40631
- const { doc: doc2 } = view.state;
40632
- const node2 = doc2.nodeAt(pos);
40633
- if (node2 && node2.type.name === "image") {
40634
- const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
40635
- view.dispatch(tr);
40636
- return true;
40637
- }
40638
- return false;
40639
- };
40640
40606
  const _Editor = class _Editor2 extends EventEmitter$1 {
40641
40607
  /**
40642
40608
  * Create a new Editor instance
@@ -40735,19 +40701,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40735
40701
  this.setHighContrastMode = setHighContrastMode;
40736
40702
  initMode();
40737
40703
  }
40738
- mount(el) {
40739
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this, el);
40740
- window.setTimeout(() => {
40741
- if (this.isDestroyed) return;
40742
- this.emit("create", { editor: this });
40743
- }, 0);
40744
- }
40745
- unmount() {
40746
- if (this.view) {
40747
- this.view.destroy();
40748
- }
40749
- this.view = null;
40750
- }
40751
40704
  /**
40752
40705
  * Set the toolbar for this editor
40753
40706
  * @param {Object} toolbar - The toolbar instance
@@ -40796,7 +40749,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40796
40749
  * @returns {boolean}
40797
40750
  */
40798
40751
  get isDestroyed() {
40799
- return this.view?.isDestroyed ?? true;
40752
+ return this.view.isDestroyed;
40800
40753
  }
40801
40754
  /**
40802
40755
  * Get the editor element
@@ -40839,12 +40792,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40839
40792
  this.commands.toggleTrackChangesShowOriginal();
40840
40793
  this.setEditable(false, false);
40841
40794
  this.setOptions({ documentMode: "viewing" });
40842
- toggleHeaderFooterEditMode({
40843
- editor: this,
40844
- focusedSectionEditor: null,
40845
- isEditMode: false,
40846
- documentMode: cleanedMode
40847
- });
40795
+ toggleHeaderFooterEditMode(this, null, false);
40848
40796
  } else if (cleanedMode === "suggesting") {
40849
40797
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
40850
40798
  this.commands.disableTrackChangesShowOriginal();
@@ -40857,12 +40805,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40857
40805
  this.commands.disableTrackChanges();
40858
40806
  this.setEditable(true, false);
40859
40807
  this.setOptions({ documentMode: "editing" });
40860
- toggleHeaderFooterEditMode({
40861
- editor: this,
40862
- focusedSectionEditor: null,
40863
- isEditMode: false,
40864
- documentMode: cleanedMode
40865
- });
40808
+ toggleHeaderFooterEditMode(this, null, false);
40866
40809
  }
40867
40810
  }
40868
40811
  /**
@@ -41039,26 +40982,29 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41039
40982
  };
41040
40983
  }
41041
40984
  /**
41042
- * Attach styles and attributes to the editor element
41043
- */
41044
- updateEditorStyles(element, proseMirror) {
40985
+ * Initialize default styles for the editor container and ProseMirror.
40986
+ * Get page size and margins from the converter.
40987
+ * Set document default font and font size.
40988
+ *
40989
+ * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
40990
+ * @returns {void}
40991
+ */
40992
+ initDefaultStyles(element = this.element) {
40993
+ if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
40994
+ const proseMirror = element?.querySelector(".ProseMirror");
41045
40995
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
41046
- if (!proseMirror || !element) {
40996
+ if (!proseMirror || !pageSize || !pageMargins) {
41047
40997
  return;
41048
40998
  }
41049
40999
  proseMirror.setAttribute("role", "document");
41050
41000
  proseMirror.setAttribute("aria-multiline", true);
41051
41001
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
41052
41002
  proseMirror.setAttribute("aria-description", "");
41053
- if (pageSize) {
41054
- element.style.width = pageSize.width + "in";
41055
- element.style.minWidth = pageSize.width + "in";
41056
- element.style.minHeight = pageSize.height + "in";
41057
- }
41058
- if (pageMargins) {
41059
- element.style.paddingLeft = pageMargins.left + "in";
41060
- element.style.paddingRight = pageMargins.right + "in";
41061
- }
41003
+ element.style.width = pageSize.width + "in";
41004
+ element.style.minWidth = pageSize.width + "in";
41005
+ element.style.minHeight = pageSize.height + "in";
41006
+ element.style.paddingLeft = pageMargins.left + "in";
41007
+ element.style.paddingRight = pageMargins.right + "in";
41062
41008
  element.style.boxSizing = "border-box";
41063
41009
  element.style.isolation = "isolate";
41064
41010
  proseMirror.style.outline = "none";
@@ -41079,19 +41025,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41079
41025
  proseMirror.style.paddingTop = "1in";
41080
41026
  proseMirror.style.paddingBottom = "1in";
41081
41027
  }
41082
- }
41083
- /**
41084
- * Initialize default styles for the editor container and ProseMirror.
41085
- * Get page size and margins from the converter.
41086
- * Set document default font and font size.
41087
- *
41088
- * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
41089
- * @returns {void}
41090
- */
41091
- initDefaultStyles(element = this.element) {
41092
- if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
41093
- const proseMirror = element?.querySelector(".ProseMirror");
41094
- this.updateEditorStyles(element, proseMirror);
41095
41028
  this.initMobileStyles(element);
41096
41029
  }
41097
41030
  /**
@@ -41303,22 +41236,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41303
41236
  */
41304
41237
  destroy() {
41305
41238
  this.emit("destroy");
41306
- this.unmount();
41307
- this.destroyHeaderFooterEditors();
41239
+ if (this.view) this.view.destroy();
41308
41240
  __privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
41309
41241
  this.removeAllListeners();
41310
41242
  }
41311
- destroyHeaderFooterEditors() {
41312
- const editors = [
41313
- ...this.converter.headerEditors,
41314
- ...this.converter.footerEditors
41315
- ];
41316
- for (let editorData of editors) {
41317
- editorData.editor.destroy();
41318
- }
41319
- this.converter.headerEditors.length = 0;
41320
- this.converter.footerEditors.length = 0;
41321
- }
41322
41243
  /**
41323
41244
  * Check if migrations are needed for the data
41324
41245
  * @static
@@ -41336,7 +41257,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41336
41257
  * @returns {Object | void} Migration results
41337
41258
  */
41338
41259
  processCollaborationMigrations() {
41339
- console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev8");
41260
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2");
41340
41261
  if (!this.options.ydoc) return;
41341
41262
  const metaMap = this.options.ydoc.getMap("meta");
41342
41263
  let docVersion = metaMap.get("version");
@@ -41380,7 +41301,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41380
41301
  __privateMethod$1(this, _Editor_instances, initMedia_fn).call(this);
41381
41302
  this.initDefaultStyles();
41382
41303
  if (this.options.ydoc && this.options.collaborationProvider) {
41383
- updateYdocDocxData(this);
41384
41304
  this.initializeCollaborationData(true);
41385
41305
  } else {
41386
41306
  __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
@@ -41532,7 +41452,7 @@ init_fn = function(options2) {
41532
41452
  this.emit("beforeCreate", { editor: this });
41533
41453
  this.on("contentError", this.options.onContentError);
41534
41454
  this.on("exception", this.options.onException);
41535
- this.mount(this.options.element);
41455
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
41536
41456
  this.initDefaultStyles();
41537
41457
  this.setDocumentMode(options2.documentMode);
41538
41458
  if (this.options.isHeadless) return;
@@ -41556,6 +41476,10 @@ init_fn = function(options2) {
41556
41476
  __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
41557
41477
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
41558
41478
  }
41479
+ window.setTimeout(() => {
41480
+ if (this.isDestroyed) return;
41481
+ this.emit("create", { editor: this });
41482
+ }, 0);
41559
41483
  };
41560
41484
  initRichText_fn = function(options2) {
41561
41485
  if (!options2.extensions || !options2.extensions.length) {
@@ -41567,7 +41491,7 @@ initRichText_fn = function(options2) {
41567
41491
  this.on("beforeCreate", this.options.onBeforeCreate);
41568
41492
  this.emit("beforeCreate", { editor: this });
41569
41493
  this.on("contentError", this.options.onContentError);
41570
- this.mount(this.options.element);
41494
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
41571
41495
  this.on("create", this.options.onCreate);
41572
41496
  this.on("update", this.options.onUpdate);
41573
41497
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -41578,6 +41502,10 @@ initRichText_fn = function(options2) {
41578
41502
  this.on("commentsLoaded", this.options.onCommentsLoaded);
41579
41503
  this.on("commentClick", this.options.onCommentClicked);
41580
41504
  this.on("locked", this.options.onDocumentLocked);
41505
+ window.setTimeout(() => {
41506
+ if (this.isDestroyed) return;
41507
+ this.emit("create", { editor: this });
41508
+ }, 0);
41581
41509
  };
41582
41510
  onFocus_fn = function({ editor, event }) {
41583
41511
  this.toolbar?.setActiveEditor(editor);
@@ -41698,15 +41626,14 @@ createDocFromHTML_fn = function(content) {
41698
41626
  }
41699
41627
  return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
41700
41628
  };
41701
- createView_fn = function(element) {
41629
+ createView_fn = function() {
41702
41630
  let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
41703
41631
  const state2 = { schema: this.schema };
41704
41632
  if (!this.options.ydoc) state2.doc = doc2;
41705
- this.view = new EditorView(element, {
41633
+ this.view = new EditorView(this.options.element, {
41706
41634
  ...this.options.editorProps,
41707
41635
  dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
41708
41636
  state: EditorState.create(state2),
41709
- handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
41710
41637
  handleDoubleClick: async (view, pos, event) => {
41711
41638
  if (this.options.documentMode !== "editing") return;
41712
41639
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -41720,12 +41647,7 @@ createView_fn = function(element) {
41720
41647
  event.stopPropagation();
41721
41648
  if (!this.options.editable) {
41722
41649
  this.setEditable(true, false);
41723
- toggleHeaderFooterEditMode({
41724
- editor: this,
41725
- focusedSectionEditor: null,
41726
- isEditMode: false,
41727
- documentMode: this.options.documentMode
41728
- });
41650
+ toggleHeaderFooterEditMode(this, null, false);
41729
41651
  const pm = document.querySelector(".ProseMirror");
41730
41652
  pm.classList.remove("header-footer-edit");
41731
41653
  pm.setAttribute("aria-readonly", false);
@@ -41738,6 +41660,8 @@ createView_fn = function(element) {
41738
41660
  });
41739
41661
  this.view.updateState(newState);
41740
41662
  this.createNodeViews();
41663
+ const dom = this.view.dom;
41664
+ dom.editor = this;
41741
41665
  this.options.telemetry?.sendReport();
41742
41666
  };
41743
41667
  onCollaborationReady_fn = function({ editor, ydoc }) {
@@ -41764,9 +41688,7 @@ initComments_fn = function() {
41764
41688
  }, 50);
41765
41689
  };
41766
41690
  initPagination_fn = async function() {
41767
- if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
41768
- return;
41769
- }
41691
+ if (this.options.isHeadless || !this.extensionService) return;
41770
41692
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
41771
41693
  if (pagination && this.options.pagination) {
41772
41694
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -41778,7 +41700,7 @@ initPagination_fn = async function() {
41778
41700
  }
41779
41701
  };
41780
41702
  dispatchTransaction_fn = function(transaction) {
41781
- if (this.isDestroyed) return;
41703
+ if (this.view.isDestroyed) return;
41782
41704
  let state2;
41783
41705
  try {
41784
41706
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -41830,11 +41752,6 @@ dispatchTransaction_fn = function(transaction) {
41830
41752
  transaction
41831
41753
  });
41832
41754
  };
41833
- handleNodeSelection_fn = function(view, pos) {
41834
- if (this.options.isHeaderOrFooter) {
41835
- return setImageNodeSelection(view, pos);
41836
- }
41837
- };
41838
41755
  prepareDocumentForImport_fn = function(doc2) {
41839
41756
  const newState = EditorState.create({
41840
41757
  schema: this.schema,
@@ -44177,7 +44094,7 @@ const Paragraph = Node$1.create({
44177
44094
  },
44178
44095
  addPmPlugins() {
44179
44096
  const { view } = this.editor;
44180
- new Plugin({
44097
+ const dropcapPlugin = new Plugin({
44181
44098
  name: "dropcapPlugin",
44182
44099
  key: new PluginKey("dropcapPlugin"),
44183
44100
  state: {
@@ -44197,7 +44114,7 @@ const Paragraph = Node$1.create({
44197
44114
  }
44198
44115
  }
44199
44116
  });
44200
- return [];
44117
+ return [dropcapPlugin];
44201
44118
  }
44202
44119
  });
44203
44120
  const getDropcapDecorations = (state2, view) => {
@@ -44550,16 +44467,7 @@ const HardBreak = Node$1.create({
44550
44467
  };
44551
44468
  },
44552
44469
  parseDOM() {
44553
- return [{
44554
- tag: 'span[linebreaktype="page"]',
44555
- getAttrs: (dom) => {
44556
- if (!(dom instanceof HTMLElement)) return false;
44557
- return {
44558
- pageBreakSource: dom.getAttribute("pagebreaksource") || null,
44559
- pageBreakType: dom.getAttribute("linebreaktype") || null
44560
- };
44561
- }
44562
- }];
44470
+ return [{ tag: "span" }];
44563
44471
  },
44564
44472
  renderDOM({ htmlAttributes }) {
44565
44473
  return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -47556,8 +47464,6 @@ function findRemovedFieldAnnotations(tr) {
47556
47464
  if (!tr.steps.length || tr.meta && !Object.keys(tr.meta).every((meta) => ["inputType", "uiEvent", "paste"].includes(meta)) || ["historyUndo", "historyRedo"].includes(tr.getMeta("inputType")) || ["drop"].includes(tr.getMeta("uiEvent")) || tr.getMeta("fieldAnnotationUpdate") === true) {
47557
47465
  return removedNodes;
47558
47466
  }
47559
- const hasDeletion = transactionDeletedAnything(tr);
47560
- if (!hasDeletion) return removedNodes;
47561
47467
  tr.steps.forEach((step, stepIndex) => {
47562
47468
  if (step instanceof ReplaceStep && step.from !== step.to) {
47563
47469
  let mapping = tr.mapping.maps[stepIndex];
@@ -47574,14 +47480,6 @@ function findRemovedFieldAnnotations(tr) {
47574
47480
  });
47575
47481
  return removedNodes;
47576
47482
  }
47577
- function transactionDeletedAnything(tr) {
47578
- return tr.steps.some((step) => {
47579
- if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
47580
- return step.from !== step.to;
47581
- }
47582
- return false;
47583
- });
47584
- }
47585
47483
  function trackFieldAnnotationsDeletion(editor, tr) {
47586
47484
  let removedAnnotations = [];
47587
47485
  try {
@@ -49107,16 +49005,12 @@ const startImageUpload = async ({ editor, view, file }) => {
49107
49005
  }
49108
49006
  let id = {};
49109
49007
  let { tr, schema } = view.state;
49110
- let { selection } = tr;
49111
- if (editor.options.isHeaderOrFooter) {
49112
- selection = editor.options.lastSelection;
49113
- }
49114
- if (!selection.empty && !editor.options.isHeaderOrFooter) {
49008
+ if (!tr.selection.empty) {
49115
49009
  tr.deleteSelection();
49116
49010
  }
49117
49011
  let imageMeta = {
49118
49012
  type: "add",
49119
- pos: selection.from,
49013
+ pos: tr.selection.from,
49120
49014
  id
49121
49015
  };
49122
49016
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -54365,8 +54259,7 @@ const Pagination = Extension.create({
54365
54259
  addStorage() {
54366
54260
  return {
54367
54261
  height: 0,
54368
- sectionData: null,
54369
- headerFooterEditors: /* @__PURE__ */ new Map()
54262
+ sectionData: null
54370
54263
  };
54371
54264
  },
54372
54265
  addCommands() {
@@ -54409,14 +54302,13 @@ const Pagination = Extension.create({
54409
54302
  shouldUpdate = true;
54410
54303
  shouldInitialize = meta.isReadyToInit;
54411
54304
  }
54412
- const syncMeta = tr.getMeta("y-sync$");
54413
- if (syncMeta && syncMeta.isChangeOrigin) {
54414
- return { ...oldState };
54415
- }
54416
54305
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
54417
54306
  if (imagePluginTransaction) {
54418
54307
  if (imagePluginTransaction.type === "remove") {
54419
- onImageLoad(editor);
54308
+ const imagePos = imagePluginTransaction.pos;
54309
+ const domImage = editor.view.domAtPos(imagePos).node.querySelector("img");
54310
+ if (domImage.complete) onImageLoad(editor);
54311
+ else domImage.onload = () => onImageLoad(editor);
54420
54312
  }
54421
54313
  return { ...oldState };
54422
54314
  }
@@ -54443,7 +54335,6 @@ const Pagination = Extension.create({
54443
54335
  if (isForceUpdate) shouldUpdate = true;
54444
54336
  return {
54445
54337
  ...oldState,
54446
- decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
54447
54338
  isReadyToInit: shouldInitialize
54448
54339
  };
54449
54340
  }
@@ -54472,10 +54363,6 @@ const Pagination = Extension.create({
54472
54363
  },
54473
54364
  onDestroy() {
54474
54365
  cleanupFloatingSeparators();
54475
- const { headerFooterEditors } = this.editor.storage.pagination;
54476
- if (headerFooterEditors) {
54477
- headerFooterEditors.clear();
54478
- }
54479
54366
  }
54480
54367
  });
54481
54368
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
@@ -54536,7 +54423,6 @@ const performUpdate = (editor, view, previousDecorations) => {
54536
54423
  const calculatePageBreaks = (view, editor, sectionData) => {
54537
54424
  if (!editor.converter) return DecorationSet.empty;
54538
54425
  const pageSize = editor.converter.pageStyles?.pageSize;
54539
- if (!pageSize) return DecorationSet.empty;
54540
54426
  const { width, height } = pageSize;
54541
54427
  if (!width || !height) return DecorationSet.empty;
54542
54428
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -54575,13 +54461,11 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
54575
54461
  let pageHeightThreshold = pageHeight;
54576
54462
  let footer = null, header = null;
54577
54463
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
54578
- const isFirstHeader = true;
54579
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
54464
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
54580
54465
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
54581
54466
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
54582
54467
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
54583
- const isLastFooter = true;
54584
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
54468
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
54585
54469
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
54586
54470
  let coords = view?.coordsAtPos(doc2.content.size);
54587
54471
  if (!coords) return [];
@@ -54600,8 +54484,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
54600
54484
  if (currentPageNumber === 1) {
54601
54485
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
54602
54486
  decorations.pop();
54603
- const isFirstHeader2 = true;
54604
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
54487
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
54605
54488
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
54606
54489
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
54607
54490
  }
@@ -54675,15 +54558,15 @@ function createFinalPagePadding(bufferHeight) {
54675
54558
  div2.style.height = bufferHeight + "px";
54676
54559
  return { nodeHeight: bufferHeight, node: div2 };
54677
54560
  }
54678
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
54679
- const headerDef = sectionData?.headers?.[headerId];
54561
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
54562
+ const headerDef = sectionData.headers?.[headerId];
54680
54563
  const minHeaderHeight = pageMargins.top * 96;
54681
54564
  const headerMargin = pageMargins.header * 96;
54682
54565
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
54683
54566
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
54684
54567
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
54685
54568
  const availableHeight = headerHeight - headerMargin;
54686
- let editorContainer = document.createElement("div");
54569
+ const editorContainer = document.createElement("div");
54687
54570
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
54688
54571
  headerId = "rId" + generateDocxRandomId();
54689
54572
  editor.converter.headerIds["default"] = headerId;
@@ -54695,31 +54578,23 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
54695
54578
  };
54696
54579
  }
54697
54580
  const data = editor.converter.headers[headerId];
54698
- const pageNumberIndex = currentPageNumber - 1;
54699
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
54700
- let editorSection = null;
54701
- const { headerFooterEditors } = editor.storage.pagination;
54702
- if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
54703
- const editorData = headerFooterEditors.get(editorKey);
54704
- editorSection = editorData.editor;
54705
- editorContainer = editorSection.element;
54706
- } else {
54707
- editorSection = createHeaderFooterEditor({
54708
- editor,
54709
- data,
54710
- editorContainer,
54711
- appendToBody: false,
54712
- sectionId: headerId,
54713
- type: "header",
54714
- availableHeight,
54715
- currentPageNumber
54716
- });
54717
- editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
54718
- headerFooterEditors.set(editorKey, { editor: editorSection });
54719
- broadcastEditorEvents(editor, editorSection);
54720
- }
54581
+ const editorSection = createHeaderFooterEditor({
54582
+ editor,
54583
+ data,
54584
+ editorContainer,
54585
+ appendToBody: false,
54586
+ sectionId: headerId,
54587
+ type: "header",
54588
+ availableHeight,
54589
+ currentPageNumber
54590
+ });
54591
+ editor.converter.headerEditors.push({
54592
+ id: headerId,
54593
+ editor: editorSection
54594
+ });
54721
54595
  editorSection.setEditable(false, false);
54722
- editorContainer.classList.add("pagination-section-header");
54596
+ broadcastEditorEvents(editor, editorSection);
54597
+ editorContainer.className = "pagination-section-header";
54723
54598
  editorContainer.style.paddingTop = headerMargin + "px";
54724
54599
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
54725
54600
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -54732,12 +54607,12 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
54732
54607
  headerHeight
54733
54608
  };
54734
54609
  }
54735
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
54736
- const footerDef = sectionData?.footers?.[footerId];
54610
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
54611
+ const footerDef = sectionData.footers?.[footerId];
54737
54612
  const minFooterHeight = pageMargins.bottom * 96;
54738
54613
  const footerPaddingFromEdge = pageMargins.footer * 96;
54739
54614
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
54740
- let editorContainer = document.createElement("div");
54615
+ const editorContainer = document.createElement("div");
54741
54616
  if (!footerId && !editor.converter.footerIds["default"]) {
54742
54617
  footerId = "rId" + generateDocxRandomId();
54743
54618
  editor.converter.footerIds["default"] = footerId;
@@ -54749,31 +54624,23 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
54749
54624
  };
54750
54625
  }
54751
54626
  const data = editor.converter.footers[footerId];
54752
- const pageNumberIndex = currentPageNumber - 1;
54753
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
54754
- let editorSection = null;
54755
- const { headerFooterEditors } = editor.storage.pagination;
54756
- if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
54757
- const editorData = headerFooterEditors.get(editorKey);
54758
- editorSection = editorData.editor;
54759
- editorContainer = editorSection.element;
54760
- } else {
54761
- editorSection = createHeaderFooterEditor({
54762
- editor,
54763
- data,
54764
- editorContainer,
54765
- appendToBody: false,
54766
- sectionId: footerId,
54767
- type: "footer",
54768
- availableHeight: footerHeight,
54769
- currentPageNumber
54770
- });
54771
- editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
54772
- headerFooterEditors.set(editorKey, { editor: editorSection });
54773
- broadcastEditorEvents(editor, editorSection);
54774
- }
54627
+ const editorSection = createHeaderFooterEditor({
54628
+ editor,
54629
+ data,
54630
+ editorContainer,
54631
+ appendToBody: false,
54632
+ sectionId: footerId,
54633
+ type: "footer",
54634
+ availableHeight: footerHeight,
54635
+ currentPageNumber
54636
+ });
54637
+ editor.converter.footerEditors.push({
54638
+ id: footerId,
54639
+ editor: editorSection
54640
+ });
54775
54641
  editorSection.setEditable(false, false);
54776
- editorContainer.classList.add("pagination-section-footer");
54642
+ broadcastEditorEvents(editor, editorSection);
54643
+ editorContainer.className = "pagination-section-footer";
54777
54644
  editorContainer.style.height = footerHeight + "px";
54778
54645
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
54779
54646
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -54786,28 +54653,10 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
54786
54653
  footerHeight: footerHeight + footerPaddingFromEdge
54787
54654
  };
54788
54655
  }
54789
- const getHeaderFooterEditorKey = ({
54790
- pageNumber,
54791
- isHeader,
54792
- isFooter,
54793
- isFirstHeader = false,
54794
- isLastFooter = false
54795
- }) => {
54796
- if (isFirstHeader) return `first-header-${pageNumber}`;
54797
- if (isLastFooter) return `last-footer-${pageNumber}`;
54798
- if (isHeader) return `header-${pageNumber}`;
54799
- if (isFooter) return `footer-${pageNumber}`;
54800
- return void 0;
54801
- };
54802
54656
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
54803
54657
  if (editor.options.documentMode !== "editing") return;
54804
54658
  editor.setEditable(false, false);
54805
- toggleHeaderFooterEditMode({
54806
- editor,
54807
- focusedSectionEditor: currentFocusedSectionEditor,
54808
- isEditMode: true,
54809
- documentMode: editor.options.documentMode
54810
- });
54659
+ toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
54811
54660
  };
54812
54661
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
54813
54662
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -55362,7 +55211,7 @@ const Search = Extension.create({
55362
55211
  }
55363
55212
  });
55364
55213
  const NodeResizerKey = new PluginKey("node-resizer");
55365
- const nodeResizer = (nodeNames = ["image"], editor) => {
55214
+ const nodeResizer = (nodeNames = ["image"]) => {
55366
55215
  let resizeState = {
55367
55216
  dragging: false,
55368
55217
  startX: 0,
@@ -55387,13 +55236,8 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
55387
55236
  if (tr.getMeta(NodeResizerKey)) {
55388
55237
  return oldState;
55389
55238
  }
55390
- if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
55391
- const { selection } = newState;
55392
- const node2 = selection.node;
55393
- if (!node2 || !nodeNames.includes(node2.type.name)) {
55394
- return DecorationSet.empty;
55395
- }
55396
55239
  const decorations = [];
55240
+ const { selection } = newState;
55397
55241
  if (nodeNames.includes(selection.node?.type.name)) {
55398
55242
  decorations.push(
55399
55243
  Decoration.node(selection.from, selection.to, {
@@ -55596,7 +55440,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
55596
55440
  const NodeResizer = Extension.create({
55597
55441
  name: "nodeResizer",
55598
55442
  addPmPlugins() {
55599
- return [nodeResizer(["image"], this.editor)];
55443
+ return [nodeResizer(["image"])];
55600
55444
  }
55601
55445
  });
55602
55446
  const getRichTextExtensions = () => {
@@ -64272,6 +64116,7 @@ const style$2 = cB("icon", `
64272
64116
  display: inline-block;
64273
64117
  position: relative;
64274
64118
  fill: currentColor;
64119
+ transform: translateZ(0);
64275
64120
  `, [cM("color-transition", {
64276
64121
  transition: "color .3s var(--n-bezier)"
64277
64122
  }), cM("depth", {