@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
@@ -32332,8 +32332,7 @@ const bookmarkEndNodeHandlerEntity = {
32332
32332
  handlerName: "w:bookmarkEndTranslator",
32333
32333
  handler: handleBookmarkEndNode
32334
32334
  };
32335
- const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
32336
- const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
32335
+ const SUPPORTED_ALTERNATE_CONTENT_REQUIRES = /* @__PURE__ */ new Set([
32337
32336
  "wps",
32338
32337
  "wp14",
32339
32338
  "w14",
@@ -32346,22 +32345,85 @@ const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
32346
32345
  "w16sdtfl",
32347
32346
  "w16se"
32348
32347
  ]);
32348
+ const XML_NODE_NAME$1 = "mc:AlternateContent";
32349
+ const SD_NODE_NAME$1 = [];
32350
+ const validXmlAttributes$1 = [];
32351
+ function encode$1(params2) {
32352
+ const { nodeListHandler } = params2;
32353
+ const { node } = params2.extraParams;
32354
+ if (!node || !node.type) {
32355
+ return null;
32356
+ }
32357
+ const { branch, elements } = selectAlternateContentElements(node);
32358
+ if (!elements) {
32359
+ return null;
32360
+ }
32361
+ return nodeListHandler.handler({
32362
+ ...params2,
32363
+ nodes: elements,
32364
+ path: buildPath(params2.path, node, branch)
32365
+ });
32366
+ }
32367
+ function decode$1(params2) {
32368
+ const { node } = params2;
32369
+ const { drawingContent } = node.attrs;
32370
+ const drawing = {
32371
+ name: "w:drawing",
32372
+ elements: [...drawingContent ? [...drawingContent.elements || []] : []]
32373
+ };
32374
+ const choice = {
32375
+ name: "mc:Choice",
32376
+ attributes: { Requires: "wps" },
32377
+ elements: [drawing]
32378
+ };
32379
+ return {
32380
+ name: "mc:AlternateContent",
32381
+ elements: [choice]
32382
+ };
32383
+ }
32384
+ const config$1 = {
32385
+ xmlName: XML_NODE_NAME$1,
32386
+ sdNodeOrKeyName: SD_NODE_NAME$1,
32387
+ type: NodeTranslator.translatorTypes.NODE,
32388
+ encode: encode$1,
32389
+ decode: decode$1,
32390
+ attributes: validXmlAttributes$1
32391
+ };
32392
+ function selectAlternateContentElements(node) {
32393
+ if (!node?.elements?.length) {
32394
+ return { branch: null, elements: null };
32395
+ }
32396
+ const choices = node.elements.filter((el) => el?.name === "mc:Choice");
32397
+ const fallback = node.elements.find((el) => el?.name === "mc:Fallback");
32398
+ const supportedChoice = choices.find((choice) => {
32399
+ const requiresAttr = choice?.attributes?.Requires || choice?.attributes?.requires;
32400
+ if (!requiresAttr) return false;
32401
+ return requiresAttr.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_ALTERNATE_CONTENT_REQUIRES.has(namespace2));
32402
+ });
32403
+ const branch = supportedChoice || fallback || choices[0] || null;
32404
+ const selectedElements = branch?.elements;
32405
+ if (!selectedElements) {
32406
+ return { branch, elements: null };
32407
+ }
32408
+ return {
32409
+ branch,
32410
+ elements: carbonCopy(selectedElements)
32411
+ };
32412
+ }
32413
+ const translator$1 = NodeTranslator.from(config$1);
32414
+ function buildPath(existingPath = [], node, branch) {
32415
+ const path = [...existingPath];
32416
+ if (node) path.push(node);
32417
+ if (branch) path.push(branch);
32418
+ return path;
32419
+ }
32420
+ const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
32349
32421
  const skipHandlerResponse = { nodes: [], consumed: 0 };
32350
32422
  const isAlternateContentNode = (node) => node?.name === ALTERNATE_CONTENT_NODE;
32351
- const isSupportedChoice = (choice) => {
32352
- if (!choice?.attributes) return false;
32353
- const requires = choice.attributes.Requires || choice.attributes.requires;
32354
- if (!requires) return false;
32355
- return requires.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_REQUIRES.has(namespace2));
32356
- };
32357
32423
  const resolveAlternateContentElements = (alternateContent) => {
32358
- if (!alternateContent?.elements?.length) return null;
32359
- const choices = alternateContent.elements.filter((el) => el.name === "mc:Choice");
32360
- const fallback = alternateContent.elements.find((el) => el.name === "mc:Fallback");
32361
- const supportedChoice = choices.find(isSupportedChoice);
32362
- const selectedElements = supportedChoice?.elements || fallback?.elements || choices[0]?.elements;
32363
- if (!selectedElements) return null;
32364
- return carbonCopy(selectedElements);
32424
+ const { elements } = selectAlternateContentElements(alternateContent);
32425
+ if (!elements) return null;
32426
+ return elements;
32365
32427
  };
32366
32428
  const buildNodeWithoutAlternateContent = (node) => {
32367
32429
  const { elements } = node || {};
@@ -32393,16 +32455,20 @@ const handleAlternateChoice = (params2) => {
32393
32455
  }
32394
32456
  const [currentNode] = nodes;
32395
32457
  if (isAlternateContentNode(currentNode)) {
32396
- const resolvedElements = resolveAlternateContentElements(currentNode);
32397
- if (!resolvedElements) {
32398
- return skipHandlerResponse;
32399
- }
32400
- const result2 = nodeListHandler.handler({
32458
+ const nodeForTranslator = currentNode?.type ? currentNode : {
32459
+ ...currentNode,
32460
+ type: "element"
32461
+ };
32462
+ const translated = translator$1.encode({
32401
32463
  ...params2,
32402
- nodes: resolvedElements,
32403
- path: [...params2.path || [], currentNode]
32464
+ nodes: [nodeForTranslator],
32465
+ extraParams: { ...params2.extraParams || {}, node: nodeForTranslator }
32404
32466
  });
32405
- return { nodes: result2, consumed: 1 };
32467
+ if (!translated) {
32468
+ return skipHandlerResponse;
32469
+ }
32470
+ const nodesArray = Array.isArray(translated) ? translated : [translated];
32471
+ return { nodes: nodesArray, consumed: 1 };
32406
32472
  }
32407
32473
  const sanitizedNode = buildNodeWithoutAlternateContent(currentNode);
32408
32474
  if (!sanitizedNode) {
@@ -33700,55 +33766,6 @@ function translateShapeTextbox(params2) {
33700
33766
  };
33701
33767
  return textbox;
33702
33768
  }
33703
- const XML_NODE_NAME$1 = "mc:AlternateContent";
33704
- const SD_NODE_NAME$1 = [];
33705
- const validXmlAttributes$1 = [];
33706
- function encode$1(params2) {
33707
- const { nodeListHandler } = params2;
33708
- const { node } = params2.extraParams;
33709
- if (!node || !node.type) {
33710
- return null;
33711
- }
33712
- const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
33713
- const wpsNode = node.elements.find(
33714
- (el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
33715
- );
33716
- if (!wpsNode) {
33717
- return null;
33718
- }
33719
- const contents = wpsNode.elements;
33720
- return nodeListHandler.handler({
33721
- ...params2,
33722
- nodes: contents,
33723
- path: [...params2.path || [], wpsNode]
33724
- });
33725
- }
33726
- function decode$1(params2) {
33727
- const { node } = params2;
33728
- const { drawingContent } = node.attrs;
33729
- const drawing = {
33730
- name: "w:drawing",
33731
- elements: [...drawingContent ? [...drawingContent.elements || []] : []]
33732
- };
33733
- const choice = {
33734
- name: "mc:Choice",
33735
- attributes: { Requires: "wps" },
33736
- elements: [drawing]
33737
- };
33738
- return {
33739
- name: "mc:AlternateContent",
33740
- elements: [choice]
33741
- };
33742
- }
33743
- const config$1 = {
33744
- xmlName: XML_NODE_NAME$1,
33745
- sdNodeOrKeyName: SD_NODE_NAME$1,
33746
- type: NodeTranslator.translatorTypes.NODE,
33747
- encode: encode$1,
33748
- decode: decode$1,
33749
- attributes: validXmlAttributes$1
33750
- };
33751
- const translator$1 = NodeTranslator.from(config$1);
33752
33769
  function translateContentBlock(params2) {
33753
33770
  const { node } = params2;
33754
33771
  const { vmlAttributes, horizontalRule } = node.attrs;
@@ -35141,7 +35158,7 @@ const _SuperConverter = class _SuperConverter2 {
35141
35158
  static getStoredSuperdocVersion(docx) {
35142
35159
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
35143
35160
  }
35144
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.24.0") {
35161
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.25.0") {
35145
35162
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
35146
35163
  }
35147
35164
  /**
@@ -38352,7 +38369,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
38352
38369
  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);
38353
38370
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
38354
38371
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
38355
- 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;
38372
+ 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;
38356
38373
  var GOOD_LEAF_SIZE = 200;
38357
38374
  var RopeSequence = function RopeSequence2() {
38358
38375
  };
@@ -52567,7 +52584,9 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
52567
52584
  isHeaderFooterChanged: false,
52568
52585
  isCustomXmlChanged: false,
52569
52586
  focusTarget: null,
52570
- permissionResolver: null
52587
+ permissionResolver: null,
52588
+ // header/footer editors may have parent(main) editor set
52589
+ parentEditor: null
52571
52590
  });
52572
52591
  __privateMethod$1(this, _Editor_instances, initContainerElement_fn).call(this, options);
52573
52592
  __privateMethod$1(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -52695,6 +52714,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
52695
52714
  * @param {string} documentMode - The document mode ('editing', 'viewing', 'suggesting')
52696
52715
  */
52697
52716
  setDocumentMode(documentMode) {
52717
+ if (this.options.isHeaderOrFooter || this.options.isChildEditor) return;
52698
52718
  let cleanedMode = documentMode?.toLowerCase() || "editing";
52699
52719
  if (!this.extensionService || !this.state) return;
52700
52720
  const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
@@ -52710,7 +52730,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
52710
52730
  isEditMode: false,
52711
52731
  documentMode: cleanedMode
52712
52732
  });
52713
- if (!this.options.isHeaderOrFooter && pm) pm.classList.add("view-mode");
52733
+ if (pm) pm.classList.add("view-mode");
52714
52734
  } else if (cleanedMode === "suggesting") {
52715
52735
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
52716
52736
  this.commands.disableTrackChangesShowOriginal();
@@ -53329,7 +53349,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
53329
53349
  * @returns {Object | void} Migration results
53330
53350
  */
53331
53351
  processCollaborationMigrations() {
53332
- console.debug("[checkVersionMigrations] Current editor version", "0.24.0");
53352
+ console.debug("[checkVersionMigrations] Current editor version", "0.25.0");
53333
53353
  if (!this.options.ydoc) return;
53334
53354
  const metaMap = this.options.ydoc.getMap("meta");
53335
53355
  let docVersion = metaMap.get("version");
@@ -53535,9 +53555,6 @@ init_fn = function() {
53535
53555
  this.emit("beforeCreate", { editor: this });
53536
53556
  this.on("contentError", this.options.onContentError);
53537
53557
  this.mount(this.options.element);
53538
- if (!this.options.isHeadless) {
53539
- __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
53540
- }
53541
53558
  this.on("create", this.options.onCreate);
53542
53559
  this.on("update", this.options.onUpdate);
53543
53560
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -53559,8 +53576,12 @@ init_fn = function() {
53559
53576
  if (!this.options.isHeadless) {
53560
53577
  this.initializeCollaborationData();
53561
53578
  this.initDefaultStyles();
53579
+ __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
53562
53580
  }
53563
- if (!this.options.ydoc || this.options.markdown || this.options.html) {
53581
+ const shouldMigrateListsOnInit = Boolean(
53582
+ this.options.markdown || this.options.html || this.options.loadFromSchema || this.options.jsonOverride || this.options.mode === "html" || this.options.mode === "text"
53583
+ );
53584
+ if (shouldMigrateListsOnInit) {
53564
53585
  this.migrateListsToV2();
53565
53586
  }
53566
53587
  this.setDocumentMode(this.options.documentMode);
@@ -53701,52 +53722,18 @@ checkFonts_fn = async function() {
53701
53722
  if (this.options.isHeadless) {
53702
53723
  return;
53703
53724
  }
53704
- const fontsUsedInDocument = this.converter.getDocumentFonts();
53705
- if (!("queryLocalFonts" in window)) {
53706
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53707
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53708
- this.emit("fonts-resolved", {
53709
- documentFonts: fontsUsedInDocument,
53710
- unsupportedFonts
53711
- });
53712
- return;
53713
- }
53714
- const localFontAccess = await navigator.permissions.query({ name: "local-fonts" });
53715
- if (localFontAccess.state === "denied") {
53716
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53717
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53718
- this.emit("fonts-resolved", {
53719
- documentFonts: fontsUsedInDocument,
53720
- unsupportedFonts
53721
- });
53722
- return;
53723
- }
53724
53725
  try {
53725
- const localFonts = await window.queryLocalFonts();
53726
- const uniqueLocalFonts = [...new Set(localFonts.map((font) => font.family))];
53727
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithLocalFonts_fn).call(this, fontsUsedInDocument, uniqueLocalFonts);
53726
+ const fontsUsedInDocument = this.converter.getDocumentFonts();
53727
+ const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFonts_fn).call(this, fontsUsedInDocument);
53728
53728
  this.emit("fonts-resolved", {
53729
53729
  documentFonts: fontsUsedInDocument,
53730
53730
  unsupportedFonts
53731
53731
  });
53732
53732
  } catch {
53733
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53734
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53735
- this.emit("fonts-resolved", {
53736
- documentFonts: fontsUsedInDocument,
53737
- unsupportedFonts
53738
- });
53733
+ console.warn("[SuperDoc] Could not determine document fonts and unsupported fonts");
53739
53734
  }
53740
53735
  };
53741
- determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
53742
- const unsupportedFonts = fonts.filter((font) => {
53743
- const isLocalFont = localFonts.includes(font);
53744
- const isFontImported = this.fontsImported.includes(font);
53745
- return !isLocalFont && !isFontImported;
53746
- });
53747
- return unsupportedFonts;
53748
- };
53749
- determineUnsupportedFontsWithCanvas_fn = function(fonts) {
53736
+ determineUnsupportedFonts_fn = function(fonts) {
53750
53737
  const unsupportedFonts = fonts.filter((font) => {
53751
53738
  const canRender = canRenderFont(font);
53752
53739
  const isFontImported = this.fontsImported.includes(font);
@@ -53834,6 +53821,9 @@ onCollaborationReady_fn = function({ editor, ydoc }) {
53834
53821
  if (this.options.collaborationIsReady) return;
53835
53822
  console.debug("🔗 [super-editor] Collaboration ready");
53836
53823
  __privateMethod$1(this, _Editor_instances, validateDocumentInit_fn).call(this);
53824
+ if (this.options.ydoc) {
53825
+ this.migrateListsToV2();
53826
+ }
53837
53827
  this.options.onCollaborationReady({ editor, ydoc });
53838
53828
  this.options.collaborationIsReady = true;
53839
53829
  this.options.initialState = this.state;
@@ -55779,10 +55769,27 @@ function getStructuredContentBlockTags(state2) {
55779
55769
  const result = findChildren$5(state2.doc, (node) => node.type.name === "structuredContentBlock");
55780
55770
  return result;
55781
55771
  }
55772
+ function getStructuredContentTablesById(id, state2) {
55773
+ if (!id || !state2) return [];
55774
+ const blocks = getStructuredContentTagsById(id, state2).filter(
55775
+ ({ node }) => node.type.name === "structuredContentBlock"
55776
+ );
55777
+ if (!blocks.length) return [];
55778
+ const { pos: blockPos, node: blockNode } = blocks[0];
55779
+ const tablesInBlock = [];
55780
+ blockNode.descendants((child, relPos) => {
55781
+ if (child.type.name === "table") {
55782
+ const absPos = blockPos + 1 + relPos;
55783
+ tablesInBlock.push({ node: child, pos: absPos });
55784
+ }
55785
+ });
55786
+ return tablesInBlock;
55787
+ }
55782
55788
  const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
55783
55789
  __proto__: null,
55784
55790
  getStructuredContentBlockTags,
55785
55791
  getStructuredContentInlineTags,
55792
+ getStructuredContentTablesById,
55786
55793
  getStructuredContentTags,
55787
55794
  getStructuredContentTagsById
55788
55795
  }, Symbol.toStringTag, { value: "Module" }));
@@ -55979,6 +55986,36 @@ const StructuredContentCommands = Extension.create({
55979
55986
  tr.replaceWith(posFrom, posTo, content);
55980
55987
  }
55981
55988
  return true;
55989
+ },
55990
+ /**
55991
+ * Append multiple rows to the end of a table inside a structured content block.
55992
+ * Each inner array represents the cell values for one new row.
55993
+ * @category Command
55994
+ * @param {StructuredContentTableAppendRowsOptions} options - Append configuration
55995
+ * @example
55996
+ * editor.commands.appendRowsToStructuredContentTable({
55997
+ * id: 'block-123',
55998
+ * tableIndex: 0,
55999
+ * rows: [['A', 'B'], ['C', 'D']],
56000
+ * copyRowStyle: true,
56001
+ * });
56002
+ */
56003
+ appendRowsToStructuredContentTable: ({ id, tableIndex = 0, rows = [], copyRowStyle = false }) => ({ state: state2, commands: commands2, dispatch }) => {
56004
+ const normalized = normalizeRowsInput(rows);
56005
+ if (!normalized.length) return true;
56006
+ const tables = getStructuredContentTablesById(id, state2);
56007
+ if (!tables.length || tableIndex < 0 || tableIndex >= tables.length) return true;
56008
+ const { node: tableNode, pos: tablePos } = tables[tableIndex];
56009
+ if (dispatch) {
56010
+ return commands2.appendRowsWithContent({ tablePos, tableNode, valueRows: normalized, copyRowStyle });
56011
+ }
56012
+ return commands2.appendRowsWithContent({
56013
+ tablePos,
56014
+ tableNode,
56015
+ valueRows: normalized,
56016
+ copyRowStyle,
56017
+ dispatch: false
56018
+ });
55982
56019
  }
55983
56020
  };
55984
56021
  },
@@ -55988,6 +56025,15 @@ const StructuredContentCommands = Extension.create({
55988
56025
  };
55989
56026
  }
55990
56027
  });
56028
+ const normalizeRowsInput = (rowsOrValues) => {
56029
+ if (!Array.isArray(rowsOrValues) || !rowsOrValues.length) {
56030
+ return [];
56031
+ }
56032
+ if (Array.isArray(rowsOrValues[0])) {
56033
+ return rowsOrValues;
56034
+ }
56035
+ return [rowsOrValues];
56036
+ };
55991
56037
  class DocumentSectionView {
55992
56038
  constructor(node, getPos, decorations, editor) {
55993
56039
  __privateAdd$1(this, _DocumentSectionView_instances);
@@ -61740,6 +61786,107 @@ function cellWrapping($pos) {
61740
61786
  }
61741
61787
  return null;
61742
61788
  }
61789
+ function resolveTable(tr, tablePos, tableNode) {
61790
+ if (tableNode && tableNode.type && tableNode.type.name === "table") {
61791
+ return tableNode;
61792
+ }
61793
+ if (typeof tablePos === "number") {
61794
+ const current = tr.doc.nodeAt(tablePos);
61795
+ if (current && current.type.name === "table") {
61796
+ return current;
61797
+ }
61798
+ }
61799
+ return null;
61800
+ }
61801
+ function pickTemplateRowForAppend(tableNode, schema) {
61802
+ const RowType = schema.nodes.tableRow;
61803
+ const rows = [];
61804
+ tableNode.descendants((child) => {
61805
+ if (child.type === RowType) rows.push(child);
61806
+ });
61807
+ if (!rows.length) return null;
61808
+ for (let i = rows.length - 1; i >= 0; i--) {
61809
+ const r2 = rows[i];
61810
+ const hasBodyCell = r2.content?.content?.some((c2) => c2.type.name === "tableCell");
61811
+ if (hasBodyCell) return r2;
61812
+ }
61813
+ return rows[rows.length - 1];
61814
+ }
61815
+ function extractRowTemplateFormatting(cellNode, schema) {
61816
+ const ParagraphType = schema.nodes.paragraph;
61817
+ let blockType = ParagraphType;
61818
+ let blockAttrs = null;
61819
+ let textMarks = [];
61820
+ const blocks = cellNode?.content?.content || [];
61821
+ for (const block of blocks) {
61822
+ const isParagraphish = block.type === ParagraphType || block.type.name === "heading";
61823
+ if (isParagraphish) {
61824
+ blockType = block.type || ParagraphType;
61825
+ blockAttrs = block.attrs || null;
61826
+ }
61827
+ let foundText = null;
61828
+ block.descendants?.((n) => {
61829
+ if (!foundText && n.isText) foundText = n;
61830
+ });
61831
+ if (foundText) {
61832
+ textMarks = foundText.marks ? Array.from(foundText.marks) : [];
61833
+ break;
61834
+ }
61835
+ }
61836
+ if (!blockType || !blockType.validContent) blockType = ParagraphType;
61837
+ return { blockType, blockAttrs, textMarks };
61838
+ }
61839
+ function buildFormattedCellBlock(schema, value, { blockType, blockAttrs, textMarks }, copyRowStyle = false) {
61840
+ const text = typeof value === "string" ? value : value == null ? "" : String(value);
61841
+ const marks = copyRowStyle ? textMarks || [] : [];
61842
+ const textNode = schema.text(text, marks);
61843
+ const type2 = blockType || schema.nodes.paragraph;
61844
+ return type2.createAndFill(blockAttrs || null, textNode);
61845
+ }
61846
+ function buildRowFromTemplateRow({ schema, tableNode, templateRow, values, copyRowStyle = false }) {
61847
+ const RowType = schema.nodes.tableRow;
61848
+ const CellType = schema.nodes.tableCell;
61849
+ const HeaderType = schema.nodes.tableHeader;
61850
+ const map22 = TableMap.get(tableNode);
61851
+ const totalColumns = map22.width;
61852
+ const byColumns = Array.isArray(values) && values.length === totalColumns;
61853
+ const newCells = [];
61854
+ let columnCursor = 0;
61855
+ templateRow.content.content.forEach((cellNode, cellIndex) => {
61856
+ const isHeaderCell = cellNode.type === HeaderType;
61857
+ const targetCellType = isHeaderCell ? CellType : cellNode.type;
61858
+ const attrs = { ...cellNode.attrs };
61859
+ const formatting = extractRowTemplateFormatting(cellNode, schema);
61860
+ let cellValue = "";
61861
+ if (byColumns) {
61862
+ const span = Math.max(1, attrs.colspan || 1);
61863
+ cellValue = values[columnCursor] ?? "";
61864
+ columnCursor += span;
61865
+ } else {
61866
+ cellValue = Array.isArray(values) ? values[cellIndex] ?? "" : "";
61867
+ }
61868
+ const content = buildFormattedCellBlock(schema, cellValue, formatting, copyRowStyle);
61869
+ const newCell = targetCellType.createAndFill(attrs, content);
61870
+ if (newCell) newCells.push(newCell);
61871
+ });
61872
+ return RowType.createAndFill(null, newCells);
61873
+ }
61874
+ function insertRowsAtTableEnd({ tr, tablePos, tableNode, rows }) {
61875
+ if (!rows || !rows.length) return;
61876
+ const RowTypeName = "tableRow";
61877
+ let lastRowRelPos = 0;
61878
+ let lastRowNode = null;
61879
+ tableNode.descendants((child, relPos) => {
61880
+ if (child.type.name === RowTypeName) {
61881
+ lastRowRelPos = relPos;
61882
+ lastRowNode = child;
61883
+ }
61884
+ });
61885
+ if (!lastRowNode) return;
61886
+ const lastRowAbsEnd = tablePos + 1 + lastRowRelPos + lastRowNode.nodeSize;
61887
+ const frag = Fragment.fromArray(rows);
61888
+ tr.insert(lastRowAbsEnd, frag);
61889
+ }
61743
61890
  const Table = Node$1.create({
61744
61891
  name: "table",
61745
61892
  content: "tableRow+",
@@ -61899,6 +62046,47 @@ const Table = Node$1.create({
61899
62046
  },
61900
62047
  addCommands() {
61901
62048
  return {
62049
+ /**
62050
+ * Append multiple rows to the end of a table in a single transaction.
62051
+ * @category Command
62052
+ * @param {appendRowsWithContentOptions} options - Append configuration
62053
+ * @example
62054
+ * editor.commands.appendRowsWithContent({ tablePos, valueRows: [['A','B'], ['C','D']], copyRowStyle: true })
62055
+ */
62056
+ appendRowsWithContent: ({ tablePos, tableNode, valueRows = [], copyRowStyle = false }) => ({ editor, chain }) => {
62057
+ if (typeof tablePos !== "number" && !tableNode || !Array.isArray(valueRows) || !valueRows.length) {
62058
+ return false;
62059
+ }
62060
+ return chain().command(({ tr, dispatch }) => {
62061
+ const workingTable = resolveTable(tr, tablePos, tableNode);
62062
+ if (!workingTable) return false;
62063
+ const templateRow = pickTemplateRowForAppend(workingTable, editor.schema);
62064
+ if (!templateRow) return false;
62065
+ const newRows = valueRows.map(
62066
+ (vals) => buildRowFromTemplateRow({
62067
+ schema: editor.schema,
62068
+ tableNode: workingTable,
62069
+ templateRow,
62070
+ values: vals,
62071
+ copyRowStyle
62072
+ })
62073
+ ).filter(Boolean);
62074
+ if (!newRows.length) return false;
62075
+ let resolvedTablePos = tablePos;
62076
+ if (typeof resolvedTablePos !== "number" && workingTable) {
62077
+ const tables = editor.getNodesOfType("table");
62078
+ const match = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
62079
+ resolvedTablePos = match?.pos ?? null;
62080
+ }
62081
+ if (typeof resolvedTablePos !== "number") {
62082
+ return false;
62083
+ }
62084
+ if (dispatch) {
62085
+ insertRowsAtTableEnd({ tr, tablePos, tableNode: workingTable, rows: newRows });
62086
+ }
62087
+ return true;
62088
+ }).run();
62089
+ },
61902
62090
  /**
61903
62091
  * Insert a new table into the document
61904
62092
  * @category Command
@@ -64805,58 +64993,6 @@ const registerImages = async (foundImages, editor, view) => {
64805
64993
  }
64806
64994
  });
64807
64995
  };
64808
- const normalizeWrap = (attrs = {}) => {
64809
- const wrap2 = attrs.wrap;
64810
- if (wrap2?.type && wrap2.type !== "Inline") {
64811
- return {
64812
- type: wrap2.type,
64813
- attrs: wrap2.attrs ?? {}
64814
- };
64815
- }
64816
- if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
64817
- return {
64818
- type: "Inline",
64819
- attrs: wrap2.attrs
64820
- };
64821
- }
64822
- if (!wrap2 && attrs.wrapText) {
64823
- return {
64824
- type: "Square",
64825
- attrs: {
64826
- wrapText: attrs.wrapText
64827
- }
64828
- };
64829
- }
64830
- if (!wrap2 && attrs.wrapTopAndBottom) {
64831
- return {
64832
- type: "TopAndBottom",
64833
- attrs: {}
64834
- };
64835
- }
64836
- if (wrap2?.type === "Inline") {
64837
- return {
64838
- type: "Inline",
64839
- attrs: wrap2.attrs ?? {}
64840
- };
64841
- }
64842
- return {
64843
- type: "Inline",
64844
- attrs: {}
64845
- };
64846
- };
64847
- const normalizeMarginOffset = (marginOffset = {}) => {
64848
- const { left: left2, horizontal, ...rest } = marginOffset;
64849
- return {
64850
- ...rest,
64851
- horizontal: horizontal ?? left2
64852
- };
64853
- };
64854
- const getNormalizedImageAttrs = (attrs = {}) => {
64855
- return {
64856
- wrap: normalizeWrap(attrs),
64857
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
64858
- };
64859
- };
64860
64996
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
64861
64997
  const ImagePositionPlugin = ({ editor }) => {
64862
64998
  const { view } = editor;
@@ -64869,8 +65005,9 @@ const ImagePositionPlugin = ({ editor }) => {
64869
65005
  return DecorationSet.empty;
64870
65006
  },
64871
65007
  apply(tr, oldDecorationSet, oldState, newState) {
64872
- if (!tr.docChanged) return oldDecorationSet;
65008
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
64873
65009
  const decorations = getImagePositionDecorations(newState, view);
65010
+ shouldUpdate = false;
64874
65011
  return DecorationSet.create(newState.doc, decorations);
64875
65012
  }
64876
65013
  },
@@ -64879,7 +65016,6 @@ const ImagePositionPlugin = ({ editor }) => {
64879
65016
  update: (view2, lastState) => {
64880
65017
  const pagination = PaginationPluginKey.getState(lastState);
64881
65018
  if (shouldUpdate) {
64882
- shouldUpdate = false;
64883
65019
  const decorations = getImagePositionDecorations(lastState, view2);
64884
65020
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
64885
65021
  view2.dispatch(updateTransaction);
@@ -64905,41 +65041,35 @@ const getImagePositionDecorations = (state2, view) => {
64905
65041
  let className = "";
64906
65042
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
64907
65043
  const { size: size2, padding } = node.attrs;
64908
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
64909
65044
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
64910
- if (pageBreak) {
64911
- switch (alignH) {
64912
- case "left":
64913
- style2 += "float: left; left: 0; margin-left: 0; ";
64914
- break;
64915
- case "right":
64916
- style2 += "float: right; right: 0; margin-right: 0; ";
64917
- break;
64918
- case "center":
64919
- style2 += "display: block; margin-left: auto; margin-right: auto; ";
64920
- break;
65045
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
65046
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
65047
+ let horizontalAlignment = `${alignH}: 0;`;
65048
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
65049
+ style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
65050
+ const nextPos = view.posAtDOM(pageBreak, 1);
65051
+ if (nextPos < 0) {
65052
+ const $pos = view.state.doc.resolve(pos);
65053
+ decorations.push(
65054
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
65055
+ style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
65056
+ })
65057
+ );
64921
65058
  }
64922
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
64923
- style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
64924
- if (vRelativeFrom === "margin") {
64925
- const nextPos = view.posAtDOM(pageBreak, 1);
64926
- if (nextPos < 0) {
64927
- const $pos = view.state.doc.resolve(pos);
64928
- decorations.push(
64929
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
64930
- style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
64931
- })
64932
- );
64933
- }
64934
- const imageBlock = document.createElement("div");
64935
- imageBlock.className = "anchor-image-placeholder";
64936
- imageBlock.style.float = alignH;
64937
- imageBlock.style.width = size2.width + parseInt(padding[alignH]) + "px";
64938
- imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
64939
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
65059
+ const imageBlock = document.createElement("div");
65060
+ imageBlock.className = "anchor-image-placeholder";
65061
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
65062
+ let paddingHorizontal;
65063
+ if (alignH === "center") {
65064
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
65065
+ } else {
65066
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
64940
65067
  }
65068
+ imageBlock.style.width = size2.width + paddingHorizontal + "px";
65069
+ imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
65070
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
65071
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
64941
65072
  }
64942
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
64943
65073
  }
64944
65074
  });
64945
65075
  return decorations;
@@ -64964,6 +65094,58 @@ const findPreviousDomNodeWithClass = (view, pos, className) => {
64964
65094
  }
64965
65095
  return null;
64966
65096
  };
65097
+ const normalizeWrap = (attrs = {}) => {
65098
+ const wrap2 = attrs.wrap;
65099
+ if (wrap2?.type && wrap2.type !== "Inline") {
65100
+ return {
65101
+ type: wrap2.type,
65102
+ attrs: wrap2.attrs ?? {}
65103
+ };
65104
+ }
65105
+ if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
65106
+ return {
65107
+ type: "Inline",
65108
+ attrs: wrap2.attrs
65109
+ };
65110
+ }
65111
+ if (!wrap2 && attrs.wrapText) {
65112
+ return {
65113
+ type: "Square",
65114
+ attrs: {
65115
+ wrapText: attrs.wrapText
65116
+ }
65117
+ };
65118
+ }
65119
+ if (!wrap2 && attrs.wrapTopAndBottom) {
65120
+ return {
65121
+ type: "TopAndBottom",
65122
+ attrs: {}
65123
+ };
65124
+ }
65125
+ if (wrap2?.type === "Inline") {
65126
+ return {
65127
+ type: "Inline",
65128
+ attrs: wrap2.attrs ?? {}
65129
+ };
65130
+ }
65131
+ return {
65132
+ type: "Inline",
65133
+ attrs: {}
65134
+ };
65135
+ };
65136
+ const normalizeMarginOffset = (marginOffset = {}) => {
65137
+ const { left: left2, horizontal, ...rest } = marginOffset;
65138
+ return {
65139
+ ...rest,
65140
+ horizontal: horizontal ?? left2
65141
+ };
65142
+ };
65143
+ const getNormalizedImageAttrs = (attrs = {}) => {
65144
+ return {
65145
+ wrap: normalizeWrap(attrs),
65146
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
65147
+ };
65148
+ };
64967
65149
  const getRotationMargins = (w2, h2, angleDegrees) => {
64968
65150
  const rad = angleDegrees * (Math.PI / 180);
64969
65151
  const cos = Math.abs(Math.cos(rad));
@@ -65172,27 +65354,15 @@ const Image = Node$1.create({
65172
65354
  style2 += "float: right;";
65173
65355
  floatRight = true;
65174
65356
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
65175
- const pageStyles2 = this.editor?.converter?.pageStyles;
65176
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size2.width) {
65177
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
65178
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
65179
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
65180
- const contentWidth = pageWidth - leftMargin - rightMargin;
65181
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65182
- const leftSpace = marginOffset.horizontal;
65183
- const rightSpace = contentWidth - leftSpace - imageWidth;
65184
- if (rightSpace < 0) {
65185
- style2 += "float: left;";
65186
- } else if (rightSpace > leftSpace) {
65187
- style2 += "float: left;";
65188
- } else {
65189
- style2 += "float: right;";
65190
- floatRight = true;
65191
- baseHorizontal = rightSpace;
65192
- }
65193
- } else {
65194
- style2 += "float: left;";
65195
- }
65357
+ const pageStylesData2 = getDataFromPageStyles({
65358
+ editor: this.editor,
65359
+ marginOffset,
65360
+ size: size2,
65361
+ attrs
65362
+ });
65363
+ style2 += pageStylesData2.style;
65364
+ floatRight = pageStylesData2.floatRight;
65365
+ baseHorizontal = pageStylesData2.baseHorizontal;
65196
65366
  }
65197
65367
  if (attrs.distTop) margin.top += attrs.distTop;
65198
65368
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -65202,27 +65372,15 @@ const Image = Node$1.create({
65202
65372
  case "Through":
65203
65373
  case "Tight":
65204
65374
  style2 += "clear: both;";
65205
- const pageStyles = this.editor?.converter?.pageStyles;
65206
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
65207
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
65208
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
65209
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
65210
- const contentWidth = pageWidth - leftMargin - rightMargin;
65211
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65212
- const leftSpace = marginOffset.horizontal;
65213
- const rightSpace = contentWidth - leftSpace - imageWidth;
65214
- if (rightSpace < 0) {
65215
- style2 += "float: left;";
65216
- } else if (rightSpace > leftSpace) {
65217
- style2 += "float: left;";
65218
- } else {
65219
- style2 += "float: right;";
65220
- floatRight = true;
65221
- baseHorizontal = rightSpace;
65222
- }
65223
- } else {
65224
- style2 += "float: left;";
65225
- }
65375
+ const pageStylesData = getDataFromPageStyles({
65376
+ editor: this.editor,
65377
+ marginOffset,
65378
+ size: size2,
65379
+ attrs
65380
+ });
65381
+ style2 += pageStylesData.style;
65382
+ floatRight = pageStylesData.floatRight;
65383
+ baseHorizontal = pageStylesData.baseHorizontal;
65226
65384
  if (attrs.distTop) margin.top += attrs.distTop;
65227
65385
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
65228
65386
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -65259,6 +65417,22 @@ const Image = Node$1.create({
65259
65417
  }
65260
65418
  const hasAnchorData = Boolean(anchorData);
65261
65419
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
65420
+ if (hasAnchorData) {
65421
+ switch (anchorData.hRelativeFrom) {
65422
+ case "page":
65423
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
65424
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
65425
+ break;
65426
+ case "margin":
65427
+ if (anchorData.alignH === "center") {
65428
+ style2 += "position: absolute; left: 50%; transform: translateX(-50%);";
65429
+ }
65430
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
65431
+ style2 += `position: absolute; ${anchorData.alignH}: 0;`;
65432
+ }
65433
+ break;
65434
+ }
65435
+ }
65262
65436
  if (hasAnchorData || hasMarginOffsets) {
65263
65437
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
65264
65438
  const maxMarginV = 500;
@@ -65407,6 +65581,37 @@ const Image = Node$1.create({
65407
65581
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
65408
65582
  }
65409
65583
  });
65584
+ const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
65585
+ let style2 = "";
65586
+ let floatRight = false;
65587
+ let baseHorizontal = marginOffset?.horizontal || 0;
65588
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
65589
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
65590
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
65591
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
65592
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
65593
+ const contentWidth = pageWidth - leftMargin - rightMargin;
65594
+ const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65595
+ const leftSpace = marginOffset.horizontal;
65596
+ const rightSpace = contentWidth - leftSpace - imageWidth;
65597
+ if (rightSpace < 0) {
65598
+ style2 += "float: left;";
65599
+ } else if (rightSpace > leftSpace) {
65600
+ style2 += "float: left;";
65601
+ } else {
65602
+ style2 += "float: right;";
65603
+ floatRight = true;
65604
+ baseHorizontal = rightSpace;
65605
+ }
65606
+ } else {
65607
+ style2 += "float: left;";
65608
+ }
65609
+ return {
65610
+ style: style2,
65611
+ floatRight,
65612
+ baseHorizontal
65613
+ };
65614
+ };
65410
65615
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
65411
65616
  const getFileOpener = () => {
65412
65617
  let fileInput = document.createElement("input");
@@ -67376,6 +67581,10 @@ const derivePermissionKey = ({ action, isOwn }) => {
67376
67581
  if (!mapping) return null;
67377
67582
  return isOwn ? mapping.own : mapping.other;
67378
67583
  };
67584
+ const normalizeEmail = (value) => {
67585
+ if (typeof value !== "string") return "";
67586
+ return value.trim().toLowerCase();
67587
+ };
67379
67588
  const resolveChanges = (editor) => {
67380
67589
  if (!editor) return { role: "editor", isInternal: false, currentUser: null, resolver: null };
67381
67590
  const role = editor.options?.role ?? "editor";
@@ -67388,10 +67597,10 @@ const isTrackedChangeActionAllowed = ({ editor, action, trackedChanges }) => {
67388
67597
  if (!trackedChanges?.length) return true;
67389
67598
  const { role, isInternal, currentUser, resolver } = resolveChanges(editor);
67390
67599
  if (typeof resolver !== "function") return true;
67391
- const currentEmail = currentUser?.email ?? null;
67600
+ const currentEmail = normalizeEmail(currentUser?.email);
67392
67601
  return trackedChanges.every((change) => {
67393
- const authorEmail = change.attrs?.authorEmail ?? null;
67394
- const isOwn = Boolean(currentEmail && authorEmail && currentEmail === authorEmail);
67602
+ const authorEmail = normalizeEmail(change.attrs?.authorEmail);
67603
+ const isOwn = !currentEmail || !authorEmail || currentEmail === authorEmail;
67395
67604
  const permission = derivePermissionKey({ action, isOwn });
67396
67605
  if (!permission) return true;
67397
67606
  const payload = {
@@ -67528,6 +67737,15 @@ const TrackChanges = Extension.create({
67528
67737
  const { from: from2, to } = state2.selection;
67529
67738
  return commands2.acceptTrackedChangesBetween(from2, to);
67530
67739
  },
67740
+ acceptTrackedChangeFromToolbar: () => ({ state: state2, commands: commands2 }) => {
67741
+ const commentsPluginState = CommentsPluginKey.getState(state2);
67742
+ const activeThreadId = commentsPluginState?.activeThreadId;
67743
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
67744
+ return commands2.acceptTrackedChangeById(activeThreadId);
67745
+ } else {
67746
+ return commands2.acceptTrackedChangeBySelection();
67747
+ }
67748
+ },
67531
67749
  acceptTrackedChangeById: (id) => ({ state: state2, tr, commands: commands2 }) => {
67532
67750
  const toResolve = getChangesByIdToResolve(state2, id) || [];
67533
67751
  return toResolve.map(({ from: from2, to }) => {
@@ -67556,6 +67774,15 @@ const TrackChanges = Extension.create({
67556
67774
  const { from: from2, to } = state2.selection;
67557
67775
  return commands2.rejectTrackedChangesBetween(from2, to);
67558
67776
  },
67777
+ rejectTrackedChangeFromToolbar: () => ({ state: state2, commands: commands2 }) => {
67778
+ const commentsPluginState = CommentsPluginKey.getState(state2);
67779
+ const activeThreadId = commentsPluginState?.activeThreadId;
67780
+ if (activeThreadId && commentsPluginState?.trackedChanges?.[activeThreadId]) {
67781
+ return commands2.rejectTrackedChangeById(activeThreadId);
67782
+ } else {
67783
+ return commands2.rejectTrackedChangeOnSelection();
67784
+ }
67785
+ },
67559
67786
  rejectAllTrackedChanges: () => ({ state: state2, commands: commands2 }) => {
67560
67787
  const from2 = 0, to = state2.doc.content.size;
67561
67788
  return commands2.rejectTrackedChangesBetween(from2, to);
@@ -72849,7 +73076,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
72849
73076
  return oldState;
72850
73077
  }
72851
73078
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
72852
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
73079
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
72853
73080
  return DecorationSet.empty;
72854
73081
  }
72855
73082
  const { selection } = newState;
@@ -85958,7 +86185,7 @@ const makeDefaultItems = ({
85958
86185
  disabled: false,
85959
86186
  name: "acceptTrackedChangeBySelection",
85960
86187
  tooltip: toolbarTexts2.trackChangesAccept,
85961
- command: "acceptTrackedChangeBySelection",
86188
+ command: "acceptTrackedChangeFromToolbar",
85962
86189
  icon: toolbarIcons2.trackChangesAccept,
85963
86190
  group: "left",
85964
86191
  attributes: {
@@ -85970,7 +86197,7 @@ const makeDefaultItems = ({
85970
86197
  disabled: false,
85971
86198
  name: "rejectTrackedChangeOnSelection",
85972
86199
  tooltip: toolbarTexts2.trackChangesReject,
85973
- command: "rejectTrackedChangeOnSelection",
86200
+ command: "rejectTrackedChangeFromToolbar",
85974
86201
  icon: toolbarIcons2.trackChangesReject,
85975
86202
  group: "left",
85976
86203
  attributes: {
@@ -88991,8 +89218,12 @@ const Extensions = {
88991
89218
  Node: Node$1,
88992
89219
  Attribute: Attribute2,
88993
89220
  Extension,
89221
+ Mark: Mark2,
89222
+ //
88994
89223
  Plugin,
88995
- Mark: Mark2
89224
+ PluginKey,
89225
+ Decoration,
89226
+ DecorationSet
88996
89227
  };
88997
89228
  exports.AIWriter = AIWriter;
88998
89229
  exports.AnnotatorHelpers = AnnotatorHelpers;