@dapplelight/signet-ui 0.2.2 → 0.3.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/README.md +324 -4
- package/dist/behaviors/index.d.ts +16 -0
- package/dist/behaviors/index.d.ts.map +1 -0
- package/dist/behaviors/index.js +27 -0
- package/dist/behaviors/index.js.map +1 -0
- package/dist/components/domain/amount.d.ts +27 -0
- package/dist/components/domain/amount.d.ts.map +1 -0
- package/dist/components/domain/amount.js +108 -0
- package/dist/components/domain/amount.js.map +1 -0
- package/dist/components/domain/csv-import.d.ts +81 -0
- package/dist/components/domain/csv-import.d.ts.map +1 -0
- package/dist/components/domain/csv-import.js +177 -0
- package/dist/components/domain/csv-import.js.map +1 -0
- package/dist/components/domain/job-runs.d.ts +27 -0
- package/dist/components/domain/job-runs.d.ts.map +1 -0
- package/dist/components/domain/job-runs.js +55 -0
- package/dist/components/domain/job-runs.js.map +1 -0
- package/dist/components/domain/kanban.d.ts +50 -0
- package/dist/components/domain/kanban.d.ts.map +1 -0
- package/dist/components/domain/kanban.js +279 -0
- package/dist/components/domain/kanban.js.map +1 -0
- package/dist/components/domain/upload.d.ts +21 -0
- package/dist/components/domain/upload.d.ts.map +1 -0
- package/dist/components/domain/upload.js +106 -0
- package/dist/components/domain/upload.js.map +1 -0
- package/dist/components/screens/abuse-screens.d.ts +101 -0
- package/dist/components/screens/abuse-screens.d.ts.map +1 -0
- package/dist/components/screens/abuse-screens.js +163 -0
- package/dist/components/screens/abuse-screens.js.map +1 -0
- package/dist/components/screens/account-screens.d.ts +120 -0
- package/dist/components/screens/account-screens.d.ts.map +1 -0
- package/dist/components/screens/account-screens.js +177 -0
- package/dist/components/screens/account-screens.js.map +1 -0
- package/dist/components/screens/admin-screens.d.ts +269 -0
- package/dist/components/screens/admin-screens.d.ts.map +1 -0
- package/dist/components/screens/admin-screens.js +781 -0
- package/dist/components/screens/admin-screens.js.map +1 -0
- package/dist/components/screens/api-screens.d.ts +113 -0
- package/dist/components/screens/api-screens.d.ts.map +1 -0
- package/dist/components/screens/api-screens.js +127 -0
- package/dist/components/screens/api-screens.js.map +1 -0
- package/dist/components/screens/auth-screens.d.ts +117 -0
- package/dist/components/screens/auth-screens.d.ts.map +1 -0
- package/dist/components/screens/auth-screens.js +164 -0
- package/dist/components/screens/auth-screens.js.map +1 -0
- package/dist/components/screens/billing-screens.d.ts +163 -0
- package/dist/components/screens/billing-screens.d.ts.map +1 -0
- package/dist/components/screens/billing-screens.js +255 -0
- package/dist/components/screens/billing-screens.js.map +1 -0
- package/dist/components/screens/collab-screens.d.ts +150 -0
- package/dist/components/screens/collab-screens.d.ts.map +1 -0
- package/dist/components/screens/collab-screens.js +287 -0
- package/dist/components/screens/collab-screens.js.map +1 -0
- package/dist/components/screens/experiment-screens.d.ts +177 -0
- package/dist/components/screens/experiment-screens.d.ts.map +1 -0
- package/dist/components/screens/experiment-screens.js +275 -0
- package/dist/components/screens/experiment-screens.js.map +1 -0
- package/dist/components/screens/funnel-screens.d.ts +131 -0
- package/dist/components/screens/funnel-screens.d.ts.map +1 -0
- package/dist/components/screens/funnel-screens.js +197 -0
- package/dist/components/screens/funnel-screens.js.map +1 -0
- package/dist/components/screens/growth-screens.d.ts +174 -0
- package/dist/components/screens/growth-screens.d.ts.map +1 -0
- package/dist/components/screens/growth-screens.js +285 -0
- package/dist/components/screens/growth-screens.js.map +1 -0
- package/dist/components/screens/monetisation-screens.d.ts +192 -0
- package/dist/components/screens/monetisation-screens.d.ts.map +1 -0
- package/dist/components/screens/monetisation-screens.js +217 -0
- package/dist/components/screens/monetisation-screens.js.map +1 -0
- package/dist/components/screens/notification-screens.d.ts +92 -0
- package/dist/components/screens/notification-screens.d.ts.map +1 -0
- package/dist/components/screens/notification-screens.js +141 -0
- package/dist/components/screens/notification-screens.js.map +1 -0
- package/dist/components/screens/org-screens.d.ts +135 -0
- package/dist/components/screens/org-screens.d.ts.map +1 -0
- package/dist/components/screens/org-screens.js +237 -0
- package/dist/components/screens/org-screens.js.map +1 -0
- package/dist/components/screens/privacy-screens.d.ts +74 -0
- package/dist/components/screens/privacy-screens.d.ts.map +1 -0
- package/dist/components/screens/privacy-screens.js +127 -0
- package/dist/components/screens/privacy-screens.js.map +1 -0
- package/dist/components/screens/realtime-screens.d.ts +53 -0
- package/dist/components/screens/realtime-screens.d.ts.map +1 -0
- package/dist/components/screens/realtime-screens.js +55 -0
- package/dist/components/screens/realtime-screens.js.map +1 -0
- package/dist/components/screens/status-screens.d.ts +139 -0
- package/dist/components/screens/status-screens.d.ts.map +1 -0
- package/dist/components/screens/status-screens.js +219 -0
- package/dist/components/screens/status-screens.js.map +1 -0
- package/dist/components/screens/subscription-charts.d.ts +113 -0
- package/dist/components/screens/subscription-charts.d.ts.map +1 -0
- package/dist/components/screens/subscription-charts.js +158 -0
- package/dist/components/screens/subscription-charts.js.map +1 -0
- package/dist/components/screens/workflow-screens.d.ts +97 -0
- package/dist/components/screens/workflow-screens.d.ts.map +1 -0
- package/dist/components/screens/workflow-screens.js +181 -0
- package/dist/components/screens/workflow-screens.js.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.js +34 -0
- package/dist/components/ui/alert-dialog.js.map +1 -0
- package/dist/components/ui/avatar.d.ts +12 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/avatar.js +31 -0
- package/dist/components/ui/avatar.js.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +14 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.js +38 -0
- package/dist/components/ui/breadcrumb.js.map +1 -0
- package/dist/components/ui/chart.d.ts +4 -3
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/chart.js +99 -1
- package/dist/components/ui/chart.js.map +1 -1
- package/dist/components/ui/command.d.ts +29 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/command.js +50 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/data-grid.d.ts +73 -0
- package/dist/components/ui/data-grid.d.ts.map +1 -0
- package/dist/components/ui/data-grid.js +612 -0
- package/dist/components/ui/data-grid.js.map +1 -0
- package/dist/components/ui/field.d.ts +15 -0
- package/dist/components/ui/field.d.ts.map +1 -0
- package/dist/components/ui/field.js +36 -0
- package/dist/components/ui/field.js.map +1 -0
- package/dist/components/ui/metric-headline.d.ts +59 -0
- package/dist/components/ui/metric-headline.d.ts.map +1 -0
- package/dist/components/ui/metric-headline.js +54 -0
- package/dist/components/ui/metric-headline.js.map +1 -0
- package/dist/components/ui/radio-group.d.ts +6 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/radio-group.js +12 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/rich-text-editor.d.ts +52 -0
- package/dist/components/ui/rich-text-editor.d.ts.map +1 -0
- package/dist/components/ui/rich-text-editor.js +669 -0
- package/dist/components/ui/rich-text-editor.js.map +1 -0
- package/dist/components/ui/sidebar.d.ts +45 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/sidebar.js +86 -0
- package/dist/components/ui/sidebar.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +4 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/spinner.js +8 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/stepper.d.ts +17 -0
- package/dist/components/ui/stepper.d.ts.map +1 -0
- package/dist/components/ui/stepper.js +17 -0
- package/dist/components/ui/stepper.js.map +1 -0
- package/dist/components/ui/tabs.js +1 -1
- package/dist/components/ui/tabs.js.map +1 -1
- package/dist/components/ui/timeline.d.ts +11 -0
- package/dist/components/ui/timeline.d.ts.map +1 -0
- package/dist/components/ui/timeline.js +27 -0
- package/dist/components/ui/timeline.js.map +1 -0
- package/dist/components/ui/toast.d.ts +47 -0
- package/dist/components/ui/toast.d.ts.map +1 -0
- package/dist/components/ui/toast.js +49 -0
- package/dist/components/ui/toast.js.map +1 -0
- package/dist/hooks/use-channel.d.ts +96 -0
- package/dist/hooks/use-channel.d.ts.map +1 -0
- package/dist/hooks/use-channel.js +242 -0
- package/dist/hooks/use-channel.js.map +1 -0
- package/dist/hooks/use-copy.d.ts +5 -0
- package/dist/hooks/use-copy.d.ts.map +1 -0
- package/dist/hooks/use-copy.js +22 -0
- package/dist/hooks/use-copy.js.map +1 -0
- package/dist/hooks/use-debounce.d.ts +2 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-debounce.js +11 -0
- package/dist/hooks/use-debounce.js.map +1 -0
- package/dist/hooks/use-intersection.d.ts +9 -0
- package/dist/hooks/use-intersection.d.ts.map +1 -0
- package/dist/hooks/use-intersection.js +29 -0
- package/dist/hooks/use-intersection.js.map +1 -0
- package/dist/hooks/use-local-storage.d.ts +2 -0
- package/dist/hooks/use-local-storage.d.ts.map +1 -0
- package/dist/hooks/use-local-storage.js +59 -0
- package/dist/hooks/use-local-storage.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/csv.d.ts +8 -0
- package/dist/lib/csv.d.ts.map +1 -0
- package/dist/lib/csv.js +77 -0
- package/dist/lib/csv.js.map +1 -0
- package/package.json +208 -7
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import Link from "@tiptap/extension-link";
|
|
4
|
+
import Mention from "@tiptap/extension-mention";
|
|
5
|
+
import { EditorContent, useEditor, useEditorState } from "@tiptap/react";
|
|
6
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
7
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { cn } from "../../lib/utils.js";
|
|
9
|
+
const MENTION = /@\[([^\]\n]{1,100})\]\(user:([A-Za-z0-9_.:-]{1,80})\)/y;
|
|
10
|
+
const SAFE_SCHEMES = new Set(["http", "https", "mailto", "tel"]);
|
|
11
|
+
const escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
12
|
+
export function isSafeUrl(url) {
|
|
13
|
+
let bare = url;
|
|
14
|
+
try {
|
|
15
|
+
bare = decodeURIComponent(bare);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
}
|
|
19
|
+
bare = bare.replace(/[\u0000-\u0020\u007f-\u009f]/g, "");
|
|
20
|
+
const colon = bare.indexOf(":");
|
|
21
|
+
const cut = bare.search(/[/?#]/);
|
|
22
|
+
if (colon < 0 || (cut >= 0 && cut < colon))
|
|
23
|
+
return true;
|
|
24
|
+
return SAFE_SCHEMES.has(bare.slice(0, colon).toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
const PUNCT = /[!-/:-@[-`{-~]/;
|
|
27
|
+
function inlineHtml(src) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const open = [];
|
|
30
|
+
let text = "";
|
|
31
|
+
const flush = () => {
|
|
32
|
+
if (text)
|
|
33
|
+
out.push(escapeHtml(text));
|
|
34
|
+
text = "";
|
|
35
|
+
};
|
|
36
|
+
let i = 0;
|
|
37
|
+
while (i < src.length) {
|
|
38
|
+
const ch = src[i];
|
|
39
|
+
if (ch === "\\" && PUNCT.test(src[i + 1] ?? "")) {
|
|
40
|
+
text += src[i + 1];
|
|
41
|
+
i += 2;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === "\n") {
|
|
45
|
+
flush();
|
|
46
|
+
out.push("<br>");
|
|
47
|
+
i++;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (ch === "`") {
|
|
51
|
+
let n = 1;
|
|
52
|
+
while (src[i + n] === "`")
|
|
53
|
+
n++;
|
|
54
|
+
const fence = "`".repeat(n);
|
|
55
|
+
const close = src.indexOf(fence, i + n);
|
|
56
|
+
if (close > 0) {
|
|
57
|
+
flush();
|
|
58
|
+
out.push(`<code>${escapeHtml(src.slice(i + n, close))}</code>`);
|
|
59
|
+
i = close + n;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
text += fence;
|
|
63
|
+
i += n;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (ch === "@" && src[i + 1] === "[") {
|
|
67
|
+
MENTION.lastIndex = i;
|
|
68
|
+
const m = MENTION.exec(src);
|
|
69
|
+
if (m) {
|
|
70
|
+
flush();
|
|
71
|
+
out.push(`<span data-mention="" data-user-id="${escapeHtml(m[2])}" contenteditable="false">@${escapeHtml(m[1])}</span>`);
|
|
72
|
+
i += m[0].length;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (ch === "[") {
|
|
77
|
+
let j = i + 1;
|
|
78
|
+
while (j < src.length && src[j] !== "]" && src[j] !== "\n")
|
|
79
|
+
j += src[j] === "\\" ? 2 : 1;
|
|
80
|
+
const m = src[j] === "]" ? /^\(([^()\s]*)\)/.exec(src.slice(j + 1)) : null;
|
|
81
|
+
if (m) {
|
|
82
|
+
flush();
|
|
83
|
+
const label = inlineHtml(src.slice(i + 1, j));
|
|
84
|
+
const url = m[1];
|
|
85
|
+
out.push(isSafeUrl(url)
|
|
86
|
+
? `<a href="${escapeHtml(url)}" rel="noopener noreferrer nofollow">${label}</a>`
|
|
87
|
+
: label);
|
|
88
|
+
i = j + 1 + m[0].length;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const marker = src.startsWith("**", i) ? "**" : ch === "_" || ch === "*" ? ch : "";
|
|
93
|
+
if (marker) {
|
|
94
|
+
flush();
|
|
95
|
+
const k = open.findIndex((o) => o.marker === marker);
|
|
96
|
+
if (k === open.length - 1 && k >= 0) {
|
|
97
|
+
open.pop();
|
|
98
|
+
out.push(marker === "**" ? "</strong>" : "</em>");
|
|
99
|
+
}
|
|
100
|
+
else if (k < 0) {
|
|
101
|
+
open.push({ marker, at: out.length });
|
|
102
|
+
out.push(marker === "**" ? "<strong>" : "<em>");
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
out.push(escapeHtml(marker));
|
|
106
|
+
i += marker.length;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
text += ch;
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
flush();
|
|
113
|
+
for (const o of open)
|
|
114
|
+
out[o.at] = escapeHtml(o.marker);
|
|
115
|
+
return out.join("");
|
|
116
|
+
}
|
|
117
|
+
const LIST_ITEM = /^( *)([-*+]|\d{1,9}[.)]) +(.*)$/;
|
|
118
|
+
const FENCE = /^(`{3,})[^`]*$/;
|
|
119
|
+
const HEADING = /^(#{1,6}) +(.*)$/;
|
|
120
|
+
export function richTextToHtml(markdown) {
|
|
121
|
+
const lines = String(markdown ?? "")
|
|
122
|
+
.replace(/\r\n?/g, "\n")
|
|
123
|
+
.split("\n");
|
|
124
|
+
const out = [];
|
|
125
|
+
let i = 0;
|
|
126
|
+
const startsBlock = (l) => FENCE.test(l) || HEADING.test(l) || LIST_ITEM.test(l);
|
|
127
|
+
while (i < lines.length) {
|
|
128
|
+
const line = lines[i];
|
|
129
|
+
if (!line.trim()) {
|
|
130
|
+
i++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const fence = FENCE.exec(line);
|
|
134
|
+
if (fence) {
|
|
135
|
+
const body = [];
|
|
136
|
+
i++;
|
|
137
|
+
while (i < lines.length && lines[i].trim() !== fence[1])
|
|
138
|
+
body.push(lines[i++]);
|
|
139
|
+
i++;
|
|
140
|
+
out.push(`<pre><code>${escapeHtml(body.join("\n"))}</code></pre>`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const h = HEADING.exec(line);
|
|
144
|
+
if (h) {
|
|
145
|
+
const n = Math.min(h[1].length, 3);
|
|
146
|
+
out.push(`<h${n}>${inlineHtml(h[2])}</h${n}>`);
|
|
147
|
+
i++;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (LIST_ITEM.test(line)) {
|
|
151
|
+
const stack = [];
|
|
152
|
+
let html = "";
|
|
153
|
+
while (i < lines.length) {
|
|
154
|
+
const m = LIST_ITEM.exec(lines[i]);
|
|
155
|
+
if (!m)
|
|
156
|
+
break;
|
|
157
|
+
const type = /\d/.test(m[2]) ? "ol" : "ul";
|
|
158
|
+
const level = Math.min(Math.floor(m[1].length / 2), stack.length);
|
|
159
|
+
while (stack.length > level + 1)
|
|
160
|
+
html += `</li></${stack.pop()}>`;
|
|
161
|
+
if (stack.length === level + 1) {
|
|
162
|
+
if (stack[level] === type)
|
|
163
|
+
html += "</li><li>";
|
|
164
|
+
else {
|
|
165
|
+
html += `</li></${stack.pop()}><${type}><li>`;
|
|
166
|
+
stack.push(type);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
html += `<${type}><li>`;
|
|
171
|
+
stack.push(type);
|
|
172
|
+
}
|
|
173
|
+
html += inlineHtml(m[3]);
|
|
174
|
+
i++;
|
|
175
|
+
}
|
|
176
|
+
while (stack.length)
|
|
177
|
+
html += `</li></${stack.pop()}>`;
|
|
178
|
+
out.push(html);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const para = [];
|
|
182
|
+
while (i < lines.length &&
|
|
183
|
+
lines[i].trim() &&
|
|
184
|
+
!(para.length && startsBlock(lines[i])))
|
|
185
|
+
para.push(lines[i++]);
|
|
186
|
+
out.push(`<p>${inlineHtml(para.join("\n"))}</p>`);
|
|
187
|
+
}
|
|
188
|
+
return out.join("");
|
|
189
|
+
}
|
|
190
|
+
const escapeText = (s) => s.replace(/[\\`*_[\]<>]/g, "\\$&");
|
|
191
|
+
const escapeLineStart = (line) => line.replace(/^(\s*)([#+-])(?=\s|#|$)/, "$1\\$2").replace(/^(\s*\d{1,9})([.)])(?=\s)/, "$1\\$2");
|
|
192
|
+
const DROP = new Set([
|
|
193
|
+
"SCRIPT",
|
|
194
|
+
"STYLE",
|
|
195
|
+
"TEMPLATE",
|
|
196
|
+
"IFRAME",
|
|
197
|
+
"OBJECT",
|
|
198
|
+
"EMBED",
|
|
199
|
+
"SVG",
|
|
200
|
+
"MATH",
|
|
201
|
+
"NOSCRIPT",
|
|
202
|
+
"HEAD",
|
|
203
|
+
"TITLE",
|
|
204
|
+
"META",
|
|
205
|
+
"LINK",
|
|
206
|
+
"BUTTON",
|
|
207
|
+
"INPUT",
|
|
208
|
+
"SELECT",
|
|
209
|
+
"TEXTAREA",
|
|
210
|
+
]);
|
|
211
|
+
const BLOCKS = new Set([
|
|
212
|
+
"P",
|
|
213
|
+
"DIV",
|
|
214
|
+
"H1",
|
|
215
|
+
"H2",
|
|
216
|
+
"H3",
|
|
217
|
+
"H4",
|
|
218
|
+
"H5",
|
|
219
|
+
"H6",
|
|
220
|
+
"UL",
|
|
221
|
+
"OL",
|
|
222
|
+
"LI",
|
|
223
|
+
"PRE",
|
|
224
|
+
"BLOCKQUOTE",
|
|
225
|
+
"SECTION",
|
|
226
|
+
"ARTICLE",
|
|
227
|
+
"HEADER",
|
|
228
|
+
"FOOTER",
|
|
229
|
+
"MAIN",
|
|
230
|
+
"TABLE",
|
|
231
|
+
"TR",
|
|
232
|
+
"BODY",
|
|
233
|
+
]);
|
|
234
|
+
function wrap(inner, mark) {
|
|
235
|
+
const m = /^(\s*)([\s\S]*?)(\s*)$/.exec(inner);
|
|
236
|
+
return m[2] ? `${m[1]}${mark}${m[2]}${mark}${m[3]}` : inner;
|
|
237
|
+
}
|
|
238
|
+
function codeSpan(text) {
|
|
239
|
+
if (!text)
|
|
240
|
+
return "";
|
|
241
|
+
const runs = text.match(/`+/g) ?? [];
|
|
242
|
+
const fence = "`".repeat(Math.max(0, ...runs.map((r) => r.length)) + 1);
|
|
243
|
+
return `${fence}${text}${fence}`;
|
|
244
|
+
}
|
|
245
|
+
function inlineMd(node) {
|
|
246
|
+
if (node.nodeType === 3)
|
|
247
|
+
return escapeText((node.nodeValue ?? "").replace(/ /g, " "));
|
|
248
|
+
if (node.nodeType !== 1)
|
|
249
|
+
return "";
|
|
250
|
+
const el = node;
|
|
251
|
+
const tag = el.tagName.toUpperCase();
|
|
252
|
+
if (DROP.has(tag))
|
|
253
|
+
return "";
|
|
254
|
+
if (tag === "BR")
|
|
255
|
+
return "\n";
|
|
256
|
+
if (el.hasAttribute("data-mention")) {
|
|
257
|
+
const id = el.getAttribute("data-user-id") ?? "";
|
|
258
|
+
const name = (el.textContent ?? "")
|
|
259
|
+
.replace(/^@/, "")
|
|
260
|
+
.replace(/[[\]\n]/g, "")
|
|
261
|
+
.slice(0, 100);
|
|
262
|
+
return /^[A-Za-z0-9_.:-]{1,80}$/.test(id) ? `@[${name || id}](user:${id})` : escapeText(name);
|
|
263
|
+
}
|
|
264
|
+
const inner = () => [...el.childNodes].map(inlineMd).join("");
|
|
265
|
+
switch (tag) {
|
|
266
|
+
case "B":
|
|
267
|
+
case "STRONG":
|
|
268
|
+
return wrap(inner(), "**");
|
|
269
|
+
case "I":
|
|
270
|
+
case "EM":
|
|
271
|
+
return wrap(inner(), "_");
|
|
272
|
+
case "CODE":
|
|
273
|
+
case "KBD":
|
|
274
|
+
case "SAMP":
|
|
275
|
+
return codeSpan(el.textContent ?? "");
|
|
276
|
+
case "A": {
|
|
277
|
+
const href = (el.getAttribute("href") ?? "").trim();
|
|
278
|
+
const text = inner();
|
|
279
|
+
if (!href || !isSafeUrl(href) || !text.trim())
|
|
280
|
+
return text;
|
|
281
|
+
return `[${text}](${href.replace(/[\s()<>]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`)})`;
|
|
282
|
+
}
|
|
283
|
+
default:
|
|
284
|
+
return inner();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function blocksMd(el, out) {
|
|
288
|
+
let para = "";
|
|
289
|
+
const flushPara = () => {
|
|
290
|
+
const text = para.replace(/^\n+|\n+$/g, "");
|
|
291
|
+
if (text.trim())
|
|
292
|
+
out.push(text
|
|
293
|
+
.split("\n")
|
|
294
|
+
.map((l) => escapeLineStart(l.trimEnd()))
|
|
295
|
+
.join("\n"));
|
|
296
|
+
para = "";
|
|
297
|
+
};
|
|
298
|
+
for (const child of [...el.childNodes]) {
|
|
299
|
+
const tag = child.nodeType === 1 ? child.tagName.toUpperCase() : "";
|
|
300
|
+
if (!BLOCKS.has(tag) || DROP.has(tag)) {
|
|
301
|
+
para += inlineMd(child);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
flushPara();
|
|
305
|
+
const c = child;
|
|
306
|
+
if (/^H[1-6]$/.test(tag)) {
|
|
307
|
+
const text = inlineMd(c).replace(/\n+/g, " ").trim();
|
|
308
|
+
if (text)
|
|
309
|
+
out.push(`${"#".repeat(Math.min(Number(tag[1]), 3))} ${text}`);
|
|
310
|
+
}
|
|
311
|
+
else if (tag === "UL" || tag === "OL") {
|
|
312
|
+
const lines = [];
|
|
313
|
+
listMd(c, 0, lines);
|
|
314
|
+
if (lines.length)
|
|
315
|
+
out.push(lines.join("\n"));
|
|
316
|
+
}
|
|
317
|
+
else if (tag === "PRE") {
|
|
318
|
+
const text = (c.textContent ?? "").replace(/\n$/, "");
|
|
319
|
+
const runs = text.match(/^`{3,}/gm) ?? [];
|
|
320
|
+
const fence = "`".repeat(Math.max(2, ...runs.map((r) => r.length)) + 1);
|
|
321
|
+
out.push(`${fence}\n${text}\n${fence}`);
|
|
322
|
+
}
|
|
323
|
+
else
|
|
324
|
+
blocksMd(c, out);
|
|
325
|
+
}
|
|
326
|
+
flushPara();
|
|
327
|
+
}
|
|
328
|
+
function listMd(list, depth, lines) {
|
|
329
|
+
const ordered = list.tagName.toUpperCase() === "OL";
|
|
330
|
+
let n = 0;
|
|
331
|
+
for (const li of [...list.children]) {
|
|
332
|
+
if (li.tagName.toUpperCase() !== "LI") {
|
|
333
|
+
if (/^(UL|OL)$/i.test(li.tagName))
|
|
334
|
+
listMd(li, depth + 1, lines);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
n++;
|
|
338
|
+
const nested = [];
|
|
339
|
+
const text = [...li.childNodes]
|
|
340
|
+
.map((c) => {
|
|
341
|
+
if (c.nodeType === 1 && /^(UL|OL)$/i.test(c.tagName)) {
|
|
342
|
+
nested.push(c);
|
|
343
|
+
return "";
|
|
344
|
+
}
|
|
345
|
+
if (c.nodeType === 1 && BLOCKS.has(c.tagName.toUpperCase()))
|
|
346
|
+
return ` ${inlineMd(c)} `;
|
|
347
|
+
return inlineMd(c);
|
|
348
|
+
})
|
|
349
|
+
.join("")
|
|
350
|
+
.replace(/\s*\n\s*/g, " ")
|
|
351
|
+
.trim();
|
|
352
|
+
lines.push(`${" ".repeat(depth)}${ordered ? `${n}.` : "-"} ${text}`);
|
|
353
|
+
for (const l of nested)
|
|
354
|
+
listMd(l, depth + 1, lines);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
export function elementToRichText(el) {
|
|
358
|
+
const out = [];
|
|
359
|
+
blocksMd(el, out);
|
|
360
|
+
return out.join("\n\n");
|
|
361
|
+
}
|
|
362
|
+
export function htmlToRichText(html) {
|
|
363
|
+
const doc = new DOMParser().parseFromString(String(html ?? ""), "text/html");
|
|
364
|
+
return elementToRichText(doc.body);
|
|
365
|
+
}
|
|
366
|
+
export const RICH_TEXT_CLASSES = cn("text-sm text-text-primary break-words", "[&_p]:my-2 [&_h1]:mt-4 [&_h1]:mb-2 [&_h1]:text-xl [&_h1]:font-semibold", "[&_h2]:mt-3 [&_h2]:mb-2 [&_h2]:text-lg [&_h2]:font-semibold [&_h3]:mt-3 [&_h3]:mb-1 [&_h3]:text-base [&_h3]:font-semibold", "[&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-5", "[&_code]:rounded [&_code]:bg-bg-elevated [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.9em]", "[&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-bg-elevated [&_pre]:p-3 [&_pre_code]:bg-transparent [&_pre_code]:p-0", "[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2", "[&_[data-mention]]:rounded [&_[data-mention]]:bg-accent-blue-subtle [&_[data-mention]]:px-1 [&_[data-mention]]:font-medium [&_[data-mention]]:text-accent-blue");
|
|
367
|
+
export function RichTextContent({ value, className, ...props }) {
|
|
368
|
+
const html = useMemo(() => richTextToHtml(value), [value]);
|
|
369
|
+
return (_jsx("div", { "data-slot": "rich-text-content", className: cn(RICH_TEXT_CLASSES, className), dangerouslySetInnerHTML: { __html: html }, ...props }));
|
|
370
|
+
}
|
|
371
|
+
export const DEFAULT_RICH_TEXT_LABELS = {
|
|
372
|
+
toolbar: "Formatting",
|
|
373
|
+
bold: "Bold",
|
|
374
|
+
italic: "Italic",
|
|
375
|
+
code: "Code",
|
|
376
|
+
link: "Link",
|
|
377
|
+
h2: "Heading",
|
|
378
|
+
h3: "Subheading",
|
|
379
|
+
ul: "Bulleted list",
|
|
380
|
+
ol: "Numbered list",
|
|
381
|
+
linkPrompt: "Link address",
|
|
382
|
+
mentionList: "People to mention",
|
|
383
|
+
noMatches: "No one matches",
|
|
384
|
+
};
|
|
385
|
+
const ALL_FORMATS = ["bold", "italic", "code", "link", "h2", "h3", "ul", "ol"];
|
|
386
|
+
const DEFAULT_ICONS = {
|
|
387
|
+
bold: _jsx("b", { children: "B" }),
|
|
388
|
+
italic: _jsx("i", { children: "I" }),
|
|
389
|
+
code: _jsx("code", { className: "font-mono", children: "</>" }),
|
|
390
|
+
link: _jsx("span", { className: "underline", children: "Link" }),
|
|
391
|
+
h2: "H2",
|
|
392
|
+
h3: "H3",
|
|
393
|
+
ul: "• List",
|
|
394
|
+
ol: "1. List",
|
|
395
|
+
};
|
|
396
|
+
const SHORTCUTS = { b: "bold", i: "italic", e: "code", k: "link" };
|
|
397
|
+
const SignetMention = Mention.extend({
|
|
398
|
+
parseHTML() {
|
|
399
|
+
return [{ tag: "span[data-mention]" }];
|
|
400
|
+
},
|
|
401
|
+
addAttributes() {
|
|
402
|
+
return {
|
|
403
|
+
...this.parent?.(),
|
|
404
|
+
id: {
|
|
405
|
+
default: null,
|
|
406
|
+
parseHTML: (el) => el.getAttribute("data-user-id"),
|
|
407
|
+
renderHTML: (a) => (a.id ? { "data-user-id": a.id } : {}),
|
|
408
|
+
},
|
|
409
|
+
label: {
|
|
410
|
+
default: null,
|
|
411
|
+
parseHTML: (el) => (el.textContent ?? "").replace(/^@/, ""),
|
|
412
|
+
renderHTML: () => ({}),
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
export function RichTextEditor({ value, defaultValue = "", onValueChange, onMentionSearch, onRequestLink, formats = ALL_FORMATS, placeholder, disabled = false, labels: labelsProp, icons = {}, className, classNames = {}, id, ...aria }) {
|
|
418
|
+
const labels = useMemo(() => ({ ...DEFAULT_RICH_TEXT_LABELS, ...labelsProp }), [labelsProp]);
|
|
419
|
+
const uid = useId();
|
|
420
|
+
const editorId = id ?? `${uid}-editor`;
|
|
421
|
+
const listId = `${uid}-mentions`;
|
|
422
|
+
const sent = useRef(value ?? defaultValue);
|
|
423
|
+
const [empty, setEmpty] = useState(!sent.current.trim());
|
|
424
|
+
const [focusIndex, setFocusIndex] = useState(0);
|
|
425
|
+
const [suggestion, setSuggestion] = useState(null);
|
|
426
|
+
const [highlight, setHighlight] = useState(0);
|
|
427
|
+
const live = useRef({ onValueChange, onMentionSearch, suggestion, highlight, formats });
|
|
428
|
+
live.current = { onValueChange, onMentionSearch, suggestion, highlight, formats };
|
|
429
|
+
const applyRef = useRef(() => undefined);
|
|
430
|
+
const appliedClasses = useRef([]);
|
|
431
|
+
const editor = useEditor({
|
|
432
|
+
editable: !disabled,
|
|
433
|
+
content: richTextToHtml(sent.current),
|
|
434
|
+
extensions: [
|
|
435
|
+
StarterKit.configure({
|
|
436
|
+
heading: { levels: [1, 2, 3] },
|
|
437
|
+
blockquote: false,
|
|
438
|
+
horizontalRule: false,
|
|
439
|
+
strike: false,
|
|
440
|
+
underline: false,
|
|
441
|
+
link: false,
|
|
442
|
+
}),
|
|
443
|
+
Link.configure({
|
|
444
|
+
openOnClick: false,
|
|
445
|
+
autolink: false,
|
|
446
|
+
protocols: ["mailto", "tel"],
|
|
447
|
+
isAllowedUri: (url) => isSafeUrl(url),
|
|
448
|
+
HTMLAttributes: { rel: "noopener noreferrer nofollow", target: null },
|
|
449
|
+
}),
|
|
450
|
+
SignetMention.configure({
|
|
451
|
+
HTMLAttributes: { "data-mention": "", contenteditable: "false" },
|
|
452
|
+
renderText: ({ node }) => `@${node.attrs.label ?? node.attrs.id}`,
|
|
453
|
+
renderHTML: ({ options, node }) => [
|
|
454
|
+
"span",
|
|
455
|
+
options.HTMLAttributes,
|
|
456
|
+
`@${node.attrs.label ?? node.attrs.id}`,
|
|
457
|
+
],
|
|
458
|
+
suggestion: {
|
|
459
|
+
char: "@",
|
|
460
|
+
items: async ({ query }) => {
|
|
461
|
+
const search = live.current.onMentionSearch;
|
|
462
|
+
if (!search)
|
|
463
|
+
return [];
|
|
464
|
+
try {
|
|
465
|
+
return await search(query);
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
return [];
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
allow: () => !!live.current.onMentionSearch,
|
|
472
|
+
render: () => ({
|
|
473
|
+
onStart: (p) => {
|
|
474
|
+
setSuggestion({ items: p.items, command: p.command });
|
|
475
|
+
setHighlight(0);
|
|
476
|
+
},
|
|
477
|
+
onUpdate: (p) => {
|
|
478
|
+
setSuggestion({ items: p.items, command: p.command });
|
|
479
|
+
setHighlight(0);
|
|
480
|
+
},
|
|
481
|
+
onKeyDown: ({ event }) => {
|
|
482
|
+
const s = live.current.suggestion;
|
|
483
|
+
if (!s)
|
|
484
|
+
return false;
|
|
485
|
+
if (event.key === "Escape") {
|
|
486
|
+
setSuggestion(null);
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
if (!s.items.length)
|
|
490
|
+
return false;
|
|
491
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
492
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
493
|
+
setHighlight((i) => (i + step + s.items.length) % s.items.length);
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
497
|
+
const p = s.items[live.current.highlight] ?? s.items[0];
|
|
498
|
+
if (p)
|
|
499
|
+
s.command({ id: p.id, label: p.name.replace(/[[\]\n]/g, "") });
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
},
|
|
504
|
+
onExit: () => setSuggestion(null),
|
|
505
|
+
}),
|
|
506
|
+
},
|
|
507
|
+
}),
|
|
508
|
+
],
|
|
509
|
+
editorProps: {
|
|
510
|
+
attributes: {
|
|
511
|
+
id: editorId,
|
|
512
|
+
role: "textbox",
|
|
513
|
+
"aria-multiline": "true",
|
|
514
|
+
"data-slot": "rich-text-content",
|
|
515
|
+
},
|
|
516
|
+
transformPastedHTML: (html) => richTextToHtml(htmlToRichText(html)),
|
|
517
|
+
handleKeyDown: (_view, event) => {
|
|
518
|
+
const f = (event.metaKey || event.ctrlKey) && !event.altKey
|
|
519
|
+
? SHORTCUTS[event.key.toLowerCase()]
|
|
520
|
+
: undefined;
|
|
521
|
+
if (f !== "link" || !live.current.formats.includes("link"))
|
|
522
|
+
return false;
|
|
523
|
+
event.preventDefault();
|
|
524
|
+
applyRef.current("link");
|
|
525
|
+
return true;
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
onUpdate: ({ editor: ed }) => {
|
|
529
|
+
const md = htmlToRichText(ed.getHTML());
|
|
530
|
+
setEmpty(ed.isEmpty);
|
|
531
|
+
if (md === sent.current)
|
|
532
|
+
return;
|
|
533
|
+
sent.current = md;
|
|
534
|
+
live.current.onValueChange?.(md);
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
useEffect(() => {
|
|
538
|
+
if (!editor || value === undefined || value === sent.current)
|
|
539
|
+
return;
|
|
540
|
+
sent.current = value;
|
|
541
|
+
editor.commands.setContent(richTextToHtml(value), { emitUpdate: false });
|
|
542
|
+
setEmpty(editor.isEmpty);
|
|
543
|
+
}, [editor, value]);
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
editor?.setEditable(!disabled);
|
|
546
|
+
}, [editor, disabled]);
|
|
547
|
+
const active = useEditorState({
|
|
548
|
+
editor,
|
|
549
|
+
selector: ({ editor: ed }) => {
|
|
550
|
+
const set = new Set();
|
|
551
|
+
if (!ed)
|
|
552
|
+
return set;
|
|
553
|
+
if (ed.isActive("bold"))
|
|
554
|
+
set.add("bold");
|
|
555
|
+
if (ed.isActive("italic"))
|
|
556
|
+
set.add("italic");
|
|
557
|
+
if (ed.isActive("code"))
|
|
558
|
+
set.add("code");
|
|
559
|
+
if (ed.isActive("link"))
|
|
560
|
+
set.add("link");
|
|
561
|
+
if (ed.isActive("heading", { level: 1 }) || ed.isActive("heading", { level: 2 }))
|
|
562
|
+
set.add("h2");
|
|
563
|
+
if (ed.isActive("heading", { level: 3 }))
|
|
564
|
+
set.add("h3");
|
|
565
|
+
if (ed.isActive("bulletList"))
|
|
566
|
+
set.add("ul");
|
|
567
|
+
if (ed.isActive("orderedList"))
|
|
568
|
+
set.add("ol");
|
|
569
|
+
return set;
|
|
570
|
+
},
|
|
571
|
+
equalityFn: (a, b) => !!a && !!b && a.size === b.size && [...a].every((f) => b.has(f)),
|
|
572
|
+
}) ?? new Set();
|
|
573
|
+
const apply = async (f) => {
|
|
574
|
+
if (!editor || disabled)
|
|
575
|
+
return;
|
|
576
|
+
const chain = editor.chain().focus();
|
|
577
|
+
if (f === "bold")
|
|
578
|
+
chain.toggleBold().run();
|
|
579
|
+
else if (f === "italic")
|
|
580
|
+
chain.toggleItalic().run();
|
|
581
|
+
else if (f === "code")
|
|
582
|
+
chain.toggleCode().run();
|
|
583
|
+
else if (f === "h2")
|
|
584
|
+
chain.toggleHeading({ level: 2 }).run();
|
|
585
|
+
else if (f === "h3")
|
|
586
|
+
chain.toggleHeading({ level: 3 }).run();
|
|
587
|
+
else if (f === "ul")
|
|
588
|
+
chain.toggleBulletList().run();
|
|
589
|
+
else if (f === "ol")
|
|
590
|
+
chain.toggleOrderedList().run();
|
|
591
|
+
else if (f === "link") {
|
|
592
|
+
const current = editor.getAttributes("link").href ?? "";
|
|
593
|
+
const ask = onRequestLink ?? ((cur) => window.prompt(labels.linkPrompt, cur));
|
|
594
|
+
const url = (await ask(current))?.trim();
|
|
595
|
+
if (url === undefined)
|
|
596
|
+
return;
|
|
597
|
+
if (url === "")
|
|
598
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
599
|
+
else if (isSafeUrl(url)) {
|
|
600
|
+
if (editor.state.selection.empty && !editor.isActive("link"))
|
|
601
|
+
editor
|
|
602
|
+
.chain()
|
|
603
|
+
.focus()
|
|
604
|
+
.insertContent({
|
|
605
|
+
type: "text",
|
|
606
|
+
text: url,
|
|
607
|
+
marks: [{ type: "link", attrs: { href: url } }],
|
|
608
|
+
})
|
|
609
|
+
.run();
|
|
610
|
+
else
|
|
611
|
+
editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
applyRef.current = (f) => void apply(f);
|
|
616
|
+
const open = !!suggestion && !!onMentionSearch;
|
|
617
|
+
useEffect(() => {
|
|
618
|
+
const dom = editor?.view.dom;
|
|
619
|
+
if (!dom)
|
|
620
|
+
return;
|
|
621
|
+
const set = (k, v) => v === undefined ? dom.removeAttribute(k) : dom.setAttribute(k, v);
|
|
622
|
+
set("aria-label", aria["aria-label"]);
|
|
623
|
+
set("aria-labelledby", aria["aria-labelledby"]);
|
|
624
|
+
set("aria-describedby", aria["aria-describedby"]);
|
|
625
|
+
set("aria-placeholder", placeholder);
|
|
626
|
+
set("aria-disabled", disabled ? "true" : undefined);
|
|
627
|
+
set("aria-autocomplete", onMentionSearch ? "list" : undefined);
|
|
628
|
+
set("aria-controls", open ? listId : undefined);
|
|
629
|
+
set("aria-activedescendant", open && suggestion?.items[highlight] ? `${listId}-${highlight}` : undefined);
|
|
630
|
+
set("data-placeholder", placeholder);
|
|
631
|
+
set("data-empty", empty ? "true" : undefined);
|
|
632
|
+
const next = cn(RICH_TEXT_CLASSES, "relative min-h-24 px-3 py-2 outline-none", "data-empty:before:pointer-events-none data-empty:before:absolute data-empty:before:text-text-muted data-empty:before:content-[attr(data-placeholder)]", classNames.content)
|
|
633
|
+
.split(/\s+/)
|
|
634
|
+
.filter(Boolean);
|
|
635
|
+
const stale = appliedClasses.current.filter((c) => !next.includes(c));
|
|
636
|
+
if (stale.length)
|
|
637
|
+
dom.classList.remove(...stale);
|
|
638
|
+
dom.classList.add(...next);
|
|
639
|
+
appliedClasses.current = next;
|
|
640
|
+
});
|
|
641
|
+
const onToolbarKeyDown = (e) => {
|
|
642
|
+
const step = e.key === "ArrowRight"
|
|
643
|
+
? 1
|
|
644
|
+
: e.key === "ArrowLeft"
|
|
645
|
+
? -1
|
|
646
|
+
: e.key === "Home"
|
|
647
|
+
? -999
|
|
648
|
+
: e.key === "End"
|
|
649
|
+
? 999
|
|
650
|
+
: 0;
|
|
651
|
+
if (!step)
|
|
652
|
+
return;
|
|
653
|
+
e.preventDefault();
|
|
654
|
+
const next = Math.max(0, Math.min(formats.length - 1, focusIndex + step));
|
|
655
|
+
setFocusIndex(next);
|
|
656
|
+
e.currentTarget.querySelectorAll("button")[next]?.focus();
|
|
657
|
+
};
|
|
658
|
+
return (_jsxs("div", { "data-slot": "rich-text-editor", "data-disabled": disabled || undefined, className: cn("relative flex flex-col rounded-lg border border-border-default bg-bg-surface focus-within:border-ring data-disabled:opacity-60", classNames.root, className), children: [_jsx("div", { role: "toolbar", "aria-label": labels.toolbar, "aria-controls": editorId, "data-slot": "rich-text-toolbar", onKeyDown: onToolbarKeyDown, className: cn("flex flex-wrap gap-0.5 border-b border-border-default p-1", classNames.toolbar), children: formats.map((f, i) => {
|
|
659
|
+
const pressed = active.has(f);
|
|
660
|
+
return (_jsx("button", { type: "button", "aria-label": labels[f], "aria-pressed": f === "link" ? undefined : pressed, title: labels[f], tabIndex: i === focusIndex ? 0 : -1, disabled: disabled, "data-slot": "rich-text-button", "data-format": f, "data-active": pressed || undefined, onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
661
|
+
setFocusIndex(i);
|
|
662
|
+
void apply(f);
|
|
663
|
+
}, className: cn("inline-flex h-7 min-w-7 items-center justify-center rounded-md px-1.5 text-xs text-text-secondary outline-none", "hover:bg-bg-elevated hover:text-text-primary focus-visible:ring-2 focus-visible:ring-ring", "data-active:bg-bg-elevated data-active:text-text-primary", classNames.button), children: icons[f] ?? DEFAULT_ICONS[f] }, f));
|
|
664
|
+
}) }), _jsx(EditorContent, { editor: editor, className: "relative" }), open && (_jsx("div", { id: listId, role: "listbox", "aria-label": labels.mentionList, "data-slot": "rich-text-mentions", className: cn("absolute top-full left-2 z-50 mt-1 max-h-56 w-64 overflow-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-border-default", classNames.mentions), children: suggestion.items.length === 0 ? (_jsx("div", { className: "px-2 py-1.5 text-sm text-text-muted", children: labels.noMatches })) : (suggestion.items.map((p, i) => (_jsxs("div", { id: `${listId}-${i}`, role: "option", "aria-selected": i === highlight, "data-slot": "rich-text-option", "data-highlighted": i === highlight ? "" : undefined, onMouseDown: (e) => {
|
|
665
|
+
e.preventDefault();
|
|
666
|
+
suggestion.command({ id: p.id, label: p.name.replace(/[[\]\n]/g, "") });
|
|
667
|
+
}, className: cn("flex cursor-default items-center gap-2 rounded-md px-2 py-1.5 text-sm data-highlighted:bg-bg-elevated", classNames.option), children: [_jsx("span", { className: "truncate", children: p.name }), p.email && _jsx("span", { className: "truncate text-xs text-text-muted", children: p.email })] }, p.id)))) }))] }));
|
|
668
|
+
}
|
|
669
|
+
//# sourceMappingURL=rich-text-editor.js.map
|