superdoc 1.0.0-beta.17 → 1.0.0-beta.18

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 (31) hide show
  1. package/dist/chunks/{PdfViewer-cvzMUtBh.es.js → PdfViewer-CDEQktlZ.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-BIlJaTm7.cjs → PdfViewer-CZgU5VTe.cjs} +1 -1
  3. package/dist/chunks/{index-DDx90Dl3.cjs → index-CBFc2Hsa.cjs} +8 -4
  4. package/dist/chunks/{index-VCeRjVPO-FBgR9qxX.es.js → index-DpnfmQSg--uFI4inB.es.js} +1 -1
  5. package/dist/chunks/{index-VCeRjVPO-DjkejB6t.cjs → index-DpnfmQSg-D54nF5iO.cjs} +1 -1
  6. package/dist/chunks/{index-CrIfBvBN.es.js → index-yYYhcBhg.es.js} +8 -4
  7. package/dist/chunks/{super-editor.es-00SpI-wK.es.js → super-editor.es-BNkRY9J-.es.js} +1834 -1121
  8. package/dist/chunks/{super-editor.es-Mlj7AGyt.cjs → super-editor.es-BfPsU6H-.cjs} +1833 -1120
  9. package/dist/packages/superdoc/src/components/CommentsLayer/use-comment.d.ts.map +1 -1
  10. package/dist/packages/superdoc/src/stores/comments-store.d.ts.map +1 -1
  11. package/dist/style.css +7 -7
  12. package/dist/super-editor/ai-writer.es.js +2 -2
  13. package/dist/super-editor/chunks/{converter-B9zUZjYT.js → converter-Cz21HA_9.js} +207 -15
  14. package/dist/super-editor/chunks/{docx-zipper-r5KdE_SA.js → docx-zipper-DiEfO4LE.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-D2k2BwSG.js → editor-DoxVe-iR.js} +1564 -1060
  16. package/dist/super-editor/chunks/{index-VCeRjVPO.js → index-DpnfmQSg.js} +1 -1
  17. package/dist/super-editor/chunks/{toolbar-8o_LgoiW.js → toolbar-CKdQr5PG.js} +2 -2
  18. package/dist/super-editor/converter.es.js +1 -1
  19. package/dist/super-editor/docx-zipper.es.js +2 -2
  20. package/dist/super-editor/editor.es.js +3 -3
  21. package/dist/super-editor/file-zipper.es.js +1 -1
  22. package/dist/super-editor/style.css +7 -7
  23. package/dist/super-editor/super-editor.es.js +126 -45
  24. package/dist/super-editor/toolbar.es.js +2 -2
  25. package/dist/super-editor.cjs +3 -3
  26. package/dist/super-editor.es.js +1 -1
  27. package/dist/superdoc.cjs +2 -2
  28. package/dist/superdoc.es.js +2 -2
  29. package/dist/superdoc.umd.js +1832 -1115
  30. package/dist/superdoc.umd.js.map +1 -1
  31. package/package.json +1 -1
@@ -19192,6 +19192,7 @@
19192
19192
  if (color2) add("text-decoration-color", color2);
19193
19193
  return parts.join("; ");
19194
19194
  }
19195
+ const INLINE_OVERRIDE_PROPERTIES = ["fontSize", "bold", "italic", "strike", "underline", "letterSpacing"];
19195
19196
  const resolveRunProperties = (params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) => {
19196
19197
  const paragraphStyleId = resolvedPpr?.styleId;
19197
19198
  const paragraphStyleProps = resolveStyleChain$1(params2, paragraphStyleId, translator$1N);
@@ -19228,6 +19229,11 @@
19228
19229
  styleChain = [...styleChain, paragraphStyleProps, runStyleProps, inlineRpr];
19229
19230
  }
19230
19231
  const finalProps = combineProperties(styleChain, ["fontFamily", "color"]);
19232
+ for (const prop of INLINE_OVERRIDE_PROPERTIES) {
19233
+ if (inlineRpr?.[prop] != null) {
19234
+ finalProps[prop] = inlineRpr[prop];
19235
+ }
19236
+ }
19231
19237
  return finalProps;
19232
19238
  };
19233
19239
  function resolveParagraphProperties(params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) {
@@ -25035,8 +25041,8 @@
25035
25041
  horizontal: positionHValue,
25036
25042
  top: positionVValue
25037
25043
  };
25038
- const useSimplePos = attributes["simplePos"] === "1" || attributes["simplePos"] === 1;
25039
- const simplePos = useSimplePos ? node2.elements.find((el) => el.name === "wp:simplePos") : null;
25044
+ const useSimplePos = attributes["simplePos"] === "1" || attributes["simplePos"] === 1 || attributes["simplePos"] === true;
25045
+ const simplePosNode = node2.elements.find((el) => el.name === "wp:simplePos");
25040
25046
  const wrapNode = isAnchor ? node2.elements.find(
25041
25047
  (el) => ["wp:wrapNone", "wp:wrapSquare", "wp:wrapThrough", "wp:wrapTight", "wp:wrapTopAndBottom"].includes(el.name)
25042
25048
  ) : null;
@@ -25176,10 +25182,10 @@
25176
25182
  anchorData,
25177
25183
  isAnchor,
25178
25184
  transformData,
25179
- ...simplePos && {
25185
+ ...useSimplePos && {
25180
25186
  simplePos: {
25181
- x: simplePos.attributes.x,
25182
- y: simplePos.attributes.y
25187
+ x: simplePosNode.attributes?.x,
25188
+ y: simplePosNode.attributes?.y
25183
25189
  }
25184
25190
  },
25185
25191
  wrap: wrap2,
@@ -30937,12 +30943,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
30937
30943
  function translateAnchorNode(params2) {
30938
30944
  const { attrs } = params2.node;
30939
30945
  const anchorElements = [];
30940
- if (attrs.simplePos) {
30946
+ const hasSimplePos = attrs.simplePos || attrs.originalAttributes?.simplePos;
30947
+ if (hasSimplePos) {
30941
30948
  anchorElements.push({
30942
30949
  name: "wp:simplePos",
30943
30950
  attributes: {
30944
- x: 0,
30945
- y: 0
30951
+ x: attrs.simplePos?.x ?? 0,
30952
+ y: attrs.simplePos?.y ?? 0
30946
30953
  }
30947
30954
  });
30948
30955
  }
@@ -30994,8 +31001,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
30994
31001
  }
30995
31002
  if (attrs.originalAttributes?.simplePos !== void 0) {
30996
31003
  inlineAttrs.simplePos = attrs.originalAttributes.simplePos;
30997
- } else if (attrs.simplePos !== void 0) {
30998
- inlineAttrs.simplePos = attrs.simplePos;
31004
+ } else if (hasSimplePos) {
31005
+ inlineAttrs.simplePos = "1";
30999
31006
  }
31000
31007
  if (attrs.originalAttributes?.locked !== void 0) {
31001
31008
  inlineAttrs.locked = attrs.originalAttributes.locked;
@@ -33760,7 +33767,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33760
33767
  const { nodes = [] } = params2;
33761
33768
  const node2 = nodes[0];
33762
33769
  if (!node2) return { nodes: [], consumed: 0 };
33763
- if (registeredHandlers[node2.name]) {
33770
+ if (registeredHandlers[node2.name] || node2.name === "w:commentReference") {
33764
33771
  return { nodes: [], consumed: 0 };
33765
33772
  }
33766
33773
  const originalXml = carbonCopy(node2) || {};
@@ -34060,7 +34067,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34060
34067
  const generateCommentsWithExtendedData = ({ docx, comments }) => {
34061
34068
  if (!comments?.length) return [];
34062
34069
  const commentsExtended = docx["word/commentsExtended.xml"];
34063
- if (!commentsExtended) return comments.map((comment2) => ({ ...comment2, isDone: comment2.isDone ?? false }));
34070
+ if (!commentsExtended) {
34071
+ const commentRanges = extractCommentRangesFromDocument(docx);
34072
+ const commentsWithThreading = detectThreadingFromRanges(comments, commentRanges);
34073
+ return commentsWithThreading.map((comment2) => ({ ...comment2, isDone: comment2.isDone ?? false }));
34074
+ }
34064
34075
  const { elements: initialElements = [] } = commentsExtended;
34065
34076
  if (!initialElements?.length) return comments.map((comment2) => ({ ...comment2, isDone: comment2.isDone ?? false }));
34066
34077
  const { elements = [] } = initialElements[0] ?? {};
@@ -34086,6 +34097,79 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34086
34097
  const paraIdParent = attributes["w15:paraIdParent"];
34087
34098
  return { paraId, isDone, paraIdParent };
34088
34099
  };
34100
+ const extractCommentRangesFromDocument = (docx) => {
34101
+ const documentXml = docx["word/document.xml"];
34102
+ if (!documentXml) {
34103
+ return [];
34104
+ }
34105
+ const pendingComments = [];
34106
+ const walkElements = (elements) => {
34107
+ if (!elements || !Array.isArray(elements)) return;
34108
+ elements.forEach((element2) => {
34109
+ if (element2.name === "w:commentRangeStart") {
34110
+ const commentId = element2.attributes?.["w:id"];
34111
+ if (commentId !== void 0) {
34112
+ pendingComments.push({
34113
+ type: "start",
34114
+ commentId: String(commentId)
34115
+ });
34116
+ }
34117
+ } else if (element2.name === "w:commentRangeEnd") {
34118
+ const commentId = element2.attributes?.["w:id"];
34119
+ if (commentId !== void 0) {
34120
+ pendingComments.push({
34121
+ type: "end",
34122
+ commentId: String(commentId)
34123
+ });
34124
+ }
34125
+ }
34126
+ if (element2.elements && Array.isArray(element2.elements)) {
34127
+ walkElements(element2.elements);
34128
+ }
34129
+ });
34130
+ };
34131
+ if (documentXml.elements && documentXml.elements.length > 0) {
34132
+ const body = documentXml.elements[0];
34133
+ if (body.elements) {
34134
+ walkElements(body.elements);
34135
+ }
34136
+ }
34137
+ return pendingComments;
34138
+ };
34139
+ const detectThreadingFromRanges = (comments, rangeEvents) => {
34140
+ if (!rangeEvents || rangeEvents.length === 0) {
34141
+ return comments;
34142
+ }
34143
+ const openRanges = [];
34144
+ const parentMap = /* @__PURE__ */ new Map();
34145
+ rangeEvents.forEach((event) => {
34146
+ if (event.type === "start") {
34147
+ if (openRanges.length > 0) {
34148
+ const parentCommentId = openRanges[openRanges.length - 1];
34149
+ parentMap.set(event.commentId, parentCommentId);
34150
+ }
34151
+ openRanges.push(event.commentId);
34152
+ } else if (event.type === "end") {
34153
+ const index2 = openRanges.lastIndexOf(event.commentId);
34154
+ if (index2 !== -1) {
34155
+ openRanges.splice(index2, 1);
34156
+ }
34157
+ }
34158
+ });
34159
+ return comments.map((comment2) => {
34160
+ const parentCommentId = parentMap.get(comment2.importedId);
34161
+ if (parentCommentId) {
34162
+ const parentComment = comments.find((c2) => c2.importedId === parentCommentId);
34163
+ if (parentComment) {
34164
+ return {
34165
+ ...comment2,
34166
+ parentCommentId: parentComment.commentId
34167
+ };
34168
+ }
34169
+ }
34170
+ return comment2;
34171
+ });
34172
+ };
34089
34173
  const RELATIONSHIP_TYPES = (
34090
34174
  /** @type {const} */
34091
34175
  {
@@ -35926,10 +36010,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35926
36010
  const updateCommentsXml = (commentDefs = [], commentsXml) => {
35927
36011
  const newCommentsXml = carbonCopy(commentsXml);
35928
36012
  commentDefs.forEach((commentDef) => {
35929
- const elements = commentDef.elements[0].elements;
36013
+ const paraNode = commentDef.elements[0];
36014
+ if (!paraNode.attributes) paraNode.attributes = {};
36015
+ const elements = paraNode.elements;
35930
36016
  elements.unshift(COMMENT_REF);
35931
36017
  const paraId = commentDef.attributes["w15:paraId"];
35932
- commentDef.elements[0].attributes["w14:paraId"] = paraId;
36018
+ paraNode.attributes["w14:paraId"] = paraId;
35933
36019
  commentDef.attributes = {
35934
36020
  "w:id": commentDef.attributes["w:id"],
35935
36021
  "w:author": commentDef.attributes["w:author"],
@@ -36303,7 +36389,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36303
36389
  static getStoredSuperdocVersion(docx) {
36304
36390
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
36305
36391
  }
36306
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.17") {
36392
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.18") {
36307
36393
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36308
36394
  }
36309
36395
  /**
@@ -36644,6 +36730,112 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36644
36730
  });
36645
36731
  return { result, params: params2 };
36646
36732
  }
36733
+ /**
36734
+ * Creates a default empty header for the specified variant.
36735
+ *
36736
+ * This method programmatically creates a new header section with an empty ProseMirror
36737
+ * document. The header is added to the converter's data structures and will be included
36738
+ * in subsequent DOCX exports.
36739
+ *
36740
+ * @param {('default' | 'first' | 'even' | 'odd')} variant - The header variant to create
36741
+ * @returns {string} The relationship ID of the created header
36742
+ *
36743
+ * @throws {Error} If variant is invalid or header already exists for this variant
36744
+ *
36745
+ * @example
36746
+ * ```javascript
36747
+ * const headerId = converter.createDefaultHeader('default');
36748
+ * // headerId: 'rId-header-default'
36749
+ * // converter.headers['rId-header-default'] contains empty PM doc
36750
+ * // converter.headerIds.default === 'rId-header-default'
36751
+ * ```
36752
+ */
36753
+ createDefaultHeader(variant = "default") {
36754
+ if (typeof variant !== "string") {
36755
+ throw new TypeError(`variant must be a string, received ${typeof variant}`);
36756
+ }
36757
+ const validVariants = ["default", "first", "even", "odd"];
36758
+ if (!validVariants.includes(variant)) {
36759
+ throw new Error(`Invalid header variant: ${variant}. Must be one of: ${validVariants.join(", ")}`);
36760
+ }
36761
+ if (this.headerIds[variant]) {
36762
+ console.warn(`[SuperConverter] Header already exists for variant '${variant}': ${this.headerIds[variant]}`);
36763
+ return this.headerIds[variant];
36764
+ }
36765
+ const rId = `rId-header-${variant}`;
36766
+ const emptyDoc = {
36767
+ type: "doc",
36768
+ content: [
36769
+ {
36770
+ type: "paragraph",
36771
+ content: []
36772
+ }
36773
+ ]
36774
+ };
36775
+ this.headers[rId] = emptyDoc;
36776
+ this.headerIds[variant] = rId;
36777
+ if (!this.headerIds.ids) {
36778
+ this.headerIds.ids = [];
36779
+ }
36780
+ if (!this.headerIds.ids.includes(rId)) {
36781
+ this.headerIds.ids.push(rId);
36782
+ }
36783
+ this.documentModified = true;
36784
+ return rId;
36785
+ }
36786
+ /**
36787
+ * Creates a default empty footer for the specified variant.
36788
+ *
36789
+ * This method programmatically creates a new footer section with an empty ProseMirror
36790
+ * document. The footer is added to the converter's data structures and will be included
36791
+ * in subsequent DOCX exports.
36792
+ *
36793
+ * @param {('default' | 'first' | 'even' | 'odd')} variant - The footer variant to create
36794
+ * @returns {string} The relationship ID of the created footer
36795
+ *
36796
+ * @throws {Error} If variant is invalid or footer already exists for this variant
36797
+ *
36798
+ * @example
36799
+ * ```javascript
36800
+ * const footerId = converter.createDefaultFooter('default');
36801
+ * // footerId: 'rId-footer-default'
36802
+ * // converter.footers['rId-footer-default'] contains empty PM doc
36803
+ * // converter.footerIds.default === 'rId-footer-default'
36804
+ * ```
36805
+ */
36806
+ createDefaultFooter(variant = "default") {
36807
+ if (typeof variant !== "string") {
36808
+ throw new TypeError(`variant must be a string, received ${typeof variant}`);
36809
+ }
36810
+ const validVariants = ["default", "first", "even", "odd"];
36811
+ if (!validVariants.includes(variant)) {
36812
+ throw new Error(`Invalid footer variant: ${variant}. Must be one of: ${validVariants.join(", ")}`);
36813
+ }
36814
+ if (this.footerIds[variant]) {
36815
+ console.warn(`[SuperConverter] Footer already exists for variant '${variant}': ${this.footerIds[variant]}`);
36816
+ return this.footerIds[variant];
36817
+ }
36818
+ const rId = `rId-footer-${variant}`;
36819
+ const emptyDoc = {
36820
+ type: "doc",
36821
+ content: [
36822
+ {
36823
+ type: "paragraph",
36824
+ content: []
36825
+ }
36826
+ ]
36827
+ };
36828
+ this.footers[rId] = emptyDoc;
36829
+ this.footerIds[variant] = rId;
36830
+ if (!this.footerIds.ids) {
36831
+ this.footerIds.ids = [];
36832
+ }
36833
+ if (!this.footerIds.ids.includes(rId)) {
36834
+ this.footerIds.ids.push(rId);
36835
+ }
36836
+ this.documentModified = true;
36837
+ return rId;
36838
+ }
36647
36839
  // Deprecated methods for backward compatibility
36648
36840
  static getStoredSuperdocId(docx) {
36649
36841
  console.warn("getStoredSuperdocId is deprecated, use getDocumentGuid instead");
@@ -47360,7 +47552,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
47360
47552
  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);
47361
47553
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
47362
47554
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
47363
- 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, dispatchWithFallback_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, getPluginKeyName_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, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _headerLayoutResults, _footerLayoutResults, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _remoteCursorState, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _remoteCursorRafHandle, _scrollTimeout, _PresentationEditor_instances, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_fn, setupPointerHandlers_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, selectWordAt_fn, selectParagraphAt_fn, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, updateDecorationProviders_fn, createDecorationProvider_fn, findHeaderFooterPageForPageNumber_fn, computeDecorationBox_fn, rebuildHeaderFooterRegions_fn, hitTestHeaderFooterRegion_fn, pointInRegion_fn, activateHeaderFooterRegion_fn, enterHeaderFooterMode_fn, exitHeaderFooterMode_fn, getActiveDomTarget_fn, emitHeaderFooterModeChanged_fn, emitHeaderFooterEditingContext_fn, updateAwarenessSession_fn, updateModeBanner_fn, announce_fn, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, computeHeaderFooterCaretRect_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, parseColumns_fn, inchesToPx_fn, applyZoom_fn, createLayoutMetrics_fn, convertPageLocalToOverlayCoords_fn, normalizeClientPoint_fn, computeCaretLayoutRect_fn, computeCaretLayoutRectFromDOM_fn, computeTableCaretLayoutRect_fn, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _layoutSurfaces, _getTargetDom, _onTargetChanged, _listeners, _currentTarget, _destroyed, _useWindowFallback, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, shouldSkipSurface_fn, isInLayoutSurface_fn, getListenerTargets_fn, isPlainCharacterKey_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, checkShouldUpdate_fn, updateHTMLAttributes_fn, updateDOMStyles_fn, resolveNeighborParagraphProperties_fn, updateListStyles_fn, initList_fn, checkIsList_fn, createMarker_fn, createSeparator_fn, calculateTabSeparatorStyle_fn, calculateMarkerStyle_fn, removeList_fn, getParagraphContext_fn, scheduleAnimation_fn, cancelScheduledAnimation_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _VectorShapeView_instances, ensureParentPositioned_fn, _ShapeGroupView_instances, ensureParentPositioned_fn2;
47555
+ 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, dispatchWithFallback_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, getPluginKeyName_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, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionUpdateScheduled, _remoteCursorUpdateScheduled, _rafHandle, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _headerLayoutResults, _footerLayoutResults, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _overlayManager, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _remoteCursorState, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _remoteCursorRafHandle, _scrollTimeout, _PresentationEditor_instances, aggregateLayoutBounds_fn, safeCleanup_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, normalizeAwarenessStates_fn, getFallbackColor_fn, getValidatedColor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, renderRemoteCaret_fn, renderRemoteCursorLabel_fn, renderRemoteSelection_fn, setupPointerHandlers_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, selectWordAt_fn, selectParagraphAt_fn, isWordCharacter_fn, _handlePointerMove, _handlePointerLeave, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, updateDecorationProviders_fn, createDecorationProvider_fn, findHeaderFooterPageForPageNumber_fn, computeDecorationBox_fn, rebuildHeaderFooterRegions_fn, hitTestHeaderFooterRegion_fn, pointInRegion_fn, activateHeaderFooterRegion_fn, enterHeaderFooterMode_fn, exitHeaderFooterMode_fn, getActiveDomTarget_fn, emitHeaderFooterModeChanged_fn, emitHeaderFooterEditingContext_fn, updateAwarenessSession_fn, updateModeBanner_fn, announce_fn, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, scrollPageIntoView_fn, waitForPageMount_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderSelectionRects_fn, renderHoverRegion_fn, clearHoverRegion_fn, renderCaretOverlay_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, parseColumns_fn, inchesToPx_fn, applyZoom_fn, createLayoutMetrics_fn, convertPageLocalToOverlayCoords_fn, normalizeClientPoint_fn, computeCaretLayoutRect_fn, computeCaretLayoutRectFromDOM_fn, computeTableCaretLayoutRect_fn, findLineContainingPos_fn, lineHeightBeforeIndex_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, createHiddenHost_fn, _windowRoot, _layoutSurfaces, _getTargetDom, _onTargetChanged, _listeners, _currentTarget, _destroyed, _useWindowFallback, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, shouldSkipSurface_fn, isInLayoutSurface_fn, getListenerTargets_fn, isPlainCharacterKey_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, checkShouldUpdate_fn, updateHTMLAttributes_fn, updateDOMStyles_fn, resolveNeighborParagraphProperties_fn, updateListStyles_fn, initList_fn, checkIsList_fn, createMarker_fn, createSeparator_fn, calculateTabSeparatorStyle_fn, calculateMarkerStyle_fn, removeList_fn, getParagraphContext_fn, scheduleAnimation_fn, cancelScheduledAnimation_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _VectorShapeView_instances, ensureParentPositioned_fn, _ShapeGroupView_instances, ensureParentPositioned_fn2;
47364
47556
  var GOOD_LEAF_SIZE = 200;
47365
47557
  var RopeSequence = function RopeSequence2() {
47366
47558
  };
@@ -58546,50 +58738,90 @@ Please report this to https://github.com/markedjs/marked.`, e) {
58546
58738
  return positions;
58547
58739
  };
58548
58740
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
58741
+ const commentMap = /* @__PURE__ */ new Map();
58742
+ comments.forEach((c2) => {
58743
+ commentMap.set(c2.commentId, c2);
58744
+ });
58745
+ new Set(comments.filter((c2) => c2.parentCommentId).map((c2) => c2.parentCommentId));
58549
58746
  const startNodes = [];
58550
58747
  const endNodes = [];
58551
58748
  const seen = /* @__PURE__ */ new Set();
58552
58749
  doc2.descendants((node2, pos) => {
58553
- const commentMarks = node2.marks?.filter((mark2) => mark2.type.name === CommentMarkName);
58750
+ const commentMarks = node2.marks?.filter((mark2) => mark2.type.name === CommentMarkName) || [];
58554
58751
  commentMarks.forEach((commentMark) => {
58555
- if (commentMark) {
58556
- const { attrs = {} } = commentMark;
58557
- const { commentId } = attrs;
58558
- if (commentId === "pending") return;
58559
- if (seen.has(commentId)) return;
58560
- seen.add(commentId);
58561
- const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
58562
- const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
58752
+ const { attrs = {} } = commentMark;
58753
+ const { commentId } = attrs;
58754
+ if (commentId === "pending") return;
58755
+ if (seen.has(commentId)) return;
58756
+ seen.add(commentId);
58757
+ const comment2 = commentMap.get(commentId);
58758
+ const parentCommentId = comment2?.parentCommentId;
58759
+ const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
58760
+ const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
58761
+ startNodes.push({
58762
+ pos,
58763
+ node: startNode,
58764
+ commentId,
58765
+ parentCommentId
58766
+ });
58767
+ const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
58768
+ endNodes.push({
58769
+ pos: pos + node2.nodeSize,
58770
+ node: endNode,
58771
+ commentId,
58772
+ parentCommentId
58773
+ });
58774
+ const childComments = comments.filter((c2) => c2.parentCommentId === commentId).sort((a2, b2) => a2.createdTime - b2.createdTime);
58775
+ childComments.forEach((c2) => {
58776
+ if (seen.has(c2.commentId)) return;
58777
+ seen.add(c2.commentId);
58778
+ const childMark = getPreparedComment({
58779
+ commentId: c2.commentId,
58780
+ internal: c2.isInternal
58781
+ });
58782
+ const childStartNode = schema.nodes.commentRangeStart.create(childMark);
58563
58783
  startNodes.push({
58564
58784
  pos,
58565
- node: startNode
58785
+ node: childStartNode,
58786
+ commentId: c2.commentId,
58787
+ parentCommentId: c2.parentCommentId
58566
58788
  });
58567
- const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
58789
+ const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
58568
58790
  endNodes.push({
58569
58791
  pos: pos + node2.nodeSize,
58570
- node: endNode
58792
+ node: childEndNode,
58793
+ commentId: c2.commentId,
58794
+ parentCommentId: c2.parentCommentId
58571
58795
  });
58572
- const parentId = commentId;
58573
- if (parentId) {
58574
- const childComments = comments.filter((c2) => c2.parentCommentId === parentId).sort((a2, b2) => a2.createdTime - b2.createdTime);
58575
- childComments.forEach((c2) => {
58576
- const childMark = getPreparedComment(c2);
58577
- const childStartNode = schema.nodes.commentRangeStart.create(childMark);
58578
- seen.add(c2.commentId);
58579
- startNodes.push({
58580
- pos,
58581
- node: childStartNode
58582
- });
58583
- const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
58584
- endNodes.push({
58585
- pos: pos + node2.nodeSize,
58586
- node: childEndNode
58587
- });
58588
- });
58589
- }
58590
- }
58796
+ });
58591
58797
  });
58592
58798
  });
58799
+ startNodes.sort((a2, b2) => {
58800
+ if (a2.pos !== b2.pos) return a2.pos - b2.pos;
58801
+ const aIsParentOfB = a2.commentId === b2.parentCommentId;
58802
+ const bIsParentOfA = b2.commentId === a2.parentCommentId;
58803
+ if (aIsParentOfB) return -1;
58804
+ if (bIsParentOfA) return 1;
58805
+ if (a2.parentCommentId && a2.parentCommentId === b2.parentCommentId) {
58806
+ const aComment = commentMap.get(a2.commentId);
58807
+ const bComment = commentMap.get(b2.commentId);
58808
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
58809
+ }
58810
+ return 0;
58811
+ });
58812
+ endNodes.sort((a2, b2) => {
58813
+ if (a2.pos !== b2.pos) return a2.pos - b2.pos;
58814
+ const aIsParentOfB = a2.commentId === b2.parentCommentId;
58815
+ const bIsParentOfA = b2.commentId === a2.parentCommentId;
58816
+ if (aIsParentOfB) return -1;
58817
+ if (bIsParentOfA) return 1;
58818
+ if (a2.parentCommentId && a2.parentCommentId === b2.parentCommentId) {
58819
+ const aComment = commentMap.get(a2.commentId);
58820
+ const bComment = commentMap.get(b2.commentId);
58821
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
58822
+ }
58823
+ return 0;
58824
+ });
58593
58825
  startNodes.forEach((n) => {
58594
58826
  const { pos, node: node2 } = n;
58595
58827
  const mappedPos = tr.mapping.map(pos);
@@ -61131,7 +61363,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61131
61363
  const shouldSkipNodeView = (editor) => {
61132
61364
  return isHeadless(editor);
61133
61365
  };
61134
- const summaryVersion = "1.0.0-beta.17";
61366
+ const summaryVersion = "1.0.0-beta.18";
61135
61367
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
61136
61368
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
61137
61369
  function mapAttributes(attrs) {
@@ -61907,7 +62139,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61907
62139
  { default: remarkStringify2 },
61908
62140
  { default: remarkGfm2 }
61909
62141
  ] = await Promise.all([
61910
- Promise.resolve().then(() => indexVCeRjVPO),
62142
+ Promise.resolve().then(() => indexDpnfmQSg),
61911
62143
  Promise.resolve().then(() => indexDRCvimau),
61912
62144
  Promise.resolve().then(() => indexC_x_N6Uh),
61913
62145
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -62112,7 +62344,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62112
62344
  * Process collaboration migrations
62113
62345
  */
62114
62346
  processCollaborationMigrations() {
62115
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.17");
62347
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.18");
62116
62348
  if (!this.options.ydoc) return;
62117
62349
  const metaMap = this.options.ydoc.getMap("meta");
62118
62350
  let docVersion = metaMap.get("version");
@@ -62814,6 +63046,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62814
63046
  gap: gapInches * PX_PER_INCH$2
62815
63047
  };
62816
63048
  }
63049
+ function extractVerticalAlign(elements) {
63050
+ const vAlign = elements.find((el) => el?.name === "w:vAlign");
63051
+ if (!vAlign?.attributes) return void 0;
63052
+ const val = vAlign.attributes["w:val"];
63053
+ if (val === "top" || val === "center" || val === "bottom" || val === "both") {
63054
+ return val;
63055
+ }
63056
+ return void 0;
63057
+ }
62817
63058
  function extractSectionData(para) {
62818
63059
  const attrs = para.attrs ?? {};
62819
63060
  let { headerPx, footerPx } = extractNormalizedMargins(attrs);
@@ -62830,7 +63071,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62830
63071
  const footerRefs = extractHeaderFooterRefs(sectPrElements, "w:footerReference");
62831
63072
  const numbering = extractPageNumbering(sectPrElements);
62832
63073
  const columnsPx = extractColumns(sectPrElements);
62833
- return { headerPx, footerPx, type: type2, pageSizePx, orientation, columnsPx, titlePg, headerRefs, footerRefs, numbering };
63074
+ const vAlign = extractVerticalAlign(sectPrElements);
63075
+ return {
63076
+ headerPx,
63077
+ footerPx,
63078
+ type: type2,
63079
+ pageSizePx,
63080
+ orientation,
63081
+ columnsPx,
63082
+ titlePg,
63083
+ headerRefs,
63084
+ footerRefs,
63085
+ numbering,
63086
+ vAlign
63087
+ };
62834
63088
  }
62835
63089
  function isSectPrElement(value) {
62836
63090
  return typeof value === "object" && value !== null && value.type === "element" && value.name === "w:sectPr";
@@ -62867,7 +63121,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62867
63121
  ...section.columns && { columns: section.columns },
62868
63122
  ...section.numbering ? { numbering: section.numbering } : {},
62869
63123
  ...section.headerRefs && { headerRefs: section.headerRefs },
62870
- ...section.footerRefs && { footerRefs: section.footerRefs }
63124
+ ...section.footerRefs && { footerRefs: section.footerRefs },
63125
+ ...section.vAlign && { vAlign: section.vAlign }
62871
63126
  };
62872
63127
  return result;
62873
63128
  }
@@ -62939,7 +63194,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62939
63194
  titlePg: sectionData.titlePg ?? false,
62940
63195
  headerRefs: sectionData.headerRefs,
62941
63196
  footerRefs: sectionData.footerRefs,
62942
- numbering: sectionData.numbering
63197
+ numbering: sectionData.numbering,
63198
+ vAlign: sectionData.vAlign
62943
63199
  };
62944
63200
  ranges.push(range2);
62945
63201
  currentStart = item.index + 1;
@@ -62978,7 +63234,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62978
63234
  type: bodySectionData.type ?? DEFAULT_BODY_SECTION_TYPE,
62979
63235
  titlePg: bodySectionData.titlePg ?? false,
62980
63236
  headerRefs: bodySectionData.headerRefs,
62981
- footerRefs: bodySectionData.footerRefs
63237
+ footerRefs: bodySectionData.footerRefs,
63238
+ vAlign: bodySectionData.vAlign
62982
63239
  };
62983
63240
  }
62984
63241
  function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex) {
@@ -64641,8 +64898,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64641
64898
  for (const entry of tabs) {
64642
64899
  if (!entry || typeof entry !== "object") continue;
64643
64900
  const rawEntry = entry;
64644
- const source = rawEntry.tab && typeof rawEntry.tab === "object" ? rawEntry.tab : rawEntry;
64645
- const posTwips = resolveTabPosition(source);
64901
+ const isNestedTab = Boolean(rawEntry.tab && typeof rawEntry.tab === "object");
64902
+ const source = isNestedTab ? rawEntry.tab : rawEntry;
64903
+ const posTwips = resolveTabPosition(source, isNestedTab);
64646
64904
  if (posTwips == null) continue;
64647
64905
  const val = normalizeTabVal(source.val ?? source.align ?? source.alignment ?? source.type ?? source.tabType);
64648
64906
  if (!val) continue;
@@ -64656,7 +64914,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64656
64914
  }
64657
64915
  return normalized.length > 0 ? normalized : void 0;
64658
64916
  };
64659
- const resolveTabPosition = (source) => {
64917
+ const resolveTabPosition = (source, treatPosAsTwips = false) => {
64660
64918
  const originalPos = pickNumber(source.originalPos);
64661
64919
  if (originalPos != null) {
64662
64920
  return originalPos;
@@ -64665,6 +64923,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64665
64923
  if (posValue == null) {
64666
64924
  return void 0;
64667
64925
  }
64926
+ if (treatPosAsTwips) {
64927
+ return posValue;
64928
+ }
64668
64929
  if (posValue > TWIPS_THRESHOLD) {
64669
64930
  return posValue;
64670
64931
  } else {
@@ -66652,19 +66913,21 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66652
66913
  }
66653
66914
  const tabObj = tab;
66654
66915
  const val = typeof tabObj.tabType === "string" ? tabObj.tabType : typeof tabObj.val === "string" ? tabObj.val : void 0;
66655
- const pos = pickNumber(tabObj.originalPos ?? tabObj.pos);
66916
+ const originalPos = pickNumber(tabObj.originalPos);
66917
+ const pos = originalPos ?? pickNumber(tabObj.pos);
66656
66918
  if (!val || pos == null) {
66657
66919
  continue;
66658
66920
  }
66659
66921
  const normalized = { val, pos };
66922
+ if (originalPos != null && Number.isFinite(originalPos)) {
66923
+ normalized.originalPos = originalPos;
66924
+ } else {
66925
+ normalized.originalPos = pos;
66926
+ }
66660
66927
  const leader = tabObj.leader;
66661
66928
  if (typeof leader === "string" && leader.length > 0) {
66662
66929
  normalized.leader = leader;
66663
66930
  }
66664
- const originalPos = pickNumber(tabObj.originalPos);
66665
- if (originalPos != null && Number.isFinite(originalPos)) {
66666
- normalized.originalPos = originalPos;
66667
- }
66668
66931
  unwrapped.push(normalized);
66669
66932
  continue;
66670
66933
  }
@@ -67506,11 +67769,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67506
67769
  if (!maps.length) return;
67507
67770
  const finalStyles = Object.assign({}, ...maps);
67508
67771
  const fontFamily2 = extractValue(finalStyles["font-family"]);
67509
- if (typeof fontFamily2 === "string" && fontFamily2 && run2.fontFamily === options.defaultFont) {
67772
+ if (typeof fontFamily2 === "string" && fontFamily2) {
67510
67773
  run2.fontFamily = fontFamily2;
67511
67774
  }
67512
67775
  const fontSize2 = toPxNumber(finalStyles["font-size"]);
67513
- if (fontSize2 != null && run2.fontSize === options.defaultSize) {
67776
+ if (fontSize2 != null) {
67514
67777
  run2.fontSize = fontSize2;
67515
67778
  }
67516
67779
  const letterSpacing = toPxNumber(finalStyles["letter-spacing"]);
@@ -67873,9 +68136,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67873
68136
  resolver: linkedStyleResolver,
67874
68137
  paragraphStyleId,
67875
68138
  inlineStyleId,
67876
- runStyleId,
67877
- defaultFont,
67878
- defaultSize
68139
+ runStyleId
67879
68140
  });
67880
68141
  };
67881
68142
  const visitNode = (node2, inheritedMarks = [], activeSdt, activeRunStyleId = null) => {
@@ -67885,7 +68146,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67885
68146
  positions,
67886
68147
  defaultFont,
67887
68148
  defaultSize,
67888
- inheritedMarks,
68149
+ [],
68150
+ // Empty marks - will be applied after linked styles
67889
68151
  activeSdt,
67890
68152
  hyperlinkConfig,
67891
68153
  themeColors
@@ -67893,6 +68155,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67893
68155
  const inlineStyleId = getInlineStyleId(inheritedMarks);
67894
68156
  applyRunStyles2(run2, inlineStyleId, activeRunStyleId);
67895
68157
  applyBaseRunDefaults(run2, baseRunDefaults, defaultFont, defaultSize);
68158
+ applyMarksToRun(run2, [...node2.marks ?? [], ...inheritedMarks ?? []], hyperlinkConfig, themeColors);
67896
68159
  currentRuns.push(run2);
67897
68160
  return;
67898
68161
  }
@@ -69767,13 +70030,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69767
70030
  if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
69768
70031
  return null;
69769
70032
  }
69770
- const spanEls = Array.from(lineEl.querySelectorAll("span"));
70033
+ const spanEls = Array.from(lineEl.querySelectorAll("span, a"));
69771
70034
  log(
69772
- "Spans in line:",
70035
+ "Spans/anchors in line:",
69773
70036
  spanEls.map((el, i2) => {
69774
70037
  const rect = el.getBoundingClientRect();
69775
70038
  return {
69776
70039
  index: i2,
70040
+ tag: el.tagName,
69777
70041
  pmStart: el.dataset.pmStart,
69778
70042
  pmEnd: el.dataset.pmEnd,
69779
70043
  text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
@@ -69793,32 +70057,33 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69793
70057
  if (viewX >= lastRect.right) {
69794
70058
  return lineEnd;
69795
70059
  }
69796
- const targetSpan = findSpanAtX(spanEls, viewX);
69797
- if (!targetSpan) {
70060
+ const targetEl = findSpanAtX(spanEls, viewX);
70061
+ if (!targetEl) {
69798
70062
  return lineStart;
69799
70063
  }
69800
- const spanStart = Number(targetSpan.dataset.pmStart ?? "NaN");
69801
- const spanEnd = Number(targetSpan.dataset.pmEnd ?? "NaN");
69802
- const targetRect = targetSpan.getBoundingClientRect();
69803
- log("Target span:", {
70064
+ const spanStart = Number(targetEl.dataset.pmStart ?? "NaN");
70065
+ const spanEnd = Number(targetEl.dataset.pmEnd ?? "NaN");
70066
+ const targetRect = targetEl.getBoundingClientRect();
70067
+ log("Target element:", {
70068
+ tag: targetEl.tagName,
69804
70069
  pmStart: spanStart,
69805
70070
  pmEnd: spanEnd,
69806
- text: targetSpan.textContent?.substring(0, 30),
69807
- visibility: targetSpan.style.visibility,
70071
+ text: targetEl.textContent?.substring(0, 30),
70072
+ visibility: targetEl.style.visibility,
69808
70073
  rect: { left: targetRect.left, right: targetRect.right, width: targetRect.width }
69809
70074
  });
69810
70075
  if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) {
69811
70076
  return null;
69812
70077
  }
69813
- const firstChild = targetSpan.firstChild;
70078
+ const firstChild = targetEl.firstChild;
69814
70079
  if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
69815
- const spanRect = targetSpan.getBoundingClientRect();
69816
- const closerToLeft = Math.abs(viewX - spanRect.left) <= Math.abs(viewX - spanRect.right);
70080
+ const elRect = targetEl.getBoundingClientRect();
70081
+ const closerToLeft = Math.abs(viewX - elRect.left) <= Math.abs(viewX - elRect.right);
69817
70082
  const snapPos = closerToLeft ? spanStart : spanEnd;
69818
70083
  return snapPos;
69819
70084
  }
69820
70085
  const textNode = firstChild;
69821
- const charIndex = findCharIndexAtX(textNode, targetSpan, viewX);
70086
+ const charIndex = findCharIndexAtX(textNode, targetEl, viewX);
69822
70087
  const pos = spanStart + charIndex;
69823
70088
  return pos;
69824
70089
  }
@@ -69856,7 +70121,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69856
70121
  const span = spanEls[i2];
69857
70122
  const rect = span.getBoundingClientRect();
69858
70123
  if (viewX >= rect.left && viewX <= rect.right) {
69859
- log("findSpanAtX: Found containing span at index", i2, {
70124
+ log("findSpanAtX: Found containing element at index", i2, {
70125
+ tag: span.tagName,
69860
70126
  pmStart: span.dataset.pmStart,
69861
70127
  pmEnd: span.dataset.pmEnd,
69862
70128
  rect: { left: rect.left, right: rect.right },
@@ -69868,16 +70134,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
69868
70134
  targetSpan = span;
69869
70135
  }
69870
70136
  }
69871
- log("findSpanAtX: No containing span, using nearest:", {
70137
+ log("findSpanAtX: No containing element, using nearest:", {
70138
+ tag: targetSpan.tagName,
69872
70139
  pmStart: targetSpan.dataset.pmStart,
69873
70140
  pmEnd: targetSpan.dataset.pmEnd,
69874
70141
  viewX
69875
70142
  });
69876
70143
  return targetSpan;
69877
70144
  }
69878
- function findCharIndexAtX(textNode, span, targetX) {
70145
+ function findCharIndexAtX(textNode, container, targetX) {
69879
70146
  const text2 = textNode.textContent ?? "";
69880
- const baseLeft = span.getBoundingClientRect().left;
70147
+ const baseLeft = container.getBoundingClientRect().left;
69881
70148
  const range2 = document.createRange();
69882
70149
  let lo = 0;
69883
70150
  let hi = text2.length;
@@ -70209,6 +70476,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
70209
70476
  if (source.orientation) {
70210
70477
  props.orientation = source.orientation;
70211
70478
  }
70479
+ if (source.vAlign) {
70480
+ props.vAlign = source.vAlign;
70481
+ }
70212
70482
  return props;
70213
70483
  };
70214
70484
  docxBreakIndexes.forEach((index2, ordinal) => {
@@ -71609,6 +71879,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
71609
71879
  runs: clonedRuns
71610
71880
  };
71611
71881
  }
71882
+ const DEFAULT_PARAGRAPH_LINE_HEIGHT_PX = 20;
71883
+ function hasHeight(fragment) {
71884
+ return fragment.kind === "image" || fragment.kind === "drawing" || fragment.kind === "table";
71885
+ }
71612
71886
  const DEFAULT_PAGE_SIZE$2 = { w: 612, h: 792 };
71613
71887
  const DEFAULT_MARGINS$2 = { top: 72, right: 72, bottom: 72, left: 72 };
71614
71888
  const COLUMN_EPSILON = 1e-4;
@@ -71703,6 +71977,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
71703
71977
  let pendingColumns = null;
71704
71978
  let activeOrientation = null;
71705
71979
  let pendingOrientation = null;
71980
+ let activeVAlign = null;
71981
+ let pendingVAlign = null;
71706
71982
  const floatManager = createFloatingObjectManager(
71707
71983
  normalizeColumns(activeColumns, contentWidth),
71708
71984
  { left: margins.left, right: margins.right },
@@ -71808,6 +72084,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
71808
72084
  if (activeOrientation) {
71809
72085
  page.orientation = activeOrientation;
71810
72086
  }
72087
+ if (activeVAlign && activeVAlign !== "top") {
72088
+ page.vAlign = activeVAlign;
72089
+ }
71811
72090
  return page;
71812
72091
  };
71813
72092
  let pageCount = 0;
@@ -71886,6 +72165,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
71886
72165
  activeSectionRefs = pendingSectionRefs;
71887
72166
  pendingSectionRefs = null;
71888
72167
  }
72168
+ if (pendingVAlign !== null) {
72169
+ activeVAlign = pendingVAlign;
72170
+ pendingVAlign = null;
72171
+ }
71889
72172
  pageCount += 1;
71890
72173
  return;
71891
72174
  }
@@ -72022,7 +72305,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72022
72305
  margins: ahead.margins ? { ...effectiveBlock.margins ?? {}, ...ahead.margins } : effectiveBlock.margins ?? {},
72023
72306
  pageSize: ahead.pageSize ?? effectiveBlock.pageSize,
72024
72307
  columns: ahead.columns ?? effectiveBlock.columns,
72025
- orientation: ahead.orientation ?? effectiveBlock.orientation
72308
+ orientation: ahead.orientation ?? effectiveBlock.orientation,
72309
+ vAlign: ahead.vAlign ?? effectiveBlock.vAlign
72026
72310
  };
72027
72311
  }
72028
72312
  const sectionState = {
@@ -72075,6 +72359,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72075
72359
  pendingColumns = updatedState.pendingColumns;
72076
72360
  activeOrientation = updatedState.activeOrientation;
72077
72361
  pendingOrientation = updatedState.pendingOrientation;
72362
+ if (effectiveBlock.vAlign) {
72363
+ const isFirstSection = effectiveBlock.attrs?.isFirstSection && states.length === 0;
72364
+ if (isFirstSection) {
72365
+ activeVAlign = effectiveBlock.vAlign;
72366
+ pendingVAlign = null;
72367
+ } else {
72368
+ pendingVAlign = effectiveBlock.vAlign;
72369
+ }
72370
+ }
72078
72371
  if (effectiveBlock.headerRefs || effectiveBlock.footerRefs) {
72079
72372
  pendingSectionRefs = {
72080
72373
  ...effectiveBlock.headerRefs && { headerRefs: effectiveBlock.headerRefs },
@@ -72083,8 +72376,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72083
72376
  layoutLog(`[Layout] After scheduleSectionBreakCompat: Scheduled pendingSectionRefs:`, pendingSectionRefs);
72084
72377
  }
72085
72378
  if (breakInfo.forceMidPageRegion && block.columns) {
72086
- const state2 = paginator.ensurePage();
72087
- startMidPageRegion(state2, { count: block.columns.count, gap: block.columns.gap });
72379
+ let state2 = paginator.ensurePage();
72380
+ const columnIndexBefore = state2.columnIndex;
72381
+ const rawCount = block.columns.count;
72382
+ const validatedCount = typeof rawCount === "number" && Number.isFinite(rawCount) && rawCount > 0 ? Math.max(1, Math.floor(rawCount)) : 1;
72383
+ const rawGap = block.columns.gap;
72384
+ const validatedGap = typeof rawGap === "number" && Number.isFinite(rawGap) && rawGap >= 0 ? Math.max(0, rawGap) : 0;
72385
+ const newColumns = { count: validatedCount, gap: validatedGap };
72386
+ if (columnIndexBefore >= newColumns.count) {
72387
+ state2 = paginator.startNewPage();
72388
+ }
72389
+ startMidPageRegion(state2, newColumns);
72088
72390
  }
72089
72391
  if (breakInfo.forcePageBreak) {
72090
72392
  let state2 = paginator.ensurePage();
@@ -72276,6 +72578,45 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72276
72578
  while (pages.length > 0 && pages[pages.length - 1].fragments.length === 0) {
72277
72579
  pages.pop();
72278
72580
  }
72581
+ for (const page of pages) {
72582
+ if (!page.vAlign || page.vAlign === "top") continue;
72583
+ if (page.fragments.length === 0) continue;
72584
+ const pageSizeForPage = page.size ?? pageSize;
72585
+ const contentTop = page.margins?.top ?? margins.top;
72586
+ const contentBottom = pageSizeForPage.h - (page.margins?.bottom ?? margins.bottom);
72587
+ const contentHeight = contentBottom - contentTop;
72588
+ let minY = Infinity;
72589
+ let maxY = -Infinity;
72590
+ for (const fragment of page.fragments) {
72591
+ if (fragment.y < minY) minY = fragment.y;
72592
+ let fragmentBottom = fragment.y;
72593
+ if (hasHeight(fragment)) {
72594
+ fragmentBottom += fragment.height;
72595
+ } else {
72596
+ const lineCount = fragment.toLine - fragment.fromLine;
72597
+ fragmentBottom += lineCount * DEFAULT_PARAGRAPH_LINE_HEIGHT_PX;
72598
+ }
72599
+ if (fragmentBottom > maxY) maxY = fragmentBottom;
72600
+ }
72601
+ const actualContentHeight = maxY - minY;
72602
+ const availableSpace = contentHeight - actualContentHeight;
72603
+ if (availableSpace <= 0) {
72604
+ continue;
72605
+ }
72606
+ let yOffset = 0;
72607
+ if (page.vAlign === "center") {
72608
+ yOffset = availableSpace / 2;
72609
+ } else if (page.vAlign === "bottom") {
72610
+ yOffset = availableSpace;
72611
+ } else if (page.vAlign === "both") {
72612
+ yOffset = availableSpace / 2;
72613
+ }
72614
+ if (yOffset > 0) {
72615
+ for (const fragment of page.fragments) {
72616
+ fragment.y += yOffset;
72617
+ }
72618
+ }
72619
+ }
72279
72620
  return {
72280
72621
  pageSize,
72281
72622
  pages,
@@ -76703,14 +77044,25 @@ ${l}
76703
77044
  }
76704
77045
  `;
76705
77046
  const LINK_AND_TOC_STYLES = `
76706
- /* Reset browser default link styling - allow run colors to show through */
77047
+ /* Reset browser default link styling - allow run colors to show through from inline styles
77048
+ *
77049
+ * Note: !important was removed from these rules to allow inline styles to take precedence.
77050
+ * This is necessary because OOXML hyperlink character styles apply colors via inline style
77051
+ * attributes on the run elements. The CSS cascade ensures that inline styles (applied via
77052
+ * element.style.color in applyRunStyles) override these class-based rules naturally.
77053
+ *
77054
+ * Implications:
77055
+ * - OOXML hyperlink character styles will correctly display their assigned colors
77056
+ * - Browser default link colors are still reset by these inherit rules
77057
+ * - Inline color styles from run objects override the inherit value as expected
77058
+ */
76707
77059
  .superdoc-link {
76708
- color: inherit !important;
76709
- text-decoration: none !important;
77060
+ color: inherit;
77061
+ text-decoration: none;
76710
77062
  }
76711
77063
 
76712
77064
  .superdoc-link:visited {
76713
- color: inherit !important;
77065
+ color: inherit;
76714
77066
  }
76715
77067
 
76716
77068
  .superdoc-link:hover {
@@ -78249,14 +78601,23 @@ ${l}
78249
78601
  lines.forEach((line, index2) => {
78250
78602
  const lineEl = this.renderLine(block, line, context);
78251
78603
  const isListFirstLine = index2 === 0 && !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker;
78252
- if (paraIndentLeft && !isListFirstLine) {
78253
- lineEl.style.paddingLeft = `${paraIndentLeft}px`;
78604
+ const hasExplicitSegmentPositioning = line.segments?.some((seg) => seg.x !== void 0);
78605
+ const isFirstLine = index2 === 0 && !fragment.continuesFromPrev;
78606
+ if (!isListFirstLine) {
78607
+ if (isFirstLine && hasExplicitSegmentPositioning && firstLineOffset !== 0) {
78608
+ const adjustedPadding = paraIndentLeft + firstLineOffset;
78609
+ lineEl.style.paddingLeft = `${adjustedPadding}px`;
78610
+ } else if (paraIndentLeft) {
78611
+ lineEl.style.paddingLeft = `${paraIndentLeft}px`;
78612
+ }
78254
78613
  }
78255
78614
  if (paraIndentRight) {
78256
78615
  lineEl.style.paddingRight = `${paraIndentRight}px`;
78257
78616
  }
78258
78617
  if (!fragment.continuesFromPrev && index2 === 0 && firstLineOffset && !isListFirstLine) {
78259
- lineEl.style.textIndent = `${firstLineOffset}px`;
78618
+ if (!hasExplicitSegmentPositioning) {
78619
+ lineEl.style.textIndent = `${firstLineOffset}px`;
78620
+ }
78260
78621
  } else if (firstLineOffset && !isListFirstLine) {
78261
78622
  lineEl.style.textIndent = "0px";
78262
78623
  }
@@ -79150,6 +79511,24 @@ ${l}
79150
79511
  }
79151
79512
  elem.setAttribute("role", "link");
79152
79513
  elem.setAttribute("tabindex", "0");
79514
+ elem.addEventListener("click", (event) => {
79515
+ event.preventDefault();
79516
+ event.stopPropagation();
79517
+ const linkClickEvent = new CustomEvent("superdoc-link-click", {
79518
+ bubbles: true,
79519
+ composed: true,
79520
+ detail: {
79521
+ href: linkData.href,
79522
+ target: linkData.target,
79523
+ rel: linkData.rel,
79524
+ tooltip: linkData.tooltip,
79525
+ element: elem,
79526
+ clientX: event.clientX,
79527
+ clientY: event.clientY
79528
+ }
79529
+ });
79530
+ elem.dispatchEvent(linkClickEvent);
79531
+ });
79153
79532
  }
79154
79533
  /**
79155
79534
  * Render a single run as an HTML element (span or anchor).
@@ -79439,7 +79818,13 @@ ${l}
79439
79818
  if (styleId) {
79440
79819
  elem.setAttribute("styleid", styleId);
79441
79820
  }
79821
+ const runSegments2 = segmentsByRun.get(runIndex);
79822
+ const segX = runSegments2 && runSegments2[0]?.x !== void 0 ? runSegments2[0].x : cumulativeX;
79823
+ const segWidth = (runSegments2 && runSegments2[0]?.width !== void 0 ? runSegments2[0].width : elem.offsetWidth) ?? 0;
79824
+ elem.style.position = "absolute";
79825
+ elem.style.left = `${segX}px`;
79442
79826
  el.appendChild(elem);
79827
+ cumulativeX = segX + segWidth;
79443
79828
  }
79444
79829
  continue;
79445
79830
  }
@@ -79981,7 +80366,7 @@ ${l}
79981
80366
  }
79982
80367
  return block.id;
79983
80368
  };
79984
- const applyRunStyles = (element2, run2, isLink = false) => {
80369
+ const applyRunStyles = (element2, run2, _isLink = false) => {
79985
80370
  if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break") {
79986
80371
  return;
79987
80372
  }
@@ -79989,9 +80374,7 @@ ${l}
79989
80374
  element2.style.fontSize = `${run2.fontSize}px`;
79990
80375
  if (run2.bold) element2.style.fontWeight = "bold";
79991
80376
  if (run2.italic) element2.style.fontStyle = "italic";
79992
- if (!isLink) {
79993
- if (run2.color) element2.style.color = run2.color;
79994
- }
80377
+ if (run2.color) element2.style.color = run2.color;
79995
80378
  if (run2.letterSpacing != null) {
79996
80379
  element2.style.letterSpacing = `${run2.letterSpacing}px`;
79997
80380
  }
@@ -80539,28 +80922,44 @@ ${l}
80539
80922
  }
80540
80923
  return true;
80541
80924
  };
80542
- const alignSegmentAtTab = (segmentText, font, runContext) => {
80543
- if (!pendingTabAlignment || !currentLine) return;
80925
+ const alignPendingTabForWidth = (segmentWidth, beforeDecimalWidth) => {
80926
+ if (!pendingTabAlignment || !currentLine) return void 0;
80927
+ if (segmentWidth < 0) {
80928
+ segmentWidth = 0;
80929
+ }
80544
80930
  const { target, val } = pendingTabAlignment;
80545
80931
  let startX = currentLine.width;
80932
+ if (val === "decimal") {
80933
+ const beforeWidth = beforeDecimalWidth ?? 0;
80934
+ startX = Math.max(0, target - beforeWidth);
80935
+ } else if (val === "end") {
80936
+ startX = Math.max(0, target - segmentWidth);
80937
+ } else if (val === "center") {
80938
+ startX = Math.max(0, target - segmentWidth / 2);
80939
+ } else {
80940
+ startX = Math.max(0, target);
80941
+ }
80942
+ currentLine.width = roundValue(startX);
80943
+ lastAppliedTabAlign = { target, val };
80944
+ pendingTabAlignment = null;
80945
+ return startX;
80946
+ };
80947
+ const alignSegmentAtTab = (segmentText, font, runContext) => {
80948
+ if (!pendingTabAlignment || !currentLine) return void 0;
80949
+ const { val } = pendingTabAlignment;
80950
+ let segmentWidth = 0;
80951
+ let beforeDecimalWidth;
80546
80952
  if (val === "decimal") {
80547
80953
  const idx = segmentText.indexOf(decimalSeparator);
80548
80954
  if (idx >= 0) {
80549
80955
  const beforeText = segmentText.slice(0, idx);
80550
- const beforeWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
80551
- startX = Math.max(0, target - beforeWidth);
80552
- } else {
80553
- startX = Math.max(0, target);
80956
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
80554
80957
  }
80958
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
80555
80959
  } else if (val === "end" || val === "center") {
80556
- const segWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
80557
- startX = val === "end" ? Math.max(0, target - segWidth) : Math.max(0, target - segWidth / 2);
80558
- } else if (val === "start" || val === "bar") {
80559
- startX = Math.max(0, target);
80960
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
80560
80961
  }
80561
- currentLine.width = roundValue(startX);
80562
- lastAppliedTabAlign = { target, val };
80563
- pendingTabAlignment = null;
80962
+ return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
80564
80963
  };
80565
80964
  const runsToProcess = [];
80566
80965
  for (const run2 of block.runs) {
@@ -80709,6 +81108,10 @@ ${l}
80709
81108
  const topSpace = run2.distTop ?? 0;
80710
81109
  const bottomSpace = run2.distBottom ?? 0;
80711
81110
  const imageHeight = run2.height + topSpace + bottomSpace;
81111
+ let imageStartX;
81112
+ if (pendingTabAlignment && currentLine) {
81113
+ imageStartX = alignPendingTabForWidth(imageWidth);
81114
+ }
80712
81115
  if (!currentLine) {
80713
81116
  currentLine = {
80714
81117
  fromRun: runIndex,
@@ -80725,12 +81128,14 @@ ${l}
80725
81128
  runIndex,
80726
81129
  fromChar: 0,
80727
81130
  toChar: 1,
80728
- width: imageWidth
81131
+ width: imageWidth,
81132
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
80729
81133
  }
80730
81134
  ]
80731
81135
  };
80732
81136
  continue;
80733
81137
  }
81138
+ const appliedTabAlign = lastAppliedTabAlign;
80734
81139
  if (currentLine.width + imageWidth > currentLine.maxWidth && currentLine.width > 0) {
80735
81140
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
80736
81141
  const completedLine = {
@@ -80741,6 +81146,7 @@ ${l}
80741
81146
  lines.push(completedLine);
80742
81147
  tabStopCursor = 0;
80743
81148
  pendingTabAlignment = null;
81149
+ lastAppliedTabAlign = null;
80744
81150
  currentLine = {
80745
81151
  fromRun: runIndex,
80746
81152
  fromChar: 0,
@@ -80768,9 +81174,15 @@ ${l}
80768
81174
  runIndex,
80769
81175
  fromChar: 0,
80770
81176
  toChar: 1,
80771
- width: imageWidth
81177
+ width: imageWidth,
81178
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
80772
81179
  });
80773
81180
  }
81181
+ const tabAlign = appliedTabAlign;
81182
+ if (tabAlign && currentLine && tabAlign.val === "end") {
81183
+ currentLine.width = roundValue(tabAlign.target);
81184
+ }
81185
+ lastAppliedTabAlign = null;
80774
81186
  continue;
80775
81187
  }
80776
81188
  if (!("text" in run2) || !("fontSize" in run2)) {
@@ -80786,8 +81198,10 @@ ${l}
80786
81198
  const words = segment.split(" ");
80787
81199
  let segmentStartX;
80788
81200
  if (currentLine && pendingTabAlignment) {
80789
- alignSegmentAtTab(segment, font, run2);
80790
- segmentStartX = currentLine.width;
81201
+ segmentStartX = alignSegmentAtTab(segment, font, run2);
81202
+ if (segmentStartX == null) {
81203
+ segmentStartX = currentLine.width;
81204
+ }
80791
81205
  }
80792
81206
  for (let wordIndex = 0; wordIndex < words.length; wordIndex++) {
80793
81207
  const word = words[wordIndex];
@@ -81428,12 +81842,49 @@ ${l}
81428
81842
  editor,
81429
81843
  data,
81430
81844
  editorContainer,
81431
- appendToBody = true,
81845
+ editorHost,
81432
81846
  sectionId,
81433
81847
  type: type2,
81848
+ availableWidth,
81434
81849
  availableHeight,
81435
- currentPageNumber
81850
+ currentPageNumber,
81851
+ totalPageCount
81436
81852
  }) => {
81853
+ if (!editor) {
81854
+ throw new TypeError("editor parameter is required");
81855
+ }
81856
+ if (!data) {
81857
+ throw new TypeError("data parameter is required");
81858
+ }
81859
+ if (!editorContainer) {
81860
+ throw new TypeError("editorContainer parameter is required");
81861
+ }
81862
+ if (!(editorContainer instanceof HTMLElement)) {
81863
+ throw new TypeError("editorContainer must be an HTMLElement");
81864
+ }
81865
+ if (editorHost !== void 0 && !(editorHost instanceof HTMLElement)) {
81866
+ throw new TypeError("editorHost must be an HTMLElement or undefined");
81867
+ }
81868
+ if (availableWidth !== void 0) {
81869
+ if (typeof availableWidth !== "number" || !Number.isFinite(availableWidth) || availableWidth <= 0) {
81870
+ throw new RangeError("availableWidth must be a positive number");
81871
+ }
81872
+ }
81873
+ if (availableHeight !== void 0) {
81874
+ if (typeof availableHeight !== "number" || !Number.isFinite(availableHeight) || availableHeight <= 0) {
81875
+ throw new RangeError("availableHeight must be a positive number");
81876
+ }
81877
+ }
81878
+ if (currentPageNumber !== void 0) {
81879
+ if (typeof currentPageNumber !== "number" || !Number.isInteger(currentPageNumber) || currentPageNumber < 1) {
81880
+ throw new RangeError("currentPageNumber must be a positive integer");
81881
+ }
81882
+ }
81883
+ if (totalPageCount !== void 0) {
81884
+ if (typeof totalPageCount !== "number" || !Number.isInteger(totalPageCount) || totalPageCount < 1) {
81885
+ throw new RangeError("totalPageCount must be a positive integer");
81886
+ }
81887
+ }
81437
81888
  const parentStyles = editor.converter.getDocumentDefaultStyles();
81438
81889
  const { fontSizePt, typeface, fontFamilyCss } = parentStyles;
81439
81890
  const fontSizeInPixles = fontSizePt * 1.3333;
@@ -81447,21 +81898,24 @@ ${l}
81447
81898
  position: "absolute",
81448
81899
  top: "0",
81449
81900
  left: "0",
81450
- width: "auto",
81901
+ width: availableWidth ? `${availableWidth}px` : "100%",
81902
+ height: availableHeight ? `${availableHeight}px` : "auto",
81451
81903
  maxWidth: "none",
81452
81904
  fontFamily: fontFamilyCss || typeface,
81453
81905
  fontSize: `${fontSizeInPixles}px`,
81454
- lineHeight: `${lineHeight2}px`
81455
- });
81456
- Object.assign(editorContainer.style, {
81457
- padding: "0",
81458
- margin: "0",
81459
- border: "none",
81460
- boxSizing: "border-box",
81461
- height: availableHeight + "px",
81462
- overflow: "hidden"
81463
- });
81464
- if (appendToBody) document.body.appendChild(editorContainer);
81906
+ lineHeight: `${lineHeight2}px`,
81907
+ overflow: "hidden",
81908
+ pointerEvents: "auto",
81909
+ // Critical: enables click interaction
81910
+ backgroundColor: "white"
81911
+ // Ensure editor has white background
81912
+ });
81913
+ if (editorHost) {
81914
+ editorHost.appendChild(editorContainer);
81915
+ } else {
81916
+ console.warn("[createHeaderFooterEditor] No editorHost provided, falling back to document.body");
81917
+ document.body.appendChild(editorContainer);
81918
+ }
81465
81919
  const headerFooterEditor = new Editor({
81466
81920
  role: editor.options.role,
81467
81921
  loadFromSchema: true,
@@ -81479,9 +81933,12 @@ ${l}
81479
81933
  pagination: false,
81480
81934
  // Explicitly disable pagination
81481
81935
  annotations: true,
81482
- currentPageNumber,
81936
+ currentPageNumber: currentPageNumber ?? 1,
81937
+ totalPageCount: totalPageCount ?? 1,
81483
81938
  // Don't set parentEditor to avoid circular reference issues
81484
81939
  // parentEditor: editor,
81940
+ // IMPORTANT: Start with editable: false to prevent triggering update cascades during creation.
81941
+ // PresentationEditor#enterHeaderFooterMode will call setEditable(true) when entering edit mode.
81485
81942
  editable: false,
81486
81943
  documentMode: "viewing",
81487
81944
  onCreate: (evt) => setEditorToolbar(evt, editor),
@@ -81511,18 +81968,23 @@ ${l}
81511
81968
  const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sectionId, type2) => {
81512
81969
  if (!type2 || !sectionId) return;
81513
81970
  const updatedData = editor.getUpdatedJson();
81514
- mainEditor.converter[`${type2}Editors`].forEach((item) => {
81515
- if (item.id === sectionId) {
81971
+ const editorsList = mainEditor.converter[`${type2}Editors`];
81972
+ if (Array.isArray(editorsList)) {
81973
+ editorsList.forEach((item) => {
81974
+ if (item.id === sectionId) {
81975
+ item.editor.setOptions({
81976
+ media: editor.options.media,
81977
+ mediaFiles: editor.options.mediaFiles
81978
+ });
81979
+ if (item.editor !== editor) {
81980
+ item.editor.replaceContent(updatedData);
81981
+ }
81982
+ }
81516
81983
  item.editor.setOptions({
81517
- media: editor.options.media,
81518
- mediaFiles: editor.options.mediaFiles
81984
+ lastSelection: transaction?.selection
81519
81985
  });
81520
- item.editor.replaceContent(updatedData);
81521
- }
81522
- item.editor.setOptions({
81523
- lastSelection: transaction?.selection
81524
81986
  });
81525
- });
81987
+ }
81526
81988
  mainEditor.converter[`${type2}s`][sectionId] = updatedData;
81527
81989
  mainEditor.setOptions({ isHeaderFooterChanged: editor.docChanged });
81528
81990
  await updateYdocDocxData(mainEditor);
@@ -81603,13 +82065,69 @@ ${l}
81603
82065
  * Handles concurrent calls for the same descriptor by tracking pending creations
81604
82066
  * and returning the same promise to all callers.
81605
82067
  *
81606
- * @param descriptor - The header or footer descriptor
82068
+ * @param descriptor - The header or footer descriptor. Must have a valid id property.
82069
+ * @param options - Optional configuration for editor creation
82070
+ * @param options.editorHost - The HTMLElement to mount the editor in. If provided, must be a valid HTMLElement.
82071
+ * @param options.availableWidth - The width of the editing region in pixels. Must be a positive number if provided.
82072
+ * @param options.availableHeight - The height of the editing region in pixels. Must be a positive number if provided.
82073
+ * @param options.currentPageNumber - The current page number for PAGE field resolution. Must be a positive integer if provided.
82074
+ * @param options.totalPageCount - The total page count for NUMPAGES field resolution. Must be a positive integer if provided.
81607
82075
  * @returns The editor instance, or null if creation failed
81608
82076
  *
81609
- * @throws Never throws - errors are logged and emitted as events
82077
+ * @throws Never throws - errors are logged and emitted as events. Invalid parameters return null with error logged.
81610
82078
  */
81611
- async ensureEditor(descriptor) {
82079
+ async ensureEditor(descriptor, options) {
81612
82080
  if (!descriptor?.id) return null;
82081
+ if (options) {
82082
+ if (options.editorHost !== void 0 && !(options.editorHost instanceof HTMLElement)) {
82083
+ console.error("[HeaderFooterEditorManager] editorHost must be an HTMLElement");
82084
+ this.emit("error", {
82085
+ descriptor,
82086
+ error: new TypeError("editorHost must be an HTMLElement")
82087
+ });
82088
+ return null;
82089
+ }
82090
+ if (options.availableWidth !== void 0) {
82091
+ if (typeof options.availableWidth !== "number" || !Number.isFinite(options.availableWidth) || options.availableWidth <= 0) {
82092
+ console.error("[HeaderFooterEditorManager] availableWidth must be a positive number");
82093
+ this.emit("error", {
82094
+ descriptor,
82095
+ error: new TypeError("availableWidth must be a positive number")
82096
+ });
82097
+ return null;
82098
+ }
82099
+ }
82100
+ if (options.availableHeight !== void 0) {
82101
+ if (typeof options.availableHeight !== "number" || !Number.isFinite(options.availableHeight) || options.availableHeight <= 0) {
82102
+ console.error("[HeaderFooterEditorManager] availableHeight must be a positive number");
82103
+ this.emit("error", {
82104
+ descriptor,
82105
+ error: new TypeError("availableHeight must be a positive number")
82106
+ });
82107
+ return null;
82108
+ }
82109
+ }
82110
+ if (options.currentPageNumber !== void 0) {
82111
+ if (typeof options.currentPageNumber !== "number" || !Number.isInteger(options.currentPageNumber) || options.currentPageNumber < 1) {
82112
+ console.error("[HeaderFooterEditorManager] currentPageNumber must be a positive integer");
82113
+ this.emit("error", {
82114
+ descriptor,
82115
+ error: new TypeError("currentPageNumber must be a positive integer")
82116
+ });
82117
+ return null;
82118
+ }
82119
+ }
82120
+ if (options.totalPageCount !== void 0) {
82121
+ if (typeof options.totalPageCount !== "number" || !Number.isInteger(options.totalPageCount) || options.totalPageCount < 1) {
82122
+ console.error("[HeaderFooterEditorManager] totalPageCount must be a positive integer");
82123
+ this.emit("error", {
82124
+ descriptor,
82125
+ error: new TypeError("totalPageCount must be a positive integer")
82126
+ });
82127
+ return null;
82128
+ }
82129
+ }
82130
+ }
81613
82131
  const existing = __privateGet$1(this, _editorEntries).get(descriptor.id);
81614
82132
  if (existing) {
81615
82133
  __privateSet(this, _cacheHits, __privateGet$1(this, _cacheHits) + 1);
@@ -81618,6 +82136,29 @@ ${l}
81618
82136
  console.error("[HeaderFooterEditorManager] Editor initialization failed:", error);
81619
82137
  this.emit("error", { descriptor, error });
81620
82138
  });
82139
+ if (existing.container && options?.editorHost) {
82140
+ if (existing.container.parentElement !== options.editorHost) {
82141
+ options.editorHost.appendChild(existing.container);
82142
+ }
82143
+ }
82144
+ if (existing.editor && options) {
82145
+ const updateOptions = {};
82146
+ if (options.currentPageNumber !== void 0) {
82147
+ updateOptions.currentPageNumber = options.currentPageNumber;
82148
+ }
82149
+ if (options.totalPageCount !== void 0) {
82150
+ updateOptions.totalPageCount = options.totalPageCount;
82151
+ }
82152
+ if (options.availableWidth !== void 0) {
82153
+ updateOptions.availableWidth = options.availableWidth;
82154
+ }
82155
+ if (options.availableHeight !== void 0) {
82156
+ updateOptions.availableHeight = options.availableHeight;
82157
+ }
82158
+ if (Object.keys(updateOptions).length > 0) {
82159
+ existing.editor.setOptions(updateOptions);
82160
+ }
82161
+ }
81621
82162
  return existing.editor;
81622
82163
  }
81623
82164
  const pending = __privateGet$1(this, _pendingCreations).get(descriptor.id);
@@ -81627,7 +82168,7 @@ ${l}
81627
82168
  __privateSet(this, _cacheMisses, __privateGet$1(this, _cacheMisses) + 1);
81628
82169
  const creationPromise = (async () => {
81629
82170
  try {
81630
- const entry = await __privateMethod$1(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor);
82171
+ const entry = await __privateMethod$1(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor, options);
81631
82172
  if (!entry) return null;
81632
82173
  __privateGet$1(this, _editorEntries).set(descriptor.id, entry);
81633
82174
  __privateMethod$1(this, _HeaderFooterEditorManager_instances, updateAccessOrder_fn).call(this, descriptor.id);
@@ -81935,7 +82476,7 @@ ${l}
81935
82476
  });
81936
82477
  __privateGet$1(this, _editorEntries).clear();
81937
82478
  };
81938
- createEditor_fn = async function(descriptor) {
82479
+ createEditor_fn = async function(descriptor, options) {
81939
82480
  const json = this.getDocumentJson(descriptor);
81940
82481
  if (!json) return null;
81941
82482
  let editor;
@@ -81946,12 +82487,13 @@ ${l}
81946
82487
  editor: __privateGet$1(this, _editor2),
81947
82488
  data: json,
81948
82489
  editorContainer: container,
81949
- appendToBody: true,
82490
+ editorHost: options?.editorHost,
81950
82491
  sectionId: descriptor.id,
81951
82492
  type: descriptor.kind,
81952
- availableHeight: DEFAULT_HEADER_FOOTER_HEIGHT,
81953
- currentPageNumber: 1
81954
- // Default page number
82493
+ availableWidth: options?.availableWidth,
82494
+ availableHeight: options?.availableHeight ?? DEFAULT_HEADER_FOOTER_HEIGHT,
82495
+ currentPageNumber: options?.currentPageNumber ?? 1,
82496
+ totalPageCount: options?.totalPageCount ?? 1
81955
82497
  });
81956
82498
  } catch (error) {
81957
82499
  console.error("[HeaderFooterEditorManager] Editor creation failed:", error);
@@ -82225,6 +82767,312 @@ ${l}
82225
82767
  }
82226
82768
  return Object.keys(context).length > 0 ? context : void 0;
82227
82769
  };
82770
+ const EDITOR_HOST_Z_INDEX = "10";
82771
+ const BORDER_LINE_Z_INDEX = "15";
82772
+ const BORDER_LINE_COLOR = "#4472c4";
82773
+ const BORDER_LINE_HEIGHT = "1px";
82774
+ class EditorOverlayManager {
82775
+ /**
82776
+ * Creates a new EditorOverlayManager instance.
82777
+ *
82778
+ * @param painterHost - The host element containing painted pages. Must be an HTMLElement connected to the DOM.
82779
+ * @param visibleHost - The visible host element for overlay positioning. Must be an HTMLElement connected to the DOM.
82780
+ * @param selectionOverlay - The selection overlay element (optional). If provided, must be an HTMLElement.
82781
+ *
82782
+ * @throws {TypeError} If painterHost is not an HTMLElement
82783
+ * @throws {TypeError} If visibleHost is not an HTMLElement
82784
+ * @throws {TypeError} If selectionOverlay is provided but is not an HTMLElement
82785
+ * @throws {Error} If painterHost is not connected to the DOM
82786
+ * @throws {Error} If visibleHost is not connected to the DOM
82787
+ */
82788
+ constructor(painterHost, visibleHost, selectionOverlay = null) {
82789
+ __privateAdd$1(this, _EditorOverlayManager_instances);
82790
+ __privateAdd$1(this, _selectionOverlay);
82791
+ __privateAdd$1(this, _activeEditorHost, null);
82792
+ __privateAdd$1(this, _activeDecorationContainer, null);
82793
+ __privateAdd$1(this, _activeRegion, null);
82794
+ __privateAdd$1(this, _borderLine, null);
82795
+ if (!(painterHost instanceof HTMLElement)) {
82796
+ throw new TypeError("painterHost must be an HTMLElement");
82797
+ }
82798
+ if (!(visibleHost instanceof HTMLElement)) {
82799
+ throw new TypeError("visibleHost must be an HTMLElement");
82800
+ }
82801
+ if (selectionOverlay !== null && !(selectionOverlay instanceof HTMLElement)) {
82802
+ throw new TypeError("selectionOverlay must be an HTMLElement or null");
82803
+ }
82804
+ if (!painterHost.isConnected) {
82805
+ throw new Error("painterHost must be connected to the DOM");
82806
+ }
82807
+ if (!visibleHost.isConnected) {
82808
+ throw new Error("visibleHost must be connected to the DOM");
82809
+ }
82810
+ __privateSet(this, _selectionOverlay, selectionOverlay);
82811
+ }
82812
+ /**
82813
+ * Sets the callback to be invoked when the dimming overlay is clicked.
82814
+ * This allows PresentationEditor to exit header/footer mode when the user
82815
+ * clicks outside the editing region.
82816
+ *
82817
+ * @param callback - Function to call when dimming overlay is clicked
82818
+ */
82819
+ setOnDimmingClick(_callback) {
82820
+ }
82821
+ /**
82822
+ * Gets the currently active editor host element.
82823
+ * This is useful for checking if a click target is inside the active editing area.
82824
+ *
82825
+ * @returns The active editor host element, or null if not in editing mode
82826
+ */
82827
+ getActiveEditorHost() {
82828
+ return __privateGet$1(this, _activeEditorHost);
82829
+ }
82830
+ /**
82831
+ * Shows the editing overlay for a header/footer region.
82832
+ *
82833
+ * This method:
82834
+ * 1. Creates or retrieves the editor host element as a sibling to the decoration container
82835
+ * 2. Positions the editor host to match the decoration container bounds
82836
+ * 3. Hides the static decoration content
82837
+ * 4. Shows the dimming overlay over body content
82838
+ * 5. Returns the editor host element for mounting the ProseMirror editor
82839
+ *
82840
+ * @param pageElement - The page DOM element containing the region
82841
+ * @param region - The header/footer region to edit
82842
+ * @param zoom - Current zoom level (for positioning calculations)
82843
+ * @returns Result object with success status and editor host element
82844
+ *
82845
+ * @example
82846
+ * ```typescript
82847
+ * const result = overlayManager.showEditingOverlay(pageElement, region, 1.0);
82848
+ * if (result.success && result.editorHost) {
82849
+ * // Mount ProseMirror editor in result.editorHost
82850
+ * }
82851
+ * ```
82852
+ */
82853
+ showEditingOverlay(pageElement, region, zoom) {
82854
+ try {
82855
+ const decorationContainer = __privateMethod$1(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, region.kind);
82856
+ if (!decorationContainer) {
82857
+ return {
82858
+ success: false,
82859
+ reason: `Decoration container not found for ${region.kind} on page ${region.pageIndex}`
82860
+ };
82861
+ }
82862
+ const editorHost = __privateMethod$1(this, _EditorOverlayManager_instances, ensureEditorHost_fn).call(this, pageElement, region.kind);
82863
+ if (!editorHost) {
82864
+ return {
82865
+ success: false,
82866
+ reason: `Failed to create editor host for ${region.kind}`
82867
+ };
82868
+ }
82869
+ __privateMethod$1(this, _EditorOverlayManager_instances, positionEditorHost_fn).call(this, editorHost, region, decorationContainer, zoom);
82870
+ decorationContainer.style.visibility = "hidden";
82871
+ editorHost.style.visibility = "visible";
82872
+ editorHost.style.zIndex = EDITOR_HOST_Z_INDEX;
82873
+ if (region.kind === "footer") {
82874
+ const contentOffset = editorHost.dataset.contentOffset;
82875
+ if (contentOffset) {
82876
+ const editorContainer = editorHost.querySelector(".super-editor");
82877
+ if (editorContainer instanceof HTMLElement) {
82878
+ editorContainer.style.top = `${contentOffset}px`;
82879
+ }
82880
+ }
82881
+ }
82882
+ __privateMethod$1(this, _EditorOverlayManager_instances, showHeaderFooterBorder_fn).call(this, pageElement, region, decorationContainer);
82883
+ __privateSet(this, _activeEditorHost, editorHost);
82884
+ __privateSet(this, _activeDecorationContainer, decorationContainer);
82885
+ __privateSet(this, _activeRegion, region);
82886
+ return {
82887
+ success: true,
82888
+ editorHost
82889
+ };
82890
+ } catch (error) {
82891
+ if (__privateGet$1(this, _activeDecorationContainer)) {
82892
+ __privateGet$1(this, _activeDecorationContainer).style.visibility = "visible";
82893
+ }
82894
+ if (__privateGet$1(this, _activeEditorHost)) {
82895
+ __privateGet$1(this, _activeEditorHost).style.visibility = "hidden";
82896
+ }
82897
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
82898
+ const errorMessage = error instanceof Error ? error.message : String(error);
82899
+ console.error("[EditorOverlayManager] Failed to show editing overlay:", error);
82900
+ return {
82901
+ success: false,
82902
+ reason: `DOM manipulation error: ${errorMessage}`
82903
+ };
82904
+ }
82905
+ }
82906
+ /**
82907
+ * Hides the editing overlay and restores normal view.
82908
+ *
82909
+ * This method:
82910
+ * 1. Shows the static decoration content
82911
+ * 2. Hides the editor host (but doesn't destroy it for reuse)
82912
+ * 3. Removes the dimming overlay
82913
+ *
82914
+ * @example
82915
+ * ```typescript
82916
+ * overlayManager.hideEditingOverlay();
82917
+ * // Static decoration is now visible, editor is hidden
82918
+ * ```
82919
+ */
82920
+ hideEditingOverlay() {
82921
+ if (__privateGet$1(this, _activeDecorationContainer)) {
82922
+ __privateGet$1(this, _activeDecorationContainer).style.visibility = "visible";
82923
+ }
82924
+ if (__privateGet$1(this, _activeEditorHost)) {
82925
+ __privateGet$1(this, _activeEditorHost).style.visibility = "hidden";
82926
+ __privateGet$1(this, _activeEditorHost).style.zIndex = "";
82927
+ if (__privateGet$1(this, _activeRegion)?.kind === "footer") {
82928
+ const editorContainer = __privateGet$1(this, _activeEditorHost).querySelector(".super-editor");
82929
+ if (editorContainer instanceof HTMLElement) {
82930
+ editorContainer.style.top = "0";
82931
+ }
82932
+ }
82933
+ }
82934
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
82935
+ __privateSet(this, _activeEditorHost, null);
82936
+ __privateSet(this, _activeDecorationContainer, null);
82937
+ __privateSet(this, _activeRegion, null);
82938
+ }
82939
+ /**
82940
+ * Hides the layout selection overlay to prevent double caret rendering.
82941
+ *
82942
+ * Called when entering header/footer editing mode to ensure only the
82943
+ * ProseMirror editor's caret is visible, not both the PM caret and the
82944
+ * layout engine's selection overlay.
82945
+ *
82946
+ * @example
82947
+ * ```typescript
82948
+ * overlayManager.hideSelectionOverlay();
82949
+ * // Selection overlay is now hidden
82950
+ * ```
82951
+ */
82952
+ hideSelectionOverlay() {
82953
+ if (__privateGet$1(this, _selectionOverlay)) {
82954
+ __privateGet$1(this, _selectionOverlay).style.visibility = "hidden";
82955
+ }
82956
+ }
82957
+ /**
82958
+ * Shows the layout selection overlay.
82959
+ *
82960
+ * Called when exiting header/footer editing mode to restore the
82961
+ * normal selection overlay rendering for body content.
82962
+ *
82963
+ * @example
82964
+ * ```typescript
82965
+ * overlayManager.showSelectionOverlay();
82966
+ * // Selection overlay is now visible
82967
+ * ```
82968
+ */
82969
+ showSelectionOverlay() {
82970
+ if (__privateGet$1(this, _selectionOverlay)) {
82971
+ __privateGet$1(this, _selectionOverlay).style.visibility = "visible";
82972
+ }
82973
+ }
82974
+ /**
82975
+ * Destroys the overlay manager and cleans up all resources.
82976
+ *
82977
+ * Clears all references.
82978
+ * Editor host elements are left in the DOM as they're children of page elements
82979
+ * that will be cleaned up by the virtualization system.
82980
+ */
82981
+ destroy() {
82982
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
82983
+ __privateSet(this, _activeEditorHost, null);
82984
+ __privateSet(this, _activeDecorationContainer, null);
82985
+ __privateSet(this, _activeRegion, null);
82986
+ __privateSet(this, _selectionOverlay, null);
82987
+ }
82988
+ }
82989
+ _selectionOverlay = /* @__PURE__ */ new WeakMap();
82990
+ _activeEditorHost = /* @__PURE__ */ new WeakMap();
82991
+ _activeDecorationContainer = /* @__PURE__ */ new WeakMap();
82992
+ _activeRegion = /* @__PURE__ */ new WeakMap();
82993
+ _borderLine = /* @__PURE__ */ new WeakMap();
82994
+ _EditorOverlayManager_instances = /* @__PURE__ */ new WeakSet();
82995
+ findDecorationContainer_fn = function(pageElement, kind) {
82996
+ const className = kind === "header" ? "superdoc-page-header" : "superdoc-page-footer";
82997
+ return pageElement.querySelector(`.${className}`);
82998
+ };
82999
+ ensureEditorHost_fn = function(pageElement, kind) {
83000
+ const className = kind === "header" ? "superdoc-header-editor-host" : "superdoc-footer-editor-host";
83001
+ let editorHost = pageElement.querySelector(`.${className}`);
83002
+ if (!editorHost) {
83003
+ editorHost = document.createElement("div");
83004
+ editorHost.className = className;
83005
+ Object.assign(editorHost.style, {
83006
+ position: "absolute",
83007
+ pointerEvents: "auto",
83008
+ // Critical: enables click interaction
83009
+ visibility: "hidden",
83010
+ // Hidden by default, shown during editing
83011
+ overflow: "hidden",
83012
+ boxSizing: "border-box"
83013
+ });
83014
+ const decorationContainer = __privateMethod$1(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, kind);
83015
+ if (!decorationContainer) {
83016
+ console.error(`[EditorOverlayManager] Decoration container not found for ${kind}`);
83017
+ return null;
83018
+ }
83019
+ decorationContainer.parentNode?.insertBefore(editorHost, decorationContainer.nextSibling);
83020
+ }
83021
+ return editorHost;
83022
+ };
83023
+ positionEditorHost_fn = function(editorHost, region, decorationContainer, _zoom) {
83024
+ const decorationRect = decorationContainer.getBoundingClientRect();
83025
+ const pageElement = editorHost.parentElement;
83026
+ if (!pageElement) {
83027
+ console.error("[EditorOverlayManager] Editor host has no parent element");
83028
+ return;
83029
+ }
83030
+ const pageRect = pageElement.getBoundingClientRect();
83031
+ const top2 = decorationRect.top - pageRect.top;
83032
+ const left2 = decorationRect.left - pageRect.left;
83033
+ const width = decorationRect.width;
83034
+ const height = decorationRect.height;
83035
+ Object.assign(editorHost.style, {
83036
+ top: `${top2}px`,
83037
+ left: `${left2}px`,
83038
+ width: `${width}px`,
83039
+ height: `${height}px`
83040
+ });
83041
+ if (region.kind === "footer") {
83042
+ const fragment = decorationContainer.querySelector(".superdoc-fragment");
83043
+ if (fragment instanceof HTMLElement) {
83044
+ const fragmentTop = parseFloat(fragment.style.top) || 0;
83045
+ editorHost.dataset.contentOffset = String(fragmentTop);
83046
+ }
83047
+ }
83048
+ };
83049
+ showHeaderFooterBorder_fn = function(pageElement, region, decorationContainer) {
83050
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
83051
+ __privateSet(this, _borderLine, document.createElement("div"));
83052
+ __privateGet$1(this, _borderLine).className = "superdoc-header-footer-border";
83053
+ const decorationRect = decorationContainer.getBoundingClientRect();
83054
+ const pageRect = pageElement.getBoundingClientRect();
83055
+ const isHeader = region.kind === "header";
83056
+ const topPosition = isHeader ? decorationRect.bottom - pageRect.top : decorationRect.top - pageRect.top;
83057
+ Object.assign(__privateGet$1(this, _borderLine).style, {
83058
+ position: "absolute",
83059
+ left: "0",
83060
+ right: "0",
83061
+ top: `${topPosition}px`,
83062
+ height: BORDER_LINE_HEIGHT,
83063
+ backgroundColor: BORDER_LINE_COLOR,
83064
+ // MS Word blue
83065
+ zIndex: BORDER_LINE_Z_INDEX,
83066
+ pointerEvents: "none"
83067
+ });
83068
+ pageElement.appendChild(__privateGet$1(this, _borderLine));
83069
+ };
83070
+ hideHeaderFooterBorder_fn = function() {
83071
+ if (__privateGet$1(this, _borderLine)) {
83072
+ __privateGet$1(this, _borderLine).remove();
83073
+ __privateSet(this, _borderLine, null);
83074
+ }
83075
+ };
82228
83076
  const uiSurfaces = /* @__PURE__ */ new WeakSet();
82229
83077
  function isInRegisteredSurface(event) {
82230
83078
  const path2 = typeof event.composedPath === "function" ? event.composedPath() : [];
@@ -82263,7 +83111,7 @@ ${l}
82263
83111
  __privateAdd$1(this, _visibleHost);
82264
83112
  __privateAdd$1(this, _viewportHost);
82265
83113
  __privateAdd$1(this, _painterHost);
82266
- __privateAdd$1(this, _selectionOverlay);
83114
+ __privateAdd$1(this, _selectionOverlay2);
82267
83115
  __privateAdd$1(this, _hiddenHost);
82268
83116
  __privateAdd$1(this, _layoutOptions);
82269
83117
  __privateAdd$1(this, _layoutState, { blocks: [], measures: [], layout: null });
@@ -82298,6 +83146,7 @@ ${l}
82298
83146
  __privateAdd$1(this, _footerRegions, /* @__PURE__ */ new Map());
82299
83147
  __privateAdd$1(this, _session, { mode: "body" });
82300
83148
  __privateAdd$1(this, _activeHeaderFooterEditor, null);
83149
+ __privateAdd$1(this, _overlayManager, null);
82301
83150
  __privateAdd$1(this, _hoverOverlay, null);
82302
83151
  __privateAdd$1(this, _hoverTooltip, null);
82303
83152
  __privateAdd$1(this, _modeBanner, null);
@@ -82352,6 +83201,11 @@ ${l}
82352
83201
  const x2 = (event.clientX - rect.left + scrollLeft) / zoom;
82353
83202
  const y2 = (event.clientY - rect.top + scrollTop) / zoom;
82354
83203
  if (__privateGet$1(this, _session).mode !== "body") {
83204
+ const activeEditorHost = __privateGet$1(this, _overlayManager)?.getActiveEditorHost?.();
83205
+ const clickedInsideEditorHost = activeEditorHost && (activeEditorHost.contains(event.target) || activeEditorHost === event.target);
83206
+ if (clickedInsideEditorHost) {
83207
+ return;
83208
+ }
82355
83209
  const headerFooterRegion2 = __privateMethod$1(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, x2, y2);
82356
83210
  if (!headerFooterRegion2) {
82357
83211
  __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -82506,6 +83360,11 @@ ${l}
82506
83360
  if (region) {
82507
83361
  event.preventDefault();
82508
83362
  event.stopPropagation();
83363
+ const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
83364
+ if (!descriptor && __privateGet$1(this, _headerFooterManager)) {
83365
+ __privateMethod$1(this, _PresentationEditor_instances, createDefaultHeaderFooter_fn).call(this, region);
83366
+ __privateGet$1(this, _headerFooterManager).refresh();
83367
+ }
82509
83368
  __privateMethod$1(this, _PresentationEditor_instances, activateHeaderFooterRegion_fn).call(this, region);
82510
83369
  } else if (__privateGet$1(this, _session).mode !== "body") {
82511
83370
  __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -82574,13 +83433,13 @@ ${l}
82574
83433
  __privateGet$1(this, _painterHost).className = "presentation-editor__pages";
82575
83434
  __privateGet$1(this, _painterHost).style.transformOrigin = "top left";
82576
83435
  __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _painterHost));
82577
- __privateSet(this, _selectionOverlay, doc2.createElement("div"));
82578
- __privateGet$1(this, _selectionOverlay).className = "presentation-editor__selection-overlay";
82579
- __privateGet$1(this, _selectionOverlay).id = `presentation-overlay-${options.documentId || "default"}`;
82580
- __privateGet$1(this, _selectionOverlay).style.position = "absolute";
82581
- __privateGet$1(this, _selectionOverlay).style.inset = "0";
82582
- __privateGet$1(this, _selectionOverlay).style.pointerEvents = "none";
82583
- __privateGet$1(this, _selectionOverlay).style.zIndex = "10";
83436
+ __privateSet(this, _selectionOverlay2, doc2.createElement("div"));
83437
+ __privateGet$1(this, _selectionOverlay2).className = "presentation-editor__selection-overlay";
83438
+ __privateGet$1(this, _selectionOverlay2).id = `presentation-overlay-${options.documentId || "default"}`;
83439
+ __privateGet$1(this, _selectionOverlay2).style.position = "absolute";
83440
+ __privateGet$1(this, _selectionOverlay2).style.inset = "0";
83441
+ __privateGet$1(this, _selectionOverlay2).style.pointerEvents = "none";
83442
+ __privateGet$1(this, _selectionOverlay2).style.zIndex = "10";
82584
83443
  __privateSet(this, _remoteCursorOverlay, doc2.createElement("div"));
82585
83444
  __privateGet$1(this, _remoteCursorOverlay).className = "presentation-editor__selection-layer--remote";
82586
83445
  __privateGet$1(this, _remoteCursorOverlay).style.position = "absolute";
@@ -82591,9 +83450,9 @@ ${l}
82591
83450
  __privateGet$1(this, _localSelectionLayer).style.position = "absolute";
82592
83451
  __privateGet$1(this, _localSelectionLayer).style.inset = "0";
82593
83452
  __privateGet$1(this, _localSelectionLayer).style.pointerEvents = "none";
82594
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _remoteCursorOverlay));
82595
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _localSelectionLayer));
82596
- __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _selectionOverlay));
83453
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _remoteCursorOverlay));
83454
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _localSelectionLayer));
83455
+ __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _selectionOverlay2));
82597
83456
  __privateSet(this, _hoverOverlay, doc2.createElement("div"));
82598
83457
  __privateGet$1(this, _hoverOverlay).className = "presentation-editor__hover-overlay";
82599
83458
  Object.assign(__privateGet$1(this, _hoverOverlay).style, {
@@ -82604,7 +83463,7 @@ ${l}
82604
83463
  display: "none",
82605
83464
  zIndex: "11"
82606
83465
  });
82607
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _hoverOverlay));
83466
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _hoverOverlay));
82608
83467
  __privateSet(this, _hoverTooltip, doc2.createElement("div"));
82609
83468
  __privateGet$1(this, _hoverTooltip).className = "presentation-editor__hover-tooltip";
82610
83469
  Object.assign(__privateGet$1(this, _hoverTooltip).style, {
@@ -82619,7 +83478,7 @@ ${l}
82619
83478
  zIndex: "12",
82620
83479
  whiteSpace: "nowrap"
82621
83480
  });
82622
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _hoverTooltip));
83481
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _hoverTooltip));
82623
83482
  __privateSet(this, _modeBanner, doc2.createElement("div"));
82624
83483
  __privateGet$1(this, _modeBanner).className = "presentation-editor__mode-banner";
82625
83484
  Object.assign(__privateGet$1(this, _modeBanner).style, {
@@ -82837,7 +83696,7 @@ ${l}
82837
83696
  * ```
82838
83697
  */
82839
83698
  get overlayElement() {
82840
- return __privateGet$1(this, _selectionOverlay) ?? null;
83699
+ return __privateGet$1(this, _selectionOverlay2) ?? null;
82841
83700
  }
82842
83701
  /**
82843
83702
  * Set the document mode and update editor editability.
@@ -83007,12 +83866,12 @@ ${l}
83007
83866
  * @returns Array of rects, each containing pageIndex and position data (left, top, right, bottom, width, height)
83008
83867
  */
83009
83868
  getRangeRects(from2, to, relativeTo) {
83010
- if (!__privateGet$1(this, _selectionOverlay)) return [];
83869
+ if (!__privateGet$1(this, _selectionOverlay2)) return [];
83011
83870
  if (!Number.isFinite(from2) || !Number.isFinite(to)) return [];
83012
83871
  const start2 = Math.min(from2, to);
83013
83872
  const end2 = Math.max(from2, to);
83014
83873
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
83015
- const overlayRect = __privateGet$1(this, _selectionOverlay).getBoundingClientRect();
83874
+ const overlayRect = __privateGet$1(this, _selectionOverlay2).getBoundingClientRect();
83016
83875
  const relativeRect = relativeTo?.getBoundingClientRect() ?? null;
83017
83876
  const layoutRectSource = () => {
83018
83877
  if (__privateGet$1(this, _session).mode !== "body") {
@@ -83273,7 +84132,7 @@ ${l}
83273
84132
  return null;
83274
84133
  }
83275
84134
  const rect2 = rects2[0];
83276
- const overlayRect = __privateGet$1(this, _selectionOverlay)?.getBoundingClientRect();
84135
+ const overlayRect = __privateGet$1(this, _selectionOverlay2)?.getBoundingClientRect();
83277
84136
  if (!overlayRect) {
83278
84137
  return null;
83279
84138
  }
@@ -83443,7 +84302,7 @@ ${l}
83443
84302
  __privateSet(this, _session, { mode: "body" });
83444
84303
  __privateSet(this, _activeHeaderFooterEditor, null);
83445
84304
  __privateSet(this, _domPainter, null);
83446
- __privateGet$1(this, _selectionOverlay)?.remove();
84305
+ __privateGet$1(this, _selectionOverlay2)?.remove();
83447
84306
  __privateGet$1(this, _painterHost)?.remove();
83448
84307
  __privateGet$1(this, _hiddenHost)?.remove();
83449
84308
  __privateSet(this, _hoverOverlay, null);
@@ -83465,7 +84324,7 @@ ${l}
83465
84324
  _visibleHost = /* @__PURE__ */ new WeakMap();
83466
84325
  _viewportHost = /* @__PURE__ */ new WeakMap();
83467
84326
  _painterHost = /* @__PURE__ */ new WeakMap();
83468
- _selectionOverlay = /* @__PURE__ */ new WeakMap();
84327
+ _selectionOverlay2 = /* @__PURE__ */ new WeakMap();
83469
84328
  _hiddenHost = /* @__PURE__ */ new WeakMap();
83470
84329
  _layoutOptions = /* @__PURE__ */ new WeakMap();
83471
84330
  _layoutState = /* @__PURE__ */ new WeakMap();
@@ -83500,6 +84359,7 @@ ${l}
83500
84359
  _footerRegions = /* @__PURE__ */ new WeakMap();
83501
84360
  _session = /* @__PURE__ */ new WeakMap();
83502
84361
  _activeHeaderFooterEditor = /* @__PURE__ */ new WeakMap();
84362
+ _overlayManager = /* @__PURE__ */ new WeakMap();
83503
84363
  _hoverOverlay = /* @__PURE__ */ new WeakMap();
83504
84364
  _hoverTooltip = /* @__PURE__ */ new WeakMap();
83505
84365
  _modeBanner = /* @__PURE__ */ new WeakMap();
@@ -83865,9 +84725,14 @@ ${l}
83865
84725
  __privateSet(this, _headerFooterManagerCleanups, []);
83866
84726
  __privateGet$1(this, _headerFooterAdapter)?.clear();
83867
84727
  __privateGet$1(this, _headerFooterManager)?.destroy();
84728
+ __privateGet$1(this, _overlayManager)?.destroy();
83868
84729
  __privateSet(this, _session, { mode: "body" });
83869
84730
  __privateSet(this, _activeHeaderFooterEditor, null);
83870
84731
  __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
84732
+ __privateSet(this, _overlayManager, new EditorOverlayManager(__privateGet$1(this, _painterHost), __privateGet$1(this, _visibleHost), __privateGet$1(this, _selectionOverlay2)));
84733
+ __privateGet$1(this, _overlayManager).setOnDimmingClick(() => {
84734
+ __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
84735
+ });
83871
84736
  const converter = __privateGet$1(this, _editor3).converter;
83872
84737
  __privateSet(this, _headerFooterIdentifier, extractIdentifierFromConverter(converter));
83873
84738
  __privateSet(this, _headerFooterManager, new HeaderFooterEditorManager(__privateGet$1(this, _editor3)));
@@ -84216,6 +85081,9 @@ ${l}
84216
85081
  });
84217
85082
  };
84218
85083
  updateSelection_fn = function() {
85084
+ if (__privateGet$1(this, _session).mode !== "body") {
85085
+ return;
85086
+ }
84219
85087
  if (!__privateGet$1(this, _localSelectionLayer)) {
84220
85088
  return;
84221
85089
  }
@@ -84225,22 +85093,6 @@ ${l}
84225
85093
  if (!selection) {
84226
85094
  return;
84227
85095
  }
84228
- if (__privateGet$1(this, _session).mode !== "body") {
84229
- if (!layout) {
84230
- return;
84231
- }
84232
- if (selection.from === selection.to) {
84233
- const caretLayout = __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterCaretRect_fn).call(this, selection.from);
84234
- if (!caretLayout) {
84235
- return;
84236
- }
84237
- __privateMethod$1(this, _PresentationEditor_instances, renderCaretOverlay_fn).call(this, caretLayout);
84238
- return;
84239
- }
84240
- const rects2 = __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterSelectionRects_fn).call(this, selection.from, selection.to);
84241
- __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, rects2);
84242
- return;
84243
- }
84244
85096
  if (!layout) {
84245
85097
  return;
84246
85098
  }
@@ -84475,46 +85327,168 @@ ${l}
84475
85327
  void __privateMethod$1(this, _PresentationEditor_instances, enterHeaderFooterMode_fn).call(this, region);
84476
85328
  };
84477
85329
  enterHeaderFooterMode_fn = async function(region) {
84478
- if (!__privateGet$1(this, _headerFooterManager)) {
84479
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
84480
- return;
84481
- }
84482
- const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
84483
- if (!descriptor) {
84484
- console.warn("[PresentationEditor] No descriptor found for region:", region);
84485
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
84486
- return;
84487
- }
84488
- if (!descriptor.id) {
84489
- console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
84490
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
84491
- return;
84492
- }
84493
- const editor = await __privateGet$1(this, _headerFooterManager).ensureEditor(descriptor);
84494
- if (!editor) {
84495
- console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
85330
+ try {
85331
+ if (!__privateGet$1(this, _headerFooterManager) || !__privateGet$1(this, _overlayManager)) {
85332
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85333
+ return;
85334
+ }
85335
+ const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
85336
+ if (!descriptor) {
85337
+ console.warn("[PresentationEditor] No descriptor found for region:", region);
85338
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85339
+ return;
85340
+ }
85341
+ if (!descriptor.id) {
85342
+ console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
85343
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85344
+ return;
85345
+ }
85346
+ let pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
85347
+ if (!pageElement) {
85348
+ try {
85349
+ __privateMethod$1(this, _PresentationEditor_instances, scrollPageIntoView_fn).call(this, region.pageIndex);
85350
+ const mounted = await __privateMethod$1(this, _PresentationEditor_instances, waitForPageMount_fn).call(this, region.pageIndex, { timeout: 2e3 });
85351
+ if (!mounted) {
85352
+ console.error("[PresentationEditor] Failed to mount page for header/footer editing");
85353
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85354
+ this.emit("error", {
85355
+ error: new Error("Failed to mount page for editing"),
85356
+ context: "enterHeaderFooterMode"
85357
+ });
85358
+ return;
85359
+ }
85360
+ pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
85361
+ } catch (scrollError) {
85362
+ console.error("[PresentationEditor] Error mounting page:", scrollError);
85363
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85364
+ this.emit("error", {
85365
+ error: scrollError,
85366
+ context: "enterHeaderFooterMode.pageMount"
85367
+ });
85368
+ return;
85369
+ }
85370
+ }
85371
+ if (!pageElement) {
85372
+ console.error("[PresentationEditor] Page element not found after mount attempt");
85373
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85374
+ this.emit("error", {
85375
+ error: new Error("Page element not found after mount"),
85376
+ context: "enterHeaderFooterMode"
85377
+ });
85378
+ return;
85379
+ }
85380
+ const { success, editorHost, reason } = __privateGet$1(this, _overlayManager).showEditingOverlay(
85381
+ pageElement,
85382
+ region,
85383
+ __privateGet$1(this, _layoutOptions).zoom ?? 1
85384
+ );
85385
+ if (!success || !editorHost) {
85386
+ console.error("[PresentationEditor] Failed to create editor host:", reason);
85387
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85388
+ this.emit("error", {
85389
+ error: new Error(`Failed to create editor host: ${reason}`),
85390
+ context: "enterHeaderFooterMode.showOverlay"
85391
+ });
85392
+ return;
85393
+ }
85394
+ const layout = __privateGet$1(this, _layoutState).layout;
85395
+ let editor;
85396
+ try {
85397
+ editor = await __privateGet$1(this, _headerFooterManager).ensureEditor(descriptor, {
85398
+ editorHost,
85399
+ availableWidth: region.width,
85400
+ availableHeight: region.height,
85401
+ currentPageNumber: region.pageNumber,
85402
+ totalPageCount: layout?.pages?.length ?? 1
85403
+ });
85404
+ } catch (editorError) {
85405
+ console.error("[PresentationEditor] Error creating editor:", editorError);
85406
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
85407
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85408
+ this.emit("error", {
85409
+ error: editorError,
85410
+ context: "enterHeaderFooterMode.ensureEditor"
85411
+ });
85412
+ return;
85413
+ }
85414
+ if (!editor) {
85415
+ console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
85416
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
85417
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85418
+ this.emit("error", {
85419
+ error: new Error("Failed to create editor instance"),
85420
+ context: "enterHeaderFooterMode.ensureEditor"
85421
+ });
85422
+ return;
85423
+ }
85424
+ try {
85425
+ editor.setEditable(true);
85426
+ editor.setOptions({ documentMode: "editing" });
85427
+ try {
85428
+ const doc2 = editor.state?.doc;
85429
+ if (doc2) {
85430
+ const endPos = doc2.content.size - 1;
85431
+ editor.commands?.setTextSelection?.(Math.max(1, endPos));
85432
+ }
85433
+ } catch (cursorError) {
85434
+ console.warn("[PresentationEditor] Could not set cursor to end:", cursorError);
85435
+ }
85436
+ } catch (editableError) {
85437
+ console.error("[PresentationEditor] Error setting editor editable:", editableError);
85438
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
85439
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85440
+ this.emit("error", {
85441
+ error: editableError,
85442
+ context: "enterHeaderFooterMode.setEditable"
85443
+ });
85444
+ return;
85445
+ }
85446
+ __privateGet$1(this, _overlayManager).hideSelectionOverlay();
85447
+ __privateSet(this, _activeHeaderFooterEditor, editor);
85448
+ __privateSet(this, _session, {
85449
+ mode: region.kind,
85450
+ kind: region.kind,
85451
+ headerId: descriptor.id,
85452
+ sectionType: descriptor.variant ?? region.sectionType ?? null,
85453
+ pageIndex: region.pageIndex,
85454
+ pageNumber: region.pageNumber
85455
+ });
84496
85456
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
84497
- return;
85457
+ try {
85458
+ editor.view?.focus();
85459
+ } catch (focusError) {
85460
+ console.warn("[PresentationEditor] Could not focus editor:", focusError);
85461
+ }
85462
+ __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
85463
+ __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
85464
+ __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
85465
+ } catch (error) {
85466
+ console.error("[PresentationEditor] Unexpected error in enterHeaderFooterMode:", error);
85467
+ try {
85468
+ __privateGet$1(this, _overlayManager)?.hideEditingOverlay();
85469
+ __privateGet$1(this, _overlayManager)?.showSelectionOverlay();
85470
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
85471
+ __privateSet(this, _activeHeaderFooterEditor, null);
85472
+ __privateSet(this, _session, { mode: "body" });
85473
+ } catch (cleanupError) {
85474
+ console.error("[PresentationEditor] Error during cleanup:", cleanupError);
85475
+ }
85476
+ this.emit("error", {
85477
+ error,
85478
+ context: "enterHeaderFooterMode"
85479
+ });
84498
85480
  }
84499
- __privateSet(this, _activeHeaderFooterEditor, editor);
84500
- __privateSet(this, _session, {
84501
- mode: region.kind,
84502
- kind: region.kind,
84503
- headerId: descriptor.id,
84504
- sectionType: descriptor.variant ?? region.sectionType ?? null,
84505
- pageIndex: region.pageIndex,
84506
- pageNumber: region.pageNumber
84507
- });
84508
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
84509
- __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
84510
- __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
84511
- __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
84512
- editor.view?.focus();
84513
85481
  };
84514
85482
  exitHeaderFooterMode_fn = function() {
84515
85483
  if (__privateGet$1(this, _session).mode === "body") return;
84516
- __privateSet(this, _session, { mode: "body" });
85484
+ if (__privateGet$1(this, _activeHeaderFooterEditor)) {
85485
+ __privateGet$1(this, _activeHeaderFooterEditor).setEditable(false);
85486
+ __privateGet$1(this, _activeHeaderFooterEditor).setOptions({ documentMode: "viewing" });
85487
+ }
85488
+ __privateGet$1(this, _overlayManager)?.hideEditingOverlay();
85489
+ __privateGet$1(this, _overlayManager)?.showSelectionOverlay();
84517
85490
  __privateSet(this, _activeHeaderFooterEditor, null);
85491
+ __privateSet(this, _session, { mode: "body" });
84518
85492
  __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
84519
85493
  __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, __privateGet$1(this, _editor3));
84520
85494
  __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
@@ -84610,6 +85584,75 @@ ${l}
84610
85584
  }
84611
85585
  return descriptors[0];
84612
85586
  };
85587
+ createDefaultHeaderFooter_fn = function(region) {
85588
+ const converter = __privateGet$1(this, _editor3).converter;
85589
+ if (!converter) {
85590
+ console.error("[PresentationEditor] Converter not available for creating header/footer");
85591
+ return;
85592
+ }
85593
+ const variant = region.sectionType ?? "default";
85594
+ try {
85595
+ if (region.kind === "header") {
85596
+ if (typeof converter.createDefaultHeader === "function") {
85597
+ const headerId = converter.createDefaultHeader(variant);
85598
+ console.log(`[PresentationEditor] Created default header: ${headerId}`);
85599
+ } else {
85600
+ console.error("[PresentationEditor] converter.createDefaultHeader is not a function");
85601
+ }
85602
+ } else if (region.kind === "footer") {
85603
+ if (typeof converter.createDefaultFooter === "function") {
85604
+ const footerId = converter.createDefaultFooter(variant);
85605
+ console.log(`[PresentationEditor] Created default footer: ${footerId}`);
85606
+ } else {
85607
+ console.error("[PresentationEditor] converter.createDefaultFooter is not a function");
85608
+ }
85609
+ }
85610
+ } catch (error) {
85611
+ console.error("[PresentationEditor] Failed to create default header/footer:", error);
85612
+ }
85613
+ };
85614
+ getPageElement_fn = function(pageIndex) {
85615
+ if (!__privateGet$1(this, _painterHost)) return null;
85616
+ const pageElements = __privateGet$1(this, _painterHost).querySelectorAll("[data-page-index]");
85617
+ for (let i2 = 0; i2 < pageElements.length; i2++) {
85618
+ const el = pageElements[i2];
85619
+ const dataPageIndex = el.getAttribute("data-page-index");
85620
+ if (dataPageIndex && parseInt(dataPageIndex, 10) === pageIndex) {
85621
+ return el;
85622
+ }
85623
+ }
85624
+ return null;
85625
+ };
85626
+ scrollPageIntoView_fn = function(pageIndex) {
85627
+ const layout = __privateGet$1(this, _layoutState).layout;
85628
+ if (!layout) return;
85629
+ const pageHeight = layout.pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
85630
+ const virtualGap = __privateGet$1(this, _layoutOptions).virtualization?.gap ?? 0;
85631
+ const yPosition = pageIndex * (pageHeight + virtualGap);
85632
+ if (__privateGet$1(this, _visibleHost)) {
85633
+ __privateGet$1(this, _visibleHost).scrollTop = yPosition;
85634
+ }
85635
+ };
85636
+ waitForPageMount_fn = async function(pageIndex, options = {}) {
85637
+ const timeout2 = options.timeout ?? 2e3;
85638
+ const startTime = performance.now();
85639
+ return new Promise((resolve2) => {
85640
+ const checkPage = () => {
85641
+ const pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, pageIndex);
85642
+ if (pageElement) {
85643
+ resolve2(true);
85644
+ return;
85645
+ }
85646
+ const elapsed = performance.now() - startTime;
85647
+ if (elapsed >= timeout2) {
85648
+ resolve2(false);
85649
+ return;
85650
+ }
85651
+ requestAnimationFrame(checkPage);
85652
+ };
85653
+ checkPage();
85654
+ });
85655
+ };
84613
85656
  getBodyPageHeight_fn = function() {
84614
85657
  return __privateGet$1(this, _layoutState).layout?.pageSize?.h ?? __privateGet$1(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
84615
85658
  };
@@ -84663,7 +85706,7 @@ ${l}
84663
85706
  __privateGet$1(this, _hoverOverlay).style.top = `${coords.y}px`;
84664
85707
  __privateGet$1(this, _hoverOverlay).style.width = `${region.width * zoom}px`;
84665
85708
  __privateGet$1(this, _hoverOverlay).style.height = `${region.height * zoom}px`;
84666
- const tooltipText = `Double-click to edit ${region.kind === "header" ? "Header" : "Footer"} (${region.sectionType ?? "default"})`;
85709
+ const tooltipText = `Double-click to edit ${region.kind === "header" ? "header" : "footer"}`;
84667
85710
  __privateGet$1(this, _hoverTooltip).textContent = tooltipText;
84668
85711
  __privateGet$1(this, _hoverTooltip).style.display = "block";
84669
85712
  __privateGet$1(this, _hoverTooltip).style.left = `${coords.x}px`;
@@ -84769,33 +85812,6 @@ ${l}
84769
85812
  };
84770
85813
  });
84771
85814
  };
84772
- computeHeaderFooterCaretRect_fn = function(pos) {
84773
- const context = __privateMethod$1(this, _PresentationEditor_instances, getHeaderFooterContext_fn).call(this);
84774
- if (!context) return null;
84775
- const hit = getFragmentAtPosition(context.layout, context.blocks, context.measures, pos);
84776
- if (!hit) return null;
84777
- const block = hit.block;
84778
- const measure = hit.measure;
84779
- if (!block || block.kind !== "paragraph" || measure?.kind !== "paragraph" || hit.fragment.kind !== "para")
84780
- return null;
84781
- const lineInfo = __privateMethod$1(this, _PresentationEditor_instances, findLineContainingPos_fn).call(this, block, measure, hit.fragment.fromLine, hit.fragment.toLine, pos);
84782
- if (!lineInfo) return null;
84783
- const { line, index: index2 } = lineInfo;
84784
- const range2 = computeLinePmRange$1(block, line);
84785
- if (range2.pmStart == null || range2.pmEnd == null) return null;
84786
- const pmCharsInLine = Math.max(1, range2.pmEnd - range2.pmStart);
84787
- const pmOffset = Math.max(0, Math.min(pmCharsInLine, pos - range2.pmStart));
84788
- const localX = hit.fragment.x + measureCharacterX(block, line, pmOffset);
84789
- const lineOffset = __privateMethod$1(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, hit.fragment.fromLine, index2);
84790
- const headerPageHeight = context.layout.pageSize?.h ?? context.region.height ?? 1;
84791
- const headerLocalY = hit.pageIndex * headerPageHeight + (hit.fragment.y + lineOffset);
84792
- return {
84793
- pageIndex: context.region.pageIndex,
84794
- x: context.region.localX + localX,
84795
- y: context.region.localY + headerLocalY,
84796
- height: line.lineHeight
84797
- };
84798
- };
84799
85815
  syncTrackedChangesPreferences_fn = function() {
84800
85816
  const mode = __privateMethod$1(this, _PresentationEditor_instances, deriveTrackedChangesMode_fn).call(this);
84801
85817
  const enabled = __privateMethod$1(this, _PresentationEditor_instances, deriveTrackedChangesEnabled_fn).call(this);
@@ -84902,7 +85918,7 @@ ${l}
84902
85918
  return null;
84903
85919
  }
84904
85920
  const pageRect = pageEl.getBoundingClientRect();
84905
- const overlayRect = __privateGet$1(this, _selectionOverlay).getBoundingClientRect();
85921
+ const overlayRect = __privateGet$1(this, _selectionOverlay2).getBoundingClientRect();
84906
85922
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
84907
85923
  return {
84908
85924
  x: pageRect.left - overlayRect.left + pageLocalX * zoom,
@@ -89772,22 +90788,53 @@ ${l}
89772
90788
  tabs
89773
90789
  };
89774
90790
  }
90791
+ const MAX_WALK_DEPTH = 50;
89775
90792
  function applyLayoutResult(result, paragraph2, paragraphPos) {
89776
90793
  const decorations = [];
89777
90794
  let tabIndex = 0;
89778
- paragraph2.forEach((node2, offset2) => {
89779
- if (node2.type.name !== "tab") return;
89780
- const pos = paragraphPos + offset2 + 1;
89781
- const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
89782
- const layout = result.tabs[tabId];
89783
- if (!layout) return;
89784
- let style2 = `width: ${layout.width}px;`;
89785
- if (layout.height) style2 += ` height: ${layout.height};`;
89786
- if (layout.leader && leaderStyles[layout.leader]) {
89787
- style2 += ` ${leaderStyles[layout.leader]}`;
89788
- }
89789
- decorations.push(Decoration.node(pos, pos + node2.nodeSize, { style: style2 }));
89790
- });
90795
+ const walk = (node2, pos, depth = 0) => {
90796
+ if (depth > MAX_WALK_DEPTH) {
90797
+ console.error(`applyLayoutResult: Maximum recursion depth (${MAX_WALK_DEPTH}) exceeded`);
90798
+ return;
90799
+ }
90800
+ if (!node2?.type?.name) {
90801
+ console.error("applyLayoutResult: Node missing type.name", { node: node2, pos, depth });
90802
+ return;
90803
+ }
90804
+ if (typeof node2.nodeSize !== "number" || node2.nodeSize < 0 || !Number.isFinite(node2.nodeSize)) {
90805
+ console.error("applyLayoutResult: Invalid nodeSize", { nodeSize: node2.nodeSize, nodeName: node2.type.name, pos });
90806
+ return;
90807
+ }
90808
+ if (node2.type.name === "tab") {
90809
+ const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
90810
+ const layout = result.tabs[tabId];
90811
+ if (layout) {
90812
+ let style2 = `width: ${layout.width}px;`;
90813
+ if (layout.height) style2 += ` height: ${layout.height};`;
90814
+ if (layout.leader && leaderStyles[layout.leader]) {
90815
+ style2 += ` ${leaderStyles[layout.leader]}`;
90816
+ }
90817
+ decorations.push(Decoration.node(pos, pos + node2.nodeSize, { style: style2 }));
90818
+ }
90819
+ return;
90820
+ }
90821
+ try {
90822
+ let offset2 = 0;
90823
+ node2.forEach((child) => {
90824
+ const childPos = pos + 1 + offset2;
90825
+ walk(child, childPos, depth + 1);
90826
+ offset2 += child.nodeSize;
90827
+ });
90828
+ } catch (error) {
90829
+ console.error("applyLayoutResult: Error during recursion", {
90830
+ error,
90831
+ nodeName: node2.type.name,
90832
+ pos,
90833
+ depth
90834
+ });
90835
+ }
90836
+ };
90837
+ walk(paragraph2, paragraphPos);
89791
90838
  return decorations;
89792
90839
  }
89793
90840
  function collectFollowingText(spans, startIndex) {
@@ -90335,8 +91382,8 @@ ${l}
90335
91382
  colgroupValues
90336
91383
  };
90337
91384
  };
90338
- var readFromCache;
90339
- var addToCache;
91385
+ let readFromCache;
91386
+ let addToCache;
90340
91387
  if (typeof WeakMap != "undefined") {
90341
91388
  let cache2 = /* @__PURE__ */ new WeakMap();
90342
91389
  readFromCache = (key2) => cache2.get(key2);
@@ -90349,8 +91396,7 @@ ${l}
90349
91396
  const cacheSize = 10;
90350
91397
  let cachePos = 0;
90351
91398
  readFromCache = (key2) => {
90352
- for (let i2 = 0; i2 < cache2.length; i2 += 2)
90353
- if (cache2[i2] == key2) return cache2[i2 + 1];
91399
+ for (let i2 = 0; i2 < cache2.length; i2 += 2) if (cache2[i2] == key2) return cache2[i2 + 1];
90354
91400
  };
90355
91401
  addToCache = (key2, value) => {
90356
91402
  if (cachePos == cacheSize) cachePos = 0;
@@ -90365,7 +91411,6 @@ ${l}
90365
91411
  this.map = map2;
90366
91412
  this.problems = problems;
90367
91413
  }
90368
- // Find the dimensions of the cell at the given position.
90369
91414
  findCell(pos) {
90370
91415
  for (let i2 = 0; i2 < this.map.length; i2++) {
90371
91416
  const curPos = this.map[i2];
@@ -90374,27 +91419,21 @@ ${l}
90374
91419
  const top2 = i2 / this.width | 0;
90375
91420
  let right2 = left2 + 1;
90376
91421
  let bottom2 = top2 + 1;
90377
- for (let j2 = 1; right2 < this.width && this.map[i2 + j2] == curPos; j2++) {
90378
- right2++;
90379
- }
90380
- for (let j2 = 1; bottom2 < this.height && this.map[i2 + this.width * j2] == curPos; j2++) {
90381
- bottom2++;
90382
- }
90383
- return { left: left2, top: top2, right: right2, bottom: bottom2 };
91422
+ for (let j2 = 1; right2 < this.width && this.map[i2 + j2] == curPos; j2++) right2++;
91423
+ for (let j2 = 1; bottom2 < this.height && this.map[i2 + this.width * j2] == curPos; j2++) bottom2++;
91424
+ return {
91425
+ left: left2,
91426
+ top: top2,
91427
+ right: right2,
91428
+ bottom: bottom2
91429
+ };
90384
91430
  }
90385
91431
  throw new RangeError(`No cell with offset ${pos} found`);
90386
91432
  }
90387
- // Find the left side of the cell at the given position.
90388
91433
  colCount(pos) {
90389
- for (let i2 = 0; i2 < this.map.length; i2++) {
90390
- if (this.map[i2] == pos) {
90391
- return i2 % this.width;
90392
- }
90393
- }
91434
+ for (let i2 = 0; i2 < this.map.length; i2++) if (this.map[i2] == pos) return i2 % this.width;
90394
91435
  throw new RangeError(`No cell with offset ${pos} found`);
90395
91436
  }
90396
- // Find the next cell in the given direction, starting from the cell
90397
- // at `pos`, if any.
90398
91437
  nextCell(pos, axis, dir) {
90399
91438
  const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
90400
91439
  if (axis == "horiz") {
@@ -90405,20 +91444,9 @@ ${l}
90405
91444
  return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
90406
91445
  }
90407
91446
  }
90408
- // Get the rectangle spanning the two given cells.
90409
91447
  rectBetween(a2, b2) {
90410
- const {
90411
- left: leftA,
90412
- right: rightA,
90413
- top: topA,
90414
- bottom: bottomA
90415
- } = this.findCell(a2);
90416
- const {
90417
- left: leftB,
90418
- right: rightB,
90419
- top: topB,
90420
- bottom: bottomB
90421
- } = this.findCell(b2);
91448
+ const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a2);
91449
+ const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b2);
90422
91450
  return {
90423
91451
  left: Math.min(leftA, leftB),
90424
91452
  top: Math.min(topA, topB),
@@ -90426,27 +91454,19 @@ ${l}
90426
91454
  bottom: Math.max(bottomA, bottomB)
90427
91455
  };
90428
91456
  }
90429
- // Return the position of all cells that have the top left corner in
90430
- // the given rectangle.
90431
91457
  cellsInRect(rect) {
90432
91458
  const result = [];
90433
91459
  const seen = {};
90434
- for (let row2 = rect.top; row2 < rect.bottom; row2++) {
90435
- for (let col = rect.left; col < rect.right; col++) {
90436
- const index2 = row2 * this.width + col;
90437
- const pos = this.map[index2];
90438
- if (seen[pos]) continue;
90439
- seen[pos] = true;
90440
- if (col == rect.left && col && this.map[index2 - 1] == pos || row2 == rect.top && row2 && this.map[index2 - this.width] == pos) {
90441
- continue;
90442
- }
90443
- result.push(pos);
90444
- }
91460
+ for (let row2 = rect.top; row2 < rect.bottom; row2++) for (let col = rect.left; col < rect.right; col++) {
91461
+ const index2 = row2 * this.width + col;
91462
+ const pos = this.map[index2];
91463
+ if (seen[pos]) continue;
91464
+ seen[pos] = true;
91465
+ if (col == rect.left && col && this.map[index2 - 1] == pos || row2 == rect.top && row2 && this.map[index2 - this.width] == pos) continue;
91466
+ result.push(pos);
90445
91467
  }
90446
91468
  return result;
90447
91469
  }
90448
- // Return the position at which the cell at the given row and column
90449
- // starts, or would start, if a cell started there.
90450
91470
  positionAt(row2, col, table2) {
90451
91471
  for (let i2 = 0, rowStart = 0; ; i2++) {
90452
91472
  const rowEnd = rowStart + table2.child(i2).nodeSize;
@@ -90459,14 +91479,12 @@ ${l}
90459
91479
  rowStart = rowEnd;
90460
91480
  }
90461
91481
  }
90462
- // Find the table map for the given table node.
90463
91482
  static get(table2) {
90464
91483
  return readFromCache(table2) || addToCache(table2, computeMap(table2));
90465
91484
  }
90466
91485
  };
90467
91486
  function computeMap(table2) {
90468
- if (table2.type.spec.tableRole != "table")
90469
- throw new RangeError("Not a table node: " + table2.type.name);
91487
+ if (table2.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table2.type.name);
90470
91488
  const width = findWidth(table2), height = table2.childCount;
90471
91489
  const map2 = [];
90472
91490
  let mapPos = 0;
@@ -90493,22 +91511,19 @@ ${l}
90493
91511
  const start2 = mapPos + h2 * width;
90494
91512
  for (let w2 = 0; w2 < colspan; w2++) {
90495
91513
  if (map2[start2 + w2] == 0) map2[start2 + w2] = pos;
90496
- else
90497
- (problems || (problems = [])).push({
90498
- type: "collision",
90499
- row: row2,
90500
- pos,
90501
- n: colspan - w2
90502
- });
91514
+ else (problems || (problems = [])).push({
91515
+ type: "collision",
91516
+ row: row2,
91517
+ pos,
91518
+ n: colspan - w2
91519
+ });
90503
91520
  const colW = colwidth && colwidth[w2];
90504
91521
  if (colW) {
90505
91522
  const widthIndex = (start2 + w2) % width * 2, prev = colWidths[widthIndex];
90506
91523
  if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
90507
91524
  colWidths[widthIndex] = colW;
90508
91525
  colWidths[widthIndex + 1] = 1;
90509
- } else if (prev == colW) {
90510
- colWidths[widthIndex + 1]++;
90511
- }
91526
+ } else if (prev == colW) colWidths[widthIndex + 1]++;
90512
91527
  }
90513
91528
  }
90514
91529
  }
@@ -90518,16 +91533,17 @@ ${l}
90518
91533
  const expectedPos = (row2 + 1) * width;
90519
91534
  let missing = 0;
90520
91535
  while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++;
90521
- if (missing)
90522
- (problems || (problems = [])).push({ type: "missing", row: row2, n: missing });
91536
+ if (missing) (problems || (problems = [])).push({
91537
+ type: "missing",
91538
+ row: row2,
91539
+ n: missing
91540
+ });
90523
91541
  pos++;
90524
91542
  }
90525
- if (width === 0 || height === 0)
90526
- (problems || (problems = [])).push({ type: "zero_sized" });
91543
+ if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
90527
91544
  const tableMap = new TableMap(width, height, map2, problems);
90528
91545
  let badWidths = false;
90529
- for (let i2 = 0; !badWidths && i2 < colWidths.length; i2 += 2)
90530
- if (colWidths[i2] != null && colWidths[i2 + 1] < height) badWidths = true;
91546
+ for (let i2 = 0; !badWidths && i2 < colWidths.length; i2 += 2) if (colWidths[i2] != null && colWidths[i2 + 1] < height) badWidths = true;
90531
91547
  if (badWidths) findBadColWidths(tableMap, colWidths, table2);
90532
91548
  return tableMap;
90533
91549
  }
@@ -90537,14 +91553,13 @@ ${l}
90537
91553
  for (let row2 = 0; row2 < table2.childCount; row2++) {
90538
91554
  const rowNode = table2.child(row2);
90539
91555
  let rowWidth = 0;
90540
- if (hasRowSpan)
90541
- for (let j2 = 0; j2 < row2; j2++) {
90542
- const prevRow = table2.child(j2);
90543
- for (let i2 = 0; i2 < prevRow.childCount; i2++) {
90544
- const cell2 = prevRow.child(i2);
90545
- if (j2 + cell2.attrs.rowspan > row2) rowWidth += cell2.attrs.colspan;
90546
- }
91556
+ if (hasRowSpan) for (let j2 = 0; j2 < row2; j2++) {
91557
+ const prevRow = table2.child(j2);
91558
+ for (let i2 = 0; i2 < prevRow.childCount; i2++) {
91559
+ const cell2 = prevRow.child(i2);
91560
+ if (j2 + cell2.attrs.rowspan > row2) rowWidth += cell2.attrs.colspan;
90547
91561
  }
91562
+ }
90548
91563
  for (let i2 = 0; i2 < rowNode.childCount; i2++) {
90549
91564
  const cell2 = rowNode.child(i2);
90550
91565
  rowWidth += cell2.attrs.colspan;
@@ -90563,23 +91578,18 @@ ${l}
90563
91578
  if (seen[pos]) continue;
90564
91579
  seen[pos] = true;
90565
91580
  const node2 = table2.nodeAt(pos);
90566
- if (!node2) {
90567
- throw new RangeError(`No cell with offset ${pos} found`);
90568
- }
91581
+ if (!node2) throw new RangeError(`No cell with offset ${pos} found`);
90569
91582
  let updated = null;
90570
91583
  const attrs = node2.attrs;
90571
91584
  for (let j2 = 0; j2 < attrs.colspan; j2++) {
90572
- const col = (i2 + j2) % map2.width;
90573
- const colWidth = colWidths[col * 2];
90574
- if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth))
90575
- (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
90576
- }
90577
- if (updated)
90578
- map2.problems.unshift({
90579
- type: "colwidth mismatch",
90580
- pos,
90581
- colwidth: updated
90582
- });
91585
+ const colWidth = colWidths[(i2 + j2) % map2.width * 2];
91586
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
91587
+ }
91588
+ if (updated) map2.problems.unshift({
91589
+ type: "colwidth mismatch",
91590
+ pos,
91591
+ colwidth: updated
91592
+ });
90583
91593
  }
90584
91594
  }
90585
91595
  function freshColWidth(attrs) {
@@ -90599,11 +91609,9 @@ ${l}
90599
91609
  }
90600
91610
  return result;
90601
91611
  }
90602
- var tableEditingKey = new PluginKey("selectingCells");
91612
+ const tableEditingKey = new PluginKey("selectingCells");
90603
91613
  function cellAround$1($pos) {
90604
- for (let d2 = $pos.depth - 1; d2 > 0; d2--)
90605
- if ($pos.node(d2).type.spec.tableRole == "row")
90606
- return $pos.node(0).resolve($pos.before(d2 + 1));
91614
+ for (let d2 = $pos.depth - 1; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d2 + 1));
90607
91615
  return null;
90608
91616
  }
90609
91617
  function cellWrapping$1($pos) {
@@ -90615,21 +91623,15 @@ ${l}
90615
91623
  }
90616
91624
  function isInTable(state2) {
90617
91625
  const $head = state2.selection.$head;
90618
- for (let d2 = $head.depth; d2 > 0; d2--)
90619
- if ($head.node(d2).type.spec.tableRole == "row") return true;
91626
+ for (let d2 = $head.depth; d2 > 0; d2--) if ($head.node(d2).type.spec.tableRole == "row") return true;
90620
91627
  return false;
90621
91628
  }
90622
91629
  function selectionCell(state2) {
90623
91630
  const sel = state2.selection;
90624
- if ("$anchorCell" in sel && sel.$anchorCell) {
90625
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
90626
- } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
90627
- return sel.$anchor;
90628
- }
91631
+ if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
91632
+ else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
90629
91633
  const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
90630
- if ($cell) {
90631
- return $cell;
90632
- }
91634
+ if ($cell) return $cell;
90633
91635
  throw new RangeError(`No cell found around position ${sel.head}`);
90634
91636
  }
90635
91637
  function cellNear($pos) {
@@ -90639,8 +91641,7 @@ ${l}
90639
91641
  }
90640
91642
  for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
90641
91643
  const role = before.type.spec.tableRole;
90642
- if (role == "cell" || role == "header_cell")
90643
- return $pos.doc.resolve(pos - before.nodeSize);
91644
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
90644
91645
  }
90645
91646
  }
90646
91647
  function pointsAtCell($pos) {
@@ -90660,7 +91661,10 @@ ${l}
90660
91661
  return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
90661
91662
  }
90662
91663
  function removeColSpan(attrs, pos, n = 1) {
90663
- const result = { ...attrs, colspan: attrs.colspan - n };
91664
+ const result = {
91665
+ ...attrs,
91666
+ colspan: attrs.colspan - n
91667
+ };
90664
91668
  if (result.colwidth) {
90665
91669
  result.colwidth = result.colwidth.slice();
90666
91670
  result.colwidth.splice(pos, n);
@@ -90669,7 +91673,10 @@ ${l}
90669
91673
  return result;
90670
91674
  }
90671
91675
  function addColSpan(attrs, pos, n = 1) {
90672
- const result = { ...attrs, colspan: attrs.colspan + n };
91676
+ const result = {
91677
+ ...attrs,
91678
+ colspan: attrs.colspan + n
91679
+ };
90673
91680
  if (result.colwidth) {
90674
91681
  result.colwidth = result.colwidth.slice();
90675
91682
  for (let i2 = 0; i2 < n; i2++) result.colwidth.splice(pos, 0, 0);
@@ -90678,37 +91685,23 @@ ${l}
90678
91685
  }
90679
91686
  function columnIsHeader(map2, table2, col) {
90680
91687
  const headerCell = tableNodeTypes(table2.type.schema).header_cell;
90681
- for (let row2 = 0; row2 < map2.height; row2++)
90682
- if (table2.nodeAt(map2.map[col + row2 * map2.width]).type != headerCell)
90683
- return false;
91688
+ for (let row2 = 0; row2 < map2.height; row2++) if (table2.nodeAt(map2.map[col + row2 * map2.width]).type != headerCell) return false;
90684
91689
  return true;
90685
91690
  }
90686
- var CellSelection = class _CellSelection extends Selection {
90687
- // A table selection is identified by its anchor and head cells. The
90688
- // positions given to this constructor should point _before_ two
90689
- // cells in the same table. They may be the same, to select a single
90690
- // cell.
91691
+ var CellSelection = class CellSelection2 extends Selection {
90691
91692
  constructor($anchorCell, $headCell = $anchorCell) {
90692
91693
  const table2 = $anchorCell.node(-1);
90693
91694
  const map2 = TableMap.get(table2);
90694
91695
  const tableStart = $anchorCell.start(-1);
90695
- const rect = map2.rectBetween(
90696
- $anchorCell.pos - tableStart,
90697
- $headCell.pos - tableStart
90698
- );
91696
+ const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
90699
91697
  const doc2 = $anchorCell.node(0);
90700
91698
  const cells = map2.cellsInRect(rect).filter((p2) => p2 != $headCell.pos - tableStart);
90701
91699
  cells.unshift($headCell.pos - tableStart);
90702
91700
  const ranges = cells.map((pos) => {
90703
91701
  const cell2 = table2.nodeAt(pos);
90704
- if (!cell2) {
90705
- throw RangeError(`No cell with offset ${pos} found`);
90706
- }
91702
+ if (!cell2) throw new RangeError(`No cell with offset ${pos} found`);
90707
91703
  const from2 = tableStart + pos + 1;
90708
- return new SelectionRange(
90709
- doc2.resolve(from2),
90710
- doc2.resolve(from2 + cell2.content.size)
90711
- );
91704
+ return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell2.content.size));
90712
91705
  });
90713
91706
  super(ranges[0].$from, ranges[0].$to, ranges);
90714
91707
  this.$anchorCell = $anchorCell;
@@ -90719,24 +91712,17 @@ ${l}
90719
91712
  const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
90720
91713
  if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
90721
91714
  const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
90722
- if (tableChanged && this.isRowSelection())
90723
- return _CellSelection.rowSelection($anchorCell, $headCell);
90724
- else if (tableChanged && this.isColSelection())
90725
- return _CellSelection.colSelection($anchorCell, $headCell);
90726
- else return new _CellSelection($anchorCell, $headCell);
91715
+ if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell);
91716
+ else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell);
91717
+ else return new CellSelection2($anchorCell, $headCell);
90727
91718
  }
90728
91719
  return TextSelection$1.between($anchorCell, $headCell);
90729
91720
  }
90730
- // Returns a rectangular slice of table rows containing the selected
90731
- // cells.
90732
91721
  content() {
90733
91722
  const table2 = this.$anchorCell.node(-1);
90734
91723
  const map2 = TableMap.get(table2);
90735
91724
  const tableStart = this.$anchorCell.start(-1);
90736
- const rect = map2.rectBetween(
90737
- this.$anchorCell.pos - tableStart,
90738
- this.$headCell.pos - tableStart
90739
- );
91725
+ const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
90740
91726
  const seen = {};
90741
91727
  const rows = [];
90742
91728
  for (let row2 = rect.top; row2 < rect.bottom; row2++) {
@@ -90747,44 +91733,25 @@ ${l}
90747
91733
  seen[pos] = true;
90748
91734
  const cellRect = map2.findCell(pos);
90749
91735
  let cell2 = table2.nodeAt(pos);
90750
- if (!cell2) {
90751
- throw RangeError(`No cell with offset ${pos} found`);
90752
- }
91736
+ if (!cell2) throw new RangeError(`No cell with offset ${pos} found`);
90753
91737
  const extraLeft = rect.left - cellRect.left;
90754
91738
  const extraRight = cellRect.right - rect.right;
90755
91739
  if (extraLeft > 0 || extraRight > 0) {
90756
91740
  let attrs = cell2.attrs;
90757
- if (extraLeft > 0) {
90758
- attrs = removeColSpan(attrs, 0, extraLeft);
90759
- }
90760
- if (extraRight > 0) {
90761
- attrs = removeColSpan(
90762
- attrs,
90763
- attrs.colspan - extraRight,
90764
- extraRight
90765
- );
90766
- }
91741
+ if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
91742
+ if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
90767
91743
  if (cellRect.left < rect.left) {
90768
91744
  cell2 = cell2.type.createAndFill(attrs);
90769
- if (!cell2) {
90770
- throw RangeError(
90771
- `Could not create cell with attrs ${JSON.stringify(attrs)}`
90772
- );
90773
- }
90774
- } else {
90775
- cell2 = cell2.type.create(attrs, cell2.content);
90776
- }
91745
+ if (!cell2) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
91746
+ } else cell2 = cell2.type.create(attrs, cell2.content);
90777
91747
  }
90778
91748
  if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
90779
91749
  const attrs = {
90780
91750
  ...cell2.attrs,
90781
91751
  rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
90782
91752
  };
90783
- if (cellRect.top < rect.top) {
90784
- cell2 = cell2.type.createAndFill(attrs);
90785
- } else {
90786
- cell2 = cell2.type.create(attrs, cell2.content);
90787
- }
91753
+ if (cellRect.top < rect.top) cell2 = cell2.type.createAndFill(attrs);
91754
+ else cell2 = cell2.type.create(attrs, cell2.content);
90788
91755
  }
90789
91756
  rowContent.push(cell2);
90790
91757
  }
@@ -90797,16 +91764,9 @@ ${l}
90797
91764
  const mapFrom = tr.steps.length, ranges = this.ranges;
90798
91765
  for (let i2 = 0; i2 < ranges.length; i2++) {
90799
91766
  const { $from, $to } = ranges[i2], mapping = tr.mapping.slice(mapFrom);
90800
- tr.replace(
90801
- mapping.map($from.pos),
90802
- mapping.map($to.pos),
90803
- i2 ? Slice.empty : content2
90804
- );
91767
+ tr.replace(mapping.map($from.pos), mapping.map($to.pos), i2 ? Slice.empty : content2);
90805
91768
  }
90806
- const sel = Selection.findFrom(
90807
- tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
90808
- -1
90809
- );
91769
+ const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
90810
91770
  if (sel) tr.setSelection(sel);
90811
91771
  }
90812
91772
  replaceWith(tr, node2) {
@@ -90816,18 +91776,9 @@ ${l}
90816
91776
  const table2 = this.$anchorCell.node(-1);
90817
91777
  const map2 = TableMap.get(table2);
90818
91778
  const tableStart = this.$anchorCell.start(-1);
90819
- const cells = map2.cellsInRect(
90820
- map2.rectBetween(
90821
- this.$anchorCell.pos - tableStart,
90822
- this.$headCell.pos - tableStart
90823
- )
90824
- );
90825
- for (let i2 = 0; i2 < cells.length; i2++) {
90826
- f2(table2.nodeAt(cells[i2]), tableStart + cells[i2]);
90827
- }
91779
+ const cells = map2.cellsInRect(map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
91780
+ for (let i2 = 0; i2 < cells.length; i2++) f2(table2.nodeAt(cells[i2]), tableStart + cells[i2]);
90828
91781
  }
90829
- // True if this selection goes all the way from the top to the
90830
- // bottom of the table.
90831
91782
  isColSelection() {
90832
91783
  const anchorTop = this.$anchorCell.index(-1);
90833
91784
  const headTop = this.$headCell.index(-1);
@@ -90836,8 +91787,6 @@ ${l}
90836
91787
  const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
90837
91788
  return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
90838
91789
  }
90839
- // Returns the smallest column selection that covers the given anchor
90840
- // and head cell.
90841
91790
  static colSelection($anchorCell, $headCell = $anchorCell) {
90842
91791
  const table2 = $anchorCell.node(-1);
90843
91792
  const map2 = TableMap.get(table2);
@@ -90846,24 +91795,14 @@ ${l}
90846
91795
  const headRect = map2.findCell($headCell.pos - tableStart);
90847
91796
  const doc2 = $anchorCell.node(0);
90848
91797
  if (anchorRect.top <= headRect.top) {
90849
- if (anchorRect.top > 0)
90850
- $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
90851
- if (headRect.bottom < map2.height)
90852
- $headCell = doc2.resolve(
90853
- tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]
90854
- );
91798
+ if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
91799
+ if (headRect.bottom < map2.height) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]);
90855
91800
  } else {
90856
- if (headRect.top > 0)
90857
- $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
90858
- if (anchorRect.bottom < map2.height)
90859
- $anchorCell = doc2.resolve(
90860
- tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]
90861
- );
91801
+ if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
91802
+ if (anchorRect.bottom < map2.height) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]);
90862
91803
  }
90863
- return new _CellSelection($anchorCell, $headCell);
91804
+ return new CellSelection2($anchorCell, $headCell);
90864
91805
  }
90865
- // True if this selection goes all the way from the left to the
90866
- // right of the table.
90867
91806
  isRowSelection() {
90868
91807
  const table2 = this.$anchorCell.node(-1);
90869
91808
  const map2 = TableMap.get(table2);
@@ -90876,10 +91815,8 @@ ${l}
90876
91815
  return Math.max(anchorRight, headRight) == map2.width;
90877
91816
  }
90878
91817
  eq(other) {
90879
- return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
91818
+ return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
90880
91819
  }
90881
- // Returns the smallest row selection that covers the given anchor
90882
- // and head cell.
90883
91820
  static rowSelection($anchorCell, $headCell = $anchorCell) {
90884
91821
  const table2 = $anchorCell.node(-1);
90885
91822
  const map2 = TableMap.get(table2);
@@ -90888,23 +91825,13 @@ ${l}
90888
91825
  const headRect = map2.findCell($headCell.pos - tableStart);
90889
91826
  const doc2 = $anchorCell.node(0);
90890
91827
  if (anchorRect.left <= headRect.left) {
90891
- if (anchorRect.left > 0)
90892
- $anchorCell = doc2.resolve(
90893
- tableStart + map2.map[anchorRect.top * map2.width]
90894
- );
90895
- if (headRect.right < map2.width)
90896
- $headCell = doc2.resolve(
90897
- tableStart + map2.map[map2.width * (headRect.top + 1) - 1]
90898
- );
91828
+ if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.top * map2.width]);
91829
+ if (headRect.right < map2.width) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (headRect.top + 1) - 1]);
90899
91830
  } else {
90900
- if (headRect.left > 0)
90901
- $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
90902
- if (anchorRect.right < map2.width)
90903
- $anchorCell = doc2.resolve(
90904
- tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]
90905
- );
91831
+ if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
91832
+ if (anchorRect.right < map2.width) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]);
90906
91833
  }
90907
- return new _CellSelection($anchorCell, $headCell);
91834
+ return new CellSelection2($anchorCell, $headCell);
90908
91835
  }
90909
91836
  toJSON() {
90910
91837
  return {
@@ -90914,10 +91841,10 @@ ${l}
90914
91841
  };
90915
91842
  }
90916
91843
  static fromJSON(doc2, json) {
90917
- return new _CellSelection(doc2.resolve(json.anchor), doc2.resolve(json.head));
91844
+ return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
90918
91845
  }
90919
91846
  static create(doc2, anchorCell, headCell = anchorCell) {
90920
- return new _CellSelection(doc2.resolve(anchorCell), doc2.resolve(headCell));
91847
+ return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
90921
91848
  }
90922
91849
  getBookmark() {
90923
91850
  return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
@@ -90925,18 +91852,17 @@ ${l}
90925
91852
  };
90926
91853
  CellSelection.prototype.visible = false;
90927
91854
  Selection.jsonID("cell", CellSelection);
90928
- var CellBookmark = class _CellBookmark {
91855
+ var CellBookmark = class CellBookmark2 {
90929
91856
  constructor(anchor, head) {
90930
91857
  this.anchor = anchor;
90931
91858
  this.head = head;
90932
91859
  }
90933
91860
  map(mapping) {
90934
- return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
91861
+ return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
90935
91862
  }
90936
91863
  resolve(doc2) {
90937
91864
  const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
90938
- if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell))
90939
- return new CellSelection($anchorCell, $headCell);
91865
+ if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);
90940
91866
  else return Selection.near($headCell, 1);
90941
91867
  }
90942
91868
  };
@@ -90944,9 +91870,7 @@ ${l}
90944
91870
  if (!(state2.selection instanceof CellSelection)) return null;
90945
91871
  const cells = [];
90946
91872
  state2.selection.forEachCell((node2, pos) => {
90947
- cells.push(
90948
- Decoration.node(pos, pos + node2.nodeSize, { class: "selectedCell" })
90949
- );
91873
+ cells.push(Decoration.node(pos, pos + node2.nodeSize, { class: "selectedCell" }));
90950
91874
  });
90951
91875
  return DecorationSet.create(state2.doc, cells);
90952
91876
  }
@@ -90955,10 +91879,8 @@ ${l}
90955
91879
  let afterFrom = $from.pos;
90956
91880
  let beforeTo = $to.pos;
90957
91881
  let depth = $from.depth;
90958
- for (; depth >= 0; depth--, afterFrom++)
90959
- if ($from.after(depth + 1) < $from.end(depth)) break;
90960
- for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
90961
- if ($to.before(d2 + 1) > $to.start(d2)) break;
91882
+ for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
91883
+ for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--) if ($to.before(d2 + 1) > $to.start(d2)) break;
90962
91884
  return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
90963
91885
  }
90964
91886
  function isTextSelectionAcrossCells({ $from, $to }) {
@@ -90986,9 +91908,8 @@ ${l}
90986
91908
  let normalize2;
90987
91909
  let role;
90988
91910
  if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
90989
- if (role == "cell" || role == "header_cell") {
90990
- normalize2 = CellSelection.create(doc2, sel.from);
90991
- } else if (role == "row") {
91911
+ if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
91912
+ else if (role == "row") {
90992
91913
  const $cell = doc2.resolve(sel.from + 1);
90993
91914
  normalize2 = CellSelection.rowSelection($cell, $cell);
90994
91915
  } else if (!allowTableNodeSelection) {
@@ -90997,29 +91918,23 @@ ${l}
90997
91918
  const lastCell = start2 + map2.map[map2.width * map2.height - 1];
90998
91919
  normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
90999
91920
  }
91000
- } else if (sel instanceof TextSelection$1 && isCellBoundarySelection(sel)) {
91001
- normalize2 = TextSelection$1.create(doc2, sel.from);
91002
- } else if (sel instanceof TextSelection$1 && isTextSelectionAcrossCells(sel)) {
91003
- normalize2 = TextSelection$1.create(doc2, sel.$from.start(), sel.$from.end());
91004
- }
91921
+ } else if (sel instanceof TextSelection$1 && isCellBoundarySelection(sel)) normalize2 = TextSelection$1.create(doc2, sel.from);
91922
+ else if (sel instanceof TextSelection$1 && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection$1.create(doc2, sel.$from.start(), sel.$from.end());
91005
91923
  if (normalize2) (tr || (tr = state2.tr)).setSelection(normalize2);
91006
91924
  return tr;
91007
91925
  }
91008
- var fixTablesKey = new PluginKey("fix-tables");
91926
+ const fixTablesKey = new PluginKey("fix-tables");
91009
91927
  function changedDescendants(old, cur, offset2, f2) {
91010
91928
  const oldSize = old.childCount, curSize = cur.childCount;
91011
91929
  outer: for (let i2 = 0, j2 = 0; i2 < curSize; i2++) {
91012
91930
  const child = cur.child(i2);
91013
- for (let scan = j2, e = Math.min(oldSize, i2 + 3); scan < e; scan++) {
91014
- if (old.child(scan) == child) {
91015
- j2 = scan + 1;
91016
- offset2 += child.nodeSize;
91017
- continue outer;
91018
- }
91931
+ for (let scan = j2, e = Math.min(oldSize, i2 + 3); scan < e; scan++) if (old.child(scan) == child) {
91932
+ j2 = scan + 1;
91933
+ offset2 += child.nodeSize;
91934
+ continue outer;
91019
91935
  }
91020
91936
  f2(child, offset2);
91021
- if (j2 < oldSize && old.child(j2).sameMarkup(child))
91022
- changedDescendants(old.child(j2), child, offset2 + 1, f2);
91937
+ if (j2 < oldSize && old.child(j2).sameMarkup(child)) changedDescendants(old.child(j2), child, offset2 + 1, f2);
91023
91938
  else child.nodesBetween(0, child.content.size, f2, offset2 + 1);
91024
91939
  offset2 += child.nodeSize;
91025
91940
  }
@@ -91027,12 +91942,10 @@ ${l}
91027
91942
  function fixTables(state2, oldState) {
91028
91943
  let tr;
91029
91944
  const check = (node2, pos) => {
91030
- if (node2.type.spec.tableRole == "table")
91031
- tr = fixTable(state2, node2, pos, tr);
91945
+ if (node2.type.spec.tableRole == "table") tr = fixTable(state2, node2, pos, tr);
91032
91946
  };
91033
91947
  if (!oldState) state2.doc.descendants(check);
91034
- else if (oldState.doc != state2.doc)
91035
- changedDescendants(oldState.doc, state2.doc, 0, check);
91948
+ else if (oldState.doc != state2.doc) changedDescendants(oldState.doc, state2.doc, 0, check);
91036
91949
  return tr;
91037
91950
  }
91038
91951
  function fixTable(state2, table2, tablePos, tr) {
@@ -91048,14 +91961,9 @@ ${l}
91048
91961
  if (!cell2) continue;
91049
91962
  const attrs = cell2.attrs;
91050
91963
  for (let j2 = 0; j2 < attrs.rowspan; j2++) mustAdd[prob.row + j2] += prob.n;
91051
- tr.setNodeMarkup(
91052
- tr.mapping.map(tablePos + 1 + prob.pos),
91053
- null,
91054
- removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
91055
- );
91056
- } else if (prob.type == "missing") {
91057
- mustAdd[prob.row] += prob.n;
91058
- } else if (prob.type == "overlong_rowspan") {
91964
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
91965
+ } else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
91966
+ else if (prob.type == "overlong_rowspan") {
91059
91967
  const cell2 = table2.nodeAt(prob.pos);
91060
91968
  if (!cell2) continue;
91061
91969
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
@@ -91075,20 +91983,17 @@ ${l}
91075
91983
  }
91076
91984
  }
91077
91985
  let first2, last;
91078
- for (let i2 = 0; i2 < mustAdd.length; i2++)
91079
- if (mustAdd[i2]) {
91080
- if (first2 == null) first2 = i2;
91081
- last = i2;
91082
- }
91986
+ for (let i2 = 0; i2 < mustAdd.length; i2++) if (mustAdd[i2]) {
91987
+ if (first2 == null) first2 = i2;
91988
+ last = i2;
91989
+ }
91083
91990
  for (let i2 = 0, pos = tablePos + 1; i2 < map2.height; i2++) {
91084
91991
  const row2 = table2.child(i2);
91085
91992
  const end2 = pos + row2.nodeSize;
91086
91993
  const add = mustAdd[i2];
91087
91994
  if (add > 0) {
91088
91995
  let role = "cell";
91089
- if (row2.firstChild) {
91090
- role = row2.firstChild.type.spec.tableRole;
91091
- }
91996
+ if (row2.firstChild) role = row2.firstChild.type.spec.tableRole;
91092
91997
  const nodes = [];
91093
91998
  for (let j2 = 0; j2 < add; j2++) {
91094
91999
  const node2 = tableNodeTypes(state2.schema)[role].createAndFill();
@@ -91107,27 +92012,22 @@ ${l}
91107
92012
  const table2 = $pos.node(-1);
91108
92013
  const tableStart = $pos.start(-1);
91109
92014
  const map2 = TableMap.get(table2);
91110
- const rect = sel instanceof CellSelection ? map2.rectBetween(
91111
- sel.$anchorCell.pos - tableStart,
91112
- sel.$headCell.pos - tableStart
91113
- ) : map2.findCell($pos.pos - tableStart);
91114
- return { ...rect, tableStart, map: map2, table: table2 };
92015
+ return {
92016
+ ...sel instanceof CellSelection ? map2.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map2.findCell($pos.pos - tableStart),
92017
+ tableStart,
92018
+ map: map2,
92019
+ table: table2
92020
+ };
91115
92021
  }
91116
92022
  function addColumn(tr, { map: map2, tableStart, table: table2 }, col) {
91117
92023
  let refColumn = col > 0 ? -1 : 0;
91118
- if (columnIsHeader(map2, table2, col + refColumn)) {
91119
- refColumn = col == 0 || col == map2.width ? null : 0;
91120
- }
92024
+ if (columnIsHeader(map2, table2, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0;
91121
92025
  for (let row2 = 0; row2 < map2.height; row2++) {
91122
92026
  const index2 = row2 * map2.width + col;
91123
92027
  if (col > 0 && col < map2.width && map2.map[index2 - 1] == map2.map[index2]) {
91124
92028
  const pos = map2.map[index2];
91125
92029
  const cell2 = table2.nodeAt(pos);
91126
- tr.setNodeMarkup(
91127
- tr.mapping.map(tableStart + pos),
91128
- null,
91129
- addColSpan(cell2.attrs, col - map2.colCount(pos))
91130
- );
92030
+ tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell2.attrs, col - map2.colCount(pos)));
91131
92031
  row2 += cell2.attrs.rowspan - 1;
91132
92032
  } else {
91133
92033
  const type2 = refColumn == null ? tableNodeTypes(table2.type.schema).cell : table2.nodeAt(map2.map[index2 + refColumn]).type;
@@ -91160,13 +92060,8 @@ ${l}
91160
92060
  const pos = map2.map[index2];
91161
92061
  const cell2 = table2.nodeAt(pos);
91162
92062
  const attrs = cell2.attrs;
91163
- if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) {
91164
- tr.setNodeMarkup(
91165
- tr.mapping.slice(mapStart).map(tableStart + pos),
91166
- null,
91167
- removeColSpan(attrs, col - map2.colCount(pos))
91168
- );
91169
- } else {
92063
+ if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map2.colCount(pos)));
92064
+ else {
91170
92065
  const start2 = tr.mapping.slice(mapStart).map(tableStart + pos);
91171
92066
  tr.delete(start2, start2 + cell2.nodeSize);
91172
92067
  }
@@ -91183,9 +92078,7 @@ ${l}
91183
92078
  removeColumn(tr, rect, i2);
91184
92079
  if (i2 == rect.left) break;
91185
92080
  const table2 = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
91186
- if (!table2) {
91187
- throw RangeError("No table found");
91188
- }
92081
+ if (!table2) throw new RangeError("No table found");
91189
92082
  rect.table = table2;
91190
92083
  rect.map = TableMap.get(table2);
91191
92084
  }
@@ -91194,35 +92087,30 @@ ${l}
91194
92087
  return true;
91195
92088
  }
91196
92089
  function rowIsHeader(map2, table2, row2) {
91197
- var _a2;
92090
+ var _table$nodeAt;
91198
92091
  const headerCell = tableNodeTypes(table2.type.schema).header_cell;
91199
- for (let col = 0; col < map2.width; col++)
91200
- if (((_a2 = table2.nodeAt(map2.map[col + row2 * map2.width])) == null ? void 0 : _a2.type) != headerCell)
91201
- return false;
92092
+ for (let col = 0; col < map2.width; col++) if (((_table$nodeAt = table2.nodeAt(map2.map[col + row2 * map2.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
91202
92093
  return true;
91203
92094
  }
91204
92095
  function addRow(tr, { map: map2, tableStart, table: table2 }, row2) {
91205
- var _a2;
91206
92096
  let rowPos = tableStart;
91207
92097
  for (let i2 = 0; i2 < row2; i2++) rowPos += table2.child(i2).nodeSize;
91208
92098
  const cells = [];
91209
92099
  let refRow = row2 > 0 ? -1 : 0;
91210
- if (rowIsHeader(map2, table2, row2 + refRow))
91211
- refRow = row2 == 0 || row2 == map2.height ? null : 0;
91212
- for (let col = 0, index2 = map2.width * row2; col < map2.width; col++, index2++) {
91213
- if (row2 > 0 && row2 < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
91214
- const pos = map2.map[index2];
91215
- const attrs = table2.nodeAt(pos).attrs;
91216
- tr.setNodeMarkup(tableStart + pos, null, {
91217
- ...attrs,
91218
- rowspan: attrs.rowspan + 1
91219
- });
91220
- col += attrs.colspan - 1;
91221
- } else {
91222
- const type2 = refRow == null ? tableNodeTypes(table2.type.schema).cell : (_a2 = table2.nodeAt(map2.map[index2 + refRow * map2.width])) == null ? void 0 : _a2.type;
91223
- const node2 = type2 == null ? void 0 : type2.createAndFill();
91224
- if (node2) cells.push(node2);
91225
- }
92100
+ if (rowIsHeader(map2, table2, row2 + refRow)) refRow = row2 == 0 || row2 == map2.height ? null : 0;
92101
+ for (let col = 0, index2 = map2.width * row2; col < map2.width; col++, index2++) if (row2 > 0 && row2 < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
92102
+ const pos = map2.map[index2];
92103
+ const attrs = table2.nodeAt(pos).attrs;
92104
+ tr.setNodeMarkup(tableStart + pos, null, {
92105
+ ...attrs,
92106
+ rowspan: attrs.rowspan + 1
92107
+ });
92108
+ col += attrs.colspan - 1;
92109
+ } else {
92110
+ var _table$nodeAt2;
92111
+ const type2 = refRow == null ? tableNodeTypes(table2.type.schema).cell : (_table$nodeAt2 = table2.nodeAt(map2.map[index2 + refRow * map2.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
92112
+ const node2 = type2 === null || type2 === void 0 ? void 0 : type2.createAndFill();
92113
+ if (node2) cells.push(node2);
91226
92114
  }
91227
92115
  tr.insert(rowPos, tableNodeTypes(table2.type.schema).row.create(null, cells));
91228
92116
  return tr;
@@ -91264,10 +92152,10 @@ ${l}
91264
92152
  } else if (row2 < map2.height && pos == map2.map[index2 + map2.width]) {
91265
92153
  const cell2 = table2.nodeAt(pos);
91266
92154
  const attrs = cell2.attrs;
91267
- const copy2 = cell2.type.create(
91268
- { ...attrs, rowspan: cell2.attrs.rowspan - 1 },
91269
- cell2.content
91270
- );
92155
+ const copy2 = cell2.type.create({
92156
+ ...attrs,
92157
+ rowspan: cell2.attrs.rowspan - 1
92158
+ }, cell2.content);
91271
92159
  const newPos = map2.positionAt(row2 + 1, col, table2);
91272
92160
  tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy2);
91273
92161
  col += attrs.colspan - 1;
@@ -91283,9 +92171,7 @@ ${l}
91283
92171
  removeRow(tr, rect, i2);
91284
92172
  if (i2 == rect.top) break;
91285
92173
  const table2 = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
91286
- if (!table2) {
91287
- throw RangeError("No table found");
91288
- }
92174
+ if (!table2) throw new RangeError("No table found");
91289
92175
  rect.table = table2;
91290
92176
  rect.map = TableMap.get(rect.table);
91291
92177
  }
@@ -91301,14 +92187,12 @@ ${l}
91301
92187
  let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
91302
92188
  let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
91303
92189
  for (let i2 = rect.top; i2 < rect.bottom; i2++) {
91304
- if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1])
91305
- return true;
92190
+ if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true;
91306
92191
  indexLeft += width;
91307
92192
  indexRight += width;
91308
92193
  }
91309
92194
  for (let i2 = rect.left; i2 < rect.right; i2++) {
91310
- if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width])
91311
- return true;
92195
+ if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true;
91312
92196
  indexTop++;
91313
92197
  indexBottom++;
91314
92198
  }
@@ -91316,8 +92200,7 @@ ${l}
91316
92200
  }
91317
92201
  function mergeCells(state2, dispatch) {
91318
92202
  const sel = state2.selection;
91319
- if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
91320
- return false;
92203
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
91321
92204
  const rect = selectedRect(state2), { map: map2 } = rect;
91322
92205
  if (cellsOverlapRectangle(map2, rect)) return false;
91323
92206
  if (dispatch) {
@@ -91326,41 +92209,31 @@ ${l}
91326
92209
  let content2 = Fragment$1.empty;
91327
92210
  let mergedPos;
91328
92211
  let mergedCell;
91329
- for (let row2 = rect.top; row2 < rect.bottom; row2++) {
91330
- for (let col = rect.left; col < rect.right; col++) {
91331
- const cellPos = map2.map[row2 * map2.width + col];
91332
- const cell2 = rect.table.nodeAt(cellPos);
91333
- if (seen[cellPos] || !cell2) continue;
91334
- seen[cellPos] = true;
91335
- if (mergedPos == null) {
91336
- mergedPos = cellPos;
91337
- mergedCell = cell2;
91338
- } else {
91339
- if (!isEmpty(cell2)) content2 = content2.append(cell2.content);
91340
- const mapped = tr.mapping.map(cellPos + rect.tableStart);
91341
- tr.delete(mapped, mapped + cell2.nodeSize);
91342
- }
92212
+ for (let row2 = rect.top; row2 < rect.bottom; row2++) for (let col = rect.left; col < rect.right; col++) {
92213
+ const cellPos = map2.map[row2 * map2.width + col];
92214
+ const cell2 = rect.table.nodeAt(cellPos);
92215
+ if (seen[cellPos] || !cell2) continue;
92216
+ seen[cellPos] = true;
92217
+ if (mergedPos == null) {
92218
+ mergedPos = cellPos;
92219
+ mergedCell = cell2;
92220
+ } else {
92221
+ if (!isEmpty(cell2)) content2 = content2.append(cell2.content);
92222
+ const mapped = tr.mapping.map(cellPos + rect.tableStart);
92223
+ tr.delete(mapped, mapped + cell2.nodeSize);
91343
92224
  }
91344
92225
  }
91345
- if (mergedPos == null || mergedCell == null) {
91346
- return true;
91347
- }
92226
+ if (mergedPos == null || mergedCell == null) return true;
91348
92227
  tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
91349
- ...addColSpan(
91350
- mergedCell.attrs,
91351
- mergedCell.attrs.colspan,
91352
- rect.right - rect.left - mergedCell.attrs.colspan
91353
- ),
92228
+ ...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
91354
92229
  rowspan: rect.bottom - rect.top
91355
92230
  });
91356
- if (content2.size) {
92231
+ if (content2.size > 0) {
91357
92232
  const end2 = mergedPos + 1 + mergedCell.content.size;
91358
92233
  const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
91359
92234
  tr.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content2);
91360
92235
  }
91361
- tr.setSelection(
91362
- new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
91363
- );
92236
+ tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
91364
92237
  dispatch(tr);
91365
92238
  }
91366
92239
  return true;
@@ -91373,63 +92246,57 @@ ${l}
91373
92246
  }
91374
92247
  function splitCellWithType(getCellType2) {
91375
92248
  return (state2, dispatch) => {
91376
- var _a2;
91377
92249
  const sel = state2.selection;
91378
92250
  let cellNode;
91379
92251
  let cellPos;
91380
92252
  if (!(sel instanceof CellSelection)) {
92253
+ var _cellAround;
91381
92254
  cellNode = cellWrapping$1(sel.$from);
91382
92255
  if (!cellNode) return false;
91383
- cellPos = (_a2 = cellAround$1(sel.$from)) == null ? void 0 : _a2.pos;
92256
+ cellPos = (_cellAround = cellAround$1(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
91384
92257
  } else {
91385
92258
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
91386
92259
  cellNode = sel.$anchorCell.nodeAfter;
91387
92260
  cellPos = sel.$anchorCell.pos;
91388
92261
  }
91389
- if (cellNode == null || cellPos == null) {
91390
- return false;
91391
- }
91392
- if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
91393
- return false;
91394
- }
92262
+ if (cellNode == null || cellPos == null) return false;
92263
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
91395
92264
  if (dispatch) {
91396
92265
  let baseAttrs = cellNode.attrs;
91397
92266
  const attrs = [];
91398
92267
  const colwidth = baseAttrs.colwidth;
91399
- if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };
91400
- if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };
92268
+ if (baseAttrs.rowspan > 1) baseAttrs = {
92269
+ ...baseAttrs,
92270
+ rowspan: 1
92271
+ };
92272
+ if (baseAttrs.colspan > 1) baseAttrs = {
92273
+ ...baseAttrs,
92274
+ colspan: 1
92275
+ };
91401
92276
  const rect = selectedRect(state2), tr = state2.tr;
91402
- for (let i2 = 0; i2 < rect.right - rect.left; i2++)
91403
- attrs.push(
91404
- colwidth ? {
91405
- ...baseAttrs,
91406
- colwidth: colwidth && colwidth[i2] ? [colwidth[i2]] : null
91407
- } : baseAttrs
91408
- );
92277
+ for (let i2 = 0; i2 < rect.right - rect.left; i2++) attrs.push(colwidth ? {
92278
+ ...baseAttrs,
92279
+ colwidth: colwidth && colwidth[i2] ? [colwidth[i2]] : null
92280
+ } : baseAttrs);
91409
92281
  let lastCell;
91410
92282
  for (let row2 = rect.top; row2 < rect.bottom; row2++) {
91411
92283
  let pos = rect.map.positionAt(row2, rect.left, rect.table);
91412
92284
  if (row2 == rect.top) pos += cellNode.nodeSize;
91413
92285
  for (let col = rect.left, i2 = 0; col < rect.right; col++, i2++) {
91414
92286
  if (col == rect.left && row2 == rect.top) continue;
91415
- tr.insert(
91416
- lastCell = tr.mapping.map(pos + rect.tableStart, 1),
91417
- getCellType2({ node: cellNode, row: row2, col }).createAndFill(attrs[i2])
91418
- );
91419
- }
91420
- }
91421
- tr.setNodeMarkup(
91422
- cellPos,
91423
- getCellType2({ node: cellNode, row: rect.top, col: rect.left }),
91424
- attrs[0]
91425
- );
91426
- if (sel instanceof CellSelection)
91427
- tr.setSelection(
91428
- new CellSelection(
91429
- tr.doc.resolve(sel.$anchorCell.pos),
91430
- lastCell ? tr.doc.resolve(lastCell) : void 0
91431
- )
91432
- );
92287
+ tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType2({
92288
+ node: cellNode,
92289
+ row: row2,
92290
+ col
92291
+ }).createAndFill(attrs[i2]));
92292
+ }
92293
+ }
92294
+ tr.setNodeMarkup(cellPos, getCellType2({
92295
+ node: cellNode,
92296
+ row: rect.top,
92297
+ col: rect.left
92298
+ }), attrs[0]);
92299
+ if (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));
91433
92300
  dispatch(tr);
91434
92301
  }
91435
92302
  return true;
@@ -91442,19 +92309,16 @@ ${l}
91442
92309
  if ($cell.nodeAfter.attrs[name] === value) return false;
91443
92310
  if (dispatch) {
91444
92311
  const tr = state2.tr;
91445
- if (state2.selection instanceof CellSelection)
91446
- state2.selection.forEachCell((node2, pos) => {
91447
- if (node2.attrs[name] !== value)
91448
- tr.setNodeMarkup(pos, null, {
91449
- ...node2.attrs,
91450
- [name]: value
91451
- });
91452
- });
91453
- else
91454
- tr.setNodeMarkup($cell.pos, null, {
91455
- ...$cell.nodeAfter.attrs,
92312
+ if (state2.selection instanceof CellSelection) state2.selection.forEachCell((node2, pos) => {
92313
+ if (node2.attrs[name] !== value) tr.setNodeMarkup(pos, null, {
92314
+ ...node2.attrs,
91456
92315
  [name]: value
91457
92316
  });
92317
+ });
92318
+ else tr.setNodeMarkup($cell.pos, null, {
92319
+ ...$cell.nodeAfter.attrs,
92320
+ [name]: value
92321
+ });
91458
92322
  dispatch(tr);
91459
92323
  }
91460
92324
  return true;
@@ -91466,34 +92330,20 @@ ${l}
91466
92330
  if (dispatch) {
91467
92331
  const types2 = tableNodeTypes(state2.schema);
91468
92332
  const rect = selectedRect(state2), tr = state2.tr;
91469
- const cells = rect.map.cellsInRect(
91470
- type2 == "column" ? {
91471
- left: rect.left,
91472
- top: 0,
91473
- right: rect.right,
91474
- bottom: rect.map.height
91475
- } : type2 == "row" ? {
91476
- left: 0,
91477
- top: rect.top,
91478
- right: rect.map.width,
91479
- bottom: rect.bottom
91480
- } : rect
91481
- );
92333
+ const cells = rect.map.cellsInRect(type2 == "column" ? {
92334
+ left: rect.left,
92335
+ top: 0,
92336
+ right: rect.right,
92337
+ bottom: rect.map.height
92338
+ } : type2 == "row" ? {
92339
+ left: 0,
92340
+ top: rect.top,
92341
+ right: rect.map.width,
92342
+ bottom: rect.bottom
92343
+ } : rect);
91482
92344
  const nodes = cells.map((pos) => rect.table.nodeAt(pos));
91483
- for (let i2 = 0; i2 < cells.length; i2++)
91484
- if (nodes[i2].type == types2.header_cell)
91485
- tr.setNodeMarkup(
91486
- rect.tableStart + cells[i2],
91487
- types2.cell,
91488
- nodes[i2].attrs
91489
- );
91490
- if (tr.steps.length == 0)
91491
- for (let i2 = 0; i2 < cells.length; i2++)
91492
- tr.setNodeMarkup(
91493
- rect.tableStart + cells[i2],
91494
- types2.header_cell,
91495
- nodes[i2].attrs
91496
- );
92345
+ for (let i2 = 0; i2 < cells.length; i2++) if (nodes[i2].type == types2.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i2], types2.cell, nodes[i2].attrs);
92346
+ if (tr.steps.length === 0) for (let i2 = 0; i2 < cells.length; i2++) tr.setNodeMarkup(rect.tableStart + cells[i2], types2.header_cell, nodes[i2].attrs);
91497
92347
  dispatch(tr);
91498
92348
  }
91499
92349
  return true;
@@ -91508,9 +92358,7 @@ ${l}
91508
92358
  });
91509
92359
  for (let i2 = 0; i2 < cellPositions.length; i2++) {
91510
92360
  const cell2 = rect.table.nodeAt(cellPositions[i2]);
91511
- if (cell2 && cell2.type !== types2.header_cell) {
91512
- return false;
91513
- }
92361
+ if (cell2 && cell2.type !== types2.header_cell) return false;
91514
92362
  }
91515
92363
  return true;
91516
92364
  }
@@ -91523,13 +92371,8 @@ ${l}
91523
92371
  const types2 = tableNodeTypes(state2.schema);
91524
92372
  const rect = selectedRect(state2), tr = state2.tr;
91525
92373
  const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types2);
91526
- const isHeaderColumnEnabled = isHeaderEnabledByType(
91527
- "column",
91528
- rect,
91529
- types2
91530
- );
91531
- const isHeaderEnabled = type2 === "column" ? isHeaderRowEnabled : type2 === "row" ? isHeaderColumnEnabled : false;
91532
- const selectionStartsAt = isHeaderEnabled ? 1 : 0;
92374
+ const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types2);
92375
+ const selectionStartsAt = (type2 === "column" ? isHeaderRowEnabled : type2 === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
91533
92376
  const cellsRect = type2 == "column" ? {
91534
92377
  left: 0,
91535
92378
  top: selectionStartsAt,
@@ -91545,24 +92388,16 @@ ${l}
91545
92388
  rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
91546
92389
  const cellPos = relativeCellPos + rect.tableStart;
91547
92390
  const cell2 = tr.doc.nodeAt(cellPos);
91548
- if (cell2) {
91549
- tr.setNodeMarkup(cellPos, newType, cell2.attrs);
91550
- }
92391
+ if (cell2) tr.setNodeMarkup(cellPos, newType, cell2.attrs);
91551
92392
  });
91552
92393
  dispatch(tr);
91553
92394
  }
91554
92395
  return true;
91555
92396
  };
91556
92397
  }
91557
- toggleHeader("row", {
91558
- useDeprecatedLogic: true
91559
- });
91560
- toggleHeader("column", {
91561
- useDeprecatedLogic: true
91562
- });
91563
- var toggleHeaderCell = toggleHeader("cell", {
91564
- useDeprecatedLogic: true
91565
- });
92398
+ toggleHeader("row", { useDeprecatedLogic: true });
92399
+ toggleHeader("column", { useDeprecatedLogic: true });
92400
+ const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
91566
92401
  function findNextCell($cell, dir) {
91567
92402
  if (dir < 0) {
91568
92403
  const before = $cell.nodeBefore;
@@ -91570,15 +92405,11 @@ ${l}
91570
92405
  for (let row2 = $cell.index(-1) - 1, rowEnd = $cell.before(); row2 >= 0; row2--) {
91571
92406
  const rowNode = $cell.node(-1).child(row2);
91572
92407
  const lastChild = rowNode.lastChild;
91573
- if (lastChild) {
91574
- return rowEnd - 1 - lastChild.nodeSize;
91575
- }
92408
+ if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
91576
92409
  rowEnd -= rowNode.nodeSize;
91577
92410
  }
91578
92411
  } else {
91579
- if ($cell.index() < $cell.parent.childCount - 1) {
91580
- return $cell.pos + $cell.nodeAfter.nodeSize;
91581
- }
92412
+ if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
91582
92413
  const table2 = $cell.node(-1);
91583
92414
  for (let row2 = $cell.indexAfter(-1), rowStart = $cell.after(); row2 < table2.childCount; row2++) {
91584
92415
  const rowNode = table2.child(row2);
@@ -91595,24 +92426,16 @@ ${l}
91595
92426
  if (cell2 == null) return false;
91596
92427
  if (dispatch) {
91597
92428
  const $cell = state2.doc.resolve(cell2);
91598
- dispatch(
91599
- state2.tr.setSelection(TextSelection$1.between($cell, moveCellForward($cell))).scrollIntoView()
91600
- );
92429
+ dispatch(state2.tr.setSelection(TextSelection$1.between($cell, moveCellForward($cell))).scrollIntoView());
91601
92430
  }
91602
92431
  return true;
91603
92432
  };
91604
92433
  }
91605
92434
  function deleteTable(state2, dispatch) {
91606
92435
  const $pos = state2.selection.$anchor;
91607
- for (let d2 = $pos.depth; d2 > 0; d2--) {
91608
- const node2 = $pos.node(d2);
91609
- if (node2.type.spec.tableRole == "table") {
91610
- if (dispatch)
91611
- dispatch(
91612
- state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
91613
- );
91614
- return true;
91615
- }
92436
+ for (let d2 = $pos.depth; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "table") {
92437
+ if (dispatch) dispatch(state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView());
92438
+ return true;
91616
92439
  }
91617
92440
  return false;
91618
92441
  }
@@ -91623,19 +92446,14 @@ ${l}
91623
92446
  const tr = state2.tr;
91624
92447
  const baseContent = tableNodeTypes(state2.schema).cell.createAndFill().content;
91625
92448
  sel.forEachCell((cell2, pos) => {
91626
- if (!cell2.content.eq(baseContent))
91627
- tr.replace(
91628
- tr.mapping.map(pos + 1),
91629
- tr.mapping.map(pos + cell2.nodeSize - 1),
91630
- new Slice(baseContent, 0, 0)
91631
- );
92449
+ if (!cell2.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell2.nodeSize - 1), new Slice(baseContent, 0, 0));
91632
92450
  });
91633
92451
  if (tr.docChanged) dispatch(tr);
91634
92452
  }
91635
92453
  return true;
91636
92454
  }
91637
92455
  function pastedCells(slice2) {
91638
- if (!slice2.size) return null;
92456
+ if (slice2.size === 0) return null;
91639
92457
  let { content: content2, openStart, openEnd } = slice2;
91640
92458
  while (content2.childCount == 1 && (openStart > 0 && openEnd > 0 || content2.child(0).type.spec.tableRole == "table")) {
91641
92459
  openStart--;
@@ -91645,28 +92463,15 @@ ${l}
91645
92463
  const first2 = content2.child(0);
91646
92464
  const role = first2.type.spec.tableRole;
91647
92465
  const schema = first2.type.schema, rows = [];
91648
- if (role == "row") {
91649
- for (let i2 = 0; i2 < content2.childCount; i2++) {
91650
- let cells = content2.child(i2).content;
91651
- const left2 = i2 ? 0 : Math.max(0, openStart - 1);
91652
- const right2 = i2 < content2.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
91653
- if (left2 || right2)
91654
- cells = fitSlice(
91655
- tableNodeTypes(schema).row,
91656
- new Slice(cells, left2, right2)
91657
- ).content;
91658
- rows.push(cells);
91659
- }
91660
- } else if (role == "cell" || role == "header_cell") {
91661
- rows.push(
91662
- openStart || openEnd ? fitSlice(
91663
- tableNodeTypes(schema).row,
91664
- new Slice(content2, openStart, openEnd)
91665
- ).content : content2
91666
- );
91667
- } else {
91668
- return null;
91669
- }
92466
+ if (role == "row") for (let i2 = 0; i2 < content2.childCount; i2++) {
92467
+ let cells = content2.child(i2).content;
92468
+ const left2 = i2 ? 0 : Math.max(0, openStart - 1);
92469
+ const right2 = i2 < content2.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
92470
+ if (left2 || right2) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left2, right2)).content;
92471
+ rows.push(cells);
92472
+ }
92473
+ else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content2, openStart, openEnd)).content : content2);
92474
+ else return null;
91670
92475
  return ensureRectangular(schema, rows);
91671
92476
  }
91672
92477
  function ensureRectangular(schema, rows) {
@@ -91675,8 +92480,7 @@ ${l}
91675
92480
  const row2 = rows[i2];
91676
92481
  for (let j2 = row2.childCount - 1; j2 >= 0; j2--) {
91677
92482
  const { rowspan, colspan } = row2.child(j2).attrs;
91678
- for (let r2 = i2; r2 < i2 + rowspan; r2++)
91679
- widths[r2] = (widths[r2] || 0) + colspan;
92483
+ for (let r2 = i2; r2 < i2 + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
91680
92484
  }
91681
92485
  }
91682
92486
  let width = 0;
@@ -91686,18 +92490,19 @@ ${l}
91686
92490
  if (widths[r2] < width) {
91687
92491
  const empty2 = tableNodeTypes(schema).cell.createAndFill();
91688
92492
  const cells = [];
91689
- for (let i2 = widths[r2]; i2 < width; i2++) {
91690
- cells.push(empty2);
91691
- }
92493
+ for (let i2 = widths[r2]; i2 < width; i2++) cells.push(empty2);
91692
92494
  rows[r2] = rows[r2].append(Fragment$1.from(cells));
91693
92495
  }
91694
92496
  }
91695
- return { height: rows.length, width, rows };
92497
+ return {
92498
+ height: rows.length,
92499
+ width,
92500
+ rows
92501
+ };
91696
92502
  }
91697
92503
  function fitSlice(nodeType, slice2) {
91698
92504
  const node2 = nodeType.createAndFill();
91699
- const tr = new Transform(node2).replace(0, node2.content.size, slice2);
91700
- return tr.doc;
92505
+ return new Transform(node2).replace(0, node2.content.size, slice2).doc;
91701
92506
  }
91702
92507
  function clipCells({ width, height, rows }, newWidth, newHeight) {
91703
92508
  if (width != newWidth) {
@@ -91707,19 +92512,10 @@ ${l}
91707
92512
  const frag = rows[row2], cells = [];
91708
92513
  for (let col = added[row2] || 0, i2 = 0; col < newWidth; i2++) {
91709
92514
  let cell2 = frag.child(i2 % frag.childCount);
91710
- if (col + cell2.attrs.colspan > newWidth)
91711
- cell2 = cell2.type.createChecked(
91712
- removeColSpan(
91713
- cell2.attrs,
91714
- cell2.attrs.colspan,
91715
- col + cell2.attrs.colspan - newWidth
91716
- ),
91717
- cell2.content
91718
- );
92515
+ if (col + cell2.attrs.colspan > newWidth) cell2 = cell2.type.createChecked(removeColSpan(cell2.attrs, cell2.attrs.colspan, col + cell2.attrs.colspan - newWidth), cell2.content);
91719
92516
  cells.push(cell2);
91720
92517
  col += cell2.attrs.colspan;
91721
- for (let j2 = 1; j2 < cell2.attrs.rowspan; j2++)
91722
- added[row2 + j2] = (added[row2 + j2] || 0) + cell2.attrs.colspan;
92518
+ for (let j2 = 1; j2 < cell2.attrs.rowspan; j2++) added[row2 + j2] = (added[row2 + j2] || 0) + cell2.attrs.colspan;
91723
92519
  }
91724
92520
  newRows.push(Fragment$1.from(cells));
91725
92521
  }
@@ -91732,14 +92528,10 @@ ${l}
91732
92528
  const cells = [], source = rows[i2 % height];
91733
92529
  for (let j2 = 0; j2 < source.childCount; j2++) {
91734
92530
  let cell2 = source.child(j2);
91735
- if (row2 + cell2.attrs.rowspan > newHeight)
91736
- cell2 = cell2.type.create(
91737
- {
91738
- ...cell2.attrs,
91739
- rowspan: Math.max(1, newHeight - cell2.attrs.rowspan)
91740
- },
91741
- cell2.content
91742
- );
92531
+ if (row2 + cell2.attrs.rowspan > newHeight) cell2 = cell2.type.create({
92532
+ ...cell2.attrs,
92533
+ rowspan: Math.max(1, newHeight - cell2.attrs.rowspan)
92534
+ }, cell2.content);
91743
92535
  cells.push(cell2);
91744
92536
  }
91745
92537
  newRows.push(Fragment$1.from(cells));
@@ -91747,33 +92539,32 @@ ${l}
91747
92539
  rows = newRows;
91748
92540
  height = newHeight;
91749
92541
  }
91750
- return { width, height, rows };
92542
+ return {
92543
+ width,
92544
+ height,
92545
+ rows
92546
+ };
91751
92547
  }
91752
92548
  function growTable(tr, map2, table2, start2, width, height, mapFrom) {
91753
92549
  const schema = tr.doc.type.schema;
91754
92550
  const types2 = tableNodeTypes(schema);
91755
92551
  let empty2;
91756
92552
  let emptyHead;
91757
- if (width > map2.width) {
91758
- for (let row2 = 0, rowEnd = 0; row2 < map2.height; row2++) {
91759
- const rowNode = table2.child(row2);
91760
- rowEnd += rowNode.nodeSize;
91761
- const cells = [];
91762
- let add;
91763
- if (rowNode.lastChild == null || rowNode.lastChild.type == types2.cell)
91764
- add = empty2 || (empty2 = types2.cell.createAndFill());
91765
- else add = emptyHead || (emptyHead = types2.header_cell.createAndFill());
91766
- for (let i2 = map2.width; i2 < width; i2++) cells.push(add);
91767
- tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
91768
- }
92553
+ if (width > map2.width) for (let row2 = 0, rowEnd = 0; row2 < map2.height; row2++) {
92554
+ const rowNode = table2.child(row2);
92555
+ rowEnd += rowNode.nodeSize;
92556
+ const cells = [];
92557
+ let add;
92558
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types2.cell) add = empty2 || (empty2 = types2.cell.createAndFill());
92559
+ else add = emptyHead || (emptyHead = types2.header_cell.createAndFill());
92560
+ for (let i2 = map2.width; i2 < width; i2++) cells.push(add);
92561
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
91769
92562
  }
91770
92563
  if (height > map2.height) {
91771
92564
  const cells = [];
91772
- for (let i2 = 0, start22 = (map2.height - 1) * map2.width; i2 < Math.max(map2.width, width); i2++) {
91773
- const header = i2 >= map2.width ? false : table2.nodeAt(map2.map[start22 + i2]).type == types2.header_cell;
91774
- cells.push(
91775
- header ? emptyHead || (emptyHead = types2.header_cell.createAndFill()) : empty2 || (empty2 = types2.cell.createAndFill())
91776
- );
92565
+ for (let i2 = 0, start$1 = (map2.height - 1) * map2.width; i2 < Math.max(map2.width, width); i2++) {
92566
+ const header = i2 >= map2.width ? false : table2.nodeAt(map2.map[start$1 + i2]).type == types2.header_cell;
92567
+ cells.push(header ? emptyHead || (emptyHead = types2.header_cell.createAndFill()) : empty2 || (empty2 = types2.cell.createAndFill()));
91777
92568
  }
91778
92569
  const emptyRow = types2.row.create(null, Fragment$1.from(cells)), rows = [];
91779
92570
  for (let i2 = map2.height; i2 < height; i2++) rows.push(emptyRow);
@@ -91794,13 +92585,10 @@ ${l}
91794
92585
  ...cell2.attrs,
91795
92586
  rowspan: top2 - cellTop
91796
92587
  });
91797
- tr.insert(
91798
- tr.mapping.slice(mapFrom).map(map2.positionAt(top2, cellLeft, table2)),
91799
- cell2.type.createAndFill({
91800
- ...cell2.attrs,
91801
- rowspan: cellTop + cell2.attrs.rowspan - top2
91802
- })
91803
- );
92588
+ tr.insert(tr.mapping.slice(mapFrom).map(map2.positionAt(top2, cellLeft, table2)), cell2.type.createAndFill({
92589
+ ...cell2.attrs,
92590
+ rowspan: cellTop + cell2.attrs.rowspan - top2
92591
+ }));
91804
92592
  col += cell2.attrs.colspan - 1;
91805
92593
  }
91806
92594
  }
@@ -91816,21 +92604,8 @@ ${l}
91816
92604
  const cell2 = table2.nodeAt(pos);
91817
92605
  const cellLeft = map2.colCount(pos);
91818
92606
  const updatePos = tr.mapping.slice(mapFrom).map(pos + start2);
91819
- tr.setNodeMarkup(
91820
- updatePos,
91821
- null,
91822
- removeColSpan(
91823
- cell2.attrs,
91824
- left2 - cellLeft,
91825
- cell2.attrs.colspan - (left2 - cellLeft)
91826
- )
91827
- );
91828
- tr.insert(
91829
- updatePos + cell2.nodeSize,
91830
- cell2.type.createAndFill(
91831
- removeColSpan(cell2.attrs, 0, left2 - cellLeft)
91832
- )
91833
- );
92607
+ tr.setNodeMarkup(updatePos, null, removeColSpan(cell2.attrs, left2 - cellLeft, cell2.attrs.colspan - (left2 - cellLeft)));
92608
+ tr.insert(updatePos + cell2.nodeSize, cell2.type.createAndFill(removeColSpan(cell2.attrs, 0, left2 - cellLeft)));
91834
92609
  row2 += cell2.attrs.rowspan - 1;
91835
92610
  }
91836
92611
  }
@@ -91838,9 +92613,7 @@ ${l}
91838
92613
  }
91839
92614
  function insertCells(state2, dispatch, tableStart, rect, cells) {
91840
92615
  let table2 = tableStart ? state2.doc.nodeAt(tableStart - 1) : state2.doc;
91841
- if (!table2) {
91842
- throw new Error("No table found");
91843
- }
92616
+ if (!table2) throw new Error("No table found");
91844
92617
  let map2 = TableMap.get(table2);
91845
92618
  const { top: top2, left: left2 } = rect;
91846
92619
  const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
@@ -91848,39 +92621,24 @@ ${l}
91848
92621
  let mapFrom = 0;
91849
92622
  function recomp() {
91850
92623
  table2 = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
91851
- if (!table2) {
91852
- throw new Error("No table found");
91853
- }
92624
+ if (!table2) throw new Error("No table found");
91854
92625
  map2 = TableMap.get(table2);
91855
92626
  mapFrom = tr.mapping.maps.length;
91856
92627
  }
91857
92628
  if (growTable(tr, map2, table2, tableStart, right2, bottom2, mapFrom)) recomp();
91858
- if (isolateHorizontal(tr, map2, table2, tableStart, left2, right2, top2, mapFrom))
91859
- recomp();
91860
- if (isolateHorizontal(tr, map2, table2, tableStart, left2, right2, bottom2, mapFrom))
91861
- recomp();
91862
- if (isolateVertical(tr, map2, table2, tableStart, top2, bottom2, left2, mapFrom))
91863
- recomp();
91864
- if (isolateVertical(tr, map2, table2, tableStart, top2, bottom2, right2, mapFrom))
91865
- recomp();
92629
+ if (isolateHorizontal(tr, map2, table2, tableStart, left2, right2, top2, mapFrom)) recomp();
92630
+ if (isolateHorizontal(tr, map2, table2, tableStart, left2, right2, bottom2, mapFrom)) recomp();
92631
+ if (isolateVertical(tr, map2, table2, tableStart, top2, bottom2, left2, mapFrom)) recomp();
92632
+ if (isolateVertical(tr, map2, table2, tableStart, top2, bottom2, right2, mapFrom)) recomp();
91866
92633
  for (let row2 = top2; row2 < bottom2; row2++) {
91867
92634
  const from2 = map2.positionAt(row2, left2, table2), to = map2.positionAt(row2, right2, table2);
91868
- tr.replace(
91869
- tr.mapping.slice(mapFrom).map(from2 + tableStart),
91870
- tr.mapping.slice(mapFrom).map(to + tableStart),
91871
- new Slice(cells.rows[row2 - top2], 0, 0)
91872
- );
92635
+ tr.replace(tr.mapping.slice(mapFrom).map(from2 + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row2 - top2], 0, 0));
91873
92636
  }
91874
92637
  recomp();
91875
- tr.setSelection(
91876
- new CellSelection(
91877
- tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table2)),
91878
- tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table2))
91879
- )
91880
- );
92638
+ tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table2)), tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table2))));
91881
92639
  dispatch(tr);
91882
92640
  }
91883
- var handleKeyDown = keydownHandler({
92641
+ const handleKeyDown = keydownHandler({
91884
92642
  ArrowLeft: arrow$2("horiz", -1),
91885
92643
  ArrowRight: arrow$2("horiz", 1),
91886
92644
  ArrowUp: arrow$2("vert", -1),
@@ -91903,29 +92661,17 @@ ${l}
91903
92661
  return (state2, dispatch, view) => {
91904
92662
  if (!view) return false;
91905
92663
  const sel = state2.selection;
91906
- if (sel instanceof CellSelection) {
91907
- return maybeSetSelection(
91908
- state2,
91909
- dispatch,
91910
- Selection.near(sel.$headCell, dir)
91911
- );
91912
- }
92664
+ if (sel instanceof CellSelection) return maybeSetSelection(state2, dispatch, Selection.near(sel.$headCell, dir));
91913
92665
  if (axis != "horiz" && !sel.empty) return false;
91914
92666
  const end2 = atEndOfCell(view, axis, dir);
91915
92667
  if (end2 == null) return false;
91916
- if (axis == "horiz") {
91917
- return maybeSetSelection(
91918
- state2,
91919
- dispatch,
91920
- Selection.near(state2.doc.resolve(sel.head + dir), dir)
91921
- );
91922
- } else {
92668
+ if (axis == "horiz") return maybeSetSelection(state2, dispatch, Selection.near(state2.doc.resolve(sel.head + dir), dir));
92669
+ else {
91923
92670
  const $cell = state2.doc.resolve(end2);
91924
92671
  const $next = nextCell($cell, axis, dir);
91925
92672
  let newSel;
91926
92673
  if ($next) newSel = Selection.near($next, 1);
91927
- else if (dir < 0)
91928
- newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
92674
+ else if (dir < 0) newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
91929
92675
  else newSel = Selection.near(state2.doc.resolve($cell.after(-1)), 1);
91930
92676
  return maybeSetSelection(state2, dispatch, newSel);
91931
92677
  }
@@ -91936,20 +92682,15 @@ ${l}
91936
92682
  if (!view) return false;
91937
92683
  const sel = state2.selection;
91938
92684
  let cellSel;
91939
- if (sel instanceof CellSelection) {
91940
- cellSel = sel;
91941
- } else {
92685
+ if (sel instanceof CellSelection) cellSel = sel;
92686
+ else {
91942
92687
  const end2 = atEndOfCell(view, axis, dir);
91943
92688
  if (end2 == null) return false;
91944
92689
  cellSel = new CellSelection(state2.doc.resolve(end2));
91945
92690
  }
91946
92691
  const $head = nextCell(cellSel.$headCell, axis, dir);
91947
92692
  if (!$head) return false;
91948
- return maybeSetSelection(
91949
- state2,
91950
- dispatch,
91951
- new CellSelection(cellSel.$anchorCell, $head)
91952
- );
92693
+ return maybeSetSelection(state2, dispatch, new CellSelection(cellSel.$anchorCell, $head));
91953
92694
  };
91954
92695
  }
91955
92696
  function handleTripleClick(view, pos) {
@@ -91963,65 +92704,45 @@ ${l}
91963
92704
  let cells = pastedCells(slice2);
91964
92705
  const sel = view.state.selection;
91965
92706
  if (sel instanceof CellSelection) {
91966
- if (!cells)
91967
- cells = {
91968
- width: 1,
91969
- height: 1,
91970
- rows: [
91971
- Fragment$1.from(
91972
- fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
91973
- )
91974
- ]
91975
- };
92707
+ if (!cells) cells = {
92708
+ width: 1,
92709
+ height: 1,
92710
+ rows: [Fragment$1.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
92711
+ };
91976
92712
  const table2 = sel.$anchorCell.node(-1);
91977
92713
  const start2 = sel.$anchorCell.start(-1);
91978
- const rect = TableMap.get(table2).rectBetween(
91979
- sel.$anchorCell.pos - start2,
91980
- sel.$headCell.pos - start2
91981
- );
92714
+ const rect = TableMap.get(table2).rectBetween(sel.$anchorCell.pos - start2, sel.$headCell.pos - start2);
91982
92715
  cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
91983
92716
  insertCells(view.state, view.dispatch, start2, rect, cells);
91984
92717
  return true;
91985
92718
  } else if (cells) {
91986
92719
  const $cell = selectionCell(view.state);
91987
92720
  const start2 = $cell.start(-1);
91988
- insertCells(
91989
- view.state,
91990
- view.dispatch,
91991
- start2,
91992
- TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
91993
- cells
91994
- );
92721
+ insertCells(view.state, view.dispatch, start2, TableMap.get($cell.node(-1)).findCell($cell.pos - start2), cells);
91995
92722
  return true;
91996
- } else {
91997
- return false;
91998
- }
92723
+ } else return false;
91999
92724
  }
92000
92725
  function handleMouseDown(view, startEvent) {
92001
- var _a2;
92726
+ var _cellUnderMouse;
92002
92727
  if (startEvent.ctrlKey || startEvent.metaKey) return;
92003
92728
  const startDOMCell = domInCell(view, startEvent.target);
92004
92729
  let $anchor;
92005
92730
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
92006
92731
  setCellSelection(view.state.selection.$anchorCell, startEvent);
92007
92732
  startEvent.preventDefault();
92008
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_a2 = cellUnderMouse(view, startEvent)) == null ? void 0 : _a2.pos) != $anchor.pos) {
92733
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {
92009
92734
  setCellSelection($anchor, startEvent);
92010
92735
  startEvent.preventDefault();
92011
- } else if (!startDOMCell) {
92012
- return;
92013
- }
92014
- function setCellSelection($anchor2, event) {
92736
+ } else if (!startDOMCell) return;
92737
+ function setCellSelection($anchor$1, event) {
92015
92738
  let $head = cellUnderMouse(view, event);
92016
92739
  const starting = tableEditingKey.getState(view.state) == null;
92017
- if (!$head || !inSameTable($anchor2, $head)) {
92018
- if (starting) $head = $anchor2;
92019
- else return;
92020
- }
92021
- const selection = new CellSelection($anchor2, $head);
92740
+ if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
92741
+ else return;
92742
+ const selection = new CellSelection($anchor$1, $head);
92022
92743
  if (starting || !view.state.selection.eq(selection)) {
92023
92744
  const tr = view.state.tr.setSelection(selection);
92024
- if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);
92745
+ if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
92025
92746
  view.dispatch(tr);
92026
92747
  }
92027
92748
  }
@@ -92029,20 +92750,18 @@ ${l}
92029
92750
  view.root.removeEventListener("mouseup", stop);
92030
92751
  view.root.removeEventListener("dragstart", stop);
92031
92752
  view.root.removeEventListener("mousemove", move2);
92032
- if (tableEditingKey.getState(view.state) != null)
92033
- view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
92753
+ if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
92034
92754
  }
92035
92755
  function move2(_event) {
92036
92756
  const event = _event;
92037
92757
  const anchor = tableEditingKey.getState(view.state);
92038
- let $anchor2;
92039
- if (anchor != null) {
92040
- $anchor2 = view.state.doc.resolve(anchor);
92041
- } else if (domInCell(view, event.target) != startDOMCell) {
92042
- $anchor2 = cellUnderMouse(view, startEvent);
92043
- if (!$anchor2) return stop();
92758
+ let $anchor$1;
92759
+ if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
92760
+ else if (domInCell(view, event.target) != startDOMCell) {
92761
+ $anchor$1 = cellUnderMouse(view, startEvent);
92762
+ if (!$anchor$1) return stop();
92044
92763
  }
92045
- if ($anchor2) setCellSelection($anchor2, event);
92764
+ if ($anchor$1) setCellSelection($anchor$1, event);
92046
92765
  }
92047
92766
  view.root.addEventListener("mouseup", stop);
92048
92767
  view.root.addEventListener("dragstart", stop);
@@ -92052,8 +92771,8 @@ ${l}
92052
92771
  if (!(view.state.selection instanceof TextSelection$1)) return null;
92053
92772
  const { $head } = view.state.selection;
92054
92773
  for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
92055
- const parent = $head.node(d2), index2 = dir < 0 ? $head.index(d2) : $head.indexAfter(d2);
92056
- if (index2 != (dir < 0 ? 0 : parent.childCount)) return null;
92774
+ const parent = $head.node(d2);
92775
+ if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
92057
92776
  if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
92058
92777
  const cellPos = $head.before(d2);
92059
92778
  const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
@@ -92063,11 +92782,7 @@ ${l}
92063
92782
  return null;
92064
92783
  }
92065
92784
  function domInCell(view, dom) {
92066
- for (; dom && dom != view.dom; dom = dom.parentNode) {
92067
- if (dom.nodeName == "TD" || dom.nodeName == "TH") {
92068
- return dom;
92069
- }
92070
- }
92785
+ for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
92071
92786
  return null;
92072
92787
  }
92073
92788
  function cellUnderMouse(view, event) {
@@ -92076,7 +92791,8 @@ ${l}
92076
92791
  top: event.clientY
92077
92792
  });
92078
92793
  if (!mousePos) return null;
92079
- return mousePos ? cellAround$1(view.state.doc.resolve(mousePos.pos)) : null;
92794
+ const pos = mousePos.inside >= 0 ? mousePos.inside : mousePos.pos;
92795
+ return cellAround$1(view.state.doc.resolve(pos));
92080
92796
  }
92081
92797
  var TableView = class {
92082
92798
  constructor(node2, defaultCellMinWidth) {
@@ -92085,10 +92801,7 @@ ${l}
92085
92801
  this.dom = document.createElement("div");
92086
92802
  this.dom.className = "tableWrapper";
92087
92803
  this.table = this.dom.appendChild(document.createElement("table"));
92088
- this.table.style.setProperty(
92089
- "--default-cell-min-width",
92090
- `${defaultCellMinWidth}px`
92091
- );
92804
+ this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
92092
92805
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
92093
92806
  updateColumnsOnResize(node2, this.colgroup, this.table, defaultCellMinWidth);
92094
92807
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
@@ -92096,12 +92809,7 @@ ${l}
92096
92809
  update(node2) {
92097
92810
  if (node2.type != this.node.type) return false;
92098
92811
  this.node = node2;
92099
- updateColumnsOnResize(
92100
- node2,
92101
- this.colgroup,
92102
- this.table,
92103
- this.defaultCellMinWidth
92104
- );
92812
+ updateColumnsOnResize(node2, this.colgroup, this.table, this.defaultCellMinWidth);
92105
92813
  return true;
92106
92814
  }
92107
92815
  ignoreMutation(record) {
@@ -92109,7 +92817,6 @@ ${l}
92109
92817
  }
92110
92818
  };
92111
92819
  function updateColumnsOnResize(node2, colgroup, table2, defaultCellMinWidth, overrideCol, overrideValue) {
92112
- var _a2;
92113
92820
  let totalWidth = 0;
92114
92821
  let fixedWidth = true;
92115
92822
  let nextDOM = colgroup.firstChild;
@@ -92123,20 +92830,19 @@ ${l}
92123
92830
  totalWidth += hasWidth || defaultCellMinWidth;
92124
92831
  if (!hasWidth) fixedWidth = false;
92125
92832
  if (!nextDOM) {
92126
- const col2 = document.createElement("col");
92127
- col2.style.width = cssWidth;
92128
- colgroup.appendChild(col2);
92833
+ const col$1 = document.createElement("col");
92834
+ col$1.style.width = cssWidth;
92835
+ colgroup.appendChild(col$1);
92129
92836
  } else {
92130
- if (nextDOM.style.width != cssWidth) {
92131
- nextDOM.style.width = cssWidth;
92132
- }
92837
+ if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
92133
92838
  nextDOM = nextDOM.nextSibling;
92134
92839
  }
92135
92840
  }
92136
92841
  }
92137
92842
  while (nextDOM) {
92843
+ var _nextDOM$parentNode;
92138
92844
  const after = nextDOM.nextSibling;
92139
- (_a2 = nextDOM.parentNode) == null ? void 0 : _a2.removeChild(nextDOM);
92845
+ (_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
92140
92846
  nextDOM = after;
92141
92847
  }
92142
92848
  if (fixedWidth) {
@@ -92147,28 +92853,18 @@ ${l}
92147
92853
  table2.style.minWidth = totalWidth + "px";
92148
92854
  }
92149
92855
  }
92150
- var columnResizingPluginKey = new PluginKey(
92151
- "tableColumnResizing"
92152
- );
92153
- function columnResizing({
92154
- handleWidth = 5,
92155
- cellMinWidth: cellMinWidth2 = 25,
92156
- defaultCellMinWidth = 100,
92157
- View = TableView,
92158
- lastColumnResizable = true
92159
- } = {}) {
92856
+ const columnResizingPluginKey = new PluginKey("tableColumnResizing");
92857
+ function columnResizing({ handleWidth = 5, cellMinWidth: cellMinWidth2 = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
92160
92858
  const plugin2 = new Plugin({
92161
92859
  key: columnResizingPluginKey,
92162
92860
  state: {
92163
92861
  init(_2, state2) {
92164
- var _a2, _b;
92165
- const nodeViews = (_b = (_a2 = plugin2.spec) == null ? void 0 : _a2.props) == null ? void 0 : _b.nodeViews;
92862
+ var _plugin$spec;
92863
+ const nodeViews = (_plugin$spec = plugin2.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
92166
92864
  const tableName = tableNodeTypes(state2.schema).table.name;
92167
- if (View && nodeViews) {
92168
- nodeViews[tableName] = (node2, view) => {
92169
- return new View(node2, defaultCellMinWidth, view);
92170
- };
92171
- }
92865
+ if (View && nodeViews) nodeViews[tableName] = (node2, view) => {
92866
+ return new View(node2, defaultCellMinWidth, view);
92867
+ };
92172
92868
  return new ResizeState(-1, false);
92173
92869
  },
92174
92870
  apply(tr, prev) {
@@ -92188,21 +92884,19 @@ ${l}
92188
92884
  handleMouseLeave(view);
92189
92885
  },
92190
92886
  mousedown: (view, event) => {
92191
- handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth);
92887
+ handleMouseDown$1(view, event, cellMinWidth2, defaultCellMinWidth);
92192
92888
  }
92193
92889
  },
92194
92890
  decorations: (state2) => {
92195
92891
  const pluginState = columnResizingPluginKey.getState(state2);
92196
- if (pluginState && pluginState.activeHandle > -1) {
92197
- return handleDecorations(state2, pluginState.activeHandle);
92198
- }
92892
+ if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state2, pluginState.activeHandle);
92199
92893
  },
92200
92894
  nodeViews: {}
92201
92895
  }
92202
92896
  });
92203
92897
  return plugin2;
92204
92898
  }
92205
- var ResizeState = class _ResizeState {
92899
+ var ResizeState = class ResizeState2 {
92206
92900
  constructor(activeHandle, dragging) {
92207
92901
  this.activeHandle = activeHandle;
92208
92902
  this.dragging = dragging;
@@ -92210,16 +92904,12 @@ ${l}
92210
92904
  apply(tr) {
92211
92905
  const state2 = this;
92212
92906
  const action = tr.getMeta(columnResizingPluginKey);
92213
- if (action && action.setHandle != null)
92214
- return new _ResizeState(action.setHandle, false);
92215
- if (action && action.setDragging !== void 0)
92216
- return new _ResizeState(state2.activeHandle, action.setDragging);
92907
+ if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false);
92908
+ if (action && action.setDragging !== void 0) return new ResizeState2(state2.activeHandle, action.setDragging);
92217
92909
  if (state2.activeHandle > -1 && tr.docChanged) {
92218
92910
  let handle2 = tr.mapping.map(state2.activeHandle, -1);
92219
- if (!pointsAtCell(tr.doc.resolve(handle2))) {
92220
- handle2 = -1;
92221
- }
92222
- return new _ResizeState(handle2, state2.dragging);
92911
+ if (!pointsAtCell(tr.doc.resolve(handle2))) handle2 = -1;
92912
+ return new ResizeState2(handle2, state2.dragging);
92223
92913
  }
92224
92914
  return state2;
92225
92915
  }
@@ -92233,10 +92923,8 @@ ${l}
92233
92923
  let cell2 = -1;
92234
92924
  if (target) {
92235
92925
  const { left: left2, right: right2 } = target.getBoundingClientRect();
92236
- if (event.clientX - left2 <= handleWidth)
92237
- cell2 = edgeCell(view, event, "left", handleWidth);
92238
- else if (right2 - event.clientX <= handleWidth)
92239
- cell2 = edgeCell(view, event, "right", handleWidth);
92926
+ if (event.clientX - left2 <= handleWidth) cell2 = edgeCell(view, event, "left", handleWidth);
92927
+ else if (right2 - event.clientX <= handleWidth) cell2 = edgeCell(view, event, "right", handleWidth);
92240
92928
  }
92241
92929
  if (cell2 != pluginState.activeHandle) {
92242
92930
  if (!lastColumnResizable && cell2 !== -1) {
@@ -92244,10 +92932,7 @@ ${l}
92244
92932
  const table2 = $cell.node(-1);
92245
92933
  const map2 = TableMap.get(table2);
92246
92934
  const tableStart = $cell.start(-1);
92247
- const col = map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
92248
- if (col == map2.width - 1) {
92249
- return;
92250
- }
92935
+ if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return;
92251
92936
  }
92252
92937
  updateHandle(view, cell2);
92253
92938
  }
@@ -92256,58 +92941,39 @@ ${l}
92256
92941
  function handleMouseLeave(view) {
92257
92942
  if (!view.editable) return;
92258
92943
  const pluginState = columnResizingPluginKey.getState(view.state);
92259
- if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
92260
- updateHandle(view, -1);
92944
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
92261
92945
  }
92262
- function handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth) {
92263
- var _a2;
92946
+ function handleMouseDown$1(view, event, cellMinWidth2, defaultCellMinWidth) {
92947
+ var _view$dom$ownerDocume;
92264
92948
  if (!view.editable) return false;
92265
- const win = (_a2 = view.dom.ownerDocument.defaultView) != null ? _a2 : window;
92949
+ const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
92266
92950
  const pluginState = columnResizingPluginKey.getState(view.state);
92267
- if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
92268
- return false;
92951
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
92269
92952
  const cell2 = view.state.doc.nodeAt(pluginState.activeHandle);
92270
92953
  const width = currentColWidth(view, pluginState.activeHandle, cell2.attrs);
92271
- view.dispatch(
92272
- view.state.tr.setMeta(columnResizingPluginKey, {
92273
- setDragging: { startX: event.clientX, startWidth: width }
92274
- })
92275
- );
92276
- function finish(event2) {
92954
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
92955
+ startX: event.clientX,
92956
+ startWidth: width
92957
+ } }));
92958
+ function finish(event$1) {
92277
92959
  win.removeEventListener("mouseup", finish);
92278
92960
  win.removeEventListener("mousemove", move2);
92279
- const pluginState2 = columnResizingPluginKey.getState(view.state);
92280
- if (pluginState2 == null ? void 0 : pluginState2.dragging) {
92281
- updateColumnWidth(
92282
- view,
92283
- pluginState2.activeHandle,
92284
- draggedWidth(pluginState2.dragging, event2, cellMinWidth2)
92285
- );
92286
- view.dispatch(
92287
- view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
92288
- );
92961
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
92962
+ if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
92963
+ updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth2));
92964
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
92289
92965
  }
92290
92966
  }
92291
- function move2(event2) {
92292
- if (!event2.which) return finish(event2);
92293
- const pluginState2 = columnResizingPluginKey.getState(view.state);
92294
- if (!pluginState2) return;
92295
- if (pluginState2.dragging) {
92296
- const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth2);
92297
- displayColumnWidth(
92298
- view,
92299
- pluginState2.activeHandle,
92300
- dragged,
92301
- defaultCellMinWidth
92302
- );
92967
+ function move2(event$1) {
92968
+ if (!event$1.which) return finish(event$1);
92969
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
92970
+ if (!pluginState$1) return;
92971
+ if (pluginState$1.dragging) {
92972
+ const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth2);
92973
+ displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
92303
92974
  }
92304
92975
  }
92305
- displayColumnWidth(
92306
- view,
92307
- pluginState.activeHandle,
92308
- width,
92309
- defaultCellMinWidth
92310
- );
92976
+ displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
92311
92977
  win.addEventListener("mouseup", finish);
92312
92978
  win.addEventListener("mousemove", move2);
92313
92979
  event.preventDefault();
@@ -92317,20 +92983,17 @@ ${l}
92317
92983
  const width = colwidth && colwidth[colwidth.length - 1];
92318
92984
  if (width) return width;
92319
92985
  const dom = view.domAtPos(cellPos);
92320
- const node2 = dom.node.childNodes[dom.offset];
92321
- let domWidth = node2.offsetWidth, parts = colspan;
92986
+ let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
92322
92987
  if (colwidth) {
92323
- for (let i2 = 0; i2 < colspan; i2++)
92324
- if (colwidth[i2]) {
92325
- domWidth -= colwidth[i2];
92326
- parts--;
92327
- }
92988
+ for (let i2 = 0; i2 < colspan; i2++) if (colwidth[i2]) {
92989
+ domWidth -= colwidth[i2];
92990
+ parts--;
92991
+ }
92328
92992
  }
92329
92993
  return domWidth / parts;
92330
92994
  }
92331
92995
  function domCellAround(target) {
92332
- while (target && target.nodeName != "TD" && target.nodeName != "TH")
92333
- target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
92996
+ while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
92334
92997
  return target;
92335
92998
  }
92336
92999
  function edgeCell(view, event, side, handleWidth) {
@@ -92353,9 +93016,7 @@ ${l}
92353
93016
  return Math.max(resizeMinWidth, dragging.startWidth + offset2);
92354
93017
  }
92355
93018
  function updateHandle(view, value) {
92356
- view.dispatch(
92357
- view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
92358
- );
93019
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
92359
93020
  }
92360
93021
  function updateColumnWidth(view, cell2, width) {
92361
93022
  const $cell = view.state.doc.resolve(cell2);
@@ -92371,7 +93032,10 @@ ${l}
92371
93032
  if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
92372
93033
  const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
92373
93034
  colwidth[index2] = width;
92374
- tr.setNodeMarkup(start2 + pos, null, { ...attrs, colwidth });
93035
+ tr.setNodeMarkup(start2 + pos, null, {
93036
+ ...attrs,
93037
+ colwidth
93038
+ });
92375
93039
  }
92376
93040
  if (tr.docChanged) view.dispatch(tr);
92377
93041
  }
@@ -92380,64 +93044,38 @@ ${l}
92380
93044
  const table2 = $cell.node(-1), start2 = $cell.start(-1);
92381
93045
  const col = TableMap.get(table2).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
92382
93046
  let dom = view.domAtPos($cell.start(-1)).node;
92383
- while (dom && dom.nodeName != "TABLE") {
92384
- dom = dom.parentNode;
92385
- }
93047
+ while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
92386
93048
  if (!dom) return;
92387
- updateColumnsOnResize(
92388
- table2,
92389
- dom.firstChild,
92390
- dom,
92391
- defaultCellMinWidth,
92392
- col,
92393
- width
92394
- );
93049
+ updateColumnsOnResize(table2, dom.firstChild, dom, defaultCellMinWidth, col, width);
92395
93050
  }
92396
93051
  function zeroes(n) {
92397
93052
  return Array(n).fill(0);
92398
93053
  }
92399
93054
  function handleDecorations(state2, cell2) {
92400
- var _a2;
92401
93055
  const decorations = [];
92402
93056
  const $cell = state2.doc.resolve(cell2);
92403
93057
  const table2 = $cell.node(-1);
92404
- if (!table2) {
92405
- return DecorationSet.empty;
92406
- }
93058
+ if (!table2) return DecorationSet.empty;
92407
93059
  const map2 = TableMap.get(table2);
92408
93060
  const start2 = $cell.start(-1);
92409
93061
  const col = map2.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
92410
93062
  for (let row2 = 0; row2 < map2.height; row2++) {
92411
93063
  const index2 = col + row2 * map2.width;
92412
93064
  if ((col == map2.width - 1 || map2.map[index2] != map2.map[index2 + 1]) && (row2 == 0 || map2.map[index2] != map2.map[index2 - map2.width])) {
93065
+ var _columnResizingPlugin;
92413
93066
  const cellPos = map2.map[index2];
92414
93067
  const pos = start2 + cellPos + table2.nodeAt(cellPos).nodeSize - 1;
92415
93068
  const dom = document.createElement("div");
92416
93069
  dom.className = "column-resize-handle";
92417
- if ((_a2 = columnResizingPluginKey.getState(state2)) == null ? void 0 : _a2.dragging) {
92418
- decorations.push(
92419
- Decoration.node(
92420
- start2 + cellPos,
92421
- start2 + cellPos + table2.nodeAt(cellPos).nodeSize,
92422
- {
92423
- class: "column-resize-dragging"
92424
- }
92425
- )
92426
- );
92427
- }
93070
+ if ((_columnResizingPlugin = columnResizingPluginKey.getState(state2)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start2 + cellPos, start2 + cellPos + table2.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
92428
93071
  decorations.push(Decoration.widget(pos, dom));
92429
93072
  }
92430
93073
  }
92431
93074
  return DecorationSet.create(state2.doc, decorations);
92432
93075
  }
92433
- function tableEditing({
92434
- allowTableNodeSelection = false
92435
- } = {}) {
93076
+ function tableEditing({ allowTableNodeSelection = false } = {}) {
92436
93077
  return new Plugin({
92437
93078
  key: tableEditingKey,
92438
- // This piece of state is used to remember when a mouse-drag
92439
- // cell-selection is happening, so that it can continue even as
92440
- // transactions (which might move its anchor cell) come in.
92441
93079
  state: {
92442
93080
  init() {
92443
93081
  return null;
@@ -92452,9 +93090,7 @@ ${l}
92452
93090
  },
92453
93091
  props: {
92454
93092
  decorations: drawCellSelection,
92455
- handleDOMEvents: {
92456
- mousedown: handleMouseDown
92457
- },
93093
+ handleDOMEvents: { mousedown: handleMouseDown },
92458
93094
  createSelectionBetween(view) {
92459
93095
  return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
92460
93096
  },
@@ -92463,11 +93099,7 @@ ${l}
92463
93099
  handlePaste
92464
93100
  },
92465
93101
  appendTransaction(_2, oldState, state2) {
92466
- return normalizeSelection(
92467
- state2,
92468
- fixTables(state2, oldState),
92469
- allowTableNodeSelection
92470
- );
93102
+ return normalizeSelection(state2, fixTables(state2, oldState), allowTableNodeSelection);
92471
93103
  }
92472
93104
  });
92473
93105
  }
@@ -115690,7 +116322,7 @@ ${style2}
115690
116322
  };
115691
116323
  };
115692
116324
  const _hoisted_1$f$1 = ["onClick", "innerHTML", "aria-label", "onKeydown"];
115693
- const _sfc_main$g$1 = {
116325
+ const _sfc_main$h$1 = {
115694
116326
  __name: "AlignmentButtons",
115695
116327
  emits: ["select"],
115696
116328
  setup(__props, { emit: __emit }) {
@@ -115781,14 +116413,14 @@ ${style2}
115781
116413
  };
115782
116414
  }
115783
116415
  };
115784
- const AlignmentButtons = /* @__PURE__ */ _export_sfc$1(_sfc_main$g$1, [["__scopeId", "data-v-d84f57b6"]]);
116416
+ const AlignmentButtons = /* @__PURE__ */ _export_sfc$1(_sfc_main$h$1, [["__scopeId", "data-v-d84f57b6"]]);
115785
116417
  const _hoisted_1$e$1 = ["onClick", "onKeydown"];
115786
116418
  const _hoisted_2$9$1 = { class: "document-mode-column icon-column" };
115787
116419
  const _hoisted_3$7$1 = ["innerHTML"];
115788
116420
  const _hoisted_4$3$1 = { class: "document-mode-column text-column" };
115789
116421
  const _hoisted_5$2$1 = { class: "document-mode-type" };
115790
116422
  const _hoisted_6$1$1 = { class: "document-mode-description" };
115791
- const _sfc_main$f$1 = {
116423
+ const _sfc_main$g$1 = {
115792
116424
  __name: "DocumentMode",
115793
116425
  props: {
115794
116426
  options: {
@@ -115868,14 +116500,14 @@ ${style2}
115868
116500
  };
115869
116501
  }
115870
116502
  };
115871
- const DocumentMode = /* @__PURE__ */ _export_sfc$1(_sfc_main$f$1, [["__scopeId", "data-v-8730b752"]]);
116503
+ const DocumentMode = /* @__PURE__ */ _export_sfc$1(_sfc_main$g$1, [["__scopeId", "data-v-8730b752"]]);
115872
116504
  const _hoisted_1$d$1 = {
115873
116505
  key: 0,
115874
116506
  class: "linked-style-buttons",
115875
116507
  "data-editor-ui-surface": ""
115876
116508
  };
115877
116509
  const _hoisted_2$8$1 = ["onClick", "onKeydown", "aria-label"];
115878
- const _sfc_main$e$1 = {
116510
+ const _sfc_main$f$1 = {
115879
116511
  __name: "LinkedStyle",
115880
116512
  props: {
115881
116513
  editor: {
@@ -115951,7 +116583,7 @@ ${style2}
115951
116583
  };
115952
116584
  }
115953
116585
  };
115954
- const LinkedStyle = /* @__PURE__ */ _export_sfc$1(_sfc_main$e$1, [["__scopeId", "data-v-ecb78965"]]);
116586
+ const LinkedStyle = /* @__PURE__ */ _export_sfc$1(_sfc_main$f$1, [["__scopeId", "data-v-ecb78965"]]);
115955
116587
  const _hoisted_1$c$1 = {
115956
116588
  key: 0,
115957
116589
  class: "link-title"
@@ -115980,7 +116612,7 @@ ${style2}
115980
116612
  key: 4,
115981
116613
  class: "input-row go-to-anchor clickable"
115982
116614
  };
115983
- const _sfc_main$d$1 = {
116615
+ const _sfc_main$e$1 = {
115984
116616
  __name: "LinkInput",
115985
116617
  props: {
115986
116618
  showInput: {
@@ -116186,12 +116818,12 @@ ${style2}
116186
116818
  };
116187
116819
  }
116188
116820
  };
116189
- const LinkInput = /* @__PURE__ */ _export_sfc$1(_sfc_main$d$1, [["__scopeId", "data-v-ba50627b"]]);
116821
+ const LinkInput = /* @__PURE__ */ _export_sfc$1(_sfc_main$e$1, [["__scopeId", "data-v-ba50627b"]]);
116190
116822
  const _hoisted_1$b$1 = ["aria-label", "onClick", "onKeydown"];
116191
116823
  const _hoisted_2$6$1 = ["innerHTML"];
116192
116824
  const _hoisted_3$5$1 = ["innerHTML"];
116193
116825
  const ROW_SIZE$1 = 7;
116194
- const _sfc_main$c$1 = {
116826
+ const _sfc_main$d$1 = {
116195
116827
  __name: "IconGridRow",
116196
116828
  props: {
116197
116829
  icons: {
@@ -116324,12 +116956,12 @@ ${style2}
116324
116956
  };
116325
116957
  }
116326
116958
  };
116327
- const IconGridRow = /* @__PURE__ */ _export_sfc$1(_sfc_main$c$1, [["__scopeId", "data-v-0f479b6c"]]);
116959
+ const IconGridRow = /* @__PURE__ */ _export_sfc$1(_sfc_main$d$1, [["__scopeId", "data-v-0f479b6c"]]);
116328
116960
  const DropIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 512c53.2 0 101.4-21.6 136.1-56.6l-298.3-235C140 257.1 128 292.3 128 320c0 106 86 192 192 192zM505.2 370.7c4.4-16.2 6.8-33.1 6.8-50.7c0-91.2-130.2-262.3-166.6-308.3C339.4 4.2 330.5 0 320.9 0l-1.8 0c-9.6 0-18.5 4.2-24.5 11.7C277.8 33 240.7 81.3 205.8 136L38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2S-1.2 34.7 9.2 42.9l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7L505.2 370.7zM224 336c0 44.2 35.8 80 80 80c8.8 0 16 7.2 16 16s-7.2 16-16 16c-61.9 0-112-50.1-112-112c0-8.8 7.2-16 16-16s16 7.2 16 16z"/></svg>\n';
116329
116961
  const _hoisted_1$a$1 = { class: "options-grid-wrap" };
116330
116962
  const _hoisted_2$5$1 = ["innerHTML"];
116331
116963
  const _hoisted_3$4$1 = { class: "option-grid-ctn" };
116332
- const _sfc_main$b$1 = {
116964
+ const _sfc_main$c$1 = {
116333
116965
  __name: "IconGrid",
116334
116966
  props: {
116335
116967
  icons: {
@@ -116389,7 +117021,7 @@ ${style2}
116389
117021
  };
116390
117022
  }
116391
117023
  };
116392
- const IconGrid = /* @__PURE__ */ _export_sfc$1(_sfc_main$b$1, [["__scopeId", "data-v-3d19fedf"]]);
117024
+ const IconGrid = /* @__PURE__ */ _export_sfc$1(_sfc_main$c$1, [["__scopeId", "data-v-3d19fedf"]]);
116393
117025
  const closeDropdown$1 = (dropdown) => {
116394
117026
  dropdown.expand.value = false;
116395
117027
  };
@@ -116501,7 +117133,7 @@ ${style2}
116501
117133
  const _hoisted_1$9$1 = ["data-cols", "data-rows", "onKeydown", "onClick"];
116502
117134
  const _hoisted_2$4$1 = ["aria-valuetext"];
116503
117135
  const ROW_SIZE = 5;
116504
- const _sfc_main$a$1 = {
117136
+ const _sfc_main$b$1 = {
116505
117137
  __name: "TableGrid",
116506
117138
  emits: ["select", "clickoutside"],
116507
117139
  setup(__props, { emit: __emit }) {
@@ -116630,13 +117262,13 @@ ${style2}
116630
117262
  };
116631
117263
  }
116632
117264
  };
116633
- const TableGrid = /* @__PURE__ */ _export_sfc$1(_sfc_main$a$1, [["__scopeId", "data-v-92e8d5fb"]]);
117265
+ const TableGrid = /* @__PURE__ */ _export_sfc$1(_sfc_main$b$1, [["__scopeId", "data-v-92e8d5fb"]]);
116634
117266
  const _hoisted_1$8$1 = { class: "toolbar-table-actions" };
116635
117267
  const _hoisted_2$3$1 = ["onClick", "data-item", "ariaLabel"];
116636
117268
  const _hoisted_3$3$1 = { class: "toolbar-table-actions__icon" };
116637
117269
  const _hoisted_4$1$1 = ["innerHTML"];
116638
117270
  const _hoisted_5$3 = { class: "toolbar-table-actions__label" };
116639
- const _sfc_main$9$1 = {
117271
+ const _sfc_main$a$1 = {
116640
117272
  __name: "TableActions",
116641
117273
  props: {
116642
117274
  options: {
@@ -116672,7 +117304,7 @@ ${style2}
116672
117304
  };
116673
117305
  }
116674
117306
  };
116675
- const TableActions = /* @__PURE__ */ _export_sfc$1(_sfc_main$9$1, [["__scopeId", "data-v-990b9a25"]]);
117307
+ const TableActions = /* @__PURE__ */ _export_sfc$1(_sfc_main$a$1, [["__scopeId", "data-v-990b9a25"]]);
116676
117308
  function getScrollableParent(element2) {
116677
117309
  let currentElement = element2;
116678
117310
  while (currentElement) {
@@ -116699,7 +117331,7 @@ ${style2}
116699
117331
  const _hoisted_1$7$1 = { class: "search-input-ctn" };
116700
117332
  const _hoisted_2$2$1 = { class: "row" };
116701
117333
  const _hoisted_3$2$1 = ["onKeydown"];
116702
- const _sfc_main$8$1 = {
117334
+ const _sfc_main$9$1 = {
116703
117335
  __name: "SearchInput",
116704
117336
  props: {
116705
117337
  searchRef: {
@@ -116738,7 +117370,7 @@ ${style2}
116738
117370
  };
116739
117371
  }
116740
117372
  };
116741
- const SearchInput = /* @__PURE__ */ _export_sfc$1(_sfc_main$8$1, [["__scopeId", "data-v-957cbcf2"]]);
117373
+ const SearchInput = /* @__PURE__ */ _export_sfc$1(_sfc_main$9$1, [["__scopeId", "data-v-957cbcf2"]]);
116742
117374
  const TOOLBAR_FONTS = [
116743
117375
  {
116744
117376
  label: "Georgia",
@@ -119513,7 +120145,7 @@ ${style2}
119513
120145
  };
119514
120146
  const _hoisted_3$1$1 = ["onClick"];
119515
120147
  const _hoisted_4$5 = ["innerHTML"];
119516
- const _sfc_main$7$1 = {
120148
+ const _sfc_main$8$1 = {
119517
120149
  __name: "SlashMenu",
119518
120150
  props: {
119519
120151
  editor: {
@@ -119867,7 +120499,7 @@ ${style2}
119867
120499
  const _hoisted_1$4$1 = { class: "numbering" };
119868
120500
  const MIN_WIDTH = 200;
119869
120501
  const alignment = "flex-end";
119870
- const _sfc_main$5$1 = {
120502
+ const _sfc_main$6$1 = {
119871
120503
  __name: "Ruler",
119872
120504
  props: {
119873
120505
  orientation: {
@@ -119958,7 +120590,7 @@ ${style2}
119958
120590
  minHeight: `${editorBounds.height}px`
119959
120591
  };
119960
120592
  });
119961
- const handleMouseDown3 = (event) => {
120593
+ const handleMouseDown2 = (event) => {
119962
120594
  isDragging.value = true;
119963
120595
  setRulerHandleActive();
119964
120596
  const itemId = event.currentTarget.id;
@@ -120033,13 +120665,13 @@ ${style2}
120033
120665
  createBaseVNode("div", {
120034
120666
  class: "margin-handle handle-left",
120035
120667
  id: "left-margin-handle",
120036
- onMousedown: handleMouseDown3,
120668
+ onMousedown: handleMouseDown2,
120037
120669
  style: normalizeStyle(getHandlePosition.value("left"))
120038
120670
  }, null, 36),
120039
120671
  createBaseVNode("div", {
120040
120672
  class: "margin-handle handle-right",
120041
120673
  id: "right-margin-handle",
120042
- onMousedown: handleMouseDown3,
120674
+ onMousedown: handleMouseDown2,
120043
120675
  style: normalizeStyle(getHandlePosition.value("right"))
120044
120676
  }, null, 36),
120045
120677
  showVerticalIndicator.value ? (openBlock(), createElementBlock("div", {
@@ -120072,8 +120704,8 @@ ${style2}
120072
120704
  };
120073
120705
  }
120074
120706
  };
120075
- const Ruler = /* @__PURE__ */ _export_sfc$1(_sfc_main$5$1, [["__scopeId", "data-v-79f9a944"]]);
120076
- const _sfc_main$4$1 = {
120707
+ const Ruler = /* @__PURE__ */ _export_sfc$1(_sfc_main$6$1, [["__scopeId", "data-v-79f9a944"]]);
120708
+ const _sfc_main$5$1 = {
120077
120709
  __name: "GenericPopover",
120078
120710
  props: {
120079
120711
  editor: { type: Object, required: true },
@@ -120101,22 +120733,22 @@ ${style2}
120101
120733
  () => props.visible,
120102
120734
  (val) => {
120103
120735
  if (val) {
120104
- document.addEventListener("mousedown", handleClickOutside2);
120736
+ document.addEventListener("pointerdown", handleClickOutside2);
120105
120737
  document.addEventListener("keydown", handleEscape);
120106
120738
  } else {
120107
- document.removeEventListener("mousedown", handleClickOutside2);
120739
+ document.removeEventListener("pointerdown", handleClickOutside2);
120108
120740
  document.removeEventListener("keydown", handleEscape);
120109
120741
  }
120110
120742
  }
120111
120743
  );
120112
120744
  onMounted(() => {
120113
120745
  if (props.visible) {
120114
- document.addEventListener("mousedown", handleClickOutside2);
120746
+ document.addEventListener("pointerdown", handleClickOutside2);
120115
120747
  document.addEventListener("keydown", handleEscape);
120116
120748
  }
120117
120749
  });
120118
120750
  onBeforeUnmount(() => {
120119
- document.removeEventListener("mousedown", handleClickOutside2);
120751
+ document.removeEventListener("pointerdown", handleClickOutside2);
120120
120752
  document.removeEventListener("keydown", handleEscape);
120121
120753
  });
120122
120754
  const derivedStyles = computed(() => ({
@@ -120131,7 +120763,7 @@ ${style2}
120131
120763
  style: normalizeStyle(derivedStyles.value),
120132
120764
  ref_key: "popover",
120133
120765
  ref: popover,
120134
- onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {
120766
+ onPointerdown: _cache[0] || (_cache[0] = withModifiers(() => {
120135
120767
  }, ["stop"])),
120136
120768
  onClick: _cache[1] || (_cache[1] = withModifiers(() => {
120137
120769
  }, ["stop"]))
@@ -120141,7 +120773,7 @@ ${style2}
120141
120773
  };
120142
120774
  }
120143
120775
  };
120144
- const GenericPopover = /* @__PURE__ */ _export_sfc$1(_sfc_main$4$1, [["__scopeId", "data-v-cbddcc0f"]]);
120776
+ const GenericPopover = /* @__PURE__ */ _export_sfc$1(_sfc_main$5$1, [["__scopeId", "data-v-157855b5"]]);
120145
120777
  const _hoisted_1$3$1 = ["data-boundary-index", "data-boundary-type", "onMousedown"];
120146
120778
  const RESIZE_HANDLE_WIDTH_PX = 9;
120147
120779
  const RESIZE_HANDLE_OFFSET_PX = 4;
@@ -120149,7 +120781,7 @@ ${style2}
120149
120781
  const MIN_DRAG_OVERLAY_WIDTH_PX = 2e3;
120150
120782
  const THROTTLE_INTERVAL_MS = 16;
120151
120783
  const MIN_RESIZE_DELTA_PX = 1;
120152
- const _sfc_main$3$1 = {
120784
+ const _sfc_main$4$1 = {
120153
120785
  __name: "TableResizeOverlay",
120154
120786
  props: {
120155
120787
  /** Editor instance for dispatching transactions */
@@ -120673,7 +121305,7 @@ ${style2}
120673
121305
  };
120674
121306
  }
120675
121307
  };
120676
- const TableResizeOverlay = /* @__PURE__ */ _export_sfc$1(_sfc_main$3$1, [["__scopeId", "data-v-2fdf7836"]]);
121308
+ const TableResizeOverlay = /* @__PURE__ */ _export_sfc$1(_sfc_main$4$1, [["__scopeId", "data-v-2fdf7836"]]);
120677
121309
  const _hoisted_1$2$1 = ["data-handle-position", "onMousedown"];
120678
121310
  const OVERLAY_EXPANSION_PX = 2e3;
120679
121311
  const RESIZE_HANDLE_SIZE_PX = 12;
@@ -120682,7 +121314,7 @@ ${style2}
120682
121314
  const Z_INDEX_OVERLAY = 10;
120683
121315
  const Z_INDEX_HANDLE = 15;
120684
121316
  const Z_INDEX_GUIDELINE = 20;
120685
- const _sfc_main$2$1 = {
121317
+ const _sfc_main$3$1 = {
120686
121318
  __name: "ImageResizeOverlay",
120687
121319
  props: {
120688
121320
  /** Editor instance for dispatching transactions */
@@ -121106,7 +121738,81 @@ ${style2}
121106
121738
  };
121107
121739
  }
121108
121740
  };
121109
- const ImageResizeOverlay = /* @__PURE__ */ _export_sfc$1(_sfc_main$2$1, [["__scopeId", "data-v-e66ec7bb"]]);
121741
+ const ImageResizeOverlay = /* @__PURE__ */ _export_sfc$1(_sfc_main$3$1, [["__scopeId", "data-v-e66ec7bb"]]);
121742
+ const _sfc_main$2$1 = {
121743
+ __name: "LinkClickHandler",
121744
+ props: {
121745
+ editor: {
121746
+ type: Object,
121747
+ required: true
121748
+ },
121749
+ openPopover: {
121750
+ type: Function,
121751
+ required: true
121752
+ },
121753
+ closePopover: {
121754
+ type: Function,
121755
+ required: true
121756
+ },
121757
+ popoverVisible: {
121758
+ type: Boolean,
121759
+ default: false
121760
+ }
121761
+ },
121762
+ setup(__props) {
121763
+ const props = __props;
121764
+ const handleLinkClick = (event) => {
121765
+ if (props.popoverVisible) {
121766
+ props.closePopover();
121767
+ return;
121768
+ }
121769
+ if (!props.editor || !props.editor.state) {
121770
+ return;
121771
+ }
121772
+ const surface = getEditorSurfaceElement(props.editor);
121773
+ if (!surface) {
121774
+ return;
121775
+ }
121776
+ moveCursorToMouseEvent(event.detail, props.editor);
121777
+ setTimeout(() => {
121778
+ const currentState = props.editor.state;
121779
+ const hasLink = selectionHasNodeOrMark(currentState, "link", { requireEnds: true });
121780
+ if (hasLink) {
121781
+ const surfaceRect = surface.getBoundingClientRect();
121782
+ if (!surfaceRect) return;
121783
+ props.openPopover(
121784
+ markRaw(LinkInput),
121785
+ {
121786
+ showInput: true,
121787
+ editor: props.editor,
121788
+ closePopover: props.closePopover
121789
+ },
121790
+ {
121791
+ left: `${event.detail.clientX - surfaceRect.left}px`,
121792
+ top: `${event.detail.clientY - surfaceRect.top + 15}px`
121793
+ }
121794
+ );
121795
+ }
121796
+ }, 10);
121797
+ };
121798
+ let surfaceElement = null;
121799
+ onMounted(() => {
121800
+ if (!props.editor) return;
121801
+ surfaceElement = getEditorSurfaceElement(props.editor);
121802
+ if (surfaceElement) {
121803
+ surfaceElement.addEventListener("superdoc-link-click", handleLinkClick);
121804
+ }
121805
+ });
121806
+ onBeforeUnmount(() => {
121807
+ if (surfaceElement) {
121808
+ surfaceElement.removeEventListener("superdoc-link-click", handleLinkClick);
121809
+ }
121810
+ });
121811
+ return (_ctx, _cache) => {
121812
+ return null;
121813
+ };
121814
+ }
121815
+ };
121110
121816
  function adjustPaginationBreaks(editorElem, editor) {
121111
121817
  if (!editorElem.value || !editor?.value?.options?.scale || isHeadless(editor)) return;
121112
121818
  const zoom = editor.value.options.scale;
@@ -121448,21 +122154,28 @@ ${style2}
121448
122154
  class: "editor-element super-editor__element",
121449
122155
  role: "presentation"
121450
122156
  }, null, 512),
121451
- !contextMenuDisabled.value && editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$7$1, {
122157
+ !contextMenuDisabled.value && editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$8$1, {
121452
122158
  key: 0,
121453
122159
  editor: activeEditor.value,
121454
122160
  popoverControls,
121455
122161
  openPopover,
121456
122162
  closePopover
121457
122163
  }, null, 8, ["editor", "popoverControls"])) : createCommentVNode("", true),
121458
- editorReady.value && activeEditor.value ? (openBlock(), createBlock(TableResizeOverlay, {
122164
+ editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$2$1, {
121459
122165
  key: 1,
121460
122166
  editor: activeEditor.value,
122167
+ openPopover,
122168
+ closePopover,
122169
+ popoverVisible: popoverControls.visible
122170
+ }, null, 8, ["editor", "popoverVisible"])) : createCommentVNode("", true),
122171
+ editorReady.value && activeEditor.value ? (openBlock(), createBlock(TableResizeOverlay, {
122172
+ key: 2,
122173
+ editor: activeEditor.value,
121461
122174
  visible: tableResizeState.visible,
121462
122175
  tableElement: tableResizeState.tableElement
121463
122176
  }, null, 8, ["editor", "visible", "tableElement"])) : createCommentVNode("", true),
121464
122177
  editorReady.value && activeEditor.value ? (openBlock(), createBlock(ImageResizeOverlay, {
121465
- key: 2,
122178
+ key: 3,
121466
122179
  editor: activeEditor.value,
121467
122180
  visible: imageResizeState.visible,
121468
122181
  imageElement: imageResizeState.imageElement
@@ -121529,7 +122242,7 @@ ${style2}
121529
122242
  };
121530
122243
  }
121531
122244
  };
121532
- const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-a84087aa"]]);
122245
+ const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-08b32c3d"]]);
121533
122246
  const _hoisted_1$h = ["innerHTML"];
121534
122247
  const _sfc_main$i = {
121535
122248
  __name: "SuperInput",
@@ -123906,6 +124619,7 @@ ${reason}`);
123906
124619
  const creatorImage = params2.creatorImage;
123907
124620
  const createdTime = params2.createdTime || Date.now();
123908
124621
  const importedAuthor = ref(params2.importedAuthor || null);
124622
+ const docxCommentJSON = params2.docxCommentJSON || null;
123909
124623
  const commentText = ref(params2.commentText || "");
123910
124624
  const selection = params2.selection ? useSelection(params2.selection) : useSelection({
123911
124625
  documentId: fileId,
@@ -124020,6 +124734,7 @@ ${reason}`);
124020
124734
  creatorImage,
124021
124735
  createdTime,
124022
124736
  importedAuthor: importedAuthor.value,
124737
+ docxCommentJSON,
124023
124738
  isInternal: isInternal.value,
124024
124739
  commentText: commentText.value,
124025
124740
  selection: selection ? selection.getValues() : null,
@@ -124058,6 +124773,7 @@ ${reason}`);
124058
124773
  resolvedByEmail,
124059
124774
  resolvedByName,
124060
124775
  importedAuthor,
124776
+ docxCommentJSON,
124061
124777
  // Actions
124062
124778
  setText,
124063
124779
  getValues,
@@ -124639,6 +125355,7 @@ ${reason}`);
124639
125355
  const newComment = useComment({
124640
125356
  fileId: documentId,
124641
125357
  fileType: document2.type,
125358
+ docxCommentJSON: comment2.textJson,
124642
125359
  commentId: comment2.commentId,
124643
125360
  isInternal: false,
124644
125361
  parentCommentId: comment2.parentCommentId,
@@ -124699,7 +125416,7 @@ ${reason}`);
124699
125416
  commentsList.value.forEach((comment2) => {
124700
125417
  const values = comment2.getValues();
124701
125418
  const richText = values.commentText;
124702
- const schema = convertHtmlToSchema(richText);
125419
+ const schema = values.docxCommentJSON || convertHtmlToSchema(richText);
124703
125420
  processedComments.push({
124704
125421
  ...values,
124705
125422
  commentJSON: schema
@@ -138672,7 +139389,7 @@ ${style2}
138672
139389
  this.config.colors = shuffleArray(this.config.colors);
138673
139390
  this.userColorMap = /* @__PURE__ */ new Map();
138674
139391
  this.colorIndex = 0;
138675
- this.version = "1.0.0-beta.17";
139392
+ this.version = "1.0.0-beta.18";
138676
139393
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
138677
139394
  this.superdocId = config2.superdocId || v4();
138678
139395
  this.colors = this.config.colors;
@@ -141115,7 +141832,7 @@ ${style2}
141115
141832
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
141116
141833
  );
141117
141834
  }
141118
- const indexVCeRjVPO = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
141835
+ const indexDpnfmQSg = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
141119
141836
  __proto__: null,
141120
141837
  unified
141121
141838
  }, Symbol.toStringTag, { value: "Module" }));