@cboxdk/cbox-ui 0.16.1 → 0.17.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/README.md +3 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +530 -219
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/tokens/controls.css +130 -0
package/dist/index.js
CHANGED
|
@@ -4942,6 +4942,67 @@ function Field({ label, id: statedId, labelAction, hint, error, required = false
|
|
|
4942
4942
|
/* @__PURE__ */ jsx("p", { id: errorId, className: "cbx-ui-error", role: "alert", hidden: !hasError, children: hasError ? error : null })
|
|
4943
4943
|
] }) });
|
|
4944
4944
|
}
|
|
4945
|
+
var useIsoLayoutEffect3 = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
4946
|
+
var GAP2 = 4;
|
|
4947
|
+
var MARGIN2 = 8;
|
|
4948
|
+
var MIN_WIDTH = 256;
|
|
4949
|
+
var MAX_WIDTH = 352;
|
|
4950
|
+
function panelContainer(anchor) {
|
|
4951
|
+
return anchor?.closest("[data-cbx-dialog-layer], .cbx-overlay") ?? document.body;
|
|
4952
|
+
}
|
|
4953
|
+
function useAnchoredPanel(open, anchor, panel, remeasure) {
|
|
4954
|
+
useIsoLayoutEffect3(() => {
|
|
4955
|
+
const element = panel.current;
|
|
4956
|
+
const target = anchor.current;
|
|
4957
|
+
if (!open || element === null || target === null) return;
|
|
4958
|
+
let width = 0;
|
|
4959
|
+
let natural = 0;
|
|
4960
|
+
const measure = () => {
|
|
4961
|
+
const box = target.getBoundingClientRect();
|
|
4962
|
+
const room = document.documentElement.clientWidth - 2 * MARGIN2;
|
|
4963
|
+
element.style.minWidth = `${Math.min(Math.max(box.width, MIN_WIDTH), room)}px`;
|
|
4964
|
+
element.style.maxWidth = `${Math.min(Math.max(box.width, MAX_WIDTH), room)}px`;
|
|
4965
|
+
element.style.width = "max-content";
|
|
4966
|
+
element.style.maxHeight = "none";
|
|
4967
|
+
width = element.offsetWidth;
|
|
4968
|
+
natural = element.offsetHeight;
|
|
4969
|
+
element.style.width = `${width}px`;
|
|
4970
|
+
};
|
|
4971
|
+
const place2 = () => {
|
|
4972
|
+
const box = target.getBoundingClientRect();
|
|
4973
|
+
const viewportWidth = document.documentElement.clientWidth;
|
|
4974
|
+
const viewportHeight = window.innerHeight;
|
|
4975
|
+
const below = viewportHeight - box.bottom - GAP2 - MARGIN2;
|
|
4976
|
+
const above = box.top - GAP2 - MARGIN2;
|
|
4977
|
+
const down = natural <= below || below >= above;
|
|
4978
|
+
const left = Math.max(MARGIN2, Math.min(box.left, viewportWidth - MARGIN2 - width));
|
|
4979
|
+
element.style.left = `${left}px`;
|
|
4980
|
+
if (down) {
|
|
4981
|
+
element.style.top = `${box.bottom + GAP2}px`;
|
|
4982
|
+
element.style.bottom = "auto";
|
|
4983
|
+
element.style.maxHeight = `${Math.max(below, 0)}px`;
|
|
4984
|
+
} else {
|
|
4985
|
+
element.style.top = "auto";
|
|
4986
|
+
element.style.bottom = `${viewportHeight - box.top + GAP2}px`;
|
|
4987
|
+
element.style.maxHeight = `${Math.max(above, 0)}px`;
|
|
4988
|
+
}
|
|
4989
|
+
element.dataset.side = down ? "bottom" : "top";
|
|
4990
|
+
};
|
|
4991
|
+
const resize = () => {
|
|
4992
|
+
measure();
|
|
4993
|
+
place2();
|
|
4994
|
+
};
|
|
4995
|
+
resize();
|
|
4996
|
+
window.addEventListener("resize", resize);
|
|
4997
|
+
window.addEventListener("scroll", place2, true);
|
|
4998
|
+
return () => {
|
|
4999
|
+
window.removeEventListener("resize", resize);
|
|
5000
|
+
window.removeEventListener("scroll", place2, true);
|
|
5001
|
+
};
|
|
5002
|
+
}, [open, anchor, panel, remeasure]);
|
|
5003
|
+
}
|
|
5004
|
+
var CREATE = "\0create";
|
|
5005
|
+
var useIsoLayoutEffect4 = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
4945
5006
|
function Combobox(props) {
|
|
4946
5007
|
const { t } = useCboxLocalization();
|
|
4947
5008
|
const field = useFieldControl();
|
|
@@ -4951,6 +5012,8 @@ function Combobox(props) {
|
|
|
4951
5012
|
searchPlaceholder = t("Search\u2026"),
|
|
4952
5013
|
emptyText = t("Nothing matches."),
|
|
4953
5014
|
footerLink,
|
|
5015
|
+
onCreate,
|
|
5016
|
+
createLabel: createLabel2,
|
|
4954
5017
|
disabled = false,
|
|
4955
5018
|
required = field.required ?? false,
|
|
4956
5019
|
ariaLabel,
|
|
@@ -4974,13 +5037,15 @@ function Combobox(props) {
|
|
|
4974
5037
|
const [open, setOpen] = useState(false);
|
|
4975
5038
|
const [query2, setQuery] = useState("");
|
|
4976
5039
|
const [highlightIndex, setHighlightIndex] = useState(-1);
|
|
5040
|
+
const [creating, setCreating] = useState(false);
|
|
4977
5041
|
const containerRef = useRef(null);
|
|
4978
5042
|
const triggerRef = useRef(null);
|
|
5043
|
+
const panelRef = useRef(null);
|
|
4979
5044
|
const inputRef = useRef(null);
|
|
4980
|
-
const listRef = useRef(null);
|
|
4981
5045
|
const reactId = useId();
|
|
4982
5046
|
const id = idProp ?? field.id ?? reactId;
|
|
4983
5047
|
const listId = `${id}-listbox`;
|
|
5048
|
+
useAnchoredPanel(open, triggerRef, panelRef);
|
|
4984
5049
|
const filteredGroups = useMemo(
|
|
4985
5050
|
() => filterGroups(groups, query2),
|
|
4986
5051
|
[groups, query2]
|
|
@@ -4989,34 +5054,61 @@ function Combobox(props) {
|
|
|
4989
5054
|
() => filteredGroups.flatMap((g) => g.options),
|
|
4990
5055
|
[filteredGroups]
|
|
4991
5056
|
);
|
|
5057
|
+
const typed = query2.trim();
|
|
5058
|
+
const createOption = useMemo(() => {
|
|
5059
|
+
if (onCreate === void 0 || typed === "") return null;
|
|
5060
|
+
const lower = typed.toLowerCase();
|
|
5061
|
+
if (flatOptions.some((opt) => opt.label.toLowerCase() === lower)) return null;
|
|
5062
|
+
return { value: CREATE, label: createLabel2?.(typed) ?? t("Create \u201C{query}\u201D", { query: typed }) };
|
|
5063
|
+
}, [onCreate, typed, flatOptions, createLabel2, t]);
|
|
5064
|
+
const navList = useMemo(
|
|
5065
|
+
() => createOption !== null ? [...filteredFlat, createOption] : filteredFlat,
|
|
5066
|
+
[filteredFlat, createOption]
|
|
5067
|
+
);
|
|
4992
5068
|
useEffect(() => {
|
|
4993
5069
|
if (!open) return;
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
setHighlightIndex(firstEnabled);
|
|
4998
|
-
}, [filteredFlat, open]);
|
|
4999
|
-
useEffect(() => {
|
|
5070
|
+
setHighlightIndex(navList.findIndex((opt) => opt.disabled !== true));
|
|
5071
|
+
}, [navList, open]);
|
|
5072
|
+
useIsoLayoutEffect4(() => {
|
|
5000
5073
|
if (open) {
|
|
5001
|
-
|
|
5002
|
-
return
|
|
5074
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
5075
|
+
return;
|
|
5003
5076
|
}
|
|
5004
5077
|
setQuery("");
|
|
5005
|
-
|
|
5078
|
+
setCreating(false);
|
|
5006
5079
|
}, [open]);
|
|
5007
5080
|
useEffect(() => {
|
|
5008
5081
|
if (!open) return;
|
|
5009
5082
|
function onPointerDown(event) {
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5083
|
+
const target = event.target;
|
|
5084
|
+
if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
|
|
5085
|
+
setOpen(false);
|
|
5013
5086
|
}
|
|
5014
|
-
|
|
5015
|
-
return () =>
|
|
5087
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
5088
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
5016
5089
|
}, [open]);
|
|
5090
|
+
const runCreate = useCallback(async () => {
|
|
5091
|
+
if (onCreate === void 0 || creating || typed === "") return;
|
|
5092
|
+
const result = onCreate(typed);
|
|
5093
|
+
if (result !== void 0 && typeof result.then === "function") {
|
|
5094
|
+
setCreating(true);
|
|
5095
|
+
try {
|
|
5096
|
+
await result;
|
|
5097
|
+
} catch {
|
|
5098
|
+
setCreating(false);
|
|
5099
|
+
return;
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
triggerRef.current?.focus();
|
|
5103
|
+
setOpen(false);
|
|
5104
|
+
}, [onCreate, creating, typed]);
|
|
5017
5105
|
const onSelectOption = useCallback(
|
|
5018
5106
|
(opt) => {
|
|
5019
5107
|
if (opt.disabled === true) return;
|
|
5108
|
+
if (opt.value === CREATE) {
|
|
5109
|
+
void runCreate();
|
|
5110
|
+
return;
|
|
5111
|
+
}
|
|
5020
5112
|
if (opt.href !== void 0 && LinkComponent !== void 0 && props.onChange === void 0) {
|
|
5021
5113
|
setOpen(false);
|
|
5022
5114
|
return;
|
|
@@ -5027,47 +5119,40 @@ function Combobox(props) {
|
|
|
5027
5119
|
}
|
|
5028
5120
|
setOpen(false);
|
|
5029
5121
|
},
|
|
5030
|
-
[LinkComponent, props]
|
|
5122
|
+
[LinkComponent, props, runCreate]
|
|
5123
|
+
);
|
|
5124
|
+
const moveTo = useCallback(
|
|
5125
|
+
(index) => {
|
|
5126
|
+
setHighlightIndex(index);
|
|
5127
|
+
if (index >= 0) revealInList(`${listId}-${index}`);
|
|
5128
|
+
},
|
|
5129
|
+
[listId]
|
|
5031
5130
|
);
|
|
5032
5131
|
const onKeyDown = useCallback(
|
|
5033
5132
|
(event) => {
|
|
5034
|
-
if (event.key === "ArrowDown") {
|
|
5133
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
5035
5134
|
event.preventDefault();
|
|
5036
|
-
|
|
5037
|
-
(current) => nextEnabledIndex(filteredFlat, current, 1)
|
|
5038
|
-
);
|
|
5039
|
-
return;
|
|
5040
|
-
}
|
|
5041
|
-
if (event.key === "ArrowUp") {
|
|
5042
|
-
event.preventDefault();
|
|
5043
|
-
setHighlightIndex(
|
|
5044
|
-
(current) => nextEnabledIndex(filteredFlat, current, -1)
|
|
5045
|
-
);
|
|
5135
|
+
moveTo(nextEnabledIndex(navList, highlightIndex, event.key === "ArrowDown" ? 1 : -1));
|
|
5046
5136
|
return;
|
|
5047
5137
|
}
|
|
5048
5138
|
if (event.key === "Home") {
|
|
5049
5139
|
event.preventDefault();
|
|
5050
|
-
|
|
5051
|
-
filteredFlat.findIndex((o) => o.disabled !== true)
|
|
5052
|
-
);
|
|
5140
|
+
moveTo(navList.findIndex((o) => o.disabled !== true));
|
|
5053
5141
|
return;
|
|
5054
5142
|
}
|
|
5055
5143
|
if (event.key === "End") {
|
|
5056
5144
|
event.preventDefault();
|
|
5057
5145
|
let last = -1;
|
|
5058
|
-
for (let i = 0; i <
|
|
5059
|
-
|
|
5060
|
-
if (opt !== void 0 && opt.disabled !== true) {
|
|
5061
|
-
last = i;
|
|
5062
|
-
}
|
|
5146
|
+
for (let i = 0; i < navList.length; i++) {
|
|
5147
|
+
if (navList[i]?.disabled !== true) last = i;
|
|
5063
5148
|
}
|
|
5064
|
-
|
|
5149
|
+
moveTo(last);
|
|
5065
5150
|
return;
|
|
5066
5151
|
}
|
|
5067
5152
|
if (event.key === "Enter") {
|
|
5068
5153
|
if (highlightIndex >= 0) {
|
|
5069
5154
|
event.preventDefault();
|
|
5070
|
-
const opt =
|
|
5155
|
+
const opt = navList[highlightIndex];
|
|
5071
5156
|
if (opt !== void 0) {
|
|
5072
5157
|
onSelectOption(opt);
|
|
5073
5158
|
}
|
|
@@ -5075,17 +5160,98 @@ function Combobox(props) {
|
|
|
5075
5160
|
return;
|
|
5076
5161
|
}
|
|
5077
5162
|
if (event.key === "Tab") {
|
|
5163
|
+
triggerRef.current?.focus();
|
|
5078
5164
|
setOpen(false);
|
|
5079
5165
|
return;
|
|
5080
5166
|
}
|
|
5081
5167
|
},
|
|
5082
|
-
[
|
|
5168
|
+
[navList, highlightIndex, onSelectOption, moveTo]
|
|
5083
5169
|
);
|
|
5170
|
+
const rowProps = {
|
|
5171
|
+
listId,
|
|
5172
|
+
flatOptions: filteredFlat,
|
|
5173
|
+
highlightIndex,
|
|
5174
|
+
activeValue: value ?? null,
|
|
5175
|
+
LinkComponent,
|
|
5176
|
+
onSelect: onSelectOption,
|
|
5177
|
+
onHover: setHighlightIndex
|
|
5178
|
+
};
|
|
5179
|
+
const panel = open && typeof document !== "undefined" ? createPortal(
|
|
5180
|
+
/* @__PURE__ */ jsxs(
|
|
5181
|
+
"div",
|
|
5182
|
+
{
|
|
5183
|
+
ref: panelRef,
|
|
5184
|
+
className: cn("cbx-ui-combo-panel", panelClassName),
|
|
5185
|
+
"data-cbx-scroll-layer": "",
|
|
5186
|
+
children: [
|
|
5187
|
+
/* @__PURE__ */ jsxs("div", { className: "cbx-ui-combo-search-row", children: [
|
|
5188
|
+
/* @__PURE__ */ jsx(SearchIcon, {}),
|
|
5189
|
+
/* @__PURE__ */ jsx(
|
|
5190
|
+
"input",
|
|
5191
|
+
{
|
|
5192
|
+
ref: inputRef,
|
|
5193
|
+
type: "text",
|
|
5194
|
+
value: query2,
|
|
5195
|
+
onChange: (e) => setQuery(e.target.value),
|
|
5196
|
+
onKeyDown,
|
|
5197
|
+
placeholder: searchPlaceholder,
|
|
5198
|
+
className: "cbx-ui-combo-search",
|
|
5199
|
+
"aria-label": searchPlaceholder,
|
|
5200
|
+
"aria-controls": listId,
|
|
5201
|
+
"aria-autocomplete": "list",
|
|
5202
|
+
"aria-activedescendant": highlightIndex >= 0 ? `${listId}-${highlightIndex}` : void 0
|
|
5203
|
+
}
|
|
5204
|
+
)
|
|
5205
|
+
] }),
|
|
5206
|
+
navList.length === 0 ? /* @__PURE__ */ jsx("p", { className: "cbx-ui-combo-empty", role: "status", children: emptyText }) : null,
|
|
5207
|
+
/* @__PURE__ */ jsxs(
|
|
5208
|
+
"ul",
|
|
5209
|
+
{
|
|
5210
|
+
id: listId,
|
|
5211
|
+
role: "listbox",
|
|
5212
|
+
"aria-label": ariaLabel ?? placeholder,
|
|
5213
|
+
className: "cbx-ui-combo-list",
|
|
5214
|
+
hidden: navList.length === 0,
|
|
5215
|
+
children: [
|
|
5216
|
+
filteredGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(
|
|
5217
|
+
OptionGroup,
|
|
5218
|
+
{
|
|
5219
|
+
group,
|
|
5220
|
+
...rowProps
|
|
5221
|
+
},
|
|
5222
|
+
group.label || `group-${groupIndex}`
|
|
5223
|
+
)),
|
|
5224
|
+
createOption !== null ? /* @__PURE__ */ jsx(
|
|
5225
|
+
OptionRow,
|
|
5226
|
+
{
|
|
5227
|
+
opt: createOption,
|
|
5228
|
+
index: filteredFlat.length,
|
|
5229
|
+
...rowProps,
|
|
5230
|
+
busy: creating
|
|
5231
|
+
}
|
|
5232
|
+
) : null
|
|
5233
|
+
]
|
|
5234
|
+
}
|
|
5235
|
+
),
|
|
5236
|
+
footerLink !== void 0 ? /* @__PURE__ */ jsx(
|
|
5237
|
+
FooterLink,
|
|
5238
|
+
{
|
|
5239
|
+
label: footerLink.label,
|
|
5240
|
+
href: footerLink.href,
|
|
5241
|
+
LinkComponent,
|
|
5242
|
+
onAfterClick: () => setOpen(false)
|
|
5243
|
+
}
|
|
5244
|
+
) : null
|
|
5245
|
+
]
|
|
5246
|
+
}
|
|
5247
|
+
),
|
|
5248
|
+
panelContainer(containerRef.current)
|
|
5249
|
+
) : null;
|
|
5084
5250
|
return /* @__PURE__ */ jsxs(
|
|
5085
5251
|
"div",
|
|
5086
5252
|
{
|
|
5087
5253
|
ref: containerRef,
|
|
5088
|
-
className: cn("
|
|
5254
|
+
className: cn("cbx-ui-combo", triggerWidth === "full" && "cbx-ui-combo--full", className),
|
|
5089
5255
|
onKeyDown: (event) => {
|
|
5090
5256
|
if (open && event.key === "Escape") {
|
|
5091
5257
|
event.preventDefault();
|
|
@@ -5105,20 +5271,13 @@ function Combobox(props) {
|
|
|
5105
5271
|
disabled,
|
|
5106
5272
|
"aria-expanded": open,
|
|
5107
5273
|
"aria-haspopup": "listbox",
|
|
5108
|
-
"aria-controls": listId,
|
|
5274
|
+
"aria-controls": open ? listId : void 0,
|
|
5109
5275
|
"aria-required": required,
|
|
5110
5276
|
"aria-label": ariaLabel,
|
|
5111
5277
|
"aria-describedby": props["aria-describedby"] ?? field["aria-describedby"],
|
|
5112
5278
|
"aria-invalid": props["aria-invalid"] ?? field["aria-invalid"],
|
|
5113
5279
|
onClick: () => setOpen((v) => !v),
|
|
5114
|
-
className: cn(
|
|
5115
|
-
"flex h-9 items-center gap-2 rounded-md border border-input bg-card px-3 text-left text-[13px] text-foreground transition-colors",
|
|
5116
|
-
triggerWidth === "full" && "w-full",
|
|
5117
|
-
"hover:border-border-strong focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none",
|
|
5118
|
-
open && "border-border-strong ring-2 ring-ring/30",
|
|
5119
|
-
disabled && "cursor-not-allowed opacity-60",
|
|
5120
|
-
triggerClassName
|
|
5121
|
-
),
|
|
5280
|
+
className: cn("cbx-ui-combo-trigger", triggerClassName),
|
|
5122
5281
|
children: [
|
|
5123
5282
|
activeOption?.avatar !== void 0 ? /* @__PURE__ */ jsx(
|
|
5124
5283
|
ComboboxAvatarChip,
|
|
@@ -5129,7 +5288,7 @@ function Combobox(props) {
|
|
|
5129
5288
|
) : activeOption?.icon !== void 0 ? /* @__PURE__ */ jsx(
|
|
5130
5289
|
activeOption.icon,
|
|
5131
5290
|
{
|
|
5132
|
-
className: "
|
|
5291
|
+
className: "cbx-ui-combo-icon",
|
|
5133
5292
|
strokeWidth: 1.7
|
|
5134
5293
|
}
|
|
5135
5294
|
) : null,
|
|
@@ -5137,176 +5296,86 @@ function Combobox(props) {
|
|
|
5137
5296
|
"span",
|
|
5138
5297
|
{
|
|
5139
5298
|
className: cn(
|
|
5140
|
-
"
|
|
5141
|
-
activeOption === null || activeOption === void 0
|
|
5299
|
+
"cbx-ui-combo-value",
|
|
5300
|
+
(activeOption === null || activeOption === void 0) && "is-placeholder"
|
|
5142
5301
|
),
|
|
5143
5302
|
children: activeOption !== null && activeOption !== void 0 ? activeOption.label : placeholder
|
|
5144
5303
|
}
|
|
5145
5304
|
),
|
|
5146
|
-
/* @__PURE__ */ jsx(Chevron2, {
|
|
5305
|
+
/* @__PURE__ */ jsx(Chevron2, {})
|
|
5147
5306
|
]
|
|
5148
5307
|
}
|
|
5149
5308
|
),
|
|
5150
|
-
|
|
5151
|
-
"div",
|
|
5152
|
-
{
|
|
5153
|
-
className: cn(
|
|
5154
|
-
"absolute left-0 right-0 top-full z-30 mt-1 overflow-hidden rounded-md border border-border bg-popover shadow-lg",
|
|
5155
|
-
panelClassName
|
|
5156
|
-
),
|
|
5157
|
-
children: [
|
|
5158
|
-
/* @__PURE__ */ jsx("div", { className: "border-b border-border/60 px-2 py-2", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
5159
|
-
/* @__PURE__ */ jsx(SearchIcon, {}),
|
|
5160
|
-
/* @__PURE__ */ jsx(
|
|
5161
|
-
"input",
|
|
5162
|
-
{
|
|
5163
|
-
ref: inputRef,
|
|
5164
|
-
type: "text",
|
|
5165
|
-
value: query2,
|
|
5166
|
-
onChange: (e) => setQuery(e.target.value),
|
|
5167
|
-
onKeyDown,
|
|
5168
|
-
placeholder: searchPlaceholder,
|
|
5169
|
-
className: "h-8 w-full rounded-sm border-0 bg-transparent pl-7 pr-2 text-base outline-none placeholder:text-muted-foreground/70 md:text-[13px]",
|
|
5170
|
-
"aria-controls": listId,
|
|
5171
|
-
"aria-autocomplete": "list",
|
|
5172
|
-
"aria-activedescendant": highlightIndex >= 0 ? `${listId}-${highlightIndex}` : void 0
|
|
5173
|
-
}
|
|
5174
|
-
)
|
|
5175
|
-
] }) }),
|
|
5176
|
-
/* @__PURE__ */ jsx(
|
|
5177
|
-
"ul",
|
|
5178
|
-
{
|
|
5179
|
-
id: listId,
|
|
5180
|
-
ref: listRef,
|
|
5181
|
-
role: "listbox",
|
|
5182
|
-
className: "max-h-72 overflow-y-auto py-1",
|
|
5183
|
-
children: filteredFlat.length === 0 ? /* @__PURE__ */ jsx("li", { className: "px-3 py-6 text-center text-[13px] text-muted-foreground", children: emptyText }) : filteredGroups.map((group, groupIndex) => /* @__PURE__ */ jsx(
|
|
5184
|
-
ComboboxGroupRows,
|
|
5185
|
-
{
|
|
5186
|
-
group,
|
|
5187
|
-
flatOptions: filteredFlat,
|
|
5188
|
-
listId,
|
|
5189
|
-
highlightIndex,
|
|
5190
|
-
activeValue: value ?? null,
|
|
5191
|
-
LinkComponent,
|
|
5192
|
-
onSelect: onSelectOption,
|
|
5193
|
-
onHover: (idx) => setHighlightIndex(idx)
|
|
5194
|
-
},
|
|
5195
|
-
group.label || `group-${groupIndex}`
|
|
5196
|
-
))
|
|
5197
|
-
}
|
|
5198
|
-
),
|
|
5199
|
-
footerLink !== void 0 ? /* @__PURE__ */ jsx(
|
|
5200
|
-
FooterLink,
|
|
5201
|
-
{
|
|
5202
|
-
label: footerLink.label,
|
|
5203
|
-
href: footerLink.href,
|
|
5204
|
-
LinkComponent,
|
|
5205
|
-
onAfterClick: () => setOpen(false)
|
|
5206
|
-
}
|
|
5207
|
-
) : null
|
|
5208
|
-
]
|
|
5209
|
-
}
|
|
5210
|
-
) : null
|
|
5309
|
+
panel
|
|
5211
5310
|
]
|
|
5212
5311
|
}
|
|
5213
5312
|
);
|
|
5214
5313
|
}
|
|
5215
|
-
function
|
|
5216
|
-
group
|
|
5217
|
-
|
|
5314
|
+
function OptionGroup({ group, ...rowProps }) {
|
|
5315
|
+
if (group.options.length === 0) return null;
|
|
5316
|
+
const rows2 = group.options.map((opt) => /* @__PURE__ */ jsx(
|
|
5317
|
+
OptionRow,
|
|
5318
|
+
{
|
|
5319
|
+
opt,
|
|
5320
|
+
index: rowProps.flatOptions.indexOf(opt),
|
|
5321
|
+
...rowProps
|
|
5322
|
+
},
|
|
5323
|
+
opt.value
|
|
5324
|
+
));
|
|
5325
|
+
if (group.label === "") return /* @__PURE__ */ jsx(Fragment, { children: rows2 });
|
|
5326
|
+
const headingId = `${rowProps.listId}-g-${rowProps.flatOptions.indexOf(group.options[0])}`;
|
|
5327
|
+
return /* @__PURE__ */ jsxs("li", { role: "presentation", children: [
|
|
5328
|
+
/* @__PURE__ */ jsx("div", { id: headingId, className: "cbx-ui-combo-group", "aria-hidden": "true", children: group.label }),
|
|
5329
|
+
/* @__PURE__ */ jsx("ul", { role: "group", "aria-labelledby": headingId, className: "cbx-ui-combo-grouplist", children: rows2 })
|
|
5330
|
+
] });
|
|
5331
|
+
}
|
|
5332
|
+
function OptionRow({
|
|
5333
|
+
opt,
|
|
5334
|
+
index,
|
|
5218
5335
|
listId,
|
|
5219
5336
|
highlightIndex,
|
|
5220
5337
|
activeValue,
|
|
5221
5338
|
LinkComponent,
|
|
5222
5339
|
onSelect,
|
|
5223
|
-
onHover
|
|
5340
|
+
onHover,
|
|
5341
|
+
busy = false
|
|
5224
5342
|
}) {
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
) : opt.icon !== void 0 ? /* @__PURE__ */ jsx(
|
|
5247
|
-
opt.icon,
|
|
5248
|
-
{
|
|
5249
|
-
className: "h-3.5 w-3.5 shrink-0 text-muted-foreground",
|
|
5250
|
-
strokeWidth: 1.7
|
|
5251
|
-
}
|
|
5252
|
-
) : null,
|
|
5253
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col leading-tight", children: [
|
|
5254
|
-
/* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-foreground", children: opt.label }),
|
|
5255
|
-
opt.secondary !== void 0 ? /* @__PURE__ */ jsx("span", { className: "text-mono truncate text-[10px] text-muted-foreground", children: opt.secondary }) : null
|
|
5256
|
-
] }),
|
|
5257
|
-
isActive ? /* @__PURE__ */ jsx(Check4, {}) : null
|
|
5258
|
-
] });
|
|
5259
|
-
const className = cn(
|
|
5260
|
-
"group block w-full rounded-sm transition-colors text-left",
|
|
5261
|
-
opt.disabled === true && "cursor-not-allowed opacity-50",
|
|
5262
|
-
isHighlighted && opt.disabled !== true && "bg-secondary",
|
|
5263
|
-
isActive && "bg-accent-soft hover:bg-accent-soft/80"
|
|
5264
|
-
);
|
|
5265
|
-
if (opt.href !== void 0 && LinkComponent !== void 0) {
|
|
5266
|
-
return /* @__PURE__ */ jsx(
|
|
5267
|
-
"li",
|
|
5268
|
-
{
|
|
5269
|
-
id: `${listId}-${flatIndex}`,
|
|
5270
|
-
role: "option",
|
|
5271
|
-
"aria-selected": isActive,
|
|
5272
|
-
"aria-disabled": opt.disabled === true,
|
|
5273
|
-
onMouseEnter: () => onHover(flatIndex),
|
|
5274
|
-
children: /* @__PURE__ */ jsx(
|
|
5275
|
-
LinkComponent,
|
|
5276
|
-
{
|
|
5277
|
-
href: opt.href,
|
|
5278
|
-
prefetch: true,
|
|
5279
|
-
className,
|
|
5280
|
-
children: inner
|
|
5281
|
-
}
|
|
5282
|
-
)
|
|
5283
|
-
},
|
|
5284
|
-
opt.value
|
|
5285
|
-
);
|
|
5286
|
-
}
|
|
5287
|
-
return /* @__PURE__ */ jsx(
|
|
5288
|
-
"li",
|
|
5289
|
-
{
|
|
5290
|
-
id: `${listId}-${flatIndex}`,
|
|
5291
|
-
role: "option",
|
|
5292
|
-
"aria-selected": isActive,
|
|
5293
|
-
"aria-disabled": opt.disabled === true,
|
|
5294
|
-
onMouseEnter: () => onHover(flatIndex),
|
|
5295
|
-
children: /* @__PURE__ */ jsx(
|
|
5296
|
-
"button",
|
|
5297
|
-
{
|
|
5298
|
-
type: "button",
|
|
5299
|
-
disabled: opt.disabled === true,
|
|
5300
|
-
onClick: () => onSelect(opt),
|
|
5301
|
-
className,
|
|
5302
|
-
children: inner
|
|
5303
|
-
}
|
|
5304
|
-
)
|
|
5305
|
-
},
|
|
5306
|
-
opt.value
|
|
5307
|
-
);
|
|
5308
|
-
})
|
|
5343
|
+
const isCreate = opt.value === CREATE;
|
|
5344
|
+
const isActive = !isCreate && opt.value === activeValue;
|
|
5345
|
+
const common = {
|
|
5346
|
+
id: `${listId}-${index}`,
|
|
5347
|
+
role: "option",
|
|
5348
|
+
"aria-selected": isActive,
|
|
5349
|
+
"aria-disabled": opt.disabled === true || void 0,
|
|
5350
|
+
"aria-busy": busy || void 0,
|
|
5351
|
+
tabIndex: -1,
|
|
5352
|
+
"data-highlighted": index === highlightIndex ? "" : void 0,
|
|
5353
|
+
"data-active": isActive ? "" : void 0,
|
|
5354
|
+
className: cn("cbx-ui-combo-option", isCreate && "cbx-ui-combo-create"),
|
|
5355
|
+
onMouseEnter: () => onHover(index)
|
|
5356
|
+
};
|
|
5357
|
+
const inner = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5358
|
+
isCreate ? busy ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-spinner cbx-ui-combo-icon", "aria-hidden": "true" }) : /* @__PURE__ */ jsx(Plus5, {}) : opt.avatar !== void 0 ? /* @__PURE__ */ jsx(ComboboxAvatarChip, { avatar: opt.avatar, fallbackLabel: opt.label }) : opt.icon !== void 0 ? /* @__PURE__ */ jsx(opt.icon, { className: "cbx-ui-combo-icon", strokeWidth: 1.7 }) : null,
|
|
5359
|
+
/* @__PURE__ */ jsxs("span", { className: "cbx-ui-combo-text", children: [
|
|
5360
|
+
/* @__PURE__ */ jsx("span", { className: "cbx-ui-combo-label", children: opt.label }),
|
|
5361
|
+
opt.secondary !== void 0 ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-combo-secondary", children: opt.secondary }) : null
|
|
5362
|
+
] }),
|
|
5363
|
+
isActive ? /* @__PURE__ */ jsx(Check4, {}) : null
|
|
5309
5364
|
] });
|
|
5365
|
+
if (opt.href !== void 0 && LinkComponent !== void 0) {
|
|
5366
|
+
const { tabIndex: _unused, ...row } = common;
|
|
5367
|
+
return /* @__PURE__ */ jsx("li", { ...row, className: cn(common.className, "cbx-ui-combo-linkrow"), children: /* @__PURE__ */ jsx(LinkComponent, { href: opt.href, prefetch: true, className: "cbx-ui-combo-link", children: inner }) });
|
|
5368
|
+
}
|
|
5369
|
+
return /* @__PURE__ */ jsx("li", { role: "presentation", children: /* @__PURE__ */ jsx(
|
|
5370
|
+
"button",
|
|
5371
|
+
{
|
|
5372
|
+
type: "button",
|
|
5373
|
+
...common,
|
|
5374
|
+
disabled: opt.disabled === true,
|
|
5375
|
+
onClick: () => onSelect(opt),
|
|
5376
|
+
children: inner
|
|
5377
|
+
}
|
|
5378
|
+
) });
|
|
5310
5379
|
}
|
|
5311
5380
|
function FooterLink({
|
|
5312
5381
|
label,
|
|
@@ -5314,7 +5383,7 @@ function FooterLink({
|
|
|
5314
5383
|
LinkComponent,
|
|
5315
5384
|
onAfterClick
|
|
5316
5385
|
}) {
|
|
5317
|
-
const className = "
|
|
5386
|
+
const className = "cbx-ui-combo-footer";
|
|
5318
5387
|
if (LinkComponent !== void 0) {
|
|
5319
5388
|
return /* @__PURE__ */ jsxs(
|
|
5320
5389
|
LinkComponent,
|
|
@@ -5354,7 +5423,7 @@ function ComboboxAvatarChip({
|
|
|
5354
5423
|
{
|
|
5355
5424
|
src: avatar.src,
|
|
5356
5425
|
alt: "",
|
|
5357
|
-
className: "
|
|
5426
|
+
className: "cbx-ui-combo-avatar",
|
|
5358
5427
|
loading: "lazy"
|
|
5359
5428
|
}
|
|
5360
5429
|
);
|
|
@@ -5363,10 +5432,7 @@ function ComboboxAvatarChip({
|
|
|
5363
5432
|
"span",
|
|
5364
5433
|
{
|
|
5365
5434
|
style,
|
|
5366
|
-
className: cn(
|
|
5367
|
-
"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-[9px] font-semibold tracking-tight",
|
|
5368
|
-
avatar.accent === void 0 && "bg-info-soft text-info-text"
|
|
5369
|
-
),
|
|
5435
|
+
className: cn("cbx-ui-combo-avatar", avatar.accent === void 0 && "is-initials"),
|
|
5370
5436
|
children: initials2
|
|
5371
5437
|
}
|
|
5372
5438
|
);
|
|
@@ -5405,7 +5471,7 @@ function matchesQuery(option, q) {
|
|
|
5405
5471
|
function nextEnabledIndex(options, current, direction) {
|
|
5406
5472
|
const total = options.length;
|
|
5407
5473
|
if (total === 0) return -1;
|
|
5408
|
-
let i = current;
|
|
5474
|
+
let i = current < 0 && direction === -1 ? 0 : current;
|
|
5409
5475
|
for (let step = 0; step < total; step++) {
|
|
5410
5476
|
i = (i + direction + total) % total;
|
|
5411
5477
|
const opt = options[i];
|
|
@@ -5415,7 +5481,8 @@ function nextEnabledIndex(options, current, direction) {
|
|
|
5415
5481
|
}
|
|
5416
5482
|
return -1;
|
|
5417
5483
|
}
|
|
5418
|
-
|
|
5484
|
+
var CREATE_ROW = CREATE;
|
|
5485
|
+
function Chevron2() {
|
|
5419
5486
|
return /* @__PURE__ */ jsx(
|
|
5420
5487
|
"svg",
|
|
5421
5488
|
{
|
|
@@ -5428,10 +5495,7 @@ function Chevron2({ open }) {
|
|
|
5428
5495
|
strokeLinecap: "round",
|
|
5429
5496
|
strokeLinejoin: "round",
|
|
5430
5497
|
"aria-hidden": true,
|
|
5431
|
-
className:
|
|
5432
|
-
"shrink-0 text-muted-foreground transition-transform duration-150",
|
|
5433
|
-
open && "rotate-180"
|
|
5434
|
-
),
|
|
5498
|
+
className: "cbx-ui-combo-chevron",
|
|
5435
5499
|
children: /* @__PURE__ */ jsx("path", { d: "m3.5 5.5 3.5 3.5 3.5-3.5" })
|
|
5436
5500
|
}
|
|
5437
5501
|
);
|
|
@@ -5448,7 +5512,7 @@ function Check4() {
|
|
|
5448
5512
|
strokeWidth: "1.6",
|
|
5449
5513
|
strokeLinecap: "round",
|
|
5450
5514
|
strokeLinejoin: "round",
|
|
5451
|
-
className: "
|
|
5515
|
+
className: "cbx-ui-combo-check",
|
|
5452
5516
|
"aria-hidden": true,
|
|
5453
5517
|
children: /* @__PURE__ */ jsx("path", { d: "m3 7.5 2.5 2.5L11 4.5" })
|
|
5454
5518
|
}
|
|
@@ -5458,15 +5522,15 @@ function Plus5() {
|
|
|
5458
5522
|
return /* @__PURE__ */ jsx(
|
|
5459
5523
|
"svg",
|
|
5460
5524
|
{
|
|
5461
|
-
width: "
|
|
5462
|
-
height: "
|
|
5525
|
+
width: "14",
|
|
5526
|
+
height: "14",
|
|
5463
5527
|
viewBox: "0 0 12 12",
|
|
5464
5528
|
fill: "none",
|
|
5465
5529
|
stroke: "currentColor",
|
|
5466
5530
|
strokeWidth: "1.8",
|
|
5467
5531
|
strokeLinecap: "round",
|
|
5468
5532
|
strokeLinejoin: "round",
|
|
5469
|
-
className: "
|
|
5533
|
+
className: "cbx-ui-combo-icon",
|
|
5470
5534
|
"aria-hidden": true,
|
|
5471
5535
|
children: /* @__PURE__ */ jsx("path", { d: "M6 2v8M2 6h8" })
|
|
5472
5536
|
}
|
|
@@ -5484,7 +5548,7 @@ function SearchIcon() {
|
|
|
5484
5548
|
strokeWidth: "1.6",
|
|
5485
5549
|
strokeLinecap: "round",
|
|
5486
5550
|
strokeLinejoin: "round",
|
|
5487
|
-
className: "
|
|
5551
|
+
className: "cbx-ui-combo-search-icon",
|
|
5488
5552
|
"aria-hidden": true,
|
|
5489
5553
|
children: [
|
|
5490
5554
|
/* @__PURE__ */ jsx("circle", { cx: "6", cy: "6", r: "4.25" }),
|
|
@@ -5946,6 +6010,253 @@ var Switch = forwardRef(function Switch2({ checked, onCheckedChange, disabled =
|
|
|
5946
6010
|
name !== void 0 && checked && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: "on" })
|
|
5947
6011
|
] });
|
|
5948
6012
|
});
|
|
6013
|
+
var trimmed = (tag) => tag.trim();
|
|
6014
|
+
function TagInput(props) {
|
|
6015
|
+
const { t } = useCboxLocalization();
|
|
6016
|
+
const field = useFieldControl();
|
|
6017
|
+
const {
|
|
6018
|
+
value,
|
|
6019
|
+
onChange,
|
|
6020
|
+
suggestions = [],
|
|
6021
|
+
creatable = true,
|
|
6022
|
+
normalize = trimmed,
|
|
6023
|
+
validate,
|
|
6024
|
+
maxLength,
|
|
6025
|
+
maxTags,
|
|
6026
|
+
placeholder = t("Add a tag\u2026"),
|
|
6027
|
+
emptyText = t("Nothing matches."),
|
|
6028
|
+
disabled = false,
|
|
6029
|
+
required = field.required ?? false,
|
|
6030
|
+
id: idProp,
|
|
6031
|
+
ariaLabel,
|
|
6032
|
+
className
|
|
6033
|
+
} = props;
|
|
6034
|
+
const [query2, setQuery] = useState("");
|
|
6035
|
+
const [focused, setFocused] = useState(false);
|
|
6036
|
+
const [dismissed, setDismissed] = useState(false);
|
|
6037
|
+
const [highlightIndex, setHighlightIndex] = useState(-1);
|
|
6038
|
+
const boxRef = useRef(null);
|
|
6039
|
+
const inputRef = useRef(null);
|
|
6040
|
+
const panelRef = useRef(null);
|
|
6041
|
+
const reactId = useId();
|
|
6042
|
+
const id = idProp ?? field.id ?? reactId;
|
|
6043
|
+
const listId = `${id}-listbox`;
|
|
6044
|
+
const labelOf = (tag) => suggestions.find((option) => option.value === tag)?.label ?? tag;
|
|
6045
|
+
const problemWith = (tag, current) => {
|
|
6046
|
+
if (current.includes(tag)) return t("\u201C{tag}\u201D is already added.", { tag: labelOf(tag) });
|
|
6047
|
+
if (maxTags !== void 0 && current.length >= maxTags) return t("Up to {count} tags.", { count: maxTags });
|
|
6048
|
+
if (maxLength !== void 0 && tag.length > maxLength) return t("Keep it to {count} characters.", { count: maxLength });
|
|
6049
|
+
if (!creatable && !suggestions.some((option) => option.value === tag)) return t("Choose one of the suggestions.");
|
|
6050
|
+
return validate?.(tag) ?? null;
|
|
6051
|
+
};
|
|
6052
|
+
const typed = query2.trim();
|
|
6053
|
+
const candidate = typed === "" ? "" : normalize(query2);
|
|
6054
|
+
const lower = typed.toLowerCase();
|
|
6055
|
+
const full = maxTags !== void 0 && value.length >= maxTags;
|
|
6056
|
+
const matches2 = useMemo(
|
|
6057
|
+
() => full ? [] : suggestions.filter((option) => !value.includes(option.value) && (lower === "" || matchesQuery(option, lower))),
|
|
6058
|
+
[full, suggestions, value, lower]
|
|
6059
|
+
);
|
|
6060
|
+
const exact = typed === "" ? void 0 : matches2.find((option) => option.value === candidate || option.label.toLowerCase() === lower);
|
|
6061
|
+
const problem = candidate === "" || exact !== void 0 || !creatable && !full ? null : problemWith(candidate, value);
|
|
6062
|
+
const createOption = creatable && !full && candidate !== "" && exact === void 0 ? { value: CREATE_ROW, label: t("Add \u201C{tag}\u201D", { tag: candidate }), disabled: problem !== null } : null;
|
|
6063
|
+
const rows2 = createOption !== null ? [...matches2, createOption] : matches2;
|
|
6064
|
+
const showEmpty = typed !== "" && rows2.length === 0 && problem === null;
|
|
6065
|
+
const open = focused && !dismissed && !disabled && (rows2.length > 0 || problem !== null || showEmpty);
|
|
6066
|
+
useAnchoredPanel(open, boxRef, panelRef, value.length);
|
|
6067
|
+
const canAdd = createOption !== null && createOption.disabled !== true;
|
|
6068
|
+
useEffect(() => {
|
|
6069
|
+
if (typed === "") setHighlightIndex(-1);
|
|
6070
|
+
else if (exact !== void 0) setHighlightIndex(matches2.indexOf(exact));
|
|
6071
|
+
else if (matches2.length > 0) setHighlightIndex(0);
|
|
6072
|
+
else setHighlightIndex(canAdd ? 0 : -1);
|
|
6073
|
+
}, [typed, matches2, exact, canAdd]);
|
|
6074
|
+
const add = (tags) => {
|
|
6075
|
+
if (tags.length > 0) onChange([...value, ...tags]);
|
|
6076
|
+
};
|
|
6077
|
+
const commit = (parts, rest = "") => {
|
|
6078
|
+
const next = [...value];
|
|
6079
|
+
let left = null;
|
|
6080
|
+
for (const part of parts) {
|
|
6081
|
+
if (part.trim() === "") continue;
|
|
6082
|
+
const tag = normalize(part);
|
|
6083
|
+
const known = suggestions.find((option) => option.value === tag || option.label.toLowerCase() === part.trim().toLowerCase());
|
|
6084
|
+
const resolved = known?.value ?? tag;
|
|
6085
|
+
if (problemWith(resolved, next) === null) next.push(resolved);
|
|
6086
|
+
else left ??= part.trim();
|
|
6087
|
+
}
|
|
6088
|
+
add(next.slice(value.length));
|
|
6089
|
+
setQuery(left ?? rest.trimStart());
|
|
6090
|
+
setDismissed(false);
|
|
6091
|
+
};
|
|
6092
|
+
const remove = (tag) => onChange(value.filter((existing) => existing !== tag));
|
|
6093
|
+
const onInput = (event) => {
|
|
6094
|
+
const text = event.target.value;
|
|
6095
|
+
setDismissed(false);
|
|
6096
|
+
if (/[,\n]/.test(text)) {
|
|
6097
|
+
const parts = text.split(/[,\n]/);
|
|
6098
|
+
const rest = parts.pop() ?? "";
|
|
6099
|
+
commit(parts, rest);
|
|
6100
|
+
return;
|
|
6101
|
+
}
|
|
6102
|
+
setQuery(text);
|
|
6103
|
+
};
|
|
6104
|
+
const pick = (option) => {
|
|
6105
|
+
if (option.disabled === true) return;
|
|
6106
|
+
if (option.value === CREATE_ROW) commit([query2]);
|
|
6107
|
+
else {
|
|
6108
|
+
add([option.value]);
|
|
6109
|
+
setQuery("");
|
|
6110
|
+
}
|
|
6111
|
+
inputRef.current?.focus();
|
|
6112
|
+
};
|
|
6113
|
+
const moveTo = (index) => {
|
|
6114
|
+
setDismissed(false);
|
|
6115
|
+
setHighlightIndex(index);
|
|
6116
|
+
if (index >= 0) revealInList(`${listId}-${index}`);
|
|
6117
|
+
};
|
|
6118
|
+
const onKeyDown = (event) => {
|
|
6119
|
+
if (event.nativeEvent.isComposing) return;
|
|
6120
|
+
if (event.key === "Enter") {
|
|
6121
|
+
const row = open ? rows2[highlightIndex] : void 0;
|
|
6122
|
+
if (row !== void 0) {
|
|
6123
|
+
event.preventDefault();
|
|
6124
|
+
pick(row);
|
|
6125
|
+
} else if (typed !== "") {
|
|
6126
|
+
event.preventDefault();
|
|
6127
|
+
commit([query2]);
|
|
6128
|
+
}
|
|
6129
|
+
return;
|
|
6130
|
+
}
|
|
6131
|
+
if (event.key === "Backspace" && query2 === "" && value.length > 0) {
|
|
6132
|
+
event.preventDefault();
|
|
6133
|
+
remove(value[value.length - 1]);
|
|
6134
|
+
return;
|
|
6135
|
+
}
|
|
6136
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
6137
|
+
event.preventDefault();
|
|
6138
|
+
moveTo(nextEnabledIndex(rows2, highlightIndex, event.key === "ArrowDown" ? 1 : -1));
|
|
6139
|
+
return;
|
|
6140
|
+
}
|
|
6141
|
+
if (event.key === "Escape" && open) {
|
|
6142
|
+
event.preventDefault();
|
|
6143
|
+
event.stopPropagation();
|
|
6144
|
+
setDismissed(true);
|
|
6145
|
+
}
|
|
6146
|
+
};
|
|
6147
|
+
const invalid = problem !== null ? true : props["aria-invalid"] ?? field["aria-invalid"];
|
|
6148
|
+
const panel = open && typeof document !== "undefined" ? createPortal(
|
|
6149
|
+
/* @__PURE__ */ jsxs(
|
|
6150
|
+
"div",
|
|
6151
|
+
{
|
|
6152
|
+
ref: panelRef,
|
|
6153
|
+
className: "cbx-ui-combo-panel cbx-ui-tags-panel",
|
|
6154
|
+
"data-cbx-scroll-layer": "",
|
|
6155
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
6156
|
+
children: [
|
|
6157
|
+
problem !== null ? /* @__PURE__ */ jsxs("p", { className: "cbx-ui-combo-note", "aria-hidden": "true", children: [
|
|
6158
|
+
/* @__PURE__ */ jsx(WarnIcon, {}),
|
|
6159
|
+
/* @__PURE__ */ jsx("span", { children: problem })
|
|
6160
|
+
] }) : null,
|
|
6161
|
+
showEmpty ? /* @__PURE__ */ jsx("p", { className: "cbx-ui-combo-empty", children: emptyText }) : null,
|
|
6162
|
+
/* @__PURE__ */ jsx("ul", { id: listId, role: "listbox", "aria-label": ariaLabel ?? placeholder, className: "cbx-ui-combo-list", hidden: rows2.length === 0, children: rows2.map((option, index) => /* @__PURE__ */ jsx(
|
|
6163
|
+
OptionRow,
|
|
6164
|
+
{
|
|
6165
|
+
opt: option,
|
|
6166
|
+
index,
|
|
6167
|
+
listId,
|
|
6168
|
+
flatOptions: rows2,
|
|
6169
|
+
highlightIndex,
|
|
6170
|
+
activeValue: null,
|
|
6171
|
+
onSelect: pick,
|
|
6172
|
+
onHover: setHighlightIndex
|
|
6173
|
+
},
|
|
6174
|
+
option.value
|
|
6175
|
+
)) })
|
|
6176
|
+
]
|
|
6177
|
+
}
|
|
6178
|
+
),
|
|
6179
|
+
panelContainer(boxRef.current)
|
|
6180
|
+
) : null;
|
|
6181
|
+
return /* @__PURE__ */ jsxs(
|
|
6182
|
+
"div",
|
|
6183
|
+
{
|
|
6184
|
+
ref: boxRef,
|
|
6185
|
+
className: cn("cbx-ui-tags", className),
|
|
6186
|
+
"data-invalid": invalid === true || invalid === "true" ? "" : void 0,
|
|
6187
|
+
"data-disabled": disabled ? "" : void 0,
|
|
6188
|
+
onMouseDown: (event) => {
|
|
6189
|
+
if (event.target === event.currentTarget) {
|
|
6190
|
+
event.preventDefault();
|
|
6191
|
+
inputRef.current?.focus();
|
|
6192
|
+
}
|
|
6193
|
+
},
|
|
6194
|
+
children: [
|
|
6195
|
+
value.map((tag) => {
|
|
6196
|
+
const label = labelOf(tag);
|
|
6197
|
+
return /* @__PURE__ */ jsxs("span", { className: "cbx-ui-tag", children: [
|
|
6198
|
+
/* @__PURE__ */ jsx("span", { className: "cbx-ui-tag-label", children: label }),
|
|
6199
|
+
!disabled ? /* @__PURE__ */ jsx(
|
|
6200
|
+
"button",
|
|
6201
|
+
{
|
|
6202
|
+
type: "button",
|
|
6203
|
+
tabIndex: -1,
|
|
6204
|
+
className: "cbx-ui-tag-remove",
|
|
6205
|
+
"aria-label": t("Remove {tag}", { tag: label }),
|
|
6206
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
6207
|
+
onClick: () => {
|
|
6208
|
+
remove(tag);
|
|
6209
|
+
inputRef.current?.focus();
|
|
6210
|
+
},
|
|
6211
|
+
children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M3.5 3.5l5 5M8.5 3.5l-5 5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) })
|
|
6212
|
+
}
|
|
6213
|
+
) : null
|
|
6214
|
+
] }, tag);
|
|
6215
|
+
}),
|
|
6216
|
+
/* @__PURE__ */ jsx(
|
|
6217
|
+
"input",
|
|
6218
|
+
{
|
|
6219
|
+
ref: inputRef,
|
|
6220
|
+
id,
|
|
6221
|
+
type: "text",
|
|
6222
|
+
role: "combobox",
|
|
6223
|
+
className: "cbx-ui-tags-input",
|
|
6224
|
+
value: query2,
|
|
6225
|
+
disabled,
|
|
6226
|
+
placeholder: value.length === 0 ? placeholder : void 0,
|
|
6227
|
+
autoComplete: "off",
|
|
6228
|
+
enterKeyHint: "enter",
|
|
6229
|
+
"aria-label": ariaLabel,
|
|
6230
|
+
"aria-expanded": open,
|
|
6231
|
+
"aria-controls": open ? listId : void 0,
|
|
6232
|
+
"aria-autocomplete": "list",
|
|
6233
|
+
"aria-activedescendant": open && highlightIndex >= 0 ? `${listId}-${highlightIndex}` : void 0,
|
|
6234
|
+
"aria-required": required,
|
|
6235
|
+
"aria-invalid": invalid,
|
|
6236
|
+
"aria-describedby": props["aria-describedby"] ?? field["aria-describedby"],
|
|
6237
|
+
onChange: onInput,
|
|
6238
|
+
onKeyDown,
|
|
6239
|
+
onFocus: () => setFocused(true),
|
|
6240
|
+
onBlur: () => {
|
|
6241
|
+
setFocused(false);
|
|
6242
|
+
setDismissed(false);
|
|
6243
|
+
if (typed !== "" && problem === null && (creatable || exact !== void 0)) commit([query2]);
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
),
|
|
6247
|
+
/* @__PURE__ */ jsx("span", { className: "cbx-ui-sr-only", "aria-live": "polite", children: focused ? problem ?? "" : "" }),
|
|
6248
|
+
panel
|
|
6249
|
+
]
|
|
6250
|
+
}
|
|
6251
|
+
);
|
|
6252
|
+
}
|
|
6253
|
+
function WarnIcon() {
|
|
6254
|
+
return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 14 14", width: "14", height: "14", fill: "none", "aria-hidden": "true", className: "cbx-ui-combo-icon", children: [
|
|
6255
|
+
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "5.75", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
6256
|
+
/* @__PURE__ */ jsx("path", { d: "M7 4.25v3.25", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
|
|
6257
|
+
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "9.75", r: "0.85", fill: "currentColor" })
|
|
6258
|
+
] });
|
|
6259
|
+
}
|
|
5949
6260
|
function SurfaceModal({
|
|
5950
6261
|
open,
|
|
5951
6262
|
onClose,
|
|
@@ -6437,6 +6748,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
|
|
|
6437
6748
|
] });
|
|
6438
6749
|
}
|
|
6439
6750
|
|
|
6440
|
-
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sheet, SheetClose, Slider, Sparkline, Spinner, StatTile, StatusPill, Switch, Textarea, applyTheme, buildUrlSearch, buttonClassName, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
6751
|
+
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sheet, SheetClose, Slider, Sparkline, Spinner, StatTile, StatusPill, Switch, TagInput, Textarea, applyTheme, buildUrlSearch, buttonClassName, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
6441
6752
|
//# sourceMappingURL=index.js.map
|
|
6442
6753
|
//# sourceMappingURL=index.js.map
|