@niwa-labs/ui-kit 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +29 -2
- package/package.json +31 -4
- package/src/agent/diff-view.tsx +62 -0
- package/src/agent/execution-track.tsx +201 -0
- package/src/agent/guard.ts +121 -0
- package/src/agent/guarded-action.tsx +272 -0
- package/src/agent/id-chip.tsx +102 -0
- package/src/agent/markdown.tsx +34 -0
- package/src/agent/payload.ts +42 -0
- package/src/agent/phase-plan.tsx +183 -0
- package/src/agent/plan-impact.ts +104 -0
- package/src/agent/state.tsx +75 -0
- package/src/agent/tool-call.tsx +106 -0
- package/src/agent/transcript.tsx +88 -0
- package/src/execution-track.css +327 -0
- package/src/index.ts +76 -0
- package/src/lib/cn.ts +19 -0
- package/src/page-layout.css +183 -0
- package/src/theme.css +136 -0
- package/src/ui/badge.tsx +32 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.tsx +13 -0
- package/src/ui/data-value.tsx +211 -0
- package/src/ui/message.tsx +81 -0
- package/src/ui/page-layout.tsx +33 -0
- package/src/ui/schema-view.tsx +144 -0
- package/src/ui/spinner.tsx +16 -0
- package/src/ui/tabs.tsx +63 -0
- package/src/ui/tooltip.tsx +50 -0
- package/src/ui/trace.tsx +100 -0
- package/test/browser.test.ts +13 -0
- package/test/diff-view.test.tsx +50 -0
- package/test/guard.test.ts +113 -0
- package/test/guarded-action.test.tsx +229 -0
- package/test/helpers.test.ts +83 -0
- package/test/phase-plan.test.tsx +146 -0
- package/test/plan.test.ts +71 -0
- package/test/render.test.tsx +62 -0
- package/test/structured-values.test.tsx +31 -0
- package/test/tabs.test.tsx +90 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Check, Copy, FileText } from "lucide-react";
|
|
2
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/** Display labels can be short. The clipboard always receives the original value. */
|
|
5
|
+
export function CopyValue({ value, label, name }: { value: string; label?: ReactNode; name?: string }) {
|
|
6
|
+
const [result, setResult] = useState<"idle" | "copied" | "failed">("idle");
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (result === "idle") return;
|
|
9
|
+
const t = setTimeout(() => setResult("idle"), 1900);
|
|
10
|
+
return () => clearTimeout(t);
|
|
11
|
+
}, [result]);
|
|
12
|
+
return (
|
|
13
|
+
<span className="nw-copy-wrap">
|
|
14
|
+
<button
|
|
15
|
+
type="button"
|
|
16
|
+
className="nw-copy"
|
|
17
|
+
data-slot="copy-value"
|
|
18
|
+
title={value}
|
|
19
|
+
aria-label={(name ?? "Скопировать") + " · " + value}
|
|
20
|
+
onClick={async () => {
|
|
21
|
+
try {
|
|
22
|
+
await navigator.clipboard.writeText(value);
|
|
23
|
+
setResult("copied");
|
|
24
|
+
} catch {
|
|
25
|
+
setResult("failed");
|
|
26
|
+
}
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{label ?? value}
|
|
30
|
+
{result === "copied" ? <Check size={13} /> : <Copy size={13} />}
|
|
31
|
+
</button>
|
|
32
|
+
{result !== "idle" && (
|
|
33
|
+
<small role="status">
|
|
34
|
+
{result === "copied" ? (
|
|
35
|
+
"Скопировано"
|
|
36
|
+
) : (
|
|
37
|
+
<>
|
|
38
|
+
<span>Скопируйте вручную</span>{" "}
|
|
39
|
+
<input
|
|
40
|
+
aria-label="Полное значение для копирования"
|
|
41
|
+
readOnly
|
|
42
|
+
value={value}
|
|
43
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
44
|
+
/>
|
|
45
|
+
</>
|
|
46
|
+
)}
|
|
47
|
+
</small>
|
|
48
|
+
)}
|
|
49
|
+
</span>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
export function FileRef({ path }: { path: string }) {
|
|
53
|
+
const parts = path.replace(/[\\/]+$/, "").split(/[\\/]/);
|
|
54
|
+
const file = parts.pop() || path,
|
|
55
|
+
directory = parts.filter(Boolean).slice(-2).join("/");
|
|
56
|
+
return (
|
|
57
|
+
<CopyValue
|
|
58
|
+
value={path}
|
|
59
|
+
name="Скопировать путь"
|
|
60
|
+
label={
|
|
61
|
+
<span className="nw-file">
|
|
62
|
+
<FileText size={15} />
|
|
63
|
+
<span>
|
|
64
|
+
<b>{file}</b>
|
|
65
|
+
{directory && <small>{directory}/</small>}
|
|
66
|
+
</span>
|
|
67
|
+
</span>
|
|
68
|
+
}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const fieldNames: Record<string, string> = {
|
|
73
|
+
id: "Идентификатор",
|
|
74
|
+
run: "Запуск",
|
|
75
|
+
session: "Сессия",
|
|
76
|
+
task: "Задача",
|
|
77
|
+
from: "Отправитель",
|
|
78
|
+
to: "Получатель",
|
|
79
|
+
kind: "Вид",
|
|
80
|
+
type: "Тип",
|
|
81
|
+
text: "Текст",
|
|
82
|
+
title: "Название",
|
|
83
|
+
description: "Описание",
|
|
84
|
+
detail: "Подробности",
|
|
85
|
+
status: "Статус",
|
|
86
|
+
state: "Состояние",
|
|
87
|
+
message: "Сообщение",
|
|
88
|
+
reason: "Причина",
|
|
89
|
+
result: "Результат",
|
|
90
|
+
outcome: "Итог",
|
|
91
|
+
file: "Файл",
|
|
92
|
+
directory: "Каталог",
|
|
93
|
+
cwd: "Рабочий каталог",
|
|
94
|
+
path: "Путь",
|
|
95
|
+
owner: "Владелец",
|
|
96
|
+
at: "Время",
|
|
97
|
+
key: "Ключ",
|
|
98
|
+
scope: "Область",
|
|
99
|
+
action: "Действие",
|
|
100
|
+
input: "Вход",
|
|
101
|
+
answer: "Ответ",
|
|
102
|
+
data: "Данные",
|
|
103
|
+
actor: "Автор",
|
|
104
|
+
branch: "Ветка",
|
|
105
|
+
duration: "Длительность",
|
|
106
|
+
version: "Версия",
|
|
107
|
+
model: "Модель",
|
|
108
|
+
harness: "Агент",
|
|
109
|
+
name: "Имя",
|
|
110
|
+
label: "Название",
|
|
111
|
+
prompt: "Поручение",
|
|
112
|
+
options: "Варианты",
|
|
113
|
+
required: "Обязательно",
|
|
114
|
+
workflow: "Сценарий",
|
|
115
|
+
seq: "Позиция в журнале",
|
|
116
|
+
root: "Начало цепочки",
|
|
117
|
+
cause: "Причина",
|
|
118
|
+
value: "Значение",
|
|
119
|
+
invocation: "Вызов",
|
|
120
|
+
attempt: "Попытка",
|
|
121
|
+
operationId: "Операция",
|
|
122
|
+
permissions: "Разрешения",
|
|
123
|
+
};
|
|
124
|
+
export const fieldLabel = (key: string) =>
|
|
125
|
+
Object.hasOwn(fieldNames, key) ? fieldNames[key]! : key.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ");
|
|
126
|
+
export const recordObject = (v: unknown): Record<string, unknown> | undefined =>
|
|
127
|
+
v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : undefined;
|
|
128
|
+
function Disclosure({ label, children }: { label: string; children: ReactNode }) {
|
|
129
|
+
const [open, setOpen] = useState(false);
|
|
130
|
+
return (
|
|
131
|
+
<details className="nw-fold" onToggle={(e) => setOpen(e.currentTarget.open)}>
|
|
132
|
+
<summary>{label}</summary>
|
|
133
|
+
{open && children}
|
|
134
|
+
</details>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function Series({ values, depth }: { values: unknown[]; depth: number }) {
|
|
138
|
+
const [limit, more] = useState(12);
|
|
139
|
+
return (
|
|
140
|
+
<>
|
|
141
|
+
<ul className="nw-value-list">
|
|
142
|
+
{values.slice(0, limit).map((v, i) => (
|
|
143
|
+
<li key={i}>
|
|
144
|
+
<DataValue value={v} depth={depth + 1} />
|
|
145
|
+
</li>
|
|
146
|
+
))}
|
|
147
|
+
</ul>
|
|
148
|
+
{values.length > limit && (
|
|
149
|
+
<button className="nw-more" type="button" onClick={() => more(limit + 24)}>
|
|
150
|
+
Показать ещё · {values.length - limit}
|
|
151
|
+
</button>
|
|
152
|
+
)}
|
|
153
|
+
</>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
export function DataValue({ value, field = "", depth = 0 }: { value: unknown; field?: string; depth?: number }) {
|
|
157
|
+
if (value == null) return <span className="nw-quiet">Не задано</span>;
|
|
158
|
+
if (typeof value === "boolean")
|
|
159
|
+
return (
|
|
160
|
+
<span className="nw-tag" data-tone={value ? "green" : "neutral"}>
|
|
161
|
+
{value ? "Да" : "Нет"}
|
|
162
|
+
</span>
|
|
163
|
+
);
|
|
164
|
+
if (typeof value === "number") {
|
|
165
|
+
if (/^(at|createdAt|dueAt|nextDue|timestamp)$/.test(field) && value > 1e11 && value < 1e14)
|
|
166
|
+
return <time>{new Date(value).toLocaleString("ru")}</time>;
|
|
167
|
+
return <span className="nw-number">{value.toLocaleString("ru")}</span>;
|
|
168
|
+
}
|
|
169
|
+
if (typeof value === "string") {
|
|
170
|
+
const s = value.trim();
|
|
171
|
+
if ((s.startsWith("{") && s.endsWith("}")) || (s.startsWith("[") && s.endsWith("]"))) {
|
|
172
|
+
try {
|
|
173
|
+
return <DataValue value={JSON.parse(s)} depth={depth} field={field} />;
|
|
174
|
+
} catch {
|
|
175
|
+
/* Human text may contain brackets. */
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (/^(\/|~\/|[A-Za-z]:[\\/])[^\n]+$/.test(s)) return <FileRef path={value} />;
|
|
179
|
+
if (/^https?:\/\/[^\s]+$/i.test(s))
|
|
180
|
+
return (
|
|
181
|
+
<a className="nw-url" href={s} target="_blank" rel="noreferrer">
|
|
182
|
+
{s}
|
|
183
|
+
</a>
|
|
184
|
+
);
|
|
185
|
+
if (/^[a-z]{1,14}-[a-f0-9]{6,}$|^[a-f0-9]{16,}$/i.test(s))
|
|
186
|
+
return <CopyValue value={value} label={s.length > 22 ? s.slice(0, 10) + "…" + s.slice(-5) : s} />;
|
|
187
|
+
return <span className="nw-value-text">{s || "Пустая строка"}</span>;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(value)) {
|
|
190
|
+
if (!value.length) return <span className="nw-quiet">Пока пусто</span>;
|
|
191
|
+
const content = <Series values={value} depth={depth} />;
|
|
192
|
+
return depth >= 2 ? <Disclosure label={"Список · " + value.length}>{content}</Disclosure> : content;
|
|
193
|
+
}
|
|
194
|
+
const object = recordObject(value);
|
|
195
|
+
if (!object) return <span className="nw-quiet">Нет значения</span>;
|
|
196
|
+
const entries = Object.entries(object);
|
|
197
|
+
if (!entries.length) return <span className="nw-quiet">Нет полей</span>;
|
|
198
|
+
const content = (
|
|
199
|
+
<dl className="nw-fields">
|
|
200
|
+
{entries.map(([key, v]) => (
|
|
201
|
+
<div key={key}>
|
|
202
|
+
<dt title={key}>{fieldLabel(key)}</dt>
|
|
203
|
+
<dd>
|
|
204
|
+
<DataValue value={v} field={key} depth={depth + 1} />
|
|
205
|
+
</dd>
|
|
206
|
+
</div>
|
|
207
|
+
))}
|
|
208
|
+
</dl>
|
|
209
|
+
);
|
|
210
|
+
return depth >= 2 ? <Disclosure label={"Подробности · " + entries.length}>{content}</Disclosure> : content;
|
|
211
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** One turn of a conversation: who spoke, what they said, and what the agent did inside the turn. */
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/cn.ts";
|
|
6
|
+
|
|
7
|
+
export function MessageGroup({ className, ...props }: ComponentProps<"div">) {
|
|
8
|
+
return <div data-slot="message-group" className={cn("flex min-w-0 flex-col gap-2", className)} {...props} />;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** `end` puts the turn on the right: the owner's own messages. */
|
|
12
|
+
export function Message({ className, align = "start", ...props }: ComponentProps<"div"> & { align?: "start" | "end" }) {
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
data-slot="message"
|
|
16
|
+
data-align={align}
|
|
17
|
+
className={cn("group/message relative flex w-full min-w-0 gap-2 text-sm data-[align=end]:flex-row-reverse", className)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function MessageAvatar({ className, ...props }: ComponentProps<"div">) {
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
data-slot="message-avatar"
|
|
27
|
+
className={cn("flex w-fit min-w-8 shrink-0 items-center justify-center self-start overflow-hidden rounded-full bg-muted", className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function MessageContent({ className, ...props }: ComponentProps<"div">) {
|
|
34
|
+
return (
|
|
35
|
+
<div
|
|
36
|
+
data-slot="message-content"
|
|
37
|
+
className={cn(
|
|
38
|
+
"flex w-full min-w-0 flex-col gap-2.5 wrap-break-word group-data-[align=end]/message:items-end",
|
|
39
|
+
className,
|
|
40
|
+
)}
|
|
41
|
+
{...props}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The text of a turn in a bubble; the owner's bubble is filled, the agent's is plain. */
|
|
47
|
+
export function MessageBubble({ className, ...props }: ComponentProps<"div">) {
|
|
48
|
+
return (
|
|
49
|
+
<div
|
|
50
|
+
data-slot="message-bubble"
|
|
51
|
+
className={cn(
|
|
52
|
+
"max-w-full min-w-0 rounded-xl group-data-[align=end]/message:bg-secondary group-data-[align=end]/message:px-3 group-data-[align=end]/message:py-2",
|
|
53
|
+
className,
|
|
54
|
+
)}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function MessageHeader({ className, ...props }: ComponentProps<"div">) {
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
data-slot="message-header"
|
|
64
|
+
className={cn("flex max-w-full min-w-0 items-center gap-2 text-xs font-medium text-muted-foreground", className)}
|
|
65
|
+
{...props}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function MessageFooter({ className, ...props }: ComponentProps<"div">) {
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
data-slot="message-footer"
|
|
74
|
+
className={cn(
|
|
75
|
+
"flex max-w-full min-w-0 items-center gap-2 text-xs text-muted-foreground group-data-[align=end]/message:justify-end",
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { cn } from "../lib/cn.ts";
|
|
3
|
+
|
|
4
|
+
type HeadingProps = Omit<ComponentPropsWithoutRef<"header">, "title"> & { title: ReactNode; meta?: ReactNode };
|
|
5
|
+
/** A page title, its optional context and the controls that belong to this page. */
|
|
6
|
+
export function PageHeading({ title, meta, children, className, ...props }: HeadingProps) {
|
|
7
|
+
return (
|
|
8
|
+
<header {...props} className={cn("desk-heading", className)}>
|
|
9
|
+
<div>
|
|
10
|
+
<h1>{title}</h1>
|
|
11
|
+
{meta && <small>{meta}</small>}
|
|
12
|
+
</div>
|
|
13
|
+
{children}
|
|
14
|
+
</header>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type SectionProps = Omit<ComponentPropsWithoutRef<"section">, "title"> & { title: ReactNode; actions?: ReactNode };
|
|
19
|
+
export function PageSection({ title, actions, children, className, ...props }: SectionProps) {
|
|
20
|
+
return (
|
|
21
|
+
<section {...props} className={cn("desk-section", className)}>
|
|
22
|
+
{actions ? (
|
|
23
|
+
<header className="desk-tools">
|
|
24
|
+
<h2>{title}</h2>
|
|
25
|
+
{actions}
|
|
26
|
+
</header>
|
|
27
|
+
) : (
|
|
28
|
+
<h2>{title}</h2>
|
|
29
|
+
)}
|
|
30
|
+
{children}
|
|
31
|
+
</section>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { DataValue, recordObject } from "./data-value.tsx";
|
|
3
|
+
|
|
4
|
+
const types: Record<string, string> = {
|
|
5
|
+
object: "Группа",
|
|
6
|
+
string: "Текст",
|
|
7
|
+
array: "Список",
|
|
8
|
+
integer: "Целое",
|
|
9
|
+
number: "Число",
|
|
10
|
+
boolean: "Да / нет",
|
|
11
|
+
null: "Пустое значение",
|
|
12
|
+
};
|
|
13
|
+
const typeName = (s: Record<string, unknown>) =>
|
|
14
|
+
Array.isArray(s.type)
|
|
15
|
+
? s.type.map((v) => types[String(v)] ?? String(v)).join(" / ")
|
|
16
|
+
: (types[String(s.type)] ??
|
|
17
|
+
(s.properties ? "Группа" : s.enum ? "Выбор" : s.anyOf || s.oneOf ? "Варианты" : "Значение"));
|
|
18
|
+
function reference(ref: string, root: unknown) {
|
|
19
|
+
if (!ref.startsWith("#/")) return;
|
|
20
|
+
let v = root;
|
|
21
|
+
for (const k of ref.slice(2).split("/")) v = recordObject(v)?.[k.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
const limits: Record<string, string> = {
|
|
25
|
+
minLength: "Мин. символов",
|
|
26
|
+
maxLength: "Макс. символов",
|
|
27
|
+
minimum: "Минимум",
|
|
28
|
+
maximum: "Максимум",
|
|
29
|
+
exclusiveMinimum: "Больше",
|
|
30
|
+
exclusiveMaximum: "Меньше",
|
|
31
|
+
minItems: "Мин. элементов",
|
|
32
|
+
maxItems: "Макс. элементов",
|
|
33
|
+
format: "Формат",
|
|
34
|
+
pattern: "Шаблон",
|
|
35
|
+
multipleOf: "Кратно",
|
|
36
|
+
};
|
|
37
|
+
function Fields({ schema, root, seen, level = 0 }: { schema: unknown; root: unknown; seen: string[]; level?: number }) {
|
|
38
|
+
const [expanded, setExpanded] = useState(level < 2);
|
|
39
|
+
if (typeof schema === "boolean") return <p>{schema ? "Допускается любое значение" : "Значение запрещено"}</p>;
|
|
40
|
+
const s = recordObject(schema);
|
|
41
|
+
if (!s) return null;
|
|
42
|
+
if (typeof s.$ref === "string") {
|
|
43
|
+
const dest = reference(s.$ref, root);
|
|
44
|
+
return dest !== undefined && !seen.includes(s.$ref) ? (
|
|
45
|
+
<Fields schema={dest} root={root} seen={[...seen, s.$ref]} level={level} />
|
|
46
|
+
) : (
|
|
47
|
+
<small>Ссылка на тип · {s.$ref.split("/").at(-1)}</small>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const props = Object.entries(recordObject(s.properties) ?? {}),
|
|
51
|
+
required = Array.isArray(s.required) ? s.required : [];
|
|
52
|
+
const variants = s.oneOf ?? s.anyOf ?? s.allOf;
|
|
53
|
+
return (
|
|
54
|
+
<div className="nw-schema">
|
|
55
|
+
{typeof s.description === "string" && <p>{s.description}</p>}
|
|
56
|
+
{props.length > 0 && (
|
|
57
|
+
<>
|
|
58
|
+
{level >= 2 && (
|
|
59
|
+
<button type="button" className="nw-more" aria-expanded={expanded} onClick={() => setExpanded(!expanded)}>
|
|
60
|
+
Поля группы · {props.length}
|
|
61
|
+
</button>
|
|
62
|
+
)}
|
|
63
|
+
{expanded && (
|
|
64
|
+
<ul>
|
|
65
|
+
{props.map(([name, child]) => (
|
|
66
|
+
<li key={name}>
|
|
67
|
+
<div className="nw-field-heading">
|
|
68
|
+
<strong>{name}</strong>
|
|
69
|
+
<span className="nw-tag" data-tone="blue">
|
|
70
|
+
{typeName(recordObject(child) ?? {})}
|
|
71
|
+
</span>
|
|
72
|
+
{required.includes(name) && <small>Обязательно</small>}
|
|
73
|
+
</div>
|
|
74
|
+
<Fields schema={child} root={root} seen={seen} level={level + 1} />
|
|
75
|
+
</li>
|
|
76
|
+
))}
|
|
77
|
+
</ul>
|
|
78
|
+
)}
|
|
79
|
+
</>
|
|
80
|
+
)}
|
|
81
|
+
{s.items !== undefined && (
|
|
82
|
+
<div className="nw-schema-child">
|
|
83
|
+
<b>Элементы · {typeName(recordObject(s.items) ?? {})}</b>
|
|
84
|
+
<Fields schema={s.items} root={root} seen={seen} level={level + 1} />
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
{Array.isArray(variants) && (
|
|
88
|
+
<div className="nw-schema-child">
|
|
89
|
+
<b>{s.allOf ? "Все условия" : "Допустимые варианты"}</b>
|
|
90
|
+
{variants.map((v, i) => (
|
|
91
|
+
<div key={i}>
|
|
92
|
+
<span className="nw-tag">{typeName(recordObject(v) ?? {})}</span>
|
|
93
|
+
<Fields schema={v} root={root} seen={seen} level={level + 1} />
|
|
94
|
+
</div>
|
|
95
|
+
))}
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
{s.enum !== undefined && (
|
|
99
|
+
<div className="nw-field-rule">
|
|
100
|
+
На выбор <DataValue value={s.enum} />
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
{Object.hasOwn(s, "const") && (
|
|
104
|
+
<div className="nw-field-rule">
|
|
105
|
+
Значение <DataValue value={s.const} />
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
{Object.hasOwn(s, "default") && (
|
|
109
|
+
<div className="nw-field-rule">
|
|
110
|
+
По умолчанию <DataValue value={s.default} />
|
|
111
|
+
</div>
|
|
112
|
+
)}
|
|
113
|
+
{Object.keys(limits)
|
|
114
|
+
.filter((k) => s[k] !== undefined)
|
|
115
|
+
.map((k) => (
|
|
116
|
+
<span className="nw-field-rule" key={k}>
|
|
117
|
+
{limits[k]} <b>{String(s[k])}</b>
|
|
118
|
+
</span>
|
|
119
|
+
))}
|
|
120
|
+
{s.additionalProperties === false && props.length > 0 && (
|
|
121
|
+
<small className="nw-quiet">Только перечисленные поля</small>
|
|
122
|
+
)}
|
|
123
|
+
{recordObject(s.additionalProperties) && (
|
|
124
|
+
<div className="nw-schema-child">
|
|
125
|
+
<b>Дополнительные поля</b>
|
|
126
|
+
<Fields schema={s.additionalProperties} root={root} seen={seen} level={level + 1} />
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
export function SchemaView({ schema }: { schema: unknown }) {
|
|
133
|
+
const s = recordObject(schema);
|
|
134
|
+
return (
|
|
135
|
+
<div data-slot="schema-view">
|
|
136
|
+
{!s?.properties && (
|
|
137
|
+
<span className="nw-tag" data-tone="blue">
|
|
138
|
+
{typeName(s ?? {})}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
<Fields schema={schema} root={schema} seen={[]} />
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Loader2Icon } from "lucide-react";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/cn.ts";
|
|
5
|
+
|
|
6
|
+
export function Spinner({ className, ...props }: ComponentProps<"svg">) {
|
|
7
|
+
return (
|
|
8
|
+
<Loader2Icon
|
|
9
|
+
data-slot="spinner"
|
|
10
|
+
role="status"
|
|
11
|
+
aria-label="Loading"
|
|
12
|
+
className={cn("size-4 animate-spin", className)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/ui/tabs.tsx
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn, cnWith } from "../lib/cn.ts";
|
|
5
|
+
|
|
6
|
+
export function Tabs({ className, orientation = "horizontal", ...props }: TabsPrimitive.Root.Props) {
|
|
7
|
+
return (
|
|
8
|
+
<TabsPrimitive.Root
|
|
9
|
+
data-slot="tabs"
|
|
10
|
+
orientation={orientation}
|
|
11
|
+
className={cnWith<TabsPrimitive.Root.State>(
|
|
12
|
+
"group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",
|
|
13
|
+
className,
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const tabsListVariants = cva(
|
|
21
|
+
"group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-8 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",
|
|
22
|
+
{
|
|
23
|
+
variants: { variant: { default: "bg-muted", line: "gap-1 bg-transparent" } },
|
|
24
|
+
defaultVariants: { variant: "default" },
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export function TabsList({
|
|
29
|
+
className,
|
|
30
|
+
variant = "default",
|
|
31
|
+
...props
|
|
32
|
+
}: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>) {
|
|
33
|
+
return (
|
|
34
|
+
<TabsPrimitive.List
|
|
35
|
+
data-slot="tabs-list"
|
|
36
|
+
data-variant={variant}
|
|
37
|
+
className={cnWith<TabsPrimitive.List.State>(tabsListVariants({ variant }), className)}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
|
|
44
|
+
return (
|
|
45
|
+
<TabsPrimitive.Tab
|
|
46
|
+
data-slot="tabs-trigger"
|
|
47
|
+
className={cnWith<TabsPrimitive.Tab.State>(
|
|
48
|
+
[
|
|
49
|
+
"relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
50
|
+
"group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent",
|
|
51
|
+
"data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30",
|
|
52
|
+
"after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
|
|
53
|
+
],
|
|
54
|
+
className,
|
|
55
|
+
)}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
|
|
62
|
+
return <TabsPrimitive.Panel data-slot="tabs-content" className={cnWith<TabsPrimitive.Panel.State>("flex-1 text-sm outline-none", className)} {...props} />;
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
|
|
2
|
+
|
|
3
|
+
import { cnWith } from "../lib/cn.ts";
|
|
4
|
+
|
|
5
|
+
/** Shares the open delay between tooltips: once one is open, its neighbours open at once. */
|
|
6
|
+
export function TooltipProvider({ delay = 300, ...props }: TooltipPrimitive.Provider.Props) {
|
|
7
|
+
return <TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} {...props} />;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Tooltip(props: TooltipPrimitive.Root.Props) {
|
|
11
|
+
return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function TooltipTrigger(props: TooltipPrimitive.Trigger.Props) {
|
|
15
|
+
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function TooltipContent({
|
|
19
|
+
className,
|
|
20
|
+
side = "top",
|
|
21
|
+
sideOffset = 4,
|
|
22
|
+
align = "center",
|
|
23
|
+
alignOffset = 0,
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
26
|
+
}: TooltipPrimitive.Popup.Props &
|
|
27
|
+
Pick<TooltipPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset">) {
|
|
28
|
+
return (
|
|
29
|
+
<TooltipPrimitive.Portal>
|
|
30
|
+
<TooltipPrimitive.Positioner
|
|
31
|
+
align={align}
|
|
32
|
+
alignOffset={alignOffset}
|
|
33
|
+
side={side}
|
|
34
|
+
sideOffset={sideOffset}
|
|
35
|
+
className="isolate z-50"
|
|
36
|
+
>
|
|
37
|
+
<TooltipPrimitive.Popup
|
|
38
|
+
data-slot="tooltip-content"
|
|
39
|
+
className={cnWith<TooltipPrimitive.Popup.State>(
|
|
40
|
+
"z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background transition-opacity data-ending-style:opacity-0 data-starting-style:opacity-0",
|
|
41
|
+
className,
|
|
42
|
+
)}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</TooltipPrimitive.Popup>
|
|
47
|
+
</TooltipPrimitive.Positioner>
|
|
48
|
+
</TooltipPrimitive.Portal>
|
|
49
|
+
);
|
|
50
|
+
}
|