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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-CHxWXmuK.cjs} +1 -1
  2. package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-KKY27oz-.es.js} +1 -1
  3. package/dist/chunks/{index-Hr3Um-Bg.es.js → index-BqLFjUHn.es.js} +2 -2
  4. package/dist/chunks/{index-B4J7wgs6.cjs → index-CweAXNfB.cjs} +2 -2
  5. package/dist/chunks/{index-Diu6UKHt.es.js → index-DS3W0eVB.es.js} +4 -4
  6. package/dist/chunks/{index-Cdsq63Xq.cjs → index-kOMfCfBT.cjs} +4 -4
  7. package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-9bCX1h2W.cjs} +1 -1
  8. package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-Cl3s9njw.es.js} +1 -1
  9. package/dist/chunks/{super-editor.es-BSS_LTA0.cjs → super-editor.es-Bdu65rjC.cjs} +1096 -819
  10. package/dist/chunks/{super-editor.es-CU8V5_XY.es.js → super-editor.es-BwWbNxcS.es.js} +1096 -819
  11. package/dist/chunks/{url-BIzg4y2i.cjs → url-B8LY3nwf.cjs} +2 -2
  12. package/dist/chunks/{url-CHayXMZH.es.js → url-Bq00tGvm.es.js} +2 -2
  13. package/dist/chunks/{vue-Bi1uWinj.es.js → vue-BBJVqxjL.es.js} +10 -3
  14. package/dist/chunks/{vue-HIY1g7dm.cjs → vue-BBjMeYfo.cjs} +10 -3
  15. package/dist/chunks/{xml-js-CfClL-1b.es.js → xml-js-1F0lia4t.es.js} +81 -102
  16. package/dist/chunks/{xml-js-BjqmFOSP.cjs → xml-js-BuAdLsHD.cjs} +81 -102
  17. package/dist/style.css +4 -3
  18. package/dist/super-editor/ai-writer.es.js +2 -2
  19. package/dist/super-editor/chunks/{converter-Bns3BtmW.js → converter-lPrQA7b1.js} +637 -55
  20. package/dist/super-editor/chunks/{docx-zipper-qf0kgh0l.js → docx-zipper-HvG9XskR.js} +1 -1
  21. package/dist/super-editor/chunks/{editor-hIfvfc-Y.js → editor-DbkiH8Up.js} +387 -685
  22. package/dist/super-editor/chunks/{toolbar-BC9mPZ43.js → toolbar-JdrfUR1G.js} +2 -3
  23. package/dist/super-editor/converter.es.js +2 -2
  24. package/dist/super-editor/core/Editor.d.ts +7 -0
  25. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  26. package/dist/super-editor/core/InputRule.d.ts +7 -0
  27. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  28. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  29. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  30. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
  31. package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
  32. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  33. package/dist/super-editor/docx-zipper.es.js +2 -2
  34. package/dist/super-editor/editor.es.js +3 -3
  35. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  36. package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
  38. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  39. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  40. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  41. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  42. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  43. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/style.css +4 -3
  46. package/dist/super-editor/super-editor.es.js +7 -7
  47. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +3 -0
  48. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +1 -0
  49. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  50. package/dist/super-editor/toolbar.es.js +2 -2
  51. package/dist/super-editor.cjs +2 -2
  52. package/dist/super-editor.es.js +2 -2
  53. package/dist/superdoc.cjs +8 -9
  54. package/dist/superdoc.es.js +9 -10
  55. package/dist/superdoc.umd.js +1107 -824
  56. package/dist/superdoc.umd.js.map +1 -1
  57. package/package.json +1 -1
@@ -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, 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, handleNodeSelection_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, 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-Bns3BtmW.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$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-lPrQA7b1.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-qf0kgh0l.js";
17
+ import { D as DocxZipper } from "./docx-zipper-HvG9XskR.js";
18
18
  function getMarksFromSelection(state) {
19
19
  const { from: from2, to, empty: empty2 } = state.selection;
20
20
  const marks = [];
@@ -1203,164 +1203,6 @@ 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
- }
1364
1206
  const first = (commands2) => (props) => {
1365
1207
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
1366
1208
  for (let i = 0; i < items.length; i += 1) {
@@ -1722,7 +1564,7 @@ function deleteBarrier(state, $cut, dispatch, dir) {
1722
1564
  for (let i = conn.length - 1; i >= 0; i--)
1723
1565
  wrap = Fragment.from(conn[i].create(null, wrap));
1724
1566
  wrap = Fragment.from(before.copy(wrap));
1725
- let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap, 1, 0), conn.length, true));
1567
+ let tr = state.tr.step(new ReplaceAroundStep$1($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap, 1, 0), conn.length, true));
1726
1568
  let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
1727
1569
  if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
1728
1570
  tr.join($joinAt.pos);
@@ -1753,7 +1595,7 @@ function deleteBarrier(state, $cut, dispatch, dir) {
1753
1595
  let end2 = Fragment.empty;
1754
1596
  for (let i = wrap.length - 1; i >= 0; i--)
1755
1597
  end2 = Fragment.from(wrap[i].copy(end2));
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));
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));
1757
1599
  dispatch(tr.scrollIntoView());
1758
1600
  }
1759
1601
  return true;
@@ -2326,7 +2168,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
2326
2168
  return;
2327
2169
  }
2328
2170
  const step = tr.steps[last];
2329
- if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
2171
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
2330
2172
  return;
2331
2173
  }
2332
2174
  const map2 = tr.mapping.maps[last];
@@ -2472,7 +2314,7 @@ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
2472
2314
  let content = Fragment.empty;
2473
2315
  for (let i = wrappers.length - 1; i >= 0; i--)
2474
2316
  content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
2475
- tr.step(new ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new Slice(content, 0, 0), wrappers.length, true));
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));
2476
2318
  let found = 0;
2477
2319
  for (let i = 0; i < wrappers.length; i++)
2478
2320
  if (wrappers[i].type == listType)
@@ -2505,7 +2347,7 @@ function liftListItem$1(itemType) {
2505
2347
  function liftToOuterList(state, dispatch, itemType, range) {
2506
2348
  let tr = state.tr, end2 = range.end, endOfList = range.$to.end(range.depth);
2507
2349
  if (end2 < endOfList) {
2508
- tr.step(new ReplaceAroundStep(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true));
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));
2509
2351
  range = new NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
2510
2352
  }
2511
2353
  const target = liftTarget(range);
@@ -2532,7 +2374,7 @@ function liftOutOfList(state, dispatch, range) {
2532
2374
  if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
2533
2375
  return false;
2534
2376
  let start2 = $start.pos, end2 = start2 + item.nodeSize;
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));
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));
2536
2378
  dispatch(tr.scrollIntoView());
2537
2379
  return true;
2538
2380
  }
@@ -2553,7 +2395,7 @@ function sinkListItem$1(itemType) {
2553
2395
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
2554
2396
  let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
2555
2397
  let before = range.start, after = range.end;
2556
- dispatch(state.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
2398
+ dispatch(state.tr.step(new ReplaceAroundStep$1(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
2557
2399
  }
2558
2400
  return true;
2559
2401
  };
@@ -10146,7 +9988,8 @@ const restoreRelativeSelection = (tr, relSel, binding) => {
10146
9988
  binding.mapping
10147
9989
  );
10148
9990
  if (anchor !== null && head !== null) {
10149
- tr.setSelection(TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head)));
9991
+ const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
9992
+ tr.setSelection(sel);
10150
9993
  }
10151
9994
  }
10152
9995
  }
@@ -10927,7 +10770,7 @@ const setMeta = (view, key, value) => {
10927
10770
  };
10928
10771
  const absolutePositionToRelativePosition = (pos, type, mapping) => {
10929
10772
  if (pos === 0) {
10930
- return Y.createRelativePositionFromTypeIndex(type, 0, -1);
10773
+ return Y.createRelativePositionFromTypeIndex(type, 0, type.length === 0 ? -1 : 0);
10931
10774
  }
10932
10775
  let n = type._first === null ? null : (
10933
10776
  /** @type {Y.ContentType} */
@@ -10936,7 +10779,7 @@ const absolutePositionToRelativePosition = (pos, type, mapping) => {
10936
10779
  while (n !== null && type !== n) {
10937
10780
  if (n instanceof Y.XmlText) {
10938
10781
  if (n._length >= pos) {
10939
- return Y.createRelativePositionFromTypeIndex(n, pos, -1);
10782
+ return Y.createRelativePositionFromTypeIndex(n, pos, type.length === 0 ? -1 : 0);
10940
10783
  } else {
10941
10784
  pos -= n._length;
10942
10785
  }
@@ -11000,7 +10843,7 @@ const absolutePositionToRelativePosition = (pos, type, mapping) => {
11000
10843
  return createRelativePosition(n._item.parent, n._item);
11001
10844
  }
11002
10845
  }
11003
- return Y.createRelativePositionFromTypeIndex(type, type._length, -1);
10846
+ return Y.createRelativePositionFromTypeIndex(type, type._length, type.length === 0 ? -1 : 0);
11004
10847
  };
11005
10848
  const createRelativePosition = (type, item) => {
11006
10849
  let typeid = null;
@@ -11597,409 +11440,6 @@ function isExtensionRulesEnabled(extension, enabled) {
11597
11440
  }
11598
11441
  return enabled;
11599
11442
  }
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
- }
12003
11443
  const _ExtensionService = class _ExtensionService {
12004
11444
  constructor(extensions, userExtensions, editor) {
12005
11445
  __privateAdd(this, _ExtensionService_instances);
@@ -12847,6 +12287,7 @@ const createHeaderFooterEditor = ({
12847
12287
  mediaFiles: editor.storage.image.media,
12848
12288
  fonts: editor.options.fonts,
12849
12289
  isHeaderOrFooter: true,
12290
+ isHeadless: editor.options.isHeadless,
12850
12291
  annotations: true,
12851
12292
  currentPageNumber,
12852
12293
  parentEditor: editor,
@@ -12854,13 +12295,15 @@ const createHeaderFooterEditor = ({
12854
12295
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type)
12855
12296
  });
12856
12297
  const pm = editorContainer.querySelector(".ProseMirror");
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.`);
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
+ }
12864
12307
  return headerFooterEditor;
12865
12308
  };
12866
12309
  const broadcastEditorEvents = (editor, sectionEditor) => {
@@ -12879,14 +12322,16 @@ const broadcastEditorEvents = (editor, sectionEditor) => {
12879
12322
  });
12880
12323
  });
12881
12324
  };
12882
- const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
12325
+ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
12883
12326
  editor.converter.headerEditors.forEach((item) => {
12884
12327
  item.editor.setEditable(isEditMode, false);
12885
12328
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
12329
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
12886
12330
  });
12887
12331
  editor.converter.footerEditors.forEach((item) => {
12888
12332
  item.editor.setEditable(isEditMode, false);
12889
12333
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
12334
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
12890
12335
  });
12891
12336
  if (isEditMode) {
12892
12337
  const pm = document.querySelector(".ProseMirror");
@@ -13967,6 +13412,19 @@ const deleteHeaderFooterFieldAnnotations = ({ editor, fieldIdOrArray }) => {
13967
13412
  );
13968
13413
  });
13969
13414
  };
13415
+ const resetHeaderFooterFieldAnnotations = ({ editor }) => {
13416
+ if (!editor) return;
13417
+ const sectionEditors = getAllHeaderFooterEditors(editor);
13418
+ sectionEditors.forEach(({ editor: sectionEditor, sectionId, type }) => {
13419
+ sectionEditor.commands.resetFieldAnnotations();
13420
+ onHeaderFooterDataUpdate(
13421
+ { editor: sectionEditor },
13422
+ editor,
13423
+ sectionId,
13424
+ type
13425
+ );
13426
+ });
13427
+ };
13970
13428
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
13971
13429
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
13972
13430
  const { doc: doc2 } = editor.state;
@@ -14037,6 +13495,7 @@ const AnnotatorHelpers = {
14037
13495
  getAllHeaderFooterEditors,
14038
13496
  updateHeaderFooterFieldAnnotations,
14039
13497
  deleteHeaderFooterFieldAnnotations,
13498
+ resetHeaderFooterFieldAnnotations,
14040
13499
  cleanUpListsWithAnnotations
14041
13500
  };
14042
13501
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -14216,6 +13675,16 @@ const setWordSelection = (view, pos) => {
14216
13675
  const tr = state.tr.setSelection(TextSelection.create(state.doc, word.from, word.to));
14217
13676
  dispatch(tr);
14218
13677
  };
13678
+ const setImageNodeSelection = (view, pos) => {
13679
+ const { doc: doc2 } = view.state;
13680
+ const node = doc2.nodeAt(pos);
13681
+ if (node && node.type.name === "image") {
13682
+ const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
13683
+ view.dispatch(tr);
13684
+ return true;
13685
+ }
13686
+ return false;
13687
+ };
14219
13688
  const _Editor = class _Editor extends EventEmitter {
14220
13689
  /**
14221
13690
  * Create a new Editor instance
@@ -14342,6 +13811,19 @@ const _Editor = class _Editor extends EventEmitter {
14342
13811
  this.setHighContrastMode = setHighContrastMode;
14343
13812
  initMode();
14344
13813
  }
13814
+ mount(el) {
13815
+ __privateMethod(this, _Editor_instances, createView_fn).call(this, el);
13816
+ window.setTimeout(() => {
13817
+ if (this.isDestroyed) return;
13818
+ this.emit("create", { editor: this });
13819
+ }, 0);
13820
+ }
13821
+ unmount() {
13822
+ if (this.view) {
13823
+ this.view.destroy();
13824
+ }
13825
+ this.view = null;
13826
+ }
14345
13827
  /**
14346
13828
  * Set the toolbar for this editor
14347
13829
  * @param {Object} toolbar - The toolbar instance
@@ -14390,7 +13872,7 @@ const _Editor = class _Editor extends EventEmitter {
14390
13872
  * @returns {boolean}
14391
13873
  */
14392
13874
  get isDestroyed() {
14393
- return this.view.isDestroyed;
13875
+ return this.view?.isDestroyed ?? true;
14394
13876
  }
14395
13877
  /**
14396
13878
  * Get the editor element
@@ -14433,7 +13915,12 @@ const _Editor = class _Editor extends EventEmitter {
14433
13915
  this.commands.toggleTrackChangesShowOriginal();
14434
13916
  this.setEditable(false, false);
14435
13917
  this.setOptions({ documentMode: "viewing" });
14436
- toggleHeaderFooterEditMode(this, null, false);
13918
+ toggleHeaderFooterEditMode({
13919
+ editor: this,
13920
+ focusedSectionEditor: null,
13921
+ isEditMode: false,
13922
+ documentMode: cleanedMode
13923
+ });
14437
13924
  } else if (cleanedMode === "suggesting") {
14438
13925
  __privateMethod(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
14439
13926
  this.commands.disableTrackChangesShowOriginal();
@@ -14446,7 +13933,12 @@ const _Editor = class _Editor extends EventEmitter {
14446
13933
  this.commands.disableTrackChanges();
14447
13934
  this.setEditable(true, false);
14448
13935
  this.setOptions({ documentMode: "editing" });
14449
- toggleHeaderFooterEditMode(this, null, false);
13936
+ toggleHeaderFooterEditMode({
13937
+ editor: this,
13938
+ focusedSectionEditor: null,
13939
+ isEditMode: false,
13940
+ documentMode: cleanedMode
13941
+ });
14450
13942
  }
14451
13943
  }
14452
13944
  /**
@@ -14623,29 +14115,26 @@ const _Editor = class _Editor extends EventEmitter {
14623
14115
  };
14624
14116
  }
14625
14117
  /**
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");
14118
+ * Attach styles and attributes to the editor element
14119
+ */
14120
+ updateEditorStyles(element, proseMirror) {
14636
14121
  const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
14637
- if (!proseMirror || !pageSize || !pageMargins) {
14122
+ if (!proseMirror || !element) {
14638
14123
  return;
14639
14124
  }
14640
14125
  proseMirror.setAttribute("role", "document");
14641
14126
  proseMirror.setAttribute("aria-multiline", true);
14642
14127
  proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
14643
14128
  proseMirror.setAttribute("aria-description", "");
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";
14129
+ if (pageSize) {
14130
+ element.style.width = pageSize.width + "in";
14131
+ element.style.minWidth = pageSize.width + "in";
14132
+ element.style.minHeight = pageSize.height + "in";
14133
+ }
14134
+ if (pageMargins) {
14135
+ element.style.paddingLeft = pageMargins.left + "in";
14136
+ element.style.paddingRight = pageMargins.right + "in";
14137
+ }
14649
14138
  element.style.boxSizing = "border-box";
14650
14139
  element.style.isolation = "isolate";
14651
14140
  proseMirror.style.outline = "none";
@@ -14666,6 +14155,19 @@ const _Editor = class _Editor extends EventEmitter {
14666
14155
  proseMirror.style.paddingTop = "1in";
14667
14156
  proseMirror.style.paddingBottom = "1in";
14668
14157
  }
14158
+ }
14159
+ /**
14160
+ * Initialize default styles for the editor container and ProseMirror.
14161
+ * Get page size and margins from the converter.
14162
+ * Set document default font and font size.
14163
+ *
14164
+ * @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
14165
+ * @returns {void}
14166
+ */
14167
+ initDefaultStyles(element = this.element) {
14168
+ if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
14169
+ const proseMirror = element?.querySelector(".ProseMirror");
14170
+ this.updateEditorStyles(element, proseMirror);
14669
14171
  this.initMobileStyles(element);
14670
14172
  }
14671
14173
  /**
@@ -14877,10 +14379,25 @@ const _Editor = class _Editor extends EventEmitter {
14877
14379
  */
14878
14380
  destroy() {
14879
14381
  this.emit("destroy");
14880
- if (this.view) this.view.destroy();
14382
+ this.unmount();
14383
+ this.destroyHeaderFooterEditors();
14881
14384
  __privateMethod(this, _Editor_instances, endCollaboration_fn).call(this);
14882
14385
  this.removeAllListeners();
14883
14386
  }
14387
+ destroyHeaderFooterEditors() {
14388
+ try {
14389
+ const editors = [
14390
+ ...this.converter.headerEditors,
14391
+ ...this.converter.footerEditors
14392
+ ];
14393
+ for (let editorData of editors) {
14394
+ editorData.editor.destroy();
14395
+ }
14396
+ this.converter.headerEditors.length = 0;
14397
+ this.converter.footerEditors.length = 0;
14398
+ } catch (error) {
14399
+ }
14400
+ }
14884
14401
  /**
14885
14402
  * Check if migrations are needed for the data
14886
14403
  * @static
@@ -14898,7 +14415,7 @@ const _Editor = class _Editor extends EventEmitter {
14898
14415
  * @returns {Object | void} Migration results
14899
14416
  */
14900
14417
  processCollaborationMigrations() {
14901
- console.debug("[checkVersionMigrations] Current editor version", "0.13.0-next.6");
14418
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev10");
14902
14419
  if (!this.options.ydoc) return;
14903
14420
  const metaMap = this.options.ydoc.getMap("meta");
14904
14421
  let docVersion = metaMap.get("version");
@@ -14942,6 +14459,7 @@ const _Editor = class _Editor extends EventEmitter {
14942
14459
  __privateMethod(this, _Editor_instances, initMedia_fn).call(this);
14943
14460
  this.initDefaultStyles();
14944
14461
  if (this.options.ydoc && this.options.collaborationProvider) {
14462
+ updateYdocDocxData(this);
14945
14463
  this.initializeCollaborationData(true);
14946
14464
  } else {
14947
14465
  __privateMethod(this, _Editor_instances, insertNewFileData_fn).call(this);
@@ -15105,7 +14623,7 @@ init_fn = function(options) {
15105
14623
  this.emit("beforeCreate", { editor: this });
15106
14624
  this.on("contentError", this.options.onContentError);
15107
14625
  this.on("exception", this.options.onException);
15108
- __privateMethod(this, _Editor_instances, createView_fn).call(this);
14626
+ this.mount(this.options.element);
15109
14627
  this.initDefaultStyles();
15110
14628
  this.setDocumentMode(options.documentMode);
15111
14629
  if (this.options.isHeadless) return;
@@ -15129,10 +14647,6 @@ init_fn = function(options) {
15129
14647
  __privateMethod(this, _Editor_instances, initPagination_fn).call(this);
15130
14648
  __privateMethod(this, _Editor_instances, initComments_fn).call(this);
15131
14649
  }
15132
- window.setTimeout(() => {
15133
- if (this.isDestroyed) return;
15134
- this.emit("create", { editor: this });
15135
- }, 0);
15136
14650
  };
15137
14651
  /**
15138
14652
  * Initialize the editor in rich text mode
@@ -15150,7 +14664,7 @@ initRichText_fn = function(options) {
15150
14664
  this.on("beforeCreate", this.options.onBeforeCreate);
15151
14665
  this.emit("beforeCreate", { editor: this });
15152
14666
  this.on("contentError", this.options.onContentError);
15153
- __privateMethod(this, _Editor_instances, createView_fn).call(this);
14667
+ this.mount(this.options.element);
15154
14668
  this.on("create", this.options.onCreate);
15155
14669
  this.on("update", this.options.onUpdate);
15156
14670
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -15161,10 +14675,6 @@ initRichText_fn = function(options) {
15161
14675
  this.on("commentsLoaded", this.options.onCommentsLoaded);
15162
14676
  this.on("commentClick", this.options.onCommentClicked);
15163
14677
  this.on("locked", this.options.onDocumentLocked);
15164
- window.setTimeout(() => {
15165
- if (this.isDestroyed) return;
15166
- this.emit("create", { editor: this });
15167
- }, 0);
15168
14678
  };
15169
14679
  /**
15170
14680
  *
@@ -15363,14 +14873,15 @@ createDocFromHTML_fn = function(content) {
15363
14873
  * @private
15364
14874
  * @returns {void}
15365
14875
  */
15366
- createView_fn = function() {
14876
+ createView_fn = function(element) {
15367
14877
  let doc2 = __privateMethod(this, _Editor_instances, generatePmData_fn).call(this);
15368
14878
  const state = { schema: this.schema };
15369
14879
  if (!this.options.ydoc) state.doc = doc2;
15370
- this.view = new EditorView(this.options.element, {
14880
+ this.view = new EditorView(element, {
15371
14881
  ...this.options.editorProps,
15372
14882
  dispatchTransaction: __privateMethod(this, _Editor_instances, dispatchTransaction_fn).bind(this),
15373
14883
  state: EditorState.create(state),
14884
+ handleClick: __privateMethod(this, _Editor_instances, handleNodeSelection_fn).bind(this),
15374
14885
  handleDoubleClick: async (view, pos, event) => {
15375
14886
  if (this.options.documentMode !== "editing") return;
15376
14887
  const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
@@ -15384,7 +14895,12 @@ createView_fn = function() {
15384
14895
  event.stopPropagation();
15385
14896
  if (!this.options.editable) {
15386
14897
  this.setEditable(true, false);
15387
- toggleHeaderFooterEditMode(this, null, false);
14898
+ toggleHeaderFooterEditMode({
14899
+ editor: this,
14900
+ focusedSectionEditor: null,
14901
+ isEditMode: false,
14902
+ documentMode: this.options.documentMode
14903
+ });
15388
14904
  const pm = document.querySelector(".ProseMirror");
15389
14905
  pm.classList.remove("header-footer-edit");
15390
14906
  pm.setAttribute("aria-readonly", false);
@@ -15397,8 +14913,6 @@ createView_fn = function() {
15397
14913
  });
15398
14914
  this.view.updateState(newState);
15399
14915
  this.createNodeViews();
15400
- const dom = this.view.dom;
15401
- dom.editor = this;
15402
14916
  this.options.telemetry?.sendReport();
15403
14917
  };
15404
14918
  /**
@@ -15440,7 +14954,9 @@ initComments_fn = function() {
15440
14954
  }, 50);
15441
14955
  };
15442
14956
  initPagination_fn = async function() {
15443
- if (this.options.isHeadless || !this.extensionService) return;
14957
+ if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
14958
+ return;
14959
+ }
15444
14960
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
15445
14961
  if (pagination && this.options.pagination) {
15446
14962
  console.debug("🔗 [super-editor] Initializing pagination");
@@ -15457,7 +14973,7 @@ initPagination_fn = async function() {
15457
14973
  * @param {Object} transaction - ProseMirror transaction
15458
14974
  */
15459
14975
  dispatchTransaction_fn = function(transaction) {
15460
- if (this.view.isDestroyed) return;
14976
+ if (this.isDestroyed) return;
15461
14977
  let state;
15462
14978
  try {
15463
14979
  const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
@@ -15509,6 +15025,14 @@ dispatchTransaction_fn = function(transaction) {
15509
15025
  transaction
15510
15026
  });
15511
15027
  };
15028
+ /**
15029
+ * Handles image node selection for header/footer editor
15030
+ */
15031
+ handleNodeSelection_fn = function(view, pos) {
15032
+ if (this.options.isHeaderOrFooter) {
15033
+ return setImageNodeSelection(view, pos);
15034
+ }
15035
+ };
15512
15036
  /**
15513
15037
  * Perform any post conversion pre prosemirror import processing.
15514
15038
  * Comments are processed here.
@@ -17869,7 +17393,7 @@ const Paragraph = Node$1.create({
17869
17393
  },
17870
17394
  addPmPlugins() {
17871
17395
  const { view } = this.editor;
17872
- const dropcapPlugin = new Plugin({
17396
+ new Plugin({
17873
17397
  name: "dropcapPlugin",
17874
17398
  key: new PluginKey("dropcapPlugin"),
17875
17399
  state: {
@@ -17889,7 +17413,7 @@ const Paragraph = Node$1.create({
17889
17413
  }
17890
17414
  }
17891
17415
  });
17892
- return [dropcapPlugin];
17416
+ return [];
17893
17417
  }
17894
17418
  });
17895
17419
  const getDropcapDecorations = (state, view) => {
@@ -18242,7 +17766,16 @@ const HardBreak = Node$1.create({
18242
17766
  };
18243
17767
  },
18244
17768
  parseDOM() {
18245
- return [{ tag: "span" }];
17769
+ return [{
17770
+ tag: 'span[linebreaktype="page"]',
17771
+ getAttrs: (dom) => {
17772
+ if (!(dom instanceof HTMLElement)) return false;
17773
+ return {
17774
+ pageBreakSource: dom.getAttribute("pagebreaksource") || null,
17775
+ pageBreakType: dom.getAttribute("linebreaktype") || null
17776
+ };
17777
+ }
17778
+ }];
18246
17779
  },
18247
17780
  renderDOM({ htmlAttributes }) {
18248
17781
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -21239,6 +20772,8 @@ function findRemovedFieldAnnotations(tr) {
21239
20772
  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) {
21240
20773
  return removedNodes;
21241
20774
  }
20775
+ const hasDeletion = transactionDeletedAnything(tr);
20776
+ if (!hasDeletion) return removedNodes;
21242
20777
  tr.steps.forEach((step, stepIndex) => {
21243
20778
  if (step instanceof ReplaceStep && step.from !== step.to) {
21244
20779
  let mapping = tr.mapping.maps[stepIndex];
@@ -21255,6 +20790,14 @@ function findRemovedFieldAnnotations(tr) {
21255
20790
  });
21256
20791
  return removedNodes;
21257
20792
  }
20793
+ function transactionDeletedAnything(tr) {
20794
+ return tr.steps.some((step) => {
20795
+ if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
20796
+ return step.from !== step.to;
20797
+ }
20798
+ return false;
20799
+ });
20800
+ }
21258
20801
  function trackFieldAnnotationsDeletion(editor, tr) {
21259
20802
  let removedAnnotations = [];
21260
20803
  try {
@@ -21650,8 +21193,18 @@ const FieldAnnotation = Node$1.create({
21650
21193
  };
21651
21194
  }
21652
21195
  },
21196
+ defaultDisplayLabel: {
21197
+ default: "",
21198
+ parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
21199
+ renderDOM: (attrs) => {
21200
+ if (!attrs.defaultDisplayLabel) return {};
21201
+ return {
21202
+ "data-default-display-label": attrs.defaultDisplayLabel
21203
+ };
21204
+ }
21205
+ },
21653
21206
  displayLabel: {
21654
- default: "Text field",
21207
+ default: "",
21655
21208
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
21656
21209
  renderDOM: (attrs) => {
21657
21210
  if (!attrs.displayLabel) return {};
@@ -21967,6 +21520,7 @@ const FieldAnnotation = Node$1.create({
21967
21520
  return renderer();
21968
21521
  },
21969
21522
  addCommands() {
21523
+ const annotationTypes = this.options.types;
21970
21524
  return {
21971
21525
  /**
21972
21526
  * Add field annotation.
@@ -21988,7 +21542,12 @@ const FieldAnnotation = Node$1.create({
21988
21542
  let currentMarks = $pos.marks();
21989
21543
  currentMarks = currentMarks.length ? [...currentMarks] : null;
21990
21544
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
21991
- let node = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
21545
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
21546
+ let node = schema.nodes[this.name].create({
21547
+ ...attrs,
21548
+ ...formatAttrs,
21549
+ defaultDisplayLabel
21550
+ }, null, null);
21992
21551
  state.tr.insert(newPos, node).setSelection(Selection.near(tr.doc.resolve(newPos + node.nodeSize)));
21993
21552
  if (editorFocus) {
21994
21553
  this.editor.view.focus();
@@ -21996,9 +21555,9 @@ const FieldAnnotation = Node$1.create({
21996
21555
  }
21997
21556
  return true;
21998
21557
  },
21999
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state, tr, commands: commands2 }) => {
21558
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state, commands: commands2 }) => {
22000
21559
  const { from: from2 } = state.selection;
22001
- commands2.addFieldAnnotation(from2, attrs, editorFocus);
21560
+ return commands2.addFieldAnnotation(from2, attrs, editorFocus);
22002
21561
  },
22003
21562
  /**
22004
21563
  * Replace field annotation.
@@ -22008,24 +21567,113 @@ const FieldAnnotation = Node$1.create({
22008
21567
  * from: 20,
22009
21568
  * to: 45,
22010
21569
  * attrs: {
22011
- * fieldType: 'TEXTINPUT'
22012
- * fieldColor: '#980043'
21570
+ * fieldType: 'TEXTINPUT'
21571
+ * fieldColor: '#980043'
22013
21572
  * }
22014
21573
  * ])
22015
21574
  */
22016
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state, tr }) => {
21575
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
22017
21576
  if (!dispatch) return true;
22018
- tr.setMeta("fieldAnnotationReplace", true);
22019
21577
  fieldsArray.forEach((annotation) => {
22020
21578
  let { from: from2, to, attrs } = annotation;
22021
21579
  let { schema } = editor;
22022
21580
  let newPosFrom = tr.mapping.map(from2);
22023
21581
  let newPosTo = tr.mapping.map(to);
22024
- let node = schema.nodes[this.name].create({ ...attrs }, null, null);
21582
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
21583
+ let node = schema.nodes[this.name].create({
21584
+ ...attrs,
21585
+ defaultDisplayLabel
21586
+ }, null, null);
22025
21587
  tr.replaceWith(newPosFrom, newPosTo, node);
22026
21588
  });
22027
21589
  return true;
22028
21590
  },
21591
+ /**
21592
+ * Replace annotations with a label (as text node) in selection.
21593
+ * @param options Additional options.
21594
+ * @example
21595
+ * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
21596
+ */
21597
+ replaceFieldAnnotationsWithLabelInSelection: (options = {}) => ({ commands: commands2 }) => {
21598
+ return commands2.replaceFieldAnnotationsWithLabel(null, {
21599
+ ...options,
21600
+ isInSelection: true
21601
+ });
21602
+ },
21603
+ /**
21604
+ * Replace annotations with a label (as text node).
21605
+ * @param fieldIdOrArray The field ID or array of field IDs.
21606
+ * @param options.isInSelection Find in selection instead of field IDs.
21607
+ * @param options.addToHistory Add to history or not.
21608
+ * @param options.types Annotation types to replace.
21609
+ * @example
21610
+ * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
21611
+ */
21612
+ replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
21613
+ isInSelection = false,
21614
+ addToHistory = false,
21615
+ types = annotationTypes
21616
+ } = {}) => ({ dispatch, state, tr }) => {
21617
+ let { from: from2, to } = state.selection;
21618
+ let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state);
21619
+ annotations = types.length ? annotations.filter(({ node }) => types.includes(node.attrs.type)) : annotations;
21620
+ if (!annotations.length) {
21621
+ return true;
21622
+ }
21623
+ if (!addToHistory) {
21624
+ tr.setMeta("addToHistory", false);
21625
+ }
21626
+ if (dispatch) {
21627
+ annotations.forEach((annotation) => {
21628
+ let { pos, node } = annotation;
21629
+ let newPosFrom = tr.mapping.map(pos);
21630
+ let newPosTo = tr.mapping.map(pos + node.nodeSize);
21631
+ let currentNode = tr.doc.nodeAt(newPosFrom);
21632
+ let nodeEqual = node.attrs.fieldId === currentNode?.attrs?.fieldId;
21633
+ let $newPosFrom = tr.doc.resolve(newPosFrom);
21634
+ let currentMarks = $newPosFrom.marks();
21635
+ currentMarks = currentMarks.length ? [...currentMarks] : null;
21636
+ if (nodeEqual) {
21637
+ let label = node.attrs.displayLabel || " ";
21638
+ let textNode = state.schema.text(label, currentMarks);
21639
+ tr.replaceWith(newPosFrom, newPosTo, textNode);
21640
+ }
21641
+ });
21642
+ }
21643
+ return true;
21644
+ },
21645
+ /**
21646
+ * Resets all annotations to default values.
21647
+ * @example
21648
+ * editor.commands.resetFieldAnnotations()
21649
+ */
21650
+ resetFieldAnnotations: () => ({ dispatch, state, tr }) => {
21651
+ let annotations = getAllFieldAnnotations(state);
21652
+ if (!annotations.length) {
21653
+ return true;
21654
+ }
21655
+ tr.setMeta("fieldAnnotationUpdate", true);
21656
+ if (dispatch) {
21657
+ annotations.forEach(({ pos, node }) => {
21658
+ let newPos = tr.mapping.map(pos);
21659
+ let currentNode = tr.doc.nodeAt(newPos);
21660
+ let nodeEqual = node.attrs.fieldId === currentNode?.attrs?.fieldId;
21661
+ if (nodeEqual) {
21662
+ let displayLabel = node.attrs.defaultDisplayLabel || node.attrs.displayLabel || "";
21663
+ tr.setNodeMarkup(newPos, void 0, {
21664
+ ...node.attrs,
21665
+ // reset displayLabel to default.
21666
+ displayLabel,
21667
+ // reset attrs ​​for specific types.
21668
+ imageSrc: null,
21669
+ rawHtml: null,
21670
+ linkUrl: null
21671
+ });
21672
+ }
21673
+ });
21674
+ }
21675
+ return true;
21676
+ },
22029
21677
  /**
22030
21678
  * Update annotations associated with a field.
22031
21679
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -22780,12 +22428,16 @@ const startImageUpload = async ({ editor, view, file }) => {
22780
22428
  }
22781
22429
  let id = {};
22782
22430
  let { tr, schema } = view.state;
22783
- if (!tr.selection.empty) {
22431
+ let { selection } = tr;
22432
+ if (editor.options.isHeaderOrFooter) {
22433
+ selection = editor.options.lastSelection;
22434
+ }
22435
+ if (!selection.empty && !editor.options.isHeaderOrFooter) {
22784
22436
  tr.deleteSelection();
22785
22437
  }
22786
22438
  let imageMeta = {
22787
22439
  type: "add",
22788
- pos: tr.selection.from,
22440
+ pos: selection.from,
22789
22441
  id
22790
22442
  };
22791
22443
  tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
@@ -28034,7 +27686,8 @@ const Pagination = Extension.create({
28034
27686
  addStorage() {
28035
27687
  return {
28036
27688
  height: 0,
28037
- sectionData: null
27689
+ sectionData: null,
27690
+ headerFooterEditors: /* @__PURE__ */ new Map()
28038
27691
  };
28039
27692
  },
28040
27693
  addCommands() {
@@ -28077,13 +27730,14 @@ const Pagination = Extension.create({
28077
27730
  shouldUpdate = true;
28078
27731
  shouldInitialize = meta.isReadyToInit;
28079
27732
  }
27733
+ const syncMeta = tr.getMeta("y-sync$");
27734
+ if (syncMeta && syncMeta.isChangeOrigin) {
27735
+ return { ...oldState };
27736
+ }
28080
27737
  const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
28081
27738
  if (imagePluginTransaction) {
28082
27739
  if (imagePluginTransaction.type === "remove") {
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);
27740
+ onImageLoad(editor);
28087
27741
  }
28088
27742
  return { ...oldState };
28089
27743
  }
@@ -28110,6 +27764,7 @@ const Pagination = Extension.create({
28110
27764
  if (isForceUpdate) shouldUpdate = true;
28111
27765
  return {
28112
27766
  ...oldState,
27767
+ decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
28113
27768
  isReadyToInit: shouldInitialize
28114
27769
  };
28115
27770
  }
@@ -28138,6 +27793,10 @@ const Pagination = Extension.create({
28138
27793
  },
28139
27794
  onDestroy() {
28140
27795
  cleanupFloatingSeparators();
27796
+ const { headerFooterEditors } = this.editor.storage.pagination;
27797
+ if (headerFooterEditors) {
27798
+ headerFooterEditors.clear();
27799
+ }
28141
27800
  }
28142
27801
  });
28143
27802
  const getHeaderFooterId = (currentPageNumber, sectionType, editor, node = null) => {
@@ -28198,6 +27857,7 @@ const performUpdate = (editor, view, previousDecorations) => {
28198
27857
  const calculatePageBreaks = (view, editor, sectionData) => {
28199
27858
  if (!editor.converter) return DecorationSet.empty;
28200
27859
  const pageSize = editor.converter.pageStyles?.pageSize;
27860
+ if (!pageSize) return DecorationSet.empty;
28201
27861
  const { width, height } = pageSize;
28202
27862
  if (!width || !height) return DecorationSet.empty;
28203
27863
  const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
@@ -28236,11 +27896,13 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
28236
27896
  let pageHeightThreshold = pageHeight;
28237
27897
  let footer = null, header = null;
28238
27898
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
28239
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
27899
+ const isFirstHeader = true;
27900
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
28240
27901
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
28241
27902
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
28242
27903
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
28243
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
27904
+ const isLastFooter = true;
27905
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
28244
27906
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
28245
27907
  let coords = view?.coordsAtPos(doc2.content.size);
28246
27908
  if (!coords) return [];
@@ -28259,7 +27921,8 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
28259
27921
  if (currentPageNumber === 1) {
28260
27922
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
28261
27923
  decorations.pop();
28262
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
27924
+ const isFirstHeader2 = true;
27925
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
28263
27926
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
28264
27927
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
28265
27928
  }
@@ -28333,15 +27996,15 @@ function createFinalPagePadding(bufferHeight) {
28333
27996
  div2.style.height = bufferHeight + "px";
28334
27997
  return { nodeHeight: bufferHeight, node: div2 };
28335
27998
  }
28336
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
28337
- const headerDef = sectionData.headers?.[headerId];
27999
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
28000
+ const headerDef = sectionData?.headers?.[headerId];
28338
28001
  const minHeaderHeight = pageMargins.top * 96;
28339
28002
  const headerMargin = pageMargins.header * 96;
28340
28003
  const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
28341
28004
  const headerOffset = hasHeaderOffset ? headerMargin : 0;
28342
28005
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
28343
28006
  const availableHeight = headerHeight - headerMargin;
28344
- const editorContainer = document.createElement("div");
28007
+ let editorContainer = document.createElement("div");
28345
28008
  if (!headerId && !editor?.converter?.headerIds?.["default"]) {
28346
28009
  headerId = "rId" + generateDocxRandomId();
28347
28010
  editor.converter.headerIds["default"] = headerId;
@@ -28353,23 +28016,31 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
28353
28016
  };
28354
28017
  }
28355
28018
  const data = editor.converter.headers[headerId];
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
- });
28019
+ const pageNumberIndex = currentPageNumber - 1;
28020
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
28021
+ let editorSection = null;
28022
+ const { headerFooterEditors } = editor.storage.pagination;
28023
+ if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
28024
+ const editorData = headerFooterEditors.get(editorKey);
28025
+ editorSection = editorData.editor;
28026
+ editorContainer = editorSection.element;
28027
+ } else {
28028
+ editorSection = createHeaderFooterEditor({
28029
+ editor,
28030
+ data,
28031
+ editorContainer,
28032
+ appendToBody: false,
28033
+ sectionId: headerId,
28034
+ type: "header",
28035
+ availableHeight,
28036
+ currentPageNumber
28037
+ });
28038
+ editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
28039
+ headerFooterEditors.set(editorKey, { editor: editorSection });
28040
+ broadcastEditorEvents(editor, editorSection);
28041
+ }
28370
28042
  editorSection.setEditable(false, false);
28371
- broadcastEditorEvents(editor, editorSection);
28372
- editorContainer.className = "pagination-section-header";
28043
+ editorContainer.classList.add("pagination-section-header");
28373
28044
  editorContainer.style.paddingTop = headerMargin + "px";
28374
28045
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
28375
28046
  editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
@@ -28382,12 +28053,12 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
28382
28053
  headerHeight
28383
28054
  };
28384
28055
  }
28385
- function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
28386
- const footerDef = sectionData.footers?.[footerId];
28056
+ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
28057
+ const footerDef = sectionData?.footers?.[footerId];
28387
28058
  const minFooterHeight = pageMargins.bottom * 96;
28388
28059
  const footerPaddingFromEdge = pageMargins.footer * 96;
28389
28060
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
28390
- const editorContainer = document.createElement("div");
28061
+ let editorContainer = document.createElement("div");
28391
28062
  if (!footerId && !editor.converter.footerIds["default"]) {
28392
28063
  footerId = "rId" + generateDocxRandomId();
28393
28064
  editor.converter.footerIds["default"] = footerId;
@@ -28399,23 +28070,31 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
28399
28070
  };
28400
28071
  }
28401
28072
  const data = editor.converter.footers[footerId];
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
- });
28073
+ const pageNumberIndex = currentPageNumber - 1;
28074
+ const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
28075
+ let editorSection = null;
28076
+ const { headerFooterEditors } = editor.storage.pagination;
28077
+ if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
28078
+ const editorData = headerFooterEditors.get(editorKey);
28079
+ editorSection = editorData.editor;
28080
+ editorContainer = editorSection.element;
28081
+ } else {
28082
+ editorSection = createHeaderFooterEditor({
28083
+ editor,
28084
+ data,
28085
+ editorContainer,
28086
+ appendToBody: false,
28087
+ sectionId: footerId,
28088
+ type: "footer",
28089
+ availableHeight: footerHeight,
28090
+ currentPageNumber
28091
+ });
28092
+ editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
28093
+ headerFooterEditors.set(editorKey, { editor: editorSection });
28094
+ broadcastEditorEvents(editor, editorSection);
28095
+ }
28416
28096
  editorSection.setEditable(false, false);
28417
- broadcastEditorEvents(editor, editorSection);
28418
- editorContainer.className = "pagination-section-footer";
28097
+ editorContainer.classList.add("pagination-section-footer");
28419
28098
  editorContainer.style.height = footerHeight + "px";
28420
28099
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
28421
28100
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -28428,10 +28107,28 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
28428
28107
  footerHeight: footerHeight + footerPaddingFromEdge
28429
28108
  };
28430
28109
  }
28110
+ const getHeaderFooterEditorKey = ({
28111
+ pageNumber,
28112
+ isHeader,
28113
+ isFooter,
28114
+ isFirstHeader = false,
28115
+ isLastFooter = false
28116
+ }) => {
28117
+ if (isFirstHeader) return `first-header-${pageNumber}`;
28118
+ if (isLastFooter) return `last-footer-${pageNumber}`;
28119
+ if (isHeader) return `header-${pageNumber}`;
28120
+ if (isFooter) return `footer-${pageNumber}`;
28121
+ return void 0;
28122
+ };
28431
28123
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
28432
28124
  if (editor.options.documentMode !== "editing") return;
28433
28125
  editor.setEditable(false, false);
28434
- toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
28126
+ toggleHeaderFooterEditMode({
28127
+ editor,
28128
+ focusedSectionEditor: currentFocusedSectionEditor,
28129
+ isEditMode: true,
28130
+ documentMode: editor.options.documentMode
28131
+ });
28435
28132
  };
28436
28133
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
28437
28134
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -28986,7 +28683,7 @@ const Search = Extension.create({
28986
28683
  }
28987
28684
  });
28988
28685
  const NodeResizerKey = new PluginKey("node-resizer");
28989
- const nodeResizer = (nodeNames = ["image"]) => {
28686
+ const nodeResizer = (nodeNames = ["image"], editor) => {
28990
28687
  let resizeState = {
28991
28688
  dragging: false,
28992
28689
  startX: 0,
@@ -29011,8 +28708,13 @@ const nodeResizer = (nodeNames = ["image"]) => {
29011
28708
  if (tr.getMeta(NodeResizerKey)) {
29012
28709
  return oldState;
29013
28710
  }
29014
- const decorations = [];
28711
+ if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
29015
28712
  const { selection } = newState;
28713
+ const node = selection.node;
28714
+ if (!node || !nodeNames.includes(node.type.name)) {
28715
+ return DecorationSet.empty;
28716
+ }
28717
+ const decorations = [];
29016
28718
  if (nodeNames.includes(selection.node?.type.name)) {
29017
28719
  decorations.push(
29018
28720
  Decoration.node(selection.from, selection.to, {
@@ -29215,7 +28917,7 @@ const nodeResizer = (nodeNames = ["image"]) => {
29215
28917
  const NodeResizer = Extension.create({
29216
28918
  name: "nodeResizer",
29217
28919
  addPmPlugins() {
29218
- return [nodeResizer(["image"])];
28920
+ return [nodeResizer(["image"], this.editor)];
29219
28921
  }
29220
28922
  });
29221
28923
  const getRichTextExtensions = () => {