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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/chunks/{PdfViewer-cvzMUtBh.es.js → PdfViewer-CDEQktlZ.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-BIlJaTm7.cjs → PdfViewer-CZgU5VTe.cjs} +1 -1
  3. package/dist/chunks/{index-DDx90Dl3.cjs → index-CBFc2Hsa.cjs} +8 -4
  4. package/dist/chunks/{index-VCeRjVPO-FBgR9qxX.es.js → index-DpnfmQSg--uFI4inB.es.js} +1 -1
  5. package/dist/chunks/{index-VCeRjVPO-DjkejB6t.cjs → index-DpnfmQSg-D54nF5iO.cjs} +1 -1
  6. package/dist/chunks/{index-CrIfBvBN.es.js → index-yYYhcBhg.es.js} +8 -4
  7. package/dist/chunks/{super-editor.es-00SpI-wK.es.js → super-editor.es-BNkRY9J-.es.js} +1834 -1121
  8. package/dist/chunks/{super-editor.es-Mlj7AGyt.cjs → super-editor.es-BfPsU6H-.cjs} +1833 -1120
  9. package/dist/packages/superdoc/src/components/CommentsLayer/use-comment.d.ts.map +1 -1
  10. package/dist/packages/superdoc/src/stores/comments-store.d.ts.map +1 -1
  11. package/dist/style.css +7 -7
  12. package/dist/super-editor/ai-writer.es.js +2 -2
  13. package/dist/super-editor/chunks/{converter-B9zUZjYT.js → converter-Cz21HA_9.js} +207 -15
  14. package/dist/super-editor/chunks/{docx-zipper-r5KdE_SA.js → docx-zipper-DiEfO4LE.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-D2k2BwSG.js → editor-DoxVe-iR.js} +1564 -1060
  16. package/dist/super-editor/chunks/{index-VCeRjVPO.js → index-DpnfmQSg.js} +1 -1
  17. package/dist/super-editor/chunks/{toolbar-8o_LgoiW.js → toolbar-CKdQr5PG.js} +2 -2
  18. package/dist/super-editor/converter.es.js +1 -1
  19. package/dist/super-editor/docx-zipper.es.js +2 -2
  20. package/dist/super-editor/editor.es.js +3 -3
  21. package/dist/super-editor/file-zipper.es.js +1 -1
  22. package/dist/super-editor/style.css +7 -7
  23. package/dist/super-editor/super-editor.es.js +126 -45
  24. package/dist/super-editor/toolbar.es.js +2 -2
  25. package/dist/super-editor.cjs +3 -3
  26. package/dist/super-editor.es.js +1 -1
  27. package/dist/superdoc.cjs +2 -2
  28. package/dist/superdoc.es.js +2 -2
  29. package/dist/superdoc.umd.js +1832 -1115
  30. package/dist/superdoc.umd.js.map +1 -1
  31. package/package.json +1 -1
@@ -19174,6 +19174,7 @@ function getUnderlineCssString({ type: type2 = "single", color = null, thickness
19174
19174
  if (color) add("text-decoration-color", color);
19175
19175
  return parts.join("; ");
19176
19176
  }
19177
+ const INLINE_OVERRIDE_PROPERTIES = ["fontSize", "bold", "italic", "strike", "underline", "letterSpacing"];
19177
19178
  const resolveRunProperties = (params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) => {
19178
19179
  const paragraphStyleId = resolvedPpr?.styleId;
19179
19180
  const paragraphStyleProps = resolveStyleChain$1(params2, paragraphStyleId, translator$1N);
@@ -19210,6 +19211,11 @@ const resolveRunProperties = (params2, inlineRpr, resolvedPpr, isListNumber = fa
19210
19211
  styleChain = [...styleChain, paragraphStyleProps, runStyleProps, inlineRpr];
19211
19212
  }
19212
19213
  const finalProps = combineProperties(styleChain, ["fontFamily", "color"]);
19214
+ for (const prop of INLINE_OVERRIDE_PROPERTIES) {
19215
+ if (inlineRpr?.[prop] != null) {
19216
+ finalProps[prop] = inlineRpr[prop];
19217
+ }
19218
+ }
19213
19219
  return finalProps;
19214
19220
  };
19215
19221
  function resolveParagraphProperties(params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) {
@@ -25017,8 +25023,8 @@ function handleImageNode$1(node, params2, isAnchor) {
25017
25023
  horizontal: positionHValue,
25018
25024
  top: positionVValue
25019
25025
  };
25020
- const useSimplePos = attributes["simplePos"] === "1" || attributes["simplePos"] === 1;
25021
- const simplePos = useSimplePos ? node.elements.find((el) => el.name === "wp:simplePos") : null;
25026
+ const useSimplePos = attributes["simplePos"] === "1" || attributes["simplePos"] === 1 || attributes["simplePos"] === true;
25027
+ const simplePosNode = node.elements.find((el) => el.name === "wp:simplePos");
25022
25028
  const wrapNode = isAnchor ? node.elements.find(
25023
25029
  (el) => ["wp:wrapNone", "wp:wrapSquare", "wp:wrapThrough", "wp:wrapTight", "wp:wrapTopAndBottom"].includes(el.name)
25024
25030
  ) : null;
@@ -25158,10 +25164,10 @@ function handleImageNode$1(node, params2, isAnchor) {
25158
25164
  anchorData,
25159
25165
  isAnchor,
25160
25166
  transformData,
25161
- ...simplePos && {
25167
+ ...useSimplePos && {
25162
25168
  simplePos: {
25163
- x: simplePos.attributes.x,
25164
- y: simplePos.attributes.y
25169
+ x: simplePosNode.attributes?.x,
25170
+ y: simplePosNode.attributes?.y
25165
25171
  }
25166
25172
  },
25167
25173
  wrap: wrap2,
@@ -30919,12 +30925,13 @@ function translateShapeGroup(params2) {
30919
30925
  function translateAnchorNode(params2) {
30920
30926
  const { attrs } = params2.node;
30921
30927
  const anchorElements = [];
30922
- if (attrs.simplePos) {
30928
+ const hasSimplePos = attrs.simplePos || attrs.originalAttributes?.simplePos;
30929
+ if (hasSimplePos) {
30923
30930
  anchorElements.push({
30924
30931
  name: "wp:simplePos",
30925
30932
  attributes: {
30926
- x: 0,
30927
- y: 0
30933
+ x: attrs.simplePos?.x ?? 0,
30934
+ y: attrs.simplePos?.y ?? 0
30928
30935
  }
30929
30936
  });
30930
30937
  }
@@ -30976,8 +30983,8 @@ function translateAnchorNode(params2) {
30976
30983
  }
30977
30984
  if (attrs.originalAttributes?.simplePos !== void 0) {
30978
30985
  inlineAttrs.simplePos = attrs.originalAttributes.simplePos;
30979
- } else if (attrs.simplePos !== void 0) {
30980
- inlineAttrs.simplePos = attrs.simplePos;
30986
+ } else if (hasSimplePos) {
30987
+ inlineAttrs.simplePos = "1";
30981
30988
  }
30982
30989
  if (attrs.originalAttributes?.locked !== void 0) {
30983
30990
  inlineAttrs.locked = attrs.originalAttributes.locked;
@@ -33742,7 +33749,7 @@ const handlePassthroughNode = (params2) => {
33742
33749
  const { nodes = [] } = params2;
33743
33750
  const node = nodes[0];
33744
33751
  if (!node) return { nodes: [], consumed: 0 };
33745
- if (registeredHandlers[node.name]) {
33752
+ if (registeredHandlers[node.name] || node.name === "w:commentReference") {
33746
33753
  return { nodes: [], consumed: 0 };
33747
33754
  }
33748
33755
  const originalXml = carbonCopy(node) || {};
@@ -34042,7 +34049,11 @@ function importCommentData({ docx, editor, converter }) {
34042
34049
  const generateCommentsWithExtendedData = ({ docx, comments }) => {
34043
34050
  if (!comments?.length) return [];
34044
34051
  const commentsExtended = docx["word/commentsExtended.xml"];
34045
- if (!commentsExtended) return comments.map((comment) => ({ ...comment, isDone: comment.isDone ?? false }));
34052
+ if (!commentsExtended) {
34053
+ const commentRanges = extractCommentRangesFromDocument(docx);
34054
+ const commentsWithThreading = detectThreadingFromRanges(comments, commentRanges);
34055
+ return commentsWithThreading.map((comment) => ({ ...comment, isDone: comment.isDone ?? false }));
34056
+ }
34046
34057
  const { elements: initialElements = [] } = commentsExtended;
34047
34058
  if (!initialElements?.length) return comments.map((comment) => ({ ...comment, isDone: comment.isDone ?? false }));
34048
34059
  const { elements = [] } = initialElements[0] ?? {};
@@ -34068,6 +34079,79 @@ const getExtendedDetails = (commentEx) => {
34068
34079
  const paraIdParent = attributes["w15:paraIdParent"];
34069
34080
  return { paraId, isDone, paraIdParent };
34070
34081
  };
34082
+ const extractCommentRangesFromDocument = (docx) => {
34083
+ const documentXml = docx["word/document.xml"];
34084
+ if (!documentXml) {
34085
+ return [];
34086
+ }
34087
+ const pendingComments = [];
34088
+ const walkElements = (elements) => {
34089
+ if (!elements || !Array.isArray(elements)) return;
34090
+ elements.forEach((element) => {
34091
+ if (element.name === "w:commentRangeStart") {
34092
+ const commentId = element.attributes?.["w:id"];
34093
+ if (commentId !== void 0) {
34094
+ pendingComments.push({
34095
+ type: "start",
34096
+ commentId: String(commentId)
34097
+ });
34098
+ }
34099
+ } else if (element.name === "w:commentRangeEnd") {
34100
+ const commentId = element.attributes?.["w:id"];
34101
+ if (commentId !== void 0) {
34102
+ pendingComments.push({
34103
+ type: "end",
34104
+ commentId: String(commentId)
34105
+ });
34106
+ }
34107
+ }
34108
+ if (element.elements && Array.isArray(element.elements)) {
34109
+ walkElements(element.elements);
34110
+ }
34111
+ });
34112
+ };
34113
+ if (documentXml.elements && documentXml.elements.length > 0) {
34114
+ const body = documentXml.elements[0];
34115
+ if (body.elements) {
34116
+ walkElements(body.elements);
34117
+ }
34118
+ }
34119
+ return pendingComments;
34120
+ };
34121
+ const detectThreadingFromRanges = (comments, rangeEvents) => {
34122
+ if (!rangeEvents || rangeEvents.length === 0) {
34123
+ return comments;
34124
+ }
34125
+ const openRanges = [];
34126
+ const parentMap = /* @__PURE__ */ new Map();
34127
+ rangeEvents.forEach((event) => {
34128
+ if (event.type === "start") {
34129
+ if (openRanges.length > 0) {
34130
+ const parentCommentId = openRanges[openRanges.length - 1];
34131
+ parentMap.set(event.commentId, parentCommentId);
34132
+ }
34133
+ openRanges.push(event.commentId);
34134
+ } else if (event.type === "end") {
34135
+ const index2 = openRanges.lastIndexOf(event.commentId);
34136
+ if (index2 !== -1) {
34137
+ openRanges.splice(index2, 1);
34138
+ }
34139
+ }
34140
+ });
34141
+ return comments.map((comment) => {
34142
+ const parentCommentId = parentMap.get(comment.importedId);
34143
+ if (parentCommentId) {
34144
+ const parentComment = comments.find((c2) => c2.importedId === parentCommentId);
34145
+ if (parentComment) {
34146
+ return {
34147
+ ...comment,
34148
+ parentCommentId: parentComment.commentId
34149
+ };
34150
+ }
34151
+ }
34152
+ return comment;
34153
+ });
34154
+ };
34071
34155
  const RELATIONSHIP_TYPES = (
34072
34156
  /** @type {const} */
34073
34157
  {
@@ -35908,10 +35992,12 @@ const toIsoNoFractional = (unixMillis) => {
35908
35992
  const updateCommentsXml = (commentDefs = [], commentsXml) => {
35909
35993
  const newCommentsXml = carbonCopy(commentsXml);
35910
35994
  commentDefs.forEach((commentDef) => {
35911
- const elements = commentDef.elements[0].elements;
35995
+ const paraNode = commentDef.elements[0];
35996
+ if (!paraNode.attributes) paraNode.attributes = {};
35997
+ const elements = paraNode.elements;
35912
35998
  elements.unshift(COMMENT_REF);
35913
35999
  const paraId = commentDef.attributes["w15:paraId"];
35914
- commentDef.elements[0].attributes["w14:paraId"] = paraId;
36000
+ paraNode.attributes["w14:paraId"] = paraId;
35915
36001
  commentDef.attributes = {
35916
36002
  "w:id": commentDef.attributes["w:id"],
35917
36003
  "w:author": commentDef.attributes["w:author"],
@@ -36285,7 +36371,7 @@ const _SuperConverter = class _SuperConverter2 {
36285
36371
  static getStoredSuperdocVersion(docx) {
36286
36372
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
36287
36373
  }
36288
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.17") {
36374
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.18") {
36289
36375
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36290
36376
  }
36291
36377
  /**
@@ -36626,6 +36712,112 @@ const _SuperConverter = class _SuperConverter2 {
36626
36712
  });
36627
36713
  return { result, params: params2 };
36628
36714
  }
36715
+ /**
36716
+ * Creates a default empty header for the specified variant.
36717
+ *
36718
+ * This method programmatically creates a new header section with an empty ProseMirror
36719
+ * document. The header is added to the converter's data structures and will be included
36720
+ * in subsequent DOCX exports.
36721
+ *
36722
+ * @param {('default' | 'first' | 'even' | 'odd')} variant - The header variant to create
36723
+ * @returns {string} The relationship ID of the created header
36724
+ *
36725
+ * @throws {Error} If variant is invalid or header already exists for this variant
36726
+ *
36727
+ * @example
36728
+ * ```javascript
36729
+ * const headerId = converter.createDefaultHeader('default');
36730
+ * // headerId: 'rId-header-default'
36731
+ * // converter.headers['rId-header-default'] contains empty PM doc
36732
+ * // converter.headerIds.default === 'rId-header-default'
36733
+ * ```
36734
+ */
36735
+ createDefaultHeader(variant = "default") {
36736
+ if (typeof variant !== "string") {
36737
+ throw new TypeError(`variant must be a string, received ${typeof variant}`);
36738
+ }
36739
+ const validVariants = ["default", "first", "even", "odd"];
36740
+ if (!validVariants.includes(variant)) {
36741
+ throw new Error(`Invalid header variant: ${variant}. Must be one of: ${validVariants.join(", ")}`);
36742
+ }
36743
+ if (this.headerIds[variant]) {
36744
+ console.warn(`[SuperConverter] Header already exists for variant '${variant}': ${this.headerIds[variant]}`);
36745
+ return this.headerIds[variant];
36746
+ }
36747
+ const rId = `rId-header-${variant}`;
36748
+ const emptyDoc = {
36749
+ type: "doc",
36750
+ content: [
36751
+ {
36752
+ type: "paragraph",
36753
+ content: []
36754
+ }
36755
+ ]
36756
+ };
36757
+ this.headers[rId] = emptyDoc;
36758
+ this.headerIds[variant] = rId;
36759
+ if (!this.headerIds.ids) {
36760
+ this.headerIds.ids = [];
36761
+ }
36762
+ if (!this.headerIds.ids.includes(rId)) {
36763
+ this.headerIds.ids.push(rId);
36764
+ }
36765
+ this.documentModified = true;
36766
+ return rId;
36767
+ }
36768
+ /**
36769
+ * Creates a default empty footer for the specified variant.
36770
+ *
36771
+ * This method programmatically creates a new footer section with an empty ProseMirror
36772
+ * document. The footer is added to the converter's data structures and will be included
36773
+ * in subsequent DOCX exports.
36774
+ *
36775
+ * @param {('default' | 'first' | 'even' | 'odd')} variant - The footer variant to create
36776
+ * @returns {string} The relationship ID of the created footer
36777
+ *
36778
+ * @throws {Error} If variant is invalid or footer already exists for this variant
36779
+ *
36780
+ * @example
36781
+ * ```javascript
36782
+ * const footerId = converter.createDefaultFooter('default');
36783
+ * // footerId: 'rId-footer-default'
36784
+ * // converter.footers['rId-footer-default'] contains empty PM doc
36785
+ * // converter.footerIds.default === 'rId-footer-default'
36786
+ * ```
36787
+ */
36788
+ createDefaultFooter(variant = "default") {
36789
+ if (typeof variant !== "string") {
36790
+ throw new TypeError(`variant must be a string, received ${typeof variant}`);
36791
+ }
36792
+ const validVariants = ["default", "first", "even", "odd"];
36793
+ if (!validVariants.includes(variant)) {
36794
+ throw new Error(`Invalid footer variant: ${variant}. Must be one of: ${validVariants.join(", ")}`);
36795
+ }
36796
+ if (this.footerIds[variant]) {
36797
+ console.warn(`[SuperConverter] Footer already exists for variant '${variant}': ${this.footerIds[variant]}`);
36798
+ return this.footerIds[variant];
36799
+ }
36800
+ const rId = `rId-footer-${variant}`;
36801
+ const emptyDoc = {
36802
+ type: "doc",
36803
+ content: [
36804
+ {
36805
+ type: "paragraph",
36806
+ content: []
36807
+ }
36808
+ ]
36809
+ };
36810
+ this.footers[rId] = emptyDoc;
36811
+ this.footerIds[variant] = rId;
36812
+ if (!this.footerIds.ids) {
36813
+ this.footerIds.ids = [];
36814
+ }
36815
+ if (!this.footerIds.ids.includes(rId)) {
36816
+ this.footerIds.ids.push(rId);
36817
+ }
36818
+ this.documentModified = true;
36819
+ return rId;
36820
+ }
36629
36821
  // Deprecated methods for backward compatibility
36630
36822
  static getStoredSuperdocId(docx) {
36631
36823
  console.warn("getStoredSuperdocId is deprecated, use getDocumentGuid instead");
@@ -39485,7 +39677,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
39485
39677
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
39486
39678
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
39487
39679
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
39488
- 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;
39680
+ 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;
39489
39681
  var GOOD_LEAF_SIZE = 200;
39490
39682
  var RopeSequence = function RopeSequence2() {
39491
39683
  };
@@ -50671,50 +50863,90 @@ const getCommentPositionsById = (commentId, doc2) => {
50671
50863
  return positions;
50672
50864
  };
50673
50865
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
50866
+ const commentMap = /* @__PURE__ */ new Map();
50867
+ comments.forEach((c2) => {
50868
+ commentMap.set(c2.commentId, c2);
50869
+ });
50870
+ new Set(comments.filter((c2) => c2.parentCommentId).map((c2) => c2.parentCommentId));
50674
50871
  const startNodes = [];
50675
50872
  const endNodes = [];
50676
50873
  const seen = /* @__PURE__ */ new Set();
50677
50874
  doc2.descendants((node, pos) => {
50678
- const commentMarks = node.marks?.filter((mark) => mark.type.name === CommentMarkName);
50875
+ const commentMarks = node.marks?.filter((mark) => mark.type.name === CommentMarkName) || [];
50679
50876
  commentMarks.forEach((commentMark) => {
50680
- if (commentMark) {
50681
- const { attrs = {} } = commentMark;
50682
- const { commentId } = attrs;
50683
- if (commentId === "pending") return;
50684
- if (seen.has(commentId)) return;
50685
- seen.add(commentId);
50686
- const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
50687
- const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
50877
+ const { attrs = {} } = commentMark;
50878
+ const { commentId } = attrs;
50879
+ if (commentId === "pending") return;
50880
+ if (seen.has(commentId)) return;
50881
+ seen.add(commentId);
50882
+ const comment = commentMap.get(commentId);
50883
+ const parentCommentId = comment?.parentCommentId;
50884
+ const commentStartNodeAttrs = getPreparedComment(commentMark.attrs);
50885
+ const startNode = schema.nodes.commentRangeStart.create(commentStartNodeAttrs);
50886
+ startNodes.push({
50887
+ pos,
50888
+ node: startNode,
50889
+ commentId,
50890
+ parentCommentId
50891
+ });
50892
+ const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
50893
+ endNodes.push({
50894
+ pos: pos + node.nodeSize,
50895
+ node: endNode,
50896
+ commentId,
50897
+ parentCommentId
50898
+ });
50899
+ const childComments = comments.filter((c2) => c2.parentCommentId === commentId).sort((a, b2) => a.createdTime - b2.createdTime);
50900
+ childComments.forEach((c2) => {
50901
+ if (seen.has(c2.commentId)) return;
50902
+ seen.add(c2.commentId);
50903
+ const childMark = getPreparedComment({
50904
+ commentId: c2.commentId,
50905
+ internal: c2.isInternal
50906
+ });
50907
+ const childStartNode = schema.nodes.commentRangeStart.create(childMark);
50688
50908
  startNodes.push({
50689
50909
  pos,
50690
- node: startNode
50910
+ node: childStartNode,
50911
+ commentId: c2.commentId,
50912
+ parentCommentId: c2.parentCommentId
50691
50913
  });
50692
- const endNode = schema.nodes.commentRangeEnd.create(commentStartNodeAttrs);
50914
+ const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
50693
50915
  endNodes.push({
50694
50916
  pos: pos + node.nodeSize,
50695
- node: endNode
50917
+ node: childEndNode,
50918
+ commentId: c2.commentId,
50919
+ parentCommentId: c2.parentCommentId
50696
50920
  });
50697
- const parentId = commentId;
50698
- if (parentId) {
50699
- const childComments = comments.filter((c2) => c2.parentCommentId === parentId).sort((a, b2) => a.createdTime - b2.createdTime);
50700
- childComments.forEach((c2) => {
50701
- const childMark = getPreparedComment(c2);
50702
- const childStartNode = schema.nodes.commentRangeStart.create(childMark);
50703
- seen.add(c2.commentId);
50704
- startNodes.push({
50705
- pos,
50706
- node: childStartNode
50707
- });
50708
- const childEndNode = schema.nodes.commentRangeEnd.create(childMark);
50709
- endNodes.push({
50710
- pos: pos + node.nodeSize,
50711
- node: childEndNode
50712
- });
50713
- });
50714
- }
50715
- }
50921
+ });
50716
50922
  });
50717
50923
  });
50924
+ startNodes.sort((a, b2) => {
50925
+ if (a.pos !== b2.pos) return a.pos - b2.pos;
50926
+ const aIsParentOfB = a.commentId === b2.parentCommentId;
50927
+ const bIsParentOfA = b2.commentId === a.parentCommentId;
50928
+ if (aIsParentOfB) return -1;
50929
+ if (bIsParentOfA) return 1;
50930
+ if (a.parentCommentId && a.parentCommentId === b2.parentCommentId) {
50931
+ const aComment = commentMap.get(a.commentId);
50932
+ const bComment = commentMap.get(b2.commentId);
50933
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
50934
+ }
50935
+ return 0;
50936
+ });
50937
+ endNodes.sort((a, b2) => {
50938
+ if (a.pos !== b2.pos) return a.pos - b2.pos;
50939
+ const aIsParentOfB = a.commentId === b2.parentCommentId;
50940
+ const bIsParentOfA = b2.commentId === a.parentCommentId;
50941
+ if (aIsParentOfB) return -1;
50942
+ if (bIsParentOfA) return 1;
50943
+ if (a.parentCommentId && a.parentCommentId === b2.parentCommentId) {
50944
+ const aComment = commentMap.get(a.commentId);
50945
+ const bComment = commentMap.get(b2.commentId);
50946
+ return (aComment?.createdTime || 0) - (bComment?.createdTime || 0);
50947
+ }
50948
+ return 0;
50949
+ });
50718
50950
  startNodes.forEach((n) => {
50719
50951
  const { pos, node } = n;
50720
50952
  const mappedPos = tr.mapping.map(pos);
@@ -53256,7 +53488,7 @@ const isHeadless = (editor) => {
53256
53488
  const shouldSkipNodeView = (editor) => {
53257
53489
  return isHeadless(editor);
53258
53490
  };
53259
- const summaryVersion = "1.0.0-beta.17";
53491
+ const summaryVersion = "1.0.0-beta.18";
53260
53492
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
53261
53493
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
53262
53494
  function mapAttributes(attrs) {
@@ -54032,7 +54264,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
54032
54264
  { default: remarkStringify },
54033
54265
  { default: remarkGfm }
54034
54266
  ] = await Promise.all([
54035
- import("./index-VCeRjVPO-FBgR9qxX.es.js"),
54267
+ import("./index-DpnfmQSg--uFI4inB.es.js"),
54036
54268
  import("./index-DRCvimau-Cw339678.es.js"),
54037
54269
  import("./index-C_x_N6Uh-DJn8hIEt.es.js"),
54038
54270
  import("./index-D_sWOSiG-DE96TaT5.es.js"),
@@ -54237,7 +54469,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
54237
54469
  * Process collaboration migrations
54238
54470
  */
54239
54471
  processCollaborationMigrations() {
54240
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.17");
54472
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.18");
54241
54473
  if (!this.options.ydoc) return;
54242
54474
  const metaMap = this.options.ydoc.getMap("meta");
54243
54475
  let docVersion = metaMap.get("version");
@@ -54939,6 +55171,15 @@ function extractColumns(elements) {
54939
55171
  gap: gapInches * PX_PER_INCH$2
54940
55172
  };
54941
55173
  }
55174
+ function extractVerticalAlign(elements) {
55175
+ const vAlign = elements.find((el) => el?.name === "w:vAlign");
55176
+ if (!vAlign?.attributes) return void 0;
55177
+ const val = vAlign.attributes["w:val"];
55178
+ if (val === "top" || val === "center" || val === "bottom" || val === "both") {
55179
+ return val;
55180
+ }
55181
+ return void 0;
55182
+ }
54942
55183
  function extractSectionData(para) {
54943
55184
  const attrs = para.attrs ?? {};
54944
55185
  let { headerPx, footerPx } = extractNormalizedMargins(attrs);
@@ -54955,7 +55196,20 @@ function extractSectionData(para) {
54955
55196
  const footerRefs = extractHeaderFooterRefs(sectPrElements, "w:footerReference");
54956
55197
  const numbering = extractPageNumbering(sectPrElements);
54957
55198
  const columnsPx = extractColumns(sectPrElements);
54958
- return { headerPx, footerPx, type: type2, pageSizePx, orientation, columnsPx, titlePg, headerRefs, footerRefs, numbering };
55199
+ const vAlign = extractVerticalAlign(sectPrElements);
55200
+ return {
55201
+ headerPx,
55202
+ footerPx,
55203
+ type: type2,
55204
+ pageSizePx,
55205
+ orientation,
55206
+ columnsPx,
55207
+ titlePg,
55208
+ headerRefs,
55209
+ footerRefs,
55210
+ numbering,
55211
+ vAlign
55212
+ };
54959
55213
  }
54960
55214
  function isSectPrElement(value) {
54961
55215
  return typeof value === "object" && value !== null && value.type === "element" && value.name === "w:sectPr";
@@ -54992,7 +55246,8 @@ function createSectionBreakBlock(section, blockIdGen, extraAttrs) {
54992
55246
  ...section.columns && { columns: section.columns },
54993
55247
  ...section.numbering ? { numbering: section.numbering } : {},
54994
55248
  ...section.headerRefs && { headerRefs: section.headerRefs },
54995
- ...section.footerRefs && { footerRefs: section.footerRefs }
55249
+ ...section.footerRefs && { footerRefs: section.footerRefs },
55250
+ ...section.vAlign && { vAlign: section.vAlign }
54996
55251
  };
54997
55252
  return result;
54998
55253
  }
@@ -55064,7 +55319,8 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
55064
55319
  titlePg: sectionData.titlePg ?? false,
55065
55320
  headerRefs: sectionData.headerRefs,
55066
55321
  footerRefs: sectionData.footerRefs,
55067
- numbering: sectionData.numbering
55322
+ numbering: sectionData.numbering,
55323
+ vAlign: sectionData.vAlign
55068
55324
  };
55069
55325
  ranges.push(range2);
55070
55326
  currentStart = item.index + 1;
@@ -55103,7 +55359,8 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
55103
55359
  type: bodySectionData.type ?? DEFAULT_BODY_SECTION_TYPE,
55104
55360
  titlePg: bodySectionData.titlePg ?? false,
55105
55361
  headerRefs: bodySectionData.headerRefs,
55106
- footerRefs: bodySectionData.footerRefs
55362
+ footerRefs: bodySectionData.footerRefs,
55363
+ vAlign: bodySectionData.vAlign
55107
55364
  };
55108
55365
  }
55109
55366
  function createDefaultFinalSection(currentStart, totalParagraphs, sectionIndex) {
@@ -56766,8 +57023,9 @@ const normalizeOoxmlTabs = (tabs) => {
56766
57023
  for (const entry of tabs) {
56767
57024
  if (!entry || typeof entry !== "object") continue;
56768
57025
  const rawEntry = entry;
56769
- const source = rawEntry.tab && typeof rawEntry.tab === "object" ? rawEntry.tab : rawEntry;
56770
- const posTwips = resolveTabPosition(source);
57026
+ const isNestedTab = Boolean(rawEntry.tab && typeof rawEntry.tab === "object");
57027
+ const source = isNestedTab ? rawEntry.tab : rawEntry;
57028
+ const posTwips = resolveTabPosition(source, isNestedTab);
56771
57029
  if (posTwips == null) continue;
56772
57030
  const val = normalizeTabVal(source.val ?? source.align ?? source.alignment ?? source.type ?? source.tabType);
56773
57031
  if (!val) continue;
@@ -56781,7 +57039,7 @@ const normalizeOoxmlTabs = (tabs) => {
56781
57039
  }
56782
57040
  return normalized.length > 0 ? normalized : void 0;
56783
57041
  };
56784
- const resolveTabPosition = (source) => {
57042
+ const resolveTabPosition = (source, treatPosAsTwips = false) => {
56785
57043
  const originalPos = pickNumber(source.originalPos);
56786
57044
  if (originalPos != null) {
56787
57045
  return originalPos;
@@ -56790,6 +57048,9 @@ const resolveTabPosition = (source) => {
56790
57048
  if (posValue == null) {
56791
57049
  return void 0;
56792
57050
  }
57051
+ if (treatPosAsTwips) {
57052
+ return posValue;
57053
+ }
56793
57054
  if (posValue > TWIPS_THRESHOLD) {
56794
57055
  return posValue;
56795
57056
  } else {
@@ -58777,19 +59038,21 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
58777
59038
  }
58778
59039
  const tabObj = tab;
58779
59040
  const val = typeof tabObj.tabType === "string" ? tabObj.tabType : typeof tabObj.val === "string" ? tabObj.val : void 0;
58780
- const pos = pickNumber(tabObj.originalPos ?? tabObj.pos);
59041
+ const originalPos = pickNumber(tabObj.originalPos);
59042
+ const pos = originalPos ?? pickNumber(tabObj.pos);
58781
59043
  if (!val || pos == null) {
58782
59044
  continue;
58783
59045
  }
58784
59046
  const normalized = { val, pos };
59047
+ if (originalPos != null && Number.isFinite(originalPos)) {
59048
+ normalized.originalPos = originalPos;
59049
+ } else {
59050
+ normalized.originalPos = pos;
59051
+ }
58785
59052
  const leader = tabObj.leader;
58786
59053
  if (typeof leader === "string" && leader.length > 0) {
58787
59054
  normalized.leader = leader;
58788
59055
  }
58789
- const originalPos = pickNumber(tabObj.originalPos);
58790
- if (originalPos != null && Number.isFinite(originalPos)) {
58791
- normalized.originalPos = originalPos;
58792
- }
58793
59056
  unwrapped.push(normalized);
58794
59057
  continue;
58795
59058
  }
@@ -59631,11 +59894,11 @@ const applyLinkedStyleToRun = (run2, options) => {
59631
59894
  if (!maps.length) return;
59632
59895
  const finalStyles = Object.assign({}, ...maps);
59633
59896
  const fontFamily2 = extractValue(finalStyles["font-family"]);
59634
- if (typeof fontFamily2 === "string" && fontFamily2 && run2.fontFamily === options.defaultFont) {
59897
+ if (typeof fontFamily2 === "string" && fontFamily2) {
59635
59898
  run2.fontFamily = fontFamily2;
59636
59899
  }
59637
59900
  const fontSize2 = toPxNumber(finalStyles["font-size"]);
59638
- if (fontSize2 != null && run2.fontSize === options.defaultSize) {
59901
+ if (fontSize2 != null) {
59639
59902
  run2.fontSize = fontSize2;
59640
59903
  }
59641
59904
  const letterSpacing = toPxNumber(finalStyles["letter-spacing"]);
@@ -59998,9 +60261,7 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
59998
60261
  resolver: linkedStyleResolver,
59999
60262
  paragraphStyleId,
60000
60263
  inlineStyleId,
60001
- runStyleId,
60002
- defaultFont,
60003
- defaultSize
60264
+ runStyleId
60004
60265
  });
60005
60266
  };
60006
60267
  const visitNode = (node, inheritedMarks = [], activeSdt, activeRunStyleId = null) => {
@@ -60010,7 +60271,8 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
60010
60271
  positions,
60011
60272
  defaultFont,
60012
60273
  defaultSize,
60013
- inheritedMarks,
60274
+ [],
60275
+ // Empty marks - will be applied after linked styles
60014
60276
  activeSdt,
60015
60277
  hyperlinkConfig,
60016
60278
  themeColors
@@ -60018,6 +60280,7 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
60018
60280
  const inlineStyleId = getInlineStyleId(inheritedMarks);
60019
60281
  applyRunStyles2(run2, inlineStyleId, activeRunStyleId);
60020
60282
  applyBaseRunDefaults(run2, baseRunDefaults, defaultFont, defaultSize);
60283
+ applyMarksToRun(run2, [...node.marks ?? [], ...inheritedMarks ?? []], hyperlinkConfig, themeColors);
60021
60284
  currentRuns.push(run2);
60022
60285
  return;
60023
60286
  }
@@ -61892,13 +62155,14 @@ function processFragment(fragmentEl, viewX, viewY) {
61892
62155
  if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
61893
62156
  return null;
61894
62157
  }
61895
- const spanEls = Array.from(lineEl.querySelectorAll("span"));
62158
+ const spanEls = Array.from(lineEl.querySelectorAll("span, a"));
61896
62159
  log(
61897
- "Spans in line:",
62160
+ "Spans/anchors in line:",
61898
62161
  spanEls.map((el, i) => {
61899
62162
  const rect = el.getBoundingClientRect();
61900
62163
  return {
61901
62164
  index: i,
62165
+ tag: el.tagName,
61902
62166
  pmStart: el.dataset.pmStart,
61903
62167
  pmEnd: el.dataset.pmEnd,
61904
62168
  text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
@@ -61918,32 +62182,33 @@ function processFragment(fragmentEl, viewX, viewY) {
61918
62182
  if (viewX >= lastRect.right) {
61919
62183
  return lineEnd;
61920
62184
  }
61921
- const targetSpan = findSpanAtX(spanEls, viewX);
61922
- if (!targetSpan) {
62185
+ const targetEl = findSpanAtX(spanEls, viewX);
62186
+ if (!targetEl) {
61923
62187
  return lineStart;
61924
62188
  }
61925
- const spanStart = Number(targetSpan.dataset.pmStart ?? "NaN");
61926
- const spanEnd = Number(targetSpan.dataset.pmEnd ?? "NaN");
61927
- const targetRect = targetSpan.getBoundingClientRect();
61928
- log("Target span:", {
62189
+ const spanStart = Number(targetEl.dataset.pmStart ?? "NaN");
62190
+ const spanEnd = Number(targetEl.dataset.pmEnd ?? "NaN");
62191
+ const targetRect = targetEl.getBoundingClientRect();
62192
+ log("Target element:", {
62193
+ tag: targetEl.tagName,
61929
62194
  pmStart: spanStart,
61930
62195
  pmEnd: spanEnd,
61931
- text: targetSpan.textContent?.substring(0, 30),
61932
- visibility: targetSpan.style.visibility,
62196
+ text: targetEl.textContent?.substring(0, 30),
62197
+ visibility: targetEl.style.visibility,
61933
62198
  rect: { left: targetRect.left, right: targetRect.right, width: targetRect.width }
61934
62199
  });
61935
62200
  if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) {
61936
62201
  return null;
61937
62202
  }
61938
- const firstChild = targetSpan.firstChild;
62203
+ const firstChild = targetEl.firstChild;
61939
62204
  if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
61940
- const spanRect = targetSpan.getBoundingClientRect();
61941
- const closerToLeft = Math.abs(viewX - spanRect.left) <= Math.abs(viewX - spanRect.right);
62205
+ const elRect = targetEl.getBoundingClientRect();
62206
+ const closerToLeft = Math.abs(viewX - elRect.left) <= Math.abs(viewX - elRect.right);
61942
62207
  const snapPos = closerToLeft ? spanStart : spanEnd;
61943
62208
  return snapPos;
61944
62209
  }
61945
62210
  const textNode = firstChild;
61946
- const charIndex = findCharIndexAtX(textNode, targetSpan, viewX);
62211
+ const charIndex = findCharIndexAtX(textNode, targetEl, viewX);
61947
62212
  const pos = spanStart + charIndex;
61948
62213
  return pos;
61949
62214
  }
@@ -61981,7 +62246,8 @@ function findSpanAtX(spanEls, viewX) {
61981
62246
  const span = spanEls[i];
61982
62247
  const rect = span.getBoundingClientRect();
61983
62248
  if (viewX >= rect.left && viewX <= rect.right) {
61984
- log("findSpanAtX: Found containing span at index", i, {
62249
+ log("findSpanAtX: Found containing element at index", i, {
62250
+ tag: span.tagName,
61985
62251
  pmStart: span.dataset.pmStart,
61986
62252
  pmEnd: span.dataset.pmEnd,
61987
62253
  rect: { left: rect.left, right: rect.right },
@@ -61993,16 +62259,17 @@ function findSpanAtX(spanEls, viewX) {
61993
62259
  targetSpan = span;
61994
62260
  }
61995
62261
  }
61996
- log("findSpanAtX: No containing span, using nearest:", {
62262
+ log("findSpanAtX: No containing element, using nearest:", {
62263
+ tag: targetSpan.tagName,
61997
62264
  pmStart: targetSpan.dataset.pmStart,
61998
62265
  pmEnd: targetSpan.dataset.pmEnd,
61999
62266
  viewX
62000
62267
  });
62001
62268
  return targetSpan;
62002
62269
  }
62003
- function findCharIndexAtX(textNode, span, targetX) {
62270
+ function findCharIndexAtX(textNode, container, targetX) {
62004
62271
  const text = textNode.textContent ?? "";
62005
- const baseLeft = span.getBoundingClientRect().left;
62272
+ const baseLeft = container.getBoundingClientRect().left;
62006
62273
  const range2 = document.createRange();
62007
62274
  let lo = 0;
62008
62275
  let hi = text.length;
@@ -62334,6 +62601,9 @@ function computeNextSectionPropsAtBreak(blocks) {
62334
62601
  if (source.orientation) {
62335
62602
  props.orientation = source.orientation;
62336
62603
  }
62604
+ if (source.vAlign) {
62605
+ props.vAlign = source.vAlign;
62606
+ }
62337
62607
  return props;
62338
62608
  };
62339
62609
  docxBreakIndexes.forEach((index2, ordinal) => {
@@ -63734,6 +64004,10 @@ function cloneBlockWithResolvedTokens(block, displayPageText, totalPagesStr) {
63734
64004
  runs: clonedRuns
63735
64005
  };
63736
64006
  }
64007
+ const DEFAULT_PARAGRAPH_LINE_HEIGHT_PX = 20;
64008
+ function hasHeight(fragment) {
64009
+ return fragment.kind === "image" || fragment.kind === "drawing" || fragment.kind === "table";
64010
+ }
63737
64011
  const DEFAULT_PAGE_SIZE$2 = { w: 612, h: 792 };
63738
64012
  const DEFAULT_MARGINS$2 = { top: 72, right: 72, bottom: 72, left: 72 };
63739
64013
  const COLUMN_EPSILON = 1e-4;
@@ -63828,6 +64102,8 @@ function layoutDocument(blocks, measures, options = {}) {
63828
64102
  let pendingColumns = null;
63829
64103
  let activeOrientation = null;
63830
64104
  let pendingOrientation = null;
64105
+ let activeVAlign = null;
64106
+ let pendingVAlign = null;
63831
64107
  const floatManager = createFloatingObjectManager(
63832
64108
  normalizeColumns(activeColumns, contentWidth),
63833
64109
  { left: margins.left, right: margins.right },
@@ -63933,6 +64209,9 @@ function layoutDocument(blocks, measures, options = {}) {
63933
64209
  if (activeOrientation) {
63934
64210
  page.orientation = activeOrientation;
63935
64211
  }
64212
+ if (activeVAlign && activeVAlign !== "top") {
64213
+ page.vAlign = activeVAlign;
64214
+ }
63936
64215
  return page;
63937
64216
  };
63938
64217
  let pageCount = 0;
@@ -64011,6 +64290,10 @@ function layoutDocument(blocks, measures, options = {}) {
64011
64290
  activeSectionRefs = pendingSectionRefs;
64012
64291
  pendingSectionRefs = null;
64013
64292
  }
64293
+ if (pendingVAlign !== null) {
64294
+ activeVAlign = pendingVAlign;
64295
+ pendingVAlign = null;
64296
+ }
64014
64297
  pageCount += 1;
64015
64298
  return;
64016
64299
  }
@@ -64147,7 +64430,8 @@ function layoutDocument(blocks, measures, options = {}) {
64147
64430
  margins: ahead.margins ? { ...effectiveBlock.margins ?? {}, ...ahead.margins } : effectiveBlock.margins ?? {},
64148
64431
  pageSize: ahead.pageSize ?? effectiveBlock.pageSize,
64149
64432
  columns: ahead.columns ?? effectiveBlock.columns,
64150
- orientation: ahead.orientation ?? effectiveBlock.orientation
64433
+ orientation: ahead.orientation ?? effectiveBlock.orientation,
64434
+ vAlign: ahead.vAlign ?? effectiveBlock.vAlign
64151
64435
  };
64152
64436
  }
64153
64437
  const sectionState = {
@@ -64200,6 +64484,15 @@ function layoutDocument(blocks, measures, options = {}) {
64200
64484
  pendingColumns = updatedState.pendingColumns;
64201
64485
  activeOrientation = updatedState.activeOrientation;
64202
64486
  pendingOrientation = updatedState.pendingOrientation;
64487
+ if (effectiveBlock.vAlign) {
64488
+ const isFirstSection = effectiveBlock.attrs?.isFirstSection && states.length === 0;
64489
+ if (isFirstSection) {
64490
+ activeVAlign = effectiveBlock.vAlign;
64491
+ pendingVAlign = null;
64492
+ } else {
64493
+ pendingVAlign = effectiveBlock.vAlign;
64494
+ }
64495
+ }
64203
64496
  if (effectiveBlock.headerRefs || effectiveBlock.footerRefs) {
64204
64497
  pendingSectionRefs = {
64205
64498
  ...effectiveBlock.headerRefs && { headerRefs: effectiveBlock.headerRefs },
@@ -64208,8 +64501,17 @@ function layoutDocument(blocks, measures, options = {}) {
64208
64501
  layoutLog(`[Layout] After scheduleSectionBreakCompat: Scheduled pendingSectionRefs:`, pendingSectionRefs);
64209
64502
  }
64210
64503
  if (breakInfo.forceMidPageRegion && block.columns) {
64211
- const state2 = paginator.ensurePage();
64212
- startMidPageRegion(state2, { count: block.columns.count, gap: block.columns.gap });
64504
+ let state2 = paginator.ensurePage();
64505
+ const columnIndexBefore = state2.columnIndex;
64506
+ const rawCount = block.columns.count;
64507
+ const validatedCount = typeof rawCount === "number" && Number.isFinite(rawCount) && rawCount > 0 ? Math.max(1, Math.floor(rawCount)) : 1;
64508
+ const rawGap = block.columns.gap;
64509
+ const validatedGap = typeof rawGap === "number" && Number.isFinite(rawGap) && rawGap >= 0 ? Math.max(0, rawGap) : 0;
64510
+ const newColumns = { count: validatedCount, gap: validatedGap };
64511
+ if (columnIndexBefore >= newColumns.count) {
64512
+ state2 = paginator.startNewPage();
64513
+ }
64514
+ startMidPageRegion(state2, newColumns);
64213
64515
  }
64214
64516
  if (breakInfo.forcePageBreak) {
64215
64517
  let state2 = paginator.ensurePage();
@@ -64401,6 +64703,45 @@ function layoutDocument(blocks, measures, options = {}) {
64401
64703
  while (pages.length > 0 && pages[pages.length - 1].fragments.length === 0) {
64402
64704
  pages.pop();
64403
64705
  }
64706
+ for (const page of pages) {
64707
+ if (!page.vAlign || page.vAlign === "top") continue;
64708
+ if (page.fragments.length === 0) continue;
64709
+ const pageSizeForPage = page.size ?? pageSize;
64710
+ const contentTop = page.margins?.top ?? margins.top;
64711
+ const contentBottom = pageSizeForPage.h - (page.margins?.bottom ?? margins.bottom);
64712
+ const contentHeight = contentBottom - contentTop;
64713
+ let minY = Infinity;
64714
+ let maxY = -Infinity;
64715
+ for (const fragment of page.fragments) {
64716
+ if (fragment.y < minY) minY = fragment.y;
64717
+ let fragmentBottom = fragment.y;
64718
+ if (hasHeight(fragment)) {
64719
+ fragmentBottom += fragment.height;
64720
+ } else {
64721
+ const lineCount = fragment.toLine - fragment.fromLine;
64722
+ fragmentBottom += lineCount * DEFAULT_PARAGRAPH_LINE_HEIGHT_PX;
64723
+ }
64724
+ if (fragmentBottom > maxY) maxY = fragmentBottom;
64725
+ }
64726
+ const actualContentHeight = maxY - minY;
64727
+ const availableSpace = contentHeight - actualContentHeight;
64728
+ if (availableSpace <= 0) {
64729
+ continue;
64730
+ }
64731
+ let yOffset = 0;
64732
+ if (page.vAlign === "center") {
64733
+ yOffset = availableSpace / 2;
64734
+ } else if (page.vAlign === "bottom") {
64735
+ yOffset = availableSpace;
64736
+ } else if (page.vAlign === "both") {
64737
+ yOffset = availableSpace / 2;
64738
+ }
64739
+ if (yOffset > 0) {
64740
+ for (const fragment of page.fragments) {
64741
+ fragment.y += yOffset;
64742
+ }
64743
+ }
64744
+ }
64404
64745
  return {
64405
64746
  pageSize,
64406
64747
  pages,
@@ -68828,14 +69169,25 @@ const PRINT_STYLES = `
68828
69169
  }
68829
69170
  `;
68830
69171
  const LINK_AND_TOC_STYLES = `
68831
- /* Reset browser default link styling - allow run colors to show through */
69172
+ /* Reset browser default link styling - allow run colors to show through from inline styles
69173
+ *
69174
+ * Note: !important was removed from these rules to allow inline styles to take precedence.
69175
+ * This is necessary because OOXML hyperlink character styles apply colors via inline style
69176
+ * attributes on the run elements. The CSS cascade ensures that inline styles (applied via
69177
+ * element.style.color in applyRunStyles) override these class-based rules naturally.
69178
+ *
69179
+ * Implications:
69180
+ * - OOXML hyperlink character styles will correctly display their assigned colors
69181
+ * - Browser default link colors are still reset by these inherit rules
69182
+ * - Inline color styles from run objects override the inherit value as expected
69183
+ */
68832
69184
  .superdoc-link {
68833
- color: inherit !important;
68834
- text-decoration: none !important;
69185
+ color: inherit;
69186
+ text-decoration: none;
68835
69187
  }
68836
69188
 
68837
69189
  .superdoc-link:visited {
68838
- color: inherit !important;
69190
+ color: inherit;
68839
69191
  }
68840
69192
 
68841
69193
  .superdoc-link:hover {
@@ -70374,14 +70726,23 @@ const _DomPainter = class _DomPainter2 {
70374
70726
  lines.forEach((line, index2) => {
70375
70727
  const lineEl = this.renderLine(block, line, context);
70376
70728
  const isListFirstLine = index2 === 0 && !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker;
70377
- if (paraIndentLeft && !isListFirstLine) {
70378
- lineEl.style.paddingLeft = `${paraIndentLeft}px`;
70729
+ const hasExplicitSegmentPositioning = line.segments?.some((seg) => seg.x !== void 0);
70730
+ const isFirstLine = index2 === 0 && !fragment.continuesFromPrev;
70731
+ if (!isListFirstLine) {
70732
+ if (isFirstLine && hasExplicitSegmentPositioning && firstLineOffset !== 0) {
70733
+ const adjustedPadding = paraIndentLeft + firstLineOffset;
70734
+ lineEl.style.paddingLeft = `${adjustedPadding}px`;
70735
+ } else if (paraIndentLeft) {
70736
+ lineEl.style.paddingLeft = `${paraIndentLeft}px`;
70737
+ }
70379
70738
  }
70380
70739
  if (paraIndentRight) {
70381
70740
  lineEl.style.paddingRight = `${paraIndentRight}px`;
70382
70741
  }
70383
70742
  if (!fragment.continuesFromPrev && index2 === 0 && firstLineOffset && !isListFirstLine) {
70384
- lineEl.style.textIndent = `${firstLineOffset}px`;
70743
+ if (!hasExplicitSegmentPositioning) {
70744
+ lineEl.style.textIndent = `${firstLineOffset}px`;
70745
+ }
70385
70746
  } else if (firstLineOffset && !isListFirstLine) {
70386
70747
  lineEl.style.textIndent = "0px";
70387
70748
  }
@@ -71275,6 +71636,24 @@ const _DomPainter = class _DomPainter2 {
71275
71636
  }
71276
71637
  elem.setAttribute("role", "link");
71277
71638
  elem.setAttribute("tabindex", "0");
71639
+ elem.addEventListener("click", (event) => {
71640
+ event.preventDefault();
71641
+ event.stopPropagation();
71642
+ const linkClickEvent = new CustomEvent("superdoc-link-click", {
71643
+ bubbles: true,
71644
+ composed: true,
71645
+ detail: {
71646
+ href: linkData.href,
71647
+ target: linkData.target,
71648
+ rel: linkData.rel,
71649
+ tooltip: linkData.tooltip,
71650
+ element: elem,
71651
+ clientX: event.clientX,
71652
+ clientY: event.clientY
71653
+ }
71654
+ });
71655
+ elem.dispatchEvent(linkClickEvent);
71656
+ });
71278
71657
  }
71279
71658
  /**
71280
71659
  * Render a single run as an HTML element (span or anchor).
@@ -71564,7 +71943,13 @@ const _DomPainter = class _DomPainter2 {
71564
71943
  if (styleId) {
71565
71944
  elem.setAttribute("styleid", styleId);
71566
71945
  }
71946
+ const runSegments2 = segmentsByRun.get(runIndex);
71947
+ const segX = runSegments2 && runSegments2[0]?.x !== void 0 ? runSegments2[0].x : cumulativeX;
71948
+ const segWidth = (runSegments2 && runSegments2[0]?.width !== void 0 ? runSegments2[0].width : elem.offsetWidth) ?? 0;
71949
+ elem.style.position = "absolute";
71950
+ elem.style.left = `${segX}px`;
71567
71951
  el.appendChild(elem);
71952
+ cumulativeX = segX + segWidth;
71568
71953
  }
71569
71954
  continue;
71570
71955
  }
@@ -72106,7 +72491,7 @@ const deriveBlockVersion = (block) => {
72106
72491
  }
72107
72492
  return block.id;
72108
72493
  };
72109
- const applyRunStyles = (element, run2, isLink = false) => {
72494
+ const applyRunStyles = (element, run2, _isLink = false) => {
72110
72495
  if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break") {
72111
72496
  return;
72112
72497
  }
@@ -72114,9 +72499,7 @@ const applyRunStyles = (element, run2, isLink = false) => {
72114
72499
  element.style.fontSize = `${run2.fontSize}px`;
72115
72500
  if (run2.bold) element.style.fontWeight = "bold";
72116
72501
  if (run2.italic) element.style.fontStyle = "italic";
72117
- if (!isLink) {
72118
- if (run2.color) element.style.color = run2.color;
72119
- }
72502
+ if (run2.color) element.style.color = run2.color;
72120
72503
  if (run2.letterSpacing != null) {
72121
72504
  element.style.letterSpacing = `${run2.letterSpacing}px`;
72122
72505
  }
@@ -72664,28 +73047,44 @@ async function measureParagraphBlock(block, maxWidth) {
72664
73047
  }
72665
73048
  return true;
72666
73049
  };
72667
- const alignSegmentAtTab = (segmentText, font, runContext) => {
72668
- if (!pendingTabAlignment || !currentLine) return;
73050
+ const alignPendingTabForWidth = (segmentWidth, beforeDecimalWidth) => {
73051
+ if (!pendingTabAlignment || !currentLine) return void 0;
73052
+ if (segmentWidth < 0) {
73053
+ segmentWidth = 0;
73054
+ }
72669
73055
  const { target, val } = pendingTabAlignment;
72670
73056
  let startX = currentLine.width;
73057
+ if (val === "decimal") {
73058
+ const beforeWidth = beforeDecimalWidth ?? 0;
73059
+ startX = Math.max(0, target - beforeWidth);
73060
+ } else if (val === "end") {
73061
+ startX = Math.max(0, target - segmentWidth);
73062
+ } else if (val === "center") {
73063
+ startX = Math.max(0, target - segmentWidth / 2);
73064
+ } else {
73065
+ startX = Math.max(0, target);
73066
+ }
73067
+ currentLine.width = roundValue(startX);
73068
+ lastAppliedTabAlign = { target, val };
73069
+ pendingTabAlignment = null;
73070
+ return startX;
73071
+ };
73072
+ const alignSegmentAtTab = (segmentText, font, runContext) => {
73073
+ if (!pendingTabAlignment || !currentLine) return void 0;
73074
+ const { val } = pendingTabAlignment;
73075
+ let segmentWidth = 0;
73076
+ let beforeDecimalWidth;
72671
73077
  if (val === "decimal") {
72672
73078
  const idx = segmentText.indexOf(decimalSeparator);
72673
73079
  if (idx >= 0) {
72674
73080
  const beforeText = segmentText.slice(0, idx);
72675
- const beforeWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
72676
- startX = Math.max(0, target - beforeWidth);
72677
- } else {
72678
- startX = Math.max(0, target);
73081
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
72679
73082
  }
73083
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
72680
73084
  } else if (val === "end" || val === "center") {
72681
- const segWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
72682
- startX = val === "end" ? Math.max(0, target - segWidth) : Math.max(0, target - segWidth / 2);
72683
- } else if (val === "start" || val === "bar") {
72684
- startX = Math.max(0, target);
73085
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
72685
73086
  }
72686
- currentLine.width = roundValue(startX);
72687
- lastAppliedTabAlign = { target, val };
72688
- pendingTabAlignment = null;
73087
+ return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
72689
73088
  };
72690
73089
  const runsToProcess = [];
72691
73090
  for (const run2 of block.runs) {
@@ -72834,6 +73233,10 @@ async function measureParagraphBlock(block, maxWidth) {
72834
73233
  const topSpace = run2.distTop ?? 0;
72835
73234
  const bottomSpace = run2.distBottom ?? 0;
72836
73235
  const imageHeight = run2.height + topSpace + bottomSpace;
73236
+ let imageStartX;
73237
+ if (pendingTabAlignment && currentLine) {
73238
+ imageStartX = alignPendingTabForWidth(imageWidth);
73239
+ }
72837
73240
  if (!currentLine) {
72838
73241
  currentLine = {
72839
73242
  fromRun: runIndex,
@@ -72850,12 +73253,14 @@ async function measureParagraphBlock(block, maxWidth) {
72850
73253
  runIndex,
72851
73254
  fromChar: 0,
72852
73255
  toChar: 1,
72853
- width: imageWidth
73256
+ width: imageWidth,
73257
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
72854
73258
  }
72855
73259
  ]
72856
73260
  };
72857
73261
  continue;
72858
73262
  }
73263
+ const appliedTabAlign = lastAppliedTabAlign;
72859
73264
  if (currentLine.width + imageWidth > currentLine.maxWidth && currentLine.width > 0) {
72860
73265
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
72861
73266
  const completedLine = {
@@ -72866,6 +73271,7 @@ async function measureParagraphBlock(block, maxWidth) {
72866
73271
  lines.push(completedLine);
72867
73272
  tabStopCursor = 0;
72868
73273
  pendingTabAlignment = null;
73274
+ lastAppliedTabAlign = null;
72869
73275
  currentLine = {
72870
73276
  fromRun: runIndex,
72871
73277
  fromChar: 0,
@@ -72893,9 +73299,15 @@ async function measureParagraphBlock(block, maxWidth) {
72893
73299
  runIndex,
72894
73300
  fromChar: 0,
72895
73301
  toChar: 1,
72896
- width: imageWidth
73302
+ width: imageWidth,
73303
+ ...imageStartX !== void 0 ? { x: imageStartX } : {}
72897
73304
  });
72898
73305
  }
73306
+ const tabAlign = appliedTabAlign;
73307
+ if (tabAlign && currentLine && tabAlign.val === "end") {
73308
+ currentLine.width = roundValue(tabAlign.target);
73309
+ }
73310
+ lastAppliedTabAlign = null;
72899
73311
  continue;
72900
73312
  }
72901
73313
  if (!("text" in run2) || !("fontSize" in run2)) {
@@ -72911,8 +73323,10 @@ async function measureParagraphBlock(block, maxWidth) {
72911
73323
  const words = segment.split(" ");
72912
73324
  let segmentStartX;
72913
73325
  if (currentLine && pendingTabAlignment) {
72914
- alignSegmentAtTab(segment, font, run2);
72915
- segmentStartX = currentLine.width;
73326
+ segmentStartX = alignSegmentAtTab(segment, font, run2);
73327
+ if (segmentStartX == null) {
73328
+ segmentStartX = currentLine.width;
73329
+ }
72916
73330
  }
72917
73331
  for (let wordIndex = 0; wordIndex < words.length; wordIndex++) {
72918
73332
  const word = words[wordIndex];
@@ -73553,12 +73967,49 @@ const createHeaderFooterEditor = ({
73553
73967
  editor,
73554
73968
  data,
73555
73969
  editorContainer,
73556
- appendToBody = true,
73970
+ editorHost,
73557
73971
  sectionId,
73558
73972
  type: type2,
73973
+ availableWidth,
73559
73974
  availableHeight,
73560
- currentPageNumber
73975
+ currentPageNumber,
73976
+ totalPageCount
73561
73977
  }) => {
73978
+ if (!editor) {
73979
+ throw new TypeError("editor parameter is required");
73980
+ }
73981
+ if (!data) {
73982
+ throw new TypeError("data parameter is required");
73983
+ }
73984
+ if (!editorContainer) {
73985
+ throw new TypeError("editorContainer parameter is required");
73986
+ }
73987
+ if (!(editorContainer instanceof HTMLElement)) {
73988
+ throw new TypeError("editorContainer must be an HTMLElement");
73989
+ }
73990
+ if (editorHost !== void 0 && !(editorHost instanceof HTMLElement)) {
73991
+ throw new TypeError("editorHost must be an HTMLElement or undefined");
73992
+ }
73993
+ if (availableWidth !== void 0) {
73994
+ if (typeof availableWidth !== "number" || !Number.isFinite(availableWidth) || availableWidth <= 0) {
73995
+ throw new RangeError("availableWidth must be a positive number");
73996
+ }
73997
+ }
73998
+ if (availableHeight !== void 0) {
73999
+ if (typeof availableHeight !== "number" || !Number.isFinite(availableHeight) || availableHeight <= 0) {
74000
+ throw new RangeError("availableHeight must be a positive number");
74001
+ }
74002
+ }
74003
+ if (currentPageNumber !== void 0) {
74004
+ if (typeof currentPageNumber !== "number" || !Number.isInteger(currentPageNumber) || currentPageNumber < 1) {
74005
+ throw new RangeError("currentPageNumber must be a positive integer");
74006
+ }
74007
+ }
74008
+ if (totalPageCount !== void 0) {
74009
+ if (typeof totalPageCount !== "number" || !Number.isInteger(totalPageCount) || totalPageCount < 1) {
74010
+ throw new RangeError("totalPageCount must be a positive integer");
74011
+ }
74012
+ }
73562
74013
  const parentStyles = editor.converter.getDocumentDefaultStyles();
73563
74014
  const { fontSizePt, typeface, fontFamilyCss } = parentStyles;
73564
74015
  const fontSizeInPixles = fontSizePt * 1.3333;
@@ -73572,21 +74023,24 @@ const createHeaderFooterEditor = ({
73572
74023
  position: "absolute",
73573
74024
  top: "0",
73574
74025
  left: "0",
73575
- width: "auto",
74026
+ width: availableWidth ? `${availableWidth}px` : "100%",
74027
+ height: availableHeight ? `${availableHeight}px` : "auto",
73576
74028
  maxWidth: "none",
73577
74029
  fontFamily: fontFamilyCss || typeface,
73578
74030
  fontSize: `${fontSizeInPixles}px`,
73579
- lineHeight: `${lineHeight2}px`
73580
- });
73581
- Object.assign(editorContainer.style, {
73582
- padding: "0",
73583
- margin: "0",
73584
- border: "none",
73585
- boxSizing: "border-box",
73586
- height: availableHeight + "px",
73587
- overflow: "hidden"
73588
- });
73589
- if (appendToBody) document.body.appendChild(editorContainer);
74031
+ lineHeight: `${lineHeight2}px`,
74032
+ overflow: "hidden",
74033
+ pointerEvents: "auto",
74034
+ // Critical: enables click interaction
74035
+ backgroundColor: "white"
74036
+ // Ensure editor has white background
74037
+ });
74038
+ if (editorHost) {
74039
+ editorHost.appendChild(editorContainer);
74040
+ } else {
74041
+ console.warn("[createHeaderFooterEditor] No editorHost provided, falling back to document.body");
74042
+ document.body.appendChild(editorContainer);
74043
+ }
73590
74044
  const headerFooterEditor = new Editor({
73591
74045
  role: editor.options.role,
73592
74046
  loadFromSchema: true,
@@ -73604,9 +74058,12 @@ const createHeaderFooterEditor = ({
73604
74058
  pagination: false,
73605
74059
  // Explicitly disable pagination
73606
74060
  annotations: true,
73607
- currentPageNumber,
74061
+ currentPageNumber: currentPageNumber ?? 1,
74062
+ totalPageCount: totalPageCount ?? 1,
73608
74063
  // Don't set parentEditor to avoid circular reference issues
73609
74064
  // parentEditor: editor,
74065
+ // IMPORTANT: Start with editable: false to prevent triggering update cascades during creation.
74066
+ // PresentationEditor#enterHeaderFooterMode will call setEditable(true) when entering edit mode.
73610
74067
  editable: false,
73611
74068
  documentMode: "viewing",
73612
74069
  onCreate: (evt) => setEditorToolbar(evt, editor),
@@ -73636,18 +74093,23 @@ const createHeaderFooterEditor = ({
73636
74093
  const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sectionId, type2) => {
73637
74094
  if (!type2 || !sectionId) return;
73638
74095
  const updatedData = editor.getUpdatedJson();
73639
- mainEditor.converter[`${type2}Editors`].forEach((item) => {
73640
- if (item.id === sectionId) {
74096
+ const editorsList = mainEditor.converter[`${type2}Editors`];
74097
+ if (Array.isArray(editorsList)) {
74098
+ editorsList.forEach((item) => {
74099
+ if (item.id === sectionId) {
74100
+ item.editor.setOptions({
74101
+ media: editor.options.media,
74102
+ mediaFiles: editor.options.mediaFiles
74103
+ });
74104
+ if (item.editor !== editor) {
74105
+ item.editor.replaceContent(updatedData);
74106
+ }
74107
+ }
73641
74108
  item.editor.setOptions({
73642
- media: editor.options.media,
73643
- mediaFiles: editor.options.mediaFiles
74109
+ lastSelection: transaction?.selection
73644
74110
  });
73645
- item.editor.replaceContent(updatedData);
73646
- }
73647
- item.editor.setOptions({
73648
- lastSelection: transaction?.selection
73649
74111
  });
73650
- });
74112
+ }
73651
74113
  mainEditor.converter[`${type2}s`][sectionId] = updatedData;
73652
74114
  mainEditor.setOptions({ isHeaderFooterChanged: editor.docChanged });
73653
74115
  await updateYdocDocxData(mainEditor);
@@ -73728,13 +74190,69 @@ class HeaderFooterEditorManager extends EventEmitter$1 {
73728
74190
  * Handles concurrent calls for the same descriptor by tracking pending creations
73729
74191
  * and returning the same promise to all callers.
73730
74192
  *
73731
- * @param descriptor - The header or footer descriptor
74193
+ * @param descriptor - The header or footer descriptor. Must have a valid id property.
74194
+ * @param options - Optional configuration for editor creation
74195
+ * @param options.editorHost - The HTMLElement to mount the editor in. If provided, must be a valid HTMLElement.
74196
+ * @param options.availableWidth - The width of the editing region in pixels. Must be a positive number if provided.
74197
+ * @param options.availableHeight - The height of the editing region in pixels. Must be a positive number if provided.
74198
+ * @param options.currentPageNumber - The current page number for PAGE field resolution. Must be a positive integer if provided.
74199
+ * @param options.totalPageCount - The total page count for NUMPAGES field resolution. Must be a positive integer if provided.
73732
74200
  * @returns The editor instance, or null if creation failed
73733
74201
  *
73734
- * @throws Never throws - errors are logged and emitted as events
74202
+ * @throws Never throws - errors are logged and emitted as events. Invalid parameters return null with error logged.
73735
74203
  */
73736
- async ensureEditor(descriptor) {
74204
+ async ensureEditor(descriptor, options) {
73737
74205
  if (!descriptor?.id) return null;
74206
+ if (options) {
74207
+ if (options.editorHost !== void 0 && !(options.editorHost instanceof HTMLElement)) {
74208
+ console.error("[HeaderFooterEditorManager] editorHost must be an HTMLElement");
74209
+ this.emit("error", {
74210
+ descriptor,
74211
+ error: new TypeError("editorHost must be an HTMLElement")
74212
+ });
74213
+ return null;
74214
+ }
74215
+ if (options.availableWidth !== void 0) {
74216
+ if (typeof options.availableWidth !== "number" || !Number.isFinite(options.availableWidth) || options.availableWidth <= 0) {
74217
+ console.error("[HeaderFooterEditorManager] availableWidth must be a positive number");
74218
+ this.emit("error", {
74219
+ descriptor,
74220
+ error: new TypeError("availableWidth must be a positive number")
74221
+ });
74222
+ return null;
74223
+ }
74224
+ }
74225
+ if (options.availableHeight !== void 0) {
74226
+ if (typeof options.availableHeight !== "number" || !Number.isFinite(options.availableHeight) || options.availableHeight <= 0) {
74227
+ console.error("[HeaderFooterEditorManager] availableHeight must be a positive number");
74228
+ this.emit("error", {
74229
+ descriptor,
74230
+ error: new TypeError("availableHeight must be a positive number")
74231
+ });
74232
+ return null;
74233
+ }
74234
+ }
74235
+ if (options.currentPageNumber !== void 0) {
74236
+ if (typeof options.currentPageNumber !== "number" || !Number.isInteger(options.currentPageNumber) || options.currentPageNumber < 1) {
74237
+ console.error("[HeaderFooterEditorManager] currentPageNumber must be a positive integer");
74238
+ this.emit("error", {
74239
+ descriptor,
74240
+ error: new TypeError("currentPageNumber must be a positive integer")
74241
+ });
74242
+ return null;
74243
+ }
74244
+ }
74245
+ if (options.totalPageCount !== void 0) {
74246
+ if (typeof options.totalPageCount !== "number" || !Number.isInteger(options.totalPageCount) || options.totalPageCount < 1) {
74247
+ console.error("[HeaderFooterEditorManager] totalPageCount must be a positive integer");
74248
+ this.emit("error", {
74249
+ descriptor,
74250
+ error: new TypeError("totalPageCount must be a positive integer")
74251
+ });
74252
+ return null;
74253
+ }
74254
+ }
74255
+ }
73738
74256
  const existing = __privateGet$1(this, _editorEntries).get(descriptor.id);
73739
74257
  if (existing) {
73740
74258
  __privateSet(this, _cacheHits, __privateGet$1(this, _cacheHits) + 1);
@@ -73743,6 +74261,29 @@ class HeaderFooterEditorManager extends EventEmitter$1 {
73743
74261
  console.error("[HeaderFooterEditorManager] Editor initialization failed:", error);
73744
74262
  this.emit("error", { descriptor, error });
73745
74263
  });
74264
+ if (existing.container && options?.editorHost) {
74265
+ if (existing.container.parentElement !== options.editorHost) {
74266
+ options.editorHost.appendChild(existing.container);
74267
+ }
74268
+ }
74269
+ if (existing.editor && options) {
74270
+ const updateOptions = {};
74271
+ if (options.currentPageNumber !== void 0) {
74272
+ updateOptions.currentPageNumber = options.currentPageNumber;
74273
+ }
74274
+ if (options.totalPageCount !== void 0) {
74275
+ updateOptions.totalPageCount = options.totalPageCount;
74276
+ }
74277
+ if (options.availableWidth !== void 0) {
74278
+ updateOptions.availableWidth = options.availableWidth;
74279
+ }
74280
+ if (options.availableHeight !== void 0) {
74281
+ updateOptions.availableHeight = options.availableHeight;
74282
+ }
74283
+ if (Object.keys(updateOptions).length > 0) {
74284
+ existing.editor.setOptions(updateOptions);
74285
+ }
74286
+ }
73746
74287
  return existing.editor;
73747
74288
  }
73748
74289
  const pending = __privateGet$1(this, _pendingCreations).get(descriptor.id);
@@ -73752,7 +74293,7 @@ class HeaderFooterEditorManager extends EventEmitter$1 {
73752
74293
  __privateSet(this, _cacheMisses, __privateGet$1(this, _cacheMisses) + 1);
73753
74294
  const creationPromise = (async () => {
73754
74295
  try {
73755
- const entry = await __privateMethod$1(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor);
74296
+ const entry = await __privateMethod$1(this, _HeaderFooterEditorManager_instances, createEditor_fn).call(this, descriptor, options);
73756
74297
  if (!entry) return null;
73757
74298
  __privateGet$1(this, _editorEntries).set(descriptor.id, entry);
73758
74299
  __privateMethod$1(this, _HeaderFooterEditorManager_instances, updateAccessOrder_fn).call(this, descriptor.id);
@@ -74060,7 +74601,7 @@ teardownEditors_fn = function() {
74060
74601
  });
74061
74602
  __privateGet$1(this, _editorEntries).clear();
74062
74603
  };
74063
- createEditor_fn = async function(descriptor) {
74604
+ createEditor_fn = async function(descriptor, options) {
74064
74605
  const json = this.getDocumentJson(descriptor);
74065
74606
  if (!json) return null;
74066
74607
  let editor;
@@ -74071,12 +74612,13 @@ createEditor_fn = async function(descriptor) {
74071
74612
  editor: __privateGet$1(this, _editor2),
74072
74613
  data: json,
74073
74614
  editorContainer: container,
74074
- appendToBody: true,
74615
+ editorHost: options?.editorHost,
74075
74616
  sectionId: descriptor.id,
74076
74617
  type: descriptor.kind,
74077
- availableHeight: DEFAULT_HEADER_FOOTER_HEIGHT,
74078
- currentPageNumber: 1
74079
- // Default page number
74618
+ availableWidth: options?.availableWidth,
74619
+ availableHeight: options?.availableHeight ?? DEFAULT_HEADER_FOOTER_HEIGHT,
74620
+ currentPageNumber: options?.currentPageNumber ?? 1,
74621
+ totalPageCount: options?.totalPageCount ?? 1
74080
74622
  });
74081
74623
  } catch (error) {
74082
74624
  console.error("[HeaderFooterEditorManager] Editor creation failed:", error);
@@ -74350,6 +74892,312 @@ getConverterContext_fn = function() {
74350
74892
  }
74351
74893
  return Object.keys(context).length > 0 ? context : void 0;
74352
74894
  };
74895
+ const EDITOR_HOST_Z_INDEX = "10";
74896
+ const BORDER_LINE_Z_INDEX = "15";
74897
+ const BORDER_LINE_COLOR = "#4472c4";
74898
+ const BORDER_LINE_HEIGHT = "1px";
74899
+ class EditorOverlayManager {
74900
+ /**
74901
+ * Creates a new EditorOverlayManager instance.
74902
+ *
74903
+ * @param painterHost - The host element containing painted pages. Must be an HTMLElement connected to the DOM.
74904
+ * @param visibleHost - The visible host element for overlay positioning. Must be an HTMLElement connected to the DOM.
74905
+ * @param selectionOverlay - The selection overlay element (optional). If provided, must be an HTMLElement.
74906
+ *
74907
+ * @throws {TypeError} If painterHost is not an HTMLElement
74908
+ * @throws {TypeError} If visibleHost is not an HTMLElement
74909
+ * @throws {TypeError} If selectionOverlay is provided but is not an HTMLElement
74910
+ * @throws {Error} If painterHost is not connected to the DOM
74911
+ * @throws {Error} If visibleHost is not connected to the DOM
74912
+ */
74913
+ constructor(painterHost, visibleHost, selectionOverlay = null) {
74914
+ __privateAdd$1(this, _EditorOverlayManager_instances);
74915
+ __privateAdd$1(this, _selectionOverlay);
74916
+ __privateAdd$1(this, _activeEditorHost, null);
74917
+ __privateAdd$1(this, _activeDecorationContainer, null);
74918
+ __privateAdd$1(this, _activeRegion, null);
74919
+ __privateAdd$1(this, _borderLine, null);
74920
+ if (!(painterHost instanceof HTMLElement)) {
74921
+ throw new TypeError("painterHost must be an HTMLElement");
74922
+ }
74923
+ if (!(visibleHost instanceof HTMLElement)) {
74924
+ throw new TypeError("visibleHost must be an HTMLElement");
74925
+ }
74926
+ if (selectionOverlay !== null && !(selectionOverlay instanceof HTMLElement)) {
74927
+ throw new TypeError("selectionOverlay must be an HTMLElement or null");
74928
+ }
74929
+ if (!painterHost.isConnected) {
74930
+ throw new Error("painterHost must be connected to the DOM");
74931
+ }
74932
+ if (!visibleHost.isConnected) {
74933
+ throw new Error("visibleHost must be connected to the DOM");
74934
+ }
74935
+ __privateSet(this, _selectionOverlay, selectionOverlay);
74936
+ }
74937
+ /**
74938
+ * Sets the callback to be invoked when the dimming overlay is clicked.
74939
+ * This allows PresentationEditor to exit header/footer mode when the user
74940
+ * clicks outside the editing region.
74941
+ *
74942
+ * @param callback - Function to call when dimming overlay is clicked
74943
+ */
74944
+ setOnDimmingClick(_callback) {
74945
+ }
74946
+ /**
74947
+ * Gets the currently active editor host element.
74948
+ * This is useful for checking if a click target is inside the active editing area.
74949
+ *
74950
+ * @returns The active editor host element, or null if not in editing mode
74951
+ */
74952
+ getActiveEditorHost() {
74953
+ return __privateGet$1(this, _activeEditorHost);
74954
+ }
74955
+ /**
74956
+ * Shows the editing overlay for a header/footer region.
74957
+ *
74958
+ * This method:
74959
+ * 1. Creates or retrieves the editor host element as a sibling to the decoration container
74960
+ * 2. Positions the editor host to match the decoration container bounds
74961
+ * 3. Hides the static decoration content
74962
+ * 4. Shows the dimming overlay over body content
74963
+ * 5. Returns the editor host element for mounting the ProseMirror editor
74964
+ *
74965
+ * @param pageElement - The page DOM element containing the region
74966
+ * @param region - The header/footer region to edit
74967
+ * @param zoom - Current zoom level (for positioning calculations)
74968
+ * @returns Result object with success status and editor host element
74969
+ *
74970
+ * @example
74971
+ * ```typescript
74972
+ * const result = overlayManager.showEditingOverlay(pageElement, region, 1.0);
74973
+ * if (result.success && result.editorHost) {
74974
+ * // Mount ProseMirror editor in result.editorHost
74975
+ * }
74976
+ * ```
74977
+ */
74978
+ showEditingOverlay(pageElement, region, zoom) {
74979
+ try {
74980
+ const decorationContainer = __privateMethod$1(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, region.kind);
74981
+ if (!decorationContainer) {
74982
+ return {
74983
+ success: false,
74984
+ reason: `Decoration container not found for ${region.kind} on page ${region.pageIndex}`
74985
+ };
74986
+ }
74987
+ const editorHost = __privateMethod$1(this, _EditorOverlayManager_instances, ensureEditorHost_fn).call(this, pageElement, region.kind);
74988
+ if (!editorHost) {
74989
+ return {
74990
+ success: false,
74991
+ reason: `Failed to create editor host for ${region.kind}`
74992
+ };
74993
+ }
74994
+ __privateMethod$1(this, _EditorOverlayManager_instances, positionEditorHost_fn).call(this, editorHost, region, decorationContainer, zoom);
74995
+ decorationContainer.style.visibility = "hidden";
74996
+ editorHost.style.visibility = "visible";
74997
+ editorHost.style.zIndex = EDITOR_HOST_Z_INDEX;
74998
+ if (region.kind === "footer") {
74999
+ const contentOffset = editorHost.dataset.contentOffset;
75000
+ if (contentOffset) {
75001
+ const editorContainer = editorHost.querySelector(".super-editor");
75002
+ if (editorContainer instanceof HTMLElement) {
75003
+ editorContainer.style.top = `${contentOffset}px`;
75004
+ }
75005
+ }
75006
+ }
75007
+ __privateMethod$1(this, _EditorOverlayManager_instances, showHeaderFooterBorder_fn).call(this, pageElement, region, decorationContainer);
75008
+ __privateSet(this, _activeEditorHost, editorHost);
75009
+ __privateSet(this, _activeDecorationContainer, decorationContainer);
75010
+ __privateSet(this, _activeRegion, region);
75011
+ return {
75012
+ success: true,
75013
+ editorHost
75014
+ };
75015
+ } catch (error) {
75016
+ if (__privateGet$1(this, _activeDecorationContainer)) {
75017
+ __privateGet$1(this, _activeDecorationContainer).style.visibility = "visible";
75018
+ }
75019
+ if (__privateGet$1(this, _activeEditorHost)) {
75020
+ __privateGet$1(this, _activeEditorHost).style.visibility = "hidden";
75021
+ }
75022
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
75023
+ const errorMessage = error instanceof Error ? error.message : String(error);
75024
+ console.error("[EditorOverlayManager] Failed to show editing overlay:", error);
75025
+ return {
75026
+ success: false,
75027
+ reason: `DOM manipulation error: ${errorMessage}`
75028
+ };
75029
+ }
75030
+ }
75031
+ /**
75032
+ * Hides the editing overlay and restores normal view.
75033
+ *
75034
+ * This method:
75035
+ * 1. Shows the static decoration content
75036
+ * 2. Hides the editor host (but doesn't destroy it for reuse)
75037
+ * 3. Removes the dimming overlay
75038
+ *
75039
+ * @example
75040
+ * ```typescript
75041
+ * overlayManager.hideEditingOverlay();
75042
+ * // Static decoration is now visible, editor is hidden
75043
+ * ```
75044
+ */
75045
+ hideEditingOverlay() {
75046
+ if (__privateGet$1(this, _activeDecorationContainer)) {
75047
+ __privateGet$1(this, _activeDecorationContainer).style.visibility = "visible";
75048
+ }
75049
+ if (__privateGet$1(this, _activeEditorHost)) {
75050
+ __privateGet$1(this, _activeEditorHost).style.visibility = "hidden";
75051
+ __privateGet$1(this, _activeEditorHost).style.zIndex = "";
75052
+ if (__privateGet$1(this, _activeRegion)?.kind === "footer") {
75053
+ const editorContainer = __privateGet$1(this, _activeEditorHost).querySelector(".super-editor");
75054
+ if (editorContainer instanceof HTMLElement) {
75055
+ editorContainer.style.top = "0";
75056
+ }
75057
+ }
75058
+ }
75059
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
75060
+ __privateSet(this, _activeEditorHost, null);
75061
+ __privateSet(this, _activeDecorationContainer, null);
75062
+ __privateSet(this, _activeRegion, null);
75063
+ }
75064
+ /**
75065
+ * Hides the layout selection overlay to prevent double caret rendering.
75066
+ *
75067
+ * Called when entering header/footer editing mode to ensure only the
75068
+ * ProseMirror editor's caret is visible, not both the PM caret and the
75069
+ * layout engine's selection overlay.
75070
+ *
75071
+ * @example
75072
+ * ```typescript
75073
+ * overlayManager.hideSelectionOverlay();
75074
+ * // Selection overlay is now hidden
75075
+ * ```
75076
+ */
75077
+ hideSelectionOverlay() {
75078
+ if (__privateGet$1(this, _selectionOverlay)) {
75079
+ __privateGet$1(this, _selectionOverlay).style.visibility = "hidden";
75080
+ }
75081
+ }
75082
+ /**
75083
+ * Shows the layout selection overlay.
75084
+ *
75085
+ * Called when exiting header/footer editing mode to restore the
75086
+ * normal selection overlay rendering for body content.
75087
+ *
75088
+ * @example
75089
+ * ```typescript
75090
+ * overlayManager.showSelectionOverlay();
75091
+ * // Selection overlay is now visible
75092
+ * ```
75093
+ */
75094
+ showSelectionOverlay() {
75095
+ if (__privateGet$1(this, _selectionOverlay)) {
75096
+ __privateGet$1(this, _selectionOverlay).style.visibility = "visible";
75097
+ }
75098
+ }
75099
+ /**
75100
+ * Destroys the overlay manager and cleans up all resources.
75101
+ *
75102
+ * Clears all references.
75103
+ * Editor host elements are left in the DOM as they're children of page elements
75104
+ * that will be cleaned up by the virtualization system.
75105
+ */
75106
+ destroy() {
75107
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
75108
+ __privateSet(this, _activeEditorHost, null);
75109
+ __privateSet(this, _activeDecorationContainer, null);
75110
+ __privateSet(this, _activeRegion, null);
75111
+ __privateSet(this, _selectionOverlay, null);
75112
+ }
75113
+ }
75114
+ _selectionOverlay = /* @__PURE__ */ new WeakMap();
75115
+ _activeEditorHost = /* @__PURE__ */ new WeakMap();
75116
+ _activeDecorationContainer = /* @__PURE__ */ new WeakMap();
75117
+ _activeRegion = /* @__PURE__ */ new WeakMap();
75118
+ _borderLine = /* @__PURE__ */ new WeakMap();
75119
+ _EditorOverlayManager_instances = /* @__PURE__ */ new WeakSet();
75120
+ findDecorationContainer_fn = function(pageElement, kind) {
75121
+ const className = kind === "header" ? "superdoc-page-header" : "superdoc-page-footer";
75122
+ return pageElement.querySelector(`.${className}`);
75123
+ };
75124
+ ensureEditorHost_fn = function(pageElement, kind) {
75125
+ const className = kind === "header" ? "superdoc-header-editor-host" : "superdoc-footer-editor-host";
75126
+ let editorHost = pageElement.querySelector(`.${className}`);
75127
+ if (!editorHost) {
75128
+ editorHost = document.createElement("div");
75129
+ editorHost.className = className;
75130
+ Object.assign(editorHost.style, {
75131
+ position: "absolute",
75132
+ pointerEvents: "auto",
75133
+ // Critical: enables click interaction
75134
+ visibility: "hidden",
75135
+ // Hidden by default, shown during editing
75136
+ overflow: "hidden",
75137
+ boxSizing: "border-box"
75138
+ });
75139
+ const decorationContainer = __privateMethod$1(this, _EditorOverlayManager_instances, findDecorationContainer_fn).call(this, pageElement, kind);
75140
+ if (!decorationContainer) {
75141
+ console.error(`[EditorOverlayManager] Decoration container not found for ${kind}`);
75142
+ return null;
75143
+ }
75144
+ decorationContainer.parentNode?.insertBefore(editorHost, decorationContainer.nextSibling);
75145
+ }
75146
+ return editorHost;
75147
+ };
75148
+ positionEditorHost_fn = function(editorHost, region, decorationContainer, _zoom) {
75149
+ const decorationRect = decorationContainer.getBoundingClientRect();
75150
+ const pageElement = editorHost.parentElement;
75151
+ if (!pageElement) {
75152
+ console.error("[EditorOverlayManager] Editor host has no parent element");
75153
+ return;
75154
+ }
75155
+ const pageRect = pageElement.getBoundingClientRect();
75156
+ const top2 = decorationRect.top - pageRect.top;
75157
+ const left2 = decorationRect.left - pageRect.left;
75158
+ const width = decorationRect.width;
75159
+ const height = decorationRect.height;
75160
+ Object.assign(editorHost.style, {
75161
+ top: `${top2}px`,
75162
+ left: `${left2}px`,
75163
+ width: `${width}px`,
75164
+ height: `${height}px`
75165
+ });
75166
+ if (region.kind === "footer") {
75167
+ const fragment = decorationContainer.querySelector(".superdoc-fragment");
75168
+ if (fragment instanceof HTMLElement) {
75169
+ const fragmentTop = parseFloat(fragment.style.top) || 0;
75170
+ editorHost.dataset.contentOffset = String(fragmentTop);
75171
+ }
75172
+ }
75173
+ };
75174
+ showHeaderFooterBorder_fn = function(pageElement, region, decorationContainer) {
75175
+ __privateMethod$1(this, _EditorOverlayManager_instances, hideHeaderFooterBorder_fn).call(this);
75176
+ __privateSet(this, _borderLine, document.createElement("div"));
75177
+ __privateGet$1(this, _borderLine).className = "superdoc-header-footer-border";
75178
+ const decorationRect = decorationContainer.getBoundingClientRect();
75179
+ const pageRect = pageElement.getBoundingClientRect();
75180
+ const isHeader = region.kind === "header";
75181
+ const topPosition = isHeader ? decorationRect.bottom - pageRect.top : decorationRect.top - pageRect.top;
75182
+ Object.assign(__privateGet$1(this, _borderLine).style, {
75183
+ position: "absolute",
75184
+ left: "0",
75185
+ right: "0",
75186
+ top: `${topPosition}px`,
75187
+ height: BORDER_LINE_HEIGHT,
75188
+ backgroundColor: BORDER_LINE_COLOR,
75189
+ // MS Word blue
75190
+ zIndex: BORDER_LINE_Z_INDEX,
75191
+ pointerEvents: "none"
75192
+ });
75193
+ pageElement.appendChild(__privateGet$1(this, _borderLine));
75194
+ };
75195
+ hideHeaderFooterBorder_fn = function() {
75196
+ if (__privateGet$1(this, _borderLine)) {
75197
+ __privateGet$1(this, _borderLine).remove();
75198
+ __privateSet(this, _borderLine, null);
75199
+ }
75200
+ };
74353
75201
  const uiSurfaces = /* @__PURE__ */ new WeakSet();
74354
75202
  function isInRegisteredSurface(event) {
74355
75203
  const path = typeof event.composedPath === "function" ? event.composedPath() : [];
@@ -74388,7 +75236,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74388
75236
  __privateAdd$1(this, _visibleHost);
74389
75237
  __privateAdd$1(this, _viewportHost);
74390
75238
  __privateAdd$1(this, _painterHost);
74391
- __privateAdd$1(this, _selectionOverlay);
75239
+ __privateAdd$1(this, _selectionOverlay2);
74392
75240
  __privateAdd$1(this, _hiddenHost);
74393
75241
  __privateAdd$1(this, _layoutOptions);
74394
75242
  __privateAdd$1(this, _layoutState, { blocks: [], measures: [], layout: null });
@@ -74423,6 +75271,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74423
75271
  __privateAdd$1(this, _footerRegions, /* @__PURE__ */ new Map());
74424
75272
  __privateAdd$1(this, _session, { mode: "body" });
74425
75273
  __privateAdd$1(this, _activeHeaderFooterEditor, null);
75274
+ __privateAdd$1(this, _overlayManager, null);
74426
75275
  __privateAdd$1(this, _hoverOverlay, null);
74427
75276
  __privateAdd$1(this, _hoverTooltip, null);
74428
75277
  __privateAdd$1(this, _modeBanner, null);
@@ -74477,6 +75326,11 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74477
75326
  const x2 = (event.clientX - rect.left + scrollLeft) / zoom;
74478
75327
  const y2 = (event.clientY - rect.top + scrollTop) / zoom;
74479
75328
  if (__privateGet$1(this, _session).mode !== "body") {
75329
+ const activeEditorHost = __privateGet$1(this, _overlayManager)?.getActiveEditorHost?.();
75330
+ const clickedInsideEditorHost = activeEditorHost && (activeEditorHost.contains(event.target) || activeEditorHost === event.target);
75331
+ if (clickedInsideEditorHost) {
75332
+ return;
75333
+ }
74480
75334
  const headerFooterRegion2 = __privateMethod$1(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, x2, y2);
74481
75335
  if (!headerFooterRegion2) {
74482
75336
  __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -74631,6 +75485,11 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74631
75485
  if (region) {
74632
75486
  event.preventDefault();
74633
75487
  event.stopPropagation();
75488
+ const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
75489
+ if (!descriptor && __privateGet$1(this, _headerFooterManager)) {
75490
+ __privateMethod$1(this, _PresentationEditor_instances, createDefaultHeaderFooter_fn).call(this, region);
75491
+ __privateGet$1(this, _headerFooterManager).refresh();
75492
+ }
74634
75493
  __privateMethod$1(this, _PresentationEditor_instances, activateHeaderFooterRegion_fn).call(this, region);
74635
75494
  } else if (__privateGet$1(this, _session).mode !== "body") {
74636
75495
  __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
@@ -74699,13 +75558,13 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74699
75558
  __privateGet$1(this, _painterHost).className = "presentation-editor__pages";
74700
75559
  __privateGet$1(this, _painterHost).style.transformOrigin = "top left";
74701
75560
  __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _painterHost));
74702
- __privateSet(this, _selectionOverlay, doc2.createElement("div"));
74703
- __privateGet$1(this, _selectionOverlay).className = "presentation-editor__selection-overlay";
74704
- __privateGet$1(this, _selectionOverlay).id = `presentation-overlay-${options.documentId || "default"}`;
74705
- __privateGet$1(this, _selectionOverlay).style.position = "absolute";
74706
- __privateGet$1(this, _selectionOverlay).style.inset = "0";
74707
- __privateGet$1(this, _selectionOverlay).style.pointerEvents = "none";
74708
- __privateGet$1(this, _selectionOverlay).style.zIndex = "10";
75561
+ __privateSet(this, _selectionOverlay2, doc2.createElement("div"));
75562
+ __privateGet$1(this, _selectionOverlay2).className = "presentation-editor__selection-overlay";
75563
+ __privateGet$1(this, _selectionOverlay2).id = `presentation-overlay-${options.documentId || "default"}`;
75564
+ __privateGet$1(this, _selectionOverlay2).style.position = "absolute";
75565
+ __privateGet$1(this, _selectionOverlay2).style.inset = "0";
75566
+ __privateGet$1(this, _selectionOverlay2).style.pointerEvents = "none";
75567
+ __privateGet$1(this, _selectionOverlay2).style.zIndex = "10";
74709
75568
  __privateSet(this, _remoteCursorOverlay, doc2.createElement("div"));
74710
75569
  __privateGet$1(this, _remoteCursorOverlay).className = "presentation-editor__selection-layer--remote";
74711
75570
  __privateGet$1(this, _remoteCursorOverlay).style.position = "absolute";
@@ -74716,9 +75575,9 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74716
75575
  __privateGet$1(this, _localSelectionLayer).style.position = "absolute";
74717
75576
  __privateGet$1(this, _localSelectionLayer).style.inset = "0";
74718
75577
  __privateGet$1(this, _localSelectionLayer).style.pointerEvents = "none";
74719
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _remoteCursorOverlay));
74720
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _localSelectionLayer));
74721
- __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _selectionOverlay));
75578
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _remoteCursorOverlay));
75579
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _localSelectionLayer));
75580
+ __privateGet$1(this, _viewportHost).appendChild(__privateGet$1(this, _selectionOverlay2));
74722
75581
  __privateSet(this, _hoverOverlay, doc2.createElement("div"));
74723
75582
  __privateGet$1(this, _hoverOverlay).className = "presentation-editor__hover-overlay";
74724
75583
  Object.assign(__privateGet$1(this, _hoverOverlay).style, {
@@ -74729,7 +75588,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74729
75588
  display: "none",
74730
75589
  zIndex: "11"
74731
75590
  });
74732
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _hoverOverlay));
75591
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _hoverOverlay));
74733
75592
  __privateSet(this, _hoverTooltip, doc2.createElement("div"));
74734
75593
  __privateGet$1(this, _hoverTooltip).className = "presentation-editor__hover-tooltip";
74735
75594
  Object.assign(__privateGet$1(this, _hoverTooltip).style, {
@@ -74744,7 +75603,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74744
75603
  zIndex: "12",
74745
75604
  whiteSpace: "nowrap"
74746
75605
  });
74747
- __privateGet$1(this, _selectionOverlay).appendChild(__privateGet$1(this, _hoverTooltip));
75606
+ __privateGet$1(this, _selectionOverlay2).appendChild(__privateGet$1(this, _hoverTooltip));
74748
75607
  __privateSet(this, _modeBanner, doc2.createElement("div"));
74749
75608
  __privateGet$1(this, _modeBanner).className = "presentation-editor__mode-banner";
74750
75609
  Object.assign(__privateGet$1(this, _modeBanner).style, {
@@ -74962,7 +75821,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
74962
75821
  * ```
74963
75822
  */
74964
75823
  get overlayElement() {
74965
- return __privateGet$1(this, _selectionOverlay) ?? null;
75824
+ return __privateGet$1(this, _selectionOverlay2) ?? null;
74966
75825
  }
74967
75826
  /**
74968
75827
  * Set the document mode and update editor editability.
@@ -75132,12 +75991,12 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
75132
75991
  * @returns Array of rects, each containing pageIndex and position data (left, top, right, bottom, width, height)
75133
75992
  */
75134
75993
  getRangeRects(from2, to, relativeTo) {
75135
- if (!__privateGet$1(this, _selectionOverlay)) return [];
75994
+ if (!__privateGet$1(this, _selectionOverlay2)) return [];
75136
75995
  if (!Number.isFinite(from2) || !Number.isFinite(to)) return [];
75137
75996
  const start2 = Math.min(from2, to);
75138
75997
  const end2 = Math.max(from2, to);
75139
75998
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
75140
- const overlayRect = __privateGet$1(this, _selectionOverlay).getBoundingClientRect();
75999
+ const overlayRect = __privateGet$1(this, _selectionOverlay2).getBoundingClientRect();
75141
76000
  const relativeRect = relativeTo?.getBoundingClientRect() ?? null;
75142
76001
  const layoutRectSource = () => {
75143
76002
  if (__privateGet$1(this, _session).mode !== "body") {
@@ -75398,7 +76257,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
75398
76257
  return null;
75399
76258
  }
75400
76259
  const rect2 = rects2[0];
75401
- const overlayRect = __privateGet$1(this, _selectionOverlay)?.getBoundingClientRect();
76260
+ const overlayRect = __privateGet$1(this, _selectionOverlay2)?.getBoundingClientRect();
75402
76261
  if (!overlayRect) {
75403
76262
  return null;
75404
76263
  }
@@ -75568,7 +76427,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
75568
76427
  __privateSet(this, _session, { mode: "body" });
75569
76428
  __privateSet(this, _activeHeaderFooterEditor, null);
75570
76429
  __privateSet(this, _domPainter, null);
75571
- __privateGet$1(this, _selectionOverlay)?.remove();
76430
+ __privateGet$1(this, _selectionOverlay2)?.remove();
75572
76431
  __privateGet$1(this, _painterHost)?.remove();
75573
76432
  __privateGet$1(this, _hiddenHost)?.remove();
75574
76433
  __privateSet(this, _hoverOverlay, null);
@@ -75590,7 +76449,7 @@ _editor3 = /* @__PURE__ */ new WeakMap();
75590
76449
  _visibleHost = /* @__PURE__ */ new WeakMap();
75591
76450
  _viewportHost = /* @__PURE__ */ new WeakMap();
75592
76451
  _painterHost = /* @__PURE__ */ new WeakMap();
75593
- _selectionOverlay = /* @__PURE__ */ new WeakMap();
76452
+ _selectionOverlay2 = /* @__PURE__ */ new WeakMap();
75594
76453
  _hiddenHost = /* @__PURE__ */ new WeakMap();
75595
76454
  _layoutOptions = /* @__PURE__ */ new WeakMap();
75596
76455
  _layoutState = /* @__PURE__ */ new WeakMap();
@@ -75625,6 +76484,7 @@ _headerRegions = /* @__PURE__ */ new WeakMap();
75625
76484
  _footerRegions = /* @__PURE__ */ new WeakMap();
75626
76485
  _session = /* @__PURE__ */ new WeakMap();
75627
76486
  _activeHeaderFooterEditor = /* @__PURE__ */ new WeakMap();
76487
+ _overlayManager = /* @__PURE__ */ new WeakMap();
75628
76488
  _hoverOverlay = /* @__PURE__ */ new WeakMap();
75629
76489
  _hoverTooltip = /* @__PURE__ */ new WeakMap();
75630
76490
  _modeBanner = /* @__PURE__ */ new WeakMap();
@@ -75990,9 +76850,14 @@ initHeaderFooterRegistry_fn = function() {
75990
76850
  __privateSet(this, _headerFooterManagerCleanups, []);
75991
76851
  __privateGet$1(this, _headerFooterAdapter)?.clear();
75992
76852
  __privateGet$1(this, _headerFooterManager)?.destroy();
76853
+ __privateGet$1(this, _overlayManager)?.destroy();
75993
76854
  __privateSet(this, _session, { mode: "body" });
75994
76855
  __privateSet(this, _activeHeaderFooterEditor, null);
75995
76856
  __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
76857
+ __privateSet(this, _overlayManager, new EditorOverlayManager(__privateGet$1(this, _painterHost), __privateGet$1(this, _visibleHost), __privateGet$1(this, _selectionOverlay2)));
76858
+ __privateGet$1(this, _overlayManager).setOnDimmingClick(() => {
76859
+ __privateMethod$1(this, _PresentationEditor_instances, exitHeaderFooterMode_fn).call(this);
76860
+ });
75996
76861
  const converter = __privateGet$1(this, _editor3).converter;
75997
76862
  __privateSet(this, _headerFooterIdentifier, extractIdentifierFromConverter(converter));
75998
76863
  __privateSet(this, _headerFooterManager, new HeaderFooterEditorManager(__privateGet$1(this, _editor3)));
@@ -76341,6 +77206,9 @@ scheduleSelectionUpdate_fn = function() {
76341
77206
  });
76342
77207
  };
76343
77208
  updateSelection_fn = function() {
77209
+ if (__privateGet$1(this, _session).mode !== "body") {
77210
+ return;
77211
+ }
76344
77212
  if (!__privateGet$1(this, _localSelectionLayer)) {
76345
77213
  return;
76346
77214
  }
@@ -76350,22 +77218,6 @@ updateSelection_fn = function() {
76350
77218
  if (!selection) {
76351
77219
  return;
76352
77220
  }
76353
- if (__privateGet$1(this, _session).mode !== "body") {
76354
- if (!layout) {
76355
- return;
76356
- }
76357
- if (selection.from === selection.to) {
76358
- const caretLayout = __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterCaretRect_fn).call(this, selection.from);
76359
- if (!caretLayout) {
76360
- return;
76361
- }
76362
- __privateMethod$1(this, _PresentationEditor_instances, renderCaretOverlay_fn).call(this, caretLayout);
76363
- return;
76364
- }
76365
- const rects2 = __privateMethod$1(this, _PresentationEditor_instances, computeHeaderFooterSelectionRects_fn).call(this, selection.from, selection.to);
76366
- __privateMethod$1(this, _PresentationEditor_instances, renderSelectionRects_fn).call(this, rects2);
76367
- return;
76368
- }
76369
77221
  if (!layout) {
76370
77222
  return;
76371
77223
  }
@@ -76600,46 +77452,168 @@ activateHeaderFooterRegion_fn = function(region) {
76600
77452
  void __privateMethod$1(this, _PresentationEditor_instances, enterHeaderFooterMode_fn).call(this, region);
76601
77453
  };
76602
77454
  enterHeaderFooterMode_fn = async function(region) {
76603
- if (!__privateGet$1(this, _headerFooterManager)) {
76604
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
76605
- return;
76606
- }
76607
- const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
76608
- if (!descriptor) {
76609
- console.warn("[PresentationEditor] No descriptor found for region:", region);
76610
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
76611
- return;
76612
- }
76613
- if (!descriptor.id) {
76614
- console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
76615
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
76616
- return;
76617
- }
76618
- const editor = await __privateGet$1(this, _headerFooterManager).ensureEditor(descriptor);
76619
- if (!editor) {
76620
- console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
77455
+ try {
77456
+ if (!__privateGet$1(this, _headerFooterManager) || !__privateGet$1(this, _overlayManager)) {
77457
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77458
+ return;
77459
+ }
77460
+ const descriptor = __privateMethod$1(this, _PresentationEditor_instances, resolveDescriptorForRegion_fn).call(this, region);
77461
+ if (!descriptor) {
77462
+ console.warn("[PresentationEditor] No descriptor found for region:", region);
77463
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77464
+ return;
77465
+ }
77466
+ if (!descriptor.id) {
77467
+ console.warn("[PresentationEditor] Descriptor missing id:", descriptor);
77468
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77469
+ return;
77470
+ }
77471
+ let pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
77472
+ if (!pageElement) {
77473
+ try {
77474
+ __privateMethod$1(this, _PresentationEditor_instances, scrollPageIntoView_fn).call(this, region.pageIndex);
77475
+ const mounted = await __privateMethod$1(this, _PresentationEditor_instances, waitForPageMount_fn).call(this, region.pageIndex, { timeout: 2e3 });
77476
+ if (!mounted) {
77477
+ console.error("[PresentationEditor] Failed to mount page for header/footer editing");
77478
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77479
+ this.emit("error", {
77480
+ error: new Error("Failed to mount page for editing"),
77481
+ context: "enterHeaderFooterMode"
77482
+ });
77483
+ return;
77484
+ }
77485
+ pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, region.pageIndex);
77486
+ } catch (scrollError) {
77487
+ console.error("[PresentationEditor] Error mounting page:", scrollError);
77488
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77489
+ this.emit("error", {
77490
+ error: scrollError,
77491
+ context: "enterHeaderFooterMode.pageMount"
77492
+ });
77493
+ return;
77494
+ }
77495
+ }
77496
+ if (!pageElement) {
77497
+ console.error("[PresentationEditor] Page element not found after mount attempt");
77498
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77499
+ this.emit("error", {
77500
+ error: new Error("Page element not found after mount"),
77501
+ context: "enterHeaderFooterMode"
77502
+ });
77503
+ return;
77504
+ }
77505
+ const { success, editorHost, reason } = __privateGet$1(this, _overlayManager).showEditingOverlay(
77506
+ pageElement,
77507
+ region,
77508
+ __privateGet$1(this, _layoutOptions).zoom ?? 1
77509
+ );
77510
+ if (!success || !editorHost) {
77511
+ console.error("[PresentationEditor] Failed to create editor host:", reason);
77512
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77513
+ this.emit("error", {
77514
+ error: new Error(`Failed to create editor host: ${reason}`),
77515
+ context: "enterHeaderFooterMode.showOverlay"
77516
+ });
77517
+ return;
77518
+ }
77519
+ const layout = __privateGet$1(this, _layoutState).layout;
77520
+ let editor;
77521
+ try {
77522
+ editor = await __privateGet$1(this, _headerFooterManager).ensureEditor(descriptor, {
77523
+ editorHost,
77524
+ availableWidth: region.width,
77525
+ availableHeight: region.height,
77526
+ currentPageNumber: region.pageNumber,
77527
+ totalPageCount: layout?.pages?.length ?? 1
77528
+ });
77529
+ } catch (editorError) {
77530
+ console.error("[PresentationEditor] Error creating editor:", editorError);
77531
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
77532
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77533
+ this.emit("error", {
77534
+ error: editorError,
77535
+ context: "enterHeaderFooterMode.ensureEditor"
77536
+ });
77537
+ return;
77538
+ }
77539
+ if (!editor) {
77540
+ console.warn("[PresentationEditor] Failed to ensure editor for descriptor:", descriptor);
77541
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
77542
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77543
+ this.emit("error", {
77544
+ error: new Error("Failed to create editor instance"),
77545
+ context: "enterHeaderFooterMode.ensureEditor"
77546
+ });
77547
+ return;
77548
+ }
77549
+ try {
77550
+ editor.setEditable(true);
77551
+ editor.setOptions({ documentMode: "editing" });
77552
+ try {
77553
+ const doc2 = editor.state?.doc;
77554
+ if (doc2) {
77555
+ const endPos = doc2.content.size - 1;
77556
+ editor.commands?.setTextSelection?.(Math.max(1, endPos));
77557
+ }
77558
+ } catch (cursorError) {
77559
+ console.warn("[PresentationEditor] Could not set cursor to end:", cursorError);
77560
+ }
77561
+ } catch (editableError) {
77562
+ console.error("[PresentationEditor] Error setting editor editable:", editableError);
77563
+ __privateGet$1(this, _overlayManager).hideEditingOverlay();
77564
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77565
+ this.emit("error", {
77566
+ error: editableError,
77567
+ context: "enterHeaderFooterMode.setEditable"
77568
+ });
77569
+ return;
77570
+ }
77571
+ __privateGet$1(this, _overlayManager).hideSelectionOverlay();
77572
+ __privateSet(this, _activeHeaderFooterEditor, editor);
77573
+ __privateSet(this, _session, {
77574
+ mode: region.kind,
77575
+ kind: region.kind,
77576
+ headerId: descriptor.id,
77577
+ sectionType: descriptor.variant ?? region.sectionType ?? null,
77578
+ pageIndex: region.pageIndex,
77579
+ pageNumber: region.pageNumber
77580
+ });
76621
77581
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
76622
- return;
77582
+ try {
77583
+ editor.view?.focus();
77584
+ } catch (focusError) {
77585
+ console.warn("[PresentationEditor] Could not focus editor:", focusError);
77586
+ }
77587
+ __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
77588
+ __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
77589
+ __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
77590
+ } catch (error) {
77591
+ console.error("[PresentationEditor] Unexpected error in enterHeaderFooterMode:", error);
77592
+ try {
77593
+ __privateGet$1(this, _overlayManager)?.hideEditingOverlay();
77594
+ __privateGet$1(this, _overlayManager)?.showSelectionOverlay();
77595
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
77596
+ __privateSet(this, _activeHeaderFooterEditor, null);
77597
+ __privateSet(this, _session, { mode: "body" });
77598
+ } catch (cleanupError) {
77599
+ console.error("[PresentationEditor] Error during cleanup:", cleanupError);
77600
+ }
77601
+ this.emit("error", {
77602
+ error,
77603
+ context: "enterHeaderFooterMode"
77604
+ });
76623
77605
  }
76624
- __privateSet(this, _activeHeaderFooterEditor, editor);
76625
- __privateSet(this, _session, {
76626
- mode: region.kind,
76627
- kind: region.kind,
76628
- headerId: descriptor.id,
76629
- sectionType: descriptor.variant ?? region.sectionType ?? null,
76630
- pageIndex: region.pageIndex,
76631
- pageNumber: region.pageNumber
76632
- });
76633
- __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
76634
- __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
76635
- __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, editor);
76636
- __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
76637
- editor.view?.focus();
76638
77606
  };
76639
77607
  exitHeaderFooterMode_fn = function() {
76640
77608
  if (__privateGet$1(this, _session).mode === "body") return;
76641
- __privateSet(this, _session, { mode: "body" });
77609
+ if (__privateGet$1(this, _activeHeaderFooterEditor)) {
77610
+ __privateGet$1(this, _activeHeaderFooterEditor).setEditable(false);
77611
+ __privateGet$1(this, _activeHeaderFooterEditor).setOptions({ documentMode: "viewing" });
77612
+ }
77613
+ __privateGet$1(this, _overlayManager)?.hideEditingOverlay();
77614
+ __privateGet$1(this, _overlayManager)?.showSelectionOverlay();
76642
77615
  __privateSet(this, _activeHeaderFooterEditor, null);
77616
+ __privateSet(this, _session, { mode: "body" });
76643
77617
  __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterModeChanged_fn).call(this);
76644
77618
  __privateMethod$1(this, _PresentationEditor_instances, emitHeaderFooterEditingContext_fn).call(this, __privateGet$1(this, _editor3));
76645
77619
  __privateGet$1(this, _inputBridge)?.notifyTargetChanged();
@@ -76735,6 +77709,75 @@ resolveDescriptorForRegion_fn = function(region) {
76735
77709
  }
76736
77710
  return descriptors[0];
76737
77711
  };
77712
+ createDefaultHeaderFooter_fn = function(region) {
77713
+ const converter = __privateGet$1(this, _editor3).converter;
77714
+ if (!converter) {
77715
+ console.error("[PresentationEditor] Converter not available for creating header/footer");
77716
+ return;
77717
+ }
77718
+ const variant = region.sectionType ?? "default";
77719
+ try {
77720
+ if (region.kind === "header") {
77721
+ if (typeof converter.createDefaultHeader === "function") {
77722
+ const headerId = converter.createDefaultHeader(variant);
77723
+ console.log(`[PresentationEditor] Created default header: ${headerId}`);
77724
+ } else {
77725
+ console.error("[PresentationEditor] converter.createDefaultHeader is not a function");
77726
+ }
77727
+ } else if (region.kind === "footer") {
77728
+ if (typeof converter.createDefaultFooter === "function") {
77729
+ const footerId = converter.createDefaultFooter(variant);
77730
+ console.log(`[PresentationEditor] Created default footer: ${footerId}`);
77731
+ } else {
77732
+ console.error("[PresentationEditor] converter.createDefaultFooter is not a function");
77733
+ }
77734
+ }
77735
+ } catch (error) {
77736
+ console.error("[PresentationEditor] Failed to create default header/footer:", error);
77737
+ }
77738
+ };
77739
+ getPageElement_fn = function(pageIndex) {
77740
+ if (!__privateGet$1(this, _painterHost)) return null;
77741
+ const pageElements = __privateGet$1(this, _painterHost).querySelectorAll("[data-page-index]");
77742
+ for (let i = 0; i < pageElements.length; i++) {
77743
+ const el = pageElements[i];
77744
+ const dataPageIndex = el.getAttribute("data-page-index");
77745
+ if (dataPageIndex && parseInt(dataPageIndex, 10) === pageIndex) {
77746
+ return el;
77747
+ }
77748
+ }
77749
+ return null;
77750
+ };
77751
+ scrollPageIntoView_fn = function(pageIndex) {
77752
+ const layout = __privateGet$1(this, _layoutState).layout;
77753
+ if (!layout) return;
77754
+ const pageHeight = layout.pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
77755
+ const virtualGap = __privateGet$1(this, _layoutOptions).virtualization?.gap ?? 0;
77756
+ const yPosition = pageIndex * (pageHeight + virtualGap);
77757
+ if (__privateGet$1(this, _visibleHost)) {
77758
+ __privateGet$1(this, _visibleHost).scrollTop = yPosition;
77759
+ }
77760
+ };
77761
+ waitForPageMount_fn = async function(pageIndex, options = {}) {
77762
+ const timeout2 = options.timeout ?? 2e3;
77763
+ const startTime = performance.now();
77764
+ return new Promise((resolve) => {
77765
+ const checkPage = () => {
77766
+ const pageElement = __privateMethod$1(this, _PresentationEditor_instances, getPageElement_fn).call(this, pageIndex);
77767
+ if (pageElement) {
77768
+ resolve(true);
77769
+ return;
77770
+ }
77771
+ const elapsed = performance.now() - startTime;
77772
+ if (elapsed >= timeout2) {
77773
+ resolve(false);
77774
+ return;
77775
+ }
77776
+ requestAnimationFrame(checkPage);
77777
+ };
77778
+ checkPage();
77779
+ });
77780
+ };
76738
77781
  getBodyPageHeight_fn = function() {
76739
77782
  return __privateGet$1(this, _layoutState).layout?.pageSize?.h ?? __privateGet$1(this, _layoutOptions).pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
76740
77783
  };
@@ -76788,7 +77831,7 @@ renderHoverRegion_fn = function(region) {
76788
77831
  __privateGet$1(this, _hoverOverlay).style.top = `${coords.y}px`;
76789
77832
  __privateGet$1(this, _hoverOverlay).style.width = `${region.width * zoom}px`;
76790
77833
  __privateGet$1(this, _hoverOverlay).style.height = `${region.height * zoom}px`;
76791
- const tooltipText = `Double-click to edit ${region.kind === "header" ? "Header" : "Footer"} (${region.sectionType ?? "default"})`;
77834
+ const tooltipText = `Double-click to edit ${region.kind === "header" ? "header" : "footer"}`;
76792
77835
  __privateGet$1(this, _hoverTooltip).textContent = tooltipText;
76793
77836
  __privateGet$1(this, _hoverTooltip).style.display = "block";
76794
77837
  __privateGet$1(this, _hoverTooltip).style.left = `${coords.x}px`;
@@ -76894,33 +77937,6 @@ computeHeaderFooterSelectionRects_fn = function(from2, to) {
76894
77937
  };
76895
77938
  });
76896
77939
  };
76897
- computeHeaderFooterCaretRect_fn = function(pos) {
76898
- const context = __privateMethod$1(this, _PresentationEditor_instances, getHeaderFooterContext_fn).call(this);
76899
- if (!context) return null;
76900
- const hit = getFragmentAtPosition(context.layout, context.blocks, context.measures, pos);
76901
- if (!hit) return null;
76902
- const block = hit.block;
76903
- const measure = hit.measure;
76904
- if (!block || block.kind !== "paragraph" || measure?.kind !== "paragraph" || hit.fragment.kind !== "para")
76905
- return null;
76906
- const lineInfo = __privateMethod$1(this, _PresentationEditor_instances, findLineContainingPos_fn).call(this, block, measure, hit.fragment.fromLine, hit.fragment.toLine, pos);
76907
- if (!lineInfo) return null;
76908
- const { line, index: index2 } = lineInfo;
76909
- const range2 = computeLinePmRange$1(block, line);
76910
- if (range2.pmStart == null || range2.pmEnd == null) return null;
76911
- const pmCharsInLine = Math.max(1, range2.pmEnd - range2.pmStart);
76912
- const pmOffset = Math.max(0, Math.min(pmCharsInLine, pos - range2.pmStart));
76913
- const localX = hit.fragment.x + measureCharacterX(block, line, pmOffset);
76914
- const lineOffset = __privateMethod$1(this, _PresentationEditor_instances, lineHeightBeforeIndex_fn).call(this, measure.lines, hit.fragment.fromLine, index2);
76915
- const headerPageHeight = context.layout.pageSize?.h ?? context.region.height ?? 1;
76916
- const headerLocalY = hit.pageIndex * headerPageHeight + (hit.fragment.y + lineOffset);
76917
- return {
76918
- pageIndex: context.region.pageIndex,
76919
- x: context.region.localX + localX,
76920
- y: context.region.localY + headerLocalY,
76921
- height: line.lineHeight
76922
- };
76923
- };
76924
77940
  syncTrackedChangesPreferences_fn = function() {
76925
77941
  const mode = __privateMethod$1(this, _PresentationEditor_instances, deriveTrackedChangesMode_fn).call(this);
76926
77942
  const enabled = __privateMethod$1(this, _PresentationEditor_instances, deriveTrackedChangesEnabled_fn).call(this);
@@ -77027,7 +78043,7 @@ convertPageLocalToOverlayCoords_fn = function(pageIndex, pageLocalX, pageLocalY)
77027
78043
  return null;
77028
78044
  }
77029
78045
  const pageRect = pageEl.getBoundingClientRect();
77030
- const overlayRect = __privateGet$1(this, _selectionOverlay).getBoundingClientRect();
78046
+ const overlayRect = __privateGet$1(this, _selectionOverlay2).getBoundingClientRect();
77031
78047
  const zoom = __privateGet$1(this, _layoutOptions).zoom ?? 1;
77032
78048
  return {
77033
78049
  x: pageRect.left - overlayRect.left + pageLocalX * zoom,
@@ -81897,22 +82913,53 @@ function calculateTabLayout(request, measurement, view) {
81897
82913
  tabs
81898
82914
  };
81899
82915
  }
82916
+ const MAX_WALK_DEPTH = 50;
81900
82917
  function applyLayoutResult(result, paragraph, paragraphPos) {
81901
82918
  const decorations = [];
81902
82919
  let tabIndex = 0;
81903
- paragraph.forEach((node, offset2) => {
81904
- if (node.type.name !== "tab") return;
81905
- const pos = paragraphPos + offset2 + 1;
81906
- const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
81907
- const layout = result.tabs[tabId];
81908
- if (!layout) return;
81909
- let style2 = `width: ${layout.width}px;`;
81910
- if (layout.height) style2 += ` height: ${layout.height};`;
81911
- if (layout.leader && leaderStyles[layout.leader]) {
81912
- style2 += ` ${leaderStyles[layout.leader]}`;
81913
- }
81914
- decorations.push(Decoration.node(pos, pos + node.nodeSize, { style: style2 }));
81915
- });
82920
+ const walk = (node, pos, depth = 0) => {
82921
+ if (depth > MAX_WALK_DEPTH) {
82922
+ console.error(`applyLayoutResult: Maximum recursion depth (${MAX_WALK_DEPTH}) exceeded`);
82923
+ return;
82924
+ }
82925
+ if (!node?.type?.name) {
82926
+ console.error("applyLayoutResult: Node missing type.name", { node, pos, depth });
82927
+ return;
82928
+ }
82929
+ if (typeof node.nodeSize !== "number" || node.nodeSize < 0 || !Number.isFinite(node.nodeSize)) {
82930
+ console.error("applyLayoutResult: Invalid nodeSize", { nodeSize: node.nodeSize, nodeName: node.type.name, pos });
82931
+ return;
82932
+ }
82933
+ if (node.type.name === "tab") {
82934
+ const tabId = tabIdForIndex(result.paragraphId, tabIndex++);
82935
+ const layout = result.tabs[tabId];
82936
+ if (layout) {
82937
+ let style2 = `width: ${layout.width}px;`;
82938
+ if (layout.height) style2 += ` height: ${layout.height};`;
82939
+ if (layout.leader && leaderStyles[layout.leader]) {
82940
+ style2 += ` ${leaderStyles[layout.leader]}`;
82941
+ }
82942
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, { style: style2 }));
82943
+ }
82944
+ return;
82945
+ }
82946
+ try {
82947
+ let offset2 = 0;
82948
+ node.forEach((child) => {
82949
+ const childPos = pos + 1 + offset2;
82950
+ walk(child, childPos, depth + 1);
82951
+ offset2 += child.nodeSize;
82952
+ });
82953
+ } catch (error) {
82954
+ console.error("applyLayoutResult: Error during recursion", {
82955
+ error,
82956
+ nodeName: node.type.name,
82957
+ pos,
82958
+ depth
82959
+ });
82960
+ }
82961
+ };
82962
+ walk(paragraph, paragraphPos);
81916
82963
  return decorations;
81917
82964
  }
81918
82965
  function collectFollowingText(spans, startIndex) {
@@ -82460,8 +83507,8 @@ const createColGroup = (node, cellMinWidth2, overrideCol, overrideValue) => {
82460
83507
  colgroupValues
82461
83508
  };
82462
83509
  };
82463
- var readFromCache;
82464
- var addToCache;
83510
+ let readFromCache;
83511
+ let addToCache;
82465
83512
  if (typeof WeakMap != "undefined") {
82466
83513
  let cache2 = /* @__PURE__ */ new WeakMap();
82467
83514
  readFromCache = (key2) => cache2.get(key2);
@@ -82474,8 +83521,7 @@ if (typeof WeakMap != "undefined") {
82474
83521
  const cacheSize = 10;
82475
83522
  let cachePos = 0;
82476
83523
  readFromCache = (key2) => {
82477
- for (let i = 0; i < cache2.length; i += 2)
82478
- if (cache2[i] == key2) return cache2[i + 1];
83524
+ for (let i = 0; i < cache2.length; i += 2) if (cache2[i] == key2) return cache2[i + 1];
82479
83525
  };
82480
83526
  addToCache = (key2, value) => {
82481
83527
  if (cachePos == cacheSize) cachePos = 0;
@@ -82490,7 +83536,6 @@ var TableMap = class {
82490
83536
  this.map = map22;
82491
83537
  this.problems = problems;
82492
83538
  }
82493
- // Find the dimensions of the cell at the given position.
82494
83539
  findCell(pos) {
82495
83540
  for (let i = 0; i < this.map.length; i++) {
82496
83541
  const curPos = this.map[i];
@@ -82499,27 +83544,21 @@ var TableMap = class {
82499
83544
  const top2 = i / this.width | 0;
82500
83545
  let right2 = left2 + 1;
82501
83546
  let bottom2 = top2 + 1;
82502
- for (let j2 = 1; right2 < this.width && this.map[i + j2] == curPos; j2++) {
82503
- right2++;
82504
- }
82505
- for (let j2 = 1; bottom2 < this.height && this.map[i + this.width * j2] == curPos; j2++) {
82506
- bottom2++;
82507
- }
82508
- return { left: left2, top: top2, right: right2, bottom: bottom2 };
83547
+ for (let j2 = 1; right2 < this.width && this.map[i + j2] == curPos; j2++) right2++;
83548
+ for (let j2 = 1; bottom2 < this.height && this.map[i + this.width * j2] == curPos; j2++) bottom2++;
83549
+ return {
83550
+ left: left2,
83551
+ top: top2,
83552
+ right: right2,
83553
+ bottom: bottom2
83554
+ };
82509
83555
  }
82510
83556
  throw new RangeError(`No cell with offset ${pos} found`);
82511
83557
  }
82512
- // Find the left side of the cell at the given position.
82513
83558
  colCount(pos) {
82514
- for (let i = 0; i < this.map.length; i++) {
82515
- if (this.map[i] == pos) {
82516
- return i % this.width;
82517
- }
82518
- }
83559
+ for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
82519
83560
  throw new RangeError(`No cell with offset ${pos} found`);
82520
83561
  }
82521
- // Find the next cell in the given direction, starting from the cell
82522
- // at `pos`, if any.
82523
83562
  nextCell(pos, axis, dir) {
82524
83563
  const { left: left2, right: right2, top: top2, bottom: bottom2 } = this.findCell(pos);
82525
83564
  if (axis == "horiz") {
@@ -82530,20 +83569,9 @@ var TableMap = class {
82530
83569
  return this.map[left2 + this.width * (dir < 0 ? top2 - 1 : bottom2)];
82531
83570
  }
82532
83571
  }
82533
- // Get the rectangle spanning the two given cells.
82534
83572
  rectBetween(a, b2) {
82535
- const {
82536
- left: leftA,
82537
- right: rightA,
82538
- top: topA,
82539
- bottom: bottomA
82540
- } = this.findCell(a);
82541
- const {
82542
- left: leftB,
82543
- right: rightB,
82544
- top: topB,
82545
- bottom: bottomB
82546
- } = this.findCell(b2);
83573
+ const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
83574
+ const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b2);
82547
83575
  return {
82548
83576
  left: Math.min(leftA, leftB),
82549
83577
  top: Math.min(topA, topB),
@@ -82551,27 +83579,19 @@ var TableMap = class {
82551
83579
  bottom: Math.max(bottomA, bottomB)
82552
83580
  };
82553
83581
  }
82554
- // Return the position of all cells that have the top left corner in
82555
- // the given rectangle.
82556
83582
  cellsInRect(rect) {
82557
83583
  const result = [];
82558
83584
  const seen = {};
82559
- for (let row = rect.top; row < rect.bottom; row++) {
82560
- for (let col = rect.left; col < rect.right; col++) {
82561
- const index2 = row * this.width + col;
82562
- const pos = this.map[index2];
82563
- if (seen[pos]) continue;
82564
- seen[pos] = true;
82565
- if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) {
82566
- continue;
82567
- }
82568
- result.push(pos);
82569
- }
83585
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
83586
+ const index2 = row * this.width + col;
83587
+ const pos = this.map[index2];
83588
+ if (seen[pos]) continue;
83589
+ seen[pos] = true;
83590
+ if (col == rect.left && col && this.map[index2 - 1] == pos || row == rect.top && row && this.map[index2 - this.width] == pos) continue;
83591
+ result.push(pos);
82570
83592
  }
82571
83593
  return result;
82572
83594
  }
82573
- // Return the position at which the cell at the given row and column
82574
- // starts, or would start, if a cell started there.
82575
83595
  positionAt(row, col, table) {
82576
83596
  for (let i = 0, rowStart = 0; ; i++) {
82577
83597
  const rowEnd = rowStart + table.child(i).nodeSize;
@@ -82584,14 +83604,12 @@ var TableMap = class {
82584
83604
  rowStart = rowEnd;
82585
83605
  }
82586
83606
  }
82587
- // Find the table map for the given table node.
82588
83607
  static get(table) {
82589
83608
  return readFromCache(table) || addToCache(table, computeMap(table));
82590
83609
  }
82591
83610
  };
82592
83611
  function computeMap(table) {
82593
- if (table.type.spec.tableRole != "table")
82594
- throw new RangeError("Not a table node: " + table.type.name);
83612
+ if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
82595
83613
  const width = findWidth(table), height = table.childCount;
82596
83614
  const map22 = [];
82597
83615
  let mapPos = 0;
@@ -82618,22 +83636,19 @@ function computeMap(table) {
82618
83636
  const start2 = mapPos + h2 * width;
82619
83637
  for (let w2 = 0; w2 < colspan; w2++) {
82620
83638
  if (map22[start2 + w2] == 0) map22[start2 + w2] = pos;
82621
- else
82622
- (problems || (problems = [])).push({
82623
- type: "collision",
82624
- row,
82625
- pos,
82626
- n: colspan - w2
82627
- });
83639
+ else (problems || (problems = [])).push({
83640
+ type: "collision",
83641
+ row,
83642
+ pos,
83643
+ n: colspan - w2
83644
+ });
82628
83645
  const colW = colwidth && colwidth[w2];
82629
83646
  if (colW) {
82630
83647
  const widthIndex = (start2 + w2) % width * 2, prev = colWidths[widthIndex];
82631
83648
  if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
82632
83649
  colWidths[widthIndex] = colW;
82633
83650
  colWidths[widthIndex + 1] = 1;
82634
- } else if (prev == colW) {
82635
- colWidths[widthIndex + 1]++;
82636
- }
83651
+ } else if (prev == colW) colWidths[widthIndex + 1]++;
82637
83652
  }
82638
83653
  }
82639
83654
  }
@@ -82643,16 +83658,17 @@ function computeMap(table) {
82643
83658
  const expectedPos = (row + 1) * width;
82644
83659
  let missing = 0;
82645
83660
  while (mapPos < expectedPos) if (map22[mapPos++] == 0) missing++;
82646
- if (missing)
82647
- (problems || (problems = [])).push({ type: "missing", row, n: missing });
83661
+ if (missing) (problems || (problems = [])).push({
83662
+ type: "missing",
83663
+ row,
83664
+ n: missing
83665
+ });
82648
83666
  pos++;
82649
83667
  }
82650
- if (width === 0 || height === 0)
82651
- (problems || (problems = [])).push({ type: "zero_sized" });
83668
+ if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
82652
83669
  const tableMap = new TableMap(width, height, map22, problems);
82653
83670
  let badWidths = false;
82654
- for (let i = 0; !badWidths && i < colWidths.length; i += 2)
82655
- if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
83671
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
82656
83672
  if (badWidths) findBadColWidths(tableMap, colWidths, table);
82657
83673
  return tableMap;
82658
83674
  }
@@ -82662,14 +83678,13 @@ function findWidth(table) {
82662
83678
  for (let row = 0; row < table.childCount; row++) {
82663
83679
  const rowNode = table.child(row);
82664
83680
  let rowWidth = 0;
82665
- if (hasRowSpan)
82666
- for (let j2 = 0; j2 < row; j2++) {
82667
- const prevRow = table.child(j2);
82668
- for (let i = 0; i < prevRow.childCount; i++) {
82669
- const cell = prevRow.child(i);
82670
- if (j2 + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
82671
- }
83681
+ if (hasRowSpan) for (let j2 = 0; j2 < row; j2++) {
83682
+ const prevRow = table.child(j2);
83683
+ for (let i = 0; i < prevRow.childCount; i++) {
83684
+ const cell = prevRow.child(i);
83685
+ if (j2 + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
82672
83686
  }
83687
+ }
82673
83688
  for (let i = 0; i < rowNode.childCount; i++) {
82674
83689
  const cell = rowNode.child(i);
82675
83690
  rowWidth += cell.attrs.colspan;
@@ -82688,23 +83703,18 @@ function findBadColWidths(map22, colWidths, table) {
82688
83703
  if (seen[pos]) continue;
82689
83704
  seen[pos] = true;
82690
83705
  const node = table.nodeAt(pos);
82691
- if (!node) {
82692
- throw new RangeError(`No cell with offset ${pos} found`);
82693
- }
83706
+ if (!node) throw new RangeError(`No cell with offset ${pos} found`);
82694
83707
  let updated = null;
82695
83708
  const attrs = node.attrs;
82696
83709
  for (let j2 = 0; j2 < attrs.colspan; j2++) {
82697
- const col = (i + j2) % map22.width;
82698
- const colWidth = colWidths[col * 2];
82699
- if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth))
82700
- (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
82701
- }
82702
- if (updated)
82703
- map22.problems.unshift({
82704
- type: "colwidth mismatch",
82705
- pos,
82706
- colwidth: updated
82707
- });
83710
+ const colWidth = colWidths[(i + j2) % map22.width * 2];
83711
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j2] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j2] = colWidth;
83712
+ }
83713
+ if (updated) map22.problems.unshift({
83714
+ type: "colwidth mismatch",
83715
+ pos,
83716
+ colwidth: updated
83717
+ });
82708
83718
  }
82709
83719
  }
82710
83720
  function freshColWidth(attrs) {
@@ -82724,11 +83734,9 @@ function tableNodeTypes(schema) {
82724
83734
  }
82725
83735
  return result;
82726
83736
  }
82727
- var tableEditingKey = new PluginKey("selectingCells");
83737
+ const tableEditingKey = new PluginKey("selectingCells");
82728
83738
  function cellAround$1($pos) {
82729
- for (let d2 = $pos.depth - 1; d2 > 0; d2--)
82730
- if ($pos.node(d2).type.spec.tableRole == "row")
82731
- return $pos.node(0).resolve($pos.before(d2 + 1));
83739
+ 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));
82732
83740
  return null;
82733
83741
  }
82734
83742
  function cellWrapping$1($pos) {
@@ -82740,21 +83748,15 @@ function cellWrapping$1($pos) {
82740
83748
  }
82741
83749
  function isInTable(state2) {
82742
83750
  const $head = state2.selection.$head;
82743
- for (let d2 = $head.depth; d2 > 0; d2--)
82744
- if ($head.node(d2).type.spec.tableRole == "row") return true;
83751
+ for (let d2 = $head.depth; d2 > 0; d2--) if ($head.node(d2).type.spec.tableRole == "row") return true;
82745
83752
  return false;
82746
83753
  }
82747
83754
  function selectionCell(state2) {
82748
83755
  const sel = state2.selection;
82749
- if ("$anchorCell" in sel && sel.$anchorCell) {
82750
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
82751
- } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
82752
- return sel.$anchor;
82753
- }
83756
+ if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
83757
+ else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
82754
83758
  const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
82755
- if ($cell) {
82756
- return $cell;
82757
- }
83759
+ if ($cell) return $cell;
82758
83760
  throw new RangeError(`No cell found around position ${sel.head}`);
82759
83761
  }
82760
83762
  function cellNear($pos) {
@@ -82764,8 +83766,7 @@ function cellNear($pos) {
82764
83766
  }
82765
83767
  for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
82766
83768
  const role = before.type.spec.tableRole;
82767
- if (role == "cell" || role == "header_cell")
82768
- return $pos.doc.resolve(pos - before.nodeSize);
83769
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
82769
83770
  }
82770
83771
  }
82771
83772
  function pointsAtCell($pos) {
@@ -82785,7 +83786,10 @@ function nextCell($pos, axis, dir) {
82785
83786
  return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
82786
83787
  }
82787
83788
  function removeColSpan(attrs, pos, n = 1) {
82788
- const result = { ...attrs, colspan: attrs.colspan - n };
83789
+ const result = {
83790
+ ...attrs,
83791
+ colspan: attrs.colspan - n
83792
+ };
82789
83793
  if (result.colwidth) {
82790
83794
  result.colwidth = result.colwidth.slice();
82791
83795
  result.colwidth.splice(pos, n);
@@ -82794,7 +83798,10 @@ function removeColSpan(attrs, pos, n = 1) {
82794
83798
  return result;
82795
83799
  }
82796
83800
  function addColSpan(attrs, pos, n = 1) {
82797
- const result = { ...attrs, colspan: attrs.colspan + n };
83801
+ const result = {
83802
+ ...attrs,
83803
+ colspan: attrs.colspan + n
83804
+ };
82798
83805
  if (result.colwidth) {
82799
83806
  result.colwidth = result.colwidth.slice();
82800
83807
  for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
@@ -82803,37 +83810,23 @@ function addColSpan(attrs, pos, n = 1) {
82803
83810
  }
82804
83811
  function columnIsHeader(map22, table, col) {
82805
83812
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
82806
- for (let row = 0; row < map22.height; row++)
82807
- if (table.nodeAt(map22.map[col + row * map22.width]).type != headerCell)
82808
- return false;
83813
+ for (let row = 0; row < map22.height; row++) if (table.nodeAt(map22.map[col + row * map22.width]).type != headerCell) return false;
82809
83814
  return true;
82810
83815
  }
82811
- var CellSelection = class _CellSelection extends Selection {
82812
- // A table selection is identified by its anchor and head cells. The
82813
- // positions given to this constructor should point _before_ two
82814
- // cells in the same table. They may be the same, to select a single
82815
- // cell.
83816
+ var CellSelection = class CellSelection2 extends Selection {
82816
83817
  constructor($anchorCell, $headCell = $anchorCell) {
82817
83818
  const table = $anchorCell.node(-1);
82818
83819
  const map22 = TableMap.get(table);
82819
83820
  const tableStart = $anchorCell.start(-1);
82820
- const rect = map22.rectBetween(
82821
- $anchorCell.pos - tableStart,
82822
- $headCell.pos - tableStart
82823
- );
83821
+ const rect = map22.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
82824
83822
  const doc2 = $anchorCell.node(0);
82825
83823
  const cells = map22.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
82826
83824
  cells.unshift($headCell.pos - tableStart);
82827
83825
  const ranges = cells.map((pos) => {
82828
83826
  const cell = table.nodeAt(pos);
82829
- if (!cell) {
82830
- throw RangeError(`No cell with offset ${pos} found`);
82831
- }
83827
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
82832
83828
  const from2 = tableStart + pos + 1;
82833
- return new SelectionRange(
82834
- doc2.resolve(from2),
82835
- doc2.resolve(from2 + cell.content.size)
82836
- );
83829
+ return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size));
82837
83830
  });
82838
83831
  super(ranges[0].$from, ranges[0].$to, ranges);
82839
83832
  this.$anchorCell = $anchorCell;
@@ -82844,24 +83837,17 @@ var CellSelection = class _CellSelection extends Selection {
82844
83837
  const $headCell = doc2.resolve(mapping.map(this.$headCell.pos));
82845
83838
  if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
82846
83839
  const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
82847
- if (tableChanged && this.isRowSelection())
82848
- return _CellSelection.rowSelection($anchorCell, $headCell);
82849
- else if (tableChanged && this.isColSelection())
82850
- return _CellSelection.colSelection($anchorCell, $headCell);
82851
- else return new _CellSelection($anchorCell, $headCell);
83840
+ if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell);
83841
+ else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell);
83842
+ else return new CellSelection2($anchorCell, $headCell);
82852
83843
  }
82853
83844
  return TextSelection$1.between($anchorCell, $headCell);
82854
83845
  }
82855
- // Returns a rectangular slice of table rows containing the selected
82856
- // cells.
82857
83846
  content() {
82858
83847
  const table = this.$anchorCell.node(-1);
82859
83848
  const map22 = TableMap.get(table);
82860
83849
  const tableStart = this.$anchorCell.start(-1);
82861
- const rect = map22.rectBetween(
82862
- this.$anchorCell.pos - tableStart,
82863
- this.$headCell.pos - tableStart
82864
- );
83850
+ const rect = map22.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
82865
83851
  const seen = {};
82866
83852
  const rows = [];
82867
83853
  for (let row = rect.top; row < rect.bottom; row++) {
@@ -82872,44 +83858,25 @@ var CellSelection = class _CellSelection extends Selection {
82872
83858
  seen[pos] = true;
82873
83859
  const cellRect = map22.findCell(pos);
82874
83860
  let cell = table.nodeAt(pos);
82875
- if (!cell) {
82876
- throw RangeError(`No cell with offset ${pos} found`);
82877
- }
83861
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
82878
83862
  const extraLeft = rect.left - cellRect.left;
82879
83863
  const extraRight = cellRect.right - rect.right;
82880
83864
  if (extraLeft > 0 || extraRight > 0) {
82881
83865
  let attrs = cell.attrs;
82882
- if (extraLeft > 0) {
82883
- attrs = removeColSpan(attrs, 0, extraLeft);
82884
- }
82885
- if (extraRight > 0) {
82886
- attrs = removeColSpan(
82887
- attrs,
82888
- attrs.colspan - extraRight,
82889
- extraRight
82890
- );
82891
- }
83866
+ if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
83867
+ if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
82892
83868
  if (cellRect.left < rect.left) {
82893
83869
  cell = cell.type.createAndFill(attrs);
82894
- if (!cell) {
82895
- throw RangeError(
82896
- `Could not create cell with attrs ${JSON.stringify(attrs)}`
82897
- );
82898
- }
82899
- } else {
82900
- cell = cell.type.create(attrs, cell.content);
82901
- }
83870
+ if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
83871
+ } else cell = cell.type.create(attrs, cell.content);
82902
83872
  }
82903
83873
  if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
82904
83874
  const attrs = {
82905
83875
  ...cell.attrs,
82906
83876
  rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
82907
83877
  };
82908
- if (cellRect.top < rect.top) {
82909
- cell = cell.type.createAndFill(attrs);
82910
- } else {
82911
- cell = cell.type.create(attrs, cell.content);
82912
- }
83878
+ if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
83879
+ else cell = cell.type.create(attrs, cell.content);
82913
83880
  }
82914
83881
  rowContent.push(cell);
82915
83882
  }
@@ -82922,16 +83889,9 @@ var CellSelection = class _CellSelection extends Selection {
82922
83889
  const mapFrom = tr.steps.length, ranges = this.ranges;
82923
83890
  for (let i = 0; i < ranges.length; i++) {
82924
83891
  const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
82925
- tr.replace(
82926
- mapping.map($from.pos),
82927
- mapping.map($to.pos),
82928
- i ? Slice.empty : content
82929
- );
83892
+ tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
82930
83893
  }
82931
- const sel = Selection.findFrom(
82932
- tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
82933
- -1
82934
- );
83894
+ const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
82935
83895
  if (sel) tr.setSelection(sel);
82936
83896
  }
82937
83897
  replaceWith(tr, node) {
@@ -82941,18 +83901,9 @@ var CellSelection = class _CellSelection extends Selection {
82941
83901
  const table = this.$anchorCell.node(-1);
82942
83902
  const map22 = TableMap.get(table);
82943
83903
  const tableStart = this.$anchorCell.start(-1);
82944
- const cells = map22.cellsInRect(
82945
- map22.rectBetween(
82946
- this.$anchorCell.pos - tableStart,
82947
- this.$headCell.pos - tableStart
82948
- )
82949
- );
82950
- for (let i = 0; i < cells.length; i++) {
82951
- f2(table.nodeAt(cells[i]), tableStart + cells[i]);
82952
- }
83904
+ const cells = map22.cellsInRect(map22.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
83905
+ for (let i = 0; i < cells.length; i++) f2(table.nodeAt(cells[i]), tableStart + cells[i]);
82953
83906
  }
82954
- // True if this selection goes all the way from the top to the
82955
- // bottom of the table.
82956
83907
  isColSelection() {
82957
83908
  const anchorTop = this.$anchorCell.index(-1);
82958
83909
  const headTop = this.$headCell.index(-1);
@@ -82961,8 +83912,6 @@ var CellSelection = class _CellSelection extends Selection {
82961
83912
  const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
82962
83913
  return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
82963
83914
  }
82964
- // Returns the smallest column selection that covers the given anchor
82965
- // and head cell.
82966
83915
  static colSelection($anchorCell, $headCell = $anchorCell) {
82967
83916
  const table = $anchorCell.node(-1);
82968
83917
  const map22 = TableMap.get(table);
@@ -82971,24 +83920,14 @@ var CellSelection = class _CellSelection extends Selection {
82971
83920
  const headRect = map22.findCell($headCell.pos - tableStart);
82972
83921
  const doc2 = $anchorCell.node(0);
82973
83922
  if (anchorRect.top <= headRect.top) {
82974
- if (anchorRect.top > 0)
82975
- $anchorCell = doc2.resolve(tableStart + map22.map[anchorRect.left]);
82976
- if (headRect.bottom < map22.height)
82977
- $headCell = doc2.resolve(
82978
- tableStart + map22.map[map22.width * (map22.height - 1) + headRect.right - 1]
82979
- );
83923
+ if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map22.map[anchorRect.left]);
83924
+ if (headRect.bottom < map22.height) $headCell = doc2.resolve(tableStart + map22.map[map22.width * (map22.height - 1) + headRect.right - 1]);
82980
83925
  } else {
82981
- if (headRect.top > 0)
82982
- $headCell = doc2.resolve(tableStart + map22.map[headRect.left]);
82983
- if (anchorRect.bottom < map22.height)
82984
- $anchorCell = doc2.resolve(
82985
- tableStart + map22.map[map22.width * (map22.height - 1) + anchorRect.right - 1]
82986
- );
83926
+ if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map22.map[headRect.left]);
83927
+ if (anchorRect.bottom < map22.height) $anchorCell = doc2.resolve(tableStart + map22.map[map22.width * (map22.height - 1) + anchorRect.right - 1]);
82987
83928
  }
82988
- return new _CellSelection($anchorCell, $headCell);
83929
+ return new CellSelection2($anchorCell, $headCell);
82989
83930
  }
82990
- // True if this selection goes all the way from the left to the
82991
- // right of the table.
82992
83931
  isRowSelection() {
82993
83932
  const table = this.$anchorCell.node(-1);
82994
83933
  const map22 = TableMap.get(table);
@@ -83001,10 +83940,8 @@ var CellSelection = class _CellSelection extends Selection {
83001
83940
  return Math.max(anchorRight, headRight) == map22.width;
83002
83941
  }
83003
83942
  eq(other) {
83004
- return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
83943
+ return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
83005
83944
  }
83006
- // Returns the smallest row selection that covers the given anchor
83007
- // and head cell.
83008
83945
  static rowSelection($anchorCell, $headCell = $anchorCell) {
83009
83946
  const table = $anchorCell.node(-1);
83010
83947
  const map22 = TableMap.get(table);
@@ -83013,23 +83950,13 @@ var CellSelection = class _CellSelection extends Selection {
83013
83950
  const headRect = map22.findCell($headCell.pos - tableStart);
83014
83951
  const doc2 = $anchorCell.node(0);
83015
83952
  if (anchorRect.left <= headRect.left) {
83016
- if (anchorRect.left > 0)
83017
- $anchorCell = doc2.resolve(
83018
- tableStart + map22.map[anchorRect.top * map22.width]
83019
- );
83020
- if (headRect.right < map22.width)
83021
- $headCell = doc2.resolve(
83022
- tableStart + map22.map[map22.width * (headRect.top + 1) - 1]
83023
- );
83953
+ if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map22.map[anchorRect.top * map22.width]);
83954
+ if (headRect.right < map22.width) $headCell = doc2.resolve(tableStart + map22.map[map22.width * (headRect.top + 1) - 1]);
83024
83955
  } else {
83025
- if (headRect.left > 0)
83026
- $headCell = doc2.resolve(tableStart + map22.map[headRect.top * map22.width]);
83027
- if (anchorRect.right < map22.width)
83028
- $anchorCell = doc2.resolve(
83029
- tableStart + map22.map[map22.width * (anchorRect.top + 1) - 1]
83030
- );
83956
+ if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map22.map[headRect.top * map22.width]);
83957
+ if (anchorRect.right < map22.width) $anchorCell = doc2.resolve(tableStart + map22.map[map22.width * (anchorRect.top + 1) - 1]);
83031
83958
  }
83032
- return new _CellSelection($anchorCell, $headCell);
83959
+ return new CellSelection2($anchorCell, $headCell);
83033
83960
  }
83034
83961
  toJSON() {
83035
83962
  return {
@@ -83039,10 +83966,10 @@ var CellSelection = class _CellSelection extends Selection {
83039
83966
  };
83040
83967
  }
83041
83968
  static fromJSON(doc2, json) {
83042
- return new _CellSelection(doc2.resolve(json.anchor), doc2.resolve(json.head));
83969
+ return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head));
83043
83970
  }
83044
83971
  static create(doc2, anchorCell, headCell = anchorCell) {
83045
- return new _CellSelection(doc2.resolve(anchorCell), doc2.resolve(headCell));
83972
+ return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell));
83046
83973
  }
83047
83974
  getBookmark() {
83048
83975
  return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
@@ -83050,18 +83977,17 @@ var CellSelection = class _CellSelection extends Selection {
83050
83977
  };
83051
83978
  CellSelection.prototype.visible = false;
83052
83979
  Selection.jsonID("cell", CellSelection);
83053
- var CellBookmark = class _CellBookmark {
83980
+ var CellBookmark = class CellBookmark2 {
83054
83981
  constructor(anchor, head) {
83055
83982
  this.anchor = anchor;
83056
83983
  this.head = head;
83057
83984
  }
83058
83985
  map(mapping) {
83059
- return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
83986
+ return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head));
83060
83987
  }
83061
83988
  resolve(doc2) {
83062
83989
  const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head);
83063
- 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))
83064
- return new CellSelection($anchorCell, $headCell);
83990
+ 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);
83065
83991
  else return Selection.near($headCell, 1);
83066
83992
  }
83067
83993
  };
@@ -83069,9 +83995,7 @@ function drawCellSelection(state2) {
83069
83995
  if (!(state2.selection instanceof CellSelection)) return null;
83070
83996
  const cells = [];
83071
83997
  state2.selection.forEachCell((node, pos) => {
83072
- cells.push(
83073
- Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
83074
- );
83998
+ cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
83075
83999
  });
83076
84000
  return DecorationSet.create(state2.doc, cells);
83077
84001
  }
@@ -83080,10 +84004,8 @@ function isCellBoundarySelection({ $from, $to }) {
83080
84004
  let afterFrom = $from.pos;
83081
84005
  let beforeTo = $to.pos;
83082
84006
  let depth = $from.depth;
83083
- for (; depth >= 0; depth--, afterFrom++)
83084
- if ($from.after(depth + 1) < $from.end(depth)) break;
83085
- for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--)
83086
- if ($to.before(d2 + 1) > $to.start(d2)) break;
84007
+ for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
84008
+ for (let d2 = $to.depth; d2 >= 0; d2--, beforeTo--) if ($to.before(d2 + 1) > $to.start(d2)) break;
83087
84009
  return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
83088
84010
  }
83089
84011
  function isTextSelectionAcrossCells({ $from, $to }) {
@@ -83111,9 +84033,8 @@ function normalizeSelection(state2, tr, allowTableNodeSelection) {
83111
84033
  let normalize2;
83112
84034
  let role;
83113
84035
  if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
83114
- if (role == "cell" || role == "header_cell") {
83115
- normalize2 = CellSelection.create(doc2, sel.from);
83116
- } else if (role == "row") {
84036
+ if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from);
84037
+ else if (role == "row") {
83117
84038
  const $cell = doc2.resolve(sel.from + 1);
83118
84039
  normalize2 = CellSelection.rowSelection($cell, $cell);
83119
84040
  } else if (!allowTableNodeSelection) {
@@ -83122,29 +84043,23 @@ function normalizeSelection(state2, tr, allowTableNodeSelection) {
83122
84043
  const lastCell = start2 + map22.map[map22.width * map22.height - 1];
83123
84044
  normalize2 = CellSelection.create(doc2, start2 + 1, lastCell);
83124
84045
  }
83125
- } else if (sel instanceof TextSelection$1 && isCellBoundarySelection(sel)) {
83126
- normalize2 = TextSelection$1.create(doc2, sel.from);
83127
- } else if (sel instanceof TextSelection$1 && isTextSelectionAcrossCells(sel)) {
83128
- normalize2 = TextSelection$1.create(doc2, sel.$from.start(), sel.$from.end());
83129
- }
84046
+ } else if (sel instanceof TextSelection$1 && isCellBoundarySelection(sel)) normalize2 = TextSelection$1.create(doc2, sel.from);
84047
+ else if (sel instanceof TextSelection$1 && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection$1.create(doc2, sel.$from.start(), sel.$from.end());
83130
84048
  if (normalize2) (tr || (tr = state2.tr)).setSelection(normalize2);
83131
84049
  return tr;
83132
84050
  }
83133
- var fixTablesKey = new PluginKey("fix-tables");
84051
+ const fixTablesKey = new PluginKey("fix-tables");
83134
84052
  function changedDescendants(old, cur, offset2, f2) {
83135
84053
  const oldSize = old.childCount, curSize = cur.childCount;
83136
84054
  outer: for (let i = 0, j2 = 0; i < curSize; i++) {
83137
84055
  const child = cur.child(i);
83138
- for (let scan = j2, e = Math.min(oldSize, i + 3); scan < e; scan++) {
83139
- if (old.child(scan) == child) {
83140
- j2 = scan + 1;
83141
- offset2 += child.nodeSize;
83142
- continue outer;
83143
- }
84056
+ for (let scan = j2, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {
84057
+ j2 = scan + 1;
84058
+ offset2 += child.nodeSize;
84059
+ continue outer;
83144
84060
  }
83145
84061
  f2(child, offset2);
83146
- if (j2 < oldSize && old.child(j2).sameMarkup(child))
83147
- changedDescendants(old.child(j2), child, offset2 + 1, f2);
84062
+ if (j2 < oldSize && old.child(j2).sameMarkup(child)) changedDescendants(old.child(j2), child, offset2 + 1, f2);
83148
84063
  else child.nodesBetween(0, child.content.size, f2, offset2 + 1);
83149
84064
  offset2 += child.nodeSize;
83150
84065
  }
@@ -83152,12 +84067,10 @@ function changedDescendants(old, cur, offset2, f2) {
83152
84067
  function fixTables(state2, oldState) {
83153
84068
  let tr;
83154
84069
  const check = (node, pos) => {
83155
- if (node.type.spec.tableRole == "table")
83156
- tr = fixTable(state2, node, pos, tr);
84070
+ if (node.type.spec.tableRole == "table") tr = fixTable(state2, node, pos, tr);
83157
84071
  };
83158
84072
  if (!oldState) state2.doc.descendants(check);
83159
- else if (oldState.doc != state2.doc)
83160
- changedDescendants(oldState.doc, state2.doc, 0, check);
84073
+ else if (oldState.doc != state2.doc) changedDescendants(oldState.doc, state2.doc, 0, check);
83161
84074
  return tr;
83162
84075
  }
83163
84076
  function fixTable(state2, table, tablePos, tr) {
@@ -83173,14 +84086,9 @@ function fixTable(state2, table, tablePos, tr) {
83173
84086
  if (!cell) continue;
83174
84087
  const attrs = cell.attrs;
83175
84088
  for (let j2 = 0; j2 < attrs.rowspan; j2++) mustAdd[prob.row + j2] += prob.n;
83176
- tr.setNodeMarkup(
83177
- tr.mapping.map(tablePos + 1 + prob.pos),
83178
- null,
83179
- removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
83180
- );
83181
- } else if (prob.type == "missing") {
83182
- mustAdd[prob.row] += prob.n;
83183
- } else if (prob.type == "overlong_rowspan") {
84089
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
84090
+ } else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
84091
+ else if (prob.type == "overlong_rowspan") {
83184
84092
  const cell = table.nodeAt(prob.pos);
83185
84093
  if (!cell) continue;
83186
84094
  tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
@@ -83200,20 +84108,17 @@ function fixTable(state2, table, tablePos, tr) {
83200
84108
  }
83201
84109
  }
83202
84110
  let first2, last;
83203
- for (let i = 0; i < mustAdd.length; i++)
83204
- if (mustAdd[i]) {
83205
- if (first2 == null) first2 = i;
83206
- last = i;
83207
- }
84111
+ for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
84112
+ if (first2 == null) first2 = i;
84113
+ last = i;
84114
+ }
83208
84115
  for (let i = 0, pos = tablePos + 1; i < map22.height; i++) {
83209
84116
  const row = table.child(i);
83210
84117
  const end2 = pos + row.nodeSize;
83211
84118
  const add = mustAdd[i];
83212
84119
  if (add > 0) {
83213
84120
  let role = "cell";
83214
- if (row.firstChild) {
83215
- role = row.firstChild.type.spec.tableRole;
83216
- }
84121
+ if (row.firstChild) role = row.firstChild.type.spec.tableRole;
83217
84122
  const nodes = [];
83218
84123
  for (let j2 = 0; j2 < add; j2++) {
83219
84124
  const node = tableNodeTypes(state2.schema)[role].createAndFill();
@@ -83232,27 +84137,22 @@ function selectedRect(state2) {
83232
84137
  const table = $pos.node(-1);
83233
84138
  const tableStart = $pos.start(-1);
83234
84139
  const map22 = TableMap.get(table);
83235
- const rect = sel instanceof CellSelection ? map22.rectBetween(
83236
- sel.$anchorCell.pos - tableStart,
83237
- sel.$headCell.pos - tableStart
83238
- ) : map22.findCell($pos.pos - tableStart);
83239
- return { ...rect, tableStart, map: map22, table };
84140
+ return {
84141
+ ...sel instanceof CellSelection ? map22.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map22.findCell($pos.pos - tableStart),
84142
+ tableStart,
84143
+ map: map22,
84144
+ table
84145
+ };
83240
84146
  }
83241
84147
  function addColumn(tr, { map: map22, tableStart, table }, col) {
83242
84148
  let refColumn = col > 0 ? -1 : 0;
83243
- if (columnIsHeader(map22, table, col + refColumn)) {
83244
- refColumn = col == 0 || col == map22.width ? null : 0;
83245
- }
84149
+ if (columnIsHeader(map22, table, col + refColumn)) refColumn = col == 0 || col == map22.width ? null : 0;
83246
84150
  for (let row = 0; row < map22.height; row++) {
83247
84151
  const index2 = row * map22.width + col;
83248
84152
  if (col > 0 && col < map22.width && map22.map[index2 - 1] == map22.map[index2]) {
83249
84153
  const pos = map22.map[index2];
83250
84154
  const cell = table.nodeAt(pos);
83251
- tr.setNodeMarkup(
83252
- tr.mapping.map(tableStart + pos),
83253
- null,
83254
- addColSpan(cell.attrs, col - map22.colCount(pos))
83255
- );
84155
+ tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map22.colCount(pos)));
83256
84156
  row += cell.attrs.rowspan - 1;
83257
84157
  } else {
83258
84158
  const type2 = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map22.map[index2 + refColumn]).type;
@@ -83285,13 +84185,8 @@ function removeColumn(tr, { map: map22, table, tableStart }, col) {
83285
84185
  const pos = map22.map[index2];
83286
84186
  const cell = table.nodeAt(pos);
83287
84187
  const attrs = cell.attrs;
83288
- if (col > 0 && map22.map[index2 - 1] == pos || col < map22.width - 1 && map22.map[index2 + 1] == pos) {
83289
- tr.setNodeMarkup(
83290
- tr.mapping.slice(mapStart).map(tableStart + pos),
83291
- null,
83292
- removeColSpan(attrs, col - map22.colCount(pos))
83293
- );
83294
- } else {
84188
+ if (col > 0 && map22.map[index2 - 1] == pos || col < map22.width - 1 && map22.map[index2 + 1] == pos) tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map22.colCount(pos)));
84189
+ else {
83295
84190
  const start2 = tr.mapping.slice(mapStart).map(tableStart + pos);
83296
84191
  tr.delete(start2, start2 + cell.nodeSize);
83297
84192
  }
@@ -83308,9 +84203,7 @@ function deleteColumn(state2, dispatch) {
83308
84203
  removeColumn(tr, rect, i);
83309
84204
  if (i == rect.left) break;
83310
84205
  const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
83311
- if (!table) {
83312
- throw RangeError("No table found");
83313
- }
84206
+ if (!table) throw new RangeError("No table found");
83314
84207
  rect.table = table;
83315
84208
  rect.map = TableMap.get(table);
83316
84209
  }
@@ -83319,35 +84212,30 @@ function deleteColumn(state2, dispatch) {
83319
84212
  return true;
83320
84213
  }
83321
84214
  function rowIsHeader(map22, table, row) {
83322
- var _a2;
84215
+ var _table$nodeAt;
83323
84216
  const headerCell = tableNodeTypes(table.type.schema).header_cell;
83324
- for (let col = 0; col < map22.width; col++)
83325
- if (((_a2 = table.nodeAt(map22.map[col + row * map22.width])) == null ? void 0 : _a2.type) != headerCell)
83326
- return false;
84217
+ for (let col = 0; col < map22.width; col++) if (((_table$nodeAt = table.nodeAt(map22.map[col + row * map22.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
83327
84218
  return true;
83328
84219
  }
83329
84220
  function addRow(tr, { map: map22, tableStart, table }, row) {
83330
- var _a2;
83331
84221
  let rowPos = tableStart;
83332
84222
  for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
83333
84223
  const cells = [];
83334
84224
  let refRow = row > 0 ? -1 : 0;
83335
- if (rowIsHeader(map22, table, row + refRow))
83336
- refRow = row == 0 || row == map22.height ? null : 0;
83337
- for (let col = 0, index2 = map22.width * row; col < map22.width; col++, index2++) {
83338
- if (row > 0 && row < map22.height && map22.map[index2] == map22.map[index2 - map22.width]) {
83339
- const pos = map22.map[index2];
83340
- const attrs = table.nodeAt(pos).attrs;
83341
- tr.setNodeMarkup(tableStart + pos, null, {
83342
- ...attrs,
83343
- rowspan: attrs.rowspan + 1
83344
- });
83345
- col += attrs.colspan - 1;
83346
- } else {
83347
- const type2 = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a2 = table.nodeAt(map22.map[index2 + refRow * map22.width])) == null ? void 0 : _a2.type;
83348
- const node = type2 == null ? void 0 : type2.createAndFill();
83349
- if (node) cells.push(node);
83350
- }
84225
+ if (rowIsHeader(map22, table, row + refRow)) refRow = row == 0 || row == map22.height ? null : 0;
84226
+ for (let col = 0, index2 = map22.width * row; col < map22.width; col++, index2++) if (row > 0 && row < map22.height && map22.map[index2] == map22.map[index2 - map22.width]) {
84227
+ const pos = map22.map[index2];
84228
+ const attrs = table.nodeAt(pos).attrs;
84229
+ tr.setNodeMarkup(tableStart + pos, null, {
84230
+ ...attrs,
84231
+ rowspan: attrs.rowspan + 1
84232
+ });
84233
+ col += attrs.colspan - 1;
84234
+ } else {
84235
+ var _table$nodeAt2;
84236
+ const type2 = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map22.map[index2 + refRow * map22.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
84237
+ const node = type2 === null || type2 === void 0 ? void 0 : type2.createAndFill();
84238
+ if (node) cells.push(node);
83351
84239
  }
83352
84240
  tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
83353
84241
  return tr;
@@ -83389,10 +84277,10 @@ function removeRow(tr, { map: map22, table, tableStart }, row) {
83389
84277
  } else if (row < map22.height && pos == map22.map[index2 + map22.width]) {
83390
84278
  const cell = table.nodeAt(pos);
83391
84279
  const attrs = cell.attrs;
83392
- const copy2 = cell.type.create(
83393
- { ...attrs, rowspan: cell.attrs.rowspan - 1 },
83394
- cell.content
83395
- );
84280
+ const copy2 = cell.type.create({
84281
+ ...attrs,
84282
+ rowspan: cell.attrs.rowspan - 1
84283
+ }, cell.content);
83396
84284
  const newPos = map22.positionAt(row + 1, col, table);
83397
84285
  tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy2);
83398
84286
  col += attrs.colspan - 1;
@@ -83408,9 +84296,7 @@ function deleteRow(state2, dispatch) {
83408
84296
  removeRow(tr, rect, i);
83409
84297
  if (i == rect.top) break;
83410
84298
  const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
83411
- if (!table) {
83412
- throw RangeError("No table found");
83413
- }
84299
+ if (!table) throw new RangeError("No table found");
83414
84300
  rect.table = table;
83415
84301
  rect.map = TableMap.get(rect.table);
83416
84302
  }
@@ -83426,14 +84312,12 @@ function cellsOverlapRectangle({ width, height, map: map22 }, rect) {
83426
84312
  let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
83427
84313
  let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
83428
84314
  for (let i = rect.top; i < rect.bottom; i++) {
83429
- if (rect.left > 0 && map22[indexLeft] == map22[indexLeft - 1] || rect.right < width && map22[indexRight] == map22[indexRight + 1])
83430
- return true;
84315
+ if (rect.left > 0 && map22[indexLeft] == map22[indexLeft - 1] || rect.right < width && map22[indexRight] == map22[indexRight + 1]) return true;
83431
84316
  indexLeft += width;
83432
84317
  indexRight += width;
83433
84318
  }
83434
84319
  for (let i = rect.left; i < rect.right; i++) {
83435
- if (rect.top > 0 && map22[indexTop] == map22[indexTop - width] || rect.bottom < height && map22[indexBottom] == map22[indexBottom + width])
83436
- return true;
84320
+ if (rect.top > 0 && map22[indexTop] == map22[indexTop - width] || rect.bottom < height && map22[indexBottom] == map22[indexBottom + width]) return true;
83437
84321
  indexTop++;
83438
84322
  indexBottom++;
83439
84323
  }
@@ -83441,8 +84325,7 @@ function cellsOverlapRectangle({ width, height, map: map22 }, rect) {
83441
84325
  }
83442
84326
  function mergeCells(state2, dispatch) {
83443
84327
  const sel = state2.selection;
83444
- if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
83445
- return false;
84328
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
83446
84329
  const rect = selectedRect(state2), { map: map22 } = rect;
83447
84330
  if (cellsOverlapRectangle(map22, rect)) return false;
83448
84331
  if (dispatch) {
@@ -83451,41 +84334,31 @@ function mergeCells(state2, dispatch) {
83451
84334
  let content = Fragment.empty;
83452
84335
  let mergedPos;
83453
84336
  let mergedCell;
83454
- for (let row = rect.top; row < rect.bottom; row++) {
83455
- for (let col = rect.left; col < rect.right; col++) {
83456
- const cellPos = map22.map[row * map22.width + col];
83457
- const cell = rect.table.nodeAt(cellPos);
83458
- if (seen[cellPos] || !cell) continue;
83459
- seen[cellPos] = true;
83460
- if (mergedPos == null) {
83461
- mergedPos = cellPos;
83462
- mergedCell = cell;
83463
- } else {
83464
- if (!isEmpty(cell)) content = content.append(cell.content);
83465
- const mapped = tr.mapping.map(cellPos + rect.tableStart);
83466
- tr.delete(mapped, mapped + cell.nodeSize);
83467
- }
84337
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
84338
+ const cellPos = map22.map[row * map22.width + col];
84339
+ const cell = rect.table.nodeAt(cellPos);
84340
+ if (seen[cellPos] || !cell) continue;
84341
+ seen[cellPos] = true;
84342
+ if (mergedPos == null) {
84343
+ mergedPos = cellPos;
84344
+ mergedCell = cell;
84345
+ } else {
84346
+ if (!isEmpty(cell)) content = content.append(cell.content);
84347
+ const mapped = tr.mapping.map(cellPos + rect.tableStart);
84348
+ tr.delete(mapped, mapped + cell.nodeSize);
83468
84349
  }
83469
84350
  }
83470
- if (mergedPos == null || mergedCell == null) {
83471
- return true;
83472
- }
84351
+ if (mergedPos == null || mergedCell == null) return true;
83473
84352
  tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
83474
- ...addColSpan(
83475
- mergedCell.attrs,
83476
- mergedCell.attrs.colspan,
83477
- rect.right - rect.left - mergedCell.attrs.colspan
83478
- ),
84353
+ ...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
83479
84354
  rowspan: rect.bottom - rect.top
83480
84355
  });
83481
- if (content.size) {
84356
+ if (content.size > 0) {
83482
84357
  const end2 = mergedPos + 1 + mergedCell.content.size;
83483
84358
  const start2 = isEmpty(mergedCell) ? mergedPos + 1 : end2;
83484
84359
  tr.replaceWith(start2 + rect.tableStart, end2 + rect.tableStart, content);
83485
84360
  }
83486
- tr.setSelection(
83487
- new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
83488
- );
84361
+ tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
83489
84362
  dispatch(tr);
83490
84363
  }
83491
84364
  return true;
@@ -83498,63 +84371,57 @@ function splitCell(state2, dispatch) {
83498
84371
  }
83499
84372
  function splitCellWithType(getCellType2) {
83500
84373
  return (state2, dispatch) => {
83501
- var _a2;
83502
84374
  const sel = state2.selection;
83503
84375
  let cellNode;
83504
84376
  let cellPos;
83505
84377
  if (!(sel instanceof CellSelection)) {
84378
+ var _cellAround;
83506
84379
  cellNode = cellWrapping$1(sel.$from);
83507
84380
  if (!cellNode) return false;
83508
- cellPos = (_a2 = cellAround$1(sel.$from)) == null ? void 0 : _a2.pos;
84381
+ cellPos = (_cellAround = cellAround$1(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
83509
84382
  } else {
83510
84383
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
83511
84384
  cellNode = sel.$anchorCell.nodeAfter;
83512
84385
  cellPos = sel.$anchorCell.pos;
83513
84386
  }
83514
- if (cellNode == null || cellPos == null) {
83515
- return false;
83516
- }
83517
- if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
83518
- return false;
83519
- }
84387
+ if (cellNode == null || cellPos == null) return false;
84388
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
83520
84389
  if (dispatch) {
83521
84390
  let baseAttrs = cellNode.attrs;
83522
84391
  const attrs = [];
83523
84392
  const colwidth = baseAttrs.colwidth;
83524
- if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };
83525
- if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };
84393
+ if (baseAttrs.rowspan > 1) baseAttrs = {
84394
+ ...baseAttrs,
84395
+ rowspan: 1
84396
+ };
84397
+ if (baseAttrs.colspan > 1) baseAttrs = {
84398
+ ...baseAttrs,
84399
+ colspan: 1
84400
+ };
83526
84401
  const rect = selectedRect(state2), tr = state2.tr;
83527
- for (let i = 0; i < rect.right - rect.left; i++)
83528
- attrs.push(
83529
- colwidth ? {
83530
- ...baseAttrs,
83531
- colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
83532
- } : baseAttrs
83533
- );
84402
+ for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {
84403
+ ...baseAttrs,
84404
+ colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
84405
+ } : baseAttrs);
83534
84406
  let lastCell;
83535
84407
  for (let row = rect.top; row < rect.bottom; row++) {
83536
84408
  let pos = rect.map.positionAt(row, rect.left, rect.table);
83537
84409
  if (row == rect.top) pos += cellNode.nodeSize;
83538
84410
  for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
83539
84411
  if (col == rect.left && row == rect.top) continue;
83540
- tr.insert(
83541
- lastCell = tr.mapping.map(pos + rect.tableStart, 1),
83542
- getCellType2({ node: cellNode, row, col }).createAndFill(attrs[i])
83543
- );
83544
- }
83545
- }
83546
- tr.setNodeMarkup(
83547
- cellPos,
83548
- getCellType2({ node: cellNode, row: rect.top, col: rect.left }),
83549
- attrs[0]
83550
- );
83551
- if (sel instanceof CellSelection)
83552
- tr.setSelection(
83553
- new CellSelection(
83554
- tr.doc.resolve(sel.$anchorCell.pos),
83555
- lastCell ? tr.doc.resolve(lastCell) : void 0
83556
- )
83557
- );
84412
+ tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType2({
84413
+ node: cellNode,
84414
+ row,
84415
+ col
84416
+ }).createAndFill(attrs[i]));
84417
+ }
84418
+ }
84419
+ tr.setNodeMarkup(cellPos, getCellType2({
84420
+ node: cellNode,
84421
+ row: rect.top,
84422
+ col: rect.left
84423
+ }), attrs[0]);
84424
+ if (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));
83558
84425
  dispatch(tr);
83559
84426
  }
83560
84427
  return true;
@@ -83567,19 +84434,16 @@ function setCellAttr(name, value) {
83567
84434
  if ($cell.nodeAfter.attrs[name] === value) return false;
83568
84435
  if (dispatch) {
83569
84436
  const tr = state2.tr;
83570
- if (state2.selection instanceof CellSelection)
83571
- state2.selection.forEachCell((node, pos) => {
83572
- if (node.attrs[name] !== value)
83573
- tr.setNodeMarkup(pos, null, {
83574
- ...node.attrs,
83575
- [name]: value
83576
- });
83577
- });
83578
- else
83579
- tr.setNodeMarkup($cell.pos, null, {
83580
- ...$cell.nodeAfter.attrs,
84437
+ if (state2.selection instanceof CellSelection) state2.selection.forEachCell((node, pos) => {
84438
+ if (node.attrs[name] !== value) tr.setNodeMarkup(pos, null, {
84439
+ ...node.attrs,
83581
84440
  [name]: value
83582
84441
  });
84442
+ });
84443
+ else tr.setNodeMarkup($cell.pos, null, {
84444
+ ...$cell.nodeAfter.attrs,
84445
+ [name]: value
84446
+ });
83583
84447
  dispatch(tr);
83584
84448
  }
83585
84449
  return true;
@@ -83591,34 +84455,20 @@ function deprecated_toggleHeader(type2) {
83591
84455
  if (dispatch) {
83592
84456
  const types2 = tableNodeTypes(state2.schema);
83593
84457
  const rect = selectedRect(state2), tr = state2.tr;
83594
- const cells = rect.map.cellsInRect(
83595
- type2 == "column" ? {
83596
- left: rect.left,
83597
- top: 0,
83598
- right: rect.right,
83599
- bottom: rect.map.height
83600
- } : type2 == "row" ? {
83601
- left: 0,
83602
- top: rect.top,
83603
- right: rect.map.width,
83604
- bottom: rect.bottom
83605
- } : rect
83606
- );
84458
+ const cells = rect.map.cellsInRect(type2 == "column" ? {
84459
+ left: rect.left,
84460
+ top: 0,
84461
+ right: rect.right,
84462
+ bottom: rect.map.height
84463
+ } : type2 == "row" ? {
84464
+ left: 0,
84465
+ top: rect.top,
84466
+ right: rect.map.width,
84467
+ bottom: rect.bottom
84468
+ } : rect);
83607
84469
  const nodes = cells.map((pos) => rect.table.nodeAt(pos));
83608
- for (let i = 0; i < cells.length; i++)
83609
- if (nodes[i].type == types2.header_cell)
83610
- tr.setNodeMarkup(
83611
- rect.tableStart + cells[i],
83612
- types2.cell,
83613
- nodes[i].attrs
83614
- );
83615
- if (tr.steps.length == 0)
83616
- for (let i = 0; i < cells.length; i++)
83617
- tr.setNodeMarkup(
83618
- rect.tableStart + cells[i],
83619
- types2.header_cell,
83620
- nodes[i].attrs
83621
- );
84470
+ for (let i = 0; i < cells.length; i++) if (nodes[i].type == types2.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i], types2.cell, nodes[i].attrs);
84471
+ if (tr.steps.length === 0) for (let i = 0; i < cells.length; i++) tr.setNodeMarkup(rect.tableStart + cells[i], types2.header_cell, nodes[i].attrs);
83622
84472
  dispatch(tr);
83623
84473
  }
83624
84474
  return true;
@@ -83633,9 +84483,7 @@ function isHeaderEnabledByType(type2, rect, types2) {
83633
84483
  });
83634
84484
  for (let i = 0; i < cellPositions.length; i++) {
83635
84485
  const cell = rect.table.nodeAt(cellPositions[i]);
83636
- if (cell && cell.type !== types2.header_cell) {
83637
- return false;
83638
- }
84486
+ if (cell && cell.type !== types2.header_cell) return false;
83639
84487
  }
83640
84488
  return true;
83641
84489
  }
@@ -83648,13 +84496,8 @@ function toggleHeader(type2, options) {
83648
84496
  const types2 = tableNodeTypes(state2.schema);
83649
84497
  const rect = selectedRect(state2), tr = state2.tr;
83650
84498
  const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types2);
83651
- const isHeaderColumnEnabled = isHeaderEnabledByType(
83652
- "column",
83653
- rect,
83654
- types2
83655
- );
83656
- const isHeaderEnabled = type2 === "column" ? isHeaderRowEnabled : type2 === "row" ? isHeaderColumnEnabled : false;
83657
- const selectionStartsAt = isHeaderEnabled ? 1 : 0;
84499
+ const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types2);
84500
+ const selectionStartsAt = (type2 === "column" ? isHeaderRowEnabled : type2 === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
83658
84501
  const cellsRect = type2 == "column" ? {
83659
84502
  left: 0,
83660
84503
  top: selectionStartsAt,
@@ -83670,24 +84513,16 @@ function toggleHeader(type2, options) {
83670
84513
  rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
83671
84514
  const cellPos = relativeCellPos + rect.tableStart;
83672
84515
  const cell = tr.doc.nodeAt(cellPos);
83673
- if (cell) {
83674
- tr.setNodeMarkup(cellPos, newType, cell.attrs);
83675
- }
84516
+ if (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);
83676
84517
  });
83677
84518
  dispatch(tr);
83678
84519
  }
83679
84520
  return true;
83680
84521
  };
83681
84522
  }
83682
- toggleHeader("row", {
83683
- useDeprecatedLogic: true
83684
- });
83685
- toggleHeader("column", {
83686
- useDeprecatedLogic: true
83687
- });
83688
- var toggleHeaderCell = toggleHeader("cell", {
83689
- useDeprecatedLogic: true
83690
- });
84523
+ toggleHeader("row", { useDeprecatedLogic: true });
84524
+ toggleHeader("column", { useDeprecatedLogic: true });
84525
+ const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
83691
84526
  function findNextCell($cell, dir) {
83692
84527
  if (dir < 0) {
83693
84528
  const before = $cell.nodeBefore;
@@ -83695,15 +84530,11 @@ function findNextCell($cell, dir) {
83695
84530
  for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
83696
84531
  const rowNode = $cell.node(-1).child(row);
83697
84532
  const lastChild = rowNode.lastChild;
83698
- if (lastChild) {
83699
- return rowEnd - 1 - lastChild.nodeSize;
83700
- }
84533
+ if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
83701
84534
  rowEnd -= rowNode.nodeSize;
83702
84535
  }
83703
84536
  } else {
83704
- if ($cell.index() < $cell.parent.childCount - 1) {
83705
- return $cell.pos + $cell.nodeAfter.nodeSize;
83706
- }
84537
+ if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
83707
84538
  const table = $cell.node(-1);
83708
84539
  for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
83709
84540
  const rowNode = table.child(row);
@@ -83720,24 +84551,16 @@ function goToNextCell(direction) {
83720
84551
  if (cell == null) return false;
83721
84552
  if (dispatch) {
83722
84553
  const $cell = state2.doc.resolve(cell);
83723
- dispatch(
83724
- state2.tr.setSelection(TextSelection$1.between($cell, moveCellForward($cell))).scrollIntoView()
83725
- );
84554
+ dispatch(state2.tr.setSelection(TextSelection$1.between($cell, moveCellForward($cell))).scrollIntoView());
83726
84555
  }
83727
84556
  return true;
83728
84557
  };
83729
84558
  }
83730
84559
  function deleteTable(state2, dispatch) {
83731
84560
  const $pos = state2.selection.$anchor;
83732
- for (let d2 = $pos.depth; d2 > 0; d2--) {
83733
- const node = $pos.node(d2);
83734
- if (node.type.spec.tableRole == "table") {
83735
- if (dispatch)
83736
- dispatch(
83737
- state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView()
83738
- );
83739
- return true;
83740
- }
84561
+ for (let d2 = $pos.depth; d2 > 0; d2--) if ($pos.node(d2).type.spec.tableRole == "table") {
84562
+ if (dispatch) dispatch(state2.tr.delete($pos.before(d2), $pos.after(d2)).scrollIntoView());
84563
+ return true;
83741
84564
  }
83742
84565
  return false;
83743
84566
  }
@@ -83748,19 +84571,14 @@ function deleteCellSelection(state2, dispatch) {
83748
84571
  const tr = state2.tr;
83749
84572
  const baseContent = tableNodeTypes(state2.schema).cell.createAndFill().content;
83750
84573
  sel.forEachCell((cell, pos) => {
83751
- if (!cell.content.eq(baseContent))
83752
- tr.replace(
83753
- tr.mapping.map(pos + 1),
83754
- tr.mapping.map(pos + cell.nodeSize - 1),
83755
- new Slice(baseContent, 0, 0)
83756
- );
84574
+ if (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
83757
84575
  });
83758
84576
  if (tr.docChanged) dispatch(tr);
83759
84577
  }
83760
84578
  return true;
83761
84579
  }
83762
84580
  function pastedCells(slice2) {
83763
- if (!slice2.size) return null;
84581
+ if (slice2.size === 0) return null;
83764
84582
  let { content, openStart, openEnd } = slice2;
83765
84583
  while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
83766
84584
  openStart--;
@@ -83770,28 +84588,15 @@ function pastedCells(slice2) {
83770
84588
  const first2 = content.child(0);
83771
84589
  const role = first2.type.spec.tableRole;
83772
84590
  const schema = first2.type.schema, rows = [];
83773
- if (role == "row") {
83774
- for (let i = 0; i < content.childCount; i++) {
83775
- let cells = content.child(i).content;
83776
- const left2 = i ? 0 : Math.max(0, openStart - 1);
83777
- const right2 = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
83778
- if (left2 || right2)
83779
- cells = fitSlice(
83780
- tableNodeTypes(schema).row,
83781
- new Slice(cells, left2, right2)
83782
- ).content;
83783
- rows.push(cells);
83784
- }
83785
- } else if (role == "cell" || role == "header_cell") {
83786
- rows.push(
83787
- openStart || openEnd ? fitSlice(
83788
- tableNodeTypes(schema).row,
83789
- new Slice(content, openStart, openEnd)
83790
- ).content : content
83791
- );
83792
- } else {
83793
- return null;
83794
- }
84591
+ if (role == "row") for (let i = 0; i < content.childCount; i++) {
84592
+ let cells = content.child(i).content;
84593
+ const left2 = i ? 0 : Math.max(0, openStart - 1);
84594
+ const right2 = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
84595
+ if (left2 || right2) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left2, right2)).content;
84596
+ rows.push(cells);
84597
+ }
84598
+ else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
84599
+ else return null;
83795
84600
  return ensureRectangular(schema, rows);
83796
84601
  }
83797
84602
  function ensureRectangular(schema, rows) {
@@ -83800,8 +84605,7 @@ function ensureRectangular(schema, rows) {
83800
84605
  const row = rows[i];
83801
84606
  for (let j2 = row.childCount - 1; j2 >= 0; j2--) {
83802
84607
  const { rowspan, colspan } = row.child(j2).attrs;
83803
- for (let r2 = i; r2 < i + rowspan; r2++)
83804
- widths[r2] = (widths[r2] || 0) + colspan;
84608
+ for (let r2 = i; r2 < i + rowspan; r2++) widths[r2] = (widths[r2] || 0) + colspan;
83805
84609
  }
83806
84610
  }
83807
84611
  let width = 0;
@@ -83811,18 +84615,19 @@ function ensureRectangular(schema, rows) {
83811
84615
  if (widths[r2] < width) {
83812
84616
  const empty2 = tableNodeTypes(schema).cell.createAndFill();
83813
84617
  const cells = [];
83814
- for (let i = widths[r2]; i < width; i++) {
83815
- cells.push(empty2);
83816
- }
84618
+ for (let i = widths[r2]; i < width; i++) cells.push(empty2);
83817
84619
  rows[r2] = rows[r2].append(Fragment.from(cells));
83818
84620
  }
83819
84621
  }
83820
- return { height: rows.length, width, rows };
84622
+ return {
84623
+ height: rows.length,
84624
+ width,
84625
+ rows
84626
+ };
83821
84627
  }
83822
84628
  function fitSlice(nodeType, slice2) {
83823
84629
  const node = nodeType.createAndFill();
83824
- const tr = new Transform(node).replace(0, node.content.size, slice2);
83825
- return tr.doc;
84630
+ return new Transform(node).replace(0, node.content.size, slice2).doc;
83826
84631
  }
83827
84632
  function clipCells({ width, height, rows }, newWidth, newHeight) {
83828
84633
  if (width != newWidth) {
@@ -83832,19 +84637,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
83832
84637
  const frag = rows[row], cells = [];
83833
84638
  for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
83834
84639
  let cell = frag.child(i % frag.childCount);
83835
- if (col + cell.attrs.colspan > newWidth)
83836
- cell = cell.type.createChecked(
83837
- removeColSpan(
83838
- cell.attrs,
83839
- cell.attrs.colspan,
83840
- col + cell.attrs.colspan - newWidth
83841
- ),
83842
- cell.content
83843
- );
84640
+ if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
83844
84641
  cells.push(cell);
83845
84642
  col += cell.attrs.colspan;
83846
- for (let j2 = 1; j2 < cell.attrs.rowspan; j2++)
83847
- added[row + j2] = (added[row + j2] || 0) + cell.attrs.colspan;
84643
+ for (let j2 = 1; j2 < cell.attrs.rowspan; j2++) added[row + j2] = (added[row + j2] || 0) + cell.attrs.colspan;
83848
84644
  }
83849
84645
  newRows.push(Fragment.from(cells));
83850
84646
  }
@@ -83857,14 +84653,10 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
83857
84653
  const cells = [], source = rows[i % height];
83858
84654
  for (let j2 = 0; j2 < source.childCount; j2++) {
83859
84655
  let cell = source.child(j2);
83860
- if (row + cell.attrs.rowspan > newHeight)
83861
- cell = cell.type.create(
83862
- {
83863
- ...cell.attrs,
83864
- rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
83865
- },
83866
- cell.content
83867
- );
84656
+ if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
84657
+ ...cell.attrs,
84658
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
84659
+ }, cell.content);
83868
84660
  cells.push(cell);
83869
84661
  }
83870
84662
  newRows.push(Fragment.from(cells));
@@ -83872,33 +84664,32 @@ function clipCells({ width, height, rows }, newWidth, newHeight) {
83872
84664
  rows = newRows;
83873
84665
  height = newHeight;
83874
84666
  }
83875
- return { width, height, rows };
84667
+ return {
84668
+ width,
84669
+ height,
84670
+ rows
84671
+ };
83876
84672
  }
83877
84673
  function growTable(tr, map22, table, start2, width, height, mapFrom) {
83878
84674
  const schema = tr.doc.type.schema;
83879
84675
  const types2 = tableNodeTypes(schema);
83880
84676
  let empty2;
83881
84677
  let emptyHead;
83882
- if (width > map22.width) {
83883
- for (let row = 0, rowEnd = 0; row < map22.height; row++) {
83884
- const rowNode = table.child(row);
83885
- rowEnd += rowNode.nodeSize;
83886
- const cells = [];
83887
- let add;
83888
- if (rowNode.lastChild == null || rowNode.lastChild.type == types2.cell)
83889
- add = empty2 || (empty2 = types2.cell.createAndFill());
83890
- else add = emptyHead || (emptyHead = types2.header_cell.createAndFill());
83891
- for (let i = map22.width; i < width; i++) cells.push(add);
83892
- tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
83893
- }
84678
+ if (width > map22.width) for (let row = 0, rowEnd = 0; row < map22.height; row++) {
84679
+ const rowNode = table.child(row);
84680
+ rowEnd += rowNode.nodeSize;
84681
+ const cells = [];
84682
+ let add;
84683
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types2.cell) add = empty2 || (empty2 = types2.cell.createAndFill());
84684
+ else add = emptyHead || (emptyHead = types2.header_cell.createAndFill());
84685
+ for (let i = map22.width; i < width; i++) cells.push(add);
84686
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start2), cells);
83894
84687
  }
83895
84688
  if (height > map22.height) {
83896
84689
  const cells = [];
83897
- for (let i = 0, start22 = (map22.height - 1) * map22.width; i < Math.max(map22.width, width); i++) {
83898
- const header = i >= map22.width ? false : table.nodeAt(map22.map[start22 + i]).type == types2.header_cell;
83899
- cells.push(
83900
- header ? emptyHead || (emptyHead = types2.header_cell.createAndFill()) : empty2 || (empty2 = types2.cell.createAndFill())
83901
- );
84690
+ for (let i = 0, start$1 = (map22.height - 1) * map22.width; i < Math.max(map22.width, width); i++) {
84691
+ const header = i >= map22.width ? false : table.nodeAt(map22.map[start$1 + i]).type == types2.header_cell;
84692
+ cells.push(header ? emptyHead || (emptyHead = types2.header_cell.createAndFill()) : empty2 || (empty2 = types2.cell.createAndFill()));
83902
84693
  }
83903
84694
  const emptyRow = types2.row.create(null, Fragment.from(cells)), rows = [];
83904
84695
  for (let i = map22.height; i < height; i++) rows.push(emptyRow);
@@ -83919,13 +84710,10 @@ function isolateHorizontal(tr, map22, table, start2, left2, right2, top2, mapFro
83919
84710
  ...cell.attrs,
83920
84711
  rowspan: top2 - cellTop
83921
84712
  });
83922
- tr.insert(
83923
- tr.mapping.slice(mapFrom).map(map22.positionAt(top2, cellLeft, table)),
83924
- cell.type.createAndFill({
83925
- ...cell.attrs,
83926
- rowspan: cellTop + cell.attrs.rowspan - top2
83927
- })
83928
- );
84713
+ tr.insert(tr.mapping.slice(mapFrom).map(map22.positionAt(top2, cellLeft, table)), cell.type.createAndFill({
84714
+ ...cell.attrs,
84715
+ rowspan: cellTop + cell.attrs.rowspan - top2
84716
+ }));
83929
84717
  col += cell.attrs.colspan - 1;
83930
84718
  }
83931
84719
  }
@@ -83941,21 +84729,8 @@ function isolateVertical(tr, map22, table, start2, top2, bottom2, left2, mapFrom
83941
84729
  const cell = table.nodeAt(pos);
83942
84730
  const cellLeft = map22.colCount(pos);
83943
84731
  const updatePos = tr.mapping.slice(mapFrom).map(pos + start2);
83944
- tr.setNodeMarkup(
83945
- updatePos,
83946
- null,
83947
- removeColSpan(
83948
- cell.attrs,
83949
- left2 - cellLeft,
83950
- cell.attrs.colspan - (left2 - cellLeft)
83951
- )
83952
- );
83953
- tr.insert(
83954
- updatePos + cell.nodeSize,
83955
- cell.type.createAndFill(
83956
- removeColSpan(cell.attrs, 0, left2 - cellLeft)
83957
- )
83958
- );
84732
+ tr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left2 - cellLeft, cell.attrs.colspan - (left2 - cellLeft)));
84733
+ tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left2 - cellLeft)));
83959
84734
  row += cell.attrs.rowspan - 1;
83960
84735
  }
83961
84736
  }
@@ -83963,9 +84738,7 @@ function isolateVertical(tr, map22, table, start2, top2, bottom2, left2, mapFrom
83963
84738
  }
83964
84739
  function insertCells(state2, dispatch, tableStart, rect, cells) {
83965
84740
  let table = tableStart ? state2.doc.nodeAt(tableStart - 1) : state2.doc;
83966
- if (!table) {
83967
- throw new Error("No table found");
83968
- }
84741
+ if (!table) throw new Error("No table found");
83969
84742
  let map22 = TableMap.get(table);
83970
84743
  const { top: top2, left: left2 } = rect;
83971
84744
  const right2 = left2 + cells.width, bottom2 = top2 + cells.height;
@@ -83973,39 +84746,24 @@ function insertCells(state2, dispatch, tableStart, rect, cells) {
83973
84746
  let mapFrom = 0;
83974
84747
  function recomp() {
83975
84748
  table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
83976
- if (!table) {
83977
- throw new Error("No table found");
83978
- }
84749
+ if (!table) throw new Error("No table found");
83979
84750
  map22 = TableMap.get(table);
83980
84751
  mapFrom = tr.mapping.maps.length;
83981
84752
  }
83982
84753
  if (growTable(tr, map22, table, tableStart, right2, bottom2, mapFrom)) recomp();
83983
- if (isolateHorizontal(tr, map22, table, tableStart, left2, right2, top2, mapFrom))
83984
- recomp();
83985
- if (isolateHorizontal(tr, map22, table, tableStart, left2, right2, bottom2, mapFrom))
83986
- recomp();
83987
- if (isolateVertical(tr, map22, table, tableStart, top2, bottom2, left2, mapFrom))
83988
- recomp();
83989
- if (isolateVertical(tr, map22, table, tableStart, top2, bottom2, right2, mapFrom))
83990
- recomp();
84754
+ if (isolateHorizontal(tr, map22, table, tableStart, left2, right2, top2, mapFrom)) recomp();
84755
+ if (isolateHorizontal(tr, map22, table, tableStart, left2, right2, bottom2, mapFrom)) recomp();
84756
+ if (isolateVertical(tr, map22, table, tableStart, top2, bottom2, left2, mapFrom)) recomp();
84757
+ if (isolateVertical(tr, map22, table, tableStart, top2, bottom2, right2, mapFrom)) recomp();
83991
84758
  for (let row = top2; row < bottom2; row++) {
83992
84759
  const from2 = map22.positionAt(row, left2, table), to = map22.positionAt(row, right2, table);
83993
- tr.replace(
83994
- tr.mapping.slice(mapFrom).map(from2 + tableStart),
83995
- tr.mapping.slice(mapFrom).map(to + tableStart),
83996
- new Slice(cells.rows[row - top2], 0, 0)
83997
- );
84760
+ tr.replace(tr.mapping.slice(mapFrom).map(from2 + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top2], 0, 0));
83998
84761
  }
83999
84762
  recomp();
84000
- tr.setSelection(
84001
- new CellSelection(
84002
- tr.doc.resolve(tableStart + map22.positionAt(top2, left2, table)),
84003
- tr.doc.resolve(tableStart + map22.positionAt(bottom2 - 1, right2 - 1, table))
84004
- )
84005
- );
84763
+ tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map22.positionAt(top2, left2, table)), tr.doc.resolve(tableStart + map22.positionAt(bottom2 - 1, right2 - 1, table))));
84006
84764
  dispatch(tr);
84007
84765
  }
84008
- var handleKeyDown = keydownHandler({
84766
+ const handleKeyDown = keydownHandler({
84009
84767
  ArrowLeft: arrow$2("horiz", -1),
84010
84768
  ArrowRight: arrow$2("horiz", 1),
84011
84769
  ArrowUp: arrow$2("vert", -1),
@@ -84028,29 +84786,17 @@ function arrow$2(axis, dir) {
84028
84786
  return (state2, dispatch, view) => {
84029
84787
  if (!view) return false;
84030
84788
  const sel = state2.selection;
84031
- if (sel instanceof CellSelection) {
84032
- return maybeSetSelection(
84033
- state2,
84034
- dispatch,
84035
- Selection.near(sel.$headCell, dir)
84036
- );
84037
- }
84789
+ if (sel instanceof CellSelection) return maybeSetSelection(state2, dispatch, Selection.near(sel.$headCell, dir));
84038
84790
  if (axis != "horiz" && !sel.empty) return false;
84039
84791
  const end2 = atEndOfCell(view, axis, dir);
84040
84792
  if (end2 == null) return false;
84041
- if (axis == "horiz") {
84042
- return maybeSetSelection(
84043
- state2,
84044
- dispatch,
84045
- Selection.near(state2.doc.resolve(sel.head + dir), dir)
84046
- );
84047
- } else {
84793
+ if (axis == "horiz") return maybeSetSelection(state2, dispatch, Selection.near(state2.doc.resolve(sel.head + dir), dir));
84794
+ else {
84048
84795
  const $cell = state2.doc.resolve(end2);
84049
84796
  const $next = nextCell($cell, axis, dir);
84050
84797
  let newSel;
84051
84798
  if ($next) newSel = Selection.near($next, 1);
84052
- else if (dir < 0)
84053
- newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
84799
+ else if (dir < 0) newSel = Selection.near(state2.doc.resolve($cell.before(-1)), -1);
84054
84800
  else newSel = Selection.near(state2.doc.resolve($cell.after(-1)), 1);
84055
84801
  return maybeSetSelection(state2, dispatch, newSel);
84056
84802
  }
@@ -84061,20 +84807,15 @@ function shiftArrow(axis, dir) {
84061
84807
  if (!view) return false;
84062
84808
  const sel = state2.selection;
84063
84809
  let cellSel;
84064
- if (sel instanceof CellSelection) {
84065
- cellSel = sel;
84066
- } else {
84810
+ if (sel instanceof CellSelection) cellSel = sel;
84811
+ else {
84067
84812
  const end2 = atEndOfCell(view, axis, dir);
84068
84813
  if (end2 == null) return false;
84069
84814
  cellSel = new CellSelection(state2.doc.resolve(end2));
84070
84815
  }
84071
84816
  const $head = nextCell(cellSel.$headCell, axis, dir);
84072
84817
  if (!$head) return false;
84073
- return maybeSetSelection(
84074
- state2,
84075
- dispatch,
84076
- new CellSelection(cellSel.$anchorCell, $head)
84077
- );
84818
+ return maybeSetSelection(state2, dispatch, new CellSelection(cellSel.$anchorCell, $head));
84078
84819
  };
84079
84820
  }
84080
84821
  function handleTripleClick(view, pos) {
@@ -84088,65 +84829,45 @@ function handlePaste(view, _2, slice2) {
84088
84829
  let cells = pastedCells(slice2);
84089
84830
  const sel = view.state.selection;
84090
84831
  if (sel instanceof CellSelection) {
84091
- if (!cells)
84092
- cells = {
84093
- width: 1,
84094
- height: 1,
84095
- rows: [
84096
- Fragment.from(
84097
- fitSlice(tableNodeTypes(view.state.schema).cell, slice2)
84098
- )
84099
- ]
84100
- };
84832
+ if (!cells) cells = {
84833
+ width: 1,
84834
+ height: 1,
84835
+ rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))]
84836
+ };
84101
84837
  const table = sel.$anchorCell.node(-1);
84102
84838
  const start2 = sel.$anchorCell.start(-1);
84103
- const rect = TableMap.get(table).rectBetween(
84104
- sel.$anchorCell.pos - start2,
84105
- sel.$headCell.pos - start2
84106
- );
84839
+ const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start2, sel.$headCell.pos - start2);
84107
84840
  cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
84108
84841
  insertCells(view.state, view.dispatch, start2, rect, cells);
84109
84842
  return true;
84110
84843
  } else if (cells) {
84111
84844
  const $cell = selectionCell(view.state);
84112
84845
  const start2 = $cell.start(-1);
84113
- insertCells(
84114
- view.state,
84115
- view.dispatch,
84116
- start2,
84117
- TableMap.get($cell.node(-1)).findCell($cell.pos - start2),
84118
- cells
84119
- );
84846
+ insertCells(view.state, view.dispatch, start2, TableMap.get($cell.node(-1)).findCell($cell.pos - start2), cells);
84120
84847
  return true;
84121
- } else {
84122
- return false;
84123
- }
84848
+ } else return false;
84124
84849
  }
84125
84850
  function handleMouseDown(view, startEvent) {
84126
- var _a2;
84851
+ var _cellUnderMouse;
84127
84852
  if (startEvent.ctrlKey || startEvent.metaKey) return;
84128
84853
  const startDOMCell = domInCell(view, startEvent.target);
84129
84854
  let $anchor;
84130
84855
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
84131
84856
  setCellSelection(view.state.selection.$anchorCell, startEvent);
84132
84857
  startEvent.preventDefault();
84133
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_a2 = cellUnderMouse(view, startEvent)) == null ? void 0 : _a2.pos) != $anchor.pos) {
84858
+ } 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) {
84134
84859
  setCellSelection($anchor, startEvent);
84135
84860
  startEvent.preventDefault();
84136
- } else if (!startDOMCell) {
84137
- return;
84138
- }
84139
- function setCellSelection($anchor2, event) {
84861
+ } else if (!startDOMCell) return;
84862
+ function setCellSelection($anchor$1, event) {
84140
84863
  let $head = cellUnderMouse(view, event);
84141
84864
  const starting = tableEditingKey.getState(view.state) == null;
84142
- if (!$head || !inSameTable($anchor2, $head)) {
84143
- if (starting) $head = $anchor2;
84144
- else return;
84145
- }
84146
- const selection = new CellSelection($anchor2, $head);
84865
+ if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
84866
+ else return;
84867
+ const selection = new CellSelection($anchor$1, $head);
84147
84868
  if (starting || !view.state.selection.eq(selection)) {
84148
84869
  const tr = view.state.tr.setSelection(selection);
84149
- if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);
84870
+ if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
84150
84871
  view.dispatch(tr);
84151
84872
  }
84152
84873
  }
@@ -84154,20 +84875,18 @@ function handleMouseDown(view, startEvent) {
84154
84875
  view.root.removeEventListener("mouseup", stop);
84155
84876
  view.root.removeEventListener("dragstart", stop);
84156
84877
  view.root.removeEventListener("mousemove", move2);
84157
- if (tableEditingKey.getState(view.state) != null)
84158
- view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
84878
+ if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
84159
84879
  }
84160
84880
  function move2(_event) {
84161
84881
  const event = _event;
84162
84882
  const anchor = tableEditingKey.getState(view.state);
84163
- let $anchor2;
84164
- if (anchor != null) {
84165
- $anchor2 = view.state.doc.resolve(anchor);
84166
- } else if (domInCell(view, event.target) != startDOMCell) {
84167
- $anchor2 = cellUnderMouse(view, startEvent);
84168
- if (!$anchor2) return stop();
84883
+ let $anchor$1;
84884
+ if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
84885
+ else if (domInCell(view, event.target) != startDOMCell) {
84886
+ $anchor$1 = cellUnderMouse(view, startEvent);
84887
+ if (!$anchor$1) return stop();
84169
84888
  }
84170
- if ($anchor2) setCellSelection($anchor2, event);
84889
+ if ($anchor$1) setCellSelection($anchor$1, event);
84171
84890
  }
84172
84891
  view.root.addEventListener("mouseup", stop);
84173
84892
  view.root.addEventListener("dragstart", stop);
@@ -84177,8 +84896,8 @@ function atEndOfCell(view, axis, dir) {
84177
84896
  if (!(view.state.selection instanceof TextSelection$1)) return null;
84178
84897
  const { $head } = view.state.selection;
84179
84898
  for (let d2 = $head.depth - 1; d2 >= 0; d2--) {
84180
- const parent = $head.node(d2), index2 = dir < 0 ? $head.index(d2) : $head.indexAfter(d2);
84181
- if (index2 != (dir < 0 ? 0 : parent.childCount)) return null;
84899
+ const parent = $head.node(d2);
84900
+ if ((dir < 0 ? $head.index(d2) : $head.indexAfter(d2)) != (dir < 0 ? 0 : parent.childCount)) return null;
84182
84901
  if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
84183
84902
  const cellPos = $head.before(d2);
84184
84903
  const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
@@ -84188,11 +84907,7 @@ function atEndOfCell(view, axis, dir) {
84188
84907
  return null;
84189
84908
  }
84190
84909
  function domInCell(view, dom) {
84191
- for (; dom && dom != view.dom; dom = dom.parentNode) {
84192
- if (dom.nodeName == "TD" || dom.nodeName == "TH") {
84193
- return dom;
84194
- }
84195
- }
84910
+ for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
84196
84911
  return null;
84197
84912
  }
84198
84913
  function cellUnderMouse(view, event) {
@@ -84201,7 +84916,8 @@ function cellUnderMouse(view, event) {
84201
84916
  top: event.clientY
84202
84917
  });
84203
84918
  if (!mousePos) return null;
84204
- return mousePos ? cellAround$1(view.state.doc.resolve(mousePos.pos)) : null;
84919
+ const pos = mousePos.inside >= 0 ? mousePos.inside : mousePos.pos;
84920
+ return cellAround$1(view.state.doc.resolve(pos));
84205
84921
  }
84206
84922
  var TableView = class {
84207
84923
  constructor(node, defaultCellMinWidth) {
@@ -84210,10 +84926,7 @@ var TableView = class {
84210
84926
  this.dom = document.createElement("div");
84211
84927
  this.dom.className = "tableWrapper";
84212
84928
  this.table = this.dom.appendChild(document.createElement("table"));
84213
- this.table.style.setProperty(
84214
- "--default-cell-min-width",
84215
- `${defaultCellMinWidth}px`
84216
- );
84929
+ this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
84217
84930
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
84218
84931
  updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
84219
84932
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
@@ -84221,12 +84934,7 @@ var TableView = class {
84221
84934
  update(node) {
84222
84935
  if (node.type != this.node.type) return false;
84223
84936
  this.node = node;
84224
- updateColumnsOnResize(
84225
- node,
84226
- this.colgroup,
84227
- this.table,
84228
- this.defaultCellMinWidth
84229
- );
84937
+ updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
84230
84938
  return true;
84231
84939
  }
84232
84940
  ignoreMutation(record) {
@@ -84234,7 +84942,6 @@ var TableView = class {
84234
84942
  }
84235
84943
  };
84236
84944
  function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
84237
- var _a2;
84238
84945
  let totalWidth = 0;
84239
84946
  let fixedWidth = true;
84240
84947
  let nextDOM = colgroup.firstChild;
@@ -84248,20 +84955,19 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
84248
84955
  totalWidth += hasWidth || defaultCellMinWidth;
84249
84956
  if (!hasWidth) fixedWidth = false;
84250
84957
  if (!nextDOM) {
84251
- const col2 = document.createElement("col");
84252
- col2.style.width = cssWidth;
84253
- colgroup.appendChild(col2);
84958
+ const col$1 = document.createElement("col");
84959
+ col$1.style.width = cssWidth;
84960
+ colgroup.appendChild(col$1);
84254
84961
  } else {
84255
- if (nextDOM.style.width != cssWidth) {
84256
- nextDOM.style.width = cssWidth;
84257
- }
84962
+ if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
84258
84963
  nextDOM = nextDOM.nextSibling;
84259
84964
  }
84260
84965
  }
84261
84966
  }
84262
84967
  while (nextDOM) {
84968
+ var _nextDOM$parentNode;
84263
84969
  const after = nextDOM.nextSibling;
84264
- (_a2 = nextDOM.parentNode) == null ? void 0 : _a2.removeChild(nextDOM);
84970
+ (_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
84265
84971
  nextDOM = after;
84266
84972
  }
84267
84973
  if (fixedWidth) {
@@ -84272,28 +84978,18 @@ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overr
84272
84978
  table.style.minWidth = totalWidth + "px";
84273
84979
  }
84274
84980
  }
84275
- var columnResizingPluginKey = new PluginKey(
84276
- "tableColumnResizing"
84277
- );
84278
- function columnResizing({
84279
- handleWidth = 5,
84280
- cellMinWidth: cellMinWidth2 = 25,
84281
- defaultCellMinWidth = 100,
84282
- View = TableView,
84283
- lastColumnResizable = true
84284
- } = {}) {
84981
+ const columnResizingPluginKey = new PluginKey("tableColumnResizing");
84982
+ function columnResizing({ handleWidth = 5, cellMinWidth: cellMinWidth2 = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
84285
84983
  const plugin2 = new Plugin({
84286
84984
  key: columnResizingPluginKey,
84287
84985
  state: {
84288
84986
  init(_2, state2) {
84289
- var _a2, _b;
84290
- const nodeViews = (_b = (_a2 = plugin2.spec) == null ? void 0 : _a2.props) == null ? void 0 : _b.nodeViews;
84987
+ var _plugin$spec;
84988
+ const nodeViews = (_plugin$spec = plugin2.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
84291
84989
  const tableName = tableNodeTypes(state2.schema).table.name;
84292
- if (View && nodeViews) {
84293
- nodeViews[tableName] = (node, view) => {
84294
- return new View(node, defaultCellMinWidth, view);
84295
- };
84296
- }
84990
+ if (View && nodeViews) nodeViews[tableName] = (node, view) => {
84991
+ return new View(node, defaultCellMinWidth, view);
84992
+ };
84297
84993
  return new ResizeState(-1, false);
84298
84994
  },
84299
84995
  apply(tr, prev) {
@@ -84313,21 +85009,19 @@ function columnResizing({
84313
85009
  handleMouseLeave(view);
84314
85010
  },
84315
85011
  mousedown: (view, event) => {
84316
- handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth);
85012
+ handleMouseDown$1(view, event, cellMinWidth2, defaultCellMinWidth);
84317
85013
  }
84318
85014
  },
84319
85015
  decorations: (state2) => {
84320
85016
  const pluginState = columnResizingPluginKey.getState(state2);
84321
- if (pluginState && pluginState.activeHandle > -1) {
84322
- return handleDecorations(state2, pluginState.activeHandle);
84323
- }
85017
+ if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state2, pluginState.activeHandle);
84324
85018
  },
84325
85019
  nodeViews: {}
84326
85020
  }
84327
85021
  });
84328
85022
  return plugin2;
84329
85023
  }
84330
- var ResizeState = class _ResizeState {
85024
+ var ResizeState = class ResizeState2 {
84331
85025
  constructor(activeHandle, dragging) {
84332
85026
  this.activeHandle = activeHandle;
84333
85027
  this.dragging = dragging;
@@ -84335,16 +85029,12 @@ var ResizeState = class _ResizeState {
84335
85029
  apply(tr) {
84336
85030
  const state2 = this;
84337
85031
  const action = tr.getMeta(columnResizingPluginKey);
84338
- if (action && action.setHandle != null)
84339
- return new _ResizeState(action.setHandle, false);
84340
- if (action && action.setDragging !== void 0)
84341
- return new _ResizeState(state2.activeHandle, action.setDragging);
85032
+ if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false);
85033
+ if (action && action.setDragging !== void 0) return new ResizeState2(state2.activeHandle, action.setDragging);
84342
85034
  if (state2.activeHandle > -1 && tr.docChanged) {
84343
85035
  let handle = tr.mapping.map(state2.activeHandle, -1);
84344
- if (!pointsAtCell(tr.doc.resolve(handle))) {
84345
- handle = -1;
84346
- }
84347
- return new _ResizeState(handle, state2.dragging);
85036
+ if (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;
85037
+ return new ResizeState2(handle, state2.dragging);
84348
85038
  }
84349
85039
  return state2;
84350
85040
  }
@@ -84358,10 +85048,8 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
84358
85048
  let cell = -1;
84359
85049
  if (target) {
84360
85050
  const { left: left2, right: right2 } = target.getBoundingClientRect();
84361
- if (event.clientX - left2 <= handleWidth)
84362
- cell = edgeCell(view, event, "left", handleWidth);
84363
- else if (right2 - event.clientX <= handleWidth)
84364
- cell = edgeCell(view, event, "right", handleWidth);
85051
+ if (event.clientX - left2 <= handleWidth) cell = edgeCell(view, event, "left", handleWidth);
85052
+ else if (right2 - event.clientX <= handleWidth) cell = edgeCell(view, event, "right", handleWidth);
84365
85053
  }
84366
85054
  if (cell != pluginState.activeHandle) {
84367
85055
  if (!lastColumnResizable && cell !== -1) {
@@ -84369,10 +85057,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
84369
85057
  const table = $cell.node(-1);
84370
85058
  const map22 = TableMap.get(table);
84371
85059
  const tableStart = $cell.start(-1);
84372
- const col = map22.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
84373
- if (col == map22.width - 1) {
84374
- return;
84375
- }
85060
+ if (map22.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map22.width - 1) return;
84376
85061
  }
84377
85062
  updateHandle(view, cell);
84378
85063
  }
@@ -84381,58 +85066,39 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
84381
85066
  function handleMouseLeave(view) {
84382
85067
  if (!view.editable) return;
84383
85068
  const pluginState = columnResizingPluginKey.getState(view.state);
84384
- if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
84385
- updateHandle(view, -1);
85069
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
84386
85070
  }
84387
- function handleMouseDown2(view, event, cellMinWidth2, defaultCellMinWidth) {
84388
- var _a2;
85071
+ function handleMouseDown$1(view, event, cellMinWidth2, defaultCellMinWidth) {
85072
+ var _view$dom$ownerDocume;
84389
85073
  if (!view.editable) return false;
84390
- const win = (_a2 = view.dom.ownerDocument.defaultView) != null ? _a2 : window;
85074
+ const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
84391
85075
  const pluginState = columnResizingPluginKey.getState(view.state);
84392
- if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
84393
- return false;
85076
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
84394
85077
  const cell = view.state.doc.nodeAt(pluginState.activeHandle);
84395
85078
  const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
84396
- view.dispatch(
84397
- view.state.tr.setMeta(columnResizingPluginKey, {
84398
- setDragging: { startX: event.clientX, startWidth: width }
84399
- })
84400
- );
84401
- function finish(event2) {
85079
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
85080
+ startX: event.clientX,
85081
+ startWidth: width
85082
+ } }));
85083
+ function finish(event$1) {
84402
85084
  win.removeEventListener("mouseup", finish);
84403
85085
  win.removeEventListener("mousemove", move2);
84404
- const pluginState2 = columnResizingPluginKey.getState(view.state);
84405
- if (pluginState2 == null ? void 0 : pluginState2.dragging) {
84406
- updateColumnWidth(
84407
- view,
84408
- pluginState2.activeHandle,
84409
- draggedWidth(pluginState2.dragging, event2, cellMinWidth2)
84410
- );
84411
- view.dispatch(
84412
- view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
84413
- );
85086
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
85087
+ if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
85088
+ updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth2));
85089
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
84414
85090
  }
84415
85091
  }
84416
- function move2(event2) {
84417
- if (!event2.which) return finish(event2);
84418
- const pluginState2 = columnResizingPluginKey.getState(view.state);
84419
- if (!pluginState2) return;
84420
- if (pluginState2.dragging) {
84421
- const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth2);
84422
- displayColumnWidth(
84423
- view,
84424
- pluginState2.activeHandle,
84425
- dragged,
84426
- defaultCellMinWidth
84427
- );
85092
+ function move2(event$1) {
85093
+ if (!event$1.which) return finish(event$1);
85094
+ const pluginState$1 = columnResizingPluginKey.getState(view.state);
85095
+ if (!pluginState$1) return;
85096
+ if (pluginState$1.dragging) {
85097
+ const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth2);
85098
+ displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
84428
85099
  }
84429
85100
  }
84430
- displayColumnWidth(
84431
- view,
84432
- pluginState.activeHandle,
84433
- width,
84434
- defaultCellMinWidth
84435
- );
85101
+ displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
84436
85102
  win.addEventListener("mouseup", finish);
84437
85103
  win.addEventListener("mousemove", move2);
84438
85104
  event.preventDefault();
@@ -84442,20 +85108,17 @@ function currentColWidth(view, cellPos, { colspan, colwidth }) {
84442
85108
  const width = colwidth && colwidth[colwidth.length - 1];
84443
85109
  if (width) return width;
84444
85110
  const dom = view.domAtPos(cellPos);
84445
- const node = dom.node.childNodes[dom.offset];
84446
- let domWidth = node.offsetWidth, parts = colspan;
85111
+ let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
84447
85112
  if (colwidth) {
84448
- for (let i = 0; i < colspan; i++)
84449
- if (colwidth[i]) {
84450
- domWidth -= colwidth[i];
84451
- parts--;
84452
- }
85113
+ for (let i = 0; i < colspan; i++) if (colwidth[i]) {
85114
+ domWidth -= colwidth[i];
85115
+ parts--;
85116
+ }
84453
85117
  }
84454
85118
  return domWidth / parts;
84455
85119
  }
84456
85120
  function domCellAround(target) {
84457
- while (target && target.nodeName != "TD" && target.nodeName != "TH")
84458
- target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
85121
+ while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
84459
85122
  return target;
84460
85123
  }
84461
85124
  function edgeCell(view, event, side, handleWidth) {
@@ -84478,9 +85141,7 @@ function draggedWidth(dragging, event, resizeMinWidth) {
84478
85141
  return Math.max(resizeMinWidth, dragging.startWidth + offset2);
84479
85142
  }
84480
85143
  function updateHandle(view, value) {
84481
- view.dispatch(
84482
- view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
84483
- );
85144
+ view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
84484
85145
  }
84485
85146
  function updateColumnWidth(view, cell, width) {
84486
85147
  const $cell = view.state.doc.resolve(cell);
@@ -84496,7 +85157,10 @@ function updateColumnWidth(view, cell, width) {
84496
85157
  if (attrs.colwidth && attrs.colwidth[index2] == width) continue;
84497
85158
  const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
84498
85159
  colwidth[index2] = width;
84499
- tr.setNodeMarkup(start2 + pos, null, { ...attrs, colwidth });
85160
+ tr.setNodeMarkup(start2 + pos, null, {
85161
+ ...attrs,
85162
+ colwidth
85163
+ });
84500
85164
  }
84501
85165
  if (tr.docChanged) view.dispatch(tr);
84502
85166
  }
@@ -84505,64 +85169,38 @@ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
84505
85169
  const table = $cell.node(-1), start2 = $cell.start(-1);
84506
85170
  const col = TableMap.get(table).colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
84507
85171
  let dom = view.domAtPos($cell.start(-1)).node;
84508
- while (dom && dom.nodeName != "TABLE") {
84509
- dom = dom.parentNode;
84510
- }
85172
+ while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
84511
85173
  if (!dom) return;
84512
- updateColumnsOnResize(
84513
- table,
84514
- dom.firstChild,
84515
- dom,
84516
- defaultCellMinWidth,
84517
- col,
84518
- width
84519
- );
85174
+ updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
84520
85175
  }
84521
85176
  function zeroes(n) {
84522
85177
  return Array(n).fill(0);
84523
85178
  }
84524
85179
  function handleDecorations(state2, cell) {
84525
- var _a2;
84526
85180
  const decorations = [];
84527
85181
  const $cell = state2.doc.resolve(cell);
84528
85182
  const table = $cell.node(-1);
84529
- if (!table) {
84530
- return DecorationSet.empty;
84531
- }
85183
+ if (!table) return DecorationSet.empty;
84532
85184
  const map22 = TableMap.get(table);
84533
85185
  const start2 = $cell.start(-1);
84534
85186
  const col = map22.colCount($cell.pos - start2) + $cell.nodeAfter.attrs.colspan - 1;
84535
85187
  for (let row = 0; row < map22.height; row++) {
84536
85188
  const index2 = col + row * map22.width;
84537
85189
  if ((col == map22.width - 1 || map22.map[index2] != map22.map[index2 + 1]) && (row == 0 || map22.map[index2] != map22.map[index2 - map22.width])) {
85190
+ var _columnResizingPlugin;
84538
85191
  const cellPos = map22.map[index2];
84539
85192
  const pos = start2 + cellPos + table.nodeAt(cellPos).nodeSize - 1;
84540
85193
  const dom = document.createElement("div");
84541
85194
  dom.className = "column-resize-handle";
84542
- if ((_a2 = columnResizingPluginKey.getState(state2)) == null ? void 0 : _a2.dragging) {
84543
- decorations.push(
84544
- Decoration.node(
84545
- start2 + cellPos,
84546
- start2 + cellPos + table.nodeAt(cellPos).nodeSize,
84547
- {
84548
- class: "column-resize-dragging"
84549
- }
84550
- )
84551
- );
84552
- }
85195
+ if ((_columnResizingPlugin = columnResizingPluginKey.getState(state2)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start2 + cellPos, start2 + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
84553
85196
  decorations.push(Decoration.widget(pos, dom));
84554
85197
  }
84555
85198
  }
84556
85199
  return DecorationSet.create(state2.doc, decorations);
84557
85200
  }
84558
- function tableEditing({
84559
- allowTableNodeSelection = false
84560
- } = {}) {
85201
+ function tableEditing({ allowTableNodeSelection = false } = {}) {
84561
85202
  return new Plugin({
84562
85203
  key: tableEditingKey,
84563
- // This piece of state is used to remember when a mouse-drag
84564
- // cell-selection is happening, so that it can continue even as
84565
- // transactions (which might move its anchor cell) come in.
84566
85204
  state: {
84567
85205
  init() {
84568
85206
  return null;
@@ -84577,9 +85215,7 @@ function tableEditing({
84577
85215
  },
84578
85216
  props: {
84579
85217
  decorations: drawCellSelection,
84580
- handleDOMEvents: {
84581
- mousedown: handleMouseDown
84582
- },
85218
+ handleDOMEvents: { mousedown: handleMouseDown },
84583
85219
  createSelectionBetween(view) {
84584
85220
  return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
84585
85221
  },
@@ -84588,11 +85224,7 @@ function tableEditing({
84588
85224
  handlePaste
84589
85225
  },
84590
85226
  appendTransaction(_2, oldState, state2) {
84591
- return normalizeSelection(
84592
- state2,
84593
- fixTables(state2, oldState),
84594
- allowTableNodeSelection
84595
- );
85227
+ return normalizeSelection(state2, fixTables(state2, oldState), allowTableNodeSelection);
84596
85228
  }
84597
85229
  });
84598
85230
  }
@@ -95667,7 +96299,7 @@ const _hoisted_2$c = { key: 0 };
95667
96299
  const _hoisted_3$a = { key: 0 };
95668
96300
  const _hoisted_4$6 = { key: 1 };
95669
96301
  const _hoisted_5$5 = { key: 1 };
95670
- const _sfc_main$j = {
96302
+ const _sfc_main$k = {
95671
96303
  __name: "Mentions",
95672
96304
  props: {
95673
96305
  users: {
@@ -95750,7 +96382,7 @@ const _sfc_main$j = {
95750
96382
  };
95751
96383
  }
95752
96384
  };
95753
- const Mentions = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-bcae18cf"]]);
96385
+ const Mentions = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["__scopeId", "data-v-bcae18cf"]]);
95754
96386
  const popoverPluginKey = new PluginKey("popoverPlugin");
95755
96387
  const PopoverPlugin = Extension.create({
95756
96388
  name: "popoverPlugin",
@@ -106902,7 +107534,7 @@ const _sfc_main$1$1 = {
106902
107534
  }
106903
107535
  };
106904
107536
  const ButtonGroup = /* @__PURE__ */ _export_sfc(_sfc_main$1$1, [["__scopeId", "data-v-c80a1e51"]]);
106905
- const _sfc_main$i = {
107537
+ const _sfc_main$j = {
106906
107538
  __name: "Toolbar",
106907
107539
  emits: ["command", "toggle", "select"],
106908
107540
  setup(__props, { emit: __emit }) {
@@ -106984,7 +107616,7 @@ const _sfc_main$i = {
106984
107616
  };
106985
107617
  }
106986
107618
  };
106987
- const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["__scopeId", "data-v-3f5ec271"]]);
107619
+ const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-3f5ec271"]]);
106988
107620
  const DEFAULT_API_ENDPOINT = "https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights";
106989
107621
  const SYSTEM_PROMPT = "You are an expert copywriter and you are immersed in a document editor. You are to provide document related text responses based on the user prompts. Only write what is asked for. Do not provide explanations. Try to keep placeholders as short as possible. Do not output your prompt. Your instructions are: ";
106990
107622
  async function baseInsightsFetch(payload, options = {}) {
@@ -107225,7 +107857,7 @@ const _hoisted_2$a = ["innerHTML"];
107225
107857
  const _hoisted_3$8 = ["placeholder"];
107226
107858
  const _hoisted_4$4 = { class: "ai-loader" };
107227
107859
  const _hoisted_5$3 = ["innerHTML"];
107228
- const _sfc_main$h = {
107860
+ const _sfc_main$i = {
107229
107861
  __name: "AIWriter",
107230
107862
  props: {
107231
107863
  selectedText: {
@@ -107501,7 +108133,7 @@ const _sfc_main$h = {
107501
108133
  };
107502
108134
  }
107503
108135
  };
107504
- const AIWriter = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-d869be75"]]);
108136
+ const AIWriter = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["__scopeId", "data-v-d869be75"]]);
107505
108137
  async function createZip(blobs, fileNames) {
107506
108138
  const zip = new JSZip();
107507
108139
  blobs.forEach((blob, index2) => {
@@ -107815,7 +108447,7 @@ const useToolbarItem = (options) => {
107815
108447
  };
107816
108448
  };
107817
108449
  const _hoisted_1$f = ["onClick", "innerHTML", "aria-label", "onKeydown"];
107818
- const _sfc_main$g = {
108450
+ const _sfc_main$h = {
107819
108451
  __name: "AlignmentButtons",
107820
108452
  emits: ["select"],
107821
108453
  setup(__props, { emit: __emit }) {
@@ -107906,14 +108538,14 @@ const _sfc_main$g = {
107906
108538
  };
107907
108539
  }
107908
108540
  };
107909
- const AlignmentButtons = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-d84f57b6"]]);
108541
+ const AlignmentButtons = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-d84f57b6"]]);
107910
108542
  const _hoisted_1$e = ["onClick", "onKeydown"];
107911
108543
  const _hoisted_2$9 = { class: "document-mode-column icon-column" };
107912
108544
  const _hoisted_3$7 = ["innerHTML"];
107913
108545
  const _hoisted_4$3 = { class: "document-mode-column text-column" };
107914
108546
  const _hoisted_5$2 = { class: "document-mode-type" };
107915
108547
  const _hoisted_6$1 = { class: "document-mode-description" };
107916
- const _sfc_main$f = {
108548
+ const _sfc_main$g = {
107917
108549
  __name: "DocumentMode",
107918
108550
  props: {
107919
108551
  options: {
@@ -107993,14 +108625,14 @@ const _sfc_main$f = {
107993
108625
  };
107994
108626
  }
107995
108627
  };
107996
- const DocumentMode = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-8730b752"]]);
108628
+ const DocumentMode = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-8730b752"]]);
107997
108629
  const _hoisted_1$d = {
107998
108630
  key: 0,
107999
108631
  class: "linked-style-buttons",
108000
108632
  "data-editor-ui-surface": ""
108001
108633
  };
108002
108634
  const _hoisted_2$8 = ["onClick", "onKeydown", "aria-label"];
108003
- const _sfc_main$e = {
108635
+ const _sfc_main$f = {
108004
108636
  __name: "LinkedStyle",
108005
108637
  props: {
108006
108638
  editor: {
@@ -108076,7 +108708,7 @@ const _sfc_main$e = {
108076
108708
  };
108077
108709
  }
108078
108710
  };
108079
- const LinkedStyle = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-ecb78965"]]);
108711
+ const LinkedStyle = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["__scopeId", "data-v-ecb78965"]]);
108080
108712
  const _hoisted_1$c = {
108081
108713
  key: 0,
108082
108714
  class: "link-title"
@@ -108105,7 +108737,7 @@ const _hoisted_13 = {
108105
108737
  key: 4,
108106
108738
  class: "input-row go-to-anchor clickable"
108107
108739
  };
108108
- const _sfc_main$d = {
108740
+ const _sfc_main$e = {
108109
108741
  __name: "LinkInput",
108110
108742
  props: {
108111
108743
  showInput: {
@@ -108311,12 +108943,12 @@ const _sfc_main$d = {
108311
108943
  };
108312
108944
  }
108313
108945
  };
108314
- const LinkInput = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["__scopeId", "data-v-ba50627b"]]);
108946
+ const LinkInput = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-ba50627b"]]);
108315
108947
  const _hoisted_1$b = ["aria-label", "onClick", "onKeydown"];
108316
108948
  const _hoisted_2$6 = ["innerHTML"];
108317
108949
  const _hoisted_3$5 = ["innerHTML"];
108318
108950
  const ROW_SIZE$1 = 7;
108319
- const _sfc_main$c = {
108951
+ const _sfc_main$d = {
108320
108952
  __name: "IconGridRow",
108321
108953
  props: {
108322
108954
  icons: {
@@ -108449,12 +109081,12 @@ const _sfc_main$c = {
108449
109081
  };
108450
109082
  }
108451
109083
  };
108452
- const IconGridRow = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-0f479b6c"]]);
109084
+ const IconGridRow = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["__scopeId", "data-v-0f479b6c"]]);
108453
109085
  const DropIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 512c53.2 0 101.4-21.6 136.1-56.6l-298.3-235C140 257.1 128 292.3 128 320c0 106 86 192 192 192zM505.2 370.7c4.4-16.2 6.8-33.1 6.8-50.7c0-91.2-130.2-262.3-166.6-308.3C339.4 4.2 330.5 0 320.9 0l-1.8 0c-9.6 0-18.5 4.2-24.5 11.7C277.8 33 240.7 81.3 205.8 136L38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2S-1.2 34.7 9.2 42.9l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7L505.2 370.7zM224 336c0 44.2 35.8 80 80 80c8.8 0 16 7.2 16 16s-7.2 16-16 16c-61.9 0-112-50.1-112-112c0-8.8 7.2-16 16-16s16 7.2 16 16z"/></svg>\n';
108454
109086
  const _hoisted_1$a = { class: "options-grid-wrap" };
108455
109087
  const _hoisted_2$5 = ["innerHTML"];
108456
109088
  const _hoisted_3$4 = { class: "option-grid-ctn" };
108457
- const _sfc_main$b = {
109089
+ const _sfc_main$c = {
108458
109090
  __name: "IconGrid",
108459
109091
  props: {
108460
109092
  icons: {
@@ -108514,7 +109146,7 @@ const _sfc_main$b = {
108514
109146
  };
108515
109147
  }
108516
109148
  };
108517
- const IconGrid = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-3d19fedf"]]);
109149
+ const IconGrid = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-3d19fedf"]]);
108518
109150
  const closeDropdown$1 = (dropdown) => {
108519
109151
  dropdown.expand.value = false;
108520
109152
  };
@@ -108626,7 +109258,7 @@ const getAvailableColorOptions = () => {
108626
109258
  const _hoisted_1$9 = ["data-cols", "data-rows", "onKeydown", "onClick"];
108627
109259
  const _hoisted_2$4 = ["aria-valuetext"];
108628
109260
  const ROW_SIZE = 5;
108629
- const _sfc_main$a = {
109261
+ const _sfc_main$b = {
108630
109262
  __name: "TableGrid",
108631
109263
  emits: ["select", "clickoutside"],
108632
109264
  setup(__props, { emit: __emit }) {
@@ -108755,13 +109387,13 @@ const _sfc_main$a = {
108755
109387
  };
108756
109388
  }
108757
109389
  };
108758
- const TableGrid = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["__scopeId", "data-v-92e8d5fb"]]);
109390
+ const TableGrid = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-92e8d5fb"]]);
108759
109391
  const _hoisted_1$8 = { class: "toolbar-table-actions" };
108760
109392
  const _hoisted_2$3 = ["onClick", "data-item", "ariaLabel"];
108761
109393
  const _hoisted_3$3 = { class: "toolbar-table-actions__icon" };
108762
109394
  const _hoisted_4$1 = ["innerHTML"];
108763
109395
  const _hoisted_5 = { class: "toolbar-table-actions__label" };
108764
- const _sfc_main$9 = {
109396
+ const _sfc_main$a = {
108765
109397
  __name: "TableActions",
108766
109398
  props: {
108767
109399
  options: {
@@ -108797,7 +109429,7 @@ const _sfc_main$9 = {
108797
109429
  };
108798
109430
  }
108799
109431
  };
108800
- const TableActions = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-990b9a25"]]);
109432
+ const TableActions = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["__scopeId", "data-v-990b9a25"]]);
108801
109433
  function getScrollableParent(element) {
108802
109434
  let currentElement = element;
108803
109435
  while (currentElement) {
@@ -108824,7 +109456,7 @@ const checkIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 5
108824
109456
  const _hoisted_1$7 = { class: "search-input-ctn" };
108825
109457
  const _hoisted_2$2 = { class: "row" };
108826
109458
  const _hoisted_3$2 = ["onKeydown"];
108827
- const _sfc_main$8 = {
109459
+ const _sfc_main$9 = {
108828
109460
  __name: "SearchInput",
108829
109461
  props: {
108830
109462
  searchRef: {
@@ -108863,7 +109495,7 @@ const _sfc_main$8 = {
108863
109495
  };
108864
109496
  }
108865
109497
  };
108866
- const SearchInput = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-957cbcf2"]]);
109498
+ const SearchInput = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["__scopeId", "data-v-957cbcf2"]]);
108867
109499
  const TOOLBAR_FONTS = [
108868
109500
  {
108869
109501
  label: "Georgia",
@@ -111638,7 +112270,7 @@ const _hoisted_2$1 = {
111638
112270
  };
111639
112271
  const _hoisted_3$1 = ["onClick"];
111640
112272
  const _hoisted_4 = ["innerHTML"];
111641
- const _sfc_main$7 = {
112273
+ const _sfc_main$8 = {
111642
112274
  __name: "SlashMenu",
111643
112275
  props: {
111644
112276
  editor: {
@@ -111990,7 +112622,7 @@ const _sfc_main$7 = {
111990
112622
  }
111991
112623
  };
111992
112624
  const _hoisted_1$5 = ["accept"];
111993
- const _sfc_main$6 = /* @__PURE__ */ defineComponent({
112625
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
111994
112626
  __name: "BasicUpload",
111995
112627
  props: {
111996
112628
  accept: { default: ".docx, .pdf, .html, .md" }
@@ -112019,7 +112651,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
112019
112651
  const _hoisted_1$4 = { class: "numbering" };
112020
112652
  const MIN_WIDTH = 200;
112021
112653
  const alignment = "flex-end";
112022
- const _sfc_main$5 = {
112654
+ const _sfc_main$6 = {
112023
112655
  __name: "Ruler",
112024
112656
  props: {
112025
112657
  orientation: {
@@ -112110,7 +112742,7 @@ const _sfc_main$5 = {
112110
112742
  minHeight: `${editorBounds.height}px`
112111
112743
  };
112112
112744
  });
112113
- const handleMouseDown3 = (event) => {
112745
+ const handleMouseDown2 = (event) => {
112114
112746
  isDragging.value = true;
112115
112747
  setRulerHandleActive();
112116
112748
  const itemId = event.currentTarget.id;
@@ -112185,13 +112817,13 @@ const _sfc_main$5 = {
112185
112817
  createBaseVNode("div", {
112186
112818
  class: "margin-handle handle-left",
112187
112819
  id: "left-margin-handle",
112188
- onMousedown: handleMouseDown3,
112820
+ onMousedown: handleMouseDown2,
112189
112821
  style: normalizeStyle(getHandlePosition.value("left"))
112190
112822
  }, null, 36),
112191
112823
  createBaseVNode("div", {
112192
112824
  class: "margin-handle handle-right",
112193
112825
  id: "right-margin-handle",
112194
- onMousedown: handleMouseDown3,
112826
+ onMousedown: handleMouseDown2,
112195
112827
  style: normalizeStyle(getHandlePosition.value("right"))
112196
112828
  }, null, 36),
112197
112829
  showVerticalIndicator.value ? (openBlock(), createElementBlock("div", {
@@ -112224,8 +112856,8 @@ const _sfc_main$5 = {
112224
112856
  };
112225
112857
  }
112226
112858
  };
112227
- const Ruler = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-79f9a944"]]);
112228
- const _sfc_main$4 = {
112859
+ const Ruler = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["__scopeId", "data-v-79f9a944"]]);
112860
+ const _sfc_main$5 = {
112229
112861
  __name: "GenericPopover",
112230
112862
  props: {
112231
112863
  editor: { type: Object, required: true },
@@ -112253,22 +112885,22 @@ const _sfc_main$4 = {
112253
112885
  () => props.visible,
112254
112886
  (val) => {
112255
112887
  if (val) {
112256
- document.addEventListener("mousedown", handleClickOutside2);
112888
+ document.addEventListener("pointerdown", handleClickOutside2);
112257
112889
  document.addEventListener("keydown", handleEscape);
112258
112890
  } else {
112259
- document.removeEventListener("mousedown", handleClickOutside2);
112891
+ document.removeEventListener("pointerdown", handleClickOutside2);
112260
112892
  document.removeEventListener("keydown", handleEscape);
112261
112893
  }
112262
112894
  }
112263
112895
  );
112264
112896
  onMounted(() => {
112265
112897
  if (props.visible) {
112266
- document.addEventListener("mousedown", handleClickOutside2);
112898
+ document.addEventListener("pointerdown", handleClickOutside2);
112267
112899
  document.addEventListener("keydown", handleEscape);
112268
112900
  }
112269
112901
  });
112270
112902
  onBeforeUnmount(() => {
112271
- document.removeEventListener("mousedown", handleClickOutside2);
112903
+ document.removeEventListener("pointerdown", handleClickOutside2);
112272
112904
  document.removeEventListener("keydown", handleEscape);
112273
112905
  });
112274
112906
  const derivedStyles = computed(() => ({
@@ -112283,7 +112915,7 @@ const _sfc_main$4 = {
112283
112915
  style: normalizeStyle(derivedStyles.value),
112284
112916
  ref_key: "popover",
112285
112917
  ref: popover,
112286
- onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {
112918
+ onPointerdown: _cache[0] || (_cache[0] = withModifiers(() => {
112287
112919
  }, ["stop"])),
112288
112920
  onClick: _cache[1] || (_cache[1] = withModifiers(() => {
112289
112921
  }, ["stop"]))
@@ -112293,7 +112925,7 @@ const _sfc_main$4 = {
112293
112925
  };
112294
112926
  }
112295
112927
  };
112296
- const GenericPopover = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-cbddcc0f"]]);
112928
+ const GenericPopover = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-157855b5"]]);
112297
112929
  const _hoisted_1$3 = ["data-boundary-index", "data-boundary-type", "onMousedown"];
112298
112930
  const RESIZE_HANDLE_WIDTH_PX = 9;
112299
112931
  const RESIZE_HANDLE_OFFSET_PX = 4;
@@ -112301,7 +112933,7 @@ const DRAG_OVERLAY_EXTENSION_PX = 1e3;
112301
112933
  const MIN_DRAG_OVERLAY_WIDTH_PX = 2e3;
112302
112934
  const THROTTLE_INTERVAL_MS = 16;
112303
112935
  const MIN_RESIZE_DELTA_PX = 1;
112304
- const _sfc_main$3 = {
112936
+ const _sfc_main$4 = {
112305
112937
  __name: "TableResizeOverlay",
112306
112938
  props: {
112307
112939
  /** Editor instance for dispatching transactions */
@@ -112825,7 +113457,7 @@ const _sfc_main$3 = {
112825
113457
  };
112826
113458
  }
112827
113459
  };
112828
- const TableResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-2fdf7836"]]);
113460
+ const TableResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-2fdf7836"]]);
112829
113461
  const _hoisted_1$2 = ["data-handle-position", "onMousedown"];
112830
113462
  const OVERLAY_EXPANSION_PX = 2e3;
112831
113463
  const RESIZE_HANDLE_SIZE_PX = 12;
@@ -112834,7 +113466,7 @@ const DIMENSION_CHANGE_THRESHOLD_PX = 1;
112834
113466
  const Z_INDEX_OVERLAY = 10;
112835
113467
  const Z_INDEX_HANDLE = 15;
112836
113468
  const Z_INDEX_GUIDELINE = 20;
112837
- const _sfc_main$2 = {
113469
+ const _sfc_main$3 = {
112838
113470
  __name: "ImageResizeOverlay",
112839
113471
  props: {
112840
113472
  /** Editor instance for dispatching transactions */
@@ -113258,7 +113890,81 @@ const _sfc_main$2 = {
113258
113890
  };
113259
113891
  }
113260
113892
  };
113261
- const ImageResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-e66ec7bb"]]);
113893
+ const ImageResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-e66ec7bb"]]);
113894
+ const _sfc_main$2 = {
113895
+ __name: "LinkClickHandler",
113896
+ props: {
113897
+ editor: {
113898
+ type: Object,
113899
+ required: true
113900
+ },
113901
+ openPopover: {
113902
+ type: Function,
113903
+ required: true
113904
+ },
113905
+ closePopover: {
113906
+ type: Function,
113907
+ required: true
113908
+ },
113909
+ popoverVisible: {
113910
+ type: Boolean,
113911
+ default: false
113912
+ }
113913
+ },
113914
+ setup(__props) {
113915
+ const props = __props;
113916
+ const handleLinkClick = (event) => {
113917
+ if (props.popoverVisible) {
113918
+ props.closePopover();
113919
+ return;
113920
+ }
113921
+ if (!props.editor || !props.editor.state) {
113922
+ return;
113923
+ }
113924
+ const surface = getEditorSurfaceElement(props.editor);
113925
+ if (!surface) {
113926
+ return;
113927
+ }
113928
+ moveCursorToMouseEvent(event.detail, props.editor);
113929
+ setTimeout(() => {
113930
+ const currentState = props.editor.state;
113931
+ const hasLink = selectionHasNodeOrMark(currentState, "link", { requireEnds: true });
113932
+ if (hasLink) {
113933
+ const surfaceRect = surface.getBoundingClientRect();
113934
+ if (!surfaceRect) return;
113935
+ props.openPopover(
113936
+ markRaw(LinkInput),
113937
+ {
113938
+ showInput: true,
113939
+ editor: props.editor,
113940
+ closePopover: props.closePopover
113941
+ },
113942
+ {
113943
+ left: `${event.detail.clientX - surfaceRect.left}px`,
113944
+ top: `${event.detail.clientY - surfaceRect.top + 15}px`
113945
+ }
113946
+ );
113947
+ }
113948
+ }, 10);
113949
+ };
113950
+ let surfaceElement = null;
113951
+ onMounted(() => {
113952
+ if (!props.editor) return;
113953
+ surfaceElement = getEditorSurfaceElement(props.editor);
113954
+ if (surfaceElement) {
113955
+ surfaceElement.addEventListener("superdoc-link-click", handleLinkClick);
113956
+ }
113957
+ });
113958
+ onBeforeUnmount(() => {
113959
+ if (surfaceElement) {
113960
+ surfaceElement.removeEventListener("superdoc-link-click", handleLinkClick);
113961
+ }
113962
+ });
113963
+ return (_ctx, _cache) => {
113964
+ return null;
113965
+ };
113966
+ }
113967
+ };
113262
113968
  function adjustPaginationBreaks(editorElem, editor) {
113263
113969
  if (!editorElem.value || !editor?.value?.options?.scale || isHeadless(editor)) return;
113264
113970
  const zoom = editor.value.options.scale;
@@ -113600,21 +114306,28 @@ const _sfc_main$1 = {
113600
114306
  class: "editor-element super-editor__element",
113601
114307
  role: "presentation"
113602
114308
  }, null, 512),
113603
- !contextMenuDisabled.value && editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$7, {
114309
+ !contextMenuDisabled.value && editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$8, {
113604
114310
  key: 0,
113605
114311
  editor: activeEditor.value,
113606
114312
  popoverControls,
113607
114313
  openPopover,
113608
114314
  closePopover
113609
114315
  }, null, 8, ["editor", "popoverControls"])) : createCommentVNode("", true),
113610
- editorReady.value && activeEditor.value ? (openBlock(), createBlock(TableResizeOverlay, {
114316
+ editorReady.value && activeEditor.value ? (openBlock(), createBlock(_sfc_main$2, {
113611
114317
  key: 1,
113612
114318
  editor: activeEditor.value,
114319
+ openPopover,
114320
+ closePopover,
114321
+ popoverVisible: popoverControls.visible
114322
+ }, null, 8, ["editor", "popoverVisible"])) : createCommentVNode("", true),
114323
+ editorReady.value && activeEditor.value ? (openBlock(), createBlock(TableResizeOverlay, {
114324
+ key: 2,
114325
+ editor: activeEditor.value,
113613
114326
  visible: tableResizeState.visible,
113614
114327
  tableElement: tableResizeState.tableElement
113615
114328
  }, null, 8, ["editor", "visible", "tableElement"])) : createCommentVNode("", true),
113616
114329
  editorReady.value && activeEditor.value ? (openBlock(), createBlock(ImageResizeOverlay, {
113617
- key: 2,
114330
+ key: 3,
113618
114331
  editor: activeEditor.value,
113619
114332
  visible: imageResizeState.visible,
113620
114333
  imageElement: imageResizeState.imageElement
@@ -113681,7 +114394,7 @@ const _sfc_main$1 = {
113681
114394
  };
113682
114395
  }
113683
114396
  };
113684
- const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-a84087aa"]]);
114397
+ const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-08b32c3d"]]);
113685
114398
  const _hoisted_1 = ["innerHTML"];
113686
114399
  const _sfc_main = {
113687
114400
  __name: "SuperInput",
@@ -113792,10 +114505,10 @@ export {
113792
114505
  PresentationEditor as P,
113793
114506
  SectionHelpers as S,
113794
114507
  Toolbar as T,
113795
- _sfc_main$6 as _,
114508
+ _sfc_main$7 as _,
113796
114509
  AnnotatorHelpers as a,
113797
114510
  Extensions as b,
113798
- _sfc_main$7 as c,
114511
+ _sfc_main$8 as c,
113799
114512
  SuperConverter as d,
113800
114513
  SuperEditor as e,
113801
114514
  SuperInput as f,