devnonla-ui 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/blob-shape/BlobShape.tsx +337 -0
- package/src/button/ButtonCopy.tsx +2 -2
- package/src/chat/AgentChatbox.tsx +1 -1
- package/src/chat/AgentPanel.tsx +1 -1
- package/src/chat/chatMessageList.tsx +5 -3
- package/src/chat/chatRhythm.ts +8 -0
- package/src/chat/common/createAgentSseSession.ts +9 -3
- package/src/chat/common/sse.ts +290 -122
- package/src/chat/common/useAgentStream.ts +1 -1
- package/src/chat/index.ts +2 -2
- package/src/chat/message-ui/ChatAgentMessage.tsx +4 -3
- package/src/chat/message-ui/ChatError.tsx +5 -4
- package/src/chat/message-ui/ChatInput.tsx +5 -5
- package/src/chat/message-ui/ChatMarkdown.tsx +36 -2
- package/src/chat/message-ui/ChatThinking.tsx +8 -7
- package/src/chat/message-ui/ChatUserMessage.tsx +4 -4
- package/src/chat/tool-ui/BackgroundTaskToolUI.tsx +7 -6
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +7 -7
- package/src/chat/tool-ui/CallAgentToolUI.tsx +14 -13
- package/src/chat/tool-ui/ChatToolCall.tsx +13 -12
- package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +7 -6
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +10 -9
- package/src/chat/tool-ui/RunJsToolUI.tsx +8 -7
- package/src/chat/tool-ui/ToolUiTrailing.tsx +3 -3
- package/src/chat/tool-ui/WebFetchToolUI.tsx +10 -9
- package/src/codeblock/CodeBlock.tsx +1 -1
- package/src/desktop/DesktopIcon.tsx +3 -4
- package/src/icon/Icon.tsx +21 -0
- package/src/icon/glyphs.ts +35 -0
- package/src/index.ts +6 -20
- package/src/input/EditableInput.tsx +2 -2
- package/src/markdown-editor/MarkdownEditor.tsx +4 -4
- package/src/markdown-editor/MarkdownPreview.tsx +4 -4
- package/src/markdown-editor/MarkdownTable.tsx +48 -11
- package/src/markdown-editor/MarkdownViewer.tsx +25 -28
- package/src/markdown-editor/MermaidBlock.tsx +4 -4
- package/src/markdown-editor/ReactCodeFrame.tsx +2 -2
- package/src/markdown-editor/ReactCodeSandbox.tsx +2 -2
- package/src/markdown-editor/markdownScale.ts +65 -131
- package/src/menu/Menu.tsx +2 -2
- package/src/pagination/Pagination.tsx +4 -4
- package/src/scroll/OverlayScroll.tsx +13 -5
- package/src/sidebar/Sidebar.tsx +5 -5
- package/src/styles.css +36 -16
- package/src/tabs/Tabs.tsx +75 -13
- package/src/theme-switcher/ThemeSwitcher.tsx +6 -6
- package/src/typography/Typography.tsx +4 -4
- package/src/icon/SolarIcon.tsx +0 -39
- package/src/icon/solar.ts +0 -172
package/src/menu/Menu.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Icon } from "../icon/Icon";
|
|
3
3
|
import { cn } from "../lib/cn";
|
|
4
4
|
import type { PopperPlacement } from "../lib/placement";
|
|
5
5
|
import { Popover } from "../popover/Popover";
|
|
@@ -48,7 +48,7 @@ export function MenuTrigger({ active, open, className, children, ...rest }: Menu
|
|
|
48
48
|
{...rest}
|
|
49
49
|
>
|
|
50
50
|
<span className="min-w-0 truncate leading-5">{children}</span>
|
|
51
|
-
<
|
|
51
|
+
<Icon name="arrow-down" size={12} className={cn("shrink-0 transition-transform duration-150", open && "rotate-180")} />
|
|
52
52
|
</button>
|
|
53
53
|
);
|
|
54
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type CSSProperties, cloneElement, isValidElement, type KeyboardEvent, type ReactElement, type ReactNode, useEffect, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Icon } from "../icon/Icon";
|
|
3
3
|
import { cn } from "../lib/cn";
|
|
4
4
|
import { type CanonicalSize, type ControlSize, controlFieldFocusBorder, controlFieldSurface, controlFieldTransition, controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
|
|
5
5
|
import { Select, type SelectProps } from "../select/Select";
|
|
@@ -137,7 +137,7 @@ function JumpInner({ dir, icon }: { dir: "prev" | "next"; icon: number }) {
|
|
|
137
137
|
<span className="relative inline-flex size-full items-center justify-center">
|
|
138
138
|
<span className="leading-none group-hover:opacity-0 group-focus-visible:opacity-0">…</span>
|
|
139
139
|
<span className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100">
|
|
140
|
-
{dir === "prev" ? <
|
|
140
|
+
{dir === "prev" ? <Icon name="chevrons-left" size={icon} /> : <Icon name="chevrons-right" size={icon} />}
|
|
141
141
|
</span>
|
|
142
142
|
</span>
|
|
143
143
|
);
|
|
@@ -369,8 +369,8 @@ export function Pagination(props: PaginationProps) {
|
|
|
369
369
|
|
|
370
370
|
const sizeOptions = toSizes(pageSizeOptions);
|
|
371
371
|
|
|
372
|
-
const prevInner = wrap(page - 1, "prev", <
|
|
373
|
-
const nextInner = wrap(page + 1, "next", <
|
|
372
|
+
const prevInner = wrap(page - 1, "prev", <Icon name="arrow-left" size={icon} />);
|
|
373
|
+
const nextInner = wrap(page + 1, "next", <Icon name="arrow-right" size={icon} />);
|
|
374
374
|
|
|
375
375
|
const pager = isSimple ? (
|
|
376
376
|
<>
|
|
@@ -6,9 +6,13 @@ export type OverlayScrollVisibility = "hover" | "always";
|
|
|
6
6
|
const HIDE_MS = 1000;
|
|
7
7
|
const MIN_THUMB = 32;
|
|
8
8
|
|
|
9
|
+
export type OverlayScrollScope = "scroll" | "table";
|
|
10
|
+
|
|
9
11
|
export type OverlayScrollProps = {
|
|
10
12
|
/** `hover` shows the thumb on hover / while scrolling. `always` keeps it visible. */
|
|
11
13
|
visibility?: OverlayScrollVisibility;
|
|
14
|
+
/** Named hover group. `table` does not light up when a parent chat scroller is hovered. */
|
|
15
|
+
scope?: OverlayScrollScope;
|
|
12
16
|
/** Size to content (honors max-height on `className`) instead of filling the parent. */
|
|
13
17
|
autoHeight?: boolean;
|
|
14
18
|
className?: string;
|
|
@@ -46,7 +50,7 @@ function canScrollX(el: HTMLDivElement) {
|
|
|
46
50
|
return overflow === "auto" || overflow === "scroll";
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
export function OverlayScroll({ visibility = "hover", autoHeight = false, className, style, innerClassName, children, onScroll, scrollRef, insetTop = 0 }: OverlayScrollProps) {
|
|
53
|
+
export function OverlayScroll({ visibility = "hover", scope = "scroll", autoHeight = false, className, style, innerClassName, children, onScroll, scrollRef, insetTop = 0 }: OverlayScrollProps) {
|
|
50
54
|
const elRef = useRef<HTMLDivElement | null>(null);
|
|
51
55
|
const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
52
56
|
const vThumbRef = useRef<Thumb>(HIDDEN);
|
|
@@ -146,18 +150,22 @@ export function OverlayScroll({ visibility = "hover", autoHeight = false, classN
|
|
|
146
150
|
|
|
147
151
|
const thumbVisible = visibility === "always" || dragging || scrolling;
|
|
148
152
|
const thumbClass = cn(
|
|
149
|
-
"absolute z-20 rounded-full bg-(--nonla-scrollbar-thumb) transition-opacity duration-150
|
|
153
|
+
"absolute z-20 rounded-full bg-(--nonla-scrollbar-thumb) transition-opacity duration-150",
|
|
154
|
+
scope === "table" ? "group-hover/table:bg-(--nonla-scrollbar-thumb-hover)" : "group-hover/scroll:bg-(--nonla-scrollbar-thumb-hover)",
|
|
150
155
|
visibility === "always" || dragging
|
|
151
156
|
? "pointer-events-auto opacity-100"
|
|
152
|
-
:
|
|
157
|
+
: scope === "table"
|
|
158
|
+
? "pointer-events-none opacity-0 group-hover/table:pointer-events-auto group-hover/table:opacity-100 group-data-scrolling/table:pointer-events-auto group-data-scrolling/table:opacity-100"
|
|
159
|
+
: "pointer-events-none opacity-0 group-hover/scroll:pointer-events-auto group-hover/scroll:opacity-100 group-data-scrolling/scroll:pointer-events-auto group-data-scrolling/scroll:opacity-100",
|
|
153
160
|
);
|
|
154
161
|
|
|
155
162
|
return (
|
|
156
|
-
<div className={cn("group/scroll relative min-h-0 min-w-0 w-full overflow-hidden", className)} style={style} data-scrolling={thumbVisible ? "true" : undefined}>
|
|
163
|
+
<div className={cn(scope === "table" ? "group/table" : "group/scroll", "relative min-h-0 min-w-0 w-full overflow-hidden", className)} style={style} data-scrolling={thumbVisible ? "true" : undefined}>
|
|
157
164
|
<div
|
|
158
165
|
ref={setNode}
|
|
159
166
|
onScroll={handleScroll}
|
|
160
|
-
className={cn("overflow-y-auto overflow-x-hidden [overflow-anchor:none] [
|
|
167
|
+
className={cn("overflow-y-auto overflow-x-hidden [overflow-anchor:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0", autoHeight ? "max-h-[inherit]" : "absolute inset-0", innerClassName)}
|
|
168
|
+
style={{ scrollbarWidth: "none" }}
|
|
161
169
|
>
|
|
162
170
|
{children}
|
|
163
171
|
</div>
|
package/src/sidebar/Sidebar.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type MouseEvent, type ReactNode, useMemo, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { solarIconName } from "../icon/solar";
|
|
2
|
+
import { Icon, isIconName } from "../icon/Icon";
|
|
4
3
|
import { SearchInput } from "../input/SearchInput";
|
|
5
4
|
import { cn } from "../lib/cn";
|
|
6
5
|
import { OverlayScroll } from "../scroll/OverlayScroll";
|
|
@@ -8,7 +7,7 @@ import { OverlayScroll } from "../scroll/OverlayScroll";
|
|
|
8
7
|
export type SidebarItemType = {
|
|
9
8
|
key?: string;
|
|
10
9
|
label?: ReactNode;
|
|
11
|
-
/**
|
|
10
|
+
/** An `Icon` name, or a node. */
|
|
12
11
|
icon?: ReactNode;
|
|
13
12
|
disabled?: boolean;
|
|
14
13
|
/** `"group"` is a section label. `"divider"` is a rule. Anything else is a row. */
|
|
@@ -86,7 +85,8 @@ function filterItems(items: SidebarItemType[], q: string): SidebarItemType[] {
|
|
|
86
85
|
|
|
87
86
|
function ItemIcon({ icon }: { icon?: ReactNode }) {
|
|
88
87
|
if (icon == null || icon === false) return null;
|
|
89
|
-
if (
|
|
88
|
+
if (isIconName(icon)) return <Icon name={icon} size={16} />;
|
|
89
|
+
if (typeof icon === "string") return null;
|
|
90
90
|
return <span className="inline-flex size-4 shrink-0 items-center justify-center [&_img]:size-4 [&_svg]:size-4">{icon}</span>;
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -109,7 +109,7 @@ function SidebarList({
|
|
|
109
109
|
if (item.type === "group") {
|
|
110
110
|
if (item.label == null || item.label === "") return null;
|
|
111
111
|
return (
|
|
112
|
-
<div key={key} className={cn("px-3 pb-1 pt-3 text-[11px] font-semibold uppercase tracking-wider text-tertiary-foreground not-first:mt-
|
|
112
|
+
<div key={key} className={cn("px-3 pb-1 pt-3 text-[11px] font-semibold uppercase tracking-wider text-tertiary-foreground not-first:mt-2", item.className)}>
|
|
113
113
|
{item.label}
|
|
114
114
|
</div>
|
|
115
115
|
);
|
package/src/styles.css
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
/* ── Config. Set these. `.light` repeats the same keys. ────────────── */
|
|
21
21
|
/* Page #141414. Sidebar sits with the page, #161616. Cards #181818. */
|
|
22
22
|
--nonla-bg: #141414;
|
|
23
|
-
--nonla-text-main: #
|
|
23
|
+
--nonla-text-main: #e0e0e0;
|
|
24
24
|
--nonla-text-secondary: color-mix(in oklab, var(--nonla-text-main) 74%, var(--nonla-bg));
|
|
25
25
|
--nonla-text-tertiary: color-mix(in oklab, var(--nonla-text-main) 60%, var(--nonla-bg));
|
|
26
26
|
--nonla-text-quaternary: color-mix(in oklab, var(--nonla-text-main) 36%, var(--nonla-bg));
|
|
@@ -39,8 +39,14 @@
|
|
|
39
39
|
--nonla-input: rgba(255, 255, 235, 0.1);
|
|
40
40
|
|
|
41
41
|
--nonla-font: ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
42
|
-
/*
|
|
43
|
-
--nonla-base-text-size:
|
|
42
|
+
/* Default body size. Tailwind `text-base` follows this. Leading is 1.6. */
|
|
43
|
+
--nonla-base-text-size: 15px;
|
|
44
|
+
/* `text-md`. MarkdownViewer body and agent reply text use this. */
|
|
45
|
+
--nonla-md-text-size: 16px;
|
|
46
|
+
/* `text-sm`. Composer, tool lines, and errors use this. User bubbles use `text-base`. */
|
|
47
|
+
--nonla-sm-text-size: 14px;
|
|
48
|
+
/* Code. A step under the body, so mono does not look larger than the text around it. */
|
|
49
|
+
--nonla-mono-text-size: calc(var(--nonla-base-text-size) * 0.9);
|
|
44
50
|
--nonla-radius: 8px;
|
|
45
51
|
--nonla-height: 32px;
|
|
46
52
|
--nonla-height-sm: 24px;
|
|
@@ -122,29 +128,35 @@
|
|
|
122
128
|
font-weight: 400;
|
|
123
129
|
}
|
|
124
130
|
|
|
131
|
+
/* Size stays off `html`, so `1rem` and Tailwind spacing do not shrink. */
|
|
132
|
+
body {
|
|
133
|
+
font-size: var(--nonla-base-text-size);
|
|
134
|
+
line-height: 1.6;
|
|
135
|
+
}
|
|
136
|
+
|
|
125
137
|
/* Same color keys as Config above. Brand and the label on it stay. */
|
|
126
138
|
.light:not(.dark),
|
|
127
139
|
.light .nonla-ui:not(.dark) {
|
|
128
140
|
color-scheme: light;
|
|
129
141
|
|
|
130
|
-
/* Light grays are Tailwind neutral. Page and
|
|
131
|
-
--nonla-bg: #
|
|
132
|
-
--nonla-text-main: #
|
|
133
|
-
--nonla-text-secondary: #737373;
|
|
134
|
-
--nonla-text-tertiary: #a1a1a1;
|
|
135
|
-
--nonla-text-quaternary: #d4d4d4;
|
|
136
|
-
--nonla-text-on-solid: #ffffff;
|
|
142
|
+
/* Light grays are Tailwind neutral. Page is white. Sidebar and cards are neutral-50. */
|
|
143
|
+
--nonla-bg: #ffffff; /* white */
|
|
144
|
+
--nonla-text-main: #262626; /* neutral-800 */
|
|
145
|
+
--nonla-text-secondary: #737373; /* neutral-500 */
|
|
146
|
+
--nonla-text-tertiary: #a1a1a1; /* neutral-400 */
|
|
147
|
+
--nonla-text-quaternary: #d4d4d4; /* neutral-300 */
|
|
148
|
+
--nonla-text-on-solid: #ffffff; /* white */
|
|
137
149
|
--nonla-brand: #f18d00;
|
|
138
150
|
--nonla-danger: #dc3b3b;
|
|
139
151
|
--nonla-success: #2f7d4a;
|
|
140
|
-
--nonla-warn: #a16207;
|
|
152
|
+
--nonla-warn: #a16207; /* yellow-700 */
|
|
141
153
|
--nonla-link: #3b6d99;
|
|
142
154
|
|
|
143
|
-
--nonla-sidebar: #fafafa;
|
|
144
|
-
--nonla-surface: #
|
|
145
|
-
--nonla-bar: #e5e5e5;
|
|
146
|
-
--nonla-border: #e5e5e5;
|
|
147
|
-
--nonla-border-secondary: #f5f5f5;
|
|
155
|
+
--nonla-sidebar: #fafafa; /* neutral-50 */
|
|
156
|
+
--nonla-surface: #fafafa; /* neutral-50 */
|
|
157
|
+
--nonla-bar: #e5e5e5; /* neutral-200 */
|
|
158
|
+
--nonla-border: #e5e5e5; /* neutral-200 */
|
|
159
|
+
--nonla-border-secondary: #f5f5f5; /* neutral-100 */
|
|
148
160
|
--nonla-input: rgb(0 0 0 / 11%);
|
|
149
161
|
|
|
150
162
|
--mask: rgb(0 0 0 / 40%);
|
|
@@ -211,6 +223,14 @@
|
|
|
211
223
|
--spacing-field-lg: 40px;
|
|
212
224
|
--spacing-field-nav: 32px;
|
|
213
225
|
|
|
226
|
+
--text-sm: var(--nonla-sm-text-size);
|
|
227
|
+
--text-base: var(--nonla-base-text-size);
|
|
228
|
+
--text-base--line-height: 1.6;
|
|
229
|
+
--text-md: var(--nonla-md-text-size);
|
|
230
|
+
--text-md--line-height: calc(1.5 / 1);
|
|
231
|
+
--text-lg: 18px;
|
|
232
|
+
--text-lg--line-height: calc(1.75 / 1.125);
|
|
233
|
+
|
|
214
234
|
--font-sans: var(--nonla-font);
|
|
215
235
|
--font-family-sans: var(--font-sans);
|
|
216
236
|
--default-font-family: var(--font-sans);
|
package/src/tabs/Tabs.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type CSSProperties, type KeyboardEvent, type ReactNode, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { solarIconName } from "../icon/solar";
|
|
1
|
+
import { type CSSProperties, type KeyboardEvent, type MouseEvent as ReactMouseEvent, type ReactNode, type PointerEvent as ReactPointerEvent, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { Icon, isIconName } from "../icon/Icon";
|
|
4
3
|
import { cn } from "../lib/cn";
|
|
5
4
|
|
|
6
5
|
export type TabsItem = {
|
|
@@ -8,7 +7,7 @@ export type TabsItem = {
|
|
|
8
7
|
label: ReactNode;
|
|
9
8
|
children?: ReactNode;
|
|
10
9
|
disabled?: boolean;
|
|
11
|
-
/**
|
|
10
|
+
/** An `Icon` name, or a node. */
|
|
12
11
|
icon?: ReactNode;
|
|
13
12
|
};
|
|
14
13
|
|
|
@@ -26,6 +25,12 @@ export type TabsProps = {
|
|
|
26
25
|
const FADE = 32;
|
|
27
26
|
const EDGE = 64;
|
|
28
27
|
const TAB_HEIGHT = 40;
|
|
28
|
+
/** Mouse wheel multiplier. Raise for faster wheel scrolling. */
|
|
29
|
+
const WHEEL_SPEED = 2;
|
|
30
|
+
/** Pointer travel (px) before a press becomes a drag instead of a click. */
|
|
31
|
+
const DRAG_THRESHOLD = 4;
|
|
32
|
+
|
|
33
|
+
type DragState = { id: number; startX: number; startLeft: number; moved: boolean };
|
|
29
34
|
|
|
30
35
|
type Ink = { left: number; width: number };
|
|
31
36
|
type Overflow = { left: boolean; right: boolean };
|
|
@@ -56,7 +61,8 @@ function scrollToX(el: HTMLElement, target: number) {
|
|
|
56
61
|
|
|
57
62
|
function TabIcon({ icon, size }: { icon?: ReactNode; size: number }) {
|
|
58
63
|
if (icon == null || icon === false) return null;
|
|
59
|
-
if (
|
|
64
|
+
if (isIconName(icon)) return <Icon name={icon} size={size} />;
|
|
65
|
+
if (typeof icon === "string") return null;
|
|
60
66
|
return <span className="inline-flex shrink-0 items-center justify-center">{icon}</span>;
|
|
61
67
|
}
|
|
62
68
|
|
|
@@ -71,7 +77,7 @@ function ScrollButton({ dir, onClick }: { dir: "left" | "right"; onClick: () =>
|
|
|
71
77
|
)}
|
|
72
78
|
onClick={onClick}
|
|
73
79
|
>
|
|
74
|
-
<
|
|
80
|
+
<Icon name={dir === "left" ? "arrow-left" : "arrow-right"} size={16} />
|
|
75
81
|
</button>
|
|
76
82
|
);
|
|
77
83
|
}
|
|
@@ -87,6 +93,8 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
|
|
|
87
93
|
const rowRef = useRef<HTMLDivElement>(null);
|
|
88
94
|
const tabRefs = useRef(new Map<string, HTMLButtonElement>());
|
|
89
95
|
const focusKey = useRef<string | null>(null);
|
|
96
|
+
const drag = useRef<DragState | null>(null);
|
|
97
|
+
const suppressClick = useRef(false);
|
|
90
98
|
|
|
91
99
|
const [ink, setInk] = useState<Ink | null>(null);
|
|
92
100
|
const [overflow, setOverflow] = useState<Overflow>({ left: false, right: false });
|
|
@@ -151,9 +159,10 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
|
|
|
151
159
|
const onWheel = (event: WheelEvent) => {
|
|
152
160
|
if (el.scrollWidth <= el.clientWidth + 1) return;
|
|
153
161
|
if (Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
154
|
-
|
|
162
|
+
const raw = event.deltaY * (event.deltaMode === 1 ? 16 : 1) * WHEEL_SPEED;
|
|
163
|
+
if (raw === 0) return;
|
|
155
164
|
const max = el.scrollWidth - el.clientWidth;
|
|
156
|
-
const next = Math.min(max, Math.max(0, el.scrollLeft +
|
|
165
|
+
const next = Math.min(max, Math.max(0, el.scrollLeft + raw));
|
|
157
166
|
if (next === el.scrollLeft) return;
|
|
158
167
|
el.scrollLeft = next;
|
|
159
168
|
updateOverflow();
|
|
@@ -163,6 +172,49 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
|
|
|
163
172
|
return () => el.removeEventListener("wheel", onWheel);
|
|
164
173
|
}, [itemsKey, updateOverflow]);
|
|
165
174
|
|
|
175
|
+
function onPointerDown(event: ReactPointerEvent<HTMLDivElement>) {
|
|
176
|
+
const el = scrollerRef.current;
|
|
177
|
+
if (!el || el.scrollWidth <= el.clientWidth + 1) return;
|
|
178
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
179
|
+
suppressClick.current = false;
|
|
180
|
+
drag.current = { id: event.pointerId, startX: event.clientX, startLeft: el.scrollLeft, moved: false };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function onPointerMove(event: ReactPointerEvent<HTMLDivElement>) {
|
|
184
|
+
const state = drag.current;
|
|
185
|
+
const el = scrollerRef.current;
|
|
186
|
+
if (!state || !el || event.pointerId !== state.id) return;
|
|
187
|
+
if (event.pointerType === "mouse" && event.buttons === 0) {
|
|
188
|
+
drag.current = null;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const dx = event.clientX - state.startX;
|
|
192
|
+
if (!state.moved) {
|
|
193
|
+
if (Math.abs(dx) < DRAG_THRESHOLD) return;
|
|
194
|
+
state.moved = true;
|
|
195
|
+
el.setPointerCapture(event.pointerId);
|
|
196
|
+
}
|
|
197
|
+
scrollToX(el, state.startLeft - dx);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function endDrag(event: ReactPointerEvent<HTMLDivElement>) {
|
|
201
|
+
const state = drag.current;
|
|
202
|
+
if (!state || event.pointerId !== state.id) return;
|
|
203
|
+
drag.current = null;
|
|
204
|
+
if (!state.moved) return;
|
|
205
|
+
suppressClick.current = true;
|
|
206
|
+
const el = scrollerRef.current;
|
|
207
|
+
if (el?.hasPointerCapture(event.pointerId)) el.releasePointerCapture(event.pointerId);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** A drag that moved should not also activate the tab under the pointer. */
|
|
211
|
+
function onClickCapture(event: ReactMouseEvent<HTMLDivElement>) {
|
|
212
|
+
if (!suppressClick.current) return;
|
|
213
|
+
suppressClick.current = false;
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
}
|
|
217
|
+
|
|
166
218
|
function select(key: string, fromKeyboard = false) {
|
|
167
219
|
if (fromKeyboard) focusKey.current = key;
|
|
168
220
|
if (activeKey === undefined) setInner(key);
|
|
@@ -203,9 +255,19 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
|
|
|
203
255
|
<div aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 h-px bg-border" />
|
|
204
256
|
<div
|
|
205
257
|
ref={scrollerRef}
|
|
206
|
-
className="relative overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0"
|
|
207
|
-
style={
|
|
258
|
+
className="relative overflow-x-auto overflow-y-hidden overscroll-x-contain touch-pan-y select-none [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0"
|
|
259
|
+
style={{
|
|
260
|
+
// Inline on purpose: the unlayered `* { scrollbar-width: thin }` in styles.css beats the layered utility class.
|
|
261
|
+
scrollbarWidth: "none",
|
|
262
|
+
msOverflowStyle: "none",
|
|
263
|
+
...(mask ? { maskImage: mask, WebkitMaskImage: mask } : null),
|
|
264
|
+
}}
|
|
208
265
|
onScroll={updateOverflow}
|
|
266
|
+
onPointerDown={onPointerDown}
|
|
267
|
+
onPointerMove={onPointerMove}
|
|
268
|
+
onPointerUp={endDrag}
|
|
269
|
+
onPointerCancel={endDrag}
|
|
270
|
+
onClickCapture={onClickCapture}
|
|
209
271
|
>
|
|
210
272
|
<div ref={rowRef} role="tablist" aria-label={ariaLabel} aria-orientation="horizontal" className="relative flex w-max gap-3" onKeyDown={onKeyDown}>
|
|
211
273
|
{ink ? <span aria-hidden className="pointer-events-none absolute bottom-0 left-0 z-1 h-0.5 rounded-t-xs bg-brand transition-[transform,width] duration-380 ease-[cubic-bezier(0.3,1.25,0.5,1)] motion-reduce:transition-none" style={{ width: ink.width, transform: `translateX(${ink.left}px)` }} /> : null}
|
|
@@ -226,10 +288,10 @@ export function Tabs({ items, activeKey, defaultActiveKey, onChange, className,
|
|
|
226
288
|
tabIndex={selected ? 0 : -1}
|
|
227
289
|
disabled={item.disabled}
|
|
228
290
|
className={cn(
|
|
229
|
-
"relative z-10 inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 bg-transparent font-normal
|
|
230
|
-
"
|
|
291
|
+
"relative z-10 inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 bg-transparent font-normal transition-colors select-none",
|
|
292
|
+
"focus-visible:ring-brand/55 focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset",
|
|
231
293
|
"disabled:cursor-not-allowed disabled:opacity-40",
|
|
232
|
-
selected
|
|
294
|
+
selected ? "text-brand" : "text-(--nonla-text-main) hover:text-foreground",
|
|
233
295
|
)}
|
|
234
296
|
style={{
|
|
235
297
|
height: TAB_HEIGHT,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useLayoutEffect, useSyncExternalStore } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Icon, type IconName } from "../icon/Icon";
|
|
3
3
|
import { cn } from "../lib/cn";
|
|
4
4
|
import { getColorPreference, initColorMode, type NonlaColorPreference, setColorPreference, subscribeColorPreference } from "../theme";
|
|
5
5
|
|
|
6
|
-
const OPTIONS: { value: NonlaColorPreference; label: string; icon:
|
|
7
|
-
{ value: "system", label: "System", icon: "monitor
|
|
8
|
-
{ value: "light", label: "Light", icon: "sun
|
|
9
|
-
{ value: "dark", label: "Dark", icon: "moon
|
|
6
|
+
const OPTIONS: { value: NonlaColorPreference; label: string; icon: IconName }[] = [
|
|
7
|
+
{ value: "system", label: "System", icon: "monitor" },
|
|
8
|
+
{ value: "light", label: "Light", icon: "sun" },
|
|
9
|
+
{ value: "dark", label: "Dark", icon: "moon" },
|
|
10
10
|
];
|
|
11
11
|
|
|
12
12
|
export function useColorPreference(): NonlaColorPreference {
|
|
@@ -46,7 +46,7 @@ export function ThemeSwitcher({ className }: ThemeSwitcherProps) {
|
|
|
46
46
|
selected ? "bg-ink-active text-foreground" : "hover:bg-ink-hover hover:text-foreground",
|
|
47
47
|
)}
|
|
48
48
|
>
|
|
49
|
-
<
|
|
49
|
+
<Icon name={option.icon} size={12} />
|
|
50
50
|
</button>
|
|
51
51
|
);
|
|
52
52
|
})}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AnchorHTMLAttributes, type CSSProperties, createElement, type HTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
|
-
import { headingClass, markdownBodyClass, markdownParagraphClass,
|
|
3
|
+
import { headingClass, markdownBodyClass, markdownParagraphClass, markdownScaleStyle, pageTitleClass } from "../markdown-editor/markdownScale";
|
|
4
4
|
|
|
5
5
|
export type TypographyType = "secondary" | "success" | "warning" | "danger";
|
|
6
6
|
|
|
@@ -40,10 +40,10 @@ const TITLE_TAG = {
|
|
|
40
40
|
6: "h6",
|
|
41
41
|
} as const;
|
|
42
42
|
|
|
43
|
-
/** Same scale as MarkdownViewer
|
|
43
|
+
/** Same scale as MarkdownViewer. Body size is `text-md`. Inline code reads `--nonla-mono-text-size`. */
|
|
44
44
|
const BODY = markdownBodyClass;
|
|
45
45
|
|
|
46
|
-
const INLINE_CODE = "nonla-inline-code rounded-
|
|
46
|
+
const INLINE_CODE = "nonla-inline-code rounded-[4px] bg-muted px-[2px] py-px align-baseline font-mono text-(length:--md-inline-size,var(--nonla-mono-text-size)) leading-none whitespace-nowrap [box-decoration-break:clone] [-webkit-box-decoration-break:clone]";
|
|
47
47
|
|
|
48
48
|
const TITLE_SPACE = "nonla-typo";
|
|
49
49
|
|
|
@@ -82,7 +82,7 @@ function rankColor(role: InkRole, props: Decorations): string | undefined {
|
|
|
82
82
|
function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"], role: InkRole = "body") {
|
|
83
83
|
const line = decorationLine(props.underline, props.delete);
|
|
84
84
|
const color = rankColor(role, props);
|
|
85
|
-
const scale: CSSProperties = { ...
|
|
85
|
+
const scale: CSSProperties = { ...markdownScaleStyle, ...(color ? { color } : null), ...(line ? { textDecorationLine: line } : null), ...style };
|
|
86
86
|
return {
|
|
87
87
|
className: cn(base, props.disabled && "cursor-not-allowed", props.strong && "font-(--md-strong-weight,600)", props.italic && "italic", props.underline && "underline-offset-[3px]", className),
|
|
88
88
|
style: scale,
|
package/src/icon/SolarIcon.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { cn } from "../lib/cn";
|
|
3
|
-
import { ensureSolarIcons, getSolarSvg } from "./solar";
|
|
4
|
-
|
|
5
|
-
export function SolarIcon({ name, size = 16, className }: { name: string; size?: number; className?: string }) {
|
|
6
|
-
const [svg, setSvg] = useState<string | null>(() => getSolarSvg(name));
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
const cached = getSolarSvg(name);
|
|
10
|
-
if (cached) {
|
|
11
|
-
setSvg(cached);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
let cancelled = false;
|
|
15
|
-
void ensureSolarIcons().then(() => {
|
|
16
|
-
if (!cancelled) setSvg(getSolarSvg(name));
|
|
17
|
-
});
|
|
18
|
-
return () => {
|
|
19
|
-
cancelled = true;
|
|
20
|
-
};
|
|
21
|
-
}, [name]);
|
|
22
|
-
|
|
23
|
-
if (!svg) {
|
|
24
|
-
return <span aria-hidden className={cn("inline-block shrink-0", className)} style={{ width: size, height: size }} />;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<span
|
|
29
|
-
aria-hidden
|
|
30
|
-
className={cn("inline-flex shrink-0 select-none text-current pointer-events-none [&_svg]:size-full", className)}
|
|
31
|
-
style={{ width: size, height: size }}
|
|
32
|
-
// biome-ignore lint/security/noDangerouslySetInnerHtml: Solar SVG comes from the vendored icon pack, keyed by name
|
|
33
|
-
dangerouslySetInnerHTML={{ __html: svg }}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** @deprecated Use SolarIcon. Same component — Solar icons, not Fluent Color. */
|
|
39
|
-
export const FluentIcon = SolarIcon;
|
package/src/icon/solar.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
export const ICON_PREFIX = "solar";
|
|
2
|
-
export const DEFAULT_ICON_STYLE = "linear";
|
|
3
|
-
export const DEFAULT_ICON_NAME = "bot-linear";
|
|
4
|
-
export const DEFAULT_TOOL_ICON = `${ICON_PREFIX}:${DEFAULT_ICON_NAME}`;
|
|
5
|
-
|
|
6
|
-
const STYLE_SUFFIXES = ["bold-duotone", "line-duotone", "linear", "outline", "broken", "bold"] as const;
|
|
7
|
-
|
|
8
|
-
export type SolarIconStyle = (typeof STYLE_SUFFIXES)[number];
|
|
9
|
-
|
|
10
|
-
/** Fluent Color ids that do not share a Solar stem. Values are full Solar icon ids. */
|
|
11
|
-
const LEGACY_NAMES: Record<string, string> = {
|
|
12
|
-
alert: "bell-linear",
|
|
13
|
-
apps: "widget-4-linear",
|
|
14
|
-
"apps-list": "list-linear",
|
|
15
|
-
"apps-list-detail": "sidebar-minimalistic-linear",
|
|
16
|
-
"arrow-square-down": "alt-arrow-down-linear",
|
|
17
|
-
"arrow-sync": "refresh-linear",
|
|
18
|
-
board: "kanban-linear",
|
|
19
|
-
"book-open": "book-2-linear",
|
|
20
|
-
"bot-sparkle": "magic-stick-3-linear",
|
|
21
|
-
"calendar-clock": "calendar-mark-linear",
|
|
22
|
-
chat: "chat-round-linear",
|
|
23
|
-
"chat-bubbles-question": "chat-round-question-mark-linear",
|
|
24
|
-
"chat-more": "chat-round-dots-linear",
|
|
25
|
-
"chat-multiple": "dialog-2-linear",
|
|
26
|
-
checkbox: "check-square-linear",
|
|
27
|
-
clock: "clock-circle-linear",
|
|
28
|
-
"code-block": "code-square-linear",
|
|
29
|
-
comment: "dialog-linear",
|
|
30
|
-
"content-view": "window-frame-linear",
|
|
31
|
-
"data-bar-vertical-ascending": "chart-linear",
|
|
32
|
-
"dismiss-circle": "close-circle-linear",
|
|
33
|
-
drafts: "notes-linear",
|
|
34
|
-
edit: "pen-linear",
|
|
35
|
-
"fast-forward-circle": "round-double-alt-arrow-right-linear",
|
|
36
|
-
form: "clipboard-text-linear",
|
|
37
|
-
"image-off": "gallery-remove-linear",
|
|
38
|
-
"lightbulb-filament": "lightbulb-linear",
|
|
39
|
-
"list-bar": "hamburger-menu-linear",
|
|
40
|
-
"number-symbol-square": "hashtag-square-linear",
|
|
41
|
-
options: "tuning-2-linear",
|
|
42
|
-
"people-community": "users-group-rounded-linear",
|
|
43
|
-
person: "user-rounded-linear",
|
|
44
|
-
"search-sparkle": "magnifer-linear",
|
|
45
|
-
"share-android": "share-linear",
|
|
46
|
-
"share-ios": "square-share-line-linear",
|
|
47
|
-
sparkle: "stars-linear",
|
|
48
|
-
"text-edit-style": "text-field-linear",
|
|
49
|
-
vault: "safe-square-linear",
|
|
50
|
-
"wrench-screwdriver": "toolbox-linear",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type IconifyIcon = { body: string; width?: number; height?: number; left?: number; top?: number };
|
|
54
|
-
type IconifyAlias = { parent: string };
|
|
55
|
-
type IconifyPack = {
|
|
56
|
-
icons?: Record<string, IconifyIcon>;
|
|
57
|
-
aliases?: Record<string, IconifyAlias>;
|
|
58
|
-
width?: number;
|
|
59
|
-
height?: number;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
let pack: IconifyPack | null = null;
|
|
63
|
-
let memoryNames: string[] | null = null;
|
|
64
|
-
const svgByName = new Map<string, string>();
|
|
65
|
-
const imgSrcByName = new Map<string, string>();
|
|
66
|
-
let inflight: Promise<string[]> | null = null;
|
|
67
|
-
|
|
68
|
-
function hasStyle(name: string) {
|
|
69
|
-
return STYLE_SUFFIXES.some((style) => name.endsWith(`-${style}`));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function stripStyle(name: string) {
|
|
73
|
-
for (const style of STYLE_SUFFIXES) {
|
|
74
|
-
const suffix = `-${style}`;
|
|
75
|
-
if (name.endsWith(suffix)) return name.slice(0, -suffix.length);
|
|
76
|
-
}
|
|
77
|
-
return name;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function bareName(value: string) {
|
|
81
|
-
let name = value.trim();
|
|
82
|
-
if (name.startsWith(`${ICON_PREFIX}:`)) name = name.slice(ICON_PREFIX.length + 1);
|
|
83
|
-
if (name.startsWith("fluent-color:")) name = name.slice("fluent-color:".length);
|
|
84
|
-
return name;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Solar icon id. Accepts `solar:…`, a styled id, or a legacy Fluent Color id such as `settings-24`. Pass `style` to force a weight such as `bold-duotone`. */
|
|
88
|
-
export function solarIconName(value: string, style?: SolarIconStyle): string {
|
|
89
|
-
const name = bareName(value);
|
|
90
|
-
const stem = name.replace(/-24$/, "");
|
|
91
|
-
const resolved = hasStyle(name) ? name : (LEGACY_NAMES[stem] ?? LEGACY_NAMES[name] ?? `${stem}-${DEFAULT_ICON_STYLE}`);
|
|
92
|
-
if (!style || resolved.endsWith(`-${style}`)) return resolved;
|
|
93
|
-
return `${stripStyle(resolved)}-${style}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function solarIconRef(name: string): string {
|
|
97
|
-
return `${ICON_PREFIX}:${solarIconName(name)}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function lookup(name: string): IconifyIcon | null {
|
|
101
|
-
if (!pack) return null;
|
|
102
|
-
const seen = new Set<string>();
|
|
103
|
-
let current = name;
|
|
104
|
-
while (current && !seen.has(current)) {
|
|
105
|
-
seen.add(current);
|
|
106
|
-
const icon = pack.icons?.[current];
|
|
107
|
-
if (icon?.body) return icon;
|
|
108
|
-
const parent = pack.aliases?.[current]?.parent;
|
|
109
|
-
if (!parent) return null;
|
|
110
|
-
current = parent;
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function toSvg(icon: IconifyIcon): string {
|
|
116
|
-
const left = icon.left ?? 0;
|
|
117
|
-
const top = icon.top ?? 0;
|
|
118
|
-
const width = icon.width ?? pack?.width ?? 24;
|
|
119
|
-
const height = icon.height ?? pack?.height ?? 24;
|
|
120
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="${left} ${top} ${width} ${height}">${icon.body}</svg>`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Loads the vendored Solar pack (code-split). No network. */
|
|
124
|
-
export function ensureSolarIcons(): Promise<string[]> {
|
|
125
|
-
if (memoryNames) return Promise.resolve(memoryNames);
|
|
126
|
-
if (inflight) return inflight;
|
|
127
|
-
inflight = import("@iconify-json/solar/icons.json")
|
|
128
|
-
.then((mod) => {
|
|
129
|
-
pack = (mod.default ?? mod) as IconifyPack;
|
|
130
|
-
memoryNames = [...Object.keys(pack.icons ?? {}), ...Object.keys(pack.aliases ?? {})];
|
|
131
|
-
return memoryNames;
|
|
132
|
-
})
|
|
133
|
-
.finally(() => {
|
|
134
|
-
inflight = null;
|
|
135
|
-
});
|
|
136
|
-
return inflight;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function getIconNames(): string[] {
|
|
140
|
-
return memoryNames ?? [];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function getSolarSvg(name: string): string | null {
|
|
144
|
-
if (!pack) return null;
|
|
145
|
-
const resolved = solarIconName(name);
|
|
146
|
-
const cached = svgByName.get(resolved);
|
|
147
|
-
if (cached) return cached;
|
|
148
|
-
const icon = lookup(resolved);
|
|
149
|
-
if (!icon) return null;
|
|
150
|
-
const svg = toSvg(icon);
|
|
151
|
-
svgByName.set(resolved, svg);
|
|
152
|
-
return svg;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function getSolarImgSrc(name: string): string | null {
|
|
156
|
-
const resolved = solarIconName(name);
|
|
157
|
-
const hit = imgSrcByName.get(resolved);
|
|
158
|
-
if (hit) return hit;
|
|
159
|
-
const svg = getSolarSvg(name);
|
|
160
|
-
if (!svg) return null;
|
|
161
|
-
const src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
162
|
-
imgSrcByName.set(resolved, src);
|
|
163
|
-
return src;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function isSvgIcon(value?: string | null): boolean {
|
|
167
|
-
return !!value && value.trimStart().startsWith("<svg");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function isSolarIcon(value?: string | null): boolean {
|
|
171
|
-
return !!value && (value.startsWith(`${ICON_PREFIX}:`) || value.startsWith("fluent-color:"));
|
|
172
|
-
}
|