@wow-two-beta/ui 0.0.18 → 0.0.20
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/dist/{chunk-D7XIPKDJ.js → chunk-RK6VB3II.js} +859 -4
- package/dist/chunk-RK6VB3II.js.map +1 -0
- package/dist/{chunk-3P7DZCDS.js → chunk-WRPLV6H2.js} +553 -4
- package/dist/chunk-WRPLV6H2.js.map +1 -0
- package/dist/display/dataGrid/DataGrid.d.ts +34 -0
- package/dist/display/dataGrid/DataGrid.d.ts.map +1 -0
- package/dist/display/dataGrid/index.d.ts +2 -0
- package/dist/display/dataGrid/index.d.ts.map +1 -0
- package/dist/display/diffViewer/DiffViewer.d.ts +17 -0
- package/dist/display/diffViewer/DiffViewer.d.ts.map +1 -0
- package/dist/display/diffViewer/index.d.ts +2 -0
- package/dist/display/diffViewer/index.d.ts.map +1 -0
- package/dist/display/heatmapCalendar/HeatmapCalendar.d.ts +21 -0
- package/dist/display/heatmapCalendar/HeatmapCalendar.d.ts.map +1 -0
- package/dist/display/heatmapCalendar/index.d.ts +2 -0
- package/dist/display/heatmapCalendar/index.d.ts.map +1 -0
- package/dist/display/index.d.ts +5 -0
- package/dist/display/index.d.ts.map +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/nodeEditor/NodeEditor.d.ts +32 -0
- package/dist/display/nodeEditor/NodeEditor.d.ts.map +1 -0
- package/dist/display/nodeEditor/index.d.ts +2 -0
- package/dist/display/nodeEditor/index.d.ts.map +1 -0
- package/dist/display/sparkline/Sparkline.d.ts +22 -0
- package/dist/display/sparkline/Sparkline.d.ts.map +1 -0
- package/dist/display/sparkline/index.d.ts +2 -0
- package/dist/display/sparkline/index.d.ts.map +1 -0
- package/dist/forms/codeEditor/CodeEditor.d.ts +20 -0
- package/dist/forms/codeEditor/CodeEditor.d.ts.map +1 -0
- package/dist/forms/codeEditor/index.d.ts +2 -0
- package/dist/forms/codeEditor/index.d.ts.map +1 -0
- package/dist/forms/index.d.ts +3 -0
- package/dist/forms/index.d.ts.map +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/jsonEditor/JSONEditor.d.ts +22 -0
- package/dist/forms/jsonEditor/JSONEditor.d.ts.map +1 -0
- package/dist/forms/jsonEditor/index.d.ts +2 -0
- package/dist/forms/jsonEditor/index.d.ts.map +1 -0
- package/dist/forms/markdownEditor/MarkdownEditor.d.ts +20 -0
- package/dist/forms/markdownEditor/MarkdownEditor.d.ts.map +1 -0
- package/dist/forms/markdownEditor/index.d.ts +2 -0
- package/dist/forms/markdownEditor/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/package.json +2 -1
- package/dist/chunk-3P7DZCDS.js.map +0 -1
- package/dist/chunk-D7XIPKDJ.js.map +0 -1
|
@@ -6,7 +6,7 @@ import { composeRefs } from './chunk-DN7WBRIV.js';
|
|
|
6
6
|
import { cn } from './chunk-KZ4VFY2T.js';
|
|
7
7
|
import { forwardRef, useState, Children, isValidElement, Fragment as Fragment$1, createContext, useId, useMemo, useCallback, useContext, useEffect, useRef, cloneElement } from 'react';
|
|
8
8
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
9
|
-
import { TrendingUp, TrendingDown, Check, Copy, ChevronDown, ChevronLeft, ChevronRight, ArrowUp, ArrowDown, ArrowUpDown } from 'lucide-react';
|
|
9
|
+
import { TrendingUp, TrendingDown, Check, Copy, ChevronDown, ChevronLeft, ChevronRight, Plus, Minus, Maximize, ArrowUp, ArrowDown, ArrowUpDown } from 'lucide-react';
|
|
10
10
|
|
|
11
11
|
// src/display/heading/Heading.variants.ts
|
|
12
12
|
var headingVariants = tv({
|
|
@@ -1973,7 +1973,862 @@ function countNodes(node) {
|
|
|
1973
1973
|
if (Array.isArray(node)) return node.length;
|
|
1974
1974
|
return 1;
|
|
1975
1975
|
}
|
|
1976
|
+
var DiffViewer = forwardRef(function DiffViewer2({ left, right, view = "split", leftLabel = "Before", rightLabel = "After", showStats = true, className, ...rest }, ref) {
|
|
1977
|
+
const rows = useMemo(() => computeDiff(left, right), [left, right]);
|
|
1978
|
+
const stats = useMemo(() => {
|
|
1979
|
+
let added = 0;
|
|
1980
|
+
let removed = 0;
|
|
1981
|
+
for (const r of rows) {
|
|
1982
|
+
if (r.op === "added") added += 1;
|
|
1983
|
+
if (r.op === "removed") removed += 1;
|
|
1984
|
+
}
|
|
1985
|
+
return { added, removed };
|
|
1986
|
+
}, [rows]);
|
|
1987
|
+
return /* @__PURE__ */ jsxs(
|
|
1988
|
+
"div",
|
|
1989
|
+
{
|
|
1990
|
+
ref,
|
|
1991
|
+
className: cn(
|
|
1992
|
+
"overflow-hidden rounded-md border border-border bg-card font-mono text-xs text-card-foreground shadow-sm",
|
|
1993
|
+
className
|
|
1994
|
+
),
|
|
1995
|
+
...rest,
|
|
1996
|
+
children: [
|
|
1997
|
+
showStats && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border bg-muted/40 px-3 py-1.5 text-xs", children: [
|
|
1998
|
+
/* @__PURE__ */ jsxs("div", { className: "text-muted-foreground", children: [
|
|
1999
|
+
leftLabel,
|
|
2000
|
+
" \u2192 ",
|
|
2001
|
+
rightLabel
|
|
2002
|
+
] }),
|
|
2003
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
2004
|
+
/* @__PURE__ */ jsxs("span", { className: "text-success font-medium", children: [
|
|
2005
|
+
"+",
|
|
2006
|
+
stats.added
|
|
2007
|
+
] }),
|
|
2008
|
+
/* @__PURE__ */ jsxs("span", { className: "text-destructive font-medium", children: [
|
|
2009
|
+
"\u2212",
|
|
2010
|
+
stats.removed
|
|
2011
|
+
] })
|
|
2012
|
+
] })
|
|
2013
|
+
] }),
|
|
2014
|
+
view === "split" ? /* @__PURE__ */ jsx(SplitView, { rows }) : /* @__PURE__ */ jsx(UnifiedView, { rows })
|
|
2015
|
+
]
|
|
2016
|
+
}
|
|
2017
|
+
);
|
|
2018
|
+
});
|
|
2019
|
+
function SplitView({ rows }) {
|
|
2020
|
+
const pairs = [];
|
|
2021
|
+
for (let i = 0; i < rows.length; i++) {
|
|
2022
|
+
const r = rows[i];
|
|
2023
|
+
if (r.op === "unchanged") {
|
|
2024
|
+
pairs.push({ left: r, right: r });
|
|
2025
|
+
} else if (r.op === "removed") {
|
|
2026
|
+
const next = rows[i + 1];
|
|
2027
|
+
if (next && next.op === "added") {
|
|
2028
|
+
pairs.push({ left: r, right: next });
|
|
2029
|
+
i++;
|
|
2030
|
+
} else {
|
|
2031
|
+
pairs.push({ left: r });
|
|
2032
|
+
}
|
|
2033
|
+
} else if (r.op === "added") {
|
|
2034
|
+
pairs.push({ right: r });
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 divide-x divide-border", children: [
|
|
2038
|
+
/* @__PURE__ */ jsx(DiffColumn, { rows: pairs.map((p) => p.left) }),
|
|
2039
|
+
/* @__PURE__ */ jsx(DiffColumn, { rows: pairs.map((p) => p.right), side: "right" })
|
|
2040
|
+
] });
|
|
2041
|
+
}
|
|
2042
|
+
function DiffColumn({ rows, side = "left" }) {
|
|
2043
|
+
return /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: rows.map((r, i) => {
|
|
2044
|
+
if (!r) {
|
|
2045
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex bg-muted/30", children: [
|
|
2046
|
+
/* @__PURE__ */ jsx("span", { className: "select-none w-10 shrink-0 px-2 py-0.5 text-right text-muted-foreground", children: "\xB7" }),
|
|
2047
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 whitespace-pre px-2 py-0.5", children: "\xA0" })
|
|
2048
|
+
] }, i);
|
|
2049
|
+
}
|
|
2050
|
+
const num = side === "left" ? r.leftNum : r.rightNum;
|
|
2051
|
+
const isChanged = side === "left" && r.op === "removed" || side === "right" && r.op === "added";
|
|
2052
|
+
return /* @__PURE__ */ jsxs(
|
|
2053
|
+
"div",
|
|
2054
|
+
{
|
|
2055
|
+
"data-state": r.op,
|
|
2056
|
+
className: cn(
|
|
2057
|
+
"flex",
|
|
2058
|
+
isChanged && side === "left" && "bg-destructive-soft",
|
|
2059
|
+
isChanged && side === "right" && "bg-success-soft"
|
|
2060
|
+
),
|
|
2061
|
+
children: [
|
|
2062
|
+
/* @__PURE__ */ jsx("span", { className: "select-none w-10 shrink-0 border-r border-border px-2 py-0.5 text-right text-muted-foreground tabular-nums", children: num ?? "" }),
|
|
2063
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 whitespace-pre px-2 py-0.5", children: r.text || " " })
|
|
2064
|
+
]
|
|
2065
|
+
},
|
|
2066
|
+
i
|
|
2067
|
+
);
|
|
2068
|
+
}) });
|
|
2069
|
+
}
|
|
2070
|
+
function UnifiedView({ rows }) {
|
|
2071
|
+
return /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: rows.map((r, i) => /* @__PURE__ */ jsxs(
|
|
2072
|
+
"div",
|
|
2073
|
+
{
|
|
2074
|
+
"data-state": r.op,
|
|
2075
|
+
className: cn(
|
|
2076
|
+
"flex",
|
|
2077
|
+
r.op === "added" && "bg-success-soft",
|
|
2078
|
+
r.op === "removed" && "bg-destructive-soft"
|
|
2079
|
+
),
|
|
2080
|
+
children: [
|
|
2081
|
+
/* @__PURE__ */ jsx("span", { className: "select-none w-10 shrink-0 border-r border-border px-2 py-0.5 text-right text-muted-foreground tabular-nums", children: r.leftNum ?? "" }),
|
|
2082
|
+
/* @__PURE__ */ jsx("span", { className: "select-none w-10 shrink-0 border-r border-border px-2 py-0.5 text-right text-muted-foreground tabular-nums", children: r.rightNum ?? "" }),
|
|
2083
|
+
/* @__PURE__ */ jsx("span", { className: "w-5 shrink-0 px-1 py-0.5 text-center text-muted-foreground", children: r.op === "added" ? "+" : r.op === "removed" ? "\u2212" : " " }),
|
|
2084
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 whitespace-pre px-2 py-0.5", children: r.text || " " })
|
|
2085
|
+
]
|
|
2086
|
+
},
|
|
2087
|
+
i
|
|
2088
|
+
)) });
|
|
2089
|
+
}
|
|
2090
|
+
function computeDiff(left, right) {
|
|
2091
|
+
const a = left.split("\n");
|
|
2092
|
+
const b = right.split("\n");
|
|
2093
|
+
const n = a.length;
|
|
2094
|
+
const m = b.length;
|
|
2095
|
+
const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
2096
|
+
for (let i2 = 1; i2 <= n; i2++) {
|
|
2097
|
+
for (let j2 = 1; j2 <= m; j2++) {
|
|
2098
|
+
if (a[i2 - 1] === b[j2 - 1]) dp[i2][j2] = dp[i2 - 1][j2 - 1] + 1;
|
|
2099
|
+
else dp[i2][j2] = Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
const rows = [];
|
|
2103
|
+
let i = n;
|
|
2104
|
+
let j = m;
|
|
2105
|
+
while (i > 0 || j > 0) {
|
|
2106
|
+
if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
|
|
2107
|
+
rows.push({ op: "unchanged", leftNum: i, rightNum: j, text: a[i - 1] });
|
|
2108
|
+
i--;
|
|
2109
|
+
j--;
|
|
2110
|
+
} else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
|
|
2111
|
+
rows.push({ op: "added", leftNum: null, rightNum: j, text: b[j - 1] });
|
|
2112
|
+
j--;
|
|
2113
|
+
} else if (i > 0) {
|
|
2114
|
+
rows.push({ op: "removed", leftNum: i, rightNum: null, text: a[i - 1] });
|
|
2115
|
+
i--;
|
|
2116
|
+
} else {
|
|
2117
|
+
break;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
rows.reverse();
|
|
2121
|
+
return rows;
|
|
2122
|
+
}
|
|
2123
|
+
var TONE_CLASS = {
|
|
2124
|
+
brand: "text-primary",
|
|
2125
|
+
success: "text-success",
|
|
2126
|
+
warning: "text-warning",
|
|
2127
|
+
danger: "text-destructive",
|
|
2128
|
+
muted: "text-muted-foreground",
|
|
2129
|
+
current: ""
|
|
2130
|
+
};
|
|
2131
|
+
var Sparkline = forwardRef(function Sparkline2({
|
|
2132
|
+
data,
|
|
2133
|
+
variant = "line",
|
|
2134
|
+
width = 120,
|
|
2135
|
+
height = 32,
|
|
2136
|
+
tone = "brand",
|
|
2137
|
+
min: minProp,
|
|
2138
|
+
max: maxProp,
|
|
2139
|
+
showLast,
|
|
2140
|
+
ariaLabel = "Trend",
|
|
2141
|
+
className,
|
|
2142
|
+
...rest
|
|
2143
|
+
}, ref) {
|
|
2144
|
+
const titleId = useId();
|
|
2145
|
+
const { points, barWidth, lastX, lastY, areaPath, linePath } = useMemo(() => {
|
|
2146
|
+
if (data.length === 0) {
|
|
2147
|
+
return { points: [], barWidth: 0, lastX: 0, lastY: 0, areaPath: "", linePath: "" };
|
|
2148
|
+
}
|
|
2149
|
+
const min = minProp ?? Math.min(...data);
|
|
2150
|
+
const max = maxProp ?? Math.max(...data);
|
|
2151
|
+
const range = max - min || 1;
|
|
2152
|
+
const stepX = data.length === 1 ? 0 : width / (data.length - 1);
|
|
2153
|
+
const pad = 1;
|
|
2154
|
+
const pointsArr = data.map((v, i) => {
|
|
2155
|
+
const x = i * stepX;
|
|
2156
|
+
const y = height - (v - min) / range * (height - pad * 2) - pad;
|
|
2157
|
+
return [x, y];
|
|
2158
|
+
});
|
|
2159
|
+
const lp = pointsArr.map(([x, y], i) => i === 0 ? `M${x},${y}` : `L${x},${y}`).join(" ");
|
|
2160
|
+
const ap = `${lp} L${pointsArr[pointsArr.length - 1][0]},${height} L${pointsArr[0][0]},${height} Z`;
|
|
2161
|
+
const bw = data.length > 0 ? width / data.length - 1 : 0;
|
|
2162
|
+
const last = pointsArr[pointsArr.length - 1];
|
|
2163
|
+
return { points: pointsArr, barWidth: bw, lastX: last[0], lastY: last[1], areaPath: ap, linePath: lp };
|
|
2164
|
+
}, [data, height, width, minProp, maxProp]);
|
|
2165
|
+
return /* @__PURE__ */ jsxs(
|
|
2166
|
+
"svg",
|
|
2167
|
+
{
|
|
2168
|
+
ref,
|
|
2169
|
+
role: "img",
|
|
2170
|
+
"aria-labelledby": titleId,
|
|
2171
|
+
width,
|
|
2172
|
+
height,
|
|
2173
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
2174
|
+
preserveAspectRatio: "none",
|
|
2175
|
+
className: cn("inline-block overflow-visible", TONE_CLASS[tone], className),
|
|
2176
|
+
...rest,
|
|
2177
|
+
children: [
|
|
2178
|
+
/* @__PURE__ */ jsx("title", { id: titleId, children: ariaLabel }),
|
|
2179
|
+
variant === "area" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2180
|
+
/* @__PURE__ */ jsx("path", { d: areaPath, fill: "currentColor", fillOpacity: 0.15 }),
|
|
2181
|
+
/* @__PURE__ */ jsx("path", { d: linePath, fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
2182
|
+
] }),
|
|
2183
|
+
variant === "line" && /* @__PURE__ */ jsx("path", { d: linePath, fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
2184
|
+
variant === "bar" && /* @__PURE__ */ jsx("g", { children: points.map(([x, y], i) => /* @__PURE__ */ jsx(
|
|
2185
|
+
"rect",
|
|
2186
|
+
{
|
|
2187
|
+
x: x - barWidth / 2,
|
|
2188
|
+
y,
|
|
2189
|
+
width: Math.max(1, barWidth),
|
|
2190
|
+
height: height - y,
|
|
2191
|
+
fill: "currentColor",
|
|
2192
|
+
rx: 1
|
|
2193
|
+
},
|
|
2194
|
+
i
|
|
2195
|
+
)) }),
|
|
2196
|
+
variant === "dot" && /* @__PURE__ */ jsx("g", { children: points.map(([x, y], i) => /* @__PURE__ */ jsx("circle", { cx: x, cy: y, r: 1.5, fill: "currentColor" }, i)) }),
|
|
2197
|
+
showLast && data.length > 0 && variant !== "dot" && /* @__PURE__ */ jsx("circle", { cx: lastX, cy: lastY, r: 2.5, fill: "currentColor" })
|
|
2198
|
+
]
|
|
2199
|
+
}
|
|
2200
|
+
);
|
|
2201
|
+
});
|
|
2202
|
+
var TONE_CLASSES = {
|
|
2203
|
+
brand: ["bg-muted/50", "bg-primary/20", "bg-primary/40", "bg-primary/70", "bg-primary"],
|
|
2204
|
+
success: ["bg-muted/50", "bg-success/20", "bg-success/40", "bg-success/70", "bg-success"],
|
|
2205
|
+
warning: ["bg-muted/50", "bg-warning/20", "bg-warning/40", "bg-warning/70", "bg-warning"],
|
|
2206
|
+
danger: ["bg-muted/50", "bg-destructive/20", "bg-destructive/40", "bg-destructive/70", "bg-destructive"],
|
|
2207
|
+
muted: ["bg-muted/30", "bg-muted", "bg-muted-foreground/30", "bg-muted-foreground/60", "bg-muted-foreground"]
|
|
2208
|
+
};
|
|
2209
|
+
var DEFAULT_MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
2210
|
+
var DEFAULT_WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
2211
|
+
function formatDate(d) {
|
|
2212
|
+
const y = d.getFullYear();
|
|
2213
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
2214
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
2215
|
+
return `${y}-${m}-${day}`;
|
|
2216
|
+
}
|
|
2217
|
+
var HeatmapCalendar = forwardRef(
|
|
2218
|
+
function HeatmapCalendar2({
|
|
2219
|
+
values,
|
|
2220
|
+
year = (/* @__PURE__ */ new Date()).getFullYear(),
|
|
2221
|
+
weekStart = 0,
|
|
2222
|
+
cellSize = 12,
|
|
2223
|
+
gap = 2,
|
|
2224
|
+
levels = 5,
|
|
2225
|
+
tone = "brand",
|
|
2226
|
+
onCellClick,
|
|
2227
|
+
monthLabels = DEFAULT_MONTHS,
|
|
2228
|
+
weekdayLabels = DEFAULT_WEEKDAYS,
|
|
2229
|
+
showLegend = true,
|
|
2230
|
+
className,
|
|
2231
|
+
...rest
|
|
2232
|
+
}, ref) {
|
|
2233
|
+
const valueMap = useMemo(() => {
|
|
2234
|
+
if (values instanceof Map) return values;
|
|
2235
|
+
return new Map(Object.entries(values));
|
|
2236
|
+
}, [values]);
|
|
2237
|
+
const { columns, monthMarkers, maxValue } = useMemo(() => {
|
|
2238
|
+
const start = new Date(year, 0, 1);
|
|
2239
|
+
const end = new Date(year, 11, 31);
|
|
2240
|
+
const cur = new Date(start);
|
|
2241
|
+
const wd = cur.getDay();
|
|
2242
|
+
const offset = (wd - weekStart + 7) % 7;
|
|
2243
|
+
cur.setDate(cur.getDate() - offset);
|
|
2244
|
+
const cols = [];
|
|
2245
|
+
let column = [];
|
|
2246
|
+
const months = [];
|
|
2247
|
+
let lastSeenMonth = -1;
|
|
2248
|
+
let max = 0;
|
|
2249
|
+
while (cur <= end || column.length > 0) {
|
|
2250
|
+
const inYear = cur.getFullYear() === year;
|
|
2251
|
+
const key = formatDate(cur);
|
|
2252
|
+
const v = valueMap.get(key) ?? 0;
|
|
2253
|
+
if (v > max) max = v;
|
|
2254
|
+
column.push({ date: new Date(cur), inYear, value: v });
|
|
2255
|
+
if (inYear && cur.getMonth() !== lastSeenMonth) {
|
|
2256
|
+
lastSeenMonth = cur.getMonth();
|
|
2257
|
+
months.push({ month: cur.getMonth(), col: cols.length });
|
|
2258
|
+
}
|
|
2259
|
+
if (column.length === 7) {
|
|
2260
|
+
cols.push(column);
|
|
2261
|
+
column = [];
|
|
2262
|
+
}
|
|
2263
|
+
cur.setDate(cur.getDate() + 1);
|
|
2264
|
+
if (cur > end && column.length === 0) break;
|
|
2265
|
+
}
|
|
2266
|
+
if (column.length > 0) cols.push(column);
|
|
2267
|
+
return { columns: cols, monthMarkers: months, maxValue: max };
|
|
2268
|
+
}, [year, weekStart, valueMap]);
|
|
2269
|
+
const toneSteps = TONE_CLASSES[tone];
|
|
2270
|
+
const bucket = (v) => {
|
|
2271
|
+
if (v <= 0 || maxValue === 0) return 0;
|
|
2272
|
+
const idx = Math.ceil(v / maxValue * (levels - 1));
|
|
2273
|
+
return Math.min(levels - 1, idx);
|
|
2274
|
+
};
|
|
2275
|
+
const totalWidth = columns.length * (cellSize + gap);
|
|
2276
|
+
const colHeight = 7 * (cellSize + gap);
|
|
2277
|
+
const weekdayOrder = Array.from({ length: 7 }, (_, i) => weekdayLabels[(i + weekStart) % 7]);
|
|
2278
|
+
return /* @__PURE__ */ jsxs("div", { ref, className: cn("inline-block", className), ...rest, children: [
|
|
2279
|
+
/* @__PURE__ */ jsx("div", { className: "relative ml-8", style: { height: cellSize, width: totalWidth }, children: monthMarkers.map(({ month, col }) => /* @__PURE__ */ jsx(
|
|
2280
|
+
"span",
|
|
2281
|
+
{
|
|
2282
|
+
className: "absolute text-[10px] uppercase text-muted-foreground",
|
|
2283
|
+
style: { left: col * (cellSize + gap) },
|
|
2284
|
+
children: monthLabels[month]
|
|
2285
|
+
},
|
|
2286
|
+
month
|
|
2287
|
+
)) }),
|
|
2288
|
+
/* @__PURE__ */ jsxs("div", { className: "flex", style: { gap }, children: [
|
|
2289
|
+
/* @__PURE__ */ jsx(
|
|
2290
|
+
"div",
|
|
2291
|
+
{
|
|
2292
|
+
className: "flex flex-col text-[10px] uppercase text-muted-foreground",
|
|
2293
|
+
style: { width: 28, gap, height: colHeight },
|
|
2294
|
+
children: weekdayOrder.map((wd, i) => /* @__PURE__ */ jsx(
|
|
2295
|
+
"span",
|
|
2296
|
+
{
|
|
2297
|
+
className: i % 2 === 0 ? "opacity-0" : "",
|
|
2298
|
+
style: { height: cellSize, lineHeight: `${cellSize}px` },
|
|
2299
|
+
children: wd
|
|
2300
|
+
},
|
|
2301
|
+
i
|
|
2302
|
+
))
|
|
2303
|
+
}
|
|
2304
|
+
),
|
|
2305
|
+
/* @__PURE__ */ jsx("div", { className: "flex", style: { gap }, children: columns.map((col, colIdx) => /* @__PURE__ */ jsx("div", { className: "flex flex-col", style: { gap }, children: col.map((cell, rowIdx) => {
|
|
2306
|
+
const dateStr = formatDate(cell.date);
|
|
2307
|
+
const level = bucket(cell.value);
|
|
2308
|
+
const interactive = cell.inYear && onCellClick != null;
|
|
2309
|
+
const Tag = interactive ? "button" : "div";
|
|
2310
|
+
return /* @__PURE__ */ jsx(
|
|
2311
|
+
Tag,
|
|
2312
|
+
{
|
|
2313
|
+
type: interactive ? "button" : void 0,
|
|
2314
|
+
"aria-label": `${dateStr}: ${cell.value}`,
|
|
2315
|
+
"aria-valuenow": level,
|
|
2316
|
+
"aria-valuemin": 0,
|
|
2317
|
+
"aria-valuemax": levels - 1,
|
|
2318
|
+
onClick: interactive ? () => onCellClick?.(dateStr, cell.value) : void 0,
|
|
2319
|
+
style: { width: cellSize, height: cellSize },
|
|
2320
|
+
className: cn(
|
|
2321
|
+
"rounded-[2px] transition-colors",
|
|
2322
|
+
cell.inYear ? toneSteps[level] : "bg-transparent",
|
|
2323
|
+
interactive && "cursor-pointer hover:ring-1 hover:ring-ring focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
2324
|
+
)
|
|
2325
|
+
},
|
|
2326
|
+
rowIdx
|
|
2327
|
+
);
|
|
2328
|
+
}) }, colIdx)) })
|
|
2329
|
+
] }),
|
|
2330
|
+
showLegend && /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-center justify-end gap-1.5 text-[10px] text-muted-foreground", children: [
|
|
2331
|
+
/* @__PURE__ */ jsx("span", { children: "Less" }),
|
|
2332
|
+
toneSteps.map((cls, i) => /* @__PURE__ */ jsx(
|
|
2333
|
+
"span",
|
|
2334
|
+
{
|
|
2335
|
+
"aria-hidden": "true",
|
|
2336
|
+
style: { width: cellSize, height: cellSize },
|
|
2337
|
+
className: cn("rounded-[2px]", cls)
|
|
2338
|
+
},
|
|
2339
|
+
i
|
|
2340
|
+
)),
|
|
2341
|
+
/* @__PURE__ */ jsx("span", { children: "More" })
|
|
2342
|
+
] })
|
|
2343
|
+
] });
|
|
2344
|
+
}
|
|
2345
|
+
);
|
|
2346
|
+
function castValue(raw, type) {
|
|
2347
|
+
if (type === "number") {
|
|
2348
|
+
const n = Number(raw);
|
|
2349
|
+
return Number.isFinite(n) ? n : raw;
|
|
2350
|
+
}
|
|
2351
|
+
if (type === "boolean") return raw === "true";
|
|
2352
|
+
return raw;
|
|
2353
|
+
}
|
|
2354
|
+
var DataGrid = forwardRef(
|
|
2355
|
+
function DataGrid2({ columns, rows, rowKey, onRowChange, dense, className, ...rest }, ref) {
|
|
2356
|
+
const [active, setActive] = useState({ row: 0, col: 0 });
|
|
2357
|
+
const [editing, setEditing] = useState(false);
|
|
2358
|
+
const [draft, setDraft] = useState("");
|
|
2359
|
+
const containerRef = useRef(null);
|
|
2360
|
+
const editRef = useRef(null);
|
|
2361
|
+
useEffect(() => {
|
|
2362
|
+
if (editing && editRef.current) {
|
|
2363
|
+
editRef.current.focus();
|
|
2364
|
+
if ("select" in editRef.current && typeof editRef.current.select === "function") {
|
|
2365
|
+
editRef.current.select();
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
}, [editing]);
|
|
2369
|
+
const colCount = columns.length;
|
|
2370
|
+
const rowCount = rows.length;
|
|
2371
|
+
const beginEdit = useCallback(() => {
|
|
2372
|
+
const col = columns[active.col];
|
|
2373
|
+
const row = rows[active.row];
|
|
2374
|
+
if (!col || row === void 0) return;
|
|
2375
|
+
if (col.editable === false) return;
|
|
2376
|
+
const raw = col.accessor(row);
|
|
2377
|
+
setDraft(raw == null ? "" : String(raw));
|
|
2378
|
+
setEditing(true);
|
|
2379
|
+
}, [columns, rows, active]);
|
|
2380
|
+
const commitEdit = useCallback(
|
|
2381
|
+
(move) => {
|
|
2382
|
+
const col = columns[active.col];
|
|
2383
|
+
const row = rows[active.row];
|
|
2384
|
+
if (!col || row === void 0) {
|
|
2385
|
+
setEditing(false);
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2388
|
+
const value = castValue(draft, col.type ?? "text");
|
|
2389
|
+
onRowChange?.(row, col.key, value);
|
|
2390
|
+
setEditing(false);
|
|
2391
|
+
if (move === "right") setActive((a) => ({ row: a.row, col: Math.min(colCount - 1, a.col + 1) }));
|
|
2392
|
+
if (move === "down") setActive((a) => ({ row: Math.min(rowCount - 1, a.row + 1), col: a.col }));
|
|
2393
|
+
},
|
|
2394
|
+
[columns, rows, active, draft, onRowChange, colCount, rowCount]
|
|
2395
|
+
);
|
|
2396
|
+
const cancelEdit = useCallback(() => {
|
|
2397
|
+
setEditing(false);
|
|
2398
|
+
}, []);
|
|
2399
|
+
const handleKeyDown = (e) => {
|
|
2400
|
+
if (editing) {
|
|
2401
|
+
if (e.key === "Enter") {
|
|
2402
|
+
e.preventDefault();
|
|
2403
|
+
commitEdit("down");
|
|
2404
|
+
} else if (e.key === "Tab") {
|
|
2405
|
+
e.preventDefault();
|
|
2406
|
+
commitEdit("right");
|
|
2407
|
+
} else if (e.key === "Escape") {
|
|
2408
|
+
e.preventDefault();
|
|
2409
|
+
cancelEdit();
|
|
2410
|
+
}
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
switch (e.key) {
|
|
2414
|
+
case "ArrowRight":
|
|
2415
|
+
e.preventDefault();
|
|
2416
|
+
setActive((a) => ({ row: a.row, col: Math.min(colCount - 1, a.col + 1) }));
|
|
2417
|
+
break;
|
|
2418
|
+
case "ArrowLeft":
|
|
2419
|
+
e.preventDefault();
|
|
2420
|
+
setActive((a) => ({ row: a.row, col: Math.max(0, a.col - 1) }));
|
|
2421
|
+
break;
|
|
2422
|
+
case "ArrowDown":
|
|
2423
|
+
e.preventDefault();
|
|
2424
|
+
setActive((a) => ({ row: Math.min(rowCount - 1, a.row + 1), col: a.col }));
|
|
2425
|
+
break;
|
|
2426
|
+
case "ArrowUp":
|
|
2427
|
+
e.preventDefault();
|
|
2428
|
+
setActive((a) => ({ row: Math.max(0, a.row - 1), col: a.col }));
|
|
2429
|
+
break;
|
|
2430
|
+
case "Home":
|
|
2431
|
+
e.preventDefault();
|
|
2432
|
+
setActive((a) => ({ row: a.row, col: 0 }));
|
|
2433
|
+
break;
|
|
2434
|
+
case "End":
|
|
2435
|
+
e.preventDefault();
|
|
2436
|
+
setActive((a) => ({ row: a.row, col: colCount - 1 }));
|
|
2437
|
+
break;
|
|
2438
|
+
case "Enter":
|
|
2439
|
+
case "F2":
|
|
2440
|
+
e.preventDefault();
|
|
2441
|
+
beginEdit();
|
|
2442
|
+
break;
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2445
|
+
const cellPad = dense ? "px-2 py-1" : "px-3 py-2";
|
|
2446
|
+
return /* @__PURE__ */ jsx(
|
|
2447
|
+
"div",
|
|
2448
|
+
{
|
|
2449
|
+
ref: (el) => {
|
|
2450
|
+
containerRef.current = el;
|
|
2451
|
+
if (typeof ref === "function") ref(el);
|
|
2452
|
+
else if (ref) ref.current = el;
|
|
2453
|
+
},
|
|
2454
|
+
role: "grid",
|
|
2455
|
+
"aria-rowcount": rowCount + 1,
|
|
2456
|
+
"aria-colcount": colCount,
|
|
2457
|
+
tabIndex: 0,
|
|
2458
|
+
onKeyDown: handleKeyDown,
|
|
2459
|
+
className: cn(
|
|
2460
|
+
"overflow-auto rounded-md border border-border bg-card text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
2461
|
+
className
|
|
2462
|
+
),
|
|
2463
|
+
...rest,
|
|
2464
|
+
children: /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse", children: [
|
|
2465
|
+
/* @__PURE__ */ jsx("thead", { role: "rowgroup", children: /* @__PURE__ */ jsx("tr", { role: "row", "aria-rowindex": 1, className: "bg-muted/40", children: columns.map((col, ci) => /* @__PURE__ */ jsx(
|
|
2466
|
+
"th",
|
|
2467
|
+
{
|
|
2468
|
+
role: "columnheader",
|
|
2469
|
+
"aria-colindex": ci + 1,
|
|
2470
|
+
scope: "col",
|
|
2471
|
+
style: { width: col.width, textAlign: col.align ?? "left" },
|
|
2472
|
+
className: cn(
|
|
2473
|
+
"border-b border-border font-medium text-muted-foreground",
|
|
2474
|
+
cellPad
|
|
2475
|
+
),
|
|
2476
|
+
children: col.header
|
|
2477
|
+
},
|
|
2478
|
+
col.key
|
|
2479
|
+
)) }) }),
|
|
2480
|
+
/* @__PURE__ */ jsx("tbody", { role: "rowgroup", children: rows.map((row, ri) => /* @__PURE__ */ jsx("tr", { role: "row", "aria-rowindex": ri + 2, className: "border-b border-border last:border-b-0", children: columns.map((col, ci) => {
|
|
2481
|
+
const isActive = active.row === ri && active.col === ci;
|
|
2482
|
+
const value = col.accessor(row);
|
|
2483
|
+
const isEditable = col.editable !== false;
|
|
2484
|
+
const isEditing = editing && isActive;
|
|
2485
|
+
return /* @__PURE__ */ jsx(
|
|
2486
|
+
"td",
|
|
2487
|
+
{
|
|
2488
|
+
role: "gridcell",
|
|
2489
|
+
"aria-colindex": ci + 1,
|
|
2490
|
+
"aria-readonly": !isEditable || void 0,
|
|
2491
|
+
"aria-selected": isActive || void 0,
|
|
2492
|
+
tabIndex: isActive ? 0 : -1,
|
|
2493
|
+
onClick: () => {
|
|
2494
|
+
setActive({ row: ri, col: ci });
|
|
2495
|
+
if (isEditable && !isEditing) {
|
|
2496
|
+
requestAnimationFrame(() => {
|
|
2497
|
+
const c = columns[ci];
|
|
2498
|
+
if (!c) return;
|
|
2499
|
+
const r = rows[ri];
|
|
2500
|
+
if (r === void 0) return;
|
|
2501
|
+
const raw = c.accessor(r);
|
|
2502
|
+
setDraft(raw == null ? "" : String(raw));
|
|
2503
|
+
setEditing(true);
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
},
|
|
2507
|
+
style: { textAlign: col.align ?? "left" },
|
|
2508
|
+
className: cn(
|
|
2509
|
+
"relative cursor-cell whitespace-nowrap",
|
|
2510
|
+
cellPad,
|
|
2511
|
+
isActive && "bg-primary-soft/40 ring-2 ring-inset ring-primary",
|
|
2512
|
+
!isEditable && "cursor-default"
|
|
2513
|
+
),
|
|
2514
|
+
children: isEditing ? /* @__PURE__ */ jsx(
|
|
2515
|
+
CellEditor,
|
|
2516
|
+
{
|
|
2517
|
+
ref: editRef,
|
|
2518
|
+
col,
|
|
2519
|
+
value: draft,
|
|
2520
|
+
onChange: setDraft,
|
|
2521
|
+
onCommit: commitEdit,
|
|
2522
|
+
onCancel: cancelEdit
|
|
2523
|
+
}
|
|
2524
|
+
) : col.cell ? col.cell(row) : col.type === "boolean" ? /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: value ? "\u2713" : "\xB7" }) : /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: String(value ?? "") })
|
|
2525
|
+
},
|
|
2526
|
+
col.key
|
|
2527
|
+
);
|
|
2528
|
+
}) }, rowKey(row))) })
|
|
2529
|
+
] })
|
|
2530
|
+
}
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
);
|
|
2534
|
+
var CellEditor = forwardRef(
|
|
2535
|
+
function CellEditor2({ col, value, onChange, onCommit, onCancel }, ref) {
|
|
2536
|
+
const baseClass = "h-7 w-full rounded-sm border border-input bg-background px-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
|
2537
|
+
if (col.type === "select" && col.options) {
|
|
2538
|
+
return /* @__PURE__ */ jsx(
|
|
2539
|
+
"select",
|
|
2540
|
+
{
|
|
2541
|
+
ref,
|
|
2542
|
+
value,
|
|
2543
|
+
onChange: (e) => {
|
|
2544
|
+
onChange(e.target.value);
|
|
2545
|
+
onCommit("down");
|
|
2546
|
+
},
|
|
2547
|
+
onBlur: () => onCommit(),
|
|
2548
|
+
onKeyDown: (e) => {
|
|
2549
|
+
if (e.key === "Escape") {
|
|
2550
|
+
e.preventDefault();
|
|
2551
|
+
onCancel();
|
|
2552
|
+
}
|
|
2553
|
+
},
|
|
2554
|
+
className: baseClass,
|
|
2555
|
+
children: col.options.map((opt) => /* @__PURE__ */ jsx("option", { value: String(opt.value), children: String(opt.label) }, String(opt.value)))
|
|
2556
|
+
}
|
|
2557
|
+
);
|
|
2558
|
+
}
|
|
2559
|
+
if (col.type === "boolean") {
|
|
2560
|
+
return /* @__PURE__ */ jsxs(
|
|
2561
|
+
"select",
|
|
2562
|
+
{
|
|
2563
|
+
ref,
|
|
2564
|
+
value,
|
|
2565
|
+
onChange: (e) => {
|
|
2566
|
+
onChange(e.target.value);
|
|
2567
|
+
onCommit("down");
|
|
2568
|
+
},
|
|
2569
|
+
onBlur: () => onCommit(),
|
|
2570
|
+
onKeyDown: (e) => {
|
|
2571
|
+
if (e.key === "Escape") {
|
|
2572
|
+
e.preventDefault();
|
|
2573
|
+
onCancel();
|
|
2574
|
+
}
|
|
2575
|
+
},
|
|
2576
|
+
className: baseClass,
|
|
2577
|
+
children: [
|
|
2578
|
+
/* @__PURE__ */ jsx("option", { value: "true", children: "true" }),
|
|
2579
|
+
/* @__PURE__ */ jsx("option", { value: "false", children: "false" })
|
|
2580
|
+
]
|
|
2581
|
+
}
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2584
|
+
return /* @__PURE__ */ jsx(
|
|
2585
|
+
"input",
|
|
2586
|
+
{
|
|
2587
|
+
ref,
|
|
2588
|
+
type: col.type === "number" ? "number" : "text",
|
|
2589
|
+
value,
|
|
2590
|
+
onChange: (e) => onChange(e.target.value),
|
|
2591
|
+
onBlur: () => onCommit(),
|
|
2592
|
+
onKeyDown: (e) => {
|
|
2593
|
+
if (e.key === "Escape") {
|
|
2594
|
+
e.preventDefault();
|
|
2595
|
+
onCancel();
|
|
2596
|
+
}
|
|
2597
|
+
},
|
|
2598
|
+
className: baseClass
|
|
2599
|
+
}
|
|
2600
|
+
);
|
|
2601
|
+
}
|
|
2602
|
+
);
|
|
2603
|
+
var NodeEditor = forwardRef(function NodeEditor2({
|
|
2604
|
+
nodes,
|
|
2605
|
+
edges = [],
|
|
2606
|
+
onNodesChange,
|
|
2607
|
+
onEdgeClick,
|
|
2608
|
+
renderNode,
|
|
2609
|
+
nodeWidth = 160,
|
|
2610
|
+
nodeHeight = 60,
|
|
2611
|
+
minZoom = 0.25,
|
|
2612
|
+
maxZoom = 2,
|
|
2613
|
+
className,
|
|
2614
|
+
...rest
|
|
2615
|
+
}, ref) {
|
|
2616
|
+
const containerRef = useRef(null);
|
|
2617
|
+
const [viewport, setViewport] = useState({ x: 0, y: 0, zoom: 1 });
|
|
2618
|
+
const dragStateRef = useRef(null);
|
|
2619
|
+
const nodeIndex = useMemo(() => new Map(nodes.map((n) => [n.id, n])), [nodes]);
|
|
2620
|
+
const onContainerPointerDown = (e) => {
|
|
2621
|
+
if (e.button !== 0) return;
|
|
2622
|
+
if (e.target.closest("[data-node]")) return;
|
|
2623
|
+
dragStateRef.current = {
|
|
2624
|
+
kind: "pan",
|
|
2625
|
+
startX: e.clientX,
|
|
2626
|
+
startY: e.clientY,
|
|
2627
|
+
viewportX: viewport.x,
|
|
2628
|
+
viewportY: viewport.y
|
|
2629
|
+
};
|
|
2630
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
2631
|
+
};
|
|
2632
|
+
const onContainerPointerMove = (e) => {
|
|
2633
|
+
const drag = dragStateRef.current;
|
|
2634
|
+
if (!drag) return;
|
|
2635
|
+
if (drag.kind === "pan") {
|
|
2636
|
+
const dx = e.clientX - drag.startX;
|
|
2637
|
+
const dy = e.clientY - drag.startY;
|
|
2638
|
+
setViewport((v) => ({ ...v, x: drag.viewportX + dx, y: drag.viewportY + dy }));
|
|
2639
|
+
} else if (drag.kind === "node") {
|
|
2640
|
+
const dx = (e.clientX - drag.startX) / viewport.zoom;
|
|
2641
|
+
const dy = (e.clientY - drag.startY) / viewport.zoom;
|
|
2642
|
+
const next = nodes.map(
|
|
2643
|
+
(n) => n.id === drag.nodeId ? { ...n, x: drag.nodeStartX + dx, y: drag.nodeStartY + dy } : n
|
|
2644
|
+
);
|
|
2645
|
+
onNodesChange?.(next);
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
const onContainerPointerUp = (e) => {
|
|
2649
|
+
dragStateRef.current = null;
|
|
2650
|
+
e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
2651
|
+
};
|
|
2652
|
+
const onWheel = useCallback(
|
|
2653
|
+
(e) => {
|
|
2654
|
+
e.preventDefault();
|
|
2655
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
2656
|
+
if (!rect) return;
|
|
2657
|
+
const cx = e.clientX - rect.left;
|
|
2658
|
+
const cy = e.clientY - rect.top;
|
|
2659
|
+
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
|
2660
|
+
setViewport((v) => {
|
|
2661
|
+
const nextZoom = Math.max(minZoom, Math.min(maxZoom, v.zoom * factor));
|
|
2662
|
+
const ratio = nextZoom / v.zoom;
|
|
2663
|
+
return {
|
|
2664
|
+
zoom: nextZoom,
|
|
2665
|
+
x: cx - (cx - v.x) * ratio,
|
|
2666
|
+
y: cy - (cy - v.y) * ratio
|
|
2667
|
+
};
|
|
2668
|
+
});
|
|
2669
|
+
},
|
|
2670
|
+
[minZoom, maxZoom]
|
|
2671
|
+
);
|
|
2672
|
+
const beginNodeDrag = (e, node) => {
|
|
2673
|
+
e.stopPropagation();
|
|
2674
|
+
dragStateRef.current = {
|
|
2675
|
+
kind: "node",
|
|
2676
|
+
nodeId: node.id,
|
|
2677
|
+
startX: e.clientX,
|
|
2678
|
+
startY: e.clientY,
|
|
2679
|
+
nodeStartX: node.x,
|
|
2680
|
+
nodeStartY: node.y
|
|
2681
|
+
};
|
|
2682
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
2683
|
+
};
|
|
2684
|
+
const fitView = () => {
|
|
2685
|
+
if (nodes.length === 0) {
|
|
2686
|
+
setViewport({ x: 0, y: 0, zoom: 1 });
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
const minX = Math.min(...nodes.map((n) => n.x));
|
|
2690
|
+
const minY = Math.min(...nodes.map((n) => n.y));
|
|
2691
|
+
const maxX = Math.max(...nodes.map((n) => n.x + nodeWidth));
|
|
2692
|
+
const maxY = Math.max(...nodes.map((n) => n.y + nodeHeight));
|
|
2693
|
+
const w = maxX - minX;
|
|
2694
|
+
const h = maxY - minY;
|
|
2695
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
2696
|
+
if (!rect) return;
|
|
2697
|
+
const padding = 40;
|
|
2698
|
+
const zoomX = (rect.width - padding * 2) / w;
|
|
2699
|
+
const zoomY = (rect.height - padding * 2) / h;
|
|
2700
|
+
const zoom = Math.max(minZoom, Math.min(maxZoom, Math.min(zoomX, zoomY, 1)));
|
|
2701
|
+
setViewport({
|
|
2702
|
+
zoom,
|
|
2703
|
+
x: padding - minX * zoom + (rect.width - padding * 2 - w * zoom) / 2,
|
|
2704
|
+
y: padding - minY * zoom + (rect.height - padding * 2 - h * zoom) / 2
|
|
2705
|
+
});
|
|
2706
|
+
};
|
|
2707
|
+
return /* @__PURE__ */ jsxs(
|
|
2708
|
+
"div",
|
|
2709
|
+
{
|
|
2710
|
+
ref: (el) => {
|
|
2711
|
+
containerRef.current = el;
|
|
2712
|
+
if (typeof ref === "function") ref(el);
|
|
2713
|
+
else if (ref) ref.current = el;
|
|
2714
|
+
},
|
|
2715
|
+
onPointerDown: onContainerPointerDown,
|
|
2716
|
+
onPointerMove: onContainerPointerMove,
|
|
2717
|
+
onPointerUp: onContainerPointerUp,
|
|
2718
|
+
onPointerCancel: onContainerPointerUp,
|
|
2719
|
+
onWheel,
|
|
2720
|
+
className: cn(
|
|
2721
|
+
"relative h-96 w-full overflow-hidden rounded-md border border-border bg-muted/30 select-none",
|
|
2722
|
+
className
|
|
2723
|
+
),
|
|
2724
|
+
...rest,
|
|
2725
|
+
children: [
|
|
2726
|
+
/* @__PURE__ */ jsxs(
|
|
2727
|
+
"div",
|
|
2728
|
+
{
|
|
2729
|
+
className: "absolute inset-0 origin-top-left",
|
|
2730
|
+
style: { transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})` },
|
|
2731
|
+
children: [
|
|
2732
|
+
/* @__PURE__ */ jsx(
|
|
2733
|
+
"svg",
|
|
2734
|
+
{
|
|
2735
|
+
className: "absolute pointer-events-none",
|
|
2736
|
+
style: { overflow: "visible", width: "100%", height: "100%" },
|
|
2737
|
+
children: edges.map((edge) => {
|
|
2738
|
+
const a = nodeIndex.get(edge.source);
|
|
2739
|
+
const b = nodeIndex.get(edge.target);
|
|
2740
|
+
if (!a || !b) return null;
|
|
2741
|
+
const x1 = a.x + nodeWidth;
|
|
2742
|
+
const y1 = a.y + nodeHeight / 2;
|
|
2743
|
+
const x2 = b.x;
|
|
2744
|
+
const y2 = b.y + nodeHeight / 2;
|
|
2745
|
+
const mid = (x1 + x2) / 2;
|
|
2746
|
+
const path = `M${x1},${y1} C${mid},${y1} ${mid},${y2} ${x2},${y2}`;
|
|
2747
|
+
return /* @__PURE__ */ jsxs("g", { className: "pointer-events-auto cursor-pointer", onClick: () => onEdgeClick?.(edge), children: [
|
|
2748
|
+
/* @__PURE__ */ jsx(
|
|
2749
|
+
"path",
|
|
2750
|
+
{
|
|
2751
|
+
d: path,
|
|
2752
|
+
fill: "none",
|
|
2753
|
+
stroke: "currentColor",
|
|
2754
|
+
strokeWidth: 2 / viewport.zoom,
|
|
2755
|
+
className: "text-border-strong hover:text-primary"
|
|
2756
|
+
}
|
|
2757
|
+
),
|
|
2758
|
+
edge.label && /* @__PURE__ */ jsx(
|
|
2759
|
+
"text",
|
|
2760
|
+
{
|
|
2761
|
+
x: mid,
|
|
2762
|
+
y: (y1 + y2) / 2 - 6,
|
|
2763
|
+
textAnchor: "middle",
|
|
2764
|
+
className: "fill-muted-foreground text-[10px]",
|
|
2765
|
+
style: { fontSize: 10 / viewport.zoom },
|
|
2766
|
+
children: edge.label
|
|
2767
|
+
}
|
|
2768
|
+
)
|
|
2769
|
+
] }, edge.id);
|
|
2770
|
+
})
|
|
2771
|
+
}
|
|
2772
|
+
),
|
|
2773
|
+
nodes.map((node) => /* @__PURE__ */ jsx(
|
|
2774
|
+
"div",
|
|
2775
|
+
{
|
|
2776
|
+
"data-node": true,
|
|
2777
|
+
role: "group",
|
|
2778
|
+
"aria-label": typeof node.label === "string" ? node.label : node.id,
|
|
2779
|
+
onPointerDown: (e) => beginNodeDrag(e, node),
|
|
2780
|
+
style: {
|
|
2781
|
+
position: "absolute",
|
|
2782
|
+
left: node.x,
|
|
2783
|
+
top: node.y,
|
|
2784
|
+
width: nodeWidth,
|
|
2785
|
+
height: nodeHeight
|
|
2786
|
+
},
|
|
2787
|
+
className: "cursor-grab active:cursor-grabbing",
|
|
2788
|
+
children: renderNode ? renderNode(node) : /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center rounded-md border border-border bg-card px-3 text-sm font-medium shadow-sm", children: node.label ?? node.id })
|
|
2789
|
+
},
|
|
2790
|
+
node.id
|
|
2791
|
+
))
|
|
2792
|
+
]
|
|
2793
|
+
}
|
|
2794
|
+
),
|
|
2795
|
+
/* @__PURE__ */ jsxs("div", { className: "absolute bottom-3 right-3 flex flex-col gap-1 rounded-md border border-border bg-card p-1 shadow-sm", children: [
|
|
2796
|
+
/* @__PURE__ */ jsx(
|
|
2797
|
+
"button",
|
|
2798
|
+
{
|
|
2799
|
+
type: "button",
|
|
2800
|
+
"aria-label": "Zoom in",
|
|
2801
|
+
onClick: () => setViewport((v) => ({ ...v, zoom: Math.min(maxZoom, v.zoom * 1.2) })),
|
|
2802
|
+
className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
2803
|
+
children: /* @__PURE__ */ jsx(Icon, { icon: Plus, size: 14 })
|
|
2804
|
+
}
|
|
2805
|
+
),
|
|
2806
|
+
/* @__PURE__ */ jsx(
|
|
2807
|
+
"button",
|
|
2808
|
+
{
|
|
2809
|
+
type: "button",
|
|
2810
|
+
"aria-label": "Zoom out",
|
|
2811
|
+
onClick: () => setViewport((v) => ({ ...v, zoom: Math.max(minZoom, v.zoom / 1.2) })),
|
|
2812
|
+
className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
2813
|
+
children: /* @__PURE__ */ jsx(Icon, { icon: Minus, size: 14 })
|
|
2814
|
+
}
|
|
2815
|
+
),
|
|
2816
|
+
/* @__PURE__ */ jsx(
|
|
2817
|
+
"button",
|
|
2818
|
+
{
|
|
2819
|
+
type: "button",
|
|
2820
|
+
"aria-label": "Fit view",
|
|
2821
|
+
onClick: fitView,
|
|
2822
|
+
className: "inline-flex h-7 w-7 items-center justify-center rounded text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
2823
|
+
children: /* @__PURE__ */ jsx(Icon, { icon: Maximize, size: 12 })
|
|
2824
|
+
}
|
|
2825
|
+
)
|
|
2826
|
+
] })
|
|
2827
|
+
]
|
|
2828
|
+
}
|
|
2829
|
+
);
|
|
2830
|
+
});
|
|
1976
2831
|
|
|
1977
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Avatar, AvatarGroup, Badge, BadgeOverlay, Card, Carousel, CarouselDot, CarouselDots, CarouselNext, CarouselPrev, CarouselSlide, CarouselSlides, CarouselViewport, Code, Collapsible, CollapsibleContent, CollapsibleTrigger, CountBadge, DataTable, DescriptionList, EmptyState, Heading, Highlight, Image, InfoRow, Kbd, KeyboardShortcut, List, ListItem, Mark, NotificationDot, Quote, SectionHeader, Separator, Snippet, Stat, Status, SwipeActions, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeaderCell, TableRow, Tabs, TabsList, TabsPanel, TabsTab, Text, Timeline, TimelineDescription, TimelineItem, TimelineTitle, Tooltip, Tree, TreeGroup, TreeItem, avatarVariants, badgeVariants, codeVariants, headingVariants, textVariants };
|
|
1978
|
-
//# sourceMappingURL=chunk-
|
|
1979
|
-
//# sourceMappingURL=chunk-
|
|
2832
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Avatar, AvatarGroup, Badge, BadgeOverlay, Card, Carousel, CarouselDot, CarouselDots, CarouselNext, CarouselPrev, CarouselSlide, CarouselSlides, CarouselViewport, Code, Collapsible, CollapsibleContent, CollapsibleTrigger, CountBadge, DataGrid, DataTable, DescriptionList, DiffViewer, EmptyState, Heading, HeatmapCalendar, Highlight, Image, InfoRow, Kbd, KeyboardShortcut, List, ListItem, Mark, NodeEditor, NotificationDot, Quote, SectionHeader, Separator, Snippet, Sparkline, Stat, Status, SwipeActions, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeaderCell, TableRow, Tabs, TabsList, TabsPanel, TabsTab, Text, Timeline, TimelineDescription, TimelineItem, TimelineTitle, Tooltip, Tree, TreeGroup, TreeItem, avatarVariants, badgeVariants, codeVariants, headingVariants, textVariants };
|
|
2833
|
+
//# sourceMappingURL=chunk-RK6VB3II.js.map
|
|
2834
|
+
//# sourceMappingURL=chunk-RK6VB3II.js.map
|