@designa8/vibedesign-linear-internal-v1-b737 0.2.0 → 0.4.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 +1 -1
- package/dist/index.cjs +1998 -1492
- package/dist/index.js +2075 -1569
- package/dist/styles.css +56 -0
- package/package.json +11 -1
- package/src/atoms/AttachmentChip/AttachmentChip.tsx +126 -0
- package/src/atoms/AttachmentChip/index.ts +2 -0
- package/src/atoms/AttachmentChip/preview.tsx +144 -0
- package/src/atoms/CodeEditor/CodeEditor.tsx +497 -0
- package/src/atoms/CodeEditor/index.ts +6 -0
- package/src/atoms/CodeEditor/preview.tsx +135 -0
- package/src/atoms/Icon/icons.data.ts +1 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Badge } from "../Badge";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
import { Textarea } from "../Textarea";
|
|
6
|
+
|
|
7
|
+
export type CodeEditorLanguage = "tsx" | "ts" | "css" | "json" | "md" | "txt";
|
|
8
|
+
|
|
9
|
+
export interface CodeEditorFile {
|
|
10
|
+
name: string;
|
|
11
|
+
language: CodeEditorLanguage;
|
|
12
|
+
source: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CodeEditorProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
16
|
+
files: CodeEditorFile[];
|
|
17
|
+
/** Name of the visible file. Falls back to the first file. */
|
|
18
|
+
activeFile?: string;
|
|
19
|
+
onActiveFileChange?: (name: string) => void;
|
|
20
|
+
/** Label of the collapsible folder row in the file tree. */
|
|
21
|
+
folderLabel?: string;
|
|
22
|
+
/** Leading breadcrumb segment, e.g. `atoms / Button`. */
|
|
23
|
+
pathPrefix?: string;
|
|
24
|
+
/** Sets `data-theme="dark"` on the editor root so tokens flip locally. */
|
|
25
|
+
dark?: boolean;
|
|
26
|
+
/** Read-only viewer. Set false to render an editable textarea instead. */
|
|
27
|
+
readOnly?: boolean;
|
|
28
|
+
/** File names currently being written; the status pill shows "Writing". */
|
|
29
|
+
streamingFileNames?: string[];
|
|
30
|
+
onChange?: (filename: string, source: string) => void;
|
|
31
|
+
onCopy?: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const LANG_LABEL: Record<CodeEditorLanguage, string> = {
|
|
35
|
+
tsx: "TSX",
|
|
36
|
+
ts: "TS",
|
|
37
|
+
css: "CSS",
|
|
38
|
+
json: "JSON",
|
|
39
|
+
md: "MD",
|
|
40
|
+
txt: "TXT",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
44
|
+
parts.filter(Boolean).join(" ");
|
|
45
|
+
|
|
46
|
+
function LangBadge({ language }: { language: CodeEditorLanguage }) {
|
|
47
|
+
return (
|
|
48
|
+
<Badge size="sm" tone={language === "tsx" ? "primary" : "neutral"} className="w-8 justify-center font-mono">
|
|
49
|
+
{LANG_LABEL[language]}
|
|
50
|
+
</Badge>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type SyntaxTokenType =
|
|
55
|
+
| "plain"
|
|
56
|
+
| "comment"
|
|
57
|
+
| "string"
|
|
58
|
+
| "number"
|
|
59
|
+
| "keyword"
|
|
60
|
+
| "function"
|
|
61
|
+
| "type"
|
|
62
|
+
| "tag"
|
|
63
|
+
| "property"
|
|
64
|
+
| "punctuation";
|
|
65
|
+
|
|
66
|
+
const SYNTAX_CLASS: Record<SyntaxTokenType, string> = {
|
|
67
|
+
plain: "text-ink",
|
|
68
|
+
comment: "text-muted-soft italic",
|
|
69
|
+
string: "text-semantic-success",
|
|
70
|
+
number: "text-semantic-warning",
|
|
71
|
+
keyword: "text-primary",
|
|
72
|
+
function: "text-semantic-info",
|
|
73
|
+
type: "text-semantic-info",
|
|
74
|
+
tag: "text-semantic-error",
|
|
75
|
+
property: "text-primary",
|
|
76
|
+
punctuation: "text-muted",
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type SyntaxToken = { text: string; type: SyntaxTokenType };
|
|
80
|
+
|
|
81
|
+
const JS_KEYWORDS = new Set([
|
|
82
|
+
"import",
|
|
83
|
+
"export",
|
|
84
|
+
"default",
|
|
85
|
+
"from",
|
|
86
|
+
"const",
|
|
87
|
+
"let",
|
|
88
|
+
"var",
|
|
89
|
+
"function",
|
|
90
|
+
"return",
|
|
91
|
+
"interface",
|
|
92
|
+
"type",
|
|
93
|
+
"extends",
|
|
94
|
+
"implements",
|
|
95
|
+
"class",
|
|
96
|
+
"new",
|
|
97
|
+
"this",
|
|
98
|
+
"if",
|
|
99
|
+
"else",
|
|
100
|
+
"for",
|
|
101
|
+
"while",
|
|
102
|
+
"switch",
|
|
103
|
+
"case",
|
|
104
|
+
"break",
|
|
105
|
+
"continue",
|
|
106
|
+
"true",
|
|
107
|
+
"false",
|
|
108
|
+
"null",
|
|
109
|
+
"undefined",
|
|
110
|
+
"void",
|
|
111
|
+
"async",
|
|
112
|
+
"await",
|
|
113
|
+
"of",
|
|
114
|
+
"in",
|
|
115
|
+
"as",
|
|
116
|
+
"public",
|
|
117
|
+
"private",
|
|
118
|
+
"protected",
|
|
119
|
+
"readonly",
|
|
120
|
+
"static",
|
|
121
|
+
"enum",
|
|
122
|
+
"namespace",
|
|
123
|
+
"declare",
|
|
124
|
+
"try",
|
|
125
|
+
"catch",
|
|
126
|
+
"finally",
|
|
127
|
+
"throw",
|
|
128
|
+
"yield",
|
|
129
|
+
"typeof",
|
|
130
|
+
"instanceof",
|
|
131
|
+
"super",
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
const TS_TYPES = new Set([
|
|
135
|
+
"string",
|
|
136
|
+
"number",
|
|
137
|
+
"boolean",
|
|
138
|
+
"any",
|
|
139
|
+
"unknown",
|
|
140
|
+
"never",
|
|
141
|
+
"object",
|
|
142
|
+
"React",
|
|
143
|
+
"Record",
|
|
144
|
+
"Partial",
|
|
145
|
+
"Readonly",
|
|
146
|
+
"Promise",
|
|
147
|
+
"HTMLDivElement",
|
|
148
|
+
"HTMLButtonElement",
|
|
149
|
+
"HTMLTextAreaElement",
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
const JS_TOKEN_RE =
|
|
153
|
+
/(\/\/.*)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(\b\d+(?:\.\d+)?\b)|(<\/?[A-Za-z][\w.]*)|([A-Za-z_$][\w$]*)/g;
|
|
154
|
+
|
|
155
|
+
function tokenizeJs(line: string): SyntaxToken[] {
|
|
156
|
+
const tokens: SyntaxToken[] = [];
|
|
157
|
+
let lastIndex = 0;
|
|
158
|
+
let match: RegExpExecArray | null;
|
|
159
|
+
JS_TOKEN_RE.lastIndex = 0;
|
|
160
|
+
while ((match = JS_TOKEN_RE.exec(line)) !== null) {
|
|
161
|
+
if (match.index > lastIndex) {
|
|
162
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
163
|
+
}
|
|
164
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], type: "comment" });
|
|
165
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], type: "string" });
|
|
166
|
+
else if (match[3] !== undefined) tokens.push({ text: match[3], type: "number" });
|
|
167
|
+
else if (match[4] !== undefined) tokens.push({ text: match[4], type: "tag" });
|
|
168
|
+
else if (match[5] !== undefined) {
|
|
169
|
+
const word = match[5];
|
|
170
|
+
const isCall = /^\s*\(/.test(line.slice(JS_TOKEN_RE.lastIndex));
|
|
171
|
+
if (JS_KEYWORDS.has(word)) tokens.push({ text: word, type: "keyword" });
|
|
172
|
+
else if (TS_TYPES.has(word)) tokens.push({ text: word, type: "type" });
|
|
173
|
+
else if (isCall) tokens.push({ text: word, type: "function" });
|
|
174
|
+
else tokens.push({ text: word, type: "plain" });
|
|
175
|
+
}
|
|
176
|
+
lastIndex = JS_TOKEN_RE.lastIndex;
|
|
177
|
+
}
|
|
178
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
179
|
+
return tokens;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const CSS_TOKEN_RE =
|
|
183
|
+
/(\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|(@[a-zA-Z-]+)|(#[0-9a-fA-F]{3,8}\b)|(-?\d+\.?\d*(?:px|em|rem|%|deg|s|ms|vh|vw)?\b)|([a-zA-Z-]+)(?=\s*:)/g;
|
|
184
|
+
|
|
185
|
+
function tokenizeCss(line: string): SyntaxToken[] {
|
|
186
|
+
const tokens: SyntaxToken[] = [];
|
|
187
|
+
let lastIndex = 0;
|
|
188
|
+
let match: RegExpExecArray | null;
|
|
189
|
+
CSS_TOKEN_RE.lastIndex = 0;
|
|
190
|
+
while ((match = CSS_TOKEN_RE.exec(line)) !== null) {
|
|
191
|
+
if (match.index > lastIndex) {
|
|
192
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
193
|
+
}
|
|
194
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], type: "comment" });
|
|
195
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], type: "string" });
|
|
196
|
+
else if (match[3] !== undefined) tokens.push({ text: match[3], type: "keyword" });
|
|
197
|
+
else if (match[4] !== undefined) tokens.push({ text: match[4], type: "number" });
|
|
198
|
+
else if (match[5] !== undefined) tokens.push({ text: match[5], type: "number" });
|
|
199
|
+
else if (match[6] !== undefined) tokens.push({ text: match[6], type: "property" });
|
|
200
|
+
lastIndex = CSS_TOKEN_RE.lastIndex;
|
|
201
|
+
}
|
|
202
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
203
|
+
return tokens;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const JSON_TOKEN_RE = /("(?:\\.|[^"\\])*")(\s*:)?|(-?\d+(?:\.\d+)?)|\b(true|false|null)\b/g;
|
|
207
|
+
|
|
208
|
+
function tokenizeJson(line: string): SyntaxToken[] {
|
|
209
|
+
const tokens: SyntaxToken[] = [];
|
|
210
|
+
let lastIndex = 0;
|
|
211
|
+
let match: RegExpExecArray | null;
|
|
212
|
+
JSON_TOKEN_RE.lastIndex = 0;
|
|
213
|
+
while ((match = JSON_TOKEN_RE.exec(line)) !== null) {
|
|
214
|
+
if (match.index > lastIndex) {
|
|
215
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
216
|
+
}
|
|
217
|
+
if (match[1] !== undefined) {
|
|
218
|
+
const hasColon = match[2] !== undefined;
|
|
219
|
+
tokens.push({ text: match[1], type: hasColon ? "property" : "string" });
|
|
220
|
+
if (match[2]) tokens.push({ text: match[2], type: "punctuation" });
|
|
221
|
+
} else if (match[3] !== undefined) tokens.push({ text: match[3], type: "number" });
|
|
222
|
+
else if (match[4] !== undefined) tokens.push({ text: match[4], type: "keyword" });
|
|
223
|
+
lastIndex = JSON_TOKEN_RE.lastIndex;
|
|
224
|
+
}
|
|
225
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
226
|
+
return tokens;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const MD_TOKEN_RE = /(^#{1,6}\s.*)|(`[^`]*`)/g;
|
|
230
|
+
|
|
231
|
+
function tokenizeMd(line: string): SyntaxToken[] {
|
|
232
|
+
const tokens: SyntaxToken[] = [];
|
|
233
|
+
let lastIndex = 0;
|
|
234
|
+
let match: RegExpExecArray | null;
|
|
235
|
+
MD_TOKEN_RE.lastIndex = 0;
|
|
236
|
+
while ((match = MD_TOKEN_RE.exec(line)) !== null) {
|
|
237
|
+
if (match.index > lastIndex) {
|
|
238
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
239
|
+
}
|
|
240
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], type: "keyword" });
|
|
241
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], type: "string" });
|
|
242
|
+
lastIndex = MD_TOKEN_RE.lastIndex;
|
|
243
|
+
}
|
|
244
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
245
|
+
return tokens;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function tokenizeLine(line: string, language: CodeEditorLanguage): SyntaxToken[] {
|
|
249
|
+
if (line.length === 0) return [{ text: " ", type: "plain" }];
|
|
250
|
+
switch (language) {
|
|
251
|
+
case "tsx":
|
|
252
|
+
case "ts":
|
|
253
|
+
return tokenizeJs(line);
|
|
254
|
+
case "css":
|
|
255
|
+
return tokenizeCss(line);
|
|
256
|
+
case "json":
|
|
257
|
+
return tokenizeJson(line);
|
|
258
|
+
case "md":
|
|
259
|
+
return tokenizeMd(line);
|
|
260
|
+
default:
|
|
261
|
+
return [{ text: line, type: "plain" }];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export const CodeEditor = React.forwardRef<HTMLDivElement, CodeEditorProps>(
|
|
266
|
+
(
|
|
267
|
+
{
|
|
268
|
+
files,
|
|
269
|
+
activeFile,
|
|
270
|
+
onActiveFileChange,
|
|
271
|
+
folderLabel = "atoms",
|
|
272
|
+
pathPrefix,
|
|
273
|
+
dark = false,
|
|
274
|
+
readOnly = true,
|
|
275
|
+
streamingFileNames,
|
|
276
|
+
onChange,
|
|
277
|
+
onCopy,
|
|
278
|
+
className,
|
|
279
|
+
...rest
|
|
280
|
+
},
|
|
281
|
+
ref,
|
|
282
|
+
) => {
|
|
283
|
+
const [copied, setCopied] = React.useState(false);
|
|
284
|
+
const [openRoot, setOpenRoot] = React.useState(true);
|
|
285
|
+
const timer = React.useRef<number | undefined>(undefined);
|
|
286
|
+
const tabRefs = React.useRef<Array<HTMLButtonElement | null>>([]);
|
|
287
|
+
const baseId = React.useId();
|
|
288
|
+
|
|
289
|
+
const current = files.find((f) => f.name === activeFile) ?? files[0] ?? null;
|
|
290
|
+
const streaming = Boolean(current && streamingFileNames?.includes(current.name));
|
|
291
|
+
const activeIndex = Math.max(
|
|
292
|
+
0,
|
|
293
|
+
files.findIndex((f) => f.name === current?.name),
|
|
294
|
+
);
|
|
295
|
+
const editable = !readOnly && !streaming;
|
|
296
|
+
|
|
297
|
+
const path = [pathPrefix ?? folderLabel, current?.name].filter(Boolean).join(" / ");
|
|
298
|
+
const statusLabel = streaming ? "Writing" : readOnly ? "Read-only" : "Editing";
|
|
299
|
+
const lines = (current?.source ?? "").split("\n");
|
|
300
|
+
|
|
301
|
+
React.useEffect(() => {
|
|
302
|
+
setCopied(false);
|
|
303
|
+
}, [current?.name]);
|
|
304
|
+
|
|
305
|
+
React.useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
306
|
+
|
|
307
|
+
async function copy() {
|
|
308
|
+
if (!current) return;
|
|
309
|
+
try {
|
|
310
|
+
await navigator.clipboard.writeText(current.source);
|
|
311
|
+
} catch {
|
|
312
|
+
/* Clipboard can be unavailable in sandboxed previews. */
|
|
313
|
+
}
|
|
314
|
+
setCopied(true);
|
|
315
|
+
window.clearTimeout(timer.current);
|
|
316
|
+
timer.current = window.setTimeout(() => setCopied(false), 1200);
|
|
317
|
+
onCopy?.();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function onTabKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
|
|
321
|
+
if (files.length === 0) return;
|
|
322
|
+
let next = activeIndex;
|
|
323
|
+
if (event.key === "ArrowDown") next = (activeIndex + 1) % files.length;
|
|
324
|
+
else if (event.key === "ArrowUp") next = (activeIndex - 1 + files.length) % files.length;
|
|
325
|
+
else if (event.key === "Home") next = 0;
|
|
326
|
+
else if (event.key === "End") next = files.length - 1;
|
|
327
|
+
else return;
|
|
328
|
+
event.preventDefault();
|
|
329
|
+
onActiveFileChange?.(files[next].name);
|
|
330
|
+
tabRefs.current[next]?.focus();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<div
|
|
335
|
+
ref={ref}
|
|
336
|
+
data-theme={dark ? "dark" : undefined}
|
|
337
|
+
className={cn(
|
|
338
|
+
"flex w-full min-h-0 overflow-hidden rounded-lg border border-hairline bg-canvas text-ink",
|
|
339
|
+
className,
|
|
340
|
+
)}
|
|
341
|
+
{...rest}
|
|
342
|
+
>
|
|
343
|
+
<aside className="flex w-56 min-h-0 shrink-0 flex-col overflow-y-auto overscroll-contain border-r border-hairline bg-canvas">
|
|
344
|
+
<div className="flex items-center px-base py-md">
|
|
345
|
+
<span className="text-overline text-muted-soft">Files</span>
|
|
346
|
+
</div>
|
|
347
|
+
<nav className="flex flex-col gap-xxs px-sm pb-base" aria-label="Files">
|
|
348
|
+
<Button
|
|
349
|
+
type="button"
|
|
350
|
+
variant="item"
|
|
351
|
+
size="sm"
|
|
352
|
+
aria-expanded={openRoot}
|
|
353
|
+
aria-controls={`${baseId}-files`}
|
|
354
|
+
className="text-muted"
|
|
355
|
+
leadingIcon={
|
|
356
|
+
<Icon
|
|
357
|
+
name="chevron-down"
|
|
358
|
+
size={12}
|
|
359
|
+
className={cn(
|
|
360
|
+
"transition-transform duration-200 ease-out",
|
|
361
|
+
openRoot ? "rotate-0" : "-rotate-90",
|
|
362
|
+
)}
|
|
363
|
+
/>
|
|
364
|
+
}
|
|
365
|
+
onClick={() => setOpenRoot((open) => !open)}
|
|
366
|
+
>
|
|
367
|
+
{folderLabel}
|
|
368
|
+
</Button>
|
|
369
|
+
|
|
370
|
+
<div
|
|
371
|
+
data-state={openRoot ? "open" : "closed"}
|
|
372
|
+
className="grid transition-[grid-template-rows] duration-200 ease-out data-[state=open]:grid-rows-[1fr] data-[state=closed]:grid-rows-[0fr]"
|
|
373
|
+
>
|
|
374
|
+
<div className="min-h-0 overflow-hidden">
|
|
375
|
+
<div
|
|
376
|
+
id={`${baseId}-files`}
|
|
377
|
+
role="tablist"
|
|
378
|
+
aria-label={folderLabel}
|
|
379
|
+
aria-orientation="vertical"
|
|
380
|
+
onKeyDown={onTabKeyDown}
|
|
381
|
+
className="flex flex-col gap-xxs pt-xxs"
|
|
382
|
+
>
|
|
383
|
+
{files.map((file, index) => {
|
|
384
|
+
const active = file.name === current?.name;
|
|
385
|
+
return (
|
|
386
|
+
<Button
|
|
387
|
+
key={file.name}
|
|
388
|
+
ref={(el) => {
|
|
389
|
+
tabRefs.current[index] = el;
|
|
390
|
+
}}
|
|
391
|
+
role="tab"
|
|
392
|
+
id={`${baseId}-tab-${index}`}
|
|
393
|
+
aria-selected={active}
|
|
394
|
+
aria-controls={`${baseId}-panel`}
|
|
395
|
+
tabIndex={openRoot && active ? 0 : -1}
|
|
396
|
+
type="button"
|
|
397
|
+
variant="item"
|
|
398
|
+
size="sm"
|
|
399
|
+
className="cursor-pointer transition duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue focus-visible:ring-inset"
|
|
400
|
+
leadingIcon={<LangBadge language={file.language} />}
|
|
401
|
+
onClick={() => onActiveFileChange?.(file.name)}
|
|
402
|
+
>
|
|
403
|
+
{file.name}
|
|
404
|
+
</Button>
|
|
405
|
+
);
|
|
406
|
+
})}
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
</div>
|
|
410
|
+
</nav>
|
|
411
|
+
</aside>
|
|
412
|
+
|
|
413
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-canvas">
|
|
414
|
+
<div className="flex items-center justify-between gap-sm border-b border-hairline bg-surface-soft px-base py-sm">
|
|
415
|
+
<div className="flex min-w-0 items-center gap-sm">
|
|
416
|
+
{current ? <LangBadge language={current.language} /> : null}
|
|
417
|
+
<span className="min-w-0 truncate font-mono text-caption text-muted">
|
|
418
|
+
{path || "No file selected"}
|
|
419
|
+
</span>
|
|
420
|
+
<span aria-live="polite">
|
|
421
|
+
<Badge size="sm" tone={streaming ? "primary" : "neutral"} className="uppercase">
|
|
422
|
+
{statusLabel}
|
|
423
|
+
</Badge>
|
|
424
|
+
</span>
|
|
425
|
+
</div>
|
|
426
|
+
<Button
|
|
427
|
+
type="button"
|
|
428
|
+
variant="secondary"
|
|
429
|
+
size="sm"
|
|
430
|
+
leadingIcon={<Icon name={copied ? "check" : "copy"} size={12} />}
|
|
431
|
+
onClick={() => void copy()}
|
|
432
|
+
disabled={!current || streaming}
|
|
433
|
+
>
|
|
434
|
+
{copied ? "Copied" : "Copy"}
|
|
435
|
+
</Button>
|
|
436
|
+
</div>
|
|
437
|
+
|
|
438
|
+
<div
|
|
439
|
+
id={`${baseId}-panel`}
|
|
440
|
+
role="tabpanel"
|
|
441
|
+
aria-labelledby={`${baseId}-tab-${activeIndex}`}
|
|
442
|
+
tabIndex={0}
|
|
443
|
+
className="min-h-0 flex-1 overflow-auto overscroll-contain bg-canvas focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
444
|
+
>
|
|
445
|
+
{editable ? (
|
|
446
|
+
<div className="flex min-h-full">
|
|
447
|
+
<div
|
|
448
|
+
className="shrink-0 select-none py-sm pl-base pr-md text-right text-body-sm text-muted-soft"
|
|
449
|
+
aria-hidden="true"
|
|
450
|
+
>
|
|
451
|
+
{lines.map((_, index) => (
|
|
452
|
+
<div key={index}>{index + 1}</div>
|
|
453
|
+
))}
|
|
454
|
+
</div>
|
|
455
|
+
<Textarea
|
|
456
|
+
chrome="none"
|
|
457
|
+
resizable={false}
|
|
458
|
+
rows={Math.min(Math.max(lines.length, 4), 24)}
|
|
459
|
+
aria-label={`${current?.name ?? "file"} source`}
|
|
460
|
+
spellCheck={false}
|
|
461
|
+
value={current?.source ?? ""}
|
|
462
|
+
onChange={(event) => {
|
|
463
|
+
if (current) onChange?.(current.name, event.target.value);
|
|
464
|
+
}}
|
|
465
|
+
className="min-h-full flex-1 font-mono text-body-sm"
|
|
466
|
+
/>
|
|
467
|
+
</div>
|
|
468
|
+
) : (
|
|
469
|
+
<pre className="m-0 min-h-full bg-canvas p-0 text-body-sm">
|
|
470
|
+
{lines.map((line, index) => (
|
|
471
|
+
<div key={index} className="flex">
|
|
472
|
+
<span
|
|
473
|
+
className="w-10 shrink-0 select-none pl-base pr-sm text-right text-body-sm text-muted-soft"
|
|
474
|
+
aria-hidden="true"
|
|
475
|
+
>
|
|
476
|
+
{index + 1}
|
|
477
|
+
</span>
|
|
478
|
+
<span className="flex-1 whitespace-pre pr-base font-mono">
|
|
479
|
+
{current
|
|
480
|
+
? tokenizeLine(line, current.language).map((token, ti) => (
|
|
481
|
+
<span key={ti} className={SYNTAX_CLASS[token.type]}>
|
|
482
|
+
{token.text}
|
|
483
|
+
</span>
|
|
484
|
+
))
|
|
485
|
+
: line || " "}
|
|
486
|
+
</span>
|
|
487
|
+
</div>
|
|
488
|
+
))}
|
|
489
|
+
</pre>
|
|
490
|
+
)}
|
|
491
|
+
</div>
|
|
492
|
+
</div>
|
|
493
|
+
</div>
|
|
494
|
+
);
|
|
495
|
+
},
|
|
496
|
+
);
|
|
497
|
+
CodeEditor.displayName = "CodeEditor";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { CodeEditor, type CodeEditorFile } from "./CodeEditor";
|
|
3
|
+
|
|
4
|
+
const SHELL_TSX = `import * as React from "react";
|
|
5
|
+
|
|
6
|
+
export interface CardShellProps {
|
|
7
|
+
title: string;
|
|
8
|
+
count?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Composed panel used across the gallery.
|
|
12
|
+
export const CardShell = ({ title, count = 0 }: CardShellProps) => {
|
|
13
|
+
const label = \`\${title} (\${count})\`;
|
|
14
|
+
return (
|
|
15
|
+
<div className="rounded-lg border border-hairline p-base">
|
|
16
|
+
<header>{label}</header>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
CardShell.displayName = "CardShell";`;
|
|
21
|
+
|
|
22
|
+
const TOKENS_CSS = `/* Generated from the token source of truth. */
|
|
23
|
+
:root {
|
|
24
|
+
--color-primary: var(--brand-core);
|
|
25
|
+
--color-canvas: var(--neutral-0);
|
|
26
|
+
--radius-md: 8px;
|
|
27
|
+
--space-md: 12px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-theme="dark"] {
|
|
31
|
+
--color-canvas: var(--neutral-1000);
|
|
32
|
+
--color-primary: var(--brand-core-light);
|
|
33
|
+
}`;
|
|
34
|
+
|
|
35
|
+
const MANIFEST_JSON = `{
|
|
36
|
+
"name": "atoms",
|
|
37
|
+
"version": "2.4.0",
|
|
38
|
+
"components": 94,
|
|
39
|
+
"stable": true,
|
|
40
|
+
"registry": null
|
|
41
|
+
}`;
|
|
42
|
+
|
|
43
|
+
const NOTES_MD = `# CardShell
|
|
44
|
+
|
|
45
|
+
The default panel in the system. \`title\` renders the header and
|
|
46
|
+
\`count\` renders a muted tally beside it.
|
|
47
|
+
|
|
48
|
+
## States
|
|
49
|
+
- enabled
|
|
50
|
+
- hover
|
|
51
|
+
- disabled`;
|
|
52
|
+
|
|
53
|
+
const FILES: CodeEditorFile[] = [
|
|
54
|
+
{ name: "CardShell.tsx", language: "tsx", source: SHELL_TSX },
|
|
55
|
+
{ name: "tokens.css", language: "css", source: TOKENS_CSS },
|
|
56
|
+
{ name: "manifest.json", language: "json", source: MANIFEST_JSON },
|
|
57
|
+
{ name: "NOTES.md", language: "md", source: NOTES_MD },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export default function CodeEditorPreview() {
|
|
61
|
+
const [active, setActive] = React.useState("CardShell.tsx");
|
|
62
|
+
const [copies, setCopies] = React.useState(0);
|
|
63
|
+
const [draft, setDraft] = React.useState<Record<string, string>>(() =>
|
|
64
|
+
Object.fromEntries(FILES.map((file) => [file.name, file.source])),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const files = FILES.map((file) => ({
|
|
68
|
+
...file,
|
|
69
|
+
source: draft[file.name] ?? file.source,
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div className="mx-auto w-full max-w-3xl space-y-lg p-lg">
|
|
74
|
+
<section className="space-y-sm">
|
|
75
|
+
<p className="text-overline text-muted-soft">Read-only viewer</p>
|
|
76
|
+
<CodeEditor
|
|
77
|
+
files={files}
|
|
78
|
+
activeFile={active}
|
|
79
|
+
onActiveFileChange={setActive}
|
|
80
|
+
folderLabel="atoms"
|
|
81
|
+
pathPrefix="atoms / CardShell"
|
|
82
|
+
onCopy={() => setCopies((count) => count + 1)}
|
|
83
|
+
className="h-96 max-h-96 min-h-0"
|
|
84
|
+
/>
|
|
85
|
+
<p className="text-caption text-muted" aria-live="polite">
|
|
86
|
+
{copies === 0
|
|
87
|
+
? "Pick a file, then copy it — the button flips to Copied."
|
|
88
|
+
: `Copied ${copies} ${copies === 1 ? "time" : "times"} to the clipboard.`}
|
|
89
|
+
</p>
|
|
90
|
+
</section>
|
|
91
|
+
|
|
92
|
+
<section className="space-y-sm">
|
|
93
|
+
<p className="text-overline text-muted-soft">Writing (streaming) state</p>
|
|
94
|
+
<CodeEditor
|
|
95
|
+
files={files}
|
|
96
|
+
activeFile="tokens.css"
|
|
97
|
+
onActiveFileChange={() => {}}
|
|
98
|
+
folderLabel="tokens"
|
|
99
|
+
pathPrefix="tokens / generated"
|
|
100
|
+
streamingFileNames={["tokens.css"]}
|
|
101
|
+
className="h-80 max-h-80 min-h-0"
|
|
102
|
+
/>
|
|
103
|
+
</section>
|
|
104
|
+
|
|
105
|
+
<section className="space-y-sm">
|
|
106
|
+
<p className="text-overline text-muted-soft">Editable with line gutter</p>
|
|
107
|
+
<CodeEditor
|
|
108
|
+
files={files}
|
|
109
|
+
activeFile={active}
|
|
110
|
+
onActiveFileChange={setActive}
|
|
111
|
+
folderLabel="atoms"
|
|
112
|
+
pathPrefix="atoms / CardShell"
|
|
113
|
+
readOnly={false}
|
|
114
|
+
onChange={(name, source) =>
|
|
115
|
+
setDraft((prev) => ({ ...prev, [name]: source }))
|
|
116
|
+
}
|
|
117
|
+
className="h-80 max-h-80 min-h-0"
|
|
118
|
+
/>
|
|
119
|
+
</section>
|
|
120
|
+
|
|
121
|
+
<section className="space-y-sm">
|
|
122
|
+
<p className="text-overline text-muted-soft">Scoped dark theme</p>
|
|
123
|
+
<CodeEditor
|
|
124
|
+
files={files}
|
|
125
|
+
activeFile="manifest.json"
|
|
126
|
+
onActiveFileChange={() => {}}
|
|
127
|
+
folderLabel="config"
|
|
128
|
+
pathPrefix="config / manifest"
|
|
129
|
+
dark
|
|
130
|
+
className="h-80 max-h-80 min-h-0"
|
|
131
|
+
/>
|
|
132
|
+
</section>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
@@ -97,6 +97,7 @@ export const ICON_REGISTRY = {
|
|
|
97
97
|
"chart-bar": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M3 3v16a2 2 0 0 0 2 2h16" }, { tag: "path", d: "M7 16h8" }, { tag: "path", d: "M7 11h12" }, { tag: "path", d: "M7 6h3" }] },
|
|
98
98
|
"layout-grid": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "7", height: "7", x: "3", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "14", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "3", y: "14", rx: "1" }] },
|
|
99
99
|
"smartphone": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "14", height: "20", x: "5", y: "2", rx: "2", ry: "2" }, { tag: "path", d: "M12 18h.01" }] },
|
|
100
|
+
"folder": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }] },
|
|
100
101
|
} as const;
|
|
101
102
|
|
|
102
103
|
export type IconName = keyof typeof ICON_REGISTRY;
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./atoms/AccordionItemDesktop";
|
|
|
6
6
|
export * from "./atoms/AccordionItemMobile";
|
|
7
7
|
export * from "./atoms/AgentQuestionCard";
|
|
8
8
|
export * from "./atoms/Alert";
|
|
9
|
+
export * from "./atoms/AttachmentChip";
|
|
9
10
|
export * from "./atoms/Avatar";
|
|
10
11
|
export * from "./atoms/AvatarGroup";
|
|
11
12
|
export * from "./atoms/Badge";
|
|
@@ -19,6 +20,7 @@ export * from "./atoms/Carousel";
|
|
|
19
20
|
export * from "./atoms/ChatWindow";
|
|
20
21
|
export * from "./atoms/Checkbox";
|
|
21
22
|
export * from "./atoms/Chip";
|
|
23
|
+
export * from "./atoms/CodeEditor";
|
|
22
24
|
export * from "./atoms/Combobox";
|
|
23
25
|
export * from "./atoms/CommentThread";
|
|
24
26
|
export * from "./atoms/DataTable";
|