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

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 (56) 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-DyTkLKR1.es.js → super-editor.es-C0XuFRew.es.js} +1501 -1191
  10. package/dist/chunks/{super-editor.es--NMYzIh3.cjs → super-editor.es-DNcda5wa.cjs} +1501 -1191
  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/core/SuperDoc.d.ts +5 -0
  18. package/dist/core/SuperDoc.d.ts.map +1 -1
  19. package/dist/style.css +2 -2
  20. package/dist/super-editor/ai-writer.es.js +2 -2
  21. package/dist/super-editor/chunks/{converter-CJ9kHtZx.js → converter-g7XDS8H8.js} +632 -52
  22. package/dist/super-editor/chunks/{docx-zipper-scQqOWXA.js → docx-zipper-VpCXV0uV.js} +1 -1
  23. package/dist/super-editor/chunks/{editor-DM6yaxu_.js → editor-B3V2UfZk.js} +444 -707
  24. package/dist/super-editor/chunks/{toolbar-CIHbdcnv.js → toolbar-DbwzVBvd.js} +2 -3
  25. package/dist/super-editor/converter.es.js +2 -2
  26. package/dist/super-editor/core/Editor.d.ts +17 -3
  27. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  28. package/dist/super-editor/core/InputRule.d.ts +7 -0
  29. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  30. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  31. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  32. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
  33. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
  34. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  35. package/dist/super-editor/docx-zipper.es.js +2 -2
  36. package/dist/super-editor/editor.es.js +3 -3
  37. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  39. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  41. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  42. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  43. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  44. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  45. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  46. package/dist/super-editor/file-zipper.es.js +1 -1
  47. package/dist/super-editor/style.css +2 -2
  48. package/dist/super-editor/super-editor.es.js +7 -7
  49. package/dist/super-editor/toolbar.es.js +2 -2
  50. package/dist/super-editor.cjs +2 -2
  51. package/dist/super-editor.es.js +2 -2
  52. package/dist/superdoc.cjs +21 -9
  53. package/dist/superdoc.es.js +22 -10
  54. package/dist/superdoc.umd.js +1184 -855
  55. package/dist/superdoc.umd.js.map +1 -1
  56. 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-rev11") {
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-rev11") {
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, 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;
@@ -45228,535 +45655,132 @@
45228
45655
  49: "!",
45229
45656
  50: "@",
45230
45657
  51: "#",
45231
- 52: "$",
45232
- 53: "%",
45233
- 54: "^",
45234
- 55: "&",
45235
- 56: "*",
45236
- 57: "(",
45237
- 59: ":",
45238
- 61: "+",
45239
- 173: "_",
45240
- 186: ":",
45241
- 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
- }
45498
- };
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
- }
45658
+ 52: "$",
45659
+ 53: "%",
45660
+ 54: "^",
45661
+ 55: "&",
45662
+ 56: "*",
45663
+ 57: "(",
45664
+ 59: ":",
45665
+ 61: "+",
45666
+ 173: "_",
45667
+ 186: ":",
45668
+ 187: "+",
45669
+ 188: "<",
45670
+ 189: "_",
45671
+ 190: ">",
45672
+ 191: "?",
45673
+ 192: "~",
45674
+ 219: "{",
45675
+ 220: "|",
45676
+ 221: "}",
45677
+ 222: '"'
45678
+ };
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) {
@@ -46586,6 +46610,8 @@
46586
46610
  });
46587
46611
  if (appendToBody) document.body.appendChild(editorContainer);
46588
46612
  const headerFooterEditor = new Editor({
46613
+ documentMode: editor.options.documentMode,
46614
+ role: editor.options.role,
46589
46615
  loadFromSchema: true,
46590
46616
  mode: "docx",
46591
46617
  element: editorContainer,
@@ -46596,6 +46622,7 @@
46596
46622
  mediaFiles: editor.storage.image.media,
46597
46623
  fonts: editor.options.fonts,
46598
46624
  isHeaderOrFooter: true,
46625
+ isHeadless: editor.options.isHeadless,
46599
46626
  annotations: true,
46600
46627
  currentPageNumber,
46601
46628
  parentEditor: editor,
@@ -46603,13 +46630,15 @@
46603
46630
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
46604
46631
  });
46605
46632
  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.`);
46633
+ if (pm) {
46634
+ pm.style.maxHeight = "100%";
46635
+ pm.style.minHeight = "100%";
46636
+ pm.style.outline = "none";
46637
+ pm.style.border = "none";
46638
+ pm.setAttribute("role", "textbox");
46639
+ pm.setAttribute("aria-multiline", true);
46640
+ pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
46641
+ }
46613
46642
  return headerFooterEditor;
46614
46643
  };
46615
46644
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -46628,14 +46657,16 @@
46628
46657
  });
46629
46658
  });
46630
46659
  };
46631
- const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
46660
+ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
46632
46661
  editor.converter.headerEditors.forEach((item) => {
46633
46662
  item.editor.setEditable(isEditMode, false);
46634
46663
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46664
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46635
46665
  });
46636
46666
  editor.converter.footerEditors.forEach((item) => {
46637
46667
  item.editor.setEditable(isEditMode, false);
46638
46668
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46669
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46639
46670
  });
46640
46671
  if (isEditMode) {
46641
46672
  const pm = document.querySelector(".ProseMirror");
@@ -47716,6 +47747,19 @@
47716
47747
  );
47717
47748
  });
47718
47749
  };
47750
+ const resetHeaderFooterFieldAnnotations = ({ editor }) => {
47751
+ if (!editor) return;
47752
+ const sectionEditors = getAllHeaderFooterEditors(editor);
47753
+ sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
47754
+ sectionEditor.commands.resetFieldAnnotations();
47755
+ onHeaderFooterDataUpdate(
47756
+ { editor: sectionEditor },
47757
+ editor,
47758
+ sectionId,
47759
+ type2
47760
+ );
47761
+ });
47762
+ };
47719
47763
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
47720
47764
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
47721
47765
  const { doc: doc2 } = editor.state;
@@ -47786,6 +47830,7 @@
47786
47830
  getAllHeaderFooterEditors,
47787
47831
  updateHeaderFooterFieldAnnotations,
47788
47832
  deleteHeaderFooterFieldAnnotations,
47833
+ resetHeaderFooterFieldAnnotations,
47789
47834
  cleanUpListsWithAnnotations
47790
47835
  };
47791
47836
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -47965,6 +48010,16 @@
47965
48010
  const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
47966
48011
  dispatch(tr);
47967
48012
  };
48013
+ const setImageNodeSelection = (view, pos) => {
48014
+ const { doc: doc2 } = view.state;
48015
+ const node2 = doc2.nodeAt(pos);
48016
+ if (node2 && node2.type.name === "image") {
48017
+ const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
48018
+ view.dispatch(tr);
48019
+ return true;
48020
+ }
48021
+ return false;
48022
+ };
47968
48023
  const _Editor = class _Editor2 extends EventEmitter$2 {
47969
48024
  /**
47970
48025
  * Create a new Editor instance
@@ -48063,6 +48118,19 @@
48063
48118
  this.setHighContrastMode = setHighContrastMode;
48064
48119
  initMode();
48065
48120
  }
48121
+ mount(el) {
48122
+ __privateMethod$1(this, _Editor_instances, createView_fn).call(this, el);
48123
+ window.setTimeout(() => {
48124
+ if (this.isDestroyed) return;
48125
+ this.emit("create", { editor: this });
48126
+ }, 0);
48127
+ }
48128
+ unmount() {
48129
+ if (this.view) {
48130
+ this.view.destroy();
48131
+ }
48132
+ this.view = null;
48133
+ }
48066
48134
  /**
48067
48135
  * Set the toolbar for this editor
48068
48136
  * @param {Object} toolbar - The toolbar instance
@@ -48111,7 +48179,7 @@
48111
48179
  * @returns {boolean}
48112
48180
  */
48113
48181
  get isDestroyed() {
48114
- return this.view.isDestroyed;
48182
+ return this.view?.isDestroyed ?? true;
48115
48183
  }
48116
48184
  /**
48117
48185
  * Get the editor element
@@ -48154,7 +48222,12 @@
48154
48222
  this.commands.toggleTrackChangesShowOriginal();
48155
48223
  this.setEditable(false, false);
48156
48224
  this.setOptions({ documentMode: "viewing" });
48157
- toggleHeaderFooterEditMode(this, null, false);
48225
+ toggleHeaderFooterEditMode({
48226
+ editor: this,
48227
+ focusedSectionEditor: null,
48228
+ isEditMode: false,
48229
+ documentMode: cleanedMode
48230
+ });
48158
48231
  } else if (cleanedMode === "suggesting") {
48159
48232
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
48160
48233
  this.commands.disableTrackChangesShowOriginal();
@@ -48167,7 +48240,12 @@
48167
48240
  this.commands.disableTrackChanges();
48168
48241
  this.setEditable(true, false);
48169
48242
  this.setOptions({ documentMode: "editing" });
48170
- toggleHeaderFooterEditMode(this, null, false);
48243
+ toggleHeaderFooterEditMode({
48244
+ editor: this,
48245
+ focusedSectionEditor: null,
48246
+ isEditMode: false,
48247
+ documentMode: cleanedMode
48248
+ });
48171
48249
  }
48172
48250
  }
48173
48251
  /**
@@ -48265,10 +48343,10 @@
48265
48343
  }
48266
48344
  /**
48267
48345
  * Unregister a PM plugin
48268
- * @param {string|Object} nameOrPlugin - Plugin name or plugin instance
48346
+ * @param {string|Object} nameOrPluginKey - Plugin name or plugin instance
48269
48347
  * @returns {void}
48270
48348
  */
48271
- unregisterPlugin(nameOrPlugin) {
48349
+ unregisterPlugin(nameOrPluginKey) {
48272
48350
  if (this.isDestroyed) return;
48273
48351
  const name = typeof nameOrPluginKey === "string" ? `${nameOrPluginKey}$` : nameOrPluginKey.key;
48274
48352
  const state2 = this.state.reconfigure({
@@ -48344,29 +48422,26 @@
48344
48422
  };
48345
48423
  }
48346
48424
  /**
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");
48425
+ * Attach styles and attributes to the editor element
48426
+ */
48427
+ updateEditorStyles(element, proseMirror, hasPaginationEnabled = true) {
48357
48428
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
48358
- if (!proseMirror || !pageSize || !pageMargins) {
48429
+ if (!proseMirror || !element) {
48359
48430
  return;
48360
48431
  }
48361
48432
  proseMirror.setAttribute("role", "document");
48362
48433
  proseMirror.setAttribute("aria-multiline", true);
48363
48434
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
48364
48435
  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";
48436
+ if (pageSize) {
48437
+ element.style.width = pageSize.width + "in";
48438
+ element.style.minWidth = pageSize.width + "in";
48439
+ element.style.minHeight = pageSize.height + "in";
48440
+ }
48441
+ if (pageMargins) {
48442
+ element.style.paddingLeft = pageMargins.left + "in";
48443
+ element.style.paddingRight = pageMargins.right + "in";
48444
+ }
48370
48445
  element.style.boxSizing = "border-box";
48371
48446
  element.style.isolation = "isolate";
48372
48447
  proseMirror.style.outline = "none";
@@ -48383,10 +48458,26 @@
48383
48458
  element.style.webkitOverflowScrolling = "touch";
48384
48459
  const defaultLineHeight = 1.2;
48385
48460
  proseMirror.style.lineHeight = defaultLineHeight;
48386
- if (!this.options.extensions.find((e) => e.name === "pagination")) {
48461
+ if (!hasPaginationEnabled) {
48387
48462
  proseMirror.style.paddingTop = "1in";
48388
48463
  proseMirror.style.paddingBottom = "1in";
48464
+ } else {
48465
+ proseMirror.style.paddingTop = "0";
48466
+ proseMirror.style.paddingBottom = "0";
48389
48467
  }
48468
+ }
48469
+ /**
48470
+ * Initialize default styles for the editor container and ProseMirror.
48471
+ * Get page size and margins from the converter.
48472
+ * Set document default font and font size.
48473
+ *
48474
+ * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
48475
+ * @returns {void}
48476
+ */
48477
+ initDefaultStyles(element = this.element, isPaginationEnabled = true) {
48478
+ if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
48479
+ const proseMirror = element?.querySelector(".ProseMirror");
48480
+ this.updateEditorStyles(element, proseMirror, isPaginationEnabled);
48390
48481
  this.initMobileStyles(element);
48391
48482
  }
48392
48483
  /**
@@ -48434,6 +48525,26 @@
48434
48525
  }
48435
48526
  window.addEventListener("resize", () => handleResize);
48436
48527
  }
48528
+ /**
48529
+ * Initialize pagination, if the pagination extension is enabled.
48530
+ * @private
48531
+ * @async
48532
+ * @returns {Promise<void>}
48533
+ */
48534
+ async initPagination() {
48535
+ if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
48536
+ return;
48537
+ }
48538
+ const pagination = this.options.extensions.find((e) => e.name === "pagination");
48539
+ if (pagination && this.options.pagination) {
48540
+ console.debug("🔗 [super-editor] Initializing pagination");
48541
+ const sectionData = await initPaginationData(this);
48542
+ this.storage.pagination.sectionData = sectionData;
48543
+ const { state: state2, dispatch } = this.view;
48544
+ const tr = state2.tr.setMeta(PaginationPluginKey, { isReadyToInit: true });
48545
+ dispatch(tr);
48546
+ }
48547
+ }
48437
48548
  /**
48438
48549
  * Get attrs of the currently selected node or mark.
48439
48550
  * @param {String} nameOrType
@@ -48598,10 +48709,25 @@
48598
48709
  */
48599
48710
  destroy() {
48600
48711
  this.emit("destroy");
48601
- if (this.view) this.view.destroy();
48712
+ this.unmount();
48713
+ this.destroyHeaderFooterEditors();
48602
48714
  __privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
48603
48715
  this.removeAllListeners();
48604
48716
  }
48717
+ destroyHeaderFooterEditors() {
48718
+ try {
48719
+ const editors = [
48720
+ ...this.converter.headerEditors,
48721
+ ...this.converter.footerEditors
48722
+ ];
48723
+ for (let editorData of editors) {
48724
+ editorData.editor.destroy();
48725
+ }
48726
+ this.converter.headerEditors.length = 0;
48727
+ this.converter.footerEditors.length = 0;
48728
+ } catch (error) {
48729
+ }
48730
+ }
48605
48731
  /**
48606
48732
  * Check if migrations are needed for the data
48607
48733
  * @static
@@ -48619,7 +48745,7 @@
48619
48745
  * @returns {Object | void} Migration results
48620
48746
  */
48621
48747
  processCollaborationMigrations() {
48622
- console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev1");
48748
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev11");
48623
48749
  if (!this.options.ydoc) return;
48624
48750
  const metaMap = this.options.ydoc.getMap("meta");
48625
48751
  let docVersion = metaMap.get("version");
@@ -48669,7 +48795,7 @@
48669
48795
  __privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
48670
48796
  }
48671
48797
  if (!this.options.ydoc) {
48672
- __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
48798
+ this.initPagination();
48673
48799
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
48674
48800
  }
48675
48801
  }
@@ -48815,9 +48941,7 @@
48815
48941
  this.emit("beforeCreate", { editor: this });
48816
48942
  this.on("contentError", this.options.onContentError);
48817
48943
  this.on("exception", this.options.onException);
48818
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48819
- this.initDefaultStyles();
48820
- this.setDocumentMode(options2.documentMode);
48944
+ this.mount(this.options.element);
48821
48945
  if (this.options.isHeadless) return;
48822
48946
  this.on("create", this.options.onCreate);
48823
48947
  this.on("update", this.options.onUpdate);
@@ -48835,14 +48959,12 @@
48835
48959
  this.on("paginationUpdate", this.options.onPaginationUpdate);
48836
48960
  this.on("comment-positions", this.options.onCommentLocationsUpdate);
48837
48961
  this.initializeCollaborationData();
48962
+ this.initDefaultStyles();
48963
+ this.setDocumentMode(this.options.documentMode);
48838
48964
  if (!this.options.ydoc) {
48839
- __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
48965
+ this.initPagination();
48840
48966
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
48841
48967
  }
48842
- window.setTimeout(() => {
48843
- if (this.isDestroyed) return;
48844
- this.emit("create", { editor: this });
48845
- }, 0);
48846
48968
  };
48847
48969
  initRichText_fn = function(options2) {
48848
48970
  if (!options2.extensions || !options2.extensions.length) {
@@ -48854,7 +48976,7 @@
48854
48976
  this.on("beforeCreate", this.options.onBeforeCreate);
48855
48977
  this.emit("beforeCreate", { editor: this });
48856
48978
  this.on("contentError", this.options.onContentError);
48857
- __privateMethod$1(this, _Editor_instances, createView_fn).call(this);
48979
+ this.mount(this.options.element);
48858
48980
  this.on("create", this.options.onCreate);
48859
48981
  this.on("update", this.options.onUpdate);
48860
48982
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -48865,10 +48987,6 @@
48865
48987
  this.on("commentsLoaded", this.options.onCommentsLoaded);
48866
48988
  this.on("commentClick", this.options.onCommentClicked);
48867
48989
  this.on("locked", this.options.onDocumentLocked);
48868
- window.setTimeout(() => {
48869
- if (this.isDestroyed) return;
48870
- this.emit("create", { editor: this });
48871
- }, 0);
48872
48990
  };
48873
48991
  onFocus_fn = function({ editor, event }) {
48874
48992
  this.toolbar?.setActiveEditor(editor);
@@ -48891,7 +49009,7 @@
48891
49009
  const tr = this.state.tr.replaceWith(0, this.state.doc.content.size, doc2);
48892
49010
  this.view.dispatch(tr);
48893
49011
  setTimeout(() => {
48894
- __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
49012
+ this.initPagination();
48895
49013
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
48896
49014
  }, 50);
48897
49015
  };
@@ -48989,14 +49107,15 @@
48989
49107
  }
48990
49108
  return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
48991
49109
  };
48992
- createView_fn = function() {
49110
+ createView_fn = function(element) {
48993
49111
  let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
48994
49112
  const state2 = { schema: this.schema };
48995
49113
  if (!this.options.ydoc) state2.doc = doc2;
48996
- this.view = new EditorView(this.options.element, {
49114
+ this.view = new EditorView(element, {
48997
49115
  ...this.options.editorProps,
48998
49116
  dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
48999
49117
  state: EditorState.create(state2),
49118
+ handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
49000
49119
  handleDoubleClick: async (view, pos, event) => {
49001
49120
  if (this.options.documentMode !== "editing") return;
49002
49121
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -49010,7 +49129,12 @@
49010
49129
  event.stopPropagation();
49011
49130
  if (!this.options.editable) {
49012
49131
  this.setEditable(true, false);
49013
- toggleHeaderFooterEditMode(this, null, false);
49132
+ toggleHeaderFooterEditMode({
49133
+ editor: this,
49134
+ focusedSectionEditor: null,
49135
+ isEditMode: false,
49136
+ documentMode: this.options.documentMode
49137
+ });
49014
49138
  const pm = document.querySelector(".ProseMirror");
49015
49139
  pm.classList.remove("header-footer-edit");
49016
49140
  pm.setAttribute("aria-readonly", false);
@@ -49023,8 +49147,6 @@
49023
49147
  });
49024
49148
  this.view.updateState(newState);
49025
49149
  this.createNodeViews();
49026
- const dom = this.view.dom;
49027
- dom.editor = this;
49028
49150
  this.options.telemetry?.sendReport();
49029
49151
  };
49030
49152
  onCollaborationReady_fn = function({ editor, ydoc }) {
@@ -49033,7 +49155,7 @@
49033
49155
  this.options.onCollaborationReady({ editor, ydoc });
49034
49156
  this.options.collaborationIsReady = true;
49035
49157
  if (!this.options.isNewFile) {
49036
- __privateMethod$1(this, _Editor_instances, initPagination_fn).call(this);
49158
+ this.initPagination();
49037
49159
  __privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
49038
49160
  }
49039
49161
  };
@@ -49050,20 +49172,8 @@
49050
49172
  dispatch(tr);
49051
49173
  }, 50);
49052
49174
  };
49053
- initPagination_fn = async function() {
49054
- if (this.options.isHeadless || !this.extensionService) return;
49055
- const pagination = this.options.extensions.find((e) => e.name === "pagination");
49056
- if (pagination && this.options.pagination) {
49057
- console.debug("🔗 [super-editor] Initializing pagination");
49058
- const sectionData = await initPaginationData(this);
49059
- this.storage.pagination.sectionData = sectionData;
49060
- const { state: state2, dispatch } = this.view;
49061
- const tr = state2.tr.setMeta(PaginationPluginKey, { isReadyToInit: true });
49062
- dispatch(tr);
49063
- }
49064
- };
49065
49175
  dispatchTransaction_fn = function(transaction) {
49066
- if (this.view.isDestroyed) return;
49176
+ if (this.isDestroyed) return;
49067
49177
  let state2;
49068
49178
  try {
49069
49179
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -49115,6 +49225,11 @@
49115
49225
  transaction
49116
49226
  });
49117
49227
  };
49228
+ handleNodeSelection_fn = function(view, pos) {
49229
+ if (this.options.isHeaderOrFooter) {
49230
+ return setImageNodeSelection(view, pos);
49231
+ }
49232
+ };
49118
49233
  prepareDocumentForImport_fn = function(doc2) {
49119
49234
  const newState = EditorState.create({
49120
49235
  schema: this.schema,
@@ -51457,7 +51572,7 @@
51457
51572
  },
51458
51573
  addPmPlugins() {
51459
51574
  const { view } = this.editor;
51460
- const dropcapPlugin = new Plugin({
51575
+ new Plugin({
51461
51576
  name: "dropcapPlugin",
51462
51577
  key: new PluginKey("dropcapPlugin"),
51463
51578
  state: {
@@ -51477,7 +51592,7 @@
51477
51592
  }
51478
51593
  }
51479
51594
  });
51480
- return [dropcapPlugin];
51595
+ return [];
51481
51596
  }
51482
51597
  });
51483
51598
  const getDropcapDecorations = (state2, view) => {
@@ -51830,7 +51945,16 @@
51830
51945
  };
51831
51946
  },
51832
51947
  parseDOM() {
51833
- return [{ tag: "span" }];
51948
+ return [{
51949
+ tag: 'span[linebreaktype="page"]',
51950
+ getAttrs: (dom) => {
51951
+ if (!(dom instanceof HTMLElement)) return false;
51952
+ return {
51953
+ pageBreakSource: dom.getAttribute("pagebreaksource") || null,
51954
+ pageBreakType: dom.getAttribute("linebreaktype") || null
51955
+ };
51956
+ }
51957
+ }];
51834
51958
  },
51835
51959
  renderDOM({ htmlAttributes }) {
51836
51960
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -54827,6 +54951,8 @@
54827
54951
  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
54952
  return removedNodes;
54829
54953
  }
54954
+ const hasDeletion = transactionDeletedAnything(tr);
54955
+ if (!hasDeletion) return removedNodes;
54830
54956
  tr.steps.forEach((step, stepIndex) => {
54831
54957
  if (step instanceof ReplaceStep && step.from !== step.to) {
54832
54958
  let mapping = tr.mapping.maps[stepIndex];
@@ -54843,6 +54969,14 @@
54843
54969
  });
54844
54970
  return removedNodes;
54845
54971
  }
54972
+ function transactionDeletedAnything(tr) {
54973
+ return tr.steps.some((step) => {
54974
+ if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
54975
+ return step.from !== step.to;
54976
+ }
54977
+ return false;
54978
+ });
54979
+ }
54846
54980
  function trackFieldAnnotationsDeletion(editor, tr) {
54847
54981
  let removedAnnotations = [];
54848
54982
  try {
@@ -55238,8 +55372,18 @@
55238
55372
  };
55239
55373
  }
55240
55374
  },
55375
+ defaultDisplayLabel: {
55376
+ default: "",
55377
+ parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
55378
+ renderDOM: (attrs) => {
55379
+ if (!attrs.defaultDisplayLabel) return {};
55380
+ return {
55381
+ "data-default-display-label": attrs.defaultDisplayLabel
55382
+ };
55383
+ }
55384
+ },
55241
55385
  displayLabel: {
55242
- default: "Text field",
55386
+ default: "",
55243
55387
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
55244
55388
  renderDOM: (attrs) => {
55245
55389
  if (!attrs.displayLabel) return {};
@@ -55555,6 +55699,7 @@
55555
55699
  return renderer2();
55556
55700
  },
55557
55701
  addCommands() {
55702
+ const annotationTypes = this.options.types;
55558
55703
  return {
55559
55704
  /**
55560
55705
  * Add field annotation.
@@ -55576,7 +55721,12 @@
55576
55721
  let currentMarks = $pos.marks();
55577
55722
  currentMarks = currentMarks.length ? [...currentMarks] : null;
55578
55723
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
55579
- let node2 = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
55724
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55725
+ let node2 = schema.nodes[this.name].create({
55726
+ ...attrs,
55727
+ ...formatAttrs,
55728
+ defaultDisplayLabel
55729
+ }, null, null);
55580
55730
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
55581
55731
  if (editorFocus) {
55582
55732
  this.editor.view.focus();
@@ -55584,9 +55734,9 @@
55584
55734
  }
55585
55735
  return true;
55586
55736
  },
55587
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
55737
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
55588
55738
  const { from: from2 } = state2.selection;
55589
- commands2.addFieldAnnotation(from2, attrs, editorFocus);
55739
+ return commands2.addFieldAnnotation(from2, attrs, editorFocus);
55590
55740
  },
55591
55741
  /**
55592
55742
  * Replace field annotation.
@@ -55596,24 +55746,113 @@
55596
55746
  * from: 20,
55597
55747
  * to: 45,
55598
55748
  * attrs: {
55599
- * fieldType: 'TEXTINPUT'
55600
- * fieldColor: '#980043'
55749
+ * fieldType: 'TEXTINPUT'
55750
+ * fieldColor: '#980043'
55601
55751
  * }
55602
55752
  * ])
55603
55753
  */
55604
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
55754
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
55605
55755
  if (!dispatch) return true;
55606
- tr.setMeta("fieldAnnotationReplace", true);
55607
55756
  fieldsArray.forEach((annotation) => {
55608
55757
  let { from: from2, to, attrs } = annotation;
55609
55758
  let { schema } = editor;
55610
55759
  let newPosFrom = tr.mapping.map(from2);
55611
55760
  let newPosTo = tr.mapping.map(to);
55612
- let node2 = schema.nodes[this.name].create({ ...attrs }, null, null);
55761
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55762
+ let node2 = schema.nodes[this.name].create({
55763
+ ...attrs,
55764
+ defaultDisplayLabel
55765
+ }, null, null);
55613
55766
  tr.replaceWith(newPosFrom, newPosTo, node2);
55614
55767
  });
55615
55768
  return true;
55616
55769
  },
55770
+ /**
55771
+ * Replace annotations with a label (as text node) in selection.
55772
+ * @param options Additional options.
55773
+ * @example
55774
+ * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
55775
+ */
55776
+ replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
55777
+ return commands2.replaceFieldAnnotationsWithLabel(null, {
55778
+ ...options2,
55779
+ isInSelection: true
55780
+ });
55781
+ },
55782
+ /**
55783
+ * Replace annotations with a label (as text node).
55784
+ * @param fieldIdOrArray The field ID or array of field IDs.
55785
+ * @param options.isInSelection Find in selection instead of field IDs.
55786
+ * @param options.addToHistory Add to history or not.
55787
+ * @param options.types Annotation types to replace.
55788
+ * @example
55789
+ * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
55790
+ */
55791
+ replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
55792
+ isInSelection = false,
55793
+ addToHistory = false,
55794
+ types: types2 = annotationTypes
55795
+ } = {}) => ({ dispatch, state: state2, tr }) => {
55796
+ let { from: from2, to } = state2.selection;
55797
+ let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
55798
+ annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
55799
+ if (!annotations.length) {
55800
+ return true;
55801
+ }
55802
+ if (!addToHistory) {
55803
+ tr.setMeta("addToHistory", false);
55804
+ }
55805
+ if (dispatch) {
55806
+ annotations.forEach((annotation) => {
55807
+ let { pos, node: node2 } = annotation;
55808
+ let newPosFrom = tr.mapping.map(pos);
55809
+ let newPosTo = tr.mapping.map(pos + node2.nodeSize);
55810
+ let currentNode = tr.doc.nodeAt(newPosFrom);
55811
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55812
+ let $newPosFrom = tr.doc.resolve(newPosFrom);
55813
+ let currentMarks = $newPosFrom.marks();
55814
+ currentMarks = currentMarks.length ? [...currentMarks] : null;
55815
+ if (nodeEqual) {
55816
+ let label = node2.attrs.displayLabel || " ";
55817
+ let textNode = state2.schema.text(label, currentMarks);
55818
+ tr.replaceWith(newPosFrom, newPosTo, textNode);
55819
+ }
55820
+ });
55821
+ }
55822
+ return true;
55823
+ },
55824
+ /**
55825
+ * Resets all annotations to default values.
55826
+ * @example
55827
+ * editor.commands.resetFieldAnnotations()
55828
+ */
55829
+ resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
55830
+ let annotations = getAllFieldAnnotations(state2);
55831
+ if (!annotations.length) {
55832
+ return true;
55833
+ }
55834
+ tr.setMeta("fieldAnnotationUpdate", true);
55835
+ if (dispatch) {
55836
+ annotations.forEach(({ pos, node: node2 }) => {
55837
+ let newPos = tr.mapping.map(pos);
55838
+ let currentNode = tr.doc.nodeAt(newPos);
55839
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55840
+ if (nodeEqual) {
55841
+ let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
55842
+ tr.setNodeMarkup(newPos, void 0, {
55843
+ ...node2.attrs,
55844
+ // reset displayLabel to default.
55845
+ displayLabel,
55846
+ // reset attrs ​​for specific types.
55847
+ imageSrc: null,
55848
+ rawHtml: null,
55849
+ linkUrl: null
55850
+ });
55851
+ }
55852
+ });
55853
+ }
55854
+ return true;
55855
+ },
55617
55856
  /**
55618
55857
  * Update annotations associated with a field.
55619
55858
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -56368,12 +56607,16 @@
56368
56607
  }
56369
56608
  let id = {};
56370
56609
  let { tr, schema } = view.state;
56371
- if (!tr.selection.empty) {
56610
+ let { selection } = tr;
56611
+ if (editor.options.isHeaderOrFooter) {
56612
+ selection = editor.options.lastSelection;
56613
+ }
56614
+ if (!selection.empty && !editor.options.isHeaderOrFooter) {
56372
56615
  tr.deleteSelection();
56373
56616
  }
56374
56617
  let imageMeta = {
56375
56618
  type: "add",
56376
- pos: tr.selection.from,
56619
+ pos: selection.from,
56377
56620
  id
56378
56621
  };
56379
56622
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -61622,7 +61865,8 @@
61622
61865
  addStorage() {
61623
61866
  return {
61624
61867
  height: 0,
61625
- sectionData: null
61868
+ sectionData: null,
61869
+ headerFooterEditors: /* @__PURE__ */ new Map()
61626
61870
  };
61627
61871
  },
61628
61872
  addCommands() {
@@ -61631,6 +61875,19 @@
61631
61875
  return commands2.insertContent({
61632
61876
  type: "hardBreak"
61633
61877
  });
61878
+ },
61879
+ /**
61880
+ * Toggle pagination on/off
61881
+ * @returns {void}
61882
+ */
61883
+ togglePagination: () => ({ tr, state: state2, dispatch, editor }) => {
61884
+ const isEnabled = PaginationPluginKey.getState(state2)?.isEnabled;
61885
+ tr.setMeta(PaginationPluginKey, { isEnabled: !isEnabled });
61886
+ if (dispatch) {
61887
+ dispatch(tr);
61888
+ editor.initDefaultStyles(editor.element, !isEnabled);
61889
+ return true;
61890
+ }
61634
61891
  }
61635
61892
  };
61636
61893
  },
@@ -61656,22 +61913,33 @@
61656
61913
  return {
61657
61914
  isReadyToInit: false,
61658
61915
  decorations: DecorationSet.empty,
61659
- isDebugging
61916
+ isDebugging,
61917
+ isEnabled: editor.options.pagination
61660
61918
  };
61661
61919
  },
61662
61920
  apply(tr, oldState, prevEditorState, newEditorState) {
61663
61921
  const meta = tr.getMeta(PaginationPluginKey);
61922
+ if (meta && "isEnabled" in meta) {
61923
+ const newEnabled = meta.isEnabled;
61924
+ if (newEnabled) shouldUpdate = true;
61925
+ return {
61926
+ ...oldState,
61927
+ decorations: newEnabled ? oldState.decorations : DecorationSet.empty,
61928
+ isEnabled: newEnabled
61929
+ };
61930
+ }
61664
61931
  if (meta && meta.isReadyToInit) {
61665
61932
  shouldUpdate = true;
61666
61933
  shouldInitialize = meta.isReadyToInit;
61667
61934
  }
61935
+ const syncMeta = tr.getMeta("y-sync$");
61936
+ if (syncMeta && syncMeta.isChangeOrigin) {
61937
+ return { ...oldState };
61938
+ }
61668
61939
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
61669
61940
  if (imagePluginTransaction) {
61670
61941
  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);
61942
+ onImageLoad(editor);
61675
61943
  }
61676
61944
  return { ...oldState };
61677
61945
  }
@@ -61698,6 +61966,7 @@
61698
61966
  if (isForceUpdate) shouldUpdate = true;
61699
61967
  return {
61700
61968
  ...oldState,
61969
+ decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
61701
61970
  isReadyToInit: shouldInitialize
61702
61971
  };
61703
61972
  }
@@ -61707,6 +61976,7 @@
61707
61976
  let previousDecorations = DecorationSet.empty;
61708
61977
  return {
61709
61978
  update: (view2, prevState) => {
61979
+ if (!PaginationPluginKey.getState(view2.state)?.isEnabled) return;
61710
61980
  if (!shouldUpdate || isUpdating) return;
61711
61981
  isUpdating = true;
61712
61982
  hasInitialized = true;
@@ -61718,7 +61988,8 @@
61718
61988
  },
61719
61989
  props: {
61720
61990
  decorations(state2) {
61721
- return PaginationPluginKey.getState(state2).decorations;
61991
+ const pluginState = PaginationPluginKey.getState(state2);
61992
+ return pluginState.isEnabled ? pluginState.decorations : DecorationSet.empty;
61722
61993
  }
61723
61994
  }
61724
61995
  });
@@ -61726,6 +61997,10 @@
61726
61997
  },
61727
61998
  onDestroy() {
61728
61999
  cleanupFloatingSeparators();
62000
+ const { headerFooterEditors } = this.editor.storage.pagination;
62001
+ if (headerFooterEditors) {
62002
+ headerFooterEditors.clear();
62003
+ }
61729
62004
  }
61730
62005
  });
61731
62006
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
@@ -61786,6 +62061,7 @@
61786
62061
  const calculatePageBreaks = (view, editor, sectionData) => {
61787
62062
  if (!editor.converter) return DecorationSet.empty;
61788
62063
  const pageSize = editor.converter.pageStyles?.pageSize;
62064
+ if (!pageSize) return DecorationSet.empty;
61789
62065
  const { width, height } = pageSize;
61790
62066
  if (!width || !height) return DecorationSet.empty;
61791
62067
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -61824,11 +62100,13 @@
61824
62100
  let pageHeightThreshold = pageHeight;
61825
62101
  let footer = null, header = null;
61826
62102
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
61827
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
62103
+ const isFirstHeader = true;
62104
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
61828
62105
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
61829
62106
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
61830
62107
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
61831
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
62108
+ const isLastFooter = true;
62109
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
61832
62110
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
61833
62111
  let coords = view?.coordsAtPos(doc2.content.size);
61834
62112
  if (!coords) return [];
@@ -61847,7 +62125,8 @@
61847
62125
  if (currentPageNumber === 1) {
61848
62126
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
61849
62127
  decorations.pop();
61850
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
62128
+ const isFirstHeader2 = true;
62129
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
61851
62130
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
61852
62131
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
61853
62132
  }
@@ -61921,15 +62200,15 @@
61921
62200
  div2.style.height = bufferHeight + "px";
61922
62201
  return { nodeHeight: bufferHeight, node: div2 };
61923
62202
  }
61924
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
61925
- const headerDef = sectionData.headers?.[headerId];
62203
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
62204
+ const headerDef = sectionData?.headers?.[headerId];
61926
62205
  const minHeaderHeight = pageMargins.top * 96;
61927
62206
  const headerMargin = pageMargins.header * 96;
61928
62207
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
61929
62208
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
61930
62209
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
61931
62210
  const availableHeight = headerHeight - headerMargin;
61932
- const editorContainer = document.createElement("div");
62211
+ let editorContainer = document.createElement("div");
61933
62212
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
61934
62213
  headerId = "rId" + generateDocxRandomId();
61935
62214
  editor.converter.headerIds["default"] = headerId;
@@ -61941,23 +62220,31 @@
61941
62220
  };
61942
62221
  }
61943
62222
  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
- });
62223
+ const pageNumberIndex = currentPageNumber - 1;
62224
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
62225
+ let editorSection = null;
62226
+ const { headerFooterEditors } = editor.storage.pagination;
62227
+ if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
62228
+ const editorData = headerFooterEditors.get(editorKey);
62229
+ editorSection = editorData.editor;
62230
+ editorContainer = editorSection.element;
62231
+ } else {
62232
+ editorSection = createHeaderFooterEditor({
62233
+ editor,
62234
+ data,
62235
+ editorContainer,
62236
+ appendToBody: false,
62237
+ sectionId: headerId,
62238
+ type: "header",
62239
+ availableHeight,
62240
+ currentPageNumber
62241
+ });
62242
+ editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
62243
+ headerFooterEditors.set(editorKey, { editor: editorSection });
62244
+ broadcastEditorEvents(editor, editorSection);
62245
+ }
61958
62246
  editorSection.setEditable(false, false);
61959
- broadcastEditorEvents(editor, editorSection);
61960
- editorContainer.className = "pagination-section-header";
62247
+ editorContainer.classList.add("pagination-section-header");
61961
62248
  editorContainer.style.paddingTop = headerMargin + "px";
61962
62249
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
61963
62250
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -61970,12 +62257,12 @@
61970
62257
  headerHeight
61971
62258
  };
61972
62259
  }
61973
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
61974
- const footerDef = sectionData.footers?.[footerId];
62260
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
62261
+ const footerDef = sectionData?.footers?.[footerId];
61975
62262
  const minFooterHeight = pageMargins.bottom * 96;
61976
62263
  const footerPaddingFromEdge = pageMargins.footer * 96;
61977
62264
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
61978
- const editorContainer = document.createElement("div");
62265
+ let editorContainer = document.createElement("div");
61979
62266
  if (!footerId && !editor.converter.footerIds["default"]) {
61980
62267
  footerId = "rId" + generateDocxRandomId();
61981
62268
  editor.converter.footerIds["default"] = footerId;
@@ -61987,23 +62274,31 @@
61987
62274
  };
61988
62275
  }
61989
62276
  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
- });
62277
+ const pageNumberIndex = currentPageNumber - 1;
62278
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
62279
+ let editorSection = null;
62280
+ const { headerFooterEditors } = editor.storage.pagination;
62281
+ if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
62282
+ const editorData = headerFooterEditors.get(editorKey);
62283
+ editorSection = editorData.editor;
62284
+ editorContainer = editorSection.element;
62285
+ } else {
62286
+ editorSection = createHeaderFooterEditor({
62287
+ editor,
62288
+ data,
62289
+ editorContainer,
62290
+ appendToBody: false,
62291
+ sectionId: footerId,
62292
+ type: "footer",
62293
+ availableHeight: footerHeight,
62294
+ currentPageNumber
62295
+ });
62296
+ editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
62297
+ headerFooterEditors.set(editorKey, { editor: editorSection });
62298
+ broadcastEditorEvents(editor, editorSection);
62299
+ }
62004
62300
  editorSection.setEditable(false, false);
62005
- broadcastEditorEvents(editor, editorSection);
62006
- editorContainer.className = "pagination-section-footer";
62301
+ editorContainer.classList.add("pagination-section-footer");
62007
62302
  editorContainer.style.height = footerHeight + "px";
62008
62303
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
62009
62304
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -62016,10 +62311,28 @@
62016
62311
  footerHeight: footerHeight + footerPaddingFromEdge
62017
62312
  };
62018
62313
  }
62314
+ const getHeaderFooterEditorKey = ({
62315
+ pageNumber,
62316
+ isHeader,
62317
+ isFooter,
62318
+ isFirstHeader = false,
62319
+ isLastFooter = false
62320
+ }) => {
62321
+ if (isFirstHeader) return `first-header-${pageNumber}`;
62322
+ if (isLastFooter) return `last-footer-${pageNumber}`;
62323
+ if (isHeader) return `header-${pageNumber}`;
62324
+ if (isFooter) return `footer-${pageNumber}`;
62325
+ return void 0;
62326
+ };
62019
62327
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
62020
62328
  if (editor.options.documentMode !== "editing") return;
62021
62329
  editor.setEditable(false, false);
62022
- toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
62330
+ toggleHeaderFooterEditMode({
62331
+ editor,
62332
+ focusedSectionEditor: currentFocusedSectionEditor,
62333
+ isEditMode: true,
62334
+ documentMode: editor.options.documentMode
62335
+ });
62023
62336
  };
62024
62337
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
62025
62338
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -62574,7 +62887,7 @@
62574
62887
  }
62575
62888
  });
62576
62889
  const NodeResizerKey = new PluginKey("node-resizer");
62577
- const nodeResizer = (nodeNames = ["image"]) => {
62890
+ const nodeResizer = (nodeNames = ["image"], editor) => {
62578
62891
  let resizeState = {
62579
62892
  dragging: false,
62580
62893
  startX: 0,
@@ -62599,8 +62912,13 @@
62599
62912
  if (tr.getMeta(NodeResizerKey)) {
62600
62913
  return oldState;
62601
62914
  }
62602
- const decorations = [];
62915
+ if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
62603
62916
  const { selection } = newState;
62917
+ const node2 = selection.node;
62918
+ if (!node2 || !nodeNames.includes(node2.type.name)) {
62919
+ return DecorationSet.empty;
62920
+ }
62921
+ const decorations = [];
62604
62922
  if (nodeNames.includes(selection.node?.type.name)) {
62605
62923
  decorations.push(
62606
62924
  Decoration.node(selection.from, selection.to, {
@@ -62803,7 +63121,7 @@
62803
63121
  const NodeResizer = Extension.create({
62804
63122
  name: "nodeResizer",
62805
63123
  addPmPlugins() {
62806
- return [nodeResizer(["image"])];
63124
+ return [nodeResizer(["image"], this.editor)];
62807
63125
  }
62808
63126
  });
62809
63127
  const getRichTextExtensions = () => {
@@ -71479,7 +71797,6 @@ ${style2}
71479
71797
  display: inline-block;
71480
71798
  position: relative;
71481
71799
  fill: currentColor;
71482
- transform: translateZ(0);
71483
71800
  `, [cM$1("color-transition", {
71484
71801
  transition: "color .3s var(--n-bezier)"
71485
71802
  }), cM$1("depth", {
@@ -89446,7 +89763,6 @@ ${style2}
89446
89763
  display: inline-block;
89447
89764
  position: relative;
89448
89765
  fill: currentColor;
89449
- transform: translateZ(0);
89450
89766
  `, [cM("color-transition", {
89451
89767
  transition: "color .3s var(--n-bezier)"
89452
89768
  }), cM("depth", {
@@ -93319,7 +93635,7 @@ ${style2}
93319
93635
  this.config.colors = shuffleArray(this.config.colors);
93320
93636
  this.userColorMap = /* @__PURE__ */ new Map();
93321
93637
  this.colorIndex = 0;
93322
- this.version = "0.13.2-rev1";
93638
+ this.version = "0.13.2-rev11";
93323
93639
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
93324
93640
  this.superdocId = config.superdocId || v4();
93325
93641
  this.colors = this.config.colors;
@@ -93562,6 +93878,19 @@ ${style2}
93562
93878
  doc2.rulers = this.config.rulers;
93563
93879
  });
93564
93880
  }
93881
+ /**
93882
+ * Toggle pagination for SuperEditors
93883
+ * @returns {void}
93884
+ */
93885
+ togglePagination() {
93886
+ this.config.pagination = !this.config.pagination;
93887
+ this.superdocStore.documents.forEach((doc2) => {
93888
+ const editor = doc2.getEditor();
93889
+ if (editor) {
93890
+ editor.commands.togglePagination();
93891
+ }
93892
+ });
93893
+ }
93565
93894
  #addToolbar() {
93566
93895
  const moduleConfig = this.config.modules?.toolbar || {};
93567
93896
  this.toolbarElement = this.config.modules?.toolbar?.selector || this.config.toolbar;