superdoc 1.0.0-beta.17 → 1.0.0-beta.19

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-BIlJaTm7.cjs → PdfViewer-BLFV17De.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-cvzMUtBh.es.js → PdfViewer-D_4g-jsZ.es.js} +1 -1
  3. package/dist/chunks/{index-VCeRjVPO-FBgR9qxX.es.js → index-CRpn1mWd-B4eH8Zok.es.js} +1 -1
  4. package/dist/chunks/{index-VCeRjVPO-DjkejB6t.cjs → index-CRpn1mWd-BUbbd3Jq.cjs} +1 -1
  5. package/dist/chunks/{index-CrIfBvBN.es.js → index-NPXppXmC.es.js} +8 -4
  6. package/dist/chunks/{index-DDx90Dl3.cjs → index-k02voMEs.cjs} +8 -4
  7. package/dist/chunks/{super-editor.es-00SpI-wK.es.js → super-editor.es-CHU4dmes.es.js} +1844 -1123
  8. package/dist/chunks/{super-editor.es-Mlj7AGyt.cjs → super-editor.es-C_Gk8cDd.cjs} +1843 -1122
  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-Cu26_LdN.js} +207 -15
  14. package/dist/super-editor/chunks/{docx-zipper-r5KdE_SA.js → docx-zipper-C8lozSFd.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-D2k2BwSG.js → editor-BXC2Hzba.js} +1574 -1062
  16. package/dist/super-editor/chunks/{index-VCeRjVPO.js → index-CRpn1mWd.js} +1 -1
  17. package/dist/super-editor/chunks/{toolbar-8o_LgoiW.js → toolbar-BglLOe8y.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 +1842 -1117
  30. package/dist/superdoc.umd.js.map +1 -1
  31. package/package.json +1 -1
@@ -9,11 +9,11 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, 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;
12
+ var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, 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;
13
13
  import * as Y from "yjs";
14
14
  import { UndoManager, Item as Item$1, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
15
- import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$1, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as ListHelpers, O as updateNumberingProperties, Q as changeListLevel, U as findParentNode, V as isList, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName, $ as TrackInsertMarkName, a0 as v4, a1 as TrackFormatMarkName, a2 as comments_module_events, a3 as findMark, a4 as objectIncludes, a5 as AddMarkStep, a6 as RemoveMarkStep, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as resolveParagraphProperties, ak as _getReferencedTableStyles, al as parseSizeUnit, am as minMax, an as updateDOMAttributes, ao as findChildren$5, ap as generateRandomSigned32BitIntStrId, aq as decodeRPrFromMarks, ar as calculateResolvedParagraphProperties, as as encodeCSSFromPPr, at as twipsToPixels$2, au as resolveRunProperties, av as encodeCSSFromRPr, aw as generateOrderedListIndex, ax as docxNumberingHelpers, ay as InputRule, az as convertSizeToCSS, aA as SelectionRange, aB as Transform, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-B9zUZjYT.js";
16
- import { D as DocxZipper } from "./docx-zipper-r5KdE_SA.js";
15
+ import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$1, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as ListHelpers, O as updateNumberingProperties, Q as changeListLevel, U as findParentNode, V as isList, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName, $ as TrackInsertMarkName, a0 as v4, a1 as TrackFormatMarkName, a2 as comments_module_events, a3 as findMark, a4 as objectIncludes, a5 as AddMarkStep, a6 as RemoveMarkStep, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as resolveParagraphProperties, ak as _getReferencedTableStyles, al as parseSizeUnit, am as minMax, an as updateDOMAttributes, ao as findChildren$5, ap as generateRandomSigned32BitIntStrId, aq as decodeRPrFromMarks, ar as calculateResolvedParagraphProperties, as as encodeCSSFromPPr, at as twipsToPixels$2, au as resolveRunProperties, av as encodeCSSFromRPr, aw as generateOrderedListIndex, ax as docxNumberingHelpers, ay as InputRule, az as convertSizeToCSS, aA as SelectionRange, aB as Transform, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-Cu26_LdN.js";
16
+ import { D as DocxZipper } from "./docx-zipper-C8lozSFd.js";
17
17
  import { ref, computed, createElementBlock, openBlock, withModifiers, Fragment as Fragment$1, renderList, normalizeClass, createCommentVNode, toDisplayString, createElementVNode, createApp } from "vue";
18
18
  var GOOD_LEAF_SIZE = 200;
19
19
  var RopeSequence = function RopeSequence2() {
@@ -11209,50 +11209,90 @@ const getCommentPositionsById = (commentId, doc2) => {
11209
11209
  return positions;
11210
11210
  };
11211
11211
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
11212
+ const commentMap = /* @__PURE__ */ new Map();
11213
+ comments.forEach((c) => {
11214
+ commentMap.set(c.commentId, c);
11215
+ });
11216
+ new Set(comments.filter((c) => c.parentCommentId).map((c) => c.parentCommentId));
11212
11217
  const startNodes = [];
11213
11218
  const endNodes = [];
11214
11219
  const seen = /* @__PURE__ */ new Set();
11215
11220
  doc2.descendants((node, pos) => {
11216
- const commentMarks = node.marks?.filter((mark) => mark.type.name === CommentMarkName);
11221
+ const commentMarks = node.marks?.filter((mark) => mark.type.name === CommentMarkName) || [];
11217
11222
  commentMarks.forEach((commentMark) => {
11218
- if (commentMark) {
11219
- const { attrs = {} } = commentMark;
11220
- const { commentId } = attrs;
11221
- if (commentId === "pending") return;
11222
- if (seen.has(commentId)) return;
11223
- seen.add(commentId);
11224
- const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
11225
- const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
11223
+ const { attrs = {} } = commentMark;
11224
+ const { commentId } = attrs;
11225
+ if (commentId === "pending") return;
11226
+ if (seen.has(commentId)) return;
11227
+ seen.add(commentId);
11228
+ const comment = commentMap.get(commentId);
11229
+ const parentCommentId = comment?.parentCommentId;
11230
+ const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
11231
+ const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
11232
+ startNodes.push({
11233
+ pos,
11234
+ node: startNode,
11235
+ commentId,
11236
+ parentCommentId
11237
+ });
11238
+ const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
11239
+ endNodes.push({
11240
+ pos: pos + node.nodeSize,
11241
+ node: endNode,
11242
+ commentId,
11243
+ parentCommentId
11244
+ });
11245
+ const childComments = comments.filter((c) => c.parentCommentId === commentId).sort((a, b) => a.createdTime - b.createdTime);
11246
+ childComments.forEach((c) => {
11247
+ if (seen.has(c.commentId)) return;
11248
+ seen.add(c.commentId);
11249
+ const childMark = getPreparedComment({
11250
+ commentId: c.commentId,
11251
+ internal: c.isInternal
11252
+ });
11253
+ const childStartNode = schema.nodes.commentRangeStart.create(childMark);
11226
11254
  startNodes.push({
11227
11255
  pos,
11228
- node: startNode
11256
+ node: childStartNode,
11257
+ commentId: c.commentId,
11258
+ parentCommentId: c.parentCommentId
11229
11259
  });
11230
- const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
11260
+ const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
11231
11261
  endNodes.push({
11232
11262
  pos: pos + node.nodeSize,
11233
- node: endNode
11263
+ node: childEndNode,
11264
+ commentId: c.commentId,
11265
+ parentCommentId: c.parentCommentId
11234
11266
  });
11235
- const parentId = commentId;
11236
- if (parentId) {
11237
- const childComments = comments.filter((c) => c.parentCommentId === parentId).sort((a, b) => a.createdTime - b.createdTime);
11238
- childComments.forEach((c) => {
11239
- const childMark = getPreparedComment(c);
11240
- const childStartNode = schema.nodes.commentRangeStart.create(childMark);
11241
- seen.add(c.commentId);
11242
- startNodes.push({
11243
- pos,
11244
- node: childStartNode
11245
- });
11246
- const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
11247
- endNodes.push({
11248
- pos: pos + node.nodeSize,
11249
- node: childEndNode
11250
- });
11251
- });
11252
- }
11253
- }
11267
+ });
11254
11268
  });
11255
11269
  });
11270
+ startNodes.sort((a, b) => {
11271
+ if (a.pos !== b.pos) return a.pos - b.pos;
11272
+ const aIsParentOfB = a.commentId === b.parentCommentId;
11273
+ const bIsParentOfA = b.commentId === a.parentCommentId;
11274
+ if (aIsParentOfB) return -1;
11275
+ if (bIsParentOfA) return 1;
11276
+ if (a.parentCommentId && a.parentCommentId === b.parentCommentId) {
11277
+ const aComment = commentMap.get(a.commentId);
11278
+ const bComment = commentMap.get(b.commentId);
11279
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
11280
+ }
11281
+ return 0;
11282
+ });
11283
+ endNodes.sort((a, b) => {
11284
+ if (a.pos !== b.pos) return a.pos - b.pos;
11285
+ const aIsParentOfB = a.commentId === b.parentCommentId;
11286
+ const bIsParentOfA = b.commentId === a.parentCommentId;
11287
+ if (aIsParentOfB) return -1;
11288
+ if (bIsParentOfA) return 1;
11289
+ if (a.parentCommentId && a.parentCommentId === b.parentCommentId) {
11290
+ const aComment = commentMap.get(a.commentId);
11291
+ const bComment = commentMap.get(b.commentId);
11292
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
11293
+ }
11294
+ return 0;
11295
+ });
11256
11296
  startNodes.forEach((n) => {
11257
11297
  const { pos, node } = n;
11258
11298
  const mappedPos = tr.mapping.map(pos);
@@ -13817,7 +13857,7 @@ const isHeadless = (editor) => {
13817
13857
  const shouldSkipNodeView = (editor) => {
13818
13858
  return isHeadless(editor);
13819
13859
  };
13820
- const summaryVersion = "1.0.0-beta.17";
13860
+ const summaryVersion = "1.0.0-beta.19";
13821
13861
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
13822
13862
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
13823
13863
  function mapAttributes(attrs) {
@@ -14596,7 +14636,7 @@ const _Editor = class _Editor extends EventEmitter {
14596
14636
  { default: remarkStringify },
14597
14637
  { default: remarkGfm }
14598
14638
  ] = await Promise.all([
14599
- import("./index-VCeRjVPO.js"),
14639
+ import("./index-CRpn1mWd.js"),
14600
14640
  import("./index-DRCvimau.js"),
14601
14641
  import("./index-C_x_N6Uh.js"),
14602
14642
  import("./index-D_sWOSiG.js"),
@@ -14801,7 +14841,7 @@ const _Editor = class _Editor extends EventEmitter {
14801
14841
  * Process collaboration migrations
14802
14842
  */
14803
14843
  processCollaborationMigrations() {
14804
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.17");
14844
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.19");
14805
14845
  if (!this.options.ydoc) return;
14806
14846
  const metaMap = this.options.ydoc.getMap("meta");
14807
14847
  let docVersion = metaMap.get("version");
@@ -15591,6 +15631,15 @@ function extractColumns(elements) {
15591
15631
  gap: gapInches * PX_PER_INCH$2
15592
15632
  };
15593
15633
  }
15634
+ function extractVerticalAlign(elements) {
15635
+ const vAlign = elements.find((el) => el?.name === "w:vAlign");
15636
+ if (!vAlign?.attributes) return void 0;
15637
+ const val = vAlign.attributes["w:val"];
15638
+ if (val === "top" || val === "center" || val === "bottom" || val === "both") {
15639
+ return val;
15640
+ }
15641
+ return void 0;
15642
+ }
15594
15643
  function extractSectionData(para) {
15595
15644
  const attrs = para.attrs ?? {};
15596
15645
  let { headerPx, footerPx } = extractNormalizedMargins(attrs);
@@ -15607,7 +15656,20 @@ function extractSectionData(para) {
15607
15656
  const footerRefs = extractHeaderFooterRefs(sectPrElements, "w:footerReference");
15608
15657
  const numbering = extractPageNumbering(sectPrElements);
15609
15658
  const columnsPx = extractColumns(sectPrElements);
15610
- return { headerPx, footerPx, type, pageSizePx, orientation, columnsPx, titlePg, headerRefs, footerRefs, numbering };
15659
+ const vAlign = extractVerticalAlign(sectPrElements);
15660
+ return {
15661
+ headerPx,
15662
+ footerPx,
15663
+ type,
15664
+ pageSizePx,
15665
+ orientation,
15666
+ columnsPx,
15667
+ titlePg,
15668
+ headerRefs,
15669
+ footerRefs,
15670
+ numbering,
15671
+ vAlign
15672
+ };
15611
15673
  }
15612
15674
  function isSectPrElement(value) {
15613
15675
  return typeof value === "object" && value !== null && value.type === "element" && value.name === "w:sectPr";
@@ -15644,7 +15706,8 @@ function createSectionBreakBlock(section, blockIdGen, extraAttrs) {
15644
15706
  ...section.columns && { columns: section.columns },
15645
15707
  ...section.numbering ? { numbering: section.numbering } : {},
15646
15708
  ...section.headerRefs && { headerRefs: section.headerRefs },
15647
- ...section.footerRefs && { footerRefs: section.footerRefs }
15709
+ ...section.footerRefs && { footerRefs: section.footerRefs },
15710
+ ...section.vAlign && { vAlign: section.vAlign }
15648
15711
  };
15649
15712
  return result;
15650
15713
  }
@@ -15716,7 +15779,8 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
15716
15779
  titlePg: sectionData.titlePg ?? false,
15717
15780
  headerRefs: sectionData.headerRefs,
15718
15781
  footerRefs: sectionData.footerRefs,
15719
- numbering: sectionData.numbering
15782
+ numbering: sectionData.numbering,
15783
+ vAlign: sectionData.vAlign
15720
15784
  };
15721
15785
  ranges.push(range);
15722
15786
  currentStart = item.index + 1;
@@ -15755,7 +15819,8 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
15755
15819
  type: bodySectionData.type ?? DEFAULT_BODY_SECTION_TYPE,
15756
15820
  titlePg: bodySectionData.titlePg ?? false,
15757
15821
  headerRefs: bodySectionData.headerRefs,
15758
- footerRefs: bodySectionData.footerRefs
15822
+ footerRefs: bodySectionData.footerRefs,
15823
+ vAlign: bodySectionData.vAlign
15759
15824
  };
15760
15825
  }
15761
15826
  function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex) {
@@ -17418,8 +17483,9 @@ const normalizeOoxmlTabs = (tabs) => {
17418
17483
  for (const entry of tabs) {
17419
17484
  if (!entry || typeof entry !== "object") continue;
17420
17485
  const rawEntry = entry;
17421
- const source = rawEntry.tab && typeof rawEntry.tab === "object" ? rawEntry.tab : rawEntry;
17422
- const posTwips = resolveTabPosition(source);
17486
+ const isNestedTab = Boolean(rawEntry.tab && typeof rawEntry.tab === "object");
17487
+ const source = isNestedTab ? rawEntry.tab : rawEntry;
17488
+ const posTwips = resolveTabPosition(source, isNestedTab);
17423
17489
  if (posTwips == null) continue;
17424
17490
  const val = normalizeTabVal(source.val ?? source.align ?? source.alignment ?? source.type ?? source.tabType);
17425
17491
  if (!val) continue;
@@ -17433,7 +17499,7 @@ const normalizeOoxmlTabs = (tabs) => {
17433
17499
  }
17434
17500
  return normalized.length > 0 ? normalized : void 0;
17435
17501
  };
17436
- const resolveTabPosition = (source) => {
17502
+ const resolveTabPosition = (source, treatPosAsTwips = false) => {
17437
17503
  const originalPos = pickNumber(source.originalPos);
17438
17504
  if (originalPos != null) {
17439
17505
  return originalPos;
@@ -17442,6 +17508,9 @@ const resolveTabPosition = (source) => {
17442
17508
  if (posValue == null) {
17443
17509
  return void 0;
17444
17510
  }
17511
+ if (treatPosAsTwips) {
17512
+ return posValue;
17513
+ }
17445
17514
  if (posValue > TWIPS_THRESHOLD) {
17446
17515
  return posValue;
17447
17516
  } else {
@@ -18952,8 +19021,16 @@ const extractMarkerRun = (lvl) => {
18952
19021
  }
18953
19022
  const color = normalizeColor(getAttribute(findChild(rPr, "w:color"), "w:val"));
18954
19023
  if (color) run.color = color;
18955
- if (findChild(rPr, "w:b")) run.bold = true;
18956
- if (findChild(rPr, "w:i")) run.italic = true;
19024
+ const boldEl = findChild(rPr, "w:b");
19025
+ if (boldEl) {
19026
+ const boldVal = getAttribute(boldEl, "w:val");
19027
+ if (boldVal == null || isTruthy(boldVal)) run.bold = true;
19028
+ }
19029
+ const italicEl = findChild(rPr, "w:i");
19030
+ if (italicEl) {
19031
+ const italicVal = getAttribute(italicEl, "w:val");
19032
+ if (italicVal == null || isTruthy(italicVal)) run.italic = true;
19033
+ }
18957
19034
  const spacingTwips = parseNumberAttr(getAttribute(findChild(rPr, "w:spacing"), "w:val"));
18958
19035
  if (spacingTwips != null && Number.isFinite(spacingTwips)) {
18959
19036
  run.letterSpacing = twipsToPx$1(spacingTwips);
@@ -19429,19 +19506,21 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
19429
19506
  }
19430
19507
  const tabObj = tab;
19431
19508
  const val = typeof tabObj.tabType === "string" ? tabObj.tabType : typeof tabObj.val === "string" ? tabObj.val : void 0;
19432
- const pos = pickNumber(tabObj.originalPos ?? tabObj.pos);
19509
+ const originalPos = pickNumber(tabObj.originalPos);
19510
+ const pos = originalPos ?? pickNumber(tabObj.pos);
19433
19511
  if (!val || pos == null) {
19434
19512
  continue;
19435
19513
  }
19436
19514
  const normalized = { val, pos };
19515
+ if (originalPos != null && Number.isFinite(originalPos)) {
19516
+ normalized.originalPos = originalPos;
19517
+ } else {
19518
+ normalized.originalPos = pos;
19519
+ }
19437
19520
  const leader = tabObj.leader;
19438
19521
  if (typeof leader === "string" && leader.length > 0) {
19439
19522
  normalized.leader = leader;
19440
19523
  }
19441
- const originalPos = pickNumber(tabObj.originalPos);
19442
- if (originalPos != null && Number.isFinite(originalPos)) {
19443
- normalized.originalPos = originalPos;
19444
- }
19445
19524
  unwrapped.push(normalized);
19446
19525
  continue;
19447
19526
  }
@@ -20283,11 +20362,11 @@ const applyLinkedStyleToRun = (run, options) => {
20283
20362
  if (!maps.length) return;
20284
20363
  const finalStyles = Object.assign({}, ...maps);
20285
20364
  const fontFamily = extractValue(finalStyles["font-family"]);
20286
- if (typeof fontFamily === "string" && fontFamily && run.fontFamily === options.defaultFont) {
20365
+ if (typeof fontFamily === "string" && fontFamily) {
20287
20366
  run.fontFamily = fontFamily;
20288
20367
  }
20289
20368
  const fontSize = toPxNumber(finalStyles["font-size"]);
20290
- if (fontSize != null && run.fontSize === options.defaultSize) {
20369
+ if (fontSize != null) {
20291
20370
  run.fontSize = fontSize;
20292
20371
  }
20293
20372
  const letterSpacing = toPxNumber(finalStyles["letter-spacing"]);
@@ -20650,9 +20729,7 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
20650
20729
  resolver: linkedStyleResolver,
20651
20730
  paragraphStyleId,
20652
20731
  inlineStyleId,
20653
- runStyleId,
20654
- defaultFont,
20655
- defaultSize
20732
+ runStyleId
20656
20733
  });
20657
20734
  };
20658
20735
  const visitNode = (node, inheritedMarks = [], activeSdt, activeRunStyleId = null) => {
@@ -20662,7 +20739,8 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
20662
20739
  positions,
20663
20740
  defaultFont,
20664
20741
  defaultSize,
20665
- inheritedMarks,
20742
+ [],
20743
+ // Empty marks - will be applied after linked styles
20666
20744
  activeSdt,
20667
20745
  hyperlinkConfig,
20668
20746
  themeColors
@@ -20670,6 +20748,7 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
20670
20748
  const inlineStyleId = getInlineStyleId(inheritedMarks);
20671
20749
  applyRunStyles2(run, inlineStyleId, activeRunStyleId);
20672
20750
  applyBaseRunDefaults(run, baseRunDefaults, defaultFont, defaultSize);
20751
+ applyMarksToRun(run, [...node.marks ?? [], ...inheritedMarks ?? []], hyperlinkConfig, themeColors);
20673
20752
  currentRuns.push(run);
20674
20753
  return;
20675
20754
  }
@@ -22544,13 +22623,14 @@ function processFragment(fragmentEl, viewX, viewY) {
22544
22623
  if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
22545
22624
  return null;
22546
22625
  }
22547
- const spanEls = Array.from(lineEl.querySelectorAll("span"));
22626
+ const spanEls = Array.from(lineEl.querySelectorAll("span, a"));
22548
22627
  log(
22549
- "Spans in line:",
22628
+ "Spans/anchors in line:",
22550
22629
  spanEls.map((el, i) => {
22551
22630
  const rect = el.getBoundingClientRect();
22552
22631
  return {
22553
22632
  index: i,
22633
+ tag: el.tagName,
22554
22634
  pmStart: el.dataset.pmStart,
22555
22635
  pmEnd: el.dataset.pmEnd,
22556
22636
  text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
@@ -22570,32 +22650,33 @@ function processFragment(fragmentEl, viewX, viewY) {
22570
22650
  if (viewX >= lastRect.right) {
22571
22651
  return lineEnd;
22572
22652
  }
22573
- const targetSpan = findSpanAtX(spanEls, viewX);
22574
- if (!targetSpan) {
22653
+ const targetEl = findSpanAtX(spanEls, viewX);
22654
+ if (!targetEl) {
22575
22655
  return lineStart;
22576
22656
  }
22577
- const spanStart = Number(targetSpan.dataset.pmStart ?? "NaN");
22578
- const spanEnd = Number(targetSpan.dataset.pmEnd ?? "NaN");
22579
- const targetRect = targetSpan.getBoundingClientRect();
22580
- log("Target span:", {
22657
+ const spanStart = Number(targetEl.dataset.pmStart ?? "NaN");
22658
+ const spanEnd = Number(targetEl.dataset.pmEnd ?? "NaN");
22659
+ const targetRect = targetEl.getBoundingClientRect();
22660
+ log("Target element:", {
22661
+ tag: targetEl.tagName,
22581
22662
  pmStart: spanStart,
22582
22663
  pmEnd: spanEnd,
22583
- text: targetSpan.textContent?.substring(0, 30),
22584
- visibility: targetSpan.style.visibility,
22664
+ text: targetEl.textContent?.substring(0, 30),
22665
+ visibility: targetEl.style.visibility,
22585
22666
  rect: { left: targetRect.left, right: targetRect.right, width: targetRect.width }
22586
22667
  });
22587
22668
  if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) {
22588
22669
  return null;
22589
22670
  }
22590
- const firstChild = targetSpan.firstChild;
22671
+ const firstChild = targetEl.firstChild;
22591
22672
  if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
22592
- const spanRect = targetSpan.getBoundingClientRect();
22593
- const closerToLeft = Math.abs(viewX - spanRect.left) <= Math.abs(viewX - spanRect.right);
22673
+ const elRect = targetEl.getBoundingClientRect();
22674
+ const closerToLeft = Math.abs(viewX - elRect.left) <= Math.abs(viewX - elRect.right);
22594
22675
  const snapPos = closerToLeft ? spanStart : spanEnd;
22595
22676
  return snapPos;
22596
22677
  }
22597
22678
  const textNode = firstChild;
22598
- const charIndex = findCharIndexAtX(textNode, targetSpan, viewX);
22679
+ const charIndex = findCharIndexAtX(textNode, targetEl, viewX);
22599
22680
  const pos = spanStart + charIndex;
22600
22681
  return pos;
22601
22682
  }
@@ -22633,7 +22714,8 @@ function findSpanAtX(spanEls, viewX) {
22633
22714
  const span = spanEls[i];
22634
22715
  const rect = span.getBoundingClientRect();
22635
22716
  if (viewX >= rect.left && viewX <= rect.right) {
22636
- log("findSpanAtX: Found containing span at index", i, {
22717
+ log("findSpanAtX: Found containing element at index", i, {
22718
+ tag: span.tagName,
22637
22719
  pmStart: span.dataset.pmStart,
22638
22720
  pmEnd: span.dataset.pmEnd,
22639
22721
  rect: { left: rect.left, right: rect.right },
@@ -22645,16 +22727,17 @@ function findSpanAtX(spanEls, viewX) {
22645
22727
  targetSpan = span;
22646
22728
  }
22647
22729
  }
22648
- log("findSpanAtX: No containing span, using nearest:", {
22730
+ log("findSpanAtX: No containing element, using nearest:", {
22731
+ tag: targetSpan.tagName,
22649
22732
  pmStart: targetSpan.dataset.pmStart,
22650
22733
  pmEnd: targetSpan.dataset.pmEnd,
22651
22734
  viewX
22652
22735
  });
22653
22736
  return targetSpan;
22654
22737
  }
22655
- function findCharIndexAtX(textNode, span, targetX) {
22738
+ function findCharIndexAtX(textNode, container, targetX) {
22656
22739
  const text = textNode.textContent ?? "";
22657
- const baseLeft = span.getBoundingClientRect().left;
22740
+ const baseLeft = container.getBoundingClientRect().left;
22658
22741
  const range = document.createRange();
22659
22742
  let lo = 0;
22660
22743
  let hi = text.length;
@@ -22986,6 +23069,9 @@ function computeNextSectionPropsAtBreak(blocks) {
22986
23069
  if (source.orientation) {
22987
23070
  props.orientation = source.orientation;
22988
23071
  }
23072
+ if (source.vAlign) {
23073
+ props.vAlign = source.vAlign;
23074
+ }
22989
23075
  return props;
22990
23076
  };
22991
23077
  docxBreakIndexes.forEach((index2, ordinal) => {
@@ -24386,6 +24472,10 @@ function cloneBlockWithResolvedTokens(block, displayPageText, totalPagesStr) {
24386
24472
  runs: clonedRuns
24387
24473
  };
24388
24474
  }
24475
+ const DEFAULT_PARAGRAPH_LINE_HEIGHT_PX = 20;
24476
+ function hasHeight(fragment) {
24477
+ return fragment.kind === "image" || fragment.kind === "drawing" || fragment.kind === "table";
24478
+ }
24389
24479
  const DEFAULT_PAGE_SIZE$2 = { w: 612, h: 792 };
24390
24480
  const DEFAULT_MARGINS$2 = { top: 72, right: 72, bottom: 72, left: 72 };
24391
24481
  const COLUMN_EPSILON = 1e-4;
@@ -24480,6 +24570,8 @@ function layoutDocument(blocks, measures, options = {}) {
24480
24570
  let pendingColumns = null;
24481
24571
  let activeOrientation = null;
24482
24572
  let pendingOrientation = null;
24573
+ let activeVAlign = null;
24574
+ let pendingVAlign = null;
24483
24575
  const floatManager = createFloatingObjectManager(
24484
24576
  normalizeColumns(activeColumns, contentWidth),
24485
24577
  { left: margins.left, right: margins.right },
@@ -24585,6 +24677,9 @@ function layoutDocument(blocks, measures, options = {}) {
24585
24677
  if (activeOrientation) {
24586
24678
  page.orientation = activeOrientation;
24587
24679
  }
24680
+ if (activeVAlign && activeVAlign !== "top") {
24681
+ page.vAlign = activeVAlign;
24682
+ }
24588
24683
  return page;
24589
24684
  };
24590
24685
  let pageCount = 0;
@@ -24663,6 +24758,10 @@ function layoutDocument(blocks, measures, options = {}) {
24663
24758
  activeSectionRefs = pendingSectionRefs;
24664
24759
  pendingSectionRefs = null;
24665
24760
  }
24761
+ if (pendingVAlign !== null) {
24762
+ activeVAlign = pendingVAlign;
24763
+ pendingVAlign = null;
24764
+ }
24666
24765
  pageCount += 1;
24667
24766
  return;
24668
24767
  }
@@ -24799,7 +24898,8 @@ function layoutDocument(blocks, measures, options = {}) {
24799
24898
  margins: ahead.margins ? { ...effectiveBlock.margins ?? {}, ...ahead.margins } : effectiveBlock.margins ?? {},
24800
24899
  pageSize: ahead.pageSize ?? effectiveBlock.pageSize,
24801
24900
  columns: ahead.columns ?? effectiveBlock.columns,
24802
- orientation: ahead.orientation ?? effectiveBlock.orientation
24901
+ orientation: ahead.orientation ?? effectiveBlock.orientation,
24902
+ vAlign: ahead.vAlign ?? effectiveBlock.vAlign
24803
24903
  };
24804
24904
  }
24805
24905
  const sectionState = {
@@ -24852,6 +24952,15 @@ function layoutDocument(blocks, measures, options = {}) {
24852
24952
  pendingColumns = updatedState.pendingColumns;
24853
24953
  activeOrientation = updatedState.activeOrientation;
24854
24954
  pendingOrientation = updatedState.pendingOrientation;
24955
+ if (effectiveBlock.vAlign) {
24956
+ const isFirstSection = effectiveBlock.attrs?.isFirstSection && states.length === 0;
24957
+ if (isFirstSection) {
24958
+ activeVAlign = effectiveBlock.vAlign;
24959
+ pendingVAlign = null;
24960
+ } else {
24961
+ pendingVAlign = effectiveBlock.vAlign;
24962
+ }
24963
+ }
24855
24964
  if (effectiveBlock.headerRefs || effectiveBlock.footerRefs) {
24856
24965
  pendingSectionRefs = {
24857
24966
  ...effectiveBlock.headerRefs && { headerRefs: effectiveBlock.headerRefs },
@@ -24860,8 +24969,17 @@ function layoutDocument(blocks, measures, options = {}) {
24860
24969
  layoutLog(`[Layout] After scheduleSectionBreakCompat: Scheduled pendingSectionRefs:`, pendingSectionRefs);
24861
24970
  }
24862
24971
  if (breakInfo.forceMidPageRegion && block.columns) {
24863
- const state = paginator.ensurePage();
24864
- startMidPageRegion(state, { count: block.columns.count, gap: block.columns.gap });
24972
+ let state = paginator.ensurePage();
24973
+ const columnIndexBefore = state.columnIndex;
24974
+ const rawCount = block.columns.count;
24975
+ const validatedCount = typeof rawCount === "number" && Number.isFinite(rawCount) && rawCount > 0 ? Math.max(1, Math.floor(rawCount)) : 1;
24976
+ const rawGap = block.columns.gap;
24977
+ const validatedGap = typeof rawGap === "number" && Number.isFinite(rawGap) && rawGap >= 0 ? Math.max(0, rawGap) : 0;
24978
+ const newColumns = { count: validatedCount, gap: validatedGap };
24979
+ if (columnIndexBefore >= newColumns.count) {
24980
+ state = paginator.startNewPage();
24981
+ }
24982
+ startMidPageRegion(state, newColumns);
24865
24983
  }
24866
24984
  if (breakInfo.forcePageBreak) {
24867
24985
  let state = paginator.ensurePage();
@@ -25053,6 +25171,45 @@ function layoutDocument(blocks, measures, options = {}) {
25053
25171
  while (pages.length > 0 && pages[pages.length - 1].fragments.length === 0) {
25054
25172
  pages.pop();
25055
25173
  }
25174
+ for (const page of pages) {
25175
+ if (!page.vAlign || page.vAlign === "top") continue;
25176
+ if (page.fragments.length === 0) continue;
25177
+ const pageSizeForPage = page.size ?? pageSize;
25178
+ const contentTop = page.margins?.top ?? margins.top;
25179
+ const contentBottom = pageSizeForPage.h - (page.margins?.bottom ?? margins.bottom);
25180
+ const contentHeight = contentBottom - contentTop;
25181
+ let minY = Infinity;
25182
+ let maxY = -Infinity;
25183
+ for (const fragment of page.fragments) {
25184
+ if (fragment.y < minY) minY = fragment.y;
25185
+ let fragmentBottom = fragment.y;
25186
+ if (hasHeight(fragment)) {
25187
+ fragmentBottom += fragment.height;
25188
+ } else {
25189
+ const lineCount = fragment.toLine - fragment.fromLine;
25190
+ fragmentBottom += lineCount * DEFAULT_PARAGRAPH_LINE_HEIGHT_PX;
25191
+ }
25192
+ if (fragmentBottom > maxY) maxY = fragmentBottom;
25193
+ }
25194
+ const actualContentHeight = maxY - minY;
25195
+ const availableSpace = contentHeight - actualContentHeight;
25196
+ if (availableSpace <= 0) {
25197
+ continue;
25198
+ }
25199
+ let yOffset = 0;
25200
+ if (page.vAlign === "center") {
25201
+ yOffset = availableSpace / 2;
25202
+ } else if (page.vAlign === "bottom") {
25203
+ yOffset = availableSpace;
25204
+ } else if (page.vAlign === "both") {
25205
+ yOffset = availableSpace / 2;
25206
+ }
25207
+ if (yOffset > 0) {
25208
+ for (const fragment of page.fragments) {
25209
+ fragment.y += yOffset;
25210
+ }
25211
+ }
25212
+ }
25056
25213
  return {
25057
25214
  pageSize,
25058
25215
  pages,
@@ -29480,14 +29637,25 @@ const PRINT_STYLES = `
29480
29637
  }
29481
29638
  `;
29482
29639
  const LINK_AND_TOC_STYLES = `
29483
- /* Reset browser default link styling - allow run colors to show through */
29640
+ /* Reset browser default link styling - allow run colors to show through from inline styles
29641
+ *
29642
+ * Note: !important was removed from these rules to allow inline styles to take precedence.
29643
+ * This is necessary because OOXML hyperlink character styles apply colors via inline style
29644
+ * attributes on the run elements. The CSS cascade ensures that inline styles (applied via
29645
+ * element.style.color in applyRunStyles) override these class-based rules naturally.
29646
+ *
29647
+ * Implications:
29648
+ * - OOXML hyperlink character styles will correctly display their assigned colors
29649
+ * - Browser default link colors are still reset by these inherit rules
29650
+ * - Inline color styles from run objects override the inherit value as expected
29651
+ */
29484
29652
  .superdoc-link {
29485
- color: inherit !important;
29486
- text-decoration: none !important;
29653
+ color: inherit;
29654
+ text-decoration: none;
29487
29655
  }
29488
29656
 
29489
29657
  .superdoc-link:visited {
29490
- color: inherit !important;
29658
+ color: inherit;
29491
29659
  }
29492
29660
 
29493
29661
  .superdoc-link:hover {
@@ -31026,14 +31194,23 @@ const _DomPainter = class _DomPainter {
31026
31194
  lines.forEach((line, index2) => {
31027
31195
  const lineEl = this.renderLine(block, line, context);
31028
31196
  const isListFirstLine = index2 === 0 && !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker;
31029
- if (paraIndentLeft && !isListFirstLine) {
31030
- lineEl.style.paddingLeft = `${paraIndentLeft}px`;
31197
+ const hasExplicitSegmentPositioning = line.segments?.some((seg) => seg.x !== void 0);
31198
+ const isFirstLine = index2 === 0 && !fragment.continuesFromPrev;
31199
+ if (!isListFirstLine) {
31200
+ if (isFirstLine && hasExplicitSegmentPositioning && firstLineOffset !== 0) {
31201
+ const adjustedPadding = paraIndentLeft + firstLineOffset;
31202
+ lineEl.style.paddingLeft = `${adjustedPadding}px`;
31203
+ } else if (paraIndentLeft) {
31204
+ lineEl.style.paddingLeft = `${paraIndentLeft}px`;
31205
+ }
31031
31206
  }
31032
31207
  if (paraIndentRight) {
31033
31208
  lineEl.style.paddingRight = `${paraIndentRight}px`;
31034
31209
  }
31035
31210
  if (!fragment.continuesFromPrev && index2 === 0 && firstLineOffset && !isListFirstLine) {
31036
- lineEl.style.textIndent = `${firstLineOffset}px`;
31211
+ if (!hasExplicitSegmentPositioning) {
31212
+ lineEl.style.textIndent = `${firstLineOffset}px`;
31213
+ }
31037
31214
  } else if (firstLineOffset && !isListFirstLine) {
31038
31215
  lineEl.style.textIndent = "0px";
31039
31216
  }
@@ -31927,6 +32104,24 @@ const _DomPainter = class _DomPainter {
31927
32104
  }
31928
32105
  elem.setAttribute("role", "link");
31929
32106
  elem.setAttribute("tabindex", "0");
32107
+ elem.addEventListener("click", (event) => {
32108
+ event.preventDefault();
32109
+ event.stopPropagation();
32110
+ const linkClickEvent = new CustomEvent("superdoc-link-click", {
32111
+ bubbles: true,
32112
+ composed: true,
32113
+ detail: {
32114
+ href: linkData.href,
32115
+ target: linkData.target,
32116
+ rel: linkData.rel,
32117
+ tooltip: linkData.tooltip,
32118
+ element: elem,
32119
+ clientX: event.clientX,
32120
+ clientY: event.clientY
32121
+ }
32122
+ });
32123
+ elem.dispatchEvent(linkClickEvent);
32124
+ });
31930
32125
  }
31931
32126
  /**
31932
32127
  * Render a single run as an HTML element (span or anchor).
@@ -32216,7 +32411,13 @@ const _DomPainter = class _DomPainter {
32216
32411
  if (styleId) {
32217
32412
  elem.setAttribute("styleid", styleId);
32218
32413
  }
32414
+ const runSegments2 = segmentsByRun.get(runIndex);
32415
+ const segX = runSegments2 && runSegments2[0]?.x !== void 0 ? runSegments2[0].x : cumulativeX;
32416
+ const segWidth = (runSegments2 && runSegments2[0]?.width !== void 0 ? runSegments2[0].width : elem.offsetWidth) ?? 0;
32417
+ elem.style.position = "absolute";
32418
+ elem.style.left = `${segX}px`;
32219
32419
  el.appendChild(elem);
32420
+ cumulativeX = segX + segWidth;
32220
32421
  }
32221
32422
  continue;
32222
32423
  }
@@ -32758,7 +32959,7 @@ const deriveBlockVersion = (block) => {
32758
32959
  }
32759
32960
  return block.id;
32760
32961
  };
32761
- const applyRunStyles = (element, run, isLink = false) => {
32962
+ const applyRunStyles = (element, run, _isLink = false) => {
32762
32963
  if (run.kind === "tab" || run.kind === "image" || run.kind === "lineBreak" || run.kind === "break") {
32763
32964
  return;
32764
32965
  }
@@ -32766,9 +32967,7 @@ const applyRunStyles = (element, run, isLink = false) => {
32766
32967
  element.style.fontSize = `${run.fontSize}px`;
32767
32968
  if (run.bold) element.style.fontWeight = "bold";
32768
32969
  if (run.italic) element.style.fontStyle = "italic";
32769
- if (!isLink) {
32770
- if (run.color) element.style.color = run.color;
32771
- }
32970
+ if (run.color) element.style.color = run.color;
32772
32971
  if (run.letterSpacing != null) {
32773
32972
  element.style.letterSpacing = `${run.letterSpacing}px`;
32774
32973
  }
@@ -33316,28 +33515,44 @@ async function measureParagraphBlock(block, maxWidth) {
33316
33515
  }
33317
33516
  return true;
33318
33517
  };
33319
- const alignSegmentAtTab = (segmentText, font, runContext) => {
33320
- if (!pendingTabAlignment || !currentLine) return;
33518
+ const alignPendingTabForWidth = (segmentWidth, beforeDecimalWidth) => {
33519
+ if (!pendingTabAlignment || !currentLine) return void 0;
33520
+ if (segmentWidth < 0) {
33521
+ segmentWidth = 0;
33522
+ }
33321
33523
  const { target, val } = pendingTabAlignment;
33322
33524
  let startX = currentLine.width;
33525
+ if (val === "decimal") {
33526
+ const beforeWidth = beforeDecimalWidth ?? 0;
33527
+ startX = Math.max(0, target - beforeWidth);
33528
+ } else if (val === "end") {
33529
+ startX = Math.max(0, target - segmentWidth);
33530
+ } else if (val === "center") {
33531
+ startX = Math.max(0, target - segmentWidth / 2);
33532
+ } else {
33533
+ startX = Math.max(0, target);
33534
+ }
33535
+ currentLine.width = roundValue(startX);
33536
+ lastAppliedTabAlign = { target, val };
33537
+ pendingTabAlignment = null;
33538
+ return startX;
33539
+ };
33540
+ const alignSegmentAtTab = (segmentText, font, runContext) => {
33541
+ if (!pendingTabAlignment || !currentLine) return void 0;
33542
+ const { val } = pendingTabAlignment;
33543
+ let segmentWidth = 0;
33544
+ let beforeDecimalWidth;
33323
33545
  if (val === "decimal") {
33324
33546
  const idx = segmentText.indexOf(decimalSeparator);
33325
33547
  if (idx >= 0) {
33326
33548
  const beforeText = segmentText.slice(0, idx);
33327
- const beforeWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
33328
- startX = Math.max(0, target - beforeWidth);
33329
- } else {
33330
- startX = Math.max(0, target);
33549
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
33331
33550
  }
33551
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
33332
33552
  } else if (val === "end" || val === "center") {
33333
- const segWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
33334
- startX = val === "end" ? Math.max(0, target - segWidth) : Math.max(0, target - segWidth / 2);
33335
- } else if (val === "start" || val === "bar") {
33336
- startX = Math.max(0, target);
33553
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
33337
33554
  }
33338
- currentLine.width = roundValue(startX);
33339
- lastAppliedTabAlign = { target, val };
33340
- pendingTabAlignment = null;
33555
+ return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
33341
33556
  };
33342
33557
  const runsToProcess = [];
33343
33558
  for (const run of block.runs) {
@@ -33486,6 +33701,10 @@ async function measureParagraphBlock(block, maxWidth) {
33486
33701
  const topSpace = run.distTop ?? 0;
33487
33702
  const bottomSpace = run.distBottom ?? 0;
33488
33703
  const imageHeight = run.height + topSpace + bottomSpace;
33704
+ let imageStartX;
33705
+ if (pendingTabAlignment && currentLine) {
33706
+ imageStartX = alignPendingTabForWidth(imageWidth);
33707
+ }
33489
33708
  if (!currentLine) {
33490
33709
  currentLine = {
33491
33710
  fromRun: runIndex,
@@ -33502,12 +33721,14 @@ async function measureParagraphBlock(block, maxWidth) {
33502
33721
  runIndex,
33503
33722
  fromChar: 0,
33504
33723
  toChar: 1,
33505
- width: imageWidth
33724
+ width: imageWidth,
33725
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
33506
33726
  }
33507
33727
  ]
33508
33728
  };
33509
33729
  continue;
33510
33730
  }
33731
+ const appliedTabAlign = lastAppliedTabAlign;
33511
33732
  if (currentLine.width + imageWidth > currentLine.maxWidth && currentLine.width > 0) {
33512
33733
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
33513
33734
  const completedLine = {
@@ -33518,6 +33739,7 @@ async function measureParagraphBlock(block, maxWidth) {
33518
33739
  lines.push(completedLine);
33519
33740
  tabStopCursor = 0;
33520
33741
  pendingTabAlignment = null;
33742
+ lastAppliedTabAlign = null;
33521
33743
  currentLine = {
33522
33744
  fromRun: runIndex,
33523
33745
  fromChar: 0,
@@ -33545,9 +33767,15 @@ async function measureParagraphBlock(block, maxWidth) {
33545
33767
  runIndex,
33546
33768
  fromChar: 0,
33547
33769
  toChar: 1,
33548
- width: imageWidth
33770
+ width: imageWidth,
33771
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
33549
33772
  });
33550
33773
  }
33774
+ const tabAlign = appliedTabAlign;
33775
+ if (tabAlign && currentLine && tabAlign.val === "end") {
33776
+ currentLine.width = roundValue(tabAlign.target);
33777
+ }
33778
+ lastAppliedTabAlign = null;
33551
33779
  continue;
33552
33780
  }
33553
33781
  if (!("text" in run) || !("fontSize" in run)) {
@@ -33563,8 +33791,10 @@ async function measureParagraphBlock(block, maxWidth) {
33563
33791
  const words = segment.split(" ");
33564
33792
  let segmentStartX;
33565
33793
  if (currentLine && pendingTabAlignment) {
33566
- alignSegmentAtTab(segment, font, run);
33567
- segmentStartX = currentLine.width;
33794
+ segmentStartX = alignSegmentAtTab(segment, font, run);
33795
+ if (segmentStartX == null) {
33796
+ segmentStartX = currentLine.width;
33797
+ }
33568
33798
  }
33569
33799
  for (let wordIndex = 0; wordIndex < words.length; wordIndex++) {
33570
33800
  const word = words[wordIndex];
@@ -34205,12 +34435,49 @@ const createHeaderFooterEditor = ({
34205
34435
  editor,
34206
34436
  data,
34207
34437
  editorContainer,
34208
- appendToBody = true,
34438
+ editorHost,
34209
34439
  sectionId,
34210
34440
  type,
34441
+ availableWidth,
34211
34442
  availableHeight,
34212
- currentPageNumber
34443
+ currentPageNumber,
34444
+ totalPageCount
34213
34445
  }) => {
34446
+ if (!editor) {
34447
+ throw new TypeError("editor parameter is required");
34448
+ }
34449
+ if (!data) {
34450
+ throw new TypeError("data parameter is required");
34451
+ }
34452
+ if (!editorContainer) {
34453
+ throw new TypeError("editorContainer parameter is required");
34454
+ }
34455
+ if (!(editorContainer instanceof HTMLElement)) {
34456
+ throw new TypeError("editorContainer must be an HTMLElement");
34457
+ }
34458
+ if (editorHost !== void 0 && !(editorHost instanceof HTMLElement)) {
34459
+ throw new TypeError("editorHost must be an HTMLElement or undefined");
34460
+ }
34461
+ if (availableWidth !== void 0) {
34462
+ if (typeof availableWidth !== "number" || !Number.isFinite(availableWidth) || availableWidth <= 0) {
34463
+ throw new RangeError("availableWidth must be a positive number");
34464
+ }
34465
+ }
34466
+ if (availableHeight !== void 0) {
34467
+ if (typeof availableHeight !== "number" || !Number.isFinite(availableHeight) || availableHeight <= 0) {
34468
+ throw new RangeError("availableHeight must be a positive number");
34469
+ }
34470
+ }
34471
+ if (currentPageNumber !== void 0) {
34472
+ if (typeof currentPageNumber !== "number" || !Number.isInteger(currentPageNumber) || currentPageNumber < 1) {
34473
+ throw new RangeError("currentPageNumber must be a positive integer");
34474
+ }
34475
+ }
34476
+ if (totalPageCount !== void 0) {
34477
+ if (typeof totalPageCount !== "number" || !Number.isInteger(totalPageCount) || totalPageCount < 1) {
34478
+ throw new RangeError("totalPageCount must be a positive integer");
34479
+ }
34480
+ }
34214
34481
  const parentStyles = editor.converter.getDocumentDefaultStyles();
34215
34482
  const { fontSizePt, typeface, fontFamilyCss } = parentStyles;
34216
34483
  const fontSizeInPixles = fontSizePt * 1.3333;
@@ -34224,21 +34491,24 @@ const createHeaderFooterEditor = ({
34224
34491
  position: "absolute",
34225
34492
  top: "0",
34226
34493
  left: "0",
34227
- width: "auto",
34494
+ width: availableWidth ? `${availableWidth}px` : "100%",
34495
+ height: availableHeight ? `${availableHeight}px` : "auto",
34228
34496
  maxWidth: "none",
34229
34497
  fontFamily: fontFamilyCss || typeface,
34230
34498
  fontSize: `${fontSizeInPixles}px`,
34231
- lineHeight: `${lineHeight}px`
34232
- });
34233
- Object.assign(editorContainer.style, {
34234
- padding: "0",
34235
- margin: "0",
34236
- border: "none",
34237
- boxSizing: "border-box",
34238
- height: availableHeight + "px",
34239
- overflow: "hidden"
34240
- });
34241
- if (appendToBody) document.body.appendChild(editorContainer);
34499
+ lineHeight: `${lineHeight}px`,
34500
+ overflow: "hidden",
34501
+ pointerEvents: "auto",
34502
+ // Critical: enables click interaction
34503
+ backgroundColor: "white"
34504
+ // Ensure editor has white background
34505
+ });
34506
+ if (editorHost) {
34507
+ editorHost.appendChild(editorContainer);
34508
+ } else {
34509
+ console.warn("[createHeaderFooterEditor] No editorHost provided, falling back to document.body");
34510
+ document.body.appendChild(editorContainer);
34511
+ }
34242
34512
  const headerFooterEditor = new Editor({
34243
34513
  role: editor.options.role,
34244
34514
  loadFromSchema: true,
@@ -34256,9 +34526,12 @@ const createHeaderFooterEditor = ({
34256
34526
  pagination: false,
34257
34527
  // Explicitly disable pagination
34258
34528
  annotations: true,
34259
- currentPageNumber,
34529
+ currentPageNumber: currentPageNumber ?? 1,
34530
+ totalPageCount: totalPageCount ?? 1,
34260
34531
  // Don't set parentEditor to avoid circular reference issues
34261
34532
  // parentEditor: editor,
34533
+ // IMPORTANT: Start with editable: false to prevent triggering update cascades during creation.
34534
+ // PresentationEditor#enterHeaderFooterMode will call setEditable(true) when entering edit mode.
34262
34535
  editable: false,
34263
34536
  documentMode: "viewing",
34264
34537
  onCreate: (evt) => setEditorToolbar(evt, editor),
@@ -34288,18 +34561,23 @@ const createHeaderFooterEditor = ({
34288
34561
  const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sectionId, type) => {
34289
34562
  if (!type || !sectionId) return;
34290
34563
  const updatedData = editor.getUpdatedJson();
34291
- mainEditor.converter[`${type}Editors`].forEach((item) => {
34292
- if (item.id === sectionId) {
34564
+ const editorsList = mainEditor.converter[`${type}Editors`];
34565
+ if (Array.isArray(editorsList)) {
34566
+ editorsList.forEach((item) => {
34567
+ if (item.id === sectionId) {
34568
+ item.editor.setOptions({
34569
+ media: editor.options.media,
34570
+ mediaFiles: editor.options.mediaFiles
34571
+ });
34572
+ if (item.editor !== editor) {
34573
+ item.editor.replaceContent(updatedData);
34574
+ }
34575
+ }
34293
34576
  item.editor.setOptions({
34294
- media: editor.options.media,
34295
- mediaFiles: editor.options.mediaFiles
34577
+ lastSelection: transaction?.selection
34296
34578
  });
34297
- item.editor.replaceContent(updatedData);
34298
- }
34299
- item.editor.setOptions({
34300
- lastSelection: transaction?.selection
34301
34579
  });
34302
- });
34580
+ }
34303
34581
  mainEditor.converter[`${type}s`][sectionId] = updatedData;
34304
34582
  mainEditor.setOptions({ isHeaderFooterChanged: editor.docChanged });
34305
34583
  await updateYdocDocxData(mainEditor);
@@ -34380,13 +34658,69 @@ class HeaderFooterEditorManager extends EventEmitter {
34380
34658
  * Handles concurrent calls for the same descriptor by tracking pending creations
34381
34659
  * and returning the same promise to all callers.
34382
34660
  *
34383
- * @param descriptor - The header or footer descriptor
34661
+ * @param descriptor - The header or footer descriptor. Must have a valid id property.
34662
+ * @param options - Optional configuration for editor creation
34663
+ * @param options.editorHost - The HTMLElement to mount the editor in. If provided, must be a valid HTMLElement.
34664
+ * @param options.availableWidth - The width of the editing region in pixels. Must be a positive number if provided.
34665
+ * @param options.availableHeight - The height of the editing region in pixels. Must be a positive number if provided.
34666
+ * @param options.currentPageNumber - The current page number for PAGE field resolution. Must be a positive integer if provided.
34667
+ * @param options.totalPageCount - The total page count for NUMPAGES field resolution. Must be a positive integer if provided.
34384
34668
  * @returns The editor instance, or null if creation failed
34385
34669
  *
34386
- * @throws Never throws - errors are logged and emitted as events
34670
+ * @throws Never throws - errors are logged and emitted as events. Invalid parameters return null with error logged.
34387
34671
  */
34388
- async ensureEditor(descriptor) {
34672
+ async ensureEditor(descriptor, options) {
34389
34673
  if (!descriptor?.id) return null;
34674
+ if (options) {
34675
+ if (options.editorHost !== void 0 && !(options.editorHost instanceof HTMLElement)) {
34676
+ console.error("[HeaderFooterEditorManager] editorHost must be an HTMLElement");
34677
+ this.emit("error", {
34678
+ descriptor,
34679
+ error: new TypeError("editorHost must be an HTMLElement")
34680
+ });
34681
+ return null;
34682
+ }
34683
+ if (options.availableWidth !== void 0) {
34684
+ if (typeof options.availableWidth !== "number" || !Number.isFinite(options.availableWidth) || options.availableWidth <= 0) {
34685
+ console.error("[HeaderFooterEditorManager] availableWidth must be a positive number");
34686
+ this.emit("error", {
34687
+ descriptor,
34688
+ error: new TypeError("availableWidth must be a positive number")
34689
+ });
34690
+ return null;
34691
+ }
34692
+ }
34693
+ if (options.availableHeight !== void 0) {
34694
+ if (typeof options.availableHeight !== "number" || !Number.isFinite(options.availableHeight) || options.availableHeight <= 0) {
34695
+ console.error("[HeaderFooterEditorManager] availableHeight must be a positive number");
34696
+ this.emit("error", {
34697
+ descriptor,
34698
+ error: new TypeError("availableHeight must be a positive number")
34699
+ });
34700
+ return null;
34701
+ }
34702
+ }
34703
+ if (options.currentPageNumber !== void 0) {
34704
+ if (typeof options.currentPageNumber !== "number" || !Number.isInteger(options.currentPageNumber) || options.currentPageNumber < 1) {
34705
+ console.error("[HeaderFooterEditorManager] currentPageNumber must be a positive integer");
34706
+ this.emit("error", {
34707
+ descriptor,
34708
+ error: new TypeError("currentPageNumber must be a positive integer")
34709
+ });
34710
+ return null;
34711
+ }
34712
+ }
34713
+ if (options.totalPageCount !== void 0) {
34714
+ if (typeof options.totalPageCount !== "number" || !Number.isInteger(options.totalPageCount) || options.totalPageCount < 1) {
34715
+ console.error("[HeaderFooterEditorManager] totalPageCount must be a positive integer");
34716
+ this.emit("error", {
34717
+ descriptor,
34718
+ error: new TypeError("totalPageCount must be a positive integer")
34719
+ });
34720
+ return null;
34721
+ }
34722
+ }
34723
+ }
34390
34724
  const existing = __privateGet(this, _editorEntries).get(descriptor.id);
34391
34725
  if (existing) {
34392
34726
  __privateSet(this, _cacheHits, __privateGet(this, _cacheHits) + 1);
@@ -34395,6 +34729,29 @@ class HeaderFooterEditorManager extends EventEmitter {
34395
34729
  console.error("[HeaderFooterEditorManager] Editor initialization failed:", error);
34396
34730
  this.emit("error", { descriptor, error });
34397
34731
  });
34732
+ if (existing.container && options?.editorHost) {
34733
+ if (existing.container.parentElement !== options.editorHost) {
34734
+ options.editorHost.appendChild(existing.container);
34735
+ }
34736
+ }
34737
+ if (existing.editor && options) {
34738
+ const updateOptions = {};
34739
+ if (options.currentPageNumber !== void 0) {
34740
+ updateOptions.currentPageNumber = options.currentPageNumber;
34741
+ }
34742
+ if (options.totalPageCount !== void 0) {
34743
+ updateOptions.totalPageCount = options.totalPageCount;
34744
+ }
34745
+ if (options.availableWidth !== void 0) {
34746
+ updateOptions.availableWidth = options.availableWidth;
34747
+ }
34748
+ if (options.availableHeight !== void 0) {
34749
+ updateOptions.availableHeight = options.availableHeight;
34750
+ }
34751
+ if (Object.keys(updateOptions).length > 0) {
34752
+ existing.editor.setOptions(updateOptions);
34753
+ }
34754
+ }
34398
34755
  return existing.editor;
34399
34756
  }
34400
34757
  const pending = __privateGet(this, _pendingCreations).get(descriptor.id);
@@ -34404,7 +34761,7 @@ class HeaderFooterEditorManager extends EventEmitter {
34404
34761
  __privateSet(this, _cacheMisses, __privateGet(this, _cacheMisses) + 1);
34405
34762
  const creationPromise = (async () => {
34406
34763
  try {
34407
- const entry = await __privateMethod(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor);
34764
+ const entry = await __privateMethod(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor, options);
34408
34765
  if (!entry) return null;
34409
34766
  __privateGet(this, _editorEntries).set(descriptor.id, entry);
34410
34767
  __privateMethod(this, _HeaderFooterEditorManager_instances, updateAccessOrder_fn).call(this, descriptor.id);
@@ -34731,7 +35088,7 @@ teardownEditors_fn = function() {
34731
35088
  });
34732
35089
  __privateGet(this, _editorEntries).clear();
34733
35090
  };
34734
- createEditor_fn = async function(descriptor) {
35091
+ createEditor_fn = async function(descriptor, options) {
34735
35092
  const json = this.getDocumentJson(descriptor);
34736
35093
  if (!json) return null;
34737
35094
  let editor;
@@ -34742,12 +35099,13 @@ createEditor_fn = async function(descriptor) {
34742
35099
  editor: __privateGet(this, _editor2),
34743
35100
  data: json,
34744
35101
  editorContainer: container,
34745
- appendToBody: true,
35102
+ editorHost: options?.editorHost,
34746
35103
  sectionId: descriptor.id,
34747
35104
  type: descriptor.kind,
34748
- availableHeight: DEFAULT_HEADER_FOOTER_HEIGHT,
34749
- currentPageNumber: 1
34750
- // Default page number
35105
+ availableWidth: options?.availableWidth,
35106
+ availableHeight: options?.availableHeight ?? DEFAULT_HEADER_FOOTER_HEIGHT,
35107
+ currentPageNumber: options?.currentPageNumber ?? 1,
35108
+ totalPageCount: options?.totalPageCount ?? 1
34751
35109
  });
34752
35110
  } catch (error) {
34753
35111
  console.error("[HeaderFooterEditorManager] Editor creation failed:", error);
@@ -35055,6 +35413,356 @@ getConverterContext_fn = function() {
35055
35413
  }
35056
35414
  return Object.keys(context).length > 0 ? context : void 0;
35057
35415
  };
35416
+ const EDITOR_HOST_Z_INDEX = "10";
35417
+ const BORDER_LINE_Z_INDEX = "15";
35418
+ const BORDER_LINE_COLOR = "#4472c4";
35419
+ const BORDER_LINE_HEIGHT = "1px";
35420
+ class EditorOverlayManager {
35421
+ /**
35422
+ * Creates a new EditorOverlayManager instance.
35423
+ *
35424
+ * @param painterHost - The host element containing painted pages. Must be an HTMLElement connected to the DOM.
35425
+ * @param visibleHost - The visible host element for overlay positioning. Must be an HTMLElement connected to the DOM.
35426
+ * @param selectionOverlay - The selection overlay element (optional). If provided, must be an HTMLElement.
35427
+ *
35428
+ * @throws {TypeError} If painterHost is not an HTMLElement
35429
+ * @throws {TypeError} If visibleHost is not an HTMLElement
35430
+ * @throws {TypeError} If selectionOverlay is provided but is not an HTMLElement
35431
+ * @throws {Error} If painterHost is not connected to the DOM
35432
+ * @throws {Error} If visibleHost is not connected to the DOM
35433
+ */
35434
+ constructor(painterHost, visibleHost, selectionOverlay = null) {
35435
+ __privateAdd(this, _EditorOverlayManager_instances);
35436
+ /** Selection overlay element (for hiding during editing) */
35437
+ __privateAdd(this, _selectionOverlay);
35438
+ /** Currently active editor host element */
35439
+ __privateAdd(this, _activeEditorHost, null);
35440
+ /** Currently active static decoration container */
35441
+ __privateAdd(this, _activeDecorationContainer, null);
35442
+ /** Current editing region */
35443
+ __privateAdd(this, _activeRegion, null);
35444
+ /** Full-width border line element (MS Word style) */
35445
+ __privateAdd(this, _borderLine, null);
35446
+ if (!(painterHost instanceof HTMLElement)) {
35447
+ throw new TypeError("painterHost must be an HTMLElement");
35448
+ }
35449
+ if (!(visibleHost instanceof HTMLElement)) {
35450
+ throw new TypeError("visibleHost must be an HTMLElement");
35451
+ }
35452
+ if (selectionOverlay !== null && !(selectionOverlay instanceof HTMLElement)) {
35453
+ throw new TypeError("selectionOverlay must be an HTMLElement or null");
35454
+ }
35455
+ if (!painterHost.isConnected) {
35456
+ throw new Error("painterHost must be connected to the DOM");
35457
+ }
35458
+ if (!visibleHost.isConnected) {
35459
+ throw new Error("visibleHost must be connected to the DOM");
35460
+ }
35461
+ __privateSet(this, _selectionOverlay, selectionOverlay);
35462
+ }
35463
+ /**
35464
+ * Sets the callback to be invoked when the dimming overlay is clicked.
35465
+ * This allows PresentationEditor to exit header/footer mode when the user
35466
+ * clicks outside the editing region.
35467
+ *
35468
+ * @param callback - Function to call when dimming overlay is clicked
35469
+ */
35470
+ setOnDimmingClick(_callback) {
35471
+ }
35472
+ /**
35473
+ * Gets the currently active editor host element.
35474
+ * This is useful for checking if a click target is inside the active editing area.
35475
+ *
35476
+ * @returns The active editor host element, or null if not in editing mode
35477
+ */
35478
+ getActiveEditorHost() {
35479
+ return __privateGet(this, _activeEditorHost);
35480
+ }
35481
+ /**
35482
+ * Shows the editing overlay for a header/footer region.
35483
+ *
35484
+ * This method:
35485
+ * 1. Creates or retrieves the editor host element as a sibling to the decoration container
35486
+ * 2. Positions the editor host to match the decoration container bounds
35487
+ * 3. Hides the static decoration content
35488
+ * 4. Shows the dimming overlay over body content
35489
+ * 5. Returns the editor host element for mounting the ProseMirror editor
35490
+ *
35491
+ * @param pageElement - The page DOM element containing the region
35492
+ * @param region - The header/footer region to edit
35493
+ * @param zoom - Current zoom level (for positioning calculations)
35494
+ * @returns Result object with success status and editor host element
35495
+ *
35496
+ * @example
35497
+ * ```typescript
35498
+ * const result = overlayManager.showEditingOverlay(pageElement, region, 1.0);
35499
+ * if (result.success && result.editorHost) {
35500
+ * // Mount ProseMirror editor in result.editorHost
35501
+ * }
35502
+ * ```
35503
+ */
35504
+ showEditingOverlay(pageElement, region, zoom) {
35505
+ try {
35506
+ const decorationContainer = __privateMethod(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, region.kind);
35507
+ if (!decorationContainer) {
35508
+ return {
35509
+ success: false,
35510
+ reason: `Decoration container not found for ${region.kind} on page ${region.pageIndex}`
35511
+ };
35512
+ }
35513
+ const editorHost = __privateMethod(this, _EditorOverlayManager_instances, ensureEditorHost_fn).call(this, pageElement, region.kind);
35514
+ if (!editorHost) {
35515
+ return {
35516
+ success: false,
35517
+ reason: `Failed to create editor host for ${region.kind}`
35518
+ };
35519
+ }
35520
+ __privateMethod(this, _EditorOverlayManager_instances, positionEditorHost_fn).call(this, editorHost, region, decorationContainer, zoom);
35521
+ decorationContainer.style.visibility = "hidden";
35522
+ editorHost.style.visibility = "visible";
35523
+ editorHost.style.zIndex = EDITOR_HOST_Z_INDEX;
35524
+ if (region.kind === "footer") {
35525
+ const contentOffset = editorHost.dataset.contentOffset;
35526
+ if (contentOffset) {
35527
+ const editorContainer = editorHost.querySelector(".super-editor");
35528
+ if (editorContainer instanceof HTMLElement) {
35529
+ editorContainer.style.top = `${contentOffset}px`;
35530
+ }
35531
+ }
35532
+ }
35533
+ __privateMethod(this, _EditorOverlayManager_instances, showHeaderFooterBorder_fn).call(this, pageElement, region, decorationContainer);
35534
+ __privateSet(this, _activeEditorHost, editorHost);
35535
+ __privateSet(this, _activeDecorationContainer, decorationContainer);
35536
+ __privateSet(this, _activeRegion, region);
35537
+ return {
35538
+ success: true,
35539
+ editorHost
35540
+ };
35541
+ } catch (error) {
35542
+ if (__privateGet(this, _activeDecorationContainer)) {
35543
+ __privateGet(this, _activeDecorationContainer).style.visibility = "visible";
35544
+ }
35545
+ if (__privateGet(this, _activeEditorHost)) {
35546
+ __privateGet(this, _activeEditorHost).style.visibility = "hidden";
35547
+ }
35548
+ __privateMethod(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
35549
+ const errorMessage = error instanceof Error ? error.message : String(error);
35550
+ console.error("[EditorOverlayManager] Failed to show editing overlay:", error);
35551
+ return {
35552
+ success: false,
35553
+ reason: `DOM manipulation error: ${errorMessage}`
35554
+ };
35555
+ }
35556
+ }
35557
+ /**
35558
+ * Hides the editing overlay and restores normal view.
35559
+ *
35560
+ * This method:
35561
+ * 1. Shows the static decoration content
35562
+ * 2. Hides the editor host (but doesn't destroy it for reuse)
35563
+ * 3. Removes the dimming overlay
35564
+ *
35565
+ * @example
35566
+ * ```typescript
35567
+ * overlayManager.hideEditingOverlay();
35568
+ * // Static decoration is now visible, editor is hidden
35569
+ * ```
35570
+ */
35571
+ hideEditingOverlay() {
35572
+ if (__privateGet(this, _activeDecorationContainer)) {
35573
+ __privateGet(this, _activeDecorationContainer).style.visibility = "visible";
35574
+ }
35575
+ if (__privateGet(this, _activeEditorHost)) {
35576
+ __privateGet(this, _activeEditorHost).style.visibility = "hidden";
35577
+ __privateGet(this, _activeEditorHost).style.zIndex = "";
35578
+ if (__privateGet(this, _activeRegion)?.kind === "footer") {
35579
+ const editorContainer = __privateGet(this, _activeEditorHost).querySelector(".super-editor");
35580
+ if (editorContainer instanceof HTMLElement) {
35581
+ editorContainer.style.top = "0";
35582
+ }
35583
+ }
35584
+ }
35585
+ __privateMethod(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
35586
+ __privateSet(this, _activeEditorHost, null);
35587
+ __privateSet(this, _activeDecorationContainer, null);
35588
+ __privateSet(this, _activeRegion, null);
35589
+ }
35590
+ /**
35591
+ * Hides the layout selection overlay to prevent double caret rendering.
35592
+ *
35593
+ * Called when entering header/footer editing mode to ensure only the
35594
+ * ProseMirror editor's caret is visible, not both the PM caret and the
35595
+ * layout engine's selection overlay.
35596
+ *
35597
+ * @example
35598
+ * ```typescript
35599
+ * overlayManager.hideSelectionOverlay();
35600
+ * // Selection overlay is now hidden
35601
+ * ```
35602
+ */
35603
+ hideSelectionOverlay() {
35604
+ if (__privateGet(this, _selectionOverlay)) {
35605
+ __privateGet(this, _selectionOverlay).style.visibility = "hidden";
35606
+ }
35607
+ }
35608
+ /**
35609
+ * Shows the layout selection overlay.
35610
+ *
35611
+ * Called when exiting header/footer editing mode to restore the
35612
+ * normal selection overlay rendering for body content.
35613
+ *
35614
+ * @example
35615
+ * ```typescript
35616
+ * overlayManager.showSelectionOverlay();
35617
+ * // Selection overlay is now visible
35618
+ * ```
35619
+ */
35620
+ showSelectionOverlay() {
35621
+ if (__privateGet(this, _selectionOverlay)) {
35622
+ __privateGet(this, _selectionOverlay).style.visibility = "visible";
35623
+ }
35624
+ }
35625
+ /**
35626
+ * Destroys the overlay manager and cleans up all resources.
35627
+ *
35628
+ * Clears all references.
35629
+ * Editor host elements are left in the DOM as they're children of page elements
35630
+ * that will be cleaned up by the virtualization system.
35631
+ */
35632
+ destroy() {
35633
+ __privateMethod(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
35634
+ __privateSet(this, _activeEditorHost, null);
35635
+ __privateSet(this, _activeDecorationContainer, null);
35636
+ __privateSet(this, _activeRegion, null);
35637
+ __privateSet(this, _selectionOverlay, null);
35638
+ }
35639
+ }
35640
+ _selectionOverlay = new WeakMap();
35641
+ _activeEditorHost = new WeakMap();
35642
+ _activeDecorationContainer = new WeakMap();
35643
+ _activeRegion = new WeakMap();
35644
+ _borderLine = new WeakMap();
35645
+ _EditorOverlayManager_instances = new WeakSet();
35646
+ /**
35647
+ * Finds the decoration container element for a given region kind.
35648
+ *
35649
+ * Decoration containers are created by the layout engine renderer with
35650
+ * class names 'superdoc-page-header' or 'superdoc-page-footer'.
35651
+ *
35652
+ * @param pageElement - The page element to search within
35653
+ * @param kind - The region kind (header or footer)
35654
+ * @returns The decoration container element, or null if not found
35655
+ */
35656
+ findDecorationContainer_fn = function(pageElement, kind) {
35657
+ const className = kind === "header" ? "superdoc-page-header" : "superdoc-page-footer";
35658
+ return pageElement.querySelector(`.${className}`);
35659
+ };
35660
+ /**
35661
+ * Ensures an editor host element exists as a sibling to the decoration container.
35662
+ *
35663
+ * If the editor host doesn't exist, creates it. Otherwise, returns the existing one.
35664
+ * The editor host is positioned as a sibling (not child) of the decoration container
35665
+ * to avoid the pointer-events: none constraint.
35666
+ *
35667
+ * @param pageElement - The page element to create the host within
35668
+ * @param kind - The region kind (header or footer)
35669
+ * @returns The editor host element
35670
+ */
35671
+ ensureEditorHost_fn = function(pageElement, kind) {
35672
+ const className = kind === "header" ? "superdoc-header-editor-host" : "superdoc-footer-editor-host";
35673
+ let editorHost = pageElement.querySelector(`.${className}`);
35674
+ if (!editorHost) {
35675
+ editorHost = document.createElement("div");
35676
+ editorHost.className = className;
35677
+ Object.assign(editorHost.style, {
35678
+ position: "absolute",
35679
+ pointerEvents: "auto",
35680
+ // Critical: enables click interaction
35681
+ visibility: "hidden",
35682
+ // Hidden by default, shown during editing
35683
+ overflow: "hidden",
35684
+ boxSizing: "border-box"
35685
+ });
35686
+ const decorationContainer = __privateMethod(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, kind);
35687
+ if (!decorationContainer) {
35688
+ console.error(`[EditorOverlayManager] Decoration container not found for ${kind}`);
35689
+ return null;
35690
+ }
35691
+ decorationContainer.parentNode?.insertBefore(editorHost, decorationContainer.nextSibling);
35692
+ }
35693
+ return editorHost;
35694
+ };
35695
+ /**
35696
+ * Positions the editor host to match the decoration container bounds.
35697
+ *
35698
+ * The editor host is positioned absolutely within the page element to exactly
35699
+ * overlap the decoration container's visual space.
35700
+ *
35701
+ * @param editorHost - The editor host element to position
35702
+ * @param region - The header/footer region with dimension data
35703
+ * @param decorationContainer - The decoration container to match
35704
+ * @param zoom - Current zoom level
35705
+ */
35706
+ positionEditorHost_fn = function(editorHost, region, decorationContainer, _zoom) {
35707
+ const decorationRect = decorationContainer.getBoundingClientRect();
35708
+ const pageElement = editorHost.parentElement;
35709
+ if (!pageElement) {
35710
+ console.error("[EditorOverlayManager] Editor host has no parent element");
35711
+ return;
35712
+ }
35713
+ const pageRect = pageElement.getBoundingClientRect();
35714
+ const top2 = decorationRect.top - pageRect.top;
35715
+ const left2 = decorationRect.left - pageRect.left;
35716
+ const width = decorationRect.width;
35717
+ const height = decorationRect.height;
35718
+ Object.assign(editorHost.style, {
35719
+ top: `${top2}px`,
35720
+ left: `${left2}px`,
35721
+ width: `${width}px`,
35722
+ height: `${height}px`
35723
+ });
35724
+ if (region.kind === "footer") {
35725
+ const fragment = decorationContainer.querySelector(".superdoc-fragment");
35726
+ if (fragment instanceof HTMLElement) {
35727
+ const fragmentTop = parseFloat(fragment.style.top) || 0;
35728
+ editorHost.dataset.contentOffset = String(fragmentTop);
35729
+ }
35730
+ }
35731
+ };
35732
+ /**
35733
+ * Shows a full-width border line at the bottom of the header or top of the footer.
35734
+ * This creates the MS Word style visual indicator spanning edge-to-edge of the page.
35735
+ */
35736
+ showHeaderFooterBorder_fn = function(pageElement, region, decorationContainer) {
35737
+ __privateMethod(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
35738
+ __privateSet(this, _borderLine, document.createElement("div"));
35739
+ __privateGet(this, _borderLine).className = "superdoc-header-footer-border";
35740
+ const decorationRect = decorationContainer.getBoundingClientRect();
35741
+ const pageRect = pageElement.getBoundingClientRect();
35742
+ const isHeader = region.kind === "header";
35743
+ const topPosition = isHeader ? decorationRect.bottom - pageRect.top : decorationRect.top - pageRect.top;
35744
+ Object.assign(__privateGet(this, _borderLine).style, {
35745
+ position: "absolute",
35746
+ left: "0",
35747
+ right: "0",
35748
+ top: `${topPosition}px`,
35749
+ height: BORDER_LINE_HEIGHT,
35750
+ backgroundColor: BORDER_LINE_COLOR,
35751
+ // MS Word blue
35752
+ zIndex: BORDER_LINE_Z_INDEX,
35753
+ pointerEvents: "none"
35754
+ });
35755
+ pageElement.appendChild(__privateGet(this, _borderLine));
35756
+ };
35757
+ /**
35758
+ * Hides and removes the header/footer border line.
35759
+ */
35760
+ hideHeaderFooterBorder_fn = function() {
35761
+ if (__privateGet(this, _borderLine)) {
35762
+ __privateGet(this, _borderLine).remove();
35763
+ __privateSet(this, _borderLine, null);
35764
+ }
35765
+ };
35058
35766
  const uiSurfaces = /* @__PURE__ */ new WeakSet();
35059
35767
  function isInRegisteredSurface(event) {
35060
35768
  const path = typeof event.composedPath === "function" ? event.composedPath() : [];
@@ -35093,7 +35801,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35093
35801
  __privateAdd(this, _visibleHost);
35094
35802
  __privateAdd(this, _viewportHost);
35095
35803
  __privateAdd(this, _painterHost);
35096
- __privateAdd(this, _selectionOverlay);
35804
+ __privateAdd(this, _selectionOverlay2);
35097
35805
  __privateAdd(this, _hiddenHost);
35098
35806
  __privateAdd(this, _layoutOptions);
35099
35807
  __privateAdd(this, _layoutState, { blocks: [], measures: [], layout: null });
@@ -35128,6 +35836,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35128
35836
  __privateAdd(this, _footerRegions, /* @__PURE__ */ new Map());
35129
35837
  __privateAdd(this, _session, { mode: "body" });
35130
35838
  __privateAdd(this, _activeHeaderFooterEditor, null);
35839
+ __privateAdd(this, _overlayManager, null);
35131
35840
  __privateAdd(this, _hoverOverlay, null);
35132
35841
  __privateAdd(this, _hoverTooltip, null);
35133
35842
  __privateAdd(this, _modeBanner, null);
@@ -35191,6 +35900,11 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35191
35900
  const x = (event.clientX - rect.left + scrollLeft) / zoom;
35192
35901
  const y = (event.clientY - rect.top + scrollTop) / zoom;
35193
35902
  if (__privateGet(this, _session).mode !== "body") {
35903
+ const activeEditorHost = __privateGet(this, _overlayManager)?.getActiveEditorHost?.();
35904
+ const clickedInsideEditorHost = activeEditorHost && (activeEditorHost.contains(event.target) || activeEditorHost === event.target);
35905
+ if (clickedInsideEditorHost) {
35906
+ return;
35907
+ }
35194
35908
  const headerFooterRegion2 = __privateMethod(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, x, y);
35195
35909
  if (!headerFooterRegion2) {
35196
35910
  __privateMethod(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -35345,6 +36059,11 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35345
36059
  if (region) {
35346
36060
  event.preventDefault();
35347
36061
  event.stopPropagation();
36062
+ const descriptor = __privateMethod(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
36063
+ if (!descriptor && __privateGet(this, _headerFooterManager)) {
36064
+ __privateMethod(this, _PresentationEditor_instances, createDefaultHeaderFooter_fn).call(this, region);
36065
+ __privateGet(this, _headerFooterManager).refresh();
36066
+ }
35348
36067
  __privateMethod(this, _PresentationEditor_instances, activateHeaderFooterRegion_fn).call(this, region);
35349
36068
  } else if (__privateGet(this, _session).mode !== "body") {
35350
36069
  __privateMethod(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -35413,13 +36132,13 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35413
36132
  __privateGet(this, _painterHost).className = "presentation-editor__pages";
35414
36133
  __privateGet(this, _painterHost).style.transformOrigin = "top left";
35415
36134
  __privateGet(this, _viewportHost).appendChild(__privateGet(this, _painterHost));
35416
- __privateSet(this, _selectionOverlay, doc2.createElement("div"));
35417
- __privateGet(this, _selectionOverlay).className = "presentation-editor__selection-overlay";
35418
- __privateGet(this, _selectionOverlay).id = `presentation-overlay-${options.documentId || "default"}`;
35419
- __privateGet(this, _selectionOverlay).style.position = "absolute";
35420
- __privateGet(this, _selectionOverlay).style.inset = "0";
35421
- __privateGet(this, _selectionOverlay).style.pointerEvents = "none";
35422
- __privateGet(this, _selectionOverlay).style.zIndex = "10";
36135
+ __privateSet(this, _selectionOverlay2, doc2.createElement("div"));
36136
+ __privateGet(this, _selectionOverlay2).className = "presentation-editor__selection-overlay";
36137
+ __privateGet(this, _selectionOverlay2).id = `presentation-overlay-${options.documentId || "default"}`;
36138
+ __privateGet(this, _selectionOverlay2).style.position = "absolute";
36139
+ __privateGet(this, _selectionOverlay2).style.inset = "0";
36140
+ __privateGet(this, _selectionOverlay2).style.pointerEvents = "none";
36141
+ __privateGet(this, _selectionOverlay2).style.zIndex = "10";
35423
36142
  __privateSet(this, _remoteCursorOverlay, doc2.createElement("div"));
35424
36143
  __privateGet(this, _remoteCursorOverlay).className = "presentation-editor__selection-layer--remote";
35425
36144
  __privateGet(this, _remoteCursorOverlay).style.position = "absolute";
@@ -35430,9 +36149,9 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35430
36149
  __privateGet(this, _localSelectionLayer).style.position = "absolute";
35431
36150
  __privateGet(this, _localSelectionLayer).style.inset = "0";
35432
36151
  __privateGet(this, _localSelectionLayer).style.pointerEvents = "none";
35433
- __privateGet(this, _selectionOverlay).appendChild(__privateGet(this, _remoteCursorOverlay));
35434
- __privateGet(this, _selectionOverlay).appendChild(__privateGet(this, _localSelectionLayer));
35435
- __privateGet(this, _viewportHost).appendChild(__privateGet(this, _selectionOverlay));
36152
+ __privateGet(this, _selectionOverlay2).appendChild(__privateGet(this, _remoteCursorOverlay));
36153
+ __privateGet(this, _selectionOverlay2).appendChild(__privateGet(this, _localSelectionLayer));
36154
+ __privateGet(this, _viewportHost).appendChild(__privateGet(this, _selectionOverlay2));
35436
36155
  __privateSet(this, _hoverOverlay, doc2.createElement("div"));
35437
36156
  __privateGet(this, _hoverOverlay).className = "presentation-editor__hover-overlay";
35438
36157
  Object.assign(__privateGet(this, _hoverOverlay).style, {
@@ -35443,7 +36162,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35443
36162
  display: "none",
35444
36163
  zIndex: "11"
35445
36164
  });
35446
- __privateGet(this, _selectionOverlay).appendChild(__privateGet(this, _hoverOverlay));
36165
+ __privateGet(this, _selectionOverlay2).appendChild(__privateGet(this, _hoverOverlay));
35447
36166
  __privateSet(this, _hoverTooltip, doc2.createElement("div"));
35448
36167
  __privateGet(this, _hoverTooltip).className = "presentation-editor__hover-tooltip";
35449
36168
  Object.assign(__privateGet(this, _hoverTooltip).style, {
@@ -35458,7 +36177,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35458
36177
  zIndex: "12",
35459
36178
  whiteSpace: "nowrap"
35460
36179
  });
35461
- __privateGet(this, _selectionOverlay).appendChild(__privateGet(this, _hoverTooltip));
36180
+ __privateGet(this, _selectionOverlay2).appendChild(__privateGet(this, _hoverTooltip));
35462
36181
  __privateSet(this, _modeBanner, doc2.createElement("div"));
35463
36182
  __privateGet(this, _modeBanner).className = "presentation-editor__mode-banner";
35464
36183
  Object.assign(__privateGet(this, _modeBanner).style, {
@@ -35676,7 +36395,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35676
36395
  * ```
35677
36396
  */
35678
36397
  get overlayElement() {
35679
- return __privateGet(this, _selectionOverlay) ?? null;
36398
+ return __privateGet(this, _selectionOverlay2) ?? null;
35680
36399
  }
35681
36400
  /**
35682
36401
  * Set the document mode and update editor editability.
@@ -35846,12 +36565,12 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
35846
36565
  * @returns Array of rects, each containing pageIndex and position data (left, top, right, bottom, width, height)
35847
36566
  */
35848
36567
  getRangeRects(from2, to, relativeTo) {
35849
- if (!__privateGet(this, _selectionOverlay)) return [];
36568
+ if (!__privateGet(this, _selectionOverlay2)) return [];
35850
36569
  if (!Number.isFinite(from2) || !Number.isFinite(to)) return [];
35851
36570
  const start2 = Math.min(from2, to);
35852
36571
  const end2 = Math.max(from2, to);
35853
36572
  const zoom = __privateGet(this, _layoutOptions).zoom ?? 1;
35854
- const overlayRect = __privateGet(this, _selectionOverlay).getBoundingClientRect();
36573
+ const overlayRect = __privateGet(this, _selectionOverlay2).getBoundingClientRect();
35855
36574
  const relativeRect = relativeTo?.getBoundingClientRect() ?? null;
35856
36575
  const layoutRectSource = () => {
35857
36576
  if (__privateGet(this, _session).mode !== "body") {
@@ -36112,7 +36831,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
36112
36831
  return null;
36113
36832
  }
36114
36833
  const rect2 = rects2[0];
36115
- const overlayRect = __privateGet(this, _selectionOverlay)?.getBoundingClientRect();
36834
+ const overlayRect = __privateGet(this, _selectionOverlay2)?.getBoundingClientRect();
36116
36835
  if (!overlayRect) {
36117
36836
  return null;
36118
36837
  }
@@ -36282,7 +37001,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
36282
37001
  __privateSet(this, _session, { mode: "body" });
36283
37002
  __privateSet(this, _activeHeaderFooterEditor, null);
36284
37003
  __privateSet(this, _domPainter, null);
36285
- __privateGet(this, _selectionOverlay)?.remove();
37004
+ __privateGet(this, _selectionOverlay2)?.remove();
36286
37005
  __privateGet(this, _painterHost)?.remove();
36287
37006
  __privateGet(this, _hiddenHost)?.remove();
36288
37007
  __privateSet(this, _hoverOverlay, null);
@@ -36304,7 +37023,7 @@ _editor3 = new WeakMap();
36304
37023
  _visibleHost = new WeakMap();
36305
37024
  _viewportHost = new WeakMap();
36306
37025
  _painterHost = new WeakMap();
36307
- _selectionOverlay = new WeakMap();
37026
+ _selectionOverlay2 = new WeakMap();
36308
37027
  _hiddenHost = new WeakMap();
36309
37028
  _layoutOptions = new WeakMap();
36310
37029
  _layoutState = new WeakMap();
@@ -36339,6 +37058,7 @@ _headerRegions = new WeakMap();
36339
37058
  _footerRegions = new WeakMap();
36340
37059
  _session = new WeakMap();
36341
37060
  _activeHeaderFooterEditor = new WeakMap();
37061
+ _overlayManager = new WeakMap();
36342
37062
  _hoverOverlay = new WeakMap();
36343
37063
  _hoverTooltip = new WeakMap();
36344
37064
  _modeBanner = new WeakMap();
@@ -36821,9 +37541,14 @@ initHeaderFooterRegistry_fn = function() {
36821
37541
  __privateSet(this, _headerFooterManagerCleanups, []);
36822
37542
  __privateGet(this, _headerFooterAdapter)?.clear();
36823
37543
  __privateGet(this, _headerFooterManager)?.destroy();
37544
+ __privateGet(this, _overlayManager)?.destroy();
36824
37545
  __privateSet(this, _session, { mode: "body" });
36825
37546
  __privateSet(this, _activeHeaderFooterEditor, null);
36826
37547
  __privateGet(this, _inputBridge)?.notifyTargetChanged();
37548
+ __privateSet(this, _overlayManager, new EditorOverlayManager(__privateGet(this, _painterHost), __privateGet(this, _visibleHost), __privateGet(this, _selectionOverlay2)));
37549
+ __privateGet(this, _overlayManager).setOnDimmingClick(() => {
37550
+ __privateMethod(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
37551
+ });
36827
37552
  const converter = __privateGet(this, _editor3).converter;
36828
37553
  __privateSet(this, _headerFooterIdentifier, extractIdentifierFromConverter(converter));
36829
37554
  __privateSet(this, _headerFooterManager, new HeaderFooterEditorManager(__privateGet(this, _editor3)));
@@ -37240,6 +37965,9 @@ scheduleSelectionUpdate_fn = function() {
37240
37965
  });
37241
37966
  };
37242
37967
  updateSelection_fn = function() {
37968
+ if (__privateGet(this, _session).mode !== "body") {
37969
+ return;
37970
+ }
37243
37971
  if (!__privateGet(this, _localSelectionLayer)) {
37244
37972
  return;
37245
37973
  }
@@ -37249,22 +37977,6 @@ updateSelection_fn = function() {
37249
37977
  if (!selection) {
37250
37978
  return;
37251
37979
  }
37252
- if (__privateGet(this, _session).mode !== "body") {
37253
- if (!layout) {
37254
- return;
37255
- }
37256
- if (selection.from === selection.to) {
37257
- const caretLayout = __privateMethod(this, _PresentationEditor_instances, computeHeaderFooterCaretRect_fn).call(this, selection.from);
37258
- if (!caretLayout) {
37259
- return;
37260
- }
37261
- __privateMethod(this, _PresentationEditor_instances, renderCaretOverlay_fn).call(this, caretLayout);
37262
- return;
37263
- }
37264
- const rects2 = __privateMethod(this, _PresentationEditor_instances, computeHeaderFooterSelectionRects_fn).call(this, selection.from, selection.to);
37265
- __privateMethod(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, rects2);
37266
- return;
37267
- }
37268
37980
  if (!layout) {
37269
37981
  return;
37270
37982
  }
@@ -37517,46 +38229,168 @@ activateHeaderFooterRegion_fn = function(region) {
37517
38229
  void __privateMethod(this, _PresentationEditor_instances, enterHeaderFooterMode_fn).call(this, region);
37518
38230
  };
37519
38231
  enterHeaderFooterMode_fn = async function(region) {
37520
- if (!__privateGet(this, _headerFooterManager)) {
37521
- __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
37522
- return;
37523
- }
37524
- const descriptor = __privateMethod(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
37525
- if (!descriptor) {
37526
- console.warn("[PresentationEditor] No descriptor found for region:", region);
37527
- __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
37528
- return;
37529
- }
37530
- if (!descriptor.id) {
37531
- console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
37532
- __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
37533
- return;
37534
- }
37535
- const editor = await __privateGet(this, _headerFooterManager).ensureEditor(descriptor);
37536
- if (!editor) {
37537
- console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
38232
+ try {
38233
+ if (!__privateGet(this, _headerFooterManager) || !__privateGet(this, _overlayManager)) {
38234
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38235
+ return;
38236
+ }
38237
+ const descriptor = __privateMethod(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
38238
+ if (!descriptor) {
38239
+ console.warn("[PresentationEditor] No descriptor found for region:", region);
38240
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38241
+ return;
38242
+ }
38243
+ if (!descriptor.id) {
38244
+ console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
38245
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38246
+ return;
38247
+ }
38248
+ let pageElement = __privateMethod(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
38249
+ if (!pageElement) {
38250
+ try {
38251
+ __privateMethod(this, _PresentationEditor_instances, scrollPageIntoView_fn).call(this, region.pageIndex);
38252
+ const mounted = await __privateMethod(this, _PresentationEditor_instances, waitForPageMount_fn).call(this, region.pageIndex, { timeout: 2e3 });
38253
+ if (!mounted) {
38254
+ console.error("[PresentationEditor] Failed to mount page for header/footer editing");
38255
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38256
+ this.emit("error", {
38257
+ error: new Error("Failed to mount page for editing"),
38258
+ context: "enterHeaderFooterMode"
38259
+ });
38260
+ return;
38261
+ }
38262
+ pageElement = __privateMethod(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
38263
+ } catch (scrollError) {
38264
+ console.error("[PresentationEditor] Error mounting page:", scrollError);
38265
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38266
+ this.emit("error", {
38267
+ error: scrollError,
38268
+ context: "enterHeaderFooterMode.pageMount"
38269
+ });
38270
+ return;
38271
+ }
38272
+ }
38273
+ if (!pageElement) {
38274
+ console.error("[PresentationEditor] Page element not found after mount attempt");
38275
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38276
+ this.emit("error", {
38277
+ error: new Error("Page element not found after mount"),
38278
+ context: "enterHeaderFooterMode"
38279
+ });
38280
+ return;
38281
+ }
38282
+ const { success, editorHost, reason } = __privateGet(this, _overlayManager).showEditingOverlay(
38283
+ pageElement,
38284
+ region,
38285
+ __privateGet(this, _layoutOptions).zoom ?? 1
38286
+ );
38287
+ if (!success || !editorHost) {
38288
+ console.error("[PresentationEditor] Failed to create editor host:", reason);
38289
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38290
+ this.emit("error", {
38291
+ error: new Error(`Failed to create editor host: ${reason}`),
38292
+ context: "enterHeaderFooterMode.showOverlay"
38293
+ });
38294
+ return;
38295
+ }
38296
+ const layout = __privateGet(this, _layoutState).layout;
38297
+ let editor;
38298
+ try {
38299
+ editor = await __privateGet(this, _headerFooterManager).ensureEditor(descriptor, {
38300
+ editorHost,
38301
+ availableWidth: region.width,
38302
+ availableHeight: region.height,
38303
+ currentPageNumber: region.pageNumber,
38304
+ totalPageCount: layout?.pages?.length ?? 1
38305
+ });
38306
+ } catch (editorError) {
38307
+ console.error("[PresentationEditor] Error creating editor:", editorError);
38308
+ __privateGet(this, _overlayManager).hideEditingOverlay();
38309
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38310
+ this.emit("error", {
38311
+ error: editorError,
38312
+ context: "enterHeaderFooterMode.ensureEditor"
38313
+ });
38314
+ return;
38315
+ }
38316
+ if (!editor) {
38317
+ console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
38318
+ __privateGet(this, _overlayManager).hideEditingOverlay();
38319
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38320
+ this.emit("error", {
38321
+ error: new Error("Failed to create editor instance"),
38322
+ context: "enterHeaderFooterMode.ensureEditor"
38323
+ });
38324
+ return;
38325
+ }
38326
+ try {
38327
+ editor.setEditable(true);
38328
+ editor.setOptions({ documentMode: "editing" });
38329
+ try {
38330
+ const doc2 = editor.state?.doc;
38331
+ if (doc2) {
38332
+ const endPos = doc2.content.size - 1;
38333
+ editor.commands?.setTextSelection?.(Math.max(1, endPos));
38334
+ }
38335
+ } catch (cursorError) {
38336
+ console.warn("[PresentationEditor] Could not set cursor to end:", cursorError);
38337
+ }
38338
+ } catch (editableError) {
38339
+ console.error("[PresentationEditor] Error setting editor editable:", editableError);
38340
+ __privateGet(this, _overlayManager).hideEditingOverlay();
38341
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38342
+ this.emit("error", {
38343
+ error: editableError,
38344
+ context: "enterHeaderFooterMode.setEditable"
38345
+ });
38346
+ return;
38347
+ }
38348
+ __privateGet(this, _overlayManager).hideSelectionOverlay();
38349
+ __privateSet(this, _activeHeaderFooterEditor, editor);
38350
+ __privateSet(this, _session, {
38351
+ mode: region.kind,
38352
+ kind: region.kind,
38353
+ headerId: descriptor.id,
38354
+ sectionType: descriptor.variant ?? region.sectionType ?? null,
38355
+ pageIndex: region.pageIndex,
38356
+ pageNumber: region.pageNumber
38357
+ });
37538
38358
  __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
37539
- return;
38359
+ try {
38360
+ editor.view?.focus();
38361
+ } catch (focusError) {
38362
+ console.warn("[PresentationEditor] Could not focus editor:", focusError);
38363
+ }
38364
+ __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
38365
+ __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
38366
+ __privateGet(this, _inputBridge)?.notifyTargetChanged();
38367
+ } catch (error) {
38368
+ console.error("[PresentationEditor] Unexpected error in enterHeaderFooterMode:", error);
38369
+ try {
38370
+ __privateGet(this, _overlayManager)?.hideEditingOverlay();
38371
+ __privateGet(this, _overlayManager)?.showSelectionOverlay();
38372
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
38373
+ __privateSet(this, _activeHeaderFooterEditor, null);
38374
+ __privateSet(this, _session, { mode: "body" });
38375
+ } catch (cleanupError) {
38376
+ console.error("[PresentationEditor] Error during cleanup:", cleanupError);
38377
+ }
38378
+ this.emit("error", {
38379
+ error,
38380
+ context: "enterHeaderFooterMode"
38381
+ });
37540
38382
  }
37541
- __privateSet(this, _activeHeaderFooterEditor, editor);
37542
- __privateSet(this, _session, {
37543
- mode: region.kind,
37544
- kind: region.kind,
37545
- headerId: descriptor.id,
37546
- sectionType: descriptor.variant ?? region.sectionType ?? null,
37547
- pageIndex: region.pageIndex,
37548
- pageNumber: region.pageNumber
37549
- });
37550
- __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
37551
- __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
37552
- __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
37553
- __privateGet(this, _inputBridge)?.notifyTargetChanged();
37554
- editor.view?.focus();
37555
38383
  };
37556
38384
  exitHeaderFooterMode_fn = function() {
37557
38385
  if (__privateGet(this, _session).mode === "body") return;
37558
- __privateSet(this, _session, { mode: "body" });
38386
+ if (__privateGet(this, _activeHeaderFooterEditor)) {
38387
+ __privateGet(this, _activeHeaderFooterEditor).setEditable(false);
38388
+ __privateGet(this, _activeHeaderFooterEditor).setOptions({ documentMode: "viewing" });
38389
+ }
38390
+ __privateGet(this, _overlayManager)?.hideEditingOverlay();
38391
+ __privateGet(this, _overlayManager)?.showSelectionOverlay();
37559
38392
  __privateSet(this, _activeHeaderFooterEditor, null);
38393
+ __privateSet(this, _session, { mode: "body" });
37560
38394
  __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
37561
38395
  __privateMethod(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, __privateGet(this, _editor3));
37562
38396
  __privateGet(this, _inputBridge)?.notifyTargetChanged();
@@ -37652,6 +38486,95 @@ resolveDescriptorForRegion_fn = function(region) {
37652
38486
  }
37653
38487
  return descriptors[0];
37654
38488
  };
38489
+ /**
38490
+ * Creates a default header or footer when none exists.
38491
+ *
38492
+ * This method is called when a user double-clicks a header/footer region
38493
+ * but no content exists yet. It uses the converter API to create an empty
38494
+ * header/footer document.
38495
+ *
38496
+ * @param region - The header/footer region to create content for
38497
+ */
38498
+ createDefaultHeaderFooter_fn = function(region) {
38499
+ const converter = __privateGet(this, _editor3).converter;
38500
+ if (!converter) {
38501
+ console.error("[PresentationEditor] Converter not available for creating header/footer");
38502
+ return;
38503
+ }
38504
+ const variant = region.sectionType ?? "default";
38505
+ try {
38506
+ if (region.kind === "header") {
38507
+ if (typeof converter.createDefaultHeader === "function") {
38508
+ const headerId = converter.createDefaultHeader(variant);
38509
+ console.log(`[PresentationEditor] Created default header: ${headerId}`);
38510
+ } else {
38511
+ console.error("[PresentationEditor] converter.createDefaultHeader is not a function");
38512
+ }
38513
+ } else if (region.kind === "footer") {
38514
+ if (typeof converter.createDefaultFooter === "function") {
38515
+ const footerId = converter.createDefaultFooter(variant);
38516
+ console.log(`[PresentationEditor] Created default footer: ${footerId}`);
38517
+ } else {
38518
+ console.error("[PresentationEditor] converter.createDefaultFooter is not a function");
38519
+ }
38520
+ }
38521
+ } catch (error) {
38522
+ console.error("[PresentationEditor] Failed to create default header/footer:", error);
38523
+ }
38524
+ };
38525
+ /**
38526
+ * Gets the DOM element for a specific page index.
38527
+ *
38528
+ * @param pageIndex - Zero-based page index
38529
+ * @returns The page element or null if not mounted
38530
+ */
38531
+ getPageElement_fn = function(pageIndex) {
38532
+ if (!__privateGet(this, _painterHost)) return null;
38533
+ const pageElements = __privateGet(this, _painterHost).querySelectorAll("[data-page-index]");
38534
+ for (let i = 0; i < pageElements.length; i++) {
38535
+ const el = pageElements[i];
38536
+ const dataPageIndex = el.getAttribute("data-page-index");
38537
+ if (dataPageIndex && parseInt(dataPageIndex, 10) === pageIndex) {
38538
+ return el;
38539
+ }
38540
+ }
38541
+ return null;
38542
+ };
38543
+ /**
38544
+ * Scrolls a page into view, triggering virtualization to mount it if needed.
38545
+ *
38546
+ * @param pageIndex - Zero-based page index to scroll to
38547
+ */
38548
+ scrollPageIntoView_fn = function(pageIndex) {
38549
+ const layout = __privateGet(this, _layoutState).layout;
38550
+ if (!layout) return;
38551
+ const pageHeight = layout.pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
38552
+ const virtualGap = __privateGet(this, _layoutOptions).virtualization?.gap ?? 0;
38553
+ const yPosition = pageIndex * (pageHeight + virtualGap);
38554
+ if (__privateGet(this, _visibleHost)) {
38555
+ __privateGet(this, _visibleHost).scrollTop = yPosition;
38556
+ }
38557
+ };
38558
+ waitForPageMount_fn = async function(pageIndex, options = {}) {
38559
+ const timeout2 = options.timeout ?? 2e3;
38560
+ const startTime = performance.now();
38561
+ return new Promise((resolve) => {
38562
+ const checkPage = () => {
38563
+ const pageElement = __privateMethod(this, _PresentationEditor_instances, getPageElement_fn).call(this, pageIndex);
38564
+ if (pageElement) {
38565
+ resolve(true);
38566
+ return;
38567
+ }
38568
+ const elapsed = performance.now() - startTime;
38569
+ if (elapsed >= timeout2) {
38570
+ resolve(false);
38571
+ return;
38572
+ }
38573
+ requestAnimationFrame(checkPage);
38574
+ };
38575
+ checkPage();
38576
+ });
38577
+ };
37655
38578
  getBodyPageHeight_fn = function() {
37656
38579
  return __privateGet(this, _layoutState).layout?.pageSize?.h ?? __privateGet(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
37657
38580
  };
@@ -37710,7 +38633,7 @@ renderHoverRegion_fn = function(region) {
37710
38633
  __privateGet(this, _hoverOverlay).style.top = `${coords.y}px`;
37711
38634
  __privateGet(this, _hoverOverlay).style.width = `${region.width * zoom}px`;
37712
38635
  __privateGet(this, _hoverOverlay).style.height = `${region.height * zoom}px`;
37713
- const tooltipText = `Double-click to edit ${region.kind === "header" ? "Header" : "Footer"} (${region.sectionType ?? "default"})`;
38636
+ const tooltipText = `Double-click to edit ${region.kind === "header" ? "header" : "footer"}`;
37714
38637
  __privateGet(this, _hoverTooltip).textContent = tooltipText;
37715
38638
  __privateGet(this, _hoverTooltip).style.display = "block";
37716
38639
  __privateGet(this, _hoverTooltip).style.left = `${coords.x}px`;
@@ -37816,33 +38739,6 @@ computeHeaderFooterSelectionRects_fn = function(from2, to) {
37816
38739
  };
37817
38740
  });
37818
38741
  };
37819
- computeHeaderFooterCaretRect_fn = function(pos) {
37820
- const context = __privateMethod(this, _PresentationEditor_instances, getHeaderFooterContext_fn).call(this);
37821
- if (!context) return null;
37822
- const hit = getFragmentAtPosition(context.layout, context.blocks, context.measures, pos);
37823
- if (!hit) return null;
37824
- const block = hit.block;
37825
- const measure = hit.measure;
37826
- if (!block || block.kind !== "paragraph" || measure?.kind !== "paragraph" || hit.fragment.kind !== "para")
37827
- return null;
37828
- const lineInfo = __privateMethod(this, _PresentationEditor_instances, findLineContainingPos_fn).call(this, block, measure, hit.fragment.fromLine, hit.fragment.toLine, pos);
37829
- if (!lineInfo) return null;
37830
- const { line, index: index2 } = lineInfo;
37831
- const range = computeLinePmRange$1(block, line);
37832
- if (range.pmStart == null || range.pmEnd == null) return null;
37833
- const pmCharsInLine = Math.max(1, range.pmEnd - range.pmStart);
37834
- const pmOffset = Math.max(0, Math.min(pmCharsInLine, pos - range.pmStart));
37835
- const localX = hit.fragment.x + measureCharacterX(block, line, pmOffset);
37836
- const lineOffset = __privateMethod(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, hit.fragment.fromLine, index2);
37837
- const headerPageHeight = context.layout.pageSize?.h ?? context.region.height ?? 1;
37838
- const headerLocalY = hit.pageIndex * headerPageHeight + (hit.fragment.y + lineOffset);
37839
- return {
37840
- pageIndex: context.region.pageIndex,
37841
- x: context.region.localX + localX,
37842
- y: context.region.localY + headerLocalY,
37843
- height: line.lineHeight
37844
- };
37845
- };
37846
38742
  syncTrackedChangesPreferences_fn = function() {
37847
38743
  const mode = __privateMethod(this, _PresentationEditor_instances, deriveTrackedChangesMode_fn).call(this);
37848
38744
  const enabled = __privateMethod(this, _PresentationEditor_instances, deriveTrackedChangesEnabled_fn).call(this);
@@ -37949,7 +38845,7 @@ convertPageLocalToOverlayCoords_fn = function(pageIndex, pageLocalX, pageLocalY)
37949
38845
  return null;
37950
38846
  }
37951
38847
  const pageRect = pageEl.getBoundingClientRect();
37952
- const overlayRect = __privateGet(this, _selectionOverlay).getBoundingClientRect();
38848
+ const overlayRect = __privateGet(this, _selectionOverlay2).getBoundingClientRect();
37953
38849
  const zoom = __privateGet(this, _layoutOptions).zoom ?? 1;
37954
38850
  return {
37955
38851
  x: pageRect.left - overlayRect.left + pageLocalX * zoom,
@@ -42963,22 +43859,53 @@ function calculateTabLayout(request, measurement, view) {
42963
43859
  tabs
42964
43860
  };
42965
43861
  }
43862
+ const MAX_WALK_DEPTH = 50;
42966
43863
  function applyLayoutResult(result, paragraph, paragraphPos) {
42967
43864
  const decorations = [];
42968
43865
  let tabIndex = 0;
42969
- paragraph.forEach((node, offset2) => {
42970
- if (node.type.name !== "tab") return;
42971
- const pos = paragraphPos + offset2 + 1;
42972
- const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
42973
- const layout = result.tabs[tabId];
42974
- if (!layout) return;
42975
- let style = `width: ${layout.width}px;`;
42976
- if (layout.height) style += ` height: ${layout.height};`;
42977
- if (layout.leader && leaderStyles[layout.leader]) {
42978
- style += ` ${leaderStyles[layout.leader]}`;
42979
- }
42980
- decorations.push(Decoration.node(pos, pos + node.nodeSize, { style }));
42981
- });
43866
+ const walk = (node, pos, depth = 0) => {
43867
+ if (depth > MAX_WALK_DEPTH) {
43868
+ console.error(`applyLayoutResult: Maximum recursion depth (${MAX_WALK_DEPTH}) exceeded`);
43869
+ return;
43870
+ }
43871
+ if (!node?.type?.name) {
43872
+ console.error("applyLayoutResult: Node missing type.name", { node, pos, depth });
43873
+ return;
43874
+ }
43875
+ if (typeof node.nodeSize !== "number" || node.nodeSize < 0 || !Number.isFinite(node.nodeSize)) {
43876
+ console.error("applyLayoutResult: Invalid nodeSize", { nodeSize: node.nodeSize, nodeName: node.type.name, pos });
43877
+ return;
43878
+ }
43879
+ if (node.type.name === "tab") {
43880
+ const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
43881
+ const layout = result.tabs[tabId];
43882
+ if (layout) {
43883
+ let style = `width: ${layout.width}px;`;
43884
+ if (layout.height) style += ` height: ${layout.height};`;
43885
+ if (layout.leader && leaderStyles[layout.leader]) {
43886
+ style += ` ${leaderStyles[layout.leader]}`;
43887
+ }
43888
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, { style }));
43889
+ }
43890
+ return;
43891
+ }
43892
+ try {
43893
+ let offset2 = 0;
43894
+ node.forEach((child) => {
43895
+ const childPos = pos + 1 + offset2;
43896
+ walk(child, childPos, depth + 1);
43897
+ offset2 += child.nodeSize;
43898
+ });
43899
+ } catch (error) {
43900
+ console.error("applyLayoutResult: Error during recursion", {
43901
+ error,
43902
+ nodeName: node.type.name,
43903
+ pos,
43904
+ depth
43905
+ });
43906
+ }
43907
+ };
43908
+ walk(paragraph, paragraphPos);
42982
43909
  return decorations;
42983
43910
  }
42984
43911
  function collectFollowingText(spans, startIndex) {
@@ -43526,8 +44453,8 @@ const createColGroup = (node, cellMinWidth, overrideCol, overrideValue) => {
43526
44453
  colgroupValues
43527
44454
  };
43528
44455
  };
43529
- var readFromCache;
43530
- var addToCache;
44456
+ let readFromCache;
44457
+ let addToCache;
43531
44458
  if (typeof WeakMap != "undefined") {
43532
44459
  let cache2 = /* @__PURE__ */ new WeakMap();
43533
44460
  readFromCache = (key2) => cache2.get(key2);
@@ -43540,8 +44467,7 @@ if (typeof WeakMap != "undefined") {
43540
44467
  const cacheSize = 10;
43541
44468
  let cachePos = 0;
43542
44469
  readFromCache = (key2) => {
43543
- for (let i = 0; i < cache2.length; i += 2)
43544
- if (cache2[i] == key2) return cache2[i + 1];
44470
+ for (let i = 0; i < cache2.length; i += 2) if (cache2[i] == key2) return cache2[i + 1];
43545
44471
  };
43546
44472
  addToCache = (key2, value) => {
43547
44473
  if (cachePos == cacheSize) cachePos = 0;
@@ -43556,7 +44482,6 @@ var TableMap = class {
43556
44482
  this.map = map2;
43557
44483
  this.problems = problems;
43558
44484
  }
43559
- // Find the dimensions of the cell at the given position.
43560
44485
  findCell(pos) {
43561
44486
  for (let i = 0; i < this.map.length; i++) {
43562
44487
  const curPos = this.map[i];
@@ -43565,27 +44490,21 @@ var TableMap = class {
43565
44490
  const top2 = i / this.width | 0;
43566
44491
  let right2 = left2 + 1;
43567
44492
  let bottom2 = top2 + 1;
43568
- for (let j = 1; right2 < this.width && this.map[i + j] == curPos; j++) {
43569
- right2++;
43570
- }
43571
- for (let j = 1; bottom2 < this.height && this.map[i + this.width * j] == curPos; j++) {
43572
- bottom2++;
43573
- }
43574
- return { left: left2, top: top2, right: right2, bottom: bottom2 };
44493
+ for (let j = 1; right2 < this.width && this.map[i + j] == curPos; j++) right2++;
44494
+ for (let j = 1; bottom2 < this.height && this.map[i + this.width * j] == curPos; j++) bottom2++;
44495
+ return {
44496
+ left: left2,
44497
+ top: top2,
44498
+ right: right2,
44499
+ bottom: bottom2
44500
+ };
43575
44501
  }
43576
44502
  throw new RangeError(`No cell with offset ${pos} found`);
43577
44503
  }
43578
- // Find the left side of the cell at the given position.
43579
44504
  colCount(pos) {
43580
- for (let i = 0; i < this.map.length; i++) {
43581
- if (this.map[i] == pos) {
43582
- return i % this.width;
43583
- }
43584
- }
44505
+ for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
43585
44506
  throw new RangeError(`No cell with offset ${pos} found`);
43586
44507
  }
43587
- // Find the next cell in the given direction, starting from the cell
43588
- // at `pos`, if any.
43589
44508
  nextCell(pos, axis, dir) {
43590
44509
  const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
43591
44510
  if (axis == "horiz") {
@@ -43596,20 +44515,9 @@ var TableMap = class {
43596
44515
  return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
43597
44516
  }
43598
44517
  }
43599
- // Get the rectangle spanning the two given cells.
43600
44518
  rectBetween(a, b) {
43601
- const {
43602
- left: leftA,
43603
- right: rightA,
43604
- top: topA,
43605
- bottom: bottomA
43606
- } = this.findCell(a);
43607
- const {
43608
- left: leftB,
43609
- right: rightB,
43610
- top: topB,
43611
- bottom: bottomB
43612
- } = this.findCell(b);
44519
+ const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
44520
+ const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b);
43613
44521
  return {
43614
44522
  left: Math.min(leftA, leftB),
43615
44523
  top: Math.min(topA, topB),
@@ -43617,27 +44525,19 @@ var TableMap = class {
43617
44525
  bottom: Math.max(bottomA, bottomB)
43618
44526
  };
43619
44527
  }
43620
- // Return the position of all cells that have the top left corner in
43621
- // the given rectangle.
43622
44528
  cellsInRect(rect) {
43623
44529
  const result = [];
43624
44530
  const seen = {};
43625
- for (let row = rect.top; row < rect.bottom; row++) {
43626
- for (let col = rect.left; col < rect.right; col++) {
43627
- const index2 = row * this.width + col;
43628
- const pos = this.map[index2];
43629
- if (seen[pos]) continue;
43630
- seen[pos] = true;
43631
- if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) {
43632
- continue;
43633
- }
43634
- result.push(pos);
43635
- }
44531
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
44532
+ const index2 = row * this.width + col;
44533
+ const pos = this.map[index2];
44534
+ if (seen[pos]) continue;
44535
+ seen[pos] = true;
44536
+ if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) continue;
44537
+ result.push(pos);
43636
44538
  }
43637
44539
  return result;
43638
44540
  }
43639
- // Return the position at which the cell at the given row and column
43640
- // starts, or would start, if a cell started there.
43641
44541
  positionAt(row, col, table) {
43642
44542
  for (let i = 0, rowStart = 0; ; i++) {
43643
44543
  const rowEnd = rowStart + table.child(i).nodeSize;
@@ -43650,14 +44550,12 @@ var TableMap = class {
43650
44550
  rowStart = rowEnd;
43651
44551
  }
43652
44552
  }
43653
- // Find the table map for the given table node.
43654
44553
  static get(table) {
43655
44554
  return readFromCache(table) || addToCache(table, computeMap(table));
43656
44555
  }
43657
44556
  };
43658
44557
  function computeMap(table) {
43659
- if (table.type.spec.tableRole != "table")
43660
- throw new RangeError("Not a table node: " + table.type.name);
44558
+ if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
43661
44559
  const width = findWidth(table), height = table.childCount;
43662
44560
  const map2 = [];
43663
44561
  let mapPos = 0;
@@ -43684,22 +44582,19 @@ function computeMap(table) {
43684
44582
  const start2 = mapPos + h * width;
43685
44583
  for (let w = 0; w < colspan; w++) {
43686
44584
  if (map2[start2 + w] == 0) map2[start2 + w] = pos;
43687
- else
43688
- (problems || (problems = [])).push({
43689
- type: "collision",
43690
- row,
43691
- pos,
43692
- n: colspan - w
43693
- });
44585
+ else (problems || (problems = [])).push({
44586
+ type: "collision",
44587
+ row,
44588
+ pos,
44589
+ n: colspan - w
44590
+ });
43694
44591
  const colW = colwidth && colwidth[w];
43695
44592
  if (colW) {
43696
44593
  const widthIndex = (start2 + w) % width * 2, prev = colWidths[widthIndex];
43697
44594
  if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
43698
44595
  colWidths[widthIndex] = colW;
43699
44596
  colWidths[widthIndex + 1] = 1;
43700
- } else if (prev == colW) {
43701
- colWidths[widthIndex + 1]++;
43702
- }
44597
+ } else if (prev == colW) colWidths[widthIndex + 1]++;
43703
44598
  }
43704
44599
  }
43705
44600
  }
@@ -43709,16 +44604,17 @@ function computeMap(table) {
43709
44604
  const expectedPos = (row + 1) * width;
43710
44605
  let missing = 0;
43711
44606
  while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++;
43712
- if (missing)
43713
- (problems || (problems = [])).push({ type: "missing", row, n: missing });
44607
+ if (missing) (problems || (problems = [])).push({
44608
+ type: "missing",
44609
+ row,
44610
+ n: missing
44611
+ });
43714
44612
  pos++;
43715
44613
  }
43716
- if (width === 0 || height === 0)
43717
- (problems || (problems = [])).push({ type: "zero_sized" });
44614
+ if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
43718
44615
  const tableMap = new TableMap(width, height, map2, problems);
43719
44616
  let badWidths = false;
43720
- for (let i = 0; !badWidths && i < colWidths.length; i += 2)
43721
- if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
44617
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
43722
44618
  if (badWidths) findBadColWidths(tableMap, colWidths, table);
43723
44619
  return tableMap;
43724
44620
  }
@@ -43728,14 +44624,13 @@ function findWidth(table) {
43728
44624
  for (let row = 0; row < table.childCount; row++) {
43729
44625
  const rowNode = table.child(row);
43730
44626
  let rowWidth = 0;
43731
- if (hasRowSpan)
43732
- for (let j = 0; j < row; j++) {
43733
- const prevRow = table.child(j);
43734
- for (let i = 0; i < prevRow.childCount; i++) {
43735
- const cell = prevRow.child(i);
43736
- if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
43737
- }
44627
+ if (hasRowSpan) for (let j = 0; j < row; j++) {
44628
+ const prevRow = table.child(j);
44629
+ for (let i = 0; i < prevRow.childCount; i++) {
44630
+ const cell = prevRow.child(i);
44631
+ if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
43738
44632
  }
44633
+ }
43739
44634
  for (let i = 0; i < rowNode.childCount; i++) {
43740
44635
  const cell = rowNode.child(i);
43741
44636
  rowWidth += cell.attrs.colspan;
@@ -43754,23 +44649,18 @@ function findBadColWidths(map2, colWidths, table) {
43754
44649
  if (seen[pos]) continue;
43755
44650
  seen[pos] = true;
43756
44651
  const node = table.nodeAt(pos);
43757
- if (!node) {
43758
- throw new RangeError(`No cell with offset ${pos} found`);
43759
- }
44652
+ if (!node) throw new RangeError(`No cell with offset ${pos} found`);
43760
44653
  let updated = null;
43761
44654
  const attrs = node.attrs;
43762
44655
  for (let j = 0; j < attrs.colspan; j++) {
43763
- const col = (i + j) % map2.width;
43764
- const colWidth = colWidths[col * 2];
43765
- if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))
43766
- (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
43767
- }
43768
- if (updated)
43769
- map2.problems.unshift({
43770
- type: "colwidth mismatch",
43771
- pos,
43772
- colwidth: updated
43773
- });
44656
+ const colWidth = colWidths[(i + j) % map2.width * 2];
44657
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
44658
+ }
44659
+ if (updated) map2.problems.unshift({
44660
+ type: "colwidth mismatch",
44661
+ pos,
44662
+ colwidth: updated
44663
+ });
43774
44664
  }
43775
44665
  }
43776
44666
  function freshColWidth(attrs) {
@@ -43790,11 +44680,9 @@ function tableNodeTypes(schema) {
43790
44680
  }
43791
44681
  return result;
43792
44682
  }
43793
- var tableEditingKey = new PluginKey("selectingCells");
44683
+ const tableEditingKey = new PluginKey("selectingCells");
43794
44684
  function cellAround$1($pos) {
43795
- for (let d2 = $pos.depth - 1; d2 > 0; d2--)
43796
- if ($pos.node(d2).type.spec.tableRole == "row")
43797
- return $pos.node(0).resolve($pos.before(d2 + 1));
44685
+ 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));
43798
44686
  return null;
43799
44687
  }
43800
44688
  function cellWrapping$1($pos) {
@@ -43806,21 +44694,15 @@ function cellWrapping$1($pos) {
43806
44694
  }
43807
44695
  function isInTable(state) {
43808
44696
  const $head = state.selection.$head;
43809
- for (let d2 = $head.depth; d2 > 0; d2--)
43810
- if ($head.node(d2).type.spec.tableRole == "row") return true;
44697
+ for (let d2 = $head.depth; d2 > 0; d2--) if ($head.node(d2).type.spec.tableRole == "row") return true;
43811
44698
  return false;
43812
44699
  }
43813
44700
  function selectionCell(state) {
43814
44701
  const sel = state.selection;
43815
- if ("$anchorCell" in sel && sel.$anchorCell) {
43816
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
43817
- } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
43818
- return sel.$anchor;
43819
- }
44702
+ if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
44703
+ else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
43820
44704
  const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
43821
- if ($cell) {
43822
- return $cell;
43823
- }
44705
+ if ($cell) return $cell;
43824
44706
  throw new RangeError(`No cell found around position ${sel.head}`);
43825
44707
  }
43826
44708
  function cellNear($pos) {
@@ -43830,8 +44712,7 @@ function cellNear($pos) {
43830
44712
  }
43831
44713
  for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
43832
44714
  const role = before.type.spec.tableRole;
43833
- if (role == "cell" || role == "header_cell")
43834
- return $pos.doc.resolve(pos - before.nodeSize);
44715
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
43835
44716
  }
43836
44717
  }
43837
44718
  function pointsAtCell($pos) {
@@ -43851,7 +44732,10 @@ function nextCell($pos, axis, dir) {
43851
44732
  return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
43852
44733
  }
43853
44734
  function removeColSpan(attrs, pos, n = 1) {
43854
- const result = { ...attrs, colspan: attrs.colspan - n };
44735
+ const result = {
44736
+ ...attrs,
44737
+ colspan: attrs.colspan - n
44738
+ };
43855
44739
  if (result.colwidth) {
43856
44740
  result.colwidth = result.colwidth.slice();
43857
44741
  result.colwidth.splice(pos, n);
@@ -43860,7 +44744,10 @@ function removeColSpan(attrs, pos, n = 1) {
43860
44744
  return result;
43861
44745
  }
43862
44746
  function addColSpan(attrs, pos, n = 1) {
43863
- const result = { ...attrs, colspan: attrs.colspan + n };
44747
+ const result = {
44748
+ ...attrs,
44749
+ colspan: attrs.colspan + n
44750
+ };
43864
44751
  if (result.colwidth) {
43865
44752
  result.colwidth = result.colwidth.slice();
43866
44753
  for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
@@ -43869,37 +44756,23 @@ function addColSpan(attrs, pos, n = 1) {
43869
44756
  }
43870
44757
  function columnIsHeader(map2, table, col) {
43871
44758
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
43872
- for (let row = 0; row < map2.height; row++)
43873
- if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell)
43874
- return false;
44759
+ for (let row = 0; row < map2.height; row++) if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell) return false;
43875
44760
  return true;
43876
44761
  }
43877
- var CellSelection = class _CellSelection extends Selection {
43878
- // A table selection is identified by its anchor and head cells. The
43879
- // positions given to this constructor should point _before_ two
43880
- // cells in the same table. They may be the same, to select a single
43881
- // cell.
44762
+ var CellSelection = class CellSelection2 extends Selection {
43882
44763
  constructor($anchorCell, $headCell = $anchorCell) {
43883
44764
  const table = $anchorCell.node(-1);
43884
44765
  const map2 = TableMap.get(table);
43885
44766
  const tableStart = $anchorCell.start(-1);
43886
- const rect = map2.rectBetween(
43887
- $anchorCell.pos - tableStart,
43888
- $headCell.pos - tableStart
43889
- );
44767
+ const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
43890
44768
  const doc2 = $anchorCell.node(0);
43891
44769
  const cells = map2.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
43892
44770
  cells.unshift($headCell.pos - tableStart);
43893
44771
  const ranges = cells.map((pos) => {
43894
44772
  const cell = table.nodeAt(pos);
43895
- if (!cell) {
43896
- throw RangeError(`No cell with offset ${pos} found`);
43897
- }
44773
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
43898
44774
  const from2 = tableStart + pos + 1;
43899
- return new SelectionRange(
43900
- doc2.resolve(from2),
43901
- doc2.resolve(from2 + cell.content.size)
43902
- );
44775
+ return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size));
43903
44776
  });
43904
44777
  super(ranges[0].$from, ranges[0].$to, ranges);
43905
44778
  this.$anchorCell = $anchorCell;
@@ -43910,24 +44783,17 @@ var CellSelection = class _CellSelection extends Selection {
43910
44783
  const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
43911
44784
  if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
43912
44785
  const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
43913
- if (tableChanged && this.isRowSelection())
43914
- return _CellSelection.rowSelection($anchorCell, $headCell);
43915
- else if (tableChanged && this.isColSelection())
43916
- return _CellSelection.colSelection($anchorCell, $headCell);
43917
- else return new _CellSelection($anchorCell, $headCell);
44786
+ if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell);
44787
+ else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell);
44788
+ else return new CellSelection2($anchorCell, $headCell);
43918
44789
  }
43919
44790
  return TextSelection.between($anchorCell, $headCell);
43920
44791
  }
43921
- // Returns a rectangular slice of table rows containing the selected
43922
- // cells.
43923
44792
  content() {
43924
44793
  const table = this.$anchorCell.node(-1);
43925
44794
  const map2 = TableMap.get(table);
43926
44795
  const tableStart = this.$anchorCell.start(-1);
43927
- const rect = map2.rectBetween(
43928
- this.$anchorCell.pos - tableStart,
43929
- this.$headCell.pos - tableStart
43930
- );
44796
+ const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
43931
44797
  const seen = {};
43932
44798
  const rows = [];
43933
44799
  for (let row = rect.top; row < rect.bottom; row++) {
@@ -43938,44 +44804,25 @@ var CellSelection = class _CellSelection extends Selection {
43938
44804
  seen[pos] = true;
43939
44805
  const cellRect = map2.findCell(pos);
43940
44806
  let cell = table.nodeAt(pos);
43941
- if (!cell) {
43942
- throw RangeError(`No cell with offset ${pos} found`);
43943
- }
44807
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
43944
44808
  const extraLeft = rect.left - cellRect.left;
43945
44809
  const extraRight = cellRect.right - rect.right;
43946
44810
  if (extraLeft > 0 || extraRight > 0) {
43947
44811
  let attrs = cell.attrs;
43948
- if (extraLeft > 0) {
43949
- attrs = removeColSpan(attrs, 0, extraLeft);
43950
- }
43951
- if (extraRight > 0) {
43952
- attrs = removeColSpan(
43953
- attrs,
43954
- attrs.colspan - extraRight,
43955
- extraRight
43956
- );
43957
- }
44812
+ if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
44813
+ if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
43958
44814
  if (cellRect.left < rect.left) {
43959
44815
  cell = cell.type.createAndFill(attrs);
43960
- if (!cell) {
43961
- throw RangeError(
43962
- `Could not create cell with attrs ${JSON.stringify(attrs)}`
43963
- );
43964
- }
43965
- } else {
43966
- cell = cell.type.create(attrs, cell.content);
43967
- }
44816
+ if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
44817
+ } else cell = cell.type.create(attrs, cell.content);
43968
44818
  }
43969
44819
  if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
43970
44820
  const attrs = {
43971
44821
  ...cell.attrs,
43972
44822
  rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
43973
44823
  };
43974
- if (cellRect.top < rect.top) {
43975
- cell = cell.type.createAndFill(attrs);
43976
- } else {
43977
- cell = cell.type.create(attrs, cell.content);
43978
- }
44824
+ if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
44825
+ else cell = cell.type.create(attrs, cell.content);
43979
44826
  }
43980
44827
  rowContent.push(cell);
43981
44828
  }
@@ -43988,16 +44835,9 @@ var CellSelection = class _CellSelection extends Selection {
43988
44835
  const mapFrom = tr.steps.length, ranges = this.ranges;
43989
44836
  for (let i = 0; i < ranges.length; i++) {
43990
44837
  const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
43991
- tr.replace(
43992
- mapping.map($from.pos),
43993
- mapping.map($to.pos),
43994
- i ? Slice.empty : content
43995
- );
44838
+ tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
43996
44839
  }
43997
- const sel = Selection.findFrom(
43998
- tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
43999
- -1
44000
- );
44840
+ const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
44001
44841
  if (sel) tr.setSelection(sel);
44002
44842
  }
44003
44843
  replaceWith(tr, node) {
@@ -44007,18 +44847,9 @@ var CellSelection = class _CellSelection extends Selection {
44007
44847
  const table = this.$anchorCell.node(-1);
44008
44848
  const map2 = TableMap.get(table);
44009
44849
  const tableStart = this.$anchorCell.start(-1);
44010
- const cells = map2.cellsInRect(
44011
- map2.rectBetween(
44012
- this.$anchorCell.pos - tableStart,
44013
- this.$headCell.pos - tableStart
44014
- )
44015
- );
44016
- for (let i = 0; i < cells.length; i++) {
44017
- f2(table.nodeAt(cells[i]), tableStart + cells[i]);
44018
- }
44850
+ const cells = map2.cellsInRect(map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
44851
+ for (let i = 0; i < cells.length; i++) f2(table.nodeAt(cells[i]), tableStart + cells[i]);
44019
44852
  }
44020
- // True if this selection goes all the way from the top to the
44021
- // bottom of the table.
44022
44853
  isColSelection() {
44023
44854
  const anchorTop = this.$anchorCell.index(-1);
44024
44855
  const headTop = this.$headCell.index(-1);
@@ -44027,8 +44858,6 @@ var CellSelection = class _CellSelection extends Selection {
44027
44858
  const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
44028
44859
  return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
44029
44860
  }
44030
- // Returns the smallest column selection that covers the given anchor
44031
- // and head cell.
44032
44861
  static colSelection($anchorCell, $headCell = $anchorCell) {
44033
44862
  const table = $anchorCell.node(-1);
44034
44863
  const map2 = TableMap.get(table);
@@ -44037,24 +44866,14 @@ var CellSelection = class _CellSelection extends Selection {
44037
44866
  const headRect = map2.findCell($headCell.pos - tableStart);
44038
44867
  const doc2 = $anchorCell.node(0);
44039
44868
  if (anchorRect.top <= headRect.top) {
44040
- if (anchorRect.top > 0)
44041
- $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
44042
- if (headRect.bottom < map2.height)
44043
- $headCell = doc2.resolve(
44044
- tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]
44045
- );
44869
+ if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]);
44870
+ if (headRect.bottom < map2.height) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]);
44046
44871
  } else {
44047
- if (headRect.top > 0)
44048
- $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
44049
- if (anchorRect.bottom < map2.height)
44050
- $anchorCell = doc2.resolve(
44051
- tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]
44052
- );
44872
+ if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.left]);
44873
+ if (anchorRect.bottom < map2.height) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]);
44053
44874
  }
44054
- return new _CellSelection($anchorCell, $headCell);
44875
+ return new CellSelection2($anchorCell, $headCell);
44055
44876
  }
44056
- // True if this selection goes all the way from the left to the
44057
- // right of the table.
44058
44877
  isRowSelection() {
44059
44878
  const table = this.$anchorCell.node(-1);
44060
44879
  const map2 = TableMap.get(table);
@@ -44067,10 +44886,8 @@ var CellSelection = class _CellSelection extends Selection {
44067
44886
  return Math.max(anchorRight, headRight) == map2.width;
44068
44887
  }
44069
44888
  eq(other) {
44070
- return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
44889
+ return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
44071
44890
  }
44072
- // Returns the smallest row selection that covers the given anchor
44073
- // and head cell.
44074
44891
  static rowSelection($anchorCell, $headCell = $anchorCell) {
44075
44892
  const table = $anchorCell.node(-1);
44076
44893
  const map2 = TableMap.get(table);
@@ -44079,23 +44896,13 @@ var CellSelection = class _CellSelection extends Selection {
44079
44896
  const headRect = map2.findCell($headCell.pos - tableStart);
44080
44897
  const doc2 = $anchorCell.node(0);
44081
44898
  if (anchorRect.left <= headRect.left) {
44082
- if (anchorRect.left > 0)
44083
- $anchorCell = doc2.resolve(
44084
- tableStart + map2.map[anchorRect.top * map2.width]
44085
- );
44086
- if (headRect.right < map2.width)
44087
- $headCell = doc2.resolve(
44088
- tableStart + map2.map[map2.width * (headRect.top + 1) - 1]
44089
- );
44899
+ if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.top * map2.width]);
44900
+ if (headRect.right < map2.width) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (headRect.top + 1) - 1]);
44090
44901
  } else {
44091
- if (headRect.left > 0)
44092
- $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
44093
- if (anchorRect.right < map2.width)
44094
- $anchorCell = doc2.resolve(
44095
- tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]
44096
- );
44902
+ if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]);
44903
+ if (anchorRect.right < map2.width) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]);
44097
44904
  }
44098
- return new _CellSelection($anchorCell, $headCell);
44905
+ return new CellSelection2($anchorCell, $headCell);
44099
44906
  }
44100
44907
  toJSON() {
44101
44908
  return {
@@ -44105,10 +44912,10 @@ var CellSelection = class _CellSelection extends Selection {
44105
44912
  };
44106
44913
  }
44107
44914
  static fromJSON(doc2, json) {
44108
- return new _CellSelection(doc2.resolve(json.anchor), doc2.resolve(json.head));
44915
+ return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
44109
44916
  }
44110
44917
  static create(doc2, anchorCell, headCell = anchorCell) {
44111
- return new _CellSelection(doc2.resolve(anchorCell), doc2.resolve(headCell));
44918
+ return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
44112
44919
  }
44113
44920
  getBookmark() {
44114
44921
  return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
@@ -44116,18 +44923,17 @@ var CellSelection = class _CellSelection extends Selection {
44116
44923
  };
44117
44924
  CellSelection.prototype.visible = false;
44118
44925
  Selection.jsonID("cell", CellSelection);
44119
- var CellBookmark = class _CellBookmark {
44926
+ var CellBookmark = class CellBookmark2 {
44120
44927
  constructor(anchor, head) {
44121
44928
  this.anchor = anchor;
44122
44929
  this.head = head;
44123
44930
  }
44124
44931
  map(mapping) {
44125
- return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
44932
+ return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
44126
44933
  }
44127
44934
  resolve(doc2) {
44128
44935
  const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
44129
- 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))
44130
- return new CellSelection($anchorCell, $headCell);
44936
+ 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);
44131
44937
  else return Selection.near($headCell, 1);
44132
44938
  }
44133
44939
  };
@@ -44135,9 +44941,7 @@ function drawCellSelection(state) {
44135
44941
  if (!(state.selection instanceof CellSelection)) return null;
44136
44942
  const cells = [];
44137
44943
  state.selection.forEachCell((node, pos) => {
44138
- cells.push(
44139
- Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
44140
- );
44944
+ cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
44141
44945
  });
44142
44946
  return DecorationSet.create(state.doc, cells);
44143
44947
  }
@@ -44146,10 +44950,8 @@ function isCellBoundarySelection({ $from, $to }) {
44146
44950
  let afterFrom = $from.pos;
44147
44951
  let beforeTo = $to.pos;
44148
44952
  let depth = $from.depth;
44149
- for (; depth >= 0; depth--, afterFrom++)
44150
- if ($from.after(depth + 1) < $from.end(depth)) break;
44151
- for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
44152
- if ($to.before(d2 + 1) > $to.start(d2)) break;
44953
+ for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
44954
+ for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--) if ($to.before(d2 + 1) > $to.start(d2)) break;
44153
44955
  return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
44154
44956
  }
44155
44957
  function isTextSelectionAcrossCells({ $from, $to }) {
@@ -44177,9 +44979,8 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
44177
44979
  let normalize2;
44178
44980
  let role;
44179
44981
  if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
44180
- if (role == "cell" || role == "header_cell") {
44181
- normalize2 = CellSelection.create(doc2, sel.from);
44182
- } else if (role == "row") {
44982
+ if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
44983
+ else if (role == "row") {
44183
44984
  const $cell = doc2.resolve(sel.from + 1);
44184
44985
  normalize2 = CellSelection.rowSelection($cell, $cell);
44185
44986
  } else if (!allowTableNodeSelection) {
@@ -44188,29 +44989,23 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
44188
44989
  const lastCell = start2 + map2.map[map2.width * map2.height - 1];
44189
44990
  normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
44190
44991
  }
44191
- } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
44192
- normalize2 = TextSelection.create(doc2, sel.from);
44193
- } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
44194
- normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
44195
- }
44992
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize2 = TextSelection.create(doc2, sel.from);
44993
+ else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end());
44196
44994
  if (normalize2) (tr || (tr = state.tr)).setSelection(normalize2);
44197
44995
  return tr;
44198
44996
  }
44199
- var fixTablesKey = new PluginKey("fix-tables");
44997
+ const fixTablesKey = new PluginKey("fix-tables");
44200
44998
  function changedDescendants(old, cur, offset2, f2) {
44201
44999
  const oldSize = old.childCount, curSize = cur.childCount;
44202
45000
  outer: for (let i = 0, j = 0; i < curSize; i++) {
44203
45001
  const child = cur.child(i);
44204
- for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
44205
- if (old.child(scan) == child) {
44206
- j = scan + 1;
44207
- offset2 += child.nodeSize;
44208
- continue outer;
44209
- }
45002
+ for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {
45003
+ j = scan + 1;
45004
+ offset2 += child.nodeSize;
45005
+ continue outer;
44210
45006
  }
44211
45007
  f2(child, offset2);
44212
- if (j < oldSize && old.child(j).sameMarkup(child))
44213
- changedDescendants(old.child(j), child, offset2 + 1, f2);
45008
+ if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset2 + 1, f2);
44214
45009
  else child.nodesBetween(0, child.content.size, f2, offset2 + 1);
44215
45010
  offset2 += child.nodeSize;
44216
45011
  }
@@ -44218,12 +45013,10 @@ function changedDescendants(old, cur, offset2, f2) {
44218
45013
  function fixTables(state, oldState) {
44219
45014
  let tr;
44220
45015
  const check = (node, pos) => {
44221
- if (node.type.spec.tableRole == "table")
44222
- tr = fixTable(state, node, pos, tr);
45016
+ if (node.type.spec.tableRole == "table") tr = fixTable(state, node, pos, tr);
44223
45017
  };
44224
45018
  if (!oldState) state.doc.descendants(check);
44225
- else if (oldState.doc != state.doc)
44226
- changedDescendants(oldState.doc, state.doc, 0, check);
45019
+ else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);
44227
45020
  return tr;
44228
45021
  }
44229
45022
  function fixTable(state, table, tablePos, tr) {
@@ -44239,14 +45032,9 @@ function fixTable(state, table, tablePos, tr) {
44239
45032
  if (!cell) continue;
44240
45033
  const attrs = cell.attrs;
44241
45034
  for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
44242
- tr.setNodeMarkup(
44243
- tr.mapping.map(tablePos + 1 + prob.pos),
44244
- null,
44245
- removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
44246
- );
44247
- } else if (prob.type == "missing") {
44248
- mustAdd[prob.row] += prob.n;
44249
- } else if (prob.type == "overlong_rowspan") {
45035
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
45036
+ } else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
45037
+ else if (prob.type == "overlong_rowspan") {
44250
45038
  const cell = table.nodeAt(prob.pos);
44251
45039
  if (!cell) continue;
44252
45040
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
@@ -44266,20 +45054,17 @@ function fixTable(state, table, tablePos, tr) {
44266
45054
  }
44267
45055
  }
44268
45056
  let first2, last;
44269
- for (let i = 0; i < mustAdd.length; i++)
44270
- if (mustAdd[i]) {
44271
- if (first2 == null) first2 = i;
44272
- last = i;
44273
- }
45057
+ for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
45058
+ if (first2 == null) first2 = i;
45059
+ last = i;
45060
+ }
44274
45061
  for (let i = 0, pos = tablePos + 1; i < map2.height; i++) {
44275
45062
  const row = table.child(i);
44276
45063
  const end2 = pos + row.nodeSize;
44277
45064
  const add = mustAdd[i];
44278
45065
  if (add > 0) {
44279
45066
  let role = "cell";
44280
- if (row.firstChild) {
44281
- role = row.firstChild.type.spec.tableRole;
44282
- }
45067
+ if (row.firstChild) role = row.firstChild.type.spec.tableRole;
44283
45068
  const nodes = [];
44284
45069
  for (let j = 0; j < add; j++) {
44285
45070
  const node = tableNodeTypes(state.schema)[role].createAndFill();
@@ -44298,27 +45083,22 @@ function selectedRect(state) {
44298
45083
  const table = $pos.node(-1);
44299
45084
  const tableStart = $pos.start(-1);
44300
45085
  const map2 = TableMap.get(table);
44301
- const rect = sel instanceof CellSelection ? map2.rectBetween(
44302
- sel.$anchorCell.pos - tableStart,
44303
- sel.$headCell.pos - tableStart
44304
- ) : map2.findCell($pos.pos - tableStart);
44305
- return { ...rect, tableStart, map: map2, table };
45086
+ return {
45087
+ ...sel instanceof CellSelection ? map2.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map2.findCell($pos.pos - tableStart),
45088
+ tableStart,
45089
+ map: map2,
45090
+ table
45091
+ };
44306
45092
  }
44307
45093
  function addColumn(tr, { map: map2, tableStart, table }, col) {
44308
45094
  let refColumn = col > 0 ? -1 : 0;
44309
- if (columnIsHeader(map2, table, col + refColumn)) {
44310
- refColumn = col == 0 || col == map2.width ? null : 0;
44311
- }
45095
+ if (columnIsHeader(map2, table, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0;
44312
45096
  for (let row = 0; row < map2.height; row++) {
44313
45097
  const index2 = row * map2.width + col;
44314
45098
  if (col > 0 && col < map2.width && map2.map[index2 - 1] == map2.map[index2]) {
44315
45099
  const pos = map2.map[index2];
44316
45100
  const cell = table.nodeAt(pos);
44317
- tr.setNodeMarkup(
44318
- tr.mapping.map(tableStart + pos),
44319
- null,
44320
- addColSpan(cell.attrs, col - map2.colCount(pos))
44321
- );
45101
+ tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map2.colCount(pos)));
44322
45102
  row += cell.attrs.rowspan - 1;
44323
45103
  } else {
44324
45104
  const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map2.map[index2 + refColumn]).type;
@@ -44351,13 +45131,8 @@ function removeColumn(tr, { map: map2, table, tableStart }, col) {
44351
45131
  const pos = map2.map[index2];
44352
45132
  const cell = table.nodeAt(pos);
44353
45133
  const attrs = cell.attrs;
44354
- if (col > 0 && map2.map[index2 - 1] == pos || col < map2.width - 1 && map2.map[index2 + 1] == pos) {
44355
- tr.setNodeMarkup(
44356
- tr.mapping.slice(mapStart).map(tableStart + pos),
44357
- null,
44358
- removeColSpan(attrs, col - map2.colCount(pos))
44359
- );
44360
- } else {
45134
+ 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)));
45135
+ else {
44361
45136
  const start2 = tr.mapping.slice(mapStart).map(tableStart + pos);
44362
45137
  tr.delete(start2, start2 + cell.nodeSize);
44363
45138
  }
@@ -44374,9 +45149,7 @@ function deleteColumn(state, dispatch) {
44374
45149
  removeColumn(tr, rect, i);
44375
45150
  if (i == rect.left) break;
44376
45151
  const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
44377
- if (!table) {
44378
- throw RangeError("No table found");
44379
- }
45152
+ if (!table) throw new RangeError("No table found");
44380
45153
  rect.table = table;
44381
45154
  rect.map = TableMap.get(table);
44382
45155
  }
@@ -44385,35 +45158,30 @@ function deleteColumn(state, dispatch) {
44385
45158
  return true;
44386
45159
  }
44387
45160
  function rowIsHeader(map2, table, row) {
44388
- var _a;
45161
+ var _table$nodeAt;
44389
45162
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
44390
- for (let col = 0; col < map2.width; col++)
44391
- if (((_a = table.nodeAt(map2.map[col + row * map2.width])) == null ? void 0 : _a.type) != headerCell)
44392
- return false;
45163
+ for (let col = 0; col < map2.width; col++) if (((_table$nodeAt = table.nodeAt(map2.map[col + row * map2.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
44393
45164
  return true;
44394
45165
  }
44395
45166
  function addRow(tr, { map: map2, tableStart, table }, row) {
44396
- var _a;
44397
45167
  let rowPos = tableStart;
44398
45168
  for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
44399
45169
  const cells = [];
44400
45170
  let refRow = row > 0 ? -1 : 0;
44401
- if (rowIsHeader(map2, table, row + refRow))
44402
- refRow = row == 0 || row == map2.height ? null : 0;
44403
- for (let col = 0, index2 = map2.width * row; col < map2.width; col++, index2++) {
44404
- if (row > 0 && row < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
44405
- const pos = map2.map[index2];
44406
- const attrs = table.nodeAt(pos).attrs;
44407
- tr.setNodeMarkup(tableStart + pos, null, {
44408
- ...attrs,
44409
- rowspan: attrs.rowspan + 1
44410
- });
44411
- col += attrs.colspan - 1;
44412
- } else {
44413
- const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a = table.nodeAt(map2.map[index2 + refRow * map2.width])) == null ? void 0 : _a.type;
44414
- const node = type == null ? void 0 : type.createAndFill();
44415
- if (node) cells.push(node);
44416
- }
45171
+ if (rowIsHeader(map2, table, row + refRow)) refRow = row == 0 || row == map2.height ? null : 0;
45172
+ for (let col = 0, index2 = map2.width * row; col < map2.width; col++, index2++) if (row > 0 && row < map2.height && map2.map[index2] == map2.map[index2 - map2.width]) {
45173
+ const pos = map2.map[index2];
45174
+ const attrs = table.nodeAt(pos).attrs;
45175
+ tr.setNodeMarkup(tableStart + pos, null, {
45176
+ ...attrs,
45177
+ rowspan: attrs.rowspan + 1
45178
+ });
45179
+ col += attrs.colspan - 1;
45180
+ } else {
45181
+ var _table$nodeAt2;
45182
+ const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map2.map[index2 + refRow * map2.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
45183
+ const node = type === null || type === void 0 ? void 0 : type.createAndFill();
45184
+ if (node) cells.push(node);
44417
45185
  }
44418
45186
  tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
44419
45187
  return tr;
@@ -44455,10 +45223,10 @@ function removeRow(tr, { map: map2, table, tableStart }, row) {
44455
45223
  } else if (row < map2.height && pos == map2.map[index2 + map2.width]) {
44456
45224
  const cell = table.nodeAt(pos);
44457
45225
  const attrs = cell.attrs;
44458
- const copy = cell.type.create(
44459
- { ...attrs, rowspan: cell.attrs.rowspan - 1 },
44460
- cell.content
44461
- );
45226
+ const copy = cell.type.create({
45227
+ ...attrs,
45228
+ rowspan: cell.attrs.rowspan - 1
45229
+ }, cell.content);
44462
45230
  const newPos = map2.positionAt(row + 1, col, table);
44463
45231
  tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
44464
45232
  col += attrs.colspan - 1;
@@ -44474,9 +45242,7 @@ function deleteRow(state, dispatch) {
44474
45242
  removeRow(tr, rect, i);
44475
45243
  if (i == rect.top) break;
44476
45244
  const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
44477
- if (!table) {
44478
- throw RangeError("No table found");
44479
- }
45245
+ if (!table) throw new RangeError("No table found");
44480
45246
  rect.table = table;
44481
45247
  rect.map = TableMap.get(rect.table);
44482
45248
  }
@@ -44492,14 +45258,12 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
44492
45258
  let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
44493
45259
  let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
44494
45260
  for (let i = rect.top; i < rect.bottom; i++) {
44495
- if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1])
44496
- return true;
45261
+ if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true;
44497
45262
  indexLeft += width;
44498
45263
  indexRight += width;
44499
45264
  }
44500
45265
  for (let i = rect.left; i < rect.right; i++) {
44501
- if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width])
44502
- return true;
45266
+ if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true;
44503
45267
  indexTop++;
44504
45268
  indexBottom++;
44505
45269
  }
@@ -44507,8 +45271,7 @@ function cellsOverlapRectangle({ width, height, map: map2 }, rect) {
44507
45271
  }
44508
45272
  function mergeCells(state, dispatch) {
44509
45273
  const sel = state.selection;
44510
- if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
44511
- return false;
45274
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
44512
45275
  const rect = selectedRect(state), { map: map2 } = rect;
44513
45276
  if (cellsOverlapRectangle(map2, rect)) return false;
44514
45277
  if (dispatch) {
@@ -44517,41 +45280,31 @@ function mergeCells(state, dispatch) {
44517
45280
  let content = Fragment.empty;
44518
45281
  let mergedPos;
44519
45282
  let mergedCell;
44520
- for (let row = rect.top; row < rect.bottom; row++) {
44521
- for (let col = rect.left; col < rect.right; col++) {
44522
- const cellPos = map2.map[row * map2.width + col];
44523
- const cell = rect.table.nodeAt(cellPos);
44524
- if (seen[cellPos] || !cell) continue;
44525
- seen[cellPos] = true;
44526
- if (mergedPos == null) {
44527
- mergedPos = cellPos;
44528
- mergedCell = cell;
44529
- } else {
44530
- if (!isEmpty(cell)) content = content.append(cell.content);
44531
- const mapped = tr.mapping.map(cellPos + rect.tableStart);
44532
- tr.delete(mapped, mapped + cell.nodeSize);
44533
- }
45283
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
45284
+ const cellPos = map2.map[row * map2.width + col];
45285
+ const cell = rect.table.nodeAt(cellPos);
45286
+ if (seen[cellPos] || !cell) continue;
45287
+ seen[cellPos] = true;
45288
+ if (mergedPos == null) {
45289
+ mergedPos = cellPos;
45290
+ mergedCell = cell;
45291
+ } else {
45292
+ if (!isEmpty(cell)) content = content.append(cell.content);
45293
+ const mapped = tr.mapping.map(cellPos + rect.tableStart);
45294
+ tr.delete(mapped, mapped + cell.nodeSize);
44534
45295
  }
44535
45296
  }
44536
- if (mergedPos == null || mergedCell == null) {
44537
- return true;
44538
- }
45297
+ if (mergedPos == null || mergedCell == null) return true;
44539
45298
  tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
44540
- ...addColSpan(
44541
- mergedCell.attrs,
44542
- mergedCell.attrs.colspan,
44543
- rect.right - rect.left - mergedCell.attrs.colspan
44544
- ),
45299
+ ...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
44545
45300
  rowspan: rect.bottom - rect.top
44546
45301
  });
44547
- if (content.size) {
45302
+ if (content.size > 0) {
44548
45303
  const end2 = mergedPos + 1 + mergedCell.content.size;
44549
45304
  const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
44550
45305
  tr.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content);
44551
45306
  }
44552
- tr.setSelection(
44553
- new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
44554
- );
45307
+ tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
44555
45308
  dispatch(tr);
44556
45309
  }
44557
45310
  return true;
@@ -44564,63 +45317,57 @@ function splitCell(state, dispatch) {
44564
45317
  }
44565
45318
  function splitCellWithType(getCellType2) {
44566
45319
  return (state, dispatch) => {
44567
- var _a;
44568
45320
  const sel = state.selection;
44569
45321
  let cellNode;
44570
45322
  let cellPos;
44571
45323
  if (!(sel instanceof CellSelection)) {
45324
+ var _cellAround;
44572
45325
  cellNode = cellWrapping$1(sel.$from);
44573
45326
  if (!cellNode) return false;
44574
- cellPos = (_a = cellAround$1(sel.$from)) == null ? void 0 : _a.pos;
45327
+ cellPos = (_cellAround = cellAround$1(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
44575
45328
  } else {
44576
45329
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
44577
45330
  cellNode = sel.$anchorCell.nodeAfter;
44578
45331
  cellPos = sel.$anchorCell.pos;
44579
45332
  }
44580
- if (cellNode == null || cellPos == null) {
44581
- return false;
44582
- }
44583
- if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
44584
- return false;
44585
- }
45333
+ if (cellNode == null || cellPos == null) return false;
45334
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
44586
45335
  if (dispatch) {
44587
45336
  let baseAttrs = cellNode.attrs;
44588
45337
  const attrs = [];
44589
45338
  const colwidth = baseAttrs.colwidth;
44590
- if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };
44591
- if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };
45339
+ if (baseAttrs.rowspan > 1) baseAttrs = {
45340
+ ...baseAttrs,
45341
+ rowspan: 1
45342
+ };
45343
+ if (baseAttrs.colspan > 1) baseAttrs = {
45344
+ ...baseAttrs,
45345
+ colspan: 1
45346
+ };
44592
45347
  const rect = selectedRect(state), tr = state.tr;
44593
- for (let i = 0; i < rect.right - rect.left; i++)
44594
- attrs.push(
44595
- colwidth ? {
44596
- ...baseAttrs,
44597
- colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
44598
- } : baseAttrs
44599
- );
45348
+ for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {
45349
+ ...baseAttrs,
45350
+ colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
45351
+ } : baseAttrs);
44600
45352
  let lastCell;
44601
45353
  for (let row = rect.top; row < rect.bottom; row++) {
44602
45354
  let pos = rect.map.positionAt(row, rect.left, rect.table);
44603
45355
  if (row == rect.top) pos += cellNode.nodeSize;
44604
45356
  for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
44605
45357
  if (col == rect.left && row == rect.top) continue;
44606
- tr.insert(
44607
- lastCell = tr.mapping.map(pos + rect.tableStart, 1),
44608
- getCellType2({ node: cellNode, row, col }).createAndFill(attrs[i])
44609
- );
44610
- }
44611
- }
44612
- tr.setNodeMarkup(
44613
- cellPos,
44614
- getCellType2({ node: cellNode, row: rect.top, col: rect.left }),
44615
- attrs[0]
44616
- );
44617
- if (sel instanceof CellSelection)
44618
- tr.setSelection(
44619
- new CellSelection(
44620
- tr.doc.resolve(sel.$anchorCell.pos),
44621
- lastCell ? tr.doc.resolve(lastCell) : void 0
44622
- )
44623
- );
45358
+ tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType2({
45359
+ node: cellNode,
45360
+ row,
45361
+ col
45362
+ }).createAndFill(attrs[i]));
45363
+ }
45364
+ }
45365
+ tr.setNodeMarkup(cellPos, getCellType2({
45366
+ node: cellNode,
45367
+ row: rect.top,
45368
+ col: rect.left
45369
+ }), attrs[0]);
45370
+ if (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));
44624
45371
  dispatch(tr);
44625
45372
  }
44626
45373
  return true;
@@ -44633,19 +45380,16 @@ function setCellAttr(name, value) {
44633
45380
  if ($cell.nodeAfter.attrs[name] === value) return false;
44634
45381
  if (dispatch) {
44635
45382
  const tr = state.tr;
44636
- if (state.selection instanceof CellSelection)
44637
- state.selection.forEachCell((node, pos) => {
44638
- if (node.attrs[name] !== value)
44639
- tr.setNodeMarkup(pos, null, {
44640
- ...node.attrs,
44641
- [name]: value
44642
- });
44643
- });
44644
- else
44645
- tr.setNodeMarkup($cell.pos, null, {
44646
- ...$cell.nodeAfter.attrs,
45383
+ if (state.selection instanceof CellSelection) state.selection.forEachCell((node, pos) => {
45384
+ if (node.attrs[name] !== value) tr.setNodeMarkup(pos, null, {
45385
+ ...node.attrs,
44647
45386
  [name]: value
44648
45387
  });
45388
+ });
45389
+ else tr.setNodeMarkup($cell.pos, null, {
45390
+ ...$cell.nodeAfter.attrs,
45391
+ [name]: value
45392
+ });
44649
45393
  dispatch(tr);
44650
45394
  }
44651
45395
  return true;
@@ -44657,34 +45401,20 @@ function deprecated_toggleHeader(type) {
44657
45401
  if (dispatch) {
44658
45402
  const types = tableNodeTypes(state.schema);
44659
45403
  const rect = selectedRect(state), tr = state.tr;
44660
- const cells = rect.map.cellsInRect(
44661
- type == "column" ? {
44662
- left: rect.left,
44663
- top: 0,
44664
- right: rect.right,
44665
- bottom: rect.map.height
44666
- } : type == "row" ? {
44667
- left: 0,
44668
- top: rect.top,
44669
- right: rect.map.width,
44670
- bottom: rect.bottom
44671
- } : rect
44672
- );
45404
+ const cells = rect.map.cellsInRect(type == "column" ? {
45405
+ left: rect.left,
45406
+ top: 0,
45407
+ right: rect.right,
45408
+ bottom: rect.map.height
45409
+ } : type == "row" ? {
45410
+ left: 0,
45411
+ top: rect.top,
45412
+ right: rect.map.width,
45413
+ bottom: rect.bottom
45414
+ } : rect);
44673
45415
  const nodes = cells.map((pos) => rect.table.nodeAt(pos));
44674
- for (let i = 0; i < cells.length; i++)
44675
- if (nodes[i].type == types.header_cell)
44676
- tr.setNodeMarkup(
44677
- rect.tableStart + cells[i],
44678
- types.cell,
44679
- nodes[i].attrs
44680
- );
44681
- if (tr.steps.length == 0)
44682
- for (let i = 0; i < cells.length; i++)
44683
- tr.setNodeMarkup(
44684
- rect.tableStart + cells[i],
44685
- types.header_cell,
44686
- nodes[i].attrs
44687
- );
45416
+ for (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs);
45417
+ if (tr.steps.length === 0) for (let i = 0; i < cells.length; i++) tr.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs);
44688
45418
  dispatch(tr);
44689
45419
  }
44690
45420
  return true;
@@ -44699,9 +45429,7 @@ function isHeaderEnabledByType(type, rect, types) {
44699
45429
  });
44700
45430
  for (let i = 0; i < cellPositions.length; i++) {
44701
45431
  const cell = rect.table.nodeAt(cellPositions[i]);
44702
- if (cell && cell.type !== types.header_cell) {
44703
- return false;
44704
- }
45432
+ if (cell && cell.type !== types.header_cell) return false;
44705
45433
  }
44706
45434
  return true;
44707
45435
  }
@@ -44714,13 +45442,8 @@ function toggleHeader(type, options) {
44714
45442
  const types = tableNodeTypes(state.schema);
44715
45443
  const rect = selectedRect(state), tr = state.tr;
44716
45444
  const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
44717
- const isHeaderColumnEnabled = isHeaderEnabledByType(
44718
- "column",
44719
- rect,
44720
- types
44721
- );
44722
- const isHeaderEnabled = type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false;
44723
- const selectionStartsAt = isHeaderEnabled ? 1 : 0;
45445
+ const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types);
45446
+ const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
44724
45447
  const cellsRect = type == "column" ? {
44725
45448
  left: 0,
44726
45449
  top: selectionStartsAt,
@@ -44736,24 +45459,16 @@ function toggleHeader(type, options) {
44736
45459
  rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
44737
45460
  const cellPos = relativeCellPos + rect.tableStart;
44738
45461
  const cell = tr.doc.nodeAt(cellPos);
44739
- if (cell) {
44740
- tr.setNodeMarkup(cellPos, newType, cell.attrs);
44741
- }
45462
+ if (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);
44742
45463
  });
44743
45464
  dispatch(tr);
44744
45465
  }
44745
45466
  return true;
44746
45467
  };
44747
45468
  }
44748
- toggleHeader("row", {
44749
- useDeprecatedLogic: true
44750
- });
44751
- toggleHeader("column", {
44752
- useDeprecatedLogic: true
44753
- });
44754
- var toggleHeaderCell = toggleHeader("cell", {
44755
- useDeprecatedLogic: true
44756
- });
45469
+ toggleHeader("row", { useDeprecatedLogic: true });
45470
+ toggleHeader("column", { useDeprecatedLogic: true });
45471
+ const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
44757
45472
  function findNextCell($cell, dir) {
44758
45473
  if (dir < 0) {
44759
45474
  const before = $cell.nodeBefore;
@@ -44761,15 +45476,11 @@ function findNextCell($cell, dir) {
44761
45476
  for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
44762
45477
  const rowNode = $cell.node(-1).child(row);
44763
45478
  const lastChild = rowNode.lastChild;
44764
- if (lastChild) {
44765
- return rowEnd - 1 - lastChild.nodeSize;
44766
- }
45479
+ if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
44767
45480
  rowEnd -= rowNode.nodeSize;
44768
45481
  }
44769
45482
  } else {
44770
- if ($cell.index() < $cell.parent.childCount - 1) {
44771
- return $cell.pos + $cell.nodeAfter.nodeSize;
44772
- }
45483
+ if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
44773
45484
  const table = $cell.node(-1);
44774
45485
  for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
44775
45486
  const rowNode = table.child(row);
@@ -44786,24 +45497,16 @@ function goToNextCell(direction) {
44786
45497
  if (cell == null) return false;
44787
45498
  if (dispatch) {
44788
45499
  const $cell = state.doc.resolve(cell);
44789
- dispatch(
44790
- state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
44791
- );
45500
+ dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
44792
45501
  }
44793
45502
  return true;
44794
45503
  };
44795
45504
  }
44796
45505
  function deleteTable(state, dispatch) {
44797
45506
  const $pos = state.selection.$anchor;
44798
- for (let d2 = $pos.depth; d2 > 0; d2--) {
44799
- const node = $pos.node(d2);
44800
- if (node.type.spec.tableRole == "table") {
44801
- if (dispatch)
44802
- dispatch(
44803
- state.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
44804
- );
44805
- return true;
44806
- }
45507
+ for (let d2 = $pos.depth; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "table") {
45508
+ if (dispatch) dispatch(state.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView());
45509
+ return true;
44807
45510
  }
44808
45511
  return false;
44809
45512
  }
@@ -44814,19 +45517,14 @@ function deleteCellSelection(state, dispatch) {
44814
45517
  const tr = state.tr;
44815
45518
  const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
44816
45519
  sel.forEachCell((cell, pos) => {
44817
- if (!cell.content.eq(baseContent))
44818
- tr.replace(
44819
- tr.mapping.map(pos + 1),
44820
- tr.mapping.map(pos + cell.nodeSize - 1),
44821
- new Slice(baseContent, 0, 0)
44822
- );
45520
+ if (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
44823
45521
  });
44824
45522
  if (tr.docChanged) dispatch(tr);
44825
45523
  }
44826
45524
  return true;
44827
45525
  }
44828
45526
  function pastedCells(slice2) {
44829
- if (!slice2.size) return null;
45527
+ if (slice2.size === 0) return null;
44830
45528
  let { content, openStart, openEnd } = slice2;
44831
45529
  while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
44832
45530
  openStart--;
@@ -44836,28 +45534,15 @@ function pastedCells(slice2) {
44836
45534
  const first2 = content.child(0);
44837
45535
  const role = first2.type.spec.tableRole;
44838
45536
  const schema = first2.type.schema, rows = [];
44839
- if (role == "row") {
44840
- for (let i = 0; i < content.childCount; i++) {
44841
- let cells = content.child(i).content;
44842
- const left2 = i ? 0 : Math.max(0, openStart - 1);
44843
- const right2 = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
44844
- if (left2 || right2)
44845
- cells = fitSlice(
44846
- tableNodeTypes(schema).row,
44847
- new Slice(cells, left2, right2)
44848
- ).content;
44849
- rows.push(cells);
44850
- }
44851
- } else if (role == "cell" || role == "header_cell") {
44852
- rows.push(
44853
- openStart || openEnd ? fitSlice(
44854
- tableNodeTypes(schema).row,
44855
- new Slice(content, openStart, openEnd)
44856
- ).content : content
44857
- );
44858
- } else {
44859
- return null;
44860
- }
45537
+ if (role == "row") for (let i = 0; i < content.childCount; i++) {
45538
+ let cells = content.child(i).content;
45539
+ const left2 = i ? 0 : Math.max(0, openStart - 1);
45540
+ const right2 = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
45541
+ if (left2 || right2) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left2, right2)).content;
45542
+ rows.push(cells);
45543
+ }
45544
+ else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
45545
+ else return null;
44861
45546
  return ensureRectangular(schema, rows);
44862
45547
  }
44863
45548
  function ensureRectangular(schema, rows) {
@@ -44866,8 +45551,7 @@ function ensureRectangular(schema, rows) {
44866
45551
  const row = rows[i];
44867
45552
  for (let j = row.childCount - 1; j >= 0; j--) {
44868
45553
  const { rowspan, colspan } = row.child(j).attrs;
44869
- for (let r2 = i; r2 < i + rowspan; r2++)
44870
- widths[r2] = (widths[r2] || 0) + colspan;
45554
+ for (let r2 = i; r2 < i + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
44871
45555
  }
44872
45556
  }
44873
45557
  let width = 0;
@@ -44877,18 +45561,19 @@ function ensureRectangular(schema, rows) {
44877
45561
  if (widths[r2] < width) {
44878
45562
  const empty2 = tableNodeTypes(schema).cell.createAndFill();
44879
45563
  const cells = [];
44880
- for (let i = widths[r2]; i < width; i++) {
44881
- cells.push(empty2);
44882
- }
45564
+ for (let i = widths[r2]; i < width; i++) cells.push(empty2);
44883
45565
  rows[r2] = rows[r2].append(Fragment.from(cells));
44884
45566
  }
44885
45567
  }
44886
- return { height: rows.length, width, rows };
45568
+ return {
45569
+ height: rows.length,
45570
+ width,
45571
+ rows
45572
+ };
44887
45573
  }
44888
45574
  function fitSlice(nodeType, slice2) {
44889
45575
  const node = nodeType.createAndFill();
44890
- const tr = new Transform(node).replace(0, node.content.size, slice2);
44891
- return tr.doc;
45576
+ return new Transform(node).replace(0, node.content.size, slice2).doc;
44892
45577
  }
44893
45578
  function clipCells({ width, height, rows }, newWidth, newHeight) {
44894
45579
  if (width != newWidth) {
@@ -44898,19 +45583,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
44898
45583
  const frag = rows[row], cells = [];
44899
45584
  for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
44900
45585
  let cell = frag.child(i % frag.childCount);
44901
- if (col + cell.attrs.colspan > newWidth)
44902
- cell = cell.type.createChecked(
44903
- removeColSpan(
44904
- cell.attrs,
44905
- cell.attrs.colspan,
44906
- col + cell.attrs.colspan - newWidth
44907
- ),
44908
- cell.content
44909
- );
45586
+ if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
44910
45587
  cells.push(cell);
44911
45588
  col += cell.attrs.colspan;
44912
- for (let j = 1; j < cell.attrs.rowspan; j++)
44913
- added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
45589
+ for (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
44914
45590
  }
44915
45591
  newRows.push(Fragment.from(cells));
44916
45592
  }
@@ -44923,14 +45599,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
44923
45599
  const cells = [], source = rows[i % height];
44924
45600
  for (let j = 0; j < source.childCount; j++) {
44925
45601
  let cell = source.child(j);
44926
- if (row + cell.attrs.rowspan > newHeight)
44927
- cell = cell.type.create(
44928
- {
44929
- ...cell.attrs,
44930
- rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
44931
- },
44932
- cell.content
44933
- );
45602
+ if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
45603
+ ...cell.attrs,
45604
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
45605
+ }, cell.content);
44934
45606
  cells.push(cell);
44935
45607
  }
44936
45608
  newRows.push(Fragment.from(cells));
@@ -44938,33 +45610,32 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
44938
45610
  rows = newRows;
44939
45611
  height = newHeight;
44940
45612
  }
44941
- return { width, height, rows };
45613
+ return {
45614
+ width,
45615
+ height,
45616
+ rows
45617
+ };
44942
45618
  }
44943
45619
  function growTable(tr, map2, table, start2, width, height, mapFrom) {
44944
45620
  const schema = tr.doc.type.schema;
44945
45621
  const types = tableNodeTypes(schema);
44946
45622
  let empty2;
44947
45623
  let emptyHead;
44948
- if (width > map2.width) {
44949
- for (let row = 0, rowEnd = 0; row < map2.height; row++) {
44950
- const rowNode = table.child(row);
44951
- rowEnd += rowNode.nodeSize;
44952
- const cells = [];
44953
- let add;
44954
- if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
44955
- add = empty2 || (empty2 = types.cell.createAndFill());
44956
- else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
44957
- for (let i = map2.width; i < width; i++) cells.push(add);
44958
- tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
44959
- }
45624
+ if (width > map2.width) for (let row = 0, rowEnd = 0; row < map2.height; row++) {
45625
+ const rowNode = table.child(row);
45626
+ rowEnd += rowNode.nodeSize;
45627
+ const cells = [];
45628
+ let add;
45629
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty2 || (empty2 = types.cell.createAndFill());
45630
+ else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
45631
+ for (let i = map2.width; i < width; i++) cells.push(add);
45632
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
44960
45633
  }
44961
45634
  if (height > map2.height) {
44962
45635
  const cells = [];
44963
- for (let i = 0, start22 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) {
44964
- const header = i >= map2.width ? false : table.nodeAt(map2.map[start22 + i]).type == types.header_cell;
44965
- cells.push(
44966
- header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())
44967
- );
45636
+ for (let i = 0, start$1 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) {
45637
+ const header = i >= map2.width ? false : table.nodeAt(map2.map[start$1 + i]).type == types.header_cell;
45638
+ cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill()));
44968
45639
  }
44969
45640
  const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
44970
45641
  for (let i = map2.height; i < height; i++) rows.push(emptyRow);
@@ -44985,13 +45656,10 @@ function isolateHorizontal(tr, map2, table, start2, left2, right2, top2, mapFrom
44985
45656
  ...cell.attrs,
44986
45657
  rowspan: top2 - cellTop
44987
45658
  });
44988
- tr.insert(
44989
- tr.mapping.slice(mapFrom).map(map2.positionAt(top2, cellLeft, table)),
44990
- cell.type.createAndFill({
44991
- ...cell.attrs,
44992
- rowspan: cellTop + cell.attrs.rowspan - top2
44993
- })
44994
- );
45659
+ tr.insert(tr.mapping.slice(mapFrom).map(map2.positionAt(top2, cellLeft, table)), cell.type.createAndFill({
45660
+ ...cell.attrs,
45661
+ rowspan: cellTop + cell.attrs.rowspan - top2
45662
+ }));
44995
45663
  col += cell.attrs.colspan - 1;
44996
45664
  }
44997
45665
  }
@@ -45007,21 +45675,8 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
45007
45675
  const cell = table.nodeAt(pos);
45008
45676
  const cellLeft = map2.colCount(pos);
45009
45677
  const updatePos = tr.mapping.slice(mapFrom).map(pos + start2);
45010
- tr.setNodeMarkup(
45011
- updatePos,
45012
- null,
45013
- removeColSpan(
45014
- cell.attrs,
45015
- left2 - cellLeft,
45016
- cell.attrs.colspan - (left2 - cellLeft)
45017
- )
45018
- );
45019
- tr.insert(
45020
- updatePos + cell.nodeSize,
45021
- cell.type.createAndFill(
45022
- removeColSpan(cell.attrs, 0, left2 - cellLeft)
45023
- )
45024
- );
45678
+ tr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left2 - cellLeft, cell.attrs.colspan - (left2 - cellLeft)));
45679
+ tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left2 - cellLeft)));
45025
45680
  row += cell.attrs.rowspan - 1;
45026
45681
  }
45027
45682
  }
@@ -45029,9 +45684,7 @@ function isolateVertical(tr, map2, table, start2, top2, bottom2, left2, mapFrom)
45029
45684
  }
45030
45685
  function insertCells(state, dispatch, tableStart, rect, cells) {
45031
45686
  let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
45032
- if (!table) {
45033
- throw new Error("No table found");
45034
- }
45687
+ if (!table) throw new Error("No table found");
45035
45688
  let map2 = TableMap.get(table);
45036
45689
  const { top: top2, left: left2 } = rect;
45037
45690
  const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
@@ -45039,39 +45692,24 @@ function insertCells(state, dispatch, tableStart, rect, cells) {
45039
45692
  let mapFrom = 0;
45040
45693
  function recomp() {
45041
45694
  table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
45042
- if (!table) {
45043
- throw new Error("No table found");
45044
- }
45695
+ if (!table) throw new Error("No table found");
45045
45696
  map2 = TableMap.get(table);
45046
45697
  mapFrom = tr.mapping.maps.length;
45047
45698
  }
45048
45699
  if (growTable(tr, map2, table, tableStart, right2, bottom2, mapFrom)) recomp();
45049
- if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, top2, mapFrom))
45050
- recomp();
45051
- if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, bottom2, mapFrom))
45052
- recomp();
45053
- if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, left2, mapFrom))
45054
- recomp();
45055
- if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, right2, mapFrom))
45056
- recomp();
45700
+ if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, top2, mapFrom)) recomp();
45701
+ if (isolateHorizontal(tr, map2, table, tableStart, left2, right2, bottom2, mapFrom)) recomp();
45702
+ if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, left2, mapFrom)) recomp();
45703
+ if (isolateVertical(tr, map2, table, tableStart, top2, bottom2, right2, mapFrom)) recomp();
45057
45704
  for (let row = top2; row < bottom2; row++) {
45058
45705
  const from2 = map2.positionAt(row, left2, table), to = map2.positionAt(row, right2, table);
45059
- tr.replace(
45060
- tr.mapping.slice(mapFrom).map(from2 + tableStart),
45061
- tr.mapping.slice(mapFrom).map(to + tableStart),
45062
- new Slice(cells.rows[row - top2], 0, 0)
45063
- );
45706
+ tr.replace(tr.mapping.slice(mapFrom).map(from2 + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top2], 0, 0));
45064
45707
  }
45065
45708
  recomp();
45066
- tr.setSelection(
45067
- new CellSelection(
45068
- tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table)),
45069
- tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table))
45070
- )
45071
- );
45709
+ tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map2.positionAt(top2, left2, table)), tr.doc.resolve(tableStart + map2.positionAt(bottom2 - 1, right2 - 1, table))));
45072
45710
  dispatch(tr);
45073
45711
  }
45074
- var handleKeyDown = keydownHandler({
45712
+ const handleKeyDown = keydownHandler({
45075
45713
  ArrowLeft: arrow$2("horiz", -1),
45076
45714
  ArrowRight: arrow$2("horiz", 1),
45077
45715
  ArrowUp: arrow$2("vert", -1),
@@ -45094,29 +45732,17 @@ function arrow$2(axis, dir) {
45094
45732
  return (state, dispatch, view) => {
45095
45733
  if (!view) return false;
45096
45734
  const sel = state.selection;
45097
- if (sel instanceof CellSelection) {
45098
- return maybeSetSelection(
45099
- state,
45100
- dispatch,
45101
- Selection.near(sel.$headCell, dir)
45102
- );
45103
- }
45735
+ if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
45104
45736
  if (axis != "horiz" && !sel.empty) return false;
45105
45737
  const end2 = atEndOfCell(view, axis, dir);
45106
45738
  if (end2 == null) return false;
45107
- if (axis == "horiz") {
45108
- return maybeSetSelection(
45109
- state,
45110
- dispatch,
45111
- Selection.near(state.doc.resolve(sel.head + dir), dir)
45112
- );
45113
- } else {
45739
+ if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
45740
+ else {
45114
45741
  const $cell = state.doc.resolve(end2);
45115
45742
  const $next = nextCell($cell, axis, dir);
45116
45743
  let newSel;
45117
45744
  if ($next) newSel = Selection.near($next, 1);
45118
- else if (dir < 0)
45119
- newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
45745
+ else if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
45120
45746
  else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
45121
45747
  return maybeSetSelection(state, dispatch, newSel);
45122
45748
  }
@@ -45127,20 +45753,15 @@ function shiftArrow(axis, dir) {
45127
45753
  if (!view) return false;
45128
45754
  const sel = state.selection;
45129
45755
  let cellSel;
45130
- if (sel instanceof CellSelection) {
45131
- cellSel = sel;
45132
- } else {
45756
+ if (sel instanceof CellSelection) cellSel = sel;
45757
+ else {
45133
45758
  const end2 = atEndOfCell(view, axis, dir);
45134
45759
  if (end2 == null) return false;
45135
45760
  cellSel = new CellSelection(state.doc.resolve(end2));
45136
45761
  }
45137
45762
  const $head = nextCell(cellSel.$headCell, axis, dir);
45138
45763
  if (!$head) return false;
45139
- return maybeSetSelection(
45140
- state,
45141
- dispatch,
45142
- new CellSelection(cellSel.$anchorCell, $head)
45143
- );
45764
+ return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));
45144
45765
  };
45145
45766
  }
45146
45767
  function handleTripleClick(view, pos) {
@@ -45154,65 +45775,45 @@ function handlePaste(view, _, slice2) {
45154
45775
  let cells = pastedCells(slice2);
45155
45776
  const sel = view.state.selection;
45156
45777
  if (sel instanceof CellSelection) {
45157
- if (!cells)
45158
- cells = {
45159
- width: 1,
45160
- height: 1,
45161
- rows: [
45162
- Fragment.from(
45163
- fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
45164
- )
45165
- ]
45166
- };
45778
+ if (!cells) cells = {
45779
+ width: 1,
45780
+ height: 1,
45781
+ rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
45782
+ };
45167
45783
  const table = sel.$anchorCell.node(-1);
45168
45784
  const start2 = sel.$anchorCell.start(-1);
45169
- const rect = TableMap.get(table).rectBetween(
45170
- sel.$anchorCell.pos - start2,
45171
- sel.$headCell.pos - start2
45172
- );
45785
+ const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start2, sel.$headCell.pos - start2);
45173
45786
  cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
45174
45787
  insertCells(view.state, view.dispatch, start2, rect, cells);
45175
45788
  return true;
45176
45789
  } else if (cells) {
45177
45790
  const $cell = selectionCell(view.state);
45178
45791
  const start2 = $cell.start(-1);
45179
- insertCells(
45180
- view.state,
45181
- view.dispatch,
45182
- start2,
45183
- TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
45184
- cells
45185
- );
45792
+ insertCells(view.state, view.dispatch, start2, TableMap.get($cell.node(-1)).findCell($cell.pos - start2), cells);
45186
45793
  return true;
45187
- } else {
45188
- return false;
45189
- }
45794
+ } else return false;
45190
45795
  }
45191
45796
  function handleMouseDown(view, startEvent) {
45192
- var _a;
45797
+ var _cellUnderMouse;
45193
45798
  if (startEvent.ctrlKey || startEvent.metaKey) return;
45194
45799
  const startDOMCell = domInCell(view, startEvent.target);
45195
45800
  let $anchor;
45196
45801
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
45197
45802
  setCellSelection(view.state.selection.$anchorCell, startEvent);
45198
45803
  startEvent.preventDefault();
45199
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
45804
+ } 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) {
45200
45805
  setCellSelection($anchor, startEvent);
45201
45806
  startEvent.preventDefault();
45202
- } else if (!startDOMCell) {
45203
- return;
45204
- }
45205
- function setCellSelection($anchor2, event) {
45807
+ } else if (!startDOMCell) return;
45808
+ function setCellSelection($anchor$1, event) {
45206
45809
  let $head = cellUnderMouse(view, event);
45207
45810
  const starting = tableEditingKey.getState(view.state) == null;
45208
- if (!$head || !inSameTable($anchor2, $head)) {
45209
- if (starting) $head = $anchor2;
45210
- else return;
45211
- }
45212
- const selection = new CellSelection($anchor2, $head);
45811
+ if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
45812
+ else return;
45813
+ const selection = new CellSelection($anchor$1, $head);
45213
45814
  if (starting || !view.state.selection.eq(selection)) {
45214
45815
  const tr = view.state.tr.setSelection(selection);
45215
- if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);
45816
+ if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
45216
45817
  view.dispatch(tr);
45217
45818
  }
45218
45819
  }
@@ -45220,20 +45821,18 @@ function handleMouseDown(view, startEvent) {
45220
45821
  view.root.removeEventListener("mouseup", stop);
45221
45822
  view.root.removeEventListener("dragstart", stop);
45222
45823
  view.root.removeEventListener("mousemove", move);
45223
- if (tableEditingKey.getState(view.state) != null)
45224
- view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
45824
+ if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
45225
45825
  }
45226
45826
  function move(_event) {
45227
45827
  const event = _event;
45228
45828
  const anchor = tableEditingKey.getState(view.state);
45229
- let $anchor2;
45230
- if (anchor != null) {
45231
- $anchor2 = view.state.doc.resolve(anchor);
45232
- } else if (domInCell(view, event.target) != startDOMCell) {
45233
- $anchor2 = cellUnderMouse(view, startEvent);
45234
- if (!$anchor2) return stop();
45829
+ let $anchor$1;
45830
+ if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
45831
+ else if (domInCell(view, event.target) != startDOMCell) {
45832
+ $anchor$1 = cellUnderMouse(view, startEvent);
45833
+ if (!$anchor$1) return stop();
45235
45834
  }
45236
- if ($anchor2) setCellSelection($anchor2, event);
45835
+ if ($anchor$1) setCellSelection($anchor$1, event);
45237
45836
  }
45238
45837
  view.root.addEventListener("mouseup", stop);
45239
45838
  view.root.addEventListener("dragstart", stop);
@@ -45243,8 +45842,8 @@ function atEndOfCell(view, axis, dir) {
45243
45842
  if (!(view.state.selection instanceof TextSelection)) return null;
45244
45843
  const { $head } = view.state.selection;
45245
45844
  for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
45246
- const parent = $head.node(d2), index2 = dir < 0 ? $head.index(d2) : $head.indexAfter(d2);
45247
- if (index2 != (dir < 0 ? 0 : parent.childCount)) return null;
45845
+ const parent = $head.node(d2);
45846
+ if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
45248
45847
  if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
45249
45848
  const cellPos = $head.before(d2);
45250
45849
  const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
@@ -45254,11 +45853,7 @@ function atEndOfCell(view, axis, dir) {
45254
45853
  return null;
45255
45854
  }
45256
45855
  function domInCell(view, dom) {
45257
- for (; dom && dom != view.dom; dom = dom.parentNode) {
45258
- if (dom.nodeName == "TD" || dom.nodeName == "TH") {
45259
- return dom;
45260
- }
45261
- }
45856
+ for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
45262
45857
  return null;
45263
45858
  }
45264
45859
  function cellUnderMouse(view, event) {
@@ -45267,7 +45862,8 @@ function cellUnderMouse(view, event) {
45267
45862
  top: event.clientY
45268
45863
  });
45269
45864
  if (!mousePos) return null;
45270
- return mousePos ? cellAround$1(view.state.doc.resolve(mousePos.pos)) : null;
45865
+ const pos = mousePos.inside >= 0 ? mousePos.inside : mousePos.pos;
45866
+ return cellAround$1(view.state.doc.resolve(pos));
45271
45867
  }
45272
45868
  var TableView = class {
45273
45869
  constructor(node, defaultCellMinWidth) {
@@ -45276,10 +45872,7 @@ var TableView = class {
45276
45872
  this.dom = document.createElement("div");
45277
45873
  this.dom.className = "tableWrapper";
45278
45874
  this.table = this.dom.appendChild(document.createElement("table"));
45279
- this.table.style.setProperty(
45280
- "--default-cell-min-width",
45281
- `${defaultCellMinWidth}px`
45282
- );
45875
+ this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
45283
45876
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
45284
45877
  updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
45285
45878
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
@@ -45287,12 +45880,7 @@ var TableView = class {
45287
45880
  update(node) {
45288
45881
  if (node.type != this.node.type) return false;
45289
45882
  this.node = node;
45290
- updateColumnsOnResize(
45291
- node,
45292
- this.colgroup,
45293
- this.table,
45294
- this.defaultCellMinWidth
45295
- );
45883
+ updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
45296
45884
  return true;
45297
45885
  }
45298
45886
  ignoreMutation(record) {
@@ -45300,7 +45888,6 @@ var TableView = class {
45300
45888
  }
45301
45889
  };
45302
45890
  function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
45303
- var _a;
45304
45891
  let totalWidth = 0;
45305
45892
  let fixedWidth = true;
45306
45893
  let nextDOM = colgroup.firstChild;
@@ -45314,20 +45901,19 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
45314
45901
  totalWidth += hasWidth || defaultCellMinWidth;
45315
45902
  if (!hasWidth) fixedWidth = false;
45316
45903
  if (!nextDOM) {
45317
- const col2 = document.createElement("col");
45318
- col2.style.width = cssWidth;
45319
- colgroup.appendChild(col2);
45904
+ const col$1 = document.createElement("col");
45905
+ col$1.style.width = cssWidth;
45906
+ colgroup.appendChild(col$1);
45320
45907
  } else {
45321
- if (nextDOM.style.width != cssWidth) {
45322
- nextDOM.style.width = cssWidth;
45323
- }
45908
+ if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
45324
45909
  nextDOM = nextDOM.nextSibling;
45325
45910
  }
45326
45911
  }
45327
45912
  }
45328
45913
  while (nextDOM) {
45914
+ var _nextDOM$parentNode;
45329
45915
  const after = nextDOM.nextSibling;
45330
- (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
45916
+ (_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
45331
45917
  nextDOM = after;
45332
45918
  }
45333
45919
  if (fixedWidth) {
@@ -45338,28 +45924,18 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
45338
45924
  table.style.minWidth = totalWidth + "px";
45339
45925
  }
45340
45926
  }
45341
- var columnResizingPluginKey = new PluginKey(
45342
- "tableColumnResizing"
45343
- );
45344
- function columnResizing({
45345
- handleWidth = 5,
45346
- cellMinWidth = 25,
45347
- defaultCellMinWidth = 100,
45348
- View = TableView,
45349
- lastColumnResizable = true
45350
- } = {}) {
45927
+ const columnResizingPluginKey = new PluginKey("tableColumnResizing");
45928
+ function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
45351
45929
  const plugin = new Plugin({
45352
45930
  key: columnResizingPluginKey,
45353
45931
  state: {
45354
45932
  init(_, state) {
45355
- var _a, _b;
45356
- const nodeViews = (_b = (_a = plugin.spec) == null ? void 0 : _a.props) == null ? void 0 : _b.nodeViews;
45933
+ var _plugin$spec;
45934
+ const nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
45357
45935
  const tableName = tableNodeTypes(state.schema).table.name;
45358
- if (View && nodeViews) {
45359
- nodeViews[tableName] = (node, view) => {
45360
- return new View(node, defaultCellMinWidth, view);
45361
- };
45362
- }
45936
+ if (View && nodeViews) nodeViews[tableName] = (node, view) => {
45937
+ return new View(node, defaultCellMinWidth, view);
45938
+ };
45363
45939
  return new ResizeState(-1, false);
45364
45940
  },
45365
45941
  apply(tr, prev) {
@@ -45379,21 +45955,19 @@ function columnResizing({
45379
45955
  handleMouseLeave(view);
45380
45956
  },
45381
45957
  mousedown: (view, event) => {
45382
- handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth);
45958
+ handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth);
45383
45959
  }
45384
45960
  },
45385
45961
  decorations: (state) => {
45386
45962
  const pluginState = columnResizingPluginKey.getState(state);
45387
- if (pluginState && pluginState.activeHandle > -1) {
45388
- return handleDecorations(state, pluginState.activeHandle);
45389
- }
45963
+ if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);
45390
45964
  },
45391
45965
  nodeViews: {}
45392
45966
  }
45393
45967
  });
45394
45968
  return plugin;
45395
45969
  }
45396
- var ResizeState = class _ResizeState {
45970
+ var ResizeState = class ResizeState2 {
45397
45971
  constructor(activeHandle, dragging) {
45398
45972
  this.activeHandle = activeHandle;
45399
45973
  this.dragging = dragging;
@@ -45401,16 +45975,12 @@ var ResizeState = class _ResizeState {
45401
45975
  apply(tr) {
45402
45976
  const state = this;
45403
45977
  const action = tr.getMeta(columnResizingPluginKey);
45404
- if (action && action.setHandle != null)
45405
- return new _ResizeState(action.setHandle, false);
45406
- if (action && action.setDragging !== void 0)
45407
- return new _ResizeState(state.activeHandle, action.setDragging);
45978
+ if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false);
45979
+ if (action && action.setDragging !== void 0) return new ResizeState2(state.activeHandle, action.setDragging);
45408
45980
  if (state.activeHandle > -1 && tr.docChanged) {
45409
45981
  let handle = tr.mapping.map(state.activeHandle, -1);
45410
- if (!pointsAtCell(tr.doc.resolve(handle))) {
45411
- handle = -1;
45412
- }
45413
- return new _ResizeState(handle, state.dragging);
45982
+ if (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;
45983
+ return new ResizeState2(handle, state.dragging);
45414
45984
  }
45415
45985
  return state;
45416
45986
  }
@@ -45424,10 +45994,8 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
45424
45994
  let cell = -1;
45425
45995
  if (target) {
45426
45996
  const { left: left2, right: right2 } = target.getBoundingClientRect();
45427
- if (event.clientX - left2 <= handleWidth)
45428
- cell = edgeCell(view, event, "left", handleWidth);
45429
- else if (right2 - event.clientX <= handleWidth)
45430
- cell = edgeCell(view, event, "right", handleWidth);
45997
+ if (event.clientX - left2 <= handleWidth) cell = edgeCell(view, event, "left", handleWidth);
45998
+ else if (right2 - event.clientX <= handleWidth) cell = edgeCell(view, event, "right", handleWidth);
45431
45999
  }
45432
46000
  if (cell != pluginState.activeHandle) {
45433
46001
  if (!lastColumnResizable && cell !== -1) {
@@ -45435,10 +46003,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
45435
46003
  const table = $cell.node(-1);
45436
46004
  const map2 = TableMap.get(table);
45437
46005
  const tableStart = $cell.start(-1);
45438
- const col = map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
45439
- if (col == map2.width - 1) {
45440
- return;
45441
- }
46006
+ if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return;
45442
46007
  }
45443
46008
  updateHandle(view, cell);
45444
46009
  }
@@ -45447,58 +46012,39 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
45447
46012
  function handleMouseLeave(view) {
45448
46013
  if (!view.editable) return;
45449
46014
  const pluginState = columnResizingPluginKey.getState(view.state);
45450
- if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
45451
- updateHandle(view, -1);
46015
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
45452
46016
  }
45453
- function handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth) {
45454
- var _a;
46017
+ function handleMouseDown$1(view, event, cellMinWidth, defaultCellMinWidth) {
46018
+ var _view$dom$ownerDocume;
45455
46019
  if (!view.editable) return false;
45456
- const win = (_a = view.dom.ownerDocument.defaultView) != null ? _a : window;
46020
+ const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
45457
46021
  const pluginState = columnResizingPluginKey.getState(view.state);
45458
- if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
45459
- return false;
46022
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
45460
46023
  const cell = view.state.doc.nodeAt(pluginState.activeHandle);
45461
46024
  const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
45462
- view.dispatch(
45463
- view.state.tr.setMeta(columnResizingPluginKey, {
45464
- setDragging: { startX: event.clientX, startWidth: width }
45465
- })
45466
- );
45467
- function finish(event2) {
46025
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
46026
+ startX: event.clientX,
46027
+ startWidth: width
46028
+ } }));
46029
+ function finish(event$1) {
45468
46030
  win.removeEventListener("mouseup", finish);
45469
46031
  win.removeEventListener("mousemove", move);
45470
- const pluginState2 = columnResizingPluginKey.getState(view.state);
45471
- if (pluginState2 == null ? void 0 : pluginState2.dragging) {
45472
- updateColumnWidth(
45473
- view,
45474
- pluginState2.activeHandle,
45475
- draggedWidth(pluginState2.dragging, event2, cellMinWidth)
45476
- );
45477
- view.dispatch(
45478
- view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
45479
- );
46032
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
46033
+ if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
46034
+ updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth));
46035
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
45480
46036
  }
45481
46037
  }
45482
- function move(event2) {
45483
- if (!event2.which) return finish(event2);
45484
- const pluginState2 = columnResizingPluginKey.getState(view.state);
45485
- if (!pluginState2) return;
45486
- if (pluginState2.dragging) {
45487
- const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth);
45488
- displayColumnWidth(
45489
- view,
45490
- pluginState2.activeHandle,
45491
- dragged,
45492
- defaultCellMinWidth
45493
- );
46038
+ function move(event$1) {
46039
+ if (!event$1.which) return finish(event$1);
46040
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
46041
+ if (!pluginState$1) return;
46042
+ if (pluginState$1.dragging) {
46043
+ const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth);
46044
+ displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
45494
46045
  }
45495
46046
  }
45496
- displayColumnWidth(
45497
- view,
45498
- pluginState.activeHandle,
45499
- width,
45500
- defaultCellMinWidth
45501
- );
46047
+ displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
45502
46048
  win.addEventListener("mouseup", finish);
45503
46049
  win.addEventListener("mousemove", move);
45504
46050
  event.preventDefault();
@@ -45508,20 +46054,17 @@ function currentColWidth(view, cellPos, { colspan, colwidth }) {
45508
46054
  const width = colwidth && colwidth[colwidth.length - 1];
45509
46055
  if (width) return width;
45510
46056
  const dom = view.domAtPos(cellPos);
45511
- const node = dom.node.childNodes[dom.offset];
45512
- let domWidth = node.offsetWidth, parts = colspan;
46057
+ let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
45513
46058
  if (colwidth) {
45514
- for (let i = 0; i < colspan; i++)
45515
- if (colwidth[i]) {
45516
- domWidth -= colwidth[i];
45517
- parts--;
45518
- }
46059
+ for (let i = 0; i < colspan; i++) if (colwidth[i]) {
46060
+ domWidth -= colwidth[i];
46061
+ parts--;
46062
+ }
45519
46063
  }
45520
46064
  return domWidth / parts;
45521
46065
  }
45522
46066
  function domCellAround(target) {
45523
- while (target && target.nodeName != "TD" && target.nodeName != "TH")
45524
- target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
46067
+ while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
45525
46068
  return target;
45526
46069
  }
45527
46070
  function edgeCell(view, event, side, handleWidth) {
@@ -45544,9 +46087,7 @@ function draggedWidth(dragging, event, resizeMinWidth) {
45544
46087
  return Math.max(resizeMinWidth, dragging.startWidth + offset2);
45545
46088
  }
45546
46089
  function updateHandle(view, value) {
45547
- view.dispatch(
45548
- view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
45549
- );
46090
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
45550
46091
  }
45551
46092
  function updateColumnWidth(view, cell, width) {
45552
46093
  const $cell = view.state.doc.resolve(cell);
@@ -45562,7 +46103,10 @@ function updateColumnWidth(view, cell, width) {
45562
46103
  if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
45563
46104
  const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
45564
46105
  colwidth[index2] = width;
45565
- tr.setNodeMarkup(start2 + pos, null, { ...attrs, colwidth });
46106
+ tr.setNodeMarkup(start2 + pos, null, {
46107
+ ...attrs,
46108
+ colwidth
46109
+ });
45566
46110
  }
45567
46111
  if (tr.docChanged) view.dispatch(tr);
45568
46112
  }
@@ -45571,64 +46115,38 @@ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
45571
46115
  const table = $cell.node(-1), start2 = $cell.start(-1);
45572
46116
  const col = TableMap.get(table).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
45573
46117
  let dom = view.domAtPos($cell.start(-1)).node;
45574
- while (dom && dom.nodeName != "TABLE") {
45575
- dom = dom.parentNode;
45576
- }
46118
+ while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
45577
46119
  if (!dom) return;
45578
- updateColumnsOnResize(
45579
- table,
45580
- dom.firstChild,
45581
- dom,
45582
- defaultCellMinWidth,
45583
- col,
45584
- width
45585
- );
46120
+ updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
45586
46121
  }
45587
46122
  function zeroes(n) {
45588
46123
  return Array(n).fill(0);
45589
46124
  }
45590
46125
  function handleDecorations(state, cell) {
45591
- var _a;
45592
46126
  const decorations = [];
45593
46127
  const $cell = state.doc.resolve(cell);
45594
46128
  const table = $cell.node(-1);
45595
- if (!table) {
45596
- return DecorationSet.empty;
45597
- }
46129
+ if (!table) return DecorationSet.empty;
45598
46130
  const map2 = TableMap.get(table);
45599
46131
  const start2 = $cell.start(-1);
45600
46132
  const col = map2.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
45601
46133
  for (let row = 0; row < map2.height; row++) {
45602
46134
  const index2 = col + row * map2.width;
45603
46135
  if ((col == map2.width - 1 || map2.map[index2] != map2.map[index2 + 1]) && (row == 0 || map2.map[index2] != map2.map[index2 - map2.width])) {
46136
+ var _columnResizingPlugin;
45604
46137
  const cellPos = map2.map[index2];
45605
46138
  const pos = start2 + cellPos + table.nodeAt(cellPos).nodeSize - 1;
45606
46139
  const dom = document.createElement("div");
45607
46140
  dom.className = "column-resize-handle";
45608
- if ((_a = columnResizingPluginKey.getState(state)) == null ? void 0 : _a.dragging) {
45609
- decorations.push(
45610
- Decoration.node(
45611
- start2 + cellPos,
45612
- start2 + cellPos + table.nodeAt(cellPos).nodeSize,
45613
- {
45614
- class: "column-resize-dragging"
45615
- }
45616
- )
45617
- );
45618
- }
46141
+ if ((_columnResizingPlugin = columnResizingPluginKey.getState(state)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start2 + cellPos, start2 + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
45619
46142
  decorations.push(Decoration.widget(pos, dom));
45620
46143
  }
45621
46144
  }
45622
46145
  return DecorationSet.create(state.doc, decorations);
45623
46146
  }
45624
- function tableEditing({
45625
- allowTableNodeSelection = false
45626
- } = {}) {
46147
+ function tableEditing({ allowTableNodeSelection = false } = {}) {
45627
46148
  return new Plugin({
45628
46149
  key: tableEditingKey,
45629
- // This piece of state is used to remember when a mouse-drag
45630
- // cell-selection is happening, so that it can continue even as
45631
- // transactions (which might move its anchor cell) come in.
45632
46150
  state: {
45633
46151
  init() {
45634
46152
  return null;
@@ -45643,9 +46161,7 @@ function tableEditing({
45643
46161
  },
45644
46162
  props: {
45645
46163
  decorations: drawCellSelection,
45646
- handleDOMEvents: {
45647
- mousedown: handleMouseDown
45648
- },
46164
+ handleDOMEvents: { mousedown: handleMouseDown },
45649
46165
  createSelectionBetween(view) {
45650
46166
  return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
45651
46167
  },
@@ -45654,11 +46170,7 @@ function tableEditing({
45654
46170
  handlePaste
45655
46171
  },
45656
46172
  appendTransaction(_, oldState, state) {
45657
- return normalizeSelection(
45658
- state,
45659
- fixTables(state, oldState),
45660
- allowTableNodeSelection
45661
- );
46173
+ return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);
45662
46174
  }
45663
46175
  });
45664
46176
  }