@hachej/boring-workspace 0.1.34 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{FileTree-DWbh0xNI.js → FileTree-CkCxHBDu.js} +1 -1
- package/dist/MarkdownEditor-CtPphEVP.js +549 -0
- package/dist/{WorkspaceLoadingState-RVGURLJy.js → WorkspaceLoadingState-Bl-92Dly.js} +287 -252
- package/dist/WorkspaceProvider-BhRPFy5R.js +7508 -0
- package/dist/app-front.d.ts +50 -3
- package/dist/app-front.js +893 -756
- package/dist/app-server.js +6 -0
- package/dist/boring-workspace.css +1 -1
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.js +8 -1
- package/dist/server.js +6 -0
- package/dist/testing.js +1 -1
- package/dist/workspace.css +328 -30
- package/dist/workspace.d.ts +68 -2
- package/dist/workspace.js +31 -30
- package/package.json +5 -5
- package/dist/MarkdownEditor-BhLjIyPQ.js +0 -540
- package/dist/WorkspaceProvider-hCE2wXKZ.js +0 -6567
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
import { jsxs as H, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { useState as D, useCallback as K, useRef as L, useEffect as E, useMemo as Q } from "react";
|
|
3
|
-
import { ReactNodeViewRenderer as Z, NodeViewWrapper as G, useEditor as J, EditorContent as Y, useEditorState as tt } from "@tiptap/react";
|
|
4
|
-
import et from "@tiptap/starter-kit";
|
|
5
|
-
import rt from "@tiptap/extension-underline";
|
|
6
|
-
import it from "@tiptap/extension-link";
|
|
7
|
-
import q from "@tiptap/extension-placeholder";
|
|
8
|
-
import nt from "@tiptap/extension-task-list";
|
|
9
|
-
import at from "@tiptap/extension-task-item";
|
|
10
|
-
import ot from "@tiptap/extension-text-align";
|
|
11
|
-
import st from "@tiptap/extension-highlight";
|
|
12
|
-
import { Table as lt } from "@tiptap/extension-table";
|
|
13
|
-
import { TableRow as ct } from "@tiptap/extension-table-row";
|
|
14
|
-
import { TableHeader as ut } from "@tiptap/extension-table-header";
|
|
15
|
-
import { TableCell as gt } from "@tiptap/extension-table-cell";
|
|
16
|
-
import dt from "@tiptap/extension-image";
|
|
17
|
-
import { c as S } from "./utils-B6yFEsav.js";
|
|
18
|
-
import { _ as j, aq as _ } from "./WorkspaceProvider-hCE2wXKZ.js";
|
|
19
|
-
import { uploadFile as ft } from "@hachej/boring-agent/front";
|
|
20
|
-
import mt from "@tiptap/extension-code-block-lowlight";
|
|
21
|
-
import { createLowlight as pt, common as ht } from "lowlight";
|
|
22
|
-
import { Markdown as wt } from "@tiptap/markdown";
|
|
23
|
-
import { BoldIcon as kt, ItalicIcon as vt, UnderlineIcon as bt, StrikethroughIcon as It, Heading1Icon as At, Heading2Icon as yt, Heading3Icon as Lt, ListIcon as xt, ListOrderedIcon as Nt, ListChecksIcon as Ct, QuoteIcon as Tt, CodeIcon as Mt, LinkIcon as Rt, ImageIcon as Ut, HighlighterIcon as Ht, AlignLeftIcon as St, AlignCenterIcon as $t, AlignRightIcon as Bt, MinusIcon as Et, Loader2Icon as Dt } from "lucide-react";
|
|
24
|
-
import { Toolbar as Ft, Input as zt, ToolbarButton as Wt, ToolbarSeparator as Pt } from "@hachej/boring-ui-kit";
|
|
25
|
-
function qt(t) {
|
|
26
|
-
const r = j(), i = _(), [a, l] = D(0);
|
|
27
|
-
return { upload: K(
|
|
28
|
-
async (g, o) => {
|
|
29
|
-
l((p) => p + 1);
|
|
30
|
-
try {
|
|
31
|
-
return await ft(g, {
|
|
32
|
-
apiBaseUrl: r,
|
|
33
|
-
workspaceRequestId: i,
|
|
34
|
-
directory: (o == null ? void 0 : o.directory) ?? (t == null ? void 0 : t.directory),
|
|
35
|
-
sourcePath: o == null ? void 0 : o.sourcePath
|
|
36
|
-
});
|
|
37
|
-
} finally {
|
|
38
|
-
l((p) => p - 1);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
[r, i, t == null ? void 0 : t.directory]
|
|
42
|
-
), uploading: a > 0 };
|
|
43
|
-
}
|
|
44
|
-
const F = 64, z = 2e3;
|
|
45
|
-
function jt(t) {
|
|
46
|
-
return t.replace(/\\/g, "\\\\").replace(/]/g, "\\]");
|
|
47
|
-
}
|
|
48
|
-
function B(t) {
|
|
49
|
-
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
50
|
-
}
|
|
51
|
-
function W(t) {
|
|
52
|
-
if (typeof t == "number" && Number.isFinite(t) && t > 0) return t;
|
|
53
|
-
if (typeof t == "string" && t.trim()) {
|
|
54
|
-
const r = Number(t);
|
|
55
|
-
if (Number.isFinite(r) && r > 0) return r;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const O = dt.extend({
|
|
60
|
-
name: "image",
|
|
61
|
-
draggable: !0,
|
|
62
|
-
addOptions() {
|
|
63
|
-
var t;
|
|
64
|
-
return {
|
|
65
|
-
...(t = this.parent) == null ? void 0 : t.call(this),
|
|
66
|
-
resolveSrc: (r) => r
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
parseMarkdown: (t, r) => r.createNode("image", {
|
|
70
|
-
src: t.href,
|
|
71
|
-
title: t.title,
|
|
72
|
-
alt: t.text
|
|
73
|
-
}),
|
|
74
|
-
renderMarkdown: (t) => {
|
|
75
|
-
var y, b, A, n, c, k, I;
|
|
76
|
-
const r = typeof ((y = t.attrs) == null ? void 0 : y.src) == "string" ? t.attrs.src : "", i = typeof ((b = t.attrs) == null ? void 0 : b.alt) == "string" ? t.attrs.alt : "", a = typeof ((A = t.attrs) == null ? void 0 : A.title) == "string" ? t.attrs.title : "", l = W((n = t.attrs) == null ? void 0 : n.width), s = W((c = t.attrs) == null ? void 0 : c.height), g = ((k = t.attrs) == null ? void 0 : k.align) === "center" || ((I = t.attrs) == null ? void 0 : I.align) === "right" ? t.attrs.align : "left";
|
|
77
|
-
if (!l && !s && g === "left") {
|
|
78
|
-
const h = jt(i);
|
|
79
|
-
return a ? `}")` : ``;
|
|
80
|
-
}
|
|
81
|
-
const p = `<img ${[
|
|
82
|
-
`src="${B(r)}"`,
|
|
83
|
-
i ? `alt="${B(i)}"` : null,
|
|
84
|
-
a ? `title="${B(a)}"` : null,
|
|
85
|
-
l ? `width="${l}"` : null,
|
|
86
|
-
s ? `height="${s}"` : null
|
|
87
|
-
].filter(Boolean).join(" ")} />`;
|
|
88
|
-
return g === "center" || g === "right" ? `<p align="${g}">${p}</p>` : p;
|
|
89
|
-
},
|
|
90
|
-
addAttributes() {
|
|
91
|
-
var r;
|
|
92
|
-
return {
|
|
93
|
-
...((r = this.parent) == null ? void 0 : r.call(this)) ?? {},
|
|
94
|
-
width: {
|
|
95
|
-
default: null,
|
|
96
|
-
parseHTML: (i) => {
|
|
97
|
-
const a = i.getAttribute("width");
|
|
98
|
-
if (a) {
|
|
99
|
-
const s = parseInt(a, 10);
|
|
100
|
-
return Number.isFinite(s) ? s : null;
|
|
101
|
-
}
|
|
102
|
-
const l = i.style.width;
|
|
103
|
-
if (l && l.endsWith("px")) {
|
|
104
|
-
const s = parseInt(l, 10);
|
|
105
|
-
return Number.isFinite(s) ? s : null;
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
},
|
|
109
|
-
renderHTML: (i) => i.width ? { width: String(i.width) } : {}
|
|
110
|
-
},
|
|
111
|
-
align: {
|
|
112
|
-
default: "left",
|
|
113
|
-
parseHTML: (i) => {
|
|
114
|
-
const a = i.getAttribute("data-align");
|
|
115
|
-
return a === "left" || a === "center" || a === "right" ? a : i.style.marginLeft === "auto" && i.style.marginRight === "auto" ? "center" : i.style.marginLeft === "auto" ? "right" : "left";
|
|
116
|
-
},
|
|
117
|
-
renderHTML: (i) => ({ "data-align": i.align ?? "left" })
|
|
118
|
-
},
|
|
119
|
-
// Transient marker used by MarkdownEditor.insertImageRef to find THIS
|
|
120
|
-
// specific inserted image when its background upload completes, even
|
|
121
|
-
// if the user pasted the same file twice (which produces two image
|
|
122
|
-
// nodes with identical `src` data URLs). Never serialized to HTML or
|
|
123
|
-
// markdown — purely in-memory state for the swap.
|
|
124
|
-
pendingUploadId: {
|
|
125
|
-
default: null,
|
|
126
|
-
parseHTML: () => null,
|
|
127
|
-
renderHTML: () => ({})
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
},
|
|
131
|
-
addNodeView() {
|
|
132
|
-
return Z(_t);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
function _t({ node: t, updateAttributes: r, selected: i, extension: a }) {
|
|
136
|
-
const l = L(null), s = L(null), [g, o] = D(!1), p = t.attrs.src ?? "", b = (a.options.resolveSrc ?? ((h) => h))(p), A = t.attrs.alt ?? "", n = t.attrs.title ?? void 0, c = t.attrs.width, k = t.attrs.align ?? "left";
|
|
137
|
-
E(() => {
|
|
138
|
-
if (!g) return;
|
|
139
|
-
const h = (x) => {
|
|
140
|
-
const u = s.current;
|
|
141
|
-
if (!u) return;
|
|
142
|
-
const d = x.clientX - u.x, m = Math.max(F, Math.min(z, u.width + d));
|
|
143
|
-
r({ width: Math.round(m) });
|
|
144
|
-
}, v = () => {
|
|
145
|
-
s.current = null, o(!1);
|
|
146
|
-
};
|
|
147
|
-
return window.addEventListener("pointermove", h), window.addEventListener("pointerup", v), window.addEventListener("pointercancel", v), () => {
|
|
148
|
-
window.removeEventListener("pointermove", h), window.removeEventListener("pointerup", v), window.removeEventListener("pointercancel", v);
|
|
149
|
-
};
|
|
150
|
-
}, [g, r]);
|
|
151
|
-
const I = (h) => {
|
|
152
|
-
var u;
|
|
153
|
-
h.preventDefault(), h.stopPropagation();
|
|
154
|
-
const v = (u = l.current) == null ? void 0 : u.querySelector("img"), x = c ?? (v == null ? void 0 : v.getBoundingClientRect().width) ?? 320;
|
|
155
|
-
s.current = { x: h.clientX, width: x }, o(!0);
|
|
156
|
-
};
|
|
157
|
-
return /* @__PURE__ */ H(
|
|
158
|
-
G,
|
|
159
|
-
{
|
|
160
|
-
ref: l,
|
|
161
|
-
"data-resizable-image": "",
|
|
162
|
-
"data-selected": i ? "true" : void 0,
|
|
163
|
-
className: S(
|
|
164
|
-
"relative block max-w-full align-baseline",
|
|
165
|
-
"[&>img]:block [&>img]:max-w-full [&>img]:h-auto [&>img]:rounded-md",
|
|
166
|
-
k === "left" && "mr-auto",
|
|
167
|
-
k === "center" && "mx-auto",
|
|
168
|
-
k === "right" && "ml-auto",
|
|
169
|
-
i && "ring-2 ring-[color:var(--accent)] ring-offset-1 ring-offset-background"
|
|
170
|
-
),
|
|
171
|
-
style: { width: c ? `${c}px` : void 0 },
|
|
172
|
-
children: [
|
|
173
|
-
/* @__PURE__ */ e("img", { src: b, alt: A, title: n, draggable: !1 }),
|
|
174
|
-
/* @__PURE__ */ e(
|
|
175
|
-
"span",
|
|
176
|
-
{
|
|
177
|
-
role: "slider",
|
|
178
|
-
"aria-label": "Resize image",
|
|
179
|
-
"aria-valuenow": c ?? 0,
|
|
180
|
-
"aria-valuemin": F,
|
|
181
|
-
"aria-valuemax": z,
|
|
182
|
-
"data-testid": "resize-handle",
|
|
183
|
-
onPointerDown: I,
|
|
184
|
-
className: S(
|
|
185
|
-
"absolute right-0 bottom-0 h-3 w-3 translate-x-1/2 translate-y-1/2 cursor-nwse-resize",
|
|
186
|
-
"rounded-full border border-background bg-[color:var(--accent)] shadow",
|
|
187
|
-
"opacity-0 transition-opacity duration-150 ease-out",
|
|
188
|
-
(i || g) && "opacity-100"
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
)
|
|
192
|
-
]
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
const Ot = pt(ht), Vt = [
|
|
197
|
-
/<script[\s>][\s\S]*?<\/script>/gi,
|
|
198
|
-
/<iframe[\s>][\s\S]*?<\/iframe>/gi,
|
|
199
|
-
/\s+on\w+\s*=\s*["'][^"']*["']/gi,
|
|
200
|
-
/\s+on\w+\s*=\s*\S+/gi,
|
|
201
|
-
/href\s*=\s*["']?\s*javascript:[^"'\s>]*/gi,
|
|
202
|
-
/src\s*=\s*["']?\s*javascript:[^"'\s>]*/gi
|
|
203
|
-
];
|
|
204
|
-
function Xt(t) {
|
|
205
|
-
let r = t;
|
|
206
|
-
for (const i of Vt)
|
|
207
|
-
r = r.replace(i, "");
|
|
208
|
-
return r;
|
|
209
|
-
}
|
|
210
|
-
function Kt(t) {
|
|
211
|
-
return /^(?:[a-z][a-z0-9+.-]*:|\/|#)/i.test(t);
|
|
212
|
-
}
|
|
213
|
-
function Qt(t, r) {
|
|
214
|
-
return !(t === "" && !r);
|
|
215
|
-
}
|
|
216
|
-
function Zt(t, r) {
|
|
217
|
-
const i = t.match(/^([^?#]*)([?#].*)?$/), a = (i == null ? void 0 : i[1]) ?? t, l = (i == null ? void 0 : i[2]) ?? "", s = r != null && r.includes("/") ? r.slice(0, r.lastIndexOf("/")) : "", g = `${s ? `${s}/` : ""}${a}`.split("/"), o = [];
|
|
218
|
-
for (const p of g)
|
|
219
|
-
!p || p === "." || (p === ".." ? o.pop() : o.push(p));
|
|
220
|
-
return `${o.join("/")}${l}`;
|
|
221
|
-
}
|
|
222
|
-
function Gt(t, r, i, a) {
|
|
223
|
-
if (!t || Kt(t)) return t;
|
|
224
|
-
const l = Zt(t, r), s = i.replace(/\/$/, ""), g = new URLSearchParams({ path: l });
|
|
225
|
-
return a && g.set("workspaceId", a), `${s}/api/v1/files/raw?${g.toString()}`;
|
|
226
|
-
}
|
|
227
|
-
const Jt = [
|
|
228
|
-
et.configure({
|
|
229
|
-
codeBlock: !1,
|
|
230
|
-
link: !1,
|
|
231
|
-
underline: !1
|
|
232
|
-
}),
|
|
233
|
-
rt,
|
|
234
|
-
it.configure({
|
|
235
|
-
openOnClick: !0,
|
|
236
|
-
autolink: !0,
|
|
237
|
-
linkOnPaste: !0,
|
|
238
|
-
defaultProtocol: "https",
|
|
239
|
-
HTMLAttributes: { rel: "noopener noreferrer nofollow", target: "_blank" }
|
|
240
|
-
}),
|
|
241
|
-
q.configure({
|
|
242
|
-
placeholder: "Start writing..."
|
|
243
|
-
}),
|
|
244
|
-
nt,
|
|
245
|
-
at.configure({ nested: !0 }),
|
|
246
|
-
ot.configure({
|
|
247
|
-
types: ["heading", "paragraph"]
|
|
248
|
-
}),
|
|
249
|
-
st,
|
|
250
|
-
lt.configure({
|
|
251
|
-
resizable: !0
|
|
252
|
-
}),
|
|
253
|
-
ct,
|
|
254
|
-
ut,
|
|
255
|
-
gt,
|
|
256
|
-
O.configure({
|
|
257
|
-
inline: !1,
|
|
258
|
-
allowBase64: !0
|
|
259
|
-
}),
|
|
260
|
-
mt.configure({ lowlight: Ot }),
|
|
261
|
-
wt.configure({
|
|
262
|
-
markedOptions: {
|
|
263
|
-
gfm: !0,
|
|
264
|
-
breaks: !1,
|
|
265
|
-
pedantic: !1
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
];
|
|
269
|
-
function f({ onClick: t, active: r, disabled: i, title: a, children: l }) {
|
|
270
|
-
return /* @__PURE__ */ e(
|
|
271
|
-
Wt,
|
|
272
|
-
{
|
|
273
|
-
type: "button",
|
|
274
|
-
size: "icon-xs",
|
|
275
|
-
onClick: t,
|
|
276
|
-
disabled: i,
|
|
277
|
-
title: a,
|
|
278
|
-
"aria-pressed": r,
|
|
279
|
-
className: S(
|
|
280
|
-
"text-muted-foreground/70",
|
|
281
|
-
r && "bg-[color:var(--accent-soft)] text-[color:var(--accent)]"
|
|
282
|
-
),
|
|
283
|
-
children: l
|
|
284
|
-
}
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
function C() {
|
|
288
|
-
return /* @__PURE__ */ e(Pt, { className: "mx-2 h-3.5" });
|
|
289
|
-
}
|
|
290
|
-
function P(t) {
|
|
291
|
-
const r = t.trim().toLowerCase();
|
|
292
|
-
return !r.startsWith("javascript:") && !r.startsWith("data:text/html");
|
|
293
|
-
}
|
|
294
|
-
function Yt(t) {
|
|
295
|
-
return new Promise((r, i) => {
|
|
296
|
-
const a = new FileReader();
|
|
297
|
-
a.onload = () => r(a.result), a.onerror = () => i(a.error ?? new Error("Read failed")), a.readAsDataURL(t);
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
function te(t) {
|
|
301
|
-
if (!t) return null;
|
|
302
|
-
for (const r of Array.from(t.files ?? []))
|
|
303
|
-
if (r.type.startsWith("image/")) return r;
|
|
304
|
-
for (const r of Array.from(t.items ?? [])) {
|
|
305
|
-
if (r.kind !== "file" || !r.type.startsWith("image/")) continue;
|
|
306
|
-
const i = r.getAsFile();
|
|
307
|
-
if (i) return i;
|
|
308
|
-
}
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
function ee({
|
|
312
|
-
editor: t,
|
|
313
|
-
onInsertImage: r,
|
|
314
|
-
rawMode: i,
|
|
315
|
-
onToggleRawMode: a,
|
|
316
|
-
uploading: l
|
|
317
|
-
}) {
|
|
318
|
-
const s = (n) => {
|
|
319
|
-
if (t) {
|
|
320
|
-
if (t.isActive("image")) {
|
|
321
|
-
t.chain().focus().updateAttributes("image", { align: n }).run();
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
t.chain().focus().setTextAlign(n).run();
|
|
325
|
-
}
|
|
326
|
-
}, g = L(null), o = tt({
|
|
327
|
-
editor: t,
|
|
328
|
-
selector: ({ editor: n }) => n ? {
|
|
329
|
-
bold: n.isActive("bold"),
|
|
330
|
-
italic: n.isActive("italic"),
|
|
331
|
-
underline: n.isActive("underline"),
|
|
332
|
-
strike: n.isActive("strike"),
|
|
333
|
-
h1: n.isActive("heading", { level: 1 }),
|
|
334
|
-
h2: n.isActive("heading", { level: 2 }),
|
|
335
|
-
h3: n.isActive("heading", { level: 3 }),
|
|
336
|
-
bulletList: n.isActive("bulletList"),
|
|
337
|
-
orderedList: n.isActive("orderedList"),
|
|
338
|
-
taskList: n.isActive("taskList"),
|
|
339
|
-
blockquote: n.isActive("blockquote"),
|
|
340
|
-
codeBlock: n.isActive("codeBlock"),
|
|
341
|
-
link: n.isActive("link"),
|
|
342
|
-
highlight: n.isActive("highlight"),
|
|
343
|
-
alignLeft: n.isActive("image") ? (n.getAttributes("image").align ?? "left") === "left" : n.isActive({ textAlign: "left" }),
|
|
344
|
-
alignCenter: n.isActive("image") ? n.getAttributes("image").align === "center" : n.isActive({ textAlign: "center" }),
|
|
345
|
-
alignRight: n.isActive("image") ? n.getAttributes("image").align === "right" : n.isActive({ textAlign: "right" })
|
|
346
|
-
} : null
|
|
347
|
-
});
|
|
348
|
-
if (!t || !o) return null;
|
|
349
|
-
const p = () => {
|
|
350
|
-
const n = window.prompt("URL:");
|
|
351
|
-
n && P(n) && t.chain().focus().extendMarkRange("link").setLink({ href: n }).run();
|
|
352
|
-
}, y = () => {
|
|
353
|
-
const n = window.prompt("Image URL:");
|
|
354
|
-
n && P(n) && t.chain().focus().setImage({ src: n }).run();
|
|
355
|
-
}, b = (n) => {
|
|
356
|
-
var c;
|
|
357
|
-
if (n != null && n.shiftKey) {
|
|
358
|
-
y();
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
(c = g.current) == null || c.click();
|
|
362
|
-
}, A = async (n) => {
|
|
363
|
-
var k;
|
|
364
|
-
const c = (k = n.target.files) == null ? void 0 : k[0];
|
|
365
|
-
n.target.value = "", !(!c || !c.type.startsWith("image/")) && await r(c);
|
|
366
|
-
};
|
|
367
|
-
return /* @__PURE__ */ H(Ft, { className: "border-b border-border/60 bg-background px-3 py-1.5", "aria-label": "Formatting toolbar", children: [
|
|
368
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleBold().run(), active: o.bold, title: "Bold", children: /* @__PURE__ */ e(kt, { className: "h-4 w-4" }) }),
|
|
369
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleItalic().run(), active: o.italic, title: "Italic", children: /* @__PURE__ */ e(vt, { className: "h-4 w-4" }) }),
|
|
370
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleUnderline().run(), active: o.underline, title: "Underline", children: /* @__PURE__ */ e(bt, { className: "h-4 w-4" }) }),
|
|
371
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleStrike().run(), active: o.strike, title: "Strikethrough", children: /* @__PURE__ */ e(It, { className: "h-4 w-4" }) }),
|
|
372
|
-
/* @__PURE__ */ e(C, {}),
|
|
373
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleHeading({ level: 1 }).run(), active: o.h1, title: "Heading 1", children: /* @__PURE__ */ e(At, { className: "h-4 w-4" }) }),
|
|
374
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleHeading({ level: 2 }).run(), active: o.h2, title: "Heading 2", children: /* @__PURE__ */ e(yt, { className: "h-4 w-4" }) }),
|
|
375
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleHeading({ level: 3 }).run(), active: o.h3, title: "Heading 3", children: /* @__PURE__ */ e(Lt, { className: "h-4 w-4" }) }),
|
|
376
|
-
/* @__PURE__ */ e(C, {}),
|
|
377
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleBulletList().run(), active: o.bulletList, title: "Bullet list", children: /* @__PURE__ */ e(xt, { className: "h-4 w-4" }) }),
|
|
378
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleOrderedList().run(), active: o.orderedList, title: "Ordered list", children: /* @__PURE__ */ e(Nt, { className: "h-4 w-4" }) }),
|
|
379
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleTaskList().run(), active: o.taskList, title: "Task list", children: /* @__PURE__ */ e(Ct, { className: "h-4 w-4" }) }),
|
|
380
|
-
/* @__PURE__ */ e(C, {}),
|
|
381
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleBlockquote().run(), active: o.blockquote, title: "Quote", children: /* @__PURE__ */ e(Tt, { className: "h-4 w-4" }) }),
|
|
382
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleCodeBlock().run(), active: o.codeBlock, title: "Code block", children: /* @__PURE__ */ e(Mt, { className: "h-4 w-4" }) }),
|
|
383
|
-
/* @__PURE__ */ e(f, { onClick: p, active: o.link, title: "Link", children: /* @__PURE__ */ e(Rt, { className: "h-4 w-4" }) }),
|
|
384
|
-
/* @__PURE__ */ e(
|
|
385
|
-
f,
|
|
386
|
-
{
|
|
387
|
-
onClick: b,
|
|
388
|
-
title: "Image (click to upload, Shift+click for URL)",
|
|
389
|
-
children: /* @__PURE__ */ e(Ut, { className: "h-4 w-4" })
|
|
390
|
-
}
|
|
391
|
-
),
|
|
392
|
-
/* @__PURE__ */ e(
|
|
393
|
-
zt,
|
|
394
|
-
{
|
|
395
|
-
ref: g,
|
|
396
|
-
"data-testid": "image-file-input",
|
|
397
|
-
type: "file",
|
|
398
|
-
accept: "image/*",
|
|
399
|
-
className: "hidden",
|
|
400
|
-
onChange: A
|
|
401
|
-
}
|
|
402
|
-
),
|
|
403
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().toggleHighlight().run(), active: o.highlight, title: "Highlight", children: /* @__PURE__ */ e(Ht, { className: "h-4 w-4" }) }),
|
|
404
|
-
/* @__PURE__ */ e(C, {}),
|
|
405
|
-
/* @__PURE__ */ e(f, { onClick: () => s("left"), active: o.alignLeft, title: "Align left", children: /* @__PURE__ */ e(St, { className: "h-4 w-4" }) }),
|
|
406
|
-
/* @__PURE__ */ e(f, { onClick: () => s("center"), active: o.alignCenter, title: "Center align", children: /* @__PURE__ */ e($t, { className: "h-4 w-4" }) }),
|
|
407
|
-
/* @__PURE__ */ e(f, { onClick: () => s("right"), active: o.alignRight, title: "Align right", children: /* @__PURE__ */ e(Bt, { className: "h-4 w-4" }) }),
|
|
408
|
-
/* @__PURE__ */ e(C, {}),
|
|
409
|
-
/* @__PURE__ */ e(f, { onClick: () => t.chain().focus().setHorizontalRule().run(), title: "Horizontal rule", children: /* @__PURE__ */ e(Et, { className: "h-4 w-4" }) }),
|
|
410
|
-
/* @__PURE__ */ e(C, {}),
|
|
411
|
-
l && /* @__PURE__ */ H(
|
|
412
|
-
"span",
|
|
413
|
-
{
|
|
414
|
-
role: "status",
|
|
415
|
-
"aria-live": "polite",
|
|
416
|
-
className: "ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground/80",
|
|
417
|
-
children: [
|
|
418
|
-
/* @__PURE__ */ e(Dt, { className: "h-3 w-3 animate-spin", "aria-hidden": !0 }),
|
|
419
|
-
"Uploading…"
|
|
420
|
-
]
|
|
421
|
-
}
|
|
422
|
-
),
|
|
423
|
-
/* @__PURE__ */ e(
|
|
424
|
-
f,
|
|
425
|
-
{
|
|
426
|
-
onClick: a,
|
|
427
|
-
active: i,
|
|
428
|
-
title: i ? "Rich text" : "Raw markdown",
|
|
429
|
-
children: /* @__PURE__ */ e("span", { className: "font-mono text-[10px] font-semibold leading-none tracking-[-0.02em]", children: "MD" })
|
|
430
|
-
}
|
|
431
|
-
)
|
|
432
|
-
] });
|
|
433
|
-
}
|
|
434
|
-
function Ne({
|
|
435
|
-
content: t,
|
|
436
|
-
onChange: r,
|
|
437
|
-
readOnly: i = !1,
|
|
438
|
-
placeholder: a,
|
|
439
|
-
className: l,
|
|
440
|
-
documentPath: s
|
|
441
|
-
}) {
|
|
442
|
-
const g = j(), o = _(), { upload: p, uploading: y } = qt(), [b, A] = D(!1), n = Q(() => {
|
|
443
|
-
const d = O.configure({
|
|
444
|
-
inline: !1,
|
|
445
|
-
allowBase64: !0,
|
|
446
|
-
resolveSrc: (w) => Gt(w, s, g, o)
|
|
447
|
-
}), m = Jt.map((w) => w.name === "image" ? d : w);
|
|
448
|
-
return a ? [
|
|
449
|
-
...m.filter((w) => w.name !== "placeholder"),
|
|
450
|
-
q.configure({ placeholder: a })
|
|
451
|
-
] : m;
|
|
452
|
-
}, [g, s, a, o]), c = L(r);
|
|
453
|
-
c.current = r;
|
|
454
|
-
const k = L(!1), I = L(null), h = L(async () => {
|
|
455
|
-
});
|
|
456
|
-
h.current = async (d) => {
|
|
457
|
-
const m = I.current;
|
|
458
|
-
if (!m) return;
|
|
459
|
-
let w;
|
|
460
|
-
try {
|
|
461
|
-
w = await Yt(d);
|
|
462
|
-
} catch {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
const N = typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `pending-${Date.now()}-${Math.random().toString(36).slice(2)}`, V = { src: w, alt: d.name, pendingUploadId: N };
|
|
466
|
-
m.chain().focus().setImage(V).run();
|
|
467
|
-
try {
|
|
468
|
-
const { url: T } = await p(d, { sourcePath: s }), M = I.current;
|
|
469
|
-
if (!M || M.isDestroyed) return;
|
|
470
|
-
M.commands.command(({ tr: $, state: R }) => (R.doc.descendants((U, X) => (U.type.name === "image" && U.attrs.pendingUploadId === N && $.setNodeMarkup(X, void 0, { ...U.attrs, src: T, pendingUploadId: null }), !0)), !0));
|
|
471
|
-
} catch {
|
|
472
|
-
const T = I.current;
|
|
473
|
-
if (!T || T.isDestroyed) return;
|
|
474
|
-
T.commands.command(({ tr: M, state: $ }) => ($.doc.descendants((R, U) => (R.type.name === "image" && R.attrs.pendingUploadId === N && M.setNodeMarkup(U, void 0, { ...R.attrs, pendingUploadId: null }), !0)), !0));
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
const v = t || { type: "doc", content: [{ type: "paragraph" }] }, x = t ? "markdown" : "json", u = J({
|
|
478
|
-
extensions: n,
|
|
479
|
-
content: v,
|
|
480
|
-
contentType: x,
|
|
481
|
-
editable: !i,
|
|
482
|
-
editorProps: {
|
|
483
|
-
attributes: {
|
|
484
|
-
class: "tiptap-prose max-w-[68ch] px-8 py-6 focus:outline-none min-h-[200px]"
|
|
485
|
-
},
|
|
486
|
-
transformPastedHTML: Xt,
|
|
487
|
-
handlePaste: (d, m) => {
|
|
488
|
-
if (i) return !1;
|
|
489
|
-
const w = te(m.clipboardData);
|
|
490
|
-
return w ? (m.preventDefault(), h.current(w), !0) : !1;
|
|
491
|
-
}
|
|
492
|
-
},
|
|
493
|
-
onUpdate: ({ editor: d }) => {
|
|
494
|
-
var w, N;
|
|
495
|
-
if (k.current) return;
|
|
496
|
-
const m = ((w = d.getMarkdown) == null ? void 0 : w.call(d)) ?? d.getHTML();
|
|
497
|
-
Qt(m, d.isFocused) && ((N = c.current) == null || N.call(c, m));
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
return I.current = u, E(() => {
|
|
501
|
-
!u || u.isDestroyed || u.setEditable(!i);
|
|
502
|
-
}, [u, i]), E(() => {
|
|
503
|
-
var m;
|
|
504
|
-
!u || u.isDestroyed || (((m = u.getMarkdown) == null ? void 0 : m.call(u)) ?? u.getHTML()) === t || (k.current = !0, u.commands.setContent(v, { contentType: x }), k.current = !1);
|
|
505
|
-
}, [u, t]), /* @__PURE__ */ H("div", { className: S("flex h-full min-h-0 flex-col overflow-hidden", l), children: [
|
|
506
|
-
!i && /* @__PURE__ */ e(
|
|
507
|
-
ee,
|
|
508
|
-
{
|
|
509
|
-
editor: u,
|
|
510
|
-
onInsertImage: (d) => h.current(d),
|
|
511
|
-
rawMode: b,
|
|
512
|
-
onToggleRawMode: () => A((d) => !d),
|
|
513
|
-
uploading: y
|
|
514
|
-
}
|
|
515
|
-
),
|
|
516
|
-
/* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: b && !i ? /* @__PURE__ */ e(
|
|
517
|
-
"textarea",
|
|
518
|
-
{
|
|
519
|
-
"aria-label": "Raw markdown",
|
|
520
|
-
"data-testid": "markdown-raw-editor",
|
|
521
|
-
className: "h-full min-h-[200px] w-full resize-none bg-background px-8 py-6 font-mono text-[13px] leading-6 text-foreground outline-none placeholder:text-muted-foreground/70",
|
|
522
|
-
value: t,
|
|
523
|
-
placeholder: a,
|
|
524
|
-
spellCheck: !1,
|
|
525
|
-
onChange: (d) => {
|
|
526
|
-
var m;
|
|
527
|
-
return (m = c.current) == null ? void 0 : m.call(c, d.target.value);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
) : /* @__PURE__ */ e(Y, { editor: u }) })
|
|
531
|
-
] });
|
|
532
|
-
}
|
|
533
|
-
export {
|
|
534
|
-
Ne as MarkdownEditor,
|
|
535
|
-
P as isSafeUrl,
|
|
536
|
-
Qt as isUserEditedChange,
|
|
537
|
-
Gt as rawFileUrlForMarkdownImage,
|
|
538
|
-
Yt as readFileAsDataUrl,
|
|
539
|
-
Xt as sanitizeHtml
|
|
540
|
-
};
|