@markweave/react 0.3.5 → 0.3.6

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.
package/dist/index.js CHANGED
@@ -1,67 +1,70 @@
1
1
  import { createMarkweaveEditorExtensions as e } from "markweave/internal/editor-core/create-editor-extensions";
2
2
  import { getLocalizedSlashCommandSpecs as t, getMarkweaveMessages as n, normalizeMarkweaveLang as r } from "markweave/internal/i18n";
3
3
  import { EditorContent as i, NodeViewWrapper as a, ReactNodeViewRenderer as o, useEditor as s } from "@tiptap/react";
4
- import { AlertTriangle as c, AlignCenter as l, AlignJustify as u, AlignLeft as d, AlignRight as f, AlignVerticalJustifyCenter as p, AlignVerticalJustifyEnd as m, AlignVerticalJustifyStart as h, ArrowDown as g, ArrowDownAZ as _, ArrowLeft as v, ArrowRight as y, ArrowUp as b, ArrowUpZA as x, BetweenHorizontalEnd as S, BetweenHorizontalStart as C, BetweenVerticalEnd as w, BetweenVerticalStart as T, Bold as E, Braces as D, Captions as O, Check as k, CheckCircle2 as A, ChevronDown as j, ChevronRight as M, ChevronUp as ee, CircleX as N, Code2 as te, Copy as P, CornerDownLeft as ne, Download as F, ExternalLink as I, Eye as L, Heading1 as re, Heading2 as R, Heading3 as ie, Image as ae, ImageUp as z, IndentDecrease as B, IndentIncrease as oe, Info as se, Italic as ce, Lightbulb as le, Link2 as V, List as ue, ListChecks as H, ListOrdered as U, Minus as de, MoreVertical as fe, PaintBucket as pe, Paperclip as me, Pencil as he, Plus as ge, Quote as _e, Replace as ve, Sigma as ye, SmilePlus as be, Sparkles as xe, SquareX as Se, Strikethrough as Ce, Subscript as we, Superscript as Te, Table2 as Ee, TableCellsMerge as De, TableCellsSplit as Oe, Text as ke, Trash2 as Ae, Type as je, Underline as Me, Upload as Ne, Video as Pe } from "lucide-react";
5
- import { useCallback as W, useEffect as G, useLayoutEffect as K, useMemo as q, useRef as J, useState as Y, useSyncExternalStore as Fe } from "react";
6
- import { detectUploadSource as Ie, getDirectUploadResult as Le, resolveMarkweaveUploadResult as X } from "markweave/internal/plugins/slash-command/upload";
7
- import { MarkweaveCoreImage as Re, MarkweaveCoreVideo as ze, attrsFromMarkweaveImageUploadResult as Be, attrsFromMarkweaveVideoUploadResult as Ve, attrsFromMarkweaveVideoUrl as He, clampMarkweaveImageWidth as Ue, createMarkweaveImageUploadRequest as We, createMarkweaveVideoUploadRequest as Ge, downloadMarkweaveImage as Ke, markweaveVideoIframeAllow as qe, normalizeMarkweaveCoreImageAlign as Je, normalizeMarkweaveVideoEmbedUrl as Ye, numberAttribute as Xe, stringAttribute as Ze } from "markweave/internal/plugins/media/core-media-nodes";
8
- import { getMarkweaveEditorModeState as Qe, isMarkweaveEditorLiveEditable as $e, normalizeMarkweaveEditorMode as et, setMarkweaveEditorModeState as tt, subscribeToMarkweaveEditorMode as nt } from "markweave/internal/core/editor-mode-state";
9
- import { openMarkweaveImagePreview as rt } from "markweave/internal/plugins/media/image-preview";
10
- import { createMarkweaveLightweightImageNodeViewRenderer as it } from "markweave/internal/plugins/media/lightweight-image-node-view";
11
- import { resolveMarkweaveMediaSource as at } from "markweave/internal/plugins/media/media-source";
12
- import { Fragment as ot, jsx as Z, jsxs as Q } from "react/jsx-runtime";
13
- import { createMarkweaveAdapterMediaExtensions as st } from "markweave/internal/plugins/media/media-extension-factory";
14
- import { normalizeMarkweaveLinkCardAttrs as ct, normalizeMarkweaveLinkCardHref as lt, replaceMarkweaveLinkCardWithLink as ut } from "markweave/internal/plugins/link-card/link-card";
15
- import { openMarkweaveLinkCardComposer as dt } from "markweave/internal/plugins/link-card/link-card-composer";
16
- import { MarkweaveLinkCard as ft } from "markweave/internal/plugins/link-card/link-card-node";
17
- import { isEditorComposing as pt } from "markweave/internal/editor-core/composition-guard";
18
- import { createMarkweaveFrameScheduler as mt } from "markweave/internal/editor-core/frame-scheduler";
19
- import { createMarkweaveEditorUpdatePayload as ht, getMarkweaveContentType as gt, isEditorContentCurrent as _t, isMarkweaveControlledContentEchoCurrent as vt, normalizeMarkweaveContentFormat as yt } from "markweave/internal/editor-core/editor-content";
20
- import { openMarkweaveReadonlyLinkFromEvent as bt } from "markweave/internal/editor-core/readonly-link";
21
- import { createMarkweaveEditorRuntimeSnapshot as xt } from "markweave/internal/editor-core/runtime-snapshot";
22
- import { advanceFloatingToolbarMotionState as St, areEditorSelectionSnapshotsEquivalent as Ct, calculateFloatingToolbarFrameShift as wt, calculateFloatingToolbarPopoverPlacement as Tt, calculateFloatingToolbarTopBoundary as Et, createSelectionSnapshot as Dt, getFloatingToolbarFloatingOptions as Ot, getFloatingToolbarState as kt, markweaveRuntimeProjectionDelayMs as At, shouldShowFloatingToolbar as jt, transitionFloatingToolbarState as Mt } from "markweave/internal/editor-core/selection-state";
23
- import { codeBlockCollapsePluginKey as Nt, copyActiveCodeBlock as Pt, getActiveCodeBlockState as Ft, getCodeBlockCopyFeedbackSnapshot as It, markweaveCodeBlockBehavior as Lt, setCodeBlockCollapsedAtPosition as Rt, setCodeBlockLanguageAtPosition as zt, setCodeBlockMermaidPreviewModeAtPosition as Bt } from "markweave/internal/plugins/codeblock/codeblock-behavior";
24
- import { isMermaidInlinePreviewTransaction as Vt, setMarkweaveMermaidTheme as Ht, setMermaidInlinePreviewEditorMode as Ut, setReadonlyMermaidPreviewMode as Wt } from "markweave/internal/plugins/mermaid/mermaid-inline-preview";
25
- import { getMermaidPreviewState as Gt } from "markweave/internal/plugins/mermaid/mermaid-renderer";
26
- import { applyMarkweaveMathLatex as Kt, calculateMarkweaveMathPopoverPosition as qt, getMarkweaveMathAnchorRect as Jt, getMarkweaveMathBlockIndex as Yt, getMarkweaveMathRenderedHtml as Xt, getMarkweaveMathTargetAtPos as Zt, getMarkweaveMathTargetFromDomEvent as Qt, getMarkweaveMathTargetFromSelection as $t, renderMarkweaveMathPreview as en, setMarkweaveMathEditingDomState as tn, setMarkweaveMathEditingDomStateInView as nn, setMarkweaveMathSelectionInView as rn } from "markweave/internal/plugins/math/math-ui-model";
27
- import { filterSlashCommands as an, isExecutableSlashCommand as on } from "markweave/internal/plugins/slash-command/command-spec";
28
- import { getSlashCommandKeyboardAction as sn, isSlashCommandMenuState as cn } from "markweave/internal/plugins/slash-command/slash-keyboard";
29
- import { areSlashCommandMenuPositionsEquivalent as ln, executeSlashCommand as un, getNextSlashCommandState as dn, getSlashCommandAnchoredMenuPosition as fn, getSlashCommandContext as pn, isSlashCommandAnchorVisible as mn } from "markweave/internal/plugins/slash-command/slash-runtime";
30
- import { initialSlashCommandState as hn, reduceSlashCommandState as gn } from "markweave/internal/plugins/slash-command/slash-state";
31
- import { getFirstTableDebugSnapshot as _n } from "markweave/internal/plugins/table/table-debug-snapshot";
32
- import { focusFirstTableBodyCell as vn } from "markweave/internal/plugins/table/table-focus-position";
33
- import { getTableFocusState as yn } from "markweave/internal/plugins/table/table-focus-state";
34
- import { getTableSelectionOverlayState as bn, initialTableInteractionState as xn, tableInteractionPluginKey as Sn } from "markweave/internal/plugins/table/table-interaction-layer";
35
- import { saveMarkweaveBrowserFile as Cn } from "markweave/internal/core/browser-file-save";
36
- import { calculateCodeBlockLanguageMenuPosition as wn, clampFullscreenScale as Tn, codeBlockCopyFeedbackTimeoutMs as En, copyCodeBlockText as Dn, createCodeBlockLanguageMenuDomId as On, createCodeBlockOverlayPosition as kn, createMermaidFullscreenViewerState as An, createMermaidTabPosition as jn, focusCodeBlockTarget as Mn, formatCodeBlockLanguageLabel as Nn, formatFullscreenZoom as Pn, getActiveCodeBlockElement as Fn, getAnchoredRect as In, getCodeBlockLanguageItems as Ln, getCodeBlockLanguageOptionDomId as Rn, getCodeBlockPositionFromEventTarget as zn, getCodeBlockStateAtPosition as Bn, getFrameElement as Vn, getInitialCodeBlockLanguageItemIndex as Hn, getMermaidCodeBlockTargets as Un, getMermaidSvgMarkup as Wn, isCodeBlockTargetCollapsed as Gn, mergeStableMermaidTabPositions as Kn, mermaidFullscreenZoomStep as qn, moveCodeBlockLanguageItemIndex as Jn, moveMermaidFullscreenViewer as Yn, scrollCodeBlockLanguageItemIntoView as Xn } from "markweave/internal/plugins/codeblock/codeblock-ui-model";
37
- import { BubbleMenu as Zn } from "@tiptap/react/menus";
38
- import { applyFloatingToolbarLink as Qn, createFloatingToolbarAssistantRequest as $n, getFloatingToolbarButtonModels as er, getFloatingToolbarHighlightColorOptions as tr, getFloatingToolbarLinkHref as nr, getFloatingToolbarMessageSet as rr, getFloatingToolbarMoreActions as ir, getFloatingToolbarTextColorOptions as ar, getFloatingToolbarTooltipModel as or, getFloatingToolbarTurnIntoOptions as sr, isFloatingToolbarMoreActionActive as cr, isFloatingToolbarTurnIntoActive as lr, openFloatingToolbarLinkHref as ur, preventFloatingToolbarPointerFocusLoss as dr, removeFloatingToolbarLink as fr, runFloatingToolbarMoreAction as pr, setFloatingToolbarHighlightColor as mr, setFloatingToolbarTextColor as hr, setFloatingToolbarTurnInto as gr } from "markweave/internal/editor-core/floating-toolbar-model";
39
- import { normalizeMarkdownLinkHref as _r } from "markweave/internal/plugins/markdown/markdown-input";
40
- import { setMarkweaveTableMenuAxisTarget as vr } from "markweave/internal/plugins/table/table-clipboard";
41
- import { applyTableAxisAlignment as yr, applyTableAxisBackgroundColor as br, applyTableAxisTextColor as xr, calculateAnchoredTableMenuPosition as Sr, calculateAnchoredTableSubmenuPosition as Cr, calculateTableAxisHandleLayout as wr, calculateTableExtendButtonLayout as Tr, canRunTableCommand as Er, executeTableMenuCommand as Dr, formatTableCopyFeedback as Or, getActiveTableElement as kr, getTableAxisDropIndexAtPoint as Ar, getTableAxisFormattingState as jr, getTableAxisTargetRect as Mr, getTableControlAxisSelectionModel as Nr, getTableEditWithAiRequest as Pr, getTableMenuBoundaryRect as Fr, getTableMenuItemGroup as Ir, getTableMenuItemLabel as Lr, getTableMenuItems as Rr, getTableSelectionTargetRect as zr, measureTableSelectionOverlay as Br, moveTargetedTableAxis as Vr, selectTableAxisFromCell as Hr, tableColorOptions as Ur, tableCopyFeedbackTimeoutMs as Wr, tableHorizontalAlignmentOptions as Gr, tableMenuLabel as Kr, tableVerticalAlignmentOptions as qr, targetTableAxisFromCell as Jr } from "markweave/internal/plugins/table/table-ui-model";
42
- import { createMarkweaveTocState as Yr, emptyMarkweaveTocState as Xr, getActiveMarkweaveTocId as Zr, getMarkweaveTocItemsFromState as Qr, getValidMarkweaveTocActiveId as $r, normalizeMarkweaveInnerTocPlacement as ei, observeMarkweaveInnerTocContainerPosition as ti, scrollToMarkweaveTocItem as ni } from "markweave/internal/core/toc-state";
43
- import { normalizeMarkweaveCanvasColor as ri, normalizeMarkweaveTheme as ii } from "markweave/internal/core/theme";
44
- import { splitMarkweaveLargeMarkdown as ai } from "markweave/internal/core/large-document";
45
- import { createMarkweaveSearchController as oi } from "markweave/internal/plugins/search/search-controller";
4
+ import { AlertTriangle as c, AlignCenter as l, AlignJustify as u, AlignLeft as d, AlignRight as f, AlignVerticalJustifyCenter as p, AlignVerticalJustifyEnd as m, AlignVerticalJustifyStart as h, ArrowDown as g, ArrowDownAZ as _, ArrowLeft as v, ArrowRight as y, ArrowUp as b, ArrowUpZA as x, BetweenHorizontalEnd as S, BetweenHorizontalStart as C, BetweenVerticalEnd as w, BetweenVerticalStart as T, Bold as E, Braces as D, Captions as O, Check as k, CheckCircle2 as A, ChevronDown as ee, ChevronRight as j, ChevronUp as te, CircleX as M, Code2 as ne, Copy as N, CornerDownLeft as re, Download as ie, ExternalLink as P, Eye as F, Heading1 as ae, Heading2 as I, Heading3 as oe, Image as L, ImageUp as R, IndentDecrease as z, IndentIncrease as B, Info as se, Italic as ce, Lightbulb as le, Link2 as ue, List as de, ListChecks as V, ListOrdered as H, Minus as fe, MoreVertical as U, PaintBucket as W, Paperclip as pe, Pencil as me, Plus as he, Quote as ge, Replace as _e, RotateCcw as ve, Sigma as ye, SmilePlus as be, Sparkles as xe, Square as Se, SquareX as Ce, Strikethrough as we, Subscript as Te, Superscript as Ee, Table2 as De, TableCellsMerge as Oe, TableCellsSplit as ke, Text as Ae, Trash2 as je, Type as Me, Underline as Ne, Upload as Pe, Video as Fe, X as Ie } from "lucide-react";
5
+ import { useCallback as G, useEffect as K, useLayoutEffect as Le, useMemo as q, useRef as J, useState as Y, useSyncExternalStore as Re } from "react";
6
+ import { detectUploadSource as ze, getDirectUploadResult as Be, resolveMarkweaveUploadResult as X } from "markweave/internal/plugins/slash-command/upload";
7
+ import { MarkweaveCoreImage as Ve, MarkweaveCoreVideo as He, attrsFromMarkweaveImageUploadResult as Ue, attrsFromMarkweaveVideoUploadResult as We, attrsFromMarkweaveVideoUrl as Ge, clampMarkweaveImageWidth as Ke, createMarkweaveImageUploadRequest as qe, createMarkweaveVideoUploadRequest as Je, downloadMarkweaveImage as Ye, markweaveVideoIframeAllow as Xe, normalizeMarkweaveCoreImageAlign as Ze, normalizeMarkweaveVideoEmbedUrl as Qe, numberAttribute as $e, stringAttribute as et } from "markweave/internal/plugins/media/core-media-nodes";
8
+ import { getMarkweaveEditorModeState as tt, isMarkweaveEditorLiveEditable as nt, normalizeMarkweaveEditorMode as rt, setMarkweaveEditorModeState as it, subscribeToMarkweaveEditorMode as at } from "markweave/internal/core/editor-mode-state";
9
+ import { openMarkweaveImagePreview as ot } from "markweave/internal/plugins/media/image-preview";
10
+ import { createMarkweaveLightweightImageNodeViewRenderer as st } from "markweave/internal/plugins/media/lightweight-image-node-view";
11
+ import { resolveMarkweaveMediaSource as ct } from "markweave/internal/plugins/media/media-source";
12
+ import { Fragment as lt, jsx as Z, jsxs as Q } from "react/jsx-runtime";
13
+ import { createMarkweaveAdapterMediaExtensions as ut } from "markweave/internal/plugins/media/media-extension-factory";
14
+ import { normalizeMarkweaveLinkCardAttrs as dt, normalizeMarkweaveLinkCardHref as ft, replaceMarkweaveLinkCardWithLink as pt } from "markweave/internal/plugins/link-card/link-card";
15
+ import { openMarkweaveLinkCardComposer as mt } from "markweave/internal/plugins/link-card/link-card-composer";
16
+ import { MarkweaveLinkCard as ht } from "markweave/internal/plugins/link-card/link-card-node";
17
+ import { createMarkweaveAiEditController as gt } from "markweave";
18
+ import { isEditorComposing as _t } from "markweave/internal/editor-core/composition-guard";
19
+ import { createMarkweaveFrameScheduler as vt } from "markweave/internal/editor-core/frame-scheduler";
20
+ import { createMarkweaveEditorUpdatePayload as yt, getMarkweaveContentType as bt, isEditorContentCurrent as xt, isMarkweaveControlledContentEchoCurrent as St, normalizeMarkweaveContentFormat as Ct } from "markweave/internal/editor-core/editor-content";
21
+ import { openMarkweaveReadonlyLinkFromEvent as wt } from "markweave/internal/editor-core/readonly-link";
22
+ import { createMarkweaveEditorRuntimeSnapshot as Tt } from "markweave/internal/editor-core/runtime-snapshot";
23
+ import { advanceFloatingToolbarMotionState as Et, areEditorSelectionSnapshotsEquivalent as Dt, calculateFloatingToolbarFrameShift as Ot, calculateFloatingToolbarPopoverPlacement as kt, calculateFloatingToolbarTopBoundary as At, createSelectionSnapshot as jt, getFloatingToolbarFloatingOptions as Mt, getFloatingToolbarState as Nt, markweaveRuntimeProjectionDelayMs as Pt, shouldShowFloatingToolbar as Ft, transitionFloatingToolbarState as It } from "markweave/internal/editor-core/selection-state";
24
+ import { codeBlockCollapsePluginKey as Lt, copyActiveCodeBlock as Rt, getActiveCodeBlockState as zt, getCodeBlockCopyFeedbackSnapshot as Bt, markweaveCodeBlockBehavior as Vt, setCodeBlockCollapsedAtPosition as Ht, setCodeBlockLanguageAtPosition as Ut, setCodeBlockMermaidPreviewModeAtPosition as Wt } from "markweave/internal/plugins/codeblock/codeblock-behavior";
25
+ import { isMermaidInlinePreviewTransaction as Gt, setMarkweaveMermaidTheme as Kt, setMermaidInlinePreviewEditorMode as qt, setReadonlyMermaidPreviewMode as Jt } from "markweave/internal/plugins/mermaid/mermaid-inline-preview";
26
+ import { getMermaidPreviewState as Yt } from "markweave/internal/plugins/mermaid/mermaid-renderer";
27
+ import { applyMarkweaveMathLatex as Xt, calculateMarkweaveMathPopoverPosition as Zt, getMarkweaveMathAnchorRect as Qt, getMarkweaveMathBlockIndex as $t, getMarkweaveMathRenderedHtml as en, getMarkweaveMathTargetAtPos as tn, getMarkweaveMathTargetFromDomEvent as nn, getMarkweaveMathTargetFromSelection as rn, renderMarkweaveMathPreview as an, setMarkweaveMathEditingDomState as on, setMarkweaveMathEditingDomStateInView as sn, setMarkweaveMathSelectionInView as cn } from "markweave/internal/plugins/math/math-ui-model";
28
+ import { filterSlashCommands as ln, isExecutableSlashCommand as un } from "markweave/internal/plugins/slash-command/command-spec";
29
+ import { getSlashCommandKeyboardAction as dn, isSlashCommandMenuState as fn } from "markweave/internal/plugins/slash-command/slash-keyboard";
30
+ import { areSlashCommandMenuPositionsEquivalent as pn, executeSlashCommand as mn, getNextSlashCommandState as hn, getSlashCommandAnchoredMenuPosition as gn, getSlashCommandContext as _n, isSlashCommandAnchorVisible as vn } from "markweave/internal/plugins/slash-command/slash-runtime";
31
+ import { initialSlashCommandState as yn, reduceSlashCommandState as bn } from "markweave/internal/plugins/slash-command/slash-state";
32
+ import { getFirstTableDebugSnapshot as xn } from "markweave/internal/plugins/table/table-debug-snapshot";
33
+ import { focusFirstTableBodyCell as Sn } from "markweave/internal/plugins/table/table-focus-position";
34
+ import { getTableFocusState as Cn } from "markweave/internal/plugins/table/table-focus-state";
35
+ import { getTableSelectionOverlayState as wn, initialTableInteractionState as Tn, tableInteractionPluginKey as En } from "markweave/internal/plugins/table/table-interaction-layer";
36
+ import { saveMarkweaveBrowserFile as Dn } from "markweave/internal/core/browser-file-save";
37
+ import { calculateCodeBlockLanguageMenuPosition as On, clampFullscreenScale as kn, codeBlockCopyFeedbackTimeoutMs as An, copyCodeBlockText as jn, createCodeBlockLanguageMenuDomId as Mn, createCodeBlockOverlayPosition as Nn, createMermaidFullscreenViewerState as Pn, createMermaidTabPosition as Fn, focusCodeBlockTarget as In, formatCodeBlockLanguageLabel as Ln, formatFullscreenZoom as Rn, getActiveCodeBlockElement as zn, getAnchoredRect as Bn, getCodeBlockLanguageItems as Vn, getCodeBlockLanguageOptionDomId as Hn, getCodeBlockPositionFromEventTarget as Un, getCodeBlockStateAtPosition as Wn, getFrameElement as Gn, getInitialCodeBlockLanguageItemIndex as Kn, getMermaidCodeBlockTargets as qn, getMermaidSvgMarkup as Jn, isCodeBlockTargetCollapsed as Yn, mergeStableMermaidTabPositions as Xn, mermaidFullscreenZoomStep as Zn, moveCodeBlockLanguageItemIndex as Qn, moveMermaidFullscreenViewer as $n, scrollCodeBlockLanguageItemIntoView as er } from "markweave/internal/plugins/codeblock/codeblock-ui-model";
38
+ import { BubbleMenu as tr } from "@tiptap/react/menus";
39
+ import { applyFloatingToolbarLink as nr, createFloatingToolbarAssistantRequest as rr, getFloatingToolbarButtonModels as ir, getFloatingToolbarHighlightColorOptions as ar, getFloatingToolbarLinkHref as or, getFloatingToolbarMessageSet as sr, getFloatingToolbarMoreActions as cr, getFloatingToolbarTextColorOptions as lr, getFloatingToolbarTooltipModel as ur, getFloatingToolbarTurnIntoOptions as dr, isFloatingToolbarMoreActionActive as fr, isFloatingToolbarTurnIntoActive as pr, openFloatingToolbarLinkHref as mr, preventFloatingToolbarPointerFocusLoss as hr, removeFloatingToolbarLink as gr, runFloatingToolbarMoreAction as _r, setFloatingToolbarHighlightColor as vr, setFloatingToolbarTextColor as yr, setFloatingToolbarTurnInto as br } from "markweave/internal/editor-core/floating-toolbar-model";
40
+ import { MarkweaveAskAiError as xr, acceptMarkweaveAskAiResult as Sr, calculateMarkweaveAskAiPanelPosition as Cr, canStartMarkweaveAskAiTableTarget as wr, clearMarkweaveAskAiPreview as Tr, clearMarkweaveAskAiTarget as Er, createMarkweaveAskAiRequest as Dr, getMappedMarkweaveAskAiSelection as Or, getMarkweaveAskAiSurfaceRect as kr, getMarkweaveAskAiTarget as Ar, getMarkweaveAskAiTargetRect as jr, restoreMarkweaveAskAiTargetSelection as Mr, runMarkweaveAskAiHandler as Nr, setMarkweaveAskAiPreview as Pr, startMarkweaveAskAiTableTarget as Fr, startMarkweaveAskAiTarget as Ir } from "markweave/internal/plugins/ask-ai/ask-ai-session";
41
+ import { normalizeMarkdownLinkHref as Lr } from "markweave/internal/plugins/markdown/markdown-input";
42
+ import { setMarkweaveTableMenuAxisTarget as Rr } from "markweave/internal/plugins/table/table-clipboard";
43
+ import { applyTableAxisAlignment as zr, applyTableAxisBackgroundColor as Br, applyTableAxisTextColor as Vr, calculateAnchoredTableMenuPosition as Hr, calculateAnchoredTableSubmenuPosition as Ur, calculateTableAxisHandleLayout as Wr, calculateTableExtendButtonLayout as Gr, canRunTableCommand as Kr, executeTableMenuCommand as qr, formatTableCopyFeedback as Jr, getActiveTableElement as Yr, getTableAxisDropIndexAtPoint as Xr, getTableAxisFormattingState as Zr, getTableAxisTargetRect as Qr, getTableControlAxisSelectionModel as $r, getTableMenuBoundaryRect as ei, getTableMenuItemGroup as ti, getTableMenuItemLabel as ni, getTableMenuItems as ri, getTableSelectionTargetRect as ii, measureTableSelectionOverlay as ai, moveTargetedTableAxis as oi, selectTableAxisFromCell as si, tableColorOptions as ci, tableCopyFeedbackTimeoutMs as li, tableHorizontalAlignmentOptions as ui, tableMenuLabel as di, tableVerticalAlignmentOptions as fi, targetTableAxisFromCell as pi } from "markweave/internal/plugins/table/table-ui-model";
44
+ import { createMarkweaveTocState as mi, emptyMarkweaveTocState as hi, getActiveMarkweaveTocId as gi, getMarkweaveTocItemsFromState as _i, getValidMarkweaveTocActiveId as vi, normalizeMarkweaveInnerTocPlacement as yi, observeMarkweaveInnerTocContainerPosition as bi, scrollToMarkweaveTocItem as xi } from "markweave/internal/core/toc-state";
45
+ import { normalizeMarkweaveCanvasColor as Si, normalizeMarkweaveTheme as Ci } from "markweave/internal/core/theme";
46
+ import { splitMarkweaveLargeMarkdown as wi } from "markweave/internal/core/large-document";
47
+ import { createMarkweaveSearchController as Ti } from "markweave/internal/plugins/search/search-controller";
48
+ import { createMarkweaveAiEditController as Ei } from "markweave/internal/plugins/ai-edit/ai-edit-controller";
46
49
  //#region src/editor-mode-state.ts
47
- var si = {
50
+ var Di = {
48
51
  mode: "live",
49
52
  editable: !0
50
53
  };
51
- function ci(e) {
52
- return Fe((t) => nt(e, t), () => Qe(e), () => si);
54
+ function Oi(e) {
55
+ return Re((t) => at(e, t), () => tt(e), () => Di);
53
56
  }
54
57
  //#endregion
55
58
  //#region src/media/image-node.tsx
56
- var li = Je;
57
- function ui(e) {
59
+ var ki = Ze;
60
+ function Ai(e) {
58
61
  return e instanceof Element && !!e.closest("[data-markweave-image-ui=\"true\"]");
59
62
  }
60
- function di(e) {
61
- let { deleteNode: t, editor: r, getPos: i, node: o, selected: s, updateAttributes: c } = e, l = e.extension.options, u = l.messages ?? n("zh"), d = u.image, f = $e(ci(r)), p = Ze(o.attrs.src), m = li(o.attrs.align), h = Xe(o.attrs.width), g = Ze(o.attrs.caption), _ = J(null), v = _i(p, l.resolveMediaSource, _, s), y = v?.src ?? (l.resolveMediaSource ? null : p), b = J(null), [x, S] = Y(!1), [C, w] = Y(!1), [T, E] = Y(!1), [D, O] = Y(""), [k, A] = Y(null), [j, M] = Y(!1), [ee, N] = Y(!!g), [te, P] = Y(g ?? ""), ne = f && (!p || C), F = () => {
62
- y && rt({
63
+ function ji(e) {
64
+ let { deleteNode: t, editor: r, getPos: i, node: o, selected: s, updateAttributes: c } = e, l = e.extension.options, u = l.messages ?? n("zh"), d = u.image, f = nt(Oi(r)), p = et(o.attrs.src), m = ki(o.attrs.align), h = $e(o.attrs.width), g = et(o.attrs.caption), _ = J(null), v = Li(p, l.resolveMediaSource, _, s), y = v?.src ?? (l.resolveMediaSource ? null : p), b = J(null), [x, S] = Y(!1), [C, w] = Y(!1), [T, E] = Y(!1), [D, O] = Y(""), [k, A] = Y(null), [ee, j] = Y(!1), [te, M] = Y(!!g), [ne, N] = Y(g ?? ""), re = f && (!p || C), ie = () => {
65
+ y && ot({
63
66
  src: y,
64
- alt: Ze(o.attrs.alt) ?? "",
67
+ alt: et(o.attrs.alt) ?? "",
65
68
  messages: {
66
69
  dialogAriaLabel: d.previewDialogAriaLabel,
67
70
  zoomOut: d.previewZoomOut,
@@ -71,14 +74,14 @@ function di(e) {
71
74
  }
72
75
  });
73
76
  };
74
- G(() => {
75
- ee || P(g ?? "");
76
- }, [g, ee]);
77
- let I = () => {
77
+ K(() => {
78
+ te || N(g ?? "");
79
+ }, [g, te]);
80
+ let P = () => {
78
81
  if (!f) return;
79
82
  let e = i();
80
83
  typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
81
- }, re = () => {
84
+ }, ae = () => {
82
85
  if (f) {
83
86
  if (O(""), A(null), E(!1), p) {
84
87
  w(!1);
@@ -86,48 +89,48 @@ function di(e) {
86
89
  }
87
90
  t();
88
91
  }
89
- }, R = async (e) => {
92
+ }, I = async (e) => {
90
93
  if (f) {
91
- A(null), M(!0);
94
+ A(null), j(!0);
92
95
  try {
93
- let t = await X(We(e, p && C ? "image-replace" : "image-insert"), l.onUpload);
94
- c(Be(o.attrs, t)), w(!1), O("");
96
+ let t = await X(qe(e, p && C ? "image-replace" : "image-insert"), l.onUpload);
97
+ c(Ue(o.attrs, t)), w(!1), O("");
95
98
  } catch (e) {
96
99
  A(e instanceof Error ? e.message : d.uploadFailedError);
97
100
  } finally {
98
- M(!1), E(!1);
101
+ j(!1), E(!1);
99
102
  }
100
103
  }
101
- }, ie = () => {
104
+ }, oe = () => {
102
105
  if (f) {
103
106
  if (!D.trim()) {
104
107
  A(d.uploadRequiredError);
105
108
  return;
106
109
  }
107
- R(Ie(D));
110
+ I(ze(D));
108
111
  }
109
- }, ae = (e) => {
110
- !f || !e || R({
112
+ }, L = (e) => {
113
+ !f || !e || I({
111
114
  type: "file",
112
115
  file: e,
113
116
  mimeType: e.type
114
117
  });
118
+ }, R = (e) => {
119
+ L(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
115
120
  }, z = (e) => {
116
- ae(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
117
- }, B = (e) => {
118
- e.preventDefault(), e.stopPropagation(), f && ae(e.dataTransfer.files?.[0] ?? null);
119
- }, oe = () => {
120
- f && (N((e) => !e), ee || P(g ?? ""));
121
+ e.preventDefault(), e.stopPropagation(), f && L(e.dataTransfer.files?.[0] ?? null);
122
+ }, B = () => {
123
+ f && (M((e) => !e), te || N(g ?? ""));
121
124
  }, se = (e) => {
122
- f && (P(e), c({ caption: e.trim() ? e : null }));
125
+ f && (N(e), c({ caption: e.trim() ? e : null }));
123
126
  }, ce = (e, t) => {
124
127
  if (t.preventDefault(), t.stopPropagation(), !f) return;
125
- I();
128
+ P();
126
129
  let n = _.current;
127
130
  if (!n) return;
128
131
  let r = t.clientX, i = n.getBoundingClientRect().width || h || 320, a = n.closest(".markweave-editor-surface")?.getBoundingClientRect().width ?? n.parentElement?.getBoundingClientRect().width ?? i, o = (t) => {
129
132
  let n = e === "right" ? t.clientX - r : r - t.clientX;
130
- c({ width: Ue(i + n, a) });
133
+ c({ width: Ke(i + n, a) });
131
134
  }, s = () => {
132
135
  window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", s);
133
136
  };
@@ -140,37 +143,37 @@ function di(e) {
140
143
  "data-align": m,
141
144
  "data-selected": f && s ? "true" : "false",
142
145
  "data-hovered": x ? "true" : "false",
143
- "data-empty": ne ? "true" : "false",
146
+ "data-empty": re ? "true" : "false",
144
147
  onPointerEnter: () => S(!0),
145
148
  onPointerLeave: () => S(!1),
146
149
  onMouseDown: (e) => {
147
- f && !ui(e.target) && I();
150
+ f && !Ai(e.target) && P();
148
151
  },
149
- children: ne ? /* @__PURE__ */ Z(fi, {
152
+ children: re ? /* @__PURE__ */ Z(Mi, {
150
153
  dragActive: T,
151
154
  error: k,
152
155
  inputValue: D,
153
- isSubmitting: j,
156
+ isSubmitting: ee,
154
157
  fileInputRef: b,
155
158
  messages: u,
156
- onCancel: re,
157
- onDrop: B,
159
+ onCancel: ae,
160
+ onDrop: z,
158
161
  onDragActiveChange: E,
159
- onFileChange: z,
162
+ onFileChange: R,
160
163
  onInputChange: O,
161
- onSubmit: ie
162
- }) : /* @__PURE__ */ Q(ot, { children: [
163
- f ? /* @__PURE__ */ Z(pi, {
164
+ onSubmit: oe
165
+ }) : /* @__PURE__ */ Q(lt, { children: [
166
+ f ? /* @__PURE__ */ Z(Ni, {
164
167
  align: m,
165
- captionActive: ee || !!g,
168
+ captionActive: te || !!g,
166
169
  messages: u,
167
170
  onAlign: (e) => c({ align: e }),
168
- onCaption: oe,
171
+ onCaption: B,
169
172
  onDelete: t,
170
173
  onDownload: () => {
171
- y && Ke(y);
174
+ y && Ye(y);
172
175
  },
173
- onPreview: F,
176
+ onPreview: ie,
174
177
  onReplace: () => {
175
178
  O(""), A(null), w(!0);
176
179
  }
@@ -186,8 +189,8 @@ function di(e) {
186
189
  y ? /* @__PURE__ */ Z("img", {
187
190
  className: "markweave-image",
188
191
  src: y,
189
- alt: Ze(o.attrs.alt) ?? "",
190
- title: Ze(o.attrs.title) ?? void 0,
192
+ alt: et(o.attrs.alt) ?? "",
193
+ title: et(o.attrs.title) ?? void 0,
191
194
  draggable: !1,
192
195
  loading: "lazy",
193
196
  decoding: "async",
@@ -206,8 +209,8 @@ function di(e) {
206
209
  "aria-label": d.preview,
207
210
  title: d.preview,
208
211
  onMouseDown: (e) => e.preventDefault(),
209
- onClick: F,
210
- children: [/* @__PURE__ */ Z(L, {
212
+ onClick: ie,
213
+ children: [/* @__PURE__ */ Z(F, {
211
214
  size: 16,
212
215
  strokeWidth: 1.8
213
216
  }), /* @__PURE__ */ Z("span", {
@@ -216,28 +219,28 @@ function di(e) {
216
219
  children: d.preview
217
220
  })]
218
221
  }) : null,
219
- f ? /* @__PURE__ */ Z(hi, {
222
+ f ? /* @__PURE__ */ Z(Fi, {
220
223
  side: "left",
221
224
  messages: u,
222
225
  onPointerDown: ce
223
226
  }) : null,
224
- f ? /* @__PURE__ */ Z(hi, {
227
+ f ? /* @__PURE__ */ Z(Fi, {
225
228
  side: "right",
226
229
  messages: u,
227
230
  onPointerDown: ce
228
231
  }) : null
229
232
  ]
230
233
  }),
231
- f && (ee || g) ? /* @__PURE__ */ Z("input", {
234
+ f && (te || g) ? /* @__PURE__ */ Z("input", {
232
235
  className: "markweave-image-caption-input",
233
236
  "data-markweave-image-ui": "true",
234
237
  "data-testid": "markweave-image-caption-input",
235
- value: te,
238
+ value: ne,
236
239
  placeholder: d.captionPlaceholder,
237
240
  "aria-label": d.captionAriaLabel,
238
241
  onChange: (e) => se(e.currentTarget.value),
239
242
  onKeyDown: (e) => {
240
- e.key === "Escape" && (e.preventDefault(), N(!1));
243
+ e.key === "Escape" && (e.preventDefault(), M(!1));
241
244
  }
242
245
  }) : g ? /* @__PURE__ */ Z("figcaption", {
243
246
  className: "markweave-image-caption",
@@ -247,7 +250,7 @@ function di(e) {
247
250
  ] })
248
251
  });
249
252
  }
250
- function fi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
253
+ function Mi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
251
254
  let f = a.image;
252
255
  return /* @__PURE__ */ Q("section", {
253
256
  className: "markweave-image-upload-placeholder",
@@ -274,7 +277,7 @@ function fi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
274
277
  /* @__PURE__ */ Z("div", {
275
278
  className: "markweave-image-upload-icon",
276
279
  "aria-hidden": "true",
277
- children: /* @__PURE__ */ Z(z, {
280
+ children: /* @__PURE__ */ Z(R, {
278
281
  size: 46,
279
282
  strokeWidth: 1.6
280
283
  })
@@ -309,7 +312,7 @@ function fi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
309
312
  "data-testid": "markweave-image-upload-submit",
310
313
  disabled: i || !r.trim(),
311
314
  onClick: d,
312
- children: [/* @__PURE__ */ Z(z, {
315
+ children: [/* @__PURE__ */ Z(R, {
313
316
  size: 16,
314
317
  strokeWidth: 1.8
315
318
  }), a.common.insert]
@@ -329,7 +332,7 @@ function fi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
329
332
  ]
330
333
  });
331
334
  }
332
- function pi({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i, onDelete: a, onDownload: o, onPreview: s, onReplace: c }) {
335
+ function Ni({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i, onDelete: a, onDownload: o, onPreview: s, onReplace: c }) {
333
336
  let u = n.image;
334
337
  return /* @__PURE__ */ Q("div", {
335
338
  className: "markweave-image-toolbar",
@@ -337,21 +340,21 @@ function pi({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i,
337
340
  "data-markweave-image-ui": "true",
338
341
  "aria-label": u.toolsAriaLabel,
339
342
  children: [
340
- /* @__PURE__ */ Z(mi, {
343
+ /* @__PURE__ */ Z(Pi, {
341
344
  testId: "markweave-image-align-left",
342
345
  label: u.alignLeft,
343
346
  icon: d,
344
347
  active: e === "left",
345
348
  onClick: () => r("left")
346
349
  }),
347
- /* @__PURE__ */ Z(mi, {
350
+ /* @__PURE__ */ Z(Pi, {
348
351
  testId: "markweave-image-align-center",
349
352
  label: u.alignCenter,
350
353
  icon: l,
351
354
  active: e === "center",
352
355
  onClick: () => r("center")
353
356
  }),
354
- /* @__PURE__ */ Z(mi, {
357
+ /* @__PURE__ */ Z(Pi, {
355
358
  testId: "markweave-image-align-right",
356
359
  label: u.alignRight,
357
360
  icon: f,
@@ -362,45 +365,45 @@ function pi({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i,
362
365
  className: "markweave-image-toolbar-divider",
363
366
  "aria-hidden": "true"
364
367
  }),
365
- /* @__PURE__ */ Z(mi, {
368
+ /* @__PURE__ */ Z(Pi, {
366
369
  testId: "markweave-image-caption",
367
370
  label: u.caption,
368
371
  icon: O,
369
372
  active: t,
370
373
  onClick: i
371
374
  }),
372
- /* @__PURE__ */ Z(mi, {
375
+ /* @__PURE__ */ Z(Pi, {
373
376
  testId: "markweave-image-preview",
374
377
  label: u.preview,
375
- icon: L,
378
+ icon: F,
376
379
  onClick: s
377
380
  }),
378
- /* @__PURE__ */ Z(mi, {
381
+ /* @__PURE__ */ Z(Pi, {
379
382
  testId: "markweave-image-download",
380
383
  label: u.download,
381
- icon: F,
384
+ icon: ie,
382
385
  onClick: o
383
386
  }),
384
- /* @__PURE__ */ Z(mi, {
387
+ /* @__PURE__ */ Z(Pi, {
385
388
  testId: "markweave-image-replace",
386
389
  label: u.replace,
387
- icon: ve,
390
+ icon: _e,
388
391
  onClick: c
389
392
  }),
390
393
  /* @__PURE__ */ Z("span", {
391
394
  className: "markweave-image-toolbar-divider",
392
395
  "aria-hidden": "true"
393
396
  }),
394
- /* @__PURE__ */ Z(mi, {
397
+ /* @__PURE__ */ Z(Pi, {
395
398
  testId: "markweave-image-delete",
396
399
  label: u.delete,
397
- icon: Ae,
400
+ icon: je,
398
401
  onClick: a
399
402
  })
400
403
  ]
401
404
  });
402
405
  }
403
- function mi({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
406
+ function Pi({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
404
407
  return /* @__PURE__ */ Q("button", {
405
408
  type: "button",
406
409
  "aria-label": n,
@@ -419,7 +422,7 @@ function mi({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
419
422
  })]
420
423
  });
421
424
  }
422
- function hi({ messages: e, onPointerDown: t, side: n }) {
425
+ function Fi({ messages: e, onPointerDown: t, side: n }) {
423
426
  return /* @__PURE__ */ Z("button", {
424
427
  type: "button",
425
428
  className: "markweave-image-resize-handle",
@@ -430,7 +433,7 @@ function hi({ messages: e, onPointerDown: t, side: n }) {
430
433
  onPointerDown: (e) => t(n, e)
431
434
  });
432
435
  }
433
- var gi = Re.extend({
436
+ var Ii = Ve.extend({
434
437
  addOptions() {
435
438
  return {
436
439
  ...this.parent?.(),
@@ -441,21 +444,21 @@ var gi = Re.extend({
441
444
  },
442
445
  addNodeView() {
443
446
  if (typeof document > "u") return null;
444
- let e = o(di, { stopEvent: ({ event: e }) => ui(e.target) }), t = this.options.resolveMediaSource;
447
+ let e = o(ji, { stopEvent: ({ event: e }) => Ai(e.target) }), t = this.options.resolveMediaSource;
445
448
  if (!t) return e;
446
- let r = it({
449
+ let r = st({
447
450
  messages: this.options.messages ?? n("zh"),
448
451
  onUpload: this.options.onUpload,
449
452
  resolveMediaSource: t
450
453
  });
451
- return (t) => Ze(t.node.attrs.src) ? r(t) : e(t);
454
+ return (t) => et(t.node.attrs.src) ? r(t) : e(t);
452
455
  }
453
456
  });
454
- function _i(e, t, n, r) {
457
+ function Li(e, t, n, r) {
455
458
  let [i, a] = Y(t ? "background" : "visible"), [o, s] = Y(() => !t && e ? { src: e } : null);
456
- return G(() => {
459
+ return K(() => {
457
460
  s(!t && e ? { src: e } : null), a(t ? "background" : "visible");
458
- }, [t, e]), G(() => {
461
+ }, [t, e]), K(() => {
459
462
  if (!t || !e) return;
460
463
  if (r) {
461
464
  a("visible");
@@ -478,10 +481,10 @@ function _i(e, t, n, r) {
478
481
  t,
479
482
  r,
480
483
  e
481
- ]), G(() => {
484
+ ]), K(() => {
482
485
  if (!t || !e || i === "background") return;
483
486
  let n = new AbortController();
484
- return at(t, {
487
+ return ct(t, {
485
488
  kind: "image",
486
489
  priority: i,
487
490
  signal: n.signal,
@@ -497,28 +500,28 @@ function _i(e, t, n, r) {
497
500
  }
498
501
  //#endregion
499
502
  //#region src/media/video-node.tsx
500
- function vi(e) {
503
+ function Ri(e) {
501
504
  return e instanceof Element && !!e.closest("[data-markweave-video-ui=\"true\"], iframe[data-markweave-video-embed], video[data-markweave-video]");
502
505
  }
503
- function yi(e) {
504
- let { deleteNode: t, editor: r, getPos: i, node: o, selected: s, updateAttributes: c } = e, l = e.extension.options, u = l.messages ?? n("zh"), d = u.video, f = $e(ci(r)), p = Ze(o.attrs.src), m = Ze(o.attrs.embedUrl), h = Ze(o.attrs.provider), g = m ? Ye(m, h) : null, _ = Ze(o.attrs.mimeType), v = Ze(o.attrs.title), y = J(null), [b, x] = Y(!1), [S, C] = Y(""), [w, T] = Y(null), [E, D] = Y(!1), O = f && !p, k = () => {
506
+ function zi(e) {
507
+ let { deleteNode: t, editor: r, getPos: i, node: o, selected: s, updateAttributes: c } = e, l = e.extension.options, u = l.messages ?? n("zh"), d = u.video, f = nt(Oi(r)), p = et(o.attrs.src), m = et(o.attrs.embedUrl), h = et(o.attrs.provider), g = m ? Qe(m, h) : null, _ = et(o.attrs.mimeType), v = et(o.attrs.title), y = J(null), [b, x] = Y(!1), [S, C] = Y(""), [w, T] = Y(null), [E, D] = Y(!1), O = f && !p, k = () => {
505
508
  if (!f) return;
506
509
  let e = i();
507
510
  typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
508
511
  }, A = (e) => {
509
- f && (vi(e.target) || (e.preventDefault(), k()));
510
- }, j = (e) => {
512
+ f && (Ri(e.target) || (e.preventDefault(), k()));
513
+ }, ee = (e) => {
511
514
  f && (e.key === "Delete" || e.key === "Backspace") && s && (e.preventDefault(), t());
512
- }, M = async (e) => {
515
+ }, j = async (e) => {
513
516
  if (!(!f || !e)) {
514
517
  T(null), D(!0);
515
518
  try {
516
- let t = await X(Ge({
519
+ let t = await X(Je({
517
520
  type: "file",
518
521
  file: e,
519
522
  mimeType: e.type
520
523
  }), l.onUpload);
521
- c(Ve(t)), C("");
524
+ c(We(t)), C("");
522
525
  } catch (e) {
523
526
  T(e instanceof Error ? e.message : d.uploadFailedError);
524
527
  } finally {
@@ -532,7 +535,7 @@ function yi(e) {
532
535
  "data-testid": "markweave-video-node",
533
536
  "data-empty": "true",
534
537
  "data-selected": "false",
535
- children: /* @__PURE__ */ Z(bi, {
538
+ children: /* @__PURE__ */ Z(Bi, {
536
539
  dragActive: b,
537
540
  error: w,
538
541
  fileInputRef: y,
@@ -542,15 +545,15 @@ function yi(e) {
542
545
  onCancel: t,
543
546
  onDragActiveChange: x,
544
547
  onDrop: (e) => {
545
- e.preventDefault(), e.stopPropagation(), f && M(e.dataTransfer.files?.[0] ?? null);
548
+ e.preventDefault(), e.stopPropagation(), f && j(e.dataTransfer.files?.[0] ?? null);
546
549
  },
547
550
  onFileChange: (e) => {
548
- M(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
551
+ j(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
549
552
  },
550
553
  onInputChange: C,
551
554
  onSubmit: () => {
552
555
  if (!f) return;
553
- let e = He(S);
556
+ let e = Ge(S);
554
557
  if (!e) {
555
558
  T(d.unsupportedUrlError);
556
559
  return;
@@ -568,7 +571,7 @@ function yi(e) {
568
571
  tabIndex: f ? 0 : void 0,
569
572
  "aria-label": d.nodeAriaLabel,
570
573
  onFocus: k,
571
- onKeyDown: j,
574
+ onKeyDown: ee,
572
575
  onMouseDown: A,
573
576
  children: g ? /* @__PURE__ */ Q("div", {
574
577
  className: "markweave-video-embed",
@@ -579,7 +582,7 @@ function yi(e) {
579
582
  "data-markweave-video-embed": "true",
580
583
  "data-markweave-video-provider": h ?? void 0,
581
584
  "data-markweave-video-src": p ?? void 0,
582
- allow: qe,
585
+ allow: Xe,
583
586
  loading: "lazy",
584
587
  allowFullScreen: !0
585
588
  }), f ? /* @__PURE__ */ Z("button", {
@@ -613,7 +616,7 @@ function yi(e) {
613
616
  })
614
617
  });
615
618
  }
616
- function bi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
619
+ function Bi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
617
620
  let f = a.video;
618
621
  return /* @__PURE__ */ Q("section", {
619
622
  className: "markweave-video-upload-placeholder",
@@ -640,7 +643,7 @@ function bi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
640
643
  /* @__PURE__ */ Z("div", {
641
644
  className: "markweave-video-upload-icon",
642
645
  "aria-hidden": "true",
643
- children: /* @__PURE__ */ Z(Pe, {
646
+ children: /* @__PURE__ */ Z(Fe, {
644
647
  size: 46,
645
648
  strokeWidth: 1.6
646
649
  })
@@ -675,7 +678,7 @@ function bi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
675
678
  "data-testid": "markweave-video-upload-submit",
676
679
  disabled: i || !r.trim(),
677
680
  onClick: d,
678
- children: [/* @__PURE__ */ Z(Ne, {
681
+ children: [/* @__PURE__ */ Z(Pe, {
679
682
  size: 16,
680
683
  strokeWidth: 1.8
681
684
  }), a.common.insert]
@@ -695,7 +698,7 @@ function bi({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
695
698
  ]
696
699
  });
697
700
  }
698
- var xi = ze.extend({
701
+ var Vi = He.extend({
699
702
  addOptions() {
700
703
  return {
701
704
  ...this.parent?.(),
@@ -705,35 +708,35 @@ var xi = ze.extend({
705
708
  };
706
709
  },
707
710
  addNodeView() {
708
- return typeof document > "u" ? null : o(yi, { stopEvent: ({ event: e }) => vi(e.target) });
711
+ return typeof document > "u" ? null : o(zi, { stopEvent: ({ event: e }) => Ri(e.target) });
709
712
  }
710
713
  });
711
714
  //#endregion
712
715
  //#region src/link-card-node.tsx
713
- function Si(e) {
716
+ function Hi(e) {
714
717
  return e instanceof Element && !!e.closest("[data-markweave-link-card-ui=\"true\"]");
715
718
  }
716
- function Ci(e) {
719
+ function Ui(e) {
717
720
  return typeof navigator < "u" && navigator.clipboard?.writeText ? navigator.clipboard.writeText(e).catch(() => void 0) : Promise.resolve();
718
721
  }
719
- function wi(e) {
722
+ function Wi(e) {
720
723
  !e || typeof window > "u" || window.open(e, "_blank", "noopener,noreferrer");
721
724
  }
722
- function Ti(e) {
725
+ function Gi(e) {
723
726
  try {
724
727
  return new URL(e).host;
725
728
  } catch {
726
729
  return e;
727
730
  }
728
731
  }
729
- function Ei(e) {
730
- let { deleteNode: t, editor: r, getPos: i, node: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? n("zh"), u = l.linkCard, d = $e(ci(r)), f = ct(o.attrs), [p, m] = Y(!1), [h, g] = Y(!1), [_, v] = Y(!1), [y, b] = Y(f?.title ?? ""), [x, S] = Y(f?.href ?? ""), C = J(null);
731
- if (G(() => () => C.current?.abort(), []), G(() => {
732
+ function Ki(e) {
733
+ let { deleteNode: t, editor: r, getPos: i, node: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? n("zh"), u = l.linkCard, d = nt(Oi(r)), f = dt(o.attrs), [p, m] = Y(!1), [h, g] = Y(!1), [_, v] = Y(!1), [y, b] = Y(f?.title ?? ""), [x, S] = Y(f?.href ?? ""), C = J(null);
734
+ if (K(() => () => C.current?.abort(), []), K(() => {
732
735
  b(f?.title ?? ""), S(f?.href ?? ""), v(!1);
733
736
  }, [f?.href, f?.title]), !f) return null;
734
737
  let w = async (e) => {
735
738
  e.preventDefault();
736
- let t = ct({
739
+ let t = dt({
737
740
  ...f,
738
741
  href: x,
739
742
  title: y
@@ -748,15 +751,15 @@ function Ei(e) {
748
751
  title: t.title,
749
752
  signal: n.signal
750
753
  });
751
- !n.signal.aborted && e && s(ct({
754
+ !n.signal.aborted && e && s(dt({
752
755
  ...t,
753
756
  ...e
754
757
  }) ?? t);
755
758
  } catch {}
756
759
  }, T = () => {
757
760
  let e = i();
758
- typeof e == "number" && ut(r, e);
759
- }, E = _ ? null : f.imageUrl, D = Ti(f.href);
761
+ typeof e == "number" && pt(r, e);
762
+ }, E = _ ? null : f.imageUrl, D = Gi(f.href);
760
763
  return /* @__PURE__ */ Q(a, {
761
764
  as: "article",
762
765
  className: "markweave-link-card",
@@ -767,10 +770,10 @@ function Ei(e) {
767
770
  onMouseEnter: () => m(!0),
768
771
  onMouseLeave: () => m(!1),
769
772
  onMouseDown: (e) => {
770
- Si(e.target) || e.preventDefault();
773
+ Hi(e.target) || e.preventDefault();
771
774
  },
772
775
  onClick: (e) => {
773
- Si(e.target) || (e.preventDefault(), wi(f.href));
776
+ Hi(e.target) || (e.preventDefault(), Wi(f.href));
774
777
  },
775
778
  children: [
776
779
  /* @__PURE__ */ Q("a", {
@@ -808,24 +811,24 @@ function Ei(e) {
808
811
  "data-markweave-link-card-ui": "true",
809
812
  "aria-label": u.toolsAriaLabel,
810
813
  children: [
811
- /* @__PURE__ */ Z(Di, {
814
+ /* @__PURE__ */ Z(qi, {
812
815
  label: u.convertToLink,
813
- icon: V,
816
+ icon: ue,
814
817
  onClick: T,
815
818
  testId: "markweave-link-card-convert"
816
819
  }),
817
- /* @__PURE__ */ Z(Di, {
820
+ /* @__PURE__ */ Z(qi, {
818
821
  label: u.copyAddress,
819
- icon: P,
820
- onClick: () => void Ci(f.href),
822
+ icon: N,
823
+ onClick: () => void Ui(f.href),
821
824
  testId: "markweave-link-card-copy"
822
825
  }),
823
- /* @__PURE__ */ Z(Di, {
826
+ /* @__PURE__ */ Z(qi, {
824
827
  label: u.edit,
825
- icon: he,
828
+ icon: me,
826
829
  onClick: (e) => {
827
830
  let t = i();
828
- typeof t == "number" && dt({
831
+ typeof t == "number" && mt({
829
832
  anchor: e.currentTarget,
830
833
  editor: r,
831
834
  messages: l,
@@ -838,9 +841,9 @@ function Ei(e) {
838
841
  },
839
842
  testId: "markweave-link-card-edit"
840
843
  }),
841
- /* @__PURE__ */ Z(Di, {
844
+ /* @__PURE__ */ Z(qi, {
842
845
  label: u.delete,
843
- icon: Ae,
846
+ icon: je,
844
847
  onClick: t,
845
848
  testId: "markweave-link-card-delete"
846
849
  })
@@ -867,15 +870,15 @@ function Ei(e) {
867
870
  /* @__PURE__ */ Z("button", {
868
871
  type: "submit",
869
872
  "aria-label": u.edit,
870
- disabled: !lt(x),
871
- children: /* @__PURE__ */ Z(V, { size: 16 })
873
+ disabled: !ft(x),
874
+ children: /* @__PURE__ */ Z(ue, { size: 16 })
872
875
  })
873
876
  ]
874
877
  }) : null
875
878
  ]
876
879
  });
877
880
  }
878
- function Di({ icon: e, label: t, onClick: n, testId: r }) {
881
+ function qi({ icon: e, label: t, onClick: n, testId: r }) {
879
882
  return /* @__PURE__ */ Q("button", {
880
883
  type: "button",
881
884
  "aria-label": t,
@@ -892,7 +895,7 @@ function Di({ icon: e, label: t, onClick: n, testId: r }) {
892
895
  })]
893
896
  });
894
897
  }
895
- var Oi = ft.extend({
898
+ var Ji = ht.extend({
896
899
  addOptions() {
897
900
  return {
898
901
  ...this.parent?.(),
@@ -901,23 +904,23 @@ var Oi = ft.extend({
901
904
  };
902
905
  },
903
906
  addNodeView() {
904
- return typeof document > "u" ? null : o(Ei, { stopEvent: ({ event: e }) => Si(e.target) });
907
+ return typeof document > "u" ? null : o(Ki, { stopEvent: ({ event: e }) => Hi(e.target) });
905
908
  }
906
909
  });
907
910
  //#endregion
908
911
  //#region src/create-editor-extensions.ts
909
- function ki(t = {}) {
912
+ function Yi(t = {}) {
910
913
  return e({
911
914
  lang: t.lang,
912
915
  onImageUpload: t.onImageUpload,
913
- linkCardExtension: Oi.configure({
916
+ linkCardExtension: Ji.configure({
914
917
  lang: t.lang,
915
918
  messages: n(t.lang),
916
919
  resolver: t.linkCardResolver
917
920
  }),
918
- mediaExtensions: st({
919
- image: gi,
920
- video: xi,
921
+ mediaExtensions: ut({
922
+ image: Ii,
923
+ video: Vi,
921
924
  lang: t.lang,
922
925
  onImageUpload: t.onImageUpload,
923
926
  onVideoUpload: t.onVideoUpload,
@@ -927,12 +930,12 @@ function ki(t = {}) {
927
930
  }
928
931
  //#endregion
929
932
  //#region src/ui/codeblock/CodeBlockControls.tsx
930
- function Ai(e) {
931
- return e === "clipboard" ? /* @__PURE__ */ Q(ot, { children: [/* @__PURE__ */ Z("path", { d: "M9 4.5h6a1.5 1.5 0 0 1 1.5 1.5v11A1.5 1.5 0 0 1 15 18.5H7A1.5 1.5 0 0 1 5.5 17V6A1.5 1.5 0 0 1 7 4.5h2" }), /* @__PURE__ */ Z("path", { d: "M8.5 5.5v-1A1.5 1.5 0 0 1 10 3h2a1.5 1.5 0 0 1 1.5 1.5v1h-5Z" })] }) : e === "search" ? /* @__PURE__ */ Q(ot, { children: [/* @__PURE__ */ Z("circle", {
933
+ function Xi(e) {
934
+ return e === "clipboard" ? /* @__PURE__ */ Q(lt, { children: [/* @__PURE__ */ Z("path", { d: "M9 4.5h6a1.5 1.5 0 0 1 1.5 1.5v11A1.5 1.5 0 0 1 15 18.5H7A1.5 1.5 0 0 1 5.5 17V6A1.5 1.5 0 0 1 7 4.5h2" }), /* @__PURE__ */ Z("path", { d: "M8.5 5.5v-1A1.5 1.5 0 0 1 10 3h2a1.5 1.5 0 0 1 1.5 1.5v1h-5Z" })] }) : e === "search" ? /* @__PURE__ */ Q(lt, { children: [/* @__PURE__ */ Z("circle", {
932
935
  cx: "10",
933
936
  cy: "10",
934
937
  r: "5.5"
935
- }), /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })] }) : e === "check" ? /* @__PURE__ */ Z("path", { d: "m5 11 4 4 8-9" }) : e === "expand" ? /* @__PURE__ */ Q(ot, { children: [
938
+ }), /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })] }) : e === "check" ? /* @__PURE__ */ Z("path", { d: "m5 11 4 4 8-9" }) : e === "expand" ? /* @__PURE__ */ Q(lt, { children: [
936
939
  /* @__PURE__ */ Z("path", { d: "M8 4H4v4" }),
937
940
  /* @__PURE__ */ Z("path", { d: "M4 4l5 5" }),
938
941
  /* @__PURE__ */ Z("path", { d: "M16 4h4v4" }),
@@ -941,11 +944,11 @@ function Ai(e) {
941
944
  /* @__PURE__ */ Z("path", { d: "m4 20 5-5" }),
942
945
  /* @__PURE__ */ Z("path", { d: "M16 20h4v-4" }),
943
946
  /* @__PURE__ */ Z("path", { d: "m20 20-5-5" })
944
- ] }) : e === "download" ? /* @__PURE__ */ Q(ot, { children: [
947
+ ] }) : e === "download" ? /* @__PURE__ */ Q(lt, { children: [
945
948
  /* @__PURE__ */ Z("path", { d: "M12 4v10" }),
946
949
  /* @__PURE__ */ Z("path", { d: "m8 10 4 4 4-4" }),
947
950
  /* @__PURE__ */ Z("path", { d: "M5 19h14" })
948
- ] }) : e === "close" ? /* @__PURE__ */ Q(ot, { children: [/* @__PURE__ */ Z("path", { d: "M6 6l12 12" }), /* @__PURE__ */ Z("path", { d: "M18 6 6 18" })] }) : e === "zoomOut" ? /* @__PURE__ */ Q(ot, { children: [
951
+ ] }) : e === "close" ? /* @__PURE__ */ Q(lt, { children: [/* @__PURE__ */ Z("path", { d: "M6 6l12 12" }), /* @__PURE__ */ Z("path", { d: "M18 6 6 18" })] }) : e === "zoomOut" ? /* @__PURE__ */ Q(lt, { children: [
949
952
  /* @__PURE__ */ Z("circle", {
950
953
  cx: "10",
951
954
  cy: "10",
@@ -953,7 +956,7 @@ function Ai(e) {
953
956
  }),
954
957
  /* @__PURE__ */ Z("path", { d: "M7.5 10h5" }),
955
958
  /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })
956
- ] }) : e === "zoomIn" ? /* @__PURE__ */ Q(ot, { children: [
959
+ ] }) : e === "zoomIn" ? /* @__PURE__ */ Q(lt, { children: [
957
960
  /* @__PURE__ */ Z("circle", {
958
961
  cx: "10",
959
962
  cy: "10",
@@ -962,9 +965,9 @@ function Ai(e) {
962
965
  /* @__PURE__ */ Z("path", { d: "M7.5 10h5" }),
963
966
  /* @__PURE__ */ Z("path", { d: "M10 7.5v5" }),
964
967
  /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })
965
- ] }) : e === "reset" ? /* @__PURE__ */ Q(ot, { children: [/* @__PURE__ */ Z("path", { d: "M6.5 8.5A6 6 0 1 1 6 15" }), /* @__PURE__ */ Z("path", { d: "M6.5 8.5H3.5v-3" })] }) : /* @__PURE__ */ Z("path", { d: "m6 9 6 6 6-6" });
968
+ ] }) : e === "reset" ? /* @__PURE__ */ Q(lt, { children: [/* @__PURE__ */ Z("path", { d: "M6.5 8.5A6 6 0 1 1 6 15" }), /* @__PURE__ */ Z("path", { d: "M6.5 8.5H3.5v-3" })] }) : /* @__PURE__ */ Z("path", { d: "m6 9 6 6 6-6" });
966
969
  }
967
- function ji({ icon: e }) {
970
+ function Zi({ icon: e }) {
968
971
  return /* @__PURE__ */ Z("svg", {
969
972
  viewBox: "0 0 24 24",
970
973
  "aria-hidden": "true",
@@ -975,50 +978,50 @@ function ji({ icon: e }) {
975
978
  strokeLinecap: "round",
976
979
  strokeLinejoin: "round",
977
980
  strokeWidth: "1.8",
978
- children: Ai(e)
981
+ children: Xi(e)
979
982
  })
980
983
  });
981
984
  }
982
- function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, readOnly: i = !1 }) {
985
+ function Qi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, readOnly: i = !1 }) {
983
986
  let a = J(null), o = J(null), s = J(null), c = J(null), l = J(null), u = J({
984
987
  active: !1,
985
988
  lastX: 0,
986
989
  lastY: 0
987
- }), [d, f] = Y(null), [p, m] = Y(null), [h, g] = Y([]), [_, v] = Y(null), [y, b] = Y(!1), [x, S] = Y(""), [C, w] = Y(-1), [T, E] = Y(null), [D, O] = Y(!1), [k, A] = Y(null), [j, M] = Y(null), [ee, N] = Y(!1), [te, P] = Y(0), [ne, F] = Y(0), I = Ft(t), L = Bn(t, d), re = !i && e && I.active && I.pos !== null ? {
988
- ...I,
989
- pos: I.pos,
990
+ }), [d, f] = Y(null), [p, m] = Y(null), [h, g] = Y([]), [_, v] = Y(null), [y, b] = Y(!1), [x, S] = Y(""), [C, w] = Y(-1), [T, E] = Y(null), [D, O] = Y(!1), [k, A] = Y(null), [ee, j] = Y(null), [te, M] = Y(!1), [ne, N] = Y(0), [re, ie] = Y(0), P = zt(t), F = Wn(t, d), ae = !i && e && P.active && P.pos !== null ? {
991
+ ...P,
992
+ pos: P.pos,
990
993
  active: !0
991
- } : null, R = L ?? re, ie = R !== null, ae = R?.language === "mermaid", z = Gn(t, R), B = ie && R !== null && !z, oe = !i, se = Nn(R ? R.language : "text"), ce = T?.status ?? "idle", le = R?.mermaidPreviewMode ?? n, V = ae && le === "preview", ue = Un(t), H = `${ne}|${ue.map((e) => `${e.pos}:${e.mermaidPreviewMode}:${e.text.length}`).join("|")}`, U = q(() => Ln(x.trim().toLowerCase()), [x]);
992
- if (G(() => {
994
+ } : null, I = F ?? ae, oe = I !== null, L = I?.language === "mermaid", R = Yn(t, I), z = oe && I !== null && !R, B = !i, se = Ln(I ? I.language : "text"), ce = T?.status ?? "idle", le = I?.mermaidPreviewMode ?? n, ue = L && le === "preview", de = qn(t), V = `${re}|${de.map((e) => `${e.pos}:${e.mermaidPreviewMode}:${e.text.length}`).join("|")}`, H = q(() => Vn(x.trim().toLowerCase()), [x]);
995
+ if (K(() => {
993
996
  i && (b(!1), S(""), w(-1));
994
- }, [i]), G(() => {
997
+ }, [i]), K(() => {
995
998
  if (!T) return;
996
999
  let e = window.setTimeout(() => {
997
1000
  E(null);
998
- }, En);
1001
+ }, An);
999
1002
  return () => {
1000
1003
  window.clearTimeout(e);
1001
1004
  };
1002
- }, [T]), G(() => {
1003
- E(null), b(!1), S(""), w(-1), A(null), M(null), N(!1);
1005
+ }, [T]), K(() => {
1006
+ E(null), b(!1), S(""), w(-1), A(null), j(null), M(!1);
1004
1007
  }, [
1005
1008
  e,
1006
- R?.language,
1007
- R?.pos,
1008
- R?.text
1009
- ]), G(() => {
1009
+ I?.language,
1010
+ I?.pos,
1011
+ I?.text
1012
+ ]), K(() => {
1010
1013
  let e = ({ transaction: e }) => {
1011
- e.getMeta(Nt) && P((e) => e + 1);
1014
+ e.getMeta(Lt) && N((e) => e + 1);
1012
1015
  };
1013
1016
  return t.on("transaction", e), () => {
1014
1017
  t.off("transaction", e);
1015
1018
  };
1016
- }, [t]), G(() => {
1019
+ }, [t]), K(() => {
1017
1020
  let e = t.view.dom.closest(".markweave-editor-frame");
1018
1021
  if (!e) return;
1019
1022
  let n = (e) => {
1020
1023
  if (e.target instanceof Node && a.current?.contains(e.target) || y) return;
1021
- let n = Bn(t, zn(t, e.target)), r = n && !Gn(t, n) ? n.pos : null;
1024
+ let n = Wn(t, Un(t, e.target)), r = n && !Yn(t, n) ? n.pos : null;
1022
1025
  f((e) => e === r ? e : r);
1023
1026
  }, r = () => {
1024
1027
  y || f(null);
@@ -1026,20 +1029,20 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1026
1029
  return e.addEventListener("mousemove", n), e.addEventListener("mouseleave", r), () => {
1027
1030
  e.removeEventListener("mousemove", n), e.removeEventListener("mouseleave", r);
1028
1031
  };
1029
- }, [t, y]), G(() => {
1032
+ }, [t, y]), K(() => {
1030
1033
  y && s.current?.focus({ preventScroll: !0 });
1031
- }, [y]), K(() => {
1034
+ }, [y]), Le(() => {
1032
1035
  if (!y || C < 0) return;
1033
1036
  let e = c.current, t = e?.querySelector(`[data-language-index="${C}"]`);
1034
- e && t && Xn(e, t);
1037
+ e && t && er(e, t);
1035
1038
  }, [
1036
1039
  C,
1037
- U,
1040
+ H,
1038
1041
  y
1039
- ]), G(() => {
1042
+ ]), K(() => {
1040
1043
  if (!k) return;
1041
1044
  let e = (e) => {
1042
- e.key === "Escape" && (A(null), M(null), N(!1), u.current = {
1045
+ e.key === "Escape" && (A(null), j(null), M(!1), u.current = {
1043
1046
  active: !1,
1044
1047
  lastX: 0,
1045
1048
  lastY: 0
@@ -1048,8 +1051,8 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1048
1051
  return document.addEventListener("keydown", e), () => {
1049
1052
  document.removeEventListener("keydown", e);
1050
1053
  };
1051
- }, [t, k]), G(() => {
1052
- if (!ie || !y) return;
1054
+ }, [t, k]), K(() => {
1055
+ if (!oe || !y) return;
1053
1056
  let e = (e) => {
1054
1057
  e.key === "Escape" && (b(!1), w(-1), t.view.focus());
1055
1058
  }, n = (e) => {
@@ -1059,22 +1062,22 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1059
1062
  document.removeEventListener("keydown", e), document.removeEventListener("mousedown", n);
1060
1063
  };
1061
1064
  }, [
1062
- ie,
1065
+ oe,
1063
1066
  t,
1064
1067
  y
1065
- ]), K(() => {
1068
+ ]), Le(() => {
1066
1069
  let e = () => {
1067
1070
  let e = a.current;
1068
1071
  if (!e) return;
1069
- if (!Vn(e) || ue.length === 0) {
1072
+ if (!Gn(e) || de.length === 0) {
1070
1073
  g([]);
1071
1074
  return;
1072
1075
  }
1073
- let n = e.getBoundingClientRect(), r = ue.flatMap((e) => {
1074
- let r = In(Fn(t, e.pos, e.mermaidPreviewMode), n);
1075
- return r ? [jn(e, r, n)] : [];
1076
+ let n = e.getBoundingClientRect(), r = de.flatMap((e) => {
1077
+ let r = Bn(zn(t, e.pos, e.mermaidPreviewMode), n);
1078
+ return r ? [Fn(e, r, n)] : [];
1076
1079
  });
1077
- g((e) => Kn(e, r, ue.map((e) => e.pos)));
1080
+ g((e) => Xn(e, r, de.map((e) => e.pos)));
1078
1081
  };
1079
1082
  e();
1080
1083
  let n = window.requestAnimationFrame(e);
@@ -1082,26 +1085,26 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1082
1085
  window.cancelAnimationFrame(n), window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
1083
1086
  };
1084
1087
  }, [
1085
- te,
1088
+ ne,
1086
1089
  t,
1087
- H
1088
- ]), K(() => {
1089
- if (!B || !R) {
1090
+ V
1091
+ ]), Le(() => {
1092
+ if (!z || !I) {
1090
1093
  m(null), v(null);
1091
1094
  return;
1092
1095
  }
1093
1096
  let e = () => {
1094
1097
  let e = a.current;
1095
1098
  if (!e) return;
1096
- let n = Fn(t, R.pos, le), r = e.getBoundingClientRect(), i = In(n, r);
1099
+ let n = zn(t, I.pos, le), r = e.getBoundingClientRect(), i = Bn(n, r);
1097
1100
  if (!i) {
1098
- m((e) => e?.pos === R.pos ? e : null), v((e) => y ? e : null);
1101
+ m((e) => e?.pos === I.pos ? e : null), v((e) => y ? e : null);
1099
1102
  return;
1100
1103
  }
1101
- let s = kn(R.pos, i, r);
1104
+ let s = Nn(I.pos, i, r);
1102
1105
  if (m(s), y && o.current) {
1103
1106
  let e = o.current.getBoundingClientRect();
1104
- v(wn({
1107
+ v(On({
1105
1108
  overlayRect: r,
1106
1109
  buttonRect: e,
1107
1110
  windowWidth: window.innerWidth,
@@ -1113,101 +1116,101 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1113
1116
  window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
1114
1117
  };
1115
1118
  }, [
1116
- B,
1117
- te,
1118
- R?.pos,
1119
+ z,
1120
+ ne,
1121
+ I?.pos,
1119
1122
  t,
1120
1123
  y,
1121
1124
  le
1122
- ]), !B && ue.length === 0 && !k) return null;
1123
- let de = p ? {
1125
+ ]), !z && de.length === 0 && !k) return null;
1126
+ let fe = p ? {
1124
1127
  top: p.top,
1125
1128
  right: p.right
1126
- } : void 0, fe = async () => {
1129
+ } : void 0, U = async () => {
1127
1130
  if (i) {
1128
- if (!R) return;
1129
- let e = await Dn(R.text);
1130
- E(It(R, e ? "copied" : "failed"));
1131
+ if (!I) return;
1132
+ let e = await jn(I.text);
1133
+ E(Bt(I, e ? "copied" : "failed"));
1131
1134
  return;
1132
1135
  }
1133
- if (!Mn(t, R)) return;
1134
- let e = await Pt(t);
1135
- E(It(Ft(t), e ? "copied" : "failed")), t.view.focus();
1136
- }, pe = (e, n) => {
1136
+ if (!In(t, I)) return;
1137
+ let e = await Rt(t);
1138
+ E(Bt(zt(t), e ? "copied" : "failed")), t.view.focus();
1139
+ }, W = (e, n) => {
1137
1140
  if (i) {
1138
- Wt(t, e.pos, n) && F((e) => e + 1);
1141
+ Jt(t, e.pos, n) && ie((e) => e + 1);
1139
1142
  return;
1140
1143
  }
1141
- let a = I.active && I.pos === e.pos;
1142
- Bt(t, e.pos, n) && (r(n), F((e) => e + 1), a && t.view.focus());
1143
- }, me = (e) => {
1144
- if (i || !R) return;
1145
- let n = I.active && I.pos === R.pos;
1146
- zt(t, R.pos, e) && (e === "mermaid" && Bt(t, R.pos, "preview") && r("preview"), b(!1), S(""), w(-1), F((e) => e + 1), n && t.view.focus());
1147
- }, he = () => {
1144
+ let a = P.active && P.pos === e.pos;
1145
+ Wt(t, e.pos, n) && (r(n), ie((e) => e + 1), a && t.view.focus());
1146
+ }, pe = (e) => {
1147
+ if (i || !I) return;
1148
+ let n = P.active && P.pos === I.pos;
1149
+ Ut(t, I.pos, e) && (e === "mermaid" && Wt(t, I.pos, "preview") && r("preview"), b(!1), S(""), w(-1), ie((e) => e + 1), n && t.view.focus());
1150
+ }, me = () => {
1148
1151
  let e = !y;
1149
- e && l.current === null && (l.current = On()), w(e ? Hn(U, R?.language ?? null) : -1), b(e);
1152
+ e && l.current === null && (l.current = Mn()), w(e ? Kn(H, I?.language ?? null) : -1), b(e);
1153
+ }, he = (e) => {
1154
+ let t = Vn(e);
1155
+ S(e), w(Kn(t, e.trim() ? null : I?.language ?? null));
1150
1156
  }, ge = (e) => {
1151
- let t = Ln(e);
1152
- S(e), w(Hn(t, e.trim() ? null : R?.language ?? null));
1153
- }, _e = (e) => {
1154
1157
  if (!e.nativeEvent.isComposing) {
1155
1158
  if (e.key === "ArrowDown" || e.key === "ArrowUp") {
1156
- e.preventDefault(), w((t) => Jn(t, U.length, e.key === "ArrowUp" ? "previous" : "next"));
1159
+ e.preventDefault(), w((t) => Qn(t, H.length, e.key === "ArrowUp" ? "previous" : "next"));
1157
1160
  return;
1158
1161
  }
1159
1162
  if (e.key === "Enter") {
1160
- let t = U[C];
1161
- t && (e.preventDefault(), me(t.language));
1163
+ let t = H[C];
1164
+ t && (e.preventDefault(), pe(t.language));
1162
1165
  return;
1163
1166
  }
1164
1167
  e.key === "Escape" && (e.preventDefault(), b(!1), w(-1), t.view.focus());
1165
1168
  }
1166
- }, ve = U[C], ye = l.current && ve ? Rn(l.current, ve.language) : void 0, be = () => {
1167
- i || !R || Rt(t, R.pos, !z) && (P((e) => e + 1), f(null));
1168
- }, xe = () => {
1169
- if (!R) return;
1170
- let e = Wn(t, R.pos);
1171
- e && Cn({
1169
+ }, _e = H[C], ve = l.current && _e ? Hn(l.current, _e.language) : void 0, ye = () => {
1170
+ i || !I || Ht(t, I.pos, !R) && (N((e) => e + 1), f(null));
1171
+ }, be = () => {
1172
+ if (!I) return;
1173
+ let e = Jn(t, I.pos);
1174
+ e && Dn({
1172
1175
  data: new Blob([e], { type: "image/svg+xml" }),
1173
1176
  fileName: "markweave-mermaid.svg",
1174
1177
  onSettled: () => t.view.focus(),
1175
1178
  ownerDocument: document
1176
1179
  });
1177
- }, Se = () => {
1178
- if (!R) return;
1179
- let e = Wn(t, R.pos);
1180
- e && (A(An(e)), M(null), N(!1), u.current = {
1180
+ }, xe = () => {
1181
+ if (!I) return;
1182
+ let e = Jn(t, I.pos);
1183
+ e && (A(Pn(e)), j(null), M(!1), u.current = {
1181
1184
  active: !1,
1182
1185
  lastX: 0,
1183
1186
  lastY: 0
1184
1187
  });
1185
- }, Ce = () => {
1186
- A(null), M(null), N(!1), u.current = {
1188
+ }, Se = () => {
1189
+ A(null), j(null), M(!1), u.current = {
1187
1190
  active: !1,
1188
1191
  lastX: 0,
1189
1192
  lastY: 0
1190
1193
  }, t.view.focus();
1191
- }, we = (e) => {
1194
+ }, Ce = (e) => {
1192
1195
  A((t) => t && {
1193
1196
  ...t,
1194
- scale: Tn(t.scale + e)
1197
+ scale: kn(t.scale + e)
1195
1198
  });
1196
- }, Te = () => {
1197
- A((e) => e && An(e.svg)), u.current = {
1199
+ }, we = () => {
1200
+ A((e) => e && Pn(e.svg)), u.current = {
1198
1201
  active: !1,
1199
1202
  lastX: 0,
1200
1203
  lastY: 0
1201
- }, N(!1);
1204
+ }, M(!1);
1205
+ }, Te = (e) => {
1206
+ e.preventDefault(), Ce(e.deltaY < 0 ? Zn : -Zn);
1202
1207
  }, Ee = (e) => {
1203
- e.preventDefault(), we(e.deltaY < 0 ? qn : -qn);
1204
- }, De = (e) => {
1205
1208
  e.button === 0 && (e.preventDefault(), u.current = {
1206
1209
  active: !0,
1207
1210
  lastX: e.clientX,
1208
1211
  lastY: e.clientY
1209
- }, N(!0));
1210
- }, Oe = (e) => {
1212
+ }, M(!0));
1213
+ }, De = (e) => {
1211
1214
  let t = u.current;
1212
1215
  if (!t.active) return;
1213
1216
  let n = e.clientX - t.lastX, r = e.clientY - t.lastY;
@@ -1215,13 +1218,13 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1215
1218
  active: !0,
1216
1219
  lastX: e.clientX,
1217
1220
  lastY: e.clientY
1218
- }, A((e) => Yn(e, n, r));
1219
- }, ke = () => {
1221
+ }, A((e) => $n(e, n, r));
1222
+ }, Oe = () => {
1220
1223
  u.current = {
1221
1224
  active: !1,
1222
1225
  lastX: 0,
1223
1226
  lastY: 0
1224
- }, N(!1);
1227
+ }, M(!1);
1225
1228
  };
1226
1229
  return /* @__PURE__ */ Q("div", {
1227
1230
  ref: a,
@@ -1229,7 +1232,7 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1229
1232
  "data-testid": "markweave-codeblock-overlay",
1230
1233
  "data-read-only": i ? "true" : "false",
1231
1234
  children: [
1232
- ue.map((e) => {
1235
+ de.map((e) => {
1233
1236
  let t = h.find((t) => t.pos === e.pos);
1234
1237
  return /* @__PURE__ */ Z("div", {
1235
1238
  className: "markweave-mermaid-tabs",
@@ -1245,19 +1248,19 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1245
1248
  "data-testid": `markweave-mermaid-mode-${t}`,
1246
1249
  "data-active": e.mermaidPreviewMode === t,
1247
1250
  onMouseDown: (e) => e.preventDefault(),
1248
- onClick: () => pe(e, t),
1251
+ onClick: () => W(e, t),
1249
1252
  children: t === "code" ? "Code" : "Preview"
1250
1253
  }, t))
1251
1254
  }, e.pos);
1252
1255
  }),
1253
- B ? /* @__PURE__ */ Q("div", {
1256
+ z ? /* @__PURE__ */ Q("div", {
1254
1257
  className: "markweave-codeblock-controls",
1255
1258
  "data-testid": "markweave-codeblock-controls",
1256
1259
  "data-positioned": p ? "true" : "false",
1257
- "data-collapsed": z ? "true" : "false",
1260
+ "data-collapsed": R ? "true" : "false",
1258
1261
  "data-read-only": i ? "true" : "false",
1259
1262
  "aria-label": "Code block controls",
1260
- style: de,
1263
+ style: fe,
1261
1264
  children: [
1262
1265
  i ? /* @__PURE__ */ Z("span", {
1263
1266
  className: "markweave-codeblock-language-button markweave-codeblock-language-label",
@@ -1273,19 +1276,19 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1273
1276
  "aria-haspopup": "listbox",
1274
1277
  "data-testid": "markweave-codeblock-language",
1275
1278
  onMouseDown: (e) => e.preventDefault(),
1276
- onClick: he,
1277
- children: [/* @__PURE__ */ Z("span", { children: se }), /* @__PURE__ */ Z(ji, { icon: "chevron" })]
1279
+ onClick: me,
1280
+ children: [/* @__PURE__ */ Z("span", { children: se }), /* @__PURE__ */ Z(Zi, { icon: "chevron" })]
1278
1281
  }),
1279
- oe ? /* @__PURE__ */ Z("button", {
1282
+ B ? /* @__PURE__ */ Z("button", {
1280
1283
  type: "button",
1281
1284
  className: "markweave-codeblock-icon-button markweave-codeblock-collapse-button",
1282
- "aria-label": z ? "Expand code block" : "Collapse code block",
1283
- title: z ? "Expand code block" : "Collapse code block",
1285
+ "aria-label": R ? "Expand code block" : "Collapse code block",
1286
+ title: R ? "Expand code block" : "Collapse code block",
1284
1287
  "data-testid": "markweave-codeblock-collapse",
1285
- "data-collapsed": z ? "true" : "false",
1288
+ "data-collapsed": R ? "true" : "false",
1286
1289
  onMouseDown: (e) => e.preventDefault(),
1287
- onClick: be,
1288
- children: /* @__PURE__ */ Z(ji, { icon: "chevron" })
1290
+ onClick: ye,
1291
+ children: /* @__PURE__ */ Z(Zi, { icon: "chevron" })
1289
1292
  }) : null,
1290
1293
  /* @__PURE__ */ Q("span", {
1291
1294
  className: "markweave-codeblock-copy-wrap",
@@ -1300,8 +1303,8 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1300
1303
  onMouseLeave: () => O(!1),
1301
1304
  onFocus: () => O(!0),
1302
1305
  onBlur: () => O(!1),
1303
- onClick: fe,
1304
- children: /* @__PURE__ */ Z(ji, { icon: ce === "copied" ? "check" : "clipboard" })
1306
+ onClick: U,
1307
+ children: /* @__PURE__ */ Z(Zi, { icon: ce === "copied" ? "check" : "clipboard" })
1305
1308
  }), D ? /* @__PURE__ */ Z("span", {
1306
1309
  className: "markweave-codeblock-tooltip",
1307
1310
  role: "tooltip",
@@ -1309,7 +1312,7 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1309
1312
  children: "Copy to clipboard"
1310
1313
  }) : null]
1311
1314
  }),
1312
- ae && le === "preview" ? /* @__PURE__ */ Q("div", {
1315
+ L && le === "preview" ? /* @__PURE__ */ Q("div", {
1313
1316
  className: "markweave-mermaid-preview-actions",
1314
1317
  "data-testid": "markweave-mermaid-preview-actions",
1315
1318
  children: [/* @__PURE__ */ Z("button", {
@@ -1317,24 +1320,24 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1317
1320
  className: "markweave-codeblock-icon-button",
1318
1321
  "aria-label": "Fullscreen Mermaid preview",
1319
1322
  "data-testid": "markweave-mermaid-fullscreen",
1320
- disabled: !V,
1323
+ disabled: !ue,
1321
1324
  onMouseDown: (e) => e.preventDefault(),
1322
- onClick: Se,
1323
- children: /* @__PURE__ */ Z(ji, { icon: "expand" })
1325
+ onClick: xe,
1326
+ children: /* @__PURE__ */ Z(Zi, { icon: "expand" })
1324
1327
  }), /* @__PURE__ */ Z("button", {
1325
1328
  type: "button",
1326
1329
  className: "markweave-codeblock-icon-button",
1327
1330
  "aria-label": "Download Mermaid SVG",
1328
1331
  "data-testid": "markweave-mermaid-download",
1329
- disabled: !V,
1332
+ disabled: !ue,
1330
1333
  onMouseDown: (e) => e.preventDefault(),
1331
- onClick: xe,
1332
- children: /* @__PURE__ */ Z(ji, { icon: "download" })
1334
+ onClick: be,
1335
+ children: /* @__PURE__ */ Z(Zi, { icon: "download" })
1333
1336
  })]
1334
1337
  }) : null
1335
1338
  ]
1336
1339
  }) : null,
1337
- oe && B && y ? /* @__PURE__ */ Q("div", {
1340
+ B && z && y ? /* @__PURE__ */ Q("div", {
1338
1341
  className: "markweave-codeblock-language-menu",
1339
1342
  "data-testid": "markweave-codeblock-language-menu",
1340
1343
  "data-positioned": _ ? "true" : "false",
@@ -1350,24 +1353,24 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1350
1353
  "aria-autocomplete": "list",
1351
1354
  "aria-controls": l.current ?? void 0,
1352
1355
  "aria-expanded": "true",
1353
- "aria-activedescendant": ye,
1356
+ "aria-activedescendant": ve,
1354
1357
  "aria-label": "Search code block languages",
1355
1358
  value: x,
1356
1359
  placeholder: "Search...",
1357
1360
  "data-testid": "markweave-codeblock-language-search",
1358
- onChange: (e) => ge(e.target.value),
1359
- onKeyDown: _e
1360
- }), /* @__PURE__ */ Z(ji, { icon: "search" })]
1361
+ onChange: (e) => he(e.target.value),
1362
+ onKeyDown: ge
1363
+ }), /* @__PURE__ */ Z(Zi, { icon: "search" })]
1361
1364
  }), /* @__PURE__ */ Z("div", {
1362
1365
  ref: c,
1363
1366
  id: l.current ?? void 0,
1364
1367
  className: "markweave-codeblock-language-list",
1365
1368
  role: "listbox",
1366
1369
  "aria-label": "Code block languages",
1367
- children: U.map((e, t) => {
1368
- let n = e.language === R.language, r = t === C;
1370
+ children: H.map((e, t) => {
1371
+ let n = e.language === I.language, r = t === C;
1369
1372
  return /* @__PURE__ */ Q("button", {
1370
- id: l.current ? Rn(l.current, e.language) : void 0,
1373
+ id: l.current ? Hn(l.current, e.language) : void 0,
1371
1374
  type: "button",
1372
1375
  role: "option",
1373
1376
  "aria-selected": n,
@@ -1377,8 +1380,8 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1377
1380
  "data-language-index": t,
1378
1381
  onMouseDown: (e) => e.preventDefault(),
1379
1382
  onMouseEnter: () => w(t),
1380
- onClick: () => me(e.language),
1381
- children: [/* @__PURE__ */ Z("span", { children: e.label }), n ? /* @__PURE__ */ Z(ji, { icon: "check" }) : null]
1383
+ onClick: () => pe(e.language),
1384
+ children: [/* @__PURE__ */ Z("span", { children: e.label }), n ? /* @__PURE__ */ Z(Zi, { icon: "check" }) : null]
1382
1385
  }, e.language);
1383
1386
  })
1384
1387
  })]
@@ -1399,47 +1402,47 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1399
1402
  className: "markweave-mermaid-fullscreen-control",
1400
1403
  "aria-label": "Zoom out",
1401
1404
  "data-testid": "markweave-mermaid-fullscreen-zoom-out",
1402
- onMouseEnter: () => M("zoom-out"),
1403
- onMouseLeave: () => M(null),
1404
- onFocus: () => M("zoom-out"),
1405
- onBlur: () => M(null),
1406
- onClick: () => we(-qn),
1407
- children: /* @__PURE__ */ Z(ji, { icon: "zoomOut" })
1405
+ onMouseEnter: () => j("zoom-out"),
1406
+ onMouseLeave: () => j(null),
1407
+ onFocus: () => j("zoom-out"),
1408
+ onBlur: () => j(null),
1409
+ onClick: () => Ce(-Zn),
1410
+ children: /* @__PURE__ */ Z(Zi, { icon: "zoomOut" })
1408
1411
  }),
1409
1412
  /* @__PURE__ */ Z("span", {
1410
1413
  className: "markweave-mermaid-fullscreen-zoom-label",
1411
1414
  "data-testid": "markweave-mermaid-fullscreen-zoom-label",
1412
- children: Pn(k.scale)
1415
+ children: Rn(k.scale)
1413
1416
  }),
1414
1417
  /* @__PURE__ */ Z("button", {
1415
1418
  type: "button",
1416
1419
  className: "markweave-mermaid-fullscreen-control",
1417
1420
  "aria-label": "Zoom in",
1418
1421
  "data-testid": "markweave-mermaid-fullscreen-zoom-in",
1419
- onMouseEnter: () => M("zoom-in"),
1420
- onMouseLeave: () => M(null),
1421
- onFocus: () => M("zoom-in"),
1422
- onBlur: () => M(null),
1423
- onClick: () => we(qn),
1424
- children: /* @__PURE__ */ Z(ji, { icon: "zoomIn" })
1422
+ onMouseEnter: () => j("zoom-in"),
1423
+ onMouseLeave: () => j(null),
1424
+ onFocus: () => j("zoom-in"),
1425
+ onBlur: () => j(null),
1426
+ onClick: () => Ce(Zn),
1427
+ children: /* @__PURE__ */ Z(Zi, { icon: "zoomIn" })
1425
1428
  }),
1426
1429
  /* @__PURE__ */ Z("button", {
1427
1430
  type: "button",
1428
1431
  className: "markweave-mermaid-fullscreen-control",
1429
1432
  "aria-label": "Reset zoom",
1430
1433
  "data-testid": "markweave-mermaid-fullscreen-reset",
1431
- onMouseEnter: () => M("reset"),
1432
- onMouseLeave: () => M(null),
1433
- onFocus: () => M("reset"),
1434
- onBlur: () => M(null),
1435
- onClick: Te,
1436
- children: /* @__PURE__ */ Z(ji, { icon: "reset" })
1434
+ onMouseEnter: () => j("reset"),
1435
+ onMouseLeave: () => j(null),
1436
+ onFocus: () => j("reset"),
1437
+ onBlur: () => j(null),
1438
+ onClick: we,
1439
+ children: /* @__PURE__ */ Z(Zi, { icon: "reset" })
1437
1440
  }),
1438
- j ? /* @__PURE__ */ Z("span", {
1441
+ ee ? /* @__PURE__ */ Z("span", {
1439
1442
  className: "markweave-mermaid-fullscreen-tooltip",
1440
1443
  role: "tooltip",
1441
1444
  "data-testid": "markweave-mermaid-fullscreen-tooltip",
1442
- children: j === "zoom-out" ? "Zoom out" : j === "zoom-in" ? "Zoom in" : "Reset"
1445
+ children: ee === "zoom-out" ? "Zoom out" : ee === "zoom-in" ? "Zoom in" : "Reset"
1443
1446
  }) : null
1444
1447
  ]
1445
1448
  }),
@@ -1448,18 +1451,18 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1448
1451
  className: "markweave-mermaid-fullscreen-close",
1449
1452
  "aria-label": "Close fullscreen Mermaid preview",
1450
1453
  "data-testid": "markweave-mermaid-fullscreen-close",
1451
- onClick: Ce,
1452
- children: /* @__PURE__ */ Z(ji, { icon: "close" })
1454
+ onClick: Se,
1455
+ children: /* @__PURE__ */ Z(Zi, { icon: "close" })
1453
1456
  }),
1454
1457
  /* @__PURE__ */ Z("div", {
1455
1458
  className: "markweave-mermaid-fullscreen-viewport",
1456
1459
  "data-testid": "markweave-mermaid-fullscreen-viewport",
1457
- "data-dragging": ee ? "true" : "false",
1458
- onWheel: Ee,
1459
- onMouseDown: De,
1460
- onMouseMove: Oe,
1461
- onMouseUp: ke,
1462
- onMouseLeave: ke,
1460
+ "data-dragging": te ? "true" : "false",
1461
+ onWheel: Te,
1462
+ onMouseDown: Ee,
1463
+ onMouseMove: De,
1464
+ onMouseUp: Oe,
1465
+ onMouseLeave: Oe,
1463
1466
  children: /* @__PURE__ */ Z("div", {
1464
1467
  className: "markweave-mermaid-fullscreen-content",
1465
1468
  "data-testid": "markweave-mermaid-fullscreen-content",
@@ -1480,25 +1483,25 @@ function Mi({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1480
1483
  }
1481
1484
  //#endregion
1482
1485
  //#region src/ui/floating-toolbar/FloatingToolbar.tsx
1483
- var Ni = n("zh");
1484
- function Pi() {
1486
+ var $i = n("zh");
1487
+ function ea() {
1485
1488
  return typeof performance > "u" ? Date.now() : performance.now();
1486
1489
  }
1487
- function Fi(e, t) {
1490
+ function ta(e, t) {
1488
1491
  return {
1489
1492
  "--markweave-toolbar-motion-duration": `${e.motionDurationMs}ms`,
1490
1493
  "--markweave-toolbar-motion-easing": e.motionEasing,
1491
1494
  marginLeft: t === 0 ? void 0 : `${t}px`
1492
1495
  };
1493
1496
  }
1494
- function Ii(e, t) {
1497
+ function na(e, t) {
1495
1498
  let n = e?.getBoundingClientRect().height ?? 0, r = t?.getBoundingClientRect().height ?? 0;
1496
1499
  return Math.max(n, r, 44);
1497
1500
  }
1498
- function Li(e) {
1501
+ function ra(e) {
1499
1502
  if (e !== null) return { "--markweave-floating-toolbar-tooltip-left": `${e}px` };
1500
1503
  }
1501
- function Ri(e, t, n, r) {
1504
+ function ia(e, t, n, r) {
1502
1505
  let i = {
1503
1506
  bottom: t + r,
1504
1507
  height: r,
@@ -1514,26 +1517,26 @@ function Ri(e, t, n, r) {
1514
1517
  toJSON: () => i
1515
1518
  };
1516
1519
  }
1517
- function zi(e) {
1520
+ function aa(e) {
1518
1521
  return e.width > 0 && e.height > 0;
1519
1522
  }
1520
- function Bi(e) {
1523
+ function oa(e) {
1521
1524
  let t = Math.min(...e.map((e) => e.left)), n = Math.min(...e.map((e) => e.top)), r = Math.max(...e.map((e) => e.right)), i = Math.max(...e.map((e) => e.bottom));
1522
- return Ri(t, n, r - t, i - n);
1525
+ return ia(t, n, r - t, i - n);
1523
1526
  }
1524
- function Vi(e, t) {
1527
+ function sa(e, t) {
1525
1528
  let n = e.view.dom.ownerDocument.defaultView?.Node.ELEMENT_NODE ?? 1, r = (t) => t ? e.view.dom.contains(t.nodeType === n ? t : t.parentNode) : !1;
1526
1529
  return r(t.anchorNode) && r(t.focusNode);
1527
1530
  }
1528
- function Hi(e) {
1531
+ function ca(e) {
1529
1532
  if (typeof e.getClientRects != "function") return null;
1530
- let t = Array.from(e.getClientRects()).filter(zi).map((e) => Ri(e.left, e.top, e.width, e.height));
1533
+ let t = Array.from(e.getClientRects()).filter(aa).map((e) => ia(e.left, e.top, e.width, e.height));
1531
1534
  if (t.length > 0) return t;
1532
1535
  if (typeof e.getBoundingClientRect != "function") return null;
1533
1536
  let n = e.getBoundingClientRect();
1534
- return zi(n) ? [Ri(n.left, n.top, n.width, n.height)] : null;
1537
+ return aa(n) ? [ia(n.left, n.top, n.width, n.height)] : null;
1535
1538
  }
1536
- function Ui(e, t) {
1539
+ function la(e, t) {
1537
1540
  if (t.rangeCount === 0) return null;
1538
1541
  let n = t.getRangeAt(0);
1539
1542
  try {
@@ -1546,8 +1549,8 @@ function Ui(e, t) {
1546
1549
  return null;
1547
1550
  }
1548
1551
  }
1549
- function Wi(e, t) {
1550
- let n = Ui(e, t);
1552
+ function ua(e, t) {
1553
+ let n = la(e, t);
1551
1554
  if (!n) return !1;
1552
1555
  let { selection: r } = e.state, i = {
1553
1556
  from: Math.min(r.from, r.to),
@@ -1555,53 +1558,58 @@ function Wi(e, t) {
1555
1558
  };
1556
1559
  return n.from === i.from && n.to === i.to;
1557
1560
  }
1558
- function Gi(e) {
1561
+ function da(e) {
1559
1562
  let t = e.view.dom.ownerDocument.getSelection();
1560
- return !t || t.rangeCount === 0 || t.isCollapsed || !Vi(e, t) || !Wi(e, t) ? null : Hi(t.getRangeAt(0));
1563
+ return !t || t.rangeCount === 0 || t.isCollapsed || !sa(e, t) || !ua(e, t) ? null : ca(t.getRangeAt(0));
1561
1564
  }
1562
- function Ki(e) {
1565
+ function fa(e) {
1563
1566
  let { selection: t } = e.state;
1564
1567
  if (t.empty) return null;
1565
1568
  let n = Math.min(t.from, t.to), r = Math.max(t.from, t.to);
1566
1569
  try {
1567
1570
  let t = e.view.domAtPos(n), i = e.view.domAtPos(r), a = e.view.dom.ownerDocument.createRange();
1568
- return a.setStart(t.node, t.offset), a.setEnd(i.node, i.offset), Hi(a);
1571
+ return a.setStart(t.node, t.offset), a.setEnd(i.node, i.offset), ca(a);
1569
1572
  } catch {
1570
1573
  return null;
1571
1574
  }
1572
1575
  }
1573
- function qi(e) {
1576
+ function pa(e) {
1574
1577
  let { selection: t } = e.state;
1575
1578
  if (t.empty) return null;
1576
- let n = Math.min(t.from, t.to), r = Math.max(t.from, t.to), i = e.view.coordsAtPos(n), a = e.view.coordsAtPos(r, -1), o = Math.min(i.top, a.top), s = Math.max(i.bottom, a.bottom), c = Math.min(i.left, a.left), l = Ri(c, o, Math.max(i.right, a.right) - c, s - o);
1577
- return zi(l) ? [l] : null;
1579
+ let n = Math.min(t.from, t.to), r = Math.max(t.from, t.to), i = e.view.coordsAtPos(n), a = e.view.coordsAtPos(r, -1), o = Math.min(i.top, a.top), s = Math.max(i.bottom, a.bottom), c = Math.min(i.left, a.left), l = ia(c, o, Math.max(i.right, a.right) - c, s - o);
1580
+ return aa(l) ? [l] : null;
1578
1581
  }
1579
- function Ji(e) {
1580
- return Gi(e) ?? Ki(e) ?? qi(e);
1582
+ function ma(e) {
1583
+ return da(e) ?? fa(e) ?? pa(e);
1581
1584
  }
1582
- function Yi(e) {
1583
- let t = Ji(e);
1584
- return t && t.length > 0 ? Bi(t) : null;
1585
+ function ha(e) {
1586
+ let t = ma(e);
1587
+ return t && t.length > 0 ? oa(t) : null;
1585
1588
  }
1586
- function Xi(e) {
1589
+ function ga(e) {
1587
1590
  return {
1588
- getBoundingClientRect: () => Yi(e) ?? Ri(0, 0, 0, 0),
1589
- getClientRects: () => Ji(e) ?? []
1591
+ getBoundingClientRect: () => ha(e) ?? ia(0, 0, 0, 0),
1592
+ getClientRects: () => ma(e) ?? []
1590
1593
  };
1591
1594
  }
1592
- function Zi(e) {
1593
- return e === "block-type" || e === "link" || e === "color" || e === "more";
1595
+ function _a(e) {
1596
+ return e === "ask-ai" || e === "block-type" || e === "link" || e === "color" || e === "more";
1594
1597
  }
1595
- function Qi(e, t, n) {
1596
- n?.($n(e, t)), e.commands.focus();
1598
+ function va(e, t, n) {
1599
+ n?.(rr(e, t)), e.commands.focus();
1597
1600
  }
1598
- function $i({ editor: e, messages: t = Ni, selectionSnapshot: n, onRewriteSelection: r }) {
1599
- let i = q(() => ir(t), [t]), a = kt(n, { editable: e.isEditable }), [o, s] = Y(a), [c, l] = Y(null), [u, d] = Y(null), [f, p] = Y(null), [m, h] = Y(""), [g, _] = Y(""), [v, y] = Y(null), [b, x] = Y(0), [S, C] = Y(a.boundaryPadding), [w, T] = Y("bottom"), E = J(0), D = J(null), O = J(null), k = J(null), A = J(null), j = er(e, o.variant, t), M = or(j.find((e) => e.id === c) ?? null), ee = _r(m), N = W(() => {
1600
- let t = D.current, n = e.view.dom.closest(".markweave-editor-frame");
1601
+ var ya = "markweave-floating-toolbar";
1602
+ function ba({ editor: e, lang: t = "zh", messages: n = $i, selectionSnapshot: r, askAi: i, onRewriteSelection: a }) {
1603
+ let o = q(() => cr(n), [n]), s = Nt(r, { editable: e.isEditable }), [c, l] = Y(s), [u, d] = Y(null), [f, p] = Y(null), [m, h] = Y(null), [g, _] = Y("input"), [v, y] = Y(""), [b, x] = Y(""), [S, C] = Y(""), [w, T] = Y(""), [E, D] = Y(""), [O, k] = Y(""), [A, ee] = Y(null), [j, te] = Y(0), [M, ne] = Y(s.boundaryPadding), [N, re] = Y("bottom"), ie = J(0), P = J(null), F = J(null), ae = J(null), I = J(null), oe = J(null), L = J(null), R = J(null), z = J(null), B = J(null), se = J(""), ce = i?.enabled === !0 && typeof i.handler == "function", le = ir(e, c.variant, n, { askAiEnabled: ce }), ue = ur(le.find((e) => e.id === u) ?? null), de = Lr(E), V = G(() => {
1604
+ B.current !== null && (window.cancelAnimationFrame(B.current), B.current = null);
1605
+ }, []), H = G((t = !0) => {
1606
+ R.current?.abort(), R.current = null, z.current = null, V(), t && Mr(e), Er(e), h(null);
1607
+ }, [V, e]), fe = G(() => {
1608
+ let t = P.current, n = e.view.dom.closest(".markweave-editor-frame");
1601
1609
  if (!t || !(n instanceof HTMLElement)) return;
1602
- let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = Ii(t, O.current), s = E.current, c = wt({
1610
+ let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = na(t, F.current), o = ie.current, s = Ot({
1603
1611
  toolbarRect: {
1604
- left: r.left - s,
1612
+ left: r.left - o,
1605
1613
  top: r.top,
1606
1614
  width: r.width,
1607
1615
  height: r.height
@@ -1612,8 +1620,8 @@ function $i({ editor: e, messages: t = Ni, selectionSnapshot: n, onRewriteSelect
1612
1620
  width: i.width,
1613
1621
  height: i.height
1614
1622
  },
1615
- boundaryPadding: o.boundaryPadding
1616
- }), l = Et({
1623
+ boundaryPadding: c.boundaryPadding
1624
+ }), l = At({
1617
1625
  frameRect: {
1618
1626
  left: i.left,
1619
1627
  top: i.top,
@@ -1624,237 +1632,391 @@ function $i({ editor: e, messages: t = Ni, selectionSnapshot: n, onRewriteSelect
1624
1632
  width: r.width,
1625
1633
  height: a
1626
1634
  },
1627
- offset: o.offset,
1628
- boundaryPadding: o.boundaryPadding
1635
+ offset: c.offset,
1636
+ boundaryPadding: c.boundaryPadding
1629
1637
  });
1630
- t.style.marginLeft = c === 0 ? "" : `${c}px`, t.style.visibility = "visible", t.style.opacity = "1", E.current = c, x((e) => e === c ? e : c), C((e) => e === l ? e : l);
1638
+ t.style.marginLeft = s === 0 ? "" : `${s}px`, t.style.visibility = "visible", t.style.opacity = "1", ie.current = s, te((e) => e === s ? e : s), ne((e) => e === l ? e : l);
1631
1639
  }, [
1632
1640
  e.view.dom,
1633
- o.boundaryPadding,
1634
- o.offset
1635
- ]), te = W(() => {
1636
- D.current && (D.current.style.visibility = "hidden", D.current.style.opacity = "0");
1637
- }, []), P = W(() => {
1638
- N();
1639
- }, [N]), ne = W(() => Xi(e), [e]), F = W((e) => {
1640
- k.current = e;
1641
- }, []), I = W(() => {
1642
- let t = D.current, n = k.current, r = e.view.dom.closest(".markweave-editor-frame");
1643
- if (!f || !t || !n) return;
1644
- let i = t.getBoundingClientRect(), a = n.getBoundingClientRect(), s = r?.getBoundingClientRect() ?? null, c = Tt({
1641
+ c.boundaryPadding,
1642
+ c.offset
1643
+ ]), U = G(() => {
1644
+ P.current && (P.current.style.visibility = "hidden", P.current.style.opacity = "0");
1645
+ }, []), W = G(() => {
1646
+ fe();
1647
+ }, [fe]), pe = G(() => Ar(e)?.target.kind === "table" ? {
1648
+ getBoundingClientRect: () => {
1649
+ let t = jr(e);
1650
+ return t ? ia(t.left, t.top, t.width, t.height) : ia(0, 0, 0, 0);
1651
+ },
1652
+ getClientRects: () => {
1653
+ let t = jr(e);
1654
+ return t ? [ia(t.left, t.top, t.width, t.height)] : [];
1655
+ }
1656
+ } : ga(e), [e]), me = G((e) => {
1657
+ ae.current = e, e?.classList.contains("markweave-ask-ai-popover") && (e.dataset.positioned = "false");
1658
+ }, []), he = G(() => {
1659
+ let t = P.current, n = ae.current, r = e.view.dom.closest(".markweave-editor-frame");
1660
+ if (!m || !t || !n) return;
1661
+ let i = t.getBoundingClientRect(), a = n.getBoundingClientRect(), o = r?.getBoundingClientRect() ?? null;
1662
+ if (m === "ask-ai") {
1663
+ let t = jr(e), r = F.current?.getBoundingClientRect();
1664
+ if (!t || !r) return;
1665
+ let i = {
1666
+ anchorRect: r,
1667
+ selectionRect: t,
1668
+ viewport: {
1669
+ width: window.innerWidth,
1670
+ height: window.innerHeight
1671
+ },
1672
+ frameRect: o,
1673
+ surfaceRect: kr(e.view.dom),
1674
+ boundaryPadding: c.boundaryPadding
1675
+ }, s = Cr({
1676
+ ...i,
1677
+ panelSize: a
1678
+ }), l = `${s.width}px`;
1679
+ n.style.width !== l && (n.style.width = l, s = Cr({
1680
+ ...i,
1681
+ panelSize: n.getBoundingClientRect()
1682
+ })), n.style.left = `${s.left}px`, n.style.top = `${s.top}px`, n.style.bottom = "auto", n.style.maxWidth = `${s.maxWidth}px`, n.style.maxHeight = `${Math.max(0, s.maxHeight)}px`, n.dataset.positioned = "true", re((e) => e === s.placement ? e : s.placement);
1683
+ return;
1684
+ }
1685
+ let s = kt({
1645
1686
  toolbarRect: i,
1646
1687
  popoverSize: a,
1647
1688
  viewport: {
1648
1689
  width: window.innerWidth,
1649
1690
  height: window.innerHeight
1650
1691
  },
1651
- frameRect: s,
1652
- gap: f === "more" ? 8 : 6,
1653
- boundaryPadding: o.boundaryPadding
1692
+ frameRect: o,
1693
+ gap: m === "more" ? 8 : 6,
1694
+ boundaryPadding: c.boundaryPadding
1654
1695
  });
1655
- T((e) => e === c.placement ? e : c.placement);
1696
+ re((e) => e === s.placement ? e : s.placement);
1656
1697
  }, [
1657
- e.view.dom,
1658
- f,
1659
- o.boundaryPadding
1660
- ]), L = q(() => ({
1661
- ...Ot(o, { topBoundaryPadding: S }),
1662
- onShow: te,
1663
- onUpdate: P
1698
+ e,
1699
+ m,
1700
+ c.boundaryPadding
1701
+ ]), ge = q(() => ({
1702
+ ...Mt(c, { topBoundaryPadding: M }),
1703
+ onShow: U,
1704
+ onUpdate: W
1664
1705
  }), [
1665
- te,
1666
- P,
1667
- o,
1668
- S
1706
+ U,
1707
+ W,
1708
+ c,
1709
+ M
1669
1710
  ]);
1670
- G(() => {
1671
- let e = Pi();
1672
- s((t) => Mt(t, a, e));
1711
+ K(() => {
1712
+ let e = ea();
1713
+ l((t) => It(t, s, e));
1673
1714
  }, [
1674
- a.hiddenReason,
1675
- a.motionDurationMs,
1676
- a.motionEasing,
1677
- a.motionPhase,
1678
- a.offset,
1679
- a.boundaryPadding,
1680
- a.placement,
1681
- a.updateDelayMs,
1682
- a.variant,
1683
- a.visibility
1684
- ]), G(() => {
1685
- if (o.motionStartedAtMs === null || o.motionDurationMs <= 0) return;
1686
- let e = Math.max(0, o.motionStartedAtMs + o.motionDurationMs - Pi()), t = window.setTimeout(() => {
1687
- s((e) => St(e, Pi()));
1715
+ s.hiddenReason,
1716
+ s.motionDurationMs,
1717
+ s.motionEasing,
1718
+ s.motionPhase,
1719
+ s.offset,
1720
+ s.boundaryPadding,
1721
+ s.placement,
1722
+ s.updateDelayMs,
1723
+ s.variant,
1724
+ s.visibility
1725
+ ]), K(() => {
1726
+ if (c.motionStartedAtMs === null || c.motionDurationMs <= 0) return;
1727
+ let e = Math.max(0, c.motionStartedAtMs + c.motionDurationMs - ea()), t = window.setTimeout(() => {
1728
+ l((e) => Et(e, ea()));
1688
1729
  }, e);
1689
1730
  return () => {
1690
1731
  window.clearTimeout(t);
1691
1732
  };
1692
1733
  }, [
1693
- o.motionDurationMs,
1694
- o.motionPhase,
1695
- o.motionStartedAtMs
1696
- ]), K(() => {
1697
- if (o.visibility !== "visible") {
1698
- E.current = 0, D.current && (D.current.style.marginLeft = "", D.current.style.visibility = "hidden", D.current.style.opacity = "0"), x(0), C(o.boundaryPadding);
1734
+ c.motionDurationMs,
1735
+ c.motionPhase,
1736
+ c.motionStartedAtMs
1737
+ ]), Le(() => {
1738
+ if (c.visibility !== "visible") {
1739
+ ie.current = 0, P.current && (P.current.style.marginLeft = "", P.current.style.visibility = "hidden", P.current.style.opacity = "0"), te(0), ne(c.boundaryPadding);
1699
1740
  return;
1700
1741
  }
1701
- let e = mt(N);
1742
+ let e = vt(fe);
1702
1743
  return e.schedule(), window.addEventListener("resize", e.schedule), window.addEventListener("scroll", e.schedule, !0), () => {
1703
1744
  e.cancel(), window.removeEventListener("resize", e.schedule), window.removeEventListener("scroll", e.schedule, !0);
1704
1745
  };
1705
1746
  }, [
1706
- N,
1747
+ fe,
1707
1748
  e.view.dom,
1708
- f,
1709
- n?.from,
1710
- n?.to,
1711
- o.variant,
1712
- o.visibility,
1713
- j.length
1714
- ]), K(() => {
1715
- if (!f) return;
1716
- let e = mt(I);
1749
+ m,
1750
+ r?.from,
1751
+ r?.to,
1752
+ c.variant,
1753
+ c.visibility,
1754
+ le.length
1755
+ ]), Le(() => {
1756
+ if (!m) return;
1757
+ let e = vt(he);
1717
1758
  return e.schedule(), window.addEventListener("resize", e.schedule), window.addEventListener("scroll", e.schedule, !0), () => {
1718
1759
  e.cancel(), window.removeEventListener("resize", e.schedule), window.removeEventListener("scroll", e.schedule, !0);
1719
1760
  };
1720
- }, [f, I]), G(() => {
1721
- f === "more" && i.some((e) => e.id === c) || j.some((e) => e.id === c) || (l(null), d(null));
1722
1761
  }, [
1723
- i,
1724
- f,
1725
- c,
1726
- j
1727
- ]), G(() => {
1728
- if (!f) return;
1762
+ w,
1763
+ S,
1764
+ g,
1765
+ m,
1766
+ he
1767
+ ]), K(() => {
1768
+ m === "more" && o.some((e) => e.id === u) || le.some((e) => e.id === u) || (d(null), p(null));
1769
+ }, [
1770
+ o,
1771
+ m,
1772
+ u,
1773
+ le
1774
+ ]), K(() => {
1775
+ if (!m) return;
1729
1776
  let t = (e) => {
1730
- O.current?.contains(e.target) || p(null);
1777
+ F.current?.contains(e.target) || (m === "ask-ai" ? H(!0) : h(null));
1731
1778
  }, n = (t) => {
1732
- t.key === "Escape" && (t.preventDefault(), p(null), e.commands.focus());
1779
+ t.key === "Escape" && (t.preventDefault(), m === "ask-ai" ? g === "generating" ? (R.current?.abort(), V(), _("input")) : H(!0) : (h(null), e.commands.focus()));
1733
1780
  };
1734
1781
  return document.addEventListener("pointerdown", t, !0), document.addEventListener("keydown", n, !0), () => {
1735
1782
  document.removeEventListener("pointerdown", t, !0), document.removeEventListener("keydown", n, !0);
1736
1783
  };
1737
- }, [e, f]), G(() => {
1738
- if (f !== "link") return;
1784
+ }, [
1785
+ g,
1786
+ V,
1787
+ H,
1788
+ e,
1789
+ m
1790
+ ]), K(() => {
1791
+ let t = () => {
1792
+ let t = Ar(e);
1793
+ if (t?.target.kind === "table" && t.status === "target" && m !== "ask-ai") {
1794
+ L.current = t.selection, _("input"), y(""), C(""), T(""), x(""), l((e) => ({
1795
+ ...e,
1796
+ visibility: "visible",
1797
+ variant: "default",
1798
+ hiddenReason: null,
1799
+ motionPhase: "visible",
1800
+ motionStartedAtMs: null
1801
+ })), h("ask-ai");
1802
+ return;
1803
+ }
1804
+ m === "ask-ai" && t?.status === "conflict" && (R.current?.abort(), V(), _("conflict"));
1805
+ };
1806
+ return e.on("transaction", t), () => {
1807
+ e.off("transaction", t);
1808
+ };
1809
+ }, [
1810
+ V,
1811
+ e,
1812
+ m
1813
+ ]), K(() => () => {
1814
+ R.current?.abort(), V(), Er(e);
1815
+ }, [V, e]), K(() => {
1816
+ if (m !== "link" && m !== "ask-ai") return;
1739
1817
  let e = window.requestAnimationFrame(() => {
1740
- A.current?.focus(), A.current?.select();
1818
+ m === "ask-ai" ? oe.current?.focus() : (I.current?.focus(), I.current?.select());
1741
1819
  });
1742
1820
  return () => window.cancelAnimationFrame(e);
1743
- }, [f]);
1744
- let re = (t) => {
1745
- if (Zi(t.id)) {
1821
+ }, [m]), K(() => {
1822
+ m !== "ask-ai" || e.isDestroyed || e.view.dispatch(e.state.tr.setMeta(ya, "show").setMeta("addToHistory", !1));
1823
+ }, [e, m]);
1824
+ let _e = (t) => {
1825
+ if (_a(t.id)) {
1746
1826
  let n = t.id;
1827
+ if (m === n) {
1828
+ n === "ask-ai" ? H(!0) : h(null);
1829
+ return;
1830
+ }
1831
+ if (m === "ask-ai" && H(!1), n === "ask-ai") {
1832
+ if (!ce) return;
1833
+ let t = Ir(e);
1834
+ if (!t) return;
1835
+ L.current = t, _("input"), C(""), T(""), x("");
1836
+ }
1747
1837
  if (n === "link") {
1748
- let t = nr(e);
1749
- h(t), _(t), y({
1838
+ let t = or(e);
1839
+ D(t), k(t), ee({
1750
1840
  from: Math.min(e.state.selection.from, e.state.selection.to),
1751
1841
  to: Math.max(e.state.selection.from, e.state.selection.to)
1752
1842
  });
1753
1843
  }
1754
- p((e) => e === n ? null : n);
1844
+ h(n);
1755
1845
  return;
1756
1846
  }
1757
- if (p(null), t.id === "improve") {
1758
- Qi(e, "rewrite-selection", r);
1847
+ if (h(null), t.id === "improve") {
1848
+ va(e, "rewrite-selection", a);
1759
1849
  return;
1760
1850
  }
1761
1851
  t.run(), e.commands.focus();
1762
- }, R = () => {
1763
- p(null), e.commands.focus();
1764
- }, ie = () => {
1765
- v && e.commands.setTextSelection(v);
1766
- }, ae = () => {
1767
- ie(), Qn(e, m) && R();
1768
- }, z = () => {
1769
- if (ie(), fr(e)) {
1770
- h(""), _(""), R();
1852
+ }, ve = G(async (r) => {
1853
+ if (!ce || i?.enabled !== !0 || !L.current) return;
1854
+ let a = (r ?? v).trim();
1855
+ if (!a) {
1856
+ T(n.askAi.emptyPrompt), _("error");
1771
1857
  return;
1772
1858
  }
1773
- m.trim() && h("");
1774
- }, B = (e, t) => {
1775
- if (l(e), !e || !t || !O.current) {
1776
- d(null);
1859
+ let o = Or(e, L.current);
1860
+ if (!o) {
1861
+ _("conflict");
1777
1862
  return;
1778
1863
  }
1779
- let n = t.getBoundingClientRect(), r = O.current.getBoundingClientRect();
1780
- d(n.left + n.width / 2 - r.left);
1864
+ L.current = o, R.current?.abort(), V(), Tr(e);
1865
+ let s = new AbortController(), c = Dr(o, a, t, s.signal, void 0, Ar(e)?.target);
1866
+ R.current = s, z.current = c.id, x(a), T(""), C(""), _("generating");
1867
+ try {
1868
+ let t = await Nr(i.handler, c, (t) => {
1869
+ z.current !== c.id || s.signal.aborted || (se.current = t, B.current === null && (B.current = window.requestAnimationFrame(() => {
1870
+ B.current = null, Pr(e, se.current), C(se.current);
1871
+ })));
1872
+ });
1873
+ if (z.current !== c.id || s.signal.aborted) return;
1874
+ if (!Pr(e, t)) throw new xr("invalid-output", "Ask AI output is incompatible with the selected content.");
1875
+ V(), C(t), y(""), _(Ar(e)?.status === "target" ? "result" : "conflict");
1876
+ } catch (t) {
1877
+ if (z.current !== c.id) return;
1878
+ if (V(), s.signal.aborted) {
1879
+ Tr(e), _(Ar(e)?.status === "conflict" ? "conflict" : "input");
1880
+ return;
1881
+ }
1882
+ Tr(e), T(t instanceof xr ? t.code === "empty-result" ? n.askAi.emptyResult : n.askAi.errorFallback : t instanceof Error && t.message ? t.message : n.askAi.errorFallback), _("error");
1883
+ }
1884
+ }, [
1885
+ i,
1886
+ ce,
1887
+ v,
1888
+ V,
1889
+ e,
1890
+ t,
1891
+ n
1892
+ ]), ye = G(() => {
1893
+ if (!Sr(e, S)) {
1894
+ _(Ar(e)?.status === "conflict" ? "conflict" : "error"), T(n.askAi.errorFallback);
1895
+ return;
1896
+ }
1897
+ h(null), z.current = null, window.setTimeout(() => Er(e), 560), e.commands.focus();
1898
+ }, [
1899
+ S,
1900
+ e,
1901
+ n.askAi.errorFallback
1902
+ ]), be = () => {
1903
+ h(null), e.commands.focus();
1904
+ }, xe = () => {
1905
+ A && e.commands.setTextSelection(A);
1906
+ }, Se = () => {
1907
+ xe(), nr(e, E) && be();
1908
+ }, Ce = () => {
1909
+ if (xe(), gr(e)) {
1910
+ D(""), k(""), be();
1911
+ return;
1912
+ }
1913
+ E.trim() && D("");
1914
+ }, we = (e, t) => {
1915
+ if (d(e), !e || !t || !F.current) {
1916
+ p(null);
1917
+ return;
1918
+ }
1919
+ let n = t.getBoundingClientRect(), r = F.current.getBoundingClientRect();
1920
+ p(n.left + n.width / 2 - r.left);
1781
1921
  };
1782
- return /* @__PURE__ */ Z(Zn, {
1783
- ref: D,
1922
+ return /* @__PURE__ */ Z(tr, {
1923
+ ref: P,
1784
1924
  editor: e,
1785
- className: `markweave-floating-toolbar markweave-floating-toolbar--${o.variant} markweave-floating-toolbar--motion-${o.motionPhase}`,
1786
- "data-motion": o.motionPhase,
1787
- "data-position-strategy": L.strategy,
1788
- "data-boundary-padding": o.boundaryPadding,
1789
- "data-popover-placement": f ? w : void 0,
1925
+ pluginKey: ya,
1926
+ className: `markweave-floating-toolbar markweave-floating-toolbar--${c.variant} markweave-floating-toolbar--motion-${c.motionPhase}`,
1927
+ "data-motion": c.motionPhase,
1928
+ "data-position-strategy": ge.strategy,
1929
+ "data-boundary-padding": c.boundaryPadding,
1930
+ "data-popover-placement": m ? N : void 0,
1931
+ "data-ask-ai-session": m === "ask-ai" ? "open" : "closed",
1790
1932
  "data-testid": "markweave-floating-toolbar",
1791
- style: Fi(o, b),
1933
+ style: ta(c, j),
1792
1934
  updateDelay: 0,
1793
- getReferencedVirtualElement: ne,
1794
- options: L,
1795
- shouldShow: ({ editor: e }) => e.isEditable && jt(Dt(e)),
1935
+ getReferencedVirtualElement: pe,
1936
+ options: ge,
1937
+ shouldShow: ({ editor: e }) => {
1938
+ let t = Ar(e);
1939
+ return e.isEditable && (t?.target.kind === "table" && t.status === "target" || Ft(jt(e)));
1940
+ },
1796
1941
  children: /* @__PURE__ */ Q("div", {
1797
- ref: O,
1942
+ ref: F,
1798
1943
  className: "markweave-floating-toolbar-content",
1799
- "data-menu": f ?? "none",
1944
+ "data-menu": m ?? "none",
1800
1945
  children: [
1801
- j.map((e, t) => /* @__PURE__ */ Z(ta, {
1946
+ le.map((e, t) => /* @__PURE__ */ Z(Ca, {
1802
1947
  button: e,
1803
- expanded: f === e.id,
1804
- showDivider: t > 0 && j[t - 1].group !== e.group,
1805
- tooltipActive: c === e.id,
1806
- onPointerDown: dr,
1807
- onTooltipChange: B,
1808
- onRun: re
1948
+ expanded: m === e.id,
1949
+ showDivider: t > 0 && le[t - 1].group !== e.group,
1950
+ tooltipActive: u === e.id,
1951
+ onPointerDown: hr,
1952
+ onTooltipChange: we,
1953
+ onRun: _e
1809
1954
  }, e.id)),
1810
- f === "block-type" ? /* @__PURE__ */ Z(ra, {
1955
+ m === "block-type" ? /* @__PURE__ */ Z(Ta, {
1811
1956
  editor: e,
1812
- messages: t,
1813
- onPopoverRef: F,
1814
- onClose: () => p(null)
1957
+ messages: n,
1958
+ onPopoverRef: me,
1959
+ onClose: () => h(null)
1960
+ }) : null,
1961
+ m === "ask-ai" ? /* @__PURE__ */ Z(Sa, {
1962
+ inputRef: oe,
1963
+ messages: n,
1964
+ phase: g,
1965
+ prompt: v,
1966
+ hasStreamedContent: !!S,
1967
+ error: w,
1968
+ onPromptChange: y,
1969
+ onSubmit: ve,
1970
+ onStop: () => {
1971
+ R.current?.abort(), V(), Tr(e), _("input");
1972
+ },
1973
+ onAccept: ye,
1974
+ onRetry: () => ve(b),
1975
+ onDiscard: () => H(!0),
1976
+ onPopoverRef: me
1815
1977
  }) : null,
1816
- f === "link" ? /* @__PURE__ */ Z(ea, {
1817
- inputRef: A,
1818
- messages: t,
1819
- value: m,
1820
- canApply: !!ee,
1821
- canOpen: !!ee,
1822
- canRemove: !!(g || m.trim()),
1823
- onValueChange: h,
1824
- onApply: ae,
1825
- onOpen: () => ur(m),
1826
- onRemove: z,
1827
- onPopoverRef: F
1978
+ m === "link" ? /* @__PURE__ */ Z(xa, {
1979
+ inputRef: I,
1980
+ messages: n,
1981
+ value: E,
1982
+ canApply: !!de,
1983
+ canOpen: !!de,
1984
+ canRemove: !!(O || E.trim()),
1985
+ onValueChange: D,
1986
+ onApply: Se,
1987
+ onOpen: () => mr(E),
1988
+ onRemove: Ce,
1989
+ onPopoverRef: me
1828
1990
  }) : null,
1829
- f === "color" ? /* @__PURE__ */ Z(aa, {
1991
+ m === "color" ? /* @__PURE__ */ Z(Da, {
1830
1992
  editor: e,
1831
- messages: t,
1832
- onPopoverRef: F,
1833
- onClose: () => p(null)
1993
+ messages: n,
1994
+ onPopoverRef: me,
1995
+ onClose: () => h(null)
1834
1996
  }) : null,
1835
- f === "more" ? /* @__PURE__ */ Z(sa, {
1997
+ m === "more" ? /* @__PURE__ */ Z(ka, {
1836
1998
  editor: e,
1837
- messages: t,
1838
- activeTooltipId: c,
1839
- onPopoverRef: F,
1840
- onTooltipChange: l,
1841
- onClose: () => p(null)
1999
+ messages: n,
2000
+ activeTooltipId: u,
2001
+ onPopoverRef: me,
2002
+ onTooltipChange: d,
2003
+ onClose: () => h(null)
1842
2004
  }) : null,
1843
- M && f === null ? /* @__PURE__ */ Z("div", {
2005
+ ue && m === null ? /* @__PURE__ */ Z("div", {
1844
2006
  className: "markweave-floating-toolbar-tooltip",
1845
2007
  role: "tooltip",
1846
2008
  "data-testid": "markweave-floating-toolbar-tooltip",
1847
- "data-button-id": M.buttonId,
1848
- "data-active": M.active,
1849
- style: Li(u),
1850
- children: M.label
2009
+ "data-button-id": ue.buttonId,
2010
+ "data-active": ue.active,
2011
+ style: ra(f),
2012
+ children: ue.label
1851
2013
  }) : null
1852
2014
  ]
1853
2015
  })
1854
2016
  });
1855
2017
  }
1856
- function ea({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRemove: a, onValueChange: o, onApply: s, onOpen: c, onRemove: l, onPopoverRef: u }) {
1857
- let d = rr(t);
2018
+ function xa({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRemove: a, onValueChange: o, onApply: s, onOpen: c, onRemove: l, onPopoverRef: u }) {
2019
+ let d = sr(t);
1858
2020
  return /* @__PURE__ */ Q("form", {
1859
2021
  ref: u,
1860
2022
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-link-popover",
@@ -1877,7 +2039,7 @@ function ea({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1877
2039
  "aria-label": d.applyLink,
1878
2040
  "data-testid": "markweave-floating-toolbar-link-apply",
1879
2041
  disabled: !r,
1880
- onMouseDown: dr,
2042
+ onMouseDown: hr,
1881
2043
  children: /* @__PURE__ */ Z($, { name: "corner-down-left" })
1882
2044
  }),
1883
2045
  /* @__PURE__ */ Z("span", {
@@ -1889,7 +2051,7 @@ function ea({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1889
2051
  "aria-label": d.openLink,
1890
2052
  "data-testid": "markweave-floating-toolbar-link-open",
1891
2053
  disabled: !i,
1892
- onMouseDown: dr,
2054
+ onMouseDown: hr,
1893
2055
  onClick: c,
1894
2056
  children: /* @__PURE__ */ Z($, { name: "external-link" })
1895
2057
  }),
@@ -1898,7 +2060,7 @@ function ea({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1898
2060
  "aria-label": d.removeLink,
1899
2061
  "data-testid": "markweave-floating-toolbar-link-remove",
1900
2062
  disabled: !a,
1901
- onMouseDown: dr,
2063
+ onMouseDown: hr,
1902
2064
  onClick: l,
1903
2065
  children: /* @__PURE__ */ Z($, { name: "trash" })
1904
2066
  })
@@ -1906,15 +2068,125 @@ function ea({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1906
2068
  })]
1907
2069
  });
1908
2070
  }
1909
- function ta({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointerDown: i, onTooltipChange: a, onRun: o }) {
1910
- return /* @__PURE__ */ Q(ot, { children: [n ? /* @__PURE__ */ Z("span", {
2071
+ function Sa({ inputRef: e, messages: t, phase: n, prompt: r, hasStreamedContent: i, error: a, onPromptChange: o, onSubmit: s, onStop: c, onAccept: l, onRetry: u, onDiscard: d, onPopoverRef: f }) {
2072
+ let p = n === "input" || n === "result" || n === "error";
2073
+ return /* @__PURE__ */ Q("section", {
2074
+ ref: f,
2075
+ className: "markweave-floating-toolbar-popover markweave-ask-ai-popover",
2076
+ "aria-label": t.askAi.ariaLabel,
2077
+ "data-phase": n,
2078
+ "data-testid": "markweave-ask-ai-popover",
2079
+ children: [
2080
+ p ? /* @__PURE__ */ Q("div", {
2081
+ className: "markweave-ask-ai-composer",
2082
+ "data-variant": n === "result" ? "follow-up" : "prompt",
2083
+ children: [/* @__PURE__ */ Z("textarea", {
2084
+ ref: e,
2085
+ className: "markweave-ask-ai-input",
2086
+ "aria-label": n === "result" ? t.askAi.followUpPlaceholder : t.askAi.promptPlaceholder,
2087
+ placeholder: n === "result" ? t.askAi.followUpPlaceholder : t.askAi.promptPlaceholder,
2088
+ value: r,
2089
+ rows: 2,
2090
+ onChange: (e) => o(e.currentTarget.value),
2091
+ onKeyDown: (e) => {
2092
+ e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), s());
2093
+ }
2094
+ }), /* @__PURE__ */ Z("button", {
2095
+ type: "button",
2096
+ className: "markweave-ask-ai-send",
2097
+ "aria-label": t.askAi.send,
2098
+ disabled: !r.trim(),
2099
+ onMouseDown: hr,
2100
+ onClick: () => s(),
2101
+ children: /* @__PURE__ */ Z($, { name: "arrow-up" })
2102
+ })]
2103
+ }) : null,
2104
+ n === "generating" ? /* @__PURE__ */ Q("div", {
2105
+ className: "markweave-ask-ai-progress markweave-ask-ai-generating",
2106
+ role: "status",
2107
+ children: [
2108
+ /* @__PURE__ */ Z("span", {
2109
+ className: "markweave-ask-ai-sparkles",
2110
+ "aria-hidden": "true",
2111
+ children: /* @__PURE__ */ Z($, { name: "sparkles" })
2112
+ }),
2113
+ /* @__PURE__ */ Z("span", {
2114
+ className: "markweave-ask-ai-progress-label",
2115
+ children: i ? t.askAi.streaming : t.askAi.generating
2116
+ }),
2117
+ /* @__PURE__ */ Z("button", {
2118
+ type: "button",
2119
+ className: "markweave-ask-ai-stop",
2120
+ "aria-label": t.askAi.stop,
2121
+ onMouseDown: hr,
2122
+ onClick: c,
2123
+ children: /* @__PURE__ */ Z($, { name: "square" })
2124
+ })
2125
+ ]
2126
+ }) : null,
2127
+ n === "result" ? /* @__PURE__ */ Q("div", {
2128
+ className: "markweave-ask-ai-action-bar",
2129
+ children: [
2130
+ /* @__PURE__ */ Q("button", {
2131
+ type: "button",
2132
+ className: "markweave-ask-ai-retry",
2133
+ onMouseDown: hr,
2134
+ onClick: u,
2135
+ children: [/* @__PURE__ */ Z($, { name: "rotate-ccw" }), t.askAi.retry]
2136
+ }),
2137
+ /* @__PURE__ */ Z("span", { className: "markweave-ask-ai-action-spacer" }),
2138
+ /* @__PURE__ */ Q("button", {
2139
+ type: "button",
2140
+ className: "markweave-ask-ai-discard",
2141
+ onMouseDown: hr,
2142
+ onClick: d,
2143
+ children: [/* @__PURE__ */ Z($, { name: "x" }), t.askAi.discard]
2144
+ }),
2145
+ /* @__PURE__ */ Q("button", {
2146
+ type: "button",
2147
+ className: "markweave-ask-ai-accept",
2148
+ onMouseDown: hr,
2149
+ onClick: l,
2150
+ children: [/* @__PURE__ */ Z($, { name: "check" }), t.askAi.accept]
2151
+ })
2152
+ ]
2153
+ }) : null,
2154
+ n === "error" || n === "conflict" ? /* @__PURE__ */ Q("div", {
2155
+ className: "markweave-ask-ai-error",
2156
+ role: "alert",
2157
+ children: [n === "conflict" ? t.askAi.conflict : a || t.askAi.errorFallback, /* @__PURE__ */ Q("div", {
2158
+ className: "markweave-ask-ai-action-bar",
2159
+ children: [
2160
+ n === "error" ? /* @__PURE__ */ Q("button", {
2161
+ type: "button",
2162
+ className: "markweave-ask-ai-retry",
2163
+ onMouseDown: hr,
2164
+ onClick: u,
2165
+ children: [/* @__PURE__ */ Z($, { name: "rotate-ccw" }), t.askAi.retry]
2166
+ }) : null,
2167
+ /* @__PURE__ */ Z("span", { className: "markweave-ask-ai-action-spacer" }),
2168
+ /* @__PURE__ */ Q("button", {
2169
+ type: "button",
2170
+ className: "markweave-ask-ai-discard",
2171
+ onMouseDown: hr,
2172
+ onClick: d,
2173
+ children: [/* @__PURE__ */ Z($, { name: "x" }), t.askAi.discard]
2174
+ })
2175
+ ]
2176
+ })]
2177
+ }) : null
2178
+ ]
2179
+ });
2180
+ }
2181
+ function Ca({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointerDown: i, onTooltipChange: a, onRun: o }) {
2182
+ return /* @__PURE__ */ Q(lt, { children: [n ? /* @__PURE__ */ Z("span", {
1911
2183
  className: "markweave-floating-toolbar-divider",
1912
2184
  "aria-hidden": "true"
1913
2185
  }) : null, /* @__PURE__ */ Z("button", {
1914
2186
  type: "button",
1915
2187
  className: `markweave-floating-toolbar-button markweave-floating-toolbar-button--${e.id}`,
1916
2188
  "aria-label": e.label,
1917
- "aria-expanded": Zi(e.id) ? t : void 0,
2189
+ "aria-expanded": _a(e.id) ? t : void 0,
1918
2190
  "data-active": e.active || t,
1919
2191
  "data-tooltip-active": r ? "true" : "false",
1920
2192
  "data-testid": `markweave-floating-toolbar-button-${e.id}`,
@@ -1924,14 +2196,14 @@ function ta({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointe
1924
2196
  onMouseEnter: (t) => a(e.id, t.currentTarget),
1925
2197
  onMouseLeave: () => a(null),
1926
2198
  onClick: () => o(e),
1927
- children: /* @__PURE__ */ Z(na, {
2199
+ children: /* @__PURE__ */ Z(wa, {
1928
2200
  button: e,
1929
2201
  expanded: t
1930
2202
  })
1931
2203
  })] });
1932
2204
  }
1933
- function na({ button: e, expanded: t }) {
1934
- return e.id === "improve" ? /* @__PURE__ */ Q("span", {
2205
+ function wa({ button: e, expanded: t }) {
2206
+ return e.id === "improve" || e.id === "ask-ai" ? /* @__PURE__ */ Q("span", {
1935
2207
  className: "markweave-floating-toolbar-button-inner",
1936
2208
  children: [/* @__PURE__ */ Z($, { name: "sparkles" }), /* @__PURE__ */ Z("span", { children: e.glyph })]
1937
2209
  }) : e.id === "block-type" ? /* @__PURE__ */ Q("span", {
@@ -1948,8 +2220,8 @@ function na({ button: e, expanded: t }) {
1948
2220
  }), /* @__PURE__ */ Z($, { name: t ? "chevron-up" : "chevron-down" })]
1949
2221
  }) : /* @__PURE__ */ Z($, { name: "more" });
1950
2222
  }
1951
- function ra({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
1952
- let i = rr(t), a = sr(t);
2223
+ function Ta({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
2224
+ let i = sr(t), a = dr(t);
1953
2225
  return /* @__PURE__ */ Q("div", {
1954
2226
  ref: n,
1955
2227
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-turn-menu",
@@ -1959,48 +2231,48 @@ function ra({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
1959
2231
  children: i.turnIntoTitle
1960
2232
  }), a.map((t) => /* @__PURE__ */ Q("button", {
1961
2233
  type: "button",
1962
- "data-active": lr(e, t.id),
2234
+ "data-active": pr(e, t.id),
1963
2235
  "data-testid": `markweave-floating-toolbar-turn-${t.id}`,
1964
- onMouseDown: dr,
2236
+ onMouseDown: hr,
1965
2237
  onClick: () => {
1966
- gr(e, t.id), r();
2238
+ br(e, t.id), r();
1967
2239
  },
1968
2240
  children: [/* @__PURE__ */ Z("span", {
1969
2241
  className: "markweave-floating-toolbar-menu-icon",
1970
- children: /* @__PURE__ */ Z(ia, { option: t })
2242
+ children: /* @__PURE__ */ Z(Ea, { option: t })
1971
2243
  }), /* @__PURE__ */ Z("span", { children: t.label })]
1972
2244
  }, t.id))]
1973
2245
  });
1974
2246
  }
1975
- function ia({ option: e }) {
2247
+ function Ea({ option: e }) {
1976
2248
  return e.id === "paragraph" ? /* @__PURE__ */ Z($, { name: "text" }) : e.glyph === "bullet-list" || e.glyph === "numbered-list" || e.glyph === "todo-list" || e.glyph === "quote" || e.glyph === "code-block" ? /* @__PURE__ */ Z($, { name: e.glyph }) : /* @__PURE__ */ Z("span", { children: e.glyph });
1977
2249
  }
1978
- function aa({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
1979
- let i = rr(t), a = e.getAttributes("textStyle").color, o = e.getAttributes("highlight").color;
2250
+ function Da({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
2251
+ let i = sr(t), a = e.getAttributes("textStyle").color, o = e.getAttributes("highlight").color;
1980
2252
  return /* @__PURE__ */ Q("div", {
1981
2253
  ref: n,
1982
2254
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-color-popover",
1983
2255
  "data-testid": "markweave-floating-toolbar-color-menu",
1984
- children: [/* @__PURE__ */ Z(oa, {
2256
+ children: [/* @__PURE__ */ Z(Oa, {
1985
2257
  title: i.textColorTitle,
1986
2258
  mode: "text",
1987
2259
  activeColor: a ?? null,
1988
- options: ar(t),
2260
+ options: lr(t),
1989
2261
  onSelect: (t) => {
1990
- hr(e, t), r();
2262
+ yr(e, t), r();
1991
2263
  }
1992
- }), /* @__PURE__ */ Z(oa, {
2264
+ }), /* @__PURE__ */ Z(Oa, {
1993
2265
  title: i.highlightColorTitle,
1994
2266
  mode: "highlight",
1995
2267
  activeColor: o ?? null,
1996
- options: tr(t),
2268
+ options: ar(t),
1997
2269
  onSelect: (t) => {
1998
- mr(e, t), r();
2270
+ vr(e, t), r();
1999
2271
  }
2000
2272
  })]
2001
2273
  });
2002
2274
  }
2003
- function oa({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
2275
+ function Oa({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
2004
2276
  return /* @__PURE__ */ Q("section", {
2005
2277
  className: "markweave-floating-toolbar-color-section",
2006
2278
  "aria-label": e,
@@ -2014,7 +2286,7 @@ function oa({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
2014
2286
  "aria-label": e.label,
2015
2287
  "data-active": e.value === n || e.value === null && !n,
2016
2288
  "data-testid": `markweave-floating-toolbar-${t}-${e.id}`,
2017
- onMouseDown: dr,
2289
+ onMouseDown: hr,
2018
2290
  onClick: () => i(e.value),
2019
2291
  children: t === "text" ? /* @__PURE__ */ Z("span", {
2020
2292
  className: "markweave-floating-toolbar-text-swatch",
@@ -2029,26 +2301,26 @@ function oa({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
2029
2301
  })]
2030
2302
  });
2031
2303
  }
2032
- function sa({ editor: e, messages: t, activeTooltipId: n, onPopoverRef: r, onTooltipChange: i, onClose: a }) {
2033
- let o = ir(t);
2304
+ function ka({ editor: e, messages: t, activeTooltipId: n, onPopoverRef: r, onTooltipChange: i, onClose: a }) {
2305
+ let o = cr(t);
2034
2306
  return /* @__PURE__ */ Z("div", {
2035
2307
  ref: r,
2036
2308
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-more-menu",
2037
2309
  "data-testid": "markweave-floating-toolbar-more-menu",
2038
- children: o.map((t, r) => /* @__PURE__ */ Z(ca, {
2310
+ children: o.map((t, r) => /* @__PURE__ */ Z(Aa, {
2039
2311
  action: t,
2040
- active: cr(e, t.id),
2312
+ active: fr(e, t.id),
2041
2313
  tooltipActive: n === t.id,
2042
2314
  showDivider: r > 0 && o[r - 1].group !== t.group,
2043
2315
  onTooltipChange: i,
2044
2316
  onRun: () => {
2045
- pr(e, t.id), a();
2317
+ _r(e, t.id), a();
2046
2318
  }
2047
2319
  }, t.id))
2048
2320
  });
2049
2321
  }
2050
- function ca({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipChange: i, onRun: a }) {
2051
- return /* @__PURE__ */ Q(ot, { children: [r ? /* @__PURE__ */ Z("span", {
2322
+ function Aa({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipChange: i, onRun: a }) {
2323
+ return /* @__PURE__ */ Q(lt, { children: [r ? /* @__PURE__ */ Z("span", {
2052
2324
  className: "markweave-floating-toolbar-divider",
2053
2325
  "aria-hidden": "true"
2054
2326
  }) : null, /* @__PURE__ */ Q("span", {
@@ -2059,11 +2331,11 @@ function ca({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipC
2059
2331
  "data-active": t,
2060
2332
  "data-tooltip-active": n ? "true" : "false",
2061
2333
  "data-testid": `markweave-floating-toolbar-more-${e.id}`,
2062
- onMouseDown: dr,
2334
+ onMouseDown: hr,
2063
2335
  onMouseEnter: () => i(e.id),
2064
2336
  onMouseLeave: () => i(null),
2065
2337
  onClick: a,
2066
- children: /* @__PURE__ */ Z(la, { id: e.id })
2338
+ children: /* @__PURE__ */ Z(ja, { id: e.id })
2067
2339
  }), n ? /* @__PURE__ */ Z("div", {
2068
2340
  className: "markweave-floating-toolbar-tooltip markweave-floating-toolbar-tooltip--more",
2069
2341
  role: "tooltip",
@@ -2071,41 +2343,46 @@ function ca({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipC
2071
2343
  }) : null]
2072
2344
  })] });
2073
2345
  }
2074
- function la({ id: e }) {
2346
+ function ja({ id: e }) {
2075
2347
  return e === "superscript" ? /* @__PURE__ */ Z($, { name: "superscript" }) : e === "subscript" ? /* @__PURE__ */ Z($, { name: "subscript" }) : e === "inline-math" ? /* @__PURE__ */ Z($, { name: "math" }) : Z($, { name: e });
2076
2348
  }
2077
- var ua = {
2349
+ var Ma = {
2078
2350
  sparkles: xe,
2079
- "chevron-down": j,
2080
- "chevron-up": ee,
2081
- "corner-down-left": ne,
2082
- "external-link": I,
2351
+ "arrow-up": b,
2352
+ check: k,
2353
+ "chevron-down": ee,
2354
+ "chevron-up": te,
2355
+ "corner-down-left": re,
2356
+ "external-link": P,
2083
2357
  bold: E,
2084
2358
  italic: ce,
2085
- underline: Me,
2086
- strike: Ce,
2087
- "inline-code": te,
2088
- link: V,
2089
- more: fe,
2090
- text: je,
2091
- "bullet-list": ue,
2092
- "numbered-list": U,
2093
- "todo-list": H,
2094
- quote: _e,
2359
+ underline: Ne,
2360
+ strike: we,
2361
+ "inline-code": ne,
2362
+ link: ue,
2363
+ more: U,
2364
+ text: Me,
2365
+ "bullet-list": de,
2366
+ "numbered-list": H,
2367
+ "todo-list": V,
2368
+ quote: ge,
2095
2369
  "code-block": D,
2096
- superscript: Te,
2097
- subscript: we,
2370
+ superscript: Ee,
2371
+ subscript: Te,
2098
2372
  math: ye,
2099
2373
  "align-left": d,
2100
2374
  "align-center": l,
2101
2375
  "align-right": f,
2102
2376
  "align-justify": u,
2103
- "decrease-indent": B,
2104
- "increase-indent": oe,
2105
- trash: Ae
2377
+ "decrease-indent": z,
2378
+ "increase-indent": B,
2379
+ trash: je,
2380
+ "rotate-ccw": ve,
2381
+ square: Se,
2382
+ x: Ie
2106
2383
  };
2107
2384
  function $({ name: e }) {
2108
- let t = ua[e];
2385
+ let t = Ma[e];
2109
2386
  return /* @__PURE__ */ Z(t, {
2110
2387
  "aria-hidden": "true",
2111
2388
  absoluteStrokeWidth: !0,
@@ -2115,24 +2392,24 @@ function $({ name: e }) {
2115
2392
  }
2116
2393
  //#endregion
2117
2394
  //#region src/ui/math/MathEditorPopover.tsx
2118
- function da({ editor: e, messages: t, onClose: n, target: r }) {
2119
- let i = J(null), a = J(null), [o, s] = Y(r.latex), [c, l] = Y(null), u = t.math, d = q(() => Yt(e, r) ?? 1, [e, r]), f = q(() => Xt(e, r), [e, r]), p = q(() => o === r.latex && f ? {
2395
+ function Na({ editor: e, messages: t, onClose: n, target: r }) {
2396
+ let i = J(null), a = J(null), [o, s] = Y(r.latex), [c, l] = Y(null), u = t.math, d = q(() => $t(e, r) ?? 1, [e, r]), f = q(() => en(e, r), [e, r]), p = q(() => o === r.latex && f ? {
2120
2397
  html: f,
2121
2398
  error: !1
2122
- } : en(o, r.kind, e), [
2399
+ } : an(o, r.kind, e), [
2123
2400
  e,
2124
2401
  f,
2125
2402
  r.kind,
2126
2403
  r.latex,
2127
2404
  o
2128
- ]), m = o.trim().length > 0, h = W(() => {
2405
+ ]), m = o.trim().length > 0, h = G(() => {
2129
2406
  if (typeof window > "u") return;
2130
- let t = Jt(e, r), i = e.view.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
2407
+ let t = Qt(e, r), i = e.view.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
2131
2408
  if (!t || !i) {
2132
2409
  n();
2133
2410
  return;
2134
2411
  }
2135
- l(qt({
2412
+ l(Zt({
2136
2413
  anchorRect: t,
2137
2414
  frameRect: i,
2138
2415
  kind: r.kind,
@@ -2146,30 +2423,30 @@ function da({ editor: e, messages: t, onClose: n, target: r }) {
2146
2423
  r,
2147
2424
  o
2148
2425
  ]);
2149
- G(() => {
2426
+ K(() => {
2150
2427
  s(r.latex);
2151
- }, [r.latex, r.pos]), G(() => {
2152
- tn(e, r, !0), h();
2428
+ }, [r.latex, r.pos]), K(() => {
2429
+ on(e, r, !0), h();
2153
2430
  let t = window.requestAnimationFrame(() => {
2154
2431
  a.current?.focus({ preventScroll: !0 }), a.current?.select(), h();
2155
2432
  });
2156
2433
  return window.addEventListener("resize", h), window.addEventListener("scroll", h, !0), () => {
2157
- window.cancelAnimationFrame(t), window.removeEventListener("resize", h), window.removeEventListener("scroll", h, !0), tn(e, r, !1);
2434
+ window.cancelAnimationFrame(t), window.removeEventListener("resize", h), window.removeEventListener("scroll", h, !0), on(e, r, !1);
2158
2435
  };
2159
2436
  }, [
2160
2437
  e,
2161
2438
  n,
2162
2439
  r,
2163
2440
  h
2164
- ]), G(() => {
2441
+ ]), K(() => {
2165
2442
  let e = (e) => {
2166
2443
  let t = e.target;
2167
2444
  t instanceof Node && (i.current?.contains(t) || t instanceof Element && t.closest(".tiptap-mathematics-render") || n());
2168
2445
  };
2169
2446
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
2170
2447
  }, [n]);
2171
- let g = W(() => {
2172
- m && Kt(e, r, o) && n();
2448
+ let g = G(() => {
2449
+ m && Xt(e, r, o) && n();
2173
2450
  }, [
2174
2451
  m,
2175
2452
  e,
@@ -2244,7 +2521,7 @@ function da({ editor: e, messages: t, onClose: n, target: r }) {
2244
2521
  className: "markweave-math-block-toolbar",
2245
2522
  children: [
2246
2523
  /* @__PURE__ */ Z("span", { children: u.label }),
2247
- /* @__PURE__ */ Z(te, {
2524
+ /* @__PURE__ */ Z(ne, {
2248
2525
  "aria-hidden": "true",
2249
2526
  size: 15,
2250
2527
  strokeWidth: 1.75
@@ -2300,31 +2577,31 @@ function da({ editor: e, messages: t, onClose: n, target: r }) {
2300
2577
  }
2301
2578
  //#endregion
2302
2579
  //#region src/ui/slash-command/SlashCommandMenu.tsx
2303
- var fa = n("zh"), pa = {
2304
- type: ke,
2305
- "heading-1": re,
2306
- "heading-2": R,
2307
- "heading-3": ie,
2308
- "bullet-list": ue,
2309
- "ordered-list": U,
2310
- "task-list": H,
2311
- blockquote: _e,
2580
+ var Pa = n("zh"), Fa = {
2581
+ type: Ae,
2582
+ "heading-1": ae,
2583
+ "heading-2": I,
2584
+ "heading-3": oe,
2585
+ "bullet-list": de,
2586
+ "ordered-list": H,
2587
+ "task-list": V,
2588
+ blockquote: ge,
2312
2589
  "code-block": D,
2313
2590
  info: se,
2314
2591
  tip: le,
2315
2592
  warning: c,
2316
- error: N,
2593
+ error: M,
2317
2594
  success: A,
2318
2595
  emoji: be,
2319
2596
  math: ye,
2320
- table: Ee,
2321
- separator: de,
2322
- image: ae,
2323
- video: Pe,
2324
- attachment: me
2597
+ table: De,
2598
+ separator: fe,
2599
+ image: L,
2600
+ video: Fe,
2601
+ attachment: pe
2325
2602
  };
2326
- function ma({ name: e }) {
2327
- let t = pa[e];
2603
+ function Ia({ name: e }) {
2604
+ let t = Fa[e];
2328
2605
  return /* @__PURE__ */ Z(t, {
2329
2606
  "aria-hidden": "true",
2330
2607
  absoluteStrokeWidth: !0,
@@ -2332,8 +2609,8 @@ function ma({ name: e }) {
2332
2609
  strokeWidth: 1.6
2333
2610
  });
2334
2611
  }
2335
- function ha(e, t, n) {
2336
- return !cn(e) || !n ? {
2612
+ function La(e, t, n) {
2613
+ return !fn(e) || !n ? {
2337
2614
  visible: !1,
2338
2615
  empty: !1,
2339
2616
  activeIndex: -1
@@ -2347,16 +2624,16 @@ function ha(e, t, n) {
2347
2624
  activeIndex: Math.min(t.length - 1, Math.max(0, e.activeIndex))
2348
2625
  };
2349
2626
  }
2350
- function ga(e, t) {
2627
+ function Ra(e, t) {
2351
2628
  return Object.values(t.slash.groups).map((t) => ({
2352
2629
  group: t,
2353
2630
  commands: e.filter((e) => e.group === t)
2354
2631
  })).filter((e) => e.commands.length > 0);
2355
2632
  }
2356
- function _a(e, t) {
2633
+ function za(e, t) {
2357
2634
  return t.slash.uploadKindLabels[e] ?? t.slash.uploadKindLabels.upload;
2358
2635
  }
2359
- function va({ command: e, messages: t, onBack: n, onSelect: r }) {
2636
+ function Ba({ command: e, messages: t, onBack: n, onSelect: r }) {
2360
2637
  let [i, a] = Y(""), [o, s] = Y(0), c = q(() => {
2361
2638
  let e = i.trim().toLowerCase();
2362
2639
  return (e ? t.slash.emojiItems.filter((t) => [
@@ -2423,7 +2700,7 @@ function va({ command: e, messages: t, onBack: n, onSelect: r }) {
2423
2700
  ]
2424
2701
  });
2425
2702
  }
2426
- function ya({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2703
+ function Va({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2427
2704
  let a = e.uploadKind ?? "attachment", [o, s] = Y(""), [c, l] = Y(null), [u, d] = Y(null), [f, p] = Y(!1), m = async (t) => {
2428
2705
  r(e, { uploadResult: await X({
2429
2706
  kind: a,
@@ -2445,7 +2722,7 @@ function ya({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2445
2722
  d(t.slash.uploadRequiredError);
2446
2723
  return;
2447
2724
  }
2448
- await m(Ie(o));
2725
+ await m(ze(o));
2449
2726
  } catch (e) {
2450
2727
  d(e instanceof Error ? e.message : t.slash.uploadFailedError);
2451
2728
  } finally {
@@ -2463,7 +2740,7 @@ function ya({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2463
2740
  onMouseDown: (e) => e.preventDefault(),
2464
2741
  onClick: n,
2465
2742
  children: t.common.back
2466
- }), /* @__PURE__ */ Z("span", { children: _a(a, t) })]
2743
+ }), /* @__PURE__ */ Z("span", { children: za(a, t) })]
2467
2744
  }),
2468
2745
  /* @__PURE__ */ Q("label", {
2469
2746
  className: "markweave-slash-upload-field",
@@ -2511,10 +2788,10 @@ function ya({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2511
2788
  ]
2512
2789
  });
2513
2790
  }
2514
- function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand: i, onActiveIndexChange: a, onInputCommandChange: o, onSelect: s, onUpload: c }) {
2515
- let l = ha(n, e, r);
2791
+ function Ha({ commands: e, messages: t = Pa, state: n, position: r, inputCommand: i, onActiveIndexChange: a, onInputCommandChange: o, onSelect: s, onUpload: c }) {
2792
+ let l = La(n, e, r);
2516
2793
  if (!l.visible || !r) return null;
2517
- let u = ga(e, t), d = {
2794
+ let u = Ra(e, t), d = {
2518
2795
  left: r.left,
2519
2796
  top: r.top,
2520
2797
  maxHeight: r.maxHeight,
@@ -2523,7 +2800,7 @@ function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand
2523
2800
  left: r.triggerLeft,
2524
2801
  top: r.triggerTop
2525
2802
  }, p = (e) => o?.(e), m = () => o?.(null);
2526
- return /* @__PURE__ */ Q(ot, { children: [/* @__PURE__ */ Q("div", {
2803
+ return /* @__PURE__ */ Q(lt, { children: [/* @__PURE__ */ Q("div", {
2527
2804
  className: "markweave-slash-trigger",
2528
2805
  style: f,
2529
2806
  "aria-hidden": "true",
@@ -2536,12 +2813,12 @@ function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand
2536
2813
  "aria-label": t.slash.ariaLabel,
2537
2814
  "data-placement": r.placement,
2538
2815
  "data-testid": "markweave-slash-menu",
2539
- children: i?.inputKind === "emoji" ? /* @__PURE__ */ Z(va, {
2816
+ children: i?.inputKind === "emoji" ? /* @__PURE__ */ Z(Ba, {
2540
2817
  command: i,
2541
2818
  messages: t,
2542
2819
  onBack: m,
2543
2820
  onSelect: s
2544
- }) : i?.inputKind === "upload" ? /* @__PURE__ */ Z(ya, {
2821
+ }) : i?.inputKind === "upload" ? /* @__PURE__ */ Z(Va, {
2545
2822
  command: i,
2546
2823
  messages: t,
2547
2824
  onBack: m,
@@ -2561,7 +2838,7 @@ function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand
2561
2838
  className: "markweave-slash-group-title",
2562
2839
  children: t.group
2563
2840
  }), t.commands.map((t) => {
2564
- let n = e.indexOf(t), r = n === l.activeIndex, i = on(t), o = !!t.disabled;
2841
+ let n = e.indexOf(t), r = n === l.activeIndex, i = un(t), o = !!t.disabled;
2565
2842
  return /* @__PURE__ */ Q("button", {
2566
2843
  type: "button",
2567
2844
  role: "option",
@@ -2585,7 +2862,7 @@ function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand
2585
2862
  }
2586
2863
  },
2587
2864
  children: [
2588
- /* @__PURE__ */ Z(ma, { name: t.icon }),
2865
+ /* @__PURE__ */ Z(Ia, { name: t.icon }),
2589
2866
  /* @__PURE__ */ Z("span", { children: t.label }),
2590
2867
  o && t.disabledReason ? /* @__PURE__ */ Z("small", { children: t.disabledReason }) : null
2591
2868
  ]
@@ -2597,7 +2874,7 @@ function ba({ commands: e, messages: t = fa, state: n, position: r, inputCommand
2597
2874
  }
2598
2875
  //#endregion
2599
2876
  //#region src/ui/table/TableControls.tsx
2600
- var xa = n("zh"), Sa = {
2877
+ var Ua = n("zh"), Wa = {
2601
2878
  "move-left": v,
2602
2879
  "move-right": y,
2603
2880
  "move-up": b,
@@ -2608,15 +2885,16 @@ var xa = n("zh"), Sa = {
2608
2885
  "insert-below": S,
2609
2886
  "sort-asc": _,
2610
2887
  "sort-desc": x,
2611
- color: pe,
2888
+ color: W,
2612
2889
  alignment: d,
2613
- clear: Se,
2614
- duplicate: P,
2615
- copy: P,
2616
- merge: De,
2617
- split: Oe,
2618
- delete: Ae
2619
- }, Ca = {
2890
+ clear: Ce,
2891
+ duplicate: N,
2892
+ copy: N,
2893
+ merge: Oe,
2894
+ split: ke,
2895
+ "ask-ai": xe,
2896
+ delete: je
2897
+ }, Ga = {
2620
2898
  left: d,
2621
2899
  center: l,
2622
2900
  right: f,
@@ -2624,62 +2902,62 @@ var xa = n("zh"), Sa = {
2624
2902
  middle: p,
2625
2903
  bottom: m
2626
2904
  };
2627
- function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa, onCopyPayload: i, onCommandResult: a, onEditWithAi: o }) {
2628
- let [s, c] = Y(null), [l, u] = Y(null), [d, f] = Y("row-edge"), [p, m] = Y(null), [h, g] = Y(null), [_, v] = Y(null), [y, b] = Y(null), [x, S] = Y(null), [C, w] = Y(null), [T, E] = Y(null), [, D] = Y(0), O = J(null), k = J(null), [A, j] = Y(null), ee = J(null), N = J(null), te = J(null), P = J(null), ne = J(null), F = J(null), I = J(null), L = e ? yn(t.state) : null;
2629
- if (G(() => {
2905
+ function Ka({ active: e, editor: t, interactionState: n = Tn, messages: r = Ua, onCopyPayload: i, onCommandResult: a, askAi: o }) {
2906
+ let [s, c] = Y(null), [l, u] = Y(null), [d, f] = Y("row-edge"), [p, m] = Y(null), [h, g] = Y(null), [_, v] = Y(null), [y, b] = Y(null), [x, S] = Y(null), [C, w] = Y(null), [T, E] = Y(null), [, D] = Y(0), O = J(null), k = J(null), [A, ee] = Y(null), te = J(null), M = J(null), ne = J(null), N = J(null), re = J(null), ie = J(null), P = J(null), F = e ? Cn(t.state) : null;
2907
+ if (K(() => {
2630
2908
  if (!A) return;
2631
2909
  let e = window.setTimeout(() => {
2632
- j(null);
2633
- }, Wr);
2910
+ ee(null);
2911
+ }, li);
2634
2912
  return () => {
2635
2913
  window.clearTimeout(e);
2636
2914
  };
2637
- }, [A]), G(() => {
2915
+ }, [A]), K(() => {
2638
2916
  let e = (e) => {
2639
2917
  let n = O.current;
2640
2918
  if (!n) return;
2641
- let r = Ar(t, n.axis, e.clientX, e.clientY);
2919
+ let r = Xr(t, n.axis, e.clientX, e.clientY);
2642
2920
  r !== null && (e.preventDefault(), k.current = r, e.dataTransfer && (e.dataTransfer.dropEffect = "move"));
2643
2921
  }, n = (e) => {
2644
2922
  let n = O.current;
2645
2923
  if (!n) return;
2646
- let r = Ar(t, n.axis, e.clientX, e.clientY) ?? k.current;
2647
- e.preventDefault(), O.current = null, k.current = null, r !== null && Vr(t, n.axis, n.index, r);
2924
+ let r = Xr(t, n.axis, e.clientX, e.clientY) ?? k.current;
2925
+ e.preventDefault(), O.current = null, k.current = null, r !== null && oi(t, n.axis, n.index, r);
2648
2926
  };
2649
2927
  return document.addEventListener("dragover", e), document.addEventListener("drop", n), () => {
2650
2928
  document.removeEventListener("dragover", e), document.removeEventListener("drop", n);
2651
2929
  };
2652
- }, [t]), K(() => {
2930
+ }, [t]), Le(() => {
2653
2931
  if (!e) {
2654
- v(null), b(null), S(null), w(null), E(null), j(null);
2932
+ v(null), b(null), S(null), w(null), E(null), ee(null);
2655
2933
  return;
2656
2934
  }
2657
2935
  let r = () => {
2658
- let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, r = Nr(t, n, "row", L?.activeCellPos ?? null), i = Nr(t, n, "column", L?.activeCellPos ?? null), a = r ? Mr(t, r) : null, o = i ? Mr(t, i) : null, c = Rr(t, "selection").length > 0 ? zr(t) : null, l = kr(t)?.getBoundingClientRect() ?? null;
2936
+ let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, r = $r(t, n, "row", F?.activeCellPos ?? null), i = $r(t, n, "column", F?.activeCellPos ?? null), a = r ? Qr(t, r) : null, o = i ? Qr(t, i) : null, c = ri(t, "selection").length > 0 ? ii(t) : null, l = Yr(t)?.getBoundingClientRect() ?? null;
2659
2937
  if (!e) {
2660
2938
  v(null), b(null), S(null), w(null), E(null);
2661
2939
  return;
2662
2940
  }
2663
2941
  let u = e.getBoundingClientRect();
2664
- a ? v(wr({
2942
+ a ? v(Wr({
2665
2943
  targetRect: a,
2666
2944
  frameRect: u,
2667
2945
  kind: "row"
2668
- })) : s === "row" && d === "row-edge" || v(null), o ? b(wr({
2946
+ })) : s === "row" && d === "row-edge" || v(null), o ? b(Wr({
2669
2947
  targetRect: o,
2670
2948
  frameRect: u,
2671
2949
  kind: "column"
2672
- })) : s === "column" && d === "column-edge" || b(null), c ? S(wr({
2950
+ })) : s === "column" && d === "column-edge" || b(null), c ? S(Wr({
2673
2951
  targetRect: c,
2674
2952
  frameRect: u,
2675
2953
  kind: "selection"
2676
2954
  })) : s === "selection" && d === "selection-edge" || S(null);
2677
2955
  let f = n.hoverCellPos !== null && !!(r && r.index === r.visualHeight - 1), p = n.hoverCellPos !== null && !!(i && i.index === i.visualWidth - 1);
2678
- w(l && f ? Tr({
2956
+ w(l && f ? Gr({
2679
2957
  tableRect: l,
2680
2958
  frameRect: u,
2681
2959
  kind: "row"
2682
- }) : null), E(l && p ? Tr({
2960
+ }) : null), E(l && p ? Gr({
2683
2961
  tableRect: l,
2684
2962
  frameRect: u,
2685
2963
  kind: "column"
@@ -2691,34 +2969,34 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2691
2969
  }, [
2692
2970
  e,
2693
2971
  t,
2694
- L?.activeCellPos,
2695
- L?.selectionFrom,
2696
- L?.selectionTo,
2972
+ F?.activeCellPos,
2973
+ F?.selectionFrom,
2974
+ F?.selectionTo,
2697
2975
  n.hoverCellPos,
2698
2976
  n.hoverVisualColumnIndex,
2699
2977
  n.hoverVisualRowIndex,
2700
2978
  d,
2701
2979
  s
2702
- ]), K(() => {
2980
+ ]), Le(() => {
2703
2981
  if (!e || !s) {
2704
2982
  m(null);
2705
2983
  return;
2706
2984
  }
2707
2985
  let n = () => {
2708
- let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, n = d === "row-edge" ? ne.current : d === "column-edge" ? F.current : I.current, r = N.current;
2986
+ let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, n = d === "row-edge" ? re.current : d === "column-edge" ? ie.current : P.current, r = M.current;
2709
2987
  if (!e || !n || !r) {
2710
2988
  m(null);
2711
2989
  return;
2712
2990
  }
2713
- let i = n.getBoundingClientRect(), a = s === "row" ? kr(t)?.getBoundingClientRect() : null, o = a ? {
2991
+ let i = n.getBoundingClientRect(), a = s === "row" ? Yr(t)?.getBoundingClientRect() : null, o = a ? {
2714
2992
  left: i.left,
2715
2993
  top: a.top,
2716
2994
  width: i.width,
2717
2995
  height: i.height
2718
- } : i, c = e.getBoundingClientRect(), l = r.getBoundingClientRect(), u = te.current?.scrollHeight ?? 0, f = u > 0 ? u + 12 : 0, p = Sr({
2996
+ } : i, c = e.getBoundingClientRect(), l = r.getBoundingClientRect(), u = ne.current?.scrollHeight ?? 0, f = u > 0 ? u + 12 : 0, p = Hr({
2719
2997
  anchorRect: o,
2720
2998
  frameRect: c,
2721
- boundaryRect: Fr(e),
2999
+ boundaryRect: ei(e),
2722
3000
  menuSize: {
2723
3001
  width: l.width || 254,
2724
3002
  height: f || l.height || 410
@@ -2738,22 +3016,22 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2738
3016
  _,
2739
3017
  y,
2740
3018
  x
2741
- ]), K(() => {
3019
+ ]), Le(() => {
2742
3020
  if (!e || !s || !l || !p) {
2743
3021
  g(null);
2744
3022
  return;
2745
3023
  }
2746
3024
  let n = () => {
2747
- let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, n = N.current, r = P.current, i = n?.querySelector(`[data-submenu-trigger="${l}"]`);
3025
+ let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, n = M.current, r = N.current, i = n?.querySelector(`[data-submenu-trigger="${l}"]`);
2748
3026
  if (!e || !n || !r || !i) {
2749
3027
  g(null);
2750
3028
  return;
2751
3029
  }
2752
3030
  let a = r.getBoundingClientRect(), o = Math.max(r.scrollHeight + 2, a.height);
2753
- g(Cr({
3031
+ g(Ur({
2754
3032
  triggerRect: i.getBoundingClientRect(),
2755
3033
  parentMenuRect: n.getBoundingClientRect(),
2756
- boundaryRect: Fr(e),
3034
+ boundaryRect: ei(e),
2757
3035
  submenuSize: {
2758
3036
  width: a.width || 238,
2759
3037
  height: o || 410
@@ -2761,7 +3039,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2761
3039
  }));
2762
3040
  };
2763
3041
  n();
2764
- let r = te.current;
3042
+ let r = ne.current;
2765
3043
  return r?.addEventListener("scroll", n), window.addEventListener("resize", n), window.addEventListener("scroll", n, !0), () => {
2766
3044
  r?.removeEventListener("scroll", n), window.removeEventListener("resize", n), window.removeEventListener("scroll", n, !0);
2767
3045
  };
@@ -2771,7 +3049,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2771
3049
  p,
2772
3050
  s,
2773
3051
  l
2774
- ]), G(() => {
3052
+ ]), K(() => {
2775
3053
  if (!e || !s) return;
2776
3054
  let n = (e) => {
2777
3055
  if (e.key === "Escape") {
@@ -2782,7 +3060,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2782
3060
  c(null), u(null), t.view.focus();
2783
3061
  }
2784
3062
  }, r = (e) => {
2785
- e.target instanceof Node && ee.current?.contains(e.target) || (c(null), u(null));
3063
+ e.target instanceof Node && te.current?.contains(e.target) || (c(null), u(null));
2786
3064
  };
2787
3065
  return document.addEventListener("keydown", n), document.addEventListener("mousedown", r), () => {
2788
3066
  document.removeEventListener("keydown", n), document.removeEventListener("mousedown", r);
@@ -2793,54 +3071,53 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2793
3071
  s,
2794
3072
  l
2795
3073
  ]), !e) return null;
2796
- let re = (e, t) => {
3074
+ let ae = (e, t) => {
2797
3075
  let n = s === e && d === t;
2798
3076
  f(t), c(n ? null : e), u(null);
2799
- }, R = () => {
2800
- t.view.dispatch(vr(t.state.tr, null));
2801
- }, ie = (e, r) => {
2802
- let i = n.hoverCellPos ?? L?.activeCellPos ?? null, a = n.hoverCellPos === null ? null : e === "row" ? n.hoverVisualRowIndex : n.hoverVisualColumnIndex;
2803
- i !== null && Hr(t, i, e, { visualIndex: a }), re(e, r);
2804
- }, ae = () => {
2805
- R(), re("selection", "selection-edge");
2806
- }, z = Nr(t, n, "row", L?.activeCellPos ?? null), B = Nr(t, n, "column", L?.activeCellPos ?? null), oe = Rr(t, "selection").length > 0, se = s ? Rr(t, s) : [], ce = async (e, n) => {
2807
- let o = await Dr({
3077
+ }, I = () => {
3078
+ t.view.dispatch(Rr(t.state.tr, null));
3079
+ }, oe = (e, r) => {
3080
+ let i = n.hoverCellPos ?? F?.activeCellPos ?? null, a = n.hoverCellPos === null ? null : e === "row" ? n.hoverVisualRowIndex : n.hoverVisualColumnIndex;
3081
+ i !== null && si(t, i, e, { visualIndex: a }), ae(e, r);
3082
+ }, L = () => {
3083
+ I(), ae("selection", "selection-edge");
3084
+ }, R = $r(t, n, "row", F?.activeCellPos ?? null), z = $r(t, n, "column", F?.activeCellPos ?? null), B = o?.enabled === !0 && typeof o.handler == "function", se = ri(t, "selection", { askAiEnabled: B }).length > 0, ce = s ? ri(t, s, { askAiEnabled: B }) : [], le = async (e, n) => {
3085
+ let o = await qr({
2808
3086
  editor: t,
2809
3087
  commandId: e,
2810
3088
  menu: n ?? s ?? "selection",
2811
3089
  messages: r
2812
3090
  });
2813
- return o.copyFeedback ? (j(o.copyFeedback), o.copyPayload && i?.(o.copyPayload)) : j(null), a?.(o.commandResult), o.success;
2814
- }, le = (e) => {
2815
- let n = Pr(t, e);
2816
- n && o?.(n), c(null), u(null), t.view.focus();
2817
- }, V = (e) => {
2818
- s !== "row" && s !== "column" || e(s) && D((e) => e + 1);
3091
+ return o.copyFeedback ? (ee(o.copyFeedback), o.copyPayload && i?.(o.copyPayload)) : ee(null), a?.(o.commandResult), o.success;
2819
3092
  }, ue = (e) => {
2820
- let r = e === "row" ? z : B, i = n.hoverCellPos ?? L?.activeCellPos ?? null;
2821
- !r || i === null || Jr(t, i, e, { visualIndex: r.index }) && ce(e === "row" ? "add-row-after" : "add-column-after", e);
3093
+ !B || !Fr(t, e) || (c(null), u(null));
3094
+ }, de = (e) => {
3095
+ s !== "row" && s !== "column" || e(s) && D((e) => e + 1);
3096
+ }, V = (e) => {
3097
+ let r = e === "row" ? R : z, i = n.hoverCellPos ?? F?.activeCellPos ?? null;
3098
+ !r || i === null || pi(t, i, e, { visualIndex: r.index }) && le(e === "row" ? "add-row-after" : "add-column-after", e);
2822
3099
  }, H = (e, t, n) => {
2823
3100
  O.current = {
2824
3101
  axis: e,
2825
3102
  index: t
2826
3103
  }, k.current = t, n.dataTransfer.effectAllowed = "move", n.dataTransfer.setData("application/x-markweave-table-axis", `${e}:${t}`);
2827
- }, U = (e) => {
3104
+ }, fe = (e) => {
2828
3105
  let t = e.currentTarget, n = t.classList.contains("markweave-table-menu") ? t.querySelector(":scope > .markweave-table-menu-scroll") ?? t : t, r = Array.from(n.querySelectorAll(":scope > button[role=\"menuitem\"]:not(:disabled), :scope > button[role=\"menuitemradio\"]:not(:disabled)")), i = r.indexOf(document.activeElement);
2829
3106
  if (e.key === "ArrowDown" || e.key === "ArrowUp") {
2830
3107
  e.preventDefault(), e.stopPropagation();
2831
3108
  let t = e.key === "ArrowDown" ? 1 : -1;
2832
3109
  r[i < 0 ? 0 : Math.min(r.length - 1, Math.max(0, i + t))]?.focus();
2833
3110
  }
2834
- }, de = s === "row" || s === "column" ? jr(t, s) : null;
3111
+ }, W = s === "row" || s === "column" ? Zr(t, s) : null;
2835
3112
  return /* @__PURE__ */ Q("div", {
2836
- ref: ee,
3113
+ ref: te,
2837
3114
  className: "markweave-table-controls",
2838
3115
  "data-testid": "markweave-table-controls",
2839
3116
  "aria-label": r.table.controlsAriaLabel,
2840
3117
  "data-open-menu": s ?? "none",
2841
3118
  "data-positioned": _ || y || x ? "true" : "false",
2842
3119
  onMouseLeave: () => {
2843
- t.view.dispatch(t.state.tr.setMeta(Sn, { type: "clear-hover" }));
3120
+ t.view.dispatch(t.state.tr.setMeta(En, { type: "clear-hover" }));
2844
3121
  },
2845
3122
  children: [
2846
3123
  A ? /* @__PURE__ */ Z("div", {
@@ -2851,21 +3128,21 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2851
3128
  "data-copy-kind": A.kind,
2852
3129
  "data-text-length": A.textLength,
2853
3130
  "data-html-length": A.htmlLength,
2854
- children: Or(A)
3131
+ children: Jr(A)
2855
3132
  }) : null,
2856
3133
  _ ? /* @__PURE__ */ Z("button", {
2857
3134
  type: "button",
2858
- ref: ne,
3135
+ ref: re,
2859
3136
  className: "markweave-table-edge-handle markweave-table-edge-handle--row",
2860
3137
  "aria-label": r.table.activeRowActions,
2861
3138
  "aria-expanded": s === "row" && d === "row-edge",
2862
3139
  "aria-haspopup": "menu",
2863
3140
  title: r.table.rowActions,
2864
3141
  "data-testid": "markweave-table-hover-row-handle",
2865
- "data-axis-index": z?.index ?? "",
2866
- "data-axis-selected-cells": z?.selectedCellCount ?? "",
2867
- "data-axis-visual-cells": z?.visualCellCount ?? "",
2868
- "data-axis-visual-size": z?.visualHeight ?? "",
3142
+ "data-axis-index": R?.index ?? "",
3143
+ "data-axis-selected-cells": R?.selectedCellCount ?? "",
3144
+ "data-axis-visual-cells": R?.visualCellCount ?? "",
3145
+ "data-axis-visual-size": R?.visualHeight ?? "",
2869
3146
  style: {
2870
3147
  left: _.left,
2871
3148
  top: _.top,
@@ -2873,31 +3150,31 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2873
3150
  height: _.height
2874
3151
  },
2875
3152
  draggable: !0,
2876
- onDragStart: (e) => H("row", z?.index ?? 0, e),
3153
+ onDragStart: (e) => H("row", R?.index ?? 0, e),
2877
3154
  onDragEnd: () => {
2878
3155
  O.current = null, k.current = null;
2879
3156
  },
2880
3157
  onClick: () => {
2881
- ie("row", "row-edge");
3158
+ oe("row", "row-edge");
2882
3159
  },
2883
- children: /* @__PURE__ */ Z(fe, {
3160
+ children: /* @__PURE__ */ Z(U, {
2884
3161
  "aria-hidden": "true",
2885
3162
  size: 14
2886
3163
  })
2887
3164
  }) : null,
2888
3165
  y ? /* @__PURE__ */ Z("button", {
2889
3166
  type: "button",
2890
- ref: F,
3167
+ ref: ie,
2891
3168
  className: "markweave-table-edge-handle markweave-table-edge-handle--column",
2892
3169
  "aria-label": r.table.activeColumnActions,
2893
3170
  "aria-expanded": s === "column" && d === "column-edge",
2894
3171
  "aria-haspopup": "menu",
2895
3172
  title: r.table.columnActions,
2896
3173
  "data-testid": "markweave-table-hover-column-handle",
2897
- "data-axis-index": B?.index ?? "",
2898
- "data-axis-selected-cells": B?.selectedCellCount ?? "",
2899
- "data-axis-visual-cells": B?.visualCellCount ?? "",
2900
- "data-axis-visual-size": B?.visualWidth ?? "",
3174
+ "data-axis-index": z?.index ?? "",
3175
+ "data-axis-selected-cells": z?.selectedCellCount ?? "",
3176
+ "data-axis-visual-cells": z?.visualCellCount ?? "",
3177
+ "data-axis-visual-size": z?.visualWidth ?? "",
2901
3178
  style: {
2902
3179
  left: y.left,
2903
3180
  top: y.top,
@@ -2905,14 +3182,14 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2905
3182
  height: y.height
2906
3183
  },
2907
3184
  draggable: !0,
2908
- onDragStart: (e) => H("column", B?.index ?? 0, e),
3185
+ onDragStart: (e) => H("column", z?.index ?? 0, e),
2909
3186
  onDragEnd: () => {
2910
3187
  O.current = null, k.current = null;
2911
3188
  },
2912
3189
  onClick: () => {
2913
- ie("column", "column-edge");
3190
+ oe("column", "column-edge");
2914
3191
  },
2915
- children: /* @__PURE__ */ Z(fe, {
3192
+ children: /* @__PURE__ */ Z(U, {
2916
3193
  "aria-hidden": "true",
2917
3194
  size: 14
2918
3195
  })
@@ -2930,8 +3207,8 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2930
3207
  height: C.height
2931
3208
  },
2932
3209
  onMouseDown: (e) => e.preventDefault(),
2933
- onClick: () => ue("row"),
2934
- children: /* @__PURE__ */ Z(ge, {
3210
+ onClick: () => V("row"),
3211
+ children: /* @__PURE__ */ Z(he, {
2935
3212
  "aria-hidden": "true",
2936
3213
  size: 16
2937
3214
  })
@@ -2949,15 +3226,15 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2949
3226
  height: T.height
2950
3227
  },
2951
3228
  onMouseDown: (e) => e.preventDefault(),
2952
- onClick: () => ue("column"),
2953
- children: /* @__PURE__ */ Z(ge, {
3229
+ onClick: () => V("column"),
3230
+ children: /* @__PURE__ */ Z(he, {
2954
3231
  "aria-hidden": "true",
2955
3232
  size: 16
2956
3233
  })
2957
3234
  }) : null,
2958
- oe && x ? /* @__PURE__ */ Z("button", {
3235
+ se && x ? /* @__PURE__ */ Z("button", {
2959
3236
  type: "button",
2960
- ref: I,
3237
+ ref: P,
2961
3238
  className: "markweave-table-edge-handle markweave-table-edge-handle--selection",
2962
3239
  "aria-label": r.table.selectionActions,
2963
3240
  "aria-expanded": s === "selection" && d === "selection-edge",
@@ -2971,17 +3248,17 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2971
3248
  height: x.height
2972
3249
  },
2973
3250
  onMouseDown: (e) => e.preventDefault(),
2974
- onClick: ae,
2975
- children: /* @__PURE__ */ Z(fe, {
3251
+ onClick: L,
3252
+ children: /* @__PURE__ */ Z(U, {
2976
3253
  "aria-hidden": "true",
2977
3254
  size: 14
2978
3255
  })
2979
3256
  }) : null,
2980
3257
  s ? /* @__PURE__ */ Q("div", {
2981
- ref: N,
3258
+ ref: M,
2982
3259
  className: "markweave-table-menu",
2983
3260
  role: "menu",
2984
- "aria-label": Kr(s, r),
3261
+ "aria-label": di(s, r),
2985
3262
  "data-testid": "markweave-table-menu",
2986
3263
  "data-positioned": p ? "true" : "false",
2987
3264
  "data-placement": p?.placement,
@@ -2990,14 +3267,14 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
2990
3267
  left: p.left,
2991
3268
  top: p.top
2992
3269
  } : void 0,
2993
- onKeyDown: U,
3270
+ onKeyDown: fe,
2994
3271
  children: [
2995
3272
  /* @__PURE__ */ Z("div", {
2996
- ref: te,
3273
+ ref: ne,
2997
3274
  className: "markweave-table-menu-scroll",
2998
3275
  style: p ? { maxHeight: Math.max(1, p.maxHeight - 12) } : void 0,
2999
- children: se.map((e, n) => {
3000
- let i = Ir(e), a = n === 0 ? i : Ir(se[n - 1]), d = n > 0 && a !== i, f = e.submenuId ? !0 : e.commandId === null ? !!o : Er(t, e.commandId), p = Lr(e, r), m = Sa[e.icon];
3276
+ children: ce.map((e, n) => {
3277
+ let i = ti(e), a = n === 0 ? i : ti(ce[n - 1]), o = n > 0 && a !== i, d = s === "row" || s === "column" ? s : "selection", f = e.submenuId ? !0 : e.id === "edit-with-ai" ? B && wr(t, d) : e.commandId === null ? !1 : Kr(t, e.commandId), p = ni(e, r), m = Wa[e.icon];
3001
3278
  return /* @__PURE__ */ Q("button", {
3002
3279
  type: "button",
3003
3280
  role: "menuitem",
@@ -3006,24 +3283,27 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3006
3283
  "aria-haspopup": e.submenuId ? "menu" : void 0,
3007
3284
  "aria-expanded": e.submenuId ? l === e.submenuId : void 0,
3008
3285
  disabled: !f,
3286
+ title: e.id === "edit-with-ai" && B && !f ? r.askAi.tableMergedUnsupported : void 0,
3009
3287
  "data-menu-group": i,
3010
- "data-starts-group": d ? "true" : "false",
3288
+ "data-starts-group": o ? "true" : "false",
3011
3289
  "data-command-enabled": f ? "true" : "false",
3012
3290
  "data-submenu-trigger": e.submenuId ?? void 0,
3013
3291
  "data-testid": e.commandId ? `markweave-table-menu-command-${e.commandId}` : e.submenuId ? `markweave-table-menu-submenu-${e.submenuId}` : "markweave-table-menu-command-edit-with-ai",
3014
- onMouseDown: (e) => e.preventDefault(),
3292
+ onMouseDown: (t) => {
3293
+ t.preventDefault(), f && e.id === "edit-with-ai" && ue(d);
3294
+ },
3015
3295
  onMouseEnter: () => u(e.submenuId),
3016
- onClick: () => {
3296
+ onClick: (t) => {
3017
3297
  if (f) {
3018
3298
  if (e.submenuId) {
3019
3299
  u(e.submenuId);
3020
3300
  return;
3021
3301
  }
3022
3302
  if (e.commandId === null) {
3023
- le(s === "row" || s === "column" ? s : "selection");
3303
+ t.detail === 0 && ue(d);
3024
3304
  return;
3025
3305
  }
3026
- ce(e.commandId).finally(() => {
3306
+ le(e.commandId).finally(() => {
3027
3307
  c(null), u(null);
3028
3308
  });
3029
3309
  }
@@ -3041,7 +3321,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3041
3321
  className: "markweave-table-menu-item-label",
3042
3322
  children: p
3043
3323
  }),
3044
- e.submenuId ? /* @__PURE__ */ Z(M, {
3324
+ e.submenuId ? /* @__PURE__ */ Z(j, {
3045
3325
  className: "markweave-table-menu-chevron",
3046
3326
  "aria-hidden": "true",
3047
3327
  size: 16
@@ -3051,7 +3331,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3051
3331
  })
3052
3332
  }),
3053
3333
  l === "color" && (s === "row" || s === "column") ? /* @__PURE__ */ Q("div", {
3054
- ref: P,
3334
+ ref: N,
3055
3335
  className: "markweave-table-submenu markweave-table-color-menu",
3056
3336
  role: "menu",
3057
3337
  "aria-label": r.table.submenus.color,
@@ -3063,20 +3343,20 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3063
3343
  top: h.top,
3064
3344
  maxHeight: h.maxHeight
3065
3345
  } : void 0,
3066
- onKeyDown: U,
3346
+ onKeyDown: fe,
3067
3347
  children: [
3068
3348
  /* @__PURE__ */ Z("div", {
3069
3349
  className: "markweave-table-submenu-title",
3070
3350
  children: r.table.submenus.textColor
3071
3351
  }),
3072
- Ur.map((e) => /* @__PURE__ */ Q("button", {
3352
+ ci.map((e) => /* @__PURE__ */ Q("button", {
3073
3353
  type: "button",
3074
3354
  role: "menuitemradio",
3075
- "aria-checked": de?.textColorId === e.id,
3076
- "data-active": de?.textColorId === e.id ? "true" : "false",
3355
+ "aria-checked": W?.textColorId === e.id,
3356
+ "data-active": W?.textColorId === e.id ? "true" : "false",
3077
3357
  "data-testid": `markweave-table-text-color-${e.id}`,
3078
3358
  onMouseDown: (e) => e.preventDefault(),
3079
- onClick: () => V((n) => xr(t, n, e.id)),
3359
+ onClick: () => de((n) => Vr(t, n, e.id)),
3080
3360
  children: [/* @__PURE__ */ Z("span", {
3081
3361
  className: "markweave-table-color-swatch markweave-table-text-color-swatch",
3082
3362
  "aria-hidden": "true",
@@ -3088,14 +3368,14 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3088
3368
  className: "markweave-table-submenu-title",
3089
3369
  children: r.table.submenus.backgroundColor
3090
3370
  }),
3091
- Ur.map((e) => /* @__PURE__ */ Q("button", {
3371
+ ci.map((e) => /* @__PURE__ */ Q("button", {
3092
3372
  type: "button",
3093
3373
  role: "menuitemradio",
3094
- "aria-checked": de?.backgroundColorId === e.id,
3095
- "data-active": de?.backgroundColorId === e.id ? "true" : "false",
3374
+ "aria-checked": W?.backgroundColorId === e.id,
3375
+ "data-active": W?.backgroundColorId === e.id ? "true" : "false",
3096
3376
  "data-testid": `markweave-table-background-color-${e.id}`,
3097
3377
  onMouseDown: (e) => e.preventDefault(),
3098
- onClick: () => V((n) => br(t, n, e.id)),
3378
+ onClick: () => de((n) => Br(t, n, e.id)),
3099
3379
  children: [/* @__PURE__ */ Z("span", {
3100
3380
  className: "markweave-table-color-swatch",
3101
3381
  "aria-hidden": "true",
@@ -3105,7 +3385,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3105
3385
  ]
3106
3386
  }) : null,
3107
3387
  l === "alignment" && (s === "row" || s === "column") ? /* @__PURE__ */ Q("div", {
3108
- ref: P,
3388
+ ref: N,
3109
3389
  className: "markweave-table-submenu markweave-table-alignment-menu",
3110
3390
  role: "menu",
3111
3391
  "aria-label": r.table.submenus.alignment,
@@ -3117,10 +3397,10 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3117
3397
  top: h.top,
3118
3398
  maxHeight: h.maxHeight
3119
3399
  } : void 0,
3120
- onKeyDown: U,
3400
+ onKeyDown: fe,
3121
3401
  children: [
3122
- Gr.map((e) => {
3123
- let n = Ca[e], i = de?.textAlign === e;
3402
+ ui.map((e) => {
3403
+ let n = Ga[e], i = W?.textAlign === e;
3124
3404
  return /* @__PURE__ */ Q("button", {
3125
3405
  type: "button",
3126
3406
  role: "menuitemradio",
@@ -3128,7 +3408,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3128
3408
  "data-active": i ? "true" : "false",
3129
3409
  "data-testid": `markweave-table-alignment-${e}`,
3130
3410
  onMouseDown: (e) => e.preventDefault(),
3131
- onClick: () => V((n) => yr(t, n, e)),
3411
+ onClick: () => de((n) => zr(t, n, e)),
3132
3412
  children: [/* @__PURE__ */ Z(n, {
3133
3413
  "aria-hidden": "true",
3134
3414
  size: 18,
@@ -3137,8 +3417,8 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3137
3417
  }, e);
3138
3418
  }),
3139
3419
  /* @__PURE__ */ Z("div", { className: "markweave-table-submenu-separator" }),
3140
- qr.map((e) => {
3141
- let n = Ca[e], i = de?.verticalAlign === e;
3420
+ fi.map((e) => {
3421
+ let n = Ga[e], i = W?.verticalAlign === e;
3142
3422
  return /* @__PURE__ */ Q("button", {
3143
3423
  type: "button",
3144
3424
  role: "menuitemradio",
@@ -3146,7 +3426,7 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3146
3426
  "data-active": i ? "true" : "false",
3147
3427
  "data-testid": `markweave-table-alignment-${e}`,
3148
3428
  onMouseDown: (e) => e.preventDefault(),
3149
- onClick: () => V((n) => yr(t, n, e)),
3429
+ onClick: () => de((n) => zr(t, n, e)),
3150
3430
  children: [/* @__PURE__ */ Z(n, {
3151
3431
  "aria-hidden": "true",
3152
3432
  size: 18,
@@ -3163,15 +3443,15 @@ function wa({ active: e, editor: t, interactionState: n = xn, messages: r = xa,
3163
3443
  }
3164
3444
  //#endregion
3165
3445
  //#region src/ui/table/TableSelectionOverlay.tsx
3166
- function Ta({ editor: e, focusState: t }) {
3446
+ function qa({ editor: e, focusState: t }) {
3167
3447
  let [n, r] = Y(null);
3168
- return K(() => {
3448
+ return Le(() => {
3169
3449
  if (t.mode !== "cell-selection") {
3170
3450
  r(null);
3171
3451
  return;
3172
3452
  }
3173
3453
  let n = () => {
3174
- r(Br(e, bn(e.state)));
3454
+ r(ai(e, wn(e.state)));
3175
3455
  };
3176
3456
  return n(), window.addEventListener("resize", n), window.addEventListener("scroll", n, !0), () => {
3177
3457
  window.removeEventListener("resize", n), window.removeEventListener("scroll", n, !0);
@@ -3207,16 +3487,16 @@ function Ta({ editor: e, focusState: t }) {
3207
3487
  }
3208
3488
  //#endregion
3209
3489
  //#region src/ui/toc/MarkweaveInnerToc.tsx
3210
- function Ea(e, t) {
3490
+ function Ja(e, t) {
3211
3491
  return `${e.toc.itemAriaLabel}: ${t.text}`;
3212
3492
  }
3213
- function Da({ editor: e, state: t, messages: n, editable: r, placement: i }) {
3493
+ function Ya({ editor: e, state: t, messages: n, editable: r, placement: i }) {
3214
3494
  let a = J(null);
3215
- if (G(() => {
3216
- if (!(i !== "container" || !a.current)) return ti(a.current);
3495
+ if (K(() => {
3496
+ if (!(i !== "container" || !a.current)) return bi(a.current);
3217
3497
  }, [i]), !t.items.length) return null;
3218
3498
  let o = (t) => {
3219
- ni(e, t, {
3499
+ xi(e, t, {
3220
3500
  behavior: "smooth",
3221
3501
  focus: r
3222
3502
  });
@@ -3243,7 +3523,7 @@ function Da({ editor: e, state: t, messages: n, editable: r, placement: i }) {
3243
3523
  "data-level": e.level,
3244
3524
  "data-active": e.active ? "true" : "false",
3245
3525
  "aria-current": e.active ? "location" : void 0,
3246
- "aria-label": Ea(n, e),
3526
+ "aria-label": Ja(n, e),
3247
3527
  title: e.text,
3248
3528
  onClick: () => o(e),
3249
3529
  children: e.text
@@ -3254,7 +3534,7 @@ function Da({ editor: e, state: t, messages: n, editable: r, placement: i }) {
3254
3534
  }
3255
3535
  //#endregion
3256
3536
  //#region src/MarkweaveEditor.tsx
3257
- var Oa = {
3537
+ var Xa = {
3258
3538
  active: !1,
3259
3539
  mode: "outside",
3260
3540
  activeCellPos: null,
@@ -3262,21 +3542,21 @@ var Oa = {
3262
3542
  selectedCellCount: 0,
3263
3543
  selectionFrom: 0,
3264
3544
  selectionTo: 0
3265
- }, ka = {
3545
+ }, Za = {
3266
3546
  active: !1,
3267
- language: Lt.defaultLanguage,
3547
+ language: Vt.defaultLanguage,
3268
3548
  mermaidPreviewMode: "code",
3269
3549
  pos: null,
3270
3550
  text: ""
3271
- }, Aa = Gt({
3551
+ }, Qa = Yt({
3272
3552
  active: !1,
3273
3553
  mode: "code",
3274
3554
  source: ""
3275
3555
  });
3276
- function ja(e) {
3277
- return Sn.getState(e.state) ?? xn;
3556
+ function $a(e) {
3557
+ return En.getState(e.state) ?? Tn;
3278
3558
  }
3279
- function Ma(e) {
3559
+ function eo(e) {
3280
3560
  if (!e || typeof window > "u") return null;
3281
3561
  let t = e.parentElement;
3282
3562
  for (; t;) {
@@ -3286,141 +3566,143 @@ function Ma(e) {
3286
3566
  }
3287
3567
  return null;
3288
3568
  }
3289
- function Na(e) {
3569
+ function to(e) {
3290
3570
  return typeof window > "u" || typeof window.requestAnimationFrame != "function" ? globalThis.setTimeout(() => e(0), 0) : window.requestAnimationFrame(e);
3291
3571
  }
3292
- function Pa(e) {
3572
+ function no(e) {
3293
3573
  if (typeof window < "u" && typeof window.cancelAnimationFrame == "function") {
3294
3574
  window.cancelAnimationFrame(e);
3295
3575
  return;
3296
3576
  }
3297
3577
  globalThis.clearTimeout(e);
3298
3578
  }
3299
- function Fa({ ariaLabel: e, autoFocusFirstTableBodyCell: i = !1, autofocus: a = !1, content: o, contentFormat: c, defaultContent: l = "", defaultContentFormat: u, editable: d = !0, innerToc: f = !0, innerTocPlacement: p, lang: m, mode: h = "live", theme: g, canvasColor: _, onEditWithAi: v, onExtractToNote: y, onRewriteSelection: b, onRuntimeStateChange: x, onSearchControllerChange: S, onSlashCommandUpload: C, onTableCommandResult: w, onTableCopyPayload: T, onTocChange: E, onUpdate: D, linkCardResolver: O, resolveMediaSource: k } = {}) {
3300
- let A = et(h), j = ii(g), M = ri(_), ee = ei(p), N = A === "live" && d !== !1, te = yt(o === void 0 ? u : c), P = o ?? l, ne = typeof P == "string" && P.length >= 2e5, F = o === void 0 && te === "markdown" && ne && typeof P == "string", I = J(F ? P : null), [L, re] = Y(F), R = J({
3301
- editorMode: A,
3579
+ function ro({ askAi: e, ariaLabel: i, autoFocusFirstTableBodyCell: a = !1, autofocus: o = !1, content: c, contentFormat: l, defaultContent: u = "", defaultContentFormat: d, editable: f = !0, innerToc: p = !0, innerTocPlacement: m, lang: h, mode: g = "live", theme: _, canvasColor: v, onEditWithAi: y, onExtractToNote: b, onRewriteSelection: x, onAiEditControllerChange: S, onRuntimeStateChange: C, onSearchControllerChange: w, onSlashCommandUpload: T, onTableCommandResult: E, onTableCopyPayload: D, onTocChange: O, onUpdate: k, linkCardResolver: A, resolveMediaSource: ee } = {}) {
3580
+ let j = rt(g), te = Ci(_), M = Si(v), ne = yi(m), N = j === "live" && f !== !1, re = Ct(c === void 0 ? d : l), ie = c ?? u, P = typeof ie == "string" && ie.length >= 2e5, F = c === void 0 && re === "markdown" && P && typeof ie == "string", ae = J(F ? ie : null), [I, oe] = Y(F), L = J({
3581
+ editorMode: j,
3302
3582
  effectiveEditable: N
3303
3583
  });
3304
- R.current = {
3305
- editorMode: A,
3584
+ L.current = {
3585
+ editorMode: j,
3306
3586
  effectiveEditable: N
3307
3587
  };
3308
- let ie = J(null);
3309
- ie.current === null && (ie.current = r(m));
3310
- let ae = ie.current, z = q(() => n(ae), [ae]), B = q(() => t(ae), [ae]), oe = J(C);
3311
- oe.current = C;
3312
- let se = J(S);
3313
- se.current = S;
3314
- let ce = J(O);
3315
- ce.current = O;
3316
- let le = q(() => ki({
3317
- lang: ae,
3588
+ let R = J(null);
3589
+ R.current === null && (R.current = r(h));
3590
+ let z = R.current, B = q(() => n(z), [z]), se = q(() => t(z), [z]), ce = J(T);
3591
+ ce.current = T;
3592
+ let le = J(w);
3593
+ le.current = w;
3594
+ let ue = J(S);
3595
+ ue.current = S;
3596
+ let de = J(A);
3597
+ de.current = A;
3598
+ let V = q(() => Yi({
3599
+ lang: z,
3318
3600
  onImageUpload: (e) => {
3319
- if (oe.current) return oe.current(e);
3320
- let t = Le(e);
3601
+ if (ce.current) return ce.current(e);
3602
+ let t = Be(e);
3321
3603
  if (!t) throw Error("File upload requires an upload handler.");
3322
3604
  return t;
3323
3605
  },
3324
3606
  onVideoUpload: (e) => {
3325
- if (oe.current) return oe.current(e);
3326
- let t = Le(e);
3607
+ if (ce.current) return ce.current(e);
3608
+ let t = Be(e);
3327
3609
  if (!t) throw Error("File upload requires an upload handler.");
3328
3610
  return t;
3329
3611
  },
3330
- linkCardResolver: (e) => ce.current?.(e) ?? Promise.resolve(null),
3331
- resolveMediaSource: k
3332
- }), [k, ae]), [V, ue] = Y(null), [H, U] = Y(hn), [de, fe] = Y(null), [pe, me] = Y(null), [he, ge] = Y("code"), [_e, ve] = Y(null), [ye, be] = Y(xn), [xe, Se] = Y(null), [Ce, we] = Y(0), Te = J(!1), Ee = J({
3333
- content: o,
3334
- format: te
3335
- }), De = J(null), Oe = J(null), ke = J({ onUpdate: D }), Ae = q(() => an(H.query, B), [B, H.query]);
3336
- ke.current = { onUpdate: D }, Ee.current = {
3337
- content: o,
3338
- format: te
3612
+ linkCardResolver: (e) => de.current?.(e) ?? Promise.resolve(null),
3613
+ resolveMediaSource: ee
3614
+ }), [ee, z]), [H, fe] = Y(null), [U, W] = Y(yn), [pe, me] = Y(null), [he, ge] = Y(null), [_e, ve] = Y("code"), [ye, be] = Y(null), [xe, Se] = Y(Tn), [Ce, we] = Y(null), [Te, Ee] = Y(0), De = J(!1), Oe = J({
3615
+ content: c,
3616
+ format: re
3617
+ }), ke = J(null), Ae = J(null), je = J({ onUpdate: k }), Me = q(() => ln(U.query, se), [se, U.query]);
3618
+ je.current = { onUpdate: k }, Oe.current = {
3619
+ content: c,
3620
+ format: re
3339
3621
  };
3340
- let je = W(() => {
3341
- Oe.current !== null && (window.clearTimeout(Oe.current), Oe.current = null), we((e) => e + 1);
3342
- }, []), Me = W(() => {
3343
- Oe.current !== null && window.clearTimeout(Oe.current), Oe.current = window.setTimeout(() => {
3344
- Oe.current = null, we((e) => e + 1);
3345
- }, At);
3622
+ let Ne = G(() => {
3623
+ Ae.current !== null && (window.clearTimeout(Ae.current), Ae.current = null), Ee((e) => e + 1);
3624
+ }, []), Pe = G(() => {
3625
+ Ae.current !== null && window.clearTimeout(Ae.current), Ae.current = window.setTimeout(() => {
3626
+ Ae.current = null, Ee((e) => e + 1);
3627
+ }, Pt);
3346
3628
  }, []);
3347
- G(() => () => {
3348
- Oe.current !== null && window.clearTimeout(Oe.current);
3629
+ K(() => () => {
3630
+ Ae.current !== null && window.clearTimeout(Ae.current);
3349
3631
  }, []);
3350
- let Ne = W(() => {
3351
- fe(null), me(null), U(hn);
3352
- }, []), Pe = W((e) => {
3353
- let t = pn(e.state);
3632
+ let Fe = G(() => {
3633
+ me(null), ge(null), W(yn);
3634
+ }, []), Ie = G((e) => {
3635
+ let t = _n(e.state);
3354
3636
  if (!t) {
3355
- U((e) => e.name === "idle" ? e : hn), fe(null), me(null);
3637
+ W((e) => e.name === "idle" ? e : yn), me(null), ge(null);
3356
3638
  return;
3357
3639
  }
3358
3640
  let n = e.coordsAtPos(t.cursor), r = e.coordsAtPos(t.triggerFrom), i = e.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
3359
- if (!mn(r, { frameRect: i })) {
3360
- fe(null), me(null), U(hn);
3641
+ if (!vn(r, { frameRect: i })) {
3642
+ me(null), ge(null), W(yn);
3361
3643
  return;
3362
3644
  }
3363
- let a = fn(n, {
3645
+ let a = gn(n, {
3364
3646
  frameRect: i,
3365
3647
  triggerRect: r
3366
3648
  });
3367
- fe((e) => ln(e, a) ? e : a), U((e) => dn(e, t));
3368
- }, []), K = W((e) => Pe(e.view), [Pe]), Fe = W((e) => {
3369
- let t = Dt(e);
3370
- ue((e) => Ct(e, t) ? e : t);
3371
- let n = $t(e);
3372
- n && (tn(e, n, !0), ve(n));
3373
- let r = Ft(e);
3374
- r.active && r.language === "mermaid" && ge(r.mermaidPreviewMode);
3375
- }, []), Ie = W((e) => {
3376
- be(ja(e));
3649
+ me((e) => pn(e, a) ? e : a), W((e) => hn(e, t));
3650
+ }, []), Le = G((e) => Ie(e.view), [Ie]), Re = G((e) => {
3651
+ let t = jt(e);
3652
+ fe((e) => Dt(e, t) ? e : t);
3653
+ let n = rn(e);
3654
+ n && (on(e, n, !0), be(n));
3655
+ let r = zt(e);
3656
+ r.active && r.language === "mermaid" && ve(r.mermaidPreviewMode);
3657
+ }, []), ze = G((e) => {
3658
+ Se($a(e));
3377
3659
  }, []), X = s({
3378
3660
  shouldRerenderOnTransaction: !1,
3379
- extensions: le,
3380
- content: F ? "" : P,
3381
- contentType: gt(te),
3661
+ extensions: V,
3662
+ content: F ? "" : ie,
3663
+ contentType: bt(re),
3382
3664
  editable: N,
3383
- autofocus: a,
3665
+ autofocus: o,
3384
3666
  editorProps: {
3385
3667
  attributes: {
3386
3668
  class: "markweave-editor-surface",
3387
3669
  "data-testid": "markweave-editor-surface",
3388
- "data-markweave-large-document": ne ? "true" : "false",
3670
+ "data-markweave-large-document": P ? "true" : "false",
3389
3671
  autocapitalize: "off",
3390
3672
  autocorrect: "off",
3391
3673
  spellcheck: "false",
3392
3674
  translate: "no"
3393
3675
  },
3394
- handleClick: (e, t, n) => R.current.effectiveEditable ? !1 : bt(n),
3676
+ handleClick: (e, t, n) => L.current.effectiveEditable ? !1 : wt(n),
3395
3677
  handleDOMEvents: {
3396
- compositionstart: () => R.current.effectiveEditable ? (U((e) => gn(e, { type: "composition-start" })), fe(null), !1) : !1,
3397
- compositionend: (e) => (R.current.effectiveEditable && window.setTimeout(() => Pe(e), 0), !1),
3678
+ compositionstart: () => L.current.effectiveEditable ? (W((e) => bn(e, { type: "composition-start" })), me(null), !1) : !1,
3679
+ compositionend: (e) => (L.current.effectiveEditable && window.setTimeout(() => Ie(e), 0), !1),
3398
3680
  click: (e, t) => {
3399
- if (R.current.effectiveEditable) {
3400
- let n = Qt(e, t);
3401
- return n ? (t.preventDefault(), t.stopPropagation(), Ne(), nn(e, n, !0), rn(e, n), ve(n), !0) : (ve(null), !1);
3681
+ if (L.current.effectiveEditable) {
3682
+ let n = nn(e, t);
3683
+ return n ? (t.preventDefault(), t.stopPropagation(), Fe(), sn(e, n, !0), cn(e, n), be(n), !0) : (be(null), !1);
3402
3684
  }
3403
- return bt(t);
3685
+ return wt(t);
3404
3686
  }
3405
3687
  }
3406
3688
  },
3407
3689
  onSelectionUpdate: ({ editor: e }) => {
3408
- Fe(e);
3690
+ Re(e);
3409
3691
  },
3410
3692
  onCreate: ({ editor: e }) => {
3411
- i && R.current.effectiveEditable && vn(e), Ie(e), Fe(e), je();
3693
+ a && L.current.effectiveEditable && Sn(e), ze(e), Re(e), Ne();
3412
3694
  },
3413
3695
  onTransaction: ({ editor: e, transaction: t }) => {
3414
- Ie(e), (t.docChanged || Vt(t)) && Me(), t.docChanged && ve((t) => {
3696
+ ze(e), (t.docChanged || Gt(t)) && Pe(), t.docChanged && be((t) => {
3415
3697
  if (!t) return null;
3416
- let n = Zt(e, t.pos);
3698
+ let n = tn(e, t.pos);
3417
3699
  return n?.kind === t.kind ? n : null;
3418
3700
  });
3419
3701
  },
3420
3702
  onUpdate: ({ editor: e }) => {
3421
- Fe(e), R.current.effectiveEditable && K(e), Te.current || ke.current.onUpdate?.(ht(e, { onContentRead: (t, n) => {
3422
- let r = Ee.current;
3423
- r.content !== void 0 && t === r.format && (De.current = {
3703
+ Re(e), L.current.effectiveEditable && Le(e), De.current || je.current.onUpdate?.(yt(e, { onContentRead: (t, n) => {
3704
+ let r = Oe.current;
3705
+ r.content !== void 0 && t === r.format && (ke.current = {
3424
3706
  content: n,
3425
3707
  format: t,
3426
3708
  doc: e.state.doc
@@ -3428,15 +3710,15 @@ function Fa({ ariaLabel: e, autoFocusFirstTableBodyCell: i = !1, autofocus: a =
3428
3710
  } }));
3429
3711
  }
3430
3712
  });
3431
- G(() => {
3432
- let e = I.current;
3713
+ K(() => {
3714
+ let e = ae.current;
3433
3715
  if (!X || !e) return;
3434
3716
  let t = !1;
3435
3717
  return (async () => {
3436
- Te.current = !0;
3718
+ De.current = !0;
3437
3719
  try {
3438
3720
  let n = !0;
3439
- for (let r of ai(e)) {
3721
+ for (let r of wi(e)) {
3440
3722
  if (await new Promise((e) => window.setTimeout(e, 0)), t) return;
3441
3723
  let e = X.markdown?.parse(r);
3442
3724
  if (!e) throw Error("Markdown parser is unavailable.");
@@ -3444,359 +3726,367 @@ function Fa({ ariaLabel: e, autoFocusFirstTableBodyCell: i = !1, autofocus: a =
3444
3726
  X.view.dispatch(a.setMeta("addToHistory", !1)), n = !1;
3445
3727
  }
3446
3728
  if (t) return;
3447
- Fe(X), Ie(X), je(), I.current = null, re(!1);
3729
+ Re(X), ze(X), Ne(), ae.current = null, oe(!1);
3448
3730
  } finally {
3449
- Te.current = !1;
3731
+ De.current = !1;
3450
3732
  }
3451
3733
  })().catch(() => {
3452
3734
  t || (X.commands.setContent(e, {
3453
3735
  contentType: "markdown",
3454
3736
  emitUpdate: !1
3455
- }), I.current = null, re(!1));
3737
+ }), ae.current = null, oe(!1));
3456
3738
  }), () => {
3457
3739
  t = !0;
3458
3740
  };
3459
3741
  }, [
3460
3742
  X,
3461
- je,
3462
- Fe,
3463
- Ie
3464
- ]), G(() => {
3465
- if (X) return se.current?.(oi(X)), () => {
3466
- se.current?.(null);
3743
+ Ne,
3744
+ Re,
3745
+ ze
3746
+ ]), K(() => {
3747
+ if (X) return le.current?.(Ti(X)), () => {
3748
+ le.current?.(null);
3749
+ };
3750
+ }, [X]), K(() => {
3751
+ if (X) return ue.current?.(Ei(X)), () => {
3752
+ ue.current?.(null);
3467
3753
  };
3468
- }, [X]), G(() => {
3754
+ }, [X]), K(() => {
3469
3755
  if (!X) return;
3470
- let e = N && !L;
3471
- X.setEditable(e), tt(X, {
3472
- mode: A,
3756
+ let e = N && !I;
3757
+ X.setEditable(e), it(X, {
3758
+ mode: j,
3473
3759
  editable: e
3474
- }), Ut(X, e ? "live" : "view"), je(), N || Ne();
3760
+ }), qt(X, e ? "live" : "view"), Ne(), N || Fe();
3475
3761
  }, [
3476
- Ne,
3762
+ Fe,
3477
3763
  X,
3478
- A,
3764
+ j,
3479
3765
  N,
3480
- je,
3481
- L
3482
- ]), G(() => {
3483
- X && Ht(X, j);
3484
- }, [X, j]), G(() => {
3485
- let e = yt(c);
3486
- if (!(!X || o === void 0)) {
3487
- if (vt(X, De.current, o, e)) {
3488
- De.current = null;
3766
+ Ne,
3767
+ I
3768
+ ]), K(() => {
3769
+ X && Kt(X, te);
3770
+ }, [X, te]), K(() => {
3771
+ let e = Ct(l);
3772
+ if (!(!X || c === void 0)) {
3773
+ if (St(X, ke.current, c, e)) {
3774
+ ke.current = null;
3489
3775
  return;
3490
3776
  }
3491
- De.current = null, !_t(X, o, e) && (Te.current = !0, X.commands.setContent(o, {
3492
- contentType: gt(e),
3777
+ ke.current = null, !xt(X, c, e) && (De.current = !0, X.commands.setContent(c, {
3778
+ contentType: bt(e),
3493
3779
  emitUpdate: !1
3494
- }), Te.current = !1, Fe(X), N && K(X), Ie(X), je());
3780
+ }), De.current = !1, Re(X), N && Le(X), ze(X), Ne());
3495
3781
  }
3496
3782
  }, [
3497
- o,
3498
3783
  c,
3784
+ l,
3499
3785
  N,
3500
3786
  X,
3501
- je,
3502
- Fe,
3503
- K,
3504
- Ie
3505
- ]), G(() => {
3506
- if (!de) return;
3787
+ Ne,
3788
+ Re,
3789
+ Le,
3790
+ ze
3791
+ ]), K(() => {
3792
+ if (!pe) return;
3507
3793
  let e = (e) => {
3508
3794
  let t = e.target;
3509
- t instanceof Element && (t.closest(".markweave-slash-menu") || t.closest(".markweave-slash-trigger") || Ne());
3795
+ t instanceof Element && (t.closest(".markweave-slash-menu") || t.closest(".markweave-slash-trigger") || Fe());
3510
3796
  };
3511
3797
  return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
3512
- }, [Ne, de]);
3513
- let Re = de !== null;
3514
- G(() => {
3515
- if (!X || !Re) return;
3516
- let e = mt(() => {
3517
- X.isDestroyed || Pe(X.view);
3798
+ }, [Fe, pe]);
3799
+ let Ve = pe !== null;
3800
+ K(() => {
3801
+ if (!X || !Ve) return;
3802
+ let e = vt(() => {
3803
+ X.isDestroyed || Ie(X.view);
3518
3804
  }), t = () => e.schedule();
3519
3805
  return window.addEventListener("resize", t), window.addEventListener("scroll", t, !0), t(), () => {
3520
3806
  e.cancel(), window.removeEventListener("resize", t), window.removeEventListener("scroll", t, !0);
3521
3807
  };
3522
3808
  }, [
3523
3809
  X,
3524
- Re,
3525
- Pe
3810
+ Ve,
3811
+ Ie
3526
3812
  ]);
3527
- let ze = q(() => X ? Ft(X) : ka, [
3813
+ let He = q(() => X ? zt(X) : Za, [
3528
3814
  X,
3529
- Ce,
3530
- V
3531
- ]), Be = q(() => X ? yn(X.state) : Oa, [
3815
+ Te,
3816
+ H
3817
+ ]), Ue = q(() => X ? Cn(X.state) : Xa, [
3532
3818
  X,
3533
- Ce,
3534
- V,
3535
- ye
3536
- ]), Ve = V?.currentNode === "codeBlock", He = Ve && ze.language === "mermaid", Ue = q(() => X ? Gt({
3537
- active: He,
3538
- mode: he,
3539
- source: ze.text
3540
- }) : Aa, [
3541
- ze.text,
3819
+ Te,
3820
+ H,
3821
+ xe
3822
+ ]), We = H?.currentNode === "codeBlock", Ge = We && He.language === "mermaid", Ke = q(() => X ? Yt({
3823
+ active: Ge,
3824
+ mode: _e,
3825
+ source: He.text
3826
+ }) : Qa, [
3827
+ He.text,
3542
3828
  X,
3543
- He,
3544
- he
3545
- ]), We = q(() => X && x ? _n(X.state) : null, [
3829
+ Ge,
3830
+ _e
3831
+ ]), qe = q(() => X && C ? xn(X.state) : null, [
3546
3832
  X,
3547
- x,
3548
- Ce
3549
- ]), Ge = q(() => X ? Qr(X.state) : Xr.items, [X, Ce]), Ke = q(() => $r(Ge, xe), [xe, Ge]), qe = q(() => Yr(Ge, Ke), [Ke, Ge]), Je = W(() => {
3550
- if (!X || !Ge.length) {
3551
- Se(null);
3833
+ C,
3834
+ Te
3835
+ ]), Je = q(() => X ? _i(X.state) : hi.items, [X, Te]), Ye = q(() => vi(Je, Ce), [Ce, Je]), Xe = q(() => mi(Je, Ye), [Ye, Je]), Ze = G(() => {
3836
+ if (!X || !Je.length) {
3837
+ we(null);
3552
3838
  return;
3553
3839
  }
3554
- let e = Zr(X, Ge);
3555
- Se((t) => t === e ? t : e);
3556
- }, [X, Ge]);
3557
- G(() => {
3558
- Se((e) => {
3559
- let t = $r(Ge, e);
3840
+ let e = gi(X, Je);
3841
+ we((t) => t === e ? t : e);
3842
+ }, [X, Je]);
3843
+ K(() => {
3844
+ we((e) => {
3845
+ let t = vi(Je, e);
3560
3846
  return e === t ? e : t;
3561
3847
  });
3562
- }, [Ge]), G(() => {
3563
- if (!X || !Ge.length || typeof window > "u") return;
3848
+ }, [Je]), K(() => {
3849
+ if (!X || !Je.length || typeof window > "u") return;
3564
3850
  let e = null, t = () => {
3565
- e !== null && Pa(e), e = Na(() => {
3566
- e = null, Je();
3851
+ e !== null && no(e), e = to(() => {
3852
+ e = null, Ze();
3567
3853
  });
3568
- }, n = Ma(X.view.dom);
3854
+ }, n = eo(X.view.dom);
3569
3855
  return window.addEventListener("scroll", t, { passive: !0 }), window.addEventListener("resize", t), n?.addEventListener("scroll", t, { passive: !0 }), t(), () => {
3570
- window.removeEventListener("scroll", t), window.removeEventListener("resize", t), n?.removeEventListener("scroll", t), e !== null && Pa(e);
3856
+ window.removeEventListener("scroll", t), window.removeEventListener("resize", t), n?.removeEventListener("scroll", t), e !== null && no(e);
3571
3857
  };
3572
3858
  }, [
3573
3859
  X,
3574
- Ge.length,
3575
- Je
3860
+ Je.length,
3861
+ Ze
3576
3862
  ]);
3577
- let Ye = q(() => xt({
3578
- revision: Ce,
3579
- mode: A,
3863
+ let Qe = q(() => Tt({
3864
+ revision: Te,
3865
+ mode: j,
3580
3866
  editable: N,
3581
- toc: qe,
3582
- selection: V,
3583
- slash: H,
3584
- table: Be,
3585
- tableInteraction: ye,
3586
- codeBlock: ze,
3587
- mermaid: Ue,
3588
- tableDebugSnapshot: We
3867
+ toc: Xe,
3868
+ selection: H,
3869
+ slash: U,
3870
+ table: Ue,
3871
+ tableInteraction: xe,
3872
+ codeBlock: He,
3873
+ mermaid: Ke,
3874
+ tableDebugSnapshot: qe
3589
3875
  }), [
3590
- ze,
3591
- A,
3876
+ He,
3877
+ j,
3592
3878
  N,
3593
- Ue,
3594
- Ce,
3595
- V,
3879
+ Ke,
3880
+ Te,
3596
3881
  H,
3597
- We,
3598
- Be,
3599
- ye,
3600
- qe
3882
+ U,
3883
+ qe,
3884
+ Ue,
3885
+ xe,
3886
+ Xe
3601
3887
  ]);
3602
- G(() => {
3603
- x?.(Ye);
3604
- }, [x, Ye]), G(() => {
3605
- E?.(qe);
3606
- }, [E, qe]);
3607
- let Xe = W((e, t) => {
3608
- if (!(!X || !N) && on(e)) {
3888
+ K(() => {
3889
+ C?.(Qe);
3890
+ }, [C, Qe]), K(() => {
3891
+ O?.(Xe);
3892
+ }, [O, Xe]);
3893
+ let $e = G((e, t) => {
3894
+ if (!(!X || !N) && un(e)) {
3609
3895
  if (e.inputKind && !t?.emoji && !t?.uploadResult) {
3610
- me(e);
3896
+ ge(e);
3611
3897
  return;
3612
3898
  }
3613
- un(X, H, e, t), U((e) => gn(e, { type: "execute" })), Ne();
3899
+ mn(X, U, e, t), W((e) => bn(e, { type: "execute" })), Fe();
3614
3900
  }
3615
3901
  }, [
3616
- Ne,
3902
+ Fe,
3617
3903
  N,
3618
3904
  X,
3619
- H
3620
- ]), Ze = W((e) => {
3621
- U((t) => gn(t, {
3905
+ U
3906
+ ]), et = G((e) => {
3907
+ W((t) => bn(t, {
3622
3908
  type: "set-active",
3623
3909
  index: e,
3624
- optionCount: Ae.length
3910
+ optionCount: Me.length
3625
3911
  }));
3626
- }, [Ae.length]), Qe = W((e) => {
3627
- if (!X || pe || !N) return;
3628
- let t = sn(H, Ae, e.key, { isComposing: e.nativeEvent.isComposing || pt(X.state) });
3912
+ }, [Me.length]), tt = G((e) => {
3913
+ if (!X || he || !N) return;
3914
+ let t = dn(U, Me, e.key, { isComposing: e.nativeEvent.isComposing || _t(X.state) });
3629
3915
  if (t.type !== "ignore") {
3630
3916
  if (t.type === "close") {
3631
- e.preventDefault(), U((e) => gn(e, { type: "escape" })), Ne();
3917
+ e.preventDefault(), W((e) => bn(e, { type: "escape" })), Fe();
3632
3918
  return;
3633
3919
  }
3634
3920
  if (t.type === "move-active") {
3635
- e.preventDefault(), U((e) => gn(e, {
3921
+ e.preventDefault(), W((e) => bn(e, {
3636
3922
  type: "move-active",
3637
3923
  delta: t.delta,
3638
3924
  optionCount: t.optionCount
3639
3925
  }));
3640
3926
  return;
3641
3927
  }
3642
- t.type === "execute-active" && (e.preventDefault(), Xe(t.command));
3928
+ t.type === "execute-active" && (e.preventDefault(), $e(t.command));
3643
3929
  }
3644
3930
  }, [
3645
- Ne,
3931
+ Fe,
3646
3932
  N,
3647
3933
  X,
3648
- Ae,
3649
- Xe,
3650
- pe,
3651
- H
3652
- ]), $e = q(() => ({
3653
- closeSlashMenu: Ne,
3654
- focusFirstTableBodyCell: () => X ? vn(X) : !1,
3934
+ Me,
3935
+ $e,
3936
+ he,
3937
+ U
3938
+ ]), nt = q(() => ({
3939
+ closeSlashMenu: Fe,
3940
+ focusFirstTableBodyCell: () => X ? Sn(X) : !1,
3655
3941
  setContent: (e, t = {}) => {
3656
3942
  if (!X) return !1;
3657
- let n = yt(t.format);
3943
+ let n = Ct(t.format);
3658
3944
  return X.commands.setContent(e, {
3659
- contentType: gt(n),
3945
+ contentType: bt(n),
3660
3946
  emitUpdate: t.emitUpdate ?? !1
3661
- }), t.focusFirstTableBodyCell && vn(X), Fe(X), N && K(X), Ie(X), je(), !0;
3947
+ }), t.focusFirstTableBodyCell && Sn(X), Re(X), N && Le(X), ze(X), Ne(), !0;
3662
3948
  }
3663
3949
  }), [
3664
- Ne,
3950
+ Fe,
3665
3951
  N,
3666
3952
  X,
3667
- je,
3668
- Fe,
3669
- K,
3670
- Ie
3953
+ Ne,
3954
+ Re,
3955
+ Le,
3956
+ ze
3671
3957
  ]);
3672
3958
  return {
3673
3959
  editor: X,
3674
3960
  frameProps: q(() => ({
3675
3961
  className: "markweave-editor-frame",
3676
- "aria-label": e ?? z.common.editorAriaLabel,
3962
+ "aria-label": i ?? B.common.editorAriaLabel,
3677
3963
  "data-testid": "markweave-editor-frame",
3678
- "data-markweave-mode": A,
3679
- "aria-busy": L,
3680
- "data-markweave-large-document-loading": L ? "true" : "false",
3681
- "data-markweave-theme": j,
3964
+ "data-markweave-mode": j,
3965
+ "aria-busy": I,
3966
+ "data-markweave-large-document-loading": I ? "true" : "false",
3967
+ "data-markweave-theme": te,
3682
3968
  style: M ? { "--markweave-canvas": M } : void 0,
3683
- "data-markweave-inner-toc": f ? "true" : "false",
3684
- "data-markweave-inner-toc-placement": ee,
3685
- "data-mermaid-mode": Ue.mode,
3686
- "data-table-focus-mode": Be.mode,
3687
- onKeyDownCapture: Qe
3969
+ "data-markweave-inner-toc": p ? "true" : "false",
3970
+ "data-markweave-inner-toc-placement": ne,
3971
+ "data-mermaid-mode": Ke.mode,
3972
+ "data-table-focus-mode": Ue.mode,
3973
+ onKeyDownCapture: tt
3688
3974
  }), [
3689
- e,
3690
- A,
3691
- Qe,
3692
- f,
3693
- L,
3694
- Ue.mode,
3695
- z.common.editorAriaLabel,
3696
- M,
3697
- ee,
3975
+ i,
3698
3976
  j,
3699
- Be.mode
3977
+ tt,
3978
+ p,
3979
+ I,
3980
+ Ke.mode,
3981
+ B.common.editorAriaLabel,
3982
+ M,
3983
+ ne,
3984
+ te,
3985
+ Ue.mode
3700
3986
  ]),
3701
3987
  overlayProps: q(() => ({
3702
3988
  floatingToolbar: X && N ? {
3703
3989
  editor: X,
3704
- messages: z,
3705
- selectionSnapshot: V,
3706
- onRewriteSelection: b,
3707
- onExtractToNote: y
3990
+ lang: z,
3991
+ messages: B,
3992
+ selectionSnapshot: H,
3993
+ askAi: e,
3994
+ onRewriteSelection: x,
3995
+ onExtractToNote: b
3708
3996
  } : null,
3709
3997
  slashCommandMenu: X && N ? {
3710
- commands: Ae,
3711
- state: H,
3712
- position: de,
3713
- inputCommand: pe,
3714
- messages: z,
3715
- onActiveIndexChange: Ze,
3716
- onInputCommandChange: me,
3717
- onSelect: Xe,
3718
- onUpload: C
3998
+ commands: Me,
3999
+ state: U,
4000
+ position: pe,
4001
+ inputCommand: he,
4002
+ messages: B,
4003
+ onActiveIndexChange: et,
4004
+ onInputCommandChange: ge,
4005
+ onSelect: $e,
4006
+ onUpload: T
3719
4007
  } : null,
3720
4008
  tableControls: X && N ? {
3721
4009
  editor: X,
3722
- active: Be.active,
3723
- interactionState: ye,
3724
- messages: z,
3725
- onCopyPayload: T,
3726
- onCommandResult: w,
3727
- onEditWithAi: v
4010
+ active: Ue.active,
4011
+ interactionState: xe,
4012
+ messages: B,
4013
+ onCopyPayload: D,
4014
+ onCommandResult: E,
4015
+ onEditWithAi: y,
4016
+ askAi: e
3728
4017
  } : null,
3729
4018
  tableSelectionOverlay: X && N ? {
3730
4019
  editor: X,
3731
- focusState: Be
4020
+ focusState: Ue
3732
4021
  } : null,
3733
4022
  codeBlockControls: X ? {
3734
4023
  editor: X,
3735
- active: N && Ve,
3736
- mermaidMode: he,
3737
- onMermaidModeChange: ge,
4024
+ active: N && We,
4025
+ mermaidMode: _e,
4026
+ onMermaidModeChange: ve,
3738
4027
  readOnly: !N
3739
4028
  } : null,
3740
- innerToc: X && f && qe.items.length ? {
4029
+ innerToc: X && p && Xe.items.length ? {
3741
4030
  editor: X,
3742
4031
  editable: N,
3743
- messages: z,
3744
- placement: ee,
3745
- state: qe
4032
+ messages: B,
4033
+ placement: ne,
4034
+ state: Xe
3746
4035
  } : null,
3747
- mathEditorPopover: X && N && _e ? {
4036
+ mathEditorPopover: X && N && ye ? {
3748
4037
  editor: X,
3749
- messages: z,
3750
- target: _e,
3751
- onClose: () => ve(null)
4038
+ messages: B,
4039
+ target: ye,
4040
+ onClose: () => be(null)
3752
4041
  } : null
3753
4042
  }), [
3754
4043
  N,
4044
+ e,
3755
4045
  X,
3756
- Ae,
3757
- f,
3758
- Ve,
3759
- he,
3760
- z,
4046
+ Me,
4047
+ p,
4048
+ We,
3761
4049
  _e,
3762
- v,
4050
+ B,
4051
+ ye,
3763
4052
  y,
3764
4053
  b,
3765
- C,
3766
- w,
4054
+ x,
3767
4055
  T,
3768
- Xe,
3769
- V,
3770
- Ze,
3771
- pe,
3772
- de,
4056
+ E,
4057
+ D,
4058
+ $e,
3773
4059
  H,
3774
- Be,
3775
- ye,
3776
- qe
4060
+ et,
4061
+ he,
4062
+ pe,
4063
+ U,
4064
+ Ue,
4065
+ xe,
4066
+ Xe
3777
4067
  ]),
3778
- runtimeSnapshot: Ye,
3779
- actions: $e
4068
+ runtimeSnapshot: Qe,
4069
+ actions: nt
3780
4070
  };
3781
4071
  }
3782
- function Ia({ className: e, ...t }) {
3783
- let n = Fa(t);
4072
+ function io({ className: e, ...t }) {
4073
+ let n = ro(t);
3784
4074
  if (!n.editor) return null;
3785
4075
  let r = [n.frameProps.className, e].filter(Boolean).join(" ");
3786
4076
  return /* @__PURE__ */ Q("section", {
3787
4077
  ...n.frameProps,
3788
4078
  className: r,
3789
4079
  children: [
3790
- n.overlayProps.floatingToolbar ? /* @__PURE__ */ Z($i, { ...n.overlayProps.floatingToolbar }) : null,
3791
- n.overlayProps.slashCommandMenu ? /* @__PURE__ */ Z(ba, { ...n.overlayProps.slashCommandMenu }) : null,
3792
- n.overlayProps.tableControls ? /* @__PURE__ */ Z(wa, { ...n.overlayProps.tableControls }) : null,
3793
- n.overlayProps.tableSelectionOverlay ? /* @__PURE__ */ Z(Ta, { ...n.overlayProps.tableSelectionOverlay }) : null,
3794
- n.overlayProps.codeBlockControls ? /* @__PURE__ */ Z(Mi, { ...n.overlayProps.codeBlockControls }) : null,
3795
- n.overlayProps.innerToc ? /* @__PURE__ */ Z(Da, { ...n.overlayProps.innerToc }) : null,
3796
- n.overlayProps.mathEditorPopover ? /* @__PURE__ */ Z(da, { ...n.overlayProps.mathEditorPopover }) : null,
4080
+ n.overlayProps.floatingToolbar ? /* @__PURE__ */ Z(ba, { ...n.overlayProps.floatingToolbar }) : null,
4081
+ n.overlayProps.slashCommandMenu ? /* @__PURE__ */ Z(Ha, { ...n.overlayProps.slashCommandMenu }) : null,
4082
+ n.overlayProps.tableControls ? /* @__PURE__ */ Z(Ka, { ...n.overlayProps.tableControls }) : null,
4083
+ n.overlayProps.tableSelectionOverlay ? /* @__PURE__ */ Z(qa, { ...n.overlayProps.tableSelectionOverlay }) : null,
4084
+ n.overlayProps.codeBlockControls ? /* @__PURE__ */ Z(Qi, { ...n.overlayProps.codeBlockControls }) : null,
4085
+ n.overlayProps.innerToc ? /* @__PURE__ */ Z(Ya, { ...n.overlayProps.innerToc }) : null,
4086
+ n.overlayProps.mathEditorPopover ? /* @__PURE__ */ Z(Na, { ...n.overlayProps.mathEditorPopover }) : null,
3797
4087
  /* @__PURE__ */ Z(i, { editor: n.editor })
3798
4088
  ]
3799
4089
  });
3800
4090
  }
3801
4091
  //#endregion
3802
- export { Ia as MarkweaveEditor, ki as createMarkweaveEditorExtensions, ki as createMarkweaveReactEditorExtensions, Fa as useMarkweaveEditorController };
4092
+ export { io as MarkweaveEditor, gt as createMarkweaveAiEditController, Yi as createMarkweaveEditorExtensions, Yi as createMarkweaveReactEditorExtensions, ro as useMarkweaveEditorController };