devnonla-ui 0.14.0 → 0.16.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/package.json +5 -2
- package/src/blob-shape/BlobShape.tsx +337 -0
- package/src/button/ButtonCopy.tsx +2 -2
- package/src/chat/AgentChatbox.tsx +1 -1
- package/src/chat/AgentPanel.tsx +1 -1
- package/src/chat/chatMessageList.tsx +5 -3
- package/src/chat/chatRhythm.ts +8 -0
- package/src/chat/common/createAgentSseSession.ts +9 -3
- package/src/chat/common/sse.ts +290 -122
- package/src/chat/common/useAgentStream.ts +1 -1
- package/src/chat/index.ts +2 -2
- package/src/chat/message-ui/ChatAgentMessage.tsx +4 -3
- package/src/chat/message-ui/ChatError.tsx +5 -4
- package/src/chat/message-ui/ChatInput.tsx +5 -5
- package/src/chat/message-ui/ChatMarkdown.tsx +36 -2
- package/src/chat/message-ui/ChatThinking.tsx +8 -7
- package/src/chat/message-ui/ChatUserMessage.tsx +4 -4
- package/src/chat/tool-ui/BackgroundTaskToolUI.tsx +7 -6
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +7 -7
- package/src/chat/tool-ui/CallAgentToolUI.tsx +14 -13
- package/src/chat/tool-ui/ChatToolCall.tsx +13 -12
- package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +7 -6
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +10 -9
- package/src/chat/tool-ui/RunJsToolUI.tsx +8 -7
- package/src/chat/tool-ui/ToolUiTrailing.tsx +3 -3
- package/src/chat/tool-ui/WebFetchToolUI.tsx +10 -9
- package/src/codeblock/CodeBlock.tsx +1 -1
- package/src/desktop/DesktopIcon.tsx +3 -4
- package/src/icon/Icon.tsx +33 -0
- package/src/icon/glyphs.ts +42 -0
- package/src/index.ts +8 -20
- package/src/input/EditableInput.tsx +2 -2
- package/src/markdown-editor/MarkdownEditor.tsx +4 -4
- package/src/markdown-editor/MarkdownPreview.tsx +4 -4
- package/src/markdown-editor/MarkdownTable.tsx +67 -13
- package/src/markdown-editor/MarkdownViewer.tsx +25 -28
- package/src/markdown-editor/MermaidBlock.tsx +4 -4
- package/src/markdown-editor/ReactCodeFrame.tsx +2 -2
- package/src/markdown-editor/ReactCodeSandbox.tsx +2 -2
- package/src/markdown-editor/markdownScale.ts +65 -131
- package/src/menu/Menu.tsx +2 -2
- package/src/pagination/Pagination.tsx +4 -4
- package/src/scroll/OverlayScroll.tsx +13 -5
- package/src/sidebar/Sidebar.tsx +5 -5
- package/src/sortable-tree/SortableTree.tsx +599 -0
- package/src/styles.css +36 -16
- package/src/tabs/Tabs.tsx +75 -13
- package/src/theme-switcher/ThemeSwitcher.tsx +6 -6
- package/src/typography/Typography.tsx +4 -4
- package/src/icon/SolarIcon.tsx +0 -39
- package/src/icon/solar.ts +0 -172
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Collision,
|
|
3
|
+
type CollisionDetection,
|
|
4
|
+
closestCenter,
|
|
5
|
+
DndContext,
|
|
6
|
+
type DragEndEvent,
|
|
7
|
+
type DragMoveEvent,
|
|
8
|
+
DragOverlay,
|
|
9
|
+
type DragStartEvent,
|
|
10
|
+
KeyboardSensor,
|
|
11
|
+
type Modifier,
|
|
12
|
+
PointerSensor,
|
|
13
|
+
pointerWithin,
|
|
14
|
+
useSensor,
|
|
15
|
+
useSensors,
|
|
16
|
+
} from "@dnd-kit/core";
|
|
17
|
+
import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
18
|
+
import { CSS, type Transform } from "@dnd-kit/utilities";
|
|
19
|
+
import { type ReactNode, useRef, useState } from "react";
|
|
20
|
+
import { createPortal } from "react-dom";
|
|
21
|
+
import { usePopupContainer } from "../app/context";
|
|
22
|
+
import { cn } from "../lib/cn";
|
|
23
|
+
|
|
24
|
+
export type SortableTreeItem<T = unknown> = {
|
|
25
|
+
id: string;
|
|
26
|
+
label?: ReactNode;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
data?: T;
|
|
29
|
+
children?: SortableTreeItem<T>[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** A row that needs a new position. `index` is the new index in the list it landed in. */
|
|
33
|
+
export type SortableTreeChange = {
|
|
34
|
+
id: string;
|
|
35
|
+
index: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SortableTreeProps<T = unknown> = {
|
|
39
|
+
items: SortableTreeItem<T>[];
|
|
40
|
+
/** Next tree after a drop that changed order. */
|
|
41
|
+
onChange?: (items: SortableTreeItem<T>[]) => void;
|
|
42
|
+
/** Rows whose index changed. Rows that stayed put are omitted. */
|
|
43
|
+
onDragEnd?: (updates: SortableTreeChange[]) => void;
|
|
44
|
+
renderItem?: (item: SortableTreeItem<T>) => ReactNode;
|
|
45
|
+
className?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const DROP_ANIMATION = { duration: 180, easing: "cubic-bezier(0.16, 1, 0.3, 1)" };
|
|
49
|
+
|
|
50
|
+
/** Keep the floating preview inside the window. Uses the source rect so the overlay is not clamped twice. */
|
|
51
|
+
const clampOverlayToWindow: Modifier = ({ transform, activeNodeRect, windowRect }) => {
|
|
52
|
+
if (!activeNodeRect || !windowRect) return transform;
|
|
53
|
+
const next = { ...transform };
|
|
54
|
+
const left = activeNodeRect.left + transform.x;
|
|
55
|
+
const top = activeNodeRect.top + transform.y;
|
|
56
|
+
const maxLeft = windowRect.left + windowRect.width - activeNodeRect.width;
|
|
57
|
+
const maxTop = windowRect.top + windowRect.height - activeNodeRect.height;
|
|
58
|
+
if (left < windowRect.left) next.x = windowRect.left - activeNodeRect.left;
|
|
59
|
+
else if (left > maxLeft) next.x = maxLeft - activeNodeRect.left;
|
|
60
|
+
if (top < windowRect.top) next.y = windowRect.top - activeNodeRect.top;
|
|
61
|
+
else if (top > maxTop) next.y = maxTop - activeNodeRect.top;
|
|
62
|
+
return next;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function parentIdOf(data: { parentId?: unknown } | undefined): string | null {
|
|
66
|
+
return typeof data?.parentId === "string" ? data.parentId : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type FlatRow = { id: string; parentId: string | null; depth: number };
|
|
70
|
+
|
|
71
|
+
type DropHint = { overId: string; edge: "top" | "bottom" };
|
|
72
|
+
|
|
73
|
+
type Placement = { parentId: string | null; index: number; lineId: string; edge: "top" | "bottom" } | "reorder" | null;
|
|
74
|
+
|
|
75
|
+
function flatten<T>(items: SortableTreeItem<T>[], parentId: string | null = null, depth = 0, rows: FlatRow[] = []): FlatRow[] {
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
rows.push({ id: item.id, parentId, depth });
|
|
78
|
+
if (item.children?.length) flatten(item.children, item.id, depth + 1, rows);
|
|
79
|
+
}
|
|
80
|
+
return rows;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function faceRect(root: HTMLElement | null, id: string): DOMRect | null {
|
|
84
|
+
const cssEscape = globalThis.CSS?.escape;
|
|
85
|
+
if (!root || typeof cssEscape !== "function") return null;
|
|
86
|
+
const node = root.querySelector(`[data-tree-face="${cssEscape(id)}"]`);
|
|
87
|
+
return node instanceof HTMLElement ? node.getBoundingClientRect() : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The seam between two parents is only a couple of pixels, and it falls on the last child.
|
|
92
|
+
* A pointer in the lower half of that child — or in the seam just under it — is aiming at the next parent.
|
|
93
|
+
*/
|
|
94
|
+
function gapTarget<T>(items: SortableTreeItem<T>[], hitId: string, pointerY: number | null, root: HTMLElement | null, blocked: Set<string>): string {
|
|
95
|
+
if (pointerY == null) return hitId;
|
|
96
|
+
const flat = flatten(items);
|
|
97
|
+
const start = flat.findIndex((row) => row.id === hitId);
|
|
98
|
+
if (start < 0) return hitId;
|
|
99
|
+
const hit = flat[start];
|
|
100
|
+
let scan = start + 1;
|
|
101
|
+
for (; scan < flat.length; scan += 1) {
|
|
102
|
+
const row = flat[scan];
|
|
103
|
+
if (row.depth < hit.depth) break;
|
|
104
|
+
if (row.depth === hit.depth && row.parentId === hit.parentId) return hitId;
|
|
105
|
+
}
|
|
106
|
+
const following = flat[scan];
|
|
107
|
+
if (!following || following.depth >= hit.depth || blocked.has(following.id)) return hitId;
|
|
108
|
+
const rect = faceRect(root, hitId);
|
|
109
|
+
if (!rect || pointerY < rect.top + rect.height / 2) return hitId;
|
|
110
|
+
return following.id;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function smallestHit(hits: Collision[], rects: Parameters<CollisionDetection>[0]["droppableRects"]): Collision {
|
|
114
|
+
let best = hits[0];
|
|
115
|
+
let bestArea = Number.POSITIVE_INFINITY;
|
|
116
|
+
for (const hit of hits) {
|
|
117
|
+
const rect = rects.get(hit.id);
|
|
118
|
+
const area = rect ? rect.width * rect.height : Number.POSITIVE_INFINITY;
|
|
119
|
+
if (area < bestArea) {
|
|
120
|
+
best = hit;
|
|
121
|
+
bestArea = area;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return best;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isAncestor<T>(items: SortableTreeItem<T>[], activeId: string, hitId: string): boolean {
|
|
128
|
+
const byId = new Map(flatten(items).map((row) => [row.id, row]));
|
|
129
|
+
let current = byId.get(activeId);
|
|
130
|
+
while (current?.parentId) {
|
|
131
|
+
if (current.parentId === hitId) return true;
|
|
132
|
+
current = byId.get(current.parentId);
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function pointerInside(rect: { left: number; right: number; top: number; bottom: number } | null | undefined, pointer: { x: number; y: number } | null): boolean {
|
|
138
|
+
if (!rect || !pointer) return false;
|
|
139
|
+
return pointer.x >= rect.left && pointer.x <= rect.right && pointer.y >= rect.top && pointer.y <= rect.bottom;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function collideTree<T>(args: Parameters<CollisionDetection>[0], items: SortableTreeItem<T>[], blocked: Set<string>, root: HTMLElement | null): Collision[] {
|
|
143
|
+
const pointer = args.pointerCoordinates;
|
|
144
|
+
const activeRect = args.droppableRects.get(args.active.id);
|
|
145
|
+
if (pointerInside(activeRect, pointer)) return [{ id: args.active.id }];
|
|
146
|
+
|
|
147
|
+
const containers = args.droppableContainers.filter((container) => !blocked.has(String(container.id)));
|
|
148
|
+
const scoped = { ...args, droppableContainers: containers };
|
|
149
|
+
const inside = pointerWithin(scoped);
|
|
150
|
+
let hit = inside.length > 0 ? smallestHit(inside, args.droppableRects) : closestCenter(scoped)[0];
|
|
151
|
+
if (!hit) return [];
|
|
152
|
+
|
|
153
|
+
const activeId = String(args.active.id);
|
|
154
|
+
if (isAncestor(items, activeId, String(hit.id)) && !pointerInside(faceRect(root, String(hit.id)), pointer)) {
|
|
155
|
+
const parentId = parentIdOf(args.active.data.current);
|
|
156
|
+
const siblings = containers.filter((container) => parentIdOf(container.data.current) === parentId);
|
|
157
|
+
const siblingHit = closestCenter({ ...scoped, droppableContainers: siblings })[0];
|
|
158
|
+
if (siblingHit) hit = siblingHit;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const nextId = gapTarget(items, String(hit.id), pointer?.y ?? null, root, blocked);
|
|
162
|
+
if (nextId === String(hit.id)) return [hit];
|
|
163
|
+
const redirected = containers.find((container) => String(container.id) === nextId);
|
|
164
|
+
return redirected ? [{ id: redirected.id }] : [hit];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function findLocation<T>(items: SortableTreeItem<T>[], id: string, parentId: string | null = null): { parentId: string | null; index: number; node: SortableTreeItem<T> } | null {
|
|
168
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
169
|
+
const node = items[index];
|
|
170
|
+
if (node.id === id) return { parentId, index, node };
|
|
171
|
+
if (node.children?.length) {
|
|
172
|
+
const found = findLocation(node.children, id, node.id);
|
|
173
|
+
if (found) return found;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function contains<T>(item: SortableTreeItem<T>, id: string): boolean {
|
|
180
|
+
if (item.id === id) return true;
|
|
181
|
+
for (const child of item.children ?? []) {
|
|
182
|
+
if (contains(child, id)) return true;
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function removeNode<T>(items: SortableTreeItem<T>[], id: string): { items: SortableTreeItem<T>[]; node: SortableTreeItem<T> | null } {
|
|
188
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
189
|
+
const item = items[index];
|
|
190
|
+
if (item.id === id) return { items: items.filter((entry) => entry.id !== id), node: item };
|
|
191
|
+
if (item.children?.length) {
|
|
192
|
+
const child = removeNode(item.children, id);
|
|
193
|
+
if (child.node) {
|
|
194
|
+
const next = items.slice();
|
|
195
|
+
next[index] = { ...item, children: child.items.length > 0 ? child.items : undefined };
|
|
196
|
+
return { items: next, node: child.node };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { items, node: null };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function insertNode<T>(items: SortableTreeItem<T>[], parentId: string | null, index: number, node: SortableTreeItem<T>): SortableTreeItem<T>[] {
|
|
204
|
+
if (parentId == null) {
|
|
205
|
+
const next = items.slice();
|
|
206
|
+
next.splice(Math.max(0, Math.min(index, next.length)), 0, node);
|
|
207
|
+
return next;
|
|
208
|
+
}
|
|
209
|
+
let changed = false;
|
|
210
|
+
const next = items.map((item) => {
|
|
211
|
+
if (item.id === parentId) {
|
|
212
|
+
changed = true;
|
|
213
|
+
const children = (item.children ?? []).slice();
|
|
214
|
+
children.splice(Math.max(0, Math.min(index, children.length)), 0, node);
|
|
215
|
+
return { ...item, children };
|
|
216
|
+
}
|
|
217
|
+
if (!item.children?.length) return item;
|
|
218
|
+
const children = insertNode(item.children, parentId, index, node);
|
|
219
|
+
if (children === item.children) return item;
|
|
220
|
+
changed = true;
|
|
221
|
+
return { ...item, children };
|
|
222
|
+
});
|
|
223
|
+
return changed ? next : items;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function relocate<T>(items: SortableTreeItem<T>[], activeId: string, parentId: string | null, index: number): SortableTreeItem<T>[] {
|
|
227
|
+
const from = findLocation(items, activeId);
|
|
228
|
+
if (!from) return items;
|
|
229
|
+
if (parentId != null && (parentId === activeId || contains(from.node, parentId))) return items;
|
|
230
|
+
let target = index;
|
|
231
|
+
if (from.parentId === parentId && from.index < target) target -= 1;
|
|
232
|
+
if (from.parentId === parentId && from.index === target) return items;
|
|
233
|
+
const removed = removeNode(items, activeId);
|
|
234
|
+
if (!removed.node) return items;
|
|
235
|
+
return insertNode(removed.items, parentId, target, removed.node);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function pointerY(event: DragMoveEvent | DragEndEvent): number | null {
|
|
239
|
+
const source = event.activatorEvent;
|
|
240
|
+
if (!(source instanceof MouseEvent)) return null;
|
|
241
|
+
return source.clientY + event.delta.y;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function rowEdge(root: HTMLElement | null, overId: string, clientY: number | null): "top" | "bottom" {
|
|
245
|
+
if (clientY == null) return "top";
|
|
246
|
+
const rect = faceRect(root, overId);
|
|
247
|
+
if (!rect) return "top";
|
|
248
|
+
return clientY < rect.top + rect.height / 2 ? "top" : "bottom";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Where a dragged row will land. A shallower row means "just in front of this parent". */
|
|
252
|
+
function placement<T>(items: SortableTreeItem<T>[], activeId: string, overId: string, activeParent: string | null, overParent: string | null, activeDepth: number, overDepth: number, edge: "top" | "bottom"): Placement {
|
|
253
|
+
if (activeId === overId) return null;
|
|
254
|
+
if (activeParent === overParent) return "reorder";
|
|
255
|
+
const activeLoc = findLocation(items, activeId);
|
|
256
|
+
const overLoc = findLocation(items, overId);
|
|
257
|
+
if (!activeLoc || !overLoc) return null;
|
|
258
|
+
|
|
259
|
+
let parentId = overLoc.parentId;
|
|
260
|
+
let index = edge === "top" ? overLoc.index : overLoc.index + 1;
|
|
261
|
+
let line: "top" | "bottom" = edge;
|
|
262
|
+
if (overDepth < activeDepth) {
|
|
263
|
+
if (edge === "bottom" && !overLoc.node.children?.length) {
|
|
264
|
+
parentId = overId;
|
|
265
|
+
index = 0;
|
|
266
|
+
line = "bottom";
|
|
267
|
+
} else {
|
|
268
|
+
index = overLoc.index;
|
|
269
|
+
line = "top";
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (parentId != null && (parentId === activeId || contains(activeLoc.node, parentId))) return null;
|
|
273
|
+
return { parentId, index, lineId: overId, edge: line };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function describe<T>(items: SortableTreeItem<T>[], id: string): { parentId: string | null; depth: number } | null {
|
|
277
|
+
const row = flatten(items).find((entry) => entry.id === id);
|
|
278
|
+
return row ? { parentId: row.parentId, depth: row.depth } : null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function descendantIds<T>(item: SortableTreeItem<T>): string[] {
|
|
282
|
+
const ids: string[] = [];
|
|
283
|
+
for (const child of item.children ?? []) {
|
|
284
|
+
ids.push(child.id);
|
|
285
|
+
ids.push(...descendantIds(child));
|
|
286
|
+
}
|
|
287
|
+
return ids;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function siblingIds<T>(items: SortableTreeItem<T>[], parentId: string | null): string[] {
|
|
291
|
+
if (parentId == null) return items.map((item) => item.id);
|
|
292
|
+
return (findItem(items, parentId)?.children ?? []).map((item) => item.id);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function changedIndexes(before: string[], after: string[]): { id: string; index: number }[] {
|
|
296
|
+
const previous = new Map(before.map((id, index) => [id, index]));
|
|
297
|
+
const updates: { id: string; index: number }[] = [];
|
|
298
|
+
after.forEach((id, index) => {
|
|
299
|
+
if (previous.get(id) !== index) updates.push({ id, index });
|
|
300
|
+
});
|
|
301
|
+
return updates;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function findItem<T>(items: SortableTreeItem<T>[], id: string): SortableTreeItem<T> | null {
|
|
305
|
+
for (const item of items) {
|
|
306
|
+
if (item.id === id) return item;
|
|
307
|
+
if (item.children?.length) {
|
|
308
|
+
const found = findItem(item.children, id);
|
|
309
|
+
if (found) return found;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function reorderSiblings<T>(items: SortableTreeItem<T>[], parentId: string | null, activeId: string, overId: string): SortableTreeItem<T>[] {
|
|
316
|
+
if (parentId == null) {
|
|
317
|
+
const oldIndex = items.findIndex((item) => item.id === activeId);
|
|
318
|
+
const newIndex = items.findIndex((item) => item.id === overId);
|
|
319
|
+
if (oldIndex < 0 || newIndex < 0 || oldIndex === newIndex) return items;
|
|
320
|
+
return arrayMove(items, oldIndex, newIndex);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let changed = false;
|
|
324
|
+
const next = items.map((item) => {
|
|
325
|
+
if (item.id === parentId) {
|
|
326
|
+
const children = item.children ?? [];
|
|
327
|
+
const oldIndex = children.findIndex((child) => child.id === activeId);
|
|
328
|
+
const newIndex = children.findIndex((child) => child.id === overId);
|
|
329
|
+
if (oldIndex < 0 || newIndex < 0 || oldIndex === newIndex) return item;
|
|
330
|
+
changed = true;
|
|
331
|
+
return { ...item, children: arrayMove(children, oldIndex, newIndex) };
|
|
332
|
+
}
|
|
333
|
+
if (!item.children?.length) return item;
|
|
334
|
+
const children = reorderSiblings(item.children, parentId, activeId, overId);
|
|
335
|
+
if (children === item.children) return item;
|
|
336
|
+
changed = true;
|
|
337
|
+
return { ...item, children };
|
|
338
|
+
});
|
|
339
|
+
return changed ? next : items;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Drop the horizontal delta. A sideways drag must not widen the list. */
|
|
343
|
+
function verticalShift(transform: Transform | null): string | undefined {
|
|
344
|
+
if (!transform) return undefined;
|
|
345
|
+
return CSS.Translate.toString({ ...transform, x: 0 });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function RowLabel<T>({ item, renderItem }: { item: SortableTreeItem<T>; renderItem?: SortableTreeProps<T>["renderItem"] }) {
|
|
349
|
+
return <span className="min-w-0 flex-1 truncate">{renderItem ? renderItem(item) : (item.label ?? item.id)}</span>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function RowFace<T>({
|
|
353
|
+
item,
|
|
354
|
+
renderItem,
|
|
355
|
+
disabled,
|
|
356
|
+
activator,
|
|
357
|
+
}: {
|
|
358
|
+
item: SortableTreeItem<T>;
|
|
359
|
+
renderItem?: SortableTreeProps<T>["renderItem"];
|
|
360
|
+
disabled?: boolean;
|
|
361
|
+
activator?: {
|
|
362
|
+
setRef: (element: HTMLElement | null) => void;
|
|
363
|
+
props: Record<string, unknown>;
|
|
364
|
+
};
|
|
365
|
+
}) {
|
|
366
|
+
return (
|
|
367
|
+
<div
|
|
368
|
+
ref={activator?.setRef}
|
|
369
|
+
data-tree-face={item.id}
|
|
370
|
+
className={cn(
|
|
371
|
+
"flex min-h-8 min-w-0 items-center rounded-md px-1.5 text-sm text-foreground",
|
|
372
|
+
disabled ? "cursor-not-allowed opacity-45" : "cursor-grab touch-none hover:bg-ink-hover active:cursor-grabbing",
|
|
373
|
+
)}
|
|
374
|
+
{...(disabled ? undefined : activator?.props)}
|
|
375
|
+
>
|
|
376
|
+
<RowLabel item={item} renderItem={renderItem} />
|
|
377
|
+
</div>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function OverlayBranch<T>({ item, renderItem }: { item: SortableTreeItem<T>; renderItem?: SortableTreeProps<T>["renderItem"] }) {
|
|
382
|
+
return (
|
|
383
|
+
<div className="min-w-0">
|
|
384
|
+
<div className="flex min-h-8 min-w-0 items-center px-1.5 text-sm text-foreground">
|
|
385
|
+
<RowLabel item={item} renderItem={renderItem} />
|
|
386
|
+
</div>
|
|
387
|
+
{item.children?.length ? (
|
|
388
|
+
<div className="min-w-0 ps-4">
|
|
389
|
+
{item.children.map((child) => (
|
|
390
|
+
<OverlayBranch key={child.id} item={child} renderItem={renderItem} />
|
|
391
|
+
))}
|
|
392
|
+
</div>
|
|
393
|
+
) : null}
|
|
394
|
+
</div>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function DropLine({ edge }: { edge: "top" | "bottom" }) {
|
|
399
|
+
return <span aria-hidden className={cn("pointer-events-none absolute inset-x-1 z-10 h-0.5 rounded-full bg-foreground", edge === "top" ? "top-0" : "bottom-0")} />;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function SortableNode<T>({
|
|
403
|
+
item,
|
|
404
|
+
parentId,
|
|
405
|
+
depth,
|
|
406
|
+
renderItem,
|
|
407
|
+
hint,
|
|
408
|
+
}: {
|
|
409
|
+
item: SortableTreeItem<T>;
|
|
410
|
+
parentId: string | null;
|
|
411
|
+
depth: number;
|
|
412
|
+
renderItem?: SortableTreeProps<T>["renderItem"];
|
|
413
|
+
hint: DropHint | null;
|
|
414
|
+
}) {
|
|
415
|
+
const { attributes, listeners, setActivatorNodeRef, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
416
|
+
id: item.id,
|
|
417
|
+
data: { parentId },
|
|
418
|
+
disabled: item.disabled ? { draggable: true } : false,
|
|
419
|
+
});
|
|
420
|
+
const edge = hint?.overId === item.id ? hint.edge : null;
|
|
421
|
+
|
|
422
|
+
return (
|
|
423
|
+
<div
|
|
424
|
+
ref={setNodeRef}
|
|
425
|
+
data-placeholder={isDragging ? "true" : undefined}
|
|
426
|
+
className={cn("relative min-w-0 max-w-full", isDragging && "rounded-md bg-muted shadow-[inset_0_0_0_1px_var(--nonla-border)]")}
|
|
427
|
+
style={{
|
|
428
|
+
transform: verticalShift(transform),
|
|
429
|
+
transition,
|
|
430
|
+
zIndex: isDragging ? 1 : undefined,
|
|
431
|
+
}}
|
|
432
|
+
>
|
|
433
|
+
{edge ? <DropLine edge={edge} /> : null}
|
|
434
|
+
<div className={cn("min-w-0", isDragging && "invisible")}>
|
|
435
|
+
<RowFace
|
|
436
|
+
item={item}
|
|
437
|
+
renderItem={renderItem}
|
|
438
|
+
disabled={item.disabled}
|
|
439
|
+
activator={
|
|
440
|
+
item.disabled
|
|
441
|
+
? undefined
|
|
442
|
+
: {
|
|
443
|
+
setRef: setActivatorNodeRef,
|
|
444
|
+
props: { ...attributes, ...listeners },
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/>
|
|
448
|
+
{item.children?.length ? (
|
|
449
|
+
<div className="min-w-0 ps-4">
|
|
450
|
+
<SortableLevel items={item.children} parentId={item.id} depth={depth + 1} renderItem={renderItem} hint={hint} />
|
|
451
|
+
</div>
|
|
452
|
+
) : null}
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function SortableLevel<T>({
|
|
459
|
+
items,
|
|
460
|
+
parentId,
|
|
461
|
+
depth,
|
|
462
|
+
renderItem,
|
|
463
|
+
hint,
|
|
464
|
+
}: {
|
|
465
|
+
items: SortableTreeItem<T>[];
|
|
466
|
+
parentId: string | null;
|
|
467
|
+
depth: number;
|
|
468
|
+
renderItem?: SortableTreeProps<T>["renderItem"];
|
|
469
|
+
hint: DropHint | null;
|
|
470
|
+
}) {
|
|
471
|
+
return (
|
|
472
|
+
<SortableContext items={items.map((item) => item.id)} strategy={verticalListSortingStrategy}>
|
|
473
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
474
|
+
{items.map((item) => (
|
|
475
|
+
<SortableNode key={item.id} item={item} parentId={parentId} depth={depth} renderItem={renderItem} hint={hint} />
|
|
476
|
+
))}
|
|
477
|
+
</div>
|
|
478
|
+
</SortableContext>
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function SortableTree<T = unknown>({ items, onChange, onDragEnd, renderItem, className }: SortableTreeProps<T>) {
|
|
483
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
|
484
|
+
const [hint, setHint] = useState<DropHint | null>(null);
|
|
485
|
+
const hintRef = useRef<DropHint | null>(null);
|
|
486
|
+
const overRef = useRef<string | null>(null);
|
|
487
|
+
const blockedRef = useRef<Set<string>>(new Set());
|
|
488
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
489
|
+
const onChangeRef = useRef(onChange);
|
|
490
|
+
const onDragEndRef = useRef(onDragEnd);
|
|
491
|
+
const itemsRef = useRef(items);
|
|
492
|
+
onChangeRef.current = onChange;
|
|
493
|
+
onDragEndRef.current = onDragEnd;
|
|
494
|
+
itemsRef.current = items;
|
|
495
|
+
const portal = usePopupContainer();
|
|
496
|
+
|
|
497
|
+
const sensors = useSensors(
|
|
498
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
|
|
499
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
const collisionDetection: CollisionDetection = (args) => collideTree(args, itemsRef.current, blockedRef.current, rootRef.current);
|
|
503
|
+
|
|
504
|
+
const assignHint = (next: DropHint | null) => {
|
|
505
|
+
const prev = hintRef.current;
|
|
506
|
+
if (prev?.overId === next?.overId && prev?.edge === next?.edge) return;
|
|
507
|
+
hintRef.current = next;
|
|
508
|
+
setHint(next);
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
const placeFor = (activeId: string, overId: string | null, clientY: number | null) => {
|
|
512
|
+
if (!overId) return null;
|
|
513
|
+
const active = describe(itemsRef.current, activeId);
|
|
514
|
+
const over = describe(itemsRef.current, overId);
|
|
515
|
+
if (!active || !over) return null;
|
|
516
|
+
return placement(itemsRef.current, activeId, overId, active.parentId, over.parentId, active.depth, over.depth, rowEdge(rootRef.current, overId, clientY));
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const showPlace = (activeId: string, overId: string | null, clientY: number | null) => {
|
|
520
|
+
const place = placeFor(activeId, overId, clientY);
|
|
521
|
+
assignHint(place && place !== "reorder" ? { overId: place.lineId, edge: place.edge } : null);
|
|
522
|
+
return place;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const onDragStart = (event: DragStartEvent) => {
|
|
526
|
+
const id = String(event.active.id);
|
|
527
|
+
setActiveId(id);
|
|
528
|
+
overRef.current = null;
|
|
529
|
+
const node = findItem(itemsRef.current, id);
|
|
530
|
+
blockedRef.current = new Set(node ? [id, ...descendantIds(node)] : [id]);
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
const onDragOver = (event: DragMoveEvent) => {
|
|
534
|
+
const id = event.over ? String(event.over.id) : null;
|
|
535
|
+
overRef.current = id;
|
|
536
|
+
showPlace(String(event.active.id), id, pointerY(event));
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const onDragMove = (event: DragMoveEvent) => {
|
|
540
|
+
const id = event.over ? String(event.over.id) : overRef.current;
|
|
541
|
+
if (!id) return;
|
|
542
|
+
if (event.over) overRef.current = id;
|
|
543
|
+
showPlace(String(event.active.id), id, pointerY(event));
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
const stopDrag = () => {
|
|
547
|
+
setActiveId(null);
|
|
548
|
+
overRef.current = null;
|
|
549
|
+
blockedRef.current = new Set();
|
|
550
|
+
assignHint(null);
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
const handleDragEnd = (event: DragEndEvent) => {
|
|
554
|
+
const activeDragId = String(event.active.id);
|
|
555
|
+
const overId = event.over ? String(event.over.id) : overRef.current;
|
|
556
|
+
const place = placeFor(activeDragId, overId, pointerY(event));
|
|
557
|
+
stopDrag();
|
|
558
|
+
if (!place || !overId) return;
|
|
559
|
+
const current = itemsRef.current;
|
|
560
|
+
const parentId = place === "reorder" ? parentIdOf(event.active.data.current) : place.parentId;
|
|
561
|
+
const next = place === "reorder" ? reorderSiblings(current, parentId, activeDragId, overId) : relocate(current, activeDragId, place.parentId, place.index);
|
|
562
|
+
const updates = changedIndexes(siblingIds(current, parentId), siblingIds(next, parentId));
|
|
563
|
+
if (updates.length === 0) return;
|
|
564
|
+
onChangeRef.current?.(next);
|
|
565
|
+
onDragEndRef.current?.(updates);
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const onDragCancel = () => {
|
|
569
|
+
stopDrag();
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const activeItem = activeId ? findItem(items, activeId) : null;
|
|
573
|
+
const portalNode = typeof document === "undefined" ? null : portal();
|
|
574
|
+
|
|
575
|
+
return (
|
|
576
|
+
<div ref={rootRef} className={cn("w-full min-w-0 max-w-full overscroll-x-none", className)} style={{ overflowX: "clip" }}>
|
|
577
|
+
<DndContext sensors={sensors} collisionDetection={collisionDetection} onDragStart={onDragStart} onDragOver={onDragOver} onDragMove={onDragMove} onDragEnd={handleDragEnd} onDragCancel={onDragCancel}>
|
|
578
|
+
<SortableLevel items={items} parentId={null} depth={0} renderItem={renderItem} hint={hint} />
|
|
579
|
+
{portalNode
|
|
580
|
+
? createPortal(
|
|
581
|
+
<DragOverlay
|
|
582
|
+
zIndex={1050}
|
|
583
|
+
dropAnimation={DROP_ANIMATION}
|
|
584
|
+
modifiers={[clampOverlayToWindow]}
|
|
585
|
+
className="pointer-events-none overflow-hidden rounded-md bg-card shadow-(--nonla-card-shadow)"
|
|
586
|
+
>
|
|
587
|
+
{activeItem ? (
|
|
588
|
+
<div data-sortable-overlay="">
|
|
589
|
+
<OverlayBranch item={activeItem} renderItem={renderItem} />
|
|
590
|
+
</div>
|
|
591
|
+
) : null}
|
|
592
|
+
</DragOverlay>,
|
|
593
|
+
portalNode,
|
|
594
|
+
)
|
|
595
|
+
: null}
|
|
596
|
+
</DndContext>
|
|
597
|
+
</div>
|
|
598
|
+
);
|
|
599
|
+
}
|
package/src/styles.css
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
/* ── Config. Set these. `.light` repeats the same keys. ────────────── */
|
|
21
21
|
/* Page #141414. Sidebar sits with the page, #161616. Cards #181818. */
|
|
22
22
|
--nonla-bg: #141414;
|
|
23
|
-
--nonla-text-main: #
|
|
23
|
+
--nonla-text-main: #e0e0e0;
|
|
24
24
|
--nonla-text-secondary: color-mix(in oklab, var(--nonla-text-main) 74%, var(--nonla-bg));
|
|
25
25
|
--nonla-text-tertiary: color-mix(in oklab, var(--nonla-text-main) 60%, var(--nonla-bg));
|
|
26
26
|
--nonla-text-quaternary: color-mix(in oklab, var(--nonla-text-main) 36%, var(--nonla-bg));
|
|
@@ -39,8 +39,14 @@
|
|
|
39
39
|
--nonla-input: rgba(255, 255, 235, 0.1);
|
|
40
40
|
|
|
41
41
|
--nonla-font: ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
42
|
-
/*
|
|
43
|
-
--nonla-base-text-size:
|
|
42
|
+
/* Default body size. Tailwind `text-base` follows this. Leading is 1.6. */
|
|
43
|
+
--nonla-base-text-size: 15px;
|
|
44
|
+
/* `text-md`. MarkdownViewer body and agent reply text use this. */
|
|
45
|
+
--nonla-md-text-size: 16px;
|
|
46
|
+
/* `text-sm`. Composer, tool lines, and errors use this. User bubbles use `text-base`. */
|
|
47
|
+
--nonla-sm-text-size: 14px;
|
|
48
|
+
/* Code. A step under the body, so mono does not look larger than the text around it. */
|
|
49
|
+
--nonla-mono-text-size: calc(var(--nonla-base-text-size) * 0.9);
|
|
44
50
|
--nonla-radius: 8px;
|
|
45
51
|
--nonla-height: 32px;
|
|
46
52
|
--nonla-height-sm: 24px;
|
|
@@ -122,29 +128,35 @@
|
|
|
122
128
|
font-weight: 400;
|
|
123
129
|
}
|
|
124
130
|
|
|
131
|
+
/* Size stays off `html`, so `1rem` and Tailwind spacing do not shrink. */
|
|
132
|
+
body {
|
|
133
|
+
font-size: var(--nonla-base-text-size);
|
|
134
|
+
line-height: 1.6;
|
|
135
|
+
}
|
|
136
|
+
|
|
125
137
|
/* Same color keys as Config above. Brand and the label on it stay. */
|
|
126
138
|
.light:not(.dark),
|
|
127
139
|
.light .nonla-ui:not(.dark) {
|
|
128
140
|
color-scheme: light;
|
|
129
141
|
|
|
130
|
-
/* Light grays are Tailwind neutral. Page and
|
|
131
|
-
--nonla-bg: #
|
|
132
|
-
--nonla-text-main: #
|
|
133
|
-
--nonla-text-secondary: #737373;
|
|
134
|
-
--nonla-text-tertiary: #a1a1a1;
|
|
135
|
-
--nonla-text-quaternary: #d4d4d4;
|
|
136
|
-
--nonla-text-on-solid: #ffffff;
|
|
142
|
+
/* Light grays are Tailwind neutral. Page is white. Sidebar and cards are neutral-50. */
|
|
143
|
+
--nonla-bg: #ffffff; /* white */
|
|
144
|
+
--nonla-text-main: #262626; /* neutral-800 */
|
|
145
|
+
--nonla-text-secondary: #737373; /* neutral-500 */
|
|
146
|
+
--nonla-text-tertiary: #a1a1a1; /* neutral-400 */
|
|
147
|
+
--nonla-text-quaternary: #d4d4d4; /* neutral-300 */
|
|
148
|
+
--nonla-text-on-solid: #ffffff; /* white */
|
|
137
149
|
--nonla-brand: #f18d00;
|
|
138
150
|
--nonla-danger: #dc3b3b;
|
|
139
151
|
--nonla-success: #2f7d4a;
|
|
140
|
-
--nonla-warn: #a16207;
|
|
152
|
+
--nonla-warn: #a16207; /* yellow-700 */
|
|
141
153
|
--nonla-link: #3b6d99;
|
|
142
154
|
|
|
143
|
-
--nonla-sidebar: #fafafa;
|
|
144
|
-
--nonla-surface: #
|
|
145
|
-
--nonla-bar: #e5e5e5;
|
|
146
|
-
--nonla-border: #e5e5e5;
|
|
147
|
-
--nonla-border-secondary: #f5f5f5;
|
|
155
|
+
--nonla-sidebar: #fafafa; /* neutral-50 */
|
|
156
|
+
--nonla-surface: #fafafa; /* neutral-50 */
|
|
157
|
+
--nonla-bar: #e5e5e5; /* neutral-200 */
|
|
158
|
+
--nonla-border: #e5e5e5; /* neutral-200 */
|
|
159
|
+
--nonla-border-secondary: #f5f5f5; /* neutral-100 */
|
|
148
160
|
--nonla-input: rgb(0 0 0 / 11%);
|
|
149
161
|
|
|
150
162
|
--mask: rgb(0 0 0 / 40%);
|
|
@@ -211,6 +223,14 @@
|
|
|
211
223
|
--spacing-field-lg: 40px;
|
|
212
224
|
--spacing-field-nav: 32px;
|
|
213
225
|
|
|
226
|
+
--text-sm: var(--nonla-sm-text-size);
|
|
227
|
+
--text-base: var(--nonla-base-text-size);
|
|
228
|
+
--text-base--line-height: 1.6;
|
|
229
|
+
--text-md: var(--nonla-md-text-size);
|
|
230
|
+
--text-md--line-height: calc(1.5 / 1);
|
|
231
|
+
--text-lg: 18px;
|
|
232
|
+
--text-lg--line-height: calc(1.75 / 1.125);
|
|
233
|
+
|
|
214
234
|
--font-sans: var(--nonla-font);
|
|
215
235
|
--font-family-sans: var(--font-sans);
|
|
216
236
|
--default-font-family: var(--font-sans);
|