feat(ui): remember detail window presentation and sort image grids
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/ui-react",
|
||||
"version": "0.7.6",
|
||||
"version": "0.7.7",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
arrayMove,
|
||||
useSortable,
|
||||
verticalListSortingStrategy,
|
||||
rectSortingStrategy,
|
||||
} from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import { cn } from "./cn.js";
|
||||
@@ -120,8 +121,9 @@ export function DropZone({ id, data, className, children }: { id: string; data?:
|
||||
return <div ref={setNodeRef} className={cn(className, isOver && "is-drag-over")}>{children}</div>;
|
||||
}
|
||||
|
||||
export function SortableScope({ ids, children }: { ids: string[]; children: ReactNode }) {
|
||||
return <SortableContext items={ids} strategy={verticalListSortingStrategy}>{children}</SortableContext>;
|
||||
const SortableLayoutContext=createContext<"list"|"grid">("list");
|
||||
export function SortableScope({ ids, children, layout="list" }: { ids: string[]; children: ReactNode; layout?:"list"|"grid" }) {
|
||||
return <SortableLayoutContext.Provider value={layout}><SortableContext items={ids} strategy={layout==="grid"?rectSortingStrategy:verticalListSortingStrategy}>{children}</SortableContext></SortableLayoutContext.Provider>;
|
||||
}
|
||||
|
||||
export function SortableItem({ id, data, className, children }: {
|
||||
@@ -131,7 +133,8 @@ export function SortableItem({ id, data, className, children }: {
|
||||
children: (state: { handle: ReactNode; isDragging: boolean }) => ReactNode;
|
||||
}) {
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id, data });
|
||||
const verticalTransform = transform ? { ...transform, x: 0 } : null;
|
||||
const layout=useContext(SortableLayoutContext);
|
||||
const verticalTransform = transform && layout!=="grid" ? { ...transform, x: 0 } : transform;
|
||||
return (
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
@@ -143,8 +146,9 @@ export function SortableItem({ id, data, className, children }: {
|
||||
);
|
||||
}
|
||||
|
||||
export function SortableList<T>({ items, getId, className, onReorder, children }: {
|
||||
export function SortableList<T>({ items, getId, className, onReorder, children, layout="list" }: {
|
||||
items: T[];
|
||||
layout?: "list" | "grid";
|
||||
getId: (item: T) => string;
|
||||
className?: string;
|
||||
onReorder: (items: T[]) => void;
|
||||
@@ -158,7 +162,7 @@ export function SortableList<T>({ items, getId, className, onReorder, children }
|
||||
const to = ids.indexOf(overId);
|
||||
if (from >= 0 && to >= 0) onReorder(arrayMove(items, from, to));
|
||||
}}>
|
||||
<SortableScope ids={ids}>
|
||||
<SortableScope ids={ids} layout={layout}>
|
||||
<div className={className}>
|
||||
{items.map((item) => (
|
||||
<SortableItem key={getId(item)} id={getId(item)}>
|
||||
|
||||
@@ -59,6 +59,9 @@ export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title
|
||||
onRectCommit?: (rect: WindowRect) => void;
|
||||
/** Centered windows can become modeless without remounting their contents. */
|
||||
allowFloating?: boolean;
|
||||
/** App-owned presentation, persisted by window kind alongside rect. */
|
||||
floating?: boolean;
|
||||
onFloatingChange?: (floating: boolean) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
@@ -83,6 +86,8 @@ export function Window({
|
||||
rect,
|
||||
onRectCommit,
|
||||
allowFloating = true,
|
||||
floating: controlledFloating,
|
||||
onFloatingChange,
|
||||
onClose,
|
||||
className,
|
||||
style,
|
||||
@@ -107,7 +112,7 @@ export function Window({
|
||||
const changeRect = (next: WindowRect | null) => { rectRef.current = next; setFloatingRect(next); };
|
||||
const gestureChanged = useRef(false);
|
||||
const resizeRef = useRef<{ pointerId: number; x: number; y: number; rect: WindowRect; edge: ResizeEdge } | null>(null);
|
||||
const isFloating = floating && allowFloating && placement === "center";
|
||||
const isFloating = (controlledFloating ?? floating) && allowFloating && placement === "center";
|
||||
const freeGeometry = isFloating || (resizable && placement === "end");
|
||||
const canDrag = draggable || freeGeometry;
|
||||
const shouldLockBodyScroll = !suspended && !isFloating && (lockBodyScroll ?? placement === "center");
|
||||
@@ -310,7 +315,9 @@ export function Window({
|
||||
const rect = dialogRef.current?.getBoundingClientRect();
|
||||
if (rect) changeRect(fitWindow(rectRef.current ?? { left: rect.left, top: rect.top, width: rect.width, height: rect.height }, { width: window.innerWidth, height: window.innerHeight }));
|
||||
}
|
||||
if (rectRef.current) commitRef.current?.({...rectRef.current});
|
||||
setFloating(!isFloating);
|
||||
onFloatingChange?.(!isFloating);
|
||||
}}><Icon name="move" /></IconButton>}
|
||||
{headerActionsPlacement === "before-close" && headerActions}
|
||||
<button type="button" className="nodedc-window__close" aria-label={closeLabel} onClick={onClose}>
|
||||
|
||||
Reference in New Issue
Block a user