@nextlyhq/ui 0.0.2-alpha.73 → 0.0.2-alpha.74
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/index.cjs +997 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +192 -1
- package/dist/index.d.ts +192 -1
- package/dist/index.mjs +995 -10
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/theme.css +117 -82
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -56,11 +56,11 @@ let _radix_ui_react_select = require("@radix-ui/react-select");
|
|
|
56
56
|
_radix_ui_react_select = __toESM(_radix_ui_react_select, 1);
|
|
57
57
|
let cmdk = require("cmdk");
|
|
58
58
|
let sonner = require("sonner");
|
|
59
|
+
let _tanstack_react_virtual = require("@tanstack/react-virtual");
|
|
59
60
|
let _radix_ui_react_context_menu = require("@radix-ui/react-context-menu");
|
|
60
61
|
_radix_ui_react_context_menu = __toESM(_radix_ui_react_context_menu, 1);
|
|
61
62
|
let react_resizable_panels = require("react-resizable-panels");
|
|
62
63
|
react_resizable_panels = __toESM(react_resizable_panels, 1);
|
|
63
|
-
let _tanstack_react_virtual = require("@tanstack/react-virtual");
|
|
64
64
|
let _radix_ui_react_slider = require("@radix-ui/react-slider");
|
|
65
65
|
_radix_ui_react_slider = __toESM(_radix_ui_react_slider, 1);
|
|
66
66
|
// src/lib/utils.ts
|
|
@@ -98,7 +98,7 @@ function cn(...inputs) {
|
|
|
98
98
|
* Note: 'primary' is a semantic alias for 'default' variant for better code readability
|
|
99
99
|
* @experimental
|
|
100
100
|
*/
|
|
101
|
-
const buttonVariants = (0, class_variance_authority.cva)(
|
|
101
|
+
const buttonVariants = (0, class_variance_authority.cva)(`inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium cursor-pointer transition-all duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring [.overflow-hidden>&]:focus-visible:outline-offset-[-2px] [.overflow-hidden>&]:focus-visible:shadow-[inset_0_0_0_4px_var(--nx-background)] disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed active:scale-[0.98] [&_svg]:text-current`, {
|
|
102
102
|
variants: {
|
|
103
103
|
variant: {
|
|
104
104
|
default: "bg-primary text-primary-foreground border border-transparent hover:opacity-90",
|
|
@@ -1411,7 +1411,7 @@ const TabsList = (0, react.forwardRef)(({ className, variant, scrollable = false
|
|
|
1411
1411
|
});
|
|
1412
1412
|
});
|
|
1413
1413
|
TabsList.displayName = _radix_ui_react_tabs.List.displayName;
|
|
1414
|
-
const tabsTriggerVariants = (0, class_variance_authority.cva)("inline-flex items-center justify-center whitespace-nowrap rounded-none bg-transparent px-4 py-2 font-medium cursor-pointer transition-all duration-200 border-b-2 relative -mb-0.5 data-[state=active]:border-b-primary data-[state=active]:text-
|
|
1414
|
+
const tabsTriggerVariants = (0, class_variance_authority.cva)("inline-flex items-center justify-center whitespace-nowrap rounded-none bg-transparent px-4 py-2 font-medium cursor-pointer transition-all duration-200 border-b-2 relative -mb-0.5 data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=inactive]:border-transparent data-[state=inactive]:text-muted-foreground hover:text-foreground hover:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed data-[orientation=vertical]:border-b-0 data-[orientation=vertical]:mb-0 data-[orientation=vertical]:border-r-2 data-[orientation=vertical]:-mr-0.5 data-[orientation=vertical]:data-[state=active]:border-r-primary", {
|
|
1415
1415
|
variants: { size: {
|
|
1416
1416
|
default: "text-sm",
|
|
1417
1417
|
sm: "text-xs"
|
|
@@ -2422,7 +2422,7 @@ const CommandDialog = ({ children, commandProps, contentProps, ...props }) => {
|
|
|
2422
2422
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CommandDialogOverlay, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dialog.Content, {
|
|
2423
2423
|
...contentProps,
|
|
2424
2424
|
"data-slot": "command-content",
|
|
2425
|
-
className: cn("fixed left-[50%] top-[
|
|
2425
|
+
className: cn("fixed left-[50%] top-[13vh] z-[100] translate-x-[-50%]", "w-full max-w-lg", "max-h-[80vh]", "sm:max-w-lg", "max-w-full", "m-4 sm:m-0", "overflow-hidden rounded-lg border border-border bg-background shadow-xl", "duration-200", "data-[state=open]:animate-in data-[state=closed]:animate-out", "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95", "data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2"),
|
|
2426
2426
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Command, {
|
|
2427
2427
|
...commandProps,
|
|
2428
2428
|
className: cn("[&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:mb-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4", commandProps?.className),
|
|
@@ -2499,7 +2499,7 @@ CommandSeparator.displayName = "CommandSeparator";
|
|
|
2499
2499
|
*/
|
|
2500
2500
|
const CommandItem = (0, react.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(cmdk.Command.Item, {
|
|
2501
2501
|
ref,
|
|
2502
|
-
className: cn("relative flex cursor-pointer select-none items-center gap-3", "min-h-[44px] sm:min-h-[36px]", "px-3 py-2.5", "rounded-sm text-base sm:text-sm outline-none", "transition-all duration-200 ease-(--ease-premium)", "hover-unified", "aria-selected:bg-primary/5 aria-selected:text-
|
|
2502
|
+
className: cn("relative flex cursor-pointer select-none items-center gap-3", "min-h-[44px] sm:min-h-[36px]", "px-3 py-2.5", "rounded-sm text-base sm:text-sm outline-none", "transition-all duration-200 ease-(--ease-premium)", "hover-unified", "aria-selected:bg-primary/5 aria-selected:text-foreground", "data-[selected=true]:bg-primary/5 data-[selected=true]:text-foreground", "data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50", className),
|
|
2503
2503
|
...props
|
|
2504
2504
|
}));
|
|
2505
2505
|
CommandItem.displayName = "CommandItem";
|
|
@@ -2747,7 +2747,9 @@ function Toaster({ theme = "system", ...props }) {
|
|
|
2747
2747
|
"--normal-border": "var(--nx-border)",
|
|
2748
2748
|
"--border-radius": "0px",
|
|
2749
2749
|
"--success-bg": "var(--nx-toast-success-bg)",
|
|
2750
|
-
"--success-text": "var(--nx-toast-success-text)"
|
|
2750
|
+
"--success-text": "var(--nx-toast-success-text)",
|
|
2751
|
+
"--warning-bg": "var(--nx-toast-warning-bg)",
|
|
2752
|
+
"--warning-text": "var(--nx-toast-warning-text)"
|
|
2751
2753
|
},
|
|
2752
2754
|
...props
|
|
2753
2755
|
});
|
|
@@ -3647,6 +3649,963 @@ function ColorPicker({ color, onColorChange, swatches = [], onSwatchSelect, rece
|
|
|
3647
3649
|
]
|
|
3648
3650
|
});
|
|
3649
3651
|
}
|
|
3652
|
+
// src/components/icon-glyph.tsx
|
|
3653
|
+
/** The shape elements a body may contain. */
|
|
3654
|
+
const SHAPES = /* @__PURE__ */ new Set([
|
|
3655
|
+
"path",
|
|
3656
|
+
"circle",
|
|
3657
|
+
"ellipse",
|
|
3658
|
+
"line",
|
|
3659
|
+
"polygon",
|
|
3660
|
+
"polyline",
|
|
3661
|
+
"rect"
|
|
3662
|
+
]);
|
|
3663
|
+
/** The attributes a shape may carry: geometry, and its fill. */
|
|
3664
|
+
const GEOMETRY = /* @__PURE__ */ new Set([
|
|
3665
|
+
"d",
|
|
3666
|
+
"cx",
|
|
3667
|
+
"cy",
|
|
3668
|
+
"r",
|
|
3669
|
+
"rx",
|
|
3670
|
+
"ry",
|
|
3671
|
+
"x",
|
|
3672
|
+
"y",
|
|
3673
|
+
"x1",
|
|
3674
|
+
"x2",
|
|
3675
|
+
"y1",
|
|
3676
|
+
"y2",
|
|
3677
|
+
"width",
|
|
3678
|
+
"height",
|
|
3679
|
+
"points",
|
|
3680
|
+
"fill"
|
|
3681
|
+
]);
|
|
3682
|
+
/** The fills a shape may name: none, or the text colour. */
|
|
3683
|
+
const FILLS = /* @__PURE__ */ new Set(["none", "currentColor"]);
|
|
3684
|
+
/**
|
|
3685
|
+
* Read bodies, by body. A picker draws the same few hundred icons on every
|
|
3686
|
+
* scroll, and reading each once is what keeps a scroll from re-reading them.
|
|
3687
|
+
* Bounded so a host searching several large sets cannot grow it without end.
|
|
3688
|
+
*/
|
|
3689
|
+
const readBodies = /* @__PURE__ */ new Map();
|
|
3690
|
+
const READ_BODIES_LIMIT = 4096;
|
|
3691
|
+
/** One element and the attributes after its name, anchored where the last one ended. */
|
|
3692
|
+
const ELEMENT = /\s*<([a-z]+)((?:\s+[a-zA-Z0-9-]+="[^"<>]*")*)\s*\/>/y;
|
|
3693
|
+
const ATTRIBUTE = /([a-zA-Z0-9-]+)="([^"<>]*)"/g;
|
|
3694
|
+
/** A shape's attributes, or `null` when any is not allowed geometry. */
|
|
3695
|
+
function readAttributes(text) {
|
|
3696
|
+
const attributes = {};
|
|
3697
|
+
for (const [, name = "", value = ""] of text.matchAll(ATTRIBUTE)) {
|
|
3698
|
+
if (!(GEOMETRY.has(name) && (name !== "fill" || FILLS.has(value)))) return null;
|
|
3699
|
+
attributes[name] = value;
|
|
3700
|
+
}
|
|
3701
|
+
return attributes;
|
|
3702
|
+
}
|
|
3703
|
+
/** The shape at `at` and where it ends, or `null` when none starts there. */
|
|
3704
|
+
function readShape(body, at) {
|
|
3705
|
+
ELEMENT.lastIndex = at;
|
|
3706
|
+
const match = ELEMENT.exec(body);
|
|
3707
|
+
const tag = match?.[1];
|
|
3708
|
+
if (match === null || tag === void 0 || !SHAPES.has(tag)) return null;
|
|
3709
|
+
const attributes = readAttributes(match[2] ?? "");
|
|
3710
|
+
return attributes === null ? null : {
|
|
3711
|
+
shape: {
|
|
3712
|
+
tag,
|
|
3713
|
+
attributes
|
|
3714
|
+
},
|
|
3715
|
+
end: ELEMENT.lastIndex
|
|
3716
|
+
};
|
|
3717
|
+
}
|
|
3718
|
+
/**
|
|
3719
|
+
* A body read as shapes, or `null` when any part of it is not one: every
|
|
3720
|
+
* element must be an allowed shape, every attribute allowed geometry, and
|
|
3721
|
+
* nothing may sit between the elements but whitespace.
|
|
3722
|
+
*/
|
|
3723
|
+
function readBody(body) {
|
|
3724
|
+
const cached = readBodies.get(body);
|
|
3725
|
+
if (cached !== void 0) return cached;
|
|
3726
|
+
let shapes = [];
|
|
3727
|
+
let at = 0;
|
|
3728
|
+
while (shapes !== null && body.slice(at).trim() !== "") {
|
|
3729
|
+
const read = readShape(body, at);
|
|
3730
|
+
if (read === null) shapes = null;
|
|
3731
|
+
else {
|
|
3732
|
+
shapes.push(read.shape);
|
|
3733
|
+
at = read.end;
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
if (readBodies.size >= READ_BODIES_LIMIT) readBodies.clear();
|
|
3737
|
+
readBodies.set(body, shapes);
|
|
3738
|
+
return shapes;
|
|
3739
|
+
}
|
|
3740
|
+
/**
|
|
3741
|
+
* An icon from an {@link IconSource}, drawn as an inline SVG in the text
|
|
3742
|
+
* colour.
|
|
3743
|
+
*
|
|
3744
|
+
* Decorative by default (`aria-hidden`): the control around it names the
|
|
3745
|
+
* icon. The body is read into React elements rather than inserted as markup,
|
|
3746
|
+
* and a body that is not a run of plain shapes draws an empty box.
|
|
3747
|
+
*
|
|
3748
|
+
* @experimental
|
|
3749
|
+
*/
|
|
3750
|
+
function IconGlyph({ icon, className, ...props }) {
|
|
3751
|
+
const shapes = readBody(icon.body) ?? [];
|
|
3752
|
+
const stroked = icon.stroked !== false;
|
|
3753
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
3754
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3755
|
+
viewBox: icon.viewBox,
|
|
3756
|
+
"aria-hidden": "true",
|
|
3757
|
+
focusable: "false",
|
|
3758
|
+
fill: stroked ? "none" : "currentColor",
|
|
3759
|
+
stroke: stroked ? "currentColor" : "none",
|
|
3760
|
+
strokeWidth: stroked ? 2 : void 0,
|
|
3761
|
+
strokeLinecap: stroked ? "round" : void 0,
|
|
3762
|
+
strokeLinejoin: stroked ? "round" : void 0,
|
|
3763
|
+
className: cn("size-4 shrink-0", className),
|
|
3764
|
+
...props,
|
|
3765
|
+
children: shapes.map((shape, index) => react.createElement(shape.tag, {
|
|
3766
|
+
key: index,
|
|
3767
|
+
...shape.attributes
|
|
3768
|
+
}))
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
/**
|
|
3772
|
+
* An icon's name as a person reads it: `circle-arrow-up` is
|
|
3773
|
+
* `Circle arrow up`.
|
|
3774
|
+
*/
|
|
3775
|
+
function iconDisplayName(name) {
|
|
3776
|
+
const words = name.replace(/-/g, " ").trim();
|
|
3777
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3778
|
+
}
|
|
3779
|
+
// src/components/icon-picker.tsx
|
|
3780
|
+
/** Icons per row of the results grid. */
|
|
3781
|
+
const COLUMNS = 8;
|
|
3782
|
+
/** One row of the grid: a 38px cell and the 2px gap below it. */
|
|
3783
|
+
const ROW_HEIGHT$1 = 40;
|
|
3784
|
+
/** Rows a Page Up or Page Down moves the highlight by. */
|
|
3785
|
+
const PAGE_ROWS = 5;
|
|
3786
|
+
/** How the picker's headings are set: small capitals in the muted ink. */
|
|
3787
|
+
const HEADING_TEXT = "px-3 pb-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground";
|
|
3788
|
+
/** A heading inside the grid, "Recent" or "All icons": its line and the space above. */
|
|
3789
|
+
const HEADING_HEIGHT = 28;
|
|
3790
|
+
/** How many recently used icons the picker offers: one row of the grid. */
|
|
3791
|
+
const RECENT_SHOWN = COLUMNS;
|
|
3792
|
+
const loads = /* @__PURE__ */ new WeakMap();
|
|
3793
|
+
const loaded = /* @__PURE__ */ new WeakMap();
|
|
3794
|
+
function loadOnce(load) {
|
|
3795
|
+
const existing = loads.get(load);
|
|
3796
|
+
if (existing !== void 0) return existing;
|
|
3797
|
+
const loading = load();
|
|
3798
|
+
loads.set(load, loading);
|
|
3799
|
+
loading.then((source) => loaded.set(load, source), () => {
|
|
3800
|
+
if (loads.get(load) === loading) loads.delete(load);
|
|
3801
|
+
});
|
|
3802
|
+
return loading;
|
|
3803
|
+
}
|
|
3804
|
+
/**
|
|
3805
|
+
* The icon source, loaded once `wanted` turns true, and a way to try again
|
|
3806
|
+
* after a failed load.
|
|
3807
|
+
*/
|
|
3808
|
+
function useIconSource(load, wanted) {
|
|
3809
|
+
const [state, setState] = react.useState(() => {
|
|
3810
|
+
const source = loaded.get(load);
|
|
3811
|
+
return source === void 0 ? { status: "loading" } : {
|
|
3812
|
+
status: "ready",
|
|
3813
|
+
source
|
|
3814
|
+
};
|
|
3815
|
+
});
|
|
3816
|
+
const [attempt, setAttempt] = react.useState(0);
|
|
3817
|
+
react.useEffect(() => {
|
|
3818
|
+
if (!wanted) return;
|
|
3819
|
+
let current = true;
|
|
3820
|
+
setState((previous) => previous.status === "ready" ? previous : { status: "loading" });
|
|
3821
|
+
loadOnce(load).then((source) => {
|
|
3822
|
+
if (current) setState({
|
|
3823
|
+
status: "ready",
|
|
3824
|
+
source
|
|
3825
|
+
});
|
|
3826
|
+
}, () => {
|
|
3827
|
+
if (current) setState({ status: "failed" });
|
|
3828
|
+
});
|
|
3829
|
+
return () => {
|
|
3830
|
+
current = false;
|
|
3831
|
+
};
|
|
3832
|
+
}, [
|
|
3833
|
+
load,
|
|
3834
|
+
wanted,
|
|
3835
|
+
attempt
|
|
3836
|
+
]);
|
|
3837
|
+
return [state, () => setAttempt((n) => n + 1)];
|
|
3838
|
+
}
|
|
3839
|
+
/**
|
|
3840
|
+
* What a stored id draws as, once the source can say, and a way to ask again
|
|
3841
|
+
* after the asking failed.
|
|
3842
|
+
*/
|
|
3843
|
+
function useResolvedIcon(source, id) {
|
|
3844
|
+
const [resolved, setResolved] = react.useState(null);
|
|
3845
|
+
const [attempt, setAttempt] = react.useState(0);
|
|
3846
|
+
const ready = source.status === "ready" ? source.source : null;
|
|
3847
|
+
react.useEffect(() => {
|
|
3848
|
+
if (ready === null || !id) return;
|
|
3849
|
+
let current = true;
|
|
3850
|
+
ready.resolve(id).then((icon) => {
|
|
3851
|
+
if (!current) return;
|
|
3852
|
+
setResolved({
|
|
3853
|
+
id,
|
|
3854
|
+
attempt,
|
|
3855
|
+
answer: icon === null ? { status: "missing" } : {
|
|
3856
|
+
status: "found",
|
|
3857
|
+
icon
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3860
|
+
}, () => {
|
|
3861
|
+
if (current) setResolved({
|
|
3862
|
+
id,
|
|
3863
|
+
attempt,
|
|
3864
|
+
answer: { status: "failed" }
|
|
3865
|
+
});
|
|
3866
|
+
});
|
|
3867
|
+
return () => {
|
|
3868
|
+
current = false;
|
|
3869
|
+
};
|
|
3870
|
+
}, [
|
|
3871
|
+
ready,
|
|
3872
|
+
id,
|
|
3873
|
+
attempt
|
|
3874
|
+
]);
|
|
3875
|
+
const retry = () => setAttempt((n) => n + 1);
|
|
3876
|
+
if (!id) return [{ status: "none" }, retry];
|
|
3877
|
+
if (resolved?.id === id && (resolved.answer.status !== "failed" || resolved.attempt === attempt)) return [resolved.answer, retry];
|
|
3878
|
+
return [source.status === "failed" ? { status: "failed" } : { status: "loading" }, retry];
|
|
3879
|
+
}
|
|
3880
|
+
/** The set and name an id carries, read without the set: `lucide:star`. */
|
|
3881
|
+
function partsOf(id) {
|
|
3882
|
+
const colon = id.indexOf(":");
|
|
3883
|
+
return colon === -1 ? {
|
|
3884
|
+
set: "",
|
|
3885
|
+
name: id
|
|
3886
|
+
} : {
|
|
3887
|
+
set: id.slice(0, colon),
|
|
3888
|
+
name: id.slice(colon + 1)
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
/** The rows of icons from `start` up to `end`, eight to a row. */
|
|
3892
|
+
function iconRows(start, end) {
|
|
3893
|
+
const rows = [];
|
|
3894
|
+
for (let at = start; at < end; at += COLUMNS) rows.push({
|
|
3895
|
+
kind: "icons",
|
|
3896
|
+
start: at,
|
|
3897
|
+
end: Math.min(end, at + COLUMNS)
|
|
3898
|
+
});
|
|
3899
|
+
return rows;
|
|
3900
|
+
}
|
|
3901
|
+
/**
|
|
3902
|
+
* The grid's rows: the recently used icons under "Recent" and the rest under
|
|
3903
|
+
* `label` ("All icons", or the search's matches) when there are any recent
|
|
3904
|
+
* ones to show, otherwise the icons alone, under the heading above the grid.
|
|
3905
|
+
*/
|
|
3906
|
+
function gridRows(recentCount, count, label) {
|
|
3907
|
+
if (recentCount === 0) return iconRows(0, count);
|
|
3908
|
+
return [
|
|
3909
|
+
{
|
|
3910
|
+
kind: "heading",
|
|
3911
|
+
label: "Recent"
|
|
3912
|
+
},
|
|
3913
|
+
...iconRows(0, recentCount),
|
|
3914
|
+
{
|
|
3915
|
+
kind: "heading",
|
|
3916
|
+
label
|
|
3917
|
+
},
|
|
3918
|
+
...iconRows(recentCount, count)
|
|
3919
|
+
];
|
|
3920
|
+
}
|
|
3921
|
+
/** What the icons below the Recent row are: the whole set, or a search's matches. */
|
|
3922
|
+
function resultsLabel(query) {
|
|
3923
|
+
return query === "" ? "All icons" : `Matches for “${query}”`;
|
|
3924
|
+
}
|
|
3925
|
+
/** The rows the arrow and page keys move the highlight up or down by. */
|
|
3926
|
+
const ROW_STEPS = {
|
|
3927
|
+
ArrowUp: -1,
|
|
3928
|
+
ArrowDown: 1,
|
|
3929
|
+
PageUp: -5,
|
|
3930
|
+
PageDown: PAGE_ROWS
|
|
3931
|
+
};
|
|
3932
|
+
/**
|
|
3933
|
+
* Where a key moves the highlight from `active` in the grid's rows, or
|
|
3934
|
+
* `undefined` for a key the grid does not answer. Left and right move by one
|
|
3935
|
+
* icon, across rows; up and down move by rows of icons, past a heading,
|
|
3936
|
+
* keeping the column, or the last icon of a shorter row. Up from the top row
|
|
3937
|
+
* stays put rather than jumping to the first icon.
|
|
3938
|
+
*/
|
|
3939
|
+
function stepFrom(key, active, rows) {
|
|
3940
|
+
const icons = rows.filter((row) => row.kind === "icons");
|
|
3941
|
+
const last = icons.at(-1);
|
|
3942
|
+
if (last === void 0) return void 0;
|
|
3943
|
+
if (key === "ArrowLeft") return Math.max(0, active - 1);
|
|
3944
|
+
if (key === "ArrowRight") return Math.min(last.end - 1, active + 1);
|
|
3945
|
+
const step = ROW_STEPS[key];
|
|
3946
|
+
if (step === void 0) return void 0;
|
|
3947
|
+
const at = icons.findIndex((row) => active >= row.start && active < row.end);
|
|
3948
|
+
const from = icons[at];
|
|
3949
|
+
const to = icons[Math.min(icons.length - 1, Math.max(0, at + step))];
|
|
3950
|
+
if (from === void 0 || to === void 0) return void 0;
|
|
3951
|
+
return Math.min(to.end - 1, to.start + (active - from.start));
|
|
3952
|
+
}
|
|
3953
|
+
/** The row an option is drawn in, for scrolling it into view. */
|
|
3954
|
+
function rowOf(rows, index) {
|
|
3955
|
+
return Math.max(0, rows.findIndex((row) => row.kind === "icons" && index >= row.start && index < row.end));
|
|
3956
|
+
}
|
|
3957
|
+
/**
|
|
3958
|
+
* The recently used icons to offer, newest first: the ids the host remembers
|
|
3959
|
+
* that the set still draws, found among the whole set's icons, which the
|
|
3960
|
+
* picker has from the browse it opens on. Offered above a search's matches
|
|
3961
|
+
* too, so an icon used a moment ago is one press away whatever is typed.
|
|
3962
|
+
*/
|
|
3963
|
+
function recentAmong(wholeSet, recentIds) {
|
|
3964
|
+
if (wholeSet === null || recentIds === void 0) return [];
|
|
3965
|
+
const byId = new Map(wholeSet.map((icon) => [icon.id, icon]));
|
|
3966
|
+
const recent = [];
|
|
3967
|
+
for (const id of new Set(recentIds)) {
|
|
3968
|
+
const icon = byId.get(id);
|
|
3969
|
+
if (icon !== void 0) recent.push(icon);
|
|
3970
|
+
if (recent.length === RECENT_SHOWN) break;
|
|
3971
|
+
}
|
|
3972
|
+
return recent;
|
|
3973
|
+
}
|
|
3974
|
+
/** What the picker's status line says, for the results in hand. */
|
|
3975
|
+
function announcementFor(results, failed, query) {
|
|
3976
|
+
if (results === null) return failed ? "The icons could not be loaded." : "Loading icons.";
|
|
3977
|
+
if (results.length === 0) return `No icons match “${query}”.`;
|
|
3978
|
+
const icons = `${results.length} ${results.length === 1 ? "icon" : "icons"}`;
|
|
3979
|
+
return query === "" ? `${icons}.` : `${icons} match “${query}”.`;
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* The results for a query, and the highlighted one among them.
|
|
3983
|
+
*
|
|
3984
|
+
* The latest search wins: results arrive asynchronously, so a slow answer to
|
|
3985
|
+
* "tr" must not replace the answer to "truck" that came back first, and
|
|
3986
|
+
* until the query typed is answered the search is `pending`. Browsing (an
|
|
3987
|
+
* empty query) highlights the chosen icon, once `currentSettled` says which
|
|
3988
|
+
* icon `currentId` is; a search highlights its best match. The highlight is a
|
|
3989
|
+
* place among the options as drawn, which while browsing start with the
|
|
3990
|
+
* Recent row the host's `recentIds` give.
|
|
3991
|
+
*/
|
|
3992
|
+
function useIconSearch(source, query, currentId, currentSettled, recentIds) {
|
|
3993
|
+
const [answer, setAnswer] = react.useState(null);
|
|
3994
|
+
const [wholeSet, setWholeSet] = react.useState(null);
|
|
3995
|
+
const [attempt, setAttempt] = react.useState(0);
|
|
3996
|
+
const [active, setActive] = react.useState(0);
|
|
3997
|
+
const [start, setStart] = react.useState(null);
|
|
3998
|
+
const placed = react.useRef(null);
|
|
3999
|
+
const place = react.useEffectEvent((found) => {
|
|
4000
|
+
if (found.status !== "found" || !currentSettled) return;
|
|
4001
|
+
placed.current = {
|
|
4002
|
+
answer: found,
|
|
4003
|
+
wholeSet
|
|
4004
|
+
};
|
|
4005
|
+
const browsing = found.query.trim() === "";
|
|
4006
|
+
const recent = recentAmong(browsing ? found.results : wholeSet, recentIds);
|
|
4007
|
+
const options = [...recent, ...found.results];
|
|
4008
|
+
const chosen = browsing && currentId ? options.findIndex((icon) => icon.id === currentId) : -1;
|
|
4009
|
+
const index = browsing ? Math.max(0, chosen) : found.results.length > 0 ? recent.length : 0;
|
|
4010
|
+
setActive(index);
|
|
4011
|
+
setStart({
|
|
4012
|
+
index,
|
|
4013
|
+
centred: chosen > 0
|
|
4014
|
+
});
|
|
4015
|
+
});
|
|
4016
|
+
const land = react.useEffectEvent((found) => {
|
|
4017
|
+
setAnswer(found);
|
|
4018
|
+
place(found);
|
|
4019
|
+
});
|
|
4020
|
+
const wantsRecent = recentIds !== void 0 && recentIds.length > 0;
|
|
4021
|
+
react.useEffect(() => {
|
|
4022
|
+
if (source === null || !wantsRecent) return;
|
|
4023
|
+
let current = true;
|
|
4024
|
+
source.search("").then((results) => {
|
|
4025
|
+
if (!current) return;
|
|
4026
|
+
setWholeSet(results);
|
|
4027
|
+
}, () => {});
|
|
4028
|
+
return () => {
|
|
4029
|
+
current = false;
|
|
4030
|
+
};
|
|
4031
|
+
}, [source, wantsRecent]);
|
|
4032
|
+
react.useEffect(() => {
|
|
4033
|
+
if (answer !== null && (placed.current?.answer !== answer || placed.current.wholeSet !== wholeSet)) place(answer);
|
|
4034
|
+
}, [
|
|
4035
|
+
answer,
|
|
4036
|
+
currentSettled,
|
|
4037
|
+
wholeSet
|
|
4038
|
+
]);
|
|
4039
|
+
const latest = react.useRef(0);
|
|
4040
|
+
react.useEffect(() => {
|
|
4041
|
+
if (source === null) return;
|
|
4042
|
+
const search = ++latest.current;
|
|
4043
|
+
source.search(query).then((results) => {
|
|
4044
|
+
if (search === latest.current) land({
|
|
4045
|
+
status: "found",
|
|
4046
|
+
results,
|
|
4047
|
+
query,
|
|
4048
|
+
attempt
|
|
4049
|
+
});
|
|
4050
|
+
}, () => {
|
|
4051
|
+
if (search === latest.current) land({
|
|
4052
|
+
status: "failed",
|
|
4053
|
+
query,
|
|
4054
|
+
attempt
|
|
4055
|
+
});
|
|
4056
|
+
});
|
|
4057
|
+
}, [
|
|
4058
|
+
source,
|
|
4059
|
+
query,
|
|
4060
|
+
attempt
|
|
4061
|
+
]);
|
|
4062
|
+
const pending = source !== null && (answer === null || answer.query !== query || answer.attempt !== attempt);
|
|
4063
|
+
return {
|
|
4064
|
+
results: answer?.status === "found" ? answer.results : null,
|
|
4065
|
+
answered: answer?.query.trim() ?? "",
|
|
4066
|
+
failed: answer?.status === "failed",
|
|
4067
|
+
pending,
|
|
4068
|
+
active,
|
|
4069
|
+
setActive,
|
|
4070
|
+
start,
|
|
4071
|
+
retry: () => setAttempt((n) => n + 1),
|
|
4072
|
+
wholeSet
|
|
4073
|
+
};
|
|
4074
|
+
}
|
|
4075
|
+
/**
|
|
4076
|
+
* How results awaiting a newer answer are drawn: kept, and dimmed.
|
|
4077
|
+
*
|
|
4078
|
+
* Kept rather than cleared because most answers land within a frame or two,
|
|
4079
|
+
* and a grid emptied on every keystroke would flash its loading line while
|
|
4080
|
+
* the person types. Dimmed only after a short delay for the same reason, so
|
|
4081
|
+
* a quick answer never visibly dims; a slow one fades the stale icons back
|
|
4082
|
+
* to say they are not what Enter chooses. Brightening again has no delay.
|
|
4083
|
+
*/
|
|
4084
|
+
function pendingFade(pending) {
|
|
4085
|
+
return cn("transition-opacity", pending && "opacity-50 delay-150");
|
|
4086
|
+
}
|
|
4087
|
+
/** What stands in the grid while there is nothing to choose from. */
|
|
4088
|
+
function PickerMessage({ results, failed, query, onRetry }) {
|
|
4089
|
+
if (results !== null && results.length > 0) return null;
|
|
4090
|
+
if (results === null && failed) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4091
|
+
className: "flex flex-col items-center gap-2 py-8 text-center text-muted-foreground",
|
|
4092
|
+
children: [
|
|
4093
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.TriangleAlert, {
|
|
4094
|
+
className: "size-5",
|
|
4095
|
+
"aria-hidden": "true"
|
|
4096
|
+
}),
|
|
4097
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "The icons could not be loaded." }),
|
|
4098
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
4099
|
+
type: "button",
|
|
4100
|
+
variant: "outline",
|
|
4101
|
+
size: "sm",
|
|
4102
|
+
onClick: onRetry,
|
|
4103
|
+
children: "Try again"
|
|
4104
|
+
})
|
|
4105
|
+
]
|
|
4106
|
+
});
|
|
4107
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4108
|
+
className: "py-8 text-center text-muted-foreground",
|
|
4109
|
+
children: results === null ? "Loading icons…" : `No icons match “${query}”.`
|
|
4110
|
+
});
|
|
4111
|
+
}
|
|
4112
|
+
/** One icon in the grid: an option of the listbox. */
|
|
4113
|
+
function IconOption({ icon, id, index, count, isActive, isCurrent, isRecent, onHighlight, onChoose }) {
|
|
4114
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4115
|
+
id,
|
|
4116
|
+
role: "option",
|
|
4117
|
+
"aria-selected": isActive,
|
|
4118
|
+
"aria-setsize": count,
|
|
4119
|
+
"aria-posinset": index + 1,
|
|
4120
|
+
"aria-label": `${iconDisplayName(icon.name)}${isRecent ? ", recent" : ""}${isCurrent ? ", current" : ""}`,
|
|
4121
|
+
"data-current": isCurrent || void 0,
|
|
4122
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
4123
|
+
onMouseMove: () => {
|
|
4124
|
+
if (!isActive) onHighlight(index);
|
|
4125
|
+
},
|
|
4126
|
+
onClick: () => onChoose(icon),
|
|
4127
|
+
className: cn("flex h-[38px] cursor-pointer items-center justify-center rounded-md", isCurrent && !isActive && "bg-muted ring-[1.5px] ring-inset ring-primary", isActive ? "bg-primary text-primary-foreground" : "hover:bg-muted"),
|
|
4128
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconGlyph, {
|
|
4129
|
+
icon,
|
|
4130
|
+
className: "size-5"
|
|
4131
|
+
})
|
|
4132
|
+
});
|
|
4133
|
+
}
|
|
4134
|
+
/** The highlighted icon, large, with its name and the words it is found by. */
|
|
4135
|
+
function HighlightedIcon({ icon, className }) {
|
|
4136
|
+
const words = (icon?.tags ?? []).slice(0, 3).join(", ");
|
|
4137
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4138
|
+
className: cn("flex min-h-[57px] items-center gap-2.5 border-t border-border px-3 py-2", className),
|
|
4139
|
+
children: icon === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4140
|
+
className: "grid size-9 shrink-0 place-items-center rounded-md bg-muted",
|
|
4141
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconGlyph, {
|
|
4142
|
+
icon,
|
|
4143
|
+
className: "size-[22px]"
|
|
4144
|
+
})
|
|
4145
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4146
|
+
className: "min-w-0",
|
|
4147
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4148
|
+
className: "block truncate font-semibold",
|
|
4149
|
+
children: iconDisplayName(icon.name)
|
|
4150
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4151
|
+
className: "block truncate text-xs text-muted-foreground",
|
|
4152
|
+
children: words === "" ? icon.name : `${icon.name} · ${words}`
|
|
4153
|
+
})]
|
|
4154
|
+
})] })
|
|
4155
|
+
});
|
|
4156
|
+
}
|
|
4157
|
+
/**
|
|
4158
|
+
* A search-first icon picker: a search box over a grid of the matching icons,
|
|
4159
|
+
* and the highlighted icon's name and tags beneath.
|
|
4160
|
+
*
|
|
4161
|
+
* The search box keeps focus throughout, as a combobox. The arrow keys move a
|
|
4162
|
+
* highlight through the grid (left and right by one icon, up and down by a
|
|
4163
|
+
* row), Page Up and Page Down by several rows, and Enter chooses the
|
|
4164
|
+
* highlighted icon; the first match is highlighted as soon as results arrive,
|
|
4165
|
+
* so typing and pressing Enter chooses the best match. The grid is a listbox
|
|
4166
|
+
* that renders only the rows in view, which is what keeps a set of nearly two
|
|
4167
|
+
* thousand icons quick to open. How many icons match is announced politely.
|
|
4168
|
+
*
|
|
4169
|
+
* @experimental
|
|
4170
|
+
*/
|
|
4171
|
+
function IconPicker({ loadIcons, value, onChoose, recentIcons, className }) {
|
|
4172
|
+
const base = react.useId();
|
|
4173
|
+
const listId = `${base}-icons`;
|
|
4174
|
+
const optionId = (index) => `${base}-icon-${index}`;
|
|
4175
|
+
const [sourceState, retryLoad] = useIconSource(loadIcons, true);
|
|
4176
|
+
const source = sourceState.status === "ready" ? sourceState.source : null;
|
|
4177
|
+
const [query, setQuery] = react.useState("");
|
|
4178
|
+
const scrollRef = react.useRef(null);
|
|
4179
|
+
const inputRef = react.useRef(null);
|
|
4180
|
+
const [current] = useResolvedIcon(sourceState, value);
|
|
4181
|
+
const currentId = current.status === "found" ? current.icon.id : value;
|
|
4182
|
+
const { results, answered, failed: searchFailed, pending, active, setActive, start, retry: retrySearch, wholeSet } = useIconSearch(source, query, currentId, current.status !== "loading", recentIcons);
|
|
4183
|
+
const { options, recentCount } = react.useMemo(() => {
|
|
4184
|
+
const recent = recentAmong(wholeSet, recentIcons);
|
|
4185
|
+
return {
|
|
4186
|
+
options: [...recent, ...results ?? []],
|
|
4187
|
+
recentCount: recent.length
|
|
4188
|
+
};
|
|
4189
|
+
}, [
|
|
4190
|
+
results,
|
|
4191
|
+
wholeSet,
|
|
4192
|
+
recentIcons
|
|
4193
|
+
]);
|
|
4194
|
+
const count = options.length;
|
|
4195
|
+
const rows = react.useMemo(() => gridRows(recentCount, count, resultsLabel(answered)), [
|
|
4196
|
+
recentCount,
|
|
4197
|
+
count,
|
|
4198
|
+
answered
|
|
4199
|
+
]);
|
|
4200
|
+
const highlighted = pending ? void 0 : options[active];
|
|
4201
|
+
const trimmed = query.trim();
|
|
4202
|
+
const failed = sourceState.status === "failed" || searchFailed && !pending;
|
|
4203
|
+
const retry = () => {
|
|
4204
|
+
if (sourceState.status === "failed") retryLoad();
|
|
4205
|
+
else retrySearch();
|
|
4206
|
+
inputRef.current?.focus();
|
|
4207
|
+
};
|
|
4208
|
+
const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
|
|
4209
|
+
count: rows.length,
|
|
4210
|
+
getScrollElement: () => scrollRef.current,
|
|
4211
|
+
estimateSize: (index) => rows[index]?.kind === "heading" ? HEADING_HEIGHT : ROW_HEIGHT$1,
|
|
4212
|
+
overscan: 4
|
|
4213
|
+
});
|
|
4214
|
+
const scrollToStart = react.useEffectEvent((at) => {
|
|
4215
|
+
virtualizer.scrollToIndex(at.centred ? rowOf(rows, at.index) : 0, { align: at.centred ? "center" : "start" });
|
|
4216
|
+
});
|
|
4217
|
+
react.useEffect(() => {
|
|
4218
|
+
if (start !== null) scrollToStart(start);
|
|
4219
|
+
}, [start]);
|
|
4220
|
+
const chooseAnswered = (icon) => {
|
|
4221
|
+
if (!pending) onChoose(icon);
|
|
4222
|
+
};
|
|
4223
|
+
const message = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PickerMessage, {
|
|
4224
|
+
results,
|
|
4225
|
+
failed,
|
|
4226
|
+
query: answered,
|
|
4227
|
+
onRetry: retry
|
|
4228
|
+
});
|
|
4229
|
+
const onKeyDown = (event) => {
|
|
4230
|
+
if (pending) {
|
|
4231
|
+
if (event.key === "Enter") event.preventDefault();
|
|
4232
|
+
return;
|
|
4233
|
+
}
|
|
4234
|
+
const next = stepFrom(event.key, active, rows);
|
|
4235
|
+
if (next !== void 0) {
|
|
4236
|
+
event.preventDefault();
|
|
4237
|
+
setActive(next);
|
|
4238
|
+
virtualizer.scrollToIndex(rowOf(rows, next), { align: "auto" });
|
|
4239
|
+
return;
|
|
4240
|
+
}
|
|
4241
|
+
if (event.key === "Enter" && highlighted !== void 0) {
|
|
4242
|
+
event.preventDefault();
|
|
4243
|
+
onChoose(highlighted);
|
|
4244
|
+
}
|
|
4245
|
+
};
|
|
4246
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4247
|
+
className: cn("flex h-[min(452px,70vh,var(--radix-popover-content-available-height,452px))] flex-col text-sm text-foreground", className),
|
|
4248
|
+
children: [
|
|
4249
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4250
|
+
className: "m-2.5 flex items-center gap-1.5 rounded-md border-[1.5px] border-input px-2 py-1.5 focus-within:border-primary",
|
|
4251
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Search, {
|
|
4252
|
+
className: "size-[15px] shrink-0 text-muted-foreground",
|
|
4253
|
+
"aria-hidden": "true"
|
|
4254
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
4255
|
+
ref: inputRef,
|
|
4256
|
+
type: "text",
|
|
4257
|
+
role: "combobox",
|
|
4258
|
+
"aria-label": "Search icons",
|
|
4259
|
+
"aria-expanded": "true",
|
|
4260
|
+
"aria-controls": listId,
|
|
4261
|
+
"aria-autocomplete": "list",
|
|
4262
|
+
"aria-activedescendant": highlighted === void 0 ? void 0 : optionId(active),
|
|
4263
|
+
autoComplete: "off",
|
|
4264
|
+
spellCheck: false,
|
|
4265
|
+
placeholder: "Search icons",
|
|
4266
|
+
value: query,
|
|
4267
|
+
onChange: (event) => setQuery(event.target.value),
|
|
4268
|
+
onKeyDown,
|
|
4269
|
+
className: "min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
|
|
4270
|
+
})]
|
|
4271
|
+
}),
|
|
4272
|
+
recentCount > 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4273
|
+
className: HEADING_TEXT,
|
|
4274
|
+
children: resultsLabel(trimmed)
|
|
4275
|
+
}),
|
|
4276
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4277
|
+
ref: scrollRef,
|
|
4278
|
+
className: "min-h-0 flex-1 overflow-y-auto px-2.5",
|
|
4279
|
+
children: [
|
|
4280
|
+
recentCount > 0 ? null : message,
|
|
4281
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4282
|
+
id: listId,
|
|
4283
|
+
role: "listbox",
|
|
4284
|
+
"aria-label": "Icons",
|
|
4285
|
+
"aria-busy": pending || void 0,
|
|
4286
|
+
className: cn("relative w-full", pendingFade(pending)),
|
|
4287
|
+
style: { height: virtualizer.getTotalSize() },
|
|
4288
|
+
children: virtualizer.getVirtualItems().map((item) => {
|
|
4289
|
+
const row = rows[item.index];
|
|
4290
|
+
if (row === void 0) return null;
|
|
4291
|
+
if (row.kind === "heading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4292
|
+
"aria-hidden": "true",
|
|
4293
|
+
className: cn(HEADING_TEXT, "absolute inset-x-0 top-0 flex items-end px-0.5"),
|
|
4294
|
+
style: {
|
|
4295
|
+
height: HEADING_HEIGHT,
|
|
4296
|
+
transform: `translateY(${item.start}px)`
|
|
4297
|
+
},
|
|
4298
|
+
children: row.label
|
|
4299
|
+
}, item.key);
|
|
4300
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4301
|
+
role: "presentation",
|
|
4302
|
+
className: "absolute inset-x-0 top-0 grid grid-cols-8 gap-0.5",
|
|
4303
|
+
style: { transform: `translateY(${item.start}px)` },
|
|
4304
|
+
children: options.slice(row.start, row.end).map((icon, column) => {
|
|
4305
|
+
const index = row.start + column;
|
|
4306
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconOption, {
|
|
4307
|
+
icon,
|
|
4308
|
+
id: optionId(index),
|
|
4309
|
+
index,
|
|
4310
|
+
count,
|
|
4311
|
+
isActive: index === active,
|
|
4312
|
+
isCurrent: icon.id === currentId,
|
|
4313
|
+
isRecent: index < recentCount,
|
|
4314
|
+
onHighlight: setActive,
|
|
4315
|
+
onChoose: chooseAnswered
|
|
4316
|
+
}, icon.id);
|
|
4317
|
+
})
|
|
4318
|
+
}, item.key);
|
|
4319
|
+
})
|
|
4320
|
+
}),
|
|
4321
|
+
recentCount > 0 ? message : null
|
|
4322
|
+
]
|
|
4323
|
+
}),
|
|
4324
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(HighlightedIcon, {
|
|
4325
|
+
icon: options[active],
|
|
4326
|
+
className: pendingFade(pending)
|
|
4327
|
+
}),
|
|
4328
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4329
|
+
role: "status",
|
|
4330
|
+
"aria-live": "polite",
|
|
4331
|
+
className: "sr-only",
|
|
4332
|
+
children: announcementFor(results, failed, answered)
|
|
4333
|
+
})
|
|
4334
|
+
]
|
|
4335
|
+
});
|
|
4336
|
+
}
|
|
4337
|
+
/** The text the field shows and speaks for a value, however it resolved. */
|
|
4338
|
+
function valueTextFor(value, resolved, source, label) {
|
|
4339
|
+
if (!value) return {
|
|
4340
|
+
name: "Choose an icon",
|
|
4341
|
+
set: "",
|
|
4342
|
+
spoken: `${label}: none chosen`
|
|
4343
|
+
};
|
|
4344
|
+
const parts = partsOf(value);
|
|
4345
|
+
const setName = source !== null && parts.set === source.prefix ? source.label : iconDisplayName(parts.set);
|
|
4346
|
+
if (resolved.status === "missing") return {
|
|
4347
|
+
name: parts.name,
|
|
4348
|
+
set: setName === "" ? "Not found" : `${setName} · not found`,
|
|
4349
|
+
spoken: `${label}: ${parts.name}, not found`
|
|
4350
|
+
};
|
|
4351
|
+
if (resolved.status === "failed") {
|
|
4352
|
+
const name = iconDisplayName(parts.name);
|
|
4353
|
+
return {
|
|
4354
|
+
name,
|
|
4355
|
+
set: setName === "" ? "Could not load" : `${setName} · could not load`,
|
|
4356
|
+
spoken: `${label}: ${name}, could not be loaded`
|
|
4357
|
+
};
|
|
4358
|
+
}
|
|
4359
|
+
const name = iconDisplayName(resolved.status === "found" ? resolved.icon.name : parts.name);
|
|
4360
|
+
return {
|
|
4361
|
+
name,
|
|
4362
|
+
set: setName,
|
|
4363
|
+
spoken: `${label}: ${name}`
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
/** The tile the chosen icon is drawn in, or what stands in for it. */
|
|
4367
|
+
function IconSwatch({ resolved }) {
|
|
4368
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4369
|
+
className: cn("grid size-7 shrink-0 place-items-center rounded-[5px]", resolved.status === "found" ? "bg-muted" : "border border-dashed border-muted-foreground", resolved.status === "loading" && "animate-pulse bg-muted motion-reduce:animate-none"),
|
|
4370
|
+
children: resolved.status === "found" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconGlyph, {
|
|
4371
|
+
icon: resolved.icon,
|
|
4372
|
+
className: "size-[18px]"
|
|
4373
|
+
}) : resolved.status === "missing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CircleHelp, {
|
|
4374
|
+
className: "size-[18px] text-muted-foreground",
|
|
4375
|
+
"aria-hidden": "true"
|
|
4376
|
+
}) : resolved.status === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.TriangleAlert, {
|
|
4377
|
+
className: "size-[18px] text-muted-foreground",
|
|
4378
|
+
"aria-hidden": "true"
|
|
4379
|
+
}) : null
|
|
4380
|
+
});
|
|
4381
|
+
}
|
|
4382
|
+
/** What the field's button shows: the swatch, the name, the set, a chevron. */
|
|
4383
|
+
function IconFieldFace({ resolved, text, empty }) {
|
|
4384
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
4385
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconSwatch, { resolved }),
|
|
4386
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4387
|
+
className: "min-w-0 flex-1 leading-tight",
|
|
4388
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4389
|
+
className: cn("block text-sm font-medium [overflow-wrap:anywhere]", empty && "font-normal text-muted-foreground"),
|
|
4390
|
+
children: text.name
|
|
4391
|
+
}), text.set === "" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4392
|
+
className: "text-[11px] text-muted-foreground",
|
|
4393
|
+
children: text.set
|
|
4394
|
+
})]
|
|
4395
|
+
}),
|
|
4396
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, {
|
|
4397
|
+
className: "size-3.5 shrink-0 text-muted-foreground",
|
|
4398
|
+
"aria-hidden": "true"
|
|
4399
|
+
})
|
|
4400
|
+
] });
|
|
4401
|
+
}
|
|
4402
|
+
/** The warning under a field whose icon the set no longer draws. */
|
|
4403
|
+
function MissingIconWarning({ shown, id }) {
|
|
4404
|
+
if (!shown) return null;
|
|
4405
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
4406
|
+
id,
|
|
4407
|
+
className: "mt-1.5 flex items-start gap-2 rounded-md border border-warning-200 bg-warning-50 px-2.5 py-1.5 text-xs text-warning-900 dark:border-warning-900 dark:bg-warning-950 dark:text-warning-100",
|
|
4408
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.TriangleAlert, {
|
|
4409
|
+
className: "mt-px size-3.5 shrink-0",
|
|
4410
|
+
"aria-hidden": "true"
|
|
4411
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "This icon is no longer available. Choose another." })]
|
|
4412
|
+
});
|
|
4413
|
+
}
|
|
4414
|
+
/**
|
|
4415
|
+
* The button that opens the picker. Every prop it is not given by name goes
|
|
4416
|
+
* to the `<button>`, so a popover trigger can hand it its ref, state and
|
|
4417
|
+
* handlers.
|
|
4418
|
+
*/
|
|
4419
|
+
function IconFieldButton({ resolved, text, empty, interactive, invalid, readOnly, ...button }) {
|
|
4420
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4421
|
+
type: "button",
|
|
4422
|
+
...button,
|
|
4423
|
+
"aria-label": text.spoken,
|
|
4424
|
+
"aria-invalid": invalid || void 0,
|
|
4425
|
+
"aria-disabled": readOnly || void 0,
|
|
4426
|
+
className: cn("flex min-w-0 flex-1 items-center gap-2 rounded-md px-1.5 py-[5px] text-left", "outline-none focus-visible:ring-2 focus-visible:ring-ring", interactive ? "cursor-pointer hover:bg-muted" : "cursor-default"),
|
|
4427
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconFieldFace, {
|
|
4428
|
+
resolved,
|
|
4429
|
+
text,
|
|
4430
|
+
empty
|
|
4431
|
+
})
|
|
4432
|
+
});
|
|
4433
|
+
}
|
|
4434
|
+
/** The bordered row the field's two buttons sit in. */
|
|
4435
|
+
function IconFieldFrame({ invalid, disabled, children }) {
|
|
4436
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4437
|
+
className: cn("flex w-full items-center rounded-md border border-input bg-background", invalid && "border-destructive", disabled && "opacity-50"),
|
|
4438
|
+
children
|
|
4439
|
+
});
|
|
4440
|
+
}
|
|
4441
|
+
/** A button that clears the field, drawn while there is a value to clear. */
|
|
4442
|
+
function ClearIconButton({ shown, onClear }) {
|
|
4443
|
+
if (!shown) return null;
|
|
4444
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4445
|
+
type: "button",
|
|
4446
|
+
"aria-label": "Clear icon",
|
|
4447
|
+
onClick: onClear,
|
|
4448
|
+
className: "mr-1 grid place-items-center rounded p-[3px] text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
|
|
4449
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {
|
|
4450
|
+
className: "size-[15px]",
|
|
4451
|
+
"aria-hidden": "true"
|
|
4452
|
+
})
|
|
4453
|
+
});
|
|
4454
|
+
}
|
|
4455
|
+
/**
|
|
4456
|
+
* What a field's value draws as and is called, loading the set when there is
|
|
4457
|
+
* an icon to draw or a picker to fill. Opening the picker asks again for
|
|
4458
|
+
* whichever failed to arrive, the set or the value's icon.
|
|
4459
|
+
*/
|
|
4460
|
+
function useIconFieldValue(loadIcons, value, label, open) {
|
|
4461
|
+
const [sourceState, retryLoad] = useIconSource(loadIcons, Boolean(value) || open);
|
|
4462
|
+
const [resolved, retryResolve] = useResolvedIcon(sourceState, value);
|
|
4463
|
+
const source = sourceState.status === "ready" ? sourceState.source : null;
|
|
4464
|
+
const retryFailed = react.useEffectEvent(() => {
|
|
4465
|
+
if (sourceState.status === "failed") retryLoad();
|
|
4466
|
+
else if (resolved.status === "failed") retryResolve();
|
|
4467
|
+
});
|
|
4468
|
+
react.useEffect(() => {
|
|
4469
|
+
if (open) retryFailed();
|
|
4470
|
+
}, [open]);
|
|
4471
|
+
return {
|
|
4472
|
+
resolved,
|
|
4473
|
+
text: valueTextFor(value, resolved, source, label)
|
|
4474
|
+
};
|
|
4475
|
+
}
|
|
4476
|
+
/**
|
|
4477
|
+
* A button the field keeps a handle on and hands to the caller's ref too: the
|
|
4478
|
+
* field takes focus back to it after a clear, and a form focuses it from
|
|
4479
|
+
* outside. One callback ref gives the node to both.
|
|
4480
|
+
*/
|
|
4481
|
+
function useSharedButtonRef(ref) {
|
|
4482
|
+
const own = react.useRef(null);
|
|
4483
|
+
return [own, react.useCallback((node) => {
|
|
4484
|
+
own.current = node;
|
|
4485
|
+
if (typeof ref === "function") ref(node);
|
|
4486
|
+
else if (ref) ref.current = node;
|
|
4487
|
+
}, [ref])];
|
|
4488
|
+
}
|
|
4489
|
+
/** The warning's id while the warning is drawn, for the button it describes. */
|
|
4490
|
+
function warningIdIf(missing, id) {
|
|
4491
|
+
return missing ? id : void 0;
|
|
4492
|
+
}
|
|
4493
|
+
/** Joins the ids describing an element, or `undefined` when there are none. */
|
|
4494
|
+
function describedByIds(...ids) {
|
|
4495
|
+
const joined = ids.filter((id) => id !== void 0 && id !== "").join(" ");
|
|
4496
|
+
return joined === "" ? void 0 : joined;
|
|
4497
|
+
}
|
|
4498
|
+
/** The popover the field's picker opens in, beside the field. */
|
|
4499
|
+
function IconFieldPopover({ ref, loadIcons, value, recentIcons, onChoose }) {
|
|
4500
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopoverContent, {
|
|
4501
|
+
ref,
|
|
4502
|
+
align: "start",
|
|
4503
|
+
collisionPadding: 8,
|
|
4504
|
+
"aria-label": "Choose an icon",
|
|
4505
|
+
className: "w-[min(360px,calc(100vw-32px))] rounded-[10px] p-0 shadow-lg motion-reduce:animate-none",
|
|
4506
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconPicker, {
|
|
4507
|
+
loadIcons,
|
|
4508
|
+
value,
|
|
4509
|
+
recentIcons,
|
|
4510
|
+
onChoose: (icon) => onChoose(icon.id)
|
|
4511
|
+
})
|
|
4512
|
+
});
|
|
4513
|
+
}
|
|
4514
|
+
/**
|
|
4515
|
+
* Whether the field's picker is open, and a setter that opens it only for a
|
|
4516
|
+
* field that can be changed and reports the field left when it closes.
|
|
4517
|
+
*/
|
|
4518
|
+
function useReportedOpen(interactive, onBlur) {
|
|
4519
|
+
const [open, setOpen] = react.useState(false);
|
|
4520
|
+
const setOpenAndReport = (next) => {
|
|
4521
|
+
if (next && !interactive) return;
|
|
4522
|
+
setOpen(next);
|
|
4523
|
+
if (!next) onBlur?.();
|
|
4524
|
+
};
|
|
4525
|
+
return [open, setOpenAndReport];
|
|
4526
|
+
}
|
|
4527
|
+
/**
|
|
4528
|
+
* A blur handler for the field's wrapper that reports the field left when
|
|
4529
|
+
* focus moves from its buttons to somewhere outside the field. The picker sits
|
|
4530
|
+
* in a portal, elsewhere in the document, so it is checked by its own node;
|
|
4531
|
+
* its focus events still bubble to the wrapper through React. Focus never
|
|
4532
|
+
* leaves the open picker without closing it, and the close reports, so
|
|
4533
|
+
* nothing is reported while it is open or for focus leaving it.
|
|
4534
|
+
*/
|
|
4535
|
+
function focusLeftReporter(open, pickerRef, onBlur) {
|
|
4536
|
+
return (event) => {
|
|
4537
|
+
const picker = pickerRef.current;
|
|
4538
|
+
if (open || picker?.contains(event.target)) return;
|
|
4539
|
+
const next = event.relatedTarget;
|
|
4540
|
+
if (!(next instanceof Node && (event.currentTarget.contains(next) || picker?.contains(next) === true))) onBlur?.();
|
|
4541
|
+
};
|
|
4542
|
+
}
|
|
4543
|
+
/**
|
|
4544
|
+
* A field holding one icon: a button showing the chosen icon, its name and
|
|
4545
|
+
* its set, which opens an {@link IconPicker}, and a button that clears it.
|
|
4546
|
+
*
|
|
4547
|
+
* An id the source no longer draws is shown by its name with a warning, and
|
|
4548
|
+
* kept until someone chooses another: the field never rewrites a stored value
|
|
4549
|
+
* on its own. Escape closes the picker and returns focus to the button.
|
|
4550
|
+
*
|
|
4551
|
+
* @experimental
|
|
4552
|
+
*/
|
|
4553
|
+
function IconField({ value, onChange, loadIcons, label = "Icon", id, disabled = false, readOnly = false, invalid = false, "aria-describedby": describedBy, onBlur, recentIcons, ref, className }) {
|
|
4554
|
+
const interactive = !disabled && !readOnly;
|
|
4555
|
+
const [open, setOpenAndReport] = useReportedOpen(interactive, onBlur);
|
|
4556
|
+
const [triggerRef, setTrigger] = useSharedButtonRef(ref);
|
|
4557
|
+
const warningId = react.useId();
|
|
4558
|
+
const { resolved, text } = useIconFieldValue(loadIcons, value, label, open);
|
|
4559
|
+
const missing = resolved.status === "missing";
|
|
4560
|
+
const pickerRef = react.useRef(null);
|
|
4561
|
+
const reportFocusLeft = focusLeftReporter(open, pickerRef, onBlur);
|
|
4562
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4563
|
+
className: cn("w-full", className),
|
|
4564
|
+
onBlur: reportFocusLeft,
|
|
4565
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(IconFieldFrame, {
|
|
4566
|
+
invalid,
|
|
4567
|
+
disabled,
|
|
4568
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Popover, {
|
|
4569
|
+
open,
|
|
4570
|
+
onOpenChange: setOpenAndReport,
|
|
4571
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopoverTrigger, {
|
|
4572
|
+
asChild: true,
|
|
4573
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconFieldButton, {
|
|
4574
|
+
ref: setTrigger,
|
|
4575
|
+
id,
|
|
4576
|
+
"aria-describedby": describedByIds(describedBy, warningIdIf(missing, warningId)),
|
|
4577
|
+
disabled,
|
|
4578
|
+
resolved,
|
|
4579
|
+
text,
|
|
4580
|
+
empty: !value,
|
|
4581
|
+
interactive,
|
|
4582
|
+
invalid,
|
|
4583
|
+
readOnly
|
|
4584
|
+
})
|
|
4585
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconFieldPopover, {
|
|
4586
|
+
ref: pickerRef,
|
|
4587
|
+
loadIcons,
|
|
4588
|
+
value,
|
|
4589
|
+
recentIcons,
|
|
4590
|
+
onChoose: (id) => {
|
|
4591
|
+
onChange(id);
|
|
4592
|
+
setOpenAndReport(false);
|
|
4593
|
+
}
|
|
4594
|
+
})]
|
|
4595
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClearIconButton, {
|
|
4596
|
+
shown: Boolean(value) && interactive,
|
|
4597
|
+
onClear: () => {
|
|
4598
|
+
onChange(null);
|
|
4599
|
+
onBlur?.();
|
|
4600
|
+
triggerRef.current?.focus();
|
|
4601
|
+
}
|
|
4602
|
+
})]
|
|
4603
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MissingIconWarning, {
|
|
4604
|
+
shown: missing,
|
|
4605
|
+
id: warningId
|
|
4606
|
+
})]
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
3650
4609
|
// src/components/context-menu.tsx
|
|
3651
4610
|
/**
|
|
3652
4611
|
* ContextMenu Component
|
|
@@ -3979,7 +4938,17 @@ const ResizableHandle = ({ withGrip, className, children, ...props }) => /* @__P
|
|
|
3979
4938
|
* @module
|
|
3980
4939
|
*/
|
|
3981
4940
|
const ROW_HEIGHT = 28;
|
|
3982
|
-
|
|
4941
|
+
/**
|
|
4942
|
+
* How far each level of the tree is indented, in pixels.
|
|
4943
|
+
*
|
|
4944
|
+
* Exported because a consumer that lets rows be dragged to a depth has to step
|
|
4945
|
+
* by the same distance the rows are drawn at: an editor reading a pointer's x
|
|
4946
|
+
* as a depth draws its drop line where a row at that depth would start, and
|
|
4947
|
+
* two separate numbers would put the line a level away from the hand.
|
|
4948
|
+
*
|
|
4949
|
+
* @experimental
|
|
4950
|
+
*/
|
|
4951
|
+
const TREE_INDENT_PX = 20;
|
|
3983
4952
|
/** The text a row can be typed to, falling back to a string label. */
|
|
3984
4953
|
function textOf(node) {
|
|
3985
4954
|
if (typeof node.textValue === "string") return node.textValue;
|
|
@@ -4091,6 +5060,22 @@ const TreeView = react.forwardRef(({ nodes, expandedIds, defaultExpandedIds, onE
|
|
|
4091
5060
|
estimateSize: () => ROW_HEIGHT,
|
|
4092
5061
|
overscan: 8
|
|
4093
5062
|
});
|
|
5063
|
+
const revealed = react.useRef(null);
|
|
5064
|
+
react.useEffect(() => {
|
|
5065
|
+
if (selected === null) {
|
|
5066
|
+
revealed.current = null;
|
|
5067
|
+
return;
|
|
5068
|
+
}
|
|
5069
|
+
if (revealed.current === selected) return;
|
|
5070
|
+
const index = rows.findIndex((row) => row.node.id === selected);
|
|
5071
|
+
if (index < 0) return;
|
|
5072
|
+
revealed.current = selected;
|
|
5073
|
+
virtualizer.scrollToIndex(index, { align: "auto" });
|
|
5074
|
+
}, [
|
|
5075
|
+
selected,
|
|
5076
|
+
rows,
|
|
5077
|
+
virtualizer
|
|
5078
|
+
]);
|
|
4094
5079
|
const commitExpanded = (next) => {
|
|
4095
5080
|
const ids = [...next];
|
|
4096
5081
|
if (expandedIds === void 0) setExpandedState(ids);
|
|
@@ -4252,7 +5237,7 @@ const TreeView = react.forwardRef(({ nodes, expandedIds, defaultExpandedIds, onE
|
|
|
4252
5237
|
style: {
|
|
4253
5238
|
height: item.size,
|
|
4254
5239
|
transform: `translateY(${item.start}px)`,
|
|
4255
|
-
paddingLeft: 4 + row.level *
|
|
5240
|
+
paddingLeft: 4 + row.level * 20
|
|
4256
5241
|
},
|
|
4257
5242
|
children: [
|
|
4258
5243
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -5996,6 +6981,9 @@ exports.FormActions = FormActions;
|
|
|
5996
6981
|
exports.FormLabelWithTooltip = FormLabelWithTooltip;
|
|
5997
6982
|
exports.FormSection = FormSection;
|
|
5998
6983
|
exports.Grid = Grid;
|
|
6984
|
+
exports.IconField = IconField;
|
|
6985
|
+
exports.IconGlyph = IconGlyph;
|
|
6986
|
+
exports.IconPicker = IconPicker;
|
|
5999
6987
|
exports.Input = Input;
|
|
6000
6988
|
exports.Label = Label;
|
|
6001
6989
|
exports.PageHeader = PageHeader;
|
|
@@ -6041,6 +7029,7 @@ exports.Spinner = Spinner;
|
|
|
6041
7029
|
exports.Stack = Stack;
|
|
6042
7030
|
exports.Stat = Stat;
|
|
6043
7031
|
exports.Switch = Switch;
|
|
7032
|
+
exports.TREE_INDENT_PX = TREE_INDENT_PX;
|
|
6044
7033
|
exports.Table = Table;
|
|
6045
7034
|
exports.TableBody = TableBody;
|
|
6046
7035
|
exports.TableCaption = TableCaption;
|