@bygghammar/cms-platform 0.15.0 → 0.17.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.
@@ -0,0 +1,22 @@
1
+ /** Shapes the shared Media Library screen needs from the host. */
2
+
3
+ export type MediaLibraryItem = {
4
+ path: string;
5
+ name: string;
6
+ url: string;
7
+ size: number;
8
+ contentType?: string | null;
9
+ uploadedAt?: string | null;
10
+ updatedAt?: string | null;
11
+ uploadedBy?: string | null;
12
+ };
13
+
14
+ export type MediaTrashItem = {
15
+ id: string;
16
+ originalPath: string;
17
+ url: string;
18
+ size: number;
19
+ contentType?: string | null;
20
+ deletedAt: string;
21
+ deletedByEmail?: string | null;
22
+ };
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Imperative poster-frame picker for video uploads.
3
+ *
4
+ * Mounts a small dialog on demand so any upload surface (Media Library, block
5
+ * media picker) can ask the editor which frame to use as the video poster.
6
+ * Resolves with the chosen time in seconds, or `null` to keep the automatic
7
+ * frame (~10% into the clip).
8
+ */
9
+ import { useEffect, useRef, useState } from "react";
10
+ import { createRoot } from "react-dom/client";
11
+
12
+ function formatTime(s: number) {
13
+ if (!Number.isFinite(s)) return "0:00";
14
+ const m = Math.floor(s / 60);
15
+ const sec = Math.floor(s % 60);
16
+ return `${m}:${String(sec).padStart(2, "0")}`;
17
+ }
18
+
19
+ function PosterDialog({ file, onDone }: { file: File; onDone: (seconds: number | null) => void }) {
20
+ const videoRef = useRef<HTMLVideoElement>(null);
21
+ const [url] = useState(() => URL.createObjectURL(file));
22
+ const [duration, setDuration] = useState(0);
23
+ const [time, setTime] = useState(0);
24
+
25
+ useEffect(() => () => URL.revokeObjectURL(url), [url]);
26
+
27
+ useEffect(() => {
28
+ const onKey = (e: KeyboardEvent) => {
29
+ if (e.key === "Escape") onDone(null);
30
+ };
31
+ window.addEventListener("keydown", onKey);
32
+ return () => window.removeEventListener("keydown", onKey);
33
+ }, [onDone]);
34
+
35
+ const seek = (v: number) => {
36
+ setTime(v);
37
+ if (videoRef.current) videoRef.current.currentTime = v;
38
+ };
39
+
40
+ return (
41
+ <div className="fixed inset-0 z-[300] flex items-center justify-center bg-ink/70 p-4">
42
+ <div className="w-full max-w-2xl border border-ink/15 bg-white shadow-xl">
43
+ <header className="flex items-center justify-between border-b border-ink/10 px-4 py-3">
44
+ <div>
45
+ <h2 className="text-sm font-medium text-ink">Choose poster frame</h2>
46
+ <p className="text-[0.7rem] text-ink/55">{file.name}</p>
47
+ </div>
48
+ <button
49
+ type="button"
50
+ onClick={() => onDone(null)}
51
+ className="text-[0.7rem] uppercase tracking-[0.18em] text-ink/50 hover:text-ink"
52
+ >
53
+ Cancel
54
+ </button>
55
+ </header>
56
+
57
+ <div className="space-y-3 p-4">
58
+ <video
59
+ ref={videoRef}
60
+ src={url}
61
+ muted
62
+ playsInline
63
+ preload="auto"
64
+ className="max-h-[50vh] w-full bg-ink/5 object-contain"
65
+ onLoadedMetadata={(e) => {
66
+ const v = e.currentTarget;
67
+ const d = Number.isFinite(v.duration) ? v.duration : 0;
68
+ setDuration(d);
69
+ const start = Math.min(d, d * 0.1);
70
+ setTime(start);
71
+ v.currentTime = start;
72
+ }}
73
+ />
74
+ <input
75
+ type="range"
76
+ min={0}
77
+ max={Math.max(0.1, duration)}
78
+ step={0.05}
79
+ value={time}
80
+ onChange={(e) => seek(Number(e.target.value))}
81
+ className="w-full accent-sea"
82
+ />
83
+ <div className="flex items-center justify-between text-[0.72rem] text-ink/60">
84
+ <span>
85
+ {formatTime(time)} / {formatTime(duration)}
86
+ </span>
87
+ <span>Drag the slider to the frame you want as the poster image.</span>
88
+ </div>
89
+ </div>
90
+
91
+ <footer className="flex justify-end gap-2 border-t border-ink/10 px-4 py-3">
92
+ <button
93
+ type="button"
94
+ onClick={() => onDone(null)}
95
+ className="border border-ink/15 px-3 py-1.5 text-sm hover:border-ink/40"
96
+ >
97
+ Use automatic frame
98
+ </button>
99
+ <button
100
+ type="button"
101
+ onClick={() => onDone(time)}
102
+ className="bg-ink px-4 py-1.5 text-sm text-paper hover:bg-sea"
103
+ >
104
+ Use this frame
105
+ </button>
106
+ </footer>
107
+ </div>
108
+ </div>
109
+ );
110
+ }
111
+
112
+ /** Ask the editor to pick a poster frame. Returns seconds, or null for auto. */
113
+ export function pickVideoPoster(file: File): Promise<number | null> {
114
+ if (typeof document === "undefined") return Promise.resolve(null);
115
+ return new Promise((resolve) => {
116
+ const host = document.createElement("div");
117
+ document.body.appendChild(host);
118
+ const root = createRoot(host);
119
+ const done = (seconds: number | null) => {
120
+ resolve(seconds);
121
+ setTimeout(() => {
122
+ root.unmount();
123
+ host.remove();
124
+ }, 0);
125
+ };
126
+ root.render(<PosterDialog file={file} onDone={done} />);
127
+ });
128
+ }