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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-CHxWXmuK.cjs} +1 -1
  2. package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-KKY27oz-.es.js} +1 -1
  3. package/dist/chunks/{index-KzH9VKHh.es.js → index-BqLFjUHn.es.js} +2 -2
  4. package/dist/chunks/{index-B0t3i_io.cjs → index-CweAXNfB.cjs} +2 -2
  5. package/dist/chunks/{index-D_HUrFWV.es.js → index-DS3W0eVB.es.js} +4 -4
  6. package/dist/chunks/{index-Bk160jQ2.cjs → index-kOMfCfBT.cjs} +4 -4
  7. package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-9bCX1h2W.cjs} +1 -1
  8. package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-Cl3s9njw.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es--NMYzIh3.cjs → super-editor.es-Bdu65rjC.cjs} +1090 -816
  10. package/dist/chunks/{super-editor.es-DyTkLKR1.es.js → super-editor.es-BwWbNxcS.es.js} +1090 -816
  11. package/dist/chunks/{url-CWyTQ-Xy.cjs → url-B8LY3nwf.cjs} +2 -2
  12. package/dist/chunks/{url-DsBQArCl.es.js → url-Bq00tGvm.es.js} +2 -2
  13. package/dist/chunks/{vue-Bi1uWinj.es.js → vue-BBJVqxjL.es.js} +10 -3
  14. package/dist/chunks/{vue-HIY1g7dm.cjs → vue-BBjMeYfo.cjs} +10 -3
  15. package/dist/chunks/{xml-js-CdiD26MJ.es.js → xml-js-1F0lia4t.es.js} +2 -2
  16. package/dist/chunks/{xml-js-Bu1ZZzmb.cjs → xml-js-BuAdLsHD.cjs} +2 -2
  17. package/dist/style.css +2 -2
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-CJ9kHtZx.js → converter-lPrQA7b1.js} +632 -52
  20. package/dist/super-editor/chunks/{docx-zipper-scQqOWXA.js → docx-zipper-HvG9XskR.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-DM6yaxu_.js → editor-DbkiH8Up.js} +386 -685
  22. package/dist/super-editor/chunks/{toolbar-CIHbdcnv.js → toolbar-JdrfUR1G.js} +2 -3
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +7 -0
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +7 -0
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
  31. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
  32. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  33. package/dist/super-editor/docx-zipper.es.js +2 -2
  34. package/dist/super-editor/editor.es.js +3 -3
  35. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  39. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  41. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  42. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  43. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/style.css +2 -2
  46. package/dist/super-editor/super-editor.es.js +7 -7
  47. package/dist/super-editor/toolbar.es.js +2 -2
  48. package/dist/super-editor.cjs +2 -2
  49. package/dist/super-editor.es.js +2 -2
  50. package/dist/superdoc.cjs +8 -9
  51. package/dist/superdoc.es.js +9 -10
  52. package/dist/superdoc.umd.js +1101 -821
  53. package/dist/superdoc.umd.js.map +1 -1
  54. package/package.json +1 -1
@@ -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 = {
@@ -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);
@@ -30611,6 +31194,7 @@
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;
30614
31198
  const editor = { ...mainEditor };
30615
31199
  editor.options.annotations = true;
30616
31200
  headers.forEach((header) => {
@@ -30772,7 +31356,7 @@
30772
31356
  return;
30773
31357
  }
30774
31358
  }
30775
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-rev1") {
31359
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-rev10") {
30776
31360
  const customLocation = "docProps/custom.xml";
30777
31361
  if (!docx[customLocation]) {
30778
31362
  docx[customLocation] = generateCustomXml();
@@ -31239,7 +31823,7 @@
31239
31823
  function generateCustomXml() {
31240
31824
  return DEFAULT_CUSTOM_XML;
31241
31825
  }
31242
- function generateSuperdocVersion(pid = 2, version2 = "0.13.2-rev1") {
31826
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.2-rev10") {
31243
31827
  return {
31244
31828
  type: "element",
31245
31829
  name: "property",
@@ -33772,7 +34356,7 @@
33772
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);
33773
34357
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
33774
34358
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
33775
- 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;
33776
34360
  function getMarksFromSelection(state2) {
33777
34361
  const { from: from2, to, empty: empty2 } = state2.selection;
33778
34362
  const marks = [];
@@ -34961,164 +35545,6 @@
34961
35545
  };
34962
35546
  __privateAdd$1(_Schema, _Schema_static);
34963
35547
  let Schema = _Schema;
34964
- function chainableEditorState(transaction, state2) {
34965
- let { selection, doc: doc2, storedMarks } = transaction;
34966
- return {
34967
- ...state2,
34968
- apply: state2.apply.bind(state2),
34969
- applyTransaction: state2.applyTransaction.bind(state2),
34970
- plugins: state2.plugins,
34971
- schema: state2.schema,
34972
- reconfigure: state2.reconfigure.bind(state2),
34973
- toJSON: state2.toJSON.bind(state2),
34974
- get storedMarks() {
34975
- return storedMarks;
34976
- },
34977
- get selection() {
34978
- return selection;
34979
- },
34980
- get doc() {
34981
- return doc2;
34982
- },
34983
- get tr() {
34984
- selection = transaction.selection;
34985
- doc2 = transaction.doc;
34986
- storedMarks = transaction.storedMarks;
34987
- return transaction;
34988
- }
34989
- };
34990
- }
34991
- class CommandService {
34992
- constructor(props) {
34993
- __publicField$1(this, "editor");
34994
- __publicField$1(this, "rawCommands");
34995
- this.editor = props.editor;
34996
- this.rawCommands = this.editor.extensionService.commands;
34997
- }
34998
- /**
34999
- * Static method for creating a service.
35000
- * @param args Arguments for the constructor.
35001
- */
35002
- static create(...args) {
35003
- return new CommandService(...args);
35004
- }
35005
- /**
35006
- * Get editor state.
35007
- */
35008
- get state() {
35009
- return this.editor.state;
35010
- }
35011
- /**
35012
- * Get all commands with wrapped command method.
35013
- */
35014
- get commands() {
35015
- const { editor, state: state2 } = this;
35016
- const { view } = editor;
35017
- const { tr } = state2;
35018
- const props = this.createProps(tr);
35019
- const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
35020
- const method = (...args) => {
35021
- const fn2 = command2(...args)(props);
35022
- if (!tr.getMeta("preventDispatch")) {
35023
- view.dispatch(tr);
35024
- }
35025
- return fn2;
35026
- };
35027
- return [name, method];
35028
- });
35029
- return Object.fromEntries(entries);
35030
- }
35031
- /**
35032
- * Create a chain of commands to call multiple commands at once.
35033
- */
35034
- get chain() {
35035
- return () => this.createChain();
35036
- }
35037
- /**
35038
- * Check if a command or a chain of commands can be executed. Without executing it.
35039
- */
35040
- get can() {
35041
- return () => this.createCan();
35042
- }
35043
- /**
35044
- * Creates a chain of commands.
35045
- * @param startTr Start transaction.
35046
- * @param shouldDispatch Should dispatch or not.
35047
- */
35048
- createChain(startTr, shouldDispatch = true) {
35049
- const { editor, state: state2, rawCommands } = this;
35050
- const { view } = editor;
35051
- const callbacks2 = [];
35052
- const hasStartTr = !!startTr;
35053
- const tr = startTr || state2.tr;
35054
- const run2 = () => {
35055
- if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
35056
- view.dispatch(tr);
35057
- }
35058
- return callbacks2.every((cb) => cb === true);
35059
- };
35060
- const entries = Object.entries(rawCommands).map(([name, command2]) => {
35061
- const chainedCommand = (...args) => {
35062
- const props = this.createProps(tr, shouldDispatch);
35063
- const callback = command2(...args)(props);
35064
- callbacks2.push(callback);
35065
- return chain;
35066
- };
35067
- return [name, chainedCommand];
35068
- });
35069
- const chain = {
35070
- ...Object.fromEntries(entries),
35071
- run: run2
35072
- };
35073
- return chain;
35074
- }
35075
- /**
35076
- * Creates a can check for commands.
35077
- * @param startTr Start transaction.
35078
- */
35079
- createCan(startTr) {
35080
- const { rawCommands, state: state2 } = this;
35081
- const dispatch = false;
35082
- const tr = startTr || state2.tr;
35083
- const props = this.createProps(tr, dispatch);
35084
- const commands2 = Object.fromEntries(
35085
- Object.entries(rawCommands).map(([name, command2]) => {
35086
- return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
35087
- })
35088
- );
35089
- return {
35090
- ...commands2,
35091
- chain: () => this.createChain(tr, dispatch)
35092
- };
35093
- }
35094
- /**
35095
- * Creates default props for the command method.
35096
- * @param {*} tr Transaction.
35097
- * @param {*} shouldDispatch Check if should dispatch.
35098
- * @returns Object with props.
35099
- */
35100
- createProps(tr, shouldDispatch = true) {
35101
- const { editor, state: state2, rawCommands } = this;
35102
- const { view } = editor;
35103
- const props = {
35104
- tr,
35105
- editor,
35106
- view,
35107
- state: chainableEditorState(tr, state2),
35108
- dispatch: shouldDispatch ? () => void 0 : void 0,
35109
- chain: () => this.createChain(tr, shouldDispatch),
35110
- can: () => this.createCan(tr),
35111
- get commands() {
35112
- return Object.fromEntries(
35113
- Object.entries(rawCommands).map(([name, command2]) => {
35114
- return [name, (...args) => command2(...args)(props)];
35115
- })
35116
- );
35117
- }
35118
- };
35119
- return props;
35120
- }
35121
- }
35122
35548
  const first = (commands2) => (props) => {
35123
35549
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
35124
35550
  for (let i2 = 0; i2 < items.length; i2 += 1) {
@@ -35480,7 +35906,7 @@
35480
35906
  for (let i2 = conn.length - 1; i2 >= 0; i2--)
35481
35907
  wrap2 = Fragment.from(conn[i2].create(null, wrap2));
35482
35908
  wrap2 = Fragment.from(before.copy(wrap2));
35483
- 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));
35484
35910
  let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
35485
35911
  if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
35486
35912
  tr.join($joinAt.pos);
@@ -35511,7 +35937,7 @@
35511
35937
  let end2 = Fragment.empty;
35512
35938
  for (let i2 = wrap2.length - 1; i2 >= 0; i2--)
35513
35939
  end2 = Fragment.from(wrap2[i2].copy(end2));
35514
- 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));
35515
35941
  dispatch(tr.scrollIntoView());
35516
35942
  }
35517
35943
  return true;
@@ -36084,7 +36510,7 @@
36084
36510
  return;
36085
36511
  }
36086
36512
  const step = tr.steps[last];
36087
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
36513
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
36088
36514
  return;
36089
36515
  }
36090
36516
  const map2 = tr.mapping.maps[last];
@@ -36230,7 +36656,7 @@
36230
36656
  let content = Fragment.empty;
36231
36657
  for (let i2 = wrappers.length - 1; i2 >= 0; i2--)
36232
36658
  content = Fragment.from(wrappers[i2].type.create(wrappers[i2].attrs, content));
36233
- 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));
36234
36660
  let found2 = 0;
36235
36661
  for (let i2 = 0; i2 < wrappers.length; i2++)
36236
36662
  if (wrappers[i2].type == listType)
@@ -36263,7 +36689,7 @@
36263
36689
  function liftToOuterList(state2, dispatch, itemType, range2) {
36264
36690
  let tr = state2.tr, end2 = range2.end, endOfList = range2.$to.end(range2.depth);
36265
36691
  if (end2 < endOfList) {
36266
- 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));
36267
36693
  range2 = new NodeRange(tr.doc.resolve(range2.$from.pos), tr.doc.resolve(endOfList), range2.depth);
36268
36694
  }
36269
36695
  const target = liftTarget(range2);
@@ -36290,7 +36716,7 @@
36290
36716
  if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
36291
36717
  return false;
36292
36718
  let start2 = $start.pos, end2 = start2 + item.nodeSize;
36293
- 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));
36294
36720
  dispatch(tr.scrollIntoView());
36295
36721
  return true;
36296
36722
  }
@@ -36311,7 +36737,7 @@
36311
36737
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
36312
36738
  let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
36313
36739
  let before = range2.start, after = range2.end;
36314
- 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());
36315
36741
  }
36316
36742
  return true;
36317
36743
  };
@@ -43904,7 +44330,8 @@
43904
44330
  binding.mapping
43905
44331
  );
43906
44332
  if (anchor !== null && head !== null) {
43907
- 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);
43908
44335
  }
43909
44336
  }
43910
44337
  }
@@ -44685,7 +45112,7 @@
44685
45112
  };
44686
45113
  const absolutePositionToRelativePosition = (pos, type2, mapping) => {
44687
45114
  if (pos === 0) {
44688
- return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, -1);
45115
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, 0, type2.length === 0 ? -1 : 0);
44689
45116
  }
44690
45117
  let n = type2._first === null ? null : (
44691
45118
  /** @type {Y.ContentType} */
@@ -44694,7 +45121,7 @@
44694
45121
  while (n !== null && type2 !== n) {
44695
45122
  if (n instanceof Y__namespace.XmlText) {
44696
45123
  if (n._length >= pos) {
44697
- return Y__namespace.createRelativePositionFromTypeIndex(n, pos, -1);
45124
+ return Y__namespace.createRelativePositionFromTypeIndex(n, pos, type2.length === 0 ? -1 : 0);
44698
45125
  } else {
44699
45126
  pos -= n._length;
44700
45127
  }
@@ -44758,7 +45185,7 @@
44758
45185
  return createRelativePosition(n._item.parent, n._item);
44759
45186
  }
44760
45187
  }
44761
- return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, -1);
45188
+ return Y__namespace.createRelativePositionFromTypeIndex(type2, type2._length, type2.length === 0 ? -1 : 0);
44762
45189
  };
44763
45190
  const createRelativePosition = (type2, item) => {
44764
45191
  let typeid = null;
@@ -45239,524 +45666,121 @@
45239
45666
  173: "_",
45240
45667
  186: ":",
45241
45668
  187: "+",
45242
- 188: "<",
45243
- 189: "_",
45244
- 190: ">",
45245
- 191: "?",
45246
- 192: "~",
45247
- 219: "{",
45248
- 220: "|",
45249
- 221: "}",
45250
- 222: '"'
45251
- };
45252
- var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
45253
- var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
45254
- for (var i$1 = 0; i$1 < 10; i$1++) base$2[48 + i$1] = base$2[96 + i$1] = String(i$1);
45255
- for (var i$1 = 1; i$1 <= 24; i$1++) base$2[i$1 + 111] = "F" + i$1;
45256
- for (var i$1 = 65; i$1 <= 90; i$1++) {
45257
- base$2[i$1] = String.fromCharCode(i$1 + 32);
45258
- shift[i$1] = String.fromCharCode(i$1);
45259
- }
45260
- for (var code in base$2) if (!shift.hasOwnProperty(code)) shift[code] = base$2[code];
45261
- function keyName(event) {
45262
- var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
45263
- var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$2)[event.keyCode] || event.key || "Unidentified";
45264
- if (name == "Esc") name = "Escape";
45265
- if (name == "Del") name = "Delete";
45266
- if (name == "Left") name = "ArrowLeft";
45267
- if (name == "Up") name = "ArrowUp";
45268
- if (name == "Right") name = "ArrowRight";
45269
- if (name == "Down") name = "ArrowDown";
45270
- return name;
45271
- }
45272
- const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
45273
- const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
45274
- function normalizeKeyName(name) {
45275
- let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
45276
- if (result == "Space")
45277
- result = " ";
45278
- let alt, ctrl, shift2, meta;
45279
- for (let i2 = 0; i2 < parts.length - 1; i2++) {
45280
- let mod = parts[i2];
45281
- if (/^(cmd|meta|m)$/i.test(mod))
45282
- meta = true;
45283
- else if (/^a(lt)?$/i.test(mod))
45284
- alt = true;
45285
- else if (/^(c|ctrl|control)$/i.test(mod))
45286
- ctrl = true;
45287
- else if (/^s(hift)?$/i.test(mod))
45288
- shift2 = true;
45289
- else if (/^mod$/i.test(mod)) {
45290
- if (mac)
45291
- meta = true;
45292
- else
45293
- ctrl = true;
45294
- } else
45295
- throw new Error("Unrecognized modifier name: " + mod);
45296
- }
45297
- if (alt)
45298
- result = "Alt-" + result;
45299
- if (ctrl)
45300
- result = "Ctrl-" + result;
45301
- if (meta)
45302
- result = "Meta-" + result;
45303
- if (shift2)
45304
- result = "Shift-" + result;
45305
- return result;
45306
- }
45307
- function normalize(map2) {
45308
- let copy2 = /* @__PURE__ */ Object.create(null);
45309
- for (let prop in map2)
45310
- copy2[normalizeKeyName(prop)] = map2[prop];
45311
- return copy2;
45312
- }
45313
- function modifiers(name, event, shift2 = true) {
45314
- if (event.altKey)
45315
- name = "Alt-" + name;
45316
- if (event.ctrlKey)
45317
- name = "Ctrl-" + name;
45318
- if (event.metaKey)
45319
- name = "Meta-" + name;
45320
- if (shift2 && event.shiftKey)
45321
- name = "Shift-" + name;
45322
- return name;
45323
- }
45324
- function keymap(bindings) {
45325
- return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
45326
- }
45327
- function keydownHandler(bindings) {
45328
- let map2 = normalize(bindings);
45329
- return function(view, event) {
45330
- let name = keyName(event), baseName, direct = map2[modifiers(name, event)];
45331
- if (direct && direct(view.state, view.dispatch, view))
45332
- return true;
45333
- if (name.length == 1 && name != " ") {
45334
- if (event.shiftKey) {
45335
- let noShift = map2[modifiers(name, event, false)];
45336
- if (noShift && noShift(view.state, view.dispatch, view))
45337
- return true;
45338
- }
45339
- if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
45340
- !(windows && event.ctrlKey && event.altKey) && (baseName = base$2[event.keyCode]) && baseName != name) {
45341
- let fromCode = map2[modifiers(baseName, event)];
45342
- if (fromCode && fromCode(view.state, view.dispatch, view))
45343
- return true;
45344
- }
45345
- }
45346
- return false;
45347
- };
45348
- }
45349
- function isExtensionRulesEnabled(extension, enabled) {
45350
- if (Array.isArray(enabled)) {
45351
- return enabled.some((enabledExtension) => {
45352
- const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
45353
- return name === extension.name;
45354
- });
45355
- }
45356
- return enabled;
45357
- }
45358
- function getHTMLFromFragment(fragment, schema) {
45359
- const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
45360
- const temporaryDocument = document.implementation.createHTMLDocument();
45361
- const container = temporaryDocument.createElement("div");
45362
- container.appendChild(documentFragment);
45363
- return container.innerHTML;
45364
- }
45365
- const getTextContentFromNodes = ($from, maxMatch = 500) => {
45366
- let textBefore = "";
45367
- const sliceEndPos = $from.parentOffset;
45368
- $from.parent.nodesBetween(
45369
- Math.max(0, sliceEndPos - maxMatch),
45370
- sliceEndPos,
45371
- (node2, pos, parent, index2) => {
45372
- const chunk = node2.type.spec.toText?.({
45373
- node: node2,
45374
- pos,
45375
- parent,
45376
- index: index2
45377
- }) || node2.textContent || "%leaf%";
45378
- textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
45379
- }
45380
- );
45381
- return textBefore;
45382
- };
45383
- const handleDocxPaste = (html, editor, view, plugin2) => {
45384
- const { converter } = editor;
45385
- if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
45386
- let cleanedHtml = convertEmToPt(html);
45387
- cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
45388
- const tempDiv = document.createElement("div");
45389
- tempDiv.innerHTML = cleanedHtml;
45390
- const paragraphs = tempDiv.querySelectorAll("p");
45391
- paragraphs.forEach((p2) => {
45392
- const innerHTML3 = p2.innerHTML;
45393
- if (!innerHTML3.includes("<!--[if !supportLists]")) return;
45394
- const styleAttr = p2.getAttribute("style") || "";
45395
- const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
45396
- if (msoListMatch) {
45397
- const [, abstractId, level] = msoListMatch;
45398
- const listNumId = getListNumIdFromAbstract(abstractId, editor);
45399
- if (!listNumId) return;
45400
- const abstractDefinition = getListAbstractDefinition(abstractId, editor);
45401
- const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
45402
- p2.setAttribute("data-num-id", listNumId);
45403
- p2.setAttribute("data-list-level", level - 1);
45404
- p2.setAttribute("data-start", start2);
45405
- p2.setAttribute("data-lvl-text", lvlText);
45406
- p2.setAttribute("data-num-fmt", numFmt);
45407
- }
45408
- extractAndRemoveConditionalPrefix(p2);
45409
- });
45410
- transformWordLists(tempDiv);
45411
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45412
- tempDiv.remove();
45413
- const { dispatch } = editor.view;
45414
- if (!dispatch) return false;
45415
- dispatch(view.state.tr.replaceSelectionWith(doc2, true));
45416
- return true;
45417
- };
45418
- const getLevelDefinition = (abstractDefinition, level) => {
45419
- if (!abstractDefinition || !abstractDefinition.elements) return null;
45420
- const levelElement = abstractDefinition.elements.find((el) => {
45421
- return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
45422
- });
45423
- if (!levelElement) return null;
45424
- const { elements } = levelElement;
45425
- const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
45426
- const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
45427
- const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
45428
- return { lvlText, start: start2, numFmt, elements };
45429
- };
45430
- const getListNumIdFromAbstract = (abstractId, editor) => {
45431
- const { definitions } = editor?.converter?.numbering;
45432
- if (!definitions) return null;
45433
- const matchedDefinition = Object.values(definitions).find((def2) => {
45434
- return def2.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
45435
- });
45436
- return matchedDefinition?.attributes?.["w:numId"];
45437
- };
45438
- const getListAbstractDefinition = (abstractId, editor) => {
45439
- const { abstracts = {} } = editor?.converter?.numbering;
45440
- return abstracts[abstractId] || null;
45441
- };
45442
- const transformWordLists = (container) => {
45443
- const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
45444
- const listMap = /* @__PURE__ */ new Map();
45445
- const listLevels = {};
45446
- for (const p2 of paragraphs) {
45447
- const listId = p2.getAttribute("data-num-id");
45448
- const level = parseInt(p2.getAttribute("data-list-level"));
45449
- const numFmt = p2.getAttribute("data-num-fmt");
45450
- const start2 = p2.getAttribute("data-start");
45451
- const lvlText = p2.getAttribute("data-lvl-text");
45452
- if (!listMap.has(listId)) listMap.set(listId, []);
45453
- listMap.get(listId).push({ p: p2, level, numFmt, start: start2, lvlText });
45454
- }
45455
- for (const [id, items] of listMap.entries()) {
45456
- if (!listLevels[id]) {
45457
- listLevels[id] = {
45458
- stack: [],
45459
- counts: {},
45460
- prevLevel: null
45461
- };
45462
- }
45463
- const parentStack = [];
45464
- items.forEach(({ p: p2, level, numFmt, start: start2, lvlText }, index2) => {
45465
- const listLevel = generateListNestingPath(listLevels, id, level);
45466
- const li = document.createElement("li");
45467
- li.innerHTML = p2.innerHTML;
45468
- li.setAttribute("data-list-level", JSON.stringify(listLevel));
45469
- li.setAttribute("data-num-id", id);
45470
- li.setAttribute("data-lvl-text", lvlText);
45471
- li.setAttribute("data-num-fmt", numFmt);
45472
- if (p2.hasAttribute("data-font-family")) {
45473
- li.setAttribute("data-font-family", p2.getAttribute("data-font-family"));
45474
- }
45475
- if (p2.hasAttribute("data-font-size")) {
45476
- li.setAttribute("data-font-size", p2.getAttribute("data-font-size"));
45477
- }
45478
- const parentNode2 = p2.parentNode;
45479
- let listForLevel = parentStack[level];
45480
- if (!listForLevel) {
45481
- const newList = document.createElement("ol");
45482
- newList.setAttribute("data-list-id", id);
45483
- newList.level = level;
45484
- if (level > 0) {
45485
- const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
45486
- if (parentLi) parentLi.appendChild(newList);
45487
- } else {
45488
- parentNode2.insertBefore(newList, p2);
45489
- }
45490
- parentStack[level] = newList;
45491
- parentStack.length = level + 1;
45492
- listForLevel = newList;
45493
- }
45494
- listForLevel.appendChild(li);
45495
- p2.remove();
45496
- });
45497
- }
45669
+ 188: "<",
45670
+ 189: "_",
45671
+ 190: ">",
45672
+ 191: "?",
45673
+ 192: "~",
45674
+ 219: "{",
45675
+ 220: "|",
45676
+ 221: "}",
45677
+ 222: '"'
45498
45678
  };
45499
- function generateListNestingPath(listLevels, listId, currentLevel) {
45500
- const levelState = listLevels[listId];
45501
- if (!levelState.stack) levelState.stack = [];
45502
- if (levelState.prevLevel === void 0) levelState.prevLevel = null;
45503
- if (levelState.prevLevel === null) {
45504
- levelState.stack = Array(currentLevel).fill(1).concat(1);
45505
- } else {
45506
- if (currentLevel > levelState.prevLevel) {
45507
- levelState.stack.push(1);
45508
- } else if (currentLevel === levelState.prevLevel) {
45509
- levelState.stack[levelState.stack.length - 1]++;
45510
- } else {
45511
- levelState.stack = levelState.stack.slice(0, currentLevel + 1);
45512
- levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
45513
- }
45514
- }
45515
- levelState.prevLevel = currentLevel;
45516
- return [...levelState.stack];
45517
- }
45518
- function extractAndRemoveConditionalPrefix(p2) {
45519
- const nodes = Array.from(p2.childNodes);
45520
- let fontFamily2 = null;
45521
- let fontSize2 = null;
45522
- let start2 = -1, end2 = -1;
45523
- nodes.forEach((node2, index2) => {
45524
- if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
45525
- start2 = index2;
45526
- }
45527
- if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
45528
- end2 = index2;
45529
- }
45530
- });
45531
- if (start2 !== -1 && end2 !== -1) {
45532
- for (let i2 = start2 + 1; i2 < end2; i2++) {
45533
- const node2 = nodes[i2];
45534
- if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
45535
- fontFamily2 = fontFamily2 || node2.style.fontFamily;
45536
- fontSize2 = fontSize2 || node2.style.fontSize;
45537
- }
45538
- }
45539
- for (let i2 = end2; i2 >= start2; i2--) {
45540
- p2.removeChild(p2.childNodes[i2]);
45541
- }
45542
- if (fontFamily2) p2.setAttribute("data-font-family", fontFamily2);
45543
- if (fontSize2) p2.setAttribute("data-font-size", fontSize2);
45544
- }
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);
45545
45686
  }
45546
- class InputRule {
45547
- constructor(config) {
45548
- __publicField$1(this, "match");
45549
- __publicField$1(this, "handler");
45550
- this.match = config.match;
45551
- this.handler = config.handler;
45552
- }
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;
45553
45698
  }
45554
- const inputRuleMatcherHandler = (text, match) => {
45555
- if (isRegExp(match)) {
45556
- return match.exec(text);
45557
- }
45558
- const inputRuleMatch = match(text);
45559
- if (!inputRuleMatch) {
45560
- return null;
45561
- }
45562
- const result = [inputRuleMatch.text];
45563
- result.index = inputRuleMatch.index;
45564
- result.input = text;
45565
- result.data = inputRuleMatch.data;
45566
- if (inputRuleMatch.replaceWith) {
45567
- if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
45568
- console.warn(
45569
- '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
45570
- );
45571
- }
45572
- 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);
45573
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;
45574
45732
  return result;
45575
- };
45576
- const run = (config) => {
45577
- const {
45578
- editor,
45579
- from: from2,
45580
- to,
45581
- text,
45582
- rules,
45583
- plugin: plugin2
45584
- } = config;
45585
- const { view } = editor;
45586
- if (view.composing) {
45587
- return false;
45588
- }
45589
- const $from = view.state.doc.resolve(from2);
45590
- if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
45591
- return false;
45592
- }
45593
- let matched = false;
45594
- const textBefore = getTextContentFromNodes($from) + text;
45595
- rules.forEach((rule) => {
45596
- if (matched) {
45597
- return;
45598
- }
45599
- const match = inputRuleMatcherHandler(textBefore, rule.match);
45600
- if (!match) {
45601
- return;
45602
- }
45603
- const tr = view.state.tr;
45604
- const state2 = chainableEditorState(tr, view.state);
45605
- const range2 = {
45606
- from: from2 - (match[0].length - text.length),
45607
- to
45608
- };
45609
- const { commands: commands2, chain, can } = new CommandService({
45610
- editor,
45611
- state: state2
45612
- });
45613
- const handler = rule.handler({
45614
- state: state2,
45615
- range: range2,
45616
- match,
45617
- commands: commands2,
45618
- chain,
45619
- can
45620
- });
45621
- if (handler === null || !tr.steps.length) {
45622
- return;
45623
- }
45624
- tr.setMeta(plugin2, {
45625
- transform: tr,
45626
- from: from2,
45627
- to,
45628
- text
45629
- });
45630
- view.dispatch(tr);
45631
- matched = true;
45632
- });
45633
- return matched;
45634
- };
45635
- const inputRulesPlugin = ({ editor, rules }) => {
45636
- const plugin2 = new Plugin({
45637
- key: new PluginKey("inputRulesPlugin"),
45638
- state: {
45639
- init() {
45640
- return null;
45641
- },
45642
- apply(tr, prev, state2) {
45643
- const stored = tr.getMeta(plugin2);
45644
- if (stored) {
45645
- return stored;
45646
- }
45647
- const simulatedInputMeta = tr.getMeta("applyInputRules");
45648
- const isSimulatedInput = !!simulatedInputMeta;
45649
- if (isSimulatedInput) {
45650
- setTimeout(() => {
45651
- let { text } = simulatedInputMeta;
45652
- if (typeof text !== "string") {
45653
- text = getHTMLFromFragment(Fragment.from(text), state2.schema);
45654
- }
45655
- const { from: from2 } = simulatedInputMeta;
45656
- const to = from2 + text.length;
45657
- run({
45658
- editor,
45659
- from: from2,
45660
- to,
45661
- text,
45662
- rules,
45663
- plugin: plugin2
45664
- });
45665
- });
45666
- }
45667
- 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;
45668
45765
  }
45669
- },
45670
- props: {
45671
- handleTextInput(view, from2, to, text) {
45672
- return run({
45673
- editor,
45674
- from: from2,
45675
- to,
45676
- text,
45677
- rules,
45678
- plugin: plugin2
45679
- });
45680
- },
45681
- // add support for input rules to trigger on enter
45682
- // this is useful for example for code blocks
45683
- handleKeyDown(view, event) {
45684
- if (event.key !== "Enter") {
45685
- return false;
45686
- }
45687
- const { $cursor } = view.state.selection;
45688
- if ($cursor) {
45689
- return run({
45690
- editor,
45691
- from: $cursor.pos,
45692
- to: $cursor.pos,
45693
- text: "\n",
45694
- rules,
45695
- plugin: plugin2
45696
- });
45697
- }
45698
- return false;
45699
- },
45700
- // Paste handler
45701
- handlePaste(view, event, slice2) {
45702
- const clipboard = event.clipboardData;
45703
- const html = clipboard.getData("text/html");
45704
- clipboard.getData("text/plain");
45705
- const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
45706
- if (fieldAnnotationContent.length) {
45707
- return false;
45708
- }
45709
- let source;
45710
- if (!html) {
45711
- source = "plain-text";
45712
- } else if (isWordHtml(html)) {
45713
- source = "word-html";
45714
- } else {
45715
- source = "browser-html";
45716
- }
45717
- switch (source) {
45718
- case "plain-text":
45719
- break;
45720
- case "word-html":
45721
- if (editor.options.mode === "docx") {
45722
- return handleDocxPaste(html, editor, view, plugin2);
45723
- }
45724
- case "browser-html":
45725
- return handleHtmlPaste$1(html, editor);
45726
- }
45727
- 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;
45728
45771
  }
45729
- },
45730
- isInputRules: true
45731
- });
45732
- return plugin2;
45733
- };
45734
- function isWordHtml(html) {
45735
- return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
45736
- }
45737
- const handleHtmlPaste$1 = (html, editor, plugin2) => {
45738
- const cleanedHtml = convertEmToPt(html);
45739
- const tempDiv = document.createElement("div");
45740
- tempDiv.innerHTML = cleanedHtml;
45741
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45742
- tempDiv.remove();
45743
- const { dispatch } = editor.view;
45744
- if (!dispatch) return false;
45745
- dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
45746
- return true;
45747
- };
45748
- const convertEmToPt = (html) => {
45749
- return html.replace(
45750
- /font-size\s*:\s*([\d.]+)em/gi,
45751
- (_, emValue) => {
45752
- const em = parseFloat(emValue);
45753
- const pt = Math.round(em * 12 * 100) / 100;
45754
- return `font-size: ${pt}pt`;
45755
45772
  }
45756
- );
45757
- };
45758
- function cleanHtmlUnnecessaryTags(html) {
45759
- 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;
45760
45784
  }
45761
45785
  const _ExtensionService = class _ExtensionService2 {
45762
45786
  constructor(extensions, userExtensions, editor) {
@@ -46596,6 +46620,7 @@
46596
46620
  mediaFiles: editor.storage.image.media,
46597
46621
  fonts: editor.options.fonts,
46598
46622
  isHeaderOrFooter: true,
46623
+ isHeadless: editor.options.isHeadless,
46599
46624
  annotations: true,
46600
46625
  currentPageNumber,
46601
46626
  parentEditor: editor,
@@ -46603,13 +46628,15 @@
46603
46628
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
46604
46629
  });
46605
46630
  const pm = editorContainer.querySelector(".ProseMirror");
46606
- pm.style.maxHeight = "100%";
46607
- pm.style.minHeight = "100%";
46608
- pm.style.outline = "none";
46609
- pm.style.border = "none";
46610
- pm.setAttribute("role", "textbox");
46611
- pm.setAttribute("aria-multiline", true);
46612
- 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
+ }
46613
46640
  return headerFooterEditor;
46614
46641
  };
46615
46642
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -46628,14 +46655,16 @@
46628
46655
  });
46629
46656
  });
46630
46657
  };
46631
- const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
46658
+ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
46632
46659
  editor.converter.headerEditors.forEach((item) => {
46633
46660
  item.editor.setEditable(isEditMode, false);
46634
46661
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46662
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46635
46663
  });
46636
46664
  editor.converter.footerEditors.forEach((item) => {
46637
46665
  item.editor.setEditable(isEditMode, false);
46638
46666
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46667
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46639
46668
  });
46640
46669
  if (isEditMode) {
46641
46670
  const pm = document.querySelector(".ProseMirror");
@@ -47716,6 +47745,19 @@
47716
47745
  );
47717
47746
  });
47718
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
+ };
47719
47761
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
47720
47762
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
47721
47763
  const { doc: doc2 } = editor.state;
@@ -47786,6 +47828,7 @@
47786
47828
  getAllHeaderFooterEditors,
47787
47829
  updateHeaderFooterFieldAnnotations,
47788
47830
  deleteHeaderFooterFieldAnnotations,
47831
+ resetHeaderFooterFieldAnnotations,
47789
47832
  cleanUpListsWithAnnotations
47790
47833
  };
47791
47834
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -47965,6 +48008,16 @@
47965
48008
  const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
47966
48009
  dispatch(tr);
47967
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
+ };
47968
48021
  const _Editor = class _Editor2 extends EventEmitter$2 {
47969
48022
  /**
47970
48023
  * Create a new Editor instance
@@ -48063,6 +48116,19 @@
48063
48116
  this.setHighContrastMode = setHighContrastMode;
48064
48117
  initMode();
48065
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
+ }
48066
48132
  /**
48067
48133
  * Set the toolbar for this editor
48068
48134
  * @param {Object} toolbar - The toolbar instance
@@ -48111,7 +48177,7 @@
48111
48177
  * @returns {boolean}
48112
48178
  */
48113
48179
  get isDestroyed() {
48114
- return this.view.isDestroyed;
48180
+ return this.view?.isDestroyed ?? true;
48115
48181
  }
48116
48182
  /**
48117
48183
  * Get the editor element
@@ -48154,7 +48220,12 @@
48154
48220
  this.commands.toggleTrackChangesShowOriginal();
48155
48221
  this.setEditable(false, false);
48156
48222
  this.setOptions({ documentMode: "viewing" });
48157
- toggleHeaderFooterEditMode(this, null, false);
48223
+ toggleHeaderFooterEditMode({
48224
+ editor: this,
48225
+ focusedSectionEditor: null,
48226
+ isEditMode: false,
48227
+ documentMode: cleanedMode
48228
+ });
48158
48229
  } else if (cleanedMode === "suggesting") {
48159
48230
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
48160
48231
  this.commands.disableTrackChangesShowOriginal();
@@ -48167,7 +48238,12 @@
48167
48238
  this.commands.disableTrackChanges();
48168
48239
  this.setEditable(true, false);
48169
48240
  this.setOptions({ documentMode: "editing" });
48170
- toggleHeaderFooterEditMode(this, null, false);
48241
+ toggleHeaderFooterEditMode({
48242
+ editor: this,
48243
+ focusedSectionEditor: null,
48244
+ isEditMode: false,
48245
+ documentMode: cleanedMode
48246
+ });
48171
48247
  }
48172
48248
  }
48173
48249
  /**
@@ -48344,29 +48420,26 @@
48344
48420
  };
48345
48421
  }
48346
48422
  /**
48347
- * Initialize default styles for the editor container and ProseMirror.
48348
- * Get page size and margins from the converter.
48349
- * Set document default font and font size.
48350
- *
48351
- * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
48352
- * @returns {void}
48353
- */
48354
- initDefaultStyles(element = this.element) {
48355
- if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
48356
- const proseMirror = element?.querySelector(".ProseMirror");
48423
+ * Attach styles and attributes to the editor element
48424
+ */
48425
+ updateEditorStyles(element, proseMirror) {
48357
48426
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
48358
- if (!proseMirror || !pageSize || !pageMargins) {
48427
+ if (!proseMirror || !element) {
48359
48428
  return;
48360
48429
  }
48361
48430
  proseMirror.setAttribute("role", "document");
48362
48431
  proseMirror.setAttribute("aria-multiline", true);
48363
48432
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
48364
48433
  proseMirror.setAttribute("aria-description", "");
48365
- element.style.width = pageSize.width + "in";
48366
- element.style.minWidth = pageSize.width + "in";
48367
- element.style.minHeight = pageSize.height + "in";
48368
- element.style.paddingLeft = pageMargins.left + "in";
48369
- 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
+ }
48370
48443
  element.style.boxSizing = "border-box";
48371
48444
  element.style.isolation = "isolate";
48372
48445
  proseMirror.style.outline = "none";
@@ -48387,6 +48460,19 @@
48387
48460
  proseMirror.style.paddingTop = "1in";
48388
48461
  proseMirror.style.paddingBottom = "1in";
48389
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);
48390
48476
  this.initMobileStyles(element);
48391
48477
  }
48392
48478
  /**
@@ -48598,10 +48684,25 @@
48598
48684
  */
48599
48685
  destroy() {
48600
48686
  this.emit("destroy");
48601
- if (this.view) this.view.destroy();
48687
+ this.unmount();
48688
+ this.destroyHeaderFooterEditors();
48602
48689
  __privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
48603
48690
  this.removeAllListeners();
48604
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
+ }
48605
48706
  /**
48606
48707
  * Check if migrations are needed for the data
48607
48708
  * @static
@@ -48619,7 +48720,7 @@
48619
48720
  * @returns {Object | void} Migration results
48620
48721
  */
48621
48722
  processCollaborationMigrations() {
48622
- console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev1");
48723
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev10");
48623
48724
  if (!this.options.ydoc) return;
48624
48725
  const metaMap = this.options.ydoc.getMap("meta");
48625
48726
  let docVersion = metaMap.get("version");
@@ -48815,7 +48916,7 @@
48815
48916
  this.emit("beforeCreate", { editor: this });
48816
48917
  this.on("contentError", this.options.onContentError);
48817
48918
  this.on("exception", this.options.onException);
48818
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48919
+ this.mount(this.options.element);
48819
48920
  this.initDefaultStyles();
48820
48921
  this.setDocumentMode(options2.documentMode);
48821
48922
  if (this.options.isHeadless) return;
@@ -48839,10 +48940,6 @@
48839
48940
  __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
48840
48941
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
48841
48942
  }
48842
- window.setTimeout(() => {
48843
- if (this.isDestroyed) return;
48844
- this.emit("create", { editor: this });
48845
- }, 0);
48846
48943
  };
48847
48944
  initRichText_fn = function(options2) {
48848
48945
  if (!options2.extensions || !options2.extensions.length) {
@@ -48854,7 +48951,7 @@
48854
48951
  this.on("beforeCreate", this.options.onBeforeCreate);
48855
48952
  this.emit("beforeCreate", { editor: this });
48856
48953
  this.on("contentError", this.options.onContentError);
48857
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48954
+ this.mount(this.options.element);
48858
48955
  this.on("create", this.options.onCreate);
48859
48956
  this.on("update", this.options.onUpdate);
48860
48957
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -48865,10 +48962,6 @@
48865
48962
  this.on("commentsLoaded", this.options.onCommentsLoaded);
48866
48963
  this.on("commentClick", this.options.onCommentClicked);
48867
48964
  this.on("locked", this.options.onDocumentLocked);
48868
- window.setTimeout(() => {
48869
- if (this.isDestroyed) return;
48870
- this.emit("create", { editor: this });
48871
- }, 0);
48872
48965
  };
48873
48966
  onFocus_fn = function({ editor, event }) {
48874
48967
  this.toolbar?.setActiveEditor(editor);
@@ -48989,14 +49082,15 @@
48989
49082
  }
48990
49083
  return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
48991
49084
  };
48992
- createView_fn = function() {
49085
+ createView_fn = function(element) {
48993
49086
  let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
48994
49087
  const state2 = { schema: this.schema };
48995
49088
  if (!this.options.ydoc) state2.doc = doc2;
48996
- this.view = new EditorView(this.options.element, {
49089
+ this.view = new EditorView(element, {
48997
49090
  ...this.options.editorProps,
48998
49091
  dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
48999
49092
  state: EditorState.create(state2),
49093
+ handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
49000
49094
  handleDoubleClick: async (view, pos, event) => {
49001
49095
  if (this.options.documentMode !== "editing") return;
49002
49096
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -49010,7 +49104,12 @@
49010
49104
  event.stopPropagation();
49011
49105
  if (!this.options.editable) {
49012
49106
  this.setEditable(true, false);
49013
- toggleHeaderFooterEditMode(this, null, false);
49107
+ toggleHeaderFooterEditMode({
49108
+ editor: this,
49109
+ focusedSectionEditor: null,
49110
+ isEditMode: false,
49111
+ documentMode: this.options.documentMode
49112
+ });
49014
49113
  const pm = document.querySelector(".ProseMirror");
49015
49114
  pm.classList.remove("header-footer-edit");
49016
49115
  pm.setAttribute("aria-readonly", false);
@@ -49023,8 +49122,6 @@
49023
49122
  });
49024
49123
  this.view.updateState(newState);
49025
49124
  this.createNodeViews();
49026
- const dom = this.view.dom;
49027
- dom.editor = this;
49028
49125
  this.options.telemetry?.sendReport();
49029
49126
  };
49030
49127
  onCollaborationReady_fn = function({ editor, ydoc }) {
@@ -49051,7 +49148,9 @@
49051
49148
  }, 50);
49052
49149
  };
49053
49150
  initPagination_fn = async function() {
49054
- if (this.options.isHeadless || !this.extensionService) return;
49151
+ if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
49152
+ return;
49153
+ }
49055
49154
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
49056
49155
  if (pagination && this.options.pagination) {
49057
49156
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -49063,7 +49162,7 @@
49063
49162
  }
49064
49163
  };
49065
49164
  dispatchTransaction_fn = function(transaction) {
49066
- if (this.view.isDestroyed) return;
49165
+ if (this.isDestroyed) return;
49067
49166
  let state2;
49068
49167
  try {
49069
49168
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -49115,6 +49214,11 @@
49115
49214
  transaction
49116
49215
  });
49117
49216
  };
49217
+ handleNodeSelection_fn = function(view, pos) {
49218
+ if (this.options.isHeaderOrFooter) {
49219
+ return setImageNodeSelection(view, pos);
49220
+ }
49221
+ };
49118
49222
  prepareDocumentForImport_fn = function(doc2) {
49119
49223
  const newState = EditorState.create({
49120
49224
  schema: this.schema,
@@ -51457,7 +51561,7 @@
51457
51561
  },
51458
51562
  addPmPlugins() {
51459
51563
  const { view } = this.editor;
51460
- const dropcapPlugin = new Plugin({
51564
+ new Plugin({
51461
51565
  name: "dropcapPlugin",
51462
51566
  key: new PluginKey("dropcapPlugin"),
51463
51567
  state: {
@@ -51477,7 +51581,7 @@
51477
51581
  }
51478
51582
  }
51479
51583
  });
51480
- return [dropcapPlugin];
51584
+ return [];
51481
51585
  }
51482
51586
  });
51483
51587
  const getDropcapDecorations = (state2, view) => {
@@ -51830,7 +51934,16 @@
51830
51934
  };
51831
51935
  },
51832
51936
  parseDOM() {
51833
- 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
+ }];
51834
51947
  },
51835
51948
  renderDOM({ htmlAttributes }) {
51836
51949
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -54827,6 +54940,8 @@
54827
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) {
54828
54941
  return removedNodes;
54829
54942
  }
54943
+ const hasDeletion = transactionDeletedAnything(tr);
54944
+ if (!hasDeletion) return removedNodes;
54830
54945
  tr.steps.forEach((step, stepIndex) => {
54831
54946
  if (step instanceof ReplaceStep && step.from !== step.to) {
54832
54947
  let mapping = tr.mapping.maps[stepIndex];
@@ -54843,6 +54958,14 @@
54843
54958
  });
54844
54959
  return removedNodes;
54845
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
+ }
54846
54969
  function trackFieldAnnotationsDeletion(editor, tr) {
54847
54970
  let removedAnnotations = [];
54848
54971
  try {
@@ -55238,8 +55361,18 @@
55238
55361
  };
55239
55362
  }
55240
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
+ },
55241
55374
  displayLabel: {
55242
- default: "Text field",
55375
+ default: "",
55243
55376
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
55244
55377
  renderDOM: (attrs) => {
55245
55378
  if (!attrs.displayLabel) return {};
@@ -55555,6 +55688,7 @@
55555
55688
  return renderer2();
55556
55689
  },
55557
55690
  addCommands() {
55691
+ const annotationTypes = this.options.types;
55558
55692
  return {
55559
55693
  /**
55560
55694
  * Add field annotation.
@@ -55576,7 +55710,12 @@
55576
55710
  let currentMarks = $pos.marks();
55577
55711
  currentMarks = currentMarks.length ? [...currentMarks] : null;
55578
55712
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
55579
- 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);
55580
55719
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
55581
55720
  if (editorFocus) {
55582
55721
  this.editor.view.focus();
@@ -55584,9 +55723,9 @@
55584
55723
  }
55585
55724
  return true;
55586
55725
  },
55587
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
55726
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
55588
55727
  const { from: from2 } = state2.selection;
55589
- commands2.addFieldAnnotation(from2, attrs, editorFocus);
55728
+ return commands2.addFieldAnnotation(from2, attrs, editorFocus);
55590
55729
  },
55591
55730
  /**
55592
55731
  * Replace field annotation.
@@ -55596,24 +55735,113 @@
55596
55735
  * from: 20,
55597
55736
  * to: 45,
55598
55737
  * attrs: {
55599
- * fieldType: 'TEXTINPUT'
55600
- * fieldColor: '#980043'
55738
+ * fieldType: 'TEXTINPUT'
55739
+ * fieldColor: '#980043'
55601
55740
  * }
55602
55741
  * ])
55603
55742
  */
55604
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
55743
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
55605
55744
  if (!dispatch) return true;
55606
- tr.setMeta("fieldAnnotationReplace", true);
55607
55745
  fieldsArray.forEach((annotation) => {
55608
55746
  let { from: from2, to, attrs } = annotation;
55609
55747
  let { schema } = editor;
55610
55748
  let newPosFrom = tr.mapping.map(from2);
55611
55749
  let newPosTo = tr.mapping.map(to);
55612
- 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);
55613
55755
  tr.replaceWith(newPosFrom, newPosTo, node2);
55614
55756
  });
55615
55757
  return true;
55616
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
+ },
55617
55845
  /**
55618
55846
  * Update annotations associated with a field.
55619
55847
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -56368,12 +56596,16 @@
56368
56596
  }
56369
56597
  let id = {};
56370
56598
  let { tr, schema } = view.state;
56371
- 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) {
56372
56604
  tr.deleteSelection();
56373
56605
  }
56374
56606
  let imageMeta = {
56375
56607
  type: "add",
56376
- pos: tr.selection.from,
56608
+ pos: selection.from,
56377
56609
  id
56378
56610
  };
56379
56611
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -61622,7 +61854,8 @@
61622
61854
  addStorage() {
61623
61855
  return {
61624
61856
  height: 0,
61625
- sectionData: null
61857
+ sectionData: null,
61858
+ headerFooterEditors: /* @__PURE__ */ new Map()
61626
61859
  };
61627
61860
  },
61628
61861
  addCommands() {
@@ -61665,13 +61898,14 @@
61665
61898
  shouldUpdate = true;
61666
61899
  shouldInitialize = meta.isReadyToInit;
61667
61900
  }
61901
+ const syncMeta = tr.getMeta("y-sync$");
61902
+ if (syncMeta && syncMeta.isChangeOrigin) {
61903
+ return { ...oldState };
61904
+ }
61668
61905
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
61669
61906
  if (imagePluginTransaction) {
61670
61907
  if (imagePluginTransaction.type === "remove") {
61671
- const imagePos = imagePluginTransaction.pos;
61672
- const domImage = editor.view.domAtPos(imagePos).node.querySelector("img");
61673
- if (domImage.complete) onImageLoad(editor);
61674
- else domImage.onload = () => onImageLoad(editor);
61908
+ onImageLoad(editor);
61675
61909
  }
61676
61910
  return { ...oldState };
61677
61911
  }
@@ -61698,6 +61932,7 @@
61698
61932
  if (isForceUpdate) shouldUpdate = true;
61699
61933
  return {
61700
61934
  ...oldState,
61935
+ decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
61701
61936
  isReadyToInit: shouldInitialize
61702
61937
  };
61703
61938
  }
@@ -61726,6 +61961,10 @@
61726
61961
  },
61727
61962
  onDestroy() {
61728
61963
  cleanupFloatingSeparators();
61964
+ const { headerFooterEditors } = this.editor.storage.pagination;
61965
+ if (headerFooterEditors) {
61966
+ headerFooterEditors.clear();
61967
+ }
61729
61968
  }
61730
61969
  });
61731
61970
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
@@ -61786,6 +62025,7 @@
61786
62025
  const calculatePageBreaks = (view, editor, sectionData) => {
61787
62026
  if (!editor.converter) return DecorationSet.empty;
61788
62027
  const pageSize = editor.converter.pageStyles?.pageSize;
62028
+ if (!pageSize) return DecorationSet.empty;
61789
62029
  const { width, height } = pageSize;
61790
62030
  if (!width || !height) return DecorationSet.empty;
61791
62031
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -61824,11 +62064,13 @@
61824
62064
  let pageHeightThreshold = pageHeight;
61825
62065
  let footer = null, header = null;
61826
62066
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
61827
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
62067
+ const isFirstHeader = true;
62068
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
61828
62069
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
61829
62070
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
61830
62071
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
61831
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
62072
+ const isLastFooter = true;
62073
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
61832
62074
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
61833
62075
  let coords = view?.coordsAtPos(doc2.content.size);
61834
62076
  if (!coords) return [];
@@ -61847,7 +62089,8 @@
61847
62089
  if (currentPageNumber === 1) {
61848
62090
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
61849
62091
  decorations.pop();
61850
- 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);
61851
62094
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
61852
62095
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
61853
62096
  }
@@ -61921,15 +62164,15 @@
61921
62164
  div2.style.height = bufferHeight + "px";
61922
62165
  return { nodeHeight: bufferHeight, node: div2 };
61923
62166
  }
61924
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
61925
- const headerDef = sectionData.headers?.[headerId];
62167
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
62168
+ const headerDef = sectionData?.headers?.[headerId];
61926
62169
  const minHeaderHeight = pageMargins.top * 96;
61927
62170
  const headerMargin = pageMargins.header * 96;
61928
62171
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
61929
62172
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
61930
62173
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
61931
62174
  const availableHeight = headerHeight - headerMargin;
61932
- const editorContainer = document.createElement("div");
62175
+ let editorContainer = document.createElement("div");
61933
62176
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
61934
62177
  headerId = "rId" + generateDocxRandomId();
61935
62178
  editor.converter.headerIds["default"] = headerId;
@@ -61941,23 +62184,31 @@
61941
62184
  };
61942
62185
  }
61943
62186
  const data = editor.converter.headers[headerId];
61944
- const editorSection = createHeaderFooterEditor({
61945
- editor,
61946
- data,
61947
- editorContainer,
61948
- appendToBody: false,
61949
- sectionId: headerId,
61950
- type: "header",
61951
- availableHeight,
61952
- currentPageNumber
61953
- });
61954
- editor.converter.headerEditors.push({
61955
- id: headerId,
61956
- editor: editorSection
61957
- });
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
+ }
61958
62210
  editorSection.setEditable(false, false);
61959
- broadcastEditorEvents(editor, editorSection);
61960
- editorContainer.className = "pagination-section-header";
62211
+ editorContainer.classList.add("pagination-section-header");
61961
62212
  editorContainer.style.paddingTop = headerMargin + "px";
61962
62213
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
61963
62214
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -61970,12 +62221,12 @@
61970
62221
  headerHeight
61971
62222
  };
61972
62223
  }
61973
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
61974
- const footerDef = sectionData.footers?.[footerId];
62224
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
62225
+ const footerDef = sectionData?.footers?.[footerId];
61975
62226
  const minFooterHeight = pageMargins.bottom * 96;
61976
62227
  const footerPaddingFromEdge = pageMargins.footer * 96;
61977
62228
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
61978
- const editorContainer = document.createElement("div");
62229
+ let editorContainer = document.createElement("div");
61979
62230
  if (!footerId && !editor.converter.footerIds["default"]) {
61980
62231
  footerId = "rId" + generateDocxRandomId();
61981
62232
  editor.converter.footerIds["default"] = footerId;
@@ -61987,23 +62238,31 @@
61987
62238
  };
61988
62239
  }
61989
62240
  const data = editor.converter.footers[footerId];
61990
- const editorSection = createHeaderFooterEditor({
61991
- editor,
61992
- data,
61993
- editorContainer,
61994
- appendToBody: false,
61995
- sectionId: footerId,
61996
- type: "footer",
61997
- availableHeight: footerHeight,
61998
- currentPageNumber
61999
- });
62000
- editor.converter.footerEditors.push({
62001
- id: footerId,
62002
- editor: editorSection
62003
- });
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
+ }
62004
62264
  editorSection.setEditable(false, false);
62005
- broadcastEditorEvents(editor, editorSection);
62006
- editorContainer.className = "pagination-section-footer";
62265
+ editorContainer.classList.add("pagination-section-footer");
62007
62266
  editorContainer.style.height = footerHeight + "px";
62008
62267
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
62009
62268
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -62016,10 +62275,28 @@
62016
62275
  footerHeight: footerHeight + footerPaddingFromEdge
62017
62276
  };
62018
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
+ };
62019
62291
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
62020
62292
  if (editor.options.documentMode !== "editing") return;
62021
62293
  editor.setEditable(false, false);
62022
- toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
62294
+ toggleHeaderFooterEditMode({
62295
+ editor,
62296
+ focusedSectionEditor: currentFocusedSectionEditor,
62297
+ isEditMode: true,
62298
+ documentMode: editor.options.documentMode
62299
+ });
62023
62300
  };
62024
62301
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
62025
62302
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -62574,7 +62851,7 @@
62574
62851
  }
62575
62852
  });
62576
62853
  const NodeResizerKey = new PluginKey("node-resizer");
62577
- const nodeResizer = (nodeNames = ["image"]) => {
62854
+ const nodeResizer = (nodeNames = ["image"], editor) => {
62578
62855
  let resizeState = {
62579
62856
  dragging: false,
62580
62857
  startX: 0,
@@ -62599,8 +62876,13 @@
62599
62876
  if (tr.getMeta(NodeResizerKey)) {
62600
62877
  return oldState;
62601
62878
  }
62602
- const decorations = [];
62879
+ if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
62603
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 = [];
62604
62886
  if (nodeNames.includes(selection.node?.type.name)) {
62605
62887
  decorations.push(
62606
62888
  Decoration.node(selection.from, selection.to, {
@@ -62803,7 +63085,7 @@
62803
63085
  const NodeResizer = Extension.create({
62804
63086
  name: "nodeResizer",
62805
63087
  addPmPlugins() {
62806
- return [nodeResizer(["image"])];
63088
+ return [nodeResizer(["image"], this.editor)];
62807
63089
  }
62808
63090
  });
62809
63091
  const getRichTextExtensions = () => {
@@ -71479,7 +71761,6 @@ ${style2}
71479
71761
  display: inline-block;
71480
71762
  position: relative;
71481
71763
  fill: currentColor;
71482
- transform: translateZ(0);
71483
71764
  `, [cM$1("color-transition", {
71484
71765
  transition: "color .3s var(--n-bezier)"
71485
71766
  }), cM$1("depth", {
@@ -89446,7 +89727,6 @@ ${style2}
89446
89727
  display: inline-block;
89447
89728
  position: relative;
89448
89729
  fill: currentColor;
89449
- transform: translateZ(0);
89450
89730
  `, [cM("color-transition", {
89451
89731
  transition: "color .3s var(--n-bezier)"
89452
89732
  }), cM("depth", {
@@ -93319,7 +93599,7 @@ ${style2}
93319
93599
  this.config.colors = shuffleArray(this.config.colors);
93320
93600
  this.userColorMap = /* @__PURE__ */ new Map();
93321
93601
  this.colorIndex = 0;
93322
- this.version = "0.13.2-rev1";
93602
+ this.version = "0.13.2-rev10";
93323
93603
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
93324
93604
  this.superdocId = config.superdocId || v4();
93325
93605
  this.colors = this.config.colors;