@asanchez-sa/abby 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/badge/badge.d.ts +3 -2
- package/dist/components/badge/badge.js +27 -11
- package/dist/components/calendar/calendar.d.ts +26 -5
- package/dist/components/calendar/calendar.js +387 -72
- package/dist/components/chart/chart.d.ts +76 -0
- package/dist/components/chart/chart.js +565 -0
- package/dist/components/chart/parts/axes.js +126 -0
- package/dist/components/chart/parts/frame.d.ts +31 -0
- package/dist/components/chart/parts/frame.js +278 -0
- package/dist/components/chart/parts/legend.d.ts +16 -0
- package/dist/components/chart/parts/legend.js +82 -0
- package/dist/components/chart/parts/points.d.ts +1 -0
- package/dist/components/chart/parts/points.js +139 -0
- package/dist/components/chart/parts/scale.js +139 -0
- package/dist/components/chart/parts/table.js +105 -0
- package/dist/components/chart/parts/types.d.ts +44 -0
- package/dist/components/chart/parts/types.js +8 -0
- package/dist/components/filter-chip/filter-chip.d.ts +36 -0
- package/dist/components/filter-chip/filter-chip.js +97 -0
- package/dist/components/graph/graph.d.ts +151 -0
- package/dist/components/graph/graph.js +959 -0
- package/dist/components/model-selector/model-selector.d.ts +38 -3
- package/dist/components/model-selector/model-selector.js +331 -73
- package/dist/components/number-input/number-input.d.ts +14 -3
- package/dist/components/number-input/number-input.js +193 -34
- package/dist/components/spinner/spinner.d.ts +7 -1
- package/dist/components/spinner/spinner.js +86 -26
- package/dist/components/toast/toast.d.ts +19 -2
- package/dist/components/toast/toast.js +211 -49
- package/dist/components/toggle/toggle.d.ts +18 -4
- package/dist/components/toggle/toggle.js +167 -32
- package/dist/components/week-strip/week-strip.d.ts +27 -5
- package/dist/components/week-strip/week-strip.js +288 -134
- package/package.json +4 -1
- package/skills/agent-ready-ui/SKILL.md +1 -1
- package/skills/blocks/SKILL.md +1 -1
- package/skills/compose-screens/SKILL.md +47 -5
- package/skills/compose-screens/references/calendar-week.md +77 -0
- package/skills/compose-screens/references/charts-and-maps.md +183 -0
- package/skills/compose-screens/references/filter-chips.md +61 -0
- package/skills/compose-screens/references/number-units.md +52 -0
- package/skills/note-editor/SKILL.md +1 -1
- package/skills/note-status/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/components/chart/parts/scale.ts
|
|
2
|
+
/** Room above the tallest bar, as in Alma's chart. */
|
|
3
|
+
const topGap = 3;
|
|
4
|
+
const steps = [
|
|
5
|
+
1,
|
|
6
|
+
2,
|
|
7
|
+
2.5,
|
|
8
|
+
5,
|
|
9
|
+
10
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* A round top for the scale and its ticks: 3 to 5 evenly spaced marks from 0.
|
|
13
|
+
* A chart with nothing to show (no values, or all of them zero) still gets a
|
|
14
|
+
* scale from 0 to 1, so the grid has somewhere to be.
|
|
15
|
+
*/
|
|
16
|
+
function niceScale(largest, wanted = 4) {
|
|
17
|
+
if (!(largest > 0) || !Number.isFinite(largest)) return {
|
|
18
|
+
max: 1,
|
|
19
|
+
ticks: [
|
|
20
|
+
0,
|
|
21
|
+
.5,
|
|
22
|
+
1
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
const raw = largest / Math.max(1, wanted - 1);
|
|
26
|
+
const power = 10 ** Math.floor(Math.log10(raw));
|
|
27
|
+
const step = (steps.find((each) => each * power >= raw) ?? 10) * power;
|
|
28
|
+
const count = Math.ceil(largest / step - 1e-9);
|
|
29
|
+
const ticks = Array.from({ length: count + 1 }, (_, index) => Number((index * step).toPrecision(12)));
|
|
30
|
+
return {
|
|
31
|
+
max: ticks[ticks.length - 1] ?? step,
|
|
32
|
+
ticks
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** A value that can be drawn: a finite number. */
|
|
36
|
+
function present(value) {
|
|
37
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What a category adds up to when its series are stacked: the sum of its
|
|
41
|
+
* values. A value that isn't above zero adds nothing, since a bar can't go
|
|
42
|
+
* below its baseline.
|
|
43
|
+
*/
|
|
44
|
+
function stackTotal(row, series) {
|
|
45
|
+
let total = 0;
|
|
46
|
+
for (const each of series) {
|
|
47
|
+
const value = row.values[each.key];
|
|
48
|
+
if (present(value) && value > 0) total += value;
|
|
49
|
+
}
|
|
50
|
+
return total;
|
|
51
|
+
}
|
|
52
|
+
function plotScale(rows, series, height, override, options = {}) {
|
|
53
|
+
let largest = 0;
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
if (options.stack) {
|
|
56
|
+
largest = Math.max(largest, stackTotal(row, series));
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (const each of series) {
|
|
60
|
+
const value = row.values[each.key];
|
|
61
|
+
if (present(value) && value > largest) largest = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let min = 0;
|
|
65
|
+
let { max, ticks } = niceScale(override ?? largest);
|
|
66
|
+
if (options.domain) {
|
|
67
|
+
const [first, second] = options.domain;
|
|
68
|
+
min = Math.min(first, second);
|
|
69
|
+
const top = Math.max(first, second);
|
|
70
|
+
max = top > min ? top : min + 1;
|
|
71
|
+
ticks = [
|
|
72
|
+
min,
|
|
73
|
+
(min + max) / 2,
|
|
74
|
+
max
|
|
75
|
+
].map((tick) => Number(tick.toPrecision(12)));
|
|
76
|
+
}
|
|
77
|
+
const top = topGap + (options.room ?? 0);
|
|
78
|
+
const baseline = height - 1 - (options.bottom ?? 0);
|
|
79
|
+
const usable = Math.max(0, baseline - top);
|
|
80
|
+
return {
|
|
81
|
+
max,
|
|
82
|
+
ticks,
|
|
83
|
+
height,
|
|
84
|
+
top,
|
|
85
|
+
baseline,
|
|
86
|
+
min,
|
|
87
|
+
rise: (value) => {
|
|
88
|
+
if (!Number.isFinite(value) || value <= min) return 0;
|
|
89
|
+
return Math.min(usable, (value - min) / (max - min) * usable);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The category's identity, which `highlight` names. */
|
|
94
|
+
function rowId(row) {
|
|
95
|
+
return row.id ?? row.label;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The categories that get a label on the x axis: at most `wanted` of them,
|
|
99
|
+
* evenly spaced, so two never touch. The highlighted one is always labeled,
|
|
100
|
+
* and the labels next to it make room for it.
|
|
101
|
+
*/
|
|
102
|
+
function labelIndices(count, wanted, highlighted = -1) {
|
|
103
|
+
if (count <= 0) return [];
|
|
104
|
+
const stride = Math.max(1, Math.ceil(count / Math.max(1, wanted)));
|
|
105
|
+
const shown = [];
|
|
106
|
+
for (let index = 0; index < count; index += stride) {
|
|
107
|
+
if (highlighted >= 0 && index !== highlighted && Math.abs(index - highlighted) < stride) continue;
|
|
108
|
+
shown.push(index);
|
|
109
|
+
}
|
|
110
|
+
if (highlighted >= 0 && !shown.includes(highlighted)) shown.push(highlighted);
|
|
111
|
+
return shown.sort((a, b) => a - b);
|
|
112
|
+
}
|
|
113
|
+
const tokens = /* @__PURE__ */ new Set([
|
|
114
|
+
"chart-1",
|
|
115
|
+
"chart-2",
|
|
116
|
+
"chart-3",
|
|
117
|
+
"chart-4",
|
|
118
|
+
"chart-5",
|
|
119
|
+
"primary",
|
|
120
|
+
"muted",
|
|
121
|
+
"warning",
|
|
122
|
+
"success",
|
|
123
|
+
"destructive"
|
|
124
|
+
]);
|
|
125
|
+
/** The CSS color of a series: its token's variable, or the app's own color. */
|
|
126
|
+
function seriesColor(series, index) {
|
|
127
|
+
const color = series.color ?? `chart-${index % 5 + 1}`;
|
|
128
|
+
return tokens.has(color) ? `var(--${color})` : color;
|
|
129
|
+
}
|
|
130
|
+
/** The faint version of a color: Alma's tint, the color at 20%. */
|
|
131
|
+
function tintOf(color) {
|
|
132
|
+
return `color-mix(in srgb, ${color} 20%, transparent)`;
|
|
133
|
+
}
|
|
134
|
+
/** Formats a value with `Intl.NumberFormat`; a missing one is `missing`. */
|
|
135
|
+
function valueFormatter(locale, options) {
|
|
136
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
137
|
+
return (value, missing) => typeof value === "number" && Number.isFinite(value) ? formatter.format(value) : missing;
|
|
138
|
+
}
|
|
139
|
+
export { labelIndices, niceScale, plotScale, rowId, seriesColor, stackTotal, tintOf, valueFormatter };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { stackTotal } from "./scale.js";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/chart/parts/table.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The same data as a table, hidden from sight: categories down, series across.
|
|
8
|
+
* The bars give each value one at a time; this is how a screen reader reads
|
|
9
|
+
* the whole chart. It has one row per category, whatever the data holds.
|
|
10
|
+
*/
|
|
11
|
+
function ChartTable(t0) {
|
|
12
|
+
const $ = c(27);
|
|
13
|
+
const { rows, series, categoryHeader, missing, format, name, totalHeader } = t0;
|
|
14
|
+
let t1;
|
|
15
|
+
if ($[0] !== categoryHeader) {
|
|
16
|
+
t1 = /* @__PURE__ */ jsx("th", {
|
|
17
|
+
scope: "col",
|
|
18
|
+
children: categoryHeader
|
|
19
|
+
});
|
|
20
|
+
$[0] = categoryHeader;
|
|
21
|
+
$[1] = t1;
|
|
22
|
+
} else t1 = $[1];
|
|
23
|
+
let t2;
|
|
24
|
+
if ($[2] !== series) {
|
|
25
|
+
t2 = series.map(_temp);
|
|
26
|
+
$[2] = series;
|
|
27
|
+
$[3] = t2;
|
|
28
|
+
} else t2 = $[3];
|
|
29
|
+
let t3;
|
|
30
|
+
if ($[4] !== totalHeader) {
|
|
31
|
+
t3 = totalHeader === void 0 ? null : /* @__PURE__ */ jsx("th", {
|
|
32
|
+
scope: "col",
|
|
33
|
+
children: totalHeader
|
|
34
|
+
});
|
|
35
|
+
$[4] = totalHeader;
|
|
36
|
+
$[5] = t3;
|
|
37
|
+
} else t3 = $[5];
|
|
38
|
+
let t4;
|
|
39
|
+
if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3) {
|
|
40
|
+
t4 = /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
41
|
+
t1,
|
|
42
|
+
t2,
|
|
43
|
+
t3
|
|
44
|
+
] }) });
|
|
45
|
+
$[6] = t1;
|
|
46
|
+
$[7] = t2;
|
|
47
|
+
$[8] = t3;
|
|
48
|
+
$[9] = t4;
|
|
49
|
+
} else t4 = $[9];
|
|
50
|
+
let t5;
|
|
51
|
+
if ($[10] !== format || $[11] !== missing || $[12] !== rows || $[13] !== series || $[14] !== totalHeader) {
|
|
52
|
+
let t6;
|
|
53
|
+
if ($[16] !== format || $[17] !== missing || $[18] !== series || $[19] !== totalHeader) {
|
|
54
|
+
t6 = (row, index) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
55
|
+
/* @__PURE__ */ jsx("th", {
|
|
56
|
+
scope: "row",
|
|
57
|
+
children: row.label
|
|
58
|
+
}),
|
|
59
|
+
series.map((each_0) => /* @__PURE__ */ jsx("td", { children: format(row.values[each_0.key], missing) }, each_0.key)),
|
|
60
|
+
totalHeader === void 0 ? null : /* @__PURE__ */ jsx("td", { children: format(stackTotal(row, series), missing) })
|
|
61
|
+
] }, `${row.id ?? row.label}-${index}`);
|
|
62
|
+
$[16] = format;
|
|
63
|
+
$[17] = missing;
|
|
64
|
+
$[18] = series;
|
|
65
|
+
$[19] = totalHeader;
|
|
66
|
+
$[20] = t6;
|
|
67
|
+
} else t6 = $[20];
|
|
68
|
+
t5 = rows.map(t6);
|
|
69
|
+
$[10] = format;
|
|
70
|
+
$[11] = missing;
|
|
71
|
+
$[12] = rows;
|
|
72
|
+
$[13] = series;
|
|
73
|
+
$[14] = totalHeader;
|
|
74
|
+
$[15] = t5;
|
|
75
|
+
} else t5 = $[15];
|
|
76
|
+
let t6;
|
|
77
|
+
if ($[21] !== t5) {
|
|
78
|
+
t6 = /* @__PURE__ */ jsx("tbody", { children: t5 });
|
|
79
|
+
$[21] = t5;
|
|
80
|
+
$[22] = t6;
|
|
81
|
+
} else t6 = $[22];
|
|
82
|
+
let t7;
|
|
83
|
+
if ($[23] !== name || $[24] !== t4 || $[25] !== t6) {
|
|
84
|
+
t7 = /* @__PURE__ */ jsx("div", {
|
|
85
|
+
"data-slot": "chart-table",
|
|
86
|
+
className: "sr-only",
|
|
87
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
88
|
+
...name,
|
|
89
|
+
children: [t4, t6]
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
$[23] = name;
|
|
93
|
+
$[24] = t4;
|
|
94
|
+
$[25] = t6;
|
|
95
|
+
$[26] = t7;
|
|
96
|
+
} else t7 = $[26];
|
|
97
|
+
return t7;
|
|
98
|
+
}
|
|
99
|
+
function _temp(each) {
|
|
100
|
+
return /* @__PURE__ */ jsx("th", {
|
|
101
|
+
scope: "col",
|
|
102
|
+
children: each.name
|
|
103
|
+
}, each.key);
|
|
104
|
+
}
|
|
105
|
+
export { ChartTable };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A theme color token a series can take by name. */
|
|
2
|
+
export type ChartToken = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5" | "primary" | "muted" | "warning" | "success" | "destructive";
|
|
3
|
+
/** A token, or any CSS color the app passes (an area's color, `var(--area)`). */
|
|
4
|
+
export type ChartColor = ChartToken | (string & {});
|
|
5
|
+
export type ChartSeries = {
|
|
6
|
+
/** The key of this series' value in each row's `values`. */
|
|
7
|
+
key: string;
|
|
8
|
+
/** The name read in the tooltip, the table and the screen reader. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Defaults to `chart-1` … `chart-5`, in the order of `series`. */
|
|
11
|
+
color?: ChartColor;
|
|
12
|
+
/**
|
|
13
|
+
* `forecast` draws what hasn't happened yet: a dashed outline over a faint
|
|
14
|
+
* fill. It shares the column of the first series instead of taking one.
|
|
15
|
+
*/
|
|
16
|
+
variant?: "default" | "forecast";
|
|
17
|
+
};
|
|
18
|
+
export type ChartRow = {
|
|
19
|
+
/** The category's text: the x label, and the start of a bar's name. */
|
|
20
|
+
label: string;
|
|
21
|
+
/** Identifies the category for `highlight`. Defaults to `label`. */
|
|
22
|
+
id?: string;
|
|
23
|
+
/** One value per series key. A missing or `null` value draws no bar. */
|
|
24
|
+
values: Record<string, number | null | undefined>;
|
|
25
|
+
};
|
|
26
|
+
/** A chart is named by one of these, and it's required. */
|
|
27
|
+
export type ChartName = {
|
|
28
|
+
"aria-label": string;
|
|
29
|
+
"aria-labelledby"?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
"aria-label"?: undefined;
|
|
32
|
+
"aria-labelledby": string;
|
|
33
|
+
};
|
|
34
|
+
/** The texts a chart shows when the app doesn't replace them. */
|
|
35
|
+
export type ChartTexts = {
|
|
36
|
+
/** Shown instead of the plot when `data` is empty. */
|
|
37
|
+
empty?: string;
|
|
38
|
+
/** The header of the table's first column. */
|
|
39
|
+
categoryHeader?: string;
|
|
40
|
+
/** What the table shows for a value that is missing. */
|
|
41
|
+
missing?: string;
|
|
42
|
+
/** The header of the table's total column, when the bars are stacked. */
|
|
43
|
+
totalHeader?: string;
|
|
44
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChangeDetails } from "../../core/ui-sdk.js";
|
|
2
|
+
import "../../core/index.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
type FilterChipItem = string | {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type FilterChipProps = Omit<ComponentProps<"div">, "onChange" | "children" | "defaultValue"> & {
|
|
10
|
+
/** The options, one of them chosen. A string is an option whose label and value match. */
|
|
11
|
+
items: FilterChipItem[];
|
|
12
|
+
/** The chosen value. */
|
|
13
|
+
value?: string;
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
/** Runs when a choice wants to change. `details.cancel()` keeps the current one. */
|
|
16
|
+
onValueChange?: (value: string, details: ChangeDetails<string>) => void;
|
|
17
|
+
/** The value that means "no filter". The chip is active while the value is any other. */
|
|
18
|
+
allValue: string;
|
|
19
|
+
/** What the filter is, in grey before the value: "Persona". Its colon is yours to write. */
|
|
20
|
+
prefix?: string;
|
|
21
|
+
/** Draws a chevron after the value. */
|
|
22
|
+
chevron?: boolean;
|
|
23
|
+
/** A CSS color, the area's, for the small square before the value while the chip is active. */
|
|
24
|
+
color?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Shows a × while the chip is active. The × goes back to `allValue` through
|
|
27
|
+
* `onValueChange` (reason `"clear-press"`, which can cancel it), controlled
|
|
28
|
+
* or not, and then runs `onClear`.
|
|
29
|
+
*/
|
|
30
|
+
onClear?: () => void;
|
|
31
|
+
/** The × button's name. Give each chip its own when a page holds several. */
|
|
32
|
+
clearLabel?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
};
|
|
35
|
+
declare function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel, disabled, className, ...props }: FilterChipProps): import("react").JSX.Element;
|
|
36
|
+
export { FilterChip, type FilterChipItem, type FilterChipProps };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utilities/cn/index.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { Menu, MenuContent, MenuItemIndicator, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../menu/menu.js";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { ArrowDown01Icon, Cancel01Icon } from "@hugeicons/core-free-icons";
|
|
9
|
+
// src/components/filter-chip/filter-chip.tsx
|
|
10
|
+
const trigger = [
|
|
11
|
+
"flex h-full min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-full ps-2.5 pe-2.5 text-sm outline-none select-none",
|
|
12
|
+
"transition-colors motion-reduce:transition-none hover:bg-accent data-open:bg-accent",
|
|
13
|
+
"disabled:pointer-events-none"
|
|
14
|
+
];
|
|
15
|
+
function FilterChip({ items, value, defaultValue, onValueChange, allValue, prefix, chevron, color, onClear, clearLabel = "Clear filter", disabled, className, ...props }) {
|
|
16
|
+
const [own, setOwn] = useState(defaultValue ?? allValue);
|
|
17
|
+
const current = value ?? own;
|
|
18
|
+
const options = items.map((item) => typeof item === "string" ? {
|
|
19
|
+
value: item,
|
|
20
|
+
label: item
|
|
21
|
+
} : item);
|
|
22
|
+
const label = options.find((option) => option.value === current)?.label ?? current;
|
|
23
|
+
const active = current !== allValue;
|
|
24
|
+
function clear(event, press) {
|
|
25
|
+
let canceled = false;
|
|
26
|
+
const details = {
|
|
27
|
+
reason: "clear-press",
|
|
28
|
+
event: event.nativeEvent,
|
|
29
|
+
source: press.source,
|
|
30
|
+
cancel: () => {
|
|
31
|
+
canceled = true;
|
|
32
|
+
},
|
|
33
|
+
get canceled() {
|
|
34
|
+
return canceled;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
onValueChange?.(allValue, details);
|
|
38
|
+
if (details.canceled) return;
|
|
39
|
+
setOwn(allValue);
|
|
40
|
+
onClear?.();
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
43
|
+
"data-slot": "filter-chip",
|
|
44
|
+
"data-active": active ? "" : void 0,
|
|
45
|
+
"data-disabled": disabled ? "" : void 0,
|
|
46
|
+
className: cn("inline-flex h-7 max-w-full items-center rounded-full border border-input text-sm text-foreground transition-colors focus-ring-within motion-reduce:transition-none data-active:border-ring data-disabled:opacity-50", className),
|
|
47
|
+
...props,
|
|
48
|
+
children: [/* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsxs(MenuTrigger, {
|
|
49
|
+
disabled,
|
|
50
|
+
className: cn(trigger),
|
|
51
|
+
children: [
|
|
52
|
+
prefix && /* @__PURE__ */ jsxs("span", {
|
|
53
|
+
className: "shrink-0 text-muted-foreground",
|
|
54
|
+
children: [prefix, " "]
|
|
55
|
+
}),
|
|
56
|
+
active && color && /* @__PURE__ */ jsx("span", {
|
|
57
|
+
"aria-hidden": "true",
|
|
58
|
+
"data-slot": "filter-chip-color",
|
|
59
|
+
className: "size-2 shrink-0 rounded-2xs",
|
|
60
|
+
style: { backgroundColor: color }
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("span", {
|
|
63
|
+
className: cn("truncate", active && "font-medium"),
|
|
64
|
+
children: label
|
|
65
|
+
}),
|
|
66
|
+
chevron && /* @__PURE__ */ jsx(Icon, {
|
|
67
|
+
icon: ArrowDown01Icon,
|
|
68
|
+
className: "size-2.5 text-muted-foreground"
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
}), /* @__PURE__ */ jsx(MenuContent, { children: /* @__PURE__ */ jsx(MenuRadioGroup, {
|
|
72
|
+
value: current,
|
|
73
|
+
onValueChange: (next, details_0) => {
|
|
74
|
+
onValueChange?.(next, details_0);
|
|
75
|
+
if (!details_0.canceled) setOwn(next);
|
|
76
|
+
},
|
|
77
|
+
children: options.map((option_0) => /* @__PURE__ */ jsxs(MenuRadioItem, {
|
|
78
|
+
value: option_0.value,
|
|
79
|
+
disabled: option_0.disabled,
|
|
80
|
+
closeOnSelect: true,
|
|
81
|
+
children: [option_0.label, /* @__PURE__ */ jsx(MenuItemIndicator, {})]
|
|
82
|
+
}, option_0.value))
|
|
83
|
+
}) })] }), active && onClear && /* @__PURE__ */ jsx(Button, {
|
|
84
|
+
variant: "ghost",
|
|
85
|
+
size: "icon-xs",
|
|
86
|
+
"aria-label": clearLabel,
|
|
87
|
+
disabled,
|
|
88
|
+
onClick: clear,
|
|
89
|
+
className: "me-px shrink-0",
|
|
90
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
91
|
+
icon: Cancel01Icon,
|
|
92
|
+
className: "size-3"
|
|
93
|
+
})
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export { FilterChip };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ChangeDetails, PartProps } from "../../core/ui-sdk.js";
|
|
2
|
+
import "../../core/index.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
/** The colors a node's swatch can take. A swatch never says something by color alone: the name does. */
|
|
5
|
+
type GraphTone = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5";
|
|
6
|
+
/** How a line looks: `solid`, `dashed` (weaker) or `warning` (dashed and amber, for a clash). */
|
|
7
|
+
type GraphEdgeVariant = "solid" | "dashed" | "warning";
|
|
8
|
+
type GraphNodeData = {
|
|
9
|
+
/** Unique within the graph. A repeated id is ignored. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** What the node says, and its accessible name. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** The node's center, in map units (px at zoom 1). Larger `y` is farther down. */
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
/** A swatch before `meta`. */
|
|
17
|
+
color?: GraphTone;
|
|
18
|
+
/** A second, quieter line, like who wrote it and when. */
|
|
19
|
+
meta?: string;
|
|
20
|
+
/** The node the map is about: wider, with a firmer edge. */
|
|
21
|
+
current?: boolean;
|
|
22
|
+
/** A node that was replaced: its name is struck through and faded. */
|
|
23
|
+
replaced?: boolean;
|
|
24
|
+
};
|
|
25
|
+
type GraphEdgeData = {
|
|
26
|
+
/** The id of the node the line starts at. */
|
|
27
|
+
from: string;
|
|
28
|
+
/** The id of the node the line ends at. */
|
|
29
|
+
to: string;
|
|
30
|
+
/** Said on the line, and in the text list: "Contradicts". */
|
|
31
|
+
label?: string;
|
|
32
|
+
/** The line's width in px, 1.2 by default. Under 1.2 the line is fainter. */
|
|
33
|
+
weight?: number;
|
|
34
|
+
/** `solid` by default. */
|
|
35
|
+
variant?: GraphEdgeVariant;
|
|
36
|
+
};
|
|
37
|
+
type GraphChangeReason = "item-press" | "imperative";
|
|
38
|
+
/** Drives a graph from anywhere. Pass it as the `controller` prop. */
|
|
39
|
+
type GraphController = {
|
|
40
|
+
/** The selected node's id, or `null`. */
|
|
41
|
+
getSelected: () => string | null;
|
|
42
|
+
/** Selects a node, or clears the selection with `null`. False when the node doesn't exist or the app refused it. */
|
|
43
|
+
setSelected: (id: string | null) => boolean;
|
|
44
|
+
/** The zoom now, from 0.5 to 2. */
|
|
45
|
+
getZoom: () => number;
|
|
46
|
+
/** Zooms in a step. */
|
|
47
|
+
zoomIn: () => boolean;
|
|
48
|
+
/** Zooms out a step. */
|
|
49
|
+
zoomOut: () => boolean;
|
|
50
|
+
/** Focuses a node, or the one with the tab stop. */
|
|
51
|
+
focus: (id?: string) => void;
|
|
52
|
+
};
|
|
53
|
+
type GraphOptions = {
|
|
54
|
+
/** The selected node's id, or `null`. Pass it to control the graph. */
|
|
55
|
+
selected?: string | null;
|
|
56
|
+
/** The node selected at first, when uncontrolled. */
|
|
57
|
+
defaultSelected?: string | null;
|
|
58
|
+
/** Runs when a node is pressed, with Enter too, or a controller or agent selects one. `details.cancel()` keeps the selection. */
|
|
59
|
+
onSelectedChange?: (id: string | null, details: ChangeDetails<GraphChangeReason>) => void;
|
|
60
|
+
/** The points. The app places them: this component never moves them. */
|
|
61
|
+
nodes?: readonly GraphNodeData[];
|
|
62
|
+
/** The lines. One that names a node that isn't in `nodes`, or the same one twice, is ignored. */
|
|
63
|
+
edges?: readonly GraphEdgeData[];
|
|
64
|
+
/** Drives the graph from anywhere. Create one with `createGraphController()`. */
|
|
65
|
+
controller?: GraphController;
|
|
66
|
+
};
|
|
67
|
+
type GraphRootState = {
|
|
68
|
+
selected: string | null;
|
|
69
|
+
zoom: number;
|
|
70
|
+
};
|
|
71
|
+
type GraphNodeState = {
|
|
72
|
+
id: string;
|
|
73
|
+
node: GraphNodeData;
|
|
74
|
+
selected: boolean;
|
|
75
|
+
};
|
|
76
|
+
type GraphZoomState = {
|
|
77
|
+
/** Whether the zoom is already at its limit in this direction. */
|
|
78
|
+
disabled: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** Drives a graph from anywhere: pass it as `controller`. */
|
|
81
|
+
declare function createGraphController(): GraphController;
|
|
82
|
+
/**
|
|
83
|
+
* The graph's state and the methods that change it, for a component inside
|
|
84
|
+
* `Graph`. It re-renders when the state changes.
|
|
85
|
+
*/
|
|
86
|
+
declare function useGraph(): {
|
|
87
|
+
selected: string | null;
|
|
88
|
+
zoom: number;
|
|
89
|
+
nodes: GraphNodeData[];
|
|
90
|
+
edges: GraphEdgeData[];
|
|
91
|
+
setSelected: (id: string | null) => boolean;
|
|
92
|
+
zoomIn: () => boolean;
|
|
93
|
+
zoomOut: () => boolean;
|
|
94
|
+
focus: (id?: string) => void;
|
|
95
|
+
};
|
|
96
|
+
type GraphProps = GraphOptions & Omit<PartProps<"div", GraphRootState>, "defaultValue"> & {
|
|
97
|
+
/** Names the graph for screen readers and agents. Set it in the page's language. */
|
|
98
|
+
label?: string;
|
|
99
|
+
};
|
|
100
|
+
/** Without children it renders the canvas, the zoom buttons, the legend and the text list. */
|
|
101
|
+
declare function Graph({ selected, defaultSelected, onSelectedChange, nodes, edges, controller, label, className, children, ...props }: GraphProps): import("react").JSX.Element | null;
|
|
102
|
+
/**
|
|
103
|
+
* The map: the lines and their labels under the nodes. It scrolls when the
|
|
104
|
+
* zoomed map is bigger than its box. The box takes its height from `className`.
|
|
105
|
+
*/
|
|
106
|
+
declare function GraphCanvas({ className, children }: {
|
|
107
|
+
className?: string;
|
|
108
|
+
children?: ReactNode;
|
|
109
|
+
}): import("react").JSX.Element;
|
|
110
|
+
type GraphNodeProps = Omit<PartProps<"button", GraphNodeState>, "value"> & {
|
|
111
|
+
/** The node's id. */
|
|
112
|
+
value: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* One node, a button named by the node's name. Without children it draws the
|
|
116
|
+
* name and, under it, the swatch and `meta`. A `value` that isn't in `nodes`
|
|
117
|
+
* draws nothing, so an app's own list can lag a render behind.
|
|
118
|
+
*/
|
|
119
|
+
declare function GraphNode(props: GraphNodeProps): import("react").JSX.Element | null;
|
|
120
|
+
type GraphZoomProps = {
|
|
121
|
+
className?: string;
|
|
122
|
+
/** The zoom-in button's accessible name. Set it in the page's language. */
|
|
123
|
+
zoomInLabel?: string;
|
|
124
|
+
/** The zoom-out button's accessible name. Set it in the page's language. */
|
|
125
|
+
zoomOutLabel?: string;
|
|
126
|
+
};
|
|
127
|
+
/** The + and − buttons, stacked at the map's end corner. The keys + and − zoom too. */
|
|
128
|
+
declare function GraphZoom({ className, zoomInLabel, zoomOutLabel }: GraphZoomProps): import("react").JSX.Element;
|
|
129
|
+
type GraphLegendProps = {
|
|
130
|
+
className?: string;
|
|
131
|
+
/** The styles to name, in order. All three by default. */
|
|
132
|
+
variants?: readonly GraphEdgeVariant[];
|
|
133
|
+
/** What each style means. Set them in the page's language. */
|
|
134
|
+
labels?: Partial<Record<GraphEdgeVariant, ReactNode>>;
|
|
135
|
+
/** The legend's accessible name. */
|
|
136
|
+
label?: string;
|
|
137
|
+
};
|
|
138
|
+
/** Names each line style with a sample of it, at the map's start corner. */
|
|
139
|
+
declare function GraphLegend({ className, variants, labels, label }: GraphLegendProps): import("react").JSX.Element;
|
|
140
|
+
type GraphListProps = {
|
|
141
|
+
/** What a node without a label on its lines says: "Related to". */
|
|
142
|
+
relatedLabel?: string;
|
|
143
|
+
/** The list's accessible name. */
|
|
144
|
+
label?: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* The same map as text, for people who read it with a screen reader: every
|
|
148
|
+
* node once, with its lines as "Contradicts: Other node". Hidden from sight.
|
|
149
|
+
*/
|
|
150
|
+
declare function GraphList({ relatedLabel, label }: GraphListProps): import("react").JSX.Element;
|
|
151
|
+
export { Graph, GraphCanvas, type GraphChangeReason, type GraphController, type GraphEdgeData, type GraphEdgeVariant, GraphLegend, type GraphLegendProps, GraphList, type GraphListProps, GraphNode, type GraphNodeData, type GraphNodeProps, type GraphNodeState, type GraphOptions, type GraphProps, type GraphRootState, type GraphTone, GraphZoom, type GraphZoomProps, type GraphZoomState, createGraphController, useGraph };
|