devnonla-ui 0.8.0 → 0.9.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/README.md +31 -4
- package/package.json +3 -3
- package/src/app/App.tsx +5 -1
- package/src/app/context.ts +5 -3
- package/src/button/Button.tsx +2 -2
- package/src/button/ButtonCopy.tsx +2 -2
- package/src/card/Card.tsx +81 -0
- package/src/chat/AgentChatbox.tsx +1 -1
- package/src/chat/AgentPanel.tsx +1 -1
- package/src/chat/message-ui/ChatError.tsx +2 -2
- package/src/chat/message-ui/ChatInput.tsx +5 -5
- package/src/chat/message-ui/ChatMarkdown.tsx +8 -7
- package/src/chat/message-ui/ChatThinking.tsx +3 -3
- package/src/chat/message-ui/ChatUserMessage.tsx +3 -3
- package/src/chat/message-ui/MermaidBlock.tsx +68 -39
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +3 -3
- package/src/chat/tool-ui/CallAgentToolUI.tsx +3 -3
- package/src/chat/tool-ui/ChatToolCall.tsx +4 -4
- package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +2 -2
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +2 -2
- package/src/chat/tool-ui/RunJsToolUI.tsx +2 -2
- package/src/chat/tool-ui/ToolUiTrailing.tsx +3 -3
- package/src/chat/tool-ui/WebFetchToolUI.tsx +2 -2
- package/src/checkbox/Checkbox.tsx +17 -4
- package/src/codeblock/CodeBlock.tsx +2 -2
- package/src/datepicker/DatePicker.tsx +3 -3
- package/src/desktop/DesktopHeader.tsx +1 -1
- package/src/desktop/DesktopIcon.tsx +2 -2
- package/src/desktop/DesktopWindow.tsx +51 -29
- package/src/empty/Empty.tsx +8 -5
- package/src/form/FormItem.tsx +1 -1
- package/src/form-layout/FormLayout.tsx +1 -1
- package/src/icon/SolarIcon.tsx +39 -0
- package/src/icon/solar.ts +172 -0
- package/src/index.ts +24 -12
- package/src/input/EditableInput.tsx +3 -3
- package/src/input/Input.tsx +3 -3
- package/src/lib/sizes.ts +9 -6
- package/src/lib/surface.ts +1 -1
- package/src/markdown-editor/MarkdownDiff.tsx +211 -0
- package/src/markdown-editor/MarkdownEditor.tsx +301 -0
- package/src/markdown-editor/MarkdownPreview.tsx +346 -0
- package/src/markdown-editor/MarkdownSource.tsx +72 -0
- package/src/markdown-editor/blocks.ts +329 -0
- package/src/markdown-editor/diff.ts +296 -0
- package/src/menu/Menu.tsx +3 -3
- package/src/pagination/Pagination.tsx +8 -7
- package/src/segmented/Segmented.tsx +2 -2
- package/src/select/Select.tsx +192 -63
- package/src/sidebar/Sidebar.tsx +9 -8
- package/src/spin/Spin.tsx +17 -11
- package/src/styles.css +265 -110
- package/src/switch/Switch.tsx +17 -3
- package/src/table/Table.tsx +61 -26
- package/src/theme-toggle/ThemeToggle.tsx +33 -0
- package/src/theme.ts +72 -0
- package/src/timepicker/TimePicker.tsx +1 -1
- package/src/icon/FluentIcon.tsx +0 -28
- package/src/icon/fluent.ts +0 -75
package/src/index.ts
CHANGED
|
@@ -17,6 +17,8 @@ export type { AlertProps, AlertType } from "./alert/Alert";
|
|
|
17
17
|
export { Alert } from "./alert/Alert";
|
|
18
18
|
export type { CalendarProps } from "./calendar/Calendar";
|
|
19
19
|
export { Calendar } from "./calendar/Calendar";
|
|
20
|
+
export type { CardFooterProps, CardItemProps, CardProps } from "./card/Card";
|
|
21
|
+
export { Card } from "./card/Card";
|
|
20
22
|
export type {
|
|
21
23
|
AgentChatboxProps,
|
|
22
24
|
AgentHistoryMessage,
|
|
@@ -88,7 +90,7 @@ export {
|
|
|
88
90
|
useAgentStream,
|
|
89
91
|
WebFetchToolUI,
|
|
90
92
|
} from "./chat";
|
|
91
|
-
export type { CheckboxProps } from "./checkbox/Checkbox";
|
|
93
|
+
export type { CheckboxColor, CheckboxProps } from "./checkbox/Checkbox";
|
|
92
94
|
export { Checkbox } from "./checkbox/Checkbox";
|
|
93
95
|
export type { CodeBlockCopyButtonProps, CodeBlockProps } from "./codeblock/CodeBlock";
|
|
94
96
|
export { CodeBlock, CodeBlockCopyButton } from "./codeblock/CodeBlock";
|
|
@@ -137,25 +139,33 @@ export {
|
|
|
137
139
|
export type { FormLayoutItemProps, FormLayoutProps } from "./form-layout/FormLayout";
|
|
138
140
|
/** Layout-only Form + Form.Item for labeled fields. */
|
|
139
141
|
export { Form } from "./form-layout/FormLayout";
|
|
140
|
-
export { FluentIcon } from "./icon/
|
|
142
|
+
export { FluentIcon, SolarIcon } from "./icon/SolarIcon";
|
|
141
143
|
export {
|
|
142
144
|
DEFAULT_ICON_NAME,
|
|
143
145
|
DEFAULT_TOOL_ICON,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
fluentIconRef,
|
|
147
|
-
getFluentImgSrc,
|
|
146
|
+
ensureSolarIcons,
|
|
147
|
+
ensureSolarIcons as ensureFluentIcons,
|
|
148
148
|
getIconNames,
|
|
149
|
+
getSolarImgSrc,
|
|
150
|
+
getSolarImgSrc as getFluentImgSrc,
|
|
151
|
+
getSolarSvg,
|
|
149
152
|
ICON_PREFIX,
|
|
150
|
-
|
|
153
|
+
isSolarIcon,
|
|
154
|
+
isSolarIcon as isFluentIcon,
|
|
151
155
|
isSvgIcon,
|
|
152
|
-
|
|
156
|
+
solarIconName,
|
|
157
|
+
solarIconName as fluentIconName,
|
|
158
|
+
solarIconRef,
|
|
159
|
+
solarIconRef as fluentIconRef,
|
|
160
|
+
} from "./icon/solar";
|
|
153
161
|
export { cn } from "./lib/cn";
|
|
154
162
|
export type { PopperPlacement } from "./lib/placement";
|
|
155
163
|
export { placementToRadix } from "./lib/placement";
|
|
156
164
|
export type { CanonicalSize, ControlSize, ControlSizeTokens } from "./lib/sizes";
|
|
157
165
|
export { CONTROL_SIZES, controlHeightVar, controlRadiusVar, controlStatusClass, getSizeTokens, normalizeSize, useControlSize } from "./lib/sizes";
|
|
158
166
|
export { glassOverlayClass, glassSurfaceClass, meadowSurfaceClass } from "./lib/surface";
|
|
167
|
+
export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
|
|
168
|
+
export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
|
|
159
169
|
export type { MenuItemProps, MenuRootProps, MenuTriggerProps } from "./menu/Menu";
|
|
160
170
|
export { Menu, MenuAction, MenuDivider, MenuItem, MenuTrigger } from "./menu/Menu";
|
|
161
171
|
export type { MessageConfig, MessageType } from "./message/message";
|
|
@@ -180,11 +190,11 @@ export type { SidebarItemType, SidebarProps, SidebarSelectInfo } from "./sidebar
|
|
|
180
190
|
export { Sidebar } from "./sidebar/Sidebar";
|
|
181
191
|
export type { SkeletonProps } from "./skeleton/Skeleton";
|
|
182
192
|
export { Skeleton } from "./skeleton/Skeleton";
|
|
183
|
-
export type { SpinProps, SpinVariant } from "./spin/Spin";
|
|
193
|
+
export type { SpinColor, SpinProps, SpinVariant } from "./spin/Spin";
|
|
184
194
|
export { Spin } from "./spin/Spin";
|
|
185
195
|
export type { SplitterOrientation, SplitterPanelProps, SplitterProps, SplitterSemanticSlot, SplitterSize } from "./splitter/Splitter";
|
|
186
196
|
export { Splitter, SplitterPanel } from "./splitter/Splitter";
|
|
187
|
-
export type { SwitchProps, SwitchVariant } from "./switch/Switch";
|
|
197
|
+
export type { SwitchColor, SwitchProps, SwitchVariant } from "./switch/Switch";
|
|
188
198
|
export { Switch } from "./switch/Switch";
|
|
189
199
|
export type {
|
|
190
200
|
ColumnsType,
|
|
@@ -197,8 +207,10 @@ export type {
|
|
|
197
207
|
export { Table } from "./table/Table";
|
|
198
208
|
export type { TagProps, TagVariant } from "./tag/Tag";
|
|
199
209
|
export { Tag } from "./tag/Tag";
|
|
200
|
-
export type { NonlaThemeColorName, NonlaThemeColors, NonlaThemeConfig, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
|
|
201
|
-
export { applyNonlaTheme, getDesignToken, NONLA_THEME_KEYS, NONLA_THEME_KNOBS } from "./theme";
|
|
210
|
+
export type { NonlaColorMode, NonlaThemeColorName, NonlaThemeColors, NonlaThemeConfig, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
|
|
211
|
+
export { applyNonlaTheme, getColorMode, getDesignToken, initColorMode, NONLA_COLOR_MODE_KEY, NONLA_THEME_KEYS, NONLA_THEME_KNOBS, setColorMode } from "./theme";
|
|
212
|
+
export type { ThemeToggleProps } from "./theme-toggle/ThemeToggle";
|
|
213
|
+
export { ThemeToggle, useColorMode } from "./theme-toggle/ThemeToggle";
|
|
202
214
|
export type { TimePickerProps, TimeValue } from "./timepicker/TimePicker";
|
|
203
215
|
export { TimePicker } from "./timepicker/TimePicker";
|
|
204
216
|
export type { TooltipPlacement, TooltipProps } from "./tooltip/Tooltip";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Pencil } from "lucide-react";
|
|
2
1
|
import { type CSSProperties, cloneElement, isValidElement, type KeyboardEvent, type ReactElement, type ReactNode, type Ref, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
2
|
import { createPortal } from "react-dom";
|
|
4
3
|
import { usePopupContainer } from "../app/context";
|
|
5
4
|
import { Button } from "../button/Button";
|
|
5
|
+
import { SolarIcon } from "../icon/SolarIcon";
|
|
6
6
|
import { cn } from "../lib/cn";
|
|
7
7
|
import { type CanonicalSize, type ControlSize, controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
|
|
8
8
|
import { message } from "../message/message";
|
|
@@ -12,7 +12,7 @@ const FIELD_INSET: Record<CanonicalSize, string> = { small: "-4px", default: "-6
|
|
|
12
12
|
const MULTILINE_MIN: Record<CanonicalSize, number> = { small: 56, default: 72, large: 96 };
|
|
13
13
|
const GLASS_BORDER = 1;
|
|
14
14
|
|
|
15
|
-
const fieldClass = (saving: boolean) => cn("relative z-1 m-0 w-full border-0 bg-transparent text-foreground placeholder:text-
|
|
15
|
+
const fieldClass = (saving: boolean) => cn("relative z-1 m-0 w-full border-0 bg-transparent text-foreground placeholder:text-placeholder focus:outline-none", saving && "opacity-60");
|
|
16
16
|
|
|
17
17
|
type Lock = {
|
|
18
18
|
top: number;
|
|
@@ -227,7 +227,7 @@ function EditButton({ label, size, onClick }: { label: string; size: CanonicalSi
|
|
|
227
227
|
className="inline-flex shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 transition-opacity hover:bg-muted hover:text-foreground group-hover/edit:opacity-100 focus-visible:opacity-100"
|
|
228
228
|
style={{ width: box, height: box }}
|
|
229
229
|
>
|
|
230
|
-
<
|
|
230
|
+
<SolarIcon name="pen-linear" size={tok.icon} />
|
|
231
231
|
</button>
|
|
232
232
|
);
|
|
233
233
|
}
|
package/src/input/Input.tsx
CHANGED
|
@@ -15,10 +15,10 @@ export type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "p
|
|
|
15
15
|
onPressEnter?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const fieldBase = cn("w-full", controlFieldSurface, "placeholder:text-
|
|
18
|
+
const fieldBase = cn("w-full", controlFieldSurface, "placeholder:text-placeholder focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45", controlFieldFocusBorder);
|
|
19
19
|
|
|
20
20
|
function variantClass(variant: InputProps["variant"]) {
|
|
21
|
-
if (variant === "borderless") return "border-transparent bg-transparent hover:bg-transparent shadow-none focus:border-transparent";
|
|
21
|
+
if (variant === "borderless") return "border-transparent bg-transparent hover:bg-transparent shadow-none focus:border-transparent focus:bg-transparent focus-within:bg-transparent";
|
|
22
22
|
if (variant === "filled") return "border-transparent bg-muted focus:border-transparent focus:bg-[var(--control-bg-hover)]";
|
|
23
23
|
return "";
|
|
24
24
|
}
|
|
@@ -275,7 +275,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
|
|
|
275
275
|
}}
|
|
276
276
|
onKeyDown={handleKeyDown}
|
|
277
277
|
className={cn(
|
|
278
|
-
"min-w-0 flex-1 border-0 bg-transparent text-foreground placeholder:text-
|
|
278
|
+
"min-w-0 flex-1 border-0 bg-transparent text-foreground placeholder:text-placeholder outline-none",
|
|
279
279
|
"disabled:cursor-not-allowed",
|
|
280
280
|
// Kill native number chrome if type ever switches
|
|
281
281
|
"[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
package/src/lib/sizes.ts
CHANGED
|
@@ -94,14 +94,17 @@ export function controlStatusClass(status?: "error" | "warning"): string {
|
|
|
94
94
|
export const controlFieldTransition = "transition-[background-color,border-color] duration-[var(--nonla-dur-fast,150ms)] ease-[var(--nonla-ease-out,cubic-bezier(0.16,1,0.3,1))] motion-reduce:transition-none";
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
* Outlined field.
|
|
98
|
-
*
|
|
97
|
+
* Outlined field. Resting stroke is `--input` (Cursor `--border-secondary`, ink at 12%).
|
|
98
|
+
* Fill stays transparent so the stroke sits on the card, same as the settings inputs.
|
|
99
99
|
*/
|
|
100
|
-
export const controlFieldSurface =
|
|
101
|
-
"border border-solid border-input bg-glass-bar text-foreground shadow-[inset_0_1px_0_var(--glass-highlight)] backdrop-blur-xl";
|
|
100
|
+
export const controlFieldSurface = "border border-solid border-input bg-transparent text-foreground";
|
|
102
101
|
|
|
103
|
-
/**
|
|
104
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Focus fill is Cursor `--bg-tertiary` (ink at 8%).
|
|
104
|
+
* Keyboard focus / open menu also strengthens the stroke to `--border-primary` (ink at 20%).
|
|
105
|
+
*/
|
|
106
|
+
export const controlFieldFocusBorder =
|
|
107
|
+
"focus:bg-input-fill focus-within:bg-input-fill data-[state=open]:bg-input-fill aria-expanded:bg-input-fill focus-visible:border-input-focus has-[:focus-visible]:border-input-focus data-[state=open]:border-input-focus aria-expanded:border-input-focus";
|
|
105
108
|
|
|
106
109
|
/** Shared field chrome (Input / Select / DatePicker). */
|
|
107
110
|
export function controlFieldStyle(size: ControlSize | undefined): CSSProperties {
|
package/src/lib/surface.ts
CHANGED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { type ReactNode, useState } from "react";
|
|
2
|
+
import { cn } from "../lib/cn";
|
|
3
|
+
import { OverlayScroll } from "../scroll/OverlayScroll";
|
|
4
|
+
import { type DiffLine, type FoldItem, foldContext, type MarkdownDiffModel } from "./diff";
|
|
5
|
+
|
|
6
|
+
export type MarkdownDiffLayout = "inline" | "side-by-side";
|
|
7
|
+
|
|
8
|
+
function rowBg(kind: DiffLine["kind"]): string {
|
|
9
|
+
if (kind === "insert") return "bg-[color-mix(in_oklab,var(--success)_16%,var(--card))]";
|
|
10
|
+
if (kind === "delete") return "bg-[color-mix(in_oklab,var(--destructive)_14%,var(--card))]";
|
|
11
|
+
if (kind === "empty") return "bg-secondary/45";
|
|
12
|
+
return "bg-card";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function charBg(kind: DiffLine["kind"]): string {
|
|
16
|
+
if (kind === "insert") return "bg-[color-mix(in_oklab,var(--success)_42%,var(--card))]";
|
|
17
|
+
if (kind === "delete") return "bg-[color-mix(in_oklab,var(--destructive)_36%,var(--card))]";
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function marker(kind: DiffLine["kind"]): string {
|
|
22
|
+
if (kind === "insert") return "+";
|
|
23
|
+
if (kind === "delete") return "−";
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function DiffText({ line }: { line: DiffLine }) {
|
|
28
|
+
if (line.kind === "empty" || line.spans.length === 0) return <span className="inline-block min-h-5">{"\u00a0"}</span>;
|
|
29
|
+
const parts: { key: string; text: string; changed: boolean }[] = [];
|
|
30
|
+
let offset = 0;
|
|
31
|
+
for (const span of line.spans) {
|
|
32
|
+
parts.push({ key: `${offset}:${span.changed ? "c" : "s"}`, text: span.text, changed: span.changed });
|
|
33
|
+
offset += span.text.length + 1;
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{parts.map((part) => (
|
|
38
|
+
<span key={part.key} className={cn(part.changed && "rounded-xs", part.changed && charBg(line.kind))}>
|
|
39
|
+
{part.text}
|
|
40
|
+
</span>
|
|
41
|
+
))}
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function Gutter({ value, className }: { value?: number; className?: string }) {
|
|
47
|
+
return <span className={cn("w-10 shrink-0 select-none pr-2 text-right font-mono text-[11px] leading-5 text-quaternary-foreground tabular-nums", className)}>{value ?? ""}</span>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Mark({ kind }: { kind: DiffLine["kind"] }) {
|
|
51
|
+
return (
|
|
52
|
+
<span aria-hidden className={cn("w-4 shrink-0 text-center font-mono text-[13px] leading-5", kind === "insert" && "text-success", kind === "delete" && "text-destructive")}>
|
|
53
|
+
{marker(kind)}
|
|
54
|
+
</span>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function LineBody({ line }: { line: DiffLine }) {
|
|
59
|
+
return (
|
|
60
|
+
<span className="min-h-5 whitespace-pre pr-4 font-mono text-[13px] leading-5">
|
|
61
|
+
<DiffText line={line} />
|
|
62
|
+
</span>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function FoldButton({ count, onClick, span }: { count: number; onClick: () => void; span?: boolean }) {
|
|
67
|
+
return (
|
|
68
|
+
<button type="button" className={cn("flex w-full items-center justify-center border-y border-border bg-secondary/70 py-0.5 text-xs text-link hover:bg-secondary", span && "col-span-2")} onClick={onClick}>
|
|
69
|
+
Show {count} unchanged {count === 1 ? "line" : "lines"}
|
|
70
|
+
</button>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function useFolds(): [Set<number>, (id: number) => void] {
|
|
75
|
+
const [open, setOpen] = useState<Set<number>>(() => new Set());
|
|
76
|
+
const toggle = (id: number) => {
|
|
77
|
+
setOpen((current) => {
|
|
78
|
+
const next = new Set(current);
|
|
79
|
+
if (next.has(id)) next.delete(id);
|
|
80
|
+
else next.add(id);
|
|
81
|
+
return next;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
return [open, toggle];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function visibleNodes<T>(entries: FoldItem<T>[], open: Set<number>, toggle: (id: number) => void, span: boolean, renderItem: (item: T, key: string) => ReactNode): ReactNode[] {
|
|
88
|
+
const nodes: ReactNode[] = [];
|
|
89
|
+
entries.forEach((entry, index) => {
|
|
90
|
+
if (entry.type === "fold" && !open.has(entry.id)) {
|
|
91
|
+
nodes.push(<FoldButton key={`fold-${entry.id}`} count={entry.count} span={span} onClick={() => toggle(entry.id)} />);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const items = entry.type === "fold" ? entry.items : [entry.item];
|
|
95
|
+
items.forEach((item, itemIndex) => {
|
|
96
|
+
nodes.push(renderItem(item, `${index}-${itemIndex}`));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return nodes;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function SideCell({ line, num }: { line: DiffLine; num?: number }) {
|
|
103
|
+
return (
|
|
104
|
+
<div className="flex min-h-5 min-w-max">
|
|
105
|
+
<Gutter value={num} />
|
|
106
|
+
<Mark kind={line.kind} />
|
|
107
|
+
<LineBody line={line} />
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function InlineLine({ line }: { line: DiffLine }) {
|
|
113
|
+
const bg = rowBg(line.kind);
|
|
114
|
+
return (
|
|
115
|
+
<div className={cn("flex min-h-5 min-w-full w-max", bg)}>
|
|
116
|
+
<Gutter value={line.kind === "insert" ? undefined : line.oldNo} className={cn("sticky left-0 z-10", bg)} />
|
|
117
|
+
<Gutter value={line.kind === "delete" ? undefined : line.newNo} className={cn("sticky left-10 z-10", bg)} />
|
|
118
|
+
<Mark kind={line.kind} />
|
|
119
|
+
<LineBody line={line} />
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type MarkdownDiffProps = {
|
|
125
|
+
model: MarkdownDiffModel;
|
|
126
|
+
layout: MarkdownDiffLayout;
|
|
127
|
+
originalLabel?: ReactNode;
|
|
128
|
+
modifiedLabel?: ReactNode;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function MarkdownDiff({ model, layout, originalLabel = "Original", modifiedLabel = "Modified" }: MarkdownDiffProps) {
|
|
132
|
+
const [openSplit, toggleSplit] = useFolds();
|
|
133
|
+
const [openInline, toggleInline] = useFolds();
|
|
134
|
+
|
|
135
|
+
if (layout === "inline") {
|
|
136
|
+
const folded = foldContext(model.inline, (line) => line.kind === "equal");
|
|
137
|
+
return (
|
|
138
|
+
<OverlayScroll className="h-full bg-card" innerClassName="overflow-x-auto">
|
|
139
|
+
<div role="region" aria-label="Markdown diff" className="min-w-full">
|
|
140
|
+
<div className="sticky top-0 z-20 border-b border-border bg-card px-3 py-1.5 text-xs font-medium text-muted-foreground">
|
|
141
|
+
{originalLabel}
|
|
142
|
+
<span className="px-1.5 text-quaternary-foreground">→</span>
|
|
143
|
+
{modifiedLabel}
|
|
144
|
+
</div>
|
|
145
|
+
{visibleNodes(folded, openInline, toggleInline, false, (line, key) => (
|
|
146
|
+
<InlineLine key={`${key}-${line.kind}-${line.oldNo ?? "x"}-${line.newNo ?? "x"}`} line={line} />
|
|
147
|
+
))}
|
|
148
|
+
</div>
|
|
149
|
+
</OverlayScroll>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return <SplitDiff model={model} open={openSplit} toggle={toggleSplit} originalLabel={originalLabel} modifiedLabel={modifiedLabel} />;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function SplitDiff({ model, open, toggle, originalLabel, modifiedLabel }: { model: MarkdownDiffModel; open: Set<number>; toggle: (id: number) => void; originalLabel: ReactNode; modifiedLabel: ReactNode }) {
|
|
157
|
+
const folded = foldContext(model.rows, (row) => row.left.kind === "equal" && row.right.kind === "equal");
|
|
158
|
+
const chunks: ReactNode[] = [];
|
|
159
|
+
let left: ReactNode[] = [];
|
|
160
|
+
let right: ReactNode[] = [];
|
|
161
|
+
let segment = 0;
|
|
162
|
+
|
|
163
|
+
const flush = () => {
|
|
164
|
+
if (left.length === 0) return;
|
|
165
|
+
const id = segment;
|
|
166
|
+
segment += 1;
|
|
167
|
+
chunks.push(
|
|
168
|
+
<div key={`seg-${id}`} className="flex w-full items-start">
|
|
169
|
+
<div className="nonla-scroll-hover w-1/2 min-w-0 overflow-x-auto">{left}</div>
|
|
170
|
+
<div className="nonla-scroll-hover w-1/2 min-w-0 overflow-x-auto border-l border-border">{right}</div>
|
|
171
|
+
</div>,
|
|
172
|
+
);
|
|
173
|
+
left = [];
|
|
174
|
+
right = [];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
folded.forEach((entry, index) => {
|
|
178
|
+
if (entry.type === "fold" && !open.has(entry.id)) {
|
|
179
|
+
flush();
|
|
180
|
+
chunks.push(<FoldButton key={`fold-${entry.id}`} count={entry.count} onClick={() => toggle(entry.id)} />);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const rows = entry.type === "fold" ? entry.items : [entry.item];
|
|
184
|
+
rows.forEach((row, rowIndex) => {
|
|
185
|
+
const key = `${index}-${rowIndex}-${row.left.oldNo ?? "x"}-${row.right.newNo ?? "x"}`;
|
|
186
|
+
left.push(
|
|
187
|
+
<div key={key} className={cn("flex min-h-5 w-max min-w-full", rowBg(row.left.kind))}>
|
|
188
|
+
<SideCell line={row.left} num={row.left.oldNo} />
|
|
189
|
+
</div>,
|
|
190
|
+
);
|
|
191
|
+
right.push(
|
|
192
|
+
<div key={key} className={cn("flex min-h-5 w-max min-w-full", rowBg(row.right.kind))}>
|
|
193
|
+
<SideCell line={row.right} num={row.right.newNo} />
|
|
194
|
+
</div>,
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
flush();
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<OverlayScroll className="h-full bg-card">
|
|
202
|
+
<div role="region" aria-label="Markdown diff" className="min-w-full">
|
|
203
|
+
<div className="sticky top-0 z-20 grid grid-cols-2 border-b border-border bg-card text-xs font-medium text-muted-foreground">
|
|
204
|
+
<div className="px-3 py-1.5">{originalLabel}</div>
|
|
205
|
+
<div className="border-l border-border px-3 py-1.5">{modifiedLabel}</div>
|
|
206
|
+
</div>
|
|
207
|
+
{chunks}
|
|
208
|
+
</div>
|
|
209
|
+
</OverlayScroll>
|
|
210
|
+
);
|
|
211
|
+
}
|