@alexgorbatchev/shadcn 0.0.143 → 0.0.145
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 +3 -0
- package/dist/{chunk-73s0vkbs.js → chunk-31kppqkn.js} +1 -1
- package/dist/{chunk-8nqv0a1g.js → chunk-bpdseydf.js} +1 -1
- package/dist/chunk-e4t5njn9.js +23 -0
- package/dist/{chunk-xw5992sc.js → chunk-ghkzxhp0.js} +1 -1
- package/dist/{chunk-7v8ry91s.js → chunk-gq28gd3g.js} +1 -1
- package/dist/{chunk-b59tzvnw.js → chunk-tskx0wgf.js} +10 -110
- package/dist/chunk-txwykmer.js +106 -0
- package/dist/components/assistant-ui/elements/DiffViewer.js +7 -6
- package/dist/components/assistant-ui/elements/DiffViewerHeader.js +2 -2
- package/dist/components/assistant-ui/elements/DiffViewerLine.js +2 -2
- package/dist/components/assistant-ui/elements/DiffViewerSplitLine.js +2 -2
- package/dist/components/assistant-ui/elements/OptionList.js +1 -1
- package/dist/components/assistant-ui/elements/PermissionGrant.js +1 -1
- package/dist/components/assistant-ui/elements/QuestionFlow.js +2 -2
- package/dist/components/assistant-ui/elements/RecommendationCard.js +1 -1
- package/dist/components/assistant-ui/index.js +13 -11
- package/dist/components/assistant-ui/native/ContextDisplay.js +2 -2
- package/dist/components/assistant-ui/native/index.js +1 -1
- package/dist/components/image-viewer/index.js +18 -37
- package/dist/components/json-render/index.js +1 -1
- package/dist/components/text-diff/TextDiff.d.ts +25 -0
- package/dist/components/text-diff/groupDiffLines.d.ts +8 -0
- package/dist/components/text-diff/index.d.ts +3 -0
- package/dist/components/text-diff/index.js +178 -0
- package/dist/components/text-diff/types.d.ts +12 -0
- package/dist/components/virtual-data-grid/index.js +45 -9
- package/dist/index.js +8 -8
- package/dist/prototype.js +5 -1
- package/llms/components/data-display/TextDiff.md +89 -0
- package/llms/setup.md +3 -0
- package/llms.txt +1 -0
- package/package.json +5 -1
- /package/dist/{chunk-dv22y7z5.js → chunk-6r4457jk.js} +0 -0
- /package/dist/{chunk-2hp4tbrt.js → chunk-d9we0wej.js} +0 -0
- /package/dist/{chunk-x3gz994f.js → chunk-gyp2em1e.js} +0 -0
- /package/dist/{chunk-r06e11p9.js → chunk-pjph8zne.js} +0 -0
- /package/dist/{chunk-8gtsqm4v.js → chunk-qfbf1a5a.js} +0 -0
- /package/dist/{chunk-cmg54svw.js → chunk-wq1prnfw.js} +0 -0
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ Import shared controls and providers from `@alexgorbatchev/shadcn`. Import the f
|
|
|
72
72
|
| `/color-picker` | ColorPicker | `bun add react-colorful@^5.8.1` |
|
|
73
73
|
| `/image-crop` | ImageCrop and native export helpers | `bun add react-image-crop@^11.1.2` |
|
|
74
74
|
| `/image-viewer` | ImageViewer, ImageZoomToggle, ImageComparison, and image helpers | Existing core peers |
|
|
75
|
+
| `/text-diff` | TextDiff: two versions of a text as a line diff | `bun add diff@9.0.0 parse-diff@0.12.0` |
|
|
75
76
|
| `/tree` | Tree, native hooks and features | `bun add @headless-tree/core@^1.8.0 @headless-tree/react@^1.8.0`; patched runtimes are bundled |
|
|
76
77
|
| `/editor` | RichTextEditor, native Tiptap hooks and StarterKit | `bun add @tiptap/core@^3.32.0 @tiptap/react@^3.32.0 @tiptap/pm@^3.32.0 @tiptap/starter-kit@^3.32.0` |
|
|
77
78
|
| `/event-calendar` | EventCalendar, EventForm and native calendar APIs | `bun add date-fns@^4.4.0`; TypeScript: `bun add -d @types/react-big-calendar@^1.16.3` |
|
|
@@ -547,6 +548,8 @@ function Screenshot({ src, onPick }: { src: string; onPick: (point: INormalizedI
|
|
|
547
548
|
|
|
548
549
|
"Highlight differences" draws both images at the after image's natural size and compares premultiplied channels against a threshold. Changed pixels are aggregated into 16px cells and connected regions, outlined with the warning token over the after image (toggle and swipe) or both panes (side-by-side), and summarized as "3 changed regions" or "No visible differences". The comparison runs in time-boxed slices that yield to the browser and is cached per image pair for the component's lifetime. When pixels cannot be read, such as a cross-origin image served without CORS or an image that failed to decode, the switch is disabled and the reason is shown. Pass `crossOrigin: "anonymous"` only when the image server sends CORS headers. `computeImageDiff(before, after, options)` exposes the same pure comparison for equally sized `ImageData`.
|
|
549
550
|
|
|
551
|
+
`TextDiff` (`@alexgorbatchev/shadcn/text-diff`) shows two versions of a text, `before` and `after`, as a line diff labelled by `beforeLabel` and `afterLabel` (default "Before" and "After"). Removed lines carry "-" and added lines "+" in a sign gutter as well as colour, and use `del` and `ins`; long lines wrap, so the diff never scrolls sideways. Unchanged runs further than `contextLines` (default 3) from a change fold behind a "Show N unchanged lines" button that toggles them with `aria-expanded`. `viewMode` is `"auto"` (default), `"unified"`, or `"split"`; auto shows the versions side by side once the diff's own width reaches `splitMinWidth` (default 560 px) and stacked below it, and stacked before the first measurement. A missing final newline is not shown as a change. `showLineNumbers` defaults to true.
|
|
552
|
+
|
|
550
553
|
The toolbar holds the mode, orientation (enabled for side-by-side), zoom, hold-to-show-before (enabled for toggle), and highlight controls with the legend and status. It sits beside a comparison at least 48rem wide and wraps below narrower ones; `showToolbar={false}` hides it, leaving consumers to control the props themselves.
|
|
551
554
|
|
|
552
555
|
# Drag and drop
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-vxvaaptq.js";
|
|
7
7
|
import {
|
|
8
8
|
OptionList2
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-pjph8zne.js";
|
|
10
10
|
|
|
11
11
|
// src/components/assistant-ui/elements/QuestionFlow.tsx
|
|
12
12
|
import { useCallback, useId, useLayoutEffect, useRef, useState } from "react";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/components/image-viewer/hooks/useElementSize.ts
|
|
2
|
+
import { useIsoLayoutEffect } from "@base-ui/utils/useIsoLayoutEffect";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
function useElementSize(ref) {
|
|
5
|
+
const [size, setSize] = useState();
|
|
6
|
+
useIsoLayoutEffect(() => {
|
|
7
|
+
const element = ref.current;
|
|
8
|
+
if (!element)
|
|
9
|
+
return;
|
|
10
|
+
const measure = () => {
|
|
11
|
+
const width = element.clientWidth;
|
|
12
|
+
const height = element.clientHeight;
|
|
13
|
+
setSize((current) => current?.width === width && current.height === height ? current : { width, height });
|
|
14
|
+
};
|
|
15
|
+
measure();
|
|
16
|
+
const observer = new ResizeObserver(measure);
|
|
17
|
+
observer.observe(element);
|
|
18
|
+
return () => observer.disconnect();
|
|
19
|
+
}, [ref]);
|
|
20
|
+
return size;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { useElementSize };
|
|
@@ -45,7 +45,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
45
45
|
function DiffViewerText({ line, className, ...props }) {
|
|
46
46
|
return /* @__PURE__ */ jsx("code", {
|
|
47
47
|
"data-testid": "DiffViewerText",
|
|
48
|
-
className: cn2("min-w-0 flex-1 pe-3.5
|
|
48
|
+
className: cn2("min-w-0 flex-1 pe-3.5 wrap-anywhere whitespace-pre-wrap", className),
|
|
49
49
|
...props,
|
|
50
50
|
children: line?.type === "add" ? /* @__PURE__ */ jsx("ins", {
|
|
51
51
|
className: "no-underline",
|
|
@@ -3,7 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-en44w1pn.js";
|
|
4
4
|
import {
|
|
5
5
|
diffViewerVariants2
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ghkzxhp0.js";
|
|
7
|
+
import {
|
|
8
|
+
parsePatch2,
|
|
9
|
+
computeDiff2,
|
|
10
|
+
pairLinesForSplit
|
|
11
|
+
} from "./chunk-txwykmer.js";
|
|
7
12
|
import {
|
|
8
13
|
Button2
|
|
9
14
|
} from "./chunk-2sx8m8b2.js";
|
|
@@ -15,13 +20,13 @@ import {
|
|
|
15
20
|
} from "./chunk-r0g0gwv6.js";
|
|
16
21
|
import {
|
|
17
22
|
DiffViewerHeader2
|
|
18
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-6r4457jk.js";
|
|
19
24
|
import {
|
|
20
25
|
DiffViewerLine2
|
|
21
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-gq28gd3g.js";
|
|
22
27
|
import {
|
|
23
28
|
DiffViewerSplitLine2
|
|
24
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-31kppqkn.js";
|
|
25
30
|
import {
|
|
26
31
|
Empty2,
|
|
27
32
|
EmptyTitle2
|
|
@@ -30,111 +35,6 @@ import {
|
|
|
30
35
|
// src/components/assistant-ui/elements/DiffViewer.tsx
|
|
31
36
|
import { useMemo } from "react";
|
|
32
37
|
|
|
33
|
-
// src/components/assistant-ui/utils/diffViewer/parsePatch.ts
|
|
34
|
-
import parseDiff from "parse-diff";
|
|
35
|
-
function parsePatch2(patch) {
|
|
36
|
-
const files = parseDiff(patch);
|
|
37
|
-
return files.map((file) => {
|
|
38
|
-
const hunks = file.chunks.map((chunk) => {
|
|
39
|
-
const lines = [];
|
|
40
|
-
for (const change of chunk.changes) {
|
|
41
|
-
if (change.content.startsWith("\\")) {
|
|
42
|
-
lines.push({ type: "marker", content: change.content });
|
|
43
|
-
} else if (change.type === "add") {
|
|
44
|
-
lines.push({
|
|
45
|
-
type: "add",
|
|
46
|
-
content: change.content.slice(1),
|
|
47
|
-
newLineNumber: change.ln
|
|
48
|
-
});
|
|
49
|
-
} else if (change.type === "del") {
|
|
50
|
-
lines.push({
|
|
51
|
-
type: "del",
|
|
52
|
-
content: change.content.slice(1),
|
|
53
|
-
oldLineNumber: change.ln
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
lines.push({
|
|
57
|
-
type: "normal",
|
|
58
|
-
content: change.content.slice(1),
|
|
59
|
-
oldLineNumber: change.ln1,
|
|
60
|
-
newLineNumber: change.ln2
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return { header: chunk.content, lines };
|
|
65
|
-
});
|
|
66
|
-
const lines = hunks.flatMap((hunk) => hunk.lines);
|
|
67
|
-
let additions = 0;
|
|
68
|
-
let deletions = 0;
|
|
69
|
-
for (const line of lines) {
|
|
70
|
-
if (line.type === "add")
|
|
71
|
-
additions++;
|
|
72
|
-
if (line.type === "del")
|
|
73
|
-
deletions++;
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
oldName: file.from,
|
|
77
|
-
newName: file.to,
|
|
78
|
-
lines,
|
|
79
|
-
hunks,
|
|
80
|
-
additions,
|
|
81
|
-
deletions
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/components/assistant-ui/utils/diffViewer/computeDiff.ts
|
|
87
|
-
import { createTwoFilesPatch } from "diff";
|
|
88
|
-
function computeDiff2(oldContent, newContent) {
|
|
89
|
-
if (oldContent !== newContent) {
|
|
90
|
-
const file = parsePatch2(createTwoFilesPatch("file", "file", oldContent, newContent, undefined, undefined, { context: Infinity }))[0];
|
|
91
|
-
if (!file)
|
|
92
|
-
throw new Error("The native diff generator did not produce a parseable unified patch");
|
|
93
|
-
return { lines: file.lines, hunks: file.hunks, additions: file.additions, deletions: file.deletions };
|
|
94
|
-
}
|
|
95
|
-
const lines = oldContent.length === 0 ? [] : oldContent.replace(/\n$/u, "").split(`
|
|
96
|
-
`).map((content, index) => ({ type: "normal", content, oldLineNumber: index + 1, newLineNumber: index + 1 }));
|
|
97
|
-
const start = lines.length === 0 ? 0 : 1;
|
|
98
|
-
return {
|
|
99
|
-
lines,
|
|
100
|
-
hunks: [{ header: "@@ -" + start + "," + lines.length + " +" + start + "," + lines.length + " @@", lines }],
|
|
101
|
-
additions: 0,
|
|
102
|
-
deletions: 0
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/components/assistant-ui/utils/diffViewer/pairLinesForSplit.ts
|
|
107
|
-
function pairLinesForSplit(lines) {
|
|
108
|
-
const pairs = [];
|
|
109
|
-
let index = 0;
|
|
110
|
-
const takeBlock = (kind) => {
|
|
111
|
-
const block = [];
|
|
112
|
-
while (index < lines.length) {
|
|
113
|
-
const next = lines[index];
|
|
114
|
-
if (!next || next.type !== kind && next.type !== "marker")
|
|
115
|
-
break;
|
|
116
|
-
block.push(next);
|
|
117
|
-
index += 1;
|
|
118
|
-
}
|
|
119
|
-
return block;
|
|
120
|
-
};
|
|
121
|
-
while (index < lines.length) {
|
|
122
|
-
const line = lines[index];
|
|
123
|
-
if (!line)
|
|
124
|
-
break;
|
|
125
|
-
if (line.type === "normal" || line.type === "marker") {
|
|
126
|
-
pairs.push({ left: line, right: line });
|
|
127
|
-
index += 1;
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const deletions = takeBlock("del");
|
|
131
|
-
const additions = takeBlock("add");
|
|
132
|
-
for (let pairIndex = 0;pairIndex < Math.max(deletions.length, additions.length); pairIndex += 1)
|
|
133
|
-
pairs.push({ left: deletions[pairIndex] ?? null, right: additions[pairIndex] ?? null });
|
|
134
|
-
}
|
|
135
|
-
return pairs;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
38
|
// src/components/assistant-ui/elements/DiffViewerFileContent.tsx
|
|
139
39
|
import { useId, useState } from "react";
|
|
140
40
|
|
|
@@ -296,4 +196,4 @@ function DiffViewer2({
|
|
|
296
196
|
});
|
|
297
197
|
}
|
|
298
198
|
|
|
299
|
-
export {
|
|
199
|
+
export { DiffViewer2 };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/components/assistant-ui/utils/diffViewer/parsePatch.ts
|
|
2
|
+
import parseDiff from "parse-diff";
|
|
3
|
+
function parsePatch2(patch) {
|
|
4
|
+
const files = parseDiff(patch);
|
|
5
|
+
return files.map((file) => {
|
|
6
|
+
const hunks = file.chunks.map((chunk) => {
|
|
7
|
+
const lines = [];
|
|
8
|
+
for (const change of chunk.changes) {
|
|
9
|
+
if (change.content.startsWith("\\")) {
|
|
10
|
+
lines.push({ type: "marker", content: change.content });
|
|
11
|
+
} else if (change.type === "add") {
|
|
12
|
+
lines.push({
|
|
13
|
+
type: "add",
|
|
14
|
+
content: change.content.slice(1),
|
|
15
|
+
newLineNumber: change.ln
|
|
16
|
+
});
|
|
17
|
+
} else if (change.type === "del") {
|
|
18
|
+
lines.push({
|
|
19
|
+
type: "del",
|
|
20
|
+
content: change.content.slice(1),
|
|
21
|
+
oldLineNumber: change.ln
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
lines.push({
|
|
25
|
+
type: "normal",
|
|
26
|
+
content: change.content.slice(1),
|
|
27
|
+
oldLineNumber: change.ln1,
|
|
28
|
+
newLineNumber: change.ln2
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { header: chunk.content, lines };
|
|
33
|
+
});
|
|
34
|
+
const lines = hunks.flatMap((hunk) => hunk.lines);
|
|
35
|
+
let additions = 0;
|
|
36
|
+
let deletions = 0;
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
if (line.type === "add")
|
|
39
|
+
additions++;
|
|
40
|
+
if (line.type === "del")
|
|
41
|
+
deletions++;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
oldName: file.from,
|
|
45
|
+
newName: file.to,
|
|
46
|
+
lines,
|
|
47
|
+
hunks,
|
|
48
|
+
additions,
|
|
49
|
+
deletions
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/components/assistant-ui/utils/diffViewer/computeDiff.ts
|
|
55
|
+
import { createTwoFilesPatch } from "diff";
|
|
56
|
+
function computeDiff2(oldContent, newContent) {
|
|
57
|
+
if (oldContent !== newContent) {
|
|
58
|
+
const file = parsePatch2(createTwoFilesPatch("file", "file", oldContent, newContent, undefined, undefined, { context: Infinity }))[0];
|
|
59
|
+
if (!file)
|
|
60
|
+
throw new Error("The native diff generator did not produce a parseable unified patch");
|
|
61
|
+
return { lines: file.lines, hunks: file.hunks, additions: file.additions, deletions: file.deletions };
|
|
62
|
+
}
|
|
63
|
+
const lines = oldContent.length === 0 ? [] : oldContent.replace(/\n$/u, "").split(`
|
|
64
|
+
`).map((content, index) => ({ type: "normal", content, oldLineNumber: index + 1, newLineNumber: index + 1 }));
|
|
65
|
+
const start = lines.length === 0 ? 0 : 1;
|
|
66
|
+
return {
|
|
67
|
+
lines,
|
|
68
|
+
hunks: [{ header: "@@ -" + start + "," + lines.length + " +" + start + "," + lines.length + " @@", lines }],
|
|
69
|
+
additions: 0,
|
|
70
|
+
deletions: 0
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/components/assistant-ui/utils/diffViewer/pairLinesForSplit.ts
|
|
75
|
+
function pairLinesForSplit(lines) {
|
|
76
|
+
const pairs = [];
|
|
77
|
+
let index = 0;
|
|
78
|
+
const takeBlock = (kind) => {
|
|
79
|
+
const block = [];
|
|
80
|
+
while (index < lines.length) {
|
|
81
|
+
const next = lines[index];
|
|
82
|
+
if (!next || next.type !== kind && next.type !== "marker")
|
|
83
|
+
break;
|
|
84
|
+
block.push(next);
|
|
85
|
+
index += 1;
|
|
86
|
+
}
|
|
87
|
+
return block;
|
|
88
|
+
};
|
|
89
|
+
while (index < lines.length) {
|
|
90
|
+
const line = lines[index];
|
|
91
|
+
if (!line)
|
|
92
|
+
break;
|
|
93
|
+
if (line.type === "normal" || line.type === "marker") {
|
|
94
|
+
pairs.push({ left: line, right: line });
|
|
95
|
+
index += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const deletions = takeBlock("del");
|
|
99
|
+
const additions = takeBlock("add");
|
|
100
|
+
for (let pairIndex = 0;pairIndex < Math.max(deletions.length, additions.length); pairIndex += 1)
|
|
101
|
+
pairs.push({ left: deletions[pairIndex] ?? null, right: additions[pairIndex] ?? null });
|
|
102
|
+
}
|
|
103
|
+
return pairs;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { parsePatch2, computeDiff2, pairLinesForSplit };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DiffViewer2
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-tskx0wgf.js";
|
|
4
4
|
import"../../../chunk-k7gzvk6n.js";
|
|
5
5
|
import"../../../chunk-r0g0gwv6.js";
|
|
6
|
-
import"../../../chunk-
|
|
7
|
-
import"../../../chunk-mm4c6wxz.js";
|
|
8
|
-
import"../../../chunk-7v8ry91s.js";
|
|
9
|
-
import"../../../chunk-73s0vkbs.js";
|
|
10
|
-
import"../../../chunk-xw5992sc.js";
|
|
6
|
+
import"../../../chunk-6r4457jk.js";
|
|
11
7
|
import"../../../chunk-pp8ez02x.js";
|
|
8
|
+
import"../../../chunk-mm4c6wxz.js";
|
|
12
9
|
import"../../../chunk-6synj4j9.js";
|
|
13
10
|
import"../../../chunk-4e96tpw0.js";
|
|
14
11
|
import"../../../chunk-dbe9ppwf.js";
|
|
12
|
+
import"../../../chunk-txwykmer.js";
|
|
13
|
+
import"../../../chunk-gq28gd3g.js";
|
|
14
|
+
import"../../../chunk-31kppqkn.js";
|
|
15
|
+
import"../../../chunk-ghkzxhp0.js";
|
|
15
16
|
import"../../../chunk-2sx8m8b2.js";
|
|
16
17
|
import"../../../chunk-x90xmrba.js";
|
|
17
18
|
import"../../../chunk-jpvw9xqy.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DiffViewerHeader2
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import"../../../chunk-mm4c6wxz.js";
|
|
3
|
+
} from "../../../chunk-6r4457jk.js";
|
|
5
4
|
import"../../../chunk-pp8ez02x.js";
|
|
5
|
+
import"../../../chunk-mm4c6wxz.js";
|
|
6
6
|
import"../../../chunk-6synj4j9.js";
|
|
7
7
|
import"../../../chunk-dbe9ppwf.js";
|
|
8
8
|
import"../../../chunk-2sx8m8b2.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DiffViewerLine2
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import"../../../chunk-
|
|
3
|
+
} from "../../../chunk-gq28gd3g.js";
|
|
4
|
+
import"../../../chunk-ghkzxhp0.js";
|
|
5
5
|
import"../../../chunk-en44w1pn.js";
|
|
6
6
|
export {
|
|
7
7
|
DiffViewerLine2 as DiffViewerLine
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DiffViewerSplitLine2
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import"../../../chunk-
|
|
3
|
+
} from "../../../chunk-31kppqkn.js";
|
|
4
|
+
import"../../../chunk-ghkzxhp0.js";
|
|
5
5
|
import"../../../chunk-en44w1pn.js";
|
|
6
6
|
export {
|
|
7
7
|
DiffViewerSplitLine2 as DiffViewerSplitLine
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
QuestionFlow2
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import"../../../chunk-
|
|
3
|
+
} from "../../../chunk-bpdseydf.js";
|
|
4
|
+
import"../../../chunk-pjph8zne.js";
|
|
5
5
|
import"../../../chunk-8xk2zeg2.js";
|
|
6
6
|
import"../../../chunk-vxvaaptq.js";
|
|
7
7
|
import"../../../chunk-b5s5y5wq.js";
|
|
@@ -434,16 +434,16 @@ import {
|
|
|
434
434
|
} from "../../chunk-8xk2zeg2.js";
|
|
435
435
|
import {
|
|
436
436
|
OptionList2
|
|
437
|
-
} from "../../chunk-
|
|
437
|
+
} from "../../chunk-pjph8zne.js";
|
|
438
438
|
import {
|
|
439
439
|
PermissionGrant2
|
|
440
|
-
} from "../../chunk-
|
|
440
|
+
} from "../../chunk-d9we0wej.js";
|
|
441
441
|
import {
|
|
442
442
|
PromptLibrary2
|
|
443
443
|
} from "../../chunk-mj44p2x3.js";
|
|
444
444
|
import {
|
|
445
445
|
QuestionFlow2
|
|
446
|
-
} from "../../chunk-
|
|
446
|
+
} from "../../chunk-bpdseydf.js";
|
|
447
447
|
import {
|
|
448
448
|
QuotaBanner2
|
|
449
449
|
} from "../../chunk-116t197c.js";
|
|
@@ -480,7 +480,7 @@ import {
|
|
|
480
480
|
} from "../../chunk-a1c1yrkz.js";
|
|
481
481
|
import {
|
|
482
482
|
RecommendationCard2
|
|
483
|
-
} from "../../chunk-
|
|
483
|
+
} from "../../chunk-gyp2em1e.js";
|
|
484
484
|
import"../../chunk-9y4pg1xb.js";
|
|
485
485
|
import {
|
|
486
486
|
RegenerateMenu2
|
|
@@ -617,12 +617,11 @@ import {
|
|
|
617
617
|
diffViewerVariants2,
|
|
618
618
|
diffLineVariants2,
|
|
619
619
|
diffLineTextVariants2
|
|
620
|
-
} from "../../chunk-
|
|
620
|
+
} from "../../chunk-ghkzxhp0.js";
|
|
621
621
|
import {
|
|
622
622
|
parsePatch2,
|
|
623
|
-
computeDiff2
|
|
624
|
-
|
|
625
|
-
} from "../../chunk-b59tzvnw.js";
|
|
623
|
+
computeDiff2
|
|
624
|
+
} from "../../chunk-txwykmer.js";
|
|
626
625
|
import {
|
|
627
626
|
DiffViewerFile2
|
|
628
627
|
} from "../../chunk-k7gzvk6n.js";
|
|
@@ -637,13 +636,16 @@ import {
|
|
|
637
636
|
} from "../../chunk-mm4c6wxz.js";
|
|
638
637
|
import {
|
|
639
638
|
DiffViewerHeader2
|
|
640
|
-
} from "../../chunk-
|
|
639
|
+
} from "../../chunk-6r4457jk.js";
|
|
641
640
|
import {
|
|
642
641
|
DiffViewerLine2
|
|
643
|
-
} from "../../chunk-
|
|
642
|
+
} from "../../chunk-gq28gd3g.js";
|
|
644
643
|
import {
|
|
645
644
|
DiffViewerSplitLine2
|
|
646
|
-
} from "../../chunk-
|
|
645
|
+
} from "../../chunk-31kppqkn.js";
|
|
646
|
+
import {
|
|
647
|
+
DiffViewer2
|
|
648
|
+
} from "../../chunk-tskx0wgf.js";
|
|
647
649
|
import {
|
|
648
650
|
eveAskQuestionToolkit2
|
|
649
651
|
} from "../../chunk-5e9c6m71.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ContextDisplay3
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-qfbf1a5a.js";
|
|
4
4
|
import"../../../chunk-f37ge3wq.js";
|
|
5
|
-
import"../../../chunk-dvzs0424.js";
|
|
6
5
|
import"../../../chunk-4z3c9p9y.js";
|
|
6
|
+
import"../../../chunk-dvzs0424.js";
|
|
7
7
|
import"../../../chunk-056z8fc3.js";
|
|
8
8
|
import"../../../chunk-x8ftt0wm.js";
|
|
9
9
|
import"../../../chunk-9gdt00hm.js";
|
|
@@ -121,7 +121,7 @@ import {
|
|
|
121
121
|
} from "../../../chunk-dvzs0424.js";
|
|
122
122
|
import {
|
|
123
123
|
ContextDisplay3
|
|
124
|
-
} from "../../../chunk-
|
|
124
|
+
} from "../../../chunk-qfbf1a5a.js";
|
|
125
125
|
import"../../../chunk-9ecf92s6.js";
|
|
126
126
|
import"../../../chunk-brxk90eb.js";
|
|
127
127
|
import {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cn2
|
|
3
3
|
} from "../../chunk-en44w1pn.js";
|
|
4
|
+
import {
|
|
5
|
+
useElementSize
|
|
6
|
+
} from "../../chunk-e4t5njn9.js";
|
|
4
7
|
import"../../chunk-7ny0vyek.js";
|
|
5
8
|
import"../../chunk-8ssktt4b.js";
|
|
6
9
|
import"../../chunk-e6hk39ev.js";
|
|
@@ -39,15 +42,15 @@ import"../../chunk-5mydsjp3.js";
|
|
|
39
42
|
|
|
40
43
|
// src/components/image-viewer/ImageViewer.tsx
|
|
41
44
|
import { useControlled } from "@base-ui/utils/useControlled";
|
|
42
|
-
import { useIsoLayoutEffect as
|
|
45
|
+
import { useIsoLayoutEffect as useIsoLayoutEffect2 } from "@base-ui/utils/useIsoLayoutEffect";
|
|
43
46
|
import { useMergedRefs as useMergedRefs2 } from "@base-ui/utils/useMergedRefs";
|
|
44
47
|
import {
|
|
45
48
|
useRef as useRef2,
|
|
46
|
-
useState as
|
|
49
|
+
useState as useState2
|
|
47
50
|
} from "react";
|
|
48
51
|
|
|
49
52
|
// src/components/image-viewer/ImageViewport.tsx
|
|
50
|
-
import { useIsoLayoutEffect
|
|
53
|
+
import { useIsoLayoutEffect } from "@base-ui/utils/useIsoLayoutEffect";
|
|
51
54
|
import { useMergedRefs } from "@base-ui/utils/useMergedRefs";
|
|
52
55
|
import { useStableCallback } from "@base-ui/utils/useStableCallback";
|
|
53
56
|
import {
|
|
@@ -111,28 +114,6 @@ function getImageStageSize(natural, viewport, zoom) {
|
|
|
111
114
|
return { width: width * scale, height: height * scale, scale };
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
// src/components/image-viewer/hooks/useElementSize.ts
|
|
115
|
-
import { useIsoLayoutEffect } from "@base-ui/utils/useIsoLayoutEffect";
|
|
116
|
-
import { useState } from "react";
|
|
117
|
-
function useElementSize(ref) {
|
|
118
|
-
const [size, setSize] = useState();
|
|
119
|
-
useIsoLayoutEffect(() => {
|
|
120
|
-
const element = ref.current;
|
|
121
|
-
if (!element)
|
|
122
|
-
return;
|
|
123
|
-
const measure = () => {
|
|
124
|
-
const width = element.clientWidth;
|
|
125
|
-
const height = element.clientHeight;
|
|
126
|
-
setSize((current) => current?.width === width && current.height === height ? current : { width, height });
|
|
127
|
-
};
|
|
128
|
-
measure();
|
|
129
|
-
const observer = new ResizeObserver(measure);
|
|
130
|
-
observer.observe(element);
|
|
131
|
-
return () => observer.disconnect();
|
|
132
|
-
}, [ref]);
|
|
133
|
-
return size;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
117
|
// src/components/image-viewer/ImageViewport.tsx
|
|
137
118
|
import { jsx } from "react/jsx-runtime";
|
|
138
119
|
var PAN_THRESHOLD = 4;
|
|
@@ -187,7 +168,7 @@ function ImageViewport({
|
|
|
187
168
|
const stageHeight = stage?.height ?? 0;
|
|
188
169
|
const canPanX = viewportSize !== undefined && stageWidth > viewportSize.width + 0.5;
|
|
189
170
|
const canPanY = viewportSize !== undefined && stageHeight > viewportSize.height + 0.5;
|
|
190
|
-
|
|
171
|
+
useIsoLayoutEffect(() => {
|
|
191
172
|
const viewport = elementRef.current;
|
|
192
173
|
if (!viewport || stageWidth === 0 || stageHeight === 0)
|
|
193
174
|
return;
|
|
@@ -466,9 +447,9 @@ function ImageZoomControl({
|
|
|
466
447
|
}
|
|
467
448
|
|
|
468
449
|
// src/components/image-viewer/hooks/useImageLoad.ts
|
|
469
|
-
import { useState
|
|
450
|
+
import { useState } from "react";
|
|
470
451
|
function useImageLoad(src) {
|
|
471
|
-
const [state, setState] =
|
|
452
|
+
const [state, setState] = useState({ src, status: "loading" });
|
|
472
453
|
const handlers = {
|
|
473
454
|
onLoad: (event) => {
|
|
474
455
|
const image = event.currentTarget;
|
|
@@ -513,10 +494,10 @@ function ImageViewer({
|
|
|
513
494
|
const mergedStageRef = useMergedRefs2(viewportRef, stageRef);
|
|
514
495
|
const viewportSize = useElementSize(viewportRef);
|
|
515
496
|
const [image, imageHandlers] = useImageLoad(src);
|
|
516
|
-
const [openingZoom, setOpeningZoom] =
|
|
497
|
+
const [openingZoom, setOpeningZoom] = useState2();
|
|
517
498
|
const naturalSize = image.size;
|
|
518
499
|
const scales = naturalSize && viewportSize ? getImageZoomScales(naturalSize, viewportSize) : undefined;
|
|
519
|
-
|
|
500
|
+
useIsoLayoutEffect2(() => {
|
|
520
501
|
if (zoom !== undefined || openingZoom !== undefined || !naturalSize || !viewportSize)
|
|
521
502
|
return;
|
|
522
503
|
const opening = getOpeningImageZoom(naturalSize, viewportSize, openingWidth);
|
|
@@ -636,7 +617,7 @@ function ImageZoomToggle({
|
|
|
636
617
|
});
|
|
637
618
|
}
|
|
638
619
|
// src/components/image-viewer/ImageRegionSelect.tsx
|
|
639
|
-
import { useRef as useRef3, useState as
|
|
620
|
+
import { useRef as useRef3, useState as useState3 } from "react";
|
|
640
621
|
|
|
641
622
|
// src/components/image-viewer/getNormalizedImagePoint.ts
|
|
642
623
|
function clampUnit2(value) {
|
|
@@ -767,7 +748,7 @@ function toBox(region) {
|
|
|
767
748
|
function ImageRegionSelect({ region, onRegionChange }) {
|
|
768
749
|
const drag = useRef3(null);
|
|
769
750
|
const pendingClick = useRef3(null);
|
|
770
|
-
const [draft, setDraft] =
|
|
751
|
+
const [draft, setDraft] = useState3();
|
|
771
752
|
const point = (event) => getNormalizedImagePoint(event, event.currentTarget.getBoundingClientRect());
|
|
772
753
|
function cancel() {
|
|
773
754
|
drag.current = null;
|
|
@@ -901,7 +882,7 @@ function ImageRegionFields({
|
|
|
901
882
|
}
|
|
902
883
|
// src/components/image-viewer/ImageComparison.tsx
|
|
903
884
|
import { useControlled as useControlled2 } from "@base-ui/utils/useControlled";
|
|
904
|
-
import { useRef as useRef5, useState as
|
|
885
|
+
import { useRef as useRef5, useState as useState5 } from "react";
|
|
905
886
|
|
|
906
887
|
// src/components/image-viewer/ImageComparisonToolbar.tsx
|
|
907
888
|
import { Columns2Icon, Rows2Icon } from "lucide-react";
|
|
@@ -1186,7 +1167,7 @@ function ImageSwipeDivider({
|
|
|
1186
1167
|
}
|
|
1187
1168
|
|
|
1188
1169
|
// src/components/image-viewer/hooks/useImageDifferences.ts
|
|
1189
|
-
import { useEffect as useEffect2, useRef as useRef4, useState as
|
|
1170
|
+
import { useEffect as useEffect2, useRef as useRef4, useState as useState4 } from "react";
|
|
1190
1171
|
|
|
1191
1172
|
// src/components/image-viewer/computeImageDiff.ts
|
|
1192
1173
|
var DEFAULT_THRESHOLD = 32;
|
|
@@ -1399,7 +1380,7 @@ function useImageDifferences({
|
|
|
1399
1380
|
beforeRef,
|
|
1400
1381
|
afterRef
|
|
1401
1382
|
}) {
|
|
1402
|
-
const [entries, setEntries] =
|
|
1383
|
+
const [entries, setEntries] = useState4(() => new Map);
|
|
1403
1384
|
const startedRef = useRef4(new Set);
|
|
1404
1385
|
const controllerRef = useRef4(undefined);
|
|
1405
1386
|
useEffect2(() => () => controllerRef.current?.abort(), [pairKey]);
|
|
@@ -1501,8 +1482,8 @@ function ImageComparison({
|
|
|
1501
1482
|
name: "ImageComparison",
|
|
1502
1483
|
state: "showDifferences"
|
|
1503
1484
|
});
|
|
1504
|
-
const [isPeeking, setIsPeeking] =
|
|
1505
|
-
const [position, setPosition] =
|
|
1485
|
+
const [isPeeking, setIsPeeking] = useState5(false);
|
|
1486
|
+
const [position, setPosition] = useState5(50);
|
|
1506
1487
|
const [beforeImage, beforeHandlers] = useImageLoad(before.src);
|
|
1507
1488
|
const [afterImage, afterHandlers] = useImageLoad(after.src);
|
|
1508
1489
|
const beforeRef = useRef5(null);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ComponentProps, JSX } from "react";
|
|
2
|
+
import type { TextDiffViewMode } from "./types.js";
|
|
3
|
+
export interface ITextDiffProps extends Omit<ComponentProps<"div">, "children"> {
|
|
4
|
+
/** The earlier text. */
|
|
5
|
+
before: string;
|
|
6
|
+
/** The later text. */
|
|
7
|
+
after: string;
|
|
8
|
+
/** Names the earlier text, such as "Current"; defaults to "Before". */
|
|
9
|
+
beforeLabel?: string | undefined;
|
|
10
|
+
/** Names the later text, such as "Proposed"; defaults to "After". */
|
|
11
|
+
afterLabel?: string | undefined;
|
|
12
|
+
/** `auto` (default) shows the versions side by side from `splitMinWidth` of its own width and stacked below it. */
|
|
13
|
+
viewMode?: TextDiffViewMode | undefined;
|
|
14
|
+
/** The narrowest own width, in pixels, that shows the versions side by side in `auto` mode; defaults to 560. */
|
|
15
|
+
splitMinWidth?: number | undefined;
|
|
16
|
+
/** Unchanged lines kept around each change; longer unchanged runs fold behind a button. Defaults to 3. */
|
|
17
|
+
contextLines?: number | undefined;
|
|
18
|
+
showLineNumbers?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Two versions of a text as a line diff: removed lines carry "-" and added lines "+" in a sign gutter as well as colour,
|
|
22
|
+
* long lines wrap, and long unchanged runs fold behind a button. In `auto` mode the versions sit side by side once the
|
|
23
|
+
* diff is `splitMinWidth` wide and stack below that.
|
|
24
|
+
*/
|
|
25
|
+
export declare function TextDiff({ before, after, beforeLabel, afterLabel, viewMode, splitMinWidth, contextLines, showLineNumbers, className, ...props }: ITextDiffProps): JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IParsedDiffLine } from "../assistant-ui/utils/diffViewer/types.js";
|
|
2
|
+
import type { TextDiffSegment } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Splits diff lines into shown lines and runs of unchanged lines that fold away: an unchanged line stays shown when it
|
|
5
|
+
* is within `contextLines` of a change, and a hidden run of one line stays shown because folding it saves nothing. With
|
|
6
|
+
* no change at all, every line stays shown.
|
|
7
|
+
*/
|
|
8
|
+
export declare function groupDiffLines(lines: readonly IParsedDiffLine[], contextLines: number): TextDiffSegment[];
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn2
|
|
3
|
+
} from "../../chunk-en44w1pn.js";
|
|
4
|
+
import"../../chunk-7ny0vyek.js";
|
|
5
|
+
import"../../chunk-8ssktt4b.js";
|
|
6
|
+
import"../../chunk-e6hk39ev.js";
|
|
7
|
+
import"../../chunk-x90xmrba.js";
|
|
8
|
+
import"../../chunk-jpvw9xqy.js";
|
|
9
|
+
import {
|
|
10
|
+
Button2
|
|
11
|
+
} from "../../chunk-2sx8m8b2.js";
|
|
12
|
+
import {
|
|
13
|
+
computeDiff2,
|
|
14
|
+
pairLinesForSplit
|
|
15
|
+
} from "../../chunk-txwykmer.js";
|
|
16
|
+
import {
|
|
17
|
+
diffViewerVariants2
|
|
18
|
+
} from "../../chunk-ghkzxhp0.js";
|
|
19
|
+
import {
|
|
20
|
+
DiffViewerLine2
|
|
21
|
+
} from "../../chunk-gq28gd3g.js";
|
|
22
|
+
import {
|
|
23
|
+
DiffViewerSplitLine2
|
|
24
|
+
} from "../../chunk-31kppqkn.js";
|
|
25
|
+
import {
|
|
26
|
+
useElementSize
|
|
27
|
+
} from "../../chunk-e4t5njn9.js";
|
|
28
|
+
import"../../chunk-5mydsjp3.js";
|
|
29
|
+
|
|
30
|
+
// src/components/text-diff/TextDiff.tsx
|
|
31
|
+
import { Fragment, useId, useMemo, useRef, useState } from "react";
|
|
32
|
+
|
|
33
|
+
// src/components/text-diff/groupDiffLines.ts
|
|
34
|
+
function groupDiffLines(lines, contextLines) {
|
|
35
|
+
const changed = lines.flatMap((line, index) => line.type === "add" || line.type === "del" ? [index] : []);
|
|
36
|
+
if (changed.length === 0)
|
|
37
|
+
return lines.length ? [{ kind: "lines", lines: [...lines] }] : [];
|
|
38
|
+
const isNearChange = (index) => changed.some((changedIndex) => Math.abs(changedIndex - index) <= contextLines);
|
|
39
|
+
const segments = [];
|
|
40
|
+
let index = 0;
|
|
41
|
+
while (index < lines.length) {
|
|
42
|
+
const start = index;
|
|
43
|
+
const isShown = isNearChange(index);
|
|
44
|
+
while (index < lines.length && isNearChange(index) === isShown)
|
|
45
|
+
index += 1;
|
|
46
|
+
const run = lines.slice(start, index);
|
|
47
|
+
const previous = segments.at(-1);
|
|
48
|
+
if (isShown || run.length < 2) {
|
|
49
|
+
if (previous?.kind === "lines")
|
|
50
|
+
previous.lines.push(...run);
|
|
51
|
+
else
|
|
52
|
+
segments.push({ kind: "lines", lines: run });
|
|
53
|
+
} else
|
|
54
|
+
segments.push({ kind: "unchanged", start, lines: run });
|
|
55
|
+
}
|
|
56
|
+
return segments;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/components/text-diff/TextDiff.tsx
|
|
60
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
61
|
+
var SPLIT_MIN_WIDTH = 560;
|
|
62
|
+
var CONTEXT_LINES = 3;
|
|
63
|
+
function withFinalNewline(text) {
|
|
64
|
+
return text === "" || text.endsWith(`
|
|
65
|
+
`) ? text : `${text}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
function formatUnchanged(count) {
|
|
69
|
+
return `${count} unchanged ${count === 1 ? "line" : "lines"}`;
|
|
70
|
+
}
|
|
71
|
+
function SignLabel({ sign, label }) {
|
|
72
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
73
|
+
className: "flex min-w-0 items-center gap-1",
|
|
74
|
+
children: [
|
|
75
|
+
/* @__PURE__ */ jsx("span", {
|
|
76
|
+
"aria-hidden": "true",
|
|
77
|
+
className: sign === "-" ? "text-destructive" : "text-success",
|
|
78
|
+
children: sign
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ jsx("span", {
|
|
81
|
+
className: "truncate",
|
|
82
|
+
children: label
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function TextDiff({
|
|
88
|
+
before,
|
|
89
|
+
after,
|
|
90
|
+
beforeLabel = "Before",
|
|
91
|
+
afterLabel = "After",
|
|
92
|
+
viewMode = "auto",
|
|
93
|
+
splitMinWidth = SPLIT_MIN_WIDTH,
|
|
94
|
+
contextLines = CONTEXT_LINES,
|
|
95
|
+
showLineNumbers = true,
|
|
96
|
+
className,
|
|
97
|
+
...props
|
|
98
|
+
}) {
|
|
99
|
+
const container = useRef(null);
|
|
100
|
+
const size = useElementSize(container);
|
|
101
|
+
const [expanded, setExpanded] = useState(() => new Set);
|
|
102
|
+
const idPrefix = useId();
|
|
103
|
+
const segments = useMemo(() => groupDiffLines(computeDiff2(withFinalNewline(before), withFinalNewline(after)).lines, contextLines), [before, after, contextLines]);
|
|
104
|
+
const isSplit = viewMode === "split" || viewMode === "auto" && size !== undefined && size.width >= splitMinWidth;
|
|
105
|
+
const renderLines = (lines) => isSplit ? pairLinesForSplit(lines).map((pair, index) => /* @__PURE__ */ jsx(DiffViewerSplitLine2, {
|
|
106
|
+
pair,
|
|
107
|
+
showLineNumbers
|
|
108
|
+
}, index)) : lines.map((line, index) => /* @__PURE__ */ jsx(DiffViewerLine2, {
|
|
109
|
+
line,
|
|
110
|
+
showLineNumbers
|
|
111
|
+
}, index));
|
|
112
|
+
const toggle = (start) => setExpanded((current) => {
|
|
113
|
+
const next = new Set(current);
|
|
114
|
+
if (!next.delete(start))
|
|
115
|
+
next.add(start);
|
|
116
|
+
return next;
|
|
117
|
+
});
|
|
118
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
119
|
+
ref: container,
|
|
120
|
+
"data-testid": "TextDiff",
|
|
121
|
+
"data-slot": "text-diff",
|
|
122
|
+
"data-view-mode": isSplit ? "split" : "unified",
|
|
123
|
+
"data-scroll": "none",
|
|
124
|
+
...props,
|
|
125
|
+
className: cn2(diffViewerVariants2({ variant: "default", size: "sm" }), className),
|
|
126
|
+
children: [
|
|
127
|
+
/* @__PURE__ */ jsxs("div", {
|
|
128
|
+
"data-testid": "TextDiff--legend",
|
|
129
|
+
className: cn2("flex min-h-control-lg items-center gap-control-gap border-b border-frame-edge px-control-x text-xs font-medium tracking-wide text-muted-foreground", isSplit && "[&>*]:w-1/2"),
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(SignLabel, {
|
|
132
|
+
sign: "-",
|
|
133
|
+
label: beforeLabel
|
|
134
|
+
}),
|
|
135
|
+
/* @__PURE__ */ jsx(SignLabel, {
|
|
136
|
+
sign: "+",
|
|
137
|
+
label: afterLabel
|
|
138
|
+
})
|
|
139
|
+
]
|
|
140
|
+
}),
|
|
141
|
+
/* @__PURE__ */ jsx("div", {
|
|
142
|
+
className: "py-2",
|
|
143
|
+
children: segments.map((segment, segmentIndex) => {
|
|
144
|
+
if (segment.kind === "lines")
|
|
145
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
146
|
+
children: renderLines(segment.lines)
|
|
147
|
+
}, segmentIndex);
|
|
148
|
+
const isExpanded = expanded.has(segment.start);
|
|
149
|
+
const regionId = `${idPrefix}-${segment.start}`;
|
|
150
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
151
|
+
children: [
|
|
152
|
+
/* @__PURE__ */ jsx("div", {
|
|
153
|
+
className: "flex px-control-x py-0.5 font-sans",
|
|
154
|
+
children: /* @__PURE__ */ jsx(Button2, {
|
|
155
|
+
type: "button",
|
|
156
|
+
variant: "ghost",
|
|
157
|
+
size: "sm",
|
|
158
|
+
"aria-expanded": isExpanded,
|
|
159
|
+
"aria-controls": regionId,
|
|
160
|
+
onClick: () => toggle(segment.start),
|
|
161
|
+
children: isExpanded ? `Hide ${formatUnchanged(segment.lines.length)}` : `Show ${formatUnchanged(segment.lines.length)}`
|
|
162
|
+
})
|
|
163
|
+
}),
|
|
164
|
+
/* @__PURE__ */ jsx("div", {
|
|
165
|
+
id: regionId,
|
|
166
|
+
hidden: !isExpanded,
|
|
167
|
+
children: isExpanded && renderLines(segment.lines)
|
|
168
|
+
})
|
|
169
|
+
]
|
|
170
|
+
}, segmentIndex);
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
TextDiff
|
|
178
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IParsedDiffLine } from "../assistant-ui/utils/diffViewer/types.js";
|
|
2
|
+
/** How a text diff lays out its two versions: by its own width, always stacked, or always side by side. */
|
|
3
|
+
export type TextDiffViewMode = "auto" | "unified" | "split";
|
|
4
|
+
/** Lines a text diff shows, or a run of unchanged lines that folds away; `start` is the run's first line index. */
|
|
5
|
+
export type TextDiffSegment = {
|
|
6
|
+
kind: "lines";
|
|
7
|
+
lines: IParsedDiffLine[];
|
|
8
|
+
} | {
|
|
9
|
+
kind: "unchanged";
|
|
10
|
+
start: number;
|
|
11
|
+
lines: IParsedDiffLine[];
|
|
12
|
+
};
|
|
@@ -104,6 +104,50 @@ function renderDefaultRow(row, props) {
|
|
|
104
104
|
})
|
|
105
105
|
}, row.id);
|
|
106
106
|
}
|
|
107
|
+
function revealRow(viewport, row, focus) {
|
|
108
|
+
const keepInView = () => {
|
|
109
|
+
const header = viewport.querySelector("thead")?.getBoundingClientRect().height ?? 0;
|
|
110
|
+
const view = viewport.getBoundingClientRect();
|
|
111
|
+
const bounds = row.getBoundingClientRect();
|
|
112
|
+
const top = view.top + header;
|
|
113
|
+
const bottom = view.top + viewport.clientHeight;
|
|
114
|
+
if (bounds.top < top || bounds.height > bottom - top)
|
|
115
|
+
viewport.scrollTop += bounds.top - top;
|
|
116
|
+
else if (bounds.bottom > bottom)
|
|
117
|
+
viewport.scrollTop += bounds.bottom - bottom;
|
|
118
|
+
};
|
|
119
|
+
keepInView();
|
|
120
|
+
if (!focus)
|
|
121
|
+
return;
|
|
122
|
+
row.focus({ preventScroll: true });
|
|
123
|
+
const table = row.closest("table");
|
|
124
|
+
if (row.ownerDocument.activeElement !== row || !table)
|
|
125
|
+
return;
|
|
126
|
+
const input = new AbortController;
|
|
127
|
+
let frame = 0;
|
|
128
|
+
const schedule = () => {
|
|
129
|
+
if (frame)
|
|
130
|
+
return;
|
|
131
|
+
frame = requestAnimationFrame(() => {
|
|
132
|
+
frame = 0;
|
|
133
|
+
if (row === row.ownerDocument.activeElement)
|
|
134
|
+
keepInView();
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
const observer = new ResizeObserver(schedule);
|
|
138
|
+
const stop = () => {
|
|
139
|
+
cancelAnimationFrame(frame);
|
|
140
|
+
observer.disconnect();
|
|
141
|
+
input.abort();
|
|
142
|
+
};
|
|
143
|
+
for (const event of ["wheel", "pointerdown", "touchstart", "keydown"]) {
|
|
144
|
+
viewport.addEventListener(event, stop, { signal: input.signal, passive: true, capture: true });
|
|
145
|
+
}
|
|
146
|
+
row.addEventListener("blur", stop, { signal: input.signal });
|
|
147
|
+
viewport.addEventListener("scroll", schedule, { signal: input.signal, passive: true });
|
|
148
|
+
observer.observe(table);
|
|
149
|
+
return stop;
|
|
150
|
+
}
|
|
107
151
|
function handleRowKeys(cursor, event) {
|
|
108
152
|
if (event.target !== event.currentTarget || event.altKey)
|
|
109
153
|
return;
|
|
@@ -168,15 +212,7 @@ function VirtualDataGrid({
|
|
|
168
212
|
const row = viewport?.querySelector(`tr[data-row-id="${CSS.escape(reveal.rowId)}"]`);
|
|
169
213
|
if (!viewport || !row)
|
|
170
214
|
return;
|
|
171
|
-
|
|
172
|
-
const view = viewport.getBoundingClientRect();
|
|
173
|
-
const bounds = row.getBoundingClientRect();
|
|
174
|
-
if (bounds.top < view.top + header)
|
|
175
|
-
viewport.scrollTop -= view.top + header - bounds.top;
|
|
176
|
-
else if (bounds.bottom > view.bottom)
|
|
177
|
-
viewport.scrollTop += bounds.bottom - view.bottom;
|
|
178
|
-
if (reveal.focus)
|
|
179
|
-
row.focus({ preventScroll: true });
|
|
215
|
+
return revealRow(viewport, row, reveal.focus);
|
|
180
216
|
}, [reveal]);
|
|
181
217
|
const cursorProps = (row) => rowCursor ? {
|
|
182
218
|
tabIndex: row.id === tabStop ? 0 : -1,
|
package/dist/index.js
CHANGED
|
@@ -188,7 +188,11 @@ import {
|
|
|
188
188
|
DashboardLayout2,
|
|
189
189
|
BillingUsage2,
|
|
190
190
|
SelectionAction2
|
|
191
|
-
} from "./chunk-
|
|
191
|
+
} from "./chunk-wq1prnfw.js";
|
|
192
|
+
import {
|
|
193
|
+
statusDotVariants2,
|
|
194
|
+
StatusDot2
|
|
195
|
+
} from "./chunk-bvzjbk43.js";
|
|
192
196
|
import {
|
|
193
197
|
Combobox2,
|
|
194
198
|
ComboboxValue2,
|
|
@@ -239,10 +243,6 @@ import {
|
|
|
239
243
|
ToolbarGroup2,
|
|
240
244
|
ToolbarSeparator2
|
|
241
245
|
} from "./chunk-0ef27nx1.js";
|
|
242
|
-
import {
|
|
243
|
-
statusDotVariants2,
|
|
244
|
-
StatusDot2
|
|
245
|
-
} from "./chunk-bvzjbk43.js";
|
|
246
246
|
import {
|
|
247
247
|
Slider2
|
|
248
248
|
} from "./chunk-7cq1s2ey.js";
|
|
@@ -409,6 +409,9 @@ import {
|
|
|
409
409
|
CollapsibleTrigger2,
|
|
410
410
|
CollapsibleContent2
|
|
411
411
|
} from "./chunk-fw86vanx.js";
|
|
412
|
+
import {
|
|
413
|
+
useTheme2
|
|
414
|
+
} from "./chunk-1j2hz3w9.js";
|
|
412
415
|
import {
|
|
413
416
|
Label2
|
|
414
417
|
} from "./chunk-m32ptxf3.js";
|
|
@@ -477,9 +480,6 @@ import {
|
|
|
477
480
|
import {
|
|
478
481
|
Separator2
|
|
479
482
|
} from "./chunk-52aadmkc.js";
|
|
480
|
-
import {
|
|
481
|
-
useTheme2
|
|
482
|
-
} from "./chunk-1j2hz3w9.js";
|
|
483
483
|
import {
|
|
484
484
|
TooltipProvider2,
|
|
485
485
|
Tooltip2,
|
package/dist/prototype.js
CHANGED
|
@@ -2051,7 +2051,7 @@ var program = new Command;
|
|
|
2051
2051
|
// package.json
|
|
2052
2052
|
var package_default = {
|
|
2053
2053
|
name: "@alexgorbatchev/shadcn",
|
|
2054
|
-
version: "0.0.
|
|
2054
|
+
version: "0.0.145",
|
|
2055
2055
|
description: "Sharp, monospace React components with compact, comfortable, and touch densities.",
|
|
2056
2056
|
license: "MIT",
|
|
2057
2057
|
repository: {
|
|
@@ -2108,6 +2108,10 @@ var package_default = {
|
|
|
2108
2108
|
types: "./dist/components/resizable/index.d.ts",
|
|
2109
2109
|
import: "./dist/components/resizable/index.js"
|
|
2110
2110
|
},
|
|
2111
|
+
"./text-diff": {
|
|
2112
|
+
types: "./dist/components/text-diff/index.d.ts",
|
|
2113
|
+
import: "./dist/components/text-diff/index.js"
|
|
2114
|
+
},
|
|
2111
2115
|
"./sonner": {
|
|
2112
2116
|
types: "./dist/components/sonner/index.d.ts",
|
|
2113
2117
|
import: "./dist/components/sonner/index.js"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# TextDiff
|
|
2
|
+
|
|
3
|
+
Story: @alexgorbatchev/shadcn/components/data-display/TextDiff
|
|
4
|
+
Source: src/components/stories/data-display/TextDiff.stories.tsx
|
|
5
|
+
|
|
6
|
+
[Full source and local helpers](https://github.com/alexgorbatchev/shadcn/blob/main/src/components/stories/data-display/TextDiff.stories.tsx)
|
|
7
|
+
|
|
8
|
+
## Public imports
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { TextDiff } from "@alexgorbatchev/shadcn/text-diff";
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Default component
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
TextDiff
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Default args
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
{ before: configBefore, after: configAfter, beforeLabel: "Current", afterLabel: "Proposed" }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Default render
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
(args) => (<div className="w-[390px]">
|
|
30
|
+
<TextDiff {...args}/>
|
|
31
|
+
</div>)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
Storybook CSF excerpts. Default args and render apply unless overridden. Local helpers, fixtures, decorators, and providers may be required; these are reference excerpts, not standalone consumer modules. Interaction tests are omitted.
|
|
37
|
+
|
|
38
|
+
### Stacked
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
{}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### FoldedUnchangedLines
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
{}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### SideBySide
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
{
|
|
54
|
+
render: (args) => (<div className="w-[800px]">
|
|
55
|
+
<TextDiff {...args}/>
|
|
56
|
+
</div>)
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### FixedMode
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
{
|
|
64
|
+
args: { viewMode: "unified" },
|
|
65
|
+
render: SideBySide.render
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### WrappedProse
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
{
|
|
73
|
+
args: {
|
|
74
|
+
before: longLine,
|
|
75
|
+
after: longLine.replace("an ellipsis", "a fade"),
|
|
76
|
+
beforeLabel: undefined,
|
|
77
|
+
afterLabel: undefined,
|
|
78
|
+
showLineNumbers: false,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Unchanged
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
{
|
|
87
|
+
args: { after: configBefore }
|
|
88
|
+
}
|
|
89
|
+
```
|
package/llms/setup.md
CHANGED
|
@@ -72,6 +72,7 @@ Import shared controls and providers from `@alexgorbatchev/shadcn`. Import the f
|
|
|
72
72
|
| `/color-picker` | ColorPicker | `bun add react-colorful@^5.8.1` |
|
|
73
73
|
| `/image-crop` | ImageCrop and native export helpers | `bun add react-image-crop@^11.1.2` |
|
|
74
74
|
| `/image-viewer` | ImageViewer, ImageZoomToggle, ImageComparison, and image helpers | Existing core peers |
|
|
75
|
+
| `/text-diff` | TextDiff: two versions of a text as a line diff | `bun add diff@9.0.0 parse-diff@0.12.0` |
|
|
75
76
|
| `/tree` | Tree, native hooks and features | `bun add @headless-tree/core@^1.8.0 @headless-tree/react@^1.8.0`; patched runtimes are bundled |
|
|
76
77
|
| `/editor` | RichTextEditor, native Tiptap hooks and StarterKit | `bun add @tiptap/core@^3.32.0 @tiptap/react@^3.32.0 @tiptap/pm@^3.32.0 @tiptap/starter-kit@^3.32.0` |
|
|
77
78
|
| `/event-calendar` | EventCalendar, EventForm and native calendar APIs | `bun add date-fns@^4.4.0`; TypeScript: `bun add -d @types/react-big-calendar@^1.16.3` |
|
|
@@ -547,6 +548,8 @@ function Screenshot({ src, onPick }: { src: string; onPick: (point: INormalizedI
|
|
|
547
548
|
|
|
548
549
|
"Highlight differences" draws both images at the after image's natural size and compares premultiplied channels against a threshold. Changed pixels are aggregated into 16px cells and connected regions, outlined with the warning token over the after image (toggle and swipe) or both panes (side-by-side), and summarized as "3 changed regions" or "No visible differences". The comparison runs in time-boxed slices that yield to the browser and is cached per image pair for the component's lifetime. When pixels cannot be read, such as a cross-origin image served without CORS or an image that failed to decode, the switch is disabled and the reason is shown. Pass `crossOrigin: "anonymous"` only when the image server sends CORS headers. `computeImageDiff(before, after, options)` exposes the same pure comparison for equally sized `ImageData`.
|
|
549
550
|
|
|
551
|
+
`TextDiff` (`@alexgorbatchev/shadcn/text-diff`) shows two versions of a text, `before` and `after`, as a line diff labelled by `beforeLabel` and `afterLabel` (default "Before" and "After"). Removed lines carry "-" and added lines "+" in a sign gutter as well as colour, and use `del` and `ins`; long lines wrap, so the diff never scrolls sideways. Unchanged runs further than `contextLines` (default 3) from a change fold behind a "Show N unchanged lines" button that toggles them with `aria-expanded`. `viewMode` is `"auto"` (default), `"unified"`, or `"split"`; auto shows the versions side by side once the diff's own width reaches `splitMinWidth` (default 560 px) and stacked below it, and stacked before the first measurement. A missing final newline is not shown as a change. `showLineNumbers` defaults to true.
|
|
552
|
+
|
|
550
553
|
The toolbar holds the mode, orientation (enabled for side-by-side), zoom, hold-to-show-before (enabled for toggle), and highlight controls with the legend and status. It sits beside a comparison at least 48rem wide and wraps below narrower ones; `showToolbar={false}` hides it, leaving consumers to control the props themselves.
|
|
551
554
|
|
|
552
555
|
# Drag and drop
|
package/llms.txt
CHANGED
|
@@ -364,6 +364,7 @@ Generated from the public package exports and Storybook sources.
|
|
|
364
364
|
- [Table](./llms/components/data-display/Table.md)
|
|
365
365
|
- [TableResponsive](./llms/components/data-display/TableResponsive.md)
|
|
366
366
|
- [Text](./llms/components/data-display/Text.md): Text renders body copy as a paragraph with semantic `size` (xs, sm, base, lg), `tone` (default, muted, faint, primary, success, warning, destructive), `weight`, and `align`. `truncate` keeps one line with an ellipsis; otherwise long words wrap. `tabular` aligns digits. Use `render={<span />}` for inline text, or another element such as `<li />` or `<time />`.
|
|
367
|
+
- [TextDiff](./llms/components/data-display/TextDiff.md)
|
|
367
368
|
- [VirtualDataGrid](./llms/components/data-display/VirtualDataGrid.md)
|
|
368
369
|
- [VirtualTable](./llms/components/data-display/VirtualTable.md)
|
|
369
370
|
- [WeatherForecast](./llms/components/data-display/WeatherForecast.md): WeatherForecast renders several WeatherSummary days as a list named by `label`. Each day takes an `id` plus the WeatherSummary day fields; `unit` and `locale` apply to every day. `variant="strip"` (default) shows compact days side by side and wraps them to the available width; `variant="list"` shows one detailed day per row.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexgorbatchev/shadcn",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.145",
|
|
4
4
|
"description": "Sharp, monospace React components with compact, comfortable, and touch densities.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"types": "./dist/components/resizable/index.d.ts",
|
|
58
58
|
"import": "./dist/components/resizable/index.js"
|
|
59
59
|
},
|
|
60
|
+
"./text-diff": {
|
|
61
|
+
"types": "./dist/components/text-diff/index.d.ts",
|
|
62
|
+
"import": "./dist/components/text-diff/index.js"
|
|
63
|
+
},
|
|
60
64
|
"./sonner": {
|
|
61
65
|
"types": "./dist/components/sonner/index.d.ts",
|
|
62
66
|
"import": "./dist/components/sonner/index.js"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|