@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
@@ -40057,8 +40057,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40057
40057
  handlerName: "w:bookmarkEndTranslator",
40058
40058
  handler: handleBookmarkEndNode
40059
40059
  };
40060
- const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
40061
- const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
40060
+ const SUPPORTED_ALTERNATE_CONTENT_REQUIRES = /* @__PURE__ */ new Set([
40062
40061
  "wps",
40063
40062
  "wp14",
40064
40063
  "w14",
@@ -40071,22 +40070,85 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40071
40070
  "w16sdtfl",
40072
40071
  "w16se"
40073
40072
  ]);
40073
+ const XML_NODE_NAME$1 = "mc:AlternateContent";
40074
+ const SD_NODE_NAME$1 = [];
40075
+ const validXmlAttributes$1 = [];
40076
+ function encode$1(params2) {
40077
+ const { nodeListHandler } = params2;
40078
+ const { node } = params2.extraParams;
40079
+ if (!node || !node.type) {
40080
+ return null;
40081
+ }
40082
+ const { branch, elements } = selectAlternateContentElements(node);
40083
+ if (!elements) {
40084
+ return null;
40085
+ }
40086
+ return nodeListHandler.handler({
40087
+ ...params2,
40088
+ nodes: elements,
40089
+ path: buildPath(params2.path, node, branch)
40090
+ });
40091
+ }
40092
+ function decode$1(params2) {
40093
+ const { node } = params2;
40094
+ const { drawingContent } = node.attrs;
40095
+ const drawing = {
40096
+ name: "w:drawing",
40097
+ elements: [...drawingContent ? [...drawingContent.elements || []] : []]
40098
+ };
40099
+ const choice = {
40100
+ name: "mc:Choice",
40101
+ attributes: { Requires: "wps" },
40102
+ elements: [drawing]
40103
+ };
40104
+ return {
40105
+ name: "mc:AlternateContent",
40106
+ elements: [choice]
40107
+ };
40108
+ }
40109
+ const config$1 = {
40110
+ xmlName: XML_NODE_NAME$1,
40111
+ sdNodeOrKeyName: SD_NODE_NAME$1,
40112
+ type: NodeTranslator.translatorTypes.NODE,
40113
+ encode: encode$1,
40114
+ decode: decode$1,
40115
+ attributes: validXmlAttributes$1
40116
+ };
40117
+ function selectAlternateContentElements(node) {
40118
+ if (!node?.elements?.length) {
40119
+ return { branch: null, elements: null };
40120
+ }
40121
+ const choices = node.elements.filter((el) => el?.name === "mc:Choice");
40122
+ const fallback = node.elements.find((el) => el?.name === "mc:Fallback");
40123
+ const supportedChoice = choices.find((choice) => {
40124
+ const requiresAttr = choice?.attributes?.Requires || choice?.attributes?.requires;
40125
+ if (!requiresAttr) return false;
40126
+ return requiresAttr.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_ALTERNATE_CONTENT_REQUIRES.has(namespace2));
40127
+ });
40128
+ const branch = supportedChoice || fallback || choices[0] || null;
40129
+ const selectedElements = branch?.elements;
40130
+ if (!selectedElements) {
40131
+ return { branch, elements: null };
40132
+ }
40133
+ return {
40134
+ branch,
40135
+ elements: carbonCopy(selectedElements)
40136
+ };
40137
+ }
40138
+ const translator$1 = NodeTranslator.from(config$1);
40139
+ function buildPath(existingPath = [], node, branch) {
40140
+ const path = [...existingPath];
40141
+ if (node) path.push(node);
40142
+ if (branch) path.push(branch);
40143
+ return path;
40144
+ }
40145
+ const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
40074
40146
  const skipHandlerResponse = { nodes: [], consumed: 0 };
40075
40147
  const isAlternateContentNode = (node) => node?.name === ALTERNATE_CONTENT_NODE;
40076
- const isSupportedChoice = (choice) => {
40077
- if (!choice?.attributes) return false;
40078
- const requires = choice.attributes.Requires || choice.attributes.requires;
40079
- if (!requires) return false;
40080
- return requires.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_REQUIRES.has(namespace2));
40081
- };
40082
40148
  const resolveAlternateContentElements = (alternateContent) => {
40083
- if (!alternateContent?.elements?.length) return null;
40084
- const choices = alternateContent.elements.filter((el) => el.name === "mc:Choice");
40085
- const fallback = alternateContent.elements.find((el) => el.name === "mc:Fallback");
40086
- const supportedChoice = choices.find(isSupportedChoice);
40087
- const selectedElements = supportedChoice?.elements || fallback?.elements || choices[0]?.elements;
40088
- if (!selectedElements) return null;
40089
- return carbonCopy(selectedElements);
40149
+ const { elements } = selectAlternateContentElements(alternateContent);
40150
+ if (!elements) return null;
40151
+ return elements;
40090
40152
  };
40091
40153
  const buildNodeWithoutAlternateContent = (node) => {
40092
40154
  const { elements } = node || {};
@@ -40118,16 +40180,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40118
40180
  }
40119
40181
  const [currentNode] = nodes;
40120
40182
  if (isAlternateContentNode(currentNode)) {
40121
- const resolvedElements = resolveAlternateContentElements(currentNode);
40122
- if (!resolvedElements) {
40123
- return skipHandlerResponse;
40124
- }
40125
- const result2 = nodeListHandler.handler({
40183
+ const nodeForTranslator = currentNode?.type ? currentNode : {
40184
+ ...currentNode,
40185
+ type: "element"
40186
+ };
40187
+ const translated = translator$1.encode({
40126
40188
  ...params2,
40127
- nodes: resolvedElements,
40128
- path: [...params2.path || [], currentNode]
40189
+ nodes: [nodeForTranslator],
40190
+ extraParams: { ...params2.extraParams || {}, node: nodeForTranslator }
40129
40191
  });
40130
- return { nodes: result2, consumed: 1 };
40192
+ if (!translated) {
40193
+ return skipHandlerResponse;
40194
+ }
40195
+ const nodesArray = Array.isArray(translated) ? translated : [translated];
40196
+ return { nodes: nodesArray, consumed: 1 };
40131
40197
  }
40132
40198
  const sanitizedNode = buildNodeWithoutAlternateContent(currentNode);
40133
40199
  if (!sanitizedNode) {
@@ -41398,55 +41464,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41398
41464
  };
41399
41465
  return textbox;
41400
41466
  }
41401
- const XML_NODE_NAME$1 = "mc:AlternateContent";
41402
- const SD_NODE_NAME$1 = [];
41403
- const validXmlAttributes$1 = [];
41404
- function encode$1(params2) {
41405
- const { nodeListHandler } = params2;
41406
- const { node } = params2.extraParams;
41407
- if (!node || !node.type) {
41408
- return null;
41409
- }
41410
- const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
41411
- const wpsNode = node.elements.find(
41412
- (el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
41413
- );
41414
- if (!wpsNode) {
41415
- return null;
41416
- }
41417
- const contents = wpsNode.elements;
41418
- return nodeListHandler.handler({
41419
- ...params2,
41420
- nodes: contents,
41421
- path: [...params2.path || [], wpsNode]
41422
- });
41423
- }
41424
- function decode$1(params2) {
41425
- const { node } = params2;
41426
- const { drawingContent } = node.attrs;
41427
- const drawing = {
41428
- name: "w:drawing",
41429
- elements: [...drawingContent ? [...drawingContent.elements || []] : []]
41430
- };
41431
- const choice = {
41432
- name: "mc:Choice",
41433
- attributes: { Requires: "wps" },
41434
- elements: [drawing]
41435
- };
41436
- return {
41437
- name: "mc:AlternateContent",
41438
- elements: [choice]
41439
- };
41440
- }
41441
- const config$1 = {
41442
- xmlName: XML_NODE_NAME$1,
41443
- sdNodeOrKeyName: SD_NODE_NAME$1,
41444
- type: NodeTranslator.translatorTypes.NODE,
41445
- encode: encode$1,
41446
- decode: decode$1,
41447
- attributes: validXmlAttributes$1
41448
- };
41449
- const translator$1 = NodeTranslator.from(config$1);
41450
41467
  function translateContentBlock(params2) {
41451
41468
  const { node } = params2;
41452
41469
  const { vmlAttributes, horizontalRule } = node.attrs;
@@ -42839,7 +42856,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42839
42856
  static getStoredSuperdocVersion(docx) {
42840
42857
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42841
42858
  }
42842
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.24.0") {
42859
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.25.0") {
42843
42860
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42844
42861
  }
42845
42862
  /**
@@ -46050,7 +46067,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
46050
46067
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
46051
46068
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
46052
46069
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
46053
- 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;
46070
+ 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, 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;
46054
46071
  var GOOD_LEAF_SIZE = 200;
46055
46072
  var RopeSequence = function RopeSequence2() {
46056
46073
  };
@@ -60265,7 +60282,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60265
60282
  isHeaderFooterChanged: false,
60266
60283
  isCustomXmlChanged: false,
60267
60284
  focusTarget: null,
60268
- permissionResolver: null
60285
+ permissionResolver: null,
60286
+ // header/footer editors may have parent(main) editor set
60287
+ parentEditor: null
60269
60288
  });
60270
60289
  __privateMethod$1(this, _Editor_instances, initContainerElement_fn).call(this, options);
60271
60290
  __privateMethod$1(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -60393,6 +60412,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60393
60412
  * @param {string} documentMode - The document mode ('editing', 'viewing', 'suggesting')
60394
60413
  */
60395
60414
  setDocumentMode(documentMode) {
60415
+ if (this.options.isHeaderOrFooter || this.options.isChildEditor) return;
60396
60416
  let cleanedMode = documentMode?.toLowerCase() || "editing";
60397
60417
  if (!this.extensionService || !this.state) return;
60398
60418
  const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
@@ -60408,7 +60428,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60408
60428
  isEditMode: false,
60409
60429
  documentMode: cleanedMode
60410
60430
  });
60411
- if (!this.options.isHeaderOrFooter && pm) pm.classList.add("view-mode");
60431
+ if (pm) pm.classList.add("view-mode");
60412
60432
  } else if (cleanedMode === "suggesting") {
60413
60433
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
60414
60434
  this.commands.disableTrackChangesShowOriginal();
@@ -61027,7 +61047,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61027
61047
  * @returns {Object | void} Migration results
61028
61048
  */
61029
61049
  processCollaborationMigrations() {
61030
- console.debug("[checkVersionMigrations] Current editor version", "0.24.0");
61050
+ console.debug("[checkVersionMigrations] Current editor version", "0.25.0");
61031
61051
  if (!this.options.ydoc) return;
61032
61052
  const metaMap = this.options.ydoc.getMap("meta");
61033
61053
  let docVersion = metaMap.get("version");
@@ -61233,9 +61253,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61233
61253
  this.emit("beforeCreate", { editor: this });
61234
61254
  this.on("contentError", this.options.onContentError);
61235
61255
  this.mount(this.options.element);
61236
- if (!this.options.isHeadless) {
61237
- __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
61238
- }
61239
61256
  this.on("create", this.options.onCreate);
61240
61257
  this.on("update", this.options.onUpdate);
61241
61258
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -61257,8 +61274,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61257
61274
  if (!this.options.isHeadless) {
61258
61275
  this.initializeCollaborationData();
61259
61276
  this.initDefaultStyles();
61277
+ __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
61260
61278
  }
61261
- if (!this.options.ydoc || this.options.markdown || this.options.html) {
61279
+ const shouldMigrateListsOnInit = Boolean(
61280
+ this.options.markdown || this.options.html || this.options.loadFromSchema || this.options.jsonOverride || this.options.mode === "html" || this.options.mode === "text"
61281
+ );
61282
+ if (shouldMigrateListsOnInit) {
61262
61283
  this.migrateListsToV2();
61263
61284
  }
61264
61285
  this.setDocumentMode(this.options.documentMode);
@@ -61399,52 +61420,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61399
61420
  if (this.options.isHeadless) {
61400
61421
  return;
61401
61422
  }
61402
- const fontsUsedInDocument = this.converter.getDocumentFonts();
61403
- if (!("queryLocalFonts" in window)) {
61404
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61405
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61406
- this.emit("fonts-resolved", {
61407
- documentFonts: fontsUsedInDocument,
61408
- unsupportedFonts
61409
- });
61410
- return;
61411
- }
61412
- const localFontAccess = await navigator.permissions.query({ name: "local-fonts" });
61413
- if (localFontAccess.state === "denied") {
61414
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61415
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61416
- this.emit("fonts-resolved", {
61417
- documentFonts: fontsUsedInDocument,
61418
- unsupportedFonts
61419
- });
61420
- return;
61421
- }
61422
61423
  try {
61423
- const localFonts = await window.queryLocalFonts();
61424
- const uniqueLocalFonts = [...new Set(localFonts.map((font) => font.family))];
61425
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithLocalFonts_fn).call(this, fontsUsedInDocument, uniqueLocalFonts);
61424
+ const fontsUsedInDocument = this.converter.getDocumentFonts();
61425
+ const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFonts_fn).call(this, fontsUsedInDocument);
61426
61426
  this.emit("fonts-resolved", {
61427
61427
  documentFonts: fontsUsedInDocument,
61428
61428
  unsupportedFonts
61429
61429
  });
61430
61430
  } catch {
61431
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61432
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61433
- this.emit("fonts-resolved", {
61434
- documentFonts: fontsUsedInDocument,
61435
- unsupportedFonts
61436
- });
61431
+ console.warn("[SuperDoc] Could not determine document fonts and unsupported fonts");
61437
61432
  }
61438
61433
  };
61439
- determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
61440
- const unsupportedFonts = fonts.filter((font) => {
61441
- const isLocalFont = localFonts.includes(font);
61442
- const isFontImported = this.fontsImported.includes(font);
61443
- return !isLocalFont && !isFontImported;
61444
- });
61445
- return unsupportedFonts;
61446
- };
61447
- determineUnsupportedFontsWithCanvas_fn = function(fonts) {
61434
+ determineUnsupportedFonts_fn = function(fonts) {
61448
61435
  const unsupportedFonts = fonts.filter((font) => {
61449
61436
  const canRender = canRenderFont(font);
61450
61437
  const isFontImported = this.fontsImported.includes(font);
@@ -61532,6 +61519,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61532
61519
  if (this.options.collaborationIsReady) return;
61533
61520
  console.debug("🔗 [super-editor] Collaboration ready");
61534
61521
  __privateMethod$1(this, _Editor_instances, validateDocumentInit_fn).call(this);
61522
+ if (this.options.ydoc) {
61523
+ this.migrateListsToV2();
61524
+ }
61535
61525
  this.options.onCollaborationReady({ editor, ydoc });
61536
61526
  this.options.collaborationIsReady = true;
61537
61527
  this.options.initialState = this.state;
@@ -63477,10 +63467,27 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63477
63467
  const result = findChildren$5(state2.doc, (node) => node.type.name === "structuredContentBlock");
63478
63468
  return result;
63479
63469
  }
63470
+ function getStructuredContentTablesById(id, state2) {
63471
+ if (!id || !state2) return [];
63472
+ const blocks = getStructuredContentTagsById(id, state2).filter(
63473
+ ({ node }) => node.type.name === "structuredContentBlock"
63474
+ );
63475
+ if (!blocks.length) return [];
63476
+ const { pos: blockPos, node: blockNode } = blocks[0];
63477
+ const tablesInBlock = [];
63478
+ blockNode.descendants((child, relPos) => {
63479
+ if (child.type.name === "table") {
63480
+ const absPos = blockPos + 1 + relPos;
63481
+ tablesInBlock.push({ node: child, pos: absPos });
63482
+ }
63483
+ });
63484
+ return tablesInBlock;
63485
+ }
63480
63486
  const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
63481
63487
  __proto__: null,
63482
63488
  getStructuredContentBlockTags,
63483
63489
  getStructuredContentInlineTags,
63490
+ getStructuredContentTablesById,
63484
63491
  getStructuredContentTags,
63485
63492
  getStructuredContentTagsById
63486
63493
  }, Symbol.toStringTag, { value: "Module" }));
@@ -63677,6 +63684,36 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63677
63684
  tr.replaceWith(posFrom, posTo, content);
63678
63685
  }
63679
63686
  return true;
63687
+ },
63688
+ /**
63689
+ * Append multiple rows to the end of a table inside a structured content block.
63690
+ * Each inner array represents the cell values for one new row.
63691
+ * @category Command
63692
+ * @param {StructuredContentTableAppendRowsOptions} options - Append configuration
63693
+ * @example
63694
+ * editor.commands.appendRowsToStructuredContentTable({
63695
+ * id: 'block-123',
63696
+ * tableIndex: 0,
63697
+ * rows: [['A', 'B'], ['C', 'D']],
63698
+ * copyRowStyle: true,
63699
+ * });
63700
+ */
63701
+ appendRowsToStructuredContentTable: ({ id, tableIndex = 0, rows = [], copyRowStyle = false }) => ({ state: state2, commands: commands2, dispatch }) => {
63702
+ const normalized = normalizeRowsInput(rows);
63703
+ if (!normalized.length) return true;
63704
+ const tables = getStructuredContentTablesById(id, state2);
63705
+ if (!tables.length || tableIndex < 0 || tableIndex >= tables.length) return true;
63706
+ const { node: tableNode, pos: tablePos } = tables[tableIndex];
63707
+ if (dispatch) {
63708
+ return commands2.appendRowsWithContent({ tablePos, tableNode, valueRows: normalized, copyRowStyle });
63709
+ }
63710
+ return commands2.appendRowsWithContent({
63711
+ tablePos,
63712
+ tableNode,
63713
+ valueRows: normalized,
63714
+ copyRowStyle,
63715
+ dispatch: false
63716
+ });
63680
63717
  }
63681
63718
  };
63682
63719
  },
@@ -63686,6 +63723,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
63686
63723
  };
63687
63724
  }
63688
63725
  });
63726
+ const normalizeRowsInput = (rowsOrValues) => {
63727
+ if (!Array.isArray(rowsOrValues) || !rowsOrValues.length) {
63728
+ return [];
63729
+ }
63730
+ if (Array.isArray(rowsOrValues[0])) {
63731
+ return rowsOrValues;
63732
+ }
63733
+ return [rowsOrValues];
63734
+ };
63689
63735
  class DocumentSectionView {
63690
63736
  constructor(node, getPos, decorations, editor) {
63691
63737
  __privateAdd$1(this, _DocumentSectionView_instances);
@@ -69438,6 +69484,107 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69438
69484
  }
69439
69485
  return null;
69440
69486
  }
69487
+ function resolveTable(tr, tablePos, tableNode) {
69488
+ if (tableNode && tableNode.type && tableNode.type.name === "table") {
69489
+ return tableNode;
69490
+ }
69491
+ if (typeof tablePos === "number") {
69492
+ const current = tr.doc.nodeAt(tablePos);
69493
+ if (current && current.type.name === "table") {
69494
+ return current;
69495
+ }
69496
+ }
69497
+ return null;
69498
+ }
69499
+ function pickTemplateRowForAppend(tableNode, schema) {
69500
+ const RowType = schema.nodes.tableRow;
69501
+ const rows = [];
69502
+ tableNode.descendants((child) => {
69503
+ if (child.type === RowType) rows.push(child);
69504
+ });
69505
+ if (!rows.length) return null;
69506
+ for (let i2 = rows.length - 1; i2 >= 0; i2--) {
69507
+ const r2 = rows[i2];
69508
+ const hasBodyCell = r2.content?.content?.some((c2) => c2.type.name === "tableCell");
69509
+ if (hasBodyCell) return r2;
69510
+ }
69511
+ return rows[rows.length - 1];
69512
+ }
69513
+ function extractRowTemplateFormatting(cellNode, schema) {
69514
+ const ParagraphType = schema.nodes.paragraph;
69515
+ let blockType = ParagraphType;
69516
+ let blockAttrs = null;
69517
+ let textMarks = [];
69518
+ const blocks = cellNode?.content?.content || [];
69519
+ for (const block of blocks) {
69520
+ const isParagraphish = block.type === ParagraphType || block.type.name === "heading";
69521
+ if (isParagraphish) {
69522
+ blockType = block.type || ParagraphType;
69523
+ blockAttrs = block.attrs || null;
69524
+ }
69525
+ let foundText = null;
69526
+ block.descendants?.((n) => {
69527
+ if (!foundText && n.isText) foundText = n;
69528
+ });
69529
+ if (foundText) {
69530
+ textMarks = foundText.marks ? Array.from(foundText.marks) : [];
69531
+ break;
69532
+ }
69533
+ }
69534
+ if (!blockType || !blockType.validContent) blockType = ParagraphType;
69535
+ return { blockType, blockAttrs, textMarks };
69536
+ }
69537
+ function buildFormattedCellBlock(schema, value, { blockType, blockAttrs, textMarks }, copyRowStyle = false) {
69538
+ const text = typeof value === "string" ? value : value == null ? "" : String(value);
69539
+ const marks = copyRowStyle ? textMarks || [] : [];
69540
+ const textNode = schema.text(text, marks);
69541
+ const type2 = blockType || schema.nodes.paragraph;
69542
+ return type2.createAndFill(blockAttrs || null, textNode);
69543
+ }
69544
+ function buildRowFromTemplateRow({ schema, tableNode, templateRow, values, copyRowStyle = false }) {
69545
+ const RowType = schema.nodes.tableRow;
69546
+ const CellType = schema.nodes.tableCell;
69547
+ const HeaderType = schema.nodes.tableHeader;
69548
+ const map2 = TableMap.get(tableNode);
69549
+ const totalColumns = map2.width;
69550
+ const byColumns = Array.isArray(values) && values.length === totalColumns;
69551
+ const newCells = [];
69552
+ let columnCursor = 0;
69553
+ templateRow.content.content.forEach((cellNode, cellIndex) => {
69554
+ const isHeaderCell = cellNode.type === HeaderType;
69555
+ const targetCellType = isHeaderCell ? CellType : cellNode.type;
69556
+ const attrs = { ...cellNode.attrs };
69557
+ const formatting = extractRowTemplateFormatting(cellNode, schema);
69558
+ let cellValue = "";
69559
+ if (byColumns) {
69560
+ const span = Math.max(1, attrs.colspan || 1);
69561
+ cellValue = values[columnCursor] ?? "";
69562
+ columnCursor += span;
69563
+ } else {
69564
+ cellValue = Array.isArray(values) ? values[cellIndex] ?? "" : "";
69565
+ }
69566
+ const content = buildFormattedCellBlock(schema, cellValue, formatting, copyRowStyle);
69567
+ const newCell = targetCellType.createAndFill(attrs, content);
69568
+ if (newCell) newCells.push(newCell);
69569
+ });
69570
+ return RowType.createAndFill(null, newCells);
69571
+ }
69572
+ function insertRowsAtTableEnd({ tr, tablePos, tableNode, rows }) {
69573
+ if (!rows || !rows.length) return;
69574
+ const RowTypeName = "tableRow";
69575
+ let lastRowRelPos = 0;
69576
+ let lastRowNode = null;
69577
+ tableNode.descendants((child, relPos) => {
69578
+ if (child.type.name === RowTypeName) {
69579
+ lastRowRelPos = relPos;
69580
+ lastRowNode = child;
69581
+ }
69582
+ });
69583
+ if (!lastRowNode) return;
69584
+ const lastRowAbsEnd = tablePos + 1 + lastRowRelPos + lastRowNode.nodeSize;
69585
+ const frag = Fragment.fromArray(rows);
69586
+ tr.insert(lastRowAbsEnd, frag);
69587
+ }
69441
69588
  const Table = Node$1.create({
69442
69589
  name: "table",
69443
69590
  content: "tableRow+",
@@ -69597,6 +69744,47 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69597
69744
  },
69598
69745
  addCommands() {
69599
69746
  return {
69747
+ /**
69748
+ * Append multiple rows to the end of a table in a single transaction.
69749
+ * @category Command
69750
+ * @param {appendRowsWithContentOptions} options - Append configuration
69751
+ * @example
69752
+ * editor.commands.appendRowsWithContent({ tablePos, valueRows: [['A','B'], ['C','D']], copyRowStyle: true })
69753
+ */
69754
+ appendRowsWithContent: ({ tablePos, tableNode, valueRows = [], copyRowStyle = false }) => ({ editor, chain }) => {
69755
+ if (typeof tablePos !== "number" && !tableNode || !Array.isArray(valueRows) || !valueRows.length) {
69756
+ return false;
69757
+ }
69758
+ return chain().command(({ tr, dispatch }) => {
69759
+ const workingTable = resolveTable(tr, tablePos, tableNode);
69760
+ if (!workingTable) return false;
69761
+ const templateRow = pickTemplateRowForAppend(workingTable, editor.schema);
69762
+ if (!templateRow) return false;
69763
+ const newRows = valueRows.map(
69764
+ (vals) => buildRowFromTemplateRow({
69765
+ schema: editor.schema,
69766
+ tableNode: workingTable,
69767
+ templateRow,
69768
+ values: vals,
69769
+ copyRowStyle
69770
+ })
69771
+ ).filter(Boolean);
69772
+ if (!newRows.length) return false;
69773
+ let resolvedTablePos = tablePos;
69774
+ if (typeof resolvedTablePos !== "number" && workingTable) {
69775
+ const tables = editor.getNodesOfType("table");
69776
+ const match = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
69777
+ resolvedTablePos = match?.pos ?? null;
69778
+ }
69779
+ if (typeof resolvedTablePos !== "number") {
69780
+ return false;
69781
+ }
69782
+ if (dispatch) {
69783
+ insertRowsAtTableEnd({ tr, tablePos, tableNode: workingTable, rows: newRows });
69784
+ }
69785
+ return true;
69786
+ }).run();
69787
+ },
69600
69788
  /**
69601
69789
  * Insert a new table into the document
69602
69790
  * @category Command
@@ -72503,58 +72691,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72503
72691
  }
72504
72692
  });
72505
72693
  };
72506
- const normalizeWrap = (attrs = {}) => {
72507
- const wrap2 = attrs.wrap;
72508
- if (wrap2?.type && wrap2.type !== "Inline") {
72509
- return {
72510
- type: wrap2.type,
72511
- attrs: wrap2.attrs ?? {}
72512
- };
72513
- }
72514
- if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72515
- return {
72516
- type: "Inline",
72517
- attrs: wrap2.attrs
72518
- };
72519
- }
72520
- if (!wrap2 && attrs.wrapText) {
72521
- return {
72522
- type: "Square",
72523
- attrs: {
72524
- wrapText: attrs.wrapText
72525
- }
72526
- };
72527
- }
72528
- if (!wrap2 && attrs.wrapTopAndBottom) {
72529
- return {
72530
- type: "TopAndBottom",
72531
- attrs: {}
72532
- };
72533
- }
72534
- if (wrap2?.type === "Inline") {
72535
- return {
72536
- type: "Inline",
72537
- attrs: wrap2.attrs ?? {}
72538
- };
72539
- }
72540
- return {
72541
- type: "Inline",
72542
- attrs: {}
72543
- };
72544
- };
72545
- const normalizeMarginOffset = (marginOffset = {}) => {
72546
- const { left: left2, horizontal, ...rest } = marginOffset;
72547
- return {
72548
- ...rest,
72549
- horizontal: horizontal ?? left2
72550
- };
72551
- };
72552
- const getNormalizedImageAttrs = (attrs = {}) => {
72553
- return {
72554
- wrap: normalizeWrap(attrs),
72555
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72556
- };
72557
- };
72558
72694
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
72559
72695
  const ImagePositionPlugin = ({ editor }) => {
72560
72696
  const { view } = editor;
@@ -72567,8 +72703,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72567
72703
  return DecorationSet.empty;
72568
72704
  },
72569
72705
  apply(tr, oldDecorationSet, oldState, newState) {
72570
- if (!tr.docChanged) return oldDecorationSet;
72706
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
72571
72707
  const decorations = getImagePositionDecorations(newState, view);
72708
+ shouldUpdate = false;
72572
72709
  return DecorationSet.create(newState.doc, decorations);
72573
72710
  }
72574
72711
  },
@@ -72577,7 +72714,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72577
72714
  update: (view2, lastState) => {
72578
72715
  const pagination = PaginationPluginKey.getState(lastState);
72579
72716
  if (shouldUpdate) {
72580
- shouldUpdate = false;
72581
72717
  const decorations = getImagePositionDecorations(lastState, view2);
72582
72718
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
72583
72719
  view2.dispatch(updateTransaction);
@@ -72603,41 +72739,35 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72603
72739
  let className = "";
72604
72740
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
72605
72741
  const { size: size2, padding } = node.attrs;
72606
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
72607
72742
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
72608
- if (pageBreak) {
72609
- switch (alignH) {
72610
- case "left":
72611
- style2 += "float: left; left: 0; margin-left: 0; ";
72612
- break;
72613
- case "right":
72614
- style2 += "float: right; right: 0; margin-right: 0; ";
72615
- break;
72616
- case "center":
72617
- style2 += "display: block; margin-left: auto; margin-right: auto; ";
72618
- break;
72743
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
72744
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
72745
+ let horizontalAlignment = `${alignH}: 0;`;
72746
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
72747
+ style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
72748
+ const nextPos = view.posAtDOM(pageBreak, 1);
72749
+ if (nextPos < 0) {
72750
+ const $pos = view.state.doc.resolve(pos);
72751
+ decorations.push(
72752
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72753
+ style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72754
+ })
72755
+ );
72619
72756
  }
72620
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
72621
- style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
72622
- if (vRelativeFrom === "margin") {
72623
- const nextPos = view.posAtDOM(pageBreak, 1);
72624
- if (nextPos < 0) {
72625
- const $pos = view.state.doc.resolve(pos);
72626
- decorations.push(
72627
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72628
- style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72629
- })
72630
- );
72631
- }
72632
- const imageBlock = document.createElement("div");
72633
- imageBlock.className = "anchor-image-placeholder";
72634
- imageBlock.style.float = alignH;
72635
- imageBlock.style.width = size2.width + parseInt(padding[alignH]) + "px";
72636
- imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72637
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72757
+ const imageBlock = document.createElement("div");
72758
+ imageBlock.className = "anchor-image-placeholder";
72759
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
72760
+ let paddingHorizontal;
72761
+ if (alignH === "center") {
72762
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
72763
+ } else {
72764
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
72638
72765
  }
72766
+ imageBlock.style.width = size2.width + paddingHorizontal + "px";
72767
+ imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72768
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72769
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72639
72770
  }
72640
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72641
72771
  }
72642
72772
  });
72643
72773
  return decorations;
@@ -72662,6 +72792,58 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72662
72792
  }
72663
72793
  return null;
72664
72794
  };
72795
+ const normalizeWrap = (attrs = {}) => {
72796
+ const wrap2 = attrs.wrap;
72797
+ if (wrap2?.type && wrap2.type !== "Inline") {
72798
+ return {
72799
+ type: wrap2.type,
72800
+ attrs: wrap2.attrs ?? {}
72801
+ };
72802
+ }
72803
+ if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72804
+ return {
72805
+ type: "Inline",
72806
+ attrs: wrap2.attrs
72807
+ };
72808
+ }
72809
+ if (!wrap2 && attrs.wrapText) {
72810
+ return {
72811
+ type: "Square",
72812
+ attrs: {
72813
+ wrapText: attrs.wrapText
72814
+ }
72815
+ };
72816
+ }
72817
+ if (!wrap2 && attrs.wrapTopAndBottom) {
72818
+ return {
72819
+ type: "TopAndBottom",
72820
+ attrs: {}
72821
+ };
72822
+ }
72823
+ if (wrap2?.type === "Inline") {
72824
+ return {
72825
+ type: "Inline",
72826
+ attrs: wrap2.attrs ?? {}
72827
+ };
72828
+ }
72829
+ return {
72830
+ type: "Inline",
72831
+ attrs: {}
72832
+ };
72833
+ };
72834
+ const normalizeMarginOffset = (marginOffset = {}) => {
72835
+ const { left: left2, horizontal, ...rest } = marginOffset;
72836
+ return {
72837
+ ...rest,
72838
+ horizontal: horizontal ?? left2
72839
+ };
72840
+ };
72841
+ const getNormalizedImageAttrs = (attrs = {}) => {
72842
+ return {
72843
+ wrap: normalizeWrap(attrs),
72844
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72845
+ };
72846
+ };
72665
72847
  const getRotationMargins = (w2, h2, angleDegrees) => {
72666
72848
  const rad = angleDegrees * (Math.PI / 180);
72667
72849
  const cos = Math.abs(Math.cos(rad));
@@ -72870,27 +73052,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72870
73052
  style2 += "float: right;";
72871
73053
  floatRight = true;
72872
73054
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
72873
- const pageStyles2 = this.editor?.converter?.pageStyles;
72874
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size2.width) {
72875
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
72876
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
72877
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
72878
- const contentWidth = pageWidth - leftMargin - rightMargin;
72879
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72880
- const leftSpace = marginOffset.horizontal;
72881
- const rightSpace = contentWidth - leftSpace - imageWidth;
72882
- if (rightSpace < 0) {
72883
- style2 += "float: left;";
72884
- } else if (rightSpace > leftSpace) {
72885
- style2 += "float: left;";
72886
- } else {
72887
- style2 += "float: right;";
72888
- floatRight = true;
72889
- baseHorizontal = rightSpace;
72890
- }
72891
- } else {
72892
- style2 += "float: left;";
72893
- }
73055
+ const pageStylesData2 = getDataFromPageStyles({
73056
+ editor: this.editor,
73057
+ marginOffset,
73058
+ size: size2,
73059
+ attrs
73060
+ });
73061
+ style2 += pageStylesData2.style;
73062
+ floatRight = pageStylesData2.floatRight;
73063
+ baseHorizontal = pageStylesData2.baseHorizontal;
72894
73064
  }
72895
73065
  if (attrs.distTop) margin.top += attrs.distTop;
72896
73066
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -72900,27 +73070,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72900
73070
  case "Through":
72901
73071
  case "Tight":
72902
73072
  style2 += "clear: both;";
72903
- const pageStyles = this.editor?.converter?.pageStyles;
72904
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
72905
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
72906
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
72907
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
72908
- const contentWidth = pageWidth - leftMargin - rightMargin;
72909
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72910
- const leftSpace = marginOffset.horizontal;
72911
- const rightSpace = contentWidth - leftSpace - imageWidth;
72912
- if (rightSpace < 0) {
72913
- style2 += "float: left;";
72914
- } else if (rightSpace > leftSpace) {
72915
- style2 += "float: left;";
72916
- } else {
72917
- style2 += "float: right;";
72918
- floatRight = true;
72919
- baseHorizontal = rightSpace;
72920
- }
72921
- } else {
72922
- style2 += "float: left;";
72923
- }
73073
+ const pageStylesData = getDataFromPageStyles({
73074
+ editor: this.editor,
73075
+ marginOffset,
73076
+ size: size2,
73077
+ attrs
73078
+ });
73079
+ style2 += pageStylesData.style;
73080
+ floatRight = pageStylesData.floatRight;
73081
+ baseHorizontal = pageStylesData.baseHorizontal;
72924
73082
  if (attrs.distTop) margin.top += attrs.distTop;
72925
73083
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
72926
73084
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -72957,6 +73115,22 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72957
73115
  }
72958
73116
  const hasAnchorData = Boolean(anchorData);
72959
73117
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
73118
+ if (hasAnchorData) {
73119
+ switch (anchorData.hRelativeFrom) {
73120
+ case "page":
73121
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
73122
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
73123
+ break;
73124
+ case "margin":
73125
+ if (anchorData.alignH === "center") {
73126
+ style2 += "position: absolute; left: 50%; transform: translateX(-50%);";
73127
+ }
73128
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
73129
+ style2 += `position: absolute; ${anchorData.alignH}: 0;`;
73130
+ }
73131
+ break;
73132
+ }
73133
+ }
72960
73134
  if (hasAnchorData || hasMarginOffsets) {
72961
73135
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
72962
73136
  const maxMarginV = 500;
@@ -73105,6 +73279,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
73105
73279
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
73106
73280
  }
73107
73281
  });
73282
+ const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
73283
+ let style2 = "";
73284
+ let floatRight = false;
73285
+ let baseHorizontal = marginOffset?.horizontal || 0;
73286
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
73287
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
73288
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
73289
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
73290
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
73291
+ const contentWidth = pageWidth - leftMargin - rightMargin;
73292
+ const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
73293
+ const leftSpace = marginOffset.horizontal;
73294
+ const rightSpace = contentWidth - leftSpace - imageWidth;
73295
+ if (rightSpace < 0) {
73296
+ style2 += "float: left;";
73297
+ } else if (rightSpace > leftSpace) {
73298
+ style2 += "float: left;";
73299
+ } else {
73300
+ style2 += "float: right;";
73301
+ floatRight = true;
73302
+ baseHorizontal = rightSpace;
73303
+ }
73304
+ } else {
73305
+ style2 += "float: left;";
73306
+ }
73307
+ return {
73308
+ style: style2,
73309
+ floatRight,
73310
+ baseHorizontal
73311
+ };
73312
+ };
73108
73313
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
73109
73314
  const getFileOpener = () => {
73110
73315
  let fileInput = document.createElement("input");
@@ -75074,6 +75279,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75074
75279
  if (!mapping) return null;
75075
75280
  return isOwn ? mapping.own : mapping.other;
75076
75281
  };
75282
+ const normalizeEmail = (value) => {
75283
+ if (typeof value !== "string") return "";
75284
+ return value.trim().toLowerCase();
75285
+ };
75077
75286
  const resolveChanges = (editor) => {
75078
75287
  if (!editor) return { role: "editor", isInternal: false, currentUser: null, resolver: null };
75079
75288
  const role = editor.options?.role ?? "editor";
@@ -75086,10 +75295,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75086
75295
  if (!trackedChanges?.length) return true;
75087
75296
  const { role, isInternal, currentUser, resolver } = resolveChanges(editor);
75088
75297
  if (typeof resolver !== "function") return true;
75089
- const currentEmail = currentUser?.email ?? null;
75298
+ const currentEmail = normalizeEmail(currentUser?.email);
75090
75299
  return trackedChanges.every((change) => {
75091
- const authorEmail = change.attrs?.authorEmail ?? null;
75092
- const isOwn = Boolean(currentEmail && authorEmail && currentEmail === authorEmail);
75300
+ const authorEmail = normalizeEmail(change.attrs?.authorEmail);
75301
+ const isOwn = !currentEmail || !authorEmail || currentEmail === authorEmail;
75093
75302
  const permission = derivePermissionKey({ action, isOwn });
75094
75303
  if (!permission) return true;
75095
75304
  const payload = {
@@ -75226,6 +75435,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75226
75435
  const { from: from2, to } = state2.selection;
75227
75436
  return commands2.acceptTrackedChangesBetween(from2, to);
75228
75437
  },
75438
+ acceptTrackedChangeFromToolbar: () => ({ state: state2, commands: commands2 }) => {
75439
+ const commentsPluginState = CommentsPluginKey.getState(state2);
75440
+ const activeThreadId = commentsPluginState?.activeThreadId;
75441
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
75442
+ return commands2.acceptTrackedChangeById(activeThreadId);
75443
+ } else {
75444
+ return commands2.acceptTrackedChangeBySelection();
75445
+ }
75446
+ },
75229
75447
  acceptTrackedChangeById: (id) => ({ state: state2, tr, commands: commands2 }) => {
75230
75448
  const toResolve = getChangesByIdToResolve(state2, id) || [];
75231
75449
  return toResolve.map(({ from: from2, to }) => {
@@ -75254,6 +75472,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
75254
75472
  const { from: from2, to } = state2.selection;
75255
75473
  return commands2.rejectTrackedChangesBetween(from2, to);
75256
75474
  },
75475
+ rejectTrackedChangeFromToolbar: () => ({ state: state2, commands: commands2 }) => {
75476
+ const commentsPluginState = CommentsPluginKey.getState(state2);
75477
+ const activeThreadId = commentsPluginState?.activeThreadId;
75478
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
75479
+ return commands2.rejectTrackedChangeById(activeThreadId);
75480
+ } else {
75481
+ return commands2.rejectTrackedChangeOnSelection();
75482
+ }
75483
+ },
75257
75484
  rejectAllTrackedChanges: () => ({ state: state2, commands: commands2 }) => {
75258
75485
  const from2 = 0, to = state2.doc.content.size;
75259
75486
  return commands2.rejectTrackedChangesBetween(from2, to);
@@ -80547,7 +80774,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
80547
80774
  return oldState;
80548
80775
  }
80549
80776
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
80550
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
80777
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
80551
80778
  return DecorationSet.empty;
80552
80779
  }
80553
80780
  const { selection } = newState;
@@ -93656,7 +93883,7 @@ ${style2}
93656
93883
  disabled: false,
93657
93884
  name: "acceptTrackedChangeBySelection",
93658
93885
  tooltip: toolbarTexts2.trackChangesAccept,
93659
- command: "acceptTrackedChangeBySelection",
93886
+ command: "acceptTrackedChangeFromToolbar",
93660
93887
  icon: toolbarIcons2.trackChangesAccept,
93661
93888
  group: "left",
93662
93889
  attributes: {
@@ -93668,7 +93895,7 @@ ${style2}
93668
93895
  disabled: false,
93669
93896
  name: "rejectTrackedChangeOnSelection",
93670
93897
  tooltip: toolbarTexts2.trackChangesReject,
93671
- command: "rejectTrackedChangeOnSelection",
93898
+ command: "rejectTrackedChangeFromToolbar",
93672
93899
  icon: toolbarIcons2.trackChangesReject,
93673
93900
  group: "left",
93674
93901
  attributes: {
@@ -96689,8 +96916,12 @@ ${style2}
96689
96916
  Node: Node$1,
96690
96917
  Attribute,
96691
96918
  Extension,
96919
+ Mark,
96920
+ //
96692
96921
  Plugin,
96693
- Mark
96922
+ PluginKey,
96923
+ Decoration,
96924
+ DecorationSet
96694
96925
  };
96695
96926
  const DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
96696
96927
  const PDF = "application/pdf";
@@ -113759,6 +113990,10 @@ ${style2}
113759
113990
  }
113760
113991
  return currentName;
113761
113992
  };
113993
+ const DEFAULT_USER = Object.freeze({
113994
+ name: "Default SuperDoc user",
113995
+ email: null
113996
+ });
113762
113997
  class SuperDoc extends EventEmitter {
113763
113998
  /** @type {Array<string>} */
113764
113999
  static allowedTypes = [DOCX, PDF, HTML];
@@ -113837,6 +114072,18 @@ ${style2}
113837
114072
  ...this.config,
113838
114073
  ...config2
113839
114074
  };
114075
+ const incomingUser = this.config.user;
114076
+ if (!incomingUser || typeof incomingUser !== "object") {
114077
+ this.config.user = { ...DEFAULT_USER };
114078
+ } else {
114079
+ this.config.user = {
114080
+ ...DEFAULT_USER,
114081
+ ...incomingUser
114082
+ };
114083
+ if (!this.config.user.name) {
114084
+ this.config.user.name = DEFAULT_USER.name;
114085
+ }
114086
+ }
113840
114087
  this.config.modules = this.config.modules || {};
113841
114088
  if (!Object.prototype.hasOwnProperty.call(this.config.modules, "comments")) {
113842
114089
  this.config.modules.comments = {};
@@ -113844,7 +114091,7 @@ ${style2}
113844
114091
  this.config.colors = shuffleArray(this.config.colors);
113845
114092
  this.userColorMap = /* @__PURE__ */ new Map();
113846
114093
  this.colorIndex = 0;
113847
- this.version = "0.24.0";
114094
+ this.version = "0.25.0";
113848
114095
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
113849
114096
  this.superdocId = config2.superdocId || v4();
113850
114097
  this.colors = this.config.colors;