devnonla-ui 0.10.0 → 0.12.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 +29 -3
- package/package.json +4 -2
- package/src/app/App.tsx +2 -4
- package/src/avatar/AgentAvatar.tsx +205 -0
- package/src/button/Button.tsx +28 -21
- package/src/chat/message-ui/ChatWelcome.tsx +3 -23
- package/src/desktop/DesktopWindow.tsx +41 -17
- package/src/index.ts +10 -1
- package/src/logo/Logo.tsx +17 -197
- package/src/markdown-editor/MarkdownPreview.tsx +1 -1
- package/src/markdown-editor/MarkdownTable.tsx +1 -1
- package/src/markdown-editor/MarkdownViewer.tsx +40 -11
- package/src/markdown-editor/ReactCode.tsx +75 -0
- package/src/markdown-editor/ReactCodeFrame.tsx +46 -0
- package/src/markdown-editor/ReactCodeRunner.tsx +82 -0
- package/src/markdown-editor/ReactCodeSandbox.tsx +156 -0
- package/src/markdown-editor/reactCodeProtocol.ts +47 -0
- package/src/markdown-editor/reactCompile.ts +31 -0
- package/src/sidebar/Sidebar.tsx +7 -7
- package/src/styles.css +108 -0
- package/src/theme.ts +1 -1
- package/src/typography/Typography.tsx +2 -2
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ import { DesktopStage, DesktopHeader, MeadowDesktop, DesktopWindow, MeadowShell,
|
|
|
132
132
|
</DesktopStage>
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
`MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. Last collapsed position and size are restored on reopen (`persistKey`, or `false` to disable). Resize handles stay when expanded; dragging an edge leaves expand and keeps the new size. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
|
|
135
|
+
`MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. The window zooms open; `origin` is the element it zooms from, and `closeRef` receives a close function to call instead of unmounting so it can shrink back. Last collapsed position and size are restored on reopen (`persistKey`, or `false` to disable). Resize handles stay when expanded; dragging an edge leaves expand and keeps the new size. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
|
|
136
136
|
|
|
137
137
|
# Sidebar
|
|
138
138
|
|
|
@@ -205,6 +205,32 @@ import { MarkdownEditor, MarkdownViewer } from "devnonla-ui";
|
|
|
205
205
|
<MarkdownEditor value={text} original={previous} onChange={setText} />
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
+
## Live React in markdown
|
|
209
|
+
|
|
210
|
+
A `live-react` fence exports a default component and renders it above its source. It is off unless you opt in.
|
|
211
|
+
|
|
212
|
+
- **Markdown from users or agents:** pass `sandboxSrc`. The fence runs in an iframe with `sandbox="allow-scripts"` and no `allow-same-origin`, so it cannot reach the page's cookies, storage, or DOM. `sandboxSrc` is a page you host on its own origin that calls `mountReactCodeRunner`; its `modules` are the only imports markdown gets.
|
|
213
|
+
- **Markdown you wrote:** pass `trustedModules`. The fence runs in your page with full access. Never use it for content someone else can write.
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
// sandbox page
|
|
217
|
+
import * as ui from "devnonla-ui";
|
|
218
|
+
import { mountReactCodeRunner } from "devnonla-ui";
|
|
219
|
+
|
|
220
|
+
mountReactCodeRunner(document.getElementById("root")!, { "devnonla-ui": ui });
|
|
221
|
+
|
|
222
|
+
// app
|
|
223
|
+
<MarkdownViewer value={article} sandboxSrc="https://sandbox.example.com/runner.html" />
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Outside markdown, use the pieces directly. `ReactCodeSandbox` takes `code` and `src` and renders the same framed result with a Code tab. `ReactCode` is the in-page version for source you wrote. `ReactCodeFrame` is the header and tab box, if you want to wrap your own result.
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
<ReactCodeSandbox code={source} src="https://sandbox.example.com/runner.html" />
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Serve the runner page with `Content-Security-Policy: connect-src 'none'` and `Access-Control-Allow-Origin: *` on its assets, since a sandboxed frame loads them cross-origin.
|
|
233
|
+
|
|
208
234
|
# Typography
|
|
209
235
|
|
|
210
236
|
`Text`, `Title`, `Paragraph`, and `Link` share one decoration set: `type` (`secondary` | `success` | `warning` | `danger`), `disabled`, `mark`, `code`, `keyboard`, `underline`, `delete`, `strong`, and `italic`. `Title` `level` is 1–5. `Typography` groups the same pieces.
|
|
@@ -220,14 +246,14 @@ import { Link, Paragraph, Text, Title } from "devnonla-ui";
|
|
|
220
246
|
|
|
221
247
|
# Logo
|
|
222
248
|
|
|
223
|
-
`Logo` is the mark and the wordmark “Nonla Agents”. `variant` is `icon`, `text`, or `full` (default). `
|
|
249
|
+
`Logo` is the mark and the wordmark “Nonla Agents”. The wordmark is K2D regular, drawn as SVG outlines. `variant` is `icon`, `text`, or `full` (default). `size` is the icon height in px (default 32). `color` recolors the mark and the wordmark; the eyes and the smile stay.
|
|
224
250
|
|
|
225
251
|
```tsx
|
|
226
252
|
import { Logo } from "devnonla-ui";
|
|
227
253
|
|
|
228
254
|
<Logo />
|
|
229
255
|
<Logo variant="icon" size={24} />
|
|
230
|
-
<Logo
|
|
256
|
+
<Logo color="#181818" />
|
|
231
257
|
```
|
|
232
258
|
|
|
233
259
|
# Icons
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devnonla-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "NonlaUI — React controls for Nonla Agents",
|
|
6
6
|
"author": "devlangla <devlangla0x01@gmail.com>",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"src"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"typecheck": "tsc --noEmit"
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"docs": "bun --cwd docs run dev"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"react": ">=19",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"react-day-picker": "^10.0.1",
|
|
56
57
|
"react-markdown": "^10.1.0",
|
|
57
58
|
"remark-gfm": "^4.0.1",
|
|
59
|
+
"sucrase": "^3.35.1",
|
|
58
60
|
"tailwind-merge": "^3.5.0"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
package/src/app/App.tsx
CHANGED
|
@@ -20,6 +20,8 @@ export type AppProps = {
|
|
|
20
20
|
|
|
21
21
|
/** Root host for NonlaUI — ConfigProvider + message/modal holders. Mount once near app root. */
|
|
22
22
|
export function App({ children, getPopupContainer, componentSize, theme }: AppProps) {
|
|
23
|
+
// Before children paint, so a sandbox iframe can open on the saved mode instead of flashing the default.
|
|
24
|
+
initColorMode();
|
|
23
25
|
const [themeRev, setThemeRev] = useState(0);
|
|
24
26
|
const size = componentSize ? normalizeSize(componentSize) : undefined;
|
|
25
27
|
const value = useMemo<NonlaAppConfig>(
|
|
@@ -27,10 +29,6 @@ export function App({ children, getPopupContainer, componentSize, theme }: AppPr
|
|
|
27
29
|
[getPopupContainer, size, themeRev],
|
|
28
30
|
);
|
|
29
31
|
|
|
30
|
-
useLayoutEffect(() => {
|
|
31
|
-
initColorMode();
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
32
|
useLayoutEffect(() => {
|
|
35
33
|
if (!theme) return;
|
|
36
34
|
const restore = applyNonlaTheme(theme);
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createContext, type ReactNode, useContext, useId } from "react";
|
|
2
|
+
import { cn } from "../lib/cn";
|
|
3
|
+
|
|
4
|
+
/** `still` holds the pose. `idle` looks around. Defaults to `still`. */
|
|
5
|
+
export type AgentAvatarMotion = "still" | "idle";
|
|
6
|
+
|
|
7
|
+
/** Fixed facing. The head turns that way and the eyes follow. */
|
|
8
|
+
export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
|
|
9
|
+
|
|
10
|
+
export const AGENT_AVATAR_PARTS = {
|
|
11
|
+
shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
|
|
12
|
+
color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
type Part<K extends keyof typeof AGENT_AVATAR_PARTS> = (typeof AGENT_AVATAR_PARTS)[K][number];
|
|
16
|
+
|
|
17
|
+
/** A character is one shape plus the two eyes. */
|
|
18
|
+
export type AgentAvatarConfig = {
|
|
19
|
+
shape: Part<"shape">;
|
|
20
|
+
color: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AgentAvatarProps = {
|
|
24
|
+
/** Shape and color. Omitted parts use circle and `#6E56F0`. */
|
|
25
|
+
config?: Partial<AgentAvatarConfig>;
|
|
26
|
+
/** Square size in px. Defaults to 64. */
|
|
27
|
+
size?: number;
|
|
28
|
+
motion?: AgentAvatarMotion;
|
|
29
|
+
/** Which way the face is turned. Defaults to straight ahead. */
|
|
30
|
+
look?: AgentAvatarLook;
|
|
31
|
+
className?: string;
|
|
32
|
+
/** Accessible name. Defaults to "Agent". */
|
|
33
|
+
label?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function hash(seed: string) {
|
|
37
|
+
let h = 2166136261;
|
|
38
|
+
for (let i = 0; i < seed.length; i++) {
|
|
39
|
+
h ^= seed.charCodeAt(i);
|
|
40
|
+
h = Math.imul(h, 16777619);
|
|
41
|
+
}
|
|
42
|
+
return h >>> 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const DEFAULT_CONFIG: AgentAvatarConfig = {
|
|
46
|
+
shape: AGENT_AVATAR_PARTS.shape[0],
|
|
47
|
+
color: AGENT_AVATAR_PARTS.color[0],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function resolveConfig(config?: Partial<AgentAvatarConfig>): AgentAvatarConfig {
|
|
51
|
+
return {
|
|
52
|
+
shape: config?.shape ?? DEFAULT_CONFIG.shape,
|
|
53
|
+
color: config?.color ?? DEFAULT_CONFIG.color,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function stagger(seed: string) {
|
|
58
|
+
return (hash(seed) % 8) * 0.2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const EYE = "#111";
|
|
62
|
+
const EYE_ON_DARK = "#fff";
|
|
63
|
+
|
|
64
|
+
function eyeInk(color: string) {
|
|
65
|
+
const hex = color.replace("#", "");
|
|
66
|
+
if (hex.length < 6) return EYE;
|
|
67
|
+
const r = Number.parseInt(hex.slice(0, 2), 16);
|
|
68
|
+
const g = Number.parseInt(hex.slice(2, 4), 16);
|
|
69
|
+
const b = Number.parseInt(hex.slice(4, 6), 16);
|
|
70
|
+
const luma = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
|
|
71
|
+
return luma < 0.28 ? EYE_ON_DARK : EYE;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Head shift, then how much further the eyes travel, in viewBox units. */
|
|
75
|
+
const LOOK: Record<AgentAvatarLook, { head: [number, number]; eyes: [number, number] }> = {
|
|
76
|
+
forward: { head: [0, 0], eyes: [0, 0] },
|
|
77
|
+
left: { head: [-3.2, 0.6], eyes: [-6.4, 0.4] },
|
|
78
|
+
right: { head: [3.2, 0.6], eyes: [6.4, 0.4] },
|
|
79
|
+
up: { head: [0, -2.6], eyes: [0, -4.4] },
|
|
80
|
+
down: { head: [0, 2.8], eyes: [0, 4.6] },
|
|
81
|
+
"up-left": { head: [-2.3, -1.9], eyes: [-4.5, -3.1] },
|
|
82
|
+
"up-right": { head: [2.3, -1.9], eyes: [4.5, -3.1] },
|
|
83
|
+
"down-left": { head: [-2.3, 2], eyes: [-4.5, 3.3] },
|
|
84
|
+
"down-right": { head: [2.3, 2], eyes: [4.5, 3.3] },
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function mixHex(color: string, toward: "#fff" | "#000", amount: number) {
|
|
88
|
+
const hex = color.replace("#", "");
|
|
89
|
+
const channel = (start: number) => Number.parseInt(hex.slice(start, start + 2), 16);
|
|
90
|
+
const target = toward === "#fff" ? 255 : 0;
|
|
91
|
+
const mix = (value: number) => Math.round(value + (target - value) * amount)
|
|
92
|
+
.toString(16)
|
|
93
|
+
.padStart(2, "0");
|
|
94
|
+
return `#${mix(channel(0))}${mix(channel(2))}${mix(channel(4))}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const PaintContext = createContext("#111");
|
|
98
|
+
const ShadowContext = createContext<string | undefined>(undefined);
|
|
99
|
+
const InkContext = createContext(EYE);
|
|
100
|
+
|
|
101
|
+
function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number; h?: number }) {
|
|
102
|
+
const gap = w * 1.5;
|
|
103
|
+
const top = cy - h / 2;
|
|
104
|
+
const fill = useContext(InkContext);
|
|
105
|
+
return (
|
|
106
|
+
<g className="nonla-avatar-gaze">
|
|
107
|
+
<g className="nonla-avatar-eyes">
|
|
108
|
+
<rect x={cx - gap / 2 - w} y={top} width={w} height={h} rx={w / 2} fill={fill} />
|
|
109
|
+
<rect x={cx + gap / 2} y={top} width={w} height={h} rx={w / 2} fill={fill} />
|
|
110
|
+
</g>
|
|
111
|
+
</g>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Shape({ shape, color }: AgentAvatarConfig) {
|
|
116
|
+
const paint = useContext(PaintContext);
|
|
117
|
+
const shadow = useContext(ShadowContext);
|
|
118
|
+
const soft = { fill: paint, stroke: paint, strokeLinejoin: "round" as const };
|
|
119
|
+
const face = (mark: ReactNode, eyes: ReactNode, shiftY = 0) => (
|
|
120
|
+
<g transform={shiftY ? `translate(0 ${shiftY})` : undefined}>
|
|
121
|
+
<g filter={shadow}>{mark}</g>
|
|
122
|
+
{eyes}
|
|
123
|
+
</g>
|
|
124
|
+
);
|
|
125
|
+
const body: Record<AgentAvatarConfig["shape"], ReactNode> = {
|
|
126
|
+
circle: face(<circle cx="32" cy="32" r="22" fill={paint} />, <Eyes cx={32} cy={30} />),
|
|
127
|
+
square: face(<rect x="9" y="9" width="46" height="46" rx="16" fill={paint} />, <Eyes cx={32} cy={30} />),
|
|
128
|
+
triangle: face(<path d="M32 16 L50 50 H14 Z" strokeWidth="14" {...soft} />, <Eyes cx={32} cy={38} />, -1),
|
|
129
|
+
diamond: face(<path d="M32 10 L54 32 L32 54 L10 32 Z" strokeWidth="16" {...soft} />, <Eyes cx={32} cy={30} />),
|
|
130
|
+
hex: face(<path d="M32 12 L49 22 L49 42 L32 52 L15 42 L15 22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
|
|
131
|
+
gem: face(<path d="M22 12 H42 L52 22 V42 L42 52 H22 L12 42 V22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
|
|
132
|
+
pill: face(<rect x="6" y="18" width="52" height="28" rx="14" fill={paint} />, <Eyes cx={32} cy={30} />),
|
|
133
|
+
arch: face(<path d="M14 50V32C14 18 50 18 50 32V50C50 56 14 56 14 50Z" fill={paint} />, <Eyes cx={32} cy={36} />, -6),
|
|
134
|
+
cloud: face(
|
|
135
|
+
<g fill={paint}>
|
|
136
|
+
<circle cx="20" cy="38" r="12" />
|
|
137
|
+
<circle cx="44" cy="38" r="12" />
|
|
138
|
+
<circle cx="32" cy="28" r="14" />
|
|
139
|
+
<rect x="16" y="34" width="32" height="14" />
|
|
140
|
+
</g>,
|
|
141
|
+
<Eyes cx={32} cy={36} />,
|
|
142
|
+
),
|
|
143
|
+
blob: face(<ellipse cx="32" cy="34" rx="24" ry="18" fill={paint} />, <Eyes cx={32} cy={32} />, -2),
|
|
144
|
+
drop: face(
|
|
145
|
+
<path d="M27 23C19 30 15 37 15 46C15 55 22.5 60 32 60C41.5 60 49 55 49 46C49 37 45 30 37 23Q32 16 27 23Z" strokeWidth="5" {...soft} />,
|
|
146
|
+
<Eyes cx={32} cy={42} />,
|
|
147
|
+
-8,
|
|
148
|
+
),
|
|
149
|
+
shield: face(
|
|
150
|
+
<path d="M18 18H46C52 18 54 24 54 32V36C54 48 46 56 32 58C18 56 10 48 10 36V32C10 24 12 18 18 18Z" fill={paint} />,
|
|
151
|
+
<Eyes cx={32} cy={34} />,
|
|
152
|
+
-6,
|
|
153
|
+
),
|
|
154
|
+
};
|
|
155
|
+
return <InkContext.Provider value={eyeInk(color)}>{body[shape]}</InkContext.Provider>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
|
|
159
|
+
const resolved = resolveConfig(config);
|
|
160
|
+
const delay = stagger(`${resolved.shape}${resolved.color}`);
|
|
161
|
+
const facing = LOOK[look];
|
|
162
|
+
const [hx, hy] = facing.head;
|
|
163
|
+
const [ex, ey] = facing.eyes;
|
|
164
|
+
const uid = useId().replace(/:/g, "");
|
|
165
|
+
const light = `nonla-av-${uid}`;
|
|
166
|
+
const shadow = `nonla-av-s-${uid}`;
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<span
|
|
170
|
+
role="img"
|
|
171
|
+
aria-label={label}
|
|
172
|
+
data-motion={motion}
|
|
173
|
+
data-look={look}
|
|
174
|
+
className={cn("nonla-avatar", className)}
|
|
175
|
+
style={{
|
|
176
|
+
width: size,
|
|
177
|
+
height: size,
|
|
178
|
+
["--nonla-avatar-delay" as string]: `${delay}s`,
|
|
179
|
+
["--nonla-avatar-hx" as string]: `${(hx / 64) * 100}%`,
|
|
180
|
+
["--nonla-avatar-hy" as string]: `${(hy / 64) * 100}%`,
|
|
181
|
+
["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
|
|
182
|
+
["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
<span className="nonla-avatar-bob" aria-hidden>
|
|
186
|
+
<svg viewBox="0 0 64 64" width="100%" height="100%">
|
|
187
|
+
<defs>
|
|
188
|
+
<linearGradient id={light} gradientUnits="userSpaceOnUse" x1="32" y1="4" x2="32" y2="60">
|
|
189
|
+
<stop offset="0" stopColor={mixHex(resolved.color, "#fff", 0.16)} />
|
|
190
|
+
<stop offset="1" stopColor={resolved.color} />
|
|
191
|
+
</linearGradient>
|
|
192
|
+
<filter id={shadow} x="-20%" y="-20%" width="140%" height="150%">
|
|
193
|
+
<feDropShadow dx="0" dy="0.8" stdDeviation="0.6" floodColor="#000" floodOpacity="0.18" />
|
|
194
|
+
</filter>
|
|
195
|
+
</defs>
|
|
196
|
+
<PaintContext.Provider value={`url(#${light})`}>
|
|
197
|
+
<ShadowContext.Provider value={`url(#${shadow})`}>
|
|
198
|
+
<Shape {...resolved} />
|
|
199
|
+
</ShadowContext.Provider>
|
|
200
|
+
</PaintContext.Provider>
|
|
201
|
+
</svg>
|
|
202
|
+
</span>
|
|
203
|
+
</span>
|
|
204
|
+
);
|
|
205
|
+
}
|
package/src/button/Button.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import type { ControlSize } from "../lib/sizes";
|
|
|
4
4
|
import { controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
|
|
5
5
|
|
|
6
6
|
export type ButtonType = "default" | "primary" | "dashed" | "link" | "text";
|
|
7
|
-
export type ButtonVariant = "outlined" | "dashed" | "solid" | "filled" | "text" | "link";
|
|
7
|
+
export type ButtonVariant = "outlined" | "dashed" | "solid" | "filled" | "text" | "link" | "nostyle";
|
|
8
8
|
export type ButtonShape = "default" | "circle" | "round" | "square";
|
|
9
9
|
export type ButtonHtmlType = "submit" | "button" | "reset";
|
|
10
10
|
export type ButtonSize = ControlSize;
|
|
@@ -56,6 +56,7 @@ function isButtonType(value: unknown): value is ButtonType {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function resolveTone(type: ButtonType | undefined, color: ButtonColor | undefined, variant: ButtonVariant | undefined, danger: boolean): [ButtonColor, ButtonVariant] {
|
|
59
|
+
if (variant === "nostyle") return ["default", "nostyle"];
|
|
59
60
|
if (color && variant) return [danger ? "danger" : color, variant];
|
|
60
61
|
if (type || danger) {
|
|
61
62
|
const pair = TYPE_MAP[isButtonType(type) ? type : "default"];
|
|
@@ -71,6 +72,7 @@ const TWO_CN = /^[\u4e00-\u9fa5]{2}$/;
|
|
|
71
72
|
const GroupSizeContext = createContext<ButtonSize | undefined>(undefined);
|
|
72
73
|
|
|
73
74
|
function tokenAppearance(color: "default" | "primary" | "danger" | "link", variant: ButtonVariant, ghost: boolean): string {
|
|
75
|
+
if (variant === "nostyle") return "";
|
|
74
76
|
const g = ghost && variant !== "text" && variant !== "link";
|
|
75
77
|
if (color === "primary") {
|
|
76
78
|
if (variant === "solid" && !g) return "border-transparent bg-brand text-[var(--nonla-solid-fg)] hover:bg-[color-mix(in_oklab,var(--brand),var(--background)_14%)] active:bg-[color-mix(in_oklab,var(--brand),black_18%)]";
|
|
@@ -94,6 +96,7 @@ function tokenAppearance(color: "default" | "primary" | "danger" | "link", varia
|
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
function presetAppearance(variant: ButtonVariant, ghost: boolean): string {
|
|
99
|
+
if (variant === "nostyle") return "";
|
|
97
100
|
const g = ghost && variant !== "text" && variant !== "link";
|
|
98
101
|
if (variant === "solid" && !g) return "bg-(--nonla-btn) text-[var(--nonla-solid-fg)] border-transparent hover:brightness-110";
|
|
99
102
|
if (variant === "filled") return "bg-(--nonla-btn)/15 text-(--nonla-btn) border-transparent hover:bg-(--nonla-btn)/25";
|
|
@@ -196,22 +199,24 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
|
|
|
196
199
|
|
|
197
200
|
const iconNode = innerLoading ? typeof loading === "object" && loading.icon ? loading.icon : <LoadingDot size={tok.icon} /> : icon;
|
|
198
201
|
const showIcon = Boolean(iconNode);
|
|
202
|
+
const bare = mergedVariant === "nostyle";
|
|
199
203
|
const radius = shape === "circle" || shape === "round" ? 9999 : shape === "square" ? 4 : controlRadiusVar(size);
|
|
200
|
-
const appearance = preset ? presetAppearance(mergedVariant, ghost) : tokenAppearance(mergedColor as "default" | "primary" | "danger" | "link", mergedVariant, ghost);
|
|
201
|
-
const bordered = mergedVariant !== "text" && mergedVariant !== "link";
|
|
204
|
+
const appearance = bare ? "" : preset ? presetAppearance(mergedVariant, ghost) : tokenAppearance(mergedColor as "default" | "primary" | "danger" | "link", mergedVariant, ghost);
|
|
205
|
+
const bordered = !bare && mergedVariant !== "text" && mergedVariant !== "link";
|
|
202
206
|
|
|
203
207
|
const padText = tok.paddingInline;
|
|
204
208
|
const paddingLeft = iconOnly ? 0 : showIcon && placement === "start" ? tok.paddingInlineIconStart : padText;
|
|
205
209
|
const paddingRight = iconOnly ? 0 : showIcon && placement === "end" ? tok.paddingInlineIconEnd : padText;
|
|
206
210
|
|
|
207
211
|
const rootClass = cn(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
bordered ? "border" : "border-transparent",
|
|
212
|
+
bare
|
|
213
|
+
? "inline-flex items-center justify-center gap-2 cursor-pointer border-0 bg-transparent px-0 py-0 text-inherit rounded-none disabled:cursor-not-allowed"
|
|
214
|
+
: "inline-flex items-center justify-center gap-2 font-normal whitespace-nowrap select-none cursor-pointer border border-solid transition-colors duration-150 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45",
|
|
215
|
+
!bare && (bordered ? "border" : "border-transparent"),
|
|
212
216
|
appearance,
|
|
213
217
|
block && "flex w-full",
|
|
214
|
-
innerLoading && "pointer-events-none
|
|
218
|
+
innerLoading && "pointer-events-none",
|
|
219
|
+
!bare && innerLoading && "opacity-80",
|
|
215
220
|
placement === "end" && "flex-row-reverse",
|
|
216
221
|
prefixCls,
|
|
217
222
|
className,
|
|
@@ -220,18 +225,20 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
|
|
|
220
225
|
);
|
|
221
226
|
|
|
222
227
|
const boxH = controlHeightVar(size);
|
|
223
|
-
const mergedStyle: CSSProperties =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
228
|
+
const mergedStyle: CSSProperties = bare
|
|
229
|
+
? { ...styles?.root, ...style }
|
|
230
|
+
: {
|
|
231
|
+
height: boxH,
|
|
232
|
+
width: iconOnly ? boxH : undefined,
|
|
233
|
+
fontSize: tok.fontSize,
|
|
234
|
+
lineHeight: `${tok.lineHeight}px`,
|
|
235
|
+
paddingLeft,
|
|
236
|
+
paddingRight,
|
|
237
|
+
borderRadius: radius,
|
|
238
|
+
...(preset ? ({ "--nonla-btn": `var(--nonla-${mergedColor})` } as CSSProperties) : null),
|
|
239
|
+
...styles?.root,
|
|
240
|
+
...style,
|
|
241
|
+
};
|
|
235
242
|
|
|
236
243
|
const handleClick = (e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
|
|
237
244
|
if (innerLoading || disabled) {
|
|
@@ -244,7 +251,7 @@ const ButtonInner = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProp
|
|
|
244
251
|
const inner = (
|
|
245
252
|
<>
|
|
246
253
|
{showIcon ? (
|
|
247
|
-
<span className={cn("relative z-10 inline-flex shrink-0 items-center justify-center [&_svg]:size-full", classNames?.icon)} style={{ width: tok.icon, height: tok.icon, ...styles?.icon }}>
|
|
254
|
+
<span className={cn("relative z-10 inline-flex shrink-0 items-center justify-center", !bare && "[&_svg]:size-full", classNames?.icon)} style={bare ? styles?.icon : { width: tok.icon, height: tok.icon, ...styles?.icon }}>
|
|
248
255
|
{iconNode}
|
|
249
256
|
</span>
|
|
250
257
|
) : null}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import { AgentAvatar } from "../../avatar/AgentAvatar";
|
|
2
3
|
import { Button } from "../../button/Button";
|
|
3
4
|
import { cn } from "../../lib/cn";
|
|
4
5
|
|
|
@@ -16,12 +17,7 @@ export type ChatWelcomeProps = {
|
|
|
16
17
|
const DEFAULT_STARTERS = ["What can you help me with?", "Brainstorm a few ideas with me", "Walk me through how you work"] as const;
|
|
17
18
|
|
|
18
19
|
function DefaultAvatar({ name }: { name: string }) {
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div className="flex size-16 items-center justify-center rounded-full bg-brand/20 text-xl font-semibold text-brand-700" aria-hidden>
|
|
22
|
-
{initial}
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
20
|
+
return <AgentAvatar size={72} label={name} />;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
export function ChatWelcome({ name, description, avatar, starters = [...DEFAULT_STARTERS], onStarter, disabled, className }: ChatWelcomeProps) {
|
|
@@ -29,23 +25,7 @@ export function ChatWelcome({ name, description, avatar, starters = [...DEFAULT_
|
|
|
29
25
|
|
|
30
26
|
return (
|
|
31
27
|
<div className={cn("nonla-chat-welcome flex flex-col items-center justify-center min-h-full w-full px-6 py-10 text-center", className)}>
|
|
32
|
-
<div className="
|
|
33
|
-
<div
|
|
34
|
-
aria-hidden
|
|
35
|
-
className="pointer-events-none absolute left-1/2 top-1/2 size-28 -translate-x-1/2 -translate-y-1/2 rounded-full"
|
|
36
|
-
style={{
|
|
37
|
-
background: "radial-gradient(circle, color-mix(in oklab, var(--brand) 28%, transparent) 0%, transparent 70%)",
|
|
38
|
-
}}
|
|
39
|
-
/>
|
|
40
|
-
<div
|
|
41
|
-
className="relative rounded-full p-0.5"
|
|
42
|
-
style={{
|
|
43
|
-
background: "linear-gradient(145deg, color-mix(in oklab, var(--brand-600) 55%, transparent), transparent 60%)",
|
|
44
|
-
}}
|
|
45
|
-
>
|
|
46
|
-
<div className="rounded-full bg-popover p-0.5">{avatar ?? <DefaultAvatar name={name} />}</div>
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
28
|
+
<div className="mb-5">{avatar ?? <DefaultAvatar name={name} />}</div>
|
|
49
29
|
|
|
50
30
|
<h2 className="m-0 text-[22px] font-semibold tracking-tight text-foreground leading-snug">Hi, I'm {name}</h2>
|
|
51
31
|
|
|
@@ -4,7 +4,7 @@ import { cn } from "../lib/cn";
|
|
|
4
4
|
import { glassSurfaceClass } from "../lib/surface";
|
|
5
5
|
import { OverlayScroll, type OverlayScrollVisibility } from "../scroll/OverlayScroll";
|
|
6
6
|
|
|
7
|
-
type Phase = "open" | "leaving";
|
|
7
|
+
type Phase = "enter" | "open" | "leaving";
|
|
8
8
|
type Size = { w: number; h: number };
|
|
9
9
|
type Point = { x: number; y: number };
|
|
10
10
|
type Rect = { x: number; y: number; w: number; h: number };
|
|
@@ -41,11 +41,11 @@ function hasOpenDialog() {
|
|
|
41
41
|
return Boolean(document.querySelector('dialog[open], [role="dialog"][data-state="open"], .nonla-modal-content'));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
if (!(
|
|
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
47
|
|
|
48
|
-
const icon =
|
|
48
|
+
const icon = from.getBoundingClientRect();
|
|
49
49
|
const overlayBox = overlay.getBoundingClientRect();
|
|
50
50
|
const x = icon.left + icon.width / 2 - overlayBox.left - frame.offsetLeft;
|
|
51
51
|
const y = icon.top + icon.height / 2 - overlayBox.top - frame.offsetTop;
|
|
@@ -317,6 +317,10 @@ export type DesktopWindowProps = {
|
|
|
317
317
|
scrollbar?: OverlayScrollVisibility;
|
|
318
318
|
/** Last collapsed position and size. Default `"default"`. Pass a unique key per window, or `false` to disable. */
|
|
319
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 };
|
|
320
324
|
children: ReactNode;
|
|
321
325
|
};
|
|
322
326
|
|
|
@@ -331,6 +335,8 @@ export function DesktopWindow({
|
|
|
331
335
|
scroll = true,
|
|
332
336
|
scrollbar = "hover",
|
|
333
337
|
persistKey = "default",
|
|
338
|
+
origin,
|
|
339
|
+
closeRef,
|
|
334
340
|
children,
|
|
335
341
|
}: DesktopWindowProps) {
|
|
336
342
|
const overlayRef = useRef<HTMLDivElement>(null);
|
|
@@ -351,7 +357,7 @@ export function DesktopWindow({
|
|
|
351
357
|
startY: number;
|
|
352
358
|
orig: Rect;
|
|
353
359
|
} | null>(null);
|
|
354
|
-
const [phase, setPhase] = useState<Phase>("open");
|
|
360
|
+
const [phase, setPhase] = useState<Phase>(() => (prefersReducedMotion() ? "open" : "enter"));
|
|
355
361
|
const [view, setView] = useState<Size>(initialView);
|
|
356
362
|
const [offset, setOffset] = useState(() => restoreGeometry(persistKey, initialView()).offset);
|
|
357
363
|
const [size, setSize] = useState<Size | null>(() => restoreGeometry(persistKey, initialView()).size);
|
|
@@ -371,14 +377,31 @@ export function DesktopWindow({
|
|
|
371
377
|
viewRef.current = view;
|
|
372
378
|
offsetRef.current = offset;
|
|
373
379
|
|
|
374
|
-
|
|
380
|
+
const applyOrigin = () => {
|
|
375
381
|
const overlay = overlayRef.current;
|
|
376
382
|
const frame = frameRef.current;
|
|
377
|
-
if (overlay
|
|
378
|
-
|
|
379
|
-
|
|
383
|
+
if (!overlay || !frame) return;
|
|
384
|
+
frame.style.transformOrigin = zoomOrigin(overlay, frame, origin?.current ?? null);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
useLayoutEffect(() => {
|
|
388
|
+
applyOrigin();
|
|
380
389
|
}, []);
|
|
381
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
|
+
|
|
382
405
|
const requestClose = () => {
|
|
383
406
|
if (closedRef.current || phase === "leaving") return;
|
|
384
407
|
if (prefersReducedMotion()) {
|
|
@@ -386,6 +409,7 @@ export function DesktopWindow({
|
|
|
386
409
|
onClose();
|
|
387
410
|
return;
|
|
388
411
|
}
|
|
412
|
+
applyOrigin();
|
|
389
413
|
setPhase("leaving");
|
|
390
414
|
};
|
|
391
415
|
requestCloseRef.current = requestClose;
|
|
@@ -571,13 +595,13 @@ export function DesktopWindow({
|
|
|
571
595
|
onToggleExpand();
|
|
572
596
|
};
|
|
573
597
|
|
|
574
|
-
const
|
|
598
|
+
const shown = phase === "open";
|
|
575
599
|
const leaving = phase === "leaving";
|
|
576
600
|
const rect = expanded ? { x: 0, y: 0, w: view.w, h: view.h } : collapsedRect(view, offset, size);
|
|
577
601
|
const reduce = prefersReducedMotion();
|
|
578
602
|
const duration = reduce ? "150ms" : "300ms";
|
|
579
|
-
const geom =
|
|
580
|
-
const
|
|
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}` : "";
|
|
581
605
|
|
|
582
606
|
return (
|
|
583
607
|
<WindowHeaderSlotContext.Provider value={headerChrome}>
|
|
@@ -598,12 +622,12 @@ export function DesktopWindow({
|
|
|
598
622
|
left: rect.x,
|
|
599
623
|
width: rect.w,
|
|
600
624
|
height: rect.h,
|
|
601
|
-
opacity:
|
|
602
|
-
transform:
|
|
603
|
-
transition: [geom,
|
|
625
|
+
opacity: shown ? 1 : 0,
|
|
626
|
+
transform: shown ? "scale(1)" : "scale(0.18)",
|
|
627
|
+
transition: [geom, zoom].filter(Boolean).join(", ") || undefined,
|
|
604
628
|
}}
|
|
605
629
|
data-expanded={expanded || undefined}
|
|
606
|
-
className={cn("absolute flex flex-col rounded-xl pointer-events-auto transform-gpu", glassSurfaceClass, "nonla-window-glass",
|
|
630
|
+
className={cn("absolute flex flex-col rounded-xl pointer-events-auto transform-gpu", glassSurfaceClass, "nonla-window-glass", phase !== "open" && "pointer-events-none")}
|
|
607
631
|
>
|
|
608
632
|
<div className="relative flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl">
|
|
609
633
|
{header ? (
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type InputRef = HTMLInputElement;
|
|
|
15
15
|
|
|
16
16
|
export type { AlertProps, AlertType } from "./alert/Alert";
|
|
17
17
|
export { Alert } from "./alert/Alert";
|
|
18
|
+
export type { AgentAvatarConfig, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
|
|
19
|
+
export { AGENT_AVATAR_PARTS, AgentAvatar } from "./avatar/AgentAvatar";
|
|
18
20
|
export type { CalendarProps } from "./calendar/Calendar";
|
|
19
21
|
export { Calendar } from "./calendar/Calendar";
|
|
20
22
|
export type { CardFooterProps, CardItemProps, CardProps } from "./card/Card";
|
|
@@ -157,7 +159,7 @@ export { placementToRadix } from "./lib/placement";
|
|
|
157
159
|
export type { CanonicalSize, ControlSize, ControlSizeTokens } from "./lib/sizes";
|
|
158
160
|
export { CONTROL_SIZES, controlHeightVar, controlRadiusVar, controlStatusClass, getSizeTokens, normalizeSize, useControlSize } from "./lib/sizes";
|
|
159
161
|
export { glassOverlayClass, glassSurfaceClass, meadowSurfaceClass } from "./lib/surface";
|
|
160
|
-
export type {
|
|
162
|
+
export type { LogoProps, LogoVariant } from "./logo/Logo";
|
|
161
163
|
export { Logo } from "./logo/Logo";
|
|
162
164
|
export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
|
|
163
165
|
export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
|
|
@@ -165,6 +167,13 @@ export type { MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
|
|
|
165
167
|
export { MarkdownViewer } from "./markdown-editor/MarkdownViewer";
|
|
166
168
|
export type { MermaidBlockProps } from "./markdown-editor/MermaidBlock";
|
|
167
169
|
export { MermaidBlock } from "./markdown-editor/MermaidBlock";
|
|
170
|
+
export type { ReactCodeProps } from "./markdown-editor/ReactCode";
|
|
171
|
+
export { ReactCode } from "./markdown-editor/ReactCode";
|
|
172
|
+
export type { ReactCodeFrameProps } from "./markdown-editor/ReactCodeFrame";
|
|
173
|
+
export { ReactCodeFrame } from "./markdown-editor/ReactCodeFrame";
|
|
174
|
+
export { mountReactCodeRunner } from "./markdown-editor/ReactCodeRunner";
|
|
175
|
+
export type { ReactCodeSandboxProps } from "./markdown-editor/ReactCodeSandbox";
|
|
176
|
+
export { ReactCodeSandbox } from "./markdown-editor/ReactCodeSandbox";
|
|
168
177
|
export type { MenuItemProps, MenuRootProps, MenuTriggerProps } from "./menu/Menu";
|
|
169
178
|
export { Menu, MenuAction, MenuDivider, MenuItem, MenuTrigger } from "./menu/Menu";
|
|
170
179
|
export type { MessageConfig, MessageType } from "./message/message";
|