@ai-matrx/records-ui 0.116.10 → 0.116.11

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.js CHANGED
@@ -20217,7 +20217,7 @@ function structuredWordsFor(field, value) {
20217
20217
  }
20218
20218
 
20219
20219
  // src/CalendarView.tsx
20220
- import { useEffect as useEffect58, useMemo as useMemo43, useRef as useRef31, useState as useState66 } from "react";
20220
+ import { useEffect as useEffect58, useLayoutEffect as useLayoutEffect3, useMemo as useMemo43, useRef as useRef31, useState as useState66 } from "react";
20221
20221
  import { mayDrag as mayDrag2 } from "@ai-matrx/records/react";
20222
20222
  import { Button as Button55, Select as Select5, SelectContent as SelectContent3, SelectItem as SelectItem3, SelectTrigger as SelectTrigger3, SelectValue as SelectValue3, cn as cn30 } from "@ai-matrx/design-system";
20223
20223
  import { CHOICE_CHIP_CLASS } from "@ai-matrx/design-system/data-table";
@@ -20490,6 +20490,25 @@ function useNarrow() {
20490
20490
  }, []);
20491
20491
  return narrow;
20492
20492
  }
20493
+ var READABLE_CELL_PX = 72;
20494
+ function useGridWidth(grid, mode) {
20495
+ const [width, setWidth] = useState66(null);
20496
+ const useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect58 : useLayoutEffect3;
20497
+ useIsoLayoutEffect2(() => {
20498
+ const el = grid.current;
20499
+ if (!el) {
20500
+ setWidth(null);
20501
+ return;
20502
+ }
20503
+ const read = () => setWidth(el.clientWidth);
20504
+ read();
20505
+ if (typeof ResizeObserver === "undefined") return;
20506
+ const watcher = new ResizeObserver(read);
20507
+ watcher.observe(el);
20508
+ return () => watcher.disconnect();
20509
+ }, [grid, mode]);
20510
+ return width;
20511
+ }
20493
20512
  function byTime(a, b) {
20494
20513
  const allDayOn = (p) => !p.at || p.lastDay > p.firstDay;
20495
20514
  return Number(!allDayOn(a)) - Number(!allDayOn(b)) || (a.at && b.at && !allDayOn(a) && !allDayOn(b) ? a.at.getTime() - b.at.getTime() : 0) || a.firstDay.localeCompare(b.firstDay);
@@ -20582,6 +20601,11 @@ function CalendarView({
20582
20601
  const titleOf = (row) => cardWords(row, titleField, labels).text;
20583
20602
  const rowById = (id) => rows.find((r) => r.id === id);
20584
20603
  const frame = useRef31(null);
20604
+ const grid = useRef31(null);
20605
+ const gridWidth = useGridWidth(grid, mode);
20606
+ const cellColumns = mode === "month" ? 7 : mode === "week" ? 7 : 1;
20607
+ const cellReserve = mode === "month" ? 0 : 44;
20608
+ const tightCells = (mode === "month" || mode === "week") && gridWidth !== null && gridWidth > 0 && (gridWidth - cellReserve) / cellColumns < READABLE_CELL_PX;
20585
20609
  const [focusOn, setFocusOn] = useState66(null);
20586
20610
  useEffect58(() => {
20587
20611
  if (!focusOn) return;
@@ -20802,7 +20826,7 @@ function CalendarView({
20802
20826
  window.addEventListener("pointermove", onMove);
20803
20827
  window.addEventListener("pointerup", onUp);
20804
20828
  };
20805
- const cardFace = (row, extra, className2) => {
20829
+ const cardFace = (row, extra, className2, compact = false) => {
20806
20830
  const may = canMove(row);
20807
20831
  const lockWords = mayDrag2(row.level) ? WORKED_OUT_DATE_LOCK : "View only";
20808
20832
  const color = colorOf(row);
@@ -20816,17 +20840,19 @@ function CalendarView({
20816
20840
  // The chip palette, not the faint row tint: a calendar is read by its colours at a glance.
20817
20841
  color ? CHOICE_CHIP_CLASS[color] : "bg-background",
20818
20842
  may ? "cursor-grab active:cursor-grabbing" : "cursor-default",
20843
+ compact ? "min-h-3 px-0" : "",
20819
20844
  className2
20820
20845
  ),
20821
20846
  onClick: () => onOpenRecord?.(row.id),
20847
+ ...compact ? { "aria-label": title, "data-calendar-compact": "" } : {},
20822
20848
  title: may ? `${title} \xB7 drag to another day, or Alt + arrow keys` : `${title} \xB7 ${lockWords}`,
20823
20849
  ...color ? { "data-calendar-color": color } : {},
20824
20850
  ...may ? { "aria-keyshortcuts": "Alt+ArrowLeft Alt+ArrowRight Alt+ArrowUp Alt+ArrowDown" } : { "data-calendar-locked": "" },
20825
20851
  children: [
20826
- may ? null : /* @__PURE__ */ jsx72("span", { title: lockWords, "aria-label": lockWords, className: "inline-flex", ...mayDrag2(row.level) ? { "data-calendar-worked-out": "" } : {}, children: /* @__PURE__ */ jsx72(LockIcon, {}) }),
20827
- extra,
20828
- /* @__PURE__ */ jsx72("span", { className: "min-w-0 max-w-full shrink-0 truncate", "data-calendar-card-title": "", children: title }),
20829
- /* @__PURE__ */ jsx72(CardFieldsInline, { row, fields: cardFields })
20852
+ compact ? null : may ? null : /* @__PURE__ */ jsx72("span", { title: lockWords, "aria-label": lockWords, className: "inline-flex", ...mayDrag2(row.level) ? { "data-calendar-worked-out": "" } : {}, children: /* @__PURE__ */ jsx72(LockIcon, {}) }),
20853
+ compact ? null : extra,
20854
+ compact ? null : /* @__PURE__ */ jsx72("span", { className: "min-w-0 max-w-full shrink-0 truncate", "data-calendar-card-title": "", children: title }),
20855
+ compact ? null : /* @__PURE__ */ jsx72(CardFieldsInline, { row, fields: cardFields })
20830
20856
  ]
20831
20857
  }
20832
20858
  );
@@ -20836,8 +20862,8 @@ function CalendarView({
20836
20862
  const words2 = timeOfDayWords(startOf(row));
20837
20863
  return words2 ? /* @__PURE__ */ jsx72("span", { className: "hidden shrink-0 tabular-nums text-[10px] opacity-75 @[8rem]:inline", "data-calendar-time": "", children: words2 }) : null;
20838
20864
  };
20839
- const listCard = (p, key) => /* @__PURE__ */ jsxs66("li", { ...dragSource(p.row), children: [
20840
- cardFace(p.row, timeOn(p.row)),
20865
+ const listCard = (p, key, compact = false) => /* @__PURE__ */ jsxs66("li", { ...dragSource(p.row), children: [
20866
+ cardFace(p.row, timeOn(p.row), void 0, compact),
20841
20867
  refusalOn(p.row)
20842
20868
  ] }, key);
20843
20869
  const today = dayKey(personWallNow());
@@ -20895,7 +20921,7 @@ function CalendarView({
20895
20921
  if (mode === "month") {
20896
20922
  const first = startOfWeek(dayKey(new Date(anchorDate.getFullYear(), anchorDate.getMonth(), 1)), firstDay);
20897
20923
  const weeks = Array.from({ length: 6 }, (_, w) => addDays2(first, w * 7));
20898
- body = /* @__PURE__ */ jsx72("div", { className: "min-w-0 flex-1 overflow-x-auto", children: /* @__PURE__ */ jsxs66("div", { className: "w-full min-w-0 border-l border-t", role: "grid", "aria-label": heading, "data-calendar-month": "", children: [
20924
+ body = /* @__PURE__ */ jsx72("div", { className: "min-w-0 flex-1 overflow-x-auto", children: /* @__PURE__ */ jsxs66("div", { ref: grid, className: "w-full min-w-0 border-l border-t", role: "grid", "aria-label": heading, "data-calendar-month": "", ...tightCells ? { "data-calendar-tight": "" } : {}, children: [
20899
20925
  /* @__PURE__ */ jsx72("div", { className: "grid grid-cols-7", role: "row", children: Array.from({ length: 7 }, (_, i) => addDays2(first, i)).map((d) => /* @__PURE__ */ jsx72("div", { role: "columnheader", className: "border-b border-r px-1 py-0.5 text-center text-xs text-muted-foreground", children: dayDate(d).toLocaleDateString(void 0, { weekday: "short" }) }, `h${d}`)) }),
20900
20926
  weeks.map((ws) => /* @__PURE__ */ jsx72(
20901
20927
  MonthWeek,
@@ -20911,6 +20937,11 @@ function CalendarView({
20911
20937
  barDrop,
20912
20938
  canCreate: creates,
20913
20939
  onCreate: (d) => void createAt(rescheduledValue(null, d, null, moments), null, calendarDayLabel(d)),
20940
+ tight: tightCells,
20941
+ dotClass: (row) => {
20942
+ const c = colorOf(row);
20943
+ return c ? CHOICE_CHIP_CLASS[c] : "bg-muted-foreground/40";
20944
+ },
20914
20945
  card: (p, key) => listCard(p, key),
20915
20946
  bar: (p, key) => /* @__PURE__ */ jsxs66("div", { ...dragSource(p.row), className: "relative h-full", children: [
20916
20947
  cardFace(p.row, null, "h-full"),
@@ -20936,12 +20967,12 @@ function CalendarView({
20936
20967
  })
20937
20968
  );
20938
20969
  const columns = `2.75rem repeat(${days.length}, minmax(0, 1fr))`;
20939
- body = /* @__PURE__ */ jsx72("div", { className: "min-w-0 flex-1 overflow-x-auto", children: /* @__PURE__ */ jsxs66("div", { className: "w-full min-w-0 border-l border-t", "data-calendar-week": "", "data-calendar-days": days.length, children: [
20970
+ body = /* @__PURE__ */ jsx72("div", { className: "min-w-0 flex-1 overflow-x-auto", children: /* @__PURE__ */ jsxs66("div", { ref: grid, className: "w-full min-w-0 border-l border-t", "data-calendar-week": "", "data-calendar-days": days.length, ...tightCells ? { "data-calendar-tight": "" } : {}, children: [
20940
20971
  /* @__PURE__ */ jsxs66("div", { className: "grid", style: { gridTemplateColumns: columns }, children: [
20941
20972
  /* @__PURE__ */ jsx72("div", { className: "border-b border-r" }),
20942
20973
  days.map((d) => /* @__PURE__ */ jsx72("div", { className: cn30("border-b border-r px-1 py-0.5 text-center text-xs", d === today ? "font-semibold text-primary" : "text-muted-foreground"), children: dayDate(d).toLocaleDateString(void 0, { weekday: "short", day: "numeric" }) }, `h${d}`)),
20943
20974
  /* @__PURE__ */ jsx72("div", { className: "border-b border-r px-1 py-0.5 text-[10px] text-muted-foreground", children: "All day" }),
20944
- days.map((d) => /* @__PURE__ */ jsx72("div", { "data-calendar-day": d, className: cn30("min-h-8 border-b border-r p-0.5", ghost?.day === d && ghost.minute === null ? "bg-primary/10" : void 0), ...dayDrop(d), children: /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: allDay(d).map((p) => listCard(p, `${p.row.id}:${d}`)) }) }, `a${d}`))
20975
+ days.map((d) => /* @__PURE__ */ jsx72("div", { "data-calendar-day": d, className: cn30("min-h-8 border-b border-r p-0.5", ghost?.day === d && ghost.minute === null ? "bg-primary/10" : void 0), ...dayDrop(d), children: /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: allDay(d).map((p) => listCard(p, `${p.row.id}:${d}`, tightCells)) }) }, `a${d}`))
20945
20976
  ] }),
20946
20977
  /* @__PURE__ */ jsx72(
20947
20978
  WeekHours,
@@ -20987,7 +21018,8 @@ function CalendarView({
20987
21018
  p.row,
20988
21019
  tight ? null : /* @__PURE__ */ jsx72("span", { className: "hidden shrink-0 tabular-nums text-[10px] opacity-75 @[8rem]:inline", "data-calendar-time": "", children: timeLabel(start) }),
20989
21020
  // Taller blocks sharing the width stack the time over the name.
20990
- cn30("h-full items-start", !tight && end - start >= 45 && cols > 1 ? "flex-col gap-0" : void 0)
21021
+ cn30("h-full items-start", !tight && end - start >= 45 && cols > 1 ? "flex-col gap-0" : void 0),
21022
+ tightCells
20991
21023
  ),
20992
21024
  endField && !endWorkedOut && canMove(p.row) ? /* @__PURE__ */ jsx72(
20993
21025
  "div",
@@ -21056,7 +21088,9 @@ function MonthWeek({
21056
21088
  onCreate,
21057
21089
  card,
21058
21090
  bar,
21059
- refusalOn
21091
+ refusalOn,
21092
+ tight,
21093
+ dotClass
21060
21094
  }) {
21061
21095
  const weekEnd = addDays2(weekStart, 6);
21062
21096
  const days = Array.from({ length: 7 }, (_, i) => addDays2(weekStart, i));
@@ -21068,7 +21102,7 @@ function MonthWeek({
21068
21102
  laneEnds[lane] = s.to;
21069
21103
  return { ...s, lane };
21070
21104
  });
21071
- const lanesShown = Math.min(laneEnds.length, MONTH_ROWS - 1);
21105
+ const lanesShown = tight ? 0 : Math.min(laneEnds.length, MONTH_ROWS - 1);
21072
21106
  const singlesFit = MONTH_ROWS - lanesShown;
21073
21107
  return /* @__PURE__ */ jsxs66("div", { className: "relative grid grid-cols-7", role: "row", "data-calendar-week-row": weekStart, children: [
21074
21108
  days.map((d) => {
@@ -21080,7 +21114,8 @@ function MonthWeek({
21080
21114
  const everything = placed.filter((p) => p.firstDay <= d && p.lastDay >= d).sort(byTime);
21081
21115
  const create = (e) => {
21082
21116
  if (e.target.closest("button, [data-calendar-card], [role=dialog]")) return;
21083
- onCreate(d);
21117
+ if (tight && everything.length > 0) onOpenDay(d);
21118
+ else onCreate(d);
21084
21119
  };
21085
21120
  return /* @__PURE__ */ jsxs66(
21086
21121
  "div",
@@ -21089,7 +21124,8 @@ function MonthWeek({
21089
21124
  "aria-label": calendarDayLabel(d),
21090
21125
  "data-calendar-day": d,
21091
21126
  className: cn30(
21092
- "group relative flex min-h-24 min-w-0 flex-col gap-0.5 border-b border-r p-0.5",
21127
+ "group relative flex min-w-0 flex-col gap-0.5 border-b border-r p-0.5",
21128
+ tight ? "min-h-14" : "min-h-24",
21093
21129
  inMonth ? "" : "bg-muted/40",
21094
21130
  ghostDay === d ? "bg-primary/10 ring-2 ring-inset ring-primary" : "",
21095
21131
  canCreate ? "cursor-cell" : ""
@@ -21123,8 +21159,18 @@ function MonthWeek({
21123
21159
  )
21124
21160
  ] }),
21125
21161
  /* @__PURE__ */ jsx72("div", { style: { height: lanesShown * BAR_PX }, "aria-hidden": "true" }),
21126
- /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: shown4.map((p) => card(p, `${p.row.id}:${d}`)) }),
21127
- more > 0 ? /* @__PURE__ */ jsxs66("button", { type: "button", className: "self-start px-1 text-xs text-muted-foreground hover:text-foreground", "data-calendar-more": d, onClick: () => onOpenDay(d), children: [
21162
+ tight ? everything.length > 0 ? /* @__PURE__ */ jsx72(
21163
+ "button",
21164
+ {
21165
+ type: "button",
21166
+ className: "flex min-w-0 flex-wrap items-center justify-center gap-0.5 self-stretch px-0.5 py-0.5",
21167
+ "aria-label": `${everything.length} ${everything.length === 1 ? "record" : "records"} on ${calendarDayLabel(d)}`,
21168
+ "data-calendar-marks": d,
21169
+ onClick: () => onOpenDay(d),
21170
+ children: everything.length <= 3 ? everything.map((p) => /* @__PURE__ */ jsx72("span", { "aria-hidden": "true", "data-calendar-dot": "", className: cn30("h-1.5 w-1.5 rounded-full border", dotClass(p.row)) }, p.row.id)) : /* @__PURE__ */ jsx72("span", { className: "rounded-full bg-muted px-1 text-[10px] tabular-nums leading-4", "data-calendar-count": "", children: everything.length })
21171
+ }
21172
+ ) : null : /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: shown4.map((p) => card(p, `${p.row.id}:${d}`)) }),
21173
+ more > 0 && !tight ? /* @__PURE__ */ jsxs66("button", { type: "button", className: "self-start px-1 text-xs text-muted-foreground hover:text-foreground", "data-calendar-more": d, onClick: () => onOpenDay(d), children: [
21128
21174
  "+",
21129
21175
  more,
21130
21176
  " more"
@@ -21135,7 +21181,11 @@ function MonthWeek({
21135
21181
  role: "dialog",
21136
21182
  "aria-label": calendarDayLabel(d),
21137
21183
  "data-calendar-day-open": d,
21138
- className: "absolute left-0 top-0 z-20 flex w-56 flex-col gap-1 rounded-md border bg-popover p-2 shadow-lg",
21184
+ className: cn30(
21185
+ "z-20 flex flex-col gap-1 rounded-md border bg-popover p-2 shadow-lg",
21186
+ // A narrow cell cannot hold a panel: the day's list opens as a sheet over the page's foot.
21187
+ tight ? "fixed inset-x-3 bottom-3 z-50 max-h-[60vh] overflow-y-auto" : "absolute left-0 top-0 w-56"
21188
+ ),
21139
21189
  onKeyDown: (e) => {
21140
21190
  if (e.key === "Escape") onOpenDay(null);
21141
21191
  },
@@ -21144,7 +21194,8 @@ function MonthWeek({
21144
21194
  /* @__PURE__ */ jsx72("span", { className: "text-xs font-medium", children: calendarDayLabel(d) }),
21145
21195
  /* @__PURE__ */ jsx72(Button55, { size: "sm", variant: "ghost", className: "ml-auto h-6", "aria-label": "Close", onClick: () => onOpenDay(null), children: "\xD7" })
21146
21196
  ] }),
21147
- /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: everything.map((p) => card(p, `open:${p.row.id}:${d}`)) })
21197
+ /* @__PURE__ */ jsx72("ul", { className: "flex flex-col gap-0.5", children: everything.map((p) => card(p, `open:${p.row.id}:${d}`)) }),
21198
+ tight && canCreate ? /* @__PURE__ */ jsx72(Button55, { size: "sm", variant: "outline", className: "h-7 self-start", "data-calendar-add-in-sheet": d, onClick: () => onCreate(d), children: "Add a record" }) : null
21148
21199
  ]
21149
21200
  }
21150
21201
  ) : null
@@ -38826,7 +38877,7 @@ function TablePresence({ tableId }) {
38826
38877
  }
38827
38878
 
38828
38879
  // src/toolbarFit.ts
38829
- import { useEffect as useEffect102, useLayoutEffect as useLayoutEffect3, useState as useState116 } from "react";
38880
+ import { useEffect as useEffect102, useLayoutEffect as useLayoutEffect4, useState as useState116 } from "react";
38830
38881
  import { flushSync } from "react-dom";
38831
38882
  function widthAtFold(piece, fold) {
38832
38883
  for (let f = Math.min(fold, (piece.byFold?.length ?? 0) - 1); f >= 0; f -= 1) {
@@ -38918,7 +38969,7 @@ function createFitMemory() {
38918
38969
  }
38919
38970
  };
38920
38971
  }
38921
- var useIsoLayoutEffect = typeof window === "undefined" ? useEffect102 : useLayoutEffect3;
38972
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect102 : useLayoutEffect4;
38922
38973
  function useToolbarFit(row) {
38923
38974
  const [fold, setFold] = useState116(0);
38924
38975
  useIsoLayoutEffect(() => {