@marktiderman/genesis-chat 0.6.1 → 0.7.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/dist/web.d.ts +4 -1
- package/dist/web.js +2 -15
- package/dist/web.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/web-format.test.ts +28 -0
- package/src/web/format.ts +6 -15
package/dist/web.d.ts
CHANGED
|
@@ -16,7 +16,10 @@ interface ChatUser {
|
|
|
16
16
|
type ResolveUser = (userId: string) => ChatUser;
|
|
17
17
|
/** 10:42 (in the reader's locale). */
|
|
18
18
|
declare function clockTime(iso: string, locale?: string): string;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The inbox's time: "now", "5m", "10:42" today, "Yesterday", "Mon", or "12 Mar". Genesis UI's
|
|
21
|
+
* `relativeTime` in its compact style, in the reader's locale (`locale`, default the runtime's).
|
|
22
|
+
*/
|
|
20
23
|
declare function relativeTime(iso: string | null | undefined, now?: Date, locale?: string): string;
|
|
21
24
|
/** 12 KB, 3.4 MB. */
|
|
22
25
|
declare function formatBytes(bytes: number | null | undefined): string;
|
package/dist/web.js
CHANGED
|
@@ -8,29 +8,16 @@ import { createContext, useRef, useState, Fragment, useCallback, useEffect, useM
|
|
|
8
8
|
import { MessageSquare, Pin, BellOff, AtSign, Search, X, Mic, ClipboardList, ExternalLink, VideoOff, Video, RotateCcw, SendHorizontal, Square, Circle, Pause, Play, Paperclip, ChevronLeft, ChevronRight, FileText, Download, Lock, Ban, EyeOff, ShieldAlert, AlertCircle, Clock, Reply, Copy, Pencil, PinOff, Bookmark, Flag, Trash2, SmilePlus, Plus, MoreHorizontal, ChevronUp, CalendarClock, Moon, RefreshCw, Smile, Hash, LockOpen, ArrowDown, ImagePlus, Megaphone, Link2, ArrowLeft } from 'lucide-react';
|
|
9
9
|
import { Skeleton, cn, EmptyState, Button, UserAvatar, Badge, Input, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Alert, AlertDescription, Spinner, Collapsible, CollapsibleTrigger, CollapsibleContent, VisuallyHidden, Progress, ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuSeparator, ContextMenuItem, Tooltip, Textarea, Popover, PopoverTrigger, PopoverContent, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuItem, DropdownMenuLabel, Label, DialogFooter, toast, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Toggle, ToggleGroup, ToggleGroupItem, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, RadioGroup, RadioGroupItem, Split, Checkbox } from '@marktiderman/genesis-ui';
|
|
10
10
|
import { renderSlot } from '@marktiderman/genesis-core/slots';
|
|
11
|
+
import { relativeTime as relativeTime$1 } from '@marktiderman/genesis-ui/utils';
|
|
11
12
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
12
13
|
import { EmojiPicker } from 'frimousse';
|
|
13
14
|
|
|
14
|
-
// src/web/format.ts
|
|
15
15
|
function clockTime(iso, locale) {
|
|
16
16
|
return new Date(iso).toLocaleTimeString(locale, { hour: "numeric", minute: "2-digit" });
|
|
17
17
|
}
|
|
18
18
|
function relativeTime(iso, now = /* @__PURE__ */ new Date(), locale) {
|
|
19
19
|
if (!iso) return "";
|
|
20
|
-
|
|
21
|
-
const diff = now.getTime() - d.getTime();
|
|
22
|
-
if (diff < 6e4) return "now";
|
|
23
|
-
if (diff < 36e5) return `${Math.floor(diff / 6e4)}m`;
|
|
24
|
-
const startOf = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
25
|
-
const days = Math.round((startOf(now) - startOf(d)) / 864e5);
|
|
26
|
-
if (days === 0) return clockTime(iso, locale);
|
|
27
|
-
if (days === 1) return "Yesterday";
|
|
28
|
-
if (days > 1 && days < 7) return d.toLocaleDateString(locale, { weekday: "short" });
|
|
29
|
-
return d.toLocaleDateString(locale, {
|
|
30
|
-
day: "numeric",
|
|
31
|
-
month: "short",
|
|
32
|
-
year: d.getFullYear() === now.getFullYear() ? void 0 : "numeric"
|
|
33
|
-
});
|
|
20
|
+
return relativeTime$1(iso, now, { style: "compact", locale: locale ?? new Intl.DateTimeFormat().resolvedOptions().locale });
|
|
34
21
|
}
|
|
35
22
|
function formatBytes(bytes) {
|
|
36
23
|
if (bytes == null || !Number.isFinite(bytes)) return "";
|