@drawnagency/primitives 0.1.25 → 0.1.26
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/components/shared/HistoryPopover.d.ts.map +1 -1
- package/dist/components/shared/Navigation.d.ts.map +1 -1
- package/dist/components/shell/HistoryToolbar.d.ts.map +1 -1
- package/dist/components/shell/RestoreModal.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/timestamp.d.ts +2 -0
- package/dist/lib/timestamp.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/shared/HistoryPopover.tsx +2 -33
- package/src/components/shared/Navigation.tsx +2 -5
- package/src/components/shell/HistoryToolbar.tsx +2 -7
- package/src/components/shell/RestoreModal.tsx +2 -7
- package/src/lib/timestamp.ts +23 -0
- /package/dist/{chunk-KX7NRYQD.js → chunk-FSVPD7TW.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryPopover.d.ts","sourceRoot":"","sources":["../../../src/components/shared/HistoryPopover.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HistoryPopover.d.ts","sourceRoot":"","sources":["../../../src/components/shared/HistoryPopover.tsx"],"names":[],"mappings":"AAWA,UAAU,mBAAmB;IAC3B,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD;AAED,wBAAgB,cAAc,CAAC,EAAE,cAAc,EAAE,EAAE,mBAAmB,2CAwFrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Navigation.d.ts","sourceRoot":"","sources":["../../../src/components/shared/Navigation.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Navigation.d.ts","sourceRoot":"","sources":["../../../src/components/shared/Navigation.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAO7C,UAAU,KAAK;IACb,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC;IACxC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,KAAK,2CA8NvG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/shell/HistoryToolbar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HistoryToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/shell/HistoryToolbar.tsx"],"names":[],"mappings":"AAGA,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,mBAAmB,2CAsBvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestoreModal.d.ts","sourceRoot":"","sources":["../../../src/components/shell/RestoreModal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RestoreModal.d.ts","sourceRoot":"","sources":["../../../src/components/shell/RestoreModal.tsx"],"names":[],"mappings":"AAIA,UAAU,iBAAiB;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,iBAAiB,2CAiBhG"}
|
package/dist/index.js
CHANGED
package/dist/lib/index.js
CHANGED
package/dist/lib/timestamp.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/lib/timestamp.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA8BnD"}
|
|
1
|
+
{"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/lib/timestamp.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAalD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA8BnD"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect } from "react";
|
|
2
2
|
import { cn } from "../../lib/cn";
|
|
3
|
+
import { formatDateTime } from "../../lib/timestamp";
|
|
3
4
|
import { Button } from "./Button";
|
|
4
5
|
|
|
5
6
|
interface CommitItem {
|
|
@@ -12,37 +13,6 @@ interface HistoryPopoverProps {
|
|
|
12
13
|
onSelectCommit: (sha: string, date: string) => void;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
function formatRelativeDate(dateStr: string): string {
|
|
16
|
-
const date = new Date(dateStr);
|
|
17
|
-
const now = new Date();
|
|
18
|
-
const diffMs = now.getTime() - date.getTime();
|
|
19
|
-
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
|
20
|
-
|
|
21
|
-
if (diffDays === 0) return "Today";
|
|
22
|
-
if (diffDays === 1) return "Yesterday";
|
|
23
|
-
if (diffDays < 7) return `${diffDays} days ago`;
|
|
24
|
-
if (diffDays < 30) {
|
|
25
|
-
const weeks = Math.floor(diffDays / 7);
|
|
26
|
-
return `${weeks} ${weeks === 1 ? "week" : "weeks"} ago`;
|
|
27
|
-
}
|
|
28
|
-
if (diffDays < 365) {
|
|
29
|
-
const months = Math.floor(diffDays / 30);
|
|
30
|
-
return `${months} ${months === 1 ? "month" : "months"} ago`;
|
|
31
|
-
}
|
|
32
|
-
const years = Math.floor(diffDays / 365);
|
|
33
|
-
return `${years} ${years === 1 ? "year" : "years"} ago`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function formatAbsoluteDate(dateStr: string): string {
|
|
37
|
-
return new Date(dateStr).toLocaleDateString("en-US", {
|
|
38
|
-
month: "short",
|
|
39
|
-
day: "numeric",
|
|
40
|
-
year: "numeric",
|
|
41
|
-
hour: "numeric",
|
|
42
|
-
minute: "2-digit",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
16
|
export function HistoryPopover({ onSelectCommit }: HistoryPopoverProps) {
|
|
47
17
|
const [commits, setCommits] = useState<CommitItem[]>([]);
|
|
48
18
|
const [loading, setLoading] = useState(true);
|
|
@@ -111,9 +81,8 @@ export function HistoryPopover({ onSelectCommit }: HistoryPopoverProps) {
|
|
|
111
81
|
"w-full cursor-pointer px-4 py-2 text-left text-xs transition-colors",
|
|
112
82
|
"hover:bg-base-accent text-base-contrast-light hover:text-base-contrast",
|
|
113
83
|
)}
|
|
114
|
-
title={formatAbsoluteDate(commit.date)}
|
|
115
84
|
>
|
|
116
|
-
{
|
|
85
|
+
{formatDateTime(commit.date)}
|
|
117
86
|
</button>
|
|
118
87
|
</li>
|
|
119
88
|
))}
|
|
@@ -4,6 +4,7 @@ import { Toggle } from "./Toggle";
|
|
|
4
4
|
import type { NavItem } from "../../lib/nav";
|
|
5
5
|
import { editModeEvent, navChangeEvent, darkModeEvent, historySelectEvent } from "../../lib/events";
|
|
6
6
|
import { useActiveHeadings } from "../../hooks/useActiveHeadings";
|
|
7
|
+
import { formatDate } from "../../lib/timestamp";
|
|
7
8
|
import { Popover } from "./Popover";
|
|
8
9
|
import { HistoryPopover } from "./HistoryPopover";
|
|
9
10
|
|
|
@@ -205,11 +206,7 @@ export default function Navigation({ navLinks: initialNavLinks, siteName, darkMo
|
|
|
205
206
|
className="cursor-pointer text-xs text-base-contrast-light hover:text-primary transition-colors"
|
|
206
207
|
aria-label="View history"
|
|
207
208
|
>
|
|
208
|
-
Last updated {
|
|
209
|
-
month: "short",
|
|
210
|
-
day: "numeric",
|
|
211
|
-
year: "numeric",
|
|
212
|
-
})}
|
|
209
|
+
Last updated {formatDate(lastUpdated)}
|
|
213
210
|
</button>
|
|
214
211
|
<Popover
|
|
215
212
|
isOpen={showHistory}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatDateTime } from "../../lib/timestamp";
|
|
1
2
|
import { Button } from "../shared/Button";
|
|
2
3
|
|
|
3
4
|
interface HistoryToolbarProps {
|
|
@@ -7,12 +8,6 @@ interface HistoryToolbarProps {
|
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function HistoryToolbar({ date, onBackToCurrent, onRestore }: HistoryToolbarProps) {
|
|
10
|
-
const formattedDate = new Date(date).toLocaleDateString("en-US", {
|
|
11
|
-
month: "short",
|
|
12
|
-
day: "numeric",
|
|
13
|
-
year: "numeric",
|
|
14
|
-
});
|
|
15
|
-
|
|
16
11
|
return (
|
|
17
12
|
<div className="fixed top-0 right-0 left-0 z-50 border-b border-base-200 bg-base">
|
|
18
13
|
<div className="mx-auto max-w-screen-xl grid grid-cols-3 items-center px-4 py-2">
|
|
@@ -23,7 +18,7 @@ export function HistoryToolbar({ date, onBackToCurrent, onRestore }: HistoryTool
|
|
|
23
18
|
</div>
|
|
24
19
|
<div className="flex items-center justify-center">
|
|
25
20
|
<span className="text-xs font-medium text-base-contrast-light">
|
|
26
|
-
Viewing {
|
|
21
|
+
Viewing {formatDateTime(date)}
|
|
27
22
|
</span>
|
|
28
23
|
</div>
|
|
29
24
|
<div className="flex items-center justify-end">
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatDateTime } from "../../lib/timestamp";
|
|
1
2
|
import { EditorModal } from "./EditorModal";
|
|
2
3
|
import { Button } from "../shared/Button";
|
|
3
4
|
|
|
@@ -10,16 +11,10 @@ interface RestoreModalProps {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export function RestoreModal({ isOpen, onClose, date, onConfirm, isRestoring }: RestoreModalProps) {
|
|
13
|
-
const formattedDate = new Date(date).toLocaleDateString("en-US", {
|
|
14
|
-
month: "short",
|
|
15
|
-
day: "numeric",
|
|
16
|
-
year: "numeric",
|
|
17
|
-
});
|
|
18
|
-
|
|
19
14
|
return (
|
|
20
15
|
<EditorModal isOpen={isOpen} onClose={onClose} title="Restore this version?">
|
|
21
16
|
<p className="mb-4 text-sm text-base-contrast-light">
|
|
22
|
-
This will publish the content from {
|
|
17
|
+
This will publish the content from {formatDateTime(date)} as a new update.
|
|
23
18
|
Your current content will still be available in the history.
|
|
24
19
|
</p>
|
|
25
20
|
<div className="flex justify-end gap-3">
|
package/src/lib/timestamp.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
export function formatDate(iso: string): string {
|
|
2
|
+
return new Date(iso).toLocaleDateString("en-US", {
|
|
3
|
+
month: "short",
|
|
4
|
+
day: "numeric",
|
|
5
|
+
year: "numeric",
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function formatDateTime(iso: string): string {
|
|
10
|
+
const date = new Date(iso);
|
|
11
|
+
const datePart = date.toLocaleDateString("en-US", {
|
|
12
|
+
month: "short",
|
|
13
|
+
day: "numeric",
|
|
14
|
+
year: "numeric",
|
|
15
|
+
});
|
|
16
|
+
const timePart = date.toLocaleTimeString("en-US", {
|
|
17
|
+
hour: "numeric",
|
|
18
|
+
minute: "2-digit",
|
|
19
|
+
hour12: true,
|
|
20
|
+
});
|
|
21
|
+
return `${datePart} | ${timePart}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
1
24
|
export function formatTimestamp(iso: string): string {
|
|
2
25
|
const date = new Date(iso);
|
|
3
26
|
const now = new Date();
|
|
File without changes
|