@markweave/react 0.1.0
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/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.js +2982 -0
- package/dist/types/MarkweaveEditor.d.ts +73 -0
- package/dist/types/MarkweaveEditor.d.ts.map +1 -0
- package/dist/types/create-editor-extensions.d.ts +10 -0
- package/dist/types/create-editor-extensions.d.ts.map +1 -0
- package/dist/types/editor-mode-state.d.ts +3 -0
- package/dist/types/editor-mode-state.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/media/image-node.d.ts +12 -0
- package/dist/types/media/image-node.d.ts.map +1 -0
- package/dist/types/media/video-node.d.ts +12 -0
- package/dist/types/media/video-node.d.ts.map +1 -0
- package/dist/types/ui/codeblock/CodeBlockControls.d.ts +12 -0
- package/dist/types/ui/codeblock/CodeBlockControls.d.ts.map +1 -0
- package/dist/types/ui/floating-toolbar/FloatingToolbar.d.ts +16 -0
- package/dist/types/ui/floating-toolbar/FloatingToolbar.d.ts.map +1 -0
- package/dist/types/ui/floating-toolbar/behavior-contract.d.ts +3 -0
- package/dist/types/ui/floating-toolbar/behavior-contract.d.ts.map +1 -0
- package/dist/types/ui/math/MathEditorPopover.d.ts +11 -0
- package/dist/types/ui/math/MathEditorPopover.d.ts.map +1 -0
- package/dist/types/ui/mermaid/MermaidPreview.d.ts +9 -0
- package/dist/types/ui/mermaid/MermaidPreview.d.ts.map +1 -0
- package/dist/types/ui/slash-command/SlashCommandMenu.d.ts +37 -0
- package/dist/types/ui/slash-command/SlashCommandMenu.d.ts.map +1 -0
- package/dist/types/ui/table/TableControls.d.ts +18 -0
- package/dist/types/ui/table/TableControls.d.ts.map +1 -0
- package/dist/types/ui/table/TableSelectionOverlay.d.ts +10 -0
- package/dist/types/ui/table/TableSelectionOverlay.d.ts.map +1 -0
- package/dist/types/ui/toc/MarkweaveInnerToc.d.ts +11 -0
- package/dist/types/ui/toc/MarkweaveInnerToc.d.ts.map +1 -0
- package/package.json +69 -0
- package/styles.css +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2982 @@
|
|
|
1
|
+
import { createMarkweaveEditorExtensions as e } from "markweave/internal/editor-core/create-editor-extensions";
|
|
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, Heading1 as S, Heading2 as C, Heading3 as w, Image as T, ImageUp as E, IndentDecrease as D, IndentIncrease as O, Info as k, Italic as A, Lightbulb as j, Link2 as ee, List as M, ListChecks as N, ListOrdered as P, Minus as te, MoreVertical as ne, Paperclip as F, Quote as I, Replace as re, Sigma as L, SmilePlus as R, Sparkles as ie, Strikethrough as ae, Subscript as oe, Superscript as se, Table2 as ce, Text as z, Trash2 as le, Type as ue, Underline as de, Upload as B, Video as fe } from "lucide-react";
|
|
4
|
+
import { useCallback as V, useEffect as H, useLayoutEffect as U, useMemo as W, useRef as G, useState as K, useSyncExternalStore as pe } from "react";
|
|
5
|
+
import { detectUploadSource as me, getDirectUploadResult as he, resolveMarkweaveUploadResult as q } from "markweave/internal/plugins/slash-command/upload";
|
|
6
|
+
import { MarkweaveCoreImage as ge, MarkweaveCoreVideo as _e, attrsFromMarkweaveImageUploadResult as ve, attrsFromMarkweaveVideoUploadResult as ye, attrsFromMarkweaveVideoUrl as be, clampMarkweaveImageWidth as xe, createMarkweaveImageUploadRequest as J, createMarkweaveVideoUploadRequest as Se, downloadMarkweaveImage as Ce, markweaveVideoIframeAllow as we, normalizeMarkweaveCoreImageAlign as Te, normalizeMarkweaveVideoEmbedUrl as Ee, numberAttribute as De, stringAttribute as Y } from "markweave/internal/plugins/media/core-media-nodes";
|
|
7
|
+
import { getLocalizedSlashCommandSpecs as Oe, getMarkweaveMessages as ke, normalizeMarkweaveLang as Ae } from "markweave/internal/i18n";
|
|
8
|
+
import { getMarkweaveEditorModeState as je, isMarkweaveEditorLiveEditable as Me, normalizeMarkweaveEditorMode as Ne, setMarkweaveEditorModeState as Pe, subscribeToMarkweaveEditorMode as Fe } from "markweave/internal/core/editor-mode-state";
|
|
9
|
+
import { Fragment as X, jsx as Z, jsxs as Q } from "react/jsx-runtime";
|
|
10
|
+
import { createMarkweaveAdapterMediaExtensions as Ie } from "markweave/internal/plugins/media/media-extension-factory";
|
|
11
|
+
import { isEditorComposing as Le } from "markweave/internal/editor-core/composition-guard";
|
|
12
|
+
import { createMarkweaveEditorUpdatePayload as Re, getMarkweaveContentType as ze, isEditorContentCurrent as Be, normalizeMarkweaveContentFormat as Ve } from "markweave/internal/editor-core/editor-content";
|
|
13
|
+
import { openMarkweaveReadonlyLinkFromEvent as He } from "markweave/internal/editor-core/readonly-link";
|
|
14
|
+
import { createMarkweaveEditorRuntimeSnapshot as Ue } from "markweave/internal/editor-core/runtime-snapshot";
|
|
15
|
+
import { advanceFloatingToolbarMotionState as We, calculateFloatingToolbarFrameShift as Ge, calculateFloatingToolbarTopBoundary as Ke, createSelectionSnapshot as qe, getFloatingToolbarFloatingOptions as Je, getFloatingToolbarState as Ye, shouldShowFloatingToolbar as Xe, transitionFloatingToolbarState as Ze } from "markweave/internal/editor-core/selection-state";
|
|
16
|
+
import { codeBlockCollapsePluginKey as Qe, copyActiveCodeBlock as $e, getActiveCodeBlockState as et, getCodeBlockCopyFeedbackSnapshot as tt, markweaveCodeBlockBehavior as nt, setCodeBlockCollapsedAtPosition as rt, setCodeBlockLanguageAtPosition as it, setCodeBlockMermaidPreviewModeAtPosition as at } from "markweave/internal/plugins/codeblock/codeblock-behavior";
|
|
17
|
+
import { isMermaidInlinePreviewTransaction as ot, setMermaidInlinePreviewEditorMode as st, setReadonlyMermaidPreviewMode as ct } from "markweave/internal/plugins/mermaid/mermaid-inline-preview";
|
|
18
|
+
import { getMermaidPreviewState as lt } from "markweave/internal/plugins/mermaid/mermaid-renderer";
|
|
19
|
+
import { applyMarkweaveMathLatex as ut, calculateMarkweaveMathPopoverPosition as dt, getMarkweaveMathAnchorRect as ft, getMarkweaveMathBlockIndex as pt, getMarkweaveMathRenderedHtml as mt, getMarkweaveMathTargetAtPos as ht, getMarkweaveMathTargetFromDomEvent as gt, getMarkweaveMathTargetFromSelection as _t, renderMarkweaveMathPreview as vt, setMarkweaveMathEditingDomState as yt, setMarkweaveMathEditingDomStateInView as bt, setMarkweaveMathSelectionInView as xt } from "markweave/internal/plugins/math/math-ui-model";
|
|
20
|
+
import { filterSlashCommands as St, isExecutableSlashCommand as Ct } from "markweave/internal/plugins/slash-command/command-spec";
|
|
21
|
+
import { getSlashCommandKeyboardAction as wt, isSlashCommandMenuState as Tt } from "markweave/internal/plugins/slash-command/slash-keyboard";
|
|
22
|
+
import { executeSlashCommand as Et, getNextSlashCommandState as Dt, getSlashCommandAnchoredMenuPosition as Ot, getSlashCommandContext as kt } from "markweave/internal/plugins/slash-command/slash-runtime";
|
|
23
|
+
import { initialSlashCommandState as At, reduceSlashCommandState as jt } from "markweave/internal/plugins/slash-command/slash-state";
|
|
24
|
+
import { getFirstTableDebugSnapshot as Mt } from "markweave/internal/plugins/table/table-debug-snapshot";
|
|
25
|
+
import { focusFirstTableBodyCell as Nt } from "markweave/internal/plugins/table/table-focus-position";
|
|
26
|
+
import { getTableFocusState as Pt } from "markweave/internal/plugins/table/table-focus-state";
|
|
27
|
+
import { getTableSelectionOverlayState as Ft, initialTableInteractionState as It, tableInteractionPluginKey as Lt } from "markweave/internal/plugins/table/table-interaction-layer";
|
|
28
|
+
import { calculateCodeBlockLanguageMenuPosition as Rt, clampFullscreenScale as zt, codeBlockCopyFeedbackTimeoutMs as Bt, copyCodeBlockText as Vt, createCodeBlockOverlayPosition as Ht, createMermaidFullscreenViewerState as Ut, createMermaidTabPosition as Wt, focusCodeBlockTarget as Gt, formatCodeBlockLanguageLabel as Kt, formatFullscreenZoom as qt, getActiveCodeBlockElement as Jt, getAnchoredRect as Yt, getCodeBlockLanguageItems as Xt, getCodeBlockPositionFromEventTarget as Zt, getCodeBlockStateAtPosition as Qt, getFrameElement as $t, getMermaidCodeBlockTargets as en, getMermaidSvgMarkup as tn, isCodeBlockTargetCollapsed as nn, mergeStableMermaidTabPositions as rn, mermaidFullscreenZoomStep as an, moveMermaidFullscreenViewer as on } from "markweave/internal/plugins/codeblock/codeblock-ui-model";
|
|
29
|
+
import { BubbleMenu as sn } from "@tiptap/react/menus";
|
|
30
|
+
import { applyFloatingToolbarLink as cn, createFloatingToolbarAssistantRequest as ln, getFloatingToolbarButtonModels as un, getFloatingToolbarHighlightColorOptions as dn, getFloatingToolbarLinkHref as fn, getFloatingToolbarMessageSet as pn, getFloatingToolbarMoreActions as mn, getFloatingToolbarTextColorOptions as hn, getFloatingToolbarTooltipModel as gn, getFloatingToolbarTurnIntoOptions as _n, isFloatingToolbarMoreActionActive as vn, isFloatingToolbarTurnIntoActive as yn, openFloatingToolbarLinkHref as bn, preventFloatingToolbarPointerFocusLoss as xn, removeFloatingToolbarLink as Sn, runFloatingToolbarMoreAction as Cn, setFloatingToolbarHighlightColor as wn, setFloatingToolbarTextColor as Tn, setFloatingToolbarTurnInto as En } from "markweave/internal/editor-core/floating-toolbar-model";
|
|
31
|
+
import { normalizeMarkdownLinkHref as Dn } from "markweave/internal/plugins/markdown/markdown-input";
|
|
32
|
+
import { setMarkweaveTableMenuAxisTarget as On } from "markweave/internal/plugins/table/table-clipboard";
|
|
33
|
+
import { calculateAnchoredTableMenuPosition as kn, calculateTableEdgeHandlePosition as An, canRunTableCommand as jn, executeTableMenuCommand as Mn, formatTableCopyFeedback as Nn, getActiveTableElement as Pn, getAvailableCellMenuCommandSpecs as Fn, getTableAxisTargetRect as In, getTableControlAxisSelectionModel as Ln, getTableEditWithAiRequest as Rn, getTableMenuItemGroup as zn, getTableMenuItemLabel as Bn, getTableMenuItems as Vn, getTableSelectionTargetRect as Hn, measureTableSelectionOverlay as Un, selectTableAxisFromCell as Wn, tableCopyFeedbackTimeoutMs as Gn, tableMenuLabel as Kn } from "markweave/internal/plugins/table/table-ui-model";
|
|
34
|
+
import { createMarkweaveTocState as qn, emptyMarkweaveTocState as Jn, getActiveMarkweaveTocId as Yn, getMarkweaveTocItems as Xn, getValidMarkweaveTocActiveId as Zn, scrollToMarkweaveTocItem as Qn } from "markweave/internal/core/toc-state";
|
|
35
|
+
//#region src/editor-mode-state.ts
|
|
36
|
+
var $n = {
|
|
37
|
+
mode: "live",
|
|
38
|
+
editable: !0
|
|
39
|
+
};
|
|
40
|
+
function er(e) {
|
|
41
|
+
return pe((t) => Fe(e, t), () => je(e), () => $n);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/media/image-node.tsx
|
|
45
|
+
var tr = Te;
|
|
46
|
+
function nr(e) {
|
|
47
|
+
return e instanceof Element && !!e.closest("[data-markweave-image-ui=\"true\"]");
|
|
48
|
+
}
|
|
49
|
+
function rr(e) {
|
|
50
|
+
let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? ke("zh"), u = l.image, d = Me(er(r)), f = Y(a.attrs.src), p = tr(a.attrs.align), m = De(a.attrs.width), h = Y(a.attrs.caption), g = G(null), _ = G(null), [v, y] = K(!1), [b, x] = K(!1), [S, C] = K(!1), [w, T] = K(""), [E, D] = K(null), [O, k] = K(!1), [A, j] = K(!!h), [ee, M] = K(h ?? ""), N = d && (!f || b);
|
|
51
|
+
H(() => {
|
|
52
|
+
A || M(h ?? "");
|
|
53
|
+
}, [h, A]);
|
|
54
|
+
let P = () => {
|
|
55
|
+
if (!d) return;
|
|
56
|
+
let e = i();
|
|
57
|
+
typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
|
|
58
|
+
}, te = () => {
|
|
59
|
+
if (d) {
|
|
60
|
+
if (T(""), D(null), C(!1), f) {
|
|
61
|
+
x(!1);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
t();
|
|
65
|
+
}
|
|
66
|
+
}, ne = async (e) => {
|
|
67
|
+
if (d) {
|
|
68
|
+
D(null), k(!0);
|
|
69
|
+
try {
|
|
70
|
+
let t = await q(J(e, f && b ? "image-replace" : "image-insert"), c.onUpload);
|
|
71
|
+
s(ve(a.attrs, t)), x(!1), T("");
|
|
72
|
+
} catch (e) {
|
|
73
|
+
D(e instanceof Error ? e.message : u.uploadFailedError);
|
|
74
|
+
} finally {
|
|
75
|
+
k(!1), C(!1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, F = () => {
|
|
79
|
+
if (d) {
|
|
80
|
+
if (!w.trim()) {
|
|
81
|
+
D(u.uploadRequiredError);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
ne(me(w));
|
|
85
|
+
}
|
|
86
|
+
}, I = (e) => {
|
|
87
|
+
!d || !e || ne({
|
|
88
|
+
type: "file",
|
|
89
|
+
file: e,
|
|
90
|
+
mimeType: e.type
|
|
91
|
+
});
|
|
92
|
+
}, re = (e) => {
|
|
93
|
+
I(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
|
|
94
|
+
}, L = (e) => {
|
|
95
|
+
e.preventDefault(), e.stopPropagation(), d && I(e.dataTransfer.files?.[0] ?? null);
|
|
96
|
+
}, R = () => {
|
|
97
|
+
d && (j((e) => !e), A || M(h ?? ""));
|
|
98
|
+
}, ie = (e) => {
|
|
99
|
+
d && (M(e), s({ caption: e.trim() ? e : null }));
|
|
100
|
+
}, ae = (e, t) => {
|
|
101
|
+
if (t.preventDefault(), t.stopPropagation(), !d) return;
|
|
102
|
+
P();
|
|
103
|
+
let n = g.current;
|
|
104
|
+
if (!n) return;
|
|
105
|
+
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) => {
|
|
106
|
+
let n = e === "right" ? t.clientX - r : r - t.clientX;
|
|
107
|
+
s({ width: xe(i + n, a) });
|
|
108
|
+
}, c = () => {
|
|
109
|
+
window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", c);
|
|
110
|
+
};
|
|
111
|
+
window.addEventListener("pointermove", o), window.addEventListener("pointerup", c, { once: !0 });
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ Z(n, {
|
|
114
|
+
as: "figure",
|
|
115
|
+
className: "markweave-image-node",
|
|
116
|
+
"data-testid": "markweave-image-node",
|
|
117
|
+
"data-align": p,
|
|
118
|
+
"data-selected": d && o ? "true" : "false",
|
|
119
|
+
"data-hovered": d && v ? "true" : "false",
|
|
120
|
+
"data-empty": N ? "true" : "false",
|
|
121
|
+
onPointerEnter: () => y(!0),
|
|
122
|
+
onPointerLeave: () => y(!1),
|
|
123
|
+
onMouseDown: (e) => {
|
|
124
|
+
d && !nr(e.target) && P();
|
|
125
|
+
},
|
|
126
|
+
children: N ? /* @__PURE__ */ Z(ir, {
|
|
127
|
+
dragActive: S,
|
|
128
|
+
error: E,
|
|
129
|
+
inputValue: w,
|
|
130
|
+
isSubmitting: O,
|
|
131
|
+
fileInputRef: _,
|
|
132
|
+
messages: l,
|
|
133
|
+
onCancel: te,
|
|
134
|
+
onDrop: L,
|
|
135
|
+
onDragActiveChange: C,
|
|
136
|
+
onFileChange: re,
|
|
137
|
+
onInputChange: T,
|
|
138
|
+
onSubmit: F
|
|
139
|
+
}) : /* @__PURE__ */ Q(X, { children: [
|
|
140
|
+
d ? /* @__PURE__ */ Z(ar, {
|
|
141
|
+
align: p,
|
|
142
|
+
captionActive: A || !!h,
|
|
143
|
+
messages: l,
|
|
144
|
+
onAlign: (e) => s({ align: e }),
|
|
145
|
+
onCaption: R,
|
|
146
|
+
onDelete: t,
|
|
147
|
+
onDownload: () => {
|
|
148
|
+
f && Ce(f);
|
|
149
|
+
},
|
|
150
|
+
onReplace: () => {
|
|
151
|
+
T(""), D(null), x(!0);
|
|
152
|
+
}
|
|
153
|
+
}) : null,
|
|
154
|
+
/* @__PURE__ */ Q("div", {
|
|
155
|
+
className: "markweave-image-box",
|
|
156
|
+
ref: g,
|
|
157
|
+
style: m ? { width: `${m}px` } : void 0,
|
|
158
|
+
children: [
|
|
159
|
+
f ? /* @__PURE__ */ Z("img", {
|
|
160
|
+
className: "markweave-image",
|
|
161
|
+
src: f,
|
|
162
|
+
alt: Y(a.attrs.alt) ?? "",
|
|
163
|
+
title: Y(a.attrs.title) ?? void 0,
|
|
164
|
+
draggable: !1
|
|
165
|
+
}) : /* @__PURE__ */ Z("div", {
|
|
166
|
+
className: "markweave-image-readonly-empty",
|
|
167
|
+
"data-testid": "markweave-image-readonly-empty",
|
|
168
|
+
"aria-hidden": "true"
|
|
169
|
+
}),
|
|
170
|
+
d ? /* @__PURE__ */ Z(sr, {
|
|
171
|
+
side: "left",
|
|
172
|
+
messages: l,
|
|
173
|
+
onPointerDown: ae
|
|
174
|
+
}) : null,
|
|
175
|
+
d ? /* @__PURE__ */ Z(sr, {
|
|
176
|
+
side: "right",
|
|
177
|
+
messages: l,
|
|
178
|
+
onPointerDown: ae
|
|
179
|
+
}) : null
|
|
180
|
+
]
|
|
181
|
+
}),
|
|
182
|
+
d && (A || h) ? /* @__PURE__ */ Z("input", {
|
|
183
|
+
className: "markweave-image-caption-input",
|
|
184
|
+
"data-markweave-image-ui": "true",
|
|
185
|
+
"data-testid": "markweave-image-caption-input",
|
|
186
|
+
value: ee,
|
|
187
|
+
placeholder: u.captionPlaceholder,
|
|
188
|
+
"aria-label": u.captionAriaLabel,
|
|
189
|
+
onChange: (e) => ie(e.currentTarget.value),
|
|
190
|
+
onKeyDown: (e) => {
|
|
191
|
+
e.key === "Escape" && (e.preventDefault(), j(!1));
|
|
192
|
+
}
|
|
193
|
+
}) : h ? /* @__PURE__ */ Z("figcaption", {
|
|
194
|
+
className: "markweave-image-caption",
|
|
195
|
+
"data-testid": "markweave-image-caption",
|
|
196
|
+
children: h
|
|
197
|
+
}) : null
|
|
198
|
+
] })
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function ir({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
|
|
202
|
+
let f = a.image;
|
|
203
|
+
return /* @__PURE__ */ Q("section", {
|
|
204
|
+
className: "markweave-image-upload-placeholder",
|
|
205
|
+
"data-testid": "markweave-image-upload-placeholder",
|
|
206
|
+
"data-drag-active": e ? "true" : "false",
|
|
207
|
+
"data-markweave-image-ui": "true",
|
|
208
|
+
onDragEnter: (e) => {
|
|
209
|
+
e.preventDefault(), s(!0);
|
|
210
|
+
},
|
|
211
|
+
onDragOver: (e) => {
|
|
212
|
+
e.preventDefault(), s(!0);
|
|
213
|
+
},
|
|
214
|
+
onDragLeave: () => s(!1),
|
|
215
|
+
onDrop: c,
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ Z("input", {
|
|
218
|
+
ref: n,
|
|
219
|
+
"data-testid": "markweave-image-file-input",
|
|
220
|
+
type: "file",
|
|
221
|
+
accept: "image/*",
|
|
222
|
+
hidden: !0,
|
|
223
|
+
onChange: l
|
|
224
|
+
}),
|
|
225
|
+
/* @__PURE__ */ Z("div", {
|
|
226
|
+
className: "markweave-image-upload-icon",
|
|
227
|
+
"aria-hidden": "true",
|
|
228
|
+
children: /* @__PURE__ */ Z(E, {
|
|
229
|
+
size: 46,
|
|
230
|
+
strokeWidth: 1.6
|
|
231
|
+
})
|
|
232
|
+
}),
|
|
233
|
+
/* @__PURE__ */ Q("div", {
|
|
234
|
+
className: "markweave-image-upload-copy",
|
|
235
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
236
|
+
type: "button",
|
|
237
|
+
onClick: () => n.current?.click(),
|
|
238
|
+
children: f.clickToUpload
|
|
239
|
+
}), /* @__PURE__ */ Z("span", { children: f.dragAndDrop })]
|
|
240
|
+
}),
|
|
241
|
+
/* @__PURE__ */ Z("div", {
|
|
242
|
+
className: "markweave-image-upload-note",
|
|
243
|
+
children: f.uploadNote
|
|
244
|
+
}),
|
|
245
|
+
/* @__PURE__ */ Q("div", {
|
|
246
|
+
className: "markweave-image-upload-row",
|
|
247
|
+
children: [
|
|
248
|
+
/* @__PURE__ */ Z("input", {
|
|
249
|
+
"data-testid": "markweave-image-url-input",
|
|
250
|
+
value: r,
|
|
251
|
+
placeholder: f.uploadInputPlaceholder,
|
|
252
|
+
"aria-label": f.uploadInputAriaLabel,
|
|
253
|
+
onChange: (e) => u(e.currentTarget.value),
|
|
254
|
+
onKeyDown: (e) => {
|
|
255
|
+
e.key === "Enter" && (e.preventDefault(), d());
|
|
256
|
+
}
|
|
257
|
+
}),
|
|
258
|
+
/* @__PURE__ */ Q("button", {
|
|
259
|
+
type: "button",
|
|
260
|
+
"data-testid": "markweave-image-upload-submit",
|
|
261
|
+
disabled: i || !r.trim(),
|
|
262
|
+
onClick: d,
|
|
263
|
+
children: [/* @__PURE__ */ Z(E, {
|
|
264
|
+
size: 16,
|
|
265
|
+
strokeWidth: 1.8
|
|
266
|
+
}), a.common.insert]
|
|
267
|
+
}),
|
|
268
|
+
/* @__PURE__ */ Z("button", {
|
|
269
|
+
type: "button",
|
|
270
|
+
"data-testid": "markweave-image-upload-cancel",
|
|
271
|
+
onClick: o,
|
|
272
|
+
children: a.common.cancel
|
|
273
|
+
})
|
|
274
|
+
]
|
|
275
|
+
}),
|
|
276
|
+
t ? /* @__PURE__ */ Z("div", {
|
|
277
|
+
className: "markweave-image-upload-error",
|
|
278
|
+
children: t
|
|
279
|
+
}) : null
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function ar({ align: e, captionActive: t, messages: n, onAlign: r, onCaption: i, onDelete: a, onDownload: s, onReplace: u }) {
|
|
284
|
+
let d = n.image;
|
|
285
|
+
return /* @__PURE__ */ Q("div", {
|
|
286
|
+
className: "markweave-image-toolbar",
|
|
287
|
+
"data-testid": "markweave-image-toolbar",
|
|
288
|
+
"data-markweave-image-ui": "true",
|
|
289
|
+
"aria-label": d.toolsAriaLabel,
|
|
290
|
+
children: [
|
|
291
|
+
/* @__PURE__ */ Z(or, {
|
|
292
|
+
testId: "markweave-image-align-left",
|
|
293
|
+
label: d.alignLeft,
|
|
294
|
+
icon: c,
|
|
295
|
+
active: e === "left",
|
|
296
|
+
onClick: () => r("left")
|
|
297
|
+
}),
|
|
298
|
+
/* @__PURE__ */ Z(or, {
|
|
299
|
+
testId: "markweave-image-align-center",
|
|
300
|
+
label: d.alignCenter,
|
|
301
|
+
icon: o,
|
|
302
|
+
active: e === "center",
|
|
303
|
+
onClick: () => r("center")
|
|
304
|
+
}),
|
|
305
|
+
/* @__PURE__ */ Z(or, {
|
|
306
|
+
testId: "markweave-image-align-right",
|
|
307
|
+
label: d.alignRight,
|
|
308
|
+
icon: l,
|
|
309
|
+
active: e === "right",
|
|
310
|
+
onClick: () => r("right")
|
|
311
|
+
}),
|
|
312
|
+
/* @__PURE__ */ Z("span", {
|
|
313
|
+
className: "markweave-image-toolbar-divider",
|
|
314
|
+
"aria-hidden": "true"
|
|
315
|
+
}),
|
|
316
|
+
/* @__PURE__ */ Z(or, {
|
|
317
|
+
testId: "markweave-image-caption",
|
|
318
|
+
label: d.caption,
|
|
319
|
+
icon: f,
|
|
320
|
+
active: t,
|
|
321
|
+
onClick: i
|
|
322
|
+
}),
|
|
323
|
+
/* @__PURE__ */ Z(or, {
|
|
324
|
+
testId: "markweave-image-download",
|
|
325
|
+
label: d.download,
|
|
326
|
+
icon: b,
|
|
327
|
+
onClick: s
|
|
328
|
+
}),
|
|
329
|
+
/* @__PURE__ */ Z(or, {
|
|
330
|
+
testId: "markweave-image-replace",
|
|
331
|
+
label: d.replace,
|
|
332
|
+
icon: re,
|
|
333
|
+
onClick: u
|
|
334
|
+
}),
|
|
335
|
+
/* @__PURE__ */ Z("span", {
|
|
336
|
+
className: "markweave-image-toolbar-divider",
|
|
337
|
+
"aria-hidden": "true"
|
|
338
|
+
}),
|
|
339
|
+
/* @__PURE__ */ Z(or, {
|
|
340
|
+
testId: "markweave-image-delete",
|
|
341
|
+
label: d.delete,
|
|
342
|
+
icon: le,
|
|
343
|
+
onClick: a
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function or({ active: e = !1, icon: t, label: n, onClick: r, testId: i }) {
|
|
349
|
+
return /* @__PURE__ */ Q("button", {
|
|
350
|
+
type: "button",
|
|
351
|
+
"aria-label": n,
|
|
352
|
+
title: n,
|
|
353
|
+
"data-testid": i,
|
|
354
|
+
"data-active": e ? "true" : "false",
|
|
355
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
356
|
+
onClick: r,
|
|
357
|
+
children: [/* @__PURE__ */ Z(t, {
|
|
358
|
+
size: 20,
|
|
359
|
+
strokeWidth: 1.8
|
|
360
|
+
}), /* @__PURE__ */ Z("span", {
|
|
361
|
+
className: "markweave-image-tooltip",
|
|
362
|
+
role: "tooltip",
|
|
363
|
+
children: n
|
|
364
|
+
})]
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function sr({ messages: e, onPointerDown: t, side: n }) {
|
|
368
|
+
return /* @__PURE__ */ Z("button", {
|
|
369
|
+
type: "button",
|
|
370
|
+
className: "markweave-image-resize-handle",
|
|
371
|
+
"data-testid": `markweave-image-resize-${n}`,
|
|
372
|
+
"data-side": n,
|
|
373
|
+
"data-markweave-image-ui": "true",
|
|
374
|
+
"aria-label": n === "left" ? e.image.resizeLeft : e.image.resizeRight,
|
|
375
|
+
onPointerDown: (e) => t(n, e)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
var cr = ge.extend({
|
|
379
|
+
addOptions() {
|
|
380
|
+
return {
|
|
381
|
+
...this.parent?.(),
|
|
382
|
+
messages: ke("zh"),
|
|
383
|
+
onUpload: void 0
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
addNodeView() {
|
|
387
|
+
return typeof document > "u" ? null : r(rr, { stopEvent: ({ event: e }) => nr(e.target) });
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/media/video-node.tsx
|
|
392
|
+
function lr(e) {
|
|
393
|
+
return e instanceof Element && !!e.closest("[data-markweave-video-ui=\"true\"], iframe[data-markweave-video-embed], video[data-markweave-video]");
|
|
394
|
+
}
|
|
395
|
+
function ur(e) {
|
|
396
|
+
let { deleteNode: t, editor: r, getPos: i, node: a, selected: o, updateAttributes: s } = e, c = e.extension.options, l = c.messages ?? ke("zh"), u = l.video, d = Me(er(r)), f = Y(a.attrs.src), p = Y(a.attrs.embedUrl), m = Y(a.attrs.provider), h = p ? Ee(p, m) : null, g = Y(a.attrs.mimeType), _ = Y(a.attrs.title), v = G(null), [y, b] = K(!1), [x, S] = K(""), [C, w] = K(null), [T, E] = K(!1), D = d && !f, O = () => {
|
|
397
|
+
if (!d) return;
|
|
398
|
+
let e = i();
|
|
399
|
+
typeof e == "number" && r.chain().focus().setNodeSelection(e).run();
|
|
400
|
+
}, k = (e) => {
|
|
401
|
+
d && (lr(e.target) || (e.preventDefault(), O()));
|
|
402
|
+
}, A = (e) => {
|
|
403
|
+
d && (e.key === "Delete" || e.key === "Backspace") && o && (e.preventDefault(), t());
|
|
404
|
+
}, j = async (e) => {
|
|
405
|
+
if (!(!d || !e)) {
|
|
406
|
+
w(null), E(!0);
|
|
407
|
+
try {
|
|
408
|
+
let t = await q(Se({
|
|
409
|
+
type: "file",
|
|
410
|
+
file: e,
|
|
411
|
+
mimeType: e.type
|
|
412
|
+
}), c.onUpload);
|
|
413
|
+
s(ye(t)), S("");
|
|
414
|
+
} catch (e) {
|
|
415
|
+
w(e instanceof Error ? e.message : u.uploadFailedError);
|
|
416
|
+
} finally {
|
|
417
|
+
E(!1), b(!1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
return D ? /* @__PURE__ */ Z(n, {
|
|
422
|
+
as: "figure",
|
|
423
|
+
className: "markweave-video-node",
|
|
424
|
+
"data-testid": "markweave-video-node",
|
|
425
|
+
"data-empty": "true",
|
|
426
|
+
"data-selected": "false",
|
|
427
|
+
children: /* @__PURE__ */ Z(dr, {
|
|
428
|
+
dragActive: y,
|
|
429
|
+
error: C,
|
|
430
|
+
fileInputRef: v,
|
|
431
|
+
inputValue: x,
|
|
432
|
+
isSubmitting: T,
|
|
433
|
+
messages: l,
|
|
434
|
+
onCancel: t,
|
|
435
|
+
onDragActiveChange: b,
|
|
436
|
+
onDrop: (e) => {
|
|
437
|
+
e.preventDefault(), e.stopPropagation(), d && j(e.dataTransfer.files?.[0] ?? null);
|
|
438
|
+
},
|
|
439
|
+
onFileChange: (e) => {
|
|
440
|
+
j(e.currentTarget.files?.[0] ?? null), e.currentTarget.value = "";
|
|
441
|
+
},
|
|
442
|
+
onInputChange: S,
|
|
443
|
+
onSubmit: () => {
|
|
444
|
+
if (!d) return;
|
|
445
|
+
let e = be(x);
|
|
446
|
+
if (!e) {
|
|
447
|
+
w(u.unsupportedUrlError);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
w(null), s(e), S("");
|
|
451
|
+
}
|
|
452
|
+
})
|
|
453
|
+
}) : /* @__PURE__ */ Z(n, {
|
|
454
|
+
as: "figure",
|
|
455
|
+
className: "markweave-video-node",
|
|
456
|
+
"data-testid": "markweave-video-node",
|
|
457
|
+
"data-provider": m ?? "file",
|
|
458
|
+
"data-empty": f ? "false" : "true",
|
|
459
|
+
"data-selected": d && o ? "true" : "false",
|
|
460
|
+
tabIndex: d ? 0 : void 0,
|
|
461
|
+
"aria-label": u.nodeAriaLabel,
|
|
462
|
+
onFocus: O,
|
|
463
|
+
onKeyDown: A,
|
|
464
|
+
onMouseDown: k,
|
|
465
|
+
children: h ? /* @__PURE__ */ Q("div", {
|
|
466
|
+
className: "markweave-video-embed",
|
|
467
|
+
children: [/* @__PURE__ */ Z("iframe", {
|
|
468
|
+
className: "markweave-video-iframe",
|
|
469
|
+
src: h,
|
|
470
|
+
title: _ ?? `${m ?? "Video"} embed`,
|
|
471
|
+
"data-markweave-video-embed": "true",
|
|
472
|
+
"data-markweave-video-provider": m ?? void 0,
|
|
473
|
+
"data-markweave-video-src": f ?? void 0,
|
|
474
|
+
allow: we,
|
|
475
|
+
allowFullScreen: !0
|
|
476
|
+
}), d ? /* @__PURE__ */ Z("button", {
|
|
477
|
+
type: "button",
|
|
478
|
+
className: "markweave-video-selection-layer",
|
|
479
|
+
"data-testid": "markweave-video-selection-layer",
|
|
480
|
+
tabIndex: -1,
|
|
481
|
+
"aria-label": u.selectAriaLabel
|
|
482
|
+
}) : null]
|
|
483
|
+
}) : f ? /* @__PURE__ */ Q("div", {
|
|
484
|
+
className: "markweave-video-box",
|
|
485
|
+
children: [/* @__PURE__ */ Z("video", {
|
|
486
|
+
className: "markweave-video",
|
|
487
|
+
src: f,
|
|
488
|
+
title: _ ?? void 0,
|
|
489
|
+
"data-markweave-video": "true",
|
|
490
|
+
"data-markweave-mime-type": g ?? void 0,
|
|
491
|
+
controls: !0
|
|
492
|
+
}), d ? /* @__PURE__ */ Z("button", {
|
|
493
|
+
type: "button",
|
|
494
|
+
className: "markweave-video-selection-layer",
|
|
495
|
+
"data-testid": "markweave-video-selection-layer",
|
|
496
|
+
tabIndex: -1,
|
|
497
|
+
"aria-label": u.selectAriaLabel
|
|
498
|
+
}) : null]
|
|
499
|
+
}) : /* @__PURE__ */ Z("div", {
|
|
500
|
+
className: "markweave-video-readonly-empty",
|
|
501
|
+
"data-testid": "markweave-video-readonly-empty",
|
|
502
|
+
"aria-hidden": "true"
|
|
503
|
+
})
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
function dr({ dragActive: e, error: t, fileInputRef: n, inputValue: r, isSubmitting: i, messages: a, onCancel: o, onDragActiveChange: s, onDrop: c, onFileChange: l, onInputChange: u, onSubmit: d }) {
|
|
507
|
+
let f = a.video;
|
|
508
|
+
return /* @__PURE__ */ Q("section", {
|
|
509
|
+
className: "markweave-video-upload-placeholder",
|
|
510
|
+
"data-testid": "markweave-video-upload-placeholder",
|
|
511
|
+
"data-drag-active": e ? "true" : "false",
|
|
512
|
+
"data-markweave-video-ui": "true",
|
|
513
|
+
onDragEnter: (e) => {
|
|
514
|
+
e.preventDefault(), s(!0);
|
|
515
|
+
},
|
|
516
|
+
onDragOver: (e) => {
|
|
517
|
+
e.preventDefault(), s(!0);
|
|
518
|
+
},
|
|
519
|
+
onDragLeave: () => s(!1),
|
|
520
|
+
onDrop: c,
|
|
521
|
+
children: [
|
|
522
|
+
/* @__PURE__ */ Z("input", {
|
|
523
|
+
ref: n,
|
|
524
|
+
"data-testid": "markweave-video-file-input",
|
|
525
|
+
type: "file",
|
|
526
|
+
accept: "video/*",
|
|
527
|
+
hidden: !0,
|
|
528
|
+
onChange: l
|
|
529
|
+
}),
|
|
530
|
+
/* @__PURE__ */ Z("div", {
|
|
531
|
+
className: "markweave-video-upload-icon",
|
|
532
|
+
"aria-hidden": "true",
|
|
533
|
+
children: /* @__PURE__ */ Z(fe, {
|
|
534
|
+
size: 46,
|
|
535
|
+
strokeWidth: 1.6
|
|
536
|
+
})
|
|
537
|
+
}),
|
|
538
|
+
/* @__PURE__ */ Q("div", {
|
|
539
|
+
className: "markweave-video-upload-copy",
|
|
540
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
541
|
+
type: "button",
|
|
542
|
+
onClick: () => n.current?.click(),
|
|
543
|
+
children: f.clickToUpload
|
|
544
|
+
}), /* @__PURE__ */ Z("span", { children: f.dragAndDrop })]
|
|
545
|
+
}),
|
|
546
|
+
/* @__PURE__ */ Z("div", {
|
|
547
|
+
className: "markweave-video-upload-note",
|
|
548
|
+
children: f.uploadNote
|
|
549
|
+
}),
|
|
550
|
+
/* @__PURE__ */ Q("div", {
|
|
551
|
+
className: "markweave-video-upload-row",
|
|
552
|
+
children: [
|
|
553
|
+
/* @__PURE__ */ Z("input", {
|
|
554
|
+
"data-testid": "markweave-video-url-input",
|
|
555
|
+
value: r,
|
|
556
|
+
placeholder: f.uploadInputPlaceholder,
|
|
557
|
+
"aria-label": f.uploadInputAriaLabel,
|
|
558
|
+
onChange: (e) => u(e.currentTarget.value),
|
|
559
|
+
onKeyDown: (e) => {
|
|
560
|
+
e.key === "Enter" && (e.preventDefault(), d());
|
|
561
|
+
}
|
|
562
|
+
}),
|
|
563
|
+
/* @__PURE__ */ Q("button", {
|
|
564
|
+
type: "button",
|
|
565
|
+
"data-testid": "markweave-video-upload-submit",
|
|
566
|
+
disabled: i || !r.trim(),
|
|
567
|
+
onClick: d,
|
|
568
|
+
children: [/* @__PURE__ */ Z(B, {
|
|
569
|
+
size: 16,
|
|
570
|
+
strokeWidth: 1.8
|
|
571
|
+
}), a.common.insert]
|
|
572
|
+
}),
|
|
573
|
+
/* @__PURE__ */ Z("button", {
|
|
574
|
+
type: "button",
|
|
575
|
+
"data-testid": "markweave-video-upload-cancel",
|
|
576
|
+
onClick: o,
|
|
577
|
+
children: a.common.cancel
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
}),
|
|
581
|
+
t ? /* @__PURE__ */ Z("div", {
|
|
582
|
+
className: "markweave-video-upload-error",
|
|
583
|
+
children: t
|
|
584
|
+
}) : null
|
|
585
|
+
]
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
var fr = _e.extend({
|
|
589
|
+
addOptions() {
|
|
590
|
+
return {
|
|
591
|
+
...this.parent?.(),
|
|
592
|
+
messages: ke("zh"),
|
|
593
|
+
onUpload: void 0
|
|
594
|
+
};
|
|
595
|
+
},
|
|
596
|
+
addNodeView() {
|
|
597
|
+
return typeof document > "u" ? null : r(ur, { stopEvent: ({ event: e }) => lr(e.target) });
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/create-editor-extensions.ts
|
|
602
|
+
function pr(t = {}) {
|
|
603
|
+
return e({
|
|
604
|
+
lang: t.lang,
|
|
605
|
+
mediaExtensions: Ie({
|
|
606
|
+
image: cr,
|
|
607
|
+
video: fr,
|
|
608
|
+
lang: t.lang,
|
|
609
|
+
onImageUpload: t.onImageUpload,
|
|
610
|
+
onVideoUpload: t.onVideoUpload
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/ui/codeblock/CodeBlockControls.tsx
|
|
616
|
+
function mr(e) {
|
|
617
|
+
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", {
|
|
618
|
+
cx: "10",
|
|
619
|
+
cy: "10",
|
|
620
|
+
r: "5.5"
|
|
621
|
+
}), /* @__PURE__ */ Z("path", { d: "m14 14 4 4" })] }) : e === "check" ? /* @__PURE__ */ Z("path", { d: "m5 11 4 4 8-9" }) : e === "expand" ? /* @__PURE__ */ Q(X, { children: [
|
|
622
|
+
/* @__PURE__ */ Z("path", { d: "M8 4H4v4" }),
|
|
623
|
+
/* @__PURE__ */ Z("path", { d: "M4 4l5 5" }),
|
|
624
|
+
/* @__PURE__ */ Z("path", { d: "M16 4h4v4" }),
|
|
625
|
+
/* @__PURE__ */ Z("path", { d: "m20 4-5 5" }),
|
|
626
|
+
/* @__PURE__ */ Z("path", { d: "M8 20H4v-4" }),
|
|
627
|
+
/* @__PURE__ */ Z("path", { d: "m4 20 5-5" }),
|
|
628
|
+
/* @__PURE__ */ Z("path", { d: "M16 20h4v-4" }),
|
|
629
|
+
/* @__PURE__ */ Z("path", { d: "m20 20-5-5" })
|
|
630
|
+
] }) : e === "download" ? /* @__PURE__ */ Q(X, { children: [
|
|
631
|
+
/* @__PURE__ */ Z("path", { d: "M12 4v10" }),
|
|
632
|
+
/* @__PURE__ */ Z("path", { d: "m8 10 4 4 4-4" }),
|
|
633
|
+
/* @__PURE__ */ Z("path", { d: "M5 19h14" })
|
|
634
|
+
] }) : e === "close" ? /* @__PURE__ */ Q(X, { children: [/* @__PURE__ */ Z("path", { d: "M6 6l12 12" }), /* @__PURE__ */ Z("path", { d: "M18 6 6 18" })] }) : e === "zoomOut" ? /* @__PURE__ */ Q(X, { children: [
|
|
635
|
+
/* @__PURE__ */ Z("circle", {
|
|
636
|
+
cx: "10",
|
|
637
|
+
cy: "10",
|
|
638
|
+
r: "5.25"
|
|
639
|
+
}),
|
|
640
|
+
/* @__PURE__ */ Z("path", { d: "M7.5 10h5" }),
|
|
641
|
+
/* @__PURE__ */ Z("path", { d: "m14 14 4 4" })
|
|
642
|
+
] }) : e === "zoomIn" ? /* @__PURE__ */ Q(X, { children: [
|
|
643
|
+
/* @__PURE__ */ Z("circle", {
|
|
644
|
+
cx: "10",
|
|
645
|
+
cy: "10",
|
|
646
|
+
r: "5.25"
|
|
647
|
+
}),
|
|
648
|
+
/* @__PURE__ */ Z("path", { d: "M7.5 10h5" }),
|
|
649
|
+
/* @__PURE__ */ Z("path", { d: "M10 7.5v5" }),
|
|
650
|
+
/* @__PURE__ */ Z("path", { d: "m14 14 4 4" })
|
|
651
|
+
] }) : 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" });
|
|
652
|
+
}
|
|
653
|
+
function hr({ icon: e }) {
|
|
654
|
+
return /* @__PURE__ */ Z("svg", {
|
|
655
|
+
viewBox: "0 0 24 24",
|
|
656
|
+
"aria-hidden": "true",
|
|
657
|
+
focusable: "false",
|
|
658
|
+
children: /* @__PURE__ */ Z("g", {
|
|
659
|
+
fill: "none",
|
|
660
|
+
stroke: "currentColor",
|
|
661
|
+
strokeLinecap: "round",
|
|
662
|
+
strokeLinejoin: "round",
|
|
663
|
+
strokeWidth: "1.8",
|
|
664
|
+
children: mr(e)
|
|
665
|
+
})
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function gr({ active: e, editor: t, mermaidMode: n, onMermaidModeChange: r, readOnly: i = !1 }) {
|
|
669
|
+
let a = G(null), o = G(null), s = G(null), c = G({
|
|
670
|
+
active: !1,
|
|
671
|
+
lastX: 0,
|
|
672
|
+
lastY: 0
|
|
673
|
+
}), [l, u] = K(null), [d, f] = K(null), [p, m] = K([]), [h, g] = K(null), [_, v] = K(!1), [y, b] = K(""), [x, S] = K(null), [C, w] = K(!1), [T, E] = K(null), [D, O] = K(null), [k, A] = K(!1), [j, ee] = K(0), [M, N] = K(0), P = et(t), te = Qt(t, l), ne = !i && e && P.active && P.pos !== null ? {
|
|
674
|
+
...P,
|
|
675
|
+
pos: P.pos,
|
|
676
|
+
active: !0
|
|
677
|
+
} : null, F = te ?? ne, I = F !== null, re = F?.language === "mermaid", L = nn(t, F), R = I && F !== null && !L, ie = !i, ae = Kt(F ? F.language : "text"), oe = x?.status ?? "idle", se = F?.mermaidPreviewMode ?? n, ce = re && se === "preview", z = en(t), le = `${M}|${z.map((e) => `${e.pos}:${e.mermaidPreviewMode}:${e.text.length}`).join("|")}`, ue = W(() => Xt(y.trim().toLowerCase()), [y]);
|
|
678
|
+
if (H(() => {
|
|
679
|
+
i && (v(!1), b(""));
|
|
680
|
+
}, [i]), H(() => {
|
|
681
|
+
if (!x) return;
|
|
682
|
+
let e = window.setTimeout(() => {
|
|
683
|
+
S(null);
|
|
684
|
+
}, Bt);
|
|
685
|
+
return () => {
|
|
686
|
+
window.clearTimeout(e);
|
|
687
|
+
};
|
|
688
|
+
}, [x]), H(() => {
|
|
689
|
+
S(null), v(!1), b(""), E(null), O(null), A(!1);
|
|
690
|
+
}, [
|
|
691
|
+
e,
|
|
692
|
+
F?.language,
|
|
693
|
+
F?.pos,
|
|
694
|
+
F?.text
|
|
695
|
+
]), H(() => {
|
|
696
|
+
let e = ({ transaction: e }) => {
|
|
697
|
+
e.getMeta(Qe) && ee((e) => e + 1);
|
|
698
|
+
};
|
|
699
|
+
return t.on("transaction", e), () => {
|
|
700
|
+
t.off("transaction", e);
|
|
701
|
+
};
|
|
702
|
+
}, [t]), H(() => {
|
|
703
|
+
let e = t.view.dom.closest(".markweave-editor-frame");
|
|
704
|
+
if (!e) return;
|
|
705
|
+
let n = (e) => {
|
|
706
|
+
if (e.target instanceof Node && a.current?.contains(e.target) || _) return;
|
|
707
|
+
let n = Qt(t, Zt(t, e.target)), r = n && !nn(t, n) ? n.pos : null;
|
|
708
|
+
u((e) => e === r ? e : r);
|
|
709
|
+
}, r = () => {
|
|
710
|
+
_ || u(null);
|
|
711
|
+
};
|
|
712
|
+
return e.addEventListener("mousemove", n), e.addEventListener("mouseleave", r), () => {
|
|
713
|
+
e.removeEventListener("mousemove", n), e.removeEventListener("mouseleave", r);
|
|
714
|
+
};
|
|
715
|
+
}, [t, _]), H(() => {
|
|
716
|
+
_ && s.current?.focus({ preventScroll: !0 });
|
|
717
|
+
}, [_]), H(() => {
|
|
718
|
+
if (!T) return;
|
|
719
|
+
let e = (e) => {
|
|
720
|
+
e.key === "Escape" && (E(null), O(null), A(!1), c.current = {
|
|
721
|
+
active: !1,
|
|
722
|
+
lastX: 0,
|
|
723
|
+
lastY: 0
|
|
724
|
+
}, t.view.focus());
|
|
725
|
+
};
|
|
726
|
+
return document.addEventListener("keydown", e), () => {
|
|
727
|
+
document.removeEventListener("keydown", e);
|
|
728
|
+
};
|
|
729
|
+
}, [t, T]), H(() => {
|
|
730
|
+
if (!I || !_) return;
|
|
731
|
+
let e = (e) => {
|
|
732
|
+
e.key === "Escape" && (v(!1), t.view.focus());
|
|
733
|
+
}, n = (e) => {
|
|
734
|
+
e.target instanceof Node && a.current?.contains(e.target) || v(!1);
|
|
735
|
+
};
|
|
736
|
+
return document.addEventListener("keydown", e), document.addEventListener("mousedown", n), () => {
|
|
737
|
+
document.removeEventListener("keydown", e), document.removeEventListener("mousedown", n);
|
|
738
|
+
};
|
|
739
|
+
}, [
|
|
740
|
+
I,
|
|
741
|
+
t,
|
|
742
|
+
_
|
|
743
|
+
]), U(() => {
|
|
744
|
+
let e = () => {
|
|
745
|
+
let e = a.current;
|
|
746
|
+
if (!e) return;
|
|
747
|
+
if (!$t(e) || z.length === 0) {
|
|
748
|
+
m([]);
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
let n = e.getBoundingClientRect(), r = z.flatMap((e) => {
|
|
752
|
+
let r = Yt(Jt(t, e.pos, e.mermaidPreviewMode), n);
|
|
753
|
+
return r ? [Wt(e, r, n)] : [];
|
|
754
|
+
});
|
|
755
|
+
m((e) => rn(e, r, z.map((e) => e.pos)));
|
|
756
|
+
};
|
|
757
|
+
e();
|
|
758
|
+
let n = window.requestAnimationFrame(e);
|
|
759
|
+
return window.addEventListener("resize", e), window.addEventListener("scroll", e, !0), () => {
|
|
760
|
+
window.cancelAnimationFrame(n), window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
|
|
761
|
+
};
|
|
762
|
+
}, [
|
|
763
|
+
j,
|
|
764
|
+
t,
|
|
765
|
+
le
|
|
766
|
+
]), U(() => {
|
|
767
|
+
if (!R || !F) {
|
|
768
|
+
f(null), g(null);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
let e = () => {
|
|
772
|
+
let e = a.current;
|
|
773
|
+
if (!e) return;
|
|
774
|
+
let n = Jt(t, F.pos, se), r = e.getBoundingClientRect(), i = Yt(n, r);
|
|
775
|
+
if (!i) {
|
|
776
|
+
f((e) => e?.pos === F.pos ? e : null), g((e) => _ ? e : null);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
let s = Ht(F.pos, i, r);
|
|
780
|
+
if (f(s), _ && o.current) {
|
|
781
|
+
let e = o.current.getBoundingClientRect();
|
|
782
|
+
g(Rt({
|
|
783
|
+
overlayRect: r,
|
|
784
|
+
buttonRect: e,
|
|
785
|
+
windowWidth: window.innerWidth,
|
|
786
|
+
windowHeight: window.innerHeight
|
|
787
|
+
}));
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
return e(), window.addEventListener("resize", e), window.addEventListener("scroll", e, !0), () => {
|
|
791
|
+
window.removeEventListener("resize", e), window.removeEventListener("scroll", e, !0);
|
|
792
|
+
};
|
|
793
|
+
}, [
|
|
794
|
+
R,
|
|
795
|
+
j,
|
|
796
|
+
F?.pos,
|
|
797
|
+
t,
|
|
798
|
+
_,
|
|
799
|
+
se
|
|
800
|
+
]), !R && z.length === 0 && !T) return null;
|
|
801
|
+
let de = d ? {
|
|
802
|
+
top: d.top,
|
|
803
|
+
right: d.right
|
|
804
|
+
} : void 0, B = async () => {
|
|
805
|
+
if (i) {
|
|
806
|
+
if (!F) return;
|
|
807
|
+
let e = await Vt(F.text);
|
|
808
|
+
S(tt(F, e ? "copied" : "failed"));
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
if (!Gt(t, F)) return;
|
|
812
|
+
let e = await $e(t);
|
|
813
|
+
S(tt(et(t), e ? "copied" : "failed")), t.view.focus();
|
|
814
|
+
}, fe = (e, n) => {
|
|
815
|
+
if (i) {
|
|
816
|
+
ct(t, e.pos, n) && N((e) => e + 1);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
let a = P.active && P.pos === e.pos;
|
|
820
|
+
at(t, e.pos, n) && (r(n), N((e) => e + 1), a && t.view.focus());
|
|
821
|
+
}, V = (e) => {
|
|
822
|
+
if (i || !F) return;
|
|
823
|
+
let n = P.active && P.pos === F.pos;
|
|
824
|
+
it(t, F.pos, e) && (e === "mermaid" && at(t, F.pos, "preview") && r("preview"), v(!1), b(""), N((e) => e + 1), n && t.view.focus());
|
|
825
|
+
}, pe = () => {
|
|
826
|
+
i || !F || rt(t, F.pos, !L) && (ee((e) => e + 1), u(null));
|
|
827
|
+
}, me = () => {
|
|
828
|
+
if (!F) return;
|
|
829
|
+
let e = tn(t, F.pos);
|
|
830
|
+
if (!e) return;
|
|
831
|
+
let n = new Blob([e], { type: "image/svg+xml" }), r = URL.createObjectURL(n), i = document.createElement("a");
|
|
832
|
+
i.href = r, i.download = "markweave-mermaid.svg", i.click(), URL.revokeObjectURL(r), t.view.focus();
|
|
833
|
+
}, he = () => {
|
|
834
|
+
if (!F) return;
|
|
835
|
+
let e = tn(t, F.pos);
|
|
836
|
+
e && (E(Ut(e)), O(null), A(!1), c.current = {
|
|
837
|
+
active: !1,
|
|
838
|
+
lastX: 0,
|
|
839
|
+
lastY: 0
|
|
840
|
+
});
|
|
841
|
+
}, q = () => {
|
|
842
|
+
E(null), O(null), A(!1), c.current = {
|
|
843
|
+
active: !1,
|
|
844
|
+
lastX: 0,
|
|
845
|
+
lastY: 0
|
|
846
|
+
}, t.view.focus();
|
|
847
|
+
}, ge = (e) => {
|
|
848
|
+
E((t) => t && {
|
|
849
|
+
...t,
|
|
850
|
+
scale: zt(t.scale + e)
|
|
851
|
+
});
|
|
852
|
+
}, _e = () => {
|
|
853
|
+
E((e) => e && Ut(e.svg)), c.current = {
|
|
854
|
+
active: !1,
|
|
855
|
+
lastX: 0,
|
|
856
|
+
lastY: 0
|
|
857
|
+
}, A(!1);
|
|
858
|
+
}, ve = (e) => {
|
|
859
|
+
e.preventDefault(), ge(e.deltaY < 0 ? an : -an);
|
|
860
|
+
}, ye = (e) => {
|
|
861
|
+
e.button === 0 && (e.preventDefault(), c.current = {
|
|
862
|
+
active: !0,
|
|
863
|
+
lastX: e.clientX,
|
|
864
|
+
lastY: e.clientY
|
|
865
|
+
}, A(!0));
|
|
866
|
+
}, be = (e) => {
|
|
867
|
+
let t = c.current;
|
|
868
|
+
if (!t.active) return;
|
|
869
|
+
let n = e.clientX - t.lastX, r = e.clientY - t.lastY;
|
|
870
|
+
c.current = {
|
|
871
|
+
active: !0,
|
|
872
|
+
lastX: e.clientX,
|
|
873
|
+
lastY: e.clientY
|
|
874
|
+
}, E((e) => on(e, n, r));
|
|
875
|
+
}, xe = () => {
|
|
876
|
+
c.current = {
|
|
877
|
+
active: !1,
|
|
878
|
+
lastX: 0,
|
|
879
|
+
lastY: 0
|
|
880
|
+
}, A(!1);
|
|
881
|
+
};
|
|
882
|
+
return /* @__PURE__ */ Q("div", {
|
|
883
|
+
ref: a,
|
|
884
|
+
className: "markweave-codeblock-overlay",
|
|
885
|
+
"data-testid": "markweave-codeblock-overlay",
|
|
886
|
+
"data-read-only": i ? "true" : "false",
|
|
887
|
+
children: [
|
|
888
|
+
z.map((e) => {
|
|
889
|
+
let t = p.find((t) => t.pos === e.pos);
|
|
890
|
+
return /* @__PURE__ */ Z("div", {
|
|
891
|
+
className: "markweave-mermaid-tabs",
|
|
892
|
+
"data-testid": "markweave-mermaid-tabs",
|
|
893
|
+
"data-code-block-pos": e.pos,
|
|
894
|
+
"data-positioned": t ? "true" : "false",
|
|
895
|
+
style: t ? {
|
|
896
|
+
top: t.top,
|
|
897
|
+
left: t.left
|
|
898
|
+
} : void 0,
|
|
899
|
+
children: ["code", "preview"].map((t) => /* @__PURE__ */ Z("button", {
|
|
900
|
+
type: "button",
|
|
901
|
+
"data-testid": `markweave-mermaid-mode-${t}`,
|
|
902
|
+
"data-active": e.mermaidPreviewMode === t,
|
|
903
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
904
|
+
onClick: () => fe(e, t),
|
|
905
|
+
children: t === "code" ? "Code" : "Preview"
|
|
906
|
+
}, t))
|
|
907
|
+
}, e.pos);
|
|
908
|
+
}),
|
|
909
|
+
R ? /* @__PURE__ */ Q("div", {
|
|
910
|
+
className: "markweave-codeblock-controls",
|
|
911
|
+
"data-testid": "markweave-codeblock-controls",
|
|
912
|
+
"data-positioned": d ? "true" : "false",
|
|
913
|
+
"data-collapsed": L ? "true" : "false",
|
|
914
|
+
"data-read-only": i ? "true" : "false",
|
|
915
|
+
"aria-label": "Code block controls",
|
|
916
|
+
style: de,
|
|
917
|
+
children: [
|
|
918
|
+
i ? /* @__PURE__ */ Z("span", {
|
|
919
|
+
className: "markweave-codeblock-language-button markweave-codeblock-language-label",
|
|
920
|
+
"aria-label": "Code block language",
|
|
921
|
+
"data-testid": "markweave-codeblock-language",
|
|
922
|
+
children: /* @__PURE__ */ Z("span", { children: ae })
|
|
923
|
+
}) : /* @__PURE__ */ Q("button", {
|
|
924
|
+
ref: o,
|
|
925
|
+
type: "button",
|
|
926
|
+
className: "markweave-codeblock-language-button",
|
|
927
|
+
"aria-label": "Code block language",
|
|
928
|
+
"aria-expanded": _,
|
|
929
|
+
"aria-haspopup": "listbox",
|
|
930
|
+
"data-testid": "markweave-codeblock-language",
|
|
931
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
932
|
+
onClick: () => v((e) => !e),
|
|
933
|
+
children: [/* @__PURE__ */ Z("span", { children: ae }), /* @__PURE__ */ Z(hr, { icon: "chevron" })]
|
|
934
|
+
}),
|
|
935
|
+
ie ? /* @__PURE__ */ Z("button", {
|
|
936
|
+
type: "button",
|
|
937
|
+
className: "markweave-codeblock-icon-button markweave-codeblock-collapse-button",
|
|
938
|
+
"aria-label": L ? "Expand code block" : "Collapse code block",
|
|
939
|
+
title: L ? "Expand code block" : "Collapse code block",
|
|
940
|
+
"data-testid": "markweave-codeblock-collapse",
|
|
941
|
+
"data-collapsed": L ? "true" : "false",
|
|
942
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
943
|
+
onClick: pe,
|
|
944
|
+
children: /* @__PURE__ */ Z(hr, { icon: "chevron" })
|
|
945
|
+
}) : null,
|
|
946
|
+
/* @__PURE__ */ Q("span", {
|
|
947
|
+
className: "markweave-codeblock-copy-wrap",
|
|
948
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
949
|
+
type: "button",
|
|
950
|
+
className: "markweave-codeblock-icon-button",
|
|
951
|
+
"aria-label": "Copy to clipboard",
|
|
952
|
+
"data-testid": "markweave-codeblock-copy",
|
|
953
|
+
"data-copy-state": oe,
|
|
954
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
955
|
+
onMouseEnter: () => w(!0),
|
|
956
|
+
onMouseLeave: () => w(!1),
|
|
957
|
+
onFocus: () => w(!0),
|
|
958
|
+
onBlur: () => w(!1),
|
|
959
|
+
onClick: B,
|
|
960
|
+
children: /* @__PURE__ */ Z(hr, { icon: oe === "copied" ? "check" : "clipboard" })
|
|
961
|
+
}), C ? /* @__PURE__ */ Z("span", {
|
|
962
|
+
className: "markweave-codeblock-tooltip",
|
|
963
|
+
role: "tooltip",
|
|
964
|
+
"data-testid": "markweave-codeblock-copy-tooltip",
|
|
965
|
+
children: "Copy to clipboard"
|
|
966
|
+
}) : null]
|
|
967
|
+
}),
|
|
968
|
+
re && se === "preview" ? /* @__PURE__ */ Q("div", {
|
|
969
|
+
className: "markweave-mermaid-preview-actions",
|
|
970
|
+
"data-testid": "markweave-mermaid-preview-actions",
|
|
971
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
972
|
+
type: "button",
|
|
973
|
+
className: "markweave-codeblock-icon-button",
|
|
974
|
+
"aria-label": "Fullscreen Mermaid preview",
|
|
975
|
+
"data-testid": "markweave-mermaid-fullscreen",
|
|
976
|
+
disabled: !ce,
|
|
977
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
978
|
+
onClick: he,
|
|
979
|
+
children: /* @__PURE__ */ Z(hr, { icon: "expand" })
|
|
980
|
+
}), /* @__PURE__ */ Z("button", {
|
|
981
|
+
type: "button",
|
|
982
|
+
className: "markweave-codeblock-icon-button",
|
|
983
|
+
"aria-label": "Download Mermaid SVG",
|
|
984
|
+
"data-testid": "markweave-mermaid-download",
|
|
985
|
+
disabled: !ce,
|
|
986
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
987
|
+
onClick: me,
|
|
988
|
+
children: /* @__PURE__ */ Z(hr, { icon: "download" })
|
|
989
|
+
})]
|
|
990
|
+
}) : null
|
|
991
|
+
]
|
|
992
|
+
}) : null,
|
|
993
|
+
ie && R && _ ? /* @__PURE__ */ Q("div", {
|
|
994
|
+
className: "markweave-codeblock-language-menu",
|
|
995
|
+
role: "listbox",
|
|
996
|
+
"aria-label": "Code block languages",
|
|
997
|
+
"data-testid": "markweave-codeblock-language-menu",
|
|
998
|
+
"data-positioned": h ? "true" : "false",
|
|
999
|
+
style: h ? {
|
|
1000
|
+
left: h.left,
|
|
1001
|
+
top: h.top
|
|
1002
|
+
} : void 0,
|
|
1003
|
+
children: [/* @__PURE__ */ Q("label", {
|
|
1004
|
+
className: "markweave-codeblock-language-search",
|
|
1005
|
+
children: [/* @__PURE__ */ Z("input", {
|
|
1006
|
+
ref: s,
|
|
1007
|
+
value: y,
|
|
1008
|
+
placeholder: "Search...",
|
|
1009
|
+
"data-testid": "markweave-codeblock-language-search",
|
|
1010
|
+
onChange: (e) => b(e.target.value),
|
|
1011
|
+
onKeyDown: (e) => {
|
|
1012
|
+
e.key === "Escape" && (e.preventDefault(), v(!1), t.view.focus());
|
|
1013
|
+
}
|
|
1014
|
+
}), /* @__PURE__ */ Z(hr, { icon: "search" })]
|
|
1015
|
+
}), /* @__PURE__ */ Z("div", {
|
|
1016
|
+
className: "markweave-codeblock-language-list",
|
|
1017
|
+
children: ue.map((e) => {
|
|
1018
|
+
let t = e.language === F.language;
|
|
1019
|
+
return /* @__PURE__ */ Q("button", {
|
|
1020
|
+
type: "button",
|
|
1021
|
+
role: "option",
|
|
1022
|
+
"aria-selected": t,
|
|
1023
|
+
"data-testid": `markweave-codeblock-language-option-${e.language}`,
|
|
1024
|
+
"data-active": t ? "true" : "false",
|
|
1025
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1026
|
+
onClick: () => V(e.language),
|
|
1027
|
+
children: [/* @__PURE__ */ Z("span", { children: e.label }), t ? /* @__PURE__ */ Z(hr, { icon: "check" }) : null]
|
|
1028
|
+
}, e.language);
|
|
1029
|
+
})
|
|
1030
|
+
})]
|
|
1031
|
+
}) : null,
|
|
1032
|
+
T ? /* @__PURE__ */ Q("div", {
|
|
1033
|
+
className: "markweave-mermaid-fullscreen-layer",
|
|
1034
|
+
role: "dialog",
|
|
1035
|
+
"aria-modal": "true",
|
|
1036
|
+
"aria-label": "Mermaid preview",
|
|
1037
|
+
"data-testid": "markweave-mermaid-fullscreen-layer",
|
|
1038
|
+
children: [
|
|
1039
|
+
/* @__PURE__ */ Q("div", {
|
|
1040
|
+
className: "markweave-mermaid-fullscreen-toolbar",
|
|
1041
|
+
"data-testid": "markweave-mermaid-fullscreen-toolbar",
|
|
1042
|
+
children: [
|
|
1043
|
+
/* @__PURE__ */ Z("button", {
|
|
1044
|
+
type: "button",
|
|
1045
|
+
className: "markweave-mermaid-fullscreen-control",
|
|
1046
|
+
"aria-label": "Zoom out",
|
|
1047
|
+
"data-testid": "markweave-mermaid-fullscreen-zoom-out",
|
|
1048
|
+
onMouseEnter: () => O("zoom-out"),
|
|
1049
|
+
onMouseLeave: () => O(null),
|
|
1050
|
+
onFocus: () => O("zoom-out"),
|
|
1051
|
+
onBlur: () => O(null),
|
|
1052
|
+
onClick: () => ge(-an),
|
|
1053
|
+
children: /* @__PURE__ */ Z(hr, { icon: "zoomOut" })
|
|
1054
|
+
}),
|
|
1055
|
+
/* @__PURE__ */ Z("span", {
|
|
1056
|
+
className: "markweave-mermaid-fullscreen-zoom-label",
|
|
1057
|
+
"data-testid": "markweave-mermaid-fullscreen-zoom-label",
|
|
1058
|
+
children: qt(T.scale)
|
|
1059
|
+
}),
|
|
1060
|
+
/* @__PURE__ */ Z("button", {
|
|
1061
|
+
type: "button",
|
|
1062
|
+
className: "markweave-mermaid-fullscreen-control",
|
|
1063
|
+
"aria-label": "Zoom in",
|
|
1064
|
+
"data-testid": "markweave-mermaid-fullscreen-zoom-in",
|
|
1065
|
+
onMouseEnter: () => O("zoom-in"),
|
|
1066
|
+
onMouseLeave: () => O(null),
|
|
1067
|
+
onFocus: () => O("zoom-in"),
|
|
1068
|
+
onBlur: () => O(null),
|
|
1069
|
+
onClick: () => ge(an),
|
|
1070
|
+
children: /* @__PURE__ */ Z(hr, { icon: "zoomIn" })
|
|
1071
|
+
}),
|
|
1072
|
+
/* @__PURE__ */ Z("button", {
|
|
1073
|
+
type: "button",
|
|
1074
|
+
className: "markweave-mermaid-fullscreen-control",
|
|
1075
|
+
"aria-label": "Reset zoom",
|
|
1076
|
+
"data-testid": "markweave-mermaid-fullscreen-reset",
|
|
1077
|
+
onMouseEnter: () => O("reset"),
|
|
1078
|
+
onMouseLeave: () => O(null),
|
|
1079
|
+
onFocus: () => O("reset"),
|
|
1080
|
+
onBlur: () => O(null),
|
|
1081
|
+
onClick: _e,
|
|
1082
|
+
children: /* @__PURE__ */ Z(hr, { icon: "reset" })
|
|
1083
|
+
}),
|
|
1084
|
+
D ? /* @__PURE__ */ Z("span", {
|
|
1085
|
+
className: "markweave-mermaid-fullscreen-tooltip",
|
|
1086
|
+
role: "tooltip",
|
|
1087
|
+
"data-testid": "markweave-mermaid-fullscreen-tooltip",
|
|
1088
|
+
children: D === "zoom-out" ? "Zoom out" : D === "zoom-in" ? "Zoom in" : "Reset"
|
|
1089
|
+
}) : null
|
|
1090
|
+
]
|
|
1091
|
+
}),
|
|
1092
|
+
/* @__PURE__ */ Z("button", {
|
|
1093
|
+
type: "button",
|
|
1094
|
+
className: "markweave-mermaid-fullscreen-close",
|
|
1095
|
+
"aria-label": "Close fullscreen Mermaid preview",
|
|
1096
|
+
"data-testid": "markweave-mermaid-fullscreen-close",
|
|
1097
|
+
onClick: q,
|
|
1098
|
+
children: /* @__PURE__ */ Z(hr, { icon: "close" })
|
|
1099
|
+
}),
|
|
1100
|
+
/* @__PURE__ */ Z("div", {
|
|
1101
|
+
className: "markweave-mermaid-fullscreen-viewport",
|
|
1102
|
+
"data-testid": "markweave-mermaid-fullscreen-viewport",
|
|
1103
|
+
"data-dragging": k ? "true" : "false",
|
|
1104
|
+
onWheel: ve,
|
|
1105
|
+
onMouseDown: ye,
|
|
1106
|
+
onMouseMove: be,
|
|
1107
|
+
onMouseUp: xe,
|
|
1108
|
+
onMouseLeave: xe,
|
|
1109
|
+
children: /* @__PURE__ */ Z("div", {
|
|
1110
|
+
className: "markweave-mermaid-fullscreen-content",
|
|
1111
|
+
"data-testid": "markweave-mermaid-fullscreen-content",
|
|
1112
|
+
"data-scale-percent": Math.round(T.scale * 100),
|
|
1113
|
+
"data-translate": `${Math.round(T.translateX)},${Math.round(T.translateY)}`,
|
|
1114
|
+
style: {
|
|
1115
|
+
width: `${T.width}px`,
|
|
1116
|
+
height: `${T.height}px`,
|
|
1117
|
+
transform: `translate(${T.translateX}px, ${T.translateY}px) scale(${T.scale})`
|
|
1118
|
+
},
|
|
1119
|
+
dangerouslySetInnerHTML: { __html: T.svg }
|
|
1120
|
+
})
|
|
1121
|
+
})
|
|
1122
|
+
]
|
|
1123
|
+
}) : null
|
|
1124
|
+
]
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/ui/floating-toolbar/FloatingToolbar.tsx
|
|
1129
|
+
var _r = ke("zh");
|
|
1130
|
+
function vr() {
|
|
1131
|
+
return typeof performance > "u" ? Date.now() : performance.now();
|
|
1132
|
+
}
|
|
1133
|
+
function yr(e, t) {
|
|
1134
|
+
return {
|
|
1135
|
+
"--markweave-toolbar-motion-duration": `${e.motionDurationMs}ms`,
|
|
1136
|
+
"--markweave-toolbar-motion-easing": e.motionEasing,
|
|
1137
|
+
marginLeft: t === 0 ? void 0 : `${t}px`
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function br(e, t) {
|
|
1141
|
+
let n = e?.getBoundingClientRect().height ?? 0, r = t?.getBoundingClientRect().height ?? 0;
|
|
1142
|
+
return Math.max(n, r, 44);
|
|
1143
|
+
}
|
|
1144
|
+
function xr(e) {
|
|
1145
|
+
if (e !== null) return { "--markweave-floating-toolbar-tooltip-left": `${e}px` };
|
|
1146
|
+
}
|
|
1147
|
+
function Sr(e, t, n, r) {
|
|
1148
|
+
let i = {
|
|
1149
|
+
bottom: t + r,
|
|
1150
|
+
height: r,
|
|
1151
|
+
left: e,
|
|
1152
|
+
right: e + n,
|
|
1153
|
+
top: t,
|
|
1154
|
+
width: n,
|
|
1155
|
+
x: e,
|
|
1156
|
+
y: t
|
|
1157
|
+
};
|
|
1158
|
+
return typeof DOMRect < "u" ? new DOMRect(i.x, i.y, i.width, i.height) : {
|
|
1159
|
+
...i,
|
|
1160
|
+
toJSON: () => i
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
function Cr(e) {
|
|
1164
|
+
return e.width > 0 && e.height > 0;
|
|
1165
|
+
}
|
|
1166
|
+
function wr(e) {
|
|
1167
|
+
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));
|
|
1168
|
+
return Sr(t, n, r - t, i - n);
|
|
1169
|
+
}
|
|
1170
|
+
function Tr(e, t) {
|
|
1171
|
+
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;
|
|
1172
|
+
return r(t.anchorNode) && r(t.focusNode);
|
|
1173
|
+
}
|
|
1174
|
+
function Er(e) {
|
|
1175
|
+
if (typeof e.getClientRects != "function") return null;
|
|
1176
|
+
let t = Array.from(e.getClientRects()).filter(Cr).map((e) => Sr(e.left, e.top, e.width, e.height));
|
|
1177
|
+
if (t.length > 0) return t;
|
|
1178
|
+
if (typeof e.getBoundingClientRect != "function") return null;
|
|
1179
|
+
let n = e.getBoundingClientRect();
|
|
1180
|
+
return Cr(n) ? [Sr(n.left, n.top, n.width, n.height)] : null;
|
|
1181
|
+
}
|
|
1182
|
+
function Dr(e, t) {
|
|
1183
|
+
if (t.rangeCount === 0) return null;
|
|
1184
|
+
let n = t.getRangeAt(0);
|
|
1185
|
+
try {
|
|
1186
|
+
let t = e.view.posAtDOM(n.startContainer, n.startOffset), r = e.view.posAtDOM(n.endContainer, n.endOffset);
|
|
1187
|
+
return {
|
|
1188
|
+
from: Math.min(t, r),
|
|
1189
|
+
to: Math.max(t, r)
|
|
1190
|
+
};
|
|
1191
|
+
} catch {
|
|
1192
|
+
return null;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function Or(e, t) {
|
|
1196
|
+
let n = Dr(e, t);
|
|
1197
|
+
if (!n) return !1;
|
|
1198
|
+
let { selection: r } = e.state, i = {
|
|
1199
|
+
from: Math.min(r.from, r.to),
|
|
1200
|
+
to: Math.max(r.from, r.to)
|
|
1201
|
+
};
|
|
1202
|
+
return n.from === i.from && n.to === i.to;
|
|
1203
|
+
}
|
|
1204
|
+
function kr(e) {
|
|
1205
|
+
let t = e.view.dom.ownerDocument.getSelection();
|
|
1206
|
+
return !t || t.rangeCount === 0 || t.isCollapsed || !Tr(e, t) || !Or(e, t) ? null : Er(t.getRangeAt(0));
|
|
1207
|
+
}
|
|
1208
|
+
function Ar(e) {
|
|
1209
|
+
let { selection: t } = e.state;
|
|
1210
|
+
if (t.empty) return null;
|
|
1211
|
+
let n = Math.min(t.from, t.to), r = Math.max(t.from, t.to);
|
|
1212
|
+
try {
|
|
1213
|
+
let t = e.view.domAtPos(n), i = e.view.domAtPos(r), a = e.view.dom.ownerDocument.createRange();
|
|
1214
|
+
return a.setStart(t.node, t.offset), a.setEnd(i.node, i.offset), Er(a);
|
|
1215
|
+
} catch {
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
function jr(e) {
|
|
1220
|
+
let { selection: t } = e.state;
|
|
1221
|
+
if (t.empty) return null;
|
|
1222
|
+
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 = Sr(c, o, Math.max(i.right, a.right) - c, s - o);
|
|
1223
|
+
return Cr(l) ? [l] : null;
|
|
1224
|
+
}
|
|
1225
|
+
function Mr(e) {
|
|
1226
|
+
return kr(e) ?? Ar(e) ?? jr(e);
|
|
1227
|
+
}
|
|
1228
|
+
function Nr(e) {
|
|
1229
|
+
let t = Mr(e);
|
|
1230
|
+
return t && t.length > 0 ? wr(t) : null;
|
|
1231
|
+
}
|
|
1232
|
+
function Pr(e) {
|
|
1233
|
+
return {
|
|
1234
|
+
getBoundingClientRect: () => Nr(e) ?? Sr(0, 0, 0, 0),
|
|
1235
|
+
getClientRects: () => Mr(e) ?? []
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
function Fr(e) {
|
|
1239
|
+
return e === "block-type" || e === "link" || e === "color" || e === "more";
|
|
1240
|
+
}
|
|
1241
|
+
function Ir(e, t, n) {
|
|
1242
|
+
n?.(ln(e, t)), e.commands.focus();
|
|
1243
|
+
}
|
|
1244
|
+
function Lr({ editor: e, messages: t = _r, selectionSnapshot: n, onRewriteSelection: r }) {
|
|
1245
|
+
let i = W(() => mn(t), [t]), a = Ye(n, { editable: e.isEditable }), [o, s] = K(a), [c, l] = K(null), [u, d] = K(null), [f, p] = K(null), [m, h] = K(""), [g, _] = K(""), [v, y] = K(null), [b, x] = K(0), [S, C] = K(a.boundaryPadding), w = G(0), T = G(null), E = G(null), D = G(null), O = un(e, o.variant, t), k = gn(O.find((e) => e.id === c) ?? null), A = Dn(m), j = V(() => {
|
|
1246
|
+
let t = T.current, n = e.view.dom.closest(".markweave-editor-frame");
|
|
1247
|
+
if (!t || !(n instanceof HTMLElement)) return;
|
|
1248
|
+
let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = br(t, E.current), s = w.current, c = Ge({
|
|
1249
|
+
toolbarRect: {
|
|
1250
|
+
left: r.left - s,
|
|
1251
|
+
top: r.top,
|
|
1252
|
+
width: r.width,
|
|
1253
|
+
height: r.height
|
|
1254
|
+
},
|
|
1255
|
+
frameRect: {
|
|
1256
|
+
left: i.left,
|
|
1257
|
+
top: i.top,
|
|
1258
|
+
width: i.width,
|
|
1259
|
+
height: i.height
|
|
1260
|
+
},
|
|
1261
|
+
boundaryPadding: o.boundaryPadding
|
|
1262
|
+
}), l = Ke({
|
|
1263
|
+
frameRect: {
|
|
1264
|
+
left: i.left,
|
|
1265
|
+
top: i.top,
|
|
1266
|
+
width: i.width,
|
|
1267
|
+
height: i.height
|
|
1268
|
+
},
|
|
1269
|
+
toolbarSize: {
|
|
1270
|
+
width: r.width,
|
|
1271
|
+
height: a
|
|
1272
|
+
},
|
|
1273
|
+
offset: o.offset,
|
|
1274
|
+
boundaryPadding: o.boundaryPadding
|
|
1275
|
+
});
|
|
1276
|
+
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);
|
|
1277
|
+
}, [
|
|
1278
|
+
e.view.dom,
|
|
1279
|
+
o.boundaryPadding,
|
|
1280
|
+
o.offset
|
|
1281
|
+
]), ee = V(() => {
|
|
1282
|
+
T.current && (T.current.style.visibility = "hidden", T.current.style.opacity = "0");
|
|
1283
|
+
}, []), M = V(() => {
|
|
1284
|
+
j();
|
|
1285
|
+
}, [j]), N = V(() => Pr(e), [e]), P = W(() => ({
|
|
1286
|
+
...Je(o, { topBoundaryPadding: S }),
|
|
1287
|
+
onShow: ee,
|
|
1288
|
+
onUpdate: M
|
|
1289
|
+
}), [
|
|
1290
|
+
ee,
|
|
1291
|
+
M,
|
|
1292
|
+
o,
|
|
1293
|
+
S
|
|
1294
|
+
]);
|
|
1295
|
+
H(() => {
|
|
1296
|
+
let e = vr();
|
|
1297
|
+
s((t) => Ze(t, a, e));
|
|
1298
|
+
}, [
|
|
1299
|
+
a.hiddenReason,
|
|
1300
|
+
a.motionDurationMs,
|
|
1301
|
+
a.motionEasing,
|
|
1302
|
+
a.motionPhase,
|
|
1303
|
+
a.offset,
|
|
1304
|
+
a.boundaryPadding,
|
|
1305
|
+
a.placement,
|
|
1306
|
+
a.updateDelayMs,
|
|
1307
|
+
a.variant,
|
|
1308
|
+
a.visibility
|
|
1309
|
+
]), H(() => {
|
|
1310
|
+
if (o.motionStartedAtMs === null || o.motionDurationMs <= 0) return;
|
|
1311
|
+
let e = Math.max(0, o.motionStartedAtMs + o.motionDurationMs - vr()), t = window.setTimeout(() => {
|
|
1312
|
+
s((e) => We(e, vr()));
|
|
1313
|
+
}, e);
|
|
1314
|
+
return () => {
|
|
1315
|
+
window.clearTimeout(t);
|
|
1316
|
+
};
|
|
1317
|
+
}, [
|
|
1318
|
+
o.motionDurationMs,
|
|
1319
|
+
o.motionPhase,
|
|
1320
|
+
o.motionStartedAtMs
|
|
1321
|
+
]), U(() => {
|
|
1322
|
+
if (o.visibility !== "visible") {
|
|
1323
|
+
w.current = 0, T.current && (T.current.style.marginLeft = "", T.current.style.visibility = "hidden", T.current.style.opacity = "0"), x(0), C(o.boundaryPadding);
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
let e = 0;
|
|
1327
|
+
return e = window.requestAnimationFrame(j), window.addEventListener("resize", j), window.addEventListener("scroll", j, !0), () => {
|
|
1328
|
+
window.cancelAnimationFrame(e), window.removeEventListener("resize", j), window.removeEventListener("scroll", j, !0);
|
|
1329
|
+
};
|
|
1330
|
+
}, [
|
|
1331
|
+
j,
|
|
1332
|
+
e.view.dom,
|
|
1333
|
+
f,
|
|
1334
|
+
n?.from,
|
|
1335
|
+
n?.to,
|
|
1336
|
+
o.variant,
|
|
1337
|
+
o.visibility,
|
|
1338
|
+
O.length
|
|
1339
|
+
]), H(() => {
|
|
1340
|
+
f === "more" && i.some((e) => e.id === c) || O.some((e) => e.id === c) || (l(null), d(null));
|
|
1341
|
+
}, [
|
|
1342
|
+
i,
|
|
1343
|
+
f,
|
|
1344
|
+
c,
|
|
1345
|
+
O
|
|
1346
|
+
]), H(() => {
|
|
1347
|
+
if (!f) return;
|
|
1348
|
+
let t = (e) => {
|
|
1349
|
+
E.current?.contains(e.target) || p(null);
|
|
1350
|
+
}, n = (t) => {
|
|
1351
|
+
t.key === "Escape" && (t.preventDefault(), p(null), e.commands.focus());
|
|
1352
|
+
};
|
|
1353
|
+
return document.addEventListener("pointerdown", t, !0), document.addEventListener("keydown", n, !0), () => {
|
|
1354
|
+
document.removeEventListener("pointerdown", t, !0), document.removeEventListener("keydown", n, !0);
|
|
1355
|
+
};
|
|
1356
|
+
}, [e, f]), H(() => {
|
|
1357
|
+
if (f !== "link") return;
|
|
1358
|
+
let e = window.requestAnimationFrame(() => {
|
|
1359
|
+
D.current?.focus(), D.current?.select();
|
|
1360
|
+
});
|
|
1361
|
+
return () => window.cancelAnimationFrame(e);
|
|
1362
|
+
}, [f]);
|
|
1363
|
+
let te = (t) => {
|
|
1364
|
+
if (Fr(t.id)) {
|
|
1365
|
+
let n = t.id;
|
|
1366
|
+
if (n === "link") {
|
|
1367
|
+
let t = fn(e);
|
|
1368
|
+
h(t), _(t), y({
|
|
1369
|
+
from: Math.min(e.state.selection.from, e.state.selection.to),
|
|
1370
|
+
to: Math.max(e.state.selection.from, e.state.selection.to)
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
p((e) => e === n ? null : n);
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
if (p(null), t.id === "improve") {
|
|
1377
|
+
Ir(e, "rewrite-selection", r);
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
t.run(), e.commands.focus();
|
|
1381
|
+
}, ne = () => {
|
|
1382
|
+
p(null), e.commands.focus();
|
|
1383
|
+
}, F = () => {
|
|
1384
|
+
v && e.commands.setTextSelection(v);
|
|
1385
|
+
}, I = () => {
|
|
1386
|
+
F(), cn(e, m) && ne();
|
|
1387
|
+
}, re = () => {
|
|
1388
|
+
if (F(), Sn(e)) {
|
|
1389
|
+
h(""), _(""), ne();
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
m.trim() && h("");
|
|
1393
|
+
}, L = (e, t) => {
|
|
1394
|
+
if (l(e), !e || !t || !E.current) {
|
|
1395
|
+
d(null);
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
let n = t.getBoundingClientRect(), r = E.current.getBoundingClientRect();
|
|
1399
|
+
d(n.left + n.width / 2 - r.left);
|
|
1400
|
+
};
|
|
1401
|
+
return /* @__PURE__ */ Z(sn, {
|
|
1402
|
+
ref: T,
|
|
1403
|
+
editor: e,
|
|
1404
|
+
className: `markweave-floating-toolbar markweave-floating-toolbar--${o.variant} markweave-floating-toolbar--motion-${o.motionPhase}`,
|
|
1405
|
+
"data-motion": o.motionPhase,
|
|
1406
|
+
"data-position-strategy": P.strategy,
|
|
1407
|
+
"data-boundary-padding": o.boundaryPadding,
|
|
1408
|
+
"data-testid": "markweave-floating-toolbar",
|
|
1409
|
+
style: yr(o, b),
|
|
1410
|
+
updateDelay: 0,
|
|
1411
|
+
getReferencedVirtualElement: N,
|
|
1412
|
+
options: P,
|
|
1413
|
+
shouldShow: ({ editor: e }) => e.isEditable && Xe(qe(e)),
|
|
1414
|
+
children: /* @__PURE__ */ Q("div", {
|
|
1415
|
+
ref: E,
|
|
1416
|
+
className: "markweave-floating-toolbar-content",
|
|
1417
|
+
"data-menu": f ?? "none",
|
|
1418
|
+
children: [
|
|
1419
|
+
O.map((e, t) => /* @__PURE__ */ Z(zr, {
|
|
1420
|
+
button: e,
|
|
1421
|
+
expanded: f === e.id,
|
|
1422
|
+
showDivider: t > 0 && O[t - 1].group !== e.group,
|
|
1423
|
+
tooltipActive: c === e.id,
|
|
1424
|
+
onPointerDown: xn,
|
|
1425
|
+
onTooltipChange: L,
|
|
1426
|
+
onRun: te
|
|
1427
|
+
}, e.id)),
|
|
1428
|
+
f === "block-type" ? /* @__PURE__ */ Z(Vr, {
|
|
1429
|
+
editor: e,
|
|
1430
|
+
messages: t,
|
|
1431
|
+
onClose: () => p(null)
|
|
1432
|
+
}) : null,
|
|
1433
|
+
f === "link" ? /* @__PURE__ */ Z(Rr, {
|
|
1434
|
+
inputRef: D,
|
|
1435
|
+
messages: t,
|
|
1436
|
+
value: m,
|
|
1437
|
+
canApply: !!A,
|
|
1438
|
+
canOpen: !!A,
|
|
1439
|
+
canRemove: !!(g || m.trim()),
|
|
1440
|
+
onValueChange: h,
|
|
1441
|
+
onApply: I,
|
|
1442
|
+
onOpen: () => bn(m),
|
|
1443
|
+
onRemove: re
|
|
1444
|
+
}) : null,
|
|
1445
|
+
f === "color" ? /* @__PURE__ */ Z(Ur, {
|
|
1446
|
+
editor: e,
|
|
1447
|
+
messages: t,
|
|
1448
|
+
onClose: () => p(null)
|
|
1449
|
+
}) : null,
|
|
1450
|
+
f === "more" ? /* @__PURE__ */ Z(Gr, {
|
|
1451
|
+
editor: e,
|
|
1452
|
+
messages: t,
|
|
1453
|
+
activeTooltipId: c,
|
|
1454
|
+
onTooltipChange: l,
|
|
1455
|
+
onClose: () => p(null)
|
|
1456
|
+
}) : null,
|
|
1457
|
+
k && f === null ? /* @__PURE__ */ Z("div", {
|
|
1458
|
+
className: "markweave-floating-toolbar-tooltip",
|
|
1459
|
+
role: "tooltip",
|
|
1460
|
+
"data-testid": "markweave-floating-toolbar-tooltip",
|
|
1461
|
+
"data-button-id": k.buttonId,
|
|
1462
|
+
"data-active": k.active,
|
|
1463
|
+
style: xr(u),
|
|
1464
|
+
children: k.label
|
|
1465
|
+
}) : null
|
|
1466
|
+
]
|
|
1467
|
+
})
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
function Rr({ inputRef: e, messages: t, value: n, canApply: r, canOpen: i, canRemove: a, onValueChange: o, onApply: s, onOpen: c, onRemove: l }) {
|
|
1471
|
+
let u = pn(t);
|
|
1472
|
+
return /* @__PURE__ */ Q("form", {
|
|
1473
|
+
className: "markweave-floating-toolbar-popover markweave-floating-toolbar-link-popover",
|
|
1474
|
+
"data-testid": "markweave-floating-toolbar-link-popover",
|
|
1475
|
+
onSubmit: (e) => {
|
|
1476
|
+
e.preventDefault(), s();
|
|
1477
|
+
},
|
|
1478
|
+
children: [/* @__PURE__ */ Z("input", {
|
|
1479
|
+
ref: e,
|
|
1480
|
+
"aria-label": u.linkUrlLabel,
|
|
1481
|
+
"data-testid": "markweave-floating-toolbar-link-input",
|
|
1482
|
+
placeholder: u.linkPlaceholder,
|
|
1483
|
+
value: n,
|
|
1484
|
+
onChange: (e) => o(e.currentTarget.value)
|
|
1485
|
+
}), /* @__PURE__ */ Q("span", {
|
|
1486
|
+
className: "markweave-floating-toolbar-link-actions",
|
|
1487
|
+
children: [
|
|
1488
|
+
/* @__PURE__ */ Z("button", {
|
|
1489
|
+
type: "submit",
|
|
1490
|
+
"aria-label": u.applyLink,
|
|
1491
|
+
"data-testid": "markweave-floating-toolbar-link-apply",
|
|
1492
|
+
disabled: !r,
|
|
1493
|
+
onMouseDown: xn,
|
|
1494
|
+
children: /* @__PURE__ */ Z($, { name: "corner-down-left" })
|
|
1495
|
+
}),
|
|
1496
|
+
/* @__PURE__ */ Z("span", {
|
|
1497
|
+
className: "markweave-floating-toolbar-link-divider",
|
|
1498
|
+
"aria-hidden": "true"
|
|
1499
|
+
}),
|
|
1500
|
+
/* @__PURE__ */ Z("button", {
|
|
1501
|
+
type: "button",
|
|
1502
|
+
"aria-label": u.openLink,
|
|
1503
|
+
"data-testid": "markweave-floating-toolbar-link-open",
|
|
1504
|
+
disabled: !i,
|
|
1505
|
+
onMouseDown: xn,
|
|
1506
|
+
onClick: c,
|
|
1507
|
+
children: /* @__PURE__ */ Z($, { name: "external-link" })
|
|
1508
|
+
}),
|
|
1509
|
+
/* @__PURE__ */ Z("button", {
|
|
1510
|
+
type: "button",
|
|
1511
|
+
"aria-label": u.removeLink,
|
|
1512
|
+
"data-testid": "markweave-floating-toolbar-link-remove",
|
|
1513
|
+
disabled: !a,
|
|
1514
|
+
onMouseDown: xn,
|
|
1515
|
+
onClick: l,
|
|
1516
|
+
children: /* @__PURE__ */ Z($, { name: "trash" })
|
|
1517
|
+
})
|
|
1518
|
+
]
|
|
1519
|
+
})]
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
function zr({ button: e, expanded: t, showDivider: n, tooltipActive: r, onPointerDown: i, onTooltipChange: a, onRun: o }) {
|
|
1523
|
+
return /* @__PURE__ */ Q(X, { children: [n ? /* @__PURE__ */ Z("span", {
|
|
1524
|
+
className: "markweave-floating-toolbar-divider",
|
|
1525
|
+
"aria-hidden": "true"
|
|
1526
|
+
}) : null, /* @__PURE__ */ Z("button", {
|
|
1527
|
+
type: "button",
|
|
1528
|
+
className: `markweave-floating-toolbar-button markweave-floating-toolbar-button--${e.id}`,
|
|
1529
|
+
"aria-label": e.label,
|
|
1530
|
+
"aria-expanded": Fr(e.id) ? t : void 0,
|
|
1531
|
+
"data-active": e.active || t,
|
|
1532
|
+
"data-tooltip-active": r ? "true" : "false",
|
|
1533
|
+
"data-testid": `markweave-floating-toolbar-button-${e.id}`,
|
|
1534
|
+
onBlur: () => a(null),
|
|
1535
|
+
onFocus: (t) => a(e.id, t.currentTarget),
|
|
1536
|
+
onMouseDown: i,
|
|
1537
|
+
onMouseEnter: (t) => a(e.id, t.currentTarget),
|
|
1538
|
+
onMouseLeave: () => a(null),
|
|
1539
|
+
onClick: () => o(e),
|
|
1540
|
+
children: /* @__PURE__ */ Z(Br, {
|
|
1541
|
+
button: e,
|
|
1542
|
+
expanded: t
|
|
1543
|
+
})
|
|
1544
|
+
})] });
|
|
1545
|
+
}
|
|
1546
|
+
function Br({ button: e, expanded: t }) {
|
|
1547
|
+
return e.id === "improve" ? /* @__PURE__ */ Q("span", {
|
|
1548
|
+
className: "markweave-floating-toolbar-button-inner",
|
|
1549
|
+
children: [/* @__PURE__ */ Z($, { name: "sparkles" }), /* @__PURE__ */ Z("span", { children: e.glyph })]
|
|
1550
|
+
}) : e.id === "block-type" ? /* @__PURE__ */ Q("span", {
|
|
1551
|
+
className: "markweave-floating-toolbar-button-inner",
|
|
1552
|
+
children: [/* @__PURE__ */ Z("span", {
|
|
1553
|
+
className: "markweave-floating-toolbar-block-label",
|
|
1554
|
+
children: e.glyph
|
|
1555
|
+
}), /* @__PURE__ */ Z($, { name: t ? "chevron-up" : "chevron-down" })]
|
|
1556
|
+
}) : e.id === "bold" ? /* @__PURE__ */ Z($, { name: "bold" }) : e.id === "italic" ? /* @__PURE__ */ Z($, { name: "italic" }) : e.id === "underline" ? /* @__PURE__ */ Z($, { name: "underline" }) : e.id === "strike" ? /* @__PURE__ */ Z($, { name: "strike" }) : e.id === "inline-code" ? /* @__PURE__ */ Z($, { name: "inline-code" }) : e.id === "link" ? /* @__PURE__ */ Z($, { name: "link" }) : e.id === "color" ? /* @__PURE__ */ Q("span", {
|
|
1557
|
+
className: "markweave-floating-toolbar-button-inner markweave-floating-toolbar-button-inner--color",
|
|
1558
|
+
children: [/* @__PURE__ */ Z("span", {
|
|
1559
|
+
className: "markweave-floating-toolbar-color-trigger",
|
|
1560
|
+
children: "A"
|
|
1561
|
+
}), /* @__PURE__ */ Z($, { name: t ? "chevron-up" : "chevron-down" })]
|
|
1562
|
+
}) : /* @__PURE__ */ Z($, { name: "more" });
|
|
1563
|
+
}
|
|
1564
|
+
function Vr({ editor: e, messages: t, onClose: n }) {
|
|
1565
|
+
let r = pn(t), i = _n(t);
|
|
1566
|
+
return /* @__PURE__ */ Q("div", {
|
|
1567
|
+
className: "markweave-floating-toolbar-popover markweave-floating-toolbar-turn-menu",
|
|
1568
|
+
"data-testid": "markweave-floating-toolbar-turn-menu",
|
|
1569
|
+
children: [/* @__PURE__ */ Z("div", {
|
|
1570
|
+
className: "markweave-floating-toolbar-menu-title",
|
|
1571
|
+
children: r.turnIntoTitle
|
|
1572
|
+
}), i.map((t) => /* @__PURE__ */ Q("button", {
|
|
1573
|
+
type: "button",
|
|
1574
|
+
"data-active": yn(e, t.id),
|
|
1575
|
+
"data-testid": `markweave-floating-toolbar-turn-${t.id}`,
|
|
1576
|
+
onMouseDown: xn,
|
|
1577
|
+
onClick: () => {
|
|
1578
|
+
En(e, t.id), n();
|
|
1579
|
+
},
|
|
1580
|
+
children: [/* @__PURE__ */ Z("span", {
|
|
1581
|
+
className: "markweave-floating-toolbar-menu-icon",
|
|
1582
|
+
children: /* @__PURE__ */ Z(Hr, { option: t })
|
|
1583
|
+
}), /* @__PURE__ */ Z("span", { children: t.label })]
|
|
1584
|
+
}, t.id))]
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
function Hr({ option: e }) {
|
|
1588
|
+
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 });
|
|
1589
|
+
}
|
|
1590
|
+
function Ur({ editor: e, messages: t, onClose: n }) {
|
|
1591
|
+
let r = pn(t), i = e.getAttributes("textStyle").color, a = e.getAttributes("highlight").color;
|
|
1592
|
+
return /* @__PURE__ */ Q("div", {
|
|
1593
|
+
className: "markweave-floating-toolbar-popover markweave-floating-toolbar-color-popover",
|
|
1594
|
+
"data-testid": "markweave-floating-toolbar-color-menu",
|
|
1595
|
+
children: [/* @__PURE__ */ Z(Wr, {
|
|
1596
|
+
title: r.textColorTitle,
|
|
1597
|
+
mode: "text",
|
|
1598
|
+
activeColor: i ?? null,
|
|
1599
|
+
options: hn(t),
|
|
1600
|
+
onSelect: (t) => {
|
|
1601
|
+
Tn(e, t), n();
|
|
1602
|
+
}
|
|
1603
|
+
}), /* @__PURE__ */ Z(Wr, {
|
|
1604
|
+
title: r.highlightColorTitle,
|
|
1605
|
+
mode: "highlight",
|
|
1606
|
+
activeColor: a ?? null,
|
|
1607
|
+
options: dn(t),
|
|
1608
|
+
onSelect: (t) => {
|
|
1609
|
+
wn(e, t), n();
|
|
1610
|
+
}
|
|
1611
|
+
})]
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
function Wr({ title: e, mode: t, activeColor: n, options: r, onSelect: i }) {
|
|
1615
|
+
return /* @__PURE__ */ Q("section", {
|
|
1616
|
+
className: "markweave-floating-toolbar-color-section",
|
|
1617
|
+
"aria-label": e,
|
|
1618
|
+
children: [/* @__PURE__ */ Z("div", {
|
|
1619
|
+
className: "markweave-floating-toolbar-menu-title",
|
|
1620
|
+
children: e
|
|
1621
|
+
}), /* @__PURE__ */ Z("div", {
|
|
1622
|
+
className: "markweave-floating-toolbar-swatch-grid",
|
|
1623
|
+
children: r.map((e) => /* @__PURE__ */ Z("button", {
|
|
1624
|
+
type: "button",
|
|
1625
|
+
"aria-label": e.label,
|
|
1626
|
+
"data-active": e.value === n || e.value === null && !n,
|
|
1627
|
+
"data-testid": `markweave-floating-toolbar-${t}-${e.id}`,
|
|
1628
|
+
onMouseDown: xn,
|
|
1629
|
+
onClick: () => i(e.value),
|
|
1630
|
+
children: t === "text" ? /* @__PURE__ */ Z("span", {
|
|
1631
|
+
className: "markweave-floating-toolbar-text-swatch",
|
|
1632
|
+
style: { color: e.value ?? "#646970" },
|
|
1633
|
+
children: "A"
|
|
1634
|
+
}) : /* @__PURE__ */ Z("span", {
|
|
1635
|
+
className: "markweave-floating-toolbar-highlight-swatch",
|
|
1636
|
+
style: { backgroundColor: e.value ?? "#ffffff" },
|
|
1637
|
+
"aria-hidden": "true"
|
|
1638
|
+
})
|
|
1639
|
+
}, e.id))
|
|
1640
|
+
})]
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
function Gr({ editor: e, messages: t, activeTooltipId: n, onTooltipChange: r, onClose: i }) {
|
|
1644
|
+
let a = mn(t);
|
|
1645
|
+
return /* @__PURE__ */ Z("div", {
|
|
1646
|
+
className: "markweave-floating-toolbar-popover markweave-floating-toolbar-more-menu",
|
|
1647
|
+
"data-testid": "markweave-floating-toolbar-more-menu",
|
|
1648
|
+
children: a.map((t, o) => /* @__PURE__ */ Z(Kr, {
|
|
1649
|
+
action: t,
|
|
1650
|
+
active: vn(e, t.id),
|
|
1651
|
+
tooltipActive: n === t.id,
|
|
1652
|
+
showDivider: o > 0 && a[o - 1].group !== t.group,
|
|
1653
|
+
onTooltipChange: r,
|
|
1654
|
+
onRun: () => {
|
|
1655
|
+
Cn(e, t.id), i();
|
|
1656
|
+
}
|
|
1657
|
+
}, t.id))
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
function Kr({ action: e, active: t, tooltipActive: n, showDivider: r, onTooltipChange: i, onRun: a }) {
|
|
1661
|
+
return /* @__PURE__ */ Q(X, { children: [r ? /* @__PURE__ */ Z("span", {
|
|
1662
|
+
className: "markweave-floating-toolbar-divider",
|
|
1663
|
+
"aria-hidden": "true"
|
|
1664
|
+
}) : null, /* @__PURE__ */ Q("span", {
|
|
1665
|
+
className: "markweave-floating-toolbar-more-item",
|
|
1666
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
1667
|
+
type: "button",
|
|
1668
|
+
"aria-label": e.label,
|
|
1669
|
+
"data-active": t,
|
|
1670
|
+
"data-tooltip-active": n ? "true" : "false",
|
|
1671
|
+
"data-testid": `markweave-floating-toolbar-more-${e.id}`,
|
|
1672
|
+
onMouseDown: xn,
|
|
1673
|
+
onMouseEnter: () => i(e.id),
|
|
1674
|
+
onMouseLeave: () => i(null),
|
|
1675
|
+
onClick: a,
|
|
1676
|
+
children: /* @__PURE__ */ Z(qr, { id: e.id })
|
|
1677
|
+
}), n ? /* @__PURE__ */ Z("div", {
|
|
1678
|
+
className: "markweave-floating-toolbar-tooltip markweave-floating-toolbar-tooltip--more",
|
|
1679
|
+
role: "tooltip",
|
|
1680
|
+
children: e.label
|
|
1681
|
+
}) : null]
|
|
1682
|
+
})] });
|
|
1683
|
+
}
|
|
1684
|
+
function qr({ id: e }) {
|
|
1685
|
+
return e === "superscript" ? /* @__PURE__ */ Z($, { name: "superscript" }) : e === "subscript" ? /* @__PURE__ */ Z($, { name: "subscript" }) : e === "inline-math" ? /* @__PURE__ */ Z($, { name: "math" }) : Z($, { name: e });
|
|
1686
|
+
}
|
|
1687
|
+
var Jr = {
|
|
1688
|
+
sparkles: ie,
|
|
1689
|
+
"chevron-down": h,
|
|
1690
|
+
"chevron-up": g,
|
|
1691
|
+
"corner-down-left": y,
|
|
1692
|
+
"external-link": x,
|
|
1693
|
+
bold: u,
|
|
1694
|
+
italic: A,
|
|
1695
|
+
underline: de,
|
|
1696
|
+
strike: ae,
|
|
1697
|
+
"inline-code": v,
|
|
1698
|
+
link: ee,
|
|
1699
|
+
more: ne,
|
|
1700
|
+
text: ue,
|
|
1701
|
+
"bullet-list": M,
|
|
1702
|
+
"numbered-list": P,
|
|
1703
|
+
"todo-list": N,
|
|
1704
|
+
quote: I,
|
|
1705
|
+
"code-block": d,
|
|
1706
|
+
superscript: se,
|
|
1707
|
+
subscript: oe,
|
|
1708
|
+
math: L,
|
|
1709
|
+
"align-left": c,
|
|
1710
|
+
"align-center": o,
|
|
1711
|
+
"align-right": l,
|
|
1712
|
+
"align-justify": s,
|
|
1713
|
+
"decrease-indent": D,
|
|
1714
|
+
"increase-indent": O,
|
|
1715
|
+
trash: le
|
|
1716
|
+
};
|
|
1717
|
+
function $({ name: e }) {
|
|
1718
|
+
let t = Jr[e];
|
|
1719
|
+
return /* @__PURE__ */ Z(t, {
|
|
1720
|
+
"aria-hidden": "true",
|
|
1721
|
+
absoluteStrokeWidth: !0,
|
|
1722
|
+
size: 18,
|
|
1723
|
+
strokeWidth: 1.6
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
//#endregion
|
|
1727
|
+
//#region src/ui/math/MathEditorPopover.tsx
|
|
1728
|
+
function Yr({ editor: e, messages: t, onClose: n, target: r }) {
|
|
1729
|
+
let i = G(null), a = G(null), [o, s] = K(r.latex), [c, l] = K(null), u = t.math, d = W(() => pt(e, r) ?? 1, [e, r]), f = W(() => mt(e, r), [e, r]), m = W(() => o === r.latex && f ? {
|
|
1730
|
+
html: f,
|
|
1731
|
+
error: !1
|
|
1732
|
+
} : vt(o, r.kind, e), [
|
|
1733
|
+
e,
|
|
1734
|
+
f,
|
|
1735
|
+
r.kind,
|
|
1736
|
+
r.latex,
|
|
1737
|
+
o
|
|
1738
|
+
]), h = o.trim().length > 0, g = V(() => {
|
|
1739
|
+
if (typeof window > "u") return;
|
|
1740
|
+
let t = ft(e, r), i = e.view.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
|
|
1741
|
+
if (!t || !i) {
|
|
1742
|
+
n();
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1745
|
+
l(dt({
|
|
1746
|
+
anchorRect: t,
|
|
1747
|
+
frameRect: i,
|
|
1748
|
+
kind: r.kind,
|
|
1749
|
+
latex: o,
|
|
1750
|
+
viewportHeight: window.innerHeight,
|
|
1751
|
+
viewportWidth: window.innerWidth
|
|
1752
|
+
}));
|
|
1753
|
+
}, [
|
|
1754
|
+
e,
|
|
1755
|
+
n,
|
|
1756
|
+
r,
|
|
1757
|
+
o
|
|
1758
|
+
]);
|
|
1759
|
+
H(() => {
|
|
1760
|
+
s(r.latex);
|
|
1761
|
+
}, [r.latex, r.pos]), H(() => {
|
|
1762
|
+
yt(e, r, !0), g();
|
|
1763
|
+
let t = window.requestAnimationFrame(() => {
|
|
1764
|
+
a.current?.focus({ preventScroll: !0 }), a.current?.select(), g();
|
|
1765
|
+
});
|
|
1766
|
+
return window.addEventListener("resize", g), window.addEventListener("scroll", g, !0), () => {
|
|
1767
|
+
window.cancelAnimationFrame(t), window.removeEventListener("resize", g), window.removeEventListener("scroll", g, !0), yt(e, r, !1);
|
|
1768
|
+
};
|
|
1769
|
+
}, [
|
|
1770
|
+
e,
|
|
1771
|
+
n,
|
|
1772
|
+
r,
|
|
1773
|
+
g
|
|
1774
|
+
]), H(() => {
|
|
1775
|
+
let e = (e) => {
|
|
1776
|
+
let t = e.target;
|
|
1777
|
+
t instanceof Node && (i.current?.contains(t) || t instanceof Element && t.closest(".tiptap-mathematics-render") || n());
|
|
1778
|
+
};
|
|
1779
|
+
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
1780
|
+
}, [n]);
|
|
1781
|
+
let _ = V(() => {
|
|
1782
|
+
h && ut(e, r, o) && n();
|
|
1783
|
+
}, [
|
|
1784
|
+
h,
|
|
1785
|
+
e,
|
|
1786
|
+
n,
|
|
1787
|
+
r,
|
|
1788
|
+
o
|
|
1789
|
+
]), y = (t) => {
|
|
1790
|
+
if (t.key === "Escape") {
|
|
1791
|
+
t.preventDefault(), n(), e.commands.focus();
|
|
1792
|
+
return;
|
|
1793
|
+
}
|
|
1794
|
+
t.key === "Enter" && (r.kind === "inline" || t.metaKey || t.ctrlKey) && (t.preventDefault(), _());
|
|
1795
|
+
}, b = c ? {
|
|
1796
|
+
left: c.left,
|
|
1797
|
+
top: c.top,
|
|
1798
|
+
width: c.width
|
|
1799
|
+
} : void 0, x = r.kind === "block" ? u.blockTitle : u.inlineTitle;
|
|
1800
|
+
return r.kind === "inline" ? /* @__PURE__ */ Q("form", {
|
|
1801
|
+
ref: i,
|
|
1802
|
+
"aria-label": x,
|
|
1803
|
+
className: "markweave-math-editor-popover markweave-math-editor-popover--inline",
|
|
1804
|
+
"data-kind": "inline",
|
|
1805
|
+
"data-placement": c?.placement ?? "bottom",
|
|
1806
|
+
"data-testid": "markweave-math-editor-popover",
|
|
1807
|
+
onSubmit: (e) => {
|
|
1808
|
+
e.preventDefault(), _();
|
|
1809
|
+
},
|
|
1810
|
+
style: b,
|
|
1811
|
+
children: [/* @__PURE__ */ Q("label", {
|
|
1812
|
+
className: "markweave-math-inline-source",
|
|
1813
|
+
"data-testid": "markweave-math-inline-source",
|
|
1814
|
+
children: [
|
|
1815
|
+
/* @__PURE__ */ Z("span", {
|
|
1816
|
+
"aria-hidden": "true",
|
|
1817
|
+
children: "$"
|
|
1818
|
+
}),
|
|
1819
|
+
/* @__PURE__ */ Z("input", {
|
|
1820
|
+
ref: a,
|
|
1821
|
+
"aria-label": u.latexLabel,
|
|
1822
|
+
"data-testid": "markweave-math-editor-input",
|
|
1823
|
+
onChange: (e) => s(e.currentTarget.value),
|
|
1824
|
+
onKeyDown: y,
|
|
1825
|
+
placeholder: u.latexPlaceholder,
|
|
1826
|
+
size: Math.max(o.length, 1),
|
|
1827
|
+
spellCheck: !1,
|
|
1828
|
+
value: o
|
|
1829
|
+
}),
|
|
1830
|
+
/* @__PURE__ */ Z("span", {
|
|
1831
|
+
"aria-hidden": "true",
|
|
1832
|
+
children: "$"
|
|
1833
|
+
})
|
|
1834
|
+
]
|
|
1835
|
+
}), /* @__PURE__ */ Q("div", {
|
|
1836
|
+
className: "markweave-math-inline-preview",
|
|
1837
|
+
"data-error": m.error ? "true" : "false",
|
|
1838
|
+
"data-testid": "markweave-math-editor-preview",
|
|
1839
|
+
children: [/* @__PURE__ */ Z("div", { dangerouslySetInnerHTML: { __html: m.html || " " } }), m.error ? /* @__PURE__ */ Z("small", { children: u.invalidPreview }) : null]
|
|
1840
|
+
})]
|
|
1841
|
+
}) : /* @__PURE__ */ Q("form", {
|
|
1842
|
+
ref: i,
|
|
1843
|
+
"aria-label": x,
|
|
1844
|
+
className: "markweave-math-editor-popover markweave-math-editor-popover--block",
|
|
1845
|
+
"data-kind": r.kind,
|
|
1846
|
+
"data-placement": c?.placement ?? "bottom",
|
|
1847
|
+
"data-testid": "markweave-math-editor-popover",
|
|
1848
|
+
onSubmit: (e) => {
|
|
1849
|
+
e.preventDefault(), _();
|
|
1850
|
+
},
|
|
1851
|
+
style: b,
|
|
1852
|
+
children: [
|
|
1853
|
+
/* @__PURE__ */ Q("div", {
|
|
1854
|
+
className: "markweave-math-block-toolbar",
|
|
1855
|
+
children: [
|
|
1856
|
+
/* @__PURE__ */ Z("span", { children: u.label }),
|
|
1857
|
+
/* @__PURE__ */ Z(v, {
|
|
1858
|
+
"aria-hidden": "true",
|
|
1859
|
+
size: 15,
|
|
1860
|
+
strokeWidth: 1.75
|
|
1861
|
+
}),
|
|
1862
|
+
/* @__PURE__ */ Z("button", {
|
|
1863
|
+
"aria-label": u.apply,
|
|
1864
|
+
"data-testid": "markweave-math-editor-apply",
|
|
1865
|
+
disabled: !h,
|
|
1866
|
+
title: u.apply,
|
|
1867
|
+
type: "submit",
|
|
1868
|
+
children: /* @__PURE__ */ Z(p, {
|
|
1869
|
+
"aria-hidden": "true",
|
|
1870
|
+
size: 16,
|
|
1871
|
+
strokeWidth: 2
|
|
1872
|
+
})
|
|
1873
|
+
})
|
|
1874
|
+
]
|
|
1875
|
+
}),
|
|
1876
|
+
/* @__PURE__ */ Q("label", {
|
|
1877
|
+
className: "markweave-math-block-source",
|
|
1878
|
+
"data-testid": "markweave-math-block-source",
|
|
1879
|
+
children: [
|
|
1880
|
+
/* @__PURE__ */ Z("span", {
|
|
1881
|
+
"aria-hidden": "true",
|
|
1882
|
+
children: "$$"
|
|
1883
|
+
}),
|
|
1884
|
+
/* @__PURE__ */ Z("textarea", {
|
|
1885
|
+
ref: a,
|
|
1886
|
+
"aria-label": u.latexLabel,
|
|
1887
|
+
"data-testid": "markweave-math-editor-input",
|
|
1888
|
+
onChange: (e) => s(e.currentTarget.value),
|
|
1889
|
+
onKeyDown: y,
|
|
1890
|
+
placeholder: u.latexPlaceholder,
|
|
1891
|
+
rows: 3,
|
|
1892
|
+
spellCheck: !1,
|
|
1893
|
+
value: o
|
|
1894
|
+
}),
|
|
1895
|
+
/* @__PURE__ */ Z("span", {
|
|
1896
|
+
"aria-hidden": "true",
|
|
1897
|
+
children: "$$"
|
|
1898
|
+
})
|
|
1899
|
+
]
|
|
1900
|
+
}),
|
|
1901
|
+
/* @__PURE__ */ Q("div", {
|
|
1902
|
+
className: "markweave-math-block-preview",
|
|
1903
|
+
"data-error": m.error ? "true" : "false",
|
|
1904
|
+
"data-math-number": String(d),
|
|
1905
|
+
"data-testid": "markweave-math-editor-preview",
|
|
1906
|
+
children: [/* @__PURE__ */ Z("div", { dangerouslySetInnerHTML: { __html: m.html || " " } }), m.error ? /* @__PURE__ */ Z("small", { children: u.invalidPreview }) : null]
|
|
1907
|
+
})
|
|
1908
|
+
]
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
//#endregion
|
|
1912
|
+
//#region src/ui/slash-command/SlashCommandMenu.tsx
|
|
1913
|
+
var Xr = ke("zh"), Zr = {
|
|
1914
|
+
type: z,
|
|
1915
|
+
"heading-1": S,
|
|
1916
|
+
"heading-2": C,
|
|
1917
|
+
"heading-3": w,
|
|
1918
|
+
"bullet-list": M,
|
|
1919
|
+
"ordered-list": P,
|
|
1920
|
+
"task-list": N,
|
|
1921
|
+
blockquote: I,
|
|
1922
|
+
"code-block": d,
|
|
1923
|
+
info: k,
|
|
1924
|
+
tip: j,
|
|
1925
|
+
warning: a,
|
|
1926
|
+
error: _,
|
|
1927
|
+
success: m,
|
|
1928
|
+
emoji: R,
|
|
1929
|
+
math: L,
|
|
1930
|
+
table: ce,
|
|
1931
|
+
separator: te,
|
|
1932
|
+
image: T,
|
|
1933
|
+
video: fe,
|
|
1934
|
+
attachment: F
|
|
1935
|
+
};
|
|
1936
|
+
function Qr({ name: e }) {
|
|
1937
|
+
let t = Zr[e];
|
|
1938
|
+
return /* @__PURE__ */ Z(t, {
|
|
1939
|
+
"aria-hidden": "true",
|
|
1940
|
+
absoluteStrokeWidth: !0,
|
|
1941
|
+
size: 18,
|
|
1942
|
+
strokeWidth: 1.6
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
function $r(e, t, n) {
|
|
1946
|
+
return !Tt(e) || !n ? {
|
|
1947
|
+
visible: !1,
|
|
1948
|
+
empty: !1,
|
|
1949
|
+
activeIndex: -1
|
|
1950
|
+
} : t.length === 0 ? {
|
|
1951
|
+
visible: !0,
|
|
1952
|
+
empty: !0,
|
|
1953
|
+
activeIndex: -1
|
|
1954
|
+
} : {
|
|
1955
|
+
visible: !0,
|
|
1956
|
+
empty: !1,
|
|
1957
|
+
activeIndex: Math.min(t.length - 1, Math.max(0, e.activeIndex))
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
function ei(e, t) {
|
|
1961
|
+
return Object.values(t.slash.groups).map((t) => ({
|
|
1962
|
+
group: t,
|
|
1963
|
+
commands: e.filter((e) => e.group === t)
|
|
1964
|
+
})).filter((e) => e.commands.length > 0);
|
|
1965
|
+
}
|
|
1966
|
+
function ti(e, t) {
|
|
1967
|
+
return t.slash.uploadKindLabels[e] ?? t.slash.uploadKindLabels.upload;
|
|
1968
|
+
}
|
|
1969
|
+
function ni({ command: e, messages: t, onBack: n, onSelect: r }) {
|
|
1970
|
+
let [i, a] = K(""), [o, s] = K(0), c = W(() => {
|
|
1971
|
+
let e = i.trim().toLowerCase();
|
|
1972
|
+
return (e ? t.slash.emojiItems.filter((t) => [
|
|
1973
|
+
t.emoji,
|
|
1974
|
+
t.label,
|
|
1975
|
+
...t.terms
|
|
1976
|
+
].join(" ").toLowerCase().includes(e)) : t.slash.emojiItems).slice(0, 12);
|
|
1977
|
+
}, [t.slash.emojiItems, i]), l = (t) => {
|
|
1978
|
+
let n = c[Math.min(c.length - 1, Math.max(0, t))];
|
|
1979
|
+
n && r(e, { emoji: n.emoji });
|
|
1980
|
+
};
|
|
1981
|
+
return /* @__PURE__ */ Q("div", {
|
|
1982
|
+
className: "markweave-slash-subpanel",
|
|
1983
|
+
"data-testid": "markweave-slash-emoji-picker",
|
|
1984
|
+
children: [
|
|
1985
|
+
/* @__PURE__ */ Q("div", {
|
|
1986
|
+
className: "markweave-slash-subpanel-header",
|
|
1987
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
1988
|
+
type: "button",
|
|
1989
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1990
|
+
onClick: n,
|
|
1991
|
+
children: t.common.back
|
|
1992
|
+
}), /* @__PURE__ */ Z("span", { children: t.slash.emojiTitle })]
|
|
1993
|
+
}),
|
|
1994
|
+
/* @__PURE__ */ Q("label", {
|
|
1995
|
+
className: "markweave-slash-input",
|
|
1996
|
+
children: [/* @__PURE__ */ Z("span", { children: "/" }), /* @__PURE__ */ Z("input", {
|
|
1997
|
+
autoFocus: !0,
|
|
1998
|
+
value: i,
|
|
1999
|
+
placeholder: t.slash.emojiSearchPlaceholder,
|
|
2000
|
+
onChange: (e) => a(e.currentTarget.value),
|
|
2001
|
+
onKeyDown: (e) => {
|
|
2002
|
+
if (e.key === "Escape") {
|
|
2003
|
+
e.preventDefault(), n();
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
if (e.key === "ArrowDown") {
|
|
2007
|
+
e.preventDefault(), s((e) => c.length ? (e + 1) % c.length : 0);
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
if (e.key === "ArrowUp") {
|
|
2011
|
+
e.preventDefault(), s((e) => c.length ? (e - 1 + c.length) % c.length : 0);
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
(e.key === "Enter" || e.key === "Tab") && (e.preventDefault(), l(o));
|
|
2015
|
+
}
|
|
2016
|
+
})]
|
|
2017
|
+
}),
|
|
2018
|
+
/* @__PURE__ */ Z("div", {
|
|
2019
|
+
className: "markweave-slash-emoji-grid",
|
|
2020
|
+
role: "listbox",
|
|
2021
|
+
"aria-label": t.slash.emojiTitle,
|
|
2022
|
+
children: c.map((e, t) => /* @__PURE__ */ Q("button", {
|
|
2023
|
+
type: "button",
|
|
2024
|
+
role: "option",
|
|
2025
|
+
"aria-selected": t === o,
|
|
2026
|
+
"data-active": t === o,
|
|
2027
|
+
onMouseEnter: () => s(t),
|
|
2028
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2029
|
+
onClick: () => l(t),
|
|
2030
|
+
children: [/* @__PURE__ */ Z("span", { children: e.emoji }), /* @__PURE__ */ Z("small", { children: e.label })]
|
|
2031
|
+
}, `${e.emoji}-${e.label}`))
|
|
2032
|
+
})
|
|
2033
|
+
]
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
function ri({ command: e, messages: t, onBack: n, onSelect: r, onUpload: i }) {
|
|
2037
|
+
let a = e.uploadKind ?? "attachment", [o, s] = K(""), [c, l] = K(null), [u, d] = K(null), [f, p] = K(!1), m = async (t) => {
|
|
2038
|
+
r(e, { uploadResult: await q({
|
|
2039
|
+
kind: a,
|
|
2040
|
+
source: t,
|
|
2041
|
+
trigger: "slash-command"
|
|
2042
|
+
}, i) });
|
|
2043
|
+
}, h = async () => {
|
|
2044
|
+
d(null), p(!0);
|
|
2045
|
+
try {
|
|
2046
|
+
if (c) {
|
|
2047
|
+
await m({
|
|
2048
|
+
type: "file",
|
|
2049
|
+
file: c,
|
|
2050
|
+
mimeType: c.type
|
|
2051
|
+
});
|
|
2052
|
+
return;
|
|
2053
|
+
}
|
|
2054
|
+
if (!o.trim()) {
|
|
2055
|
+
d(t.slash.uploadRequiredError);
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
await m(me(o));
|
|
2059
|
+
} catch (e) {
|
|
2060
|
+
d(e instanceof Error ? e.message : t.slash.uploadFailedError);
|
|
2061
|
+
} finally {
|
|
2062
|
+
p(!1);
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
return /* @__PURE__ */ Q("div", {
|
|
2066
|
+
className: "markweave-slash-subpanel",
|
|
2067
|
+
"data-testid": "markweave-slash-upload-panel",
|
|
2068
|
+
children: [
|
|
2069
|
+
/* @__PURE__ */ Q("div", {
|
|
2070
|
+
className: "markweave-slash-subpanel-header",
|
|
2071
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
2072
|
+
type: "button",
|
|
2073
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2074
|
+
onClick: n,
|
|
2075
|
+
children: t.common.back
|
|
2076
|
+
}), /* @__PURE__ */ Z("span", { children: ti(a, t) })]
|
|
2077
|
+
}),
|
|
2078
|
+
/* @__PURE__ */ Q("label", {
|
|
2079
|
+
className: "markweave-slash-upload-field",
|
|
2080
|
+
children: [/* @__PURE__ */ Z("span", { children: t.slash.uploadValueLabel }), /* @__PURE__ */ Z("input", {
|
|
2081
|
+
autoFocus: !0,
|
|
2082
|
+
value: o,
|
|
2083
|
+
placeholder: t.slash.uploadValuePlaceholder,
|
|
2084
|
+
onChange: (e) => s(e.currentTarget.value),
|
|
2085
|
+
onKeyDown: (e) => {
|
|
2086
|
+
if (e.key === "Escape") {
|
|
2087
|
+
e.preventDefault(), n();
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
e.key === "Enter" && (e.preventDefault(), h());
|
|
2091
|
+
}
|
|
2092
|
+
})]
|
|
2093
|
+
}),
|
|
2094
|
+
/* @__PURE__ */ Q("label", {
|
|
2095
|
+
className: "markweave-slash-upload-field",
|
|
2096
|
+
children: [/* @__PURE__ */ Z("span", { children: t.common.file }), /* @__PURE__ */ Z("input", {
|
|
2097
|
+
type: "file",
|
|
2098
|
+
onChange: (e) => l(e.currentTarget.files?.[0] ?? null)
|
|
2099
|
+
})]
|
|
2100
|
+
}),
|
|
2101
|
+
u ? /* @__PURE__ */ Z("div", {
|
|
2102
|
+
className: "markweave-slash-upload-error",
|
|
2103
|
+
children: u
|
|
2104
|
+
}) : null,
|
|
2105
|
+
/* @__PURE__ */ Q("div", {
|
|
2106
|
+
className: "markweave-slash-upload-actions",
|
|
2107
|
+
children: [/* @__PURE__ */ Z("button", {
|
|
2108
|
+
type: "button",
|
|
2109
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2110
|
+
onClick: n,
|
|
2111
|
+
children: t.common.cancel
|
|
2112
|
+
}), /* @__PURE__ */ Z("button", {
|
|
2113
|
+
type: "button",
|
|
2114
|
+
"data-primary": "true",
|
|
2115
|
+
disabled: f,
|
|
2116
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2117
|
+
onClick: () => void h(),
|
|
2118
|
+
children: t.common.insert
|
|
2119
|
+
})]
|
|
2120
|
+
})
|
|
2121
|
+
]
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
function ii({ commands: e, messages: t = Xr, state: n, position: r, inputCommand: i, onActiveIndexChange: a, onInputCommandChange: o, onSelect: s, onUpload: c }) {
|
|
2125
|
+
let l = $r(n, e, r);
|
|
2126
|
+
if (!l.visible || !r) return null;
|
|
2127
|
+
let u = ei(e, t), d = {
|
|
2128
|
+
left: r.left,
|
|
2129
|
+
top: r.top,
|
|
2130
|
+
maxHeight: r.maxHeight,
|
|
2131
|
+
"--markweave-slash-menu-max-height": `${r.maxHeight}px`
|
|
2132
|
+
}, f = {
|
|
2133
|
+
left: r.triggerLeft,
|
|
2134
|
+
top: r.triggerTop
|
|
2135
|
+
}, p = (e) => o?.(e), m = () => o?.(null);
|
|
2136
|
+
return /* @__PURE__ */ Q(X, { children: [/* @__PURE__ */ Q("div", {
|
|
2137
|
+
className: "markweave-slash-trigger",
|
|
2138
|
+
style: f,
|
|
2139
|
+
"aria-hidden": "true",
|
|
2140
|
+
"data-testid": "markweave-slash-trigger",
|
|
2141
|
+
children: [/* @__PURE__ */ Z("span", { children: "/" }), /* @__PURE__ */ Z("em", { children: n.query ? n.query : t.slash.filterPlaceholder })]
|
|
2142
|
+
}), /* @__PURE__ */ Z("div", {
|
|
2143
|
+
className: "markweave-slash-menu",
|
|
2144
|
+
style: d,
|
|
2145
|
+
role: "listbox",
|
|
2146
|
+
"aria-label": t.slash.ariaLabel,
|
|
2147
|
+
"data-placement": r.placement,
|
|
2148
|
+
"data-testid": "markweave-slash-menu",
|
|
2149
|
+
children: i?.inputKind === "emoji" ? /* @__PURE__ */ Z(ni, {
|
|
2150
|
+
command: i,
|
|
2151
|
+
messages: t,
|
|
2152
|
+
onBack: m,
|
|
2153
|
+
onSelect: s
|
|
2154
|
+
}) : i?.inputKind === "upload" ? /* @__PURE__ */ Z(ri, {
|
|
2155
|
+
command: i,
|
|
2156
|
+
messages: t,
|
|
2157
|
+
onBack: m,
|
|
2158
|
+
onSelect: s,
|
|
2159
|
+
onUpload: c
|
|
2160
|
+
}) : l.empty ? /* @__PURE__ */ Z("div", {
|
|
2161
|
+
className: "markweave-slash-menu__empty",
|
|
2162
|
+
role: "option",
|
|
2163
|
+
"aria-disabled": "true",
|
|
2164
|
+
children: t.slash.noResults
|
|
2165
|
+
}) : /* @__PURE__ */ Z("div", {
|
|
2166
|
+
className: "markweave-slash-command-list",
|
|
2167
|
+
children: u.map((t) => /* @__PURE__ */ Q("section", {
|
|
2168
|
+
className: "markweave-slash-group",
|
|
2169
|
+
"aria-label": t.group,
|
|
2170
|
+
children: [/* @__PURE__ */ Z("div", {
|
|
2171
|
+
className: "markweave-slash-group-title",
|
|
2172
|
+
children: t.group
|
|
2173
|
+
}), t.commands.map((t) => {
|
|
2174
|
+
let n = e.indexOf(t), r = n === l.activeIndex, i = Ct(t), o = !!t.disabled;
|
|
2175
|
+
return /* @__PURE__ */ Q("button", {
|
|
2176
|
+
type: "button",
|
|
2177
|
+
role: "option",
|
|
2178
|
+
"aria-selected": r,
|
|
2179
|
+
"aria-disabled": !i || o,
|
|
2180
|
+
"data-active": r,
|
|
2181
|
+
"data-disabled": o ? "true" : "false",
|
|
2182
|
+
"data-execution-kind": t.executionKind,
|
|
2183
|
+
"data-testid": `markweave-slash-command-${t.id}`,
|
|
2184
|
+
title: o ? t.disabledReason : void 0,
|
|
2185
|
+
onFocus: () => a?.(n),
|
|
2186
|
+
onMouseEnter: () => a?.(n),
|
|
2187
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2188
|
+
onClick: () => {
|
|
2189
|
+
if (!(!i || o)) {
|
|
2190
|
+
if (t.inputKind) {
|
|
2191
|
+
p(t);
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
s(t);
|
|
2195
|
+
}
|
|
2196
|
+
},
|
|
2197
|
+
children: [
|
|
2198
|
+
/* @__PURE__ */ Z(Qr, { name: t.icon }),
|
|
2199
|
+
/* @__PURE__ */ Z("span", { children: t.label }),
|
|
2200
|
+
o && t.disabledReason ? /* @__PURE__ */ Z("small", { children: t.disabledReason }) : null
|
|
2201
|
+
]
|
|
2202
|
+
}, t.id);
|
|
2203
|
+
})]
|
|
2204
|
+
}, t.group))
|
|
2205
|
+
})
|
|
2206
|
+
})] });
|
|
2207
|
+
}
|
|
2208
|
+
//#endregion
|
|
2209
|
+
//#region src/ui/table/TableControls.tsx
|
|
2210
|
+
var ai = ke("zh");
|
|
2211
|
+
function oi({ active: e, editor: t, interactionState: n = It, messages: r = ai, onCopyPayload: i, onCommandResult: a, onEditWithAi: o }) {
|
|
2212
|
+
let [s, c] = K(null), [l, u] = K("row-edge"), [d, f] = K(null), [p, m] = K(null), [h, g] = K(null), [_, v] = K(null), [y, b] = K(null), x = G(null), S = G(null), C = G(null), w = G(null), T = G(null), E = e ? Pt(t.state) : null;
|
|
2213
|
+
if (H(() => {
|
|
2214
|
+
if (!y) return;
|
|
2215
|
+
let e = window.setTimeout(() => {
|
|
2216
|
+
b(null);
|
|
2217
|
+
}, Gn);
|
|
2218
|
+
return () => {
|
|
2219
|
+
window.clearTimeout(e);
|
|
2220
|
+
};
|
|
2221
|
+
}, [y]), U(() => {
|
|
2222
|
+
if (!e) {
|
|
2223
|
+
m(null), g(null), v(null), b(null);
|
|
2224
|
+
return;
|
|
2225
|
+
}
|
|
2226
|
+
let r = () => {
|
|
2227
|
+
let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, r = Ln(t, n, "row", E?.activeCellPos ?? null), i = Ln(t, n, "column", E?.activeCellPos ?? null), a = r ? In(t, r) : null, o = i ? In(t, i) : null, c = Fn(t).length > 0 ? Hn(t) : null;
|
|
2228
|
+
if (!e) {
|
|
2229
|
+
m(null), g(null), v(null);
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
let u = e.getBoundingClientRect();
|
|
2233
|
+
a ? m(An({
|
|
2234
|
+
targetRect: a,
|
|
2235
|
+
frameRect: u,
|
|
2236
|
+
kind: "row"
|
|
2237
|
+
})) : s === "row" && l === "row-edge" || m(null), o ? g(An({
|
|
2238
|
+
targetRect: o,
|
|
2239
|
+
frameRect: u,
|
|
2240
|
+
kind: "column"
|
|
2241
|
+
})) : s === "column" && l === "column-edge" || g(null), c ? v(An({
|
|
2242
|
+
targetRect: c,
|
|
2243
|
+
frameRect: u,
|
|
2244
|
+
kind: "selection"
|
|
2245
|
+
})) : s === "selection" && l === "selection-edge" || v(null);
|
|
2246
|
+
};
|
|
2247
|
+
return r(), window.addEventListener("resize", r), window.addEventListener("scroll", r, !0), () => {
|
|
2248
|
+
window.removeEventListener("resize", r), window.removeEventListener("scroll", r, !0);
|
|
2249
|
+
};
|
|
2250
|
+
}, [
|
|
2251
|
+
e,
|
|
2252
|
+
t,
|
|
2253
|
+
E?.activeCellPos,
|
|
2254
|
+
E?.selectionFrom,
|
|
2255
|
+
E?.selectionTo,
|
|
2256
|
+
n.hoverCellPos,
|
|
2257
|
+
n.hoverVisualColumnIndex,
|
|
2258
|
+
n.hoverVisualRowIndex,
|
|
2259
|
+
l,
|
|
2260
|
+
s
|
|
2261
|
+
]), U(() => {
|
|
2262
|
+
if (!e || !s) {
|
|
2263
|
+
f(null);
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
let n = () => {
|
|
2267
|
+
let e = t.view.dom.closest(".markweave-editor-frame") ?? t.view.dom.parentElement, n = l === "row-edge" ? C.current : l === "column-edge" ? w.current : T.current, r = S.current;
|
|
2268
|
+
if (!e || !n || !r) {
|
|
2269
|
+
f(null);
|
|
2270
|
+
return;
|
|
2271
|
+
}
|
|
2272
|
+
let i = n.getBoundingClientRect(), a = s === "row" ? Pn(t)?.getBoundingClientRect() : null, o = a ? {
|
|
2273
|
+
left: i.left,
|
|
2274
|
+
top: a.top,
|
|
2275
|
+
width: i.width,
|
|
2276
|
+
height: i.height
|
|
2277
|
+
} : i, c = e.getBoundingClientRect(), u = r.getBoundingClientRect(), d = kn({
|
|
2278
|
+
anchorRect: o,
|
|
2279
|
+
frameRect: c,
|
|
2280
|
+
menuSize: {
|
|
2281
|
+
width: u.width || 204,
|
|
2282
|
+
height: u.height || 220
|
|
2283
|
+
},
|
|
2284
|
+
kind: s
|
|
2285
|
+
});
|
|
2286
|
+
f(d);
|
|
2287
|
+
};
|
|
2288
|
+
return n(), window.addEventListener("resize", n), window.addEventListener("scroll", n, !0), () => {
|
|
2289
|
+
window.removeEventListener("resize", n), window.removeEventListener("scroll", n, !0);
|
|
2290
|
+
};
|
|
2291
|
+
}, [
|
|
2292
|
+
e,
|
|
2293
|
+
t,
|
|
2294
|
+
l,
|
|
2295
|
+
s,
|
|
2296
|
+
p,
|
|
2297
|
+
h,
|
|
2298
|
+
_
|
|
2299
|
+
]), H(() => {
|
|
2300
|
+
if (!e || !s) return;
|
|
2301
|
+
let n = (e) => {
|
|
2302
|
+
e.key === "Escape" && (c(null), t.view.focus());
|
|
2303
|
+
}, r = (e) => {
|
|
2304
|
+
e.target instanceof Node && x.current?.contains(e.target) || c(null);
|
|
2305
|
+
};
|
|
2306
|
+
return document.addEventListener("keydown", n), document.addEventListener("mousedown", r), () => {
|
|
2307
|
+
document.removeEventListener("keydown", n), document.removeEventListener("mousedown", r);
|
|
2308
|
+
};
|
|
2309
|
+
}, [
|
|
2310
|
+
e,
|
|
2311
|
+
t,
|
|
2312
|
+
s
|
|
2313
|
+
]), !e) return null;
|
|
2314
|
+
let D = (e, t) => {
|
|
2315
|
+
let n = s === e && l === t;
|
|
2316
|
+
u(t), c(n ? null : e);
|
|
2317
|
+
}, O = () => {
|
|
2318
|
+
t.view.dispatch(On(t.state.tr, null));
|
|
2319
|
+
}, k = (e, r) => {
|
|
2320
|
+
let i = n.hoverCellPos ?? E?.activeCellPos ?? null, a = n.hoverCellPos === null ? null : e === "row" ? n.hoverVisualRowIndex : n.hoverVisualColumnIndex;
|
|
2321
|
+
i !== null && Wn(t, i, e, { visualIndex: a }), D(e, r);
|
|
2322
|
+
}, A = () => {
|
|
2323
|
+
O(), D("selection", "selection-edge");
|
|
2324
|
+
}, j = Ln(t, n, "row", E?.activeCellPos ?? null), ee = Ln(t, n, "column", E?.activeCellPos ?? null), M = Fn(t).length > 0, N = s ? Vn(t, s) : [], P = async (e, n) => {
|
|
2325
|
+
let o = await Mn({
|
|
2326
|
+
editor: t,
|
|
2327
|
+
commandId: e,
|
|
2328
|
+
menu: n ?? s ?? "selection",
|
|
2329
|
+
messages: r
|
|
2330
|
+
});
|
|
2331
|
+
return o.copyFeedback ? (b(o.copyFeedback), o.copyPayload && i?.(o.copyPayload)) : b(null), a?.(o.commandResult), o.success;
|
|
2332
|
+
}, te = (e) => {
|
|
2333
|
+
let n = Rn(t, e);
|
|
2334
|
+
n && o?.(n), c(null), t.view.focus();
|
|
2335
|
+
};
|
|
2336
|
+
return /* @__PURE__ */ Q("div", {
|
|
2337
|
+
ref: x,
|
|
2338
|
+
className: "markweave-table-controls",
|
|
2339
|
+
"data-testid": "markweave-table-controls",
|
|
2340
|
+
"aria-label": r.table.controlsAriaLabel,
|
|
2341
|
+
"data-open-menu": s ?? "none",
|
|
2342
|
+
"data-positioned": p || h || _ ? "true" : "false",
|
|
2343
|
+
children: [
|
|
2344
|
+
y ? /* @__PURE__ */ Z("div", {
|
|
2345
|
+
className: "markweave-table-copy-feedback",
|
|
2346
|
+
role: "status",
|
|
2347
|
+
"aria-live": "polite",
|
|
2348
|
+
"data-testid": "markweave-table-copy-feedback",
|
|
2349
|
+
"data-copy-kind": y.kind,
|
|
2350
|
+
"data-text-length": y.textLength,
|
|
2351
|
+
"data-html-length": y.htmlLength,
|
|
2352
|
+
children: Nn(y)
|
|
2353
|
+
}) : null,
|
|
2354
|
+
p ? /* @__PURE__ */ Z("button", {
|
|
2355
|
+
type: "button",
|
|
2356
|
+
ref: C,
|
|
2357
|
+
className: "markweave-table-edge-handle markweave-table-edge-handle--row",
|
|
2358
|
+
"aria-label": r.table.activeRowActions,
|
|
2359
|
+
"aria-expanded": s === "row" && l === "row-edge",
|
|
2360
|
+
"aria-haspopup": "menu",
|
|
2361
|
+
title: r.table.rowActions,
|
|
2362
|
+
"data-testid": "markweave-table-hover-row-handle",
|
|
2363
|
+
"data-axis-index": j?.index ?? "",
|
|
2364
|
+
"data-axis-selected-cells": j?.selectedCellCount ?? "",
|
|
2365
|
+
"data-axis-visual-cells": j?.visualCellCount ?? "",
|
|
2366
|
+
"data-axis-visual-size": j?.visualHeight ?? "",
|
|
2367
|
+
style: {
|
|
2368
|
+
left: p.left,
|
|
2369
|
+
top: p.top
|
|
2370
|
+
},
|
|
2371
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2372
|
+
onClick: () => {
|
|
2373
|
+
k("row", "row-edge");
|
|
2374
|
+
},
|
|
2375
|
+
children: /* @__PURE__ */ Z("span", {
|
|
2376
|
+
"aria-hidden": "true",
|
|
2377
|
+
children: "..."
|
|
2378
|
+
})
|
|
2379
|
+
}) : null,
|
|
2380
|
+
h ? /* @__PURE__ */ Z("button", {
|
|
2381
|
+
type: "button",
|
|
2382
|
+
ref: w,
|
|
2383
|
+
className: "markweave-table-edge-handle markweave-table-edge-handle--column",
|
|
2384
|
+
"aria-label": r.table.activeColumnActions,
|
|
2385
|
+
"aria-expanded": s === "column" && l === "column-edge",
|
|
2386
|
+
"aria-haspopup": "menu",
|
|
2387
|
+
title: r.table.columnActions,
|
|
2388
|
+
"data-testid": "markweave-table-hover-column-handle",
|
|
2389
|
+
"data-axis-index": ee?.index ?? "",
|
|
2390
|
+
"data-axis-selected-cells": ee?.selectedCellCount ?? "",
|
|
2391
|
+
"data-axis-visual-cells": ee?.visualCellCount ?? "",
|
|
2392
|
+
"data-axis-visual-size": ee?.visualWidth ?? "",
|
|
2393
|
+
style: {
|
|
2394
|
+
left: h.left,
|
|
2395
|
+
top: h.top
|
|
2396
|
+
},
|
|
2397
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2398
|
+
onClick: () => {
|
|
2399
|
+
k("column", "column-edge");
|
|
2400
|
+
},
|
|
2401
|
+
children: /* @__PURE__ */ Z("span", {
|
|
2402
|
+
"aria-hidden": "true",
|
|
2403
|
+
children: "..."
|
|
2404
|
+
})
|
|
2405
|
+
}) : null,
|
|
2406
|
+
M && _ ? /* @__PURE__ */ Z("button", {
|
|
2407
|
+
type: "button",
|
|
2408
|
+
ref: T,
|
|
2409
|
+
className: "markweave-table-edge-handle markweave-table-edge-handle--selection",
|
|
2410
|
+
"aria-label": r.table.selectionActions,
|
|
2411
|
+
"aria-expanded": s === "selection" && l === "selection-edge",
|
|
2412
|
+
"aria-haspopup": "menu",
|
|
2413
|
+
title: r.table.selectionActions,
|
|
2414
|
+
"data-testid": "markweave-table-cell-handle",
|
|
2415
|
+
style: {
|
|
2416
|
+
left: _.left,
|
|
2417
|
+
top: _.top
|
|
2418
|
+
},
|
|
2419
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2420
|
+
onClick: A,
|
|
2421
|
+
children: /* @__PURE__ */ Z("span", {
|
|
2422
|
+
"aria-hidden": "true",
|
|
2423
|
+
children: "..."
|
|
2424
|
+
})
|
|
2425
|
+
}) : null,
|
|
2426
|
+
s ? /* @__PURE__ */ Z("div", {
|
|
2427
|
+
ref: S,
|
|
2428
|
+
className: "markweave-table-menu",
|
|
2429
|
+
role: "menu",
|
|
2430
|
+
"aria-label": Kn(s, r),
|
|
2431
|
+
"data-testid": "markweave-table-menu",
|
|
2432
|
+
"data-positioned": d ? "true" : "false",
|
|
2433
|
+
style: d ? {
|
|
2434
|
+
left: d.left,
|
|
2435
|
+
top: d.top
|
|
2436
|
+
} : void 0,
|
|
2437
|
+
children: N.map((e, n) => {
|
|
2438
|
+
let i = zn(e), a = n === 0 ? i : zn(N[n - 1]), l = n > 0 && a !== i, u = e.commandId === null ? !!o : jn(t, e.commandId), d = Bn(e, r);
|
|
2439
|
+
return /* @__PURE__ */ Z("button", {
|
|
2440
|
+
type: "button",
|
|
2441
|
+
role: "menuitem",
|
|
2442
|
+
"aria-label": d,
|
|
2443
|
+
"aria-disabled": !u,
|
|
2444
|
+
disabled: !u,
|
|
2445
|
+
"data-menu-group": i,
|
|
2446
|
+
"data-starts-group": l ? "true" : "false",
|
|
2447
|
+
"data-command-enabled": u ? "true" : "false",
|
|
2448
|
+
"data-testid": e.commandId ? `markweave-table-menu-command-${e.commandId}` : "markweave-table-menu-command-edit-with-ai",
|
|
2449
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2450
|
+
onClick: () => {
|
|
2451
|
+
if (u) {
|
|
2452
|
+
if (e.commandId === null) {
|
|
2453
|
+
te(s === "row" || s === "column" ? s : "selection");
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
P(e.commandId).finally(() => c(null));
|
|
2457
|
+
}
|
|
2458
|
+
},
|
|
2459
|
+
children: d
|
|
2460
|
+
}, `${e.id}-${n}`);
|
|
2461
|
+
})
|
|
2462
|
+
}) : null
|
|
2463
|
+
]
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
//#endregion
|
|
2467
|
+
//#region src/ui/table/TableSelectionOverlay.tsx
|
|
2468
|
+
function si({ editor: e, focusState: t }) {
|
|
2469
|
+
let [n, r] = K(null);
|
|
2470
|
+
return U(() => {
|
|
2471
|
+
if (t.mode !== "cell-selection") {
|
|
2472
|
+
r(null);
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
let n = () => {
|
|
2476
|
+
r(Un(e, Ft(e.state)));
|
|
2477
|
+
};
|
|
2478
|
+
return n(), window.addEventListener("resize", n), window.addEventListener("scroll", n, !0), () => {
|
|
2479
|
+
window.removeEventListener("resize", n), window.removeEventListener("scroll", n, !0);
|
|
2480
|
+
};
|
|
2481
|
+
}, [
|
|
2482
|
+
e,
|
|
2483
|
+
t.activeCellPos,
|
|
2484
|
+
t.anchorCellPos,
|
|
2485
|
+
t.mode,
|
|
2486
|
+
t.selectedCellCount,
|
|
2487
|
+
t.selectionFrom,
|
|
2488
|
+
t.selectionTo
|
|
2489
|
+
]), n ? /* @__PURE__ */ Z("div", {
|
|
2490
|
+
"aria-hidden": "true",
|
|
2491
|
+
className: "markweave-table-selection-overlay",
|
|
2492
|
+
"data-anchor-cell-pos": n.anchorCellPos ?? "",
|
|
2493
|
+
"data-head-cell-pos": n.headCellPos ?? "",
|
|
2494
|
+
"data-selected-cells": n.selectedCellCount,
|
|
2495
|
+
"data-visual-columns": n.visualColumnCount,
|
|
2496
|
+
"data-visual-rows": n.visualRowCount,
|
|
2497
|
+
"data-visual-slots": n.visualSlotCount,
|
|
2498
|
+
"data-testid": "markweave-table-selection-overlay",
|
|
2499
|
+
style: {
|
|
2500
|
+
"--markweave-table-selection-columns": n.visualColumnCount,
|
|
2501
|
+
"--markweave-table-selection-rows": n.visualRowCount,
|
|
2502
|
+
left: n.left,
|
|
2503
|
+
top: n.top,
|
|
2504
|
+
width: n.width,
|
|
2505
|
+
height: n.height
|
|
2506
|
+
}
|
|
2507
|
+
}) : null;
|
|
2508
|
+
}
|
|
2509
|
+
//#endregion
|
|
2510
|
+
//#region src/ui/toc/MarkweaveInnerToc.tsx
|
|
2511
|
+
function ci(e, t) {
|
|
2512
|
+
return `${e.toc.itemAriaLabel}: ${t.text}`;
|
|
2513
|
+
}
|
|
2514
|
+
function li({ editor: e, state: t, messages: n, editable: r }) {
|
|
2515
|
+
if (!t.items.length) return null;
|
|
2516
|
+
let i = (t) => {
|
|
2517
|
+
Qn(e, t, {
|
|
2518
|
+
behavior: "smooth",
|
|
2519
|
+
focus: r
|
|
2520
|
+
});
|
|
2521
|
+
};
|
|
2522
|
+
return /* @__PURE__ */ Q("nav", {
|
|
2523
|
+
className: "markweave-inner-toc",
|
|
2524
|
+
"data-testid": "markweave-inner-toc",
|
|
2525
|
+
"aria-label": n.toc.ariaLabel,
|
|
2526
|
+
children: [/* @__PURE__ */ Z("div", {
|
|
2527
|
+
className: "markweave-inner-toc-rail",
|
|
2528
|
+
"aria-hidden": "true",
|
|
2529
|
+
children: t.items.map((e) => /* @__PURE__ */ Z("span", {
|
|
2530
|
+
"data-level": e.level,
|
|
2531
|
+
"data-active": e.active ? "true" : "false"
|
|
2532
|
+
}, e.id))
|
|
2533
|
+
}), /* @__PURE__ */ Z("div", {
|
|
2534
|
+
className: "markweave-inner-toc-panel",
|
|
2535
|
+
children: /* @__PURE__ */ Z("div", {
|
|
2536
|
+
className: "markweave-inner-toc-list",
|
|
2537
|
+
children: t.items.map((e) => /* @__PURE__ */ Z("button", {
|
|
2538
|
+
type: "button",
|
|
2539
|
+
className: "markweave-inner-toc-item",
|
|
2540
|
+
"data-level": e.level,
|
|
2541
|
+
"data-active": e.active ? "true" : "false",
|
|
2542
|
+
"aria-current": e.active ? "location" : void 0,
|
|
2543
|
+
"aria-label": ci(n, e),
|
|
2544
|
+
title: e.text,
|
|
2545
|
+
onClick: () => i(e),
|
|
2546
|
+
children: e.text
|
|
2547
|
+
}, e.id))
|
|
2548
|
+
})
|
|
2549
|
+
})]
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
//#endregion
|
|
2553
|
+
//#region src/MarkweaveEditor.tsx
|
|
2554
|
+
var ui = {
|
|
2555
|
+
active: !1,
|
|
2556
|
+
mode: "outside",
|
|
2557
|
+
activeCellPos: null,
|
|
2558
|
+
anchorCellPos: null,
|
|
2559
|
+
selectedCellCount: 0,
|
|
2560
|
+
selectionFrom: 0,
|
|
2561
|
+
selectionTo: 0
|
|
2562
|
+
}, di = {
|
|
2563
|
+
active: !1,
|
|
2564
|
+
language: nt.defaultLanguage,
|
|
2565
|
+
mermaidPreviewMode: "code",
|
|
2566
|
+
pos: null,
|
|
2567
|
+
text: ""
|
|
2568
|
+
}, fi = lt({
|
|
2569
|
+
active: !1,
|
|
2570
|
+
mode: "code",
|
|
2571
|
+
source: ""
|
|
2572
|
+
});
|
|
2573
|
+
function pi(e) {
|
|
2574
|
+
return Lt.getState(e.state) ?? It;
|
|
2575
|
+
}
|
|
2576
|
+
function mi(e) {
|
|
2577
|
+
if (!e || typeof window > "u") return null;
|
|
2578
|
+
let t = e.parentElement;
|
|
2579
|
+
for (; t;) {
|
|
2580
|
+
let e = window.getComputedStyle(t), n = `${e.overflow} ${e.overflowY}`;
|
|
2581
|
+
if (/(auto|scroll|overlay)/.test(n) && t.scrollHeight > t.clientHeight) return t;
|
|
2582
|
+
t = t.parentElement;
|
|
2583
|
+
}
|
|
2584
|
+
return null;
|
|
2585
|
+
}
|
|
2586
|
+
function hi(e) {
|
|
2587
|
+
return typeof window > "u" || typeof window.requestAnimationFrame != "function" ? globalThis.setTimeout(() => e(0), 0) : window.requestAnimationFrame(e);
|
|
2588
|
+
}
|
|
2589
|
+
function gi(e) {
|
|
2590
|
+
if (typeof window < "u" && typeof window.cancelAnimationFrame == "function") {
|
|
2591
|
+
window.cancelAnimationFrame(e);
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
globalThis.clearTimeout(e);
|
|
2595
|
+
}
|
|
2596
|
+
function _i({ ariaLabel: e, autoFocusFirstTableBodyCell: t = !1, autofocus: n = !1, content: r, contentFormat: a, defaultContent: o = "", defaultContentFormat: s, editable: c = !0, innerToc: l = !0, lang: u, mode: d = "live", onEditWithAi: f, onExtractToNote: p, onRewriteSelection: m, onRuntimeStateChange: h, onSlashCommandUpload: g, onTableCommandResult: _, onTableCopyPayload: v, onTocChange: y, onUpdate: b } = {}) {
|
|
2597
|
+
let x = Ne(d), S = x === "live" && c !== !1, C = Ve(r === void 0 ? s : a), w = G({
|
|
2598
|
+
editorMode: x,
|
|
2599
|
+
effectiveEditable: S
|
|
2600
|
+
});
|
|
2601
|
+
w.current = {
|
|
2602
|
+
editorMode: x,
|
|
2603
|
+
effectiveEditable: S
|
|
2604
|
+
};
|
|
2605
|
+
let T = G(null);
|
|
2606
|
+
T.current === null && (T.current = Ae(u));
|
|
2607
|
+
let E = T.current, D = W(() => ke(E), [E]), O = W(() => Oe(E), [E]), k = G(g);
|
|
2608
|
+
k.current = g;
|
|
2609
|
+
let A = W(() => pr({
|
|
2610
|
+
lang: E,
|
|
2611
|
+
onImageUpload: (e) => {
|
|
2612
|
+
if (k.current) return k.current(e);
|
|
2613
|
+
let t = he(e);
|
|
2614
|
+
if (!t) throw Error("File upload requires an upload handler.");
|
|
2615
|
+
return t;
|
|
2616
|
+
},
|
|
2617
|
+
onVideoUpload: (e) => {
|
|
2618
|
+
if (k.current) return k.current(e);
|
|
2619
|
+
let t = he(e);
|
|
2620
|
+
if (!t) throw Error("File upload requires an upload handler.");
|
|
2621
|
+
return t;
|
|
2622
|
+
}
|
|
2623
|
+
}), [E]), [j, ee] = K(null), [M, N] = K(At), [P, te] = K(null), [ne, F] = K(null), [I, re] = K("code"), [L, R] = K(null), [ie, ae] = K(It), [oe, se] = K(null), [ce, z] = K(0), le = G(!1), ue = G({ onUpdate: b }), de = W(() => St(M.query, O), [O, M.query]);
|
|
2624
|
+
ue.current = { onUpdate: b };
|
|
2625
|
+
let B = V(() => {
|
|
2626
|
+
te(null), F(null), N(At);
|
|
2627
|
+
}, []), fe = V((e) => {
|
|
2628
|
+
let t = kt(e.state);
|
|
2629
|
+
if (!t) {
|
|
2630
|
+
N((e) => e.name === "idle" ? e : At), te(null), F(null);
|
|
2631
|
+
return;
|
|
2632
|
+
}
|
|
2633
|
+
let n = e.coordsAtPos(t.cursor), r = e.coordsAtPos(t.triggerFrom), i = e.dom.closest(".markweave-editor-frame")?.getBoundingClientRect();
|
|
2634
|
+
te(Ot(n, {
|
|
2635
|
+
frameRect: i,
|
|
2636
|
+
triggerRect: r
|
|
2637
|
+
})), N((e) => Dt(e, t));
|
|
2638
|
+
}, []), U = V((e) => fe(e.view), [fe]), pe = V((e) => {
|
|
2639
|
+
ee(qe(e));
|
|
2640
|
+
let t = _t(e);
|
|
2641
|
+
t && (yt(e, t, !0), R(t));
|
|
2642
|
+
let n = et(e);
|
|
2643
|
+
n.active && n.language === "mermaid" && re(n.mermaidPreviewMode);
|
|
2644
|
+
}, []), me = V((e) => {
|
|
2645
|
+
ae(pi(e));
|
|
2646
|
+
}, []), q = i({
|
|
2647
|
+
extensions: A,
|
|
2648
|
+
content: r ?? o,
|
|
2649
|
+
contentType: ze(C),
|
|
2650
|
+
editable: S,
|
|
2651
|
+
autofocus: n,
|
|
2652
|
+
editorProps: {
|
|
2653
|
+
attributes: {
|
|
2654
|
+
class: "markweave-editor-surface",
|
|
2655
|
+
"data-testid": "markweave-editor-surface",
|
|
2656
|
+
autocapitalize: "off",
|
|
2657
|
+
autocorrect: "off",
|
|
2658
|
+
spellcheck: "false",
|
|
2659
|
+
translate: "no"
|
|
2660
|
+
},
|
|
2661
|
+
handleClick: (e, t, n) => w.current.effectiveEditable ? !1 : He(n),
|
|
2662
|
+
handleDOMEvents: {
|
|
2663
|
+
compositionstart: () => w.current.effectiveEditable ? (N((e) => jt(e, { type: "composition-start" })), te(null), !1) : !1,
|
|
2664
|
+
compositionend: (e) => (w.current.effectiveEditable && window.setTimeout(() => fe(e), 0), !1),
|
|
2665
|
+
click: (e, t) => {
|
|
2666
|
+
if (w.current.effectiveEditable) {
|
|
2667
|
+
let n = gt(e, t);
|
|
2668
|
+
return n ? (t.preventDefault(), t.stopPropagation(), B(), bt(e, n, !0), xt(e, n), R(n), !0) : (R(null), !1);
|
|
2669
|
+
}
|
|
2670
|
+
return He(t);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
},
|
|
2674
|
+
onSelectionUpdate: ({ editor: e }) => {
|
|
2675
|
+
pe(e);
|
|
2676
|
+
},
|
|
2677
|
+
onCreate: ({ editor: e }) => {
|
|
2678
|
+
t && w.current.effectiveEditable && Nt(e), me(e), pe(e), z((e) => e + 1);
|
|
2679
|
+
},
|
|
2680
|
+
onTransaction: ({ editor: e, transaction: t }) => {
|
|
2681
|
+
me(e), (t.docChanged || ot(t)) && z((e) => e + 1), t.docChanged && R((t) => {
|
|
2682
|
+
if (!t) return null;
|
|
2683
|
+
let n = ht(e, t.pos);
|
|
2684
|
+
return n?.kind === t.kind ? n : null;
|
|
2685
|
+
});
|
|
2686
|
+
},
|
|
2687
|
+
onUpdate: ({ editor: e }) => {
|
|
2688
|
+
pe(e), w.current.effectiveEditable && U(e), le.current || ue.current.onUpdate?.(Re(e));
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
H(() => {
|
|
2692
|
+
q && (q.setEditable(S), Pe(q, {
|
|
2693
|
+
mode: x,
|
|
2694
|
+
editable: S
|
|
2695
|
+
}), st(q, S ? "live" : "view"), S || B());
|
|
2696
|
+
}, [
|
|
2697
|
+
B,
|
|
2698
|
+
q,
|
|
2699
|
+
x,
|
|
2700
|
+
S
|
|
2701
|
+
]), H(() => {
|
|
2702
|
+
!q || r === void 0 || Be(q, r, Ve(a)) || (le.current = !0, q.commands.setContent(r, {
|
|
2703
|
+
contentType: ze(Ve(a)),
|
|
2704
|
+
emitUpdate: !1
|
|
2705
|
+
}), le.current = !1, pe(q), S && U(q), me(q), z((e) => e + 1));
|
|
2706
|
+
}, [
|
|
2707
|
+
r,
|
|
2708
|
+
a,
|
|
2709
|
+
S,
|
|
2710
|
+
q,
|
|
2711
|
+
pe,
|
|
2712
|
+
U,
|
|
2713
|
+
me
|
|
2714
|
+
]), H(() => {
|
|
2715
|
+
if (!P) return;
|
|
2716
|
+
let e = (e) => {
|
|
2717
|
+
let t = e.target;
|
|
2718
|
+
t instanceof Element && (t.closest(".markweave-slash-menu") || t.closest(".markweave-slash-trigger") || B());
|
|
2719
|
+
};
|
|
2720
|
+
return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
|
|
2721
|
+
}, [B, P]);
|
|
2722
|
+
let ge = W(() => q ? et(q) : di, [
|
|
2723
|
+
q,
|
|
2724
|
+
ce,
|
|
2725
|
+
j
|
|
2726
|
+
]), _e = W(() => q ? Pt(q.state) : ui, [
|
|
2727
|
+
q,
|
|
2728
|
+
ce,
|
|
2729
|
+
j,
|
|
2730
|
+
ie
|
|
2731
|
+
]), ve = j?.currentNode === "codeBlock", ye = ve && ge.language === "mermaid", be = W(() => q ? lt({
|
|
2732
|
+
active: ye,
|
|
2733
|
+
mode: I,
|
|
2734
|
+
source: ge.text
|
|
2735
|
+
}) : fi, [
|
|
2736
|
+
ge.text,
|
|
2737
|
+
q,
|
|
2738
|
+
ye,
|
|
2739
|
+
I
|
|
2740
|
+
]), xe = W(() => q ? Mt(q.state) : null, [q, ce]), J = W(() => q ? Xn(q.state.doc) : Jn.items, [q, ce]), Se = W(() => Zn(J, oe), [oe, J]), Ce = W(() => qn(J, Se), [Se, J]), we = V(() => {
|
|
2741
|
+
if (!q || !J.length) {
|
|
2742
|
+
se(null);
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
let e = Yn(q, J);
|
|
2746
|
+
se((t) => t === e ? t : e);
|
|
2747
|
+
}, [q, J]);
|
|
2748
|
+
H(() => {
|
|
2749
|
+
se((e) => {
|
|
2750
|
+
let t = Zn(J, e);
|
|
2751
|
+
return e === t ? e : t;
|
|
2752
|
+
});
|
|
2753
|
+
}, [J]), H(() => {
|
|
2754
|
+
if (!q || !J.length || typeof window > "u") return;
|
|
2755
|
+
let e = null, t = () => {
|
|
2756
|
+
e !== null && gi(e), e = hi(() => {
|
|
2757
|
+
e = null, we();
|
|
2758
|
+
});
|
|
2759
|
+
}, n = mi(q.view.dom);
|
|
2760
|
+
return window.addEventListener("scroll", t, { passive: !0 }), window.addEventListener("resize", t), n?.addEventListener("scroll", t, { passive: !0 }), t(), () => {
|
|
2761
|
+
window.removeEventListener("scroll", t), window.removeEventListener("resize", t), n?.removeEventListener("scroll", t), e !== null && gi(e);
|
|
2762
|
+
};
|
|
2763
|
+
}, [
|
|
2764
|
+
q,
|
|
2765
|
+
J.length,
|
|
2766
|
+
we
|
|
2767
|
+
]);
|
|
2768
|
+
let Te = W(() => Ue({
|
|
2769
|
+
revision: ce,
|
|
2770
|
+
mode: x,
|
|
2771
|
+
editable: S,
|
|
2772
|
+
toc: Ce,
|
|
2773
|
+
selection: j,
|
|
2774
|
+
slash: M,
|
|
2775
|
+
table: _e,
|
|
2776
|
+
tableInteraction: ie,
|
|
2777
|
+
codeBlock: ge,
|
|
2778
|
+
mermaid: be,
|
|
2779
|
+
tableDebugSnapshot: xe
|
|
2780
|
+
}), [
|
|
2781
|
+
ge,
|
|
2782
|
+
x,
|
|
2783
|
+
S,
|
|
2784
|
+
be,
|
|
2785
|
+
ce,
|
|
2786
|
+
j,
|
|
2787
|
+
M,
|
|
2788
|
+
xe,
|
|
2789
|
+
_e,
|
|
2790
|
+
ie,
|
|
2791
|
+
Ce
|
|
2792
|
+
]);
|
|
2793
|
+
H(() => {
|
|
2794
|
+
h?.(Te);
|
|
2795
|
+
}, [h, Te]), H(() => {
|
|
2796
|
+
y?.(Ce);
|
|
2797
|
+
}, [y, Ce]);
|
|
2798
|
+
let Ee = V((e, t) => {
|
|
2799
|
+
if (!(!q || !S) && Ct(e)) {
|
|
2800
|
+
if (e.inputKind && !t?.emoji && !t?.uploadResult) {
|
|
2801
|
+
F(e);
|
|
2802
|
+
return;
|
|
2803
|
+
}
|
|
2804
|
+
Et(q, M, e, t), N((e) => jt(e, { type: "execute" })), B();
|
|
2805
|
+
}
|
|
2806
|
+
}, [
|
|
2807
|
+
B,
|
|
2808
|
+
S,
|
|
2809
|
+
q,
|
|
2810
|
+
M
|
|
2811
|
+
]), De = V((e) => {
|
|
2812
|
+
N((t) => jt(t, {
|
|
2813
|
+
type: "set-active",
|
|
2814
|
+
index: e,
|
|
2815
|
+
optionCount: de.length
|
|
2816
|
+
}));
|
|
2817
|
+
}, [de.length]), Y = V((e) => {
|
|
2818
|
+
if (!q || ne || !S) return;
|
|
2819
|
+
let t = wt(M, de, e.key, { isComposing: e.nativeEvent.isComposing || Le(q.state) });
|
|
2820
|
+
if (t.type !== "ignore") {
|
|
2821
|
+
if (t.type === "close") {
|
|
2822
|
+
e.preventDefault(), N((e) => jt(e, { type: "escape" })), B();
|
|
2823
|
+
return;
|
|
2824
|
+
}
|
|
2825
|
+
if (t.type === "move-active") {
|
|
2826
|
+
e.preventDefault(), N((e) => jt(e, {
|
|
2827
|
+
type: "move-active",
|
|
2828
|
+
delta: t.delta,
|
|
2829
|
+
optionCount: t.optionCount
|
|
2830
|
+
}));
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2833
|
+
t.type === "execute-active" && (e.preventDefault(), Ee(t.command));
|
|
2834
|
+
}
|
|
2835
|
+
}, [
|
|
2836
|
+
B,
|
|
2837
|
+
S,
|
|
2838
|
+
q,
|
|
2839
|
+
de,
|
|
2840
|
+
Ee,
|
|
2841
|
+
ne,
|
|
2842
|
+
M
|
|
2843
|
+
]), je = W(() => ({
|
|
2844
|
+
closeSlashMenu: B,
|
|
2845
|
+
focusFirstTableBodyCell: () => q ? Nt(q) : !1,
|
|
2846
|
+
setContent: (e, t = {}) => {
|
|
2847
|
+
if (!q) return !1;
|
|
2848
|
+
let n = Ve(t.format);
|
|
2849
|
+
return q.commands.setContent(e, {
|
|
2850
|
+
contentType: ze(n),
|
|
2851
|
+
emitUpdate: t.emitUpdate ?? !1
|
|
2852
|
+
}), t.focusFirstTableBodyCell && Nt(q), pe(q), S && U(q), me(q), z((e) => e + 1), !0;
|
|
2853
|
+
}
|
|
2854
|
+
}), [
|
|
2855
|
+
B,
|
|
2856
|
+
S,
|
|
2857
|
+
q,
|
|
2858
|
+
pe,
|
|
2859
|
+
U,
|
|
2860
|
+
me
|
|
2861
|
+
]);
|
|
2862
|
+
return {
|
|
2863
|
+
editor: q,
|
|
2864
|
+
frameProps: W(() => ({
|
|
2865
|
+
className: "markweave-editor-frame",
|
|
2866
|
+
"aria-label": e ?? D.common.editorAriaLabel,
|
|
2867
|
+
"data-testid": "markweave-editor-frame",
|
|
2868
|
+
"data-markweave-mode": x,
|
|
2869
|
+
"data-markweave-inner-toc": l ? "true" : "false",
|
|
2870
|
+
"data-mermaid-mode": be.mode,
|
|
2871
|
+
"data-table-focus-mode": _e.mode,
|
|
2872
|
+
onKeyDownCapture: Y
|
|
2873
|
+
}), [
|
|
2874
|
+
e,
|
|
2875
|
+
x,
|
|
2876
|
+
Y,
|
|
2877
|
+
l,
|
|
2878
|
+
be.mode,
|
|
2879
|
+
D.common.editorAriaLabel,
|
|
2880
|
+
_e.mode
|
|
2881
|
+
]),
|
|
2882
|
+
overlayProps: W(() => ({
|
|
2883
|
+
floatingToolbar: q && S ? {
|
|
2884
|
+
editor: q,
|
|
2885
|
+
messages: D,
|
|
2886
|
+
selectionSnapshot: j,
|
|
2887
|
+
onRewriteSelection: m,
|
|
2888
|
+
onExtractToNote: p
|
|
2889
|
+
} : null,
|
|
2890
|
+
slashCommandMenu: q && S ? {
|
|
2891
|
+
commands: de,
|
|
2892
|
+
state: M,
|
|
2893
|
+
position: P,
|
|
2894
|
+
inputCommand: ne,
|
|
2895
|
+
messages: D,
|
|
2896
|
+
onActiveIndexChange: De,
|
|
2897
|
+
onInputCommandChange: F,
|
|
2898
|
+
onSelect: Ee,
|
|
2899
|
+
onUpload: g
|
|
2900
|
+
} : null,
|
|
2901
|
+
tableControls: q && S ? {
|
|
2902
|
+
editor: q,
|
|
2903
|
+
active: _e.active,
|
|
2904
|
+
interactionState: ie,
|
|
2905
|
+
messages: D,
|
|
2906
|
+
onCopyPayload: v,
|
|
2907
|
+
onCommandResult: _,
|
|
2908
|
+
onEditWithAi: f
|
|
2909
|
+
} : null,
|
|
2910
|
+
tableSelectionOverlay: q && S ? {
|
|
2911
|
+
editor: q,
|
|
2912
|
+
focusState: _e
|
|
2913
|
+
} : null,
|
|
2914
|
+
codeBlockControls: q ? {
|
|
2915
|
+
editor: q,
|
|
2916
|
+
active: S && ve,
|
|
2917
|
+
mermaidMode: I,
|
|
2918
|
+
onMermaidModeChange: re,
|
|
2919
|
+
readOnly: !S
|
|
2920
|
+
} : null,
|
|
2921
|
+
innerToc: q && l && Ce.items.length ? {
|
|
2922
|
+
editor: q,
|
|
2923
|
+
editable: S,
|
|
2924
|
+
messages: D,
|
|
2925
|
+
state: Ce
|
|
2926
|
+
} : null,
|
|
2927
|
+
mathEditorPopover: q && S && L ? {
|
|
2928
|
+
editor: q,
|
|
2929
|
+
messages: D,
|
|
2930
|
+
target: L,
|
|
2931
|
+
onClose: () => R(null)
|
|
2932
|
+
} : null
|
|
2933
|
+
}), [
|
|
2934
|
+
S,
|
|
2935
|
+
q,
|
|
2936
|
+
de,
|
|
2937
|
+
l,
|
|
2938
|
+
ve,
|
|
2939
|
+
I,
|
|
2940
|
+
D,
|
|
2941
|
+
L,
|
|
2942
|
+
f,
|
|
2943
|
+
p,
|
|
2944
|
+
m,
|
|
2945
|
+
g,
|
|
2946
|
+
_,
|
|
2947
|
+
v,
|
|
2948
|
+
Ee,
|
|
2949
|
+
j,
|
|
2950
|
+
De,
|
|
2951
|
+
ne,
|
|
2952
|
+
P,
|
|
2953
|
+
M,
|
|
2954
|
+
_e,
|
|
2955
|
+
ie,
|
|
2956
|
+
Ce
|
|
2957
|
+
]),
|
|
2958
|
+
runtimeSnapshot: Te,
|
|
2959
|
+
actions: je
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
function vi({ className: e, ...n }) {
|
|
2963
|
+
let r = _i(n);
|
|
2964
|
+
if (!r.editor) return null;
|
|
2965
|
+
let i = [r.frameProps.className, e].filter(Boolean).join(" ");
|
|
2966
|
+
return /* @__PURE__ */ Q("section", {
|
|
2967
|
+
...r.frameProps,
|
|
2968
|
+
className: i,
|
|
2969
|
+
children: [
|
|
2970
|
+
r.overlayProps.floatingToolbar ? /* @__PURE__ */ Z(Lr, { ...r.overlayProps.floatingToolbar }) : null,
|
|
2971
|
+
r.overlayProps.slashCommandMenu ? /* @__PURE__ */ Z(ii, { ...r.overlayProps.slashCommandMenu }) : null,
|
|
2972
|
+
r.overlayProps.tableControls ? /* @__PURE__ */ Z(oi, { ...r.overlayProps.tableControls }) : null,
|
|
2973
|
+
r.overlayProps.tableSelectionOverlay ? /* @__PURE__ */ Z(si, { ...r.overlayProps.tableSelectionOverlay }) : null,
|
|
2974
|
+
r.overlayProps.codeBlockControls ? /* @__PURE__ */ Z(gr, { ...r.overlayProps.codeBlockControls }) : null,
|
|
2975
|
+
r.overlayProps.innerToc ? /* @__PURE__ */ Z(li, { ...r.overlayProps.innerToc }) : null,
|
|
2976
|
+
r.overlayProps.mathEditorPopover ? /* @__PURE__ */ Z(Yr, { ...r.overlayProps.mathEditorPopover }) : null,
|
|
2977
|
+
/* @__PURE__ */ Z(t, { editor: r.editor })
|
|
2978
|
+
]
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
//#endregion
|
|
2982
|
+
export { vi as MarkweaveEditor, pr as createMarkweaveEditorExtensions, pr as createMarkweaveReactEditorExtensions, _i as useMarkweaveEditorController };
|