@harbour-enterprises/superdoc 0.13.2-rev8 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/chunks/{eventemitter3-KKY27oz-.es.js → eventemitter3-BrspJk8q.es.js} +1 -1
  2. package/dist/chunks/{eventemitter3-CHxWXmuK.cjs → eventemitter3-DfVviFzP.cjs} +1 -1
  3. package/dist/chunks/{index-Bd4H2zrq.cjs → index-B4J7wgs6.cjs} +2 -2
  4. package/dist/chunks/{index-Bdjh4ZPT.cjs → index-Cdsq63Xq.cjs} +4 -4
  5. package/dist/chunks/{index-DuSTYEOs.es.js → index-Diu6UKHt.es.js} +4 -4
  6. package/dist/chunks/{index-B1TbritH.es.js → index-Hr3Um-Bg.es.js} +2 -2
  7. package/dist/chunks/{jszip-9bCX1h2W.cjs → jszip-BTAcmbVg.cjs} +1 -1
  8. package/dist/chunks/{jszip-Cl3s9njw.es.js → jszip-DckFs3A7.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-Cz-ceaxn.cjs → super-editor.es-BM89AzsN.cjs} +704 -859
  10. package/dist/chunks/{super-editor.es-BY5Eoi9A.es.js → super-editor.es-BNyzbCw0.es.js} +704 -859
  11. package/dist/chunks/{url-CJP-Jmfp.cjs → url-BIzg4y2i.cjs} +2 -2
  12. package/dist/chunks/{url-CLwIePTG.es.js → url-CHayXMZH.es.js} +2 -2
  13. package/dist/chunks/{vue-BBJVqxjL.es.js → vue-Bi1uWinj.es.js} +3 -10
  14. package/dist/chunks/{vue-BBjMeYfo.cjs → vue-HIY1g7dm.cjs} +3 -10
  15. package/dist/chunks/{xml-js-k_RETz76.cjs → xml-js-BjqmFOSP.cjs} +225 -239
  16. package/dist/chunks/{xml-js-Bp5Hoq_3.es.js → xml-js-CfClL-1b.es.js} +225 -239
  17. package/dist/style.css +1 -2
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-RV0QN3HE.js → converter-CsK9KCaL.js} +55 -637
  20. package/dist/super-editor/chunks/{docx-zipper-C5TBRQNB.js → docx-zipper-6iKmmME2.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-XlwZxMCI.js → editor-Cxb-Zwyu.js} +676 -256
  22. package/dist/super-editor/chunks/{toolbar-52_BMgdJ.js → toolbar-QHIHaeEf.js} +3 -2
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +0 -7
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +0 -7
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  29. package/dist/super-editor/docx-zipper.es.js +2 -2
  30. package/dist/super-editor/editor.es.js +3 -3
  31. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  32. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  33. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  34. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  35. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +1 -6
  36. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  39. package/dist/super-editor/file-zipper.es.js +1 -1
  40. package/dist/super-editor/style.css +1 -2
  41. package/dist/super-editor/super-editor.es.js +7 -7
  42. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  43. package/dist/super-editor/toolbar.es.js +2 -2
  44. package/dist/super-editor.cjs +2 -2
  45. package/dist/super-editor.es.js +2 -2
  46. package/dist/superdoc.cjs +9 -8
  47. package/dist/superdoc.es.js +10 -9
  48. package/dist/superdoc.umd.js +708 -869
  49. package/dist/superdoc.umd.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +0 -2
  52. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +0 -1
  53. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +0 -3
  54. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +0 -1
@@ -9,12 +9,12 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
12
+ 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;
13
13
  import * as Y from "yjs";
14
14
  import { UndoManager, Item as Item$1, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
15
- import { P as PluginKey, a as Plugin, M as Mapping, c as callOrGet, i as isEmptyObject, S as Schema$1, T as TextSelection, b as canSplit, l as liftTarget, A as AllSelection, d as canJoin, j as joinPoint, N as NodeSelection, r as replaceStep$1, e as Selection, F as Fragment, R as ReplaceAroundStep$1, f as Slice, o as objectIncludes, g as deleteProps, D as DOMParser$1, h as ReplaceStep, k as NodeRange, m as findWrapping, n as isMacOS, p as isIOS, q as generateDocxRandomId, s as minMax, t as chainableEditorState, u as generateRandom32BitHex, v as DOMSerializer, w as Mark$1, x as dropPoint, y as process$1, B as Buffer2, z as inputRulesPlugin, C as TrackDeleteMarkName, E as TrackInsertMarkName, G as v4, H as TrackFormatMarkName, I as comments_module_events, J as AddMarkStep, K as RemoveMarkStep, L as twipsToLines, O as pixelsToTwips, Q as CommandService, U as SuperConverter, V as EditorState, W as hasSomeParentWithClass, X as parseSizeUnit, Y as getLineHeightValueString, Z as InputRule, _ as toKebabCase, $ as kebabCase, a0 as getColStyleDeclaration, a1 as SelectionRange, a2 as Transform, a3 as createColGroup } from "./converter-RV0QN3HE.js";
15
+ import { P as PluginKey, a as Plugin, M as Mapping, c as callOrGet, i as isEmptyObject, S as Schema$1, T as TextSelection, b as canSplit, l as liftTarget, A as AllSelection, d as canJoin, j as joinPoint, N as NodeSelection, r as replaceStep$1, e as Selection, F as Fragment, R as ReplaceAroundStep, f as Slice, o as objectIncludes, g as deleteProps, D as DOMParser$1, h as ReplaceStep, k as NodeRange, m as findWrapping, n as isMacOS, p as isIOS, q as generateDocxRandomId, s as minMax, t as generateRandom32BitHex, u as DOMSerializer, v as Mark$1, w as dropPoint, x as process$1, B as Buffer2, y as isRegExp, z as TrackDeleteMarkName, C as TrackInsertMarkName, E as v4, G as TrackFormatMarkName, H as comments_module_events, I as AddMarkStep, J as RemoveMarkStep, K as twipsToLines, L as pixelsToTwips, O as SuperConverter, Q as EditorState, U as hasSomeParentWithClass, V as parseSizeUnit, W as getLineHeightValueString, X as toKebabCase, Y as kebabCase, Z as getColStyleDeclaration, _ as SelectionRange, $ as Transform, a0 as createColGroup } from "./converter-CsK9KCaL.js";
16
16
  import { ref, computed, createElementBlock, openBlock, withModifiers, Fragment as Fragment$1, renderList, normalizeClass, createCommentVNode, toDisplayString, createElementVNode, createApp } from "vue";
17
- import { D as DocxZipper } from "./docx-zipper-C5TBRQNB.js";
17
+ import { D as DocxZipper } from "./docx-zipper-6iKmmME2.js";
18
18
  function getMarksFromSelection(state) {
19
19
  const { from: from2, to, empty: empty2 } = state.selection;
20
20
  const marks = [];
@@ -1203,6 +1203,164 @@ createMarksSchema_fn = function(markExtensions, attributes, editor) {
1203
1203
  };
1204
1204
  __privateAdd(_Schema, _Schema_static);
1205
1205
  let Schema = _Schema;
1206
+ function chainableEditorState(transaction, state) {
1207
+ let { selection, doc: doc2, storedMarks } = transaction;
1208
+ return {
1209
+ ...state,
1210
+ apply: state.apply.bind(state),
1211
+ applyTransaction: state.applyTransaction.bind(state),
1212
+ plugins: state.plugins,
1213
+ schema: state.schema,
1214
+ reconfigure: state.reconfigure.bind(state),
1215
+ toJSON: state.toJSON.bind(state),
1216
+ get storedMarks() {
1217
+ return storedMarks;
1218
+ },
1219
+ get selection() {
1220
+ return selection;
1221
+ },
1222
+ get doc() {
1223
+ return doc2;
1224
+ },
1225
+ get tr() {
1226
+ selection = transaction.selection;
1227
+ doc2 = transaction.doc;
1228
+ storedMarks = transaction.storedMarks;
1229
+ return transaction;
1230
+ }
1231
+ };
1232
+ }
1233
+ class CommandService {
1234
+ constructor(props) {
1235
+ __publicField(this, "editor");
1236
+ __publicField(this, "rawCommands");
1237
+ this.editor = props.editor;
1238
+ this.rawCommands = this.editor.extensionService.commands;
1239
+ }
1240
+ /**
1241
+ * Static method for creating a service.
1242
+ * @param args Arguments for the constructor.
1243
+ */
1244
+ static create(...args) {
1245
+ return new CommandService(...args);
1246
+ }
1247
+ /**
1248
+ * Get editor state.
1249
+ */
1250
+ get state() {
1251
+ return this.editor.state;
1252
+ }
1253
+ /**
1254
+ * Get all commands with wrapped command method.
1255
+ */
1256
+ get commands() {
1257
+ const { editor, state } = this;
1258
+ const { view } = editor;
1259
+ const { tr } = state;
1260
+ const props = this.createProps(tr);
1261
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
1262
+ const method = (...args) => {
1263
+ const fn2 = command2(...args)(props);
1264
+ if (!tr.getMeta("preventDispatch")) {
1265
+ view.dispatch(tr);
1266
+ }
1267
+ return fn2;
1268
+ };
1269
+ return [name, method];
1270
+ });
1271
+ return Object.fromEntries(entries);
1272
+ }
1273
+ /**
1274
+ * Create a chain of commands to call multiple commands at once.
1275
+ */
1276
+ get chain() {
1277
+ return () => this.createChain();
1278
+ }
1279
+ /**
1280
+ * Check if a command or a chain of commands can be executed. Without executing it.
1281
+ */
1282
+ get can() {
1283
+ return () => this.createCan();
1284
+ }
1285
+ /**
1286
+ * Creates a chain of commands.
1287
+ * @param startTr Start transaction.
1288
+ * @param shouldDispatch Should dispatch or not.
1289
+ */
1290
+ createChain(startTr, shouldDispatch = true) {
1291
+ const { editor, state, rawCommands } = this;
1292
+ const { view } = editor;
1293
+ const callbacks = [];
1294
+ const hasStartTr = !!startTr;
1295
+ const tr = startTr || state.tr;
1296
+ const run2 = () => {
1297
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
1298
+ view.dispatch(tr);
1299
+ }
1300
+ return callbacks.every((cb) => cb === true);
1301
+ };
1302
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
1303
+ const chainedCommand = (...args) => {
1304
+ const props = this.createProps(tr, shouldDispatch);
1305
+ const callback = command2(...args)(props);
1306
+ callbacks.push(callback);
1307
+ return chain;
1308
+ };
1309
+ return [name, chainedCommand];
1310
+ });
1311
+ const chain = {
1312
+ ...Object.fromEntries(entries),
1313
+ run: run2
1314
+ };
1315
+ return chain;
1316
+ }
1317
+ /**
1318
+ * Creates a can check for commands.
1319
+ * @param startTr Start transaction.
1320
+ */
1321
+ createCan(startTr) {
1322
+ const { rawCommands, state } = this;
1323
+ const dispatch = false;
1324
+ const tr = startTr || state.tr;
1325
+ const props = this.createProps(tr, dispatch);
1326
+ const commands2 = Object.fromEntries(
1327
+ Object.entries(rawCommands).map(([name, command2]) => {
1328
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
1329
+ })
1330
+ );
1331
+ return {
1332
+ ...commands2,
1333
+ chain: () => this.createChain(tr, dispatch)
1334
+ };
1335
+ }
1336
+ /**
1337
+ * Creates default props for the command method.
1338
+ * @param {*} tr Transaction.
1339
+ * @param {*} shouldDispatch Check if should dispatch.
1340
+ * @returns Object with props.
1341
+ */
1342
+ createProps(tr, shouldDispatch = true) {
1343
+ const { editor, state, rawCommands } = this;
1344
+ const { view } = editor;
1345
+ const props = {
1346
+ tr,
1347
+ editor,
1348
+ view,
1349
+ state: chainableEditorState(tr, state),
1350
+ dispatch: shouldDispatch ? () => void 0 : void 0,
1351
+ chain: () => this.createChain(tr, shouldDispatch),
1352
+ can: () => this.createCan(tr),
1353
+ get commands() {
1354
+ return Object.fromEntries(
1355
+ Object.entries(rawCommands).map(([name, command2]) => {
1356
+ return [name, (...args) => command2(...args)(props)];
1357
+ })
1358
+ );
1359
+ }
1360
+ };
1361
+ return props;
1362
+ }
1363
+ }
1206
1364
  const first = (commands2) => (props) => {
1207
1365
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
1208
1366
  for (let i = 0; i < items.length; i += 1) {
@@ -1564,7 +1722,7 @@ function deleteBarrier(state, $cut, dispatch, dir) {
1564
1722
  for (let i = conn.length - 1; i >= 0; i--)
1565
1723
  wrap = Fragment.from(conn[i].create(null, wrap));
1566
1724
  wrap = Fragment.from(before.copy(wrap));
1567
- let tr = state.tr.step(new ReplaceAroundStep$1($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap, 1, 0), conn.length, true));
1725
+ let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap, 1, 0), conn.length, true));
1568
1726
  let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
1569
1727
  if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
1570
1728
  tr.join($joinAt.pos);
@@ -1595,7 +1753,7 @@ function deleteBarrier(state, $cut, dispatch, dir) {
1595
1753
  let end2 = Fragment.empty;
1596
1754
  for (let i = wrap.length - 1; i >= 0; i--)
1597
1755
  end2 = Fragment.from(wrap[i].copy(end2));
1598
- let tr = state.tr.step(new ReplaceAroundStep$1($cut.pos - wrap.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap.length, 0), 0, true));
1756
+ let tr = state.tr.step(new ReplaceAroundStep($cut.pos - wrap.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap.length, 0), 0, true));
1599
1757
  dispatch(tr.scrollIntoView());
1600
1758
  }
1601
1759
  return true;
@@ -2168,7 +2326,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
2168
2326
  return;
2169
2327
  }
2170
2328
  const step = tr.steps[last];
2171
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
2329
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
2172
2330
  return;
2173
2331
  }
2174
2332
  const map2 = tr.mapping.maps[last];
@@ -2314,7 +2472,7 @@ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
2314
2472
  let content = Fragment.empty;
2315
2473
  for (let i = wrappers.length - 1; i >= 0; i--)
2316
2474
  content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
2317
- tr.step(new ReplaceAroundStep$1(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new Slice(content, 0, 0), wrappers.length, true));
2475
+ tr.step(new ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new Slice(content, 0, 0), wrappers.length, true));
2318
2476
  let found = 0;
2319
2477
  for (let i = 0; i < wrappers.length; i++)
2320
2478
  if (wrappers[i].type == listType)
@@ -2347,7 +2505,7 @@ function liftListItem$1(itemType) {
2347
2505
  function liftToOuterList(state, dispatch, itemType, range) {
2348
2506
  let tr = state.tr, end2 = range.end, endOfList = range.$to.end(range.depth);
2349
2507
  if (end2 < endOfList) {
2350
- tr.step(new ReplaceAroundStep$1(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
2508
+ tr.step(new ReplaceAroundStep(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
2351
2509
  range = new NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
2352
2510
  }
2353
2511
  const target = liftTarget(range);
@@ -2374,7 +2532,7 @@ function liftOutOfList(state, dispatch, range) {
2374
2532
  if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
2375
2533
  return false;
2376
2534
  let start2 = $start.pos, end2 = start2 + item.nodeSize;
2377
- 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));
2535
+ 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));
2378
2536
  dispatch(tr.scrollIntoView());
2379
2537
  return true;
2380
2538
  }
@@ -2395,7 +2553,7 @@ function sinkListItem$1(itemType) {
2395
2553
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
2396
2554
  let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
2397
2555
  let before = range.start, after = range.end;
2398
- dispatch(state.tr.step(new ReplaceAroundStep$1(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
2556
+ dispatch(state.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
2399
2557
  }
2400
2558
  return true;
2401
2559
  };
@@ -9988,8 +10146,7 @@ const restoreRelativeSelection = (tr, relSel, binding) => {
9988
10146
  binding.mapping
9989
10147
  );
9990
10148
  if (anchor !== null && head !== null) {
9991
- const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
9992
- tr.setSelection(sel);
10149
+ tr.setSelection(TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head)));
9993
10150
  }
9994
10151
  }
9995
10152
  }
@@ -10770,7 +10927,7 @@ const setMeta = (view, key, value) => {
10770
10927
  };
10771
10928
  const absolutePositionToRelativePosition = (pos, type, mapping) => {
10772
10929
  if (pos === 0) {
10773
- return Y.createRelativePositionFromTypeIndex(type, 0, type.length === 0 ? -1 : 0);
10930
+ return Y.createRelativePositionFromTypeIndex(type, 0, -1);
10774
10931
  }
10775
10932
  let n = type._first === null ? null : (
10776
10933
  /** @type {Y.ContentType} */
@@ -10779,7 +10936,7 @@ const absolutePositionToRelativePosition = (pos, type, mapping) => {
10779
10936
  while (n !== null && type !== n) {
10780
10937
  if (n instanceof Y.XmlText) {
10781
10938
  if (n._length >= pos) {
10782
- return Y.createRelativePositionFromTypeIndex(n, pos, type.length === 0 ? -1 : 0);
10939
+ return Y.createRelativePositionFromTypeIndex(n, pos, -1);
10783
10940
  } else {
10784
10941
  pos -= n._length;
10785
10942
  }
@@ -10843,7 +11000,7 @@ const absolutePositionToRelativePosition = (pos, type, mapping) => {
10843
11000
  return createRelativePosition(n._item.parent, n._item);
10844
11001
  }
10845
11002
  }
10846
- return Y.createRelativePositionFromTypeIndex(type, type._length, type.length === 0 ? -1 : 0);
11003
+ return Y.createRelativePositionFromTypeIndex(type, type._length, -1);
10847
11004
  };
10848
11005
  const createRelativePosition = (type, item) => {
10849
11006
  let typeid = null;
@@ -11440,6 +11597,409 @@ function isExtensionRulesEnabled(extension, enabled) {
11440
11597
  }
11441
11598
  return enabled;
11442
11599
  }
11600
+ function getHTMLFromFragment(fragment, schema) {
11601
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
11602
+ const temporaryDocument = document.implementation.createHTMLDocument();
11603
+ const container = temporaryDocument.createElement("div");
11604
+ container.appendChild(documentFragment);
11605
+ return container.innerHTML;
11606
+ }
11607
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
11608
+ let textBefore = "";
11609
+ const sliceEndPos = $from.parentOffset;
11610
+ $from.parent.nodesBetween(
11611
+ Math.max(0, sliceEndPos - maxMatch),
11612
+ sliceEndPos,
11613
+ (node, pos, parent, index2) => {
11614
+ const chunk = node.type.spec.toText?.({
11615
+ node,
11616
+ pos,
11617
+ parent,
11618
+ index: index2
11619
+ }) || node.textContent || "%leaf%";
11620
+ textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
11621
+ }
11622
+ );
11623
+ return textBefore;
11624
+ };
11625
+ const handleDocxPaste = (html, editor, view, plugin) => {
11626
+ const { converter } = editor;
11627
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin);
11628
+ let cleanedHtml = convertEmToPt(html);
11629
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
11630
+ const tempDiv = document.createElement("div");
11631
+ tempDiv.innerHTML = cleanedHtml;
11632
+ const paragraphs = tempDiv.querySelectorAll("p");
11633
+ paragraphs.forEach((p) => {
11634
+ const innerHTML3 = p.innerHTML;
11635
+ if (!innerHTML3.includes("<!--[if !supportLists]")) return;
11636
+ const styleAttr = p.getAttribute("style") || "";
11637
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
11638
+ if (msoListMatch) {
11639
+ const [, abstractId, level] = msoListMatch;
11640
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
11641
+ if (!listNumId) return;
11642
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
11643
+ const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
11644
+ p.setAttribute("data-num-id", listNumId);
11645
+ p.setAttribute("data-list-level", level - 1);
11646
+ p.setAttribute("data-start", start2);
11647
+ p.setAttribute("data-lvl-text", lvlText);
11648
+ p.setAttribute("data-num-fmt", numFmt);
11649
+ }
11650
+ extractAndRemoveConditionalPrefix(p);
11651
+ });
11652
+ transformWordLists(tempDiv);
11653
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
11654
+ tempDiv.remove();
11655
+ const { dispatch } = editor.view;
11656
+ if (!dispatch) return false;
11657
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
11658
+ return true;
11659
+ };
11660
+ const getLevelDefinition = (abstractDefinition, level) => {
11661
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
11662
+ const levelElement = abstractDefinition.elements.find((el) => {
11663
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
11664
+ });
11665
+ if (!levelElement) return null;
11666
+ const { elements } = levelElement;
11667
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
11668
+ const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
11669
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
11670
+ return { lvlText, start: start2, numFmt, elements };
11671
+ };
11672
+ const getListNumIdFromAbstract = (abstractId, editor) => {
11673
+ const { definitions } = editor?.converter?.numbering;
11674
+ if (!definitions) return null;
11675
+ const matchedDefinition = Object.values(definitions).find((def) => {
11676
+ return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
11677
+ });
11678
+ return matchedDefinition?.attributes?.["w:numId"];
11679
+ };
11680
+ const getListAbstractDefinition = (abstractId, editor) => {
11681
+ const { abstracts = {} } = editor?.converter?.numbering;
11682
+ return abstracts[abstractId] || null;
11683
+ };
11684
+ const transformWordLists = (container) => {
11685
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
11686
+ const listMap = /* @__PURE__ */ new Map();
11687
+ const listLevels = {};
11688
+ for (const p of paragraphs) {
11689
+ const listId = p.getAttribute("data-num-id");
11690
+ const level = parseInt(p.getAttribute("data-list-level"));
11691
+ const numFmt = p.getAttribute("data-num-fmt");
11692
+ const start2 = p.getAttribute("data-start");
11693
+ const lvlText = p.getAttribute("data-lvl-text");
11694
+ if (!listMap.has(listId)) listMap.set(listId, []);
11695
+ listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
11696
+ }
11697
+ for (const [id, items] of listMap.entries()) {
11698
+ if (!listLevels[id]) {
11699
+ listLevels[id] = {
11700
+ stack: [],
11701
+ counts: {},
11702
+ prevLevel: null
11703
+ };
11704
+ }
11705
+ const parentStack = [];
11706
+ items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
11707
+ const listLevel = generateListNestingPath(listLevels, id, level);
11708
+ const li = document.createElement("li");
11709
+ li.innerHTML = p.innerHTML;
11710
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
11711
+ li.setAttribute("data-num-id", id);
11712
+ li.setAttribute("data-lvl-text", lvlText);
11713
+ li.setAttribute("data-num-fmt", numFmt);
11714
+ if (p.hasAttribute("data-font-family")) {
11715
+ li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
11716
+ }
11717
+ if (p.hasAttribute("data-font-size")) {
11718
+ li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
11719
+ }
11720
+ const parentNode2 = p.parentNode;
11721
+ let listForLevel = parentStack[level];
11722
+ if (!listForLevel) {
11723
+ const newList = document.createElement("ol");
11724
+ newList.setAttribute("data-list-id", id);
11725
+ newList.level = level;
11726
+ if (level > 0) {
11727
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
11728
+ if (parentLi) parentLi.appendChild(newList);
11729
+ } else {
11730
+ parentNode2.insertBefore(newList, p);
11731
+ }
11732
+ parentStack[level] = newList;
11733
+ parentStack.length = level + 1;
11734
+ listForLevel = newList;
11735
+ }
11736
+ listForLevel.appendChild(li);
11737
+ p.remove();
11738
+ });
11739
+ }
11740
+ };
11741
+ function generateListNestingPath(listLevels, listId, currentLevel) {
11742
+ const levelState = listLevels[listId];
11743
+ if (!levelState.stack) levelState.stack = [];
11744
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
11745
+ if (levelState.prevLevel === null) {
11746
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
11747
+ } else {
11748
+ if (currentLevel > levelState.prevLevel) {
11749
+ levelState.stack.push(1);
11750
+ } else if (currentLevel === levelState.prevLevel) {
11751
+ levelState.stack[levelState.stack.length - 1]++;
11752
+ } else {
11753
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
11754
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
11755
+ }
11756
+ }
11757
+ levelState.prevLevel = currentLevel;
11758
+ return [...levelState.stack];
11759
+ }
11760
+ function extractAndRemoveConditionalPrefix(p) {
11761
+ const nodes = Array.from(p.childNodes);
11762
+ let fontFamily = null;
11763
+ let fontSize = null;
11764
+ let start2 = -1, end2 = -1;
11765
+ nodes.forEach((node, index2) => {
11766
+ if (node.nodeType === Node.COMMENT_NODE && node.nodeValue.includes("[if !supportLists]")) {
11767
+ start2 = index2;
11768
+ }
11769
+ if (start2 !== -1 && node.nodeType === Node.COMMENT_NODE && node.nodeValue.includes("[endif]")) {
11770
+ end2 = index2;
11771
+ }
11772
+ });
11773
+ if (start2 !== -1 && end2 !== -1) {
11774
+ for (let i = start2 + 1; i < end2; i++) {
11775
+ const node = nodes[i];
11776
+ if (node.nodeType === Node.ELEMENT_NODE && node.style) {
11777
+ fontFamily = fontFamily || node.style.fontFamily;
11778
+ fontSize = fontSize || node.style.fontSize;
11779
+ }
11780
+ }
11781
+ for (let i = end2; i >= start2; i--) {
11782
+ p.removeChild(p.childNodes[i]);
11783
+ }
11784
+ if (fontFamily) p.setAttribute("data-font-family", fontFamily);
11785
+ if (fontSize) p.setAttribute("data-font-size", fontSize);
11786
+ }
11787
+ }
11788
+ class InputRule {
11789
+ constructor(config) {
11790
+ __publicField(this, "match");
11791
+ __publicField(this, "handler");
11792
+ this.match = config.match;
11793
+ this.handler = config.handler;
11794
+ }
11795
+ }
11796
+ const inputRuleMatcherHandler = (text, match) => {
11797
+ if (isRegExp(match)) {
11798
+ return match.exec(text);
11799
+ }
11800
+ const inputRuleMatch = match(text);
11801
+ if (!inputRuleMatch) {
11802
+ return null;
11803
+ }
11804
+ const result = [inputRuleMatch.text];
11805
+ result.index = inputRuleMatch.index;
11806
+ result.input = text;
11807
+ result.data = inputRuleMatch.data;
11808
+ if (inputRuleMatch.replaceWith) {
11809
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
11810
+ console.warn(
11811
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
11812
+ );
11813
+ }
11814
+ result.push(inputRuleMatch.replaceWith);
11815
+ }
11816
+ return result;
11817
+ };
11818
+ const run = (config) => {
11819
+ const {
11820
+ editor,
11821
+ from: from2,
11822
+ to,
11823
+ text,
11824
+ rules,
11825
+ plugin
11826
+ } = config;
11827
+ const { view } = editor;
11828
+ if (view.composing) {
11829
+ return false;
11830
+ }
11831
+ const $from = view.state.doc.resolve(from2);
11832
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
11833
+ return false;
11834
+ }
11835
+ let matched = false;
11836
+ const textBefore = getTextContentFromNodes($from) + text;
11837
+ rules.forEach((rule) => {
11838
+ if (matched) {
11839
+ return;
11840
+ }
11841
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
11842
+ if (!match) {
11843
+ return;
11844
+ }
11845
+ const tr = view.state.tr;
11846
+ const state = chainableEditorState(tr, view.state);
11847
+ const range = {
11848
+ from: from2 - (match[0].length - text.length),
11849
+ to
11850
+ };
11851
+ const { commands: commands2, chain, can } = new CommandService({
11852
+ editor,
11853
+ state
11854
+ });
11855
+ const handler = rule.handler({
11856
+ state,
11857
+ range,
11858
+ match,
11859
+ commands: commands2,
11860
+ chain,
11861
+ can
11862
+ });
11863
+ if (handler === null || !tr.steps.length) {
11864
+ return;
11865
+ }
11866
+ tr.setMeta(plugin, {
11867
+ transform: tr,
11868
+ from: from2,
11869
+ to,
11870
+ text
11871
+ });
11872
+ view.dispatch(tr);
11873
+ matched = true;
11874
+ });
11875
+ return matched;
11876
+ };
11877
+ const inputRulesPlugin = ({ editor, rules }) => {
11878
+ const plugin = new Plugin({
11879
+ key: new PluginKey("inputRulesPlugin"),
11880
+ state: {
11881
+ init() {
11882
+ return null;
11883
+ },
11884
+ apply(tr, prev, state) {
11885
+ const stored = tr.getMeta(plugin);
11886
+ if (stored) {
11887
+ return stored;
11888
+ }
11889
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
11890
+ const isSimulatedInput = !!simulatedInputMeta;
11891
+ if (isSimulatedInput) {
11892
+ setTimeout(() => {
11893
+ let { text } = simulatedInputMeta;
11894
+ if (typeof text !== "string") {
11895
+ text = getHTMLFromFragment(Fragment.from(text), state.schema);
11896
+ }
11897
+ const { from: from2 } = simulatedInputMeta;
11898
+ const to = from2 + text.length;
11899
+ run({
11900
+ editor,
11901
+ from: from2,
11902
+ to,
11903
+ text,
11904
+ rules,
11905
+ plugin
11906
+ });
11907
+ });
11908
+ }
11909
+ return tr.selectionSet || tr.docChanged ? null : prev;
11910
+ }
11911
+ },
11912
+ props: {
11913
+ handleTextInput(view, from2, to, text) {
11914
+ return run({
11915
+ editor,
11916
+ from: from2,
11917
+ to,
11918
+ text,
11919
+ rules,
11920
+ plugin
11921
+ });
11922
+ },
11923
+ // add support for input rules to trigger on enter
11924
+ // this is useful for example for code blocks
11925
+ handleKeyDown(view, event) {
11926
+ if (event.key !== "Enter") {
11927
+ return false;
11928
+ }
11929
+ const { $cursor } = view.state.selection;
11930
+ if ($cursor) {
11931
+ return run({
11932
+ editor,
11933
+ from: $cursor.pos,
11934
+ to: $cursor.pos,
11935
+ text: "\n",
11936
+ rules,
11937
+ plugin
11938
+ });
11939
+ }
11940
+ return false;
11941
+ },
11942
+ // Paste handler
11943
+ handlePaste(view, event, slice2) {
11944
+ const clipboard = event.clipboardData;
11945
+ const html = clipboard.getData("text/html");
11946
+ clipboard.getData("text/plain");
11947
+ const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
11948
+ if (fieldAnnotationContent.length) {
11949
+ return false;
11950
+ }
11951
+ let source;
11952
+ if (!html) {
11953
+ source = "plain-text";
11954
+ } else if (isWordHtml(html)) {
11955
+ source = "word-html";
11956
+ } else {
11957
+ source = "browser-html";
11958
+ }
11959
+ switch (source) {
11960
+ case "plain-text":
11961
+ break;
11962
+ case "word-html":
11963
+ if (editor.options.mode === "docx") {
11964
+ return handleDocxPaste(html, editor, view, plugin);
11965
+ }
11966
+ case "browser-html":
11967
+ return handleHtmlPaste$1(html, editor);
11968
+ }
11969
+ return false;
11970
+ }
11971
+ },
11972
+ isInputRules: true
11973
+ });
11974
+ return plugin;
11975
+ };
11976
+ function isWordHtml(html) {
11977
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
11978
+ }
11979
+ const handleHtmlPaste$1 = (html, editor, plugin) => {
11980
+ const cleanedHtml = convertEmToPt(html);
11981
+ const tempDiv = document.createElement("div");
11982
+ tempDiv.innerHTML = cleanedHtml;
11983
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
11984
+ tempDiv.remove();
11985
+ const { dispatch } = editor.view;
11986
+ if (!dispatch) return false;
11987
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
11988
+ return true;
11989
+ };
11990
+ const convertEmToPt = (html) => {
11991
+ return html.replace(
11992
+ /font-size\s*:\s*([\d.]+)em/gi,
11993
+ (_, emValue) => {
11994
+ const em = parseFloat(emValue);
11995
+ const pt = Math.round(em * 12 * 100) / 100;
11996
+ return `font-size: ${pt}pt`;
11997
+ }
11998
+ );
11999
+ };
12000
+ function cleanHtmlUnnecessaryTags(html) {
12001
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
12002
+ }
11443
12003
  const _ExtensionService = class _ExtensionService {
11444
12004
  constructor(extensions, userExtensions, editor) {
11445
12005
  __privateAdd(this, _ExtensionService_instances);
@@ -12287,7 +12847,6 @@ const createHeaderFooterEditor = ({
12287
12847
  mediaFiles: editor.storage.image.media,
12288
12848
  fonts: editor.options.fonts,
12289
12849
  isHeaderOrFooter: true,
12290
- isHeadless: editor.options.isHeadless,
12291
12850
  annotations: true,
12292
12851
  currentPageNumber,
12293
12852
  parentEditor: editor,
@@ -12295,15 +12854,13 @@ const createHeaderFooterEditor = ({
12295
12854
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type)
12296
12855
  });
12297
12856
  const pm = editorContainer.querySelector(".ProseMirror");
12298
- if (pm) {
12299
- pm.style.maxHeight = "100%";
12300
- pm.style.minHeight = "100%";
12301
- pm.style.outline = "none";
12302
- pm.style.border = "none";
12303
- pm.setAttribute("role", "textbox");
12304
- pm.setAttribute("aria-multiline", true);
12305
- pm.setAttribute("aria-label", `${type} content area. Double click to start typing.`);
12306
- }
12857
+ pm.style.maxHeight = "100%";
12858
+ pm.style.minHeight = "100%";
12859
+ pm.style.outline = "none";
12860
+ pm.style.border = "none";
12861
+ pm.setAttribute("role", "textbox");
12862
+ pm.setAttribute("aria-multiline", true);
12863
+ pm.setAttribute("aria-label", `${type} content area. Double click to start typing.`);
12307
12864
  return headerFooterEditor;
12308
12865
  };
12309
12866
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -12322,16 +12879,14 @@ const broadcastEditorEvents = (editor, sectionEditor) => {
12322
12879
  });
12323
12880
  });
12324
12881
  };
12325
- const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
12882
+ const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
12326
12883
  editor.converter.headerEditors.forEach((item) => {
12327
12884
  item.editor.setEditable(isEditMode, false);
12328
12885
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
12329
- item.editor.view.dom.setAttribute("documentmode", documentMode);
12330
12886
  });
12331
12887
  editor.converter.footerEditors.forEach((item) => {
12332
12888
  item.editor.setEditable(isEditMode, false);
12333
12889
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
12334
- item.editor.view.dom.setAttribute("documentmode", documentMode);
12335
12890
  });
12336
12891
  if (isEditMode) {
12337
12892
  const pm = document.querySelector(".ProseMirror");
@@ -13661,16 +14216,6 @@ const setWordSelection = (view, pos) => {
13661
14216
  const tr = state.tr.setSelection(TextSelection.create(state.doc, word.from, word.to));
13662
14217
  dispatch(tr);
13663
14218
  };
13664
- const setImageNodeSelection = (view, pos) => {
13665
- const { doc: doc2 } = view.state;
13666
- const node = doc2.nodeAt(pos);
13667
- if (node && node.type.name === "image") {
13668
- const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
13669
- view.dispatch(tr);
13670
- return true;
13671
- }
13672
- return false;
13673
- };
13674
14219
  const _Editor = class _Editor extends EventEmitter {
13675
14220
  /**
13676
14221
  * Create a new Editor instance
@@ -13797,19 +14342,6 @@ const _Editor = class _Editor extends EventEmitter {
13797
14342
  this.setHighContrastMode = setHighContrastMode;
13798
14343
  initMode();
13799
14344
  }
13800
- mount(el) {
13801
- __privateMethod(this, _Editor_instances, createView_fn).call(this, el);
13802
- window.setTimeout(() => {
13803
- if (this.isDestroyed) return;
13804
- this.emit("create", { editor: this });
13805
- }, 0);
13806
- }
13807
- unmount() {
13808
- if (this.view) {
13809
- this.view.destroy();
13810
- }
13811
- this.view = null;
13812
- }
13813
14345
  /**
13814
14346
  * Set the toolbar for this editor
13815
14347
  * @param {Object} toolbar - The toolbar instance
@@ -13858,7 +14390,7 @@ const _Editor = class _Editor extends EventEmitter {
13858
14390
  * @returns {boolean}
13859
14391
  */
13860
14392
  get isDestroyed() {
13861
- return this.view?.isDestroyed ?? true;
14393
+ return this.view.isDestroyed;
13862
14394
  }
13863
14395
  /**
13864
14396
  * Get the editor element
@@ -13901,12 +14433,7 @@ const _Editor = class _Editor extends EventEmitter {
13901
14433
  this.commands.toggleTrackChangesShowOriginal();
13902
14434
  this.setEditable(false, false);
13903
14435
  this.setOptions({ documentMode: "viewing" });
13904
- toggleHeaderFooterEditMode({
13905
- editor: this,
13906
- focusedSectionEditor: null,
13907
- isEditMode: false,
13908
- documentMode: cleanedMode
13909
- });
14436
+ toggleHeaderFooterEditMode(this, null, false);
13910
14437
  } else if (cleanedMode === "suggesting") {
13911
14438
  __privateMethod(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
13912
14439
  this.commands.disableTrackChangesShowOriginal();
@@ -13919,12 +14446,7 @@ const _Editor = class _Editor extends EventEmitter {
13919
14446
  this.commands.disableTrackChanges();
13920
14447
  this.setEditable(true, false);
13921
14448
  this.setOptions({ documentMode: "editing" });
13922
- toggleHeaderFooterEditMode({
13923
- editor: this,
13924
- focusedSectionEditor: null,
13925
- isEditMode: false,
13926
- documentMode: cleanedMode
13927
- });
14449
+ toggleHeaderFooterEditMode(this, null, false);
13928
14450
  }
13929
14451
  }
13930
14452
  /**
@@ -14101,26 +14623,29 @@ const _Editor = class _Editor extends EventEmitter {
14101
14623
  };
14102
14624
  }
14103
14625
  /**
14104
- * Attach styles and attributes to the editor element
14105
- */
14106
- updateEditorStyles(element, proseMirror) {
14626
+ * Initialize default styles for the editor container and ProseMirror.
14627
+ * Get page size and margins from the converter.
14628
+ * Set document default font and font size.
14629
+ *
14630
+ * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
14631
+ * @returns {void}
14632
+ */
14633
+ initDefaultStyles(element = this.element) {
14634
+ if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
14635
+ const proseMirror = element?.querySelector(".ProseMirror");
14107
14636
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
14108
- if (!proseMirror || !element) {
14637
+ if (!proseMirror || !pageSize || !pageMargins) {
14109
14638
  return;
14110
14639
  }
14111
14640
  proseMirror.setAttribute("role", "document");
14112
14641
  proseMirror.setAttribute("aria-multiline", true);
14113
14642
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
14114
14643
  proseMirror.setAttribute("aria-description", "");
14115
- if (pageSize) {
14116
- element.style.width = pageSize.width + "in";
14117
- element.style.minWidth = pageSize.width + "in";
14118
- element.style.minHeight = pageSize.height + "in";
14119
- }
14120
- if (pageMargins) {
14121
- element.style.paddingLeft = pageMargins.left + "in";
14122
- element.style.paddingRight = pageMargins.right + "in";
14123
- }
14644
+ element.style.width = pageSize.width + "in";
14645
+ element.style.minWidth = pageSize.width + "in";
14646
+ element.style.minHeight = pageSize.height + "in";
14647
+ element.style.paddingLeft = pageMargins.left + "in";
14648
+ element.style.paddingRight = pageMargins.right + "in";
14124
14649
  element.style.boxSizing = "border-box";
14125
14650
  element.style.isolation = "isolate";
14126
14651
  proseMirror.style.outline = "none";
@@ -14141,19 +14666,6 @@ const _Editor = class _Editor extends EventEmitter {
14141
14666
  proseMirror.style.paddingTop = "1in";
14142
14667
  proseMirror.style.paddingBottom = "1in";
14143
14668
  }
14144
- }
14145
- /**
14146
- * Initialize default styles for the editor container and ProseMirror.
14147
- * Get page size and margins from the converter.
14148
- * Set document default font and font size.
14149
- *
14150
- * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
14151
- * @returns {void}
14152
- */
14153
- initDefaultStyles(element = this.element) {
14154
- if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
14155
- const proseMirror = element?.querySelector(".ProseMirror");
14156
- this.updateEditorStyles(element, proseMirror);
14157
14669
  this.initMobileStyles(element);
14158
14670
  }
14159
14671
  /**
@@ -14365,22 +14877,10 @@ const _Editor = class _Editor extends EventEmitter {
14365
14877
  */
14366
14878
  destroy() {
14367
14879
  this.emit("destroy");
14368
- this.unmount();
14369
- this.destroyHeaderFooterEditors();
14880
+ if (this.view) this.view.destroy();
14370
14881
  __privateMethod(this, _Editor_instances, endCollaboration_fn).call(this);
14371
14882
  this.removeAllListeners();
14372
14883
  }
14373
- destroyHeaderFooterEditors() {
14374
- const editors = [
14375
- ...this.converter.headerEditors,
14376
- ...this.converter.footerEditors
14377
- ];
14378
- for (let editorData of editors) {
14379
- editorData.editor.destroy();
14380
- }
14381
- this.converter.headerEditors.length = 0;
14382
- this.converter.footerEditors.length = 0;
14383
- }
14384
14884
  /**
14385
14885
  * Check if migrations are needed for the data
14386
14886
  * @static
@@ -14398,7 +14898,7 @@ const _Editor = class _Editor extends EventEmitter {
14398
14898
  * @returns {Object | void} Migration results
14399
14899
  */
14400
14900
  processCollaborationMigrations() {
14401
- console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev8");
14901
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2");
14402
14902
  if (!this.options.ydoc) return;
14403
14903
  const metaMap = this.options.ydoc.getMap("meta");
14404
14904
  let docVersion = metaMap.get("version");
@@ -14442,7 +14942,6 @@ const _Editor = class _Editor extends EventEmitter {
14442
14942
  __privateMethod(this, _Editor_instances, initMedia_fn).call(this);
14443
14943
  this.initDefaultStyles();
14444
14944
  if (this.options.ydoc && this.options.collaborationProvider) {
14445
- updateYdocDocxData(this);
14446
14945
  this.initializeCollaborationData(true);
14447
14946
  } else {
14448
14947
  __privateMethod(this, _Editor_instances, insertNewFileData_fn).call(this);
@@ -14606,7 +15105,7 @@ init_fn = function(options) {
14606
15105
  this.emit("beforeCreate", { editor: this });
14607
15106
  this.on("contentError", this.options.onContentError);
14608
15107
  this.on("exception", this.options.onException);
14609
- this.mount(this.options.element);
15108
+ __privateMethod(this, _Editor_instances, createView_fn).call(this);
14610
15109
  this.initDefaultStyles();
14611
15110
  this.setDocumentMode(options.documentMode);
14612
15111
  if (this.options.isHeadless) return;
@@ -14630,6 +15129,10 @@ init_fn = function(options) {
14630
15129
  __privateMethod(this, _Editor_instances, initPagination_fn).call(this);
14631
15130
  __privateMethod(this, _Editor_instances, initComments_fn).call(this);
14632
15131
  }
15132
+ window.setTimeout(() => {
15133
+ if (this.isDestroyed) return;
15134
+ this.emit("create", { editor: this });
15135
+ }, 0);
14633
15136
  };
14634
15137
  /**
14635
15138
  * Initialize the editor in rich text mode
@@ -14647,7 +15150,7 @@ initRichText_fn = function(options) {
14647
15150
  this.on("beforeCreate", this.options.onBeforeCreate);
14648
15151
  this.emit("beforeCreate", { editor: this });
14649
15152
  this.on("contentError", this.options.onContentError);
14650
- this.mount(this.options.element);
15153
+ __privateMethod(this, _Editor_instances, createView_fn).call(this);
14651
15154
  this.on("create", this.options.onCreate);
14652
15155
  this.on("update", this.options.onUpdate);
14653
15156
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -14658,6 +15161,10 @@ initRichText_fn = function(options) {
14658
15161
  this.on("commentsLoaded", this.options.onCommentsLoaded);
14659
15162
  this.on("commentClick", this.options.onCommentClicked);
14660
15163
  this.on("locked", this.options.onDocumentLocked);
15164
+ window.setTimeout(() => {
15165
+ if (this.isDestroyed) return;
15166
+ this.emit("create", { editor: this });
15167
+ }, 0);
14661
15168
  };
14662
15169
  /**
14663
15170
  *
@@ -14856,15 +15363,14 @@ createDocFromHTML_fn = function(content) {
14856
15363
  * @private
14857
15364
  * @returns {void}
14858
15365
  */
14859
- createView_fn = function(element) {
15366
+ createView_fn = function() {
14860
15367
  let doc2 = __privateMethod(this, _Editor_instances, generatePmData_fn).call(this);
14861
15368
  const state = { schema: this.schema };
14862
15369
  if (!this.options.ydoc) state.doc = doc2;
14863
- this.view = new EditorView(element, {
15370
+ this.view = new EditorView(this.options.element, {
14864
15371
  ...this.options.editorProps,
14865
15372
  dispatchTransaction: __privateMethod(this, _Editor_instances, dispatchTransaction_fn).bind(this),
14866
15373
  state: EditorState.create(state),
14867
- handleClick: __privateMethod(this, _Editor_instances, handleNodeSelection_fn).bind(this),
14868
15374
  handleDoubleClick: async (view, pos, event) => {
14869
15375
  if (this.options.documentMode !== "editing") return;
14870
15376
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -14878,12 +15384,7 @@ createView_fn = function(element) {
14878
15384
  event.stopPropagation();
14879
15385
  if (!this.options.editable) {
14880
15386
  this.setEditable(true, false);
14881
- toggleHeaderFooterEditMode({
14882
- editor: this,
14883
- focusedSectionEditor: null,
14884
- isEditMode: false,
14885
- documentMode: this.options.documentMode
14886
- });
15387
+ toggleHeaderFooterEditMode(this, null, false);
14887
15388
  const pm = document.querySelector(".ProseMirror");
14888
15389
  pm.classList.remove("header-footer-edit");
14889
15390
  pm.setAttribute("aria-readonly", false);
@@ -14896,6 +15397,8 @@ createView_fn = function(element) {
14896
15397
  });
14897
15398
  this.view.updateState(newState);
14898
15399
  this.createNodeViews();
15400
+ const dom = this.view.dom;
15401
+ dom.editor = this;
14899
15402
  this.options.telemetry?.sendReport();
14900
15403
  };
14901
15404
  /**
@@ -14937,9 +15440,7 @@ initComments_fn = function() {
14937
15440
  }, 50);
14938
15441
  };
14939
15442
  initPagination_fn = async function() {
14940
- if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
14941
- return;
14942
- }
15443
+ if (this.options.isHeadless || !this.extensionService) return;
14943
15444
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
14944
15445
  if (pagination && this.options.pagination) {
14945
15446
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -14956,7 +15457,7 @@ initPagination_fn = async function() {
14956
15457
  * @param {Object} transaction - ProseMirror transaction
14957
15458
  */
14958
15459
  dispatchTransaction_fn = function(transaction) {
14959
- if (this.isDestroyed) return;
15460
+ if (this.view.isDestroyed) return;
14960
15461
  let state;
14961
15462
  try {
14962
15463
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -15008,14 +15509,6 @@ dispatchTransaction_fn = function(transaction) {
15008
15509
  transaction
15009
15510
  });
15010
15511
  };
15011
- /**
15012
- * Handles image node selection for header/footer editor
15013
- */
15014
- handleNodeSelection_fn = function(view, pos) {
15015
- if (this.options.isHeaderOrFooter) {
15016
- return setImageNodeSelection(view, pos);
15017
- }
15018
- };
15019
15512
  /**
15020
15513
  * Perform any post conversion pre prosemirror import processing.
15021
15514
  * Comments are processed here.
@@ -17376,7 +17869,7 @@ const Paragraph = Node$1.create({
17376
17869
  },
17377
17870
  addPmPlugins() {
17378
17871
  const { view } = this.editor;
17379
- new Plugin({
17872
+ const dropcapPlugin = new Plugin({
17380
17873
  name: "dropcapPlugin",
17381
17874
  key: new PluginKey("dropcapPlugin"),
17382
17875
  state: {
@@ -17396,7 +17889,7 @@ const Paragraph = Node$1.create({
17396
17889
  }
17397
17890
  }
17398
17891
  });
17399
- return [];
17892
+ return [dropcapPlugin];
17400
17893
  }
17401
17894
  });
17402
17895
  const getDropcapDecorations = (state, view) => {
@@ -17749,16 +18242,7 @@ const HardBreak = Node$1.create({
17749
18242
  };
17750
18243
  },
17751
18244
  parseDOM() {
17752
- return [{
17753
- tag: 'span[linebreaktype="page"]',
17754
- getAttrs: (dom) => {
17755
- if (!(dom instanceof HTMLElement)) return false;
17756
- return {
17757
- pageBreakSource: dom.getAttribute("pagebreaksource") || null,
17758
- pageBreakType: dom.getAttribute("linebreaktype") || null
17759
- };
17760
- }
17761
- }];
18245
+ return [{ tag: "span" }];
17762
18246
  },
17763
18247
  renderDOM({ htmlAttributes }) {
17764
18248
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -20755,8 +21239,6 @@ function findRemovedFieldAnnotations(tr) {
20755
21239
  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) {
20756
21240
  return removedNodes;
20757
21241
  }
20758
- const hasDeletion = transactionDeletedAnything(tr);
20759
- if (!hasDeletion) return removedNodes;
20760
21242
  tr.steps.forEach((step, stepIndex) => {
20761
21243
  if (step instanceof ReplaceStep && step.from !== step.to) {
20762
21244
  let mapping = tr.mapping.maps[stepIndex];
@@ -20773,14 +21255,6 @@ function findRemovedFieldAnnotations(tr) {
20773
21255
  });
20774
21256
  return removedNodes;
20775
21257
  }
20776
- function transactionDeletedAnything(tr) {
20777
- return tr.steps.some((step) => {
20778
- if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
20779
- return step.from !== step.to;
20780
- }
20781
- return false;
20782
- });
20783
- }
20784
21258
  function trackFieldAnnotationsDeletion(editor, tr) {
20785
21259
  let removedAnnotations = [];
20786
21260
  try {
@@ -22306,16 +22780,12 @@ const startImageUpload = async ({ editor, view, file }) => {
22306
22780
  }
22307
22781
  let id = {};
22308
22782
  let { tr, schema } = view.state;
22309
- let { selection } = tr;
22310
- if (editor.options.isHeaderOrFooter) {
22311
- selection = editor.options.lastSelection;
22312
- }
22313
- if (!selection.empty && !editor.options.isHeaderOrFooter) {
22783
+ if (!tr.selection.empty) {
22314
22784
  tr.deleteSelection();
22315
22785
  }
22316
22786
  let imageMeta = {
22317
22787
  type: "add",
22318
- pos: selection.from,
22788
+ pos: tr.selection.from,
22319
22789
  id
22320
22790
  };
22321
22791
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -27564,8 +28034,7 @@ const Pagination = Extension.create({
27564
28034
  addStorage() {
27565
28035
  return {
27566
28036
  height: 0,
27567
- sectionData: null,
27568
- headerFooterEditors: /* @__PURE__ */ new Map()
28037
+ sectionData: null
27569
28038
  };
27570
28039
  },
27571
28040
  addCommands() {
@@ -27608,14 +28077,13 @@ const Pagination = Extension.create({
27608
28077
  shouldUpdate = true;
27609
28078
  shouldInitialize = meta.isReadyToInit;
27610
28079
  }
27611
- const syncMeta = tr.getMeta("y-sync$");
27612
- if (syncMeta && syncMeta.isChangeOrigin) {
27613
- return { ...oldState };
27614
- }
27615
28080
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
27616
28081
  if (imagePluginTransaction) {
27617
28082
  if (imagePluginTransaction.type === "remove") {
27618
- onImageLoad(editor);
28083
+ const imagePos = imagePluginTransaction.pos;
28084
+ const domImage = editor.view.domAtPos(imagePos).node.querySelector("img");
28085
+ if (domImage.complete) onImageLoad(editor);
28086
+ else domImage.onload = () => onImageLoad(editor);
27619
28087
  }
27620
28088
  return { ...oldState };
27621
28089
  }
@@ -27642,7 +28110,6 @@ const Pagination = Extension.create({
27642
28110
  if (isForceUpdate) shouldUpdate = true;
27643
28111
  return {
27644
28112
  ...oldState,
27645
- decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
27646
28113
  isReadyToInit: shouldInitialize
27647
28114
  };
27648
28115
  }
@@ -27671,10 +28138,6 @@ const Pagination = Extension.create({
27671
28138
  },
27672
28139
  onDestroy() {
27673
28140
  cleanupFloatingSeparators();
27674
- const { headerFooterEditors } = this.editor.storage.pagination;
27675
- if (headerFooterEditors) {
27676
- headerFooterEditors.clear();
27677
- }
27678
28141
  }
27679
28142
  });
27680
28143
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node = null) => {
@@ -27735,7 +28198,6 @@ const performUpdate = (editor, view, previousDecorations) => {
27735
28198
  const calculatePageBreaks = (view, editor, sectionData) => {
27736
28199
  if (!editor.converter) return DecorationSet.empty;
27737
28200
  const pageSize = editor.converter.pageStyles?.pageSize;
27738
- if (!pageSize) return DecorationSet.empty;
27739
28201
  const { width, height } = pageSize;
27740
28202
  if (!width || !height) return DecorationSet.empty;
27741
28203
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -27774,13 +28236,11 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
27774
28236
  let pageHeightThreshold = pageHeight;
27775
28237
  let footer = null, header = null;
27776
28238
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
27777
- const isFirstHeader = true;
27778
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
28239
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
27779
28240
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
27780
28241
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
27781
28242
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
27782
- const isLastFooter = true;
27783
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
28243
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
27784
28244
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
27785
28245
  let coords = view?.coordsAtPos(doc2.content.size);
27786
28246
  if (!coords) return [];
@@ -27799,8 +28259,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
27799
28259
  if (currentPageNumber === 1) {
27800
28260
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
27801
28261
  decorations.pop();
27802
- const isFirstHeader2 = true;
27803
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
28262
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
27804
28263
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
27805
28264
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
27806
28265
  }
@@ -27874,15 +28333,15 @@ function createFinalPagePadding(bufferHeight) {
27874
28333
  div2.style.height = bufferHeight + "px";
27875
28334
  return { nodeHeight: bufferHeight, node: div2 };
27876
28335
  }
27877
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
27878
- const headerDef = sectionData?.headers?.[headerId];
28336
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
28337
+ const headerDef = sectionData.headers?.[headerId];
27879
28338
  const minHeaderHeight = pageMargins.top * 96;
27880
28339
  const headerMargin = pageMargins.header * 96;
27881
28340
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
27882
28341
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
27883
28342
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
27884
28343
  const availableHeight = headerHeight - headerMargin;
27885
- let editorContainer = document.createElement("div");
28344
+ const editorContainer = document.createElement("div");
27886
28345
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
27887
28346
  headerId = "rId" + generateDocxRandomId();
27888
28347
  editor.converter.headerIds["default"] = headerId;
@@ -27894,31 +28353,23 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
27894
28353
  };
27895
28354
  }
27896
28355
  const data = editor.converter.headers[headerId];
27897
- const pageNumberIndex = currentPageNumber - 1;
27898
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
27899
- let editorSection = null;
27900
- const { headerFooterEditors } = editor.storage.pagination;
27901
- if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
27902
- const editorData = headerFooterEditors.get(editorKey);
27903
- editorSection = editorData.editor;
27904
- editorContainer = editorSection.element;
27905
- } else {
27906
- editorSection = createHeaderFooterEditor({
27907
- editor,
27908
- data,
27909
- editorContainer,
27910
- appendToBody: false,
27911
- sectionId: headerId,
27912
- type: "header",
27913
- availableHeight,
27914
- currentPageNumber
27915
- });
27916
- editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
27917
- headerFooterEditors.set(editorKey, { editor: editorSection });
27918
- broadcastEditorEvents(editor, editorSection);
27919
- }
28356
+ const editorSection = createHeaderFooterEditor({
28357
+ editor,
28358
+ data,
28359
+ editorContainer,
28360
+ appendToBody: false,
28361
+ sectionId: headerId,
28362
+ type: "header",
28363
+ availableHeight,
28364
+ currentPageNumber
28365
+ });
28366
+ editor.converter.headerEditors.push({
28367
+ id: headerId,
28368
+ editor: editorSection
28369
+ });
27920
28370
  editorSection.setEditable(false, false);
27921
- editorContainer.classList.add("pagination-section-header");
28371
+ broadcastEditorEvents(editor, editorSection);
28372
+ editorContainer.className = "pagination-section-header";
27922
28373
  editorContainer.style.paddingTop = headerMargin + "px";
27923
28374
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
27924
28375
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -27931,12 +28382,12 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
27931
28382
  headerHeight
27932
28383
  };
27933
28384
  }
27934
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
27935
- const footerDef = sectionData?.footers?.[footerId];
28385
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
28386
+ const footerDef = sectionData.footers?.[footerId];
27936
28387
  const minFooterHeight = pageMargins.bottom * 96;
27937
28388
  const footerPaddingFromEdge = pageMargins.footer * 96;
27938
28389
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
27939
- let editorContainer = document.createElement("div");
28390
+ const editorContainer = document.createElement("div");
27940
28391
  if (!footerId && !editor.converter.footerIds["default"]) {
27941
28392
  footerId = "rId" + generateDocxRandomId();
27942
28393
  editor.converter.footerIds["default"] = footerId;
@@ -27948,31 +28399,23 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
27948
28399
  };
27949
28400
  }
27950
28401
  const data = editor.converter.footers[footerId];
27951
- const pageNumberIndex = currentPageNumber - 1;
27952
- const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
27953
- let editorSection = null;
27954
- const { headerFooterEditors } = editor.storage.pagination;
27955
- if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
27956
- const editorData = headerFooterEditors.get(editorKey);
27957
- editorSection = editorData.editor;
27958
- editorContainer = editorSection.element;
27959
- } else {
27960
- editorSection = createHeaderFooterEditor({
27961
- editor,
27962
- data,
27963
- editorContainer,
27964
- appendToBody: false,
27965
- sectionId: footerId,
27966
- type: "footer",
27967
- availableHeight: footerHeight,
27968
- currentPageNumber
27969
- });
27970
- editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
27971
- headerFooterEditors.set(editorKey, { editor: editorSection });
27972
- broadcastEditorEvents(editor, editorSection);
27973
- }
28402
+ const editorSection = createHeaderFooterEditor({
28403
+ editor,
28404
+ data,
28405
+ editorContainer,
28406
+ appendToBody: false,
28407
+ sectionId: footerId,
28408
+ type: "footer",
28409
+ availableHeight: footerHeight,
28410
+ currentPageNumber
28411
+ });
28412
+ editor.converter.footerEditors.push({
28413
+ id: footerId,
28414
+ editor: editorSection
28415
+ });
27974
28416
  editorSection.setEditable(false, false);
27975
- editorContainer.classList.add("pagination-section-footer");
28417
+ broadcastEditorEvents(editor, editorSection);
28418
+ editorContainer.className = "pagination-section-footer";
27976
28419
  editorContainer.style.height = footerHeight + "px";
27977
28420
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
27978
28421
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -27985,28 +28428,10 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
27985
28428
  footerHeight: footerHeight + footerPaddingFromEdge
27986
28429
  };
27987
28430
  }
27988
- const getHeaderFooterEditorKey = ({
27989
- pageNumber,
27990
- isHeader,
27991
- isFooter,
27992
- isFirstHeader = false,
27993
- isLastFooter = false
27994
- }) => {
27995
- if (isFirstHeader) return `first-header-${pageNumber}`;
27996
- if (isLastFooter) return `last-footer-${pageNumber}`;
27997
- if (isHeader) return `header-${pageNumber}`;
27998
- if (isFooter) return `footer-${pageNumber}`;
27999
- return void 0;
28000
- };
28001
28431
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
28002
28432
  if (editor.options.documentMode !== "editing") return;
28003
28433
  editor.setEditable(false, false);
28004
- toggleHeaderFooterEditMode({
28005
- editor,
28006
- focusedSectionEditor: currentFocusedSectionEditor,
28007
- isEditMode: true,
28008
- documentMode: editor.options.documentMode
28009
- });
28434
+ toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
28010
28435
  };
28011
28436
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
28012
28437
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -28561,7 +28986,7 @@ const Search = Extension.create({
28561
28986
  }
28562
28987
  });
28563
28988
  const NodeResizerKey = new PluginKey("node-resizer");
28564
- const nodeResizer = (nodeNames = ["image"], editor) => {
28989
+ const nodeResizer = (nodeNames = ["image"]) => {
28565
28990
  let resizeState = {
28566
28991
  dragging: false,
28567
28992
  startX: 0,
@@ -28586,13 +29011,8 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
28586
29011
  if (tr.getMeta(NodeResizerKey)) {
28587
29012
  return oldState;
28588
29013
  }
28589
- if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
28590
- const { selection } = newState;
28591
- const node = selection.node;
28592
- if (!node || !nodeNames.includes(node.type.name)) {
28593
- return DecorationSet.empty;
28594
- }
28595
29014
  const decorations = [];
29015
+ const { selection } = newState;
28596
29016
  if (nodeNames.includes(selection.node?.type.name)) {
28597
29017
  decorations.push(
28598
29018
  Decoration.node(selection.from, selection.to, {
@@ -28795,7 +29215,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
28795
29215
  const NodeResizer = Extension.create({
28796
29216
  name: "nodeResizer",
28797
29217
  addPmPlugins() {
28798
- return [nodeResizer(["image"], this.editor)];
29218
+ return [nodeResizer(["image"])];
28799
29219
  }
28800
29220
  });
28801
29221
  const getRichTextExtensions = () => {