@mlw-packages/react-components 1.10.28 → 1.10.30

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.mjs CHANGED
@@ -5,7 +5,7 @@ import { Slot } from '@radix-ui/react-slot';
5
5
  import { cva } from 'class-variance-authority';
6
6
  import { clsx } from 'clsx';
7
7
  import { twMerge } from 'tailwind-merge';
8
- import { XIcon, CircleNotchIcon, MagnifyingGlassIcon, CaretUpIcon, CaretDownIcon, CheckIcon, CaretRightIcon, CircleIcon, CloudArrowUpIcon, MinusIcon, CaretUpDownIcon, PencilSimpleIcon, ArrowsLeftRightIcon, FloppyDiskIcon, PlusIcon, TrashIcon, SidebarSimpleIcon, CommandIcon, ArrowElbowDownRightIcon, ArrowBendUpLeftIcon, FilePdfIcon, FileDocIcon, FileXlsIcon, FilePptIcon, FileCsvIcon, FileTextIcon, FileImageIcon, FileVideoIcon, FileAudioIcon, FileZipIcon, FileIcon, DotsSixVerticalIcon, CopyIcon, InfoIcon, WarningIcon, XCircleIcon, CheckCircleIcon, CaretLeftIcon, DownloadSimpleIcon, UploadSimpleIcon, ArrowClockwiseIcon, ArrowLeftIcon, GearIcon, BellIcon, DotsThreeIcon, FunnelIcon, HeartIcon, StarIcon, EyeIcon, EyeSlashIcon, LockIcon, LockOpenIcon, FolderIcon, ArrowRightIcon as ArrowRightIcon$1, ArrowsOutIcon, DownloadIcon, CalendarBlankIcon, CalendarIcon, MapPinIcon, CalendarDotsIcon, SunIcon, ClockIcon, AlignLeftIcon, CaretLeft, CaretRight, ArrowDownIcon, ClockUserIcon, EyeSlash, Eye, ArrowUpRightIcon, ArrowDownRightIcon, FunnelSimpleIcon, PencilIcon, ClockCounterClockwiseIcon, FileArchiveIcon, TerminalIcon, CodeIcon, CalendarDotIcon as CalendarDotIcon$1, MoonIcon, DesktopIcon } from '@phosphor-icons/react';
8
+ import { XIcon, CircleNotchIcon, MagnifyingGlassIcon, CaretUpIcon, CaretDownIcon, CheckIcon, CaretRightIcon, CircleIcon, CloudArrowUpIcon, MinusIcon, CaretUpDownIcon, PencilSimpleIcon, ArrowsLeftRightIcon, FloppyDiskIcon, PlusIcon, TrashIcon, SidebarSimpleIcon, CommandIcon, ArrowElbowDownRightIcon, ArrowBendUpLeftIcon, FilePdfIcon, FileDocIcon, FileXlsIcon, FilePptIcon, FileCsvIcon, FileTextIcon, FileImageIcon, FileVideoIcon, FileAudioIcon, FileZipIcon, FileIcon, DotsSixVerticalIcon, CopyIcon, InfoIcon, WarningIcon, XCircleIcon, CheckCircleIcon, CaretLeftIcon, DownloadSimpleIcon, UploadSimpleIcon, ArrowClockwiseIcon, ArrowLeftIcon, GearIcon, BellIcon, DotsThreeIcon, FunnelIcon, HeartIcon, StarIcon, EyeIcon, EyeSlashIcon, LockIcon, LockOpenIcon, FolderIcon, ArrowRightIcon as ArrowRightIcon$1, ArrowsOutIcon, DownloadIcon, CalendarBlankIcon, CalendarIcon, MapPinIcon, CalendarDotsIcon, SunIcon, ClockIcon, AlignLeftIcon, CaretLeft, CaretRight, ArrowDownIcon, ClockUserIcon, EyeSlash, Eye, ArrowUpRightIcon, ArrowDownRightIcon, FunnelSimpleIcon, PencilIcon, FileArchiveIcon, TerminalIcon, CodeIcon, CalendarDotIcon as CalendarDotIcon$1, MoonIcon, DesktopIcon } from '@phosphor-icons/react';
9
9
  import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
10
10
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
11
  import * as DialogPrimitive from '@radix-ui/react-dialog';
@@ -9759,7 +9759,8 @@ function DayViewAgenda({
9759
9759
  onEventSelect,
9760
9760
  showUndatedEvents,
9761
9761
  noTime = false,
9762
- onEventCreate
9762
+ onEventCreate,
9763
+ allDayCell = false
9763
9764
  }) {
9764
9765
  const hours = useMemo(() => {
9765
9766
  const dayStart = startOfDay(currentDate);
@@ -9873,7 +9874,7 @@ function DayViewAgenda({
9873
9874
  const showAllDaySection = allDayEvents.length > 0;
9874
9875
  const { currentTimePosition, currentTimeVisible } = useCurrentTimeIndicatorAgenda(currentDate, "day");
9875
9876
  return /* @__PURE__ */ jsxs("div", { className: "contents", "data-slot": "day-view", children: [
9876
- showAllDaySection && /* @__PURE__ */ jsx("div", { className: "border-border/70 border-t bg-muted/50", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[3rem_1fr] sm:grid-cols-[4rem_1fr]", children: [
9877
+ showAllDaySection && !allDayCell && /* @__PURE__ */ jsx("div", { className: "border-border/70 border-t bg-muted/50", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[3rem_1fr] sm:grid-cols-[4rem_1fr]", children: [
9877
9878
  /* @__PURE__ */ jsx("div", { className: "relative border-border/70 border-r flex items-center justify-center p-1", children: /* @__PURE__ */ jsx("span", { className: "text-center text-[10px] text-muted-foreground/70 sm:text-xs", children: "Todo Dia" }) }),
9878
9879
  /* @__PURE__ */ jsx("div", { className: "relative border-border/70 border-r p-1 last:border-r-0", children: allDayEvents.map((event) => {
9879
9880
  const eventStart = getEventStartDate(event);
@@ -9920,7 +9921,100 @@ function DayViewAgenda({
9920
9921
  },
9921
9922
  hour.toString()
9922
9923
  )) }),
9923
- /* @__PURE__ */ jsxs("div", { className: "relative", children: [
9924
+ showAllDaySection && allDayCell ? /* @__PURE__ */ jsxs("div", { className: "relative", children: [
9925
+ allDayEvents.map((event) => {
9926
+ const eventStart = new Date(event.start);
9927
+ const eventEnd = new Date(new Date(event.end).setHours(23, 59));
9928
+ const isFirstDay = isSameDay(currentDate, eventStart);
9929
+ const isLastDay = isSameDay(currentDate, eventEnd);
9930
+ return /* @__PURE__ */ jsx(
9931
+ "div",
9932
+ {
9933
+ className: "absolute z-10 px-0.5",
9934
+ style: { height: "100%", width: "100%", padding: "10px" },
9935
+ children: /* @__PURE__ */ jsx(TooltipProviderBase, { delayDuration: 400, children: /* @__PURE__ */ jsxs(TooltipBase, { children: [
9936
+ /* @__PURE__ */ jsx(TooltipTriggerBase, { asChild: true, children: /* @__PURE__ */ jsx("div", { className: "size-full", children: /* @__PURE__ */ jsx(
9937
+ EventItemAgenda,
9938
+ {
9939
+ event,
9940
+ view: "day",
9941
+ isFirstDay,
9942
+ isLastDay,
9943
+ onClick: (e) => handleEventClick(event, e),
9944
+ noTime,
9945
+ className: "flex justify-start items-start rounded-sm p-2"
9946
+ }
9947
+ ) }) }),
9948
+ /* @__PURE__ */ jsxs(
9949
+ TooltipContentBase,
9950
+ {
9951
+ side: "top",
9952
+ sideOffset: 6,
9953
+ className: "max-w-[220px] space-y-0.5",
9954
+ children: [
9955
+ /* @__PURE__ */ jsx("p", { className: "font-semibold text-sm leading-snug", children: event.title }),
9956
+ /* @__PURE__ */ jsx("p", { className: "text-xs opacity-90", children: formatDurationAgenda(event) }),
9957
+ event.location && /* @__PURE__ */ jsxs("p", { className: "text-xs flex items-center gap-2", children: [
9958
+ /* @__PURE__ */ jsx(MapPinIcon, { size: 15 }),
9959
+ " ",
9960
+ event.location
9961
+ ] }),
9962
+ event.description && /* @__PURE__ */ jsx("p", { className: "text-xs opacity-75 line-clamp-2", children: event.description })
9963
+ ]
9964
+ }
9965
+ )
9966
+ ] }) })
9967
+ },
9968
+ `spanning-${event.id}`
9969
+ );
9970
+ }),
9971
+ currentTimeVisible && /* @__PURE__ */ jsx(
9972
+ "div",
9973
+ {
9974
+ className: "pointer-events-none absolute right-0 left-0 z-20",
9975
+ style: { top: `${currentTimePosition}%` },
9976
+ children: /* @__PURE__ */ jsxs("div", { className: "relative flex items-center", children: [
9977
+ /* @__PURE__ */ jsx("div", { className: "-left-1 absolute h-2 w-2 rounded-full bg-primary" }),
9978
+ /* @__PURE__ */ jsx("div", { className: "h-[2px] w-full bg-primary" })
9979
+ ] })
9980
+ }
9981
+ ),
9982
+ hours.map((hour) => {
9983
+ const hourValue = getHours(hour);
9984
+ return /* @__PURE__ */ jsx(
9985
+ "div",
9986
+ {
9987
+ className: "relative h-[var(--week-cells-height)] border-border/70 border-b last:border-b-0",
9988
+ children: [0, 1, 2, 3].map((quarter) => {
9989
+ const quarterHourTime = hourValue + quarter * 0.25;
9990
+ return /* @__PURE__ */ jsx(
9991
+ DroppableCellAgenda,
9992
+ {
9993
+ className: cn(
9994
+ "absolute h-[calc(var(--week-cells-height)/4)] w-full",
9995
+ quarter === 0 && "top-0",
9996
+ quarter === 1 && "top-[calc(var(--week-cells-height)/4)]",
9997
+ quarter === 2 && "top-[calc(var(--week-cells-height)/4*2)]",
9998
+ quarter === 3 && "top-[calc(var(--week-cells-height)/4*3)]"
9999
+ ),
10000
+ date: currentDate,
10001
+ id: `day-cell-${currentDate.toISOString()}-${quarterHourTime}`,
10002
+ onClick: () => {
10003
+ const startTime = new Date(currentDate);
10004
+ startTime.setHours(hourValue);
10005
+ startTime.setMinutes(quarter * 15);
10006
+ if (onEventCreate) onEventCreate(startTime);
10007
+ },
10008
+ time: quarterHourTime
10009
+ },
10010
+ `${hour.toString()}-${quarter}`
10011
+ );
10012
+ })
10013
+ },
10014
+ hour.toString()
10015
+ );
10016
+ })
10017
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "relative", children: [
9924
10018
  positionedEvents.map((positionedEvent) => {
9925
10019
  const evt = positionedEvent.event;
9926
10020
  const eventStart = new Date(evt.start ?? evt.end ?? Date.now());
@@ -10274,7 +10368,8 @@ function EventAgenda({
10274
10368
  onlyWeek,
10275
10369
  onlyAgenda,
10276
10370
  onlyYear,
10277
- allowCellClick = true
10371
+ allowCellClick = true,
10372
+ allDayCell = false
10278
10373
  }) {
10279
10374
  const lockedView = onlyDay ? "day" : onlyMonth ? "month" : onlyWeek ? "week" : onlyAgenda ? "agenda" : onlyYear ? "year" : void 0;
10280
10375
  const [currentDate, setCurrentDate] = useState(
@@ -10394,9 +10489,10 @@ function EventAgenda({
10394
10489
  },
10395
10490
  children: [
10396
10491
  /* @__PURE__ */ jsxs(CalendarDndProviderAgenda, { onEventUpdate: handleEventUpdate, children: [
10397
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-2 sm:p-4", children: [
10398
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 sm:gap-4 min-w-0", children: [
10399
- /* @__PURE__ */ jsxs("div", { className: "flex items-center sm:gap-2", children: [
10492
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 px-2 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-4 sm:py-4", children: [
10493
+ /* @__PURE__ */ jsx("h2", { className: "font-semibold text-base sm:text-lg md:text-xl lg:text-2xl truncate", children: viewTitle }),
10494
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between sm:justify-end gap-2", children: [
10495
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
10400
10496
  /* @__PURE__ */ jsx(
10401
10497
  ButtonBase,
10402
10498
  {
@@ -10418,21 +10514,18 @@ function EventAgenda({
10418
10514
  }
10419
10515
  )
10420
10516
  ] }),
10421
- /* @__PURE__ */ jsx("h2", { className: "font-semibold text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl min-w-0 truncate sm:whitespace-normal", children: viewTitle })
10422
- ] }),
10423
- !lockedView && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
10424
- Select,
10425
- {
10426
- selected: activeView,
10427
- onChange: (v) => {
10428
- setView(v);
10429
- },
10430
- items: selectItems,
10431
- placeholder: viewLabel(activeView),
10432
- className: "min-w-24",
10433
- hideClear: true
10434
- }
10435
- ) })
10517
+ !lockedView && /* @__PURE__ */ jsx(
10518
+ Select,
10519
+ {
10520
+ selected: activeView,
10521
+ onChange: (v) => setView(v),
10522
+ items: selectItems,
10523
+ placeholder: viewLabel(activeView),
10524
+ className: "min-w-24",
10525
+ hideClear: true
10526
+ }
10527
+ )
10528
+ ] })
10436
10529
  ] }),
10437
10530
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col transition-all duration-200 ease-in-out", children: [
10438
10531
  activeView === "month" && /* @__PURE__ */ jsx(
@@ -10457,6 +10550,7 @@ function EventAgenda({
10457
10550
  events,
10458
10551
  onEventSelect: handleEventSelect,
10459
10552
  noTime,
10553
+ allDayCell,
10460
10554
  onEventCreate: allowCellClick ? (d) => onEventUpdate?.({
10461
10555
  start: d,
10462
10556
  end: d,
@@ -10472,6 +10566,7 @@ function EventAgenda({
10472
10566
  events,
10473
10567
  onEventSelect: handleEventSelect,
10474
10568
  noTime,
10569
+ allDayCell,
10475
10570
  onEventCreate: allowCellClick ? (d) => onEventUpdate?.({
10476
10571
  start: d,
10477
10572
  end: d,
@@ -11178,6 +11273,7 @@ function WeekViewAgenda({
11178
11273
  currentDate,
11179
11274
  events,
11180
11275
  onEventSelect,
11276
+ allDayCell = false,
11181
11277
  onEventCreate,
11182
11278
  showUndatedEvents,
11183
11279
  noTime = false
@@ -11353,7 +11449,7 @@ function WeekViewAgenda({
11353
11449
  ))
11354
11450
  ] }),
11355
11451
  showAllDaySection && /* @__PURE__ */ jsxs("div", { className: "border-border/70 border-b bg-muted/50", children: [
11356
- trueAllDayEvents.length > 0 && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-8", children: [
11452
+ trueAllDayEvents.length > 0 && !allDayCell && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-8", children: [
11357
11453
  /* @__PURE__ */ jsx("div", { className: "relative border-border/70 border-r flex items-center justify-center p-1", children: /* @__PURE__ */ jsx("span", { className: "text-center text-[10px] text-muted-foreground/70 sm:text-xs", children: "Todo dia" }) }),
11358
11454
  /* @__PURE__ */ jsxs(
11359
11455
  "div",
@@ -11541,6 +11637,60 @@ function WeekViewAgenda({
11541
11637
  className: "relative grid auto-cols-fr border-border/70 border-r last:border-r-0",
11542
11638
  "data-today": isToday(day) || void 0,
11543
11639
  children: [
11640
+ trueAllDayEvents.length > 0 && allDayCell && /* @__PURE__ */ jsx(Fragment, { children: trueAllDayEvents.filter(
11641
+ (event) => event.start?.toLocaleDateString() == new Date(day).toLocaleDateString()
11642
+ )?.map((event) => {
11643
+ const eventStart = new Date(event.start);
11644
+ const eventEnd = new Date(
11645
+ new Date(event.end).setHours(23, 59)
11646
+ );
11647
+ const isFirstDay = isSameDay(currentDate, eventStart);
11648
+ const isLastDay = isSameDay(currentDate, eventEnd);
11649
+ return /* @__PURE__ */ jsx(
11650
+ "div",
11651
+ {
11652
+ className: "absolute z-10 px-0.5",
11653
+ style: {
11654
+ height: "100%",
11655
+ width: "100%",
11656
+ padding: "10px"
11657
+ },
11658
+ children: /* @__PURE__ */ jsx(TooltipProviderBase, { delayDuration: 400, children: /* @__PURE__ */ jsxs(TooltipBase, { children: [
11659
+ /* @__PURE__ */ jsx(TooltipTriggerBase, { asChild: true, children: /* @__PURE__ */ jsx("div", { className: "size-full", children: /* @__PURE__ */ jsx(
11660
+ EventItemAgenda,
11661
+ {
11662
+ event,
11663
+ view: "day",
11664
+ isFirstDay,
11665
+ isLastDay,
11666
+ onClick: (e) => handleEventClick(event, e),
11667
+ noTime,
11668
+ className: "flex justify-start items-start rounded-sm py-1"
11669
+ }
11670
+ ) }) }),
11671
+ /* @__PURE__ */ jsxs(
11672
+ TooltipContentBase,
11673
+ {
11674
+ side: "top",
11675
+ sideOffset: 6,
11676
+ className: "max-w-[220px] space-y-0.5",
11677
+ children: [
11678
+ /* @__PURE__ */ jsx("p", { className: "font-semibold text-sm leading-snug", children: event.title }),
11679
+ /* @__PURE__ */ jsx("p", { className: "text-xs opacity-90", children: formatDurationAgenda(event) }),
11680
+ event.location && /* @__PURE__ */ jsxs("p", { className: "text-xs flex items-center gap-2", children: [
11681
+ /* @__PURE__ */ jsx(MapPinIcon$1, { size: 15 }),
11682
+ " ",
11683
+ event.location
11684
+ ] }),
11685
+ event.description && /* @__PURE__ */ jsx("p", { className: "text-xs opacity-75 line-clamp-2", children: event.description })
11686
+ ]
11687
+ }
11688
+ )
11689
+ ] }) })
11690
+ },
11691
+ `spanning-${event.id}`
11692
+ );
11693
+ }) }),
11544
11694
  (processedDayEvents[dayIndex] ?? []).map((positionedEvent) => {
11545
11695
  const timeLabel = formatDurationAgenda(positionedEvent.event);
11546
11696
  return /* @__PURE__ */ jsx(TooltipProviderBase, { children: /* @__PURE__ */ jsxs(TooltipBase, { delayDuration: 250, children: [
@@ -22242,15 +22392,24 @@ function normaliseGroups(items = [], groups = []) {
22242
22392
  }
22243
22393
  function unionGroups(base, terms) {
22244
22394
  if (terms.length === 0) return base;
22245
- const allMatchedIds = /* @__PURE__ */ new Set();
22395
+ const bestScore = /* @__PURE__ */ new Map();
22246
22396
  terms.forEach((term) => {
22247
- const filtered = filterAndScore(base, term);
22248
- filtered.forEach((g) => g.items.forEach((i) => allMatchedIds.add(i.id)));
22397
+ base.forEach((group) => {
22398
+ group.items.forEach((item) => {
22399
+ const s = scoreMatch(item, term);
22400
+ if (s >= 0) {
22401
+ const prev = bestScore.get(item.id) ?? -1;
22402
+ if (s > prev) bestScore.set(item.id, s);
22403
+ }
22404
+ });
22405
+ });
22249
22406
  });
22250
22407
  return base.map((group) => ({
22251
22408
  ...group,
22252
- items: group.items.filter((item) => allMatchedIds.has(item.id))
22253
- })).filter((group) => group.items.length > 0);
22409
+ items: group.items.filter((item) => bestScore.has(item.id)).sort(
22410
+ (a, b) => (bestScore.get(b.id) ?? 0) - (bestScore.get(a.id) ?? 0)
22411
+ )
22412
+ })).filter((group) => group.items.length > 0).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
22254
22413
  }
22255
22414
  function createGroup(id, label, items, opts) {
22256
22415
  return { id, label, items, ...opts };
@@ -22371,33 +22530,31 @@ function CommandItemRow({
22371
22530
  onHover,
22372
22531
  searchQuery
22373
22532
  }) {
22533
+ const handleCheckboxChange = (checked) => {
22534
+ if (checked !== "indeterminate") {
22535
+ onToggleSelection?.({});
22536
+ }
22537
+ };
22538
+ const handleItemClick = (e) => {
22539
+ if (multiSelect) {
22540
+ onToggleSelection?.(e);
22541
+ return;
22542
+ }
22543
+ onSelect(e);
22544
+ };
22374
22545
  return /* @__PURE__ */ jsxs(
22375
22546
  motion.button,
22376
22547
  {
22377
22548
  layout: true,
22378
- onClick: (e) => {
22379
- if (multiSelect && onToggleSelection && (e.ctrlKey || e.metaKey || e.shiftKey)) {
22380
- onToggleSelection(e);
22381
- } else {
22382
- onSelect(e);
22383
- }
22384
- },
22549
+ onClick: handleItemClick,
22385
22550
  onMouseEnter: onHover,
22386
22551
  className: `
22387
- w-full flex items-center gap-1 px-2 py-1 rounded-md text-left cursor-pointer
22388
- transition-colors duration-75 group relative
22552
+ w-full flex items-center gap-2 px-2 py-1 rounded-md text-left cursor-pointer
22553
+ transition-colors duration-75 group relative justify-between
22389
22554
  ${isActive ? "text-accent-foreground bg-accent" : "hover:bg-accent hover:text-accent-foreground"}
22390
22555
  `,
22391
22556
  children: [
22392
- item.icon && /* @__PURE__ */ jsx(
22393
- "span",
22394
- {
22395
- className: `relative flex-shrink-0 w-8 h-8 flex items-center justify-center rounded-md text-base
22396
- ${isSelected ? "bg-primary text-primary-foreground" : isActive ? "bg-primary/20 text-primary" : "bg-muted text-muted-foreground group-hover:text-foreground"}`,
22397
- children: item.icon
22398
- }
22399
- ),
22400
- /* @__PURE__ */ jsxs("div", { className: "relative flex-1 min-w-0 px-1", children: [
22557
+ /* @__PURE__ */ jsxs("div", { className: "relative flex-1 min-w-0", children: [
22401
22558
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 flex-wrap", children: [
22402
22559
  /* @__PURE__ */ jsx(
22403
22560
  "span",
@@ -22411,6 +22568,14 @@ function CommandItemRow({
22411
22568
  item.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground truncate", children: /* @__PURE__ */ jsx(HighlightText, { text: item.description, query: searchQuery }) })
22412
22569
  ] }),
22413
22570
  item.shortcut && /* @__PURE__ */ jsx("div", { className: "relative hidden sm:flex items-center gap-1 flex-shrink-0", children: item.shortcut.map((k, i) => /* @__PURE__ */ jsx(Kbd, { children: k }, i)) }),
22571
+ multiSelect && /* @__PURE__ */ jsx("div", { className: "flex-shrink-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(
22572
+ CheckboxBase,
22573
+ {
22574
+ checked: isSelected,
22575
+ onCheckedChange: handleCheckboxChange,
22576
+ className: "h-4 w-4 pointer-events-none"
22577
+ }
22578
+ ) }),
22414
22579
  isSelected && /* @__PURE__ */ jsx(
22415
22580
  motion.div,
22416
22581
  {
@@ -22418,7 +22583,8 @@ function CommandItemRow({
22418
22583
  className: "absolute left-0 top-1/2 -translate-y-1/2 w-1 h-2/3 bg-primary rounded-r-md"
22419
22584
  }
22420
22585
  ),
22421
- isActive && !isSelected && /* @__PURE__ */ jsx(
22586
+ !isSelected && /* @__PURE__ */ jsx("div", { className: "absolute left-0 top-1/2 -translate-y-1/2 w-1 h-2/3 bg-transparent rounded-r-md" }),
22587
+ isActive && !isSelected && !multiSelect && /* @__PURE__ */ jsx(
22422
22588
  CaretRightIcon,
22423
22589
  {
22424
22590
  className: "relative w-4 h-4 text-primary flex-shrink-0",
@@ -22440,12 +22606,15 @@ function useCommandPalette({
22440
22606
  maxRecentItems = 5,
22441
22607
  multiSearch = false,
22442
22608
  multiSelect = false,
22443
- onSelectMultiple
22609
+ onSelectMultiple,
22610
+ onMultiSearchSubmit
22444
22611
  }) {
22445
22612
  const [query, setQuery] = React32.useState("");
22446
22613
  const [activeIndex, setActiveIndex] = React32.useState(0);
22447
22614
  const [page, setPage] = React32.useState(0);
22448
- const [selectedItemIds, setSelectedItemIds] = React32.useState(/* @__PURE__ */ new Set());
22615
+ const [selectedItemIds, setSelectedItemIds] = React32.useState(
22616
+ /* @__PURE__ */ new Set()
22617
+ );
22449
22618
  const stateRef = useRef({
22450
22619
  activeIndex,
22451
22620
  page,
@@ -22462,27 +22631,44 @@ function useCommandPalette({
22462
22631
  });
22463
22632
  }, []);
22464
22633
  const clearSelection = useCallback(() => setSelectedItemIds(/* @__PURE__ */ new Set()), []);
22465
- const baseGroups = useMemo(() => normaliseGroups(items, groups), [items, groups]);
22634
+ const baseGroups = useMemo(
22635
+ () => normaliseGroups(items, groups),
22636
+ [items, groups]
22637
+ );
22466
22638
  useEffect(() => {
22467
22639
  if (open) {
22468
- setQuery("");
22640
+ const savedQuery = localStorage.getItem("commandPaletteQuery") || "";
22641
+ setQuery(savedQuery);
22469
22642
  setActiveIndex(0);
22470
22643
  setPage(0);
22471
- clearSelection();
22644
+ if (!multiSelect) {
22645
+ clearSelection();
22646
+ }
22472
22647
  }
22473
- }, [open, clearSelection]);
22648
+ }, [open, clearSelection, multiSelect]);
22649
+ useEffect(() => {
22650
+ if (!open) {
22651
+ localStorage.setItem("commandPaletteQuery", query);
22652
+ }
22653
+ }, [open, query]);
22474
22654
  const searchTerms = useMemo(() => {
22475
22655
  const parts = query.split(",");
22476
- if (parts.length <= 1 && !multiSearch) return [];
22477
- return parts.map((t) => t.trim().toLowerCase()).filter(Boolean);
22656
+ const terms = parts.map((t) => t.trim().toLowerCase()).filter(Boolean);
22657
+ if (terms.length > 1) return terms;
22658
+ if (multiSearch && terms.length > 0) return terms;
22659
+ return [];
22478
22660
  }, [query, multiSearch]);
22479
22661
  const allMatchedGroups = useMemo(() => {
22480
- if (!query.trim()) {
22481
- return recentItems.length > 0 ? [{ id: "__recent__", label: "Recent", icon: React32.createElement(ClockCounterClockwiseIcon), items: recentItems, priority: 999 }, ...baseGroups] : baseGroups;
22482
- }
22483
- return searchTerms.length > 1 || multiSearch && searchTerms.length > 0 ? unionGroups(baseGroups, searchTerms) : filterAndScore(baseGroups, query);
22484
- }, [query, baseGroups, recentItems, multiSearch, searchTerms]);
22485
- const allFlatItems = useMemo(() => allMatchedGroups.flatMap((g) => g.items), [allMatchedGroups]);
22662
+ if (!query.trim()) return baseGroups;
22663
+ if (searchTerms.length > 0) {
22664
+ return unionGroups(baseGroups, searchTerms);
22665
+ }
22666
+ return filterAndScore(baseGroups, query);
22667
+ }, [query, baseGroups, searchTerms]);
22668
+ const allFlatItems = useMemo(
22669
+ () => allMatchedGroups.flatMap((g) => g.items),
22670
+ [allMatchedGroups]
22671
+ );
22486
22672
  const totalItems = allFlatItems.length;
22487
22673
  const totalPages = Math.max(1, Math.ceil(totalItems / PAGE_SIZE));
22488
22674
  useEffect(() => {
@@ -22509,8 +22695,14 @@ function useCommandPalette({
22509
22695
  }
22510
22696
  return result;
22511
22697
  }, [allMatchedGroups, page]);
22512
- const flatItems = useMemo(() => displayedGroups.flatMap((g) => g.items), [displayedGroups]);
22513
- const selectedItems = useMemo(() => allFlatItems.filter((i) => selectedItemIds.has(i.id)), [allFlatItems, selectedItemIds]);
22698
+ const flatItems = useMemo(
22699
+ () => displayedGroups.flatMap((g) => g.items),
22700
+ [displayedGroups]
22701
+ );
22702
+ const selectedItems = useMemo(
22703
+ () => allFlatItems.filter((i) => selectedItemIds.has(i.id)),
22704
+ [allFlatItems, selectedItemIds]
22705
+ );
22514
22706
  useEffect(() => {
22515
22707
  stateRef.current = { activeIndex, page, flatItems, query, selectedItems };
22516
22708
  }, [activeIndex, page, flatItems, query, selectedItems]);
@@ -22519,47 +22711,92 @@ function useCommandPalette({
22519
22711
  onSelectMultiple(selectedItems);
22520
22712
  onOpenChange?.(false);
22521
22713
  }, [onSelectMultiple, selectedItems, onOpenChange]);
22522
- const handleSelect = useCallback((item, event) => {
22523
- if (!item) return;
22524
- if (multiSelect) {
22525
- const isCmdKey = event && ("ctrlKey" in event || "metaKey" in event || "shiftKey" in event) && (event.ctrlKey || event.metaKey || event.shiftKey);
22526
- if (isCmdKey) {
22527
- toggleSelection(item.id);
22528
- return;
22714
+ const handleSelect = useCallback(
22715
+ (item, event) => {
22716
+ if (!item) return;
22717
+ if (multiSelect) {
22718
+ const isCmdKey = event && ("ctrlKey" in event || "metaKey" in event || "shiftKey" in event) && (event.ctrlKey || event.metaKey || event.shiftKey);
22719
+ if (isCmdKey) {
22720
+ toggleSelection(item.id);
22721
+ return;
22722
+ }
22723
+ if (selectedItems.length > 0) {
22724
+ const finalItems = selectedItemIds.has(item.id) ? selectedItems : [...selectedItems, item];
22725
+ onSelectMultiple?.(finalItems);
22726
+ onOpenChange?.(false);
22727
+ return;
22728
+ }
22529
22729
  }
22530
- if (selectedItems.length > 0) {
22531
- const finalItems = selectedItemIds.has(item.id) ? selectedItems : [...selectedItems, item];
22532
- onSelectMultiple?.(finalItems);
22533
- onOpenChange?.(false);
22534
- return;
22730
+ item.onSelect();
22731
+ onOpenChange?.(false);
22732
+ if (onRecentItemsChange) {
22733
+ const next = [
22734
+ item,
22735
+ ...recentItems.filter((r) => r.id !== item.id)
22736
+ ].slice(0, maxRecentItems);
22737
+ onRecentItemsChange(next);
22535
22738
  }
22536
- }
22537
- item.onSelect();
22538
- onOpenChange?.(false);
22539
- if (onRecentItemsChange) {
22540
- const next = [item, ...recentItems.filter((r) => r.id !== item.id)].slice(0, maxRecentItems);
22541
- onRecentItemsChange(next);
22542
- }
22543
- }, [multiSelect, selectedItems, selectedItemIds, onSelectMultiple, onOpenChange, onRecentItemsChange, recentItems, maxRecentItems, toggleSelection]);
22739
+ },
22740
+ [
22741
+ multiSelect,
22742
+ selectedItems,
22743
+ selectedItemIds,
22744
+ onSelectMultiple,
22745
+ onOpenChange,
22746
+ onRecentItemsChange,
22747
+ recentItems,
22748
+ maxRecentItems,
22749
+ toggleSelection
22750
+ ]
22751
+ );
22544
22752
  useEffect(() => {
22545
22753
  if (!open) return;
22546
22754
  const handler = (e) => {
22547
- const { activeIndex: curIdx, flatItems: curItems, query: curQuery, selectedItems: curSelected } = stateRef.current;
22755
+ const { activeIndex: curIdx, flatItems: curItems } = stateRef.current;
22548
22756
  if (e.key === "ArrowDown") {
22549
22757
  e.preventDefault();
22550
- if (curIdx === curItems.length - 1 && page < totalPages - 1) setPage((p) => p + 1);
22758
+ if (curIdx === curItems.length - 1 && page < totalPages - 1)
22759
+ setPage((p) => p + 1);
22551
22760
  else setActiveIndex((i) => (i + 1) % Math.max(curItems.length, 1));
22552
22761
  } else if (e.key === "ArrowUp") {
22553
22762
  e.preventDefault();
22554
22763
  if (curIdx === 0 && page > 0) {
22555
22764
  setPage((p) => p - 1);
22556
22765
  setActiveIndex(PAGE_SIZE - 1);
22557
- } else setActiveIndex((i) => (i - 1 + Math.max(curItems.length, 1)) % Math.max(curItems.length, 1));
22766
+ } else
22767
+ setActiveIndex(
22768
+ (i) => (i - 1 + Math.max(curItems.length, 1)) % Math.max(curItems.length, 1)
22769
+ );
22558
22770
  } else if (e.key === "Enter") {
22559
22771
  e.preventDefault();
22560
- if (multiSearch && curQuery.includes(",") && curSelected.length === 0) {
22772
+ const currentSelectedItems = allFlatItems.filter(
22773
+ (i) => selectedItemIds.has(i.id)
22774
+ );
22775
+ if (multiSelect && currentSelectedItems.length > 0) {
22776
+ const selectedLabels = currentSelectedItems.map((item) => item.label);
22777
+ onMultiSearchSubmit?.(selectedLabels);
22561
22778
  return;
22562
22779
  }
22780
+ if (multiSearch && query.trim().length > 0) {
22781
+ const terms = query.split(",").map((t) => t.trim()).filter(Boolean);
22782
+ if (terms.length > 0) {
22783
+ if (multiSelect) {
22784
+ const matchedItems = allFlatItems.filter(
22785
+ (item) => terms.some(
22786
+ (term) => item.label.toLowerCase().includes(term.toLowerCase()) || item.id.toLowerCase().includes(term.toLowerCase())
22787
+ )
22788
+ );
22789
+ const newSelectedIds = new Set(selectedItemIds);
22790
+ matchedItems.forEach((item) => newSelectedIds.add(item.id));
22791
+ setSelectedItemIds(newSelectedIds);
22792
+ const selectedLabels = matchedItems.map((item) => item.label);
22793
+ onMultiSearchSubmit?.(selectedLabels);
22794
+ return;
22795
+ }
22796
+ onMultiSearchSubmit?.(terms);
22797
+ return;
22798
+ }
22799
+ }
22563
22800
  if (multiSelect && (e.ctrlKey || e.metaKey)) {
22564
22801
  executeBulkAction();
22565
22802
  return;
@@ -22569,7 +22806,20 @@ function useCommandPalette({
22569
22806
  };
22570
22807
  window.addEventListener("keydown", handler);
22571
22808
  return () => window.removeEventListener("keydown", handler);
22572
- }, [open, page, totalPages, multiSearch, multiSelect, handleSelect, executeBulkAction]);
22809
+ }, [
22810
+ open,
22811
+ page,
22812
+ totalPages,
22813
+ multiSearch,
22814
+ multiSelect,
22815
+ handleSelect,
22816
+ executeBulkAction,
22817
+ onMultiSearchSubmit,
22818
+ selectedItems,
22819
+ allFlatItems,
22820
+ selectedItemIds,
22821
+ query
22822
+ ]);
22573
22823
  return {
22574
22824
  query,
22575
22825
  setQuery,
@@ -22590,7 +22840,7 @@ function useCommandPalette({
22590
22840
  selectedItems,
22591
22841
  executeBulkAction,
22592
22842
  isEmpty: totalItems === 0 && query.trim().length > 0,
22593
- showList: query.trim() !== "" || recentItems.length > 0
22843
+ showList: true
22594
22844
  };
22595
22845
  }
22596
22846
  function useKeyboardShortcut(key, callback, options = {}) {
@@ -22890,7 +23140,16 @@ function CommandPalette(props) {
22890
23140
  className: "flex-1 bg-transparent border-none shadow-none focus-visible:ring-0 p-0 text-base"
22891
23141
  }
22892
23142
  ),
22893
- query && /* @__PURE__ */ jsx(ButtonBase, { variant: "ghost", size: "icon", onClick: handleClearQuery, className: "h-8 w-8", children: /* @__PURE__ */ jsx(XIcon, { className: "w-4 h-4" }) })
23143
+ query && /* @__PURE__ */ jsx(
23144
+ ButtonBase,
23145
+ {
23146
+ variant: "ghost",
23147
+ size: "icon",
23148
+ onClick: handleClearQuery,
23149
+ className: "h-8 w-8",
23150
+ children: /* @__PURE__ */ jsx(XIcon, { className: "w-4 h-4" })
23151
+ }
23152
+ )
22894
23153
  ]
22895
23154
  }
22896
23155
  ),
@@ -22943,7 +23202,13 @@ function CommandPalette(props) {
22943
23202
  style: { maxHeight: "min(600px, 80vh)" },
22944
23203
  children: [
22945
23204
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-2 border-b border-border", children: [
22946
- /* @__PURE__ */ jsx(MagnifyingGlassIcon, { className: "w-4 h-4 text-muted-foreground flex-shrink-0", weight: "bold" }),
23205
+ /* @__PURE__ */ jsx(
23206
+ MagnifyingGlassIcon,
23207
+ {
23208
+ className: "w-4 h-4 text-muted-foreground flex-shrink-0",
23209
+ weight: "bold"
23210
+ }
23211
+ ),
22947
23212
  /* @__PURE__ */ jsx(
22948
23213
  DebouncedInput,
22949
23214
  {
@@ -22974,7 +23239,8 @@ function CommandPalette(props) {
22974
23239
  footer,
22975
23240
  totalItems,
22976
23241
  selectedCount: selectedItemIds.size,
22977
- executeBulkAction
23242
+ executeBulkAction,
23243
+ multiSelect
22978
23244
  }
22979
23245
  )
22980
23246
  ]