@markweave/react 0.1.5 → 0.1.7

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,57 +1,59 @@
1
1
  import { createMarkweaveEditorExtensions as e } from "markweave/internal/editor-core/create-editor-extensions";
2
2
  import { EditorContent as t, NodeViewWrapper as n, ReactNodeViewRenderer as r, useEditor as i } from "@tiptap/react";
3
- import { AlertTriangle as a, AlignCenter as o, AlignJustify as s, AlignLeft as c, AlignRight as l, Bold as u, Braces as d, Captions as f, Check as p, CheckCircle2 as m, ChevronDown as h, ChevronUp as g, CircleX as _, Code2 as v, CornerDownLeft as y, Download as b, ExternalLink as x, Eye as S, Heading1 as C, Heading2 as w, Heading3 as T, Image as E, ImageUp as D, IndentDecrease as O, IndentIncrease as k, Info as A, Italic as j, Lightbulb as M, Link2 as N, List as P, ListChecks as F, ListOrdered as I, Minus as ee, MoreVertical as L, Paperclip as R, Quote as te, Replace as z, Sigma as ne, SmilePlus as re, Sparkles as ie, Strikethrough as ae, Subscript as oe, Superscript as se, Table2 as ce, Text as le, Trash2 as ue, Type as de, Underline as fe, Upload as pe, Video as B } from "lucide-react";
4
- import { useCallback as V, useEffect as H, useLayoutEffect as me, useMemo as U, useRef as W, useState as G, useSyncExternalStore as he } from "react";
5
- import { detectUploadSource as ge, getDirectUploadResult as _e, resolveMarkweaveUploadResult as K } from "markweave/internal/plugins/slash-command/upload";
6
- import { MarkweaveCoreImage as q, MarkweaveCoreVideo as ve, attrsFromMarkweaveImageUploadResult as ye, attrsFromMarkweaveVideoUploadResult as be, attrsFromMarkweaveVideoUrl as xe, clampMarkweaveImageWidth as Se, createMarkweaveImageUploadRequest as Ce, createMarkweaveVideoUploadRequest as J, downloadMarkweaveImage as we, markweaveVideoIframeAllow as Te, normalizeMarkweaveCoreImageAlign as Ee, normalizeMarkweaveVideoEmbedUrl as De, numberAttribute as Oe, stringAttribute as Y } from "markweave/internal/plugins/media/core-media-nodes";
7
- import { getLocalizedSlashCommandSpecs as ke, getMarkweaveMessages as Ae, normalizeMarkweaveLang as je } from "markweave/internal/i18n";
8
- import { getMarkweaveEditorModeState as Me, isMarkweaveEditorLiveEditable as Ne, normalizeMarkweaveEditorMode as Pe, setMarkweaveEditorModeState as Fe, subscribeToMarkweaveEditorMode as Ie } from "markweave/internal/core/editor-mode-state";
3
+ import { AlertTriangle as a, AlignCenter as o, AlignJustify as s, AlignLeft as c, AlignRight as l, Bold as u, Braces as d, Captions as f, Check as p, CheckCircle2 as m, ChevronDown as h, ChevronUp as g, CircleX as _, Code2 as v, CornerDownLeft as y, Download as b, ExternalLink as x, Eye as S, Heading1 as C, Heading2 as w, Heading3 as T, Image as E, ImageUp as D, IndentDecrease as O, IndentIncrease as ee, Info as k, Italic as A, Lightbulb as j, Link2 as te, List as M, ListChecks as N, ListOrdered as ne, Minus as P, MoreVertical as F, Paperclip as I, Quote as re, Replace as L, Sigma as R, SmilePlus as ie, Sparkles as ae, Strikethrough as oe, Subscript as z, Superscript as se, Table2 as ce, Text as le, Trash2 as ue, Type as de, Underline as fe, Upload as pe, Video as me } from "lucide-react";
4
+ import { useCallback as B, useEffect as V, useLayoutEffect as he, useMemo as H, useRef as U, useState as W, useSyncExternalStore as ge } from "react";
5
+ import { detectUploadSource as _e, getDirectUploadResult as ve, resolveMarkweaveUploadResult as G } from "markweave/internal/plugins/slash-command/upload";
6
+ import { MarkweaveCoreImage as ye, MarkweaveCoreVideo as be, attrsFromMarkweaveImageUploadResult as K, attrsFromMarkweaveVideoUploadResult as xe, attrsFromMarkweaveVideoUrl as Se, clampMarkweaveImageWidth as Ce, createMarkweaveImageUploadRequest as we, createMarkweaveVideoUploadRequest as q, downloadMarkweaveImage as Te, markweaveVideoIframeAllow as Ee, normalizeMarkweaveCoreImageAlign as De, normalizeMarkweaveVideoEmbedUrl as Oe, numberAttribute as ke, stringAttribute as J } from "markweave/internal/plugins/media/core-media-nodes";
7
+ import { getLocalizedSlashCommandSpecs as Ae, getMarkweaveMessages as je, normalizeMarkweaveLang as Me } from "markweave/internal/i18n";
8
+ import { getMarkweaveEditorModeState as Y, isMarkweaveEditorLiveEditable as Ne, normalizeMarkweaveEditorMode as Pe, setMarkweaveEditorModeState as Fe, subscribeToMarkweaveEditorMode as Ie } from "markweave/internal/core/editor-mode-state";
9
9
  import { openMarkweaveImagePreview as Le } from "markweave/internal/plugins/media/image-preview";
10
10
  import { Fragment as X, jsx as Z, jsxs as Q } from "react/jsx-runtime";
11
11
  import { createMarkweaveAdapterMediaExtensions as Re } from "markweave/internal/plugins/media/media-extension-factory";
12
12
  import { isEditorComposing as ze } from "markweave/internal/editor-core/composition-guard";
13
- import { createMarkweaveEditorUpdatePayload as Be, getMarkweaveContentType as Ve, isEditorContentCurrent as He, normalizeMarkweaveContentFormat as Ue } from "markweave/internal/editor-core/editor-content";
14
- import { openMarkweaveReadonlyLinkFromEvent as We } from "markweave/internal/editor-core/readonly-link";
15
- import { createMarkweaveEditorRuntimeSnapshot as Ge } from "markweave/internal/editor-core/runtime-snapshot";
16
- import { advanceFloatingToolbarMotionState as Ke, calculateFloatingToolbarFrameShift as qe, calculateFloatingToolbarTopBoundary as Je, createSelectionSnapshot as Ye, getFloatingToolbarFloatingOptions as Xe, getFloatingToolbarState as Ze, shouldShowFloatingToolbar as Qe, transitionFloatingToolbarState as $e } from "markweave/internal/editor-core/selection-state";
17
- import { codeBlockCollapsePluginKey as et, copyActiveCodeBlock as tt, getActiveCodeBlockState as nt, getCodeBlockCopyFeedbackSnapshot as rt, markweaveCodeBlockBehavior as it, setCodeBlockCollapsedAtPosition as at, setCodeBlockLanguageAtPosition as ot, setCodeBlockMermaidPreviewModeAtPosition as st } from "markweave/internal/plugins/codeblock/codeblock-behavior";
18
- import { isMermaidInlinePreviewTransaction as ct, setMermaidInlinePreviewEditorMode as lt, setReadonlyMermaidPreviewMode as ut } from "markweave/internal/plugins/mermaid/mermaid-inline-preview";
19
- import { getMermaidPreviewState as dt } from "markweave/internal/plugins/mermaid/mermaid-renderer";
20
- import { applyMarkweaveMathLatex as ft, calculateMarkweaveMathPopoverPosition as pt, getMarkweaveMathAnchorRect as mt, getMarkweaveMathBlockIndex as ht, getMarkweaveMathRenderedHtml as gt, getMarkweaveMathTargetAtPos as _t, getMarkweaveMathTargetFromDomEvent as vt, getMarkweaveMathTargetFromSelection as yt, renderMarkweaveMathPreview as bt, setMarkweaveMathEditingDomState as xt, setMarkweaveMathEditingDomStateInView as St, setMarkweaveMathSelectionInView as Ct } from "markweave/internal/plugins/math/math-ui-model";
21
- import { filterSlashCommands as wt, isExecutableSlashCommand as Tt } from "markweave/internal/plugins/slash-command/command-spec";
22
- import { getSlashCommandKeyboardAction as Et, isSlashCommandMenuState as Dt } from "markweave/internal/plugins/slash-command/slash-keyboard";
23
- import { executeSlashCommand as Ot, getNextSlashCommandState as kt, getSlashCommandAnchoredMenuPosition as At, getSlashCommandContext as jt } from "markweave/internal/plugins/slash-command/slash-runtime";
24
- import { initialSlashCommandState as Mt, reduceSlashCommandState as Nt } from "markweave/internal/plugins/slash-command/slash-state";
25
- import { getFirstTableDebugSnapshot as Pt } from "markweave/internal/plugins/table/table-debug-snapshot";
26
- import { focusFirstTableBodyCell as Ft } from "markweave/internal/plugins/table/table-focus-position";
27
- import { getTableFocusState as It } from "markweave/internal/plugins/table/table-focus-state";
28
- import { getTableSelectionOverlayState as Lt, initialTableInteractionState as Rt, tableInteractionPluginKey as zt } from "markweave/internal/plugins/table/table-interaction-layer";
29
- import { calculateCodeBlockLanguageMenuPosition as Bt, clampFullscreenScale as Vt, codeBlockCopyFeedbackTimeoutMs as Ht, copyCodeBlockText as Ut, createCodeBlockOverlayPosition as Wt, createMermaidFullscreenViewerState as Gt, createMermaidTabPosition as Kt, focusCodeBlockTarget as qt, formatCodeBlockLanguageLabel as Jt, formatFullscreenZoom as Yt, getActiveCodeBlockElement as Xt, getAnchoredRect as Zt, getCodeBlockLanguageItems as Qt, getCodeBlockPositionFromEventTarget as $t, getCodeBlockStateAtPosition as en, getFrameElement as tn, getMermaidCodeBlockTargets as nn, getMermaidSvgMarkup as rn, isCodeBlockTargetCollapsed as an, mergeStableMermaidTabPositions as on, mermaidFullscreenZoomStep as sn, moveMermaidFullscreenViewer as cn } from "markweave/internal/plugins/codeblock/codeblock-ui-model";
30
- import { BubbleMenu as ln } from "@tiptap/react/menus";
31
- import { applyFloatingToolbarLink as un, createFloatingToolbarAssistantRequest as dn, getFloatingToolbarButtonModels as fn, getFloatingToolbarHighlightColorOptions as pn, getFloatingToolbarLinkHref as mn, getFloatingToolbarMessageSet as hn, getFloatingToolbarMoreActions as gn, getFloatingToolbarTextColorOptions as _n, getFloatingToolbarTooltipModel as vn, getFloatingToolbarTurnIntoOptions as yn, isFloatingToolbarMoreActionActive as bn, isFloatingToolbarTurnIntoActive as xn, openFloatingToolbarLinkHref as Sn, preventFloatingToolbarPointerFocusLoss as Cn, removeFloatingToolbarLink as wn, runFloatingToolbarMoreAction as Tn, setFloatingToolbarHighlightColor as En, setFloatingToolbarTextColor as Dn, setFloatingToolbarTurnInto as On } from "markweave/internal/editor-core/floating-toolbar-model";
32
- import { normalizeMarkdownLinkHref as kn } from "markweave/internal/plugins/markdown/markdown-input";
33
- import { setMarkweaveTableMenuAxisTarget as An } from "markweave/internal/plugins/table/table-clipboard";
34
- import { calculateAnchoredTableMenuPosition as jn, calculateTableEdgeHandlePosition as Mn, canRunTableCommand as Nn, executeTableMenuCommand as Pn, formatTableCopyFeedback as Fn, getActiveTableElement as In, getAvailableCellMenuCommandSpecs as Ln, getTableAxisTargetRect as Rn, getTableControlAxisSelectionModel as zn, getTableEditWithAiRequest as Bn, getTableMenuItemGroup as Vn, getTableMenuItemLabel as Hn, getTableMenuItems as Un, getTableSelectionTargetRect as Wn, measureTableSelectionOverlay as Gn, selectTableAxisFromCell as Kn, tableCopyFeedbackTimeoutMs as qn, tableMenuLabel as Jn } from "markweave/internal/plugins/table/table-ui-model";
35
- import { createMarkweaveTocState as Yn, emptyMarkweaveTocState as Xn, getActiveMarkweaveTocId as Zn, getMarkweaveTocItems as Qn, getValidMarkweaveTocActiveId as $n, normalizeMarkweaveInnerTocPlacement as er, observeMarkweaveInnerTocContainerPosition as tr, scrollToMarkweaveTocItem as nr } from "markweave/internal/core/toc-state";
13
+ import { createMarkweaveEditorUpdatePayload as Be, getMarkweaveContentType as Ve, isEditorContentCurrent as He, isMarkweaveControlledContentEchoCurrent as Ue, normalizeMarkweaveContentFormat as We } from "markweave/internal/editor-core/editor-content";
14
+ import { openMarkweaveReadonlyLinkFromEvent as Ge } from "markweave/internal/editor-core/readonly-link";
15
+ import { createMarkweaveEditorRuntimeSnapshot as Ke } from "markweave/internal/editor-core/runtime-snapshot";
16
+ import { advanceFloatingToolbarMotionState as qe, areEditorSelectionSnapshotsEquivalent as Je, calculateFloatingToolbarFrameShift as Ye, calculateFloatingToolbarPopoverPlacement as Xe, calculateFloatingToolbarTopBoundary as Ze, createSelectionSnapshot as Qe, getFloatingToolbarFloatingOptions as $e, getFloatingToolbarState as et, markweaveRuntimeProjectionDelayMs as tt, shouldShowFloatingToolbar as nt, transitionFloatingToolbarState as rt } from "markweave/internal/editor-core/selection-state";
17
+ import { codeBlockCollapsePluginKey as it, copyActiveCodeBlock as at, getActiveCodeBlockState as ot, getCodeBlockCopyFeedbackSnapshot as st, markweaveCodeBlockBehavior as ct, setCodeBlockCollapsedAtPosition as lt, setCodeBlockLanguageAtPosition as ut, setCodeBlockMermaidPreviewModeAtPosition as dt } from "markweave/internal/plugins/codeblock/codeblock-behavior";
18
+ import { isMermaidInlinePreviewTransaction as ft, setMarkweaveMermaidTheme as pt, setMermaidInlinePreviewEditorMode as mt, setReadonlyMermaidPreviewMode as ht } from "markweave/internal/plugins/mermaid/mermaid-inline-preview";
19
+ import { getMermaidPreviewState as gt } from "markweave/internal/plugins/mermaid/mermaid-renderer";
20
+ import { applyMarkweaveMathLatex as _t, calculateMarkweaveMathPopoverPosition as vt, getMarkweaveMathAnchorRect as yt, getMarkweaveMathBlockIndex as bt, getMarkweaveMathRenderedHtml as xt, getMarkweaveMathTargetAtPos as St, getMarkweaveMathTargetFromDomEvent as Ct, getMarkweaveMathTargetFromSelection as wt, renderMarkweaveMathPreview as Tt, setMarkweaveMathEditingDomState as Et, setMarkweaveMathEditingDomStateInView as Dt, setMarkweaveMathSelectionInView as Ot } from "markweave/internal/plugins/math/math-ui-model";
21
+ import { filterSlashCommands as kt, isExecutableSlashCommand as At } from "markweave/internal/plugins/slash-command/command-spec";
22
+ import { getSlashCommandKeyboardAction as jt, isSlashCommandMenuState as Mt } from "markweave/internal/plugins/slash-command/slash-keyboard";
23
+ import { executeSlashCommand as Nt, getNextSlashCommandState as Pt, getSlashCommandAnchoredMenuPosition as Ft, getSlashCommandContext as It } from "markweave/internal/plugins/slash-command/slash-runtime";
24
+ import { initialSlashCommandState as Lt, reduceSlashCommandState as Rt } from "markweave/internal/plugins/slash-command/slash-state";
25
+ import { getFirstTableDebugSnapshot as zt } from "markweave/internal/plugins/table/table-debug-snapshot";
26
+ import { focusFirstTableBodyCell as Bt } from "markweave/internal/plugins/table/table-focus-position";
27
+ import { getTableFocusState as Vt } from "markweave/internal/plugins/table/table-focus-state";
28
+ import { getTableSelectionOverlayState as Ht, initialTableInteractionState as Ut, tableInteractionPluginKey as Wt } from "markweave/internal/plugins/table/table-interaction-layer";
29
+ import { calculateCodeBlockLanguageMenuPosition as Gt, clampFullscreenScale as Kt, codeBlockCopyFeedbackTimeoutMs as qt, copyCodeBlockText as Jt, createCodeBlockOverlayPosition as Yt, createMermaidFullscreenViewerState as Xt, createMermaidTabPosition as Zt, focusCodeBlockTarget as Qt, formatCodeBlockLanguageLabel as $t, formatFullscreenZoom as en, getActiveCodeBlockElement as tn, getAnchoredRect as nn, getCodeBlockLanguageItems as rn, getCodeBlockPositionFromEventTarget as an, getCodeBlockStateAtPosition as on, getFrameElement as sn, getMermaidCodeBlockTargets as cn, getMermaidSvgMarkup as ln, isCodeBlockTargetCollapsed as un, mergeStableMermaidTabPositions as dn, mermaidFullscreenZoomStep as fn, moveMermaidFullscreenViewer as pn } from "markweave/internal/plugins/codeblock/codeblock-ui-model";
30
+ import { BubbleMenu as mn } from "@tiptap/react/menus";
31
+ import { createMarkweaveFrameScheduler as hn } from "markweave/internal/editor-core/frame-scheduler";
32
+ import { applyFloatingToolbarLink as gn, createFloatingToolbarAssistantRequest as _n, getFloatingToolbarButtonModels as vn, getFloatingToolbarHighlightColorOptions as yn, getFloatingToolbarLinkHref as bn, getFloatingToolbarMessageSet as xn, getFloatingToolbarMoreActions as Sn, getFloatingToolbarTextColorOptions as Cn, getFloatingToolbarTooltipModel as wn, getFloatingToolbarTurnIntoOptions as Tn, isFloatingToolbarMoreActionActive as En, isFloatingToolbarTurnIntoActive as Dn, openFloatingToolbarLinkHref as On, preventFloatingToolbarPointerFocusLoss as kn, removeFloatingToolbarLink as An, runFloatingToolbarMoreAction as jn, setFloatingToolbarHighlightColor as Mn, setFloatingToolbarTextColor as Nn, setFloatingToolbarTurnInto as Pn } from "markweave/internal/editor-core/floating-toolbar-model";
33
+ import { normalizeMarkdownLinkHref as Fn } from "markweave/internal/plugins/markdown/markdown-input";
34
+ import { setMarkweaveTableMenuAxisTarget as In } from "markweave/internal/plugins/table/table-clipboard";
35
+ import { calculateAnchoredTableMenuPosition as Ln, calculateTableEdgeHandlePosition as Rn, canRunTableCommand as zn, executeTableMenuCommand as Bn, formatTableCopyFeedback as Vn, getActiveTableElement as Hn, getAvailableCellMenuCommandSpecs as Un, getTableAxisTargetRect as Wn, getTableControlAxisSelectionModel as Gn, getTableEditWithAiRequest as Kn, getTableMenuItemGroup as qn, getTableMenuItemLabel as Jn, getTableMenuItems as Yn, getTableSelectionTargetRect as Xn, measureTableSelectionOverlay as Zn, selectTableAxisFromCell as Qn, tableCopyFeedbackTimeoutMs as $n, tableMenuLabel as er } from "markweave/internal/plugins/table/table-ui-model";
36
+ import { createMarkweaveTocState as tr, emptyMarkweaveTocState as nr, getActiveMarkweaveTocId as rr, getMarkweaveTocItems as ir, getValidMarkweaveTocActiveId as ar, normalizeMarkweaveInnerTocPlacement as or, observeMarkweaveInnerTocContainerPosition as sr, scrollToMarkweaveTocItem as cr } from "markweave/internal/core/toc-state";
37
+ import { normalizeMarkweaveTheme as lr } from "markweave/internal/core/theme";
36
38
  //#region src/editor-mode-state.ts
37
- var rr = {
39
+ var ur = {
38
40
  mode: "live",
39
41
  editable: !0
40
42
  };
41
- function ir(e) {
42
- return he((t) => Ie(e, t), () => Me(e), () => rr);
43
+ function dr(e) {
44
+ return ge((t) => Ie(e, t), () => Y(e), () => ur);
43
45
  }
44
46
  //#endregion
45
47
  //#region src/media/image-node.tsx
46
- var ar = Ee;
47
- function or(e) {
48
+ var fr = De;
49
+ function pr(e) {
48
50
  return e instanceof Element && !!e.closest("[data-markweave-image-ui=\"true\"]");
49
51
  }
50
- function sr(e) {
51
- let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? Ae("zh"), u = l.image, d = Ne(ir(r)), f = Y(a.attrs.src), p = ar(a.attrs.align), m = Oe(a.attrs.width), h = Y(a.attrs.caption), g = W(null), _ = W(null), [v, y] = G(!1), [b, x] = G(!1), [C, w] = G(!1), [T, E] = G(""), [D, O] = G(null), [k, A] = G(!1), [j, M] = G(!!h), [N, P] = G(h ?? ""), F = d && (!f || b), I = () => {
52
+ function mr(e) {
53
+ let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? je("zh"), u = l.image, d = Ne(dr(r)), f = J(a.attrs.src), p = fr(a.attrs.align), m = ke(a.attrs.width), h = J(a.attrs.caption), g = U(null), _ = U(null), [v, y] = W(!1), [b, x] = W(!1), [C, w] = W(!1), [T, E] = W(""), [D, O] = W(null), [ee, k] = W(!1), [A, j] = W(!!h), [te, M] = W(h ?? ""), N = d && (!f || b), ne = () => {
52
54
  f && Le({
53
55
  src: f,
54
- alt: Y(a.attrs.alt) ?? "",
56
+ alt: J(a.attrs.alt) ?? "",
55
57
  messages: {
56
58
  dialogAriaLabel: u.previewDialogAriaLabel,
57
59
  zoomOut: u.previewZoomOut,
@@ -61,14 +63,14 @@ function sr(e) {
61
63
  }
62
64
  });
63
65
  };
64
- H(() => {
65
- j || P(h ?? "");
66
- }, [h, j]);
67
- let ee = () => {
66
+ V(() => {
67
+ A || M(h ?? "");
68
+ }, [h, A]);
69
+ let P = () => {
68
70
  if (!d) return;
69
71
  let e = i();
70
72
  typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
71
- }, L = () => {
73
+ }, F = () => {
72
74
  if (d) {
73
75
  if (E(""), O(null), w(!1), f) {
74
76
  x(!1);
@@ -76,48 +78,48 @@ function sr(e) {
76
78
  }
77
79
  t();
78
80
  }
79
- }, R = async (e) => {
81
+ }, I = async (e) => {
80
82
  if (d) {
81
- O(null), A(!0);
83
+ O(null), k(!0);
82
84
  try {
83
- let t = await K(Ce(e, f && b ? "image-replace" : "image-insert"), c.onUpload);
84
- s(ye(a.attrs, t)), x(!1), E("");
85
+ let t = await G(we(e, f && b ? "image-replace" : "image-insert"), c.onUpload);
86
+ s(K(a.attrs, t)), x(!1), E("");
85
87
  } catch (e) {
86
88
  O(e instanceof Error ? e.message : u.uploadFailedError);
87
89
  } finally {
88
- A(!1), w(!1);
90
+ k(!1), w(!1);
89
91
  }
90
92
  }
91
- }, te = () => {
93
+ }, re = () => {
92
94
  if (d) {
93
95
  if (!T.trim()) {
94
96
  O(u.uploadRequiredError);
95
97
  return;
96
98
  }
97
- R(ge(T));
99
+ I(_e(T));
98
100
  }
99
- }, z = (e) => {
100
- !d || !e || R({
101
+ }, L = (e) => {
102
+ !d || !e || I({
101
103
  type: "file",
102
104
  file: e,
103
105
  mimeType: e.type
104
106
  });
105
- }, ne = (e) => {
106
- z(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
107
- }, re = (e) => {
108
- e.preventDefault(), e.stopPropagation(), d && z(e.dataTransfer.files?.[0] ?? null);
109
- }, ie = () => {
110
- d && (M((e) => !e), j || P(h ?? ""));
111
- }, ae = (e) => {
112
- d && (P(e), s({ caption: e.trim() ? e : null }));
113
- }, oe = (e, t) => {
107
+ }, R = (e) => {
108
+ L(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
109
+ }, ie = (e) => {
110
+ e.preventDefault(), e.stopPropagation(), d && L(e.dataTransfer.files?.[0] ?? null);
111
+ }, ae = () => {
112
+ d && (j((e) => !e), A || M(h ?? ""));
113
+ }, oe = (e) => {
114
+ d && (M(e), s({ caption: e.trim() ? e : null }));
115
+ }, z = (e, t) => {
114
116
  if (t.preventDefault(), t.stopPropagation(), !d) return;
115
- ee();
117
+ P();
116
118
  let n = g.current;
117
119
  if (!n) return;
118
120
  let r = t.clientX, i = n.getBoundingClientRect().width || m || 320, a = n.closest(".markweave-editor-surface")?.getBoundingClientRect().width ?? n.parentElement?.getBoundingClientRect().width ?? i, o = (t) => {
119
121
  let n = e === "right" ? t.clientX - r : r - t.clientX;
120
- s({ width: Se(i + n, a) });
122
+ s({ width: Ce(i + n, a) });
121
123
  }, c = () => {
122
124
  window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", c);
123
125
  };
@@ -130,37 +132,37 @@ function sr(e) {
130
132
  "data-align": p,
131
133
  "data-selected": d && o ? "true" : "false",
132
134
  "data-hovered": v ? "true" : "false",
133
- "data-empty": F ? "true" : "false",
135
+ "data-empty": N ? "true" : "false",
134
136
  onPointerEnter: () => y(!0),
135
137
  onPointerLeave: () => y(!1),
136
138
  onMouseDown: (e) => {
137
- d && !or(e.target) && ee();
139
+ d && !pr(e.target) && P();
138
140
  },
139
- children: F ? /* @__PURE__ */ Z(cr, {
141
+ children: N ? /* @__PURE__ */ Z(hr, {
140
142
  dragActive: C,
141
143
  error: D,
142
144
  inputValue: T,
143
- isSubmitting: k,
145
+ isSubmitting: ee,
144
146
  fileInputRef: _,
145
147
  messages: l,
146
- onCancel: L,
147
- onDrop: re,
148
+ onCancel: F,
149
+ onDrop: ie,
148
150
  onDragActiveChange: w,
149
- onFileChange: ne,
151
+ onFileChange: R,
150
152
  onInputChange: E,
151
- onSubmit: te
153
+ onSubmit: re
152
154
  }) : /* @__PURE__ */ Q(X, { children: [
153
- d ? /* @__PURE__ */ Z(lr, {
155
+ d ? /* @__PURE__ */ Z(gr, {
154
156
  align: p,
155
- captionActive: j || !!h,
157
+ captionActive: A || !!h,
156
158
  messages: l,
157
159
  onAlign: (e) => s({ align: e }),
158
- onCaption: ie,
160
+ onCaption: ae,
159
161
  onDelete: t,
160
162
  onDownload: () => {
161
- f && we(f);
163
+ f && Te(f);
162
164
  },
163
- onPreview: I,
165
+ onPreview: ne,
164
166
  onReplace: () => {
165
167
  E(""), O(null), x(!0);
166
168
  }
@@ -173,8 +175,8 @@ function sr(e) {
173
175
  f ? /* @__PURE__ */ Z("img", {
174
176
  className: "markweave-image",
175
177
  src: f,
176
- alt: Y(a.attrs.alt) ?? "",
177
- title: Y(a.attrs.title) ?? void 0,
178
+ alt: J(a.attrs.alt) ?? "",
179
+ title: J(a.attrs.title) ?? void 0,
178
180
  draggable: !1
179
181
  }) : /* @__PURE__ */ Z("div", {
180
182
  className: "markweave-image-readonly-empty",
@@ -189,7 +191,7 @@ function sr(e) {
189
191
  "aria-label": u.preview,
190
192
  title: u.preview,
191
193
  onMouseDown: (e) => e.preventDefault(),
192
- onClick: I,
194
+ onClick: ne,
193
195
  children: [/* @__PURE__ */ Z(S, {
194
196
  size: 16,
195
197
  strokeWidth: 1.8
@@ -199,28 +201,28 @@ function sr(e) {
199
201
  children: u.preview
200
202
  })]
201
203
  }) : null,
202
- d ? /* @__PURE__ */ Z(dr, {
204
+ d ? /* @__PURE__ */ Z(vr, {
203
205
  side: "left",
204
206
  messages: l,
205
- onPointerDown: oe
207
+ onPointerDown: z
206
208
  }) : null,
207
- d ? /* @__PURE__ */ Z(dr, {
209
+ d ? /* @__PURE__ */ Z(vr, {
208
210
  side: "right",
209
211
  messages: l,
210
- onPointerDown: oe
212
+ onPointerDown: z
211
213
  }) : null
212
214
  ]
213
215
  }),
214
- d && (j || h) ? /* @__PURE__ */ Z("input", {
216
+ d && (A || h) ? /* @__PURE__ */ Z("input", {
215
217
  className: "markweave-image-caption-input",
216
218
  "data-markweave-image-ui": "true",
217
219
  "data-testid": "markweave-image-caption-input",
218
- value: N,
220
+ value: te,
219
221
  placeholder: u.captionPlaceholder,
220
222
  "aria-label": u.captionAriaLabel,
221
- onChange: (e) => ae(e.currentTarget.value),
223
+ onChange: (e) => oe(e.currentTarget.value),
222
224
  onKeyDown: (e) => {
223
- e.key === "Escape" && (e.preventDefault(), M(!1));
225
+ e.key === "Escape" && (e.preventDefault(), j(!1));
224
226
  }
225
227
  }) : h ? /* @__PURE__ */ Z("figcaption", {
226
228
  className: "markweave-image-caption",
@@ -230,7 +232,7 @@ function sr(e) {
230
232
  ] })
231
233
  });
232
234
  }
233
- function cr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
235
+ function hr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
234
236
  let f = a.image;
235
237
  return /* @__PURE__ */ Q("section", {
236
238
  className: "markweave-image-upload-placeholder",
@@ -312,7 +314,7 @@ function cr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
312
314
  ]
313
315
  });
314
316
  }
315
- function lr({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i, onDelete: a, onDownload: s, onPreview: u, onReplace: d }) {
317
+ function gr({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i, onDelete: a, onDownload: s, onPreview: u, onReplace: d }) {
316
318
  let p = n.image;
317
319
  return /* @__PURE__ */ Q("div", {
318
320
  className: "markweave-image-toolbar",
@@ -320,21 +322,21 @@ function lr({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i,
320
322
  "data-markweave-image-ui": "true",
321
323
  "aria-label": p.toolsAriaLabel,
322
324
  children: [
323
- /* @__PURE__ */ Z(ur, {
325
+ /* @__PURE__ */ Z(_r, {
324
326
  testId: "markweave-image-align-left",
325
327
  label: p.alignLeft,
326
328
  icon: c,
327
329
  active: e === "left",
328
330
  onClick: () => r("left")
329
331
  }),
330
- /* @__PURE__ */ Z(ur, {
332
+ /* @__PURE__ */ Z(_r, {
331
333
  testId: "markweave-image-align-center",
332
334
  label: p.alignCenter,
333
335
  icon: o,
334
336
  active: e === "center",
335
337
  onClick: () => r("center")
336
338
  }),
337
- /* @__PURE__ */ Z(ur, {
339
+ /* @__PURE__ */ Z(_r, {
338
340
  testId: "markweave-image-align-right",
339
341
  label: p.alignRight,
340
342
  icon: l,
@@ -345,36 +347,36 @@ function lr({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i,
345
347
  className: "markweave-image-toolbar-divider",
346
348
  "aria-hidden": "true"
347
349
  }),
348
- /* @__PURE__ */ Z(ur, {
350
+ /* @__PURE__ */ Z(_r, {
349
351
  testId: "markweave-image-caption",
350
352
  label: p.caption,
351
353
  icon: f,
352
354
  active: t,
353
355
  onClick: i
354
356
  }),
355
- /* @__PURE__ */ Z(ur, {
357
+ /* @__PURE__ */ Z(_r, {
356
358
  testId: "markweave-image-preview",
357
359
  label: p.preview,
358
360
  icon: S,
359
361
  onClick: u
360
362
  }),
361
- /* @__PURE__ */ Z(ur, {
363
+ /* @__PURE__ */ Z(_r, {
362
364
  testId: "markweave-image-download",
363
365
  label: p.download,
364
366
  icon: b,
365
367
  onClick: s
366
368
  }),
367
- /* @__PURE__ */ Z(ur, {
369
+ /* @__PURE__ */ Z(_r, {
368
370
  testId: "markweave-image-replace",
369
371
  label: p.replace,
370
- icon: z,
372
+ icon: L,
371
373
  onClick: d
372
374
  }),
373
375
  /* @__PURE__ */ Z("span", {
374
376
  className: "markweave-image-toolbar-divider",
375
377
  "aria-hidden": "true"
376
378
  }),
377
- /* @__PURE__ */ Z(ur, {
379
+ /* @__PURE__ */ Z(_r, {
378
380
  testId: "markweave-image-delete",
379
381
  label: p.delete,
380
382
  icon: ue,
@@ -383,7 +385,7 @@ function lr({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i,
383
385
  ]
384
386
  });
385
387
  }
386
- function ur({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
388
+ function _r({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
387
389
  return /* @__PURE__ */ Q("button", {
388
390
  type: "button",
389
391
  "aria-label": n,
@@ -402,7 +404,7 @@ function ur({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
402
404
  })]
403
405
  });
404
406
  }
405
- function dr({ messages: e, onPointerDown: t, side: n }) {
407
+ function vr({ messages: e, onPointerDown: t, side: n }) {
406
408
  return /* @__PURE__ */ Z("button", {
407
409
  type: "button",
408
410
  className: "markweave-image-resize-handle",
@@ -413,42 +415,42 @@ function dr({ messages: e, onPointerDown: t, side: n }) {
413
415
  onPointerDown: (e) => t(n, e)
414
416
  });
415
417
  }
416
- var fr = q.extend({
418
+ var yr = ye.extend({
417
419
  addOptions() {
418
420
  return {
419
421
  ...this.parent?.(),
420
- messages: Ae("zh"),
422
+ messages: je("zh"),
421
423
  onUpload: void 0
422
424
  };
423
425
  },
424
426
  addNodeView() {
425
- return typeof document > "u" ? null : r(sr, { stopEvent: ({ event: e }) => or(e.target) });
427
+ return typeof document > "u" ? null : r(mr, { stopEvent: ({ event: e }) => pr(e.target) });
426
428
  }
427
429
  });
428
430
  //#endregion
429
431
  //#region src/media/video-node.tsx
430
- function pr(e) {
432
+ function br(e) {
431
433
  return e instanceof Element && !!e.closest("[data-markweave-video-ui=\"true\"], iframe[data-markweave-video-embed], video[data-markweave-video]");
432
434
  }
433
- function mr(e) {
434
- let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? Ae("zh"), u = l.video, d = Ne(ir(r)), f = Y(a.attrs.src), p = Y(a.attrs.embedUrl), m = Y(a.attrs.provider), h = p ? De(p, m) : null, g = Y(a.attrs.mimeType), _ = Y(a.attrs.title), v = W(null), [y, b] = G(!1), [x, S] = G(""), [C, w] = G(null), [T, E] = G(!1), D = d && !f, O = () => {
435
+ function xr(e) {
436
+ let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? je("zh"), u = l.video, d = Ne(dr(r)), f = J(a.attrs.src), p = J(a.attrs.embedUrl), m = J(a.attrs.provider), h = p ? Oe(p, m) : null, g = J(a.attrs.mimeType), _ = J(a.attrs.title), v = U(null), [y, b] = W(!1), [x, S] = W(""), [C, w] = W(null), [T, E] = W(!1), D = d && !f, O = () => {
435
437
  if (!d) return;
436
438
  let e = i();
437
439
  typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
440
+ }, ee = (e) => {
441
+ d && (br(e.target) || (e.preventDefault(), O()));
438
442
  }, k = (e) => {
439
- d && (pr(e.target) || (e.preventDefault(), O()));
440
- }, A = (e) => {
441
443
  d && (e.key === "Delete" || e.key === "Backspace") && o && (e.preventDefault(), t());
442
- }, j = async (e) => {
444
+ }, A = async (e) => {
443
445
  if (!(!d || !e)) {
444
446
  w(null), E(!0);
445
447
  try {
446
- let t = await K(J({
448
+ let t = await G(q({
447
449
  type: "file",
448
450
  file: e,
449
451
  mimeType: e.type
450
452
  }), c.onUpload);
451
- s(be(t)), S("");
453
+ s(xe(t)), S("");
452
454
  } catch (e) {
453
455
  w(e instanceof Error ? e.message : u.uploadFailedError);
454
456
  } finally {
@@ -462,7 +464,7 @@ function mr(e) {
462
464
  "data-testid": "markweave-video-node",
463
465
  "data-empty": "true",
464
466
  "data-selected": "false",
465
- children: /* @__PURE__ */ Z(hr, {
467
+ children: /* @__PURE__ */ Z(Sr, {
466
468
  dragActive: y,
467
469
  error: C,
468
470
  fileInputRef: v,
@@ -472,15 +474,15 @@ function mr(e) {
472
474
  onCancel: t,
473
475
  onDragActiveChange: b,
474
476
  onDrop: (e) => {
475
- e.preventDefault(), e.stopPropagation(), d && j(e.dataTransfer.files?.[0] ?? null);
477
+ e.preventDefault(), e.stopPropagation(), d && A(e.dataTransfer.files?.[0] ?? null);
476
478
  },
477
479
  onFileChange: (e) => {
478
- j(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
480
+ A(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
479
481
  },
480
482
  onInputChange: S,
481
483
  onSubmit: () => {
482
484
  if (!d) return;
483
- let e = xe(x);
485
+ let e = Se(x);
484
486
  if (!e) {
485
487
  w(u.unsupportedUrlError);
486
488
  return;
@@ -498,8 +500,8 @@ function mr(e) {
498
500
  tabIndex: d ? 0 : void 0,
499
501
  "aria-label": u.nodeAriaLabel,
500
502
  onFocus: O,
501
- onKeyDown: A,
502
- onMouseDown: k,
503
+ onKeyDown: k,
504
+ onMouseDown: ee,
503
505
  children: h ? /* @__PURE__ */ Q("div", {
504
506
  className: "markweave-video-embed",
505
507
  children: [/* @__PURE__ */ Z("iframe", {
@@ -509,7 +511,8 @@ function mr(e) {
509
511
  "data-markweave-video-embed": "true",
510
512
  "data-markweave-video-provider": m ?? void 0,
511
513
  "data-markweave-video-src": f ?? void 0,
512
- allow: Te,
514
+ allow: Ee,
515
+ loading: "lazy",
513
516
  allowFullScreen: !0
514
517
  }), d ? /* @__PURE__ */ Z("button", {
515
518
  type: "button",
@@ -526,6 +529,7 @@ function mr(e) {
526
529
  title: _ ?? void 0,
527
530
  "data-markweave-video": "true",
528
531
  "data-markweave-mime-type": g ?? void 0,
532
+ preload: "metadata",
529
533
  controls: !0
530
534
  }), d ? /* @__PURE__ */ Z("button", {
531
535
  type: "button",
@@ -541,7 +545,7 @@ function mr(e) {
541
545
  })
542
546
  });
543
547
  }
544
- function hr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
548
+ function Sr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
545
549
  let f = a.video;
546
550
  return /* @__PURE__ */ Q("section", {
547
551
  className: "markweave-video-upload-placeholder",
@@ -568,7 +572,7 @@ function hr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
568
572
  /* @__PURE__ */ Z("div", {
569
573
  className: "markweave-video-upload-icon",
570
574
  "aria-hidden": "true",
571
- children: /* @__PURE__ */ Z(B, {
575
+ children: /* @__PURE__ */ Z(me, {
572
576
  size: 46,
573
577
  strokeWidth: 1.6
574
578
  })
@@ -623,26 +627,26 @@ function hr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitt
623
627
  ]
624
628
  });
625
629
  }
626
- var gr = ve.extend({
630
+ var Cr = be.extend({
627
631
  addOptions() {
628
632
  return {
629
633
  ...this.parent?.(),
630
- messages: Ae("zh"),
634
+ messages: je("zh"),
631
635
  onUpload: void 0
632
636
  };
633
637
  },
634
638
  addNodeView() {
635
- return typeof document > "u" ? null : r(mr, { stopEvent: ({ event: e }) => pr(e.target) });
639
+ return typeof document > "u" ? null : r(xr, { stopEvent: ({ event: e }) => br(e.target) });
636
640
  }
637
641
  });
638
642
  //#endregion
639
643
  //#region src/create-editor-extensions.ts
640
- function _r(t = {}) {
644
+ function wr(t = {}) {
641
645
  return e({
642
646
  lang: t.lang,
643
647
  mediaExtensions: Re({
644
- image: fr,
645
- video: gr,
648
+ image: yr,
649
+ video: Cr,
646
650
  lang: t.lang,
647
651
  onImageUpload: t.onImageUpload,
648
652
  onVideoUpload: t.onVideoUpload
@@ -651,7 +655,7 @@ function _r(t = {}) {
651
655
  }
652
656
  //#endregion
653
657
  //#region src/ui/codeblock/CodeBlockControls.tsx
654
- function vr(e) {
658
+ function Tr(e) {
655
659
  return e === "clipboard" ? /* @__PURE__ */ Q(X, { 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(X, { children: [/* @__PURE__ */ Z("circle", {
656
660
  cx: "10",
657
661
  cy: "10",
@@ -688,7 +692,7 @@ function vr(e) {
688
692
  /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })
689
693
  ] }) : e === "reset" ? /* @__PURE__ */ Q(X, { 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" });
690
694
  }
691
- function yr({ icon: e }) {
695
+ function Er({ icon: e }) {
692
696
  return /* @__PURE__ */ Z("svg", {
693
697
  viewBox: "0 0 24 24",
694
698
  "aria-hidden": "true",
@@ -699,50 +703,50 @@ function yr({ icon: e }) {
699
703
  strokeLinecap: "round",
700
704
  strokeLinejoin: "round",
701
705
  strokeWidth: "1.8",
702
- children: vr(e)
706
+ children: Tr(e)
703
707
  })
704
708
  });
705
709
  }
706
- function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, readOnly: i = !1 }) {
707
- let a = W(null), o = W(null), s = W(null), c = W({
710
+ function Dr({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, readOnly: i = !1 }) {
711
+ let a = U(null), o = U(null), s = U(null), c = U({
708
712
  active: !1,
709
713
  lastX: 0,
710
714
  lastY: 0
711
- }), [l, u] = G(null), [d, f] = G(null), [p, m] = G([]), [h, g] = G(null), [_, v] = G(!1), [y, b] = G(""), [x, S] = G(null), [C, w] = G(!1), [T, E] = G(null), [D, O] = G(null), [k, A] = G(!1), [j, M] = G(0), [N, P] = G(0), F = nt(t), I = en(t, l), ee = !i && e && F.active && F.pos !== null ? {
712
- ...F,
713
- pos: F.pos,
715
+ }), [l, u] = W(null), [d, f] = W(null), [p, m] = W([]), [h, g] = W(null), [_, v] = W(!1), [y, b] = W(""), [x, S] = W(null), [C, w] = W(!1), [T, E] = W(null), [D, O] = W(null), [ee, k] = W(!1), [A, j] = W(0), [te, M] = W(0), N = ot(t), ne = on(t, l), P = !i && e && N.active && N.pos !== null ? {
716
+ ...N,
717
+ pos: N.pos,
714
718
  active: !0
715
- } : null, L = I ?? ee, R = L !== null, te = L?.language === "mermaid", z = an(t, L), ne = R && L !== null && !z, re = !i, ie = Jt(L ? L.language : "text"), ae = x?.status ?? "idle", oe = L?.mermaidPreviewMode ?? n, se = te && oe === "preview", ce = nn(t), le = `${N}|${ce.map((e) => `${e.pos}:${e.mermaidPreviewMode}:${e.text.length}`).join("|")}`, ue = U(() => Qt(y.trim().toLowerCase()), [y]);
716
- if (H(() => {
719
+ } : null, F = ne ?? P, I = F !== null, re = F?.language === "mermaid", L = un(t, F), R = I && F !== null && !L, ie = !i, ae = $t(F ? F.language : "text"), oe = x?.status ?? "idle", z = F?.mermaidPreviewMode ?? n, se = re && z === "preview", ce = cn(t), le = `${te}|${ce.map((e) => `${e.pos}:${e.mermaidPreviewMode}:${e.text.length}`).join("|")}`, ue = H(() => rn(y.trim().toLowerCase()), [y]);
720
+ if (V(() => {
717
721
  i && (v(!1), b(""));
718
- }, [i]), H(() => {
722
+ }, [i]), V(() => {
719
723
  if (!x) return;
720
724
  let e = window.setTimeout(() => {
721
725
  S(null);
722
- }, Ht);
726
+ }, qt);
723
727
  return () => {
724
728
  window.clearTimeout(e);
725
729
  };
726
- }, [x]), H(() => {
727
- S(null), v(!1), b(""), E(null), O(null), A(!1);
730
+ }, [x]), V(() => {
731
+ S(null), v(!1), b(""), E(null), O(null), k(!1);
728
732
  }, [
729
733
  e,
730
- L?.language,
731
- L?.pos,
732
- L?.text
733
- ]), H(() => {
734
+ F?.language,
735
+ F?.pos,
736
+ F?.text
737
+ ]), V(() => {
734
738
  let e = ({ transaction: e }) => {
735
- e.getMeta(et) && M((e) => e + 1);
739
+ e.getMeta(it) && j((e) => e + 1);
736
740
  };
737
741
  return t.on("transaction", e), () => {
738
742
  t.off("transaction", e);
739
743
  };
740
- }, [t]), H(() => {
744
+ }, [t]), V(() => {
741
745
  let e = t.view.dom.closest(".markweave-editor-frame");
742
746
  if (!e) return;
743
747
  let n = (e) => {
744
748
  if (e.target instanceof Node && a.current?.contains(e.target) || _) return;
745
- let n = en(t, $t(t, e.target)), r = n && !an(t, n) ? n.pos : null;
749
+ let n = on(t, an(t, e.target)), r = n && !un(t, n) ? n.pos : null;
746
750
  u((e) => e === r ? e : r);
747
751
  }, r = () => {
748
752
  _ || u(null);
@@ -750,12 +754,12 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
750
754
  return e.addEventListener("mousemove", n), e.addEventListener("mouseleave", r), () => {
751
755
  e.removeEventListener("mousemove", n), e.removeEventListener("mouseleave", r);
752
756
  };
753
- }, [t, _]), H(() => {
757
+ }, [t, _]), V(() => {
754
758
  _ && s.current?.focus({ preventScroll: !0 });
755
- }, [_]), H(() => {
759
+ }, [_]), V(() => {
756
760
  if (!T) return;
757
761
  let e = (e) => {
758
- e.key === "Escape" && (E(null), O(null), A(!1), c.current = {
762
+ e.key === "Escape" && (E(null), O(null), k(!1), c.current = {
759
763
  active: !1,
760
764
  lastX: 0,
761
765
  lastY: 0
@@ -764,8 +768,8 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
764
768
  return document.addEventListener("keydown", e), () => {
765
769
  document.removeEventListener("keydown", e);
766
770
  };
767
- }, [t, T]), H(() => {
768
- if (!R || !_) return;
771
+ }, [t, T]), V(() => {
772
+ if (!I || !_) return;
769
773
  let e = (e) => {
770
774
  e.key === "Escape" && (v(!1), t.view.focus());
771
775
  }, n = (e) => {
@@ -775,22 +779,22 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
775
779
  document.removeEventListener("keydown", e), document.removeEventListener("mousedown", n);
776
780
  };
777
781
  }, [
778
- R,
782
+ I,
779
783
  t,
780
784
  _
781
- ]), me(() => {
785
+ ]), he(() => {
782
786
  let e = () => {
783
787
  let e = a.current;
784
788
  if (!e) return;
785
- if (!tn(e) || ce.length === 0) {
789
+ if (!sn(e) || ce.length === 0) {
786
790
  m([]);
787
791
  return;
788
792
  }
789
793
  let n = e.getBoundingClientRect(), r = ce.flatMap((e) => {
790
- let r = Zt(Xt(t, e.pos, e.mermaidPreviewMode), n);
791
- return r ? [Kt(e, r, n)] : [];
794
+ let r = nn(tn(t, e.pos, e.mermaidPreviewMode), n);
795
+ return r ? [Zt(e, r, n)] : [];
792
796
  });
793
- m((e) => on(e, r, ce.map((e) => e.pos)));
797
+ m((e) => dn(e, r, ce.map((e) => e.pos)));
794
798
  };
795
799
  e();
796
800
  let n = window.requestAnimationFrame(e);
@@ -798,26 +802,26 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
798
802
  window.cancelAnimationFrame(n), window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
799
803
  };
800
804
  }, [
801
- j,
805
+ A,
802
806
  t,
803
807
  le
804
- ]), me(() => {
805
- if (!ne || !L) {
808
+ ]), he(() => {
809
+ if (!R || !F) {
806
810
  f(null), g(null);
807
811
  return;
808
812
  }
809
813
  let e = () => {
810
814
  let e = a.current;
811
815
  if (!e) return;
812
- let n = Xt(t, L.pos, oe), r = e.getBoundingClientRect(), i = Zt(n, r);
816
+ let n = tn(t, F.pos, z), r = e.getBoundingClientRect(), i = nn(n, r);
813
817
  if (!i) {
814
- f((e) => e?.pos === L.pos ? e : null), g((e) => _ ? e : null);
818
+ f((e) => e?.pos === F.pos ? e : null), g((e) => _ ? e : null);
815
819
  return;
816
820
  }
817
- let s = Wt(L.pos, i, r);
821
+ let s = Yt(F.pos, i, r);
818
822
  if (f(s), _ && o.current) {
819
823
  let e = o.current.getBoundingClientRect();
820
- g(Bt({
824
+ g(Gt({
821
825
  overlayRect: r,
822
826
  buttonRect: e,
823
827
  windowWidth: window.innerWidth,
@@ -829,79 +833,79 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
829
833
  window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
830
834
  };
831
835
  }, [
832
- ne,
833
- j,
834
- L?.pos,
836
+ R,
837
+ A,
838
+ F?.pos,
835
839
  t,
836
840
  _,
837
- oe
838
- ]), !ne && ce.length === 0 && !T) return null;
841
+ z
842
+ ]), !R && ce.length === 0 && !T) return null;
839
843
  let de = d ? {
840
844
  top: d.top,
841
845
  right: d.right
842
846
  } : void 0, fe = async () => {
843
847
  if (i) {
844
- if (!L) return;
845
- let e = await Ut(L.text);
846
- S(rt(L, e ? "copied" : "failed"));
848
+ if (!F) return;
849
+ let e = await Jt(F.text);
850
+ S(st(F, e ? "copied" : "failed"));
847
851
  return;
848
852
  }
849
- if (!qt(t, L)) return;
850
- let e = await tt(t);
851
- S(rt(nt(t), e ? "copied" : "failed")), t.view.focus();
853
+ if (!Qt(t, F)) return;
854
+ let e = await at(t);
855
+ S(st(ot(t), e ? "copied" : "failed")), t.view.focus();
852
856
  }, pe = (e, n) => {
853
857
  if (i) {
854
- ut(t, e.pos, n) && P((e) => e + 1);
858
+ ht(t, e.pos, n) && M((e) => e + 1);
855
859
  return;
856
860
  }
857
- let a = F.active && F.pos === e.pos;
858
- st(t, e.pos, n) && (r(n), P((e) => e + 1), a && t.view.focus());
859
- }, B = (e) => {
860
- if (i || !L) return;
861
- let n = F.active && F.pos === L.pos;
862
- ot(t, L.pos, e) && (e === "mermaid" && st(t, L.pos, "preview") && r("preview"), v(!1), b(""), P((e) => e + 1), n && t.view.focus());
863
- }, V = () => {
864
- i || !L || at(t, L.pos, !z) && (M((e) => e + 1), u(null));
865
- }, he = () => {
866
- if (!L) return;
867
- let e = rn(t, L.pos);
861
+ let a = N.active && N.pos === e.pos;
862
+ dt(t, e.pos, n) && (r(n), M((e) => e + 1), a && t.view.focus());
863
+ }, me = (e) => {
864
+ if (i || !F) return;
865
+ let n = N.active && N.pos === F.pos;
866
+ ut(t, F.pos, e) && (e === "mermaid" && dt(t, F.pos, "preview") && r("preview"), v(!1), b(""), M((e) => e + 1), n && t.view.focus());
867
+ }, B = () => {
868
+ i || !F || lt(t, F.pos, !L) && (j((e) => e + 1), u(null));
869
+ }, ge = () => {
870
+ if (!F) return;
871
+ let e = ln(t, F.pos);
868
872
  if (!e) return;
869
873
  let n = new Blob([e], { type: "image/svg+xml" }), r = URL.createObjectURL(n), i = document.createElement("a");
870
874
  i.href = r, i.download = "markweave-mermaid.svg", i.click(), URL.revokeObjectURL(r), t.view.focus();
871
- }, ge = () => {
872
- if (!L) return;
873
- let e = rn(t, L.pos);
874
- e && (E(Gt(e)), O(null), A(!1), c.current = {
875
+ }, _e = () => {
876
+ if (!F) return;
877
+ let e = ln(t, F.pos);
878
+ e && (E(Xt(e)), O(null), k(!1), c.current = {
875
879
  active: !1,
876
880
  lastX: 0,
877
881
  lastY: 0
878
882
  });
879
- }, _e = () => {
880
- E(null), O(null), A(!1), c.current = {
883
+ }, ve = () => {
884
+ E(null), O(null), k(!1), c.current = {
881
885
  active: !1,
882
886
  lastX: 0,
883
887
  lastY: 0
884
888
  }, t.view.focus();
885
- }, K = (e) => {
889
+ }, G = (e) => {
886
890
  E((t) => t && {
887
891
  ...t,
888
- scale: Vt(t.scale + e)
892
+ scale: Kt(t.scale + e)
889
893
  });
890
- }, q = () => {
891
- E((e) => e && Gt(e.svg)), c.current = {
894
+ }, ye = () => {
895
+ E((e) => e && Xt(e.svg)), c.current = {
892
896
  active: !1,
893
897
  lastX: 0,
894
898
  lastY: 0
895
- }, A(!1);
896
- }, ve = (e) => {
897
- e.preventDefault(), K(e.deltaY < 0 ? sn : -sn);
898
- }, ye = (e) => {
899
+ }, k(!1);
900
+ }, be = (e) => {
901
+ e.preventDefault(), G(e.deltaY < 0 ? fn : -fn);
902
+ }, K = (e) => {
899
903
  e.button === 0 && (e.preventDefault(), c.current = {
900
904
  active: !0,
901
905
  lastX: e.clientX,
902
906
  lastY: e.clientY
903
- }, A(!0));
904
- }, be = (e) => {
907
+ }, k(!0));
908
+ }, xe = (e) => {
905
909
  let t = c.current;
906
910
  if (!t.active) return;
907
911
  let n = e.clientX - t.lastX, r = e.clientY - t.lastY;
@@ -909,13 +913,13 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
909
913
  active: !0,
910
914
  lastX: e.clientX,
911
915
  lastY: e.clientY
912
- }, E((e) => cn(e, n, r));
913
- }, xe = () => {
916
+ }, E((e) => pn(e, n, r));
917
+ }, Se = () => {
914
918
  c.current = {
915
919
  active: !1,
916
920
  lastX: 0,
917
921
  lastY: 0
918
- }, A(!1);
922
+ }, k(!1);
919
923
  };
920
924
  return /* @__PURE__ */ Q("div", {
921
925
  ref: a,
@@ -944,11 +948,11 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
944
948
  }, t))
945
949
  }, e.pos);
946
950
  }),
947
- ne ? /* @__PURE__ */ Q("div", {
951
+ R ? /* @__PURE__ */ Q("div", {
948
952
  className: "markweave-codeblock-controls",
949
953
  "data-testid": "markweave-codeblock-controls",
950
954
  "data-positioned": d ? "true" : "false",
951
- "data-collapsed": z ? "true" : "false",
955
+ "data-collapsed": L ? "true" : "false",
952
956
  "data-read-only": i ? "true" : "false",
953
957
  "aria-label": "Code block controls",
954
958
  style: de,
@@ -957,7 +961,7 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
957
961
  className: "markweave-codeblock-language-button markweave-codeblock-language-label",
958
962
  "aria-label": "Code block language",
959
963
  "data-testid": "markweave-codeblock-language",
960
- children: /* @__PURE__ */ Z("span", { children: ie })
964
+ children: /* @__PURE__ */ Z("span", { children: ae })
961
965
  }) : /* @__PURE__ */ Q("button", {
962
966
  ref: o,
963
967
  type: "button",
@@ -968,18 +972,18 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
968
972
  "data-testid": "markweave-codeblock-language",
969
973
  onMouseDown: (e) => e.preventDefault(),
970
974
  onClick: () => v((e) => !e),
971
- children: [/* @__PURE__ */ Z("span", { children: ie }), /* @__PURE__ */ Z(yr, { icon: "chevron" })]
975
+ children: [/* @__PURE__ */ Z("span", { children: ae }), /* @__PURE__ */ Z(Er, { icon: "chevron" })]
972
976
  }),
973
- re ? /* @__PURE__ */ Z("button", {
977
+ ie ? /* @__PURE__ */ Z("button", {
974
978
  type: "button",
975
979
  className: "markweave-codeblock-icon-button markweave-codeblock-collapse-button",
976
- "aria-label": z ? "Expand code block" : "Collapse code block",
977
- title: z ? "Expand code block" : "Collapse code block",
980
+ "aria-label": L ? "Expand code block" : "Collapse code block",
981
+ title: L ? "Expand code block" : "Collapse code block",
978
982
  "data-testid": "markweave-codeblock-collapse",
979
- "data-collapsed": z ? "true" : "false",
983
+ "data-collapsed": L ? "true" : "false",
980
984
  onMouseDown: (e) => e.preventDefault(),
981
- onClick: V,
982
- children: /* @__PURE__ */ Z(yr, { icon: "chevron" })
985
+ onClick: B,
986
+ children: /* @__PURE__ */ Z(Er, { icon: "chevron" })
983
987
  }) : null,
984
988
  /* @__PURE__ */ Q("span", {
985
989
  className: "markweave-codeblock-copy-wrap",
@@ -988,14 +992,14 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
988
992
  className: "markweave-codeblock-icon-button",
989
993
  "aria-label": "Copy to clipboard",
990
994
  "data-testid": "markweave-codeblock-copy",
991
- "data-copy-state": ae,
995
+ "data-copy-state": oe,
992
996
  onMouseDown: (e) => e.preventDefault(),
993
997
  onMouseEnter: () => w(!0),
994
998
  onMouseLeave: () => w(!1),
995
999
  onFocus: () => w(!0),
996
1000
  onBlur: () => w(!1),
997
1001
  onClick: fe,
998
- children: /* @__PURE__ */ Z(yr, { icon: ae === "copied" ? "check" : "clipboard" })
1002
+ children: /* @__PURE__ */ Z(Er, { icon: oe === "copied" ? "check" : "clipboard" })
999
1003
  }), C ? /* @__PURE__ */ Z("span", {
1000
1004
  className: "markweave-codeblock-tooltip",
1001
1005
  role: "tooltip",
@@ -1003,7 +1007,7 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1003
1007
  children: "Copy to clipboard"
1004
1008
  }) : null]
1005
1009
  }),
1006
- te && oe === "preview" ? /* @__PURE__ */ Q("div", {
1010
+ re && z === "preview" ? /* @__PURE__ */ Q("div", {
1007
1011
  className: "markweave-mermaid-preview-actions",
1008
1012
  "data-testid": "markweave-mermaid-preview-actions",
1009
1013
  children: [/* @__PURE__ */ Z("button", {
@@ -1013,8 +1017,8 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1013
1017
  "data-testid": "markweave-mermaid-fullscreen",
1014
1018
  disabled: !se,
1015
1019
  onMouseDown: (e) => e.preventDefault(),
1016
- onClick: ge,
1017
- children: /* @__PURE__ */ Z(yr, { icon: "expand" })
1020
+ onClick: _e,
1021
+ children: /* @__PURE__ */ Z(Er, { icon: "expand" })
1018
1022
  }), /* @__PURE__ */ Z("button", {
1019
1023
  type: "button",
1020
1024
  className: "markweave-codeblock-icon-button",
@@ -1022,13 +1026,13 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1022
1026
  "data-testid": "markweave-mermaid-download",
1023
1027
  disabled: !se,
1024
1028
  onMouseDown: (e) => e.preventDefault(),
1025
- onClick: he,
1026
- children: /* @__PURE__ */ Z(yr, { icon: "download" })
1029
+ onClick: ge,
1030
+ children: /* @__PURE__ */ Z(Er, { icon: "download" })
1027
1031
  })]
1028
1032
  }) : null
1029
1033
  ]
1030
1034
  }) : null,
1031
- re && ne && _ ? /* @__PURE__ */ Q("div", {
1035
+ ie && R && _ ? /* @__PURE__ */ Q("div", {
1032
1036
  className: "markweave-codeblock-language-menu",
1033
1037
  role: "listbox",
1034
1038
  "aria-label": "Code block languages",
@@ -1049,11 +1053,11 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1049
1053
  onKeyDown: (e) => {
1050
1054
  e.key === "Escape" && (e.preventDefault(), v(!1), t.view.focus());
1051
1055
  }
1052
- }), /* @__PURE__ */ Z(yr, { icon: "search" })]
1056
+ }), /* @__PURE__ */ Z(Er, { icon: "search" })]
1053
1057
  }), /* @__PURE__ */ Z("div", {
1054
1058
  className: "markweave-codeblock-language-list",
1055
1059
  children: ue.map((e) => {
1056
- let t = e.language === L.language;
1060
+ let t = e.language === F.language;
1057
1061
  return /* @__PURE__ */ Q("button", {
1058
1062
  type: "button",
1059
1063
  role: "option",
@@ -1061,8 +1065,8 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1061
1065
  "data-testid": `markweave-codeblock-language-option-${e.language}`,
1062
1066
  "data-active": t ? "true" : "false",
1063
1067
  onMouseDown: (e) => e.preventDefault(),
1064
- onClick: () => B(e.language),
1065
- children: [/* @__PURE__ */ Z("span", { children: e.label }), t ? /* @__PURE__ */ Z(yr, { icon: "check" }) : null]
1068
+ onClick: () => me(e.language),
1069
+ children: [/* @__PURE__ */ Z("span", { children: e.label }), t ? /* @__PURE__ */ Z(Er, { icon: "check" }) : null]
1066
1070
  }, e.language);
1067
1071
  })
1068
1072
  })]
@@ -1087,13 +1091,13 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1087
1091
  onMouseLeave: () => O(null),
1088
1092
  onFocus: () => O("zoom-out"),
1089
1093
  onBlur: () => O(null),
1090
- onClick: () => K(-sn),
1091
- children: /* @__PURE__ */ Z(yr, { icon: "zoomOut" })
1094
+ onClick: () => G(-fn),
1095
+ children: /* @__PURE__ */ Z(Er, { icon: "zoomOut" })
1092
1096
  }),
1093
1097
  /* @__PURE__ */ Z("span", {
1094
1098
  className: "markweave-mermaid-fullscreen-zoom-label",
1095
1099
  "data-testid": "markweave-mermaid-fullscreen-zoom-label",
1096
- children: Yt(T.scale)
1100
+ children: en(T.scale)
1097
1101
  }),
1098
1102
  /* @__PURE__ */ Z("button", {
1099
1103
  type: "button",
@@ -1104,8 +1108,8 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1104
1108
  onMouseLeave: () => O(null),
1105
1109
  onFocus: () => O("zoom-in"),
1106
1110
  onBlur: () => O(null),
1107
- onClick: () => K(sn),
1108
- children: /* @__PURE__ */ Z(yr, { icon: "zoomIn" })
1111
+ onClick: () => G(fn),
1112
+ children: /* @__PURE__ */ Z(Er, { icon: "zoomIn" })
1109
1113
  }),
1110
1114
  /* @__PURE__ */ Z("button", {
1111
1115
  type: "button",
@@ -1116,8 +1120,8 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1116
1120
  onMouseLeave: () => O(null),
1117
1121
  onFocus: () => O("reset"),
1118
1122
  onBlur: () => O(null),
1119
- onClick: q,
1120
- children: /* @__PURE__ */ Z(yr, { icon: "reset" })
1123
+ onClick: ye,
1124
+ children: /* @__PURE__ */ Z(Er, { icon: "reset" })
1121
1125
  }),
1122
1126
  D ? /* @__PURE__ */ Z("span", {
1123
1127
  className: "markweave-mermaid-fullscreen-tooltip",
@@ -1132,18 +1136,18 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1132
1136
  className: "markweave-mermaid-fullscreen-close",
1133
1137
  "aria-label": "Close fullscreen Mermaid preview",
1134
1138
  "data-testid": "markweave-mermaid-fullscreen-close",
1135
- onClick: _e,
1136
- children: /* @__PURE__ */ Z(yr, { icon: "close" })
1139
+ onClick: ve,
1140
+ children: /* @__PURE__ */ Z(Er, { icon: "close" })
1137
1141
  }),
1138
1142
  /* @__PURE__ */ Z("div", {
1139
1143
  className: "markweave-mermaid-fullscreen-viewport",
1140
1144
  "data-testid": "markweave-mermaid-fullscreen-viewport",
1141
- "data-dragging": k ? "true" : "false",
1142
- onWheel: ve,
1143
- onMouseDown: ye,
1144
- onMouseMove: be,
1145
- onMouseUp: xe,
1146
- onMouseLeave: xe,
1145
+ "data-dragging": ee ? "true" : "false",
1146
+ onWheel: be,
1147
+ onMouseDown: K,
1148
+ onMouseMove: xe,
1149
+ onMouseUp: Se,
1150
+ onMouseLeave: Se,
1147
1151
  children: /* @__PURE__ */ Z("div", {
1148
1152
  className: "markweave-mermaid-fullscreen-content",
1149
1153
  "data-testid": "markweave-mermaid-fullscreen-content",
@@ -1164,25 +1168,25 @@ function br({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, read
1164
1168
  }
1165
1169
  //#endregion
1166
1170
  //#region src/ui/floating-toolbar/FloatingToolbar.tsx
1167
- var xr = Ae("zh");
1168
- function Sr() {
1171
+ var Or = je("zh");
1172
+ function kr() {
1169
1173
  return typeof performance > "u" ? Date.now() : performance.now();
1170
1174
  }
1171
- function Cr(e, t) {
1175
+ function Ar(e, t) {
1172
1176
  return {
1173
1177
  "--markweave-toolbar-motion-duration": `${e.motionDurationMs}ms`,
1174
1178
  "--markweave-toolbar-motion-easing": e.motionEasing,
1175
1179
  marginLeft: t === 0 ? void 0 : `${t}px`
1176
1180
  };
1177
1181
  }
1178
- function wr(e, t) {
1182
+ function jr(e, t) {
1179
1183
  let n = e?.getBoundingClientRect().height ?? 0, r = t?.getBoundingClientRect().height ?? 0;
1180
1184
  return Math.max(n, r, 44);
1181
1185
  }
1182
- function Tr(e) {
1186
+ function Mr(e) {
1183
1187
  if (e !== null) return { "--markweave-floating-toolbar-tooltip-left": `${e}px` };
1184
1188
  }
1185
- function Er(e, t, n, r) {
1189
+ function Nr(e, t, n, r) {
1186
1190
  let i = {
1187
1191
  bottom: t + r,
1188
1192
  height: r,
@@ -1198,26 +1202,26 @@ function Er(e, t, n, r) {
1198
1202
  toJSON: () => i
1199
1203
  };
1200
1204
  }
1201
- function Dr(e) {
1205
+ function Pr(e) {
1202
1206
  return e.width > 0 && e.height > 0;
1203
1207
  }
1204
- function Or(e) {
1208
+ function Fr(e) {
1205
1209
  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));
1206
- return Er(t, n, r - t, i - n);
1210
+ return Nr(t, n, r - t, i - n);
1207
1211
  }
1208
- function kr(e, t) {
1212
+ function Ir(e, t) {
1209
1213
  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;
1210
1214
  return r(t.anchorNode) && r(t.focusNode);
1211
1215
  }
1212
- function Ar(e) {
1216
+ function Lr(e) {
1213
1217
  if (typeof e.getClientRects != "function") return null;
1214
- let t = Array.from(e.getClientRects()).filter(Dr).map((e) => Er(e.left, e.top, e.width, e.height));
1218
+ let t = Array.from(e.getClientRects()).filter(Pr).map((e) => Nr(e.left, e.top, e.width, e.height));
1215
1219
  if (t.length > 0) return t;
1216
1220
  if (typeof e.getBoundingClientRect != "function") return null;
1217
1221
  let n = e.getBoundingClientRect();
1218
- return Dr(n) ? [Er(n.left, n.top, n.width, n.height)] : null;
1222
+ return Pr(n) ? [Nr(n.left, n.top, n.width, n.height)] : null;
1219
1223
  }
1220
- function jr(e, t) {
1224
+ function Rr(e, t) {
1221
1225
  if (t.rangeCount === 0) return null;
1222
1226
  let n = t.getRangeAt(0);
1223
1227
  try {
@@ -1230,8 +1234,8 @@ function jr(e, t) {
1230
1234
  return null;
1231
1235
  }
1232
1236
  }
1233
- function Mr(e, t) {
1234
- let n = jr(e, t);
1237
+ function zr(e, t) {
1238
+ let n = Rr(e, t);
1235
1239
  if (!n) return !1;
1236
1240
  let { selection: r } = e.state, i = {
1237
1241
  from: Math.min(r.from, r.to),
@@ -1239,51 +1243,51 @@ function Mr(e, t) {
1239
1243
  };
1240
1244
  return n.from === i.from && n.to === i.to;
1241
1245
  }
1242
- function Nr(e) {
1246
+ function Br(e) {
1243
1247
  let t = e.view.dom.ownerDocument.getSelection();
1244
- return !t || t.rangeCount === 0 || t.isCollapsed || !kr(e, t) || !Mr(e, t) ? null : Ar(t.getRangeAt(0));
1248
+ return !t || t.rangeCount === 0 || t.isCollapsed || !Ir(e, t) || !zr(e, t) ? null : Lr(t.getRangeAt(0));
1245
1249
  }
1246
- function Pr(e) {
1250
+ function Vr(e) {
1247
1251
  let { selection: t } = e.state;
1248
1252
  if (t.empty) return null;
1249
1253
  let n = Math.min(t.from, t.to), r = Math.max(t.from, t.to);
1250
1254
  try {
1251
1255
  let t = e.view.domAtPos(n), i = e.view.domAtPos(r), a = e.view.dom.ownerDocument.createRange();
1252
- return a.setStart(t.node, t.offset), a.setEnd(i.node, i.offset), Ar(a);
1256
+ return a.setStart(t.node, t.offset), a.setEnd(i.node, i.offset), Lr(a);
1253
1257
  } catch {
1254
1258
  return null;
1255
1259
  }
1256
1260
  }
1257
- function Fr(e) {
1261
+ function Hr(e) {
1258
1262
  let { selection: t } = e.state;
1259
1263
  if (t.empty) return null;
1260
- 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 = Er(c, o, Math.max(i.right, a.right) - c, s - o);
1261
- return Dr(l) ? [l] : null;
1264
+ 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 = Nr(c, o, Math.max(i.right, a.right) - c, s - o);
1265
+ return Pr(l) ? [l] : null;
1262
1266
  }
1263
- function Ir(e) {
1264
- return Nr(e) ?? Pr(e) ?? Fr(e);
1267
+ function Ur(e) {
1268
+ return Br(e) ?? Vr(e) ?? Hr(e);
1265
1269
  }
1266
- function Lr(e) {
1267
- let t = Ir(e);
1268
- return t && t.length > 0 ? Or(t) : null;
1270
+ function Wr(e) {
1271
+ let t = Ur(e);
1272
+ return t && t.length > 0 ? Fr(t) : null;
1269
1273
  }
1270
- function Rr(e) {
1274
+ function Gr(e) {
1271
1275
  return {
1272
- getBoundingClientRect: () => Lr(e) ?? Er(0, 0, 0, 0),
1273
- getClientRects: () => Ir(e) ?? []
1276
+ getBoundingClientRect: () => Wr(e) ?? Nr(0, 0, 0, 0),
1277
+ getClientRects: () => Ur(e) ?? []
1274
1278
  };
1275
1279
  }
1276
- function zr(e) {
1280
+ function Kr(e) {
1277
1281
  return e === "block-type" || e === "link" || e === "color" || e === "more";
1278
1282
  }
1279
- function Br(e, t, n) {
1280
- n?.(dn(e, t)), e.commands.focus();
1283
+ function qr(e, t, n) {
1284
+ n?.(_n(e, t)), e.commands.focus();
1281
1285
  }
1282
- function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelection: r }) {
1283
- let i = U(() => gn(t), [t]), a = Ze(n, { editable: e.isEditable }), [o, s] = G(a), [c, l] = G(null), [u, d] = G(null), [f, p] = G(null), [m, h] = G(""), [g, _] = G(""), [v, y] = G(null), [b, x] = G(0), [S, C] = G(a.boundaryPadding), w = W(0), T = W(null), E = W(null), D = W(null), O = fn(e, o.variant, t), k = vn(O.find((e) => e.id === c) ?? null), A = kn(m), j = V(() => {
1284
- let t = T.current, n = e.view.dom.closest(".markweave-editor-frame");
1286
+ function Jr({ editor: e, messages: t = Or, selectionSnapshot: n, onRewriteSelection: r }) {
1287
+ let i = H(() => Sn(t), [t]), a = et(n, { editable: e.isEditable }), [o, s] = W(a), [c, l] = W(null), [u, d] = W(null), [f, p] = W(null), [m, h] = W(""), [g, _] = W(""), [v, y] = W(null), [b, x] = W(0), [S, C] = W(a.boundaryPadding), [w, T] = W("bottom"), E = U(0), D = U(null), O = U(null), ee = U(null), k = U(null), A = vn(e, o.variant, t), j = wn(A.find((e) => e.id === c) ?? null), te = Fn(m), M = B(() => {
1288
+ let t = D.current, n = e.view.dom.closest(".markweave-editor-frame");
1285
1289
  if (!t || !(n instanceof HTMLElement)) return;
1286
- let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = wr(t, E.current), s = w.current, c = qe({
1290
+ let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = jr(t, O.current), s = E.current, c = Ye({
1287
1291
  toolbarRect: {
1288
1292
  left: r.left - s,
1289
1293
  top: r.top,
@@ -1297,7 +1301,7 @@ function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelect
1297
1301
  height: i.height
1298
1302
  },
1299
1303
  boundaryPadding: o.boundaryPadding
1300
- }), l = Je({
1304
+ }), l = Ze({
1301
1305
  frameRect: {
1302
1306
  left: i.left,
1303
1307
  top: i.top,
@@ -1311,28 +1315,49 @@ function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelect
1311
1315
  offset: o.offset,
1312
1316
  boundaryPadding: o.boundaryPadding
1313
1317
  });
1314
- t.style.marginLeft = c === 0 ? "" : `${c}px`, t.style.visibility = "visible", t.style.opacity = "1", w.current = c, x((e) => e === c ? e : c), C((e) => e === l ? e : l);
1318
+ 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);
1315
1319
  }, [
1316
1320
  e.view.dom,
1317
1321
  o.boundaryPadding,
1318
1322
  o.offset
1319
- ]), M = V(() => {
1320
- T.current && (T.current.style.visibility = "hidden", T.current.style.opacity = "0");
1321
- }, []), N = V(() => {
1322
- j();
1323
- }, [j]), P = V(() => Rr(e), [e]), F = U(() => ({
1324
- ...Xe(o, { topBoundaryPadding: S }),
1325
- onShow: M,
1326
- onUpdate: N
1323
+ ]), N = B(() => {
1324
+ D.current && (D.current.style.visibility = "hidden", D.current.style.opacity = "0");
1325
+ }, []), ne = B(() => {
1326
+ M();
1327
+ }, [M]), P = B(() => Gr(e), [e]), F = B((e) => {
1328
+ ee.current = e;
1329
+ }, []), I = B(() => {
1330
+ let t = D.current, n = ee.current, r = e.view.dom.closest(".markweave-editor-frame");
1331
+ if (!f || !t || !n) return;
1332
+ let i = t.getBoundingClientRect(), a = n.getBoundingClientRect(), s = r?.getBoundingClientRect() ?? null, c = Xe({
1333
+ toolbarRect: i,
1334
+ popoverSize: a,
1335
+ viewport: {
1336
+ width: window.innerWidth,
1337
+ height: window.innerHeight
1338
+ },
1339
+ frameRect: s,
1340
+ gap: f === "more" ? 8 : 6,
1341
+ boundaryPadding: o.boundaryPadding
1342
+ });
1343
+ T((e) => e === c.placement ? e : c.placement);
1344
+ }, [
1345
+ e.view.dom,
1346
+ f,
1347
+ o.boundaryPadding
1348
+ ]), re = H(() => ({
1349
+ ...$e(o, { topBoundaryPadding: S }),
1350
+ onShow: N,
1351
+ onUpdate: ne
1327
1352
  }), [
1328
- M,
1329
1353
  N,
1354
+ ne,
1330
1355
  o,
1331
1356
  S
1332
1357
  ]);
1333
- H(() => {
1334
- let e = Sr();
1335
- s((t) => $e(t, a, e));
1358
+ V(() => {
1359
+ let e = kr();
1360
+ s((t) => rt(t, a, e));
1336
1361
  }, [
1337
1362
  a.hiddenReason,
1338
1363
  a.motionDurationMs,
@@ -1344,10 +1369,10 @@ function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelect
1344
1369
  a.updateDelayMs,
1345
1370
  a.variant,
1346
1371
  a.visibility
1347
- ]), H(() => {
1372
+ ]), V(() => {
1348
1373
  if (o.motionStartedAtMs === null || o.motionDurationMs <= 0) return;
1349
- let e = Math.max(0, o.motionStartedAtMs + o.motionDurationMs - Sr()), t = window.setTimeout(() => {
1350
- s((e) => Ke(e, Sr()));
1374
+ let e = Math.max(0, o.motionStartedAtMs + o.motionDurationMs - kr()), t = window.setTimeout(() => {
1375
+ s((e) => qe(e, kr()));
1351
1376
  }, e);
1352
1377
  return () => {
1353
1378
  window.clearTimeout(t);
@@ -1356,53 +1381,59 @@ function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelect
1356
1381
  o.motionDurationMs,
1357
1382
  o.motionPhase,
1358
1383
  o.motionStartedAtMs
1359
- ]), me(() => {
1384
+ ]), he(() => {
1360
1385
  if (o.visibility !== "visible") {
1361
- w.current = 0, T.current && (T.current.style.marginLeft = "", T.current.style.visibility = "hidden", T.current.style.opacity = "0"), x(0), C(o.boundaryPadding);
1386
+ E.current = 0, D.current && (D.current.style.marginLeft = "", D.current.style.visibility = "hidden", D.current.style.opacity = "0"), x(0), C(o.boundaryPadding);
1362
1387
  return;
1363
1388
  }
1364
- let e = 0;
1365
- return e = window.requestAnimationFrame(j), window.addEventListener("resize", j), window.addEventListener("scroll", j, !0), () => {
1366
- window.cancelAnimationFrame(e), window.removeEventListener("resize", j), window.removeEventListener("scroll", j, !0);
1389
+ let e = hn(M);
1390
+ return e.schedule(), window.addEventListener("resize", e.schedule), window.addEventListener("scroll", e.schedule, !0), () => {
1391
+ e.cancel(), window.removeEventListener("resize", e.schedule), window.removeEventListener("scroll", e.schedule, !0);
1367
1392
  };
1368
1393
  }, [
1369
- j,
1394
+ M,
1370
1395
  e.view.dom,
1371
1396
  f,
1372
1397
  n?.from,
1373
1398
  n?.to,
1374
1399
  o.variant,
1375
1400
  o.visibility,
1376
- O.length
1377
- ]), H(() => {
1378
- f === "more" && i.some((e) => e.id === c) || O.some((e) => e.id === c) || (l(null), d(null));
1401
+ A.length
1402
+ ]), he(() => {
1403
+ if (!f) return;
1404
+ let e = hn(I);
1405
+ return e.schedule(), window.addEventListener("resize", e.schedule), window.addEventListener("scroll", e.schedule, !0), () => {
1406
+ e.cancel(), window.removeEventListener("resize", e.schedule), window.removeEventListener("scroll", e.schedule, !0);
1407
+ };
1408
+ }, [f, I]), V(() => {
1409
+ f === "more" && i.some((e) => e.id === c) || A.some((e) => e.id === c) || (l(null), d(null));
1379
1410
  }, [
1380
1411
  i,
1381
1412
  f,
1382
1413
  c,
1383
- O
1384
- ]), H(() => {
1414
+ A
1415
+ ]), V(() => {
1385
1416
  if (!f) return;
1386
1417
  let t = (e) => {
1387
- E.current?.contains(e.target) || p(null);
1418
+ O.current?.contains(e.target) || p(null);
1388
1419
  }, n = (t) => {
1389
1420
  t.key === "Escape" && (t.preventDefault(), p(null), e.commands.focus());
1390
1421
  };
1391
1422
  return document.addEventListener("pointerdown", t, !0), document.addEventListener("keydown", n, !0), () => {
1392
1423
  document.removeEventListener("pointerdown", t, !0), document.removeEventListener("keydown", n, !0);
1393
1424
  };
1394
- }, [e, f]), H(() => {
1425
+ }, [e, f]), V(() => {
1395
1426
  if (f !== "link") return;
1396
1427
  let e = window.requestAnimationFrame(() => {
1397
- D.current?.focus(), D.current?.select();
1428
+ k.current?.focus(), k.current?.select();
1398
1429
  });
1399
1430
  return () => window.cancelAnimationFrame(e);
1400
1431
  }, [f]);
1401
- let I = (t) => {
1402
- if (zr(t.id)) {
1432
+ let L = (t) => {
1433
+ if (Kr(t.id)) {
1403
1434
  let n = t.id;
1404
1435
  if (n === "link") {
1405
- let t = mn(e);
1436
+ let t = bn(e);
1406
1437
  h(t), _(t), y({
1407
1438
  from: Math.min(e.state.selection.from, e.state.selection.to),
1408
1439
  to: Math.max(e.state.selection.from, e.state.selection.to)
@@ -1412,102 +1443,108 @@ function Vr({ editor: e, messages: t = xr, selectionSnapshot: n, onRewriteSelect
1412
1443
  return;
1413
1444
  }
1414
1445
  if (p(null), t.id === "improve") {
1415
- Br(e, "rewrite-selection", r);
1446
+ qr(e, "rewrite-selection", r);
1416
1447
  return;
1417
1448
  }
1418
1449
  t.run(), e.commands.focus();
1419
- }, ee = () => {
1450
+ }, R = () => {
1420
1451
  p(null), e.commands.focus();
1421
- }, L = () => {
1452
+ }, ie = () => {
1422
1453
  v && e.commands.setTextSelection(v);
1423
- }, R = () => {
1424
- L(), un(e, m) && ee();
1425
- }, te = () => {
1426
- if (L(), wn(e)) {
1427
- h(""), _(""), ee();
1454
+ }, ae = () => {
1455
+ ie(), gn(e, m) && R();
1456
+ }, oe = () => {
1457
+ if (ie(), An(e)) {
1458
+ h(""), _(""), R();
1428
1459
  return;
1429
1460
  }
1430
1461
  m.trim() && h("");
1431
1462
  }, z = (e, t) => {
1432
- if (l(e), !e || !t || !E.current) {
1463
+ if (l(e), !e || !t || !O.current) {
1433
1464
  d(null);
1434
1465
  return;
1435
1466
  }
1436
- let n = t.getBoundingClientRect(), r = E.current.getBoundingClientRect();
1467
+ let n = t.getBoundingClientRect(), r = O.current.getBoundingClientRect();
1437
1468
  d(n.left + n.width / 2 - r.left);
1438
1469
  };
1439
- return /* @__PURE__ */ Z(ln, {
1440
- ref: T,
1470
+ return /* @__PURE__ */ Z(mn, {
1471
+ ref: D,
1441
1472
  editor: e,
1442
1473
  className: `markweave-floating-toolbar markweave-floating-toolbar--${o.variant} markweave-floating-toolbar--motion-${o.motionPhase}`,
1443
1474
  "data-motion": o.motionPhase,
1444
- "data-position-strategy": F.strategy,
1475
+ "data-position-strategy": re.strategy,
1445
1476
  "data-boundary-padding": o.boundaryPadding,
1477
+ "data-popover-placement": f ? w : void 0,
1446
1478
  "data-testid": "markweave-floating-toolbar",
1447
- style: Cr(o, b),
1479
+ style: Ar(o, b),
1448
1480
  updateDelay: 0,
1449
1481
  getReferencedVirtualElement: P,
1450
- options: F,
1451
- shouldShow: ({ editor: e }) => e.isEditable && Qe(Ye(e)),
1482
+ options: re,
1483
+ shouldShow: ({ editor: e }) => e.isEditable && nt(Qe(e)),
1452
1484
  children: /* @__PURE__ */ Q("div", {
1453
- ref: E,
1485
+ ref: O,
1454
1486
  className: "markweave-floating-toolbar-content",
1455
1487
  "data-menu": f ?? "none",
1456
1488
  children: [
1457
- O.map((e, t) => /* @__PURE__ */ Z(Ur, {
1489
+ A.map((e, t) => /* @__PURE__ */ Z(Xr, {
1458
1490
  button: e,
1459
1491
  expanded: f === e.id,
1460
- showDivider: t > 0 && O[t - 1].group !== e.group,
1492
+ showDivider: t > 0 && A[t - 1].group !== e.group,
1461
1493
  tooltipActive: c === e.id,
1462
- onPointerDown: Cn,
1494
+ onPointerDown: kn,
1463
1495
  onTooltipChange: z,
1464
- onRun: I
1496
+ onRun: L
1465
1497
  }, e.id)),
1466
- f === "block-type" ? /* @__PURE__ */ Z(Gr, {
1498
+ f === "block-type" ? /* @__PURE__ */ Z(Qr, {
1467
1499
  editor: e,
1468
1500
  messages: t,
1501
+ onPopoverRef: F,
1469
1502
  onClose: () => p(null)
1470
1503
  }) : null,
1471
- f === "link" ? /* @__PURE__ */ Z(Hr, {
1472
- inputRef: D,
1504
+ f === "link" ? /* @__PURE__ */ Z(Yr, {
1505
+ inputRef: k,
1473
1506
  messages: t,
1474
1507
  value: m,
1475
- canApply: !!A,
1476
- canOpen: !!A,
1508
+ canApply: !!te,
1509
+ canOpen: !!te,
1477
1510
  canRemove: !!(g || m.trim()),
1478
1511
  onValueChange: h,
1479
- onApply: R,
1480
- onOpen: () => Sn(m),
1481
- onRemove: te
1512
+ onApply: ae,
1513
+ onOpen: () => On(m),
1514
+ onRemove: oe,
1515
+ onPopoverRef: F
1482
1516
  }) : null,
1483
- f === "color" ? /* @__PURE__ */ Z(qr, {
1517
+ f === "color" ? /* @__PURE__ */ Z(ei, {
1484
1518
  editor: e,
1485
1519
  messages: t,
1520
+ onPopoverRef: F,
1486
1521
  onClose: () => p(null)
1487
1522
  }) : null,
1488
- f === "more" ? /* @__PURE__ */ Z(Yr, {
1523
+ f === "more" ? /* @__PURE__ */ Z(ni, {
1489
1524
  editor: e,
1490
1525
  messages: t,
1491
1526
  activeTooltipId: c,
1527
+ onPopoverRef: F,
1492
1528
  onTooltipChange: l,
1493
1529
  onClose: () => p(null)
1494
1530
  }) : null,
1495
- k && f === null ? /* @__PURE__ */ Z("div", {
1531
+ j && f === null ? /* @__PURE__ */ Z("div", {
1496
1532
  className: "markweave-floating-toolbar-tooltip",
1497
1533
  role: "tooltip",
1498
1534
  "data-testid": "markweave-floating-toolbar-tooltip",
1499
- "data-button-id": k.buttonId,
1500
- "data-active": k.active,
1501
- style: Tr(u),
1502
- children: k.label
1535
+ "data-button-id": j.buttonId,
1536
+ "data-active": j.active,
1537
+ style: Mr(u),
1538
+ children: j.label
1503
1539
  }) : null
1504
1540
  ]
1505
1541
  })
1506
1542
  });
1507
1543
  }
1508
- function Hr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRemove: a, onValueChange: o, onApply: s, onOpen: c, onRemove: l }) {
1509
- let u = hn(t);
1544
+ function Yr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRemove: a, onValueChange: o, onApply: s, onOpen: c, onRemove: l, onPopoverRef: u }) {
1545
+ let d = xn(t);
1510
1546
  return /* @__PURE__ */ Q("form", {
1547
+ ref: u,
1511
1548
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-link-popover",
1512
1549
  "data-testid": "markweave-floating-toolbar-link-popover",
1513
1550
  onSubmit: (e) => {
@@ -1515,9 +1552,9 @@ function Hr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1515
1552
  },
1516
1553
  children: [/* @__PURE__ */ Z("input", {
1517
1554
  ref: e,
1518
- "aria-label": u.linkUrlLabel,
1555
+ "aria-label": d.linkUrlLabel,
1519
1556
  "data-testid": "markweave-floating-toolbar-link-input",
1520
- placeholder: u.linkPlaceholder,
1557
+ placeholder: d.linkPlaceholder,
1521
1558
  value: n,
1522
1559
  onChange: (e) => o(e.currentTarget.value)
1523
1560
  }), /* @__PURE__ */ Q("span", {
@@ -1525,10 +1562,10 @@ function Hr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1525
1562
  children: [
1526
1563
  /* @__PURE__ */ Z("button", {
1527
1564
  type: "submit",
1528
- "aria-label": u.applyLink,
1565
+ "aria-label": d.applyLink,
1529
1566
  "data-testid": "markweave-floating-toolbar-link-apply",
1530
1567
  disabled: !r,
1531
- onMouseDown: Cn,
1568
+ onMouseDown: kn,
1532
1569
  children: /* @__PURE__ */ Z($, { name: "corner-down-left" })
1533
1570
  }),
1534
1571
  /* @__PURE__ */ Z("span", {
@@ -1537,19 +1574,19 @@ function Hr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1537
1574
  }),
1538
1575
  /* @__PURE__ */ Z("button", {
1539
1576
  type: "button",
1540
- "aria-label": u.openLink,
1577
+ "aria-label": d.openLink,
1541
1578
  "data-testid": "markweave-floating-toolbar-link-open",
1542
1579
  disabled: !i,
1543
- onMouseDown: Cn,
1580
+ onMouseDown: kn,
1544
1581
  onClick: c,
1545
1582
  children: /* @__PURE__ */ Z($, { name: "external-link" })
1546
1583
  }),
1547
1584
  /* @__PURE__ */ Z("button", {
1548
1585
  type: "button",
1549
- "aria-label": u.removeLink,
1586
+ "aria-label": d.removeLink,
1550
1587
  "data-testid": "markweave-floating-toolbar-link-remove",
1551
1588
  disabled: !a,
1552
- onMouseDown: Cn,
1589
+ onMouseDown: kn,
1553
1590
  onClick: l,
1554
1591
  children: /* @__PURE__ */ Z($, { name: "trash" })
1555
1592
  })
@@ -1557,7 +1594,7 @@ function Hr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRe
1557
1594
  })]
1558
1595
  });
1559
1596
  }
1560
- function Ur({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointerDown: i, onTooltipChange: a, onRun: o }) {
1597
+ function Xr({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointerDown: i, onTooltipChange: a, onRun: o }) {
1561
1598
  return /* @__PURE__ */ Q(X, { children: [n ? /* @__PURE__ */ Z("span", {
1562
1599
  className: "markweave-floating-toolbar-divider",
1563
1600
  "aria-hidden": "true"
@@ -1565,7 +1602,7 @@ function Ur({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointe
1565
1602
  type: "button",
1566
1603
  className: `markweave-floating-toolbar-button markweave-floating-toolbar-button--${e.id}`,
1567
1604
  "aria-label": e.label,
1568
- "aria-expanded": zr(e.id) ? t : void 0,
1605
+ "aria-expanded": Kr(e.id) ? t : void 0,
1569
1606
  "data-active": e.active || t,
1570
1607
  "data-tooltip-active": r ? "true" : "false",
1571
1608
  "data-testid": `markweave-floating-toolbar-button-${e.id}`,
@@ -1575,13 +1612,13 @@ function Ur({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointe
1575
1612
  onMouseEnter: (t) => a(e.id, t.currentTarget),
1576
1613
  onMouseLeave: () => a(null),
1577
1614
  onClick: () => o(e),
1578
- children: /* @__PURE__ */ Z(Wr, {
1615
+ children: /* @__PURE__ */ Z(Zr, {
1579
1616
  button: e,
1580
1617
  expanded: t
1581
1618
  })
1582
1619
  })] });
1583
1620
  }
1584
- function Wr({ button: e, expanded: t }) {
1621
+ function Zr({ button: e, expanded: t }) {
1585
1622
  return e.id === "improve" ? /* @__PURE__ */ Q("span", {
1586
1623
  className: "markweave-floating-toolbar-button-inner",
1587
1624
  children: [/* @__PURE__ */ Z($, { name: "sparkles" }), /* @__PURE__ */ Z("span", { children: e.glyph })]
@@ -1599,57 +1636,59 @@ function Wr({ button: e, expanded: t }) {
1599
1636
  }), /* @__PURE__ */ Z($, { name: t ? "chevron-up" : "chevron-down" })]
1600
1637
  }) : /* @__PURE__ */ Z($, { name: "more" });
1601
1638
  }
1602
- function Gr({ editor: e, messages: t, onClose: n }) {
1603
- let r = hn(t), i = yn(t);
1639
+ function Qr({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
1640
+ let i = xn(t), a = Tn(t);
1604
1641
  return /* @__PURE__ */ Q("div", {
1642
+ ref: n,
1605
1643
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-turn-menu",
1606
1644
  "data-testid": "markweave-floating-toolbar-turn-menu",
1607
1645
  children: [/* @__PURE__ */ Z("div", {
1608
1646
  className: "markweave-floating-toolbar-menu-title",
1609
- children: r.turnIntoTitle
1610
- }), i.map((t) => /* @__PURE__ */ Q("button", {
1647
+ children: i.turnIntoTitle
1648
+ }), a.map((t) => /* @__PURE__ */ Q("button", {
1611
1649
  type: "button",
1612
- "data-active": xn(e, t.id),
1650
+ "data-active": Dn(e, t.id),
1613
1651
  "data-testid": `markweave-floating-toolbar-turn-${t.id}`,
1614
- onMouseDown: Cn,
1652
+ onMouseDown: kn,
1615
1653
  onClick: () => {
1616
- On(e, t.id), n();
1654
+ Pn(e, t.id), r();
1617
1655
  },
1618
1656
  children: [/* @__PURE__ */ Z("span", {
1619
1657
  className: "markweave-floating-toolbar-menu-icon",
1620
- children: /* @__PURE__ */ Z(Kr, { option: t })
1658
+ children: /* @__PURE__ */ Z($r, { option: t })
1621
1659
  }), /* @__PURE__ */ Z("span", { children: t.label })]
1622
1660
  }, t.id))]
1623
1661
  });
1624
1662
  }
1625
- function Kr({ option: e }) {
1663
+ function $r({ option: e }) {
1626
1664
  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 });
1627
1665
  }
1628
- function qr({ editor: e, messages: t, onClose: n }) {
1629
- let r = hn(t), i = e.getAttributes("textStyle").color, a = e.getAttributes("highlight").color;
1666
+ function ei({ editor: e, messages: t, onPopoverRef: n, onClose: r }) {
1667
+ let i = xn(t), a = e.getAttributes("textStyle").color, o = e.getAttributes("highlight").color;
1630
1668
  return /* @__PURE__ */ Q("div", {
1669
+ ref: n,
1631
1670
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-color-popover",
1632
1671
  "data-testid": "markweave-floating-toolbar-color-menu",
1633
- children: [/* @__PURE__ */ Z(Jr, {
1634
- title: r.textColorTitle,
1672
+ children: [/* @__PURE__ */ Z(ti, {
1673
+ title: i.textColorTitle,
1635
1674
  mode: "text",
1636
- activeColor: i ?? null,
1637
- options: _n(t),
1675
+ activeColor: a ?? null,
1676
+ options: Cn(t),
1638
1677
  onSelect: (t) => {
1639
- Dn(e, t), n();
1678
+ Nn(e, t), r();
1640
1679
  }
1641
- }), /* @__PURE__ */ Z(Jr, {
1642
- title: r.highlightColorTitle,
1680
+ }), /* @__PURE__ */ Z(ti, {
1681
+ title: i.highlightColorTitle,
1643
1682
  mode: "highlight",
1644
- activeColor: a ?? null,
1645
- options: pn(t),
1683
+ activeColor: o ?? null,
1684
+ options: yn(t),
1646
1685
  onSelect: (t) => {
1647
- En(e, t), n();
1686
+ Mn(e, t), r();
1648
1687
  }
1649
1688
  })]
1650
1689
  });
1651
1690
  }
1652
- function Jr({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
1691
+ function ti({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
1653
1692
  return /* @__PURE__ */ Q("section", {
1654
1693
  className: "markweave-floating-toolbar-color-section",
1655
1694
  "aria-label": e,
@@ -1663,7 +1702,7 @@ function Jr({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
1663
1702
  "aria-label": e.label,
1664
1703
  "data-active": e.value === n || e.value === null && !n,
1665
1704
  "data-testid": `markweave-floating-toolbar-${t}-${e.id}`,
1666
- onMouseDown: Cn,
1705
+ onMouseDown: kn,
1667
1706
  onClick: () => i(e.value),
1668
1707
  children: t === "text" ? /* @__PURE__ */ Z("span", {
1669
1708
  className: "markweave-floating-toolbar-text-swatch",
@@ -1678,24 +1717,25 @@ function Jr({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
1678
1717
  })]
1679
1718
  });
1680
1719
  }
1681
- function Yr({ editor: e, messages: t, activeTooltipId: n, onTooltipChange: r, onClose: i }) {
1682
- let a = gn(t);
1720
+ function ni({ editor: e, messages: t, activeTooltipId: n, onPopoverRef: r, onTooltipChange: i, onClose: a }) {
1721
+ let o = Sn(t);
1683
1722
  return /* @__PURE__ */ Z("div", {
1723
+ ref: r,
1684
1724
  className: "markweave-floating-toolbar-popover markweave-floating-toolbar-more-menu",
1685
1725
  "data-testid": "markweave-floating-toolbar-more-menu",
1686
- children: a.map((t, o) => /* @__PURE__ */ Z(Xr, {
1726
+ children: o.map((t, r) => /* @__PURE__ */ Z(ri, {
1687
1727
  action: t,
1688
- active: bn(e, t.id),
1728
+ active: En(e, t.id),
1689
1729
  tooltipActive: n === t.id,
1690
- showDivider: o > 0 && a[o - 1].group !== t.group,
1691
- onTooltipChange: r,
1730
+ showDivider: r > 0 && o[r - 1].group !== t.group,
1731
+ onTooltipChange: i,
1692
1732
  onRun: () => {
1693
- Tn(e, t.id), i();
1733
+ jn(e, t.id), a();
1694
1734
  }
1695
1735
  }, t.id))
1696
1736
  });
1697
1737
  }
1698
- function Xr({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipChange: i, onRun: a }) {
1738
+ function ri({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipChange: i, onRun: a }) {
1699
1739
  return /* @__PURE__ */ Q(X, { children: [r ? /* @__PURE__ */ Z("span", {
1700
1740
  className: "markweave-floating-toolbar-divider",
1701
1741
  "aria-hidden": "true"
@@ -1707,11 +1747,11 @@ function Xr({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipC
1707
1747
  "data-active": t,
1708
1748
  "data-tooltip-active": n ? "true" : "false",
1709
1749
  "data-testid": `markweave-floating-toolbar-more-${e.id}`,
1710
- onMouseDown: Cn,
1750
+ onMouseDown: kn,
1711
1751
  onMouseEnter: () => i(e.id),
1712
1752
  onMouseLeave: () => i(null),
1713
1753
  onClick: a,
1714
- children: /* @__PURE__ */ Z(Zr, { id: e.id })
1754
+ children: /* @__PURE__ */ Z(ii, { id: e.id })
1715
1755
  }), n ? /* @__PURE__ */ Z("div", {
1716
1756
  className: "markweave-floating-toolbar-tooltip markweave-floating-toolbar-tooltip--more",
1717
1757
  role: "tooltip",
@@ -1719,41 +1759,41 @@ function Xr({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipC
1719
1759
  }) : null]
1720
1760
  })] });
1721
1761
  }
1722
- function Zr({ id: e }) {
1762
+ function ii({ id: e }) {
1723
1763
  return e === "superscript" ? /* @__PURE__ */ Z($, { name: "superscript" }) : e === "subscript" ? /* @__PURE__ */ Z($, { name: "subscript" }) : e === "inline-math" ? /* @__PURE__ */ Z($, { name: "math" }) : Z($, { name: e });
1724
1764
  }
1725
- var Qr = {
1726
- sparkles: ie,
1765
+ var ai = {
1766
+ sparkles: ae,
1727
1767
  "chevron-down": h,
1728
1768
  "chevron-up": g,
1729
1769
  "corner-down-left": y,
1730
1770
  "external-link": x,
1731
1771
  bold: u,
1732
- italic: j,
1772
+ italic: A,
1733
1773
  underline: fe,
1734
- strike: ae,
1774
+ strike: oe,
1735
1775
  "inline-code": v,
1736
- link: N,
1737
- more: L,
1776
+ link: te,
1777
+ more: F,
1738
1778
  text: de,
1739
- "bullet-list": P,
1740
- "numbered-list": I,
1741
- "todo-list": F,
1742
- quote: te,
1779
+ "bullet-list": M,
1780
+ "numbered-list": ne,
1781
+ "todo-list": N,
1782
+ quote: re,
1743
1783
  "code-block": d,
1744
1784
  superscript: se,
1745
- subscript: oe,
1746
- math: ne,
1785
+ subscript: z,
1786
+ math: R,
1747
1787
  "align-left": c,
1748
1788
  "align-center": o,
1749
1789
  "align-right": l,
1750
1790
  "align-justify": s,
1751
1791
  "decrease-indent": O,
1752
- "increase-indent": k,
1792
+ "increase-indent": ee,
1753
1793
  trash: ue
1754
1794
  };
1755
1795
  function $({ name: e }) {
1756
- let t = Qr[e];
1796
+ let t = ai[e];
1757
1797
  return /* @__PURE__ */ Z(t, {
1758
1798
  "aria-hidden": "true",
1759
1799
  absoluteStrokeWidth: !0,
@@ -1763,24 +1803,24 @@ function $({ name: e }) {
1763
1803
  }
1764
1804
  //#endregion
1765
1805
  //#region src/ui/math/MathEditorPopover.tsx
1766
- function $r({ editor: e, messages: t, onClose: n, target: r }) {
1767
- let i = W(null), a = W(null), [o, s] = G(r.latex), [c, l] = G(null), u = t.math, d = U(() => ht(e, r) ?? 1, [e, r]), f = U(() => gt(e, r), [e, r]), m = U(() => o === r.latex && f ? {
1806
+ function oi({ editor: e, messages: t, onClose: n, target: r }) {
1807
+ let i = U(null), a = U(null), [o, s] = W(r.latex), [c, l] = W(null), u = t.math, d = H(() => bt(e, r) ?? 1, [e, r]), f = H(() => xt(e, r), [e, r]), m = H(() => o === r.latex && f ? {
1768
1808
  html: f,
1769
1809
  error: !1
1770
- } : bt(o, r.kind, e), [
1810
+ } : Tt(o, r.kind, e), [
1771
1811
  e,
1772
1812
  f,
1773
1813
  r.kind,
1774
1814
  r.latex,
1775
1815
  o
1776
- ]), h = o.trim().length > 0, g = V(() => {
1816
+ ]), h = o.trim().length > 0, g = B(() => {
1777
1817
  if (typeof window > "u") return;
1778
- let t = mt(e, r), i = e.view.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
1818
+ let t = yt(e, r), i = e.view.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
1779
1819
  if (!t || !i) {
1780
1820
  n();
1781
1821
  return;
1782
1822
  }
1783
- l(pt({
1823
+ l(vt({
1784
1824
  anchorRect: t,
1785
1825
  frameRect: i,
1786
1826
  kind: r.kind,
@@ -1794,30 +1834,30 @@ function $r({ editor: e, messages: t, onClose: n, target: r }) {
1794
1834
  r,
1795
1835
  o
1796
1836
  ]);
1797
- H(() => {
1837
+ V(() => {
1798
1838
  s(r.latex);
1799
- }, [r.latex, r.pos]), H(() => {
1800
- xt(e, r, !0), g();
1839
+ }, [r.latex, r.pos]), V(() => {
1840
+ Et(e, r, !0), g();
1801
1841
  let t = window.requestAnimationFrame(() => {
1802
1842
  a.current?.focus({ preventScroll: !0 }), a.current?.select(), g();
1803
1843
  });
1804
1844
  return window.addEventListener("resize", g), window.addEventListener("scroll", g, !0), () => {
1805
- window.cancelAnimationFrame(t), window.removeEventListener("resize", g), window.removeEventListener("scroll", g, !0), xt(e, r, !1);
1845
+ window.cancelAnimationFrame(t), window.removeEventListener("resize", g), window.removeEventListener("scroll", g, !0), Et(e, r, !1);
1806
1846
  };
1807
1847
  }, [
1808
1848
  e,
1809
1849
  n,
1810
1850
  r,
1811
1851
  g
1812
- ]), H(() => {
1852
+ ]), V(() => {
1813
1853
  let e = (e) => {
1814
1854
  let t = e.target;
1815
1855
  t instanceof Node && (i.current?.contains(t) || t instanceof Element && t.closest(".tiptap-mathematics-render") || n());
1816
1856
  };
1817
1857
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
1818
1858
  }, [n]);
1819
- let _ = V(() => {
1820
- h && ft(e, r, o) && n();
1859
+ let _ = B(() => {
1860
+ h && _t(e, r, o) && n();
1821
1861
  }, [
1822
1862
  h,
1823
1863
  e,
@@ -1948,31 +1988,31 @@ function $r({ editor: e, messages: t, onClose: n, target: r }) {
1948
1988
  }
1949
1989
  //#endregion
1950
1990
  //#region src/ui/slash-command/SlashCommandMenu.tsx
1951
- var ei = Ae("zh"), ti = {
1991
+ var si = je("zh"), ci = {
1952
1992
  type: le,
1953
1993
  "heading-1": C,
1954
1994
  "heading-2": w,
1955
1995
  "heading-3": T,
1956
- "bullet-list": P,
1957
- "ordered-list": I,
1958
- "task-list": F,
1959
- blockquote: te,
1996
+ "bullet-list": M,
1997
+ "ordered-list": ne,
1998
+ "task-list": N,
1999
+ blockquote: re,
1960
2000
  "code-block": d,
1961
- info: A,
1962
- tip: M,
2001
+ info: k,
2002
+ tip: j,
1963
2003
  warning: a,
1964
2004
  error: _,
1965
2005
  success: m,
1966
- emoji: re,
1967
- math: ne,
2006
+ emoji: ie,
2007
+ math: R,
1968
2008
  table: ce,
1969
- separator: ee,
2009
+ separator: P,
1970
2010
  image: E,
1971
- video: B,
1972
- attachment: R
2011
+ video: me,
2012
+ attachment: I
1973
2013
  };
1974
- function ni({ name: e }) {
1975
- let t = ti[e];
2014
+ function li({ name: e }) {
2015
+ let t = ci[e];
1976
2016
  return /* @__PURE__ */ Z(t, {
1977
2017
  "aria-hidden": "true",
1978
2018
  absoluteStrokeWidth: !0,
@@ -1980,8 +2020,8 @@ function ni({ name: e }) {
1980
2020
  strokeWidth: 1.6
1981
2021
  });
1982
2022
  }
1983
- function ri(e, t, n) {
1984
- return !Dt(e) || !n ? {
2023
+ function ui(e, t, n) {
2024
+ return !Mt(e) || !n ? {
1985
2025
  visible: !1,
1986
2026
  empty: !1,
1987
2027
  activeIndex: -1
@@ -1995,17 +2035,17 @@ function ri(e, t, n) {
1995
2035
  activeIndex: Math.min(t.length - 1, Math.max(0, e.activeIndex))
1996
2036
  };
1997
2037
  }
1998
- function ii(e, t) {
2038
+ function di(e, t) {
1999
2039
  return Object.values(t.slash.groups).map((t) => ({
2000
2040
  group: t,
2001
2041
  commands: e.filter((e) => e.group === t)
2002
2042
  })).filter((e) => e.commands.length > 0);
2003
2043
  }
2004
- function ai(e, t) {
2044
+ function fi(e, t) {
2005
2045
  return t.slash.uploadKindLabels[e] ?? t.slash.uploadKindLabels.upload;
2006
2046
  }
2007
- function oi({ command: e, messages: t, onBack: n, onSelect: r }) {
2008
- let [i, a] = G(""), [o, s] = G(0), c = U(() => {
2047
+ function pi({ command: e, messages: t, onBack: n, onSelect: r }) {
2048
+ let [i, a] = W(""), [o, s] = W(0), c = H(() => {
2009
2049
  let e = i.trim().toLowerCase();
2010
2050
  return (e ? t.slash.emojiItems.filter((t) => [
2011
2051
  t.emoji,
@@ -2071,9 +2111,9 @@ function oi({ command: e, messages: t, onBack: n, onSelect: r }) {
2071
2111
  ]
2072
2112
  });
2073
2113
  }
2074
- function si({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2075
- let a = e.uploadKind ?? "attachment", [o, s] = G(""), [c, l] = G(null), [u, d] = G(null), [f, p] = G(!1), m = async (t) => {
2076
- r(e, { uploadResult: await K({
2114
+ function mi({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2115
+ let a = e.uploadKind ?? "attachment", [o, s] = W(""), [c, l] = W(null), [u, d] = W(null), [f, p] = W(!1), m = async (t) => {
2116
+ r(e, { uploadResult: await G({
2077
2117
  kind: a,
2078
2118
  source: t,
2079
2119
  trigger: "slash-command"
@@ -2093,7 +2133,7 @@ function si({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2093
2133
  d(t.slash.uploadRequiredError);
2094
2134
  return;
2095
2135
  }
2096
- await m(ge(o));
2136
+ await m(_e(o));
2097
2137
  } catch (e) {
2098
2138
  d(e instanceof Error ? e.message : t.slash.uploadFailedError);
2099
2139
  } finally {
@@ -2111,7 +2151,7 @@ function si({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2111
2151
  onMouseDown: (e) => e.preventDefault(),
2112
2152
  onClick: n,
2113
2153
  children: t.common.back
2114
- }), /* @__PURE__ */ Z("span", { children: ai(a, t) })]
2154
+ }), /* @__PURE__ */ Z("span", { children: fi(a, t) })]
2115
2155
  }),
2116
2156
  /* @__PURE__ */ Q("label", {
2117
2157
  className: "markweave-slash-upload-field",
@@ -2159,10 +2199,10 @@ function si({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
2159
2199
  ]
2160
2200
  });
2161
2201
  }
2162
- function ci({ commands: e, messages: t = ei, state: n, position: r, inputCommand: i, onActiveIndexChange: a, onInputCommandChange: o, onSelect: s, onUpload: c }) {
2163
- let l = ri(n, e, r);
2202
+ function hi({ commands: e, messages: t = si, state: n, position: r, inputCommand: i, onActiveIndexChange: a, onInputCommandChange: o, onSelect: s, onUpload: c }) {
2203
+ let l = ui(n, e, r);
2164
2204
  if (!l.visible || !r) return null;
2165
- let u = ii(e, t), d = {
2205
+ let u = di(e, t), d = {
2166
2206
  left: r.left,
2167
2207
  top: r.top,
2168
2208
  maxHeight: r.maxHeight,
@@ -2184,12 +2224,12 @@ function ci({ commands: e, messages: t = ei, state: n, position: r, inputCommand
2184
2224
  "aria-label": t.slash.ariaLabel,
2185
2225
  "data-placement": r.placement,
2186
2226
  "data-testid": "markweave-slash-menu",
2187
- children: i?.inputKind === "emoji" ? /* @__PURE__ */ Z(oi, {
2227
+ children: i?.inputKind === "emoji" ? /* @__PURE__ */ Z(pi, {
2188
2228
  command: i,
2189
2229
  messages: t,
2190
2230
  onBack: m,
2191
2231
  onSelect: s
2192
- }) : i?.inputKind === "upload" ? /* @__PURE__ */ Z(si, {
2232
+ }) : i?.inputKind === "upload" ? /* @__PURE__ */ Z(mi, {
2193
2233
  command: i,
2194
2234
  messages: t,
2195
2235
  onBack: m,
@@ -2209,7 +2249,7 @@ function ci({ commands: e, messages: t = ei, state: n, position: r, inputCommand
2209
2249
  className: "markweave-slash-group-title",
2210
2250
  children: t.group
2211
2251
  }), t.commands.map((t) => {
2212
- let n = e.indexOf(t), r = n === l.activeIndex, i = Tt(t), o = !!t.disabled;
2252
+ let n = e.indexOf(t), r = n === l.activeIndex, i = At(t), o = !!t.disabled;
2213
2253
  return /* @__PURE__ */ Q("button", {
2214
2254
  type: "button",
2215
2255
  role: "option",
@@ -2233,7 +2273,7 @@ function ci({ commands: e, messages: t = ei, state: n, position: r, inputCommand
2233
2273
  }
2234
2274
  },
2235
2275
  children: [
2236
- /* @__PURE__ */ Z(ni, { name: t.icon }),
2276
+ /* @__PURE__ */ Z(li, { name: t.icon }),
2237
2277
  /* @__PURE__ */ Z("span", { children: t.label }),
2238
2278
  o && t.disabledReason ? /* @__PURE__ */ Z("small", { children: t.disabledReason }) : null
2239
2279
  ]
@@ -2245,38 +2285,38 @@ function ci({ commands: e, messages: t = ei, state: n, position: r, inputCommand
2245
2285
  }
2246
2286
  //#endregion
2247
2287
  //#region src/ui/table/TableControls.tsx
2248
- var li = Ae("zh");
2249
- function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li, onCopyPayload: i, onCommandResult: a, onEditWithAi: o }) {
2250
- let [s, c] = G(null), [l, u] = G("row-edge"), [d, f] = G(null), [p, m] = G(null), [h, g] = G(null), [_, v] = G(null), [y, b] = G(null), x = W(null), S = W(null), C = W(null), w = W(null), T = W(null), E = e ? It(t.state) : null;
2251
- if (H(() => {
2288
+ var gi = je("zh");
2289
+ function _i({ active: e, editor: t, interactionState: n = Ut, messages: r = gi, onCopyPayload: i, onCommandResult: a, onEditWithAi: o }) {
2290
+ let [s, c] = W(null), [l, u] = W("row-edge"), [d, f] = W(null), [p, m] = W(null), [h, g] = W(null), [_, v] = W(null), [y, b] = W(null), x = U(null), S = U(null), C = U(null), w = U(null), T = U(null), E = e ? Vt(t.state) : null;
2291
+ if (V(() => {
2252
2292
  if (!y) return;
2253
2293
  let e = window.setTimeout(() => {
2254
2294
  b(null);
2255
- }, qn);
2295
+ }, $n);
2256
2296
  return () => {
2257
2297
  window.clearTimeout(e);
2258
2298
  };
2259
- }, [y]), me(() => {
2299
+ }, [y]), he(() => {
2260
2300
  if (!e) {
2261
2301
  m(null), g(null), v(null), b(null);
2262
2302
  return;
2263
2303
  }
2264
2304
  let r = () => {
2265
- let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, r = zn(t, n, "row", E?.activeCellPos ?? null), i = zn(t, n, "column", E?.activeCellPos ?? null), a = r ? Rn(t, r) : null, o = i ? Rn(t, i) : null, c = Ln(t).length > 0 ? Wn(t) : null;
2305
+ let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, r = Gn(t, n, "row", E?.activeCellPos ?? null), i = Gn(t, n, "column", E?.activeCellPos ?? null), a = r ? Wn(t, r) : null, o = i ? Wn(t, i) : null, c = Un(t).length > 0 ? Xn(t) : null;
2266
2306
  if (!e) {
2267
2307
  m(null), g(null), v(null);
2268
2308
  return;
2269
2309
  }
2270
2310
  let u = e.getBoundingClientRect();
2271
- a ? m(Mn({
2311
+ a ? m(Rn({
2272
2312
  targetRect: a,
2273
2313
  frameRect: u,
2274
2314
  kind: "row"
2275
- })) : s === "row" && l === "row-edge" || m(null), o ? g(Mn({
2315
+ })) : s === "row" && l === "row-edge" || m(null), o ? g(Rn({
2276
2316
  targetRect: o,
2277
2317
  frameRect: u,
2278
2318
  kind: "column"
2279
- })) : s === "column" && l === "column-edge" || g(null), c ? v(Mn({
2319
+ })) : s === "column" && l === "column-edge" || g(null), c ? v(Rn({
2280
2320
  targetRect: c,
2281
2321
  frameRect: u,
2282
2322
  kind: "selection"
@@ -2296,7 +2336,7 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2296
2336
  n.hoverVisualRowIndex,
2297
2337
  l,
2298
2338
  s
2299
- ]), me(() => {
2339
+ ]), he(() => {
2300
2340
  if (!e || !s) {
2301
2341
  f(null);
2302
2342
  return;
@@ -2307,12 +2347,12 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2307
2347
  f(null);
2308
2348
  return;
2309
2349
  }
2310
- let i = n.getBoundingClientRect(), a = s === "row" ? In(t)?.getBoundingClientRect() : null, o = a ? {
2350
+ let i = n.getBoundingClientRect(), a = s === "row" ? Hn(t)?.getBoundingClientRect() : null, o = a ? {
2311
2351
  left: i.left,
2312
2352
  top: a.top,
2313
2353
  width: i.width,
2314
2354
  height: i.height
2315
- } : i, c = e.getBoundingClientRect(), u = r.getBoundingClientRect(), d = jn({
2355
+ } : i, c = e.getBoundingClientRect(), u = r.getBoundingClientRect(), d = Ln({
2316
2356
  anchorRect: o,
2317
2357
  frameRect: c,
2318
2358
  menuSize: {
@@ -2334,7 +2374,7 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2334
2374
  p,
2335
2375
  h,
2336
2376
  _
2337
- ]), H(() => {
2377
+ ]), V(() => {
2338
2378
  if (!e || !s) return;
2339
2379
  let n = (e) => {
2340
2380
  e.key === "Escape" && (c(null), t.view.focus());
@@ -2353,22 +2393,22 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2353
2393
  let n = s === e && l === t;
2354
2394
  u(t), c(n ? null : e);
2355
2395
  }, O = () => {
2356
- t.view.dispatch(An(t.state.tr, null));
2357
- }, k = (e, r) => {
2396
+ t.view.dispatch(In(t.state.tr, null));
2397
+ }, ee = (e, r) => {
2358
2398
  let i = n.hoverCellPos ?? E?.activeCellPos ?? null, a = n.hoverCellPos === null ? null : e === "row" ? n.hoverVisualRowIndex : n.hoverVisualColumnIndex;
2359
- i !== null && Kn(t, i, e, { visualIndex: a }), D(e, r);
2360
- }, A = () => {
2399
+ i !== null && Qn(t, i, e, { visualIndex: a }), D(e, r);
2400
+ }, k = () => {
2361
2401
  O(), D("selection", "selection-edge");
2362
- }, j = zn(t, n, "row", E?.activeCellPos ?? null), M = zn(t, n, "column", E?.activeCellPos ?? null), N = Ln(t).length > 0, P = s ? Un(t, s) : [], F = async (e, n) => {
2363
- let o = await Pn({
2402
+ }, A = Gn(t, n, "row", E?.activeCellPos ?? null), j = Gn(t, n, "column", E?.activeCellPos ?? null), te = Un(t).length > 0, M = s ? Yn(t, s) : [], N = async (e, n) => {
2403
+ let o = await Bn({
2364
2404
  editor: t,
2365
2405
  commandId: e,
2366
2406
  menu: n ?? s ?? "selection",
2367
2407
  messages: r
2368
2408
  });
2369
2409
  return o.copyFeedback ? (b(o.copyFeedback), o.copyPayload && i?.(o.copyPayload)) : b(null), a?.(o.commandResult), o.success;
2370
- }, I = (e) => {
2371
- let n = Bn(t, e);
2410
+ }, ne = (e) => {
2411
+ let n = Kn(t, e);
2372
2412
  n && o?.(n), c(null), t.view.focus();
2373
2413
  };
2374
2414
  return /* @__PURE__ */ Q("div", {
@@ -2387,7 +2427,7 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2387
2427
  "data-copy-kind": y.kind,
2388
2428
  "data-text-length": y.textLength,
2389
2429
  "data-html-length": y.htmlLength,
2390
- children: Fn(y)
2430
+ children: Vn(y)
2391
2431
  }) : null,
2392
2432
  p ? /* @__PURE__ */ Z("button", {
2393
2433
  type: "button",
@@ -2398,17 +2438,17 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2398
2438
  "aria-haspopup": "menu",
2399
2439
  title: r.table.rowActions,
2400
2440
  "data-testid": "markweave-table-hover-row-handle",
2401
- "data-axis-index": j?.index ?? "",
2402
- "data-axis-selected-cells": j?.selectedCellCount ?? "",
2403
- "data-axis-visual-cells": j?.visualCellCount ?? "",
2404
- "data-axis-visual-size": j?.visualHeight ?? "",
2441
+ "data-axis-index": A?.index ?? "",
2442
+ "data-axis-selected-cells": A?.selectedCellCount ?? "",
2443
+ "data-axis-visual-cells": A?.visualCellCount ?? "",
2444
+ "data-axis-visual-size": A?.visualHeight ?? "",
2405
2445
  style: {
2406
2446
  left: p.left,
2407
2447
  top: p.top
2408
2448
  },
2409
2449
  onMouseDown: (e) => e.preventDefault(),
2410
2450
  onClick: () => {
2411
- k("row", "row-edge");
2451
+ ee("row", "row-edge");
2412
2452
  },
2413
2453
  children: /* @__PURE__ */ Z("span", {
2414
2454
  "aria-hidden": "true",
@@ -2424,24 +2464,24 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2424
2464
  "aria-haspopup": "menu",
2425
2465
  title: r.table.columnActions,
2426
2466
  "data-testid": "markweave-table-hover-column-handle",
2427
- "data-axis-index": M?.index ?? "",
2428
- "data-axis-selected-cells": M?.selectedCellCount ?? "",
2429
- "data-axis-visual-cells": M?.visualCellCount ?? "",
2430
- "data-axis-visual-size": M?.visualWidth ?? "",
2467
+ "data-axis-index": j?.index ?? "",
2468
+ "data-axis-selected-cells": j?.selectedCellCount ?? "",
2469
+ "data-axis-visual-cells": j?.visualCellCount ?? "",
2470
+ "data-axis-visual-size": j?.visualWidth ?? "",
2431
2471
  style: {
2432
2472
  left: h.left,
2433
2473
  top: h.top
2434
2474
  },
2435
2475
  onMouseDown: (e) => e.preventDefault(),
2436
2476
  onClick: () => {
2437
- k("column", "column-edge");
2477
+ ee("column", "column-edge");
2438
2478
  },
2439
2479
  children: /* @__PURE__ */ Z("span", {
2440
2480
  "aria-hidden": "true",
2441
2481
  children: "..."
2442
2482
  })
2443
2483
  }) : null,
2444
- N && _ ? /* @__PURE__ */ Z("button", {
2484
+ te && _ ? /* @__PURE__ */ Z("button", {
2445
2485
  type: "button",
2446
2486
  ref: T,
2447
2487
  className: "markweave-table-edge-handle markweave-table-edge-handle--selection",
@@ -2455,7 +2495,7 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2455
2495
  top: _.top
2456
2496
  },
2457
2497
  onMouseDown: (e) => e.preventDefault(),
2458
- onClick: A,
2498
+ onClick: k,
2459
2499
  children: /* @__PURE__ */ Z("span", {
2460
2500
  "aria-hidden": "true",
2461
2501
  children: "..."
@@ -2465,15 +2505,15 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2465
2505
  ref: S,
2466
2506
  className: "markweave-table-menu",
2467
2507
  role: "menu",
2468
- "aria-label": Jn(s, r),
2508
+ "aria-label": er(s, r),
2469
2509
  "data-testid": "markweave-table-menu",
2470
2510
  "data-positioned": d ? "true" : "false",
2471
2511
  style: d ? {
2472
2512
  left: d.left,
2473
2513
  top: d.top
2474
2514
  } : void 0,
2475
- children: P.map((e, n) => {
2476
- let i = Vn(e), a = n === 0 ? i : Vn(P[n - 1]), l = n > 0 && a !== i, u = e.commandId === null ? !!o : Nn(t, e.commandId), d = Hn(e, r);
2515
+ children: M.map((e, n) => {
2516
+ let i = qn(e), a = n === 0 ? i : qn(M[n - 1]), l = n > 0 && a !== i, u = e.commandId === null ? !!o : zn(t, e.commandId), d = Jn(e, r);
2477
2517
  return /* @__PURE__ */ Z("button", {
2478
2518
  type: "button",
2479
2519
  role: "menuitem",
@@ -2488,10 +2528,10 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2488
2528
  onClick: () => {
2489
2529
  if (u) {
2490
2530
  if (e.commandId === null) {
2491
- I(s === "row" || s === "column" ? s : "selection");
2531
+ ne(s === "row" || s === "column" ? s : "selection");
2492
2532
  return;
2493
2533
  }
2494
- F(e.commandId).finally(() => c(null));
2534
+ N(e.commandId).finally(() => c(null));
2495
2535
  }
2496
2536
  },
2497
2537
  children: d
@@ -2503,15 +2543,15 @@ function ui({ active: e, editor: t, interactionState: n = Rt, messages: r = li,
2503
2543
  }
2504
2544
  //#endregion
2505
2545
  //#region src/ui/table/TableSelectionOverlay.tsx
2506
- function di({ editor: e, focusState: t }) {
2507
- let [n, r] = G(null);
2508
- return me(() => {
2546
+ function vi({ editor: e, focusState: t }) {
2547
+ let [n, r] = W(null);
2548
+ return he(() => {
2509
2549
  if (t.mode !== "cell-selection") {
2510
2550
  r(null);
2511
2551
  return;
2512
2552
  }
2513
2553
  let n = () => {
2514
- r(Gn(e, Lt(e.state)));
2554
+ r(Zn(e, Ht(e.state)));
2515
2555
  };
2516
2556
  return n(), window.addEventListener("resize", n), window.addEventListener("scroll", n, !0), () => {
2517
2557
  window.removeEventListener("resize", n), window.removeEventListener("scroll", n, !0);
@@ -2546,16 +2586,16 @@ function di({ editor: e, focusState: t }) {
2546
2586
  }
2547
2587
  //#endregion
2548
2588
  //#region src/ui/toc/MarkweaveInnerToc.tsx
2549
- function fi(e, t) {
2589
+ function yi(e, t) {
2550
2590
  return `${e.toc.itemAriaLabel}: ${t.text}`;
2551
2591
  }
2552
- function pi({ editor: e, state: t, messages: n, editable: r, placement: i }) {
2553
- let a = W(null);
2554
- if (H(() => {
2555
- if (!(i !== "container" || !a.current)) return tr(a.current);
2592
+ function bi({ editor: e, state: t, messages: n, editable: r, placement: i }) {
2593
+ let a = U(null);
2594
+ if (V(() => {
2595
+ if (!(i !== "container" || !a.current)) return sr(a.current);
2556
2596
  }, [i]), !t.items.length) return null;
2557
2597
  let o = (t) => {
2558
- nr(e, t, {
2598
+ cr(e, t, {
2559
2599
  behavior: "smooth",
2560
2600
  focus: r
2561
2601
  });
@@ -2582,7 +2622,7 @@ function pi({ editor: e, state: t, messages: n, editable: r, placement: i }) {
2582
2622
  "data-level": e.level,
2583
2623
  "data-active": e.active ? "true" : "false",
2584
2624
  "aria-current": e.active ? "location" : void 0,
2585
- "aria-label": fi(n, e),
2625
+ "aria-label": yi(n, e),
2586
2626
  title: e.text,
2587
2627
  onClick: () => o(e),
2588
2628
  children: e.text
@@ -2593,7 +2633,7 @@ function pi({ editor: e, state: t, messages: n, editable: r, placement: i }) {
2593
2633
  }
2594
2634
  //#endregion
2595
2635
  //#region src/MarkweaveEditor.tsx
2596
- var mi = {
2636
+ var xi = {
2597
2637
  active: !1,
2598
2638
  mode: "outside",
2599
2639
  activeCellPos: null,
@@ -2601,21 +2641,21 @@ var mi = {
2601
2641
  selectedCellCount: 0,
2602
2642
  selectionFrom: 0,
2603
2643
  selectionTo: 0
2604
- }, hi = {
2644
+ }, Si = {
2605
2645
  active: !1,
2606
- language: it.defaultLanguage,
2646
+ language: ct.defaultLanguage,
2607
2647
  mermaidPreviewMode: "code",
2608
2648
  pos: null,
2609
2649
  text: ""
2610
- }, gi = dt({
2650
+ }, Ci = gt({
2611
2651
  active: !1,
2612
2652
  mode: "code",
2613
2653
  source: ""
2614
2654
  });
2615
- function _i(e) {
2616
- return zt.getState(e.state) ?? Rt;
2655
+ function wi(e) {
2656
+ return Wt.getState(e.state) ?? Ut;
2617
2657
  }
2618
- function vi(e) {
2658
+ function Ti(e) {
2619
2659
  if (!e || typeof window > "u") return null;
2620
2660
  let t = e.parentElement;
2621
2661
  for (; t;) {
@@ -2625,71 +2665,88 @@ function vi(e) {
2625
2665
  }
2626
2666
  return null;
2627
2667
  }
2628
- function yi(e) {
2668
+ function Ei(e) {
2629
2669
  return typeof window > "u" || typeof window.requestAnimationFrame != "function" ? globalThis.setTimeout(() => e(0), 0) : window.requestAnimationFrame(e);
2630
2670
  }
2631
- function bi(e) {
2671
+ function Di(e) {
2632
2672
  if (typeof window < "u" && typeof window.cancelAnimationFrame == "function") {
2633
2673
  window.cancelAnimationFrame(e);
2634
2674
  return;
2635
2675
  }
2636
2676
  globalThis.clearTimeout(e);
2637
2677
  }
2638
- function xi({ ariaLabel: e, autoFocusFirstTableBodyCell: t = !1, autofocus: n = !1, content: r, contentFormat: a, defaultContent: o = "", defaultContentFormat: s, editable: c = !0, innerToc: l = !0, innerTocPlacement: u, lang: d, mode: f = "live", onEditWithAi: p, onExtractToNote: m, onRewriteSelection: h, onRuntimeStateChange: g, onSlashCommandUpload: _, onTableCommandResult: v, onTableCopyPayload: y, onTocChange: b, onUpdate: x } = {}) {
2639
- let S = Pe(f), C = er(u), w = S === "live" && c !== !1, T = Ue(r === void 0 ? s : a), E = W({
2640
- editorMode: S,
2641
- effectiveEditable: w
2678
+ function Oi({ ariaLabel: e, autoFocusFirstTableBodyCell: t = !1, autofocus: n = !1, content: r, contentFormat: a, defaultContent: o = "", defaultContentFormat: s, editable: c = !0, innerToc: l = !0, innerTocPlacement: u, lang: d, mode: f = "live", theme: p, onEditWithAi: m, onExtractToNote: h, onRewriteSelection: g, onRuntimeStateChange: _, onSlashCommandUpload: v, onTableCommandResult: y, onTableCopyPayload: b, onTocChange: x, onUpdate: S } = {}) {
2679
+ let C = Pe(f), w = lr(p), T = or(u), E = C === "live" && c !== !1, D = We(r === void 0 ? s : a), O = U({
2680
+ editorMode: C,
2681
+ effectiveEditable: E
2642
2682
  });
2643
- E.current = {
2644
- editorMode: S,
2645
- effectiveEditable: w
2683
+ O.current = {
2684
+ editorMode: C,
2685
+ effectiveEditable: E
2646
2686
  };
2647
- let D = W(null);
2648
- D.current === null && (D.current = je(d));
2649
- let O = D.current, k = U(() => Ae(O), [O]), A = U(() => ke(O), [O]), j = W(_);
2650
- j.current = _;
2651
- let M = U(() => _r({
2652
- lang: O,
2687
+ let ee = U(null);
2688
+ ee.current === null && (ee.current = Me(d));
2689
+ let k = ee.current, A = H(() => je(k), [k]), j = H(() => Ae(k), [k]), te = U(v);
2690
+ te.current = v;
2691
+ let M = H(() => wr({
2692
+ lang: k,
2653
2693
  onImageUpload: (e) => {
2654
- if (j.current) return j.current(e);
2655
- let t = _e(e);
2694
+ if (te.current) return te.current(e);
2695
+ let t = ve(e);
2656
2696
  if (!t) throw Error("File upload requires an upload handler.");
2657
2697
  return t;
2658
2698
  },
2659
2699
  onVideoUpload: (e) => {
2660
- if (j.current) return j.current(e);
2661
- let t = _e(e);
2700
+ if (te.current) return te.current(e);
2701
+ let t = ve(e);
2662
2702
  if (!t) throw Error("File upload requires an upload handler.");
2663
2703
  return t;
2664
2704
  }
2665
- }), [O]), [N, P] = G(null), [F, I] = G(Mt), [ee, L] = G(null), [R, te] = G(null), [z, ne] = G("code"), [re, ie] = G(null), [ae, oe] = G(Rt), [se, ce] = G(null), [le, ue] = G(0), de = W(!1), fe = W({ onUpdate: x }), pe = U(() => wt(F.query, A), [A, F.query]);
2666
- fe.current = { onUpdate: x };
2667
- let B = V(() => {
2668
- L(null), te(null), I(Mt);
2669
- }, []), me = V((e) => {
2670
- let t = jt(e.state);
2705
+ }), [k]), [N, ne] = W(null), [P, F] = W(Lt), [I, re] = W(null), [L, R] = W(null), [ie, ae] = W("code"), [oe, z] = W(null), [se, ce] = W(Ut), [le, ue] = W(null), [de, fe] = W(0), pe = U(!1), me = U({
2706
+ content: r,
2707
+ format: D
2708
+ }), he = U(null), ge = U(null), _e = U({ onUpdate: S }), G = H(() => kt(P.query, j), [j, P.query]);
2709
+ _e.current = { onUpdate: S }, me.current = {
2710
+ content: r,
2711
+ format: D
2712
+ };
2713
+ let ye = B(() => {
2714
+ ge.current !== null && (window.clearTimeout(ge.current), ge.current = null), fe((e) => e + 1);
2715
+ }, []), be = B(() => {
2716
+ ge.current !== null && window.clearTimeout(ge.current), ge.current = window.setTimeout(() => {
2717
+ ge.current = null, fe((e) => e + 1);
2718
+ }, tt);
2719
+ }, []);
2720
+ V(() => () => {
2721
+ ge.current !== null && window.clearTimeout(ge.current);
2722
+ }, []);
2723
+ let K = B(() => {
2724
+ re(null), R(null), F(Lt);
2725
+ }, []), xe = B((e) => {
2726
+ let t = It(e.state);
2671
2727
  if (!t) {
2672
- I((e) => e.name === "idle" ? e : Mt), L(null), te(null);
2728
+ F((e) => e.name === "idle" ? e : Lt), re(null), R(null);
2673
2729
  return;
2674
2730
  }
2675
2731
  let n = e.coordsAtPos(t.cursor), r = e.coordsAtPos(t.triggerFrom), i = e.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
2676
- L(At(n, {
2732
+ re(Ft(n, {
2677
2733
  frameRect: i,
2678
2734
  triggerRect: r
2679
- })), I((e) => kt(e, t));
2680
- }, []), he = V((e) => me(e.view), [me]), ge = V((e) => {
2681
- P(Ye(e));
2682
- let t = yt(e);
2683
- t && (xt(e, t, !0), ie(t));
2684
- let n = nt(e);
2685
- n.active && n.language === "mermaid" && ne(n.mermaidPreviewMode);
2686
- }, []), K = V((e) => {
2687
- oe(_i(e));
2735
+ })), F((e) => Pt(e, t));
2736
+ }, []), Se = B((e) => xe(e.view), [xe]), Ce = B((e) => {
2737
+ let t = Qe(e);
2738
+ ne((e) => Je(e, t) ? e : t);
2739
+ let n = wt(e);
2740
+ n && (Et(e, n, !0), z(n));
2741
+ let r = ot(e);
2742
+ r.active && r.language === "mermaid" && ae(r.mermaidPreviewMode);
2743
+ }, []), we = B((e) => {
2744
+ ce(wi(e));
2688
2745
  }, []), q = i({
2689
2746
  extensions: M,
2690
2747
  content: r ?? o,
2691
- contentType: Ve(T),
2692
- editable: w,
2748
+ contentType: Ve(D),
2749
+ editable: E,
2693
2750
  autofocus: n,
2694
2751
  editorProps: {
2695
2752
  attributes: {
@@ -2700,328 +2757,349 @@ function xi({ ariaLabel: e, autoFocusFirstTableBodyCell: t = !1, autofocus: n =
2700
2757
  spellcheck: "false",
2701
2758
  translate: "no"
2702
2759
  },
2703
- handleClick: (e, t, n) => E.current.effectiveEditable ? !1 : We(n),
2760
+ handleClick: (e, t, n) => O.current.effectiveEditable ? !1 : Ge(n),
2704
2761
  handleDOMEvents: {
2705
- compositionstart: () => E.current.effectiveEditable ? (I((e) => Nt(e, { type: "composition-start" })), L(null), !1) : !1,
2706
- compositionend: (e) => (E.current.effectiveEditable && window.setTimeout(() => me(e), 0), !1),
2762
+ compositionstart: () => O.current.effectiveEditable ? (F((e) => Rt(e, { type: "composition-start" })), re(null), !1) : !1,
2763
+ compositionend: (e) => (O.current.effectiveEditable && window.setTimeout(() => xe(e), 0), !1),
2707
2764
  click: (e, t) => {
2708
- if (E.current.effectiveEditable) {
2709
- let n = vt(e, t);
2710
- return n ? (t.preventDefault(), t.stopPropagation(), B(), St(e, n, !0), Ct(e, n), ie(n), !0) : (ie(null), !1);
2765
+ if (O.current.effectiveEditable) {
2766
+ let n = Ct(e, t);
2767
+ return n ? (t.preventDefault(), t.stopPropagation(), K(), Dt(e, n, !0), Ot(e, n), z(n), !0) : (z(null), !1);
2711
2768
  }
2712
- return We(t);
2769
+ return Ge(t);
2713
2770
  }
2714
2771
  }
2715
2772
  },
2716
2773
  onSelectionUpdate: ({ editor: e }) => {
2717
- ge(e);
2774
+ Ce(e);
2718
2775
  },
2719
2776
  onCreate: ({ editor: e }) => {
2720
- t && E.current.effectiveEditable && Ft(e), K(e), ge(e), ue((e) => e + 1);
2777
+ t && O.current.effectiveEditable && Bt(e), we(e), Ce(e), ye();
2721
2778
  },
2722
2779
  onTransaction: ({ editor: e, transaction: t }) => {
2723
- K(e), (t.docChanged || ct(t)) && ue((e) => e + 1), t.docChanged && ie((t) => {
2780
+ we(e), (t.docChanged || ft(t)) && be(), t.docChanged && z((t) => {
2724
2781
  if (!t) return null;
2725
- let n = _t(e, t.pos);
2782
+ let n = St(e, t.pos);
2726
2783
  return n?.kind === t.kind ? n : null;
2727
2784
  });
2728
2785
  },
2729
2786
  onUpdate: ({ editor: e }) => {
2730
- ge(e), E.current.effectiveEditable && he(e), de.current || fe.current.onUpdate?.(Be(e));
2787
+ Ce(e), O.current.effectiveEditable && Se(e), pe.current || _e.current.onUpdate?.(Be(e, { onContentRead: (t, n) => {
2788
+ let r = me.current;
2789
+ r.content !== void 0 && t === r.format && (he.current = {
2790
+ content: n,
2791
+ format: t,
2792
+ doc: e.state.doc
2793
+ });
2794
+ } }));
2731
2795
  }
2732
2796
  });
2733
- H(() => {
2734
- q && (q.setEditable(w), Fe(q, {
2735
- mode: S,
2736
- editable: w
2737
- }), lt(q, w ? "live" : "view"), w || B());
2797
+ V(() => {
2798
+ q && (q.setEditable(E), Fe(q, {
2799
+ mode: C,
2800
+ editable: E
2801
+ }), mt(q, E ? "live" : "view"), ye(), E || K());
2738
2802
  }, [
2739
- B,
2803
+ K,
2740
2804
  q,
2741
- S,
2742
- w
2743
- ]), H(() => {
2744
- !q || r === void 0 || He(q, r, Ue(a)) || (de.current = !0, q.commands.setContent(r, {
2745
- contentType: Ve(Ue(a)),
2746
- emitUpdate: !1
2747
- }), de.current = !1, ge(q), w && he(q), K(q), ue((e) => e + 1));
2805
+ C,
2806
+ E,
2807
+ ye
2808
+ ]), V(() => {
2809
+ q && pt(q, w);
2810
+ }, [q, w]), V(() => {
2811
+ let e = We(a);
2812
+ if (!(!q || r === void 0)) {
2813
+ if (Ue(q, he.current, r, e)) {
2814
+ he.current = null;
2815
+ return;
2816
+ }
2817
+ he.current = null, !He(q, r, e) && (pe.current = !0, q.commands.setContent(r, {
2818
+ contentType: Ve(e),
2819
+ emitUpdate: !1
2820
+ }), pe.current = !1, Ce(q), E && Se(q), we(q), ye());
2821
+ }
2748
2822
  }, [
2749
2823
  r,
2750
2824
  a,
2751
- w,
2825
+ E,
2752
2826
  q,
2753
- ge,
2754
- he,
2755
- K
2756
- ]), H(() => {
2757
- if (!ee) return;
2827
+ ye,
2828
+ Ce,
2829
+ Se,
2830
+ we
2831
+ ]), V(() => {
2832
+ if (!I) return;
2758
2833
  let e = (e) => {
2759
2834
  let t = e.target;
2760
- t instanceof Element && (t.closest(".markweave-slash-menu") || t.closest(".markweave-slash-trigger") || B());
2835
+ t instanceof Element && (t.closest(".markweave-slash-menu") || t.closest(".markweave-slash-trigger") || K());
2761
2836
  };
2762
2837
  return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
2763
- }, [B, ee]);
2764
- let ve = U(() => q ? nt(q) : hi, [
2838
+ }, [K, I]);
2839
+ let Te = H(() => q ? ot(q) : Si, [
2765
2840
  q,
2766
- le,
2841
+ de,
2767
2842
  N
2768
- ]), ye = U(() => q ? It(q.state) : mi, [
2843
+ ]), Ee = H(() => q ? Vt(q.state) : xi, [
2769
2844
  q,
2770
- le,
2845
+ de,
2771
2846
  N,
2772
- ae
2773
- ]), be = N?.currentNode === "codeBlock", xe = be && ve.language === "mermaid", Se = U(() => q ? dt({
2774
- active: xe,
2775
- mode: z,
2776
- source: ve.text
2777
- }) : gi, [
2778
- ve.text,
2847
+ se
2848
+ ]), De = N?.currentNode === "codeBlock", Oe = De && Te.language === "mermaid", ke = H(() => q ? gt({
2849
+ active: Oe,
2850
+ mode: ie,
2851
+ source: Te.text
2852
+ }) : Ci, [
2853
+ Te.text,
2779
2854
  q,
2780
- xe,
2781
- z
2782
- ]), Ce = U(() => q ? Pt(q.state) : null, [q, le]), J = U(() => q ? Qn(q.state.doc) : Xn.items, [q, le]), we = U(() => $n(J, se), [se, J]), Te = U(() => Yn(J, we), [we, J]), Ee = V(() => {
2783
- if (!q || !J.length) {
2784
- ce(null);
2855
+ Oe,
2856
+ ie
2857
+ ]), J = H(() => q ? zt(q.state) : null, [q, de]), Y = H(() => q ? ir(q.state.doc) : nr.items, [q, de]), Ne = H(() => ar(Y, le), [le, Y]), Ie = H(() => tr(Y, Ne), [Ne, Y]), Le = B(() => {
2858
+ if (!q || !Y.length) {
2859
+ ue(null);
2785
2860
  return;
2786
2861
  }
2787
- let e = Zn(q, J);
2788
- ce((t) => t === e ? t : e);
2789
- }, [q, J]);
2790
- H(() => {
2791
- ce((e) => {
2792
- let t = $n(J, e);
2862
+ let e = rr(q, Y);
2863
+ ue((t) => t === e ? t : e);
2864
+ }, [q, Y]);
2865
+ V(() => {
2866
+ ue((e) => {
2867
+ let t = ar(Y, e);
2793
2868
  return e === t ? e : t;
2794
2869
  });
2795
- }, [J]), H(() => {
2796
- if (!q || !J.length || typeof window > "u") return;
2870
+ }, [Y]), V(() => {
2871
+ if (!q || !Y.length || typeof window > "u") return;
2797
2872
  let e = null, t = () => {
2798
- e !== null && bi(e), e = yi(() => {
2799
- e = null, Ee();
2873
+ e !== null && Di(e), e = Ei(() => {
2874
+ e = null, Le();
2800
2875
  });
2801
- }, n = vi(q.view.dom);
2876
+ }, n = Ti(q.view.dom);
2802
2877
  return window.addEventListener("scroll", t, { passive: !0 }), window.addEventListener("resize", t), n?.addEventListener("scroll", t, { passive: !0 }), t(), () => {
2803
- window.removeEventListener("scroll", t), window.removeEventListener("resize", t), n?.removeEventListener("scroll", t), e !== null && bi(e);
2878
+ window.removeEventListener("scroll", t), window.removeEventListener("resize", t), n?.removeEventListener("scroll", t), e !== null && Di(e);
2804
2879
  };
2805
2880
  }, [
2806
2881
  q,
2807
- J.length,
2808
- Ee
2882
+ Y.length,
2883
+ Le
2809
2884
  ]);
2810
- let De = U(() => Ge({
2811
- revision: le,
2812
- mode: S,
2813
- editable: w,
2814
- toc: Te,
2885
+ let X = H(() => Ke({
2886
+ revision: de,
2887
+ mode: C,
2888
+ editable: E,
2889
+ toc: Ie,
2815
2890
  selection: N,
2816
- slash: F,
2817
- table: ye,
2818
- tableInteraction: ae,
2819
- codeBlock: ve,
2820
- mermaid: Se,
2821
- tableDebugSnapshot: Ce
2891
+ slash: P,
2892
+ table: Ee,
2893
+ tableInteraction: se,
2894
+ codeBlock: Te,
2895
+ mermaid: ke,
2896
+ tableDebugSnapshot: J
2822
2897
  }), [
2823
- ve,
2824
- S,
2825
- w,
2826
- Se,
2827
- le,
2898
+ Te,
2899
+ C,
2900
+ E,
2901
+ ke,
2902
+ de,
2828
2903
  N,
2829
- F,
2830
- Ce,
2831
- ye,
2832
- ae,
2833
- Te
2904
+ P,
2905
+ J,
2906
+ Ee,
2907
+ se,
2908
+ Ie
2834
2909
  ]);
2835
- H(() => {
2836
- g?.(De);
2837
- }, [g, De]), H(() => {
2838
- b?.(Te);
2839
- }, [b, Te]);
2840
- let Oe = V((e, t) => {
2841
- if (!(!q || !w) && Tt(e)) {
2910
+ V(() => {
2911
+ _?.(X);
2912
+ }, [_, X]), V(() => {
2913
+ x?.(Ie);
2914
+ }, [x, Ie]);
2915
+ let Z = B((e, t) => {
2916
+ if (!(!q || !E) && At(e)) {
2842
2917
  if (e.inputKind && !t?.emoji && !t?.uploadResult) {
2843
- te(e);
2918
+ R(e);
2844
2919
  return;
2845
2920
  }
2846
- Ot(q, F, e, t), I((e) => Nt(e, { type: "execute" })), B();
2921
+ Nt(q, P, e, t), F((e) => Rt(e, { type: "execute" })), K();
2847
2922
  }
2848
2923
  }, [
2849
- B,
2850
- w,
2924
+ K,
2925
+ E,
2851
2926
  q,
2852
- F
2853
- ]), Y = V((e) => {
2854
- I((t) => Nt(t, {
2927
+ P
2928
+ ]), Q = B((e) => {
2929
+ F((t) => Rt(t, {
2855
2930
  type: "set-active",
2856
2931
  index: e,
2857
- optionCount: pe.length
2932
+ optionCount: G.length
2858
2933
  }));
2859
- }, [pe.length]), Me = V((e) => {
2860
- if (!q || R || !w) return;
2861
- let t = Et(F, pe, e.key, { isComposing: e.nativeEvent.isComposing || ze(q.state) });
2934
+ }, [G.length]), Re = B((e) => {
2935
+ if (!q || L || !E) return;
2936
+ let t = jt(P, G, e.key, { isComposing: e.nativeEvent.isComposing || ze(q.state) });
2862
2937
  if (t.type !== "ignore") {
2863
2938
  if (t.type === "close") {
2864
- e.preventDefault(), I((e) => Nt(e, { type: "escape" })), B();
2939
+ e.preventDefault(), F((e) => Rt(e, { type: "escape" })), K();
2865
2940
  return;
2866
2941
  }
2867
2942
  if (t.type === "move-active") {
2868
- e.preventDefault(), I((e) => Nt(e, {
2943
+ e.preventDefault(), F((e) => Rt(e, {
2869
2944
  type: "move-active",
2870
2945
  delta: t.delta,
2871
2946
  optionCount: t.optionCount
2872
2947
  }));
2873
2948
  return;
2874
2949
  }
2875
- t.type === "execute-active" && (e.preventDefault(), Oe(t.command));
2950
+ t.type === "execute-active" && (e.preventDefault(), Z(t.command));
2876
2951
  }
2877
2952
  }, [
2878
- B,
2879
- w,
2953
+ K,
2954
+ E,
2880
2955
  q,
2881
- pe,
2882
- Oe,
2883
- R,
2884
- F
2885
- ]), Ne = U(() => ({
2886
- closeSlashMenu: B,
2887
- focusFirstTableBodyCell: () => q ? Ft(q) : !1,
2956
+ G,
2957
+ Z,
2958
+ L,
2959
+ P
2960
+ ]), qe = H(() => ({
2961
+ closeSlashMenu: K,
2962
+ focusFirstTableBodyCell: () => q ? Bt(q) : !1,
2888
2963
  setContent: (e, t = {}) => {
2889
2964
  if (!q) return !1;
2890
- let n = Ue(t.format);
2965
+ let n = We(t.format);
2891
2966
  return q.commands.setContent(e, {
2892
2967
  contentType: Ve(n),
2893
2968
  emitUpdate: t.emitUpdate ?? !1
2894
- }), t.focusFirstTableBodyCell && Ft(q), ge(q), w && he(q), K(q), ue((e) => e + 1), !0;
2969
+ }), t.focusFirstTableBodyCell && Bt(q), Ce(q), E && Se(q), we(q), ye(), !0;
2895
2970
  }
2896
2971
  }), [
2897
- B,
2898
- w,
2972
+ K,
2973
+ E,
2899
2974
  q,
2900
- ge,
2901
- he,
2902
- K
2975
+ ye,
2976
+ Ce,
2977
+ Se,
2978
+ we
2903
2979
  ]);
2904
2980
  return {
2905
2981
  editor: q,
2906
- frameProps: U(() => ({
2982
+ frameProps: H(() => ({
2907
2983
  className: "markweave-editor-frame",
2908
- "aria-label": e ?? k.common.editorAriaLabel,
2984
+ "aria-label": e ?? A.common.editorAriaLabel,
2909
2985
  "data-testid": "markweave-editor-frame",
2910
- "data-markweave-mode": S,
2986
+ "data-markweave-mode": C,
2987
+ "data-markweave-theme": w,
2911
2988
  "data-markweave-inner-toc": l ? "true" : "false",
2912
- "data-markweave-inner-toc-placement": C,
2913
- "data-mermaid-mode": Se.mode,
2914
- "data-table-focus-mode": ye.mode,
2915
- onKeyDownCapture: Me
2989
+ "data-markweave-inner-toc-placement": T,
2990
+ "data-mermaid-mode": ke.mode,
2991
+ "data-table-focus-mode": Ee.mode,
2992
+ onKeyDownCapture: Re
2916
2993
  }), [
2917
2994
  e,
2918
- S,
2919
- Me,
2920
- l,
2921
- Se.mode,
2922
- k.common.editorAriaLabel,
2923
2995
  C,
2924
- ye.mode
2996
+ Re,
2997
+ l,
2998
+ ke.mode,
2999
+ A.common.editorAriaLabel,
3000
+ T,
3001
+ w,
3002
+ Ee.mode
2925
3003
  ]),
2926
- overlayProps: U(() => ({
2927
- floatingToolbar: q && w ? {
3004
+ overlayProps: H(() => ({
3005
+ floatingToolbar: q && E ? {
2928
3006
  editor: q,
2929
- messages: k,
3007
+ messages: A,
2930
3008
  selectionSnapshot: N,
2931
- onRewriteSelection: h,
2932
- onExtractToNote: m
3009
+ onRewriteSelection: g,
3010
+ onExtractToNote: h
2933
3011
  } : null,
2934
- slashCommandMenu: q && w ? {
2935
- commands: pe,
2936
- state: F,
2937
- position: ee,
2938
- inputCommand: R,
2939
- messages: k,
2940
- onActiveIndexChange: Y,
2941
- onInputCommandChange: te,
2942
- onSelect: Oe,
2943
- onUpload: _
3012
+ slashCommandMenu: q && E ? {
3013
+ commands: G,
3014
+ state: P,
3015
+ position: I,
3016
+ inputCommand: L,
3017
+ messages: A,
3018
+ onActiveIndexChange: Q,
3019
+ onInputCommandChange: R,
3020
+ onSelect: Z,
3021
+ onUpload: v
2944
3022
  } : null,
2945
- tableControls: q && w ? {
3023
+ tableControls: q && E ? {
2946
3024
  editor: q,
2947
- active: ye.active,
2948
- interactionState: ae,
2949
- messages: k,
2950
- onCopyPayload: y,
2951
- onCommandResult: v,
2952
- onEditWithAi: p
3025
+ active: Ee.active,
3026
+ interactionState: se,
3027
+ messages: A,
3028
+ onCopyPayload: b,
3029
+ onCommandResult: y,
3030
+ onEditWithAi: m
2953
3031
  } : null,
2954
- tableSelectionOverlay: q && w ? {
3032
+ tableSelectionOverlay: q && E ? {
2955
3033
  editor: q,
2956
- focusState: ye
3034
+ focusState: Ee
2957
3035
  } : null,
2958
3036
  codeBlockControls: q ? {
2959
3037
  editor: q,
2960
- active: w && be,
2961
- mermaidMode: z,
2962
- onMermaidModeChange: ne,
2963
- readOnly: !w
3038
+ active: E && De,
3039
+ mermaidMode: ie,
3040
+ onMermaidModeChange: ae,
3041
+ readOnly: !E
2964
3042
  } : null,
2965
- innerToc: q && l && Te.items.length ? {
3043
+ innerToc: q && l && Ie.items.length ? {
2966
3044
  editor: q,
2967
- editable: w,
2968
- messages: k,
2969
- placement: C,
2970
- state: Te
3045
+ editable: E,
3046
+ messages: A,
3047
+ placement: T,
3048
+ state: Ie
2971
3049
  } : null,
2972
- mathEditorPopover: q && w && re ? {
3050
+ mathEditorPopover: q && E && oe ? {
2973
3051
  editor: q,
2974
- messages: k,
2975
- target: re,
2976
- onClose: () => ie(null)
3052
+ messages: A,
3053
+ target: oe,
3054
+ onClose: () => z(null)
2977
3055
  } : null
2978
3056
  }), [
2979
- w,
3057
+ E,
2980
3058
  q,
2981
- pe,
3059
+ G,
2982
3060
  l,
2983
- be,
2984
- z,
2985
- k,
2986
- re,
2987
- p,
3061
+ De,
3062
+ ie,
3063
+ A,
3064
+ oe,
2988
3065
  m,
2989
3066
  h,
2990
- _,
3067
+ g,
2991
3068
  v,
2992
3069
  y,
2993
- Oe,
3070
+ b,
3071
+ Z,
2994
3072
  N,
2995
- Y,
2996
- R,
2997
- ee,
2998
- F,
2999
- ye,
3000
- ae,
3001
- Te
3073
+ Q,
3074
+ L,
3075
+ I,
3076
+ P,
3077
+ Ee,
3078
+ se,
3079
+ Ie
3002
3080
  ]),
3003
- runtimeSnapshot: De,
3004
- actions: Ne
3081
+ runtimeSnapshot: X,
3082
+ actions: qe
3005
3083
  };
3006
3084
  }
3007
- function Si({ className: e, ...n }) {
3008
- let r = xi(n);
3085
+ function ki({ className: e, ...n }) {
3086
+ let r = Oi(n);
3009
3087
  if (!r.editor) return null;
3010
3088
  let i = [r.frameProps.className, e].filter(Boolean).join(" ");
3011
3089
  return /* @__PURE__ */ Q("section", {
3012
3090
  ...r.frameProps,
3013
3091
  className: i,
3014
3092
  children: [
3015
- r.overlayProps.floatingToolbar ? /* @__PURE__ */ Z(Vr, { ...r.overlayProps.floatingToolbar }) : null,
3016
- r.overlayProps.slashCommandMenu ? /* @__PURE__ */ Z(ci, { ...r.overlayProps.slashCommandMenu }) : null,
3017
- r.overlayProps.tableControls ? /* @__PURE__ */ Z(ui, { ...r.overlayProps.tableControls }) : null,
3018
- r.overlayProps.tableSelectionOverlay ? /* @__PURE__ */ Z(di, { ...r.overlayProps.tableSelectionOverlay }) : null,
3019
- r.overlayProps.codeBlockControls ? /* @__PURE__ */ Z(br, { ...r.overlayProps.codeBlockControls }) : null,
3020
- r.overlayProps.innerToc ? /* @__PURE__ */ Z(pi, { ...r.overlayProps.innerToc }) : null,
3021
- r.overlayProps.mathEditorPopover ? /* @__PURE__ */ Z($r, { ...r.overlayProps.mathEditorPopover }) : null,
3093
+ r.overlayProps.floatingToolbar ? /* @__PURE__ */ Z(Jr, { ...r.overlayProps.floatingToolbar }) : null,
3094
+ r.overlayProps.slashCommandMenu ? /* @__PURE__ */ Z(hi, { ...r.overlayProps.slashCommandMenu }) : null,
3095
+ r.overlayProps.tableControls ? /* @__PURE__ */ Z(_i, { ...r.overlayProps.tableControls }) : null,
3096
+ r.overlayProps.tableSelectionOverlay ? /* @__PURE__ */ Z(vi, { ...r.overlayProps.tableSelectionOverlay }) : null,
3097
+ r.overlayProps.codeBlockControls ? /* @__PURE__ */ Z(Dr, { ...r.overlayProps.codeBlockControls }) : null,
3098
+ r.overlayProps.innerToc ? /* @__PURE__ */ Z(bi, { ...r.overlayProps.innerToc }) : null,
3099
+ r.overlayProps.mathEditorPopover ? /* @__PURE__ */ Z(oi, { ...r.overlayProps.mathEditorPopover }) : null,
3022
3100
  /* @__PURE__ */ Z(t, { editor: r.editor })
3023
3101
  ]
3024
3102
  });
3025
3103
  }
3026
3104
  //#endregion
3027
- export { Si as MarkweaveEditor, _r as createMarkweaveEditorExtensions, _r as createMarkweaveReactEditorExtensions, xi as useMarkweaveEditorController };
3105
+ export { ki as MarkweaveEditor, wr as createMarkweaveEditorExtensions, wr as createMarkweaveReactEditorExtensions, Oi as useMarkweaveEditorController };