@harbour-enterprises/superdoc 0.13.2-rev9 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/chunks/{eventemitter3-KKY27oz-.es.js → eventemitter3-BrspJk8q.es.js} +1 -1
  2. package/dist/chunks/{eventemitter3-CHxWXmuK.cjs → eventemitter3-DfVviFzP.cjs} +1 -1
  3. package/dist/chunks/{index-CweAXNfB.cjs → index-B4J7wgs6.cjs} +2 -2
  4. package/dist/chunks/{index-kOMfCfBT.cjs → index-Cdsq63Xq.cjs} +4 -4
  5. package/dist/chunks/{index-DS3W0eVB.es.js → index-Diu6UKHt.es.js} +4 -4
  6. package/dist/chunks/{index-BqLFjUHn.es.js → index-Hr3Um-Bg.es.js} +2 -2
  7. package/dist/chunks/{jszip-9bCX1h2W.cjs → jszip-BTAcmbVg.cjs} +1 -1
  8. package/dist/chunks/{jszip-Cl3s9njw.es.js → jszip-DckFs3A7.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-TaswSSDL.cjs → super-editor.es-BM89AzsN.cjs} +811 -1088
  10. package/dist/chunks/{super-editor.es-BE0HKCoV.es.js → super-editor.es-BNyzbCw0.es.js} +811 -1088
  11. package/dist/chunks/{url-B8LY3nwf.cjs → url-BIzg4y2i.cjs} +2 -2
  12. package/dist/chunks/{url-Bq00tGvm.es.js → url-CHayXMZH.es.js} +2 -2
  13. package/dist/chunks/{vue-BBJVqxjL.es.js → vue-Bi1uWinj.es.js} +3 -10
  14. package/dist/chunks/{vue-BBjMeYfo.cjs → vue-HIY1g7dm.cjs} +3 -10
  15. package/dist/chunks/{xml-js-BuAdLsHD.cjs → xml-js-BjqmFOSP.cjs} +102 -81
  16. package/dist/chunks/{xml-js-1F0lia4t.es.js → xml-js-CfClL-1b.es.js} +102 -81
  17. package/dist/style.css +1 -2
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-BvRopd2F.js → converter-CsK9KCaL.js} +55 -637
  20. package/dist/super-editor/chunks/{docx-zipper-CZ8M74hv.js → docx-zipper-6iKmmME2.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-D1rD0fdS.js → editor-Cxb-Zwyu.js} +685 -387
  22. package/dist/super-editor/chunks/{toolbar-CvP4K1yD.js → toolbar-QHIHaeEf.js} +3 -2
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +0 -7
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +0 -7
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +0 -4
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  31. package/dist/super-editor/docx-zipper.es.js +2 -2
  32. package/dist/super-editor/editor.es.js +3 -3
  33. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  34. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  35. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +1 -6
  39. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  41. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  42. package/dist/super-editor/file-zipper.es.js +1 -1
  43. package/dist/super-editor/style.css +1 -2
  44. package/dist/super-editor/super-editor.es.js +7 -7
  45. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  46. package/dist/super-editor/toolbar.es.js +2 -2
  47. package/dist/super-editor.cjs +2 -2
  48. package/dist/super-editor.es.js +2 -2
  49. package/dist/superdoc.cjs +9 -8
  50. package/dist/superdoc.es.js +10 -9
  51. package/dist/superdoc.umd.js +815 -1098
  52. package/dist/superdoc.umd.js.map +1 -1
  53. package/package.json +1 -1
  54. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +0 -2
  55. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +0 -1
  56. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +0 -3
  57. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +0 -1
@@ -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-rev9") {
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-rev9") {
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;
@@ -38309,111 +37887,514 @@ var shift = {
38309
37887
  221: "}",
38310
37888
  222: '"'
38311
37889
  };
38312
- var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
38313
- var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
38314
- for (var i = 0; i < 10; i++) base$1[48 + i] = base$1[96 + i] = String(i);
38315
- for (var i = 1; i <= 24; i++) base$1[i + 111] = "F" + i;
38316
- for (var i = 65; i <= 90; i++) {
38317
- base$1[i] = String.fromCharCode(i + 32);
38318
- shift[i] = String.fromCharCode(i);
38319
- }
38320
- for (var code in base$1) if (!shift.hasOwnProperty(code)) shift[code] = base$1[code];
38321
- function keyName(event) {
38322
- var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
38323
- var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$1)[event.keyCode] || event.key || "Unidentified";
38324
- if (name == "Esc") name = "Escape";
38325
- if (name == "Del") name = "Delete";
38326
- if (name == "Left") name = "ArrowLeft";
38327
- if (name == "Up") name = "ArrowUp";
38328
- if (name == "Right") name = "ArrowRight";
38329
- if (name == "Down") name = "ArrowDown";
38330
- return name;
38331
- }
38332
- const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
38333
- const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
38334
- function normalizeKeyName(name) {
38335
- let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
38336
- if (result == "Space")
38337
- result = " ";
38338
- let alt, ctrl, shift2, meta;
38339
- for (let i = 0; i < parts.length - 1; i++) {
38340
- let mod = parts[i];
38341
- if (/^(cmd|meta|m)$/i.test(mod))
38342
- meta = true;
38343
- else if (/^a(lt)?$/i.test(mod))
38344
- alt = true;
38345
- else if (/^(c|ctrl|control)$/i.test(mod))
38346
- ctrl = true;
38347
- else if (/^s(hift)?$/i.test(mod))
38348
- shift2 = true;
38349
- else if (/^mod$/i.test(mod)) {
38350
- if (mac)
38351
- meta = true;
38352
- else
38353
- ctrl = true;
38354
- } else
38355
- throw new Error("Unrecognized modifier name: " + mod);
37890
+ var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
37891
+ var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
37892
+ for (var i = 0; i < 10; i++) base$1[48 + i] = base$1[96 + i] = String(i);
37893
+ for (var i = 1; i <= 24; i++) base$1[i + 111] = "F" + i;
37894
+ for (var i = 65; i <= 90; i++) {
37895
+ base$1[i] = String.fromCharCode(i + 32);
37896
+ shift[i] = String.fromCharCode(i);
37897
+ }
37898
+ for (var code in base$1) if (!shift.hasOwnProperty(code)) shift[code] = base$1[code];
37899
+ function keyName(event) {
37900
+ var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
37901
+ var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$1)[event.keyCode] || event.key || "Unidentified";
37902
+ if (name == "Esc") name = "Escape";
37903
+ if (name == "Del") name = "Delete";
37904
+ if (name == "Left") name = "ArrowLeft";
37905
+ if (name == "Up") name = "ArrowUp";
37906
+ if (name == "Right") name = "ArrowRight";
37907
+ if (name == "Down") name = "ArrowDown";
37908
+ return name;
37909
+ }
37910
+ const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
37911
+ const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
37912
+ function normalizeKeyName(name) {
37913
+ let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
37914
+ if (result == "Space")
37915
+ result = " ";
37916
+ let alt, ctrl, shift2, meta;
37917
+ for (let i = 0; i < parts.length - 1; i++) {
37918
+ let mod = parts[i];
37919
+ if (/^(cmd|meta|m)$/i.test(mod))
37920
+ meta = true;
37921
+ else if (/^a(lt)?$/i.test(mod))
37922
+ alt = true;
37923
+ else if (/^(c|ctrl|control)$/i.test(mod))
37924
+ ctrl = true;
37925
+ else if (/^s(hift)?$/i.test(mod))
37926
+ shift2 = true;
37927
+ else if (/^mod$/i.test(mod)) {
37928
+ if (mac)
37929
+ meta = true;
37930
+ else
37931
+ ctrl = true;
37932
+ } else
37933
+ throw new Error("Unrecognized modifier name: " + mod);
37934
+ }
37935
+ if (alt)
37936
+ result = "Alt-" + result;
37937
+ if (ctrl)
37938
+ result = "Ctrl-" + result;
37939
+ if (meta)
37940
+ result = "Meta-" + result;
37941
+ if (shift2)
37942
+ result = "Shift-" + result;
37943
+ return result;
37944
+ }
37945
+ function normalize(map22) {
37946
+ let copy2 = /* @__PURE__ */ Object.create(null);
37947
+ for (let prop in map22)
37948
+ copy2[normalizeKeyName(prop)] = map22[prop];
37949
+ return copy2;
37950
+ }
37951
+ function modifiers(name, event, shift2 = true) {
37952
+ if (event.altKey)
37953
+ name = "Alt-" + name;
37954
+ if (event.ctrlKey)
37955
+ name = "Ctrl-" + name;
37956
+ if (event.metaKey)
37957
+ name = "Meta-" + name;
37958
+ if (shift2 && event.shiftKey)
37959
+ name = "Shift-" + name;
37960
+ return name;
37961
+ }
37962
+ function keymap(bindings) {
37963
+ return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
37964
+ }
37965
+ function keydownHandler(bindings) {
37966
+ let map22 = normalize(bindings);
37967
+ return function(view, event) {
37968
+ let name = keyName(event), baseName, direct = map22[modifiers(name, event)];
37969
+ if (direct && direct(view.state, view.dispatch, view))
37970
+ return true;
37971
+ if (name.length == 1 && name != " ") {
37972
+ if (event.shiftKey) {
37973
+ let noShift = map22[modifiers(name, event, false)];
37974
+ if (noShift && noShift(view.state, view.dispatch, view))
37975
+ return true;
37976
+ }
37977
+ if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
37978
+ !(windows && event.ctrlKey && event.altKey) && (baseName = base$1[event.keyCode]) && baseName != name) {
37979
+ let fromCode = map22[modifiers(baseName, event)];
37980
+ if (fromCode && fromCode(view.state, view.dispatch, view))
37981
+ return true;
37982
+ }
37983
+ }
37984
+ return false;
37985
+ };
37986
+ }
37987
+ function isExtensionRulesEnabled(extension, enabled) {
37988
+ if (Array.isArray(enabled)) {
37989
+ return enabled.some((enabledExtension) => {
37990
+ const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
37991
+ return name === extension.name;
37992
+ });
37993
+ }
37994
+ return enabled;
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
+ }
38356
38152
  }
38357
- if (alt)
38358
- result = "Alt-" + result;
38359
- if (ctrl)
38360
- result = "Ctrl-" + result;
38361
- if (meta)
38362
- result = "Meta-" + result;
38363
- if (shift2)
38364
- result = "Shift-" + result;
38365
- return result;
38366
- }
38367
- function normalize(map22) {
38368
- let copy2 = /* @__PURE__ */ Object.create(null);
38369
- for (let prop in map22)
38370
- copy2[normalizeKeyName(prop)] = map22[prop];
38371
- return copy2;
38153
+ levelState.prevLevel = currentLevel;
38154
+ return [...levelState.stack];
38372
38155
  }
38373
- function modifiers(name, event, shift2 = true) {
38374
- if (event.altKey)
38375
- name = "Alt-" + name;
38376
- if (event.ctrlKey)
38377
- name = "Ctrl-" + name;
38378
- if (event.metaKey)
38379
- name = "Meta-" + name;
38380
- if (shift2 && event.shiftKey)
38381
- name = "Shift-" + name;
38382
- return name;
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
+ }
38383
38183
  }
38384
- function keymap(bindings) {
38385
- return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
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
+ }
38386
38191
  }
38387
- function keydownHandler(bindings) {
38388
- let map22 = normalize(bindings);
38389
- return function(view, event) {
38390
- let name = keyName(event), baseName, direct = map22[modifiers(name, event)];
38391
- if (direct && direct(view.state, view.dispatch, view))
38392
- return true;
38393
- if (name.length == 1 && name != " ") {
38394
- if (event.shiftKey) {
38395
- let noShift = map22[modifiers(name, event, false)];
38396
- if (noShift && noShift(view.state, view.dispatch, view))
38397
- return true;
38398
- }
38399
- if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
38400
- !(windows && event.ctrlKey && event.altKey) && (baseName = base$1[event.keyCode]) && baseName != name) {
38401
- let fromCode = map22[modifiers(baseName, event)];
38402
- if (fromCode && fromCode(view.state, view.dispatch, view))
38403
- return true;
38404
- }
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
+ );
38405
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) {
38406
38225
  return false;
38407
- };
38408
- }
38409
- function isExtensionRulesEnabled(extension, enabled) {
38410
- if (Array.isArray(enabled)) {
38411
- return enabled.some((enabledExtension) => {
38412
- const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
38413
- return name === extension.name;
38414
- });
38415
38226
  }
38416
- return enabled;
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();
38417
38398
  }
38418
38399
  const _ExtensionService = class _ExtensionService2 {
38419
38400
  constructor(extensions, userExtensions, editor) {
@@ -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");
@@ -40378,19 +40354,6 @@ const deleteHeaderFooterFieldAnnotations = ({ editor, fieldIdOrArray }) => {
40378
40354
  );
40379
40355
  });
40380
40356
  };
40381
- const resetHeaderFooterFieldAnnotations = ({ editor }) => {
40382
- if (!editor) return;
40383
- const sectionEditors = getAllHeaderFooterEditors(editor);
40384
- sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
40385
- sectionEditor.commands.resetFieldAnnotations();
40386
- onHeaderFooterDataUpdate(
40387
- { editor: sectionEditor },
40388
- editor,
40389
- sectionId,
40390
- type2
40391
- );
40392
- });
40393
- };
40394
40357
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
40395
40358
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
40396
40359
  const { doc: doc2 } = editor.state;
@@ -40461,7 +40424,6 @@ const AnnotatorHelpers = {
40461
40424
  getAllHeaderFooterEditors,
40462
40425
  updateHeaderFooterFieldAnnotations,
40463
40426
  deleteHeaderFooterFieldAnnotations,
40464
- resetHeaderFooterFieldAnnotations,
40465
40427
  cleanUpListsWithAnnotations
40466
40428
  };
40467
40429
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -40641,16 +40603,6 @@ const setWordSelection = (view, pos) => {
40641
40603
  const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
40642
40604
  dispatch(tr);
40643
40605
  };
40644
- const setImageNodeSelection = (view, pos) => {
40645
- const { doc: doc2 } = view.state;
40646
- const node2 = doc2.nodeAt(pos);
40647
- if (node2 && node2.type.name === "image") {
40648
- const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
40649
- view.dispatch(tr);
40650
- return true;
40651
- }
40652
- return false;
40653
- };
40654
40606
  const _Editor = class _Editor2 extends EventEmitter$1 {
40655
40607
  /**
40656
40608
  * Create a new Editor instance
@@ -40749,19 +40701,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40749
40701
  this.setHighContrastMode = setHighContrastMode;
40750
40702
  initMode();
40751
40703
  }
40752
- mount(el) {
40753
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this, el);
40754
- window.setTimeout(() => {
40755
- if (this.isDestroyed) return;
40756
- this.emit("create", { editor: this });
40757
- }, 0);
40758
- }
40759
- unmount() {
40760
- if (this.view) {
40761
- this.view.destroy();
40762
- }
40763
- this.view = null;
40764
- }
40765
40704
  /**
40766
40705
  * Set the toolbar for this editor
40767
40706
  * @param {Object} toolbar - The toolbar instance
@@ -40810,7 +40749,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40810
40749
  * @returns {boolean}
40811
40750
  */
40812
40751
  get isDestroyed() {
40813
- return this.view?.isDestroyed ?? true;
40752
+ return this.view.isDestroyed;
40814
40753
  }
40815
40754
  /**
40816
40755
  * Get the editor element
@@ -40853,12 +40792,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40853
40792
  this.commands.toggleTrackChangesShowOriginal();
40854
40793
  this.setEditable(false, false);
40855
40794
  this.setOptions({ documentMode: "viewing" });
40856
- toggleHeaderFooterEditMode({
40857
- editor: this,
40858
- focusedSectionEditor: null,
40859
- isEditMode: false,
40860
- documentMode: cleanedMode
40861
- });
40795
+ toggleHeaderFooterEditMode(this, null, false);
40862
40796
  } else if (cleanedMode === "suggesting") {
40863
40797
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
40864
40798
  this.commands.disableTrackChangesShowOriginal();
@@ -40871,12 +40805,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40871
40805
  this.commands.disableTrackChanges();
40872
40806
  this.setEditable(true, false);
40873
40807
  this.setOptions({ documentMode: "editing" });
40874
- toggleHeaderFooterEditMode({
40875
- editor: this,
40876
- focusedSectionEditor: null,
40877
- isEditMode: false,
40878
- documentMode: cleanedMode
40879
- });
40808
+ toggleHeaderFooterEditMode(this, null, false);
40880
40809
  }
40881
40810
  }
40882
40811
  /**
@@ -41053,26 +40982,29 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41053
40982
  };
41054
40983
  }
41055
40984
  /**
41056
- * Attach styles and attributes to the editor element
41057
- */
41058
- 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");
41059
40995
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
41060
- if (!proseMirror || !element) {
40996
+ if (!proseMirror || !pageSize || !pageMargins) {
41061
40997
  return;
41062
40998
  }
41063
40999
  proseMirror.setAttribute("role", "document");
41064
41000
  proseMirror.setAttribute("aria-multiline", true);
41065
41001
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
41066
41002
  proseMirror.setAttribute("aria-description", "");
41067
- if (pageSize) {
41068
- element.style.width = pageSize.width + "in";
41069
- element.style.minWidth = pageSize.width + "in";
41070
- element.style.minHeight = pageSize.height + "in";
41071
- }
41072
- if (pageMargins) {
41073
- element.style.paddingLeft = pageMargins.left + "in";
41074
- element.style.paddingRight = pageMargins.right + "in";
41075
- }
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";
41076
41008
  element.style.boxSizing = "border-box";
41077
41009
  element.style.isolation = "isolate";
41078
41010
  proseMirror.style.outline = "none";
@@ -41093,19 +41025,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41093
41025
  proseMirror.style.paddingTop = "1in";
41094
41026
  proseMirror.style.paddingBottom = "1in";
41095
41027
  }
41096
- }
41097
- /**
41098
- * Initialize default styles for the editor container and ProseMirror.
41099
- * Get page size and margins from the converter.
41100
- * Set document default font and font size.
41101
- *
41102
- * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
41103
- * @returns {void}
41104
- */
41105
- initDefaultStyles(element = this.element) {
41106
- if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
41107
- const proseMirror = element?.querySelector(".ProseMirror");
41108
- this.updateEditorStyles(element, proseMirror);
41109
41028
  this.initMobileStyles(element);
41110
41029
  }
41111
41030
  /**
@@ -41317,25 +41236,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41317
41236
  */
41318
41237
  destroy() {
41319
41238
  this.emit("destroy");
41320
- this.unmount();
41321
- this.destroyHeaderFooterEditors();
41239
+ if (this.view) this.view.destroy();
41322
41240
  __privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
41323
41241
  this.removeAllListeners();
41324
41242
  }
41325
- destroyHeaderFooterEditors() {
41326
- try {
41327
- const editors = [
41328
- ...this.converter.headerEditors,
41329
- ...this.converter.footerEditors
41330
- ];
41331
- for (let editorData of editors) {
41332
- editorData.editor.destroy();
41333
- }
41334
- this.converter.headerEditors.length = 0;
41335
- this.converter.footerEditors.length = 0;
41336
- } catch (error) {
41337
- }
41338
- }
41339
41243
  /**
41340
41244
  * Check if migrations are needed for the data
41341
41245
  * @static
@@ -41353,7 +41257,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41353
41257
  * @returns {Object | void} Migration results
41354
41258
  */
41355
41259
  processCollaborationMigrations() {
41356
- console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev9");
41260
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2");
41357
41261
  if (!this.options.ydoc) return;
41358
41262
  const metaMap = this.options.ydoc.getMap("meta");
41359
41263
  let docVersion = metaMap.get("version");
@@ -41397,7 +41301,6 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41397
41301
  __privateMethod$1(this, _Editor_instances, initMedia_fn).call(this);
41398
41302
  this.initDefaultStyles();
41399
41303
  if (this.options.ydoc && this.options.collaborationProvider) {
41400
- updateYdocDocxData(this);
41401
41304
  this.initializeCollaborationData(true);
41402
41305
  } else {
41403
41306
  __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
@@ -41549,7 +41452,7 @@ init_fn = function(options2) {
41549
41452
  this.emit("beforeCreate", { editor: this });
41550
41453
  this.on("contentError", this.options.onContentError);
41551
41454
  this.on("exception", this.options.onException);
41552
- this.mount(this.options.element);
41455
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
41553
41456
  this.initDefaultStyles();
41554
41457
  this.setDocumentMode(options2.documentMode);
41555
41458
  if (this.options.isHeadless) return;
@@ -41573,6 +41476,10 @@ init_fn = function(options2) {
41573
41476
  __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
41574
41477
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
41575
41478
  }
41479
+ window.setTimeout(() => {
41480
+ if (this.isDestroyed) return;
41481
+ this.emit("create", { editor: this });
41482
+ }, 0);
41576
41483
  };
41577
41484
  initRichText_fn = function(options2) {
41578
41485
  if (!options2.extensions || !options2.extensions.length) {
@@ -41584,7 +41491,7 @@ initRichText_fn = function(options2) {
41584
41491
  this.on("beforeCreate", this.options.onBeforeCreate);
41585
41492
  this.emit("beforeCreate", { editor: this });
41586
41493
  this.on("contentError", this.options.onContentError);
41587
- this.mount(this.options.element);
41494
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
41588
41495
  this.on("create", this.options.onCreate);
41589
41496
  this.on("update", this.options.onUpdate);
41590
41497
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -41595,6 +41502,10 @@ initRichText_fn = function(options2) {
41595
41502
  this.on("commentsLoaded", this.options.onCommentsLoaded);
41596
41503
  this.on("commentClick", this.options.onCommentClicked);
41597
41504
  this.on("locked", this.options.onDocumentLocked);
41505
+ window.setTimeout(() => {
41506
+ if (this.isDestroyed) return;
41507
+ this.emit("create", { editor: this });
41508
+ }, 0);
41598
41509
  };
41599
41510
  onFocus_fn = function({ editor, event }) {
41600
41511
  this.toolbar?.setActiveEditor(editor);
@@ -41715,15 +41626,14 @@ createDocFromHTML_fn = function(content) {
41715
41626
  }
41716
41627
  return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
41717
41628
  };
41718
- createView_fn = function(element) {
41629
+ createView_fn = function() {
41719
41630
  let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
41720
41631
  const state2 = { schema: this.schema };
41721
41632
  if (!this.options.ydoc) state2.doc = doc2;
41722
- this.view = new EditorView(element, {
41633
+ this.view = new EditorView(this.options.element, {
41723
41634
  ...this.options.editorProps,
41724
41635
  dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
41725
41636
  state: EditorState.create(state2),
41726
- handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
41727
41637
  handleDoubleClick: async (view, pos, event) => {
41728
41638
  if (this.options.documentMode !== "editing") return;
41729
41639
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -41737,12 +41647,7 @@ createView_fn = function(element) {
41737
41647
  event.stopPropagation();
41738
41648
  if (!this.options.editable) {
41739
41649
  this.setEditable(true, false);
41740
- toggleHeaderFooterEditMode({
41741
- editor: this,
41742
- focusedSectionEditor: null,
41743
- isEditMode: false,
41744
- documentMode: this.options.documentMode
41745
- });
41650
+ toggleHeaderFooterEditMode(this, null, false);
41746
41651
  const pm = document.querySelector(".ProseMirror");
41747
41652
  pm.classList.remove("header-footer-edit");
41748
41653
  pm.setAttribute("aria-readonly", false);
@@ -41755,6 +41660,8 @@ createView_fn = function(element) {
41755
41660
  });
41756
41661
  this.view.updateState(newState);
41757
41662
  this.createNodeViews();
41663
+ const dom = this.view.dom;
41664
+ dom.editor = this;
41758
41665
  this.options.telemetry?.sendReport();
41759
41666
  };
41760
41667
  onCollaborationReady_fn = function({ editor, ydoc }) {
@@ -41781,9 +41688,7 @@ initComments_fn = function() {
41781
41688
  }, 50);
41782
41689
  };
41783
41690
  initPagination_fn = async function() {
41784
- if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
41785
- return;
41786
- }
41691
+ if (this.options.isHeadless || !this.extensionService) return;
41787
41692
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
41788
41693
  if (pagination && this.options.pagination) {
41789
41694
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -41795,7 +41700,7 @@ initPagination_fn = async function() {
41795
41700
  }
41796
41701
  };
41797
41702
  dispatchTransaction_fn = function(transaction) {
41798
- if (this.isDestroyed) return;
41703
+ if (this.view.isDestroyed) return;
41799
41704
  let state2;
41800
41705
  try {
41801
41706
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -41847,11 +41752,6 @@ dispatchTransaction_fn = function(transaction) {
41847
41752
  transaction
41848
41753
  });
41849
41754
  };
41850
- handleNodeSelection_fn = function(view, pos) {
41851
- if (this.options.isHeaderOrFooter) {
41852
- return setImageNodeSelection(view, pos);
41853
- }
41854
- };
41855
41755
  prepareDocumentForImport_fn = function(doc2) {
41856
41756
  const newState = EditorState.create({
41857
41757
  schema: this.schema,
@@ -44194,7 +44094,7 @@ const Paragraph = Node$1.create({
44194
44094
  },
44195
44095
  addPmPlugins() {
44196
44096
  const { view } = this.editor;
44197
- new Plugin({
44097
+ const dropcapPlugin = new Plugin({
44198
44098
  name: "dropcapPlugin",
44199
44099
  key: new PluginKey("dropcapPlugin"),
44200
44100
  state: {
@@ -44214,7 +44114,7 @@ const Paragraph = Node$1.create({
44214
44114
  }
44215
44115
  }
44216
44116
  });
44217
- return [];
44117
+ return [dropcapPlugin];
44218
44118
  }
44219
44119
  });
44220
44120
  const getDropcapDecorations = (state2, view) => {
@@ -44567,16 +44467,7 @@ const HardBreak = Node$1.create({
44567
44467
  };
44568
44468
  },
44569
44469
  parseDOM() {
44570
- return [{
44571
- tag: 'span[linebreaktype="page"]',
44572
- getAttrs: (dom) => {
44573
- if (!(dom instanceof HTMLElement)) return false;
44574
- return {
44575
- pageBreakSource: dom.getAttribute("pagebreaksource") || null,
44576
- pageBreakType: dom.getAttribute("linebreaktype") || null
44577
- };
44578
- }
44579
- }];
44470
+ return [{ tag: "span" }];
44580
44471
  },
44581
44472
  renderDOM({ htmlAttributes }) {
44582
44473
  return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -47573,8 +47464,6 @@ function findRemovedFieldAnnotations(tr) {
47573
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) {
47574
47465
  return removedNodes;
47575
47466
  }
47576
- const hasDeletion = transactionDeletedAnything(tr);
47577
- if (!hasDeletion) return removedNodes;
47578
47467
  tr.steps.forEach((step, stepIndex) => {
47579
47468
  if (step instanceof ReplaceStep && step.from !== step.to) {
47580
47469
  let mapping = tr.mapping.maps[stepIndex];
@@ -47591,14 +47480,6 @@ function findRemovedFieldAnnotations(tr) {
47591
47480
  });
47592
47481
  return removedNodes;
47593
47482
  }
47594
- function transactionDeletedAnything(tr) {
47595
- return tr.steps.some((step) => {
47596
- if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
47597
- return step.from !== step.to;
47598
- }
47599
- return false;
47600
- });
47601
- }
47602
47483
  function trackFieldAnnotationsDeletion(editor, tr) {
47603
47484
  let removedAnnotations = [];
47604
47485
  try {
@@ -47994,18 +47875,8 @@ const FieldAnnotation = Node$1.create({
47994
47875
  };
47995
47876
  }
47996
47877
  },
47997
- defaultDisplayLabel: {
47998
- default: "",
47999
- parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
48000
- renderDOM: (attrs) => {
48001
- if (!attrs.defaultDisplayLabel) return {};
48002
- return {
48003
- "data-default-display-label": attrs.defaultDisplayLabel
48004
- };
48005
- }
48006
- },
48007
47878
  displayLabel: {
48008
- default: "",
47879
+ default: "Text field",
48009
47880
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
48010
47881
  renderDOM: (attrs) => {
48011
47882
  if (!attrs.displayLabel) return {};
@@ -48321,7 +48192,6 @@ const FieldAnnotation = Node$1.create({
48321
48192
  return renderer();
48322
48193
  },
48323
48194
  addCommands() {
48324
- const annotationTypes = this.options.types;
48325
48195
  return {
48326
48196
  /**
48327
48197
  * Add field annotation.
@@ -48343,12 +48213,7 @@ const FieldAnnotation = Node$1.create({
48343
48213
  let currentMarks = $pos.marks();
48344
48214
  currentMarks = currentMarks.length ? [...currentMarks] : null;
48345
48215
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
48346
- let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
48347
- let node2 = schema.nodes[this.name].create({
48348
- ...attrs,
48349
- ...formatAttrs,
48350
- defaultDisplayLabel
48351
- }, null, null);
48216
+ let node2 = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
48352
48217
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
48353
48218
  if (editorFocus) {
48354
48219
  this.editor.view.focus();
@@ -48356,9 +48221,9 @@ const FieldAnnotation = Node$1.create({
48356
48221
  }
48357
48222
  return true;
48358
48223
  },
48359
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
48224
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
48360
48225
  const { from: from2 } = state2.selection;
48361
- return commands2.addFieldAnnotation(from2, attrs, editorFocus);
48226
+ commands2.addFieldAnnotation(from2, attrs, editorFocus);
48362
48227
  },
48363
48228
  /**
48364
48229
  * Replace field annotation.
@@ -48368,113 +48233,24 @@ const FieldAnnotation = Node$1.create({
48368
48233
  * from: 20,
48369
48234
  * to: 45,
48370
48235
  * attrs: {
48371
- * fieldType: 'TEXTINPUT'
48372
- * fieldColor: '#980043'
48236
+ * fieldType: 'TEXTINPUT'
48237
+ * fieldColor: '#980043'
48373
48238
  * }
48374
48239
  * ])
48375
48240
  */
48376
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
48241
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
48377
48242
  if (!dispatch) return true;
48243
+ tr.setMeta("fieldAnnotationReplace", true);
48378
48244
  fieldsArray.forEach((annotation) => {
48379
48245
  let { from: from2, to, attrs } = annotation;
48380
48246
  let { schema } = editor;
48381
48247
  let newPosFrom = tr.mapping.map(from2);
48382
48248
  let newPosTo = tr.mapping.map(to);
48383
- let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
48384
- let node2 = schema.nodes[this.name].create({
48385
- ...attrs,
48386
- defaultDisplayLabel
48387
- }, null, null);
48249
+ let node2 = schema.nodes[this.name].create({ ...attrs }, null, null);
48388
48250
  tr.replaceWith(newPosFrom, newPosTo, node2);
48389
48251
  });
48390
48252
  return true;
48391
48253
  },
48392
- /**
48393
- * Replace annotations with a label (as text node) in selection.
48394
- * @param options Additional options.
48395
- * @example
48396
- * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
48397
- */
48398
- replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
48399
- return commands2.replaceFieldAnnotationsWithLabel(null, {
48400
- ...options2,
48401
- isInSelection: true
48402
- });
48403
- },
48404
- /**
48405
- * Replace annotations with a label (as text node).
48406
- * @param fieldIdOrArray The field ID or array of field IDs.
48407
- * @param options.isInSelection Find in selection instead of field IDs.
48408
- * @param options.addToHistory Add to history or not.
48409
- * @param options.types Annotation types to replace.
48410
- * @example
48411
- * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
48412
- */
48413
- replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
48414
- isInSelection = false,
48415
- addToHistory = false,
48416
- types: types2 = annotationTypes
48417
- } = {}) => ({ dispatch, state: state2, tr }) => {
48418
- let { from: from2, to } = state2.selection;
48419
- let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
48420
- annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
48421
- if (!annotations.length) {
48422
- return true;
48423
- }
48424
- if (!addToHistory) {
48425
- tr.setMeta("addToHistory", false);
48426
- }
48427
- if (dispatch) {
48428
- annotations.forEach((annotation) => {
48429
- let { pos, node: node2 } = annotation;
48430
- let newPosFrom = tr.mapping.map(pos);
48431
- let newPosTo = tr.mapping.map(pos + node2.nodeSize);
48432
- let currentNode = tr.doc.nodeAt(newPosFrom);
48433
- let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
48434
- let $newPosFrom = tr.doc.resolve(newPosFrom);
48435
- let currentMarks = $newPosFrom.marks();
48436
- currentMarks = currentMarks.length ? [...currentMarks] : null;
48437
- if (nodeEqual) {
48438
- let label = node2.attrs.displayLabel || " ";
48439
- let textNode = state2.schema.text(label, currentMarks);
48440
- tr.replaceWith(newPosFrom, newPosTo, textNode);
48441
- }
48442
- });
48443
- }
48444
- return true;
48445
- },
48446
- /**
48447
- * Resets all annotations to default values.
48448
- * @example
48449
- * editor.commands.resetFieldAnnotations()
48450
- */
48451
- resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
48452
- let annotations = getAllFieldAnnotations(state2);
48453
- if (!annotations.length) {
48454
- return true;
48455
- }
48456
- tr.setMeta("fieldAnnotationUpdate", true);
48457
- if (dispatch) {
48458
- annotations.forEach(({ pos, node: node2 }) => {
48459
- let newPos = tr.mapping.map(pos);
48460
- let currentNode = tr.doc.nodeAt(newPos);
48461
- let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
48462
- if (nodeEqual) {
48463
- let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
48464
- tr.setNodeMarkup(newPos, void 0, {
48465
- ...node2.attrs,
48466
- // reset displayLabel to default.
48467
- displayLabel,
48468
- // reset attrs ​​for specific types.
48469
- imageSrc: null,
48470
- rawHtml: null,
48471
- linkUrl: null
48472
- });
48473
- }
48474
- });
48475
- }
48476
- return true;
48477
- },
48478
48254
  /**
48479
48255
  * Update annotations associated with a field.
48480
48256
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -49229,16 +49005,12 @@ const startImageUpload = async ({ editor, view, file }) => {
49229
49005
  }
49230
49006
  let id = {};
49231
49007
  let { tr, schema } = view.state;
49232
- let { selection } = tr;
49233
- if (editor.options.isHeaderOrFooter) {
49234
- selection = editor.options.lastSelection;
49235
- }
49236
- if (!selection.empty && !editor.options.isHeaderOrFooter) {
49008
+ if (!tr.selection.empty) {
49237
49009
  tr.deleteSelection();
49238
49010
  }
49239
49011
  let imageMeta = {
49240
49012
  type: "add",
49241
- pos: selection.from,
49013
+ pos: tr.selection.from,
49242
49014
  id
49243
49015
  };
49244
49016
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -54487,8 +54259,7 @@ const Pagination = Extension.create({
54487
54259
  addStorage() {
54488
54260
  return {
54489
54261
  height: 0,
54490
- sectionData: null,
54491
- headerFooterEditors: /* @__PURE__ */ new Map()
54262
+ sectionData: null
54492
54263
  };
54493
54264
  },
54494
54265
  addCommands() {
@@ -54531,14 +54302,13 @@ const Pagination = Extension.create({
54531
54302
  shouldUpdate = true;
54532
54303
  shouldInitialize = meta.isReadyToInit;
54533
54304
  }
54534
- const syncMeta = tr.getMeta("y-sync$");
54535
- if (syncMeta && syncMeta.isChangeOrigin) {
54536
- return { ...oldState };
54537
- }
54538
54305
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
54539
54306
  if (imagePluginTransaction) {
54540
54307
  if (imagePluginTransaction.type === "remove") {
54541
- 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);
54542
54312
  }
54543
54313
  return { ...oldState };
54544
54314
  }
@@ -54565,7 +54335,6 @@ const Pagination = Extension.create({
54565
54335
  if (isForceUpdate) shouldUpdate = true;
54566
54336
  return {
54567
54337
  ...oldState,
54568
- decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
54569
54338
  isReadyToInit: shouldInitialize
54570
54339
  };
54571
54340
  }
@@ -54594,10 +54363,6 @@ const Pagination = Extension.create({
54594
54363
  },
54595
54364
  onDestroy() {
54596
54365
  cleanupFloatingSeparators();
54597
- const { headerFooterEditors } = this.editor.storage.pagination;
54598
- if (headerFooterEditors) {
54599
- headerFooterEditors.clear();
54600
- }
54601
54366
  }
54602
54367
  });
54603
54368
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
@@ -54658,7 +54423,6 @@ const performUpdate = (editor, view, previousDecorations) => {
54658
54423
  const calculatePageBreaks = (view, editor, sectionData) => {
54659
54424
  if (!editor.converter) return DecorationSet.empty;
54660
54425
  const pageSize = editor.converter.pageStyles?.pageSize;
54661
- if (!pageSize) return DecorationSet.empty;
54662
54426
  const { width, height } = pageSize;
54663
54427
  if (!width || !height) return DecorationSet.empty;
54664
54428
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -54697,13 +54461,11 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
54697
54461
  let pageHeightThreshold = pageHeight;
54698
54462
  let footer = null, header = null;
54699
54463
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
54700
- const isFirstHeader = true;
54701
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
54464
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
54702
54465
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
54703
54466
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
54704
54467
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
54705
- const isLastFooter = true;
54706
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
54468
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
54707
54469
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
54708
54470
  let coords = view?.coordsAtPos(doc2.content.size);
54709
54471
  if (!coords) return [];
@@ -54722,8 +54484,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
54722
54484
  if (currentPageNumber === 1) {
54723
54485
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
54724
54486
  decorations.pop();
54725
- const isFirstHeader2 = true;
54726
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
54487
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
54727
54488
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
54728
54489
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
54729
54490
  }
@@ -54797,15 +54558,15 @@ function createFinalPagePadding(bufferHeight) {
54797
54558
  div2.style.height = bufferHeight + "px";
54798
54559
  return { nodeHeight: bufferHeight, node: div2 };
54799
54560
  }
54800
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
54801
- const headerDef = sectionData?.headers?.[headerId];
54561
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
54562
+ const headerDef = sectionData.headers?.[headerId];
54802
54563
  const minHeaderHeight = pageMargins.top * 96;
54803
54564
  const headerMargin = pageMargins.header * 96;
54804
54565
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
54805
54566
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
54806
54567
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
54807
54568
  const availableHeight = headerHeight - headerMargin;
54808
- let editorContainer = document.createElement("div");
54569
+ const editorContainer = document.createElement("div");
54809
54570
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
54810
54571
  headerId = "rId" + generateDocxRandomId();
54811
54572
  editor.converter.headerIds["default"] = headerId;
@@ -54817,31 +54578,23 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
54817
54578
  };
54818
54579
  }
54819
54580
  const data = editor.converter.headers[headerId];
54820
- const pageNumberIndex = currentPageNumber - 1;
54821
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
54822
- let editorSection = null;
54823
- const { headerFooterEditors } = editor.storage.pagination;
54824
- if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
54825
- const editorData = headerFooterEditors.get(editorKey);
54826
- editorSection = editorData.editor;
54827
- editorContainer = editorSection.element;
54828
- } else {
54829
- editorSection = createHeaderFooterEditor({
54830
- editor,
54831
- data,
54832
- editorContainer,
54833
- appendToBody: false,
54834
- sectionId: headerId,
54835
- type: "header",
54836
- availableHeight,
54837
- currentPageNumber
54838
- });
54839
- editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
54840
- headerFooterEditors.set(editorKey, { editor: editorSection });
54841
- broadcastEditorEvents(editor, editorSection);
54842
- }
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
+ });
54843
54595
  editorSection.setEditable(false, false);
54844
- editorContainer.classList.add("pagination-section-header");
54596
+ broadcastEditorEvents(editor, editorSection);
54597
+ editorContainer.className = "pagination-section-header";
54845
54598
  editorContainer.style.paddingTop = headerMargin + "px";
54846
54599
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
54847
54600
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -54854,12 +54607,12 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
54854
54607
  headerHeight
54855
54608
  };
54856
54609
  }
54857
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
54858
- const footerDef = sectionData?.footers?.[footerId];
54610
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
54611
+ const footerDef = sectionData.footers?.[footerId];
54859
54612
  const minFooterHeight = pageMargins.bottom * 96;
54860
54613
  const footerPaddingFromEdge = pageMargins.footer * 96;
54861
54614
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
54862
- let editorContainer = document.createElement("div");
54615
+ const editorContainer = document.createElement("div");
54863
54616
  if (!footerId && !editor.converter.footerIds["default"]) {
54864
54617
  footerId = "rId" + generateDocxRandomId();
54865
54618
  editor.converter.footerIds["default"] = footerId;
@@ -54871,31 +54624,23 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
54871
54624
  };
54872
54625
  }
54873
54626
  const data = editor.converter.footers[footerId];
54874
- const pageNumberIndex = currentPageNumber - 1;
54875
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
54876
- let editorSection = null;
54877
- const { headerFooterEditors } = editor.storage.pagination;
54878
- if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
54879
- const editorData = headerFooterEditors.get(editorKey);
54880
- editorSection = editorData.editor;
54881
- editorContainer = editorSection.element;
54882
- } else {
54883
- editorSection = createHeaderFooterEditor({
54884
- editor,
54885
- data,
54886
- editorContainer,
54887
- appendToBody: false,
54888
- sectionId: footerId,
54889
- type: "footer",
54890
- availableHeight: footerHeight,
54891
- currentPageNumber
54892
- });
54893
- editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
54894
- headerFooterEditors.set(editorKey, { editor: editorSection });
54895
- broadcastEditorEvents(editor, editorSection);
54896
- }
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
+ });
54897
54641
  editorSection.setEditable(false, false);
54898
- editorContainer.classList.add("pagination-section-footer");
54642
+ broadcastEditorEvents(editor, editorSection);
54643
+ editorContainer.className = "pagination-section-footer";
54899
54644
  editorContainer.style.height = footerHeight + "px";
54900
54645
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
54901
54646
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -54908,28 +54653,10 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
54908
54653
  footerHeight: footerHeight + footerPaddingFromEdge
54909
54654
  };
54910
54655
  }
54911
- const getHeaderFooterEditorKey = ({
54912
- pageNumber,
54913
- isHeader,
54914
- isFooter,
54915
- isFirstHeader = false,
54916
- isLastFooter = false
54917
- }) => {
54918
- if (isFirstHeader) return `first-header-${pageNumber}`;
54919
- if (isLastFooter) return `last-footer-${pageNumber}`;
54920
- if (isHeader) return `header-${pageNumber}`;
54921
- if (isFooter) return `footer-${pageNumber}`;
54922
- return void 0;
54923
- };
54924
54656
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
54925
54657
  if (editor.options.documentMode !== "editing") return;
54926
54658
  editor.setEditable(false, false);
54927
- toggleHeaderFooterEditMode({
54928
- editor,
54929
- focusedSectionEditor: currentFocusedSectionEditor,
54930
- isEditMode: true,
54931
- documentMode: editor.options.documentMode
54932
- });
54659
+ toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
54933
54660
  };
54934
54661
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
54935
54662
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -55484,7 +55211,7 @@ const Search = Extension.create({
55484
55211
  }
55485
55212
  });
55486
55213
  const NodeResizerKey = new PluginKey("node-resizer");
55487
- const nodeResizer = (nodeNames = ["image"], editor) => {
55214
+ const nodeResizer = (nodeNames = ["image"]) => {
55488
55215
  let resizeState = {
55489
55216
  dragging: false,
55490
55217
  startX: 0,
@@ -55509,13 +55236,8 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
55509
55236
  if (tr.getMeta(NodeResizerKey)) {
55510
55237
  return oldState;
55511
55238
  }
55512
- if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
55513
- const { selection } = newState;
55514
- const node2 = selection.node;
55515
- if (!node2 || !nodeNames.includes(node2.type.name)) {
55516
- return DecorationSet.empty;
55517
- }
55518
55239
  const decorations = [];
55240
+ const { selection } = newState;
55519
55241
  if (nodeNames.includes(selection.node?.type.name)) {
55520
55242
  decorations.push(
55521
55243
  Decoration.node(selection.from, selection.to, {
@@ -55718,7 +55440,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
55718
55440
  const NodeResizer = Extension.create({
55719
55441
  name: "nodeResizer",
55720
55442
  addPmPlugins() {
55721
- return [nodeResizer(["image"], this.editor)];
55443
+ return [nodeResizer(["image"])];
55722
55444
  }
55723
55445
  });
55724
55446
  const getRichTextExtensions = () => {
@@ -64394,6 +64116,7 @@ const style$2 = cB("icon", `
64394
64116
  display: inline-block;
64395
64117
  position: relative;
64396
64118
  fill: currentColor;
64119
+ transform: translateZ(0);
64397
64120
  `, [cM("color-transition", {
64398
64121
  transition: "color .3s var(--n-bezier)"
64399
64122
  }), cM("depth", {