devnonla-ui 0.16.0 → 0.17.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 +7 -0
- package/package.json +3 -1
- package/src/app/App.tsx +34 -16
- package/src/app/context.ts +1 -1
- package/src/avatar/AgentAvatar.tsx +125 -21
- package/src/avatar/avatar.css +3 -58
- package/src/index.ts +0 -87
- package/src/markdown-editor/MarkdownViewer.tsx +1 -1
- package/src/markdown-editor/ReactCodeRunner.tsx +10 -2
- package/src/markdown-editor/index.ts +13 -0
- package/src/styles.css +73 -81
- package/src/theme.ts +36 -11
- package/src/typography/Typography.tsx +1 -1
- package/src/desktop/DesktopHeader.tsx +0 -87
- package/src/desktop/DesktopIcon.tsx +0 -25
- package/src/desktop/DesktopStage.tsx +0 -6
- package/src/desktop/DesktopWindow.tsx +0 -677
- package/src/desktop/MeadowDesktop.tsx +0 -15
- package/src/desktop/MeadowShell.tsx +0 -12
- package/src/desktop/MeadowWallpaper.tsx +0 -5
- package/src/desktop/assets/desktop-meadow.jpg +0 -0
- package/src/desktop/assets.d.ts +0 -9
- package/src/desktop/surface.ts +0 -1
- /package/src/{markdown-editor → lib}/markdownScale.ts +0 -0
|
@@ -1,677 +0,0 @@
|
|
|
1
|
-
import { createContext, type MouseEvent as ReactMouseEvent, type ReactNode, type PointerEvent as ReactPointerEvent, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { createPortal } from "react-dom";
|
|
3
|
-
import { cn } from "../lib/cn";
|
|
4
|
-
import { glassSurfaceClass } from "../lib/surface";
|
|
5
|
-
import { OverlayScroll, type OverlayScrollVisibility } from "../scroll/OverlayScroll";
|
|
6
|
-
|
|
7
|
-
type Phase = "enter" | "open" | "leaving";
|
|
8
|
-
type Size = { w: number; h: number };
|
|
9
|
-
type Point = { x: number; y: number };
|
|
10
|
-
type Rect = { x: number; y: number; w: number; h: number };
|
|
11
|
-
type Edge = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
|
|
12
|
-
|
|
13
|
-
const EASE = "var(--nonla-ease-out, cubic-bezier(0.16, 1, 0.3, 1))";
|
|
14
|
-
const MIN_W = 400;
|
|
15
|
-
const MIN_H = 240;
|
|
16
|
-
|
|
17
|
-
const HANDLES: { edge: Edge; className: string; cursor: string }[] = [
|
|
18
|
-
{ edge: "n", className: "-top-1 right-3 left-3 h-2 cursor-n-resize", cursor: "n-resize" },
|
|
19
|
-
{ edge: "s", className: "-bottom-1 right-3 left-3 h-2 cursor-s-resize", cursor: "s-resize" },
|
|
20
|
-
{ edge: "e", className: "-right-1.5 top-3 bottom-3 w-1.5 cursor-e-resize", cursor: "e-resize" },
|
|
21
|
-
{ edge: "w", className: "-left-1.5 top-3 bottom-3 w-1.5 cursor-w-resize", cursor: "w-resize" },
|
|
22
|
-
{ edge: "ne", className: "-top-1 -right-1.5 size-3 cursor-nesw-resize", cursor: "nesw-resize" },
|
|
23
|
-
{ edge: "nw", className: "-top-1 -left-1.5 size-3 cursor-nwse-resize", cursor: "nwse-resize" },
|
|
24
|
-
{ edge: "se", className: "-bottom-1 -right-1.5 size-3 cursor-nwse-resize", cursor: "nwse-resize" },
|
|
25
|
-
{ edge: "sw", className: "-bottom-1 -left-1.5 size-3 cursor-nesw-resize", cursor: "nesw-resize" },
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
function prefersReducedMotion() {
|
|
29
|
-
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function isEditableTarget(target: EventTarget | null) {
|
|
33
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
34
|
-
if (target.isContentEditable) return true;
|
|
35
|
-
const tag = target.tagName;
|
|
36
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
37
|
-
return Boolean(target.closest(".monaco-editor"));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function hasOpenDialog() {
|
|
41
|
-
return Boolean(document.querySelector('dialog[open], [role="dialog"][data-state="open"], .nonla-modal-content'));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function zoomOrigin(overlay: HTMLElement, frame: HTMLElement, source: HTMLElement | null) {
|
|
45
|
-
const from = source ?? document.querySelector('[aria-current="true"]');
|
|
46
|
-
if (!(from instanceof HTMLElement)) return "50% 50%";
|
|
47
|
-
|
|
48
|
-
const icon = from.getBoundingClientRect();
|
|
49
|
-
const overlayBox = overlay.getBoundingClientRect();
|
|
50
|
-
const x = icon.left + icon.width / 2 - overlayBox.left - frame.offsetLeft;
|
|
51
|
-
const y = icon.top + icon.height / 2 - overlayBox.top - frame.offsetTop;
|
|
52
|
-
return `${x}px ${y}px`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function compactSize(view: Size): Size {
|
|
56
|
-
return {
|
|
57
|
-
w: Math.min(window.innerWidth * 0.8, view.w),
|
|
58
|
-
h: Math.max(0, view.h - 40),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function clampSize(view: Size, size: Size): Size {
|
|
63
|
-
return {
|
|
64
|
-
w: Math.min(view.w, Math.max(Math.min(MIN_W, view.w), size.w)),
|
|
65
|
-
h: Math.min(view.h, Math.max(Math.min(MIN_H, view.h), size.h)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function windowSize(view: Size, size: Size | null): Size {
|
|
70
|
-
return size ? clampSize(view, size) : compactSize(view);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function clampOffset(view: Size, compact: Size, next: Point) {
|
|
74
|
-
const maxX = Math.max(0, (view.w - compact.w) / 2);
|
|
75
|
-
const maxY = Math.max(0, (view.h - compact.h) / 2);
|
|
76
|
-
return {
|
|
77
|
-
x: Math.min(maxX, Math.max(-maxX, next.x)),
|
|
78
|
-
y: Math.min(maxY, Math.max(-maxY, next.y)),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function collapsedRect(view: Size, offset: Point, size: Size | null): Rect {
|
|
83
|
-
const compact = windowSize(view, size);
|
|
84
|
-
const clamped = clampOffset(view, compact, offset);
|
|
85
|
-
return {
|
|
86
|
-
x: (view.w - compact.w) / 2 + clamped.x,
|
|
87
|
-
y: (view.h - compact.h) / 2 + clamped.y,
|
|
88
|
-
w: compact.w,
|
|
89
|
-
h: compact.h,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function applyResize(view: Size, orig: Rect, edge: Edge, dx: number, dy: number): Rect {
|
|
94
|
-
let w = orig.w;
|
|
95
|
-
let h = orig.h;
|
|
96
|
-
if (edge.includes("e")) w = orig.w + dx;
|
|
97
|
-
if (edge.includes("s")) h = orig.h + dy;
|
|
98
|
-
if (edge.includes("w")) w = orig.w - dx;
|
|
99
|
-
if (edge.includes("n")) h = orig.h - dy;
|
|
100
|
-
|
|
101
|
-
const minW = Math.min(MIN_W, view.w);
|
|
102
|
-
const minH = Math.min(MIN_H, view.h);
|
|
103
|
-
w = Math.min(view.w, Math.max(minW, w));
|
|
104
|
-
h = Math.min(view.h, Math.max(minH, h));
|
|
105
|
-
|
|
106
|
-
let x = orig.x;
|
|
107
|
-
let y = orig.y;
|
|
108
|
-
if (edge.includes("w")) {
|
|
109
|
-
x = orig.x + orig.w - w;
|
|
110
|
-
if (x < 0) {
|
|
111
|
-
w += x;
|
|
112
|
-
x = 0;
|
|
113
|
-
}
|
|
114
|
-
} else if (edge.includes("e")) {
|
|
115
|
-
if (x + w > view.w) w = view.w - x;
|
|
116
|
-
} else {
|
|
117
|
-
x = Math.min(Math.max(0, orig.x), Math.max(0, view.w - w));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (edge.includes("n")) {
|
|
121
|
-
y = orig.y + orig.h - h;
|
|
122
|
-
if (y < 0) {
|
|
123
|
-
h += y;
|
|
124
|
-
y = 0;
|
|
125
|
-
}
|
|
126
|
-
} else if (edge.includes("s")) {
|
|
127
|
-
if (y + h > view.h) h = view.h - y;
|
|
128
|
-
} else {
|
|
129
|
-
y = Math.min(Math.max(0, orig.y), Math.max(0, view.h - h));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return { x, y, w, h };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function offsetFromRect(view: Size, rect: Rect): Point {
|
|
136
|
-
return {
|
|
137
|
-
x: rect.x - (view.w - rect.w) / 2,
|
|
138
|
-
y: rect.y - (view.h - rect.h) / 2,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
type Geometry = Point & Size;
|
|
143
|
-
|
|
144
|
-
const GEOMETRY_PREFIX = "nonla-desktop-window:";
|
|
145
|
-
const geometryMemory = new Map<string, Geometry>();
|
|
146
|
-
|
|
147
|
-
function isGeometry(value: unknown): value is Geometry {
|
|
148
|
-
if (!value || typeof value !== "object") return false;
|
|
149
|
-
const { x, y, w, h } = value as Record<string, unknown>;
|
|
150
|
-
return [x, y, w, h].every((n) => typeof n === "number" && Number.isFinite(n));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function geometryStorageKey(persistKey: string) {
|
|
154
|
-
return `${GEOMETRY_PREFIX}${persistKey}`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function readGeometry(persistKey: string | false): Geometry | null {
|
|
158
|
-
if (!persistKey) return null;
|
|
159
|
-
const cached = geometryMemory.get(persistKey);
|
|
160
|
-
if (cached) return cached;
|
|
161
|
-
try {
|
|
162
|
-
const raw = localStorage.getItem(geometryStorageKey(persistKey));
|
|
163
|
-
if (!raw) return null;
|
|
164
|
-
const parsed: unknown = JSON.parse(raw);
|
|
165
|
-
if (!isGeometry(parsed)) return null;
|
|
166
|
-
geometryMemory.set(persistKey, parsed);
|
|
167
|
-
return parsed;
|
|
168
|
-
} catch {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function writeGeometry(persistKey: string | false, geometry: Geometry) {
|
|
174
|
-
if (!persistKey) return;
|
|
175
|
-
geometryMemory.set(persistKey, geometry);
|
|
176
|
-
try {
|
|
177
|
-
localStorage.setItem(geometryStorageKey(persistKey), JSON.stringify(geometry));
|
|
178
|
-
} catch {
|
|
179
|
-
/* private mode / quota */
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function initialView(): Size {
|
|
184
|
-
return { w: window.innerWidth, h: Math.max(0, window.innerHeight - 42) };
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function restoreGeometry(persistKey: string | false, view: Size): { offset: Point; size: Size | null } {
|
|
188
|
-
const stored = readGeometry(persistKey);
|
|
189
|
-
if (!stored) return { offset: { x: 0, y: 0 }, size: null };
|
|
190
|
-
const size = clampSize(view, stored);
|
|
191
|
-
return { offset: clampOffset(view, size, stored), size };
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function persistGeometry(persistKey: string | false, view: Size, offset: Point, size: Size | null) {
|
|
195
|
-
const compact = windowSize(view, size);
|
|
196
|
-
const clamped = clampOffset(view, compact, offset);
|
|
197
|
-
writeGeometry(persistKey, {
|
|
198
|
-
x: Math.round(clamped.x),
|
|
199
|
-
y: Math.round(clamped.y),
|
|
200
|
-
w: Math.round(compact.w),
|
|
201
|
-
h: Math.round(compact.h),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function lockResizeCursor(cursor: string | null) {
|
|
206
|
-
document.body.style.cursor = cursor ?? "";
|
|
207
|
-
document.body.style.userSelect = cursor ? "none" : "";
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function GlyphClose() {
|
|
211
|
-
return (
|
|
212
|
-
<svg width="7" height="7" viewBox="0 0 6 6" aria-hidden className="block">
|
|
213
|
-
<path d="M1.1 1.1l3.8 3.8M4.9 1.1L1.1 4.9" fill="none" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round" />
|
|
214
|
-
</svg>
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function GlyphExpand({ restore }: { restore?: boolean }) {
|
|
219
|
-
if (restore) {
|
|
220
|
-
return (
|
|
221
|
-
<svg width="7" height="7" viewBox="0 0 6 6" aria-hidden className="block">
|
|
222
|
-
<path d="M1.1 2.4V.9H2.6M4.9 3.6v1.5H3.4" fill="none" stroke="currentColor" strokeWidth="1.1" strokeLinecap="round" strokeLinejoin="round" />
|
|
223
|
-
</svg>
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
return (
|
|
227
|
-
<svg width="7" height="7" viewBox="0 0 6 6" aria-hidden className="block">
|
|
228
|
-
<path d="M.8 3.4V.8H3.4zM5.2 2.6v2.6H2.6z" fill="currentColor" />
|
|
229
|
-
</svg>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function TrafficLight({
|
|
234
|
-
label,
|
|
235
|
-
onClick,
|
|
236
|
-
shortcut,
|
|
237
|
-
tone,
|
|
238
|
-
children,
|
|
239
|
-
}: {
|
|
240
|
-
label: string;
|
|
241
|
-
onClick: () => void;
|
|
242
|
-
shortcut?: string;
|
|
243
|
-
tone: "close" | "expand";
|
|
244
|
-
children: ReactNode;
|
|
245
|
-
}) {
|
|
246
|
-
return (
|
|
247
|
-
<button
|
|
248
|
-
type="button"
|
|
249
|
-
aria-label={label}
|
|
250
|
-
aria-keyshortcuts={shortcut}
|
|
251
|
-
onClick={onClick}
|
|
252
|
-
className={`inline-flex size-3.5 shrink-0 cursor-pointer appearance-none items-center justify-center rounded-full border-0 p-0 outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand ${tone === "close" ? "bg-[#ff5f57] text-[#7a1210]" : "bg-[#28c840] text-[#0d5c18]"}`}
|
|
253
|
-
>
|
|
254
|
-
<span className="flex opacity-0 transition-opacity duration-75 group-hover/traffic:opacity-100 group-focus-within/traffic:opacity-100">{children}</span>
|
|
255
|
-
</button>
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function WindowTraffic({
|
|
260
|
-
expanded,
|
|
261
|
-
floating,
|
|
262
|
-
onClose,
|
|
263
|
-
onToggleExpand,
|
|
264
|
-
}: {
|
|
265
|
-
expanded: boolean;
|
|
266
|
-
floating?: boolean;
|
|
267
|
-
onClose: () => void;
|
|
268
|
-
onToggleExpand: () => void;
|
|
269
|
-
}) {
|
|
270
|
-
return (
|
|
271
|
-
<div className={cn("group/traffic flex shrink-0 items-center gap-2", floating && "absolute top-3 left-3 z-20")}>
|
|
272
|
-
<TrafficLight label="Close window" tone="close" onClick={onClose} shortcut="Esc">
|
|
273
|
-
<GlyphClose />
|
|
274
|
-
</TrafficLight>
|
|
275
|
-
<TrafficLight label={expanded ? "Restore window" : "Expand window"} tone="expand" onClick={onToggleExpand} shortcut="Shift + ↑">
|
|
276
|
-
<GlyphExpand restore={expanded} />
|
|
277
|
-
</TrafficLight>
|
|
278
|
-
</div>
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
type WindowHeaderSlot = {
|
|
283
|
-
left: HTMLElement | null;
|
|
284
|
-
right: HTMLElement | null;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
const WindowHeaderSlotContext = createContext<WindowHeaderSlot | null>(null);
|
|
288
|
-
|
|
289
|
-
export type WindowHeaderProps = {
|
|
290
|
-
left?: ReactNode;
|
|
291
|
-
right?: ReactNode;
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
/** Injects into the window title bar from a child. Prefer `DesktopWindow` `left` / `right` when the parent can pass them. */
|
|
295
|
-
export function WindowHeader({ left, right }: WindowHeaderProps) {
|
|
296
|
-
const ctx = useContext(WindowHeaderSlotContext);
|
|
297
|
-
if (!ctx) return null;
|
|
298
|
-
return (
|
|
299
|
-
<>
|
|
300
|
-
{ctx.left && left != null ? createPortal(left, ctx.left) : null}
|
|
301
|
-
{ctx.right && right != null ? createPortal(right, ctx.right) : null}
|
|
302
|
-
</>
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export type DesktopWindowProps = {
|
|
307
|
-
title?: ReactNode;
|
|
308
|
-
left?: ReactNode;
|
|
309
|
-
right?: ReactNode;
|
|
310
|
-
/** Title bar. `false` hides it so children fill the frame; close and expand stay pinned over the top-left. */
|
|
311
|
-
header?: boolean;
|
|
312
|
-
expanded: boolean;
|
|
313
|
-
onClose: () => void;
|
|
314
|
-
onToggleExpand: () => void;
|
|
315
|
-
/** Overlay auto-hide scrollbar on the body. Pass `false` when children manage their own scroll (split panes, AgentPanel). */
|
|
316
|
-
scroll?: boolean;
|
|
317
|
-
scrollbar?: OverlayScrollVisibility;
|
|
318
|
-
/** Last collapsed position and size. Default `"default"`. Pass a unique key per window, or `false` to disable. */
|
|
319
|
-
persistKey?: string | false;
|
|
320
|
-
/** Zoom from this element on open, and back to it on close. Falls back to the active desktop icon. */
|
|
321
|
-
origin?: { current: HTMLElement | null };
|
|
322
|
-
/** Animated close. Call this instead of unmounting so the window shrinks back to `origin`. */
|
|
323
|
-
closeRef?: { current: (() => void) | null };
|
|
324
|
-
children: ReactNode;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
export function DesktopWindow({
|
|
328
|
-
title,
|
|
329
|
-
left,
|
|
330
|
-
right,
|
|
331
|
-
header = true,
|
|
332
|
-
expanded,
|
|
333
|
-
onClose,
|
|
334
|
-
onToggleExpand,
|
|
335
|
-
scroll = true,
|
|
336
|
-
scrollbar = "hover",
|
|
337
|
-
persistKey = "default",
|
|
338
|
-
origin,
|
|
339
|
-
closeRef,
|
|
340
|
-
children,
|
|
341
|
-
}: DesktopWindowProps) {
|
|
342
|
-
const overlayRef = useRef<HTMLDivElement>(null);
|
|
343
|
-
const frameRef = useRef<HTMLElement>(null);
|
|
344
|
-
const closedRef = useRef(false);
|
|
345
|
-
const expandedRef = useRef(expanded);
|
|
346
|
-
const dragRef = useRef<{
|
|
347
|
-
pointerId: number;
|
|
348
|
-
startX: number;
|
|
349
|
-
startY: number;
|
|
350
|
-
origX: number;
|
|
351
|
-
origY: number;
|
|
352
|
-
} | null>(null);
|
|
353
|
-
const resizeRef = useRef<{
|
|
354
|
-
pointerId: number;
|
|
355
|
-
edge: Edge;
|
|
356
|
-
startX: number;
|
|
357
|
-
startY: number;
|
|
358
|
-
orig: Rect;
|
|
359
|
-
} | null>(null);
|
|
360
|
-
const [phase, setPhase] = useState<Phase>(() => (prefersReducedMotion() ? "open" : "enter"));
|
|
361
|
-
const [view, setView] = useState<Size>(initialView);
|
|
362
|
-
const [offset, setOffset] = useState(() => restoreGeometry(persistKey, initialView()).offset);
|
|
363
|
-
const [size, setSize] = useState<Size | null>(() => restoreGeometry(persistKey, initialView()).size);
|
|
364
|
-
const [dragging, setDragging] = useState(false);
|
|
365
|
-
const [resizing, setResizing] = useState(false);
|
|
366
|
-
const sizeRef = useRef<Size | null>(null);
|
|
367
|
-
const [leftSlot, setLeftSlot] = useState<HTMLDivElement | null>(null);
|
|
368
|
-
const [rightSlot, setRightSlot] = useState<HTMLDivElement | null>(null);
|
|
369
|
-
const headerChrome = useMemo(() => ({ left: leftSlot, right: rightSlot }), [leftSlot, rightSlot]);
|
|
370
|
-
const requestCloseRef = useRef<() => void>(() => {});
|
|
371
|
-
const viewRef = useRef(view);
|
|
372
|
-
const offsetRef = useRef(offset);
|
|
373
|
-
const draggingRef = useRef(false);
|
|
374
|
-
const gestureCleanupRef = useRef<(() => void) | null>(null);
|
|
375
|
-
expandedRef.current = expanded;
|
|
376
|
-
sizeRef.current = size;
|
|
377
|
-
viewRef.current = view;
|
|
378
|
-
offsetRef.current = offset;
|
|
379
|
-
|
|
380
|
-
const applyOrigin = () => {
|
|
381
|
-
const overlay = overlayRef.current;
|
|
382
|
-
const frame = frameRef.current;
|
|
383
|
-
if (!overlay || !frame) return;
|
|
384
|
-
frame.style.transformOrigin = zoomOrigin(overlay, frame, origin?.current ?? null);
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
useLayoutEffect(() => {
|
|
388
|
-
applyOrigin();
|
|
389
|
-
}, []);
|
|
390
|
-
|
|
391
|
-
useEffect(() => {
|
|
392
|
-
if (phase !== "enter") return;
|
|
393
|
-
const id = requestAnimationFrame(() => setPhase("open"));
|
|
394
|
-
return () => cancelAnimationFrame(id);
|
|
395
|
-
}, [phase]);
|
|
396
|
-
|
|
397
|
-
useLayoutEffect(() => {
|
|
398
|
-
if (!closeRef) return;
|
|
399
|
-
closeRef.current = () => requestCloseRef.current();
|
|
400
|
-
return () => {
|
|
401
|
-
closeRef.current = null;
|
|
402
|
-
};
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
const requestClose = () => {
|
|
406
|
-
if (closedRef.current || phase === "leaving") return;
|
|
407
|
-
if (prefersReducedMotion()) {
|
|
408
|
-
closedRef.current = true;
|
|
409
|
-
onClose();
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
applyOrigin();
|
|
413
|
-
setPhase("leaving");
|
|
414
|
-
};
|
|
415
|
-
requestCloseRef.current = requestClose;
|
|
416
|
-
|
|
417
|
-
useEffect(() => {
|
|
418
|
-
if (phase !== "leaving") return;
|
|
419
|
-
const t = window.setTimeout(() => {
|
|
420
|
-
if (closedRef.current) return;
|
|
421
|
-
closedRef.current = true;
|
|
422
|
-
onClose();
|
|
423
|
-
}, 280);
|
|
424
|
-
return () => window.clearTimeout(t);
|
|
425
|
-
}, [phase, onClose]);
|
|
426
|
-
|
|
427
|
-
useLayoutEffect(() => {
|
|
428
|
-
const overlay = overlayRef.current;
|
|
429
|
-
if (!overlay) return;
|
|
430
|
-
|
|
431
|
-
const sync = () => {
|
|
432
|
-
const next = { w: overlay.clientWidth, h: overlay.clientHeight };
|
|
433
|
-
setView((prev) => (prev.w === next.w && prev.h === next.h ? prev : next));
|
|
434
|
-
if (expandedRef.current) return;
|
|
435
|
-
const fitted = windowSize(next, sizeRef.current);
|
|
436
|
-
if (sizeRef.current) {
|
|
437
|
-
setSize((current) => {
|
|
438
|
-
if (!current || (current.w === fitted.w && current.h === fitted.h)) return current;
|
|
439
|
-
return fitted;
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
setOffset((current) => {
|
|
443
|
-
const clamped = clampOffset(next, fitted, current);
|
|
444
|
-
if (clamped.x === current.x && clamped.y === current.y) return current;
|
|
445
|
-
return clamped;
|
|
446
|
-
});
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
sync();
|
|
450
|
-
const observer = new ResizeObserver(sync);
|
|
451
|
-
observer.observe(overlay);
|
|
452
|
-
return () => observer.disconnect();
|
|
453
|
-
}, []);
|
|
454
|
-
|
|
455
|
-
useEffect(() => {
|
|
456
|
-
if (dragging || resizing) return;
|
|
457
|
-
persistGeometry(persistKey, view, offset, size);
|
|
458
|
-
}, [dragging, resizing, offset, size, view, persistKey]);
|
|
459
|
-
|
|
460
|
-
useEffect(() => {
|
|
461
|
-
return () => {
|
|
462
|
-
persistGeometry(persistKey, viewRef.current, offsetRef.current, sizeRef.current);
|
|
463
|
-
};
|
|
464
|
-
}, [persistKey]);
|
|
465
|
-
|
|
466
|
-
useEffect(() => {
|
|
467
|
-
const onKey = (e: KeyboardEvent) => {
|
|
468
|
-
if (e.key !== "Escape" || e.defaultPrevented || isEditableTarget(e.target) || hasOpenDialog()) return;
|
|
469
|
-
e.preventDefault();
|
|
470
|
-
requestCloseRef.current();
|
|
471
|
-
};
|
|
472
|
-
window.addEventListener("keydown", onKey);
|
|
473
|
-
return () => {
|
|
474
|
-
window.removeEventListener("keydown", onKey);
|
|
475
|
-
gestureCleanupRef.current?.();
|
|
476
|
-
gestureCleanupRef.current = null;
|
|
477
|
-
lockResizeCursor(null);
|
|
478
|
-
};
|
|
479
|
-
}, []);
|
|
480
|
-
|
|
481
|
-
const listenPointer = (pointerId: number, onMove: (e: PointerEvent) => void) => {
|
|
482
|
-
gestureCleanupRef.current?.();
|
|
483
|
-
|
|
484
|
-
const move = (e: PointerEvent) => {
|
|
485
|
-
if (e.pointerId !== pointerId) return;
|
|
486
|
-
if (e.buttons === 0) {
|
|
487
|
-
up(e);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
onMove(e);
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const up = (e: PointerEvent) => {
|
|
494
|
-
if (e.pointerId !== pointerId) return;
|
|
495
|
-
window.removeEventListener("pointermove", move, true);
|
|
496
|
-
window.removeEventListener("pointerup", up, true);
|
|
497
|
-
window.removeEventListener("pointercancel", up, true);
|
|
498
|
-
gestureCleanupRef.current = null;
|
|
499
|
-
dragRef.current = null;
|
|
500
|
-
resizeRef.current = null;
|
|
501
|
-
draggingRef.current = false;
|
|
502
|
-
setDragging(false);
|
|
503
|
-
setResizing(false);
|
|
504
|
-
lockResizeCursor(null);
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
window.addEventListener("pointermove", move, true);
|
|
508
|
-
window.addEventListener("pointerup", up, true);
|
|
509
|
-
window.addEventListener("pointercancel", up, true);
|
|
510
|
-
gestureCleanupRef.current = () => {
|
|
511
|
-
window.removeEventListener("pointermove", move, true);
|
|
512
|
-
window.removeEventListener("pointerup", up, true);
|
|
513
|
-
window.removeEventListener("pointercancel", up, true);
|
|
514
|
-
};
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
const startDrag = (e: ReactPointerEvent<HTMLElement>) => {
|
|
518
|
-
if (e.button !== 0 || expanded || phase === "leaving" || resizeRef.current) return;
|
|
519
|
-
if ((e.target as HTMLElement).closest("button, a, input, textarea, select, [role='button']")) return;
|
|
520
|
-
|
|
521
|
-
dragRef.current = {
|
|
522
|
-
pointerId: e.pointerId,
|
|
523
|
-
startX: e.clientX,
|
|
524
|
-
startY: e.clientY,
|
|
525
|
-
origX: offsetRef.current.x,
|
|
526
|
-
origY: offsetRef.current.y,
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
listenPointer(e.pointerId, (ev) => {
|
|
530
|
-
const drag = dragRef.current;
|
|
531
|
-
if (!drag) return;
|
|
532
|
-
const dx = ev.clientX - drag.startX;
|
|
533
|
-
const dy = ev.clientY - drag.startY;
|
|
534
|
-
if (!draggingRef.current && dx * dx + dy * dy < 16) return;
|
|
535
|
-
if (!draggingRef.current) {
|
|
536
|
-
draggingRef.current = true;
|
|
537
|
-
setDragging(true);
|
|
538
|
-
}
|
|
539
|
-
const nextView = viewRef.current;
|
|
540
|
-
setOffset(
|
|
541
|
-
clampOffset(nextView, windowSize(nextView, sizeRef.current), {
|
|
542
|
-
x: drag.origX + dx,
|
|
543
|
-
y: drag.origY + dy,
|
|
544
|
-
}),
|
|
545
|
-
);
|
|
546
|
-
});
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
const startResize = (edge: Edge, e: ReactPointerEvent<HTMLElement>) => {
|
|
550
|
-
if (e.button !== 0 || phase === "leaving") return;
|
|
551
|
-
e.stopPropagation();
|
|
552
|
-
e.preventDefault();
|
|
553
|
-
|
|
554
|
-
const nextView = viewRef.current;
|
|
555
|
-
const orig = expandedRef.current
|
|
556
|
-
? { x: 0, y: 0, w: nextView.w, h: nextView.h }
|
|
557
|
-
: collapsedRect(nextView, offsetRef.current, sizeRef.current);
|
|
558
|
-
|
|
559
|
-
if (expandedRef.current) {
|
|
560
|
-
const nextSize = { w: orig.w, h: orig.h };
|
|
561
|
-
const nextOffset = offsetFromRect(nextView, orig);
|
|
562
|
-
sizeRef.current = nextSize;
|
|
563
|
-
offsetRef.current = nextOffset;
|
|
564
|
-
setSize(nextSize);
|
|
565
|
-
setOffset(nextOffset);
|
|
566
|
-
onToggleExpand();
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
resizeRef.current = {
|
|
570
|
-
pointerId: e.pointerId,
|
|
571
|
-
edge,
|
|
572
|
-
startX: e.clientX,
|
|
573
|
-
startY: e.clientY,
|
|
574
|
-
orig,
|
|
575
|
-
};
|
|
576
|
-
setResizing(true);
|
|
577
|
-
lockResizeCursor(HANDLES.find((handle) => handle.edge === edge)?.cursor ?? "nwse-resize");
|
|
578
|
-
|
|
579
|
-
listenPointer(e.pointerId, (ev) => {
|
|
580
|
-
const gesture = resizeRef.current;
|
|
581
|
-
if (!gesture) return;
|
|
582
|
-
const nextView = viewRef.current;
|
|
583
|
-
const next = applyResize(nextView, gesture.orig, gesture.edge, ev.clientX - gesture.startX, ev.clientY - gesture.startY);
|
|
584
|
-
setSize({ w: next.w, h: next.h });
|
|
585
|
-
setOffset(offsetFromRect(nextView, next));
|
|
586
|
-
});
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
const onTitleBarDoubleClick = (e: ReactMouseEvent<HTMLElement>) => {
|
|
590
|
-
if (phase === "leaving") return;
|
|
591
|
-
if ((e.target as HTMLElement).closest("button, a, input, textarea, select, [role='button']")) return;
|
|
592
|
-
e.preventDefault();
|
|
593
|
-
dragRef.current = null;
|
|
594
|
-
setDragging(false);
|
|
595
|
-
onToggleExpand();
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
const shown = phase === "open";
|
|
599
|
-
const leaving = phase === "leaving";
|
|
600
|
-
const rect = expanded ? { x: 0, y: 0, w: view.w, h: view.h } : collapsedRect(view, offset, size);
|
|
601
|
-
const reduce = prefersReducedMotion();
|
|
602
|
-
const duration = reduce ? "150ms" : "300ms";
|
|
603
|
-
const geom = phase === "open" && !dragging && !resizing && !reduce ? `top ${duration} ${EASE}, left ${duration} ${EASE}, width ${duration} ${EASE}, height ${duration} ${EASE}` : "";
|
|
604
|
-
const zoom = !dragging && !resizing && !reduce ? `opacity ${duration} ${EASE}, transform ${duration} ${EASE}` : "";
|
|
605
|
-
|
|
606
|
-
return (
|
|
607
|
-
<WindowHeaderSlotContext.Provider value={headerChrome}>
|
|
608
|
-
<div ref={overlayRef} className="nonla-window-layer pointer-events-none absolute inset-x-0 bottom-0 top-[42px] z-(--nonla-z-window,30)">
|
|
609
|
-
<section
|
|
610
|
-
ref={frameRef}
|
|
611
|
-
aria-label={typeof title === "string" && title ? title : "Window"}
|
|
612
|
-
onTransitionEnd={(e) => {
|
|
613
|
-
if (e.target !== e.currentTarget) return;
|
|
614
|
-
if (phase !== "leaving") return;
|
|
615
|
-
if (e.propertyName !== "opacity" && e.propertyName !== "transform") return;
|
|
616
|
-
if (closedRef.current) return;
|
|
617
|
-
closedRef.current = true;
|
|
618
|
-
onClose();
|
|
619
|
-
}}
|
|
620
|
-
style={{
|
|
621
|
-
top: rect.y,
|
|
622
|
-
left: rect.x,
|
|
623
|
-
width: rect.w,
|
|
624
|
-
height: rect.h,
|
|
625
|
-
opacity: shown ? 1 : 0,
|
|
626
|
-
transform: shown ? "scale(1)" : "scale(0.18)",
|
|
627
|
-
transition: [geom, zoom].filter(Boolean).join(", ") || undefined,
|
|
628
|
-
}}
|
|
629
|
-
data-expanded={expanded || undefined}
|
|
630
|
-
className={cn("absolute flex flex-col rounded-xl pointer-events-auto transform-gpu", glassSurfaceClass, "nonla-window-glass border border-solid border-border bg-background shadow-(--nonla-shadow)", phase !== "open" && "pointer-events-none")}
|
|
631
|
-
>
|
|
632
|
-
<div className="relative flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl">
|
|
633
|
-
{header ? (
|
|
634
|
-
<header
|
|
635
|
-
onPointerDown={startDrag}
|
|
636
|
-
className="nonla-window-header flex h-9 shrink-0 cursor-default touch-none items-center gap-4 border-0 bg-bar px-3 select-none"
|
|
637
|
-
>
|
|
638
|
-
<WindowTraffic expanded={expanded} onClose={requestClose} onToggleExpand={onToggleExpand} />
|
|
639
|
-
<div className="flex min-w-0 flex-1 items-center">
|
|
640
|
-
<div className="flex min-w-0 items-center">
|
|
641
|
-
{left}
|
|
642
|
-
<div ref={setLeftSlot} className="contents" />
|
|
643
|
-
</div>
|
|
644
|
-
{/* biome-ignore lint/a11y/noStaticElementInteractions: middle strip double-clicks to expand */}
|
|
645
|
-
<div onDoubleClick={onTitleBarDoubleClick} className="flex min-w-8 flex-1 items-center self-stretch px-2">
|
|
646
|
-
{typeof title === "string" ? <span className="min-w-0 truncate text-xs font-semibold leading-none text-foreground/90">{title}</span> : title}
|
|
647
|
-
</div>
|
|
648
|
-
<div className="flex shrink-0 items-center">
|
|
649
|
-
{right}
|
|
650
|
-
<div ref={setRightSlot} className="contents" />
|
|
651
|
-
</div>
|
|
652
|
-
</div>
|
|
653
|
-
</header>
|
|
654
|
-
) : null}
|
|
655
|
-
|
|
656
|
-
<div className="min-h-0 flex-1 overflow-hidden">
|
|
657
|
-
{scroll ? (
|
|
658
|
-
<OverlayScroll visibility={scrollbar} className="h-full">
|
|
659
|
-
{children}
|
|
660
|
-
</OverlayScroll>
|
|
661
|
-
) : (
|
|
662
|
-
children
|
|
663
|
-
)}
|
|
664
|
-
</div>
|
|
665
|
-
{header ? null : <WindowTraffic floating expanded={expanded} onClose={requestClose} onToggleExpand={onToggleExpand} />}
|
|
666
|
-
</div>
|
|
667
|
-
|
|
668
|
-
{!leaving
|
|
669
|
-
? HANDLES.map((handle) => (
|
|
670
|
-
<div key={handle.edge} aria-hidden onPointerDown={(e) => startResize(handle.edge, e)} className={cn("absolute z-10 touch-none", handle.className)} />
|
|
671
|
-
))
|
|
672
|
-
: null}
|
|
673
|
-
</section>
|
|
674
|
-
</div>
|
|
675
|
-
</WindowHeaderSlotContext.Provider>
|
|
676
|
-
);
|
|
677
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { MeadowWallpaper } from "./MeadowWallpaper";
|
|
3
|
-
|
|
4
|
-
export function MeadowDesktop({ children, src }: { children?: ReactNode; src?: string }) {
|
|
5
|
-
return (
|
|
6
|
-
<div className="absolute inset-0 bg-background">
|
|
7
|
-
<MeadowWallpaper src={src} />
|
|
8
|
-
<div className="nonla-desktop-layer absolute inset-x-0 bottom-0 top-[42px] z-(--nonla-z-desktop,20)">
|
|
9
|
-
<nav aria-label="Desktop" className="absolute inset-0 overflow-auto pl-0 pr-3 pt-3 pb-3">
|
|
10
|
-
<div className="flex h-full flex-col flex-wrap content-start gap-x-2 gap-y-3">{children}</div>
|
|
11
|
-
</nav>
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { DesktopStage } from "./DesktopStage";
|
|
3
|
-
import { MeadowWallpaper } from "./MeadowWallpaper";
|
|
4
|
-
|
|
5
|
-
export function MeadowShell({ children }: { children: ReactNode }) {
|
|
6
|
-
return (
|
|
7
|
-
<DesktopStage>
|
|
8
|
-
<MeadowWallpaper />
|
|
9
|
-
<div className="relative z-10 flex h-full items-center justify-center overflow-y-auto p-6">{children}</div>
|
|
10
|
-
</DesktopStage>
|
|
11
|
-
);
|
|
12
|
-
}
|