@columenlabs/lumen-ui 0.1.261 → 0.1.262

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.
@@ -351,7 +351,44 @@ function UsageTip({ r, children }) {
351
351
  ];
352
352
  return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: children }), _jsx(TooltipContent, { className: "max-w-72", children: _jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [_jsx("span", { className: "whitespace-normal break-words font-medium", children: r.title }), _jsx("dl", { className: "grid grid-cols-[auto_auto] gap-x-4 gap-y-0.5", children: lines.map(([k, v]) => (_jsxs(Fragment, { children: [_jsx("dt", { className: "opacity-75", children: k }), _jsx("dd", { className: "num text-right", children: v })] }, k))) }), !t && _jsx("span", { className: "opacity-75", children: "Spent before each chat kept its own count." })] }) })] }));
353
353
  }
354
- const dayOf = (at) => at ? new Date(at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) : EARLIER;
354
+ /** Midnight of `d`'s day, local time. */
355
+ const startOf = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
356
+ /** Days from `at`'s day back to today (0 today, 1 yesterday). */
357
+ const daysAgo = (at) => Math.round((startOf(new Date()) - startOf(new Date(at))) / 86_400_000);
358
+ /** Days since Monday, today included (0 on a Monday). */
359
+ const sinceMonday = () => (new Date().getDay() + 6) % 7;
360
+ const sameMonth = (at) => {
361
+ const d = new Date(at);
362
+ const n = new Date();
363
+ return d.getFullYear() === n.getFullYear() && d.getMonth() === n.getMonth();
364
+ };
365
+ /** Grouping by date: Today, Yesterday, This week, This month, then each month by name. Spend
366
+ * from before chats kept their own count is this month's. */
367
+ const dayOf = (at) => {
368
+ if (!at)
369
+ return 'This month';
370
+ const n = daysAgo(at);
371
+ if (n <= 0)
372
+ return 'Today';
373
+ if (n === 1)
374
+ return 'Yesterday';
375
+ if (n <= sinceMonday())
376
+ return 'This week';
377
+ if (sameMonth(at))
378
+ return 'This month';
379
+ return new Date(at).toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
380
+ };
381
+ /** A row's date: today's time, Yesterday, the weekday this week, else the day. */
382
+ const relWhen = (at) => {
383
+ const n = daysAgo(at);
384
+ if (n <= 0)
385
+ return new Date(at).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
386
+ if (n === 1)
387
+ return 'Yesterday';
388
+ if (n <= sinceMonday())
389
+ return new Date(at).toLocaleDateString(undefined, { weekday: 'short' });
390
+ return new Date(at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
391
+ };
355
392
  const USAGE_FIELDS = [
356
393
  {
357
394
  key: 'title',
@@ -383,7 +420,7 @@ const USAGE_FIELDS = [
383
420
  format: 'integer',
384
421
  hideOnPhone: true,
385
422
  value: (r) => r.at,
386
- render: (r) => (_jsx(UsageTip, { r: r, children: r.at ? (_jsx("time", { dateTime: new Date(r.at).toISOString(), className: "text-muted-foreground", children: when(r.at) })) : (_jsx("span", { className: "text-muted-foreground", children: EARLIER })) })),
423
+ render: (r) => (_jsx(UsageTip, { r: r, children: r.at ? (_jsx("time", { dateTime: new Date(r.at).toISOString(), className: "text-muted-foreground", children: relWhen(r.at) })) : (_jsx("span", { className: "text-muted-foreground", children: EARLIER })) })),
387
424
  },
388
425
  {
389
426
  key: 'calls',
@@ -507,6 +507,12 @@ function CappedCell({ max, end, title, children, }) {
507
507
  return children;
508
508
  return (_jsx("div", { className: cn('flex min-w-0 *:min-w-0 *:max-w-full *:truncate', end && 'justify-end'), style: { maxWidth: max }, title: title, children: children }));
509
509
  }
510
+ /** A group heading's row count, as a chip beside its name. */
511
+ function GroupCount({ children }) {
512
+ if (children === '' || children == null)
513
+ return null;
514
+ return (_jsx(Badge, { variant: "secondary", className: "num h-4.5 shrink-0 px-1.5 font-normal text-xs", children: children }));
515
+ }
510
516
  /** The flat or grouped table: sortable headers, a Total row, group rows that collapse. */
511
517
  // Sorting, and paging of flat tables (the page is LumenView's, set right of the row count).
512
518
  const SORTING = tableFeatures({
@@ -874,7 +880,7 @@ function LumenTableRows({ domain, columns = domain.fields, rows, groupBy = null,
874
880
  const n = new Set(o);
875
881
  n.has(k) ? n.delete(k) : n.add(k);
876
882
  return n;
877
- }), children: [selection && _jsx(TableCell, {}), shown.map((f, i) => (_jsx(TableCell, { ...col(f, groupBy && i === 0 && 'pl-8'), children: i === 0 ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1 whitespace-nowrap", children: [chevron(k, `${key} ${openLabel()}`), subgroup?.mark?.(key, ms), _jsx("span", { className: "truncate font-medium", title: key, children: titleOf(key, ms) }), _jsx("span", { className: "num shrink-0 text-xs text-muted-foreground", children: ms.length })] })) : (rollCell(f, ms, 'fold')) }, f.key))), add && _jsx(TableCell, {})] }), openParts.has(k) && ms.map((p) => partRow(p, subgroup?.name))] }, k));
883
+ }), children: [selection && _jsx(TableCell, {}), shown.map((f, i) => (_jsx(TableCell, { ...col(f, groupBy && i === 0 && 'pl-8'), children: i === 0 ? (_jsxs("span", { className: "flex min-w-0 items-center gap-1 whitespace-nowrap", children: [chevron(k, `${key} ${openLabel()}`), subgroup?.mark?.(key, ms), _jsx("span", { className: "truncate font-medium", title: key, children: titleOf(key, ms) }), _jsx(GroupCount, { children: ms.length })] })) : (rollCell(f, ms, 'fold')) }, f.key))), add && _jsx(TableCell, {})] }), openParts.has(k) && ms.map((p) => partRow(p, subgroup?.name))] }, k));
878
884
  };
879
885
  const rowsOf = (list, scope) => {
880
886
  const under = folds ? subgroup?.under : undefined;
@@ -957,7 +963,7 @@ function LumenTableRows({ domain, columns = domain.fields, rows, groupBy = null,
957
963
  const n = new Set(c);
958
964
  n.has(key) ? n.delete(key) : n.add(key);
959
965
  return n;
960
- }), children: [_jsx(ChevronRightIcon, { className: cn('transition-transform', open && 'rotate-90') }), _jsx(GroupMark, { field: groupBy, value: key }), _jsx("span", { className: "truncate", children: key }), _jsx("span", { className: "num shrink-0 font-normal text-muted-foreground", children: serverGroups
966
+ }), children: [_jsx(ChevronRightIcon, { className: cn('transition-transform', open && 'rotate-90') }), _jsx(GroupMark, { field: groupBy, value: key }), _jsx("span", { className: "truncate", children: key }), _jsx(GroupCount, { children: serverGroups
961
967
  ? (served.get(key)?.n?.toLocaleString() ?? '')
962
968
  : members.length })] }), groupActions?.(key, members.map((m) => m.original))] }) }, f.key)) : (_jsx(TableCell, { ...col(f, PINNED_GROUP), children: !serverGroups &&
963
969
  rollCell(f, members.map((m) => m.original), 'group') }, f.key))), add && _jsx(TableCell, { className: PINNED_GROUP })] }), open && (serverGroups ? servedRows(members, key) : drawn(members, key))] }, key));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-ui",
3
- "version": "0.1.261",
3
+ "version": "0.1.262",
4
4
  "description": "Lumen: shared React components (frame, views, widgets, charts, drawers).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -49,7 +49,7 @@
49
49
  "@codemirror/lang-javascript": "6.2.5",
50
50
  "@codemirror/lang-json": "6.0.2",
51
51
  "@codemirror/lang-sql": "6.10.0",
52
- "@columenlabs/lumen-ui-types": "0.1.261",
52
+ "@columenlabs/lumen-ui-types": "0.1.262",
53
53
  "@dnd-kit/core": "6.3.1",
54
54
  "@dnd-kit/sortable": "10.0.0",
55
55
  "@dnd-kit/utilities": "3.2.2",