Initial commit: Luminary photo catalog and RAW editor

Browser-based photo catalog with an optional team server (SQLite + LibRaw).
Local database, uploaded photos, build output and dependencies are gitignored.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-23 15:19:25 +00:00
commit cd52a2f82f
121 changed files with 101872 additions and 0 deletions
+520
View File
@@ -0,0 +1,520 @@
import { useEffect, useRef, useState } from 'react';
import { COLOR_LABELS, isEdited, thumbTransform } from '../lib/edits';
import { draggedPhotoIds, endDrag, PHOTO_DRAG, startPhotoDrag } from '../lib/drag';
import type { ColorLabel, Flag, PhotoRecord } from '../types';
import Stars, { ColorSwatches, FlagButtons } from './Stars';
interface Props {
photos: PhotoRecord[];
totalCount: number;
selected: string[];
onSelect: (id: string, e: React.MouseEvent) => void;
onContextMenu: (e: React.MouseEvent, id: string) => void;
onOpen: (id: string) => void;
onRate: (id: string, rating: number) => void;
onBulkRate: (rating: number) => void;
onBulkFlag: (flag: Flag) => void;
onBulkColor: (color: ColorLabel) => void;
onDelete: () => void;
onExport: () => void;
onCompare: () => void;
onStack: () => void;
onVirtualCopy: () => void;
onMerge: () => void;
onPrint: () => void;
stacks: Map<string, { count: number; expanded: boolean }>;
onToggleStack: (id: string) => void;
onImport: () => void;
onDropFiles: (files: File[]) => void;
onClearSelection: () => void;
onReorder: (ids: string[], targetId: string | null) => void;
/** rubber-band selection: the complete new selection */
onMarqueeSelect: (ids: string[]) => void;
/** client proofing picks per photo, shown as a badge */
proofCounts: Map<string, number>;
proofStatus: Map<string, { approved: number; changes: number; comments: number }>;
}
function fmtSize(bytes: number) {
if (bytes > 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
return `${Math.max(1, Math.round(bytes / 1024))} KB`;
}
export default function LibraryGrid({
photos,
totalCount,
selected,
onSelect,
onContextMenu,
onOpen,
onRate,
onBulkRate,
onBulkFlag,
onBulkColor,
onDelete,
onExport,
onCompare,
onStack,
onVirtualCopy,
onMerge,
onPrint,
stacks,
onToggleStack,
onImport,
onDropFiles,
onClearSelection,
onReorder,
onMarqueeSelect,
proofCounts,
proofStatus,
}: Props) {
const gridRef = useRef<HTMLDivElement>(null);
const band = useRef<{ sx: number; sy: number; base: string[]; moved: boolean; box: DOMRect } | null>(null);
const [bandRect, setBandRect] = useState<{ x: number; y: number; w: number; h: number } | null>(null);
const virtualize = photos.length > 140;
const [viewWindow, setViewWindow] = useState({
start: 0,
end: Math.min(photos.length, 140),
top: 0,
bottom: 0,
});
const selectedSet = new Set(selected);
useEffect(() => {
if (!virtualize) {
setViewWindow({ start: 0, end: photos.length, top: 0, bottom: 0 });
return;
}
const grid = gridRef.current;
if (!grid) return;
let frame = 0;
const measure = () => {
const card = grid.querySelector<HTMLElement>('.card');
if (!card) {
if (viewWindow.start >= photos.length) {
setViewWindow({ start: 0, end: Math.min(photos.length, 140), top: 0, bottom: 0 });
}
return;
}
const box = card.getBoundingClientRect();
const style = getComputedStyle(grid);
const gapX = Number.parseFloat(style.columnGap) || 12;
const gapY = Number.parseFloat(style.rowGap) || 12;
const horizontalPadding =
(Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0);
const columns = Math.max(
1,
Math.round((grid.clientWidth - horizontalPadding + gapX) / (box.width + gapX)),
);
const rowStep = box.height + gapY;
const firstRow = Math.max(0, Math.floor(grid.scrollTop / rowStep) - 2);
const lastRow = Math.ceil((grid.scrollTop + grid.clientHeight) / rowStep) + 2;
const start = Math.min(photos.length, firstRow * columns);
const end = Math.min(photos.length, Math.max(start + columns, lastRow * columns));
const totalRows = Math.ceil(photos.length / columns);
const top = firstRow * rowStep;
const bottom = Math.max(0, totalRows - lastRow) * rowStep;
setViewWindow((current) =>
current.start === start &&
current.end === end &&
current.top === top &&
current.bottom === bottom
? current
: { start, end, top, bottom },
);
};
const schedule = () => {
cancelAnimationFrame(frame);
frame = requestAnimationFrame(measure);
};
const observer = new ResizeObserver(schedule);
observer.observe(grid);
grid.addEventListener('scroll', schedule, { passive: true });
schedule();
return () => {
cancelAnimationFrame(frame);
observer.disconnect();
grid.removeEventListener('scroll', schedule);
};
}, [photos.length, virtualize, viewWindow.start]);
const someSelected = selected.length > 0;
const sharedRating = (() => {
if (!someSelected) return 0;
const rated = photos.filter((p) => selectedSet.has(p.id));
if (!rated.length) return 0;
const first = rated[0].rating;
return rated.every((p) => p.rating === first) ? first : 0;
})();
if (!photos.length) {
return (
<div
className="grid-empty"
onDragOver={(e) => e.preventDefault()}
onDrop={(e) => {
e.preventDefault();
const ids = draggedPhotoIds();
if (ids.length) { onReorder(ids, null);
endDrag();
return;
}
onDropFiles(Array.from(e.dataTransfer.files));
}}
ref={gridRef}
onPointerDown={(e) => {
const grid = gridRef.current;
// A band starts on empty grid space; cards keep their own click/drag.
if (!grid || e.button !== 0 || e.target !== grid) return;
e.preventDefault();
const box = grid.getBoundingClientRect();
band.current = {
sx: e.clientX,
sy: e.clientY,
base: e.shiftKey || e.metaKey || e.ctrlKey ? [...selected] : [],
moved: false,
box,
};
setBandRect({ x: e.clientX - box.left + grid.scrollLeft, y: e.clientY - box.top + grid.scrollTop, w: 0, h: 0 });
grid.setPointerCapture(e.pointerId);
}}
onPointerMove={(e) => {
const grid = gridRef.current;
const start = band.current;
if (!grid || !start) return;
const left = Math.min(start.sx, e.clientX);
const top = Math.min(start.sy, e.clientY);
const right = Math.max(start.sx, e.clientX);
const bottom = Math.max(start.sy, e.clientY);
if (Math.abs(e.clientX - start.sx) > 3 || Math.abs(e.clientY - start.sy) > 3) start.moved = true;
setBandRect({
x: left - start.box.left + grid.scrollLeft,
y: top - start.box.top + grid.scrollTop,
w: right - left,
h: bottom - top,
});
if (!start.moved) return;
const hits: string[] = [];
for (const el of grid.querySelectorAll<HTMLElement>('.card')) {
const r = el.getBoundingClientRect();
if (r.right > left && r.left < right && r.bottom > top && r.top < bottom) {
const id = el.dataset.id;
if (id) hits.push(id);
}
}
onMarqueeSelect([...start.base, ...hits.filter((id) => !start.base.includes(id))]);
}}
onPointerUp={(e) => {
const grid = gridRef.current;
const start = band.current;
band.current = null;
setBandRect(null);
if (!grid || !start) return;
if (grid.hasPointerCapture(e.pointerId)) grid.releasePointerCapture(e.pointerId);
if (!start.moved && !start.base.length) onClearSelection();
}}
onPointerCancel={() => {
band.current = null;
setBandRect(null);
}}
>
<div className="empty-card">
{totalCount > 0 ? (
<>
<h2>No photos match these filters</h2>
<p className="muted">Loosen the rating, flag or label filters to see more of this event.</p>
</>
) : (
<>
<h2>Your library is empty</h2>
<p className="muted">
Create an event and import a shoot. Photos are stored locally, or on your team server
when one is connected.
</p>
<ol className="quick-steps">
<li>Import a shoot into an event.</li>
<li>Rate and flag the keepers.</li>
<li>Double-click a photo to open Develop.</li>
<li>Press ? anytime for shortcuts.</li>
</ol>
<button className="btn primary" onClick={onImport}>
Import photos
</button>
<p className="muted small">
Drop JPEG, PNG, TIFF or camera raw files anywhere in this area.
</p>
</>
)}
</div>
</div>
);
}
return (
<div className="grid-area">
<div className="grid-toolbar">
{someSelected ? (
<>
<span className="selection-count">{selected.length} selected</span>
<Stars value={sharedRating} onChange={onBulkRate} size="md" title="Set rating for selection (0–5)" />
<FlagButtons value={'none'} onChange={onBulkFlag} />
<ColorSwatches value={''} onChange={onBulkColor} />
<div className="spacer" />
<button
className="btn ghost small"
onClick={onCompare}
disabled={selected.length < 2 || selected.length > 4}
title={selected.length > 4 ? 'Select 2–4 photos to compare' : 'Compare selected photos'}
>
Compare
</button>
<button className="btn ghost small" onClick={onStack} disabled={selected.length < 2}>
Stack
</button>
<button className="btn ghost small" onClick={onVirtualCopy} disabled={selected.length !== 1}>
Virtual copy
</button>
<button className="btn ghost small" onClick={onMerge} disabled={selected.length < 2}>
Merge
</button>
<button className="btn ghost small" onClick={onExport}>
Export
</button>
<button className="btn ghost small" onClick={onPrint}>
Print
</button>
<button className="btn ghost small danger" onClick={onDelete}>
Delete
</button>
<button className="icon-btn" title="Clear selection" onClick={onClearSelection}>
✕
</button>
</>
) : (
<>
<span className="muted small">
Click to select · drag on empty space to marquee · double-click to edit · 1–5 to rate ·{' '}
? for shortcuts
</span>
<div className="spacer" />
<span className="muted small">{photos.length} photos</span>
</>
)} </div>
<div className="grid"
onDragOver={(e) => {
if (draggedPhotoIds().length) {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
}
}}
onDrop={(e) => {
e.preventDefault();
const ids = draggedPhotoIds();
if (ids.length) { onReorder(ids, null);
endDrag();
return;
}
onDropFiles(Array.from(e.dataTransfer.files));
}}
ref={gridRef}
onPointerDown={(e) => {
const grid = gridRef.current;
// A band starts on empty grid space; cards keep their own click/drag.
if (!grid || e.button !== 0 || e.target !== grid) return;
e.preventDefault();
const box = grid.getBoundingClientRect();
band.current = {
sx: e.clientX,
sy: e.clientY,
base: e.shiftKey || e.metaKey || e.ctrlKey ? [...selected] : [],
moved: false,
box,
};
setBandRect({ x: e.clientX - box.left + grid.scrollLeft, y: e.clientY - box.top + grid.scrollTop, w: 0, h: 0 });
grid.setPointerCapture(e.pointerId);
}}
onPointerMove={(e) => {
const grid = gridRef.current;
const start = band.current;
if (!grid || !start) return;
const left = Math.min(start.sx, e.clientX);
const top = Math.min(start.sy, e.clientY);
const right = Math.max(start.sx, e.clientX);
const bottom = Math.max(start.sy, e.clientY);
if (Math.abs(e.clientX - start.sx) > 3 || Math.abs(e.clientY - start.sy) > 3) start.moved = true;
setBandRect({
x: left - start.box.left + grid.scrollLeft,
y: top - start.box.top + grid.scrollTop,
w: right - left,
h: bottom - top,
});
if (!start.moved) return;
const hits: string[] = [];
for (const el of grid.querySelectorAll<HTMLElement>('.card')) {
const r = el.getBoundingClientRect();
if (r.right > left && r.left < right && r.bottom > top && r.top < bottom) {
const id = el.dataset.id;
if (id) hits.push(id);
}
}
onMarqueeSelect([...start.base, ...hits.filter((id) => !start.base.includes(id))]);
}}
onPointerUp={(e) => {
const grid = gridRef.current;
const start = band.current;
band.current = null;
setBandRect(null);
if (!grid || !start) return;
if (grid.hasPointerCapture(e.pointerId)) grid.releasePointerCapture(e.pointerId);
if (!start.moved && !start.base.length) onClearSelection();
}}
onPointerCancel={() => {
band.current = null;
setBandRect(null);
}}
>
{bandRect && (
<div
className="marquee"
style={{ left: bandRect.x, top: bandRect.y, width: bandRect.w, height: bandRect.h }}
/>
)}
{virtualize && viewWindow.top > 0 && (
<div className="grid-gap" style={{ height: viewWindow.top }} aria-hidden="true" />
)}
{photos.slice(viewWindow.start, viewWindow.end).map((p) => {
const color = COLOR_LABELS.find((c) => c.value === p.color);
const isDragging = draggedPhotoIds().includes(p.id);
return ( <figure
key={p.id}
data-id={p.id}
className={`card ${selectedSet.has(p.id) ? 'selected' : ''} ${p.flag === 'reject' ? 'rejected' : ''} ${isDragging ? 'dragging' : ''}`}
onClick={(e) => onSelect(p.id, e)}
onContextMenu={(e) => onContextMenu(e, p.id)}
onDoubleClick={() => onOpen(p.id)}
draggable
onDragStart={(e) => {
if ((e.target as HTMLElement).closest('.badge.stack')) {
e.preventDefault();
return;
}
const ids = selectedSet.has(p.id) && selected.length > 1 ? selected : [p.id];
startPhotoDrag(ids);
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData(PHOTO_DRAG, ids.join(','));
e.dataTransfer.setData('text/plain', ids.join(','));
e.currentTarget.classList.add('dragging');
}}
onDragEnd={(e) => {
e.currentTarget.classList.remove('dragging');
endDrag();
}}
onDragOver={(e) => {
if (!draggedPhotoIds().length) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'move';
e.currentTarget.classList.add('drop-target');
}}
onDragLeave={(e) => e.currentTarget.classList.remove('drop-target')}
onDrop={(e) => {
const ids = draggedPhotoIds();
e.currentTarget.classList.remove('drop-target');
if (!ids.length) return;
e.preventDefault();
e.stopPropagation();
onReorder(ids, p.id);
endDrag();
}}
>
<div className="card-thumb">
<img
src={p.thumbUrl ?? p.thumb}
alt={p.name}
loading="lazy"
draggable={false}
style={{ transform: thumbTransform(p) }}
/>
<div className="card-badges">
{p.flag === 'pick' && <span className="badge pick">✓</span>}
{p.flag === 'reject' && <span className="badge reject">✕</span>}
{p.raw && (
<span className="badge raw" title={p.decode === 'embedded' ? 'Raw (camera preview)' : 'Raw (demosaiced)'}>
RAW
</span>
)}
{isEdited(p.edits) && (
<span className="badge edit" title="Has develop adjustments">
✎
</span>
)}
{p.copyOf && (
<span className="badge copy" title={p.copyName ?? 'Virtual copy'}>
VC
</span>
)}
{stacks.get(p.id) && (
<button
className={`badge stack ${stacks.get(p.id)?.expanded ? 'expanded' : ''}`}
title={
stacks.get(p.id)?.expanded
? 'Collapse stack'
: `Stack of ${stacks.get(p.id)?.count} — click to expand`
}
onClick={(e) => {
e.stopPropagation();
onToggleStack(p.id);
}}
onDoubleClick={(e) => e.stopPropagation()}
>
{stacks.get(p.id)?.expanded ? '▣' : '▤'} {stacks.get(p.id)?.count}
</button>
)}
{(proofCounts.get(p.id) ?? 0) > 0 && (
<span
className="badge proof"
title={`Picked by ${proofCounts.get(p.id)} client${proofCounts.get(p.id) === 1 ? '' : 's'}`}
>
♥ {(proofCounts.get(p.id) ?? 0) > 1 ? proofCounts.get(p.id) : ''}
</span>
)}
{proofStatus.get(p.id)?.approved ? (
<span className="badge review-approved" title="Approved by a client">✓</span>
) : null}
{proofStatus.get(p.id)?.changes ? (
<span className="badge review-changes" title="Client requested changes">!</span>
) : null}
{proofStatus.get(p.id)?.comments ? (
<span className="badge review-comment" title={`${proofStatus.get(p.id)?.comments} client comment(s)`}>
💬 {proofStatus.get(p.id)?.comments}
</span>
) : null}
</div>
{color && <span className="color-strip" style={{ background: color.hex }} />}
<div className="card-hover">
<span className="muted small">{fmtSize(p.size)}</span>
<span className="muted small">
{p.width}×{p.height}
</span>
</div>
</div>
<figcaption>
<div className="card-name" title={p.name}>
{p.name}
</div>
<div className="card-bottom">
<Stars value={p.rating} onChange={(n) => onRate(p.id, n)} />
{p.meta.camera && <span className="card-cam">{p.meta.camera}</span>}
</div>
</figcaption>
</figure>
);
})}
{virtualize && viewWindow.bottom > 0 && (
<div className="grid-gap" style={{ height: viewWindow.bottom }} aria-hidden="true" />
)}
</div>
</div>
);
}