devnonla-ui 0.15.0 → 0.16.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -39,6 +39,9 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@ag-ui/client": "1.0.2",
42
+ "@dnd-kit/core": "6.3.1",
43
+ "@dnd-kit/sortable": "10.0.0",
44
+ "@dnd-kit/utilities": "3.2.2",
42
45
  "@fontsource-variable/inter": "^5.3.0",
43
46
  "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
44
47
  "@radix-ui/react-checkbox": "^1.3.3",
@@ -1,17 +1,17 @@
1
- import { createContext, type ReactNode, useContext, useId } from "react";
1
+ import { createContext, type ReactNode, useContext, useEffect, useId, useState } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
 
4
- /** `still` holds the pose. `idle` looks around. Defaults to `still`. */
4
+ /** `still` holds the pose. `idle` turns to a random direction. Defaults to `still`. */
5
5
  export type AgentAvatarMotion = "still" | "idle";
6
6
 
7
- /** Fixed facing. The head turns that way and the eyes follow. */
7
+ /** Fixed facing. The shape stays centered and the eyes move that way. */
8
8
  export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
9
9
 
10
10
  /** Pupil color. Omitted picks black, or white when the face is dark. */
11
11
  export type AgentAvatarEyeColor = "black" | "white";
12
12
 
13
13
  export const AGENT_AVATAR_PARTS = {
14
- shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
14
+ shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield", "nonla"],
15
15
  color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
16
16
  } as const;
17
17
 
@@ -82,19 +82,64 @@ function eyeFill(color: string, eyeColor?: AgentAvatarEyeColor) {
82
82
  return eyeInk(color);
83
83
  }
84
84
 
85
- /** Head shift, then how much further the eyes travel, in viewBox units. */
86
- const LOOK: Record<AgentAvatarLook, { head: [number, number]; eyes: [number, number] }> = {
87
- forward: { head: [0, 0], eyes: [0, 0] },
88
- left: { head: [-3.2, 0.6], eyes: [-6.4, 0.4] },
89
- right: { head: [3.2, 0.6], eyes: [6.4, 0.4] },
90
- up: { head: [0, -2.6], eyes: [0, -4.4] },
91
- down: { head: [0, 2.8], eyes: [0, 4.6] },
92
- "up-left": { head: [-2.3, -1.9], eyes: [-4.5, -3.1] },
93
- "up-right": { head: [2.3, -1.9], eyes: [4.5, -3.1] },
94
- "down-left": { head: [-2.3, 2], eyes: [-4.5, 3.3] },
95
- "down-right": { head: [2.3, 2], eyes: [4.5, 3.3] },
85
+ function randomLook(current: AgentAvatarLook) {
86
+ const pool = LOOKS.filter((item) => item !== current);
87
+ return pool[Math.floor(Math.random() * pool.length)];
88
+ }
89
+
90
+ /** Idle holds one facing, then picks a different one. */
91
+ function useIdleLook(active: boolean, home: AgentAvatarLook, delay: number) {
92
+ const [glance, setGlance] = useState(home);
93
+
94
+ useEffect(() => {
95
+ if (!active) return;
96
+ const media = window.matchMedia("(prefers-reduced-motion: reduce)");
97
+ if (media.matches) {
98
+ setGlance(home);
99
+ return;
100
+ }
101
+
102
+ let timer = 0;
103
+ const arm = (wait: number) => {
104
+ timer = window.setTimeout(() => {
105
+ setGlance((current) => randomLook(current));
106
+ arm(1100 + Math.random() * 1700);
107
+ }, wait);
108
+ };
109
+
110
+ setGlance(home);
111
+ arm(700 + delay * 1000 + Math.random() * 900);
112
+
113
+ const onChange = () => {
114
+ if (!media.matches) return;
115
+ window.clearTimeout(timer);
116
+ setGlance(home);
117
+ };
118
+ media.addEventListener("change", onChange);
119
+ return () => {
120
+ window.clearTimeout(timer);
121
+ media.removeEventListener("change", onChange);
122
+ };
123
+ }, [active, home, delay]);
124
+
125
+ return active ? glance : home;
126
+ }
127
+
128
+ /** Eye travel in viewBox units. The shape stays on the center of the box. */
129
+ const LOOK: Record<AgentAvatarLook, [number, number]> = {
130
+ forward: [0, 0],
131
+ left: [-6.4, 0],
132
+ right: [6.4, 0],
133
+ up: [0, -4.4],
134
+ down: [0, 4.4],
135
+ "up-left": [-4.5, -3.1],
136
+ "up-right": [4.5, -3.1],
137
+ "down-left": [-4.5, 3.1],
138
+ "down-right": [4.5, 3.1],
96
139
  };
97
140
 
141
+ const LOOKS = Object.keys(LOOK) as AgentAvatarLook[];
142
+
98
143
  function mixHex(color: string, toward: "#fff" | "#000", amount: number) {
99
144
  const hex = color.replace("#", "");
100
145
  const channel = (start: number) => Number.parseInt(hex.slice(start, start + 2), 16);
@@ -109,6 +154,67 @@ const PaintContext = createContext("#111");
109
154
  const ShadowContext = createContext<string | undefined>(undefined);
110
155
  const InkContext = createContext(EYE);
111
156
 
157
+ /** Logo mark, fitted to the avatar box. The mark stays centered. Eyes and the smile travel. */
158
+ const NONLA_HAT =
159
+ "M32.05 11.6C31.32 11.6 26.28 15.07 17.23 22.05C12.68 25.52 8.71 28.77 6.19 31.06C5.2 31.92 4.21 32.86 3.49 33.77C2.95 34.49 2.36 35.16 2.09 35.57C1.91 36.15 1.95 36.83 2 37.37A30 4.86 0 0 1 62 37.37C62.05 36.83 62.09 36.15 61.91 35.57C61.64 35.16 61.05 34.49 60.51 33.77C59.79 32.86 58.8 31.92 57.81 31.06C55.29 28.77 51.32 25.52 46.77 22.05C37.72 15.07 32.68 11.6 32.05 11.6Z";
160
+
161
+ function nonlaTones(color: string) {
162
+ return {
163
+ brim: mixHex(color, "#000", 0.3),
164
+ face: mixHex(color, "#fff", 0.25),
165
+ hat: color,
166
+ };
167
+ }
168
+
169
+ function NonlaHat({ tone }: { tone: ReturnType<typeof nonlaTones> }) {
170
+ return (
171
+ <>
172
+ <path fill={tone.hat} d={NONLA_HAT} />
173
+ <path fill="none" stroke={tone.hat} strokeWidth="0.4" d="M2.5 37.37A29.5 4.86 0 0 1 61.5 37.37" />
174
+ <path fill="none" stroke={tone.brim} strokeWidth="1" d="M2.5 37.37A29.5 4.77 0 0 1 61.5 37.37" />
175
+ <g fill="none" stroke={tone.brim} strokeWidth="0.5" strokeLinecap="round" opacity="0.55">
176
+ <path d="M31.23 12.86C25.6 20.25 17.95 27.5 10.15 33.9" />
177
+ <path d="M31.59 12.86C28.98 19.4 26.46 25.52 23.94 31.38" />
178
+ <path d="M32.5 12.86C35.11 19.4 37.63 25.52 40.15 31.38" />
179
+ <path d="M32.86 12.86C38.49 20.25 46.14 27.5 53.94 33.9" />
180
+ </g>
181
+ </>
182
+ );
183
+ }
184
+
185
+ function NonlaMark({ color }: { color: string }) {
186
+ const tone = nonlaTones(color);
187
+ const ink = useContext(InkContext);
188
+ const shadow = useContext(ShadowContext);
189
+ const catchlight = ink === EYE_ON_DARK ? EYE : "#fff";
190
+ const clip = `nonla-face-${useId().replace(/:/g, "")}`;
191
+ return (
192
+ <>
193
+ <g filter={shadow}>
194
+ <ellipse cx="32" cy="37.37" rx="30" ry="8.56" fill={tone.brim} />
195
+ <circle cx="32.05" cy="35.66" r="16.74" fill={tone.face} />
196
+ <NonlaHat tone={tone} />
197
+ </g>
198
+ <clipPath id={clip}>
199
+ <circle cx="32.05" cy="35.66" r="16.74" />
200
+ </clipPath>
201
+ <g clipPath={`url(#${clip})`}>
202
+ <g className="nonla-avatar-gaze">
203
+ <g className="nonla-avatar-eyes">
204
+ <ellipse cx="24.82" cy="40.3" rx="2" ry="3.06" fill={ink} />
205
+ <ellipse cx="38.96" cy="40.3" rx="2" ry="3.06" fill={ink} />
206
+ <ellipse cx="25.29" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
207
+ <ellipse cx="39.43" cy="39.08" rx="0.59" ry="0.86" fill={catchlight} />
208
+ </g>
209
+ <path fill="none" stroke={EYE} strokeWidth="1.08" strokeLinecap="round" d="M28.8 44.67C30.47 46.65 33.53 46.65 35.15 44.67" />
210
+ </g>
211
+ </g>
212
+ {/* Covers eyes that travel up into the cone. The smile stays below this edge. */}
213
+ <NonlaHat tone={tone} />
214
+ </>
215
+ );
216
+ }
217
+
112
218
  function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number; h?: number }) {
113
219
  const gap = w * 1.5;
114
220
  const top = cy - h / 2;
@@ -162,6 +268,7 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
162
268
  <Eyes cx={32} cy={34} />,
163
269
  -6,
164
270
  ),
271
+ nonla: <NonlaMark color={color} />,
165
272
  };
166
273
  return <InkContext.Provider value={eyeFill(color, eyeColor)}>{body[shape]}</InkContext.Provider>;
167
274
  }
@@ -169,9 +276,8 @@ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
169
276
  export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
170
277
  const resolved = resolveConfig(config);
171
278
  const delay = stagger(`${resolved.shape}${resolved.color}`);
172
- const facing = LOOK[look];
173
- const [hx, hy] = facing.head;
174
- const [ex, ey] = facing.eyes;
279
+ const shown = useIdleLook(motion === "idle", look, delay);
280
+ const [ex, ey] = LOOK[shown];
175
281
  const uid = useId().replace(/:/g, "");
176
282
  const light = `nonla-av-${uid}`;
177
283
  const shadow = `nonla-av-s-${uid}`;
@@ -181,14 +287,12 @@ export function AgentAvatar({ config, size = 64, motion = "still", look = "forwa
181
287
  role="img"
182
288
  aria-label={label}
183
289
  data-motion={motion}
184
- data-look={look}
290
+ data-look={shown}
185
291
  className={cn("nonla-avatar", className)}
186
292
  style={{
187
293
  width: size,
188
294
  height: size,
189
295
  ["--nonla-avatar-delay" as string]: `${delay}s`,
190
- ["--nonla-avatar-hx" as string]: `${(hx / 64) * 100}%`,
191
- ["--nonla-avatar-hy" as string]: `${(hy / 64) * 100}%`,
192
296
  ["--nonla-avatar-ex" as string]: `${(ex / 64) * 100}%`,
193
297
  ["--nonla-avatar-ey" as string]: `${(ey / 64) * 100}%`,
194
298
  }}
@@ -1,51 +1,3 @@
1
- @keyframes nonla-avatar-wander {
2
- 0%,
3
- 14%,
4
- 100% {
5
- transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
6
- }
7
- 22%,
8
- 34% {
9
- transform: translate(-5%, 1%);
10
- }
11
- 42%,
12
- 54% {
13
- transform: translate(0, -4%);
14
- }
15
- 62%,
16
- 74% {
17
- transform: translate(5%, 1%);
18
- }
19
- 82%,
20
- 94% {
21
- transform: translate(0, 4.4%);
22
- }
23
- }
24
-
25
- @keyframes nonla-avatar-glance {
26
- 0%,
27
- 14%,
28
- 100% {
29
- transform: translate(var(--nonla-avatar-ex, 0), var(--nonla-avatar-ey, 0));
30
- }
31
- 22%,
32
- 34% {
33
- transform: translate(-10%, 0.6%);
34
- }
35
- 42%,
36
- 54% {
37
- transform: translate(0, -6.9%);
38
- }
39
- 62%,
40
- 74% {
41
- transform: translate(10%, 0.6%);
42
- }
43
- 82%,
44
- 94% {
45
- transform: translate(0, 7.2%);
46
- }
47
- }
48
-
49
1
  @keyframes nonla-avatar-blink {
50
2
  0%,
51
3
  46%,
@@ -58,7 +10,7 @@
58
10
  }
59
11
  }
60
12
 
61
- /* A quiet shift, not a bounce. */
13
+ /* The shape stays put. Only the eyes travel. */
62
14
  .nonla-avatar {
63
15
  display: inline-flex;
64
16
  flex-shrink: 0;
@@ -70,7 +22,6 @@
70
22
  display: block;
71
23
  width: 100%;
72
24
  height: 100%;
73
- transform: translate(var(--nonla-avatar-hx, 0), var(--nonla-avatar-hy, 0));
74
25
  }
75
26
 
76
27
  .nonla-avatar-gaze {
@@ -83,14 +34,8 @@
83
34
  transform-origin: center;
84
35
  }
85
36
 
86
- .nonla-avatar[data-motion="idle"] .nonla-avatar-bob {
87
- animation: nonla-avatar-wander 8.4s ease-in-out infinite;
88
- animation-delay: var(--nonla-avatar-delay, 0s);
89
- }
90
-
91
37
  .nonla-avatar[data-motion="idle"] .nonla-avatar-gaze {
92
- animation: nonla-avatar-glance 8.4s ease-in-out infinite;
93
- animation-delay: var(--nonla-avatar-delay, 0s);
38
+ transition: transform 0.55s ease-in-out;
94
39
  }
95
40
 
96
41
  .nonla-avatar[data-motion="idle"] .nonla-avatar-eyes {
@@ -99,9 +44,9 @@
99
44
  }
100
45
 
101
46
  @media (prefers-reduced-motion: reduce) {
102
- .nonla-avatar[data-motion] .nonla-avatar-bob,
103
47
  .nonla-avatar[data-motion] .nonla-avatar-gaze,
104
48
  .nonla-avatar[data-motion] .nonla-avatar-eyes {
105
49
  animation: none;
50
+ transition: none;
106
51
  }
107
52
  }
@@ -6,26 +6,26 @@ export type ChatMarkdownProps = {
6
6
  streaming?: boolean;
7
7
  };
8
8
 
9
- /** Reply headings match the body: `text-md`, weight 400. Strong is 500. Tables stay `text-base`. */
9
+ /** Reply headings are `text-lg` at the strong weight. Body stays `text-md`. Strong is 500. Tables stay `text-base`. */
10
10
  const chatHeadingScale = {
11
- "--md-h1-size": "var(--nonla-md-text-size)",
12
- "--md-h2-size": "var(--nonla-md-text-size)",
13
- "--md-h3-size": "var(--nonla-md-text-size)",
14
- "--md-h4-size": "var(--nonla-md-text-size)",
15
- "--md-h5-size": "var(--nonla-md-text-size)",
16
- "--md-h6-size": "var(--nonla-md-text-size)",
17
- "--md-h1-leading": "var(--md-body-leading)",
18
- "--md-h2-leading": "var(--md-body-leading)",
19
- "--md-h3-leading": "var(--md-body-leading)",
20
- "--md-h4-leading": "var(--md-body-leading)",
21
- "--md-h5-leading": "var(--md-body-leading)",
22
- "--md-h6-leading": "var(--md-body-leading)",
23
- "--md-h1-weight": "400",
24
- "--md-h2-weight": "400",
25
- "--md-h3-weight": "400",
26
- "--md-h4-weight": "400",
27
- "--md-h5-weight": "400",
28
- "--md-h6-weight": "400",
11
+ "--md-h1-size": "var(--text-lg)",
12
+ "--md-h2-size": "var(--text-lg)",
13
+ "--md-h3-size": "var(--text-lg)",
14
+ "--md-h4-size": "var(--text-lg)",
15
+ "--md-h5-size": "var(--text-lg)",
16
+ "--md-h6-size": "var(--text-lg)",
17
+ "--md-h1-leading": "var(--text-lg--line-height)",
18
+ "--md-h2-leading": "var(--text-lg--line-height)",
19
+ "--md-h3-leading": "var(--text-lg--line-height)",
20
+ "--md-h4-leading": "var(--text-lg--line-height)",
21
+ "--md-h5-leading": "var(--text-lg--line-height)",
22
+ "--md-h6-leading": "var(--text-lg--line-height)",
23
+ "--md-h1-weight": "500",
24
+ "--md-h2-weight": "500",
25
+ "--md-h3-weight": "500",
26
+ "--md-h4-weight": "500",
27
+ "--md-h5-weight": "500",
28
+ "--md-h6-weight": "500",
29
29
  "--md-strong-weight": "500",
30
30
  } as CSSProperties;
31
31
 
@@ -39,7 +39,7 @@ const chatEdgeClass = [
39
39
  "[&_[data-md-block]:first-child_:is(p,h1,h2,h3,h4,h5,h6,ul,ol)]:mt-0! [&_[data-md-block]:first-child_:is(p,h1,h2,h3,h4,h5,h6)]:pt-0! [&_[data-md-block]:last-child_:is(p,h1,h2,h3,h4,h5,h6,ul,ol)]:mb-0! [&_[data-md-block]:last-child_:is(p,h1,h2,h3,h4,h5,h6)]:pb-0!",
40
40
  ].join(" ");
41
41
 
42
- /** Agent markdown. Headings use the body size at weight 400. */
42
+ /** Agent markdown. Headings are `text-lg` at the strong weight. */
43
43
  export function ChatMarkdown({ content, streaming = false }: ChatMarkdownProps) {
44
44
  return <MarkdownViewer value={content} streaming={streaming} className={chatEdgeClass} style={chatHeadingScale} />;
45
45
  }
package/src/icon/Icon.tsx CHANGED
@@ -7,12 +7,24 @@ export function isIconName(value: unknown): value is IconName {
7
7
  return typeof value === "string" && value in ICON_GLYPHS;
8
8
  }
9
9
 
10
- export function Icon({ name, size = 16, className }: { name: IconName; size?: number; className?: string }) {
11
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">${ICON_GLYPHS[name]}</svg>`;
10
+ export function Icon({
11
+ name,
12
+ size = 16,
13
+ stroke = 1.5,
14
+ className,
15
+ }: {
16
+ name: IconName;
17
+ size?: number;
18
+ /** Line weight in the 24 viewBox. `1.5` is the regular weight. Higher draws a bolder line. */
19
+ stroke?: number;
20
+ className?: string;
21
+ }) {
22
+ const glyph = ICON_GLYPHS[name].replaceAll('stroke-width="1.5"', `stroke-width="${stroke}"`);
23
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke-width="${stroke}" shape-rendering="geometricPrecision">${glyph}</svg>`;
12
24
  return (
13
25
  <span
14
26
  aria-hidden
15
- className={cn("inline-flex shrink-0 select-none text-current pointer-events-none [&_svg]:size-full", className)}
27
+ className={cn("inline-flex shrink-0 items-center justify-center leading-none select-none text-current pointer-events-none", className)}
16
28
  style={{ width: size, height: size }}
17
29
  // biome-ignore lint/security/noDangerouslySetInnerHtml: glyph markup is a fixed set shipped with the library
18
30
  dangerouslySetInnerHTML={{ __html: svg }}
@@ -1,4 +1,4 @@
1
- /** Glyphs from the Solar icon set by 480 Design, CC BY 4.0. https://creativecommons.org/licenses/by/4.0/ */
1
+ /** Glyphs from the Solar icon set by 480 Design, CC BY 4.0. `json` and `md` are drawn in the same stroke style. https://creativecommons.org/licenses/by/4.0/ */
2
2
  export const ICON_GLYPHS = {
3
3
  "add": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M4 12L20 12\"/><path d=\"M12 4L12 20\"/></g>",
4
4
  "arrow-down": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\" d=\"M19 9L12 15L5 9\"/>",
@@ -7,12 +7,14 @@ export const ICON_GLYPHS = {
7
7
  "arrow-up": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\" d=\"M12 20L12 4M6 10L12 4L18 10\"/>",
8
8
  "book": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M4 8C4 5.17157 4 3.75736 4.87868 2.87868C5.75736 2 7.17157 2 10 2H14C16.8284 2 18.2426 2 19.1213 2.87868C20 3.75736 20 5.17157 20 8V16C20 18.8284 20 20.2426 19.1213 21.1213C18.2426 22 16.8284 22 14 22H10C7.17157 22 5.75736 22 4.87868 21.1213C4 20.2426 4 18.8284 4 16V8Z\"/><path d=\"M19.8978 16H7.89778C6.96781 16 6.50282 16 6.12132 16.1022C5.08604 16.3796 4.2774 17.1883 4 18.2235\"/><path d=\"M8 7H16\"/><path d=\"M8 10.5H13\"/></g>",
9
9
  "check": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\" d=\"M5 13L9 17L19 7\"/>",
10
+ "checkbox": "<g fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"><path d=\"M2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12Z\"/><path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M8.5 12.5L10.5 14.5L15.5 9.5\"/></g>",
10
11
  "chevrons-left": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M13 19L7 12L13 5\"/><path d=\"M17 19L11 12L17 5\"/></g>",
11
12
  "chevrons-right": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M11 19L17 12L11 5\"/><path d=\"M7 19L13 12L7 5\"/></g>",
12
13
  "clock": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path stroke-linejoin=\"round\" d=\"M12 8V12L14.5 14.5\"/></g>",
13
14
  "close": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M19 5L5 19\"/><path d=\"M19 19L5 5\"/></g>",
14
15
  "code": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M15.5 9L15.6716 9.17157C17.0049 10.5049 17.6716 11.1716 17.6716 12C17.6716 12.8284 17.0049 13.4951 15.6716 14.8284L15.5 15\"/><path d=\"M13.2939 7.17041L11.9998 12L10.7058 16.8297\"/><path d=\"M8.50019 9L8.32861 9.17157C6.99528 10.5049 6.32861 11.1716 6.32861 12C6.32861 12.8284 6.99528 13.4951 8.32861 14.8284L8.50019 15\"/><path d=\"M2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12Z\"/></g>",
15
16
  "copy": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M6 11C6 8.17157 6 6.75736 6.87868 5.87868C7.75736 5 9.17157 5 12 5H15C17.8284 5 19.2426 5 20.1213 5.87868C21 6.75736 21 8.17157 21 11V16C21 18.8284 21 20.2426 20.1213 21.1213C19.2426 22 17.8284 22 15 22H12C9.17157 22 7.75736 22 6.87868 21.1213C6 20.2426 6 18.8284 6 16V11Z\"/><path d=\"M6 19C4.34315 19 3 17.6569 3 16V10C3 6.22876 3 4.34315 4.17157 3.17157C5.34315 2 7.22876 2 11 2H15C16.6569 2 18 3.34315 18 5\"/></g>",
17
+ "datetime": "<g fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"><path d=\"M2 12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12V14C22 17.7712 22 19.6569 20.8284 20.8284C19.6569 22 17.7712 22 14 22H10C6.22876 22 4.34315 22 3.17157 20.8284C2 19.6569 2 17.7712 2 14V12Z\"/><path stroke-linecap=\"round\" d=\"M7 4V2.5\"/><path stroke-linecap=\"round\" d=\"M17 4V2.5\"/><path stroke-linecap=\"round\" d=\"M2.5 9H21.5\"/></g>",
16
18
  "dialog": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M16.09 6.58944C15.1281 6 13.8187 6 11.2 6H8.8C6.18126 6 4.87188 6 3.91001 6.58944C3.37178 6.91927 2.91926 7.37179 2.58944 7.91001C2 8.8719 2 10.1813 2 12.8V13.6C2 15.4638 2 16.3957 2.30448 17.1308C2.71046 18.1109 3.48915 18.8896 4.46927 19.2956C4.93479 19.4884 5.47923 19.5591 6.28931 19.585C7.15324 19.6126 7.58521 19.6264 7.91637 19.8223C8.24753 20.0182 8.45544 20.3695 8.8712 21.0719L8.87121 21.0719L9.13064 21.5102C9.51718 22.1633 10.4828 22.1633 10.8693 21.5102L11.1288 21.0719C11.5445 20.3695 11.7524 20.0182 12.0836 19.8223C12.4148 19.6264 12.8467 19.6126 13.7107 19.585C14.5208 19.5591 15.0652 19.4884 15.5307 19.2956C16.5108 18.8896 17.2895 18.1109 17.6955 17.1308C18 16.3957 18 15.4638 18 13.6V12.8C18 10.1813 18 8.8719 17.4106 7.91001C17.0807 7.37179 16.6282 6.91927 16.09 6.58944Z\"/><path d=\"M7.0332 6C7.08481 5.00787 7.2165 4.33902 7.55255 3.79064C7.86176 3.28605 8.28599 2.86181 8.79058 2.5526C9.69234 2 10.9199 2 13.3749 2H15.6249C18.08 2 19.3076 2 20.2093 2.5526C20.7139 2.86181 21.1381 3.28605 21.4473 3.79064C21.9999 4.6924 21.9999 5.91994 21.9999 8.37503V9.12503C21.9999 10.8723 21.9999 11.746 21.7145 12.4351C21.3339 13.354 20.6039 14.084 19.685 14.4646C19.2527 14.6437 18.7477 14.7104 18 14.7352\"/><path stroke-linejoin=\"round\" d=\"M6.50928 13H6.51828M10 13H10.009M13.491 13H13.5\"/></g>",
17
19
  "document": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M3 10C3 6.22876 3 4.34315 4.17157 3.17157C5.34315 2 7.22876 2 11 2H13C16.7712 2 18.6569 2 19.8284 3.17157C21 4.34315 21 6.22876 21 10V14C21 17.7712 21 19.6569 19.8284 20.8284C18.6569 22 16.7712 22 13 22H11C7.22876 22 5.34315 22 4.17157 20.8284C3 19.6569 3 17.7712 3 14V10Z\"/><path d=\"M8 12H16\"/><path d=\"M8 8H16\"/><path d=\"M8 16H13\"/></g>",
18
20
  "download": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M17 9.00195C19.175 9.01406 20.3529 9.11051 21.1213 9.8789C22 10.7576 22 12.1718 22 15.0002V16.0002C22 18.8286 22 20.2429 21.1213 21.1215C20.2426 22.0002 18.8284 22.0002 16 22.0002H8C5.17157 22.0002 3.75736 22.0002 2.87868 21.1215C2 20.2429 2 18.8286 2 16.0002L2 15.0002C2 12.1718 2 10.7576 2.87868 9.87889C3.64706 9.11051 4.82497 9.01406 7 9.00195\"/><path stroke-linejoin=\"round\" d=\"M12 2L12 15M15 11.5L12 15L9 11.5\"/></g>",
@@ -20,16 +22,21 @@ export const ICON_GLYPHS = {
20
22
  "error": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 7V13\"/><path stroke-linejoin=\"round\" d=\"M12 16H12.0001\"/></g>",
21
23
  "eye": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M3.27489 15.2957C2.42496 14.1915 2 13.6394 2 12C2 10.3606 2.42496 9.80853 3.27489 8.70433C4.97196 6.49956 7.81811 4 12 4C16.1819 4 19.028 6.49956 20.7251 8.70433C21.575 9.80853 22 10.3606 22 12C22 13.6394 21.575 14.1915 20.7251 15.2957C19.028 17.5004 16.1819 20 12 20C7.81811 20 4.97196 17.5004 3.27489 15.2957Z\"/><path d=\"M15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12Z\"/></g>",
22
24
  "globe": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><circle cx=\"12\" cy=\"12\" r=\"10\"/><ellipse cx=\"12\" cy=\"12\" rx=\"4\" ry=\"10\"/><path d=\"M2 12H22\"/></g>",
25
+ "json": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M9.5 5C7.6 5 7.2 7.2 7.2 9.2C7.2 10.6 5.4 11.2 5.4 12C5.4 12.8 7.2 13.4 7.2 14.8C7.2 16.8 7.6 19 9.5 19\"/><path d=\"M14.5 5C16.4 5 16.8 7.2 16.8 9.2C16.8 10.6 18.6 11.2 18.6 12C18.6 12.8 16.8 13.4 16.8 14.8C16.8 16.8 16.4 19 14.5 19\"/></g>",
23
26
  "maximize": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M9 15L2 22M2 16.1429V22H7.85714\"/><path d=\"M15 9L22 2M22 7.85714V2H16.1429\"/></g>",
27
+ "md": "<g fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"><path d=\"M2 12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12C22 15.7712 22 17.6569 20.8284 18.8284C19.6569 20 17.7712 20 14 20H10C6.22876 20 4.34315 20 3.17157 18.8284C2 17.6569 2 15.7712 2 12Z\"/><path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M5.5 15.75V8.25L7.85 12.35L10.2 8.25V15.75\"/><path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M13.35 8.25H14.7C16.85 8.25 18.15 10.05 18.15 12C18.15 13.95 16.85 15.75 14.7 15.75H13.35V8.25\"/></g>",
24
28
  "minimize": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M2 22L9 15M9 20.8571V15H3.14286\"/><path d=\"M22 2L15 9M15 3.14286V9H20.8571\"/></g>",
25
29
  "monitor": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M2 10C2 6.22876 2 4.34315 3.17157 3.17157C4.34315 2 6.22876 2 10 2H14C17.7712 2 19.6569 2 20.8284 3.17157C22 4.34315 22 6.22876 22 10V11C22 13.8284 22 15.2426 21.1213 16.1213C20.2426 17 18.8284 17 16 17H8C5.17157 17 3.75736 17 2.87868 16.1213C2 15.2426 2 13.8284 2 11V10Z\"/><path d=\"M16 22H8\"/><path d=\"M12 17L12 22\"/><path d=\"M22 13H2\"/></g>",
26
30
  "moon": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\" d=\"M12 22C17.5228 22 22 17.5228 22 12C22 11.5373 21.3065 11.4608 21.0672 11.8568C19.9289 13.7406 17.8615 15 15.5 15C11.9101 15 9 12.0899 9 8.5C9 6.13845 10.2594 4.07105 12.1432 2.93276C12.5392 2.69347 12.4627 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z\"/>",
27
31
  "pen": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\" d=\"M14.3601 4.07866L15.2869 3.15178C16.8226 1.61607 19.3125 1.61607 20.8482 3.15178C22.3839 4.68748 22.3839 7.17735 20.8482 8.71306L19.9213 9.63993M14.3601 4.07866C14.3601 4.07866 14.4759 6.04828 16.2138 7.78618C17.9517 9.52407 19.9213 9.63993 19.9213 9.63993M19.9213 9.63993L11.4001 18.1612C10.8229 18.7383 10.5344 19.0269 10.2162 19.2751C9.84082 19.5679 9.43469 19.8189 9.00498 20.0237C8.6407 20.1973 8.25352 20.3263 7.47918 20.5844L4.19792 21.6782L3.39584 21.9456C3.01478 22.0726 2.59466 21.9734 2.31063 21.6894C2.0266 21.4053 1.92743 20.9852 2.05445 20.6042L2.32181 19.8021L3.41556 16.5208C3.67368 15.7465 3.80273 15.3593 3.97634 14.995C4.18114 14.5653 4.43213 14.1592 4.7249 13.7838C4.97308 13.4656 5.26166 13.1771 5.83882 12.5999L14.3601 4.07866M4.19792 21.6782L2.32181 19.8021\"/>",
32
+ "select": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M21 6L3 6\"/><path d=\"M21 10L3 10\"/><path d=\"M10 14H3\"/><path d=\"M10 18H3\"/><path stroke-linejoin=\"round\" d=\"M14 15L17.5 18L21 15\"/></g>",
28
33
  "shield-check": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M3 10.4167C3 7.21907 3 5.62028 3.37752 5.08241C3.75503 4.54454 5.25832 4.02996 8.26491 3.00079L8.83772 2.80472C10.405 2.26824 11.1886 2 12 2C12.8114 2 13.595 2.26824 15.1623 2.80472L15.7351 3.00079C18.7417 4.02996 20.245 4.54454 20.6225 5.08241C21 5.62028 21 7.21907 21 10.4167C21 10.8996 21 11.4234 21 11.9914C21 17.6294 16.761 20.3655 14.1014 21.5273C13.38 21.8424 13.0193 22 12 22C10.9807 22 10.62 21.8424 9.89856 21.5273C7.23896 20.3655 3 17.6294 3 11.9914C3 11.4234 3 10.8996 3 10.4167Z\"/><path stroke-linejoin=\"round\" d=\"M9.5 12.4L10.9286 14L14.5 10\"/></g>",
29
34
  "stars": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M8.03339 3.65784C8.37932 2.78072 9.62068 2.78072 9.96661 3.65785L11.0386 6.37599C11.1442 6.64378 11.3562 6.85576 11.624 6.96137L14.3422 8.03339C15.2193 8.37932 15.2193 9.62068 14.3422 9.96661L11.624 11.0386C11.3562 11.1442 11.1442 11.3562 11.0386 11.624L9.96661 14.3422C9.62067 15.2193 8.37932 15.2193 8.03339 14.3422L6.96137 11.624C6.85575 11.3562 6.64378 11.1442 6.37599 11.0386L3.65784 9.96661C2.78072 9.62067 2.78072 8.37932 3.65785 8.03339L6.37599 6.96137C6.64378 6.85575 6.85576 6.64378 6.96137 6.37599L8.03339 3.65784Z\"/><path d=\"M16.4885 13.3481C16.6715 12.884 17.3285 12.884 17.5115 13.3481L18.3121 15.3781C18.368 15.5198 18.4802 15.632 18.6219 15.6879L20.6519 16.4885C21.116 16.6715 21.116 17.3285 20.6519 17.5115L18.6219 18.3121C18.4802 18.368 18.368 18.4802 18.3121 18.6219L17.5115 20.6519C17.3285 21.116 16.6715 21.116 16.4885 20.6519L15.6879 18.6219C15.632 18.4802 15.5198 18.368 15.3781 18.3121L13.3481 17.5115C12.884 17.3285 12.884 16.6715 13.3481 16.4885L15.3781 15.6879C15.5198 15.632 15.632 15.5198 15.6879 15.3781L16.4885 13.3481Z\"/></g>",
30
35
  "stop": "<path fill=\"currentColor\" d=\"M2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12Z\"/>",
31
36
  "sun": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><circle cx=\"12\" cy=\"12\" r=\"6\"/><path d=\"M12 2V3\"/><path d=\"M12 21V22\"/><path d=\"M22 12L21 12\"/><path d=\"M3 12L2 12\"/><path d=\"M19.0708 4.92969L18.678 5.32252\"/><path d=\"M5.32178 18.6777L4.92894 19.0706\"/><path d=\"M19.0708 19.0703L18.678 18.6775\"/><path d=\"M5.32178 5.32227L4.92894 4.92943\"/></g>",
37
+ "text": "<g fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"><path d=\"M2 12C2 8.22876 2 6.34315 3.17157 5.17157C4.34315 4 6.22876 4 10 4H14C17.7712 4 19.6569 4 20.8284 5.17157C22 6.34315 22 8.22876 22 12C22 15.7712 22 17.6569 20.8284 18.8284C19.6569 20 17.7712 20 14 20H10C6.22876 20 4.34315 20 3.17157 18.8284C2 17.6569 2 15.7712 2 12Z\"/><path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 8.5H7.925C7.05492 8.5 6.61989 8.5 6.33575 8.75249C6.30638 8.77858 6.27858 8.80638 6.25249 8.83575C6 9.11989 6 9.55492 6 10.425M9 8.5H10.075C10.9451 8.5 11.3801 8.5 11.6643 8.75249C11.6936 8.77858 11.7214 8.80638 11.7475 8.83575C12 9.11989 12 9.55492 12 10.425M9 8.5V15.5M7 15.5H11\"/></g>",
32
38
  "transfer": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M20 10L4 10L9.5 4\"/><path d=\"M4 14L20 14L14.5 20\"/></g>",
39
+ "trash": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-width=\"1.5\"><path d=\"M9.1709 4C9.58273 2.83481 10.694 2 12.0002 2C13.3064 2 14.4177 2.83481 14.8295 4\"/><path d=\"M20.5001 6H3.5\"/><path d=\"M18.8332 8.5L18.3732 15.3991C18.1962 18.054 18.1077 19.3815 17.2427 20.1907C16.3777 21 15.0473 21 12.3865 21H11.6132C8.95235 21 7.62195 21 6.75694 20.1907C5.89194 19.3815 5.80344 18.054 5.62644 15.3991L5.1665 8.5\"/><path d=\"M9.5 11L10 16\"/><path d=\"M14.5 11L14 16\"/></g>",
33
40
  } as const;
34
41
 
35
42
  export type IconName = keyof typeof ICON_GLYPHS;
package/src/index.ts CHANGED
@@ -184,6 +184,8 @@ export type { SidebarItemType, SidebarProps, SidebarSelectInfo } from "./sidebar
184
184
  export { Sidebar } from "./sidebar/Sidebar";
185
185
  export type { SkeletonProps } from "./skeleton/Skeleton";
186
186
  export { Skeleton } from "./skeleton/Skeleton";
187
+ export type { SortableTreeChange, SortableTreeItem, SortableTreeProps } from "./sortable-tree/SortableTree";
188
+ export { SortableTree } from "./sortable-tree/SortableTree";
187
189
  export type { SpinColor, SpinProps, SpinVariant } from "./spin/Spin";
188
190
  export { Spin } from "./spin/Spin";
189
191
  export type { SplitterOrientation, SplitterPanelProps, SplitterProps, SplitterSemanticSlot, SplitterSize } from "./splitter/Splitter";
@@ -1,6 +1,5 @@
1
- import { type ReactNode, useCallback, useRef } from "react";
1
+ import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
2
2
  import { Button } from "../button/Button";
3
- import { ButtonCopy } from "../button/ButtonCopy";
4
3
  import { Icon } from "../icon/Icon";
5
4
  import { OverlayScroll } from "../scroll/OverlayScroll";
6
5
 
@@ -29,12 +28,30 @@ const tableClass =
29
28
  export function MarkdownTable({ children }: { children: ReactNode }) {
30
29
  const tableRef = useRef<HTMLTableElement>(null);
31
30
  const dialogRef = useRef<HTMLDialogElement>(null);
31
+ const [copied, setCopied] = useState(false);
32
32
 
33
33
  const getText = useCallback(() => {
34
34
  const table = tableRef.current;
35
35
  return table ? tableToMarkdown(table) : "";
36
36
  }, []);
37
37
 
38
+ useEffect(() => {
39
+ if (!copied) return;
40
+ const t = window.setTimeout(() => setCopied(false), 1600);
41
+ return () => window.clearTimeout(t);
42
+ }, [copied]);
43
+
44
+ const copyMarkdown = async () => {
45
+ const value = getText();
46
+ if (!value) return;
47
+ try {
48
+ await navigator.clipboard.writeText(value);
49
+ setCopied(true);
50
+ } catch {
51
+ /* ignore */
52
+ }
53
+ };
54
+
38
55
  const openFullscreen = () => {
39
56
  dialogRef.current?.showModal();
40
57
  };
@@ -45,14 +62,14 @@ export function MarkdownTable({ children }: { children: ReactNode }) {
45
62
 
46
63
  return (
47
64
  <>
48
- <div className="group relative my-(--md-table-my,16px) max-w-full">
49
- <div className="absolute top-1 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100">
50
- <ButtonCopy getText={getText} label="Copy as Markdown" />
51
- <Button size="small" icon={<Icon name="maximize" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
65
+ <div className="group relative my-(--md-table-my,16px) max-w-full overflow-hidden rounded-xl border border-border bg-card">
66
+ <div className="absolute top-1.5 right-1.5 z-10 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100">
67
+ <Button size="small" className="bg-background" icon={<Icon name={copied ? "check" : "copy"} size={12} />} title={copied ? "Copied" : "Copy as Markdown"} aria-label={copied ? "Copied" : "Copy as Markdown"} onClick={copyMarkdown} />
68
+ <Button size="small" className="bg-background" icon={<Icon name="maximize" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
52
69
  </div>
53
70
 
54
71
  <OverlayScroll autoHeight visibility="hover" scope="table" innerClassName="overflow-x-auto">
55
- <table ref={tableRef} className={`${tableClass} [&_th]:max-w-[360px] [&_td]:max-w-[360px] [&_th:first-child]:pl-0 [&_th:last-child]:pr-0 [&_td:first-child]:pl-0 [&_td:last-child]:pr-0`}>
72
+ <table ref={tableRef} className={`${tableClass} [&_tr:last-child_td]:border-b-0 [&_th]:max-w-[360px] [&_td]:max-w-[360px]`}>
56
73
  {children}
57
74
  </table>
58
75
  </OverlayScroll>
@@ -68,9 +85,9 @@ export function MarkdownTable({ children }: { children: ReactNode }) {
68
85
  closeFullscreen();
69
86
  }}
70
87
  >
71
- <div className="absolute top-5 right-5 z-50 flex items-center gap-1.5">
72
- <ButtonCopy getText={getText} label="Copy as Markdown" />
73
- <Button size="small" icon={<Icon name="minimize" size={12} />} title="Exit fullscreen" aria-label="Exit fullscreen" onClick={closeFullscreen} />
88
+ <div className="absolute top-5 right-5 z-50 flex items-center gap-1">
89
+ <Button size="small" className="bg-background" icon={<Icon name={copied ? "check" : "copy"} size={12} />} title={copied ? "Copied" : "Copy as Markdown"} aria-label={copied ? "Copied" : "Copy as Markdown"} onClick={copyMarkdown} />
90
+ <Button size="small" className="bg-background" icon={<Icon name="minimize" size={12} />} title="Exit fullscreen" aria-label="Exit fullscreen" onClick={closeFullscreen} />
74
91
  </div>
75
92
 
76
93
  <div className="min-h-0 flex-1 overflow-auto p-8">
@@ -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
@@ -18,25 +18,25 @@
18
18
  color-scheme: dark;
19
19
 
20
20
  /* ── Config. Set these. `.light` repeats the same keys. ────────────── */
21
- /* Page #141414. Sidebar sits with the page, #161616. Cards #181818. */
22
- --nonla-bg: #141414;
23
- --nonla-text-main: #e0e0e0;
24
- --nonla-text-secondary: color-mix(in oklab, var(--nonla-text-main) 74%, var(--nonla-bg));
25
- --nonla-text-tertiary: color-mix(in oklab, var(--nonla-text-main) 60%, var(--nonla-bg));
26
- --nonla-text-quaternary: color-mix(in oklab, var(--nonla-text-main) 36%, var(--nonla-bg));
21
+ /* Claude dark (claude.com). Warm gray, hue ~60. Page 950, sidebar 900, cards 850, bar 800. */
22
+ --nonla-bg: #141413;
23
+ --nonla-text-main: #faf9f5;
24
+ --nonla-text-secondary: #b0aea5;
25
+ --nonla-text-tertiary: #87867f;
26
+ --nonla-text-quaternary: #73726c;
27
27
  --nonla-text-on-solid: #ffffff;
28
28
  --nonla-brand: #f18d00;
29
- --nonla-danger: #ef4444;
30
- --nonla-success: #3fa266;
29
+ --nonla-danger: #bf4d43;
30
+ --nonla-success: #629987; /* mineral */
31
31
  --nonla-warn: #f1b467;
32
- --nonla-link: #81a1c1;
33
-
34
- --nonla-sidebar: #161616;
35
- --nonla-surface: #181818;
36
- --nonla-bar: #242424;
37
- --nonla-border: color-mix(in oklab, var(--nonla-text-main) 6%, transparent);
38
- --nonla-border-secondary: color-mix(in oklab, var(--nonla-text-main) 3%, transparent);
39
- --nonla-input: rgba(255, 255, 235, 0.1);
32
+ --nonla-link: #6a9bcc; /* sky */
33
+
34
+ --nonla-sidebar: #1a1918;
35
+ --nonla-surface: #1f1e1d;
36
+ --nonla-bar: #262624;
37
+ --nonla-border: #2c2b29;
38
+ --nonla-border-secondary: #242322;
39
+ --nonla-input: rgb(250 249 245 / 14%);
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
42
  /* Default body size. Tailwind `text-base` follows this. Leading is 1.6. */