@harbour-enterprises/superdoc 0.25.0 → 0.26.0-next.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 (34) hide show
  1. package/dist/chunks/{PdfViewer-Y13XRanw.es.js → PdfViewer-BUDqeNx7.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-DDL0V0l5.cjs → PdfViewer-Bk6eeTRu.cjs} +1 -1
  3. package/dist/chunks/{index-Bo5YCvD5.cjs → index-W-nB4woH.cjs} +19 -3
  4. package/dist/chunks/{index-DKNVSdr6.es.js → index-kTEBpqiG.es.js} +19 -3
  5. package/dist/chunks/{super-editor.es-Ct2sXbNV.cjs → super-editor.es-C74O3hXJ.cjs} +484 -253
  6. package/dist/chunks/{super-editor.es-CYtLh0Ob.es.js → super-editor.es-DznCuGcp.es.js} +484 -253
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/core/types/index.d.ts.map +1 -1
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-gSy6s2VK.js → converter-khE-H7hH.js} +90 -73
  11. package/dist/super-editor/chunks/{docx-zipper-CceGxV02.js → docx-zipper-KoUEtzIj.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-CoX24lXQ.js → editor-wd9pvfTV.js} +421 -192
  13. package/dist/super-editor/chunks/{toolbar-BTw9-jfX.js → toolbar-CWJmT_bY.js} +2 -2
  14. package/dist/super-editor/converter.es.js +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/file-zipper.es.js +1 -1
  18. package/dist/super-editor/super-editor/src/core/Editor.d.ts +1 -0
  19. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/mc/altermateContent/alternate-content-translator.d.ts +11 -0
  20. package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content-commands.d.ts +25 -0
  21. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTablesById.d.ts +10 -0
  22. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/index.d.ts +1 -0
  23. package/dist/super-editor/super-editor/src/extensions/table/table.d.ts +84 -0
  24. package/dist/super-editor/super-editor/src/extensions/table/tableHelpers/appendRows.d.ts +139 -0
  25. package/dist/super-editor/super-editor/src/index.d.ts +8 -2
  26. package/dist/super-editor/super-editor.es.js +18 -14
  27. package/dist/super-editor/toolbar.es.js +2 -2
  28. package/dist/super-editor.cjs +1 -1
  29. package/dist/super-editor.es.js +1 -1
  30. package/dist/superdoc.cjs +2 -2
  31. package/dist/superdoc.es.js +2 -2
  32. package/dist/superdoc.umd.js +501 -254
  33. package/dist/superdoc.umd.js.map +1 -1
  34. 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, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFontsWithLocalFonts_fn, determineUnsupportedFontsWithCanvas_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, _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, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initTrackChanges_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, _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, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$1, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as ReplaceStep, E as NodeRange, G as findWrapping, L as ListHelpers, H as findParentNode, I as isMacOS, J as isIOS, K as getSchemaTypeByName, O as inputRulesPlugin, Q as TrackDeleteMarkName, U as TrackInsertMarkName, V as v4, W as TrackFormatMarkName, X as comments_module_events, Y as findMark, Z as objectIncludes, _ as AddMarkStep, $ as RemoveMarkStep, a0 as twipsToLines, a1 as pixelsToTwips, a2 as helpers, a3 as posToDOMRect, a4 as CommandService, a5 as SuperConverter, a6 as createDocument, a7 as createDocFromMarkdown, a8 as createDocFromHTML, a9 as EditorState, aa as hasSomeParentWithClass, ab as isActive, ac as unflattenListsInHtml, ad as parseSizeUnit, ae as minMax, af as getLineHeightValueString, ag as updateDOMAttributes, ah as findChildren$5, ai as htmlHandler, aj as generateRandomSigned32BitIntStrId, ak as InputRule, al as kebabCase, am as findParentNodeClosestToPos, an as getListItemStyleDefinitions, ao as docxNumberigHelpers, ap as parseIndentElement, aq as combineIndents, ar as twipsToPixels, as as PIXELS_PER_INCH, at as SelectionRange, au as Transform, av as isInTable$1, aw as generateDocxRandomId, ax as insertNewRelationship, ay as inchesToPixels } from "./converter-gSy6s2VK.js";
15
+ import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$1, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as ReplaceStep, E as NodeRange, G as findWrapping, L as ListHelpers, H as findParentNode, I as isMacOS, J as isIOS, K as getSchemaTypeByName, O as inputRulesPlugin, Q as TrackDeleteMarkName, U as TrackInsertMarkName, V as v4, W as TrackFormatMarkName, X as comments_module_events, Y as findMark, Z as objectIncludes, _ as AddMarkStep, $ as RemoveMarkStep, a0 as twipsToLines, a1 as pixelsToTwips, a2 as helpers, a3 as posToDOMRect, a4 as CommandService, a5 as SuperConverter, a6 as createDocument, a7 as createDocFromMarkdown, a8 as createDocFromHTML, a9 as EditorState, aa as hasSomeParentWithClass, ab as isActive, ac as unflattenListsInHtml, ad as parseSizeUnit, ae as minMax, af as getLineHeightValueString, ag as updateDOMAttributes, ah as findChildren$5, ai as htmlHandler, aj as generateRandomSigned32BitIntStrId, ak as InputRule, al as kebabCase, am as findParentNodeClosestToPos, an as getListItemStyleDefinitions, ao as docxNumberigHelpers, ap as parseIndentElement, aq as combineIndents, ar as twipsToPixels, as as PIXELS_PER_INCH, at as SelectionRange, au as Transform, av as isInTable$1, aw as generateDocxRandomId, ax as insertNewRelationship, ay as inchesToPixels } from "./converter-khE-H7hH.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-CceGxV02.js";
17
+ import { D as DocxZipper } from "./docx-zipper-KoUEtzIj.js";
18
18
  var GOOD_LEAF_SIZE = 200;
19
19
  var RopeSequence = function RopeSequence2() {
20
20
  };
@@ -14294,7 +14294,9 @@ const _Editor = class _Editor extends EventEmitter {
14294
14294
  isHeaderFooterChanged: false,
14295
14295
  isCustomXmlChanged: false,
14296
14296
  focusTarget: null,
14297
- permissionResolver: null
14297
+ permissionResolver: null,
14298
+ // header/footer editors may have parent(main) editor set
14299
+ parentEditor: null
14298
14300
  });
14299
14301
  __privateMethod(this, _Editor_instances, initContainerElement_fn).call(this, options);
14300
14302
  __privateMethod(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -14422,6 +14424,7 @@ const _Editor = class _Editor extends EventEmitter {
14422
14424
  * @param {string} documentMode - The document mode ('editing', 'viewing', 'suggesting')
14423
14425
  */
14424
14426
  setDocumentMode(documentMode) {
14427
+ if (this.options.isHeaderOrFooter || this.options.isChildEditor) return;
14425
14428
  let cleanedMode = documentMode?.toLowerCase() || "editing";
14426
14429
  if (!this.extensionService || !this.state) return;
14427
14430
  const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
@@ -14437,7 +14440,7 @@ const _Editor = class _Editor extends EventEmitter {
14437
14440
  isEditMode: false,
14438
14441
  documentMode: cleanedMode
14439
14442
  });
14440
- if (!this.options.isHeaderOrFooter && pm) pm.classList.add("view-mode");
14443
+ if (pm) pm.classList.add("view-mode");
14441
14444
  } else if (cleanedMode === "suggesting") {
14442
14445
  __privateMethod(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
14443
14446
  this.commands.disableTrackChangesShowOriginal();
@@ -15056,7 +15059,7 @@ const _Editor = class _Editor extends EventEmitter {
15056
15059
  * @returns {Object | void} Migration results
15057
15060
  */
15058
15061
  processCollaborationMigrations() {
15059
- console.debug("[checkVersionMigrations] Current editor version", "0.24.0");
15062
+ console.debug("[checkVersionMigrations] Current editor version", "0.25.0");
15060
15063
  if (!this.options.ydoc) return;
15061
15064
  const metaMap = this.options.ydoc.getMap("meta");
15062
15065
  let docVersion = metaMap.get("version");
@@ -15271,9 +15274,6 @@ init_fn = function() {
15271
15274
  this.emit("beforeCreate", { editor: this });
15272
15275
  this.on("contentError", this.options.onContentError);
15273
15276
  this.mount(this.options.element);
15274
- if (!this.options.isHeadless) {
15275
- __privateMethod(this, _Editor_instances, checkFonts_fn).call(this);
15276
- }
15277
15277
  this.on("create", this.options.onCreate);
15278
15278
  this.on("update", this.options.onUpdate);
15279
15279
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -15295,8 +15295,12 @@ init_fn = function() {
15295
15295
  if (!this.options.isHeadless) {
15296
15296
  this.initializeCollaborationData();
15297
15297
  this.initDefaultStyles();
15298
+ __privateMethod(this, _Editor_instances, checkFonts_fn).call(this);
15298
15299
  }
15299
- if (!this.options.ydoc || this.options.markdown || this.options.html) {
15300
+ const shouldMigrateListsOnInit = Boolean(
15301
+ this.options.markdown || this.options.html || this.options.loadFromSchema || this.options.jsonOverride || this.options.mode === "html" || this.options.mode === "text"
15302
+ );
15303
+ if (shouldMigrateListsOnInit) {
15300
15304
  this.migrateListsToV2();
15301
15305
  }
15302
15306
  this.setDocumentMode(this.options.documentMode);
@@ -15490,58 +15494,17 @@ checkFonts_fn = async function() {
15490
15494
  if (this.options.isHeadless) {
15491
15495
  return;
15492
15496
  }
15493
- const fontsUsedInDocument = this.converter.getDocumentFonts();
15494
- if (!("queryLocalFonts" in window)) {
15495
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
15496
- const unsupportedFonts = __privateMethod(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
15497
- this.emit("fonts-resolved", {
15498
- documentFonts: fontsUsedInDocument,
15499
- unsupportedFonts
15500
- });
15501
- return;
15502
- }
15503
- const localFontAccess = await navigator.permissions.query({ name: "local-fonts" });
15504
- if (localFontAccess.state === "denied") {
15505
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
15506
- const unsupportedFonts = __privateMethod(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
15507
- this.emit("fonts-resolved", {
15508
- documentFonts: fontsUsedInDocument,
15509
- unsupportedFonts
15510
- });
15511
- return;
15512
- }
15513
15497
  try {
15514
- const localFonts = await window.queryLocalFonts();
15515
- const uniqueLocalFonts = [...new Set(localFonts.map((font) => font.family))];
15516
- const unsupportedFonts = __privateMethod(this, _Editor_instances, determineUnsupportedFontsWithLocalFonts_fn).call(this, fontsUsedInDocument, uniqueLocalFonts);
15498
+ const fontsUsedInDocument = this.converter.getDocumentFonts();
15499
+ const unsupportedFonts = __privateMethod(this, _Editor_instances, determineUnsupportedFonts_fn).call(this, fontsUsedInDocument);
15517
15500
  this.emit("fonts-resolved", {
15518
15501
  documentFonts: fontsUsedInDocument,
15519
15502
  unsupportedFonts
15520
15503
  });
15521
15504
  } catch {
15522
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
15523
- const unsupportedFonts = __privateMethod(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
15524
- this.emit("fonts-resolved", {
15525
- documentFonts: fontsUsedInDocument,
15526
- unsupportedFonts
15527
- });
15505
+ console.warn("[SuperDoc] Could not determine document fonts and unsupported fonts");
15528
15506
  }
15529
15507
  };
15530
- /**
15531
- * Determines which fonts used in the document are not available locally nor imported.
15532
- *
15533
- * @param {string[]} fonts - Array of font family names used in the document.
15534
- * @param {string[]} localFonts - Array of local font family names available on the system.
15535
- * @returns {string[]} Array of font names that are unsupported.
15536
- */
15537
- determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
15538
- const unsupportedFonts = fonts.filter((font) => {
15539
- const isLocalFont = localFonts.includes(font);
15540
- const isFontImported = this.fontsImported.includes(font);
15541
- return !isLocalFont && !isFontImported;
15542
- });
15543
- return unsupportedFonts;
15544
- };
15545
15508
  /**
15546
15509
  * Determines which fonts used in the document are not supported
15547
15510
  * by attempting to render them on a canvas.
@@ -15551,7 +15514,7 @@ determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
15551
15514
  * @param {string[]} fonts - Array of font family names used in the document.
15552
15515
  * @returns {string[]} Array of unsupported font family names.
15553
15516
  */
15554
- determineUnsupportedFontsWithCanvas_fn = function(fonts) {
15517
+ determineUnsupportedFonts_fn = function(fonts) {
15555
15518
  const unsupportedFonts = fonts.filter((font) => {
15556
15519
  const canRender = canRenderFont(font);
15557
15520
  const isFontImported = this.fontsImported.includes(font);
@@ -15660,6 +15623,9 @@ onCollaborationReady_fn = function({ editor, ydoc }) {
15660
15623
  if (this.options.collaborationIsReady) return;
15661
15624
  console.debug("🔗 [super-editor] Collaboration ready");
15662
15625
  __privateMethod(this, _Editor_instances, validateDocumentInit_fn).call(this);
15626
+ if (this.options.ydoc) {
15627
+ this.migrateListsToV2();
15628
+ }
15663
15629
  this.options.onCollaborationReady({ editor, ydoc });
15664
15630
  this.options.collaborationIsReady = true;
15665
15631
  this.options.initialState = this.state;
@@ -15689,6 +15655,30 @@ initComments_fn = function() {
15689
15655
  dispatch(tr);
15690
15656
  }, 50);
15691
15657
  };
15658
+ /**
15659
+ * Initialize track changes based on document mode
15660
+ * @returns {void}
15661
+ */
15662
+ initTrackChanges_fn = function() {
15663
+ if (!this.extensionService || this.options.isHeaderOrFooter) {
15664
+ return;
15665
+ }
15666
+ switch (this.options.documentMode) {
15667
+ case "editing":
15668
+ __privateMethod(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
15669
+ this.commands.disableTrackChangesShowOriginal();
15670
+ this.commands.disableTrackChanges();
15671
+ break;
15672
+ case "suggesting":
15673
+ __privateMethod(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
15674
+ this.commands.disableTrackChangesShowOriginal();
15675
+ this.commands.enableTrackChanges();
15676
+ break;
15677
+ case "viewing":
15678
+ this.commands.toggleTrackChangesShowOriginal();
15679
+ break;
15680
+ }
15681
+ };
15692
15682
  initPagination_fn = async function() {
15693
15683
  if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
15694
15684
  return;
@@ -17639,10 +17629,27 @@ function getStructuredContentBlockTags(state) {
17639
17629
  const result = findChildren$5(state.doc, (node) => node.type.name === "structuredContentBlock");
17640
17630
  return result;
17641
17631
  }
17632
+ function getStructuredContentTablesById(id, state) {
17633
+ if (!id || !state) return [];
17634
+ const blocks = getStructuredContentTagsById(id, state).filter(
17635
+ ({ node }) => node.type.name === "structuredContentBlock"
17636
+ );
17637
+ if (!blocks.length) return [];
17638
+ const { pos: blockPos, node: blockNode } = blocks[0];
17639
+ const tablesInBlock = [];
17640
+ blockNode.descendants((child, relPos) => {
17641
+ if (child.type.name === "table") {
17642
+ const absPos = blockPos + 1 + relPos;
17643
+ tablesInBlock.push({ node: child, pos: absPos });
17644
+ }
17645
+ });
17646
+ return tablesInBlock;
17647
+ }
17642
17648
  const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17643
17649
  __proto__: null,
17644
17650
  getStructuredContentBlockTags,
17645
17651
  getStructuredContentInlineTags,
17652
+ getStructuredContentTablesById,
17646
17653
  getStructuredContentTags,
17647
17654
  getStructuredContentTagsById
17648
17655
  }, Symbol.toStringTag, { value: "Module" }));
@@ -17839,6 +17846,36 @@ const StructuredContentCommands = Extension.create({
17839
17846
  tr.replaceWith(posFrom, posTo, content);
17840
17847
  }
17841
17848
  return true;
17849
+ },
17850
+ /**
17851
+ * Append multiple rows to the end of a table inside a structured content block.
17852
+ * Each inner array represents the cell values for one new row.
17853
+ * @category Command
17854
+ * @param {StructuredContentTableAppendRowsOptions} options - Append configuration
17855
+ * @example
17856
+ * editor.commands.appendRowsToStructuredContentTable({
17857
+ * id: 'block-123',
17858
+ * tableIndex: 0,
17859
+ * rows: [['A', 'B'], ['C', 'D']],
17860
+ * copyRowStyle: true,
17861
+ * });
17862
+ */
17863
+ appendRowsToStructuredContentTable: ({ id, tableIndex = 0, rows = [], copyRowStyle = false }) => ({ state, commands: commands2, dispatch }) => {
17864
+ const normalized = normalizeRowsInput(rows);
17865
+ if (!normalized.length) return true;
17866
+ const tables = getStructuredContentTablesById(id, state);
17867
+ if (!tables.length || tableIndex < 0 || tableIndex >= tables.length) return true;
17868
+ const { node: tableNode, pos: tablePos } = tables[tableIndex];
17869
+ if (dispatch) {
17870
+ return commands2.appendRowsWithContent({ tablePos, tableNode, valueRows: normalized, copyRowStyle });
17871
+ }
17872
+ return commands2.appendRowsWithContent({
17873
+ tablePos,
17874
+ tableNode,
17875
+ valueRows: normalized,
17876
+ copyRowStyle,
17877
+ dispatch: false
17878
+ });
17842
17879
  }
17843
17880
  };
17844
17881
  },
@@ -17848,6 +17885,15 @@ const StructuredContentCommands = Extension.create({
17848
17885
  };
17849
17886
  }
17850
17887
  });
17888
+ const normalizeRowsInput = (rowsOrValues) => {
17889
+ if (!Array.isArray(rowsOrValues) || !rowsOrValues.length) {
17890
+ return [];
17891
+ }
17892
+ if (Array.isArray(rowsOrValues[0])) {
17893
+ return rowsOrValues;
17894
+ }
17895
+ return [rowsOrValues];
17896
+ };
17851
17897
  class DocumentSectionView {
17852
17898
  constructor(node, getPos, decorations, editor) {
17853
17899
  __privateAdd(this, _DocumentSectionView_instances);
@@ -23600,6 +23646,107 @@ function cellWrapping($pos) {
23600
23646
  }
23601
23647
  return null;
23602
23648
  }
23649
+ function resolveTable(tr, tablePos, tableNode) {
23650
+ if (tableNode && tableNode.type && tableNode.type.name === "table") {
23651
+ return tableNode;
23652
+ }
23653
+ if (typeof tablePos === "number") {
23654
+ const current = tr.doc.nodeAt(tablePos);
23655
+ if (current && current.type.name === "table") {
23656
+ return current;
23657
+ }
23658
+ }
23659
+ return null;
23660
+ }
23661
+ function pickTemplateRowForAppend(tableNode, schema) {
23662
+ const RowType = schema.nodes.tableRow;
23663
+ const rows = [];
23664
+ tableNode.descendants((child) => {
23665
+ if (child.type === RowType) rows.push(child);
23666
+ });
23667
+ if (!rows.length) return null;
23668
+ for (let i = rows.length - 1; i >= 0; i--) {
23669
+ const r2 = rows[i];
23670
+ const hasBodyCell = r2.content?.content?.some((c) => c.type.name === "tableCell");
23671
+ if (hasBodyCell) return r2;
23672
+ }
23673
+ return rows[rows.length - 1];
23674
+ }
23675
+ function extractRowTemplateFormatting(cellNode, schema) {
23676
+ const ParagraphType = schema.nodes.paragraph;
23677
+ let blockType = ParagraphType;
23678
+ let blockAttrs = null;
23679
+ let textMarks = [];
23680
+ const blocks = cellNode?.content?.content || [];
23681
+ for (const block of blocks) {
23682
+ const isParagraphish = block.type === ParagraphType || block.type.name === "heading";
23683
+ if (isParagraphish) {
23684
+ blockType = block.type || ParagraphType;
23685
+ blockAttrs = block.attrs || null;
23686
+ }
23687
+ let foundText = null;
23688
+ block.descendants?.((n) => {
23689
+ if (!foundText && n.isText) foundText = n;
23690
+ });
23691
+ if (foundText) {
23692
+ textMarks = foundText.marks ? Array.from(foundText.marks) : [];
23693
+ break;
23694
+ }
23695
+ }
23696
+ if (!blockType || !blockType.validContent) blockType = ParagraphType;
23697
+ return { blockType, blockAttrs, textMarks };
23698
+ }
23699
+ function buildFormattedCellBlock(schema, value, { blockType, blockAttrs, textMarks }, copyRowStyle = false) {
23700
+ const text = typeof value === "string" ? value : value == null ? "" : String(value);
23701
+ const marks = copyRowStyle ? textMarks || [] : [];
23702
+ const textNode = schema.text(text, marks);
23703
+ const type = blockType || schema.nodes.paragraph;
23704
+ return type.createAndFill(blockAttrs || null, textNode);
23705
+ }
23706
+ function buildRowFromTemplateRow({ schema, tableNode, templateRow, values, copyRowStyle = false }) {
23707
+ const RowType = schema.nodes.tableRow;
23708
+ const CellType = schema.nodes.tableCell;
23709
+ const HeaderType = schema.nodes.tableHeader;
23710
+ const map2 = TableMap.get(tableNode);
23711
+ const totalColumns = map2.width;
23712
+ const byColumns = Array.isArray(values) && values.length === totalColumns;
23713
+ const newCells = [];
23714
+ let columnCursor = 0;
23715
+ templateRow.content.content.forEach((cellNode, cellIndex) => {
23716
+ const isHeaderCell = cellNode.type === HeaderType;
23717
+ const targetCellType = isHeaderCell ? CellType : cellNode.type;
23718
+ const attrs = { ...cellNode.attrs };
23719
+ const formatting = extractRowTemplateFormatting(cellNode, schema);
23720
+ let cellValue = "";
23721
+ if (byColumns) {
23722
+ const span = Math.max(1, attrs.colspan || 1);
23723
+ cellValue = values[columnCursor] ?? "";
23724
+ columnCursor += span;
23725
+ } else {
23726
+ cellValue = Array.isArray(values) ? values[cellIndex] ?? "" : "";
23727
+ }
23728
+ const content = buildFormattedCellBlock(schema, cellValue, formatting, copyRowStyle);
23729
+ const newCell = targetCellType.createAndFill(attrs, content);
23730
+ if (newCell) newCells.push(newCell);
23731
+ });
23732
+ return RowType.createAndFill(null, newCells);
23733
+ }
23734
+ function insertRowsAtTableEnd({ tr, tablePos, tableNode, rows }) {
23735
+ if (!rows || !rows.length) return;
23736
+ const RowTypeName = "tableRow";
23737
+ let lastRowRelPos = 0;
23738
+ let lastRowNode = null;
23739
+ tableNode.descendants((child, relPos) => {
23740
+ if (child.type.name === RowTypeName) {
23741
+ lastRowRelPos = relPos;
23742
+ lastRowNode = child;
23743
+ }
23744
+ });
23745
+ if (!lastRowNode) return;
23746
+ const lastRowAbsEnd = tablePos + 1 + lastRowRelPos + lastRowNode.nodeSize;
23747
+ const frag = Fragment.fromArray(rows);
23748
+ tr.insert(lastRowAbsEnd, frag);
23749
+ }
23603
23750
  const Table = Node$1.create({
23604
23751
  name: "table",
23605
23752
  content: "tableRow+",
@@ -23759,6 +23906,47 @@ const Table = Node$1.create({
23759
23906
  },
23760
23907
  addCommands() {
23761
23908
  return {
23909
+ /**
23910
+ * Append multiple rows to the end of a table in a single transaction.
23911
+ * @category Command
23912
+ * @param {appendRowsWithContentOptions} options - Append configuration
23913
+ * @example
23914
+ * editor.commands.appendRowsWithContent({ tablePos, valueRows: [['A','B'], ['C','D']], copyRowStyle: true })
23915
+ */
23916
+ appendRowsWithContent: ({ tablePos, tableNode, valueRows = [], copyRowStyle = false }) => ({ editor, chain }) => {
23917
+ if (typeof tablePos !== "number" && !tableNode || !Array.isArray(valueRows) || !valueRows.length) {
23918
+ return false;
23919
+ }
23920
+ return chain().command(({ tr, dispatch }) => {
23921
+ const workingTable = resolveTable(tr, tablePos, tableNode);
23922
+ if (!workingTable) return false;
23923
+ const templateRow = pickTemplateRowForAppend(workingTable, editor.schema);
23924
+ if (!templateRow) return false;
23925
+ const newRows = valueRows.map(
23926
+ (vals) => buildRowFromTemplateRow({
23927
+ schema: editor.schema,
23928
+ tableNode: workingTable,
23929
+ templateRow,
23930
+ values: vals,
23931
+ copyRowStyle
23932
+ })
23933
+ ).filter(Boolean);
23934
+ if (!newRows.length) return false;
23935
+ let resolvedTablePos = tablePos;
23936
+ if (typeof resolvedTablePos !== "number" && workingTable) {
23937
+ const tables = editor.getNodesOfType("table");
23938
+ const match = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
23939
+ resolvedTablePos = match?.pos ?? null;
23940
+ }
23941
+ if (typeof resolvedTablePos !== "number") {
23942
+ return false;
23943
+ }
23944
+ if (dispatch) {
23945
+ insertRowsAtTableEnd({ tr, tablePos, tableNode: workingTable, rows: newRows });
23946
+ }
23947
+ return true;
23948
+ }).run();
23949
+ },
23762
23950
  /**
23763
23951
  * Insert a new table into the document
23764
23952
  * @category Command
@@ -26665,58 +26853,6 @@ const registerImages = async (foundImages, editor, view) => {
26665
26853
  }
26666
26854
  });
26667
26855
  };
26668
- const normalizeWrap = (attrs = {}) => {
26669
- const wrap = attrs.wrap;
26670
- if (wrap?.type && wrap.type !== "Inline") {
26671
- return {
26672
- type: wrap.type,
26673
- attrs: wrap.attrs ?? {}
26674
- };
26675
- }
26676
- if (wrap?.type === "Inline" && Object.keys(wrap.attrs ?? {}).length) {
26677
- return {
26678
- type: "Inline",
26679
- attrs: wrap.attrs
26680
- };
26681
- }
26682
- if (!wrap && attrs.wrapText) {
26683
- return {
26684
- type: "Square",
26685
- attrs: {
26686
- wrapText: attrs.wrapText
26687
- }
26688
- };
26689
- }
26690
- if (!wrap && attrs.wrapTopAndBottom) {
26691
- return {
26692
- type: "TopAndBottom",
26693
- attrs: {}
26694
- };
26695
- }
26696
- if (wrap?.type === "Inline") {
26697
- return {
26698
- type: "Inline",
26699
- attrs: wrap.attrs ?? {}
26700
- };
26701
- }
26702
- return {
26703
- type: "Inline",
26704
- attrs: {}
26705
- };
26706
- };
26707
- const normalizeMarginOffset = (marginOffset = {}) => {
26708
- const { left: left2, horizontal, ...rest } = marginOffset;
26709
- return {
26710
- ...rest,
26711
- horizontal: horizontal ?? left2
26712
- };
26713
- };
26714
- const getNormalizedImageAttrs = (attrs = {}) => {
26715
- return {
26716
- wrap: normalizeWrap(attrs),
26717
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
26718
- };
26719
- };
26720
26856
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
26721
26857
  const ImagePositionPlugin = ({ editor }) => {
26722
26858
  const { view } = editor;
@@ -26729,8 +26865,9 @@ const ImagePositionPlugin = ({ editor }) => {
26729
26865
  return DecorationSet.empty;
26730
26866
  },
26731
26867
  apply(tr, oldDecorationSet, oldState, newState) {
26732
- if (!tr.docChanged) return oldDecorationSet;
26868
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
26733
26869
  const decorations = getImagePositionDecorations(newState, view);
26870
+ shouldUpdate = false;
26734
26871
  return DecorationSet.create(newState.doc, decorations);
26735
26872
  }
26736
26873
  },
@@ -26739,7 +26876,6 @@ const ImagePositionPlugin = ({ editor }) => {
26739
26876
  update: (view2, lastState) => {
26740
26877
  const pagination = PaginationPluginKey.getState(lastState);
26741
26878
  if (shouldUpdate) {
26742
- shouldUpdate = false;
26743
26879
  const decorations = getImagePositionDecorations(lastState, view2);
26744
26880
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
26745
26881
  view2.dispatch(updateTransaction);
@@ -26765,41 +26901,35 @@ const getImagePositionDecorations = (state, view) => {
26765
26901
  let className = "";
26766
26902
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
26767
26903
  const { size, padding } = node.attrs;
26768
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
26769
26904
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
26770
- if (pageBreak) {
26771
- switch (alignH) {
26772
- case "left":
26773
- style += "float: left; left: 0; margin-left: 0; ";
26774
- break;
26775
- case "right":
26776
- style += "float: right; right: 0; margin-right: 0; ";
26777
- break;
26778
- case "center":
26779
- style += "display: block; margin-left: auto; margin-right: auto; ";
26780
- break;
26905
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
26906
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
26907
+ let horizontalAlignment = `${alignH}: 0;`;
26908
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
26909
+ style += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
26910
+ const nextPos = view.posAtDOM(pageBreak, 1);
26911
+ if (nextPos < 0) {
26912
+ const $pos = view.state.doc.resolve(pos);
26913
+ decorations.push(
26914
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
26915
+ style: `height: ${size.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
26916
+ })
26917
+ );
26781
26918
  }
26782
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
26783
- style += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
26784
- if (vRelativeFrom === "margin") {
26785
- const nextPos = view.posAtDOM(pageBreak, 1);
26786
- if (nextPos < 0) {
26787
- const $pos = view.state.doc.resolve(pos);
26788
- decorations.push(
26789
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
26790
- style: `height: ${size.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
26791
- })
26792
- );
26793
- }
26794
- const imageBlock = document.createElement("div");
26795
- imageBlock.className = "anchor-image-placeholder";
26796
- imageBlock.style.float = alignH;
26797
- imageBlock.style.width = size.width + parseInt(padding[alignH]) + "px";
26798
- imageBlock.style.height = size.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
26799
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
26919
+ const imageBlock = document.createElement("div");
26920
+ imageBlock.className = "anchor-image-placeholder";
26921
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
26922
+ let paddingHorizontal;
26923
+ if (alignH === "center") {
26924
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
26925
+ } else {
26926
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
26800
26927
  }
26928
+ imageBlock.style.width = size.width + paddingHorizontal + "px";
26929
+ imageBlock.style.height = size.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
26930
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
26931
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style, class: className }));
26801
26932
  }
26802
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style, class: className }));
26803
26933
  }
26804
26934
  });
26805
26935
  return decorations;
@@ -26824,6 +26954,58 @@ const findPreviousDomNodeWithClass = (view, pos, className) => {
26824
26954
  }
26825
26955
  return null;
26826
26956
  };
26957
+ const normalizeWrap = (attrs = {}) => {
26958
+ const wrap = attrs.wrap;
26959
+ if (wrap?.type && wrap.type !== "Inline") {
26960
+ return {
26961
+ type: wrap.type,
26962
+ attrs: wrap.attrs ?? {}
26963
+ };
26964
+ }
26965
+ if (wrap?.type === "Inline" && Object.keys(wrap.attrs ?? {}).length) {
26966
+ return {
26967
+ type: "Inline",
26968
+ attrs: wrap.attrs
26969
+ };
26970
+ }
26971
+ if (!wrap && attrs.wrapText) {
26972
+ return {
26973
+ type: "Square",
26974
+ attrs: {
26975
+ wrapText: attrs.wrapText
26976
+ }
26977
+ };
26978
+ }
26979
+ if (!wrap && attrs.wrapTopAndBottom) {
26980
+ return {
26981
+ type: "TopAndBottom",
26982
+ attrs: {}
26983
+ };
26984
+ }
26985
+ if (wrap?.type === "Inline") {
26986
+ return {
26987
+ type: "Inline",
26988
+ attrs: wrap.attrs ?? {}
26989
+ };
26990
+ }
26991
+ return {
26992
+ type: "Inline",
26993
+ attrs: {}
26994
+ };
26995
+ };
26996
+ const normalizeMarginOffset = (marginOffset = {}) => {
26997
+ const { left: left2, horizontal, ...rest } = marginOffset;
26998
+ return {
26999
+ ...rest,
27000
+ horizontal: horizontal ?? left2
27001
+ };
27002
+ };
27003
+ const getNormalizedImageAttrs = (attrs = {}) => {
27004
+ return {
27005
+ wrap: normalizeWrap(attrs),
27006
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
27007
+ };
27008
+ };
26827
27009
  const getRotationMargins = (w, h, angleDegrees) => {
26828
27010
  const rad = angleDegrees * (Math.PI / 180);
26829
27011
  const cos = Math.abs(Math.cos(rad));
@@ -27032,27 +27214,15 @@ const Image = Node$1.create({
27032
27214
  style += "float: right;";
27033
27215
  floatRight = true;
27034
27216
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
27035
- const pageStyles2 = this.editor?.converter?.pageStyles;
27036
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size.width) {
27037
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
27038
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
27039
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
27040
- const contentWidth = pageWidth - leftMargin - rightMargin;
27041
- const imageWidth = size.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
27042
- const leftSpace = marginOffset.horizontal;
27043
- const rightSpace = contentWidth - leftSpace - imageWidth;
27044
- if (rightSpace < 0) {
27045
- style += "float: left;";
27046
- } else if (rightSpace > leftSpace) {
27047
- style += "float: left;";
27048
- } else {
27049
- style += "float: right;";
27050
- floatRight = true;
27051
- baseHorizontal = rightSpace;
27052
- }
27053
- } else {
27054
- style += "float: left;";
27055
- }
27217
+ const pageStylesData2 = getDataFromPageStyles({
27218
+ editor: this.editor,
27219
+ marginOffset,
27220
+ size,
27221
+ attrs
27222
+ });
27223
+ style += pageStylesData2.style;
27224
+ floatRight = pageStylesData2.floatRight;
27225
+ baseHorizontal = pageStylesData2.baseHorizontal;
27056
27226
  }
27057
27227
  if (attrs.distTop) margin.top += attrs.distTop;
27058
27228
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -27062,27 +27232,15 @@ const Image = Node$1.create({
27062
27232
  case "Through":
27063
27233
  case "Tight":
27064
27234
  style += "clear: both;";
27065
- const pageStyles = this.editor?.converter?.pageStyles;
27066
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size.width) {
27067
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
27068
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
27069
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
27070
- const contentWidth = pageWidth - leftMargin - rightMargin;
27071
- const imageWidth = size.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
27072
- const leftSpace = marginOffset.horizontal;
27073
- const rightSpace = contentWidth - leftSpace - imageWidth;
27074
- if (rightSpace < 0) {
27075
- style += "float: left;";
27076
- } else if (rightSpace > leftSpace) {
27077
- style += "float: left;";
27078
- } else {
27079
- style += "float: right;";
27080
- floatRight = true;
27081
- baseHorizontal = rightSpace;
27082
- }
27083
- } else {
27084
- style += "float: left;";
27085
- }
27235
+ const pageStylesData = getDataFromPageStyles({
27236
+ editor: this.editor,
27237
+ marginOffset,
27238
+ size,
27239
+ attrs
27240
+ });
27241
+ style += pageStylesData.style;
27242
+ floatRight = pageStylesData.floatRight;
27243
+ baseHorizontal = pageStylesData.baseHorizontal;
27086
27244
  if (attrs.distTop) margin.top += attrs.distTop;
27087
27245
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
27088
27246
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -27119,6 +27277,22 @@ const Image = Node$1.create({
27119
27277
  }
27120
27278
  const hasAnchorData = Boolean(anchorData);
27121
27279
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
27280
+ if (hasAnchorData) {
27281
+ switch (anchorData.hRelativeFrom) {
27282
+ case "page":
27283
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
27284
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
27285
+ break;
27286
+ case "margin":
27287
+ if (anchorData.alignH === "center") {
27288
+ style += "position: absolute; left: 50%; transform: translateX(-50%);";
27289
+ }
27290
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
27291
+ style += `position: absolute; ${anchorData.alignH}: 0;`;
27292
+ }
27293
+ break;
27294
+ }
27295
+ }
27122
27296
  if (hasAnchorData || hasMarginOffsets) {
27123
27297
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
27124
27298
  const maxMarginV = 500;
@@ -27267,6 +27441,37 @@ const Image = Node$1.create({
27267
27441
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
27268
27442
  }
27269
27443
  });
27444
+ const getDataFromPageStyles = ({ editor, marginOffset, size, attrs }) => {
27445
+ let style = "";
27446
+ let floatRight = false;
27447
+ let baseHorizontal = marginOffset?.horizontal || 0;
27448
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
27449
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size.width) {
27450
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
27451
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
27452
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
27453
+ const contentWidth = pageWidth - leftMargin - rightMargin;
27454
+ const imageWidth = size.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
27455
+ const leftSpace = marginOffset.horizontal;
27456
+ const rightSpace = contentWidth - leftSpace - imageWidth;
27457
+ if (rightSpace < 0) {
27458
+ style += "float: left;";
27459
+ } else if (rightSpace > leftSpace) {
27460
+ style += "float: left;";
27461
+ } else {
27462
+ style += "float: right;";
27463
+ floatRight = true;
27464
+ baseHorizontal = rightSpace;
27465
+ }
27466
+ } else {
27467
+ style += "float: left;";
27468
+ }
27469
+ return {
27470
+ style,
27471
+ floatRight,
27472
+ baseHorizontal
27473
+ };
27474
+ };
27270
27475
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
27271
27476
  const getFileOpener = () => {
27272
27477
  let fileInput = document.createElement("input");
@@ -29236,6 +29441,10 @@ const derivePermissionKey = ({ action, isOwn }) => {
29236
29441
  if (!mapping) return null;
29237
29442
  return isOwn ? mapping.own : mapping.other;
29238
29443
  };
29444
+ const normalizeEmail = (value) => {
29445
+ if (typeof value !== "string") return "";
29446
+ return value.trim().toLowerCase();
29447
+ };
29239
29448
  const resolveChanges = (editor) => {
29240
29449
  if (!editor) return { role: "editor", isInternal: false, currentUser: null, resolver: null };
29241
29450
  const role = editor.options?.role ?? "editor";
@@ -29248,10 +29457,10 @@ const isTrackedChangeActionAllowed = ({ editor, action, trackedChanges }) => {
29248
29457
  if (!trackedChanges?.length) return true;
29249
29458
  const { role, isInternal, currentUser, resolver } = resolveChanges(editor);
29250
29459
  if (typeof resolver !== "function") return true;
29251
- const currentEmail = currentUser?.email ?? null;
29460
+ const currentEmail = normalizeEmail(currentUser?.email);
29252
29461
  return trackedChanges.every((change) => {
29253
- const authorEmail = change.attrs?.authorEmail ?? null;
29254
- const isOwn = Boolean(currentEmail && authorEmail && currentEmail === authorEmail);
29462
+ const authorEmail = normalizeEmail(change.attrs?.authorEmail);
29463
+ const isOwn = !currentEmail || !authorEmail || currentEmail === authorEmail;
29255
29464
  const permission = derivePermissionKey({ action, isOwn });
29256
29465
  if (!permission) return true;
29257
29466
  const payload = {
@@ -29388,6 +29597,15 @@ const TrackChanges = Extension.create({
29388
29597
  const { from: from2, to } = state.selection;
29389
29598
  return commands2.acceptTrackedChangesBetween(from2, to);
29390
29599
  },
29600
+ acceptTrackedChangeFromToolbar: () => ({ state, commands: commands2 }) => {
29601
+ const commentsPluginState = CommentsPluginKey.getState(state);
29602
+ const activeThreadId = commentsPluginState?.activeThreadId;
29603
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
29604
+ return commands2.acceptTrackedChangeById(activeThreadId);
29605
+ } else {
29606
+ return commands2.acceptTrackedChangeBySelection();
29607
+ }
29608
+ },
29391
29609
  acceptTrackedChangeById: (id) => ({ state, tr, commands: commands2 }) => {
29392
29610
  const toResolve = getChangesByIdToResolve(state, id) || [];
29393
29611
  return toResolve.map(({ from: from2, to }) => {
@@ -29416,6 +29634,15 @@ const TrackChanges = Extension.create({
29416
29634
  const { from: from2, to } = state.selection;
29417
29635
  return commands2.rejectTrackedChangesBetween(from2, to);
29418
29636
  },
29637
+ rejectTrackedChangeFromToolbar: () => ({ state, commands: commands2 }) => {
29638
+ const commentsPluginState = CommentsPluginKey.getState(state);
29639
+ const activeThreadId = commentsPluginState?.activeThreadId;
29640
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
29641
+ return commands2.rejectTrackedChangeById(activeThreadId);
29642
+ } else {
29643
+ return commands2.rejectTrackedChangeOnSelection();
29644
+ }
29645
+ },
29419
29646
  rejectAllTrackedChanges: () => ({ state, commands: commands2 }) => {
29420
29647
  const from2 = 0, to = state.doc.content.size;
29421
29648
  return commands2.rejectTrackedChangesBetween(from2, to);
@@ -34709,7 +34936,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
34709
34936
  return oldState;
34710
34937
  }
34711
34938
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
34712
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
34939
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
34713
34940
  return DecorationSet.empty;
34714
34941
  }
34715
34942
  const { selection } = newState;
@@ -35059,6 +35286,7 @@ const getStarterExtensions = () => {
35059
35286
  export {
35060
35287
  Attribute as A,
35061
35288
  CommentsPluginKey as C,
35289
+ DecorationSet as D,
35062
35290
  Editor as E,
35063
35291
  Mark as M,
35064
35292
  Node$1 as N,
@@ -35079,14 +35307,15 @@ export {
35079
35307
  collectTrackedChangesForContext as k,
35080
35308
  getStarterExtensions as l,
35081
35309
  getRichTextExtensions as m,
35082
- Extension as n,
35083
- index$1 as o,
35084
- index as p,
35085
- AnnotatorHelpers as q,
35310
+ Decoration as n,
35311
+ Extension as o,
35312
+ index$1 as p,
35313
+ index as q,
35086
35314
  replaceSelectionWithImagePlaceholder as r,
35087
35315
  shouldBypassContextMenu as s,
35088
- SectionHelpers as t,
35316
+ AnnotatorHelpers as t,
35089
35317
  useHighContrastMode as u,
35090
- getAllowedImageDimensions as v,
35318
+ SectionHelpers as v,
35319
+ getAllowedImageDimensions as w,
35091
35320
  yUndoPluginKey as y
35092
35321
  };