@harbour-enterprises/superdoc 0.13.0-next.6 → 0.13.2-rev10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-CHxWXmuK.cjs} +1 -1
  2. package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-KKY27oz-.es.js} +1 -1
  3. package/dist/chunks/{index-Hr3Um-Bg.es.js → index-BqLFjUHn.es.js} +2 -2
  4. package/dist/chunks/{index-B4J7wgs6.cjs → index-CweAXNfB.cjs} +2 -2
  5. package/dist/chunks/{index-Diu6UKHt.es.js → index-DS3W0eVB.es.js} +4 -4
  6. package/dist/chunks/{index-Cdsq63Xq.cjs → index-kOMfCfBT.cjs} +4 -4
  7. package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-9bCX1h2W.cjs} +1 -1
  8. package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-Cl3s9njw.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-BSS_LTA0.cjs → super-editor.es-Bdu65rjC.cjs} +1096 -819
  10. package/dist/chunks/{super-editor.es-CU8V5_XY.es.js → super-editor.es-BwWbNxcS.es.js} +1096 -819
  11. package/dist/chunks/{url-BIzg4y2i.cjs → url-B8LY3nwf.cjs} +2 -2
  12. package/dist/chunks/{url-CHayXMZH.es.js → url-Bq00tGvm.es.js} +2 -2
  13. package/dist/chunks/{vue-Bi1uWinj.es.js → vue-BBJVqxjL.es.js} +10 -3
  14. package/dist/chunks/{vue-HIY1g7dm.cjs → vue-BBjMeYfo.cjs} +10 -3
  15. package/dist/chunks/{xml-js-CfClL-1b.es.js → xml-js-1F0lia4t.es.js} +81 -102
  16. package/dist/chunks/{xml-js-BjqmFOSP.cjs → xml-js-BuAdLsHD.cjs} +81 -102
  17. package/dist/style.css +4 -3
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-Bns3BtmW.js → converter-lPrQA7b1.js} +637 -55
  20. package/dist/super-editor/chunks/{docx-zipper-qf0kgh0l.js → docx-zipper-HvG9XskR.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-hIfvfc-Y.js → editor-DbkiH8Up.js} +387 -685
  22. package/dist/super-editor/chunks/{toolbar-BC9mPZ43.js → toolbar-JdrfUR1G.js} +2 -3
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +7 -0
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +7 -0
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
  31. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
  32. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  33. package/dist/super-editor/docx-zipper.es.js +2 -2
  34. package/dist/super-editor/editor.es.js +3 -3
  35. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  39. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  41. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  42. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  43. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/style.css +4 -3
  46. package/dist/super-editor/super-editor.es.js +7 -7
  47. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +3 -0
  48. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +1 -0
  49. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  50. package/dist/super-editor/toolbar.es.js +2 -2
  51. package/dist/super-editor.cjs +2 -2
  52. package/dist/super-editor.es.js +2 -2
  53. package/dist/superdoc.cjs +8 -9
  54. package/dist/superdoc.es.js +9 -10
  55. package/dist/superdoc.umd.js +1107 -824
  56. package/dist/superdoc.umd.js.map +1 -1
  57. package/package.json +1 -1
@@ -22,7 +22,7 @@
22
22
  const pdfjsLib__namespace = /* @__PURE__ */ _interopNamespaceDefault(pdfjsLib);
23
23
  const pdfjsViewer__namespace = /* @__PURE__ */ _interopNamespaceDefault(pdfjsViewer);
24
24
  /**
25
- * @vue/shared v3.5.16
25
+ * @vue/shared v3.5.17
26
26
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
27
27
  * @license MIT
28
28
  **/
@@ -622,6 +622,7 @@
622
622
  }
623
623
  };
624
624
  class Dep {
625
+ // TODO isolatedDeclarations "__v_skip"
625
626
  constructor(computed2) {
626
627
  this.computed = computed2;
627
628
  this.version = 0;
@@ -630,6 +631,7 @@
630
631
  this.map = void 0;
631
632
  this.key = void 0;
632
633
  this.sc = 0;
634
+ this.__v_skip = true;
633
635
  }
634
636
  track(debugInfo) {
635
637
  if (!activeSub || !shouldTrack || activeSub === this.computed) {
@@ -4099,6 +4101,8 @@
4099
4101
  const initSlots = (instance, children, optimized) => {
4100
4102
  const slots = instance.slots = createInternalObject();
4101
4103
  if (instance.vnode.shapeFlag & 32) {
4104
+ const cacheIndexes = children.__;
4105
+ if (cacheIndexes) def(slots, "__", cacheIndexes, true);
4102
4106
  const type2 = children._;
4103
4107
  if (type2) {
4104
4108
  assignSlots(slots, children, optimized);
@@ -4256,6 +4260,8 @@
4256
4260
  }
4257
4261
  if (ref3 != null && parentComponent) {
4258
4262
  setRef(ref3, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
4263
+ } else if (ref3 == null && n1 && n1.ref != null) {
4264
+ setRef(n1.ref, null, parentSuspense, n1, true);
4259
4265
  }
4260
4266
  };
4261
4267
  const processText = (n1, n2, container, anchor) => {
@@ -4729,7 +4735,8 @@
4729
4735
  }
4730
4736
  toggleRecurse(instance, true);
4731
4737
  {
4732
- if (root2.ce) {
4738
+ if (root2.ce && // @ts-expect-error _def is private
4739
+ root2.ce._def.shadowRoot !== false) {
4733
4740
  root2.ce._injectChildStyle(type2);
4734
4741
  }
4735
4742
  const subTree = instance.subTree = renderComponentRoot(instance);
@@ -6520,7 +6527,7 @@
6520
6527
  return createVNode(type2, propsOrChildren, children);
6521
6528
  }
6522
6529
  }
6523
- const version$1 = "3.5.16";
6530
+ const version$1 = "3.5.17";
6524
6531
  let policy = void 0;
6525
6532
  const tt = typeof window !== "undefined" && window.trustedTypes;
6526
6533
  if (tt) {
@@ -18318,7 +18325,7 @@
18318
18325
  }
18319
18326
  }
18320
18327
  const emptyAttrs = /* @__PURE__ */ Object.create(null);
18321
- let Node$2 = class Node2 {
18328
+ let Node$1$1 = class Node2 {
18322
18329
  /**
18323
18330
  @internal
18324
18331
  */
@@ -18719,8 +18726,8 @@
18719
18726
  return node2;
18720
18727
  }
18721
18728
  };
18722
- Node$2.prototype.text = void 0;
18723
- class TextNode extends Node$2 {
18729
+ Node$1$1.prototype.text = void 0;
18730
+ class TextNode extends Node$1$1 {
18724
18731
  /**
18725
18732
  @internal
18726
18733
  */
@@ -19307,7 +19314,7 @@
19307
19314
  create(attrs = null, content, marks) {
19308
19315
  if (this.isText)
19309
19316
  throw new Error("NodeType.create can't construct text nodes");
19310
- return new Node$2(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
19317
+ return new Node$1$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
19311
19318
  }
19312
19319
  /**
19313
19320
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
@@ -19317,7 +19324,7 @@
19317
19324
  createChecked(attrs = null, content, marks) {
19318
19325
  content = Fragment.from(content);
19319
19326
  this.checkContent(content);
19320
- return new Node$2(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
19327
+ return new Node$1$1(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
19321
19328
  }
19322
19329
  /**
19323
19330
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
@@ -19340,7 +19347,7 @@
19340
19347
  let after = matched && matched.fillBefore(Fragment.empty, true);
19341
19348
  if (!after)
19342
19349
  return null;
19343
- return new Node$2(this, attrs, content.append(after), Mark$1.setFrom(marks));
19350
+ return new Node$1$1(this, attrs, content.append(after), Mark$1.setFrom(marks));
19344
19351
  }
19345
19352
  /**
19346
19353
  Returns true if the given fragment is valid content for this node
@@ -19577,7 +19584,7 @@
19577
19584
  bound.
19578
19585
  */
19579
19586
  nodeFromJSON(json) {
19580
- return Node$2.fromJSON(this, json);
19587
+ return Node$1$1.fromJSON(this, json);
19581
19588
  }
19582
19589
  /**
19583
19590
  Deserialize a mark from its JSON representation. This method is
@@ -21103,7 +21110,7 @@
21103
21110
  }
21104
21111
  }
21105
21112
  Step.jsonID("replace", ReplaceStep);
21106
- class ReplaceAroundStep extends Step {
21113
+ let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
21107
21114
  /**
21108
21115
  Create a replace-around step with the given range and gap.
21109
21116
  `insert` should be the point in the slice into which the content
@@ -21143,7 +21150,7 @@
21143
21150
  }
21144
21151
  invert(doc2) {
21145
21152
  let gap = this.gapTo - this.gapFrom;
21146
- 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);
21153
+ 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);
21147
21154
  }
21148
21155
  map(mapping) {
21149
21156
  let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
@@ -21151,7 +21158,7 @@
21151
21158
  let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
21152
21159
  if (from2.deletedAcross && to.deletedAcross || gapFrom < from2.pos || gapTo > to.pos)
21153
21160
  return null;
21154
- return new ReplaceAroundStep(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
21161
+ return new ReplaceAroundStep2(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
21155
21162
  }
21156
21163
  toJSON() {
21157
21164
  let json = {
@@ -21174,10 +21181,10 @@
21174
21181
  static fromJSON(schema, json) {
21175
21182
  if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
21176
21183
  throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
21177
- return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
21184
+ return new ReplaceAroundStep2(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
21178
21185
  }
21179
- }
21180
- Step.jsonID("replaceAround", ReplaceAroundStep);
21186
+ };
21187
+ Step.jsonID("replaceAround", ReplaceAroundStep$1);
21181
21188
  function contentBetween(doc2, from2, to) {
21182
21189
  let $from = doc2.resolve(from2), dist2 = to - from2, depth = $from.depth;
21183
21190
  while (dist2 > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
@@ -21330,7 +21337,7 @@
21330
21337
  } else {
21331
21338
  end2++;
21332
21339
  }
21333
- tr.step(new ReplaceAroundStep(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
21340
+ tr.step(new ReplaceAroundStep$1(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
21334
21341
  }
21335
21342
  function findWrapping(range2, nodeType, attrs = null, innerRange = range2) {
21336
21343
  let around = findWrappingOutside(range2, nodeType);
@@ -21375,7 +21382,7 @@
21375
21382
  content = Fragment.from(wrappers[i2].type.create(wrappers[i2].attrs, content));
21376
21383
  }
21377
21384
  let start2 = range2.start, end2 = range2.end;
21378
- tr.step(new ReplaceAroundStep(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
21385
+ tr.step(new ReplaceAroundStep$1(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
21379
21386
  }
21380
21387
  function setBlockType$1(tr, from2, to, type2, attrs) {
21381
21388
  if (!type2.isTextblock)
@@ -21397,7 +21404,7 @@
21397
21404
  clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type2, void 0, convertNewlines === null);
21398
21405
  let mapping = tr.mapping.slice(mapFrom);
21399
21406
  let startM = mapping.map(pos, 1), endM = mapping.map(pos + node2.nodeSize, 1);
21400
- tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type2.create(attrsHere, null, node2.marks)), 0, 0), 1, true));
21407
+ 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));
21401
21408
  if (convertNewlines === true)
21402
21409
  replaceNewlines(tr, node2, pos, mapFrom);
21403
21410
  return false;
@@ -21438,7 +21445,7 @@
21438
21445
  return tr.replaceWith(pos, pos + node2.nodeSize, newNode);
21439
21446
  if (!type2.validContent(node2.content))
21440
21447
  throw new RangeError("Invalid content for node type " + type2.name);
21441
- tr.step(new ReplaceAroundStep(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
21448
+ tr.step(new ReplaceAroundStep$1(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
21442
21449
  }
21443
21450
  function canSplit(doc2, pos, depth = 1, typesAfter) {
21444
21451
  let $pos = doc2.resolve(pos), base2 = $pos.depth - depth;
@@ -21639,7 +21646,7 @@
21639
21646
  }
21640
21647
  let slice = new Slice(content, openStart, openEnd);
21641
21648
  if (moveInline > -1)
21642
- return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
21649
+ return new ReplaceAroundStep$1($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
21643
21650
  if (slice.size || $from.pos != this.$to.pos)
21644
21651
  return new ReplaceStep($from.pos, $to.pos, slice);
21645
21652
  return null;
@@ -22722,7 +22729,7 @@
22722
22729
  if (last < startLen)
22723
22730
  return;
22724
22731
  let step = tr.steps[last];
22725
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
22732
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1))
22726
22733
  return;
22727
22734
  let map2 = tr.mapping.maps[last], end2;
22728
22735
  map2.forEach((_from, _to, _newFrom, newTo) => {
@@ -23137,7 +23144,7 @@
23137
23144
  let instance = new EditorState($config);
23138
23145
  $config.fields.forEach((field) => {
23139
23146
  if (field.name == "doc") {
23140
- instance.doc = Node$2.fromJSON(config.schema, json.doc);
23147
+ instance.doc = Node$1$1.fromJSON(config.schema, json.doc);
23141
23148
  } else if (field.name == "selection") {
23142
23149
  instance.selection = Selection.fromJSON(instance.doc, json.selection);
23143
23150
  } else if (field.name == "storedMarks") {
@@ -26198,6 +26205,583 @@
26198
26205
  colgroupValues
26199
26206
  };
26200
26207
  };
26208
+ function chainableEditorState(transaction, state2) {
26209
+ let { selection, doc: doc2, storedMarks } = transaction;
26210
+ return {
26211
+ ...state2,
26212
+ apply: state2.apply.bind(state2),
26213
+ applyTransaction: state2.applyTransaction.bind(state2),
26214
+ plugins: state2.plugins,
26215
+ schema: state2.schema,
26216
+ reconfigure: state2.reconfigure.bind(state2),
26217
+ toJSON: state2.toJSON.bind(state2),
26218
+ get storedMarks() {
26219
+ return storedMarks;
26220
+ },
26221
+ get selection() {
26222
+ return selection;
26223
+ },
26224
+ get doc() {
26225
+ return doc2;
26226
+ },
26227
+ get tr() {
26228
+ selection = transaction.selection;
26229
+ doc2 = transaction.doc;
26230
+ storedMarks = transaction.storedMarks;
26231
+ return transaction;
26232
+ }
26233
+ };
26234
+ }
26235
+ class CommandService {
26236
+ constructor(props) {
26237
+ __publicField$2(this, "editor");
26238
+ __publicField$2(this, "rawCommands");
26239
+ this.editor = props.editor;
26240
+ this.rawCommands = this.editor.extensionService.commands;
26241
+ }
26242
+ /**
26243
+ * Static method for creating a service.
26244
+ * @param args Arguments for the constructor.
26245
+ */
26246
+ static create(...args) {
26247
+ return new CommandService(...args);
26248
+ }
26249
+ /**
26250
+ * Get editor state.
26251
+ */
26252
+ get state() {
26253
+ return this.editor.state;
26254
+ }
26255
+ /**
26256
+ * Get all commands with wrapped command method.
26257
+ */
26258
+ get commands() {
26259
+ const { editor, state: state2 } = this;
26260
+ const { view } = editor;
26261
+ const { tr } = state2;
26262
+ const props = this.createProps(tr);
26263
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
26264
+ const method = (...args) => {
26265
+ const fn = command2(...args)(props);
26266
+ if (!tr.getMeta("preventDispatch")) {
26267
+ view.dispatch(tr);
26268
+ }
26269
+ return fn;
26270
+ };
26271
+ return [name, method];
26272
+ });
26273
+ return Object.fromEntries(entries);
26274
+ }
26275
+ /**
26276
+ * Create a chain of commands to call multiple commands at once.
26277
+ */
26278
+ get chain() {
26279
+ return () => this.createChain();
26280
+ }
26281
+ /**
26282
+ * Check if a command or a chain of commands can be executed. Without executing it.
26283
+ */
26284
+ get can() {
26285
+ return () => this.createCan();
26286
+ }
26287
+ /**
26288
+ * Creates a chain of commands.
26289
+ * @param startTr Start transaction.
26290
+ * @param shouldDispatch Should dispatch or not.
26291
+ */
26292
+ createChain(startTr, shouldDispatch = true) {
26293
+ const { editor, state: state2, rawCommands } = this;
26294
+ const { view } = editor;
26295
+ const callbacks2 = [];
26296
+ const hasStartTr = !!startTr;
26297
+ const tr = startTr || state2.tr;
26298
+ const run2 = () => {
26299
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
26300
+ view.dispatch(tr);
26301
+ }
26302
+ return callbacks2.every((cb) => cb === true);
26303
+ };
26304
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
26305
+ const chainedCommand = (...args) => {
26306
+ const props = this.createProps(tr, shouldDispatch);
26307
+ const callback = command2(...args)(props);
26308
+ callbacks2.push(callback);
26309
+ return chain;
26310
+ };
26311
+ return [name, chainedCommand];
26312
+ });
26313
+ const chain = {
26314
+ ...Object.fromEntries(entries),
26315
+ run: run2
26316
+ };
26317
+ return chain;
26318
+ }
26319
+ /**
26320
+ * Creates a can check for commands.
26321
+ * @param startTr Start transaction.
26322
+ */
26323
+ createCan(startTr) {
26324
+ const { rawCommands, state: state2 } = this;
26325
+ const dispatch = false;
26326
+ const tr = startTr || state2.tr;
26327
+ const props = this.createProps(tr, dispatch);
26328
+ const commands2 = Object.fromEntries(
26329
+ Object.entries(rawCommands).map(([name, command2]) => {
26330
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
26331
+ })
26332
+ );
26333
+ return {
26334
+ ...commands2,
26335
+ chain: () => this.createChain(tr, dispatch)
26336
+ };
26337
+ }
26338
+ /**
26339
+ * Creates default props for the command method.
26340
+ * @param {*} tr Transaction.
26341
+ * @param {*} shouldDispatch Check if should dispatch.
26342
+ * @returns Object with props.
26343
+ */
26344
+ createProps(tr, shouldDispatch = true) {
26345
+ const { editor, state: state2, rawCommands } = this;
26346
+ const { view } = editor;
26347
+ const props = {
26348
+ tr,
26349
+ editor,
26350
+ view,
26351
+ state: chainableEditorState(tr, state2),
26352
+ dispatch: shouldDispatch ? () => void 0 : void 0,
26353
+ chain: () => this.createChain(tr, shouldDispatch),
26354
+ can: () => this.createCan(tr),
26355
+ get commands() {
26356
+ return Object.fromEntries(
26357
+ Object.entries(rawCommands).map(([name, command2]) => {
26358
+ return [name, (...args) => command2(...args)(props)];
26359
+ })
26360
+ );
26361
+ }
26362
+ };
26363
+ return props;
26364
+ }
26365
+ }
26366
+ function getHTMLFromFragment(fragment, schema) {
26367
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
26368
+ const temporaryDocument = document.implementation.createHTMLDocument();
26369
+ const container = temporaryDocument.createElement("div");
26370
+ container.appendChild(documentFragment);
26371
+ return container.innerHTML;
26372
+ }
26373
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
26374
+ let textBefore = "";
26375
+ const sliceEndPos = $from.parentOffset;
26376
+ $from.parent.nodesBetween(
26377
+ Math.max(0, sliceEndPos - maxMatch),
26378
+ sliceEndPos,
26379
+ (node2, pos, parent, index2) => {
26380
+ const chunk = node2.type.spec.toText?.({
26381
+ node: node2,
26382
+ pos,
26383
+ parent,
26384
+ index: index2
26385
+ }) || node2.textContent || "%leaf%";
26386
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
26387
+ }
26388
+ );
26389
+ return textBefore;
26390
+ };
26391
+ const handleDocxPaste = (html, editor, view, plugin2) => {
26392
+ const { converter } = editor;
26393
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
26394
+ let cleanedHtml = convertEmToPt(html);
26395
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
26396
+ const tempDiv = document.createElement("div");
26397
+ tempDiv.innerHTML = cleanedHtml;
26398
+ const paragraphs = tempDiv.querySelectorAll("p");
26399
+ paragraphs.forEach((p2) => {
26400
+ const innerHTML2 = p2.innerHTML;
26401
+ if (!innerHTML2.includes("<!--[if !supportLists]")) return;
26402
+ const styleAttr = p2.getAttribute("style") || "";
26403
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
26404
+ if (msoListMatch) {
26405
+ const [, abstractId, level] = msoListMatch;
26406
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
26407
+ if (!listNumId) return;
26408
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
26409
+ const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
26410
+ p2.setAttribute("data-num-id", listNumId);
26411
+ p2.setAttribute("data-list-level", level - 1);
26412
+ p2.setAttribute("data-start", start2);
26413
+ p2.setAttribute("data-lvl-text", lvlText);
26414
+ p2.setAttribute("data-num-fmt", numFmt);
26415
+ }
26416
+ extractAndRemoveConditionalPrefix(p2);
26417
+ });
26418
+ transformWordLists(tempDiv);
26419
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
26420
+ tempDiv.remove();
26421
+ const { dispatch } = editor.view;
26422
+ if (!dispatch) return false;
26423
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
26424
+ return true;
26425
+ };
26426
+ const getLevelDefinition = (abstractDefinition, level) => {
26427
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
26428
+ const levelElement = abstractDefinition.elements.find((el) => {
26429
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
26430
+ });
26431
+ if (!levelElement) return null;
26432
+ const { elements } = levelElement;
26433
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
26434
+ const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
26435
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
26436
+ return { lvlText, start: start2, numFmt, elements };
26437
+ };
26438
+ const getListNumIdFromAbstract = (abstractId, editor) => {
26439
+ const { definitions } = editor?.converter?.numbering;
26440
+ if (!definitions) return null;
26441
+ const matchedDefinition = Object.values(definitions).find((def2) => {
26442
+ return def2.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
26443
+ });
26444
+ return matchedDefinition?.attributes?.["w:numId"];
26445
+ };
26446
+ const getListAbstractDefinition = (abstractId, editor) => {
26447
+ const { abstracts = {} } = editor?.converter?.numbering;
26448
+ return abstracts[abstractId] || null;
26449
+ };
26450
+ const transformWordLists = (container) => {
26451
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
26452
+ const listMap = /* @__PURE__ */ new Map();
26453
+ const listLevels = {};
26454
+ for (const p2 of paragraphs) {
26455
+ const listId = p2.getAttribute("data-num-id");
26456
+ const level = parseInt(p2.getAttribute("data-list-level"));
26457
+ const numFmt = p2.getAttribute("data-num-fmt");
26458
+ const start2 = p2.getAttribute("data-start");
26459
+ const lvlText = p2.getAttribute("data-lvl-text");
26460
+ if (!listMap.has(listId)) listMap.set(listId, []);
26461
+ listMap.get(listId).push({ p: p2, level, numFmt, start: start2, lvlText });
26462
+ }
26463
+ for (const [id, items] of listMap.entries()) {
26464
+ if (!listLevels[id]) {
26465
+ listLevels[id] = {
26466
+ stack: [],
26467
+ counts: {},
26468
+ prevLevel: null
26469
+ };
26470
+ }
26471
+ const parentStack = [];
26472
+ items.forEach(({ p: p2, level, numFmt, start: start2, lvlText }, index2) => {
26473
+ const listLevel = generateListNestingPath(listLevels, id, level);
26474
+ const li = document.createElement("li");
26475
+ li.innerHTML = p2.innerHTML;
26476
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
26477
+ li.setAttribute("data-num-id", id);
26478
+ li.setAttribute("data-lvl-text", lvlText);
26479
+ li.setAttribute("data-num-fmt", numFmt);
26480
+ if (p2.hasAttribute("data-font-family")) {
26481
+ li.setAttribute("data-font-family", p2.getAttribute("data-font-family"));
26482
+ }
26483
+ if (p2.hasAttribute("data-font-size")) {
26484
+ li.setAttribute("data-font-size", p2.getAttribute("data-font-size"));
26485
+ }
26486
+ const parentNode2 = p2.parentNode;
26487
+ let listForLevel = parentStack[level];
26488
+ if (!listForLevel) {
26489
+ const newList = document.createElement("ol");
26490
+ newList.setAttribute("data-list-id", id);
26491
+ newList.level = level;
26492
+ if (level > 0) {
26493
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
26494
+ if (parentLi) parentLi.appendChild(newList);
26495
+ } else {
26496
+ parentNode2.insertBefore(newList, p2);
26497
+ }
26498
+ parentStack[level] = newList;
26499
+ parentStack.length = level + 1;
26500
+ listForLevel = newList;
26501
+ }
26502
+ listForLevel.appendChild(li);
26503
+ p2.remove();
26504
+ });
26505
+ }
26506
+ };
26507
+ function generateListNestingPath(listLevels, listId, currentLevel) {
26508
+ const levelState = listLevels[listId];
26509
+ if (!levelState.stack) levelState.stack = [];
26510
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
26511
+ if (levelState.prevLevel === null) {
26512
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
26513
+ } else {
26514
+ if (currentLevel > levelState.prevLevel) {
26515
+ levelState.stack.push(1);
26516
+ } else if (currentLevel === levelState.prevLevel) {
26517
+ levelState.stack[levelState.stack.length - 1]++;
26518
+ } else {
26519
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
26520
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
26521
+ }
26522
+ }
26523
+ levelState.prevLevel = currentLevel;
26524
+ return [...levelState.stack];
26525
+ }
26526
+ function extractAndRemoveConditionalPrefix(p2) {
26527
+ const nodes = Array.from(p2.childNodes);
26528
+ let fontFamily2 = null;
26529
+ let fontSize2 = null;
26530
+ let start2 = -1, end2 = -1;
26531
+ nodes.forEach((node2, index2) => {
26532
+ if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
26533
+ start2 = index2;
26534
+ }
26535
+ if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
26536
+ end2 = index2;
26537
+ }
26538
+ });
26539
+ if (start2 !== -1 && end2 !== -1) {
26540
+ for (let i2 = start2 + 1; i2 < end2; i2++) {
26541
+ const node2 = nodes[i2];
26542
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
26543
+ fontFamily2 = fontFamily2 || node2.style.fontFamily;
26544
+ fontSize2 = fontSize2 || node2.style.fontSize;
26545
+ }
26546
+ }
26547
+ for (let i2 = end2; i2 >= start2; i2--) {
26548
+ p2.removeChild(p2.childNodes[i2]);
26549
+ }
26550
+ if (fontFamily2) p2.setAttribute("data-font-family", fontFamily2);
26551
+ if (fontSize2) p2.setAttribute("data-font-size", fontSize2);
26552
+ }
26553
+ }
26554
+ class InputRule {
26555
+ constructor(config) {
26556
+ __publicField$2(this, "match");
26557
+ __publicField$2(this, "handler");
26558
+ this.match = config.match;
26559
+ this.handler = config.handler;
26560
+ }
26561
+ }
26562
+ const inputRuleMatcherHandler = (text, match) => {
26563
+ if (isRegExp(match)) {
26564
+ return match.exec(text);
26565
+ }
26566
+ const inputRuleMatch = match(text);
26567
+ if (!inputRuleMatch) {
26568
+ return null;
26569
+ }
26570
+ const result = [inputRuleMatch.text];
26571
+ result.index = inputRuleMatch.index;
26572
+ result.input = text;
26573
+ result.data = inputRuleMatch.data;
26574
+ if (inputRuleMatch.replaceWith) {
26575
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
26576
+ console.warn(
26577
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
26578
+ );
26579
+ }
26580
+ result.push(inputRuleMatch.replaceWith);
26581
+ }
26582
+ return result;
26583
+ };
26584
+ const run = (config) => {
26585
+ const {
26586
+ editor,
26587
+ from: from2,
26588
+ to,
26589
+ text,
26590
+ rules,
26591
+ plugin: plugin2
26592
+ } = config;
26593
+ const { view } = editor;
26594
+ if (view.composing) {
26595
+ return false;
26596
+ }
26597
+ const $from = view.state.doc.resolve(from2);
26598
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
26599
+ return false;
26600
+ }
26601
+ let matched = false;
26602
+ const textBefore = getTextContentFromNodes($from) + text;
26603
+ rules.forEach((rule) => {
26604
+ if (matched) {
26605
+ return;
26606
+ }
26607
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
26608
+ if (!match) {
26609
+ return;
26610
+ }
26611
+ const tr = view.state.tr;
26612
+ const state2 = chainableEditorState(tr, view.state);
26613
+ const range2 = {
26614
+ from: from2 - (match[0].length - text.length),
26615
+ to
26616
+ };
26617
+ const { commands: commands2, chain, can } = new CommandService({
26618
+ editor,
26619
+ state: state2
26620
+ });
26621
+ const handler = rule.handler({
26622
+ state: state2,
26623
+ range: range2,
26624
+ match,
26625
+ commands: commands2,
26626
+ chain,
26627
+ can
26628
+ });
26629
+ if (handler === null || !tr.steps.length) {
26630
+ return;
26631
+ }
26632
+ tr.setMeta(plugin2, {
26633
+ transform: tr,
26634
+ from: from2,
26635
+ to,
26636
+ text
26637
+ });
26638
+ view.dispatch(tr);
26639
+ matched = true;
26640
+ });
26641
+ return matched;
26642
+ };
26643
+ const inputRulesPlugin = ({ editor, rules }) => {
26644
+ const plugin2 = new Plugin({
26645
+ key: new PluginKey("inputRulesPlugin"),
26646
+ state: {
26647
+ init() {
26648
+ return null;
26649
+ },
26650
+ apply(tr, prev, state2) {
26651
+ const stored = tr.getMeta(plugin2);
26652
+ if (stored) {
26653
+ return stored;
26654
+ }
26655
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
26656
+ const isSimulatedInput = !!simulatedInputMeta;
26657
+ if (isSimulatedInput) {
26658
+ setTimeout(() => {
26659
+ let { text } = simulatedInputMeta;
26660
+ if (typeof text !== "string") {
26661
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
26662
+ }
26663
+ const { from: from2 } = simulatedInputMeta;
26664
+ const to = from2 + text.length;
26665
+ run({
26666
+ editor,
26667
+ from: from2,
26668
+ to,
26669
+ text,
26670
+ rules,
26671
+ plugin: plugin2
26672
+ });
26673
+ });
26674
+ }
26675
+ return tr.selectionSet || tr.docChanged ? null : prev;
26676
+ }
26677
+ },
26678
+ props: {
26679
+ handleTextInput(view, from2, to, text) {
26680
+ return run({
26681
+ editor,
26682
+ from: from2,
26683
+ to,
26684
+ text,
26685
+ rules,
26686
+ plugin: plugin2
26687
+ });
26688
+ },
26689
+ // add support for input rules to trigger on enter
26690
+ // this is useful for example for code blocks
26691
+ handleKeyDown(view, event) {
26692
+ if (event.key !== "Enter") {
26693
+ return false;
26694
+ }
26695
+ const { $cursor } = view.state.selection;
26696
+ if ($cursor) {
26697
+ return run({
26698
+ editor,
26699
+ from: $cursor.pos,
26700
+ to: $cursor.pos,
26701
+ text: "\n",
26702
+ rules,
26703
+ plugin: plugin2
26704
+ });
26705
+ }
26706
+ return false;
26707
+ },
26708
+ // Paste handler
26709
+ handlePaste(view, event, slice) {
26710
+ const clipboard = event.clipboardData;
26711
+ const html = clipboard.getData("text/html");
26712
+ clipboard.getData("text/plain");
26713
+ const fieldAnnotationContent = slice.content.content.filter((item) => item.type.name === "fieldAnnotation");
26714
+ if (fieldAnnotationContent.length) {
26715
+ return false;
26716
+ }
26717
+ let source;
26718
+ if (!html) {
26719
+ source = "plain-text";
26720
+ } else if (isWordHtml(html)) {
26721
+ source = "word-html";
26722
+ } else {
26723
+ source = "browser-html";
26724
+ }
26725
+ switch (source) {
26726
+ case "plain-text":
26727
+ break;
26728
+ case "word-html":
26729
+ if (editor.options.mode === "docx") {
26730
+ return handleDocxPaste(html, editor, view, plugin2);
26731
+ }
26732
+ case "browser-html":
26733
+ return handleHtmlPaste$1(html, editor);
26734
+ }
26735
+ return false;
26736
+ }
26737
+ },
26738
+ isInputRules: true
26739
+ });
26740
+ return plugin2;
26741
+ };
26742
+ function isWordHtml(html) {
26743
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
26744
+ }
26745
+ const handleHtmlPaste$1 = (html, editor, plugin2) => {
26746
+ const htmlWithPtSizing = convertEmToPt(html);
26747
+ const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
26748
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
26749
+ const { dispatch } = editor.view;
26750
+ if (!dispatch) return false;
26751
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
26752
+ return true;
26753
+ };
26754
+ const convertEmToPt = (html) => {
26755
+ return html.replace(
26756
+ /font-size\s*:\s*([\d.]+)em/gi,
26757
+ (_, emValue) => {
26758
+ const em = parseFloat(emValue);
26759
+ const pt = Math.round(em * 12 * 100) / 100;
26760
+ return `font-size: ${pt}pt`;
26761
+ }
26762
+ );
26763
+ };
26764
+ function cleanHtmlUnnecessaryTags(html) {
26765
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
26766
+ }
26767
+ function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
26768
+ const container = document.createElement("div");
26769
+ container.innerHTML = html;
26770
+ const walkAndClean = (node2) => {
26771
+ for (const child of [...node2.children]) {
26772
+ if (forbiddenTags.includes(child.tagName.toLowerCase())) {
26773
+ child.remove();
26774
+ continue;
26775
+ }
26776
+ if (child.hasAttribute("linebreaktype")) {
26777
+ child.removeAttribute("linebreaktype");
26778
+ }
26779
+ walkAndClean(child);
26780
+ }
26781
+ };
26782
+ walkAndClean(container);
26783
+ return container;
26784
+ }
26201
26785
  function exportSchemaToJson(params2) {
26202
26786
  const { type: type2 } = params2.node || {};
26203
26787
  const router = {
@@ -26235,13 +26819,13 @@
26235
26819
  function translateBodyNode(params2) {
26236
26820
  let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
26237
26821
  if (params2.converter) {
26238
- const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
26822
+ const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
26239
26823
  const hasDefaultHeader = params2.converter.headerIds?.default;
26240
26824
  if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
26241
26825
  const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
26242
26826
  sectPr.elements.push(defaultHeader);
26243
26827
  }
26244
- const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
26828
+ const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
26245
26829
  const hasDefaultFooter = params2.converter.footerIds?.default;
26246
26830
  if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
26247
26831
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
@@ -27541,12 +28125,11 @@
27541
28125
  node: { attrs = {}, marks = [] },
27542
28126
  editorSchema
27543
28127
  } = params2;
27544
- const parser = new window.DOMParser();
27545
- const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
28128
+ const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
27546
28129
  const marksFromAttrs = translateFieldAttrsToMarks(attrs);
27547
28130
  const allMarks = [...marks, ...marksFromAttrs];
27548
28131
  let state2 = EditorState.create({
27549
- doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtml)
28132
+ doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
27550
28133
  });
27551
28134
  if (allMarks.length) {
27552
28135
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
@@ -30601,7 +31184,7 @@
30601
31184
  });
30602
31185
  return updatedStyles;
30603
31186
  }
30604
- const importHeadersFooters = (docx, converter, editor) => {
31187
+ const importHeadersFooters = (docx, converter, mainEditor) => {
30605
31188
  const rels = docx["word/_rels/document.xml.rels"];
30606
31189
  const relationships = rels.elements.find((el) => el.name === "Relationships");
30607
31190
  const { elements } = relationships;
@@ -30611,6 +31194,9 @@
30611
31194
  const footers = elements.filter((el) => el.attributes["Type"] === footerType);
30612
31195
  const sectPr = findSectPr(docx["word/document.xml"]) || [];
30613
31196
  const allSectPrElements = sectPr.flatMap((el) => el.elements);
31197
+ if (!mainEditor) return;
31198
+ const editor = { ...mainEditor };
31199
+ editor.options.annotations = true;
30614
31200
  headers.forEach((header) => {
30615
31201
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(header, docx);
30616
31202
  const sectPrHeader = allSectPrElements.find((el) => el.name === "w:headerReference" && el.attributes["r:id"] === rId);
@@ -30770,7 +31356,7 @@
30770
31356
  return;
30771
31357
  }
30772
31358
  }
30773
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.0-next.6") {
31359
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-rev10") {
30774
31360
  const customLocation = "docProps/custom.xml";
30775
31361
  if (!docx[customLocation]) {
30776
31362
  docx[customLocation] = generateCustomXml();
@@ -31237,7 +31823,7 @@
31237
31823
  function generateCustomXml() {
31238
31824
  return DEFAULT_CUSTOM_XML;
31239
31825
  }
31240
- function generateSuperdocVersion(pid = 2, version2 = "0.13.0-next.6") {
31826
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.2-rev10") {
31241
31827
  return {
31242
31828
  type: "element",
31243
31829
  name: "property",
@@ -33770,7 +34356,7 @@
33770
34356
  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);
33771
34357
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
33772
34358
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
33773
- 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;
34359
+ 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;
33774
34360
  function getMarksFromSelection(state2) {
33775
34361
  const { from: from2, to, empty: empty2 } = state2.selection;
33776
34362
  const marks = [];
@@ -34959,164 +35545,6 @@
34959
35545
  };
34960
35546
  __privateAdd$1(_Schema, _Schema_static);
34961
35547
  let Schema = _Schema;
34962
- function chainableEditorState(transaction, state2) {
34963
- let { selection, doc: doc2, storedMarks } = transaction;
34964
- return {
34965
- ...state2,
34966
- apply: state2.apply.bind(state2),
34967
- applyTransaction: state2.applyTransaction.bind(state2),
34968
- plugins: state2.plugins,
34969
- schema: state2.schema,
34970
- reconfigure: state2.reconfigure.bind(state2),
34971
- toJSON: state2.toJSON.bind(state2),
34972
- get storedMarks() {
34973
- return storedMarks;
34974
- },
34975
- get selection() {
34976
- return selection;
34977
- },
34978
- get doc() {
34979
- return doc2;
34980
- },
34981
- get tr() {
34982
- selection = transaction.selection;
34983
- doc2 = transaction.doc;
34984
- storedMarks = transaction.storedMarks;
34985
- return transaction;
34986
- }
34987
- };
34988
- }
34989
- class CommandService {
34990
- constructor(props) {
34991
- __publicField$1(this, "editor");
34992
- __publicField$1(this, "rawCommands");
34993
- this.editor = props.editor;
34994
- this.rawCommands = this.editor.extensionService.commands;
34995
- }
34996
- /**
34997
- * Static method for creating a service.
34998
- * @param args Arguments for the constructor.
34999
- */
35000
- static create(...args) {
35001
- return new CommandService(...args);
35002
- }
35003
- /**
35004
- * Get editor state.
35005
- */
35006
- get state() {
35007
- return this.editor.state;
35008
- }
35009
- /**
35010
- * Get all commands with wrapped command method.
35011
- */
35012
- get commands() {
35013
- const { editor, state: state2 } = this;
35014
- const { view } = editor;
35015
- const { tr } = state2;
35016
- const props = this.createProps(tr);
35017
- const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
35018
- const method = (...args) => {
35019
- const fn2 = command2(...args)(props);
35020
- if (!tr.getMeta("preventDispatch")) {
35021
- view.dispatch(tr);
35022
- }
35023
- return fn2;
35024
- };
35025
- return [name, method];
35026
- });
35027
- return Object.fromEntries(entries);
35028
- }
35029
- /**
35030
- * Create a chain of commands to call multiple commands at once.
35031
- */
35032
- get chain() {
35033
- return () => this.createChain();
35034
- }
35035
- /**
35036
- * Check if a command or a chain of commands can be executed. Without executing it.
35037
- */
35038
- get can() {
35039
- return () => this.createCan();
35040
- }
35041
- /**
35042
- * Creates a chain of commands.
35043
- * @param startTr Start transaction.
35044
- * @param shouldDispatch Should dispatch or not.
35045
- */
35046
- createChain(startTr, shouldDispatch = true) {
35047
- const { editor, state: state2, rawCommands } = this;
35048
- const { view } = editor;
35049
- const callbacks2 = [];
35050
- const hasStartTr = !!startTr;
35051
- const tr = startTr || state2.tr;
35052
- const run2 = () => {
35053
- if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
35054
- view.dispatch(tr);
35055
- }
35056
- return callbacks2.every((cb) => cb === true);
35057
- };
35058
- const entries = Object.entries(rawCommands).map(([name, command2]) => {
35059
- const chainedCommand = (...args) => {
35060
- const props = this.createProps(tr, shouldDispatch);
35061
- const callback = command2(...args)(props);
35062
- callbacks2.push(callback);
35063
- return chain;
35064
- };
35065
- return [name, chainedCommand];
35066
- });
35067
- const chain = {
35068
- ...Object.fromEntries(entries),
35069
- run: run2
35070
- };
35071
- return chain;
35072
- }
35073
- /**
35074
- * Creates a can check for commands.
35075
- * @param startTr Start transaction.
35076
- */
35077
- createCan(startTr) {
35078
- const { rawCommands, state: state2 } = this;
35079
- const dispatch = false;
35080
- const tr = startTr || state2.tr;
35081
- const props = this.createProps(tr, dispatch);
35082
- const commands2 = Object.fromEntries(
35083
- Object.entries(rawCommands).map(([name, command2]) => {
35084
- return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
35085
- })
35086
- );
35087
- return {
35088
- ...commands2,
35089
- chain: () => this.createChain(tr, dispatch)
35090
- };
35091
- }
35092
- /**
35093
- * Creates default props for the command method.
35094
- * @param {*} tr Transaction.
35095
- * @param {*} shouldDispatch Check if should dispatch.
35096
- * @returns Object with props.
35097
- */
35098
- createProps(tr, shouldDispatch = true) {
35099
- const { editor, state: state2, rawCommands } = this;
35100
- const { view } = editor;
35101
- const props = {
35102
- tr,
35103
- editor,
35104
- view,
35105
- state: chainableEditorState(tr, state2),
35106
- dispatch: shouldDispatch ? () => void 0 : void 0,
35107
- chain: () => this.createChain(tr, shouldDispatch),
35108
- can: () => this.createCan(tr),
35109
- get commands() {
35110
- return Object.fromEntries(
35111
- Object.entries(rawCommands).map(([name, command2]) => {
35112
- return [name, (...args) => command2(...args)(props)];
35113
- })
35114
- );
35115
- }
35116
- };
35117
- return props;
35118
- }
35119
- }
35120
35548
  const first = (commands2) => (props) => {
35121
35549
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
35122
35550
  for (let i2 = 0; i2 < items.length; i2 += 1) {
@@ -35478,7 +35906,7 @@
35478
35906
  for (let i2 = conn.length - 1; i2 >= 0; i2--)
35479
35907
  wrap2 = Fragment.from(conn[i2].create(null, wrap2));
35480
35908
  wrap2 = Fragment.from(before.copy(wrap2));
35481
- let tr = state2.tr.step(new ReplaceAroundStep($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
35909
+ let tr = state2.tr.step(new ReplaceAroundStep$1($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
35482
35910
  let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
35483
35911
  if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
35484
35912
  tr.join($joinAt.pos);
@@ -35509,7 +35937,7 @@
35509
35937
  let end2 = Fragment.empty;
35510
35938
  for (let i2 = wrap2.length - 1; i2 >= 0; i2--)
35511
35939
  end2 = Fragment.from(wrap2[i2].copy(end2));
35512
- 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));
35940
+ 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));
35513
35941
  dispatch(tr.scrollIntoView());
35514
35942
  }
35515
35943
  return true;
@@ -36082,7 +36510,7 @@
36082
36510
  return;
36083
36511
  }
36084
36512
  const step = tr.steps[last];
36085
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
36513
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
36086
36514
  return;
36087
36515
  }
36088
36516
  const map2 = tr.mapping.maps[last];
@@ -36228,7 +36656,7 @@
36228
36656
  let content = Fragment.empty;
36229
36657
  for (let i2 = wrappers.length - 1; i2 >= 0; i2--)
36230
36658
  content = Fragment.from(wrappers[i2].type.create(wrappers[i2].attrs, content));
36231
- tr.step(new ReplaceAroundStep(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
36659
+ tr.step(new ReplaceAroundStep$1(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
36232
36660
  let found2 = 0;
36233
36661
  for (let i2 = 0; i2 < wrappers.length; i2++)
36234
36662
  if (wrappers[i2].type == listType)
@@ -36261,7 +36689,7 @@
36261
36689
  function liftToOuterList(state2, dispatch, itemType, range2) {
36262
36690
  let tr = state2.tr, end2 = range2.end, endOfList = range2.$to.end(range2.depth);
36263
36691
  if (end2 < endOfList) {
36264
- tr.step(new ReplaceAroundStep(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
36692
+ tr.step(new ReplaceAroundStep$1(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
36265
36693
  range2 = new NodeRange(tr.doc.resolve(range2.$from.pos), tr.doc.resolve(endOfList), range2.depth);
36266
36694
  }
36267
36695
  const target = liftTarget(range2);
@@ -36288,7 +36716,7 @@
36288
36716
  if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
36289
36717
  return false;
36290
36718
  let start2 = $start.pos, end2 = start2 + item.nodeSize;
36291
- 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));
36719
+ 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));
36292
36720
  dispatch(tr.scrollIntoView());
36293
36721
  return true;
36294
36722
  }
@@ -36309,7 +36737,7 @@
36309
36737
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
36310
36738
  let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
36311
36739
  let before = range2.start, after = range2.end;
36312
- dispatch(state2.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
36740
+ dispatch(state2.tr.step(new ReplaceAroundStep$1(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
36313
36741
  }
36314
36742
  return true;
36315
36743
  };
@@ -43902,7 +44330,8 @@
43902
44330
  binding.mapping
43903
44331
  );
43904
44332
  if (anchor !== null && head !== null) {
43905
- tr.setSelection(TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head)));
44333
+ const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
44334
+ tr.setSelection(sel);
43906
44335
  }
43907
44336
  }
43908
44337
  }
@@ -44683,7 +45112,7 @@
44683
45112
  };
44684
45113
  const absolutePositionToRelativePosition = (pos, type2, mapping) => {
44685
45114
  if (pos === 0) {
44686
- return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, -1);
45115
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, type2.length === 0 ? -1 : 0);
44687
45116
  }
44688
45117
  let n = type2._first === null ? null : (
44689
45118
  /** @type {Y.ContentType} */
@@ -44692,7 +45121,7 @@
44692
45121
  while (n !== null && type2 !== n) {
44693
45122
  if (n instanceof Y__namespace.XmlText) {
44694
45123
  if (n._length >= pos) {
44695
- return Y__namespace.createRelativePositionFromTypeIndex(n, pos, -1);
45124
+ return Y__namespace.createRelativePositionFromTypeIndex(n, pos, type2.length === 0 ? -1 : 0);
44696
45125
  } else {
44697
45126
  pos -= n._length;
44698
45127
  }
@@ -44756,7 +45185,7 @@
44756
45185
  return createRelativePosition(n._item.parent, n._item);
44757
45186
  }
44758
45187
  }
44759
- return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, -1);
45188
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, type2.length === 0 ? -1 : 0);
44760
45189
  };
44761
45190
  const createRelativePosition = (type2, item) => {
44762
45191
  let typeid = null;
@@ -45237,524 +45666,121 @@
45237
45666
  173: "_",
45238
45667
  186: ":",
45239
45668
  187: "+",
45240
- 188: "<",
45241
- 189: "_",
45242
- 190: ">",
45243
- 191: "?",
45244
- 192: "~",
45245
- 219: "{",
45246
- 220: "|",
45247
- 221: "}",
45248
- 222: '"'
45249
- };
45250
- var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
45251
- var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
45252
- for (var i$1 = 0; i$1 < 10; i$1++) base$2[48 + i$1] = base$2[96 + i$1] = String(i$1);
45253
- for (var i$1 = 1; i$1 <= 24; i$1++) base$2[i$1 + 111] = "F" + i$1;
45254
- for (var i$1 = 65; i$1 <= 90; i$1++) {
45255
- base$2[i$1] = String.fromCharCode(i$1 + 32);
45256
- shift[i$1] = String.fromCharCode(i$1);
45257
- }
45258
- for (var code in base$2) if (!shift.hasOwnProperty(code)) shift[code] = base$2[code];
45259
- function keyName(event) {
45260
- var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
45261
- var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$2)[event.keyCode] || event.key || "Unidentified";
45262
- if (name == "Esc") name = "Escape";
45263
- if (name == "Del") name = "Delete";
45264
- if (name == "Left") name = "ArrowLeft";
45265
- if (name == "Up") name = "ArrowUp";
45266
- if (name == "Right") name = "ArrowRight";
45267
- if (name == "Down") name = "ArrowDown";
45268
- return name;
45269
- }
45270
- const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
45271
- const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
45272
- function normalizeKeyName(name) {
45273
- let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
45274
- if (result == "Space")
45275
- result = " ";
45276
- let alt, ctrl, shift2, meta;
45277
- for (let i2 = 0; i2 < parts.length - 1; i2++) {
45278
- let mod = parts[i2];
45279
- if (/^(cmd|meta|m)$/i.test(mod))
45280
- meta = true;
45281
- else if (/^a(lt)?$/i.test(mod))
45282
- alt = true;
45283
- else if (/^(c|ctrl|control)$/i.test(mod))
45284
- ctrl = true;
45285
- else if (/^s(hift)?$/i.test(mod))
45286
- shift2 = true;
45287
- else if (/^mod$/i.test(mod)) {
45288
- if (mac)
45289
- meta = true;
45290
- else
45291
- ctrl = true;
45292
- } else
45293
- throw new Error("Unrecognized modifier name: " + mod);
45294
- }
45295
- if (alt)
45296
- result = "Alt-" + result;
45297
- if (ctrl)
45298
- result = "Ctrl-" + result;
45299
- if (meta)
45300
- result = "Meta-" + result;
45301
- if (shift2)
45302
- result = "Shift-" + result;
45303
- return result;
45304
- }
45305
- function normalize(map2) {
45306
- let copy2 = /* @__PURE__ */ Object.create(null);
45307
- for (let prop in map2)
45308
- copy2[normalizeKeyName(prop)] = map2[prop];
45309
- return copy2;
45310
- }
45311
- function modifiers(name, event, shift2 = true) {
45312
- if (event.altKey)
45313
- name = "Alt-" + name;
45314
- if (event.ctrlKey)
45315
- name = "Ctrl-" + name;
45316
- if (event.metaKey)
45317
- name = "Meta-" + name;
45318
- if (shift2 && event.shiftKey)
45319
- name = "Shift-" + name;
45320
- return name;
45321
- }
45322
- function keymap(bindings) {
45323
- return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
45324
- }
45325
- function keydownHandler(bindings) {
45326
- let map2 = normalize(bindings);
45327
- return function(view, event) {
45328
- let name = keyName(event), baseName, direct = map2[modifiers(name, event)];
45329
- if (direct && direct(view.state, view.dispatch, view))
45330
- return true;
45331
- if (name.length == 1 && name != " ") {
45332
- if (event.shiftKey) {
45333
- let noShift = map2[modifiers(name, event, false)];
45334
- if (noShift && noShift(view.state, view.dispatch, view))
45335
- return true;
45336
- }
45337
- if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
45338
- !(windows && event.ctrlKey && event.altKey) && (baseName = base$2[event.keyCode]) && baseName != name) {
45339
- let fromCode = map2[modifiers(baseName, event)];
45340
- if (fromCode && fromCode(view.state, view.dispatch, view))
45341
- return true;
45342
- }
45343
- }
45344
- return false;
45345
- };
45346
- }
45347
- function isExtensionRulesEnabled(extension, enabled) {
45348
- if (Array.isArray(enabled)) {
45349
- return enabled.some((enabledExtension) => {
45350
- const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
45351
- return name === extension.name;
45352
- });
45353
- }
45354
- return enabled;
45355
- }
45356
- function getHTMLFromFragment(fragment, schema) {
45357
- const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
45358
- const temporaryDocument = document.implementation.createHTMLDocument();
45359
- const container = temporaryDocument.createElement("div");
45360
- container.appendChild(documentFragment);
45361
- return container.innerHTML;
45362
- }
45363
- const getTextContentFromNodes = ($from, maxMatch = 500) => {
45364
- let textBefore = "";
45365
- const sliceEndPos = $from.parentOffset;
45366
- $from.parent.nodesBetween(
45367
- Math.max(0, sliceEndPos - maxMatch),
45368
- sliceEndPos,
45369
- (node2, pos, parent, index2) => {
45370
- const chunk = node2.type.spec.toText?.({
45371
- node: node2,
45372
- pos,
45373
- parent,
45374
- index: index2
45375
- }) || node2.textContent || "%leaf%";
45376
- textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
45377
- }
45378
- );
45379
- return textBefore;
45380
- };
45381
- const handleDocxPaste = (html, editor, view, plugin2) => {
45382
- const { converter } = editor;
45383
- if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
45384
- let cleanedHtml = convertEmToPt(html);
45385
- cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
45386
- const tempDiv = document.createElement("div");
45387
- tempDiv.innerHTML = cleanedHtml;
45388
- const paragraphs = tempDiv.querySelectorAll("p");
45389
- paragraphs.forEach((p2) => {
45390
- const innerHTML3 = p2.innerHTML;
45391
- if (!innerHTML3.includes("<!--[if !supportLists]")) return;
45392
- const styleAttr = p2.getAttribute("style") || "";
45393
- const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
45394
- if (msoListMatch) {
45395
- const [, abstractId, level] = msoListMatch;
45396
- const listNumId = getListNumIdFromAbstract(abstractId, editor);
45397
- if (!listNumId) return;
45398
- const abstractDefinition = getListAbstractDefinition(abstractId, editor);
45399
- const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
45400
- p2.setAttribute("data-num-id", listNumId);
45401
- p2.setAttribute("data-list-level", level - 1);
45402
- p2.setAttribute("data-start", start2);
45403
- p2.setAttribute("data-lvl-text", lvlText);
45404
- p2.setAttribute("data-num-fmt", numFmt);
45405
- }
45406
- extractAndRemoveConditionalPrefix(p2);
45407
- });
45408
- transformWordLists(tempDiv);
45409
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45410
- tempDiv.remove();
45411
- const { dispatch } = editor.view;
45412
- if (!dispatch) return false;
45413
- dispatch(view.state.tr.replaceSelectionWith(doc2, true));
45414
- return true;
45415
- };
45416
- const getLevelDefinition = (abstractDefinition, level) => {
45417
- if (!abstractDefinition || !abstractDefinition.elements) return null;
45418
- const levelElement = abstractDefinition.elements.find((el) => {
45419
- return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
45420
- });
45421
- if (!levelElement) return null;
45422
- const { elements } = levelElement;
45423
- const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
45424
- const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
45425
- const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
45426
- return { lvlText, start: start2, numFmt, elements };
45427
- };
45428
- const getListNumIdFromAbstract = (abstractId, editor) => {
45429
- const { definitions } = editor?.converter?.numbering;
45430
- if (!definitions) return null;
45431
- const matchedDefinition = Object.values(definitions).find((def2) => {
45432
- return def2.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
45433
- });
45434
- return matchedDefinition?.attributes?.["w:numId"];
45435
- };
45436
- const getListAbstractDefinition = (abstractId, editor) => {
45437
- const { abstracts = {} } = editor?.converter?.numbering;
45438
- return abstracts[abstractId] || null;
45439
- };
45440
- const transformWordLists = (container) => {
45441
- const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
45442
- const listMap = /* @__PURE__ */ new Map();
45443
- const listLevels = {};
45444
- for (const p2 of paragraphs) {
45445
- const listId = p2.getAttribute("data-num-id");
45446
- const level = parseInt(p2.getAttribute("data-list-level"));
45447
- const numFmt = p2.getAttribute("data-num-fmt");
45448
- const start2 = p2.getAttribute("data-start");
45449
- const lvlText = p2.getAttribute("data-lvl-text");
45450
- if (!listMap.has(listId)) listMap.set(listId, []);
45451
- listMap.get(listId).push({ p: p2, level, numFmt, start: start2, lvlText });
45452
- }
45453
- for (const [id, items] of listMap.entries()) {
45454
- if (!listLevels[id]) {
45455
- listLevels[id] = {
45456
- stack: [],
45457
- counts: {},
45458
- prevLevel: null
45459
- };
45460
- }
45461
- const parentStack = [];
45462
- items.forEach(({ p: p2, level, numFmt, start: start2, lvlText }, index2) => {
45463
- const listLevel = generateListNestingPath(listLevels, id, level);
45464
- const li = document.createElement("li");
45465
- li.innerHTML = p2.innerHTML;
45466
- li.setAttribute("data-list-level", JSON.stringify(listLevel));
45467
- li.setAttribute("data-num-id", id);
45468
- li.setAttribute("data-lvl-text", lvlText);
45469
- li.setAttribute("data-num-fmt", numFmt);
45470
- if (p2.hasAttribute("data-font-family")) {
45471
- li.setAttribute("data-font-family", p2.getAttribute("data-font-family"));
45472
- }
45473
- if (p2.hasAttribute("data-font-size")) {
45474
- li.setAttribute("data-font-size", p2.getAttribute("data-font-size"));
45475
- }
45476
- const parentNode2 = p2.parentNode;
45477
- let listForLevel = parentStack[level];
45478
- if (!listForLevel) {
45479
- const newList = document.createElement("ol");
45480
- newList.setAttribute("data-list-id", id);
45481
- newList.level = level;
45482
- if (level > 0) {
45483
- const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
45484
- if (parentLi) parentLi.appendChild(newList);
45485
- } else {
45486
- parentNode2.insertBefore(newList, p2);
45487
- }
45488
- parentStack[level] = newList;
45489
- parentStack.length = level + 1;
45490
- listForLevel = newList;
45491
- }
45492
- listForLevel.appendChild(li);
45493
- p2.remove();
45494
- });
45495
- }
45669
+ 188: "<",
45670
+ 189: "_",
45671
+ 190: ">",
45672
+ 191: "?",
45673
+ 192: "~",
45674
+ 219: "{",
45675
+ 220: "|",
45676
+ 221: "}",
45677
+ 222: '"'
45496
45678
  };
45497
- function generateListNestingPath(listLevels, listId, currentLevel) {
45498
- const levelState = listLevels[listId];
45499
- if (!levelState.stack) levelState.stack = [];
45500
- if (levelState.prevLevel === void 0) levelState.prevLevel = null;
45501
- if (levelState.prevLevel === null) {
45502
- levelState.stack = Array(currentLevel).fill(1).concat(1);
45503
- } else {
45504
- if (currentLevel > levelState.prevLevel) {
45505
- levelState.stack.push(1);
45506
- } else if (currentLevel === levelState.prevLevel) {
45507
- levelState.stack[levelState.stack.length - 1]++;
45508
- } else {
45509
- levelState.stack = levelState.stack.slice(0, currentLevel + 1);
45510
- levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
45511
- }
45512
- }
45513
- levelState.prevLevel = currentLevel;
45514
- return [...levelState.stack];
45515
- }
45516
- function extractAndRemoveConditionalPrefix(p2) {
45517
- const nodes = Array.from(p2.childNodes);
45518
- let fontFamily2 = null;
45519
- let fontSize2 = null;
45520
- let start2 = -1, end2 = -1;
45521
- nodes.forEach((node2, index2) => {
45522
- if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
45523
- start2 = index2;
45524
- }
45525
- if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
45526
- end2 = index2;
45527
- }
45528
- });
45529
- if (start2 !== -1 && end2 !== -1) {
45530
- for (let i2 = start2 + 1; i2 < end2; i2++) {
45531
- const node2 = nodes[i2];
45532
- if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
45533
- fontFamily2 = fontFamily2 || node2.style.fontFamily;
45534
- fontSize2 = fontSize2 || node2.style.fontSize;
45535
- }
45536
- }
45537
- for (let i2 = end2; i2 >= start2; i2--) {
45538
- p2.removeChild(p2.childNodes[i2]);
45539
- }
45540
- if (fontFamily2) p2.setAttribute("data-font-family", fontFamily2);
45541
- if (fontSize2) p2.setAttribute("data-font-size", fontSize2);
45542
- }
45679
+ var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
45680
+ var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
45681
+ for (var i$1 = 0; i$1 < 10; i$1++) base$2[48 + i$1] = base$2[96 + i$1] = String(i$1);
45682
+ for (var i$1 = 1; i$1 <= 24; i$1++) base$2[i$1 + 111] = "F" + i$1;
45683
+ for (var i$1 = 65; i$1 <= 90; i$1++) {
45684
+ base$2[i$1] = String.fromCharCode(i$1 + 32);
45685
+ shift[i$1] = String.fromCharCode(i$1);
45543
45686
  }
45544
- class InputRule {
45545
- constructor(config) {
45546
- __publicField$1(this, "match");
45547
- __publicField$1(this, "handler");
45548
- this.match = config.match;
45549
- this.handler = config.handler;
45550
- }
45687
+ for (var code in base$2) if (!shift.hasOwnProperty(code)) shift[code] = base$2[code];
45688
+ function keyName(event) {
45689
+ var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
45690
+ var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$2)[event.keyCode] || event.key || "Unidentified";
45691
+ if (name == "Esc") name = "Escape";
45692
+ if (name == "Del") name = "Delete";
45693
+ if (name == "Left") name = "ArrowLeft";
45694
+ if (name == "Up") name = "ArrowUp";
45695
+ if (name == "Right") name = "ArrowRight";
45696
+ if (name == "Down") name = "ArrowDown";
45697
+ return name;
45551
45698
  }
45552
- const inputRuleMatcherHandler = (text, match) => {
45553
- if (isRegExp(match)) {
45554
- return match.exec(text);
45555
- }
45556
- const inputRuleMatch = match(text);
45557
- if (!inputRuleMatch) {
45558
- return null;
45559
- }
45560
- const result = [inputRuleMatch.text];
45561
- result.index = inputRuleMatch.index;
45562
- result.input = text;
45563
- result.data = inputRuleMatch.data;
45564
- if (inputRuleMatch.replaceWith) {
45565
- if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
45566
- console.warn(
45567
- '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
45568
- );
45569
- }
45570
- result.push(inputRuleMatch.replaceWith);
45699
+ const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
45700
+ const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
45701
+ function normalizeKeyName(name) {
45702
+ let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
45703
+ if (result == "Space")
45704
+ result = " ";
45705
+ let alt, ctrl, shift2, meta;
45706
+ for (let i2 = 0; i2 < parts.length - 1; i2++) {
45707
+ let mod = parts[i2];
45708
+ if (/^(cmd|meta|m)$/i.test(mod))
45709
+ meta = true;
45710
+ else if (/^a(lt)?$/i.test(mod))
45711
+ alt = true;
45712
+ else if (/^(c|ctrl|control)$/i.test(mod))
45713
+ ctrl = true;
45714
+ else if (/^s(hift)?$/i.test(mod))
45715
+ shift2 = true;
45716
+ else if (/^mod$/i.test(mod)) {
45717
+ if (mac)
45718
+ meta = true;
45719
+ else
45720
+ ctrl = true;
45721
+ } else
45722
+ throw new Error("Unrecognized modifier name: " + mod);
45571
45723
  }
45724
+ if (alt)
45725
+ result = "Alt-" + result;
45726
+ if (ctrl)
45727
+ result = "Ctrl-" + result;
45728
+ if (meta)
45729
+ result = "Meta-" + result;
45730
+ if (shift2)
45731
+ result = "Shift-" + result;
45572
45732
  return result;
45573
- };
45574
- const run = (config) => {
45575
- const {
45576
- editor,
45577
- from: from2,
45578
- to,
45579
- text,
45580
- rules,
45581
- plugin: plugin2
45582
- } = config;
45583
- const { view } = editor;
45584
- if (view.composing) {
45585
- return false;
45586
- }
45587
- const $from = view.state.doc.resolve(from2);
45588
- if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
45589
- return false;
45590
- }
45591
- let matched = false;
45592
- const textBefore = getTextContentFromNodes($from) + text;
45593
- rules.forEach((rule) => {
45594
- if (matched) {
45595
- return;
45596
- }
45597
- const match = inputRuleMatcherHandler(textBefore, rule.match);
45598
- if (!match) {
45599
- return;
45600
- }
45601
- const tr = view.state.tr;
45602
- const state2 = chainableEditorState(tr, view.state);
45603
- const range2 = {
45604
- from: from2 - (match[0].length - text.length),
45605
- to
45606
- };
45607
- const { commands: commands2, chain, can } = new CommandService({
45608
- editor,
45609
- state: state2
45610
- });
45611
- const handler = rule.handler({
45612
- state: state2,
45613
- range: range2,
45614
- match,
45615
- commands: commands2,
45616
- chain,
45617
- can
45618
- });
45619
- if (handler === null || !tr.steps.length) {
45620
- return;
45621
- }
45622
- tr.setMeta(plugin2, {
45623
- transform: tr,
45624
- from: from2,
45625
- to,
45626
- text
45627
- });
45628
- view.dispatch(tr);
45629
- matched = true;
45630
- });
45631
- return matched;
45632
- };
45633
- const inputRulesPlugin = ({ editor, rules }) => {
45634
- const plugin2 = new Plugin({
45635
- key: new PluginKey("inputRulesPlugin"),
45636
- state: {
45637
- init() {
45638
- return null;
45639
- },
45640
- apply(tr, prev, state2) {
45641
- const stored = tr.getMeta(plugin2);
45642
- if (stored) {
45643
- return stored;
45644
- }
45645
- const simulatedInputMeta = tr.getMeta("applyInputRules");
45646
- const isSimulatedInput = !!simulatedInputMeta;
45647
- if (isSimulatedInput) {
45648
- setTimeout(() => {
45649
- let { text } = simulatedInputMeta;
45650
- if (typeof text !== "string") {
45651
- text = getHTMLFromFragment(Fragment.from(text), state2.schema);
45652
- }
45653
- const { from: from2 } = simulatedInputMeta;
45654
- const to = from2 + text.length;
45655
- run({
45656
- editor,
45657
- from: from2,
45658
- to,
45659
- text,
45660
- rules,
45661
- plugin: plugin2
45662
- });
45663
- });
45664
- }
45665
- return tr.selectionSet || tr.docChanged ? null : prev;
45733
+ }
45734
+ function normalize(map2) {
45735
+ let copy2 = /* @__PURE__ */ Object.create(null);
45736
+ for (let prop in map2)
45737
+ copy2[normalizeKeyName(prop)] = map2[prop];
45738
+ return copy2;
45739
+ }
45740
+ function modifiers(name, event, shift2 = true) {
45741
+ if (event.altKey)
45742
+ name = "Alt-" + name;
45743
+ if (event.ctrlKey)
45744
+ name = "Ctrl-" + name;
45745
+ if (event.metaKey)
45746
+ name = "Meta-" + name;
45747
+ if (shift2 && event.shiftKey)
45748
+ name = "Shift-" + name;
45749
+ return name;
45750
+ }
45751
+ function keymap(bindings) {
45752
+ return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
45753
+ }
45754
+ function keydownHandler(bindings) {
45755
+ let map2 = normalize(bindings);
45756
+ return function(view, event) {
45757
+ let name = keyName(event), baseName, direct = map2[modifiers(name, event)];
45758
+ if (direct && direct(view.state, view.dispatch, view))
45759
+ return true;
45760
+ if (name.length == 1 && name != " ") {
45761
+ if (event.shiftKey) {
45762
+ let noShift = map2[modifiers(name, event, false)];
45763
+ if (noShift && noShift(view.state, view.dispatch, view))
45764
+ return true;
45666
45765
  }
45667
- },
45668
- props: {
45669
- handleTextInput(view, from2, to, text) {
45670
- return run({
45671
- editor,
45672
- from: from2,
45673
- to,
45674
- text,
45675
- rules,
45676
- plugin: plugin2
45677
- });
45678
- },
45679
- // add support for input rules to trigger on enter
45680
- // this is useful for example for code blocks
45681
- handleKeyDown(view, event) {
45682
- if (event.key !== "Enter") {
45683
- return false;
45684
- }
45685
- const { $cursor } = view.state.selection;
45686
- if ($cursor) {
45687
- return run({
45688
- editor,
45689
- from: $cursor.pos,
45690
- to: $cursor.pos,
45691
- text: "\n",
45692
- rules,
45693
- plugin: plugin2
45694
- });
45695
- }
45696
- return false;
45697
- },
45698
- // Paste handler
45699
- handlePaste(view, event, slice2) {
45700
- const clipboard = event.clipboardData;
45701
- const html = clipboard.getData("text/html");
45702
- clipboard.getData("text/plain");
45703
- const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
45704
- if (fieldAnnotationContent.length) {
45705
- return false;
45706
- }
45707
- let source;
45708
- if (!html) {
45709
- source = "plain-text";
45710
- } else if (isWordHtml(html)) {
45711
- source = "word-html";
45712
- } else {
45713
- source = "browser-html";
45714
- }
45715
- switch (source) {
45716
- case "plain-text":
45717
- break;
45718
- case "word-html":
45719
- if (editor.options.mode === "docx") {
45720
- return handleDocxPaste(html, editor, view, plugin2);
45721
- }
45722
- case "browser-html":
45723
- return handleHtmlPaste$1(html, editor);
45724
- }
45725
- return false;
45766
+ if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
45767
+ !(windows && event.ctrlKey && event.altKey) && (baseName = base$2[event.keyCode]) && baseName != name) {
45768
+ let fromCode = map2[modifiers(baseName, event)];
45769
+ if (fromCode && fromCode(view.state, view.dispatch, view))
45770
+ return true;
45726
45771
  }
45727
- },
45728
- isInputRules: true
45729
- });
45730
- return plugin2;
45731
- };
45732
- function isWordHtml(html) {
45733
- return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
45734
- }
45735
- const handleHtmlPaste$1 = (html, editor, plugin2) => {
45736
- const cleanedHtml = convertEmToPt(html);
45737
- const tempDiv = document.createElement("div");
45738
- tempDiv.innerHTML = cleanedHtml;
45739
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45740
- tempDiv.remove();
45741
- const { dispatch } = editor.view;
45742
- if (!dispatch) return false;
45743
- dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
45744
- return true;
45745
- };
45746
- const convertEmToPt = (html) => {
45747
- return html.replace(
45748
- /font-size\s*:\s*([\d.]+)em/gi,
45749
- (_, emValue) => {
45750
- const em = parseFloat(emValue);
45751
- const pt = Math.round(em * 12 * 100) / 100;
45752
- return `font-size: ${pt}pt`;
45753
45772
  }
45754
- );
45755
- };
45756
- function cleanHtmlUnnecessaryTags(html) {
45757
- return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
45773
+ return false;
45774
+ };
45775
+ }
45776
+ function isExtensionRulesEnabled(extension, enabled) {
45777
+ if (Array.isArray(enabled)) {
45778
+ return enabled.some((enabledExtension) => {
45779
+ const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
45780
+ return name === extension.name;
45781
+ });
45782
+ }
45783
+ return enabled;
45758
45784
  }
45759
45785
  const _ExtensionService = class _ExtensionService2 {
45760
45786
  constructor(extensions, userExtensions, editor) {
@@ -46594,6 +46620,7 @@
46594
46620
  mediaFiles: editor.storage.image.media,
46595
46621
  fonts: editor.options.fonts,
46596
46622
  isHeaderOrFooter: true,
46623
+ isHeadless: editor.options.isHeadless,
46597
46624
  annotations: true,
46598
46625
  currentPageNumber,
46599
46626
  parentEditor: editor,
@@ -46601,13 +46628,15 @@
46601
46628
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
46602
46629
  });
46603
46630
  const pm = editorContainer.querySelector(".ProseMirror");
46604
- pm.style.maxHeight = "100%";
46605
- pm.style.minHeight = "100%";
46606
- pm.style.outline = "none";
46607
- pm.style.border = "none";
46608
- pm.setAttribute("role", "textbox");
46609
- pm.setAttribute("aria-multiline", true);
46610
- pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
46631
+ if (pm) {
46632
+ pm.style.maxHeight = "100%";
46633
+ pm.style.minHeight = "100%";
46634
+ pm.style.outline = "none";
46635
+ pm.style.border = "none";
46636
+ pm.setAttribute("role", "textbox");
46637
+ pm.setAttribute("aria-multiline", true);
46638
+ pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
46639
+ }
46611
46640
  return headerFooterEditor;
46612
46641
  };
46613
46642
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -46626,14 +46655,16 @@
46626
46655
  });
46627
46656
  });
46628
46657
  };
46629
- const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
46658
+ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
46630
46659
  editor.converter.headerEditors.forEach((item) => {
46631
46660
  item.editor.setEditable(isEditMode, false);
46632
46661
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46662
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46633
46663
  });
46634
46664
  editor.converter.footerEditors.forEach((item) => {
46635
46665
  item.editor.setEditable(isEditMode, false);
46636
46666
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46667
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46637
46668
  });
46638
46669
  if (isEditMode) {
46639
46670
  const pm = document.querySelector(".ProseMirror");
@@ -47714,6 +47745,19 @@
47714
47745
  );
47715
47746
  });
47716
47747
  };
47748
+ const resetHeaderFooterFieldAnnotations = ({ editor }) => {
47749
+ if (!editor) return;
47750
+ const sectionEditors = getAllHeaderFooterEditors(editor);
47751
+ sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
47752
+ sectionEditor.commands.resetFieldAnnotations();
47753
+ onHeaderFooterDataUpdate(
47754
+ { editor: sectionEditor },
47755
+ editor,
47756
+ sectionId,
47757
+ type2
47758
+ );
47759
+ });
47760
+ };
47717
47761
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
47718
47762
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
47719
47763
  const { doc: doc2 } = editor.state;
@@ -47784,6 +47828,7 @@
47784
47828
  getAllHeaderFooterEditors,
47785
47829
  updateHeaderFooterFieldAnnotations,
47786
47830
  deleteHeaderFooterFieldAnnotations,
47831
+ resetHeaderFooterFieldAnnotations,
47787
47832
  cleanUpListsWithAnnotations
47788
47833
  };
47789
47834
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -47963,6 +48008,16 @@
47963
48008
  const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
47964
48009
  dispatch(tr);
47965
48010
  };
48011
+ const setImageNodeSelection = (view, pos) => {
48012
+ const { doc: doc2 } = view.state;
48013
+ const node2 = doc2.nodeAt(pos);
48014
+ if (node2 && node2.type.name === "image") {
48015
+ const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
48016
+ view.dispatch(tr);
48017
+ return true;
48018
+ }
48019
+ return false;
48020
+ };
47966
48021
  const _Editor = class _Editor2 extends EventEmitter$2 {
47967
48022
  /**
47968
48023
  * Create a new Editor instance
@@ -48061,6 +48116,19 @@
48061
48116
  this.setHighContrastMode = setHighContrastMode;
48062
48117
  initMode();
48063
48118
  }
48119
+ mount(el) {
48120
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this, el);
48121
+ window.setTimeout(() => {
48122
+ if (this.isDestroyed) return;
48123
+ this.emit("create", { editor: this });
48124
+ }, 0);
48125
+ }
48126
+ unmount() {
48127
+ if (this.view) {
48128
+ this.view.destroy();
48129
+ }
48130
+ this.view = null;
48131
+ }
48064
48132
  /**
48065
48133
  * Set the toolbar for this editor
48066
48134
  * @param {Object} toolbar - The toolbar instance
@@ -48109,7 +48177,7 @@
48109
48177
  * @returns {boolean}
48110
48178
  */
48111
48179
  get isDestroyed() {
48112
- return this.view.isDestroyed;
48180
+ return this.view?.isDestroyed ?? true;
48113
48181
  }
48114
48182
  /**
48115
48183
  * Get the editor element
@@ -48152,7 +48220,12 @@
48152
48220
  this.commands.toggleTrackChangesShowOriginal();
48153
48221
  this.setEditable(false, false);
48154
48222
  this.setOptions({ documentMode: "viewing" });
48155
- toggleHeaderFooterEditMode(this, null, false);
48223
+ toggleHeaderFooterEditMode({
48224
+ editor: this,
48225
+ focusedSectionEditor: null,
48226
+ isEditMode: false,
48227
+ documentMode: cleanedMode
48228
+ });
48156
48229
  } else if (cleanedMode === "suggesting") {
48157
48230
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
48158
48231
  this.commands.disableTrackChangesShowOriginal();
@@ -48165,7 +48238,12 @@
48165
48238
  this.commands.disableTrackChanges();
48166
48239
  this.setEditable(true, false);
48167
48240
  this.setOptions({ documentMode: "editing" });
48168
- toggleHeaderFooterEditMode(this, null, false);
48241
+ toggleHeaderFooterEditMode({
48242
+ editor: this,
48243
+ focusedSectionEditor: null,
48244
+ isEditMode: false,
48245
+ documentMode: cleanedMode
48246
+ });
48169
48247
  }
48170
48248
  }
48171
48249
  /**
@@ -48342,29 +48420,26 @@
48342
48420
  };
48343
48421
  }
48344
48422
  /**
48345
- * Initialize default styles for the editor container and ProseMirror.
48346
- * Get page size and margins from the converter.
48347
- * Set document default font and font size.
48348
- *
48349
- * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
48350
- * @returns {void}
48351
- */
48352
- initDefaultStyles(element = this.element) {
48353
- if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
48354
- const proseMirror = element?.querySelector(".ProseMirror");
48423
+ * Attach styles and attributes to the editor element
48424
+ */
48425
+ updateEditorStyles(element, proseMirror) {
48355
48426
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
48356
- if (!proseMirror || !pageSize || !pageMargins) {
48427
+ if (!proseMirror || !element) {
48357
48428
  return;
48358
48429
  }
48359
48430
  proseMirror.setAttribute("role", "document");
48360
48431
  proseMirror.setAttribute("aria-multiline", true);
48361
48432
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
48362
48433
  proseMirror.setAttribute("aria-description", "");
48363
- element.style.width = pageSize.width + "in";
48364
- element.style.minWidth = pageSize.width + "in";
48365
- element.style.minHeight = pageSize.height + "in";
48366
- element.style.paddingLeft = pageMargins.left + "in";
48367
- element.style.paddingRight = pageMargins.right + "in";
48434
+ if (pageSize) {
48435
+ element.style.width = pageSize.width + "in";
48436
+ element.style.minWidth = pageSize.width + "in";
48437
+ element.style.minHeight = pageSize.height + "in";
48438
+ }
48439
+ if (pageMargins) {
48440
+ element.style.paddingLeft = pageMargins.left + "in";
48441
+ element.style.paddingRight = pageMargins.right + "in";
48442
+ }
48368
48443
  element.style.boxSizing = "border-box";
48369
48444
  element.style.isolation = "isolate";
48370
48445
  proseMirror.style.outline = "none";
@@ -48385,6 +48460,19 @@
48385
48460
  proseMirror.style.paddingTop = "1in";
48386
48461
  proseMirror.style.paddingBottom = "1in";
48387
48462
  }
48463
+ }
48464
+ /**
48465
+ * Initialize default styles for the editor container and ProseMirror.
48466
+ * Get page size and margins from the converter.
48467
+ * Set document default font and font size.
48468
+ *
48469
+ * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
48470
+ * @returns {void}
48471
+ */
48472
+ initDefaultStyles(element = this.element) {
48473
+ if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
48474
+ const proseMirror = element?.querySelector(".ProseMirror");
48475
+ this.updateEditorStyles(element, proseMirror);
48388
48476
  this.initMobileStyles(element);
48389
48477
  }
48390
48478
  /**
@@ -48596,10 +48684,25 @@
48596
48684
  */
48597
48685
  destroy() {
48598
48686
  this.emit("destroy");
48599
- if (this.view) this.view.destroy();
48687
+ this.unmount();
48688
+ this.destroyHeaderFooterEditors();
48600
48689
  __privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
48601
48690
  this.removeAllListeners();
48602
48691
  }
48692
+ destroyHeaderFooterEditors() {
48693
+ try {
48694
+ const editors = [
48695
+ ...this.converter.headerEditors,
48696
+ ...this.converter.footerEditors
48697
+ ];
48698
+ for (let editorData of editors) {
48699
+ editorData.editor.destroy();
48700
+ }
48701
+ this.converter.headerEditors.length = 0;
48702
+ this.converter.footerEditors.length = 0;
48703
+ } catch (error) {
48704
+ }
48705
+ }
48603
48706
  /**
48604
48707
  * Check if migrations are needed for the data
48605
48708
  * @static
@@ -48617,7 +48720,7 @@
48617
48720
  * @returns {Object | void} Migration results
48618
48721
  */
48619
48722
  processCollaborationMigrations() {
48620
- console.debug("[checkVersionMigrations] Current editor version", "0.13.0-next.6");
48723
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev10");
48621
48724
  if (!this.options.ydoc) return;
48622
48725
  const metaMap = this.options.ydoc.getMap("meta");
48623
48726
  let docVersion = metaMap.get("version");
@@ -48661,6 +48764,7 @@
48661
48764
  __privateMethod$1(this, _Editor_instances, initMedia_fn).call(this);
48662
48765
  this.initDefaultStyles();
48663
48766
  if (this.options.ydoc && this.options.collaborationProvider) {
48767
+ updateYdocDocxData(this);
48664
48768
  this.initializeCollaborationData(true);
48665
48769
  } else {
48666
48770
  __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
@@ -48812,7 +48916,7 @@
48812
48916
  this.emit("beforeCreate", { editor: this });
48813
48917
  this.on("contentError", this.options.onContentError);
48814
48918
  this.on("exception", this.options.onException);
48815
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48919
+ this.mount(this.options.element);
48816
48920
  this.initDefaultStyles();
48817
48921
  this.setDocumentMode(options2.documentMode);
48818
48922
  if (this.options.isHeadless) return;
@@ -48836,10 +48940,6 @@
48836
48940
  __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
48837
48941
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
48838
48942
  }
48839
- window.setTimeout(() => {
48840
- if (this.isDestroyed) return;
48841
- this.emit("create", { editor: this });
48842
- }, 0);
48843
48943
  };
48844
48944
  initRichText_fn = function(options2) {
48845
48945
  if (!options2.extensions || !options2.extensions.length) {
@@ -48851,7 +48951,7 @@
48851
48951
  this.on("beforeCreate", this.options.onBeforeCreate);
48852
48952
  this.emit("beforeCreate", { editor: this });
48853
48953
  this.on("contentError", this.options.onContentError);
48854
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48954
+ this.mount(this.options.element);
48855
48955
  this.on("create", this.options.onCreate);
48856
48956
  this.on("update", this.options.onUpdate);
48857
48957
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -48862,10 +48962,6 @@
48862
48962
  this.on("commentsLoaded", this.options.onCommentsLoaded);
48863
48963
  this.on("commentClick", this.options.onCommentClicked);
48864
48964
  this.on("locked", this.options.onDocumentLocked);
48865
- window.setTimeout(() => {
48866
- if (this.isDestroyed) return;
48867
- this.emit("create", { editor: this });
48868
- }, 0);
48869
48965
  };
48870
48966
  onFocus_fn = function({ editor, event }) {
48871
48967
  this.toolbar?.setActiveEditor(editor);
@@ -48986,14 +49082,15 @@
48986
49082
  }
48987
49083
  return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
48988
49084
  };
48989
- createView_fn = function() {
49085
+ createView_fn = function(element) {
48990
49086
  let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
48991
49087
  const state2 = { schema: this.schema };
48992
49088
  if (!this.options.ydoc) state2.doc = doc2;
48993
- this.view = new EditorView(this.options.element, {
49089
+ this.view = new EditorView(element, {
48994
49090
  ...this.options.editorProps,
48995
49091
  dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
48996
49092
  state: EditorState.create(state2),
49093
+ handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
48997
49094
  handleDoubleClick: async (view, pos, event) => {
48998
49095
  if (this.options.documentMode !== "editing") return;
48999
49096
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -49007,7 +49104,12 @@
49007
49104
  event.stopPropagation();
49008
49105
  if (!this.options.editable) {
49009
49106
  this.setEditable(true, false);
49010
- toggleHeaderFooterEditMode(this, null, false);
49107
+ toggleHeaderFooterEditMode({
49108
+ editor: this,
49109
+ focusedSectionEditor: null,
49110
+ isEditMode: false,
49111
+ documentMode: this.options.documentMode
49112
+ });
49011
49113
  const pm = document.querySelector(".ProseMirror");
49012
49114
  pm.classList.remove("header-footer-edit");
49013
49115
  pm.setAttribute("aria-readonly", false);
@@ -49020,8 +49122,6 @@
49020
49122
  });
49021
49123
  this.view.updateState(newState);
49022
49124
  this.createNodeViews();
49023
- const dom = this.view.dom;
49024
- dom.editor = this;
49025
49125
  this.options.telemetry?.sendReport();
49026
49126
  };
49027
49127
  onCollaborationReady_fn = function({ editor, ydoc }) {
@@ -49048,7 +49148,9 @@
49048
49148
  }, 50);
49049
49149
  };
49050
49150
  initPagination_fn = async function() {
49051
- if (this.options.isHeadless || !this.extensionService) return;
49151
+ if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
49152
+ return;
49153
+ }
49052
49154
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
49053
49155
  if (pagination && this.options.pagination) {
49054
49156
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -49060,7 +49162,7 @@
49060
49162
  }
49061
49163
  };
49062
49164
  dispatchTransaction_fn = function(transaction) {
49063
- if (this.view.isDestroyed) return;
49165
+ if (this.isDestroyed) return;
49064
49166
  let state2;
49065
49167
  try {
49066
49168
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -49112,6 +49214,11 @@
49112
49214
  transaction
49113
49215
  });
49114
49216
  };
49217
+ handleNodeSelection_fn = function(view, pos) {
49218
+ if (this.options.isHeaderOrFooter) {
49219
+ return setImageNodeSelection(view, pos);
49220
+ }
49221
+ };
49115
49222
  prepareDocumentForImport_fn = function(doc2) {
49116
49223
  const newState = EditorState.create({
49117
49224
  schema: this.schema,
@@ -51454,7 +51561,7 @@
51454
51561
  },
51455
51562
  addPmPlugins() {
51456
51563
  const { view } = this.editor;
51457
- const dropcapPlugin = new Plugin({
51564
+ new Plugin({
51458
51565
  name: "dropcapPlugin",
51459
51566
  key: new PluginKey("dropcapPlugin"),
51460
51567
  state: {
@@ -51474,7 +51581,7 @@
51474
51581
  }
51475
51582
  }
51476
51583
  });
51477
- return [dropcapPlugin];
51584
+ return [];
51478
51585
  }
51479
51586
  });
51480
51587
  const getDropcapDecorations = (state2, view) => {
@@ -51827,7 +51934,16 @@
51827
51934
  };
51828
51935
  },
51829
51936
  parseDOM() {
51830
- return [{ tag: "span" }];
51937
+ return [{
51938
+ tag: 'span[linebreaktype="page"]',
51939
+ getAttrs: (dom) => {
51940
+ if (!(dom instanceof HTMLElement)) return false;
51941
+ return {
51942
+ pageBreakSource: dom.getAttribute("pagebreaksource") || null,
51943
+ pageBreakType: dom.getAttribute("linebreaktype") || null
51944
+ };
51945
+ }
51946
+ }];
51831
51947
  },
51832
51948
  renderDOM({ htmlAttributes }) {
51833
51949
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -54824,6 +54940,8 @@
54824
54940
  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) {
54825
54941
  return removedNodes;
54826
54942
  }
54943
+ const hasDeletion = transactionDeletedAnything(tr);
54944
+ if (!hasDeletion) return removedNodes;
54827
54945
  tr.steps.forEach((step, stepIndex) => {
54828
54946
  if (step instanceof ReplaceStep && step.from !== step.to) {
54829
54947
  let mapping = tr.mapping.maps[stepIndex];
@@ -54840,6 +54958,14 @@
54840
54958
  });
54841
54959
  return removedNodes;
54842
54960
  }
54961
+ function transactionDeletedAnything(tr) {
54962
+ return tr.steps.some((step) => {
54963
+ if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
54964
+ return step.from !== step.to;
54965
+ }
54966
+ return false;
54967
+ });
54968
+ }
54843
54969
  function trackFieldAnnotationsDeletion(editor, tr) {
54844
54970
  let removedAnnotations = [];
54845
54971
  try {
@@ -55235,8 +55361,18 @@
55235
55361
  };
55236
55362
  }
55237
55363
  },
55364
+ defaultDisplayLabel: {
55365
+ default: "",
55366
+ parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
55367
+ renderDOM: (attrs) => {
55368
+ if (!attrs.defaultDisplayLabel) return {};
55369
+ return {
55370
+ "data-default-display-label": attrs.defaultDisplayLabel
55371
+ };
55372
+ }
55373
+ },
55238
55374
  displayLabel: {
55239
- default: "Text field",
55375
+ default: "",
55240
55376
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
55241
55377
  renderDOM: (attrs) => {
55242
55378
  if (!attrs.displayLabel) return {};
@@ -55552,6 +55688,7 @@
55552
55688
  return renderer2();
55553
55689
  },
55554
55690
  addCommands() {
55691
+ const annotationTypes = this.options.types;
55555
55692
  return {
55556
55693
  /**
55557
55694
  * Add field annotation.
@@ -55573,7 +55710,12 @@
55573
55710
  let currentMarks = $pos.marks();
55574
55711
  currentMarks = currentMarks.length ? [...currentMarks] : null;
55575
55712
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
55576
- let node2 = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
55713
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55714
+ let node2 = schema.nodes[this.name].create({
55715
+ ...attrs,
55716
+ ...formatAttrs,
55717
+ defaultDisplayLabel
55718
+ }, null, null);
55577
55719
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
55578
55720
  if (editorFocus) {
55579
55721
  this.editor.view.focus();
@@ -55581,9 +55723,9 @@
55581
55723
  }
55582
55724
  return true;
55583
55725
  },
55584
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
55726
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
55585
55727
  const { from: from2 } = state2.selection;
55586
- commands2.addFieldAnnotation(from2, attrs, editorFocus);
55728
+ return commands2.addFieldAnnotation(from2, attrs, editorFocus);
55587
55729
  },
55588
55730
  /**
55589
55731
  * Replace field annotation.
@@ -55593,24 +55735,113 @@
55593
55735
  * from: 20,
55594
55736
  * to: 45,
55595
55737
  * attrs: {
55596
- * fieldType: 'TEXTINPUT'
55597
- * fieldColor: '#980043'
55738
+ * fieldType: 'TEXTINPUT'
55739
+ * fieldColor: '#980043'
55598
55740
  * }
55599
55741
  * ])
55600
55742
  */
55601
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
55743
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
55602
55744
  if (!dispatch) return true;
55603
- tr.setMeta("fieldAnnotationReplace", true);
55604
55745
  fieldsArray.forEach((annotation) => {
55605
55746
  let { from: from2, to, attrs } = annotation;
55606
55747
  let { schema } = editor;
55607
55748
  let newPosFrom = tr.mapping.map(from2);
55608
55749
  let newPosTo = tr.mapping.map(to);
55609
- let node2 = schema.nodes[this.name].create({ ...attrs }, null, null);
55750
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55751
+ let node2 = schema.nodes[this.name].create({
55752
+ ...attrs,
55753
+ defaultDisplayLabel
55754
+ }, null, null);
55610
55755
  tr.replaceWith(newPosFrom, newPosTo, node2);
55611
55756
  });
55612
55757
  return true;
55613
55758
  },
55759
+ /**
55760
+ * Replace annotations with a label (as text node) in selection.
55761
+ * @param options Additional options.
55762
+ * @example
55763
+ * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
55764
+ */
55765
+ replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
55766
+ return commands2.replaceFieldAnnotationsWithLabel(null, {
55767
+ ...options2,
55768
+ isInSelection: true
55769
+ });
55770
+ },
55771
+ /**
55772
+ * Replace annotations with a label (as text node).
55773
+ * @param fieldIdOrArray The field ID or array of field IDs.
55774
+ * @param options.isInSelection Find in selection instead of field IDs.
55775
+ * @param options.addToHistory Add to history or not.
55776
+ * @param options.types Annotation types to replace.
55777
+ * @example
55778
+ * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
55779
+ */
55780
+ replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
55781
+ isInSelection = false,
55782
+ addToHistory = false,
55783
+ types: types2 = annotationTypes
55784
+ } = {}) => ({ dispatch, state: state2, tr }) => {
55785
+ let { from: from2, to } = state2.selection;
55786
+ let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
55787
+ annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
55788
+ if (!annotations.length) {
55789
+ return true;
55790
+ }
55791
+ if (!addToHistory) {
55792
+ tr.setMeta("addToHistory", false);
55793
+ }
55794
+ if (dispatch) {
55795
+ annotations.forEach((annotation) => {
55796
+ let { pos, node: node2 } = annotation;
55797
+ let newPosFrom = tr.mapping.map(pos);
55798
+ let newPosTo = tr.mapping.map(pos + node2.nodeSize);
55799
+ let currentNode = tr.doc.nodeAt(newPosFrom);
55800
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55801
+ let $newPosFrom = tr.doc.resolve(newPosFrom);
55802
+ let currentMarks = $newPosFrom.marks();
55803
+ currentMarks = currentMarks.length ? [...currentMarks] : null;
55804
+ if (nodeEqual) {
55805
+ let label = node2.attrs.displayLabel || " ";
55806
+ let textNode = state2.schema.text(label, currentMarks);
55807
+ tr.replaceWith(newPosFrom, newPosTo, textNode);
55808
+ }
55809
+ });
55810
+ }
55811
+ return true;
55812
+ },
55813
+ /**
55814
+ * Resets all annotations to default values.
55815
+ * @example
55816
+ * editor.commands.resetFieldAnnotations()
55817
+ */
55818
+ resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
55819
+ let annotations = getAllFieldAnnotations(state2);
55820
+ if (!annotations.length) {
55821
+ return true;
55822
+ }
55823
+ tr.setMeta("fieldAnnotationUpdate", true);
55824
+ if (dispatch) {
55825
+ annotations.forEach(({ pos, node: node2 }) => {
55826
+ let newPos = tr.mapping.map(pos);
55827
+ let currentNode = tr.doc.nodeAt(newPos);
55828
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55829
+ if (nodeEqual) {
55830
+ let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
55831
+ tr.setNodeMarkup(newPos, void 0, {
55832
+ ...node2.attrs,
55833
+ // reset displayLabel to default.
55834
+ displayLabel,
55835
+ // reset attrs ​​for specific types.
55836
+ imageSrc: null,
55837
+ rawHtml: null,
55838
+ linkUrl: null
55839
+ });
55840
+ }
55841
+ });
55842
+ }
55843
+ return true;
55844
+ },
55614
55845
  /**
55615
55846
  * Update annotations associated with a field.
55616
55847
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -56365,12 +56596,16 @@
56365
56596
  }
56366
56597
  let id = {};
56367
56598
  let { tr, schema } = view.state;
56368
- if (!tr.selection.empty) {
56599
+ let { selection } = tr;
56600
+ if (editor.options.isHeaderOrFooter) {
56601
+ selection = editor.options.lastSelection;
56602
+ }
56603
+ if (!selection.empty && !editor.options.isHeaderOrFooter) {
56369
56604
  tr.deleteSelection();
56370
56605
  }
56371
56606
  let imageMeta = {
56372
56607
  type: "add",
56373
- pos: tr.selection.from,
56608
+ pos: selection.from,
56374
56609
  id
56375
56610
  };
56376
56611
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -61619,7 +61854,8 @@
61619
61854
  addStorage() {
61620
61855
  return {
61621
61856
  height: 0,
61622
- sectionData: null
61857
+ sectionData: null,
61858
+ headerFooterEditors: /* @__PURE__ */ new Map()
61623
61859
  };
61624
61860
  },
61625
61861
  addCommands() {
@@ -61662,13 +61898,14 @@
61662
61898
  shouldUpdate = true;
61663
61899
  shouldInitialize = meta.isReadyToInit;
61664
61900
  }
61901
+ const syncMeta = tr.getMeta("y-sync$");
61902
+ if (syncMeta && syncMeta.isChangeOrigin) {
61903
+ return { ...oldState };
61904
+ }
61665
61905
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
61666
61906
  if (imagePluginTransaction) {
61667
61907
  if (imagePluginTransaction.type === "remove") {
61668
- const imagePos = imagePluginTransaction.pos;
61669
- const domImage = editor.view.domAtPos(imagePos).node.querySelector("img");
61670
- if (domImage.complete) onImageLoad(editor);
61671
- else domImage.onload = () => onImageLoad(editor);
61908
+ onImageLoad(editor);
61672
61909
  }
61673
61910
  return { ...oldState };
61674
61911
  }
@@ -61695,6 +61932,7 @@
61695
61932
  if (isForceUpdate) shouldUpdate = true;
61696
61933
  return {
61697
61934
  ...oldState,
61935
+ decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
61698
61936
  isReadyToInit: shouldInitialize
61699
61937
  };
61700
61938
  }
@@ -61723,6 +61961,10 @@
61723
61961
  },
61724
61962
  onDestroy() {
61725
61963
  cleanupFloatingSeparators();
61964
+ const { headerFooterEditors } = this.editor.storage.pagination;
61965
+ if (headerFooterEditors) {
61966
+ headerFooterEditors.clear();
61967
+ }
61726
61968
  }
61727
61969
  });
61728
61970
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
@@ -61783,6 +62025,7 @@
61783
62025
  const calculatePageBreaks = (view, editor, sectionData) => {
61784
62026
  if (!editor.converter) return DecorationSet.empty;
61785
62027
  const pageSize = editor.converter.pageStyles?.pageSize;
62028
+ if (!pageSize) return DecorationSet.empty;
61786
62029
  const { width, height } = pageSize;
61787
62030
  if (!width || !height) return DecorationSet.empty;
61788
62031
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -61821,11 +62064,13 @@
61821
62064
  let pageHeightThreshold = pageHeight;
61822
62065
  let footer = null, header = null;
61823
62066
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
61824
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
62067
+ const isFirstHeader = true;
62068
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
61825
62069
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
61826
62070
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
61827
62071
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
61828
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
62072
+ const isLastFooter = true;
62073
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
61829
62074
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
61830
62075
  let coords = view?.coordsAtPos(doc2.content.size);
61831
62076
  if (!coords) return [];
@@ -61844,7 +62089,8 @@
61844
62089
  if (currentPageNumber === 1) {
61845
62090
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
61846
62091
  decorations.pop();
61847
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
62092
+ const isFirstHeader2 = true;
62093
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
61848
62094
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
61849
62095
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
61850
62096
  }
@@ -61918,15 +62164,15 @@
61918
62164
  div2.style.height = bufferHeight + "px";
61919
62165
  return { nodeHeight: bufferHeight, node: div2 };
61920
62166
  }
61921
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
61922
- const headerDef = sectionData.headers?.[headerId];
62167
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
62168
+ const headerDef = sectionData?.headers?.[headerId];
61923
62169
  const minHeaderHeight = pageMargins.top * 96;
61924
62170
  const headerMargin = pageMargins.header * 96;
61925
62171
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
61926
62172
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
61927
62173
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
61928
62174
  const availableHeight = headerHeight - headerMargin;
61929
- const editorContainer = document.createElement("div");
62175
+ let editorContainer = document.createElement("div");
61930
62176
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
61931
62177
  headerId = "rId" + generateDocxRandomId();
61932
62178
  editor.converter.headerIds["default"] = headerId;
@@ -61938,23 +62184,31 @@
61938
62184
  };
61939
62185
  }
61940
62186
  const data = editor.converter.headers[headerId];
61941
- const editorSection = createHeaderFooterEditor({
61942
- editor,
61943
- data,
61944
- editorContainer,
61945
- appendToBody: false,
61946
- sectionId: headerId,
61947
- type: "header",
61948
- availableHeight,
61949
- currentPageNumber
61950
- });
61951
- editor.converter.headerEditors.push({
61952
- id: headerId,
61953
- editor: editorSection
61954
- });
62187
+ const pageNumberIndex = currentPageNumber - 1;
62188
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
62189
+ let editorSection = null;
62190
+ const { headerFooterEditors } = editor.storage.pagination;
62191
+ if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
62192
+ const editorData = headerFooterEditors.get(editorKey);
62193
+ editorSection = editorData.editor;
62194
+ editorContainer = editorSection.element;
62195
+ } else {
62196
+ editorSection = createHeaderFooterEditor({
62197
+ editor,
62198
+ data,
62199
+ editorContainer,
62200
+ appendToBody: false,
62201
+ sectionId: headerId,
62202
+ type: "header",
62203
+ availableHeight,
62204
+ currentPageNumber
62205
+ });
62206
+ editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
62207
+ headerFooterEditors.set(editorKey, { editor: editorSection });
62208
+ broadcastEditorEvents(editor, editorSection);
62209
+ }
61955
62210
  editorSection.setEditable(false, false);
61956
- broadcastEditorEvents(editor, editorSection);
61957
- editorContainer.className = "pagination-section-header";
62211
+ editorContainer.classList.add("pagination-section-header");
61958
62212
  editorContainer.style.paddingTop = headerMargin + "px";
61959
62213
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
61960
62214
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -61967,12 +62221,12 @@
61967
62221
  headerHeight
61968
62222
  };
61969
62223
  }
61970
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
61971
- const footerDef = sectionData.footers?.[footerId];
62224
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
62225
+ const footerDef = sectionData?.footers?.[footerId];
61972
62226
  const minFooterHeight = pageMargins.bottom * 96;
61973
62227
  const footerPaddingFromEdge = pageMargins.footer * 96;
61974
62228
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
61975
- const editorContainer = document.createElement("div");
62229
+ let editorContainer = document.createElement("div");
61976
62230
  if (!footerId && !editor.converter.footerIds["default"]) {
61977
62231
  footerId = "rId" + generateDocxRandomId();
61978
62232
  editor.converter.footerIds["default"] = footerId;
@@ -61984,23 +62238,31 @@
61984
62238
  };
61985
62239
  }
61986
62240
  const data = editor.converter.footers[footerId];
61987
- const editorSection = createHeaderFooterEditor({
61988
- editor,
61989
- data,
61990
- editorContainer,
61991
- appendToBody: false,
61992
- sectionId: footerId,
61993
- type: "footer",
61994
- availableHeight: footerHeight,
61995
- currentPageNumber
61996
- });
61997
- editor.converter.footerEditors.push({
61998
- id: footerId,
61999
- editor: editorSection
62000
- });
62241
+ const pageNumberIndex = currentPageNumber - 1;
62242
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
62243
+ let editorSection = null;
62244
+ const { headerFooterEditors } = editor.storage.pagination;
62245
+ if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
62246
+ const editorData = headerFooterEditors.get(editorKey);
62247
+ editorSection = editorData.editor;
62248
+ editorContainer = editorSection.element;
62249
+ } else {
62250
+ editorSection = createHeaderFooterEditor({
62251
+ editor,
62252
+ data,
62253
+ editorContainer,
62254
+ appendToBody: false,
62255
+ sectionId: footerId,
62256
+ type: "footer",
62257
+ availableHeight: footerHeight,
62258
+ currentPageNumber
62259
+ });
62260
+ editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
62261
+ headerFooterEditors.set(editorKey, { editor: editorSection });
62262
+ broadcastEditorEvents(editor, editorSection);
62263
+ }
62001
62264
  editorSection.setEditable(false, false);
62002
- broadcastEditorEvents(editor, editorSection);
62003
- editorContainer.className = "pagination-section-footer";
62265
+ editorContainer.classList.add("pagination-section-footer");
62004
62266
  editorContainer.style.height = footerHeight + "px";
62005
62267
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
62006
62268
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -62013,10 +62275,28 @@
62013
62275
  footerHeight: footerHeight + footerPaddingFromEdge
62014
62276
  };
62015
62277
  }
62278
+ const getHeaderFooterEditorKey = ({
62279
+ pageNumber,
62280
+ isHeader,
62281
+ isFooter,
62282
+ isFirstHeader = false,
62283
+ isLastFooter = false
62284
+ }) => {
62285
+ if (isFirstHeader) return `first-header-${pageNumber}`;
62286
+ if (isLastFooter) return `last-footer-${pageNumber}`;
62287
+ if (isHeader) return `header-${pageNumber}`;
62288
+ if (isFooter) return `footer-${pageNumber}`;
62289
+ return void 0;
62290
+ };
62016
62291
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
62017
62292
  if (editor.options.documentMode !== "editing") return;
62018
62293
  editor.setEditable(false, false);
62019
- toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
62294
+ toggleHeaderFooterEditMode({
62295
+ editor,
62296
+ focusedSectionEditor: currentFocusedSectionEditor,
62297
+ isEditMode: true,
62298
+ documentMode: editor.options.documentMode
62299
+ });
62020
62300
  };
62021
62301
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
62022
62302
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -62571,7 +62851,7 @@
62571
62851
  }
62572
62852
  });
62573
62853
  const NodeResizerKey = new PluginKey("node-resizer");
62574
- const nodeResizer = (nodeNames = ["image"]) => {
62854
+ const nodeResizer = (nodeNames = ["image"], editor) => {
62575
62855
  let resizeState = {
62576
62856
  dragging: false,
62577
62857
  startX: 0,
@@ -62596,8 +62876,13 @@
62596
62876
  if (tr.getMeta(NodeResizerKey)) {
62597
62877
  return oldState;
62598
62878
  }
62599
- const decorations = [];
62879
+ if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
62600
62880
  const { selection } = newState;
62881
+ const node2 = selection.node;
62882
+ if (!node2 || !nodeNames.includes(node2.type.name)) {
62883
+ return DecorationSet.empty;
62884
+ }
62885
+ const decorations = [];
62601
62886
  if (nodeNames.includes(selection.node?.type.name)) {
62602
62887
  decorations.push(
62603
62888
  Decoration.node(selection.from, selection.to, {
@@ -62800,7 +63085,7 @@
62800
63085
  const NodeResizer = Extension.create({
62801
63086
  name: "nodeResizer",
62802
63087
  addPmPlugins() {
62803
- return [nodeResizer(["image"])];
63088
+ return [nodeResizer(["image"], this.editor)];
62804
63089
  }
62805
63090
  });
62806
63091
  const getRichTextExtensions = () => {
@@ -71476,7 +71761,6 @@ ${style2}
71476
71761
  display: inline-block;
71477
71762
  position: relative;
71478
71763
  fill: currentColor;
71479
- transform: translateZ(0);
71480
71764
  `, [cM$1("color-transition", {
71481
71765
  transition: "color .3s var(--n-bezier)"
71482
71766
  }), cM$1("depth", {
@@ -89443,7 +89727,6 @@ ${style2}
89443
89727
  display: inline-block;
89444
89728
  position: relative;
89445
89729
  fill: currentColor;
89446
- transform: translateZ(0);
89447
89730
  `, [cM("color-transition", {
89448
89731
  transition: "color .3s var(--n-bezier)"
89449
89732
  }), cM("depth", {
@@ -93316,7 +93599,7 @@ ${style2}
93316
93599
  this.config.colors = shuffleArray(this.config.colors);
93317
93600
  this.userColorMap = /* @__PURE__ */ new Map();
93318
93601
  this.colorIndex = 0;
93319
- this.version = "0.13.0-next.6";
93602
+ this.version = "0.13.2-rev10";
93320
93603
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
93321
93604
  this.superdocId = config.superdocId || v4();
93322
93605
  this.colors = this.config.colors;