typescript
This commit is contained in:
@@ -51,6 +51,13 @@ interface NavigatorSnapshot {
|
||||
height?: number | null;
|
||||
}
|
||||
|
||||
type OverlayOriginHint = {
|
||||
rotation?: number;
|
||||
scale?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
};
|
||||
|
||||
interface OverlayOriginTransform {
|
||||
rotation: number;
|
||||
scaleX: number;
|
||||
@@ -180,7 +187,7 @@ interface DesktopWorkspaceViewProps {
|
||||
bringToFront: (docId: Identifier | null | undefined) => void;
|
||||
setDraggingId: (value: string | null) => void;
|
||||
canvasSize: { width: number; height: number };
|
||||
openOverlayForDoc: (docId: Identifier | null | undefined, originInfo?: OverlayOriginTransform | null) => void;
|
||||
openOverlayForDoc: (docId: Identifier | null | undefined, originInfo?: OverlayOriginHint | null) => void;
|
||||
recalcVisibleDocIds: () => void;
|
||||
dragSettings: DragSettings;
|
||||
onInspectDocument?: DesktopWorkspaceProps['onInspectDocument'];
|
||||
@@ -340,7 +347,7 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
||||
if (existing && existing.width === normalized.width && existing.height === normalized.height) {
|
||||
return;
|
||||
}
|
||||
const next = new Map(docSizeMapRef.current);
|
||||
const next = new Map<string, DocumentSizeInfo>(docSizeMapRef.current);
|
||||
next.set(docKey, { ...normalized, source: 'snapshot' });
|
||||
docSizeMapRef.current = next;
|
||||
setDocSizeVersion((value) => value + 1);
|
||||
@@ -505,7 +512,7 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
const current = docSizeMapRef.current;
|
||||
const next = new Map(current);
|
||||
const next = new Map<string, DocumentSizeInfo>(current);
|
||||
const itemKeys = new Set(items.filter((doc) => doc?.id != null).map((doc) => String(doc.id)));
|
||||
let changed = false;
|
||||
|
||||
@@ -618,7 +625,7 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
||||
}, [draggingId, items, setDraggingId]);
|
||||
|
||||
const openOverlayForDoc = useCallback(
|
||||
(docId: Identifier | null | undefined, originInfo: OverlayOriginTransform | null = null) => {
|
||||
(docId: Identifier | null | undefined, originInfo: OverlayOriginHint | null = null) => {
|
||||
if (!docId) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,8 +126,6 @@ const createDesktopSurface = ({
|
||||
title,
|
||||
subtitle,
|
||||
sidebarToggle,
|
||||
parentBreadcrumb,
|
||||
onNavigateParent,
|
||||
actions,
|
||||
breadcrumbs: workspaceProps?.breadcrumbs || null,
|
||||
selectionLabel: null,
|
||||
|
||||
@@ -21,8 +21,11 @@ export const preventAll = (event?: PreventableEvent | null): void => {
|
||||
|
||||
type AnyFn = (...args: unknown[]) => unknown;
|
||||
|
||||
export const safeInvoke = <Fn extends AnyFn>(fn: Fn | null | undefined, ...args: Parameters<Fn>): ReturnType<Fn> | undefined =>
|
||||
(fn ? fn(...args) : undefined);
|
||||
export const safeInvoke = <Fn extends AnyFn>(
|
||||
fn: Fn | null | undefined,
|
||||
...args: Parameters<Fn>
|
||||
): ReturnType<Fn> | undefined =>
|
||||
(fn ? (fn(...args) as ReturnType<Fn>) : undefined);
|
||||
|
||||
export const getPointerPosition = (
|
||||
event?: PointerLikeEvent | null,
|
||||
|
||||
@@ -65,8 +65,8 @@ export const createPointerIntent = ({
|
||||
const alreadySelected = selectedDocumentIds.includes(doc.id);
|
||||
const selectionCount = Array.isArray(selectedDocumentIds) ? selectedDocumentIds.length : 0;
|
||||
|
||||
let clickAction = CLICK_ACTIONS.none;
|
||||
let dragAction = DRAG_ACTIONS.none;
|
||||
let clickAction: ClickAction = CLICK_ACTIONS.none;
|
||||
let dragAction: DragAction = DRAG_ACTIONS.none;
|
||||
|
||||
if (metaKey) {
|
||||
clickAction = CLICK_ACTIONS.addStack;
|
||||
@@ -79,8 +79,8 @@ export const createPointerIntent = ({
|
||||
dragAction = DRAG_ACTIONS.dragSelectSingle;
|
||||
}
|
||||
|
||||
const stackList = Array.isArray(stackHits) && stackHits.length > 0
|
||||
? stackHits.slice()
|
||||
const stackList: string[] = Array.isArray(stackHits) && stackHits.length > 0
|
||||
? stackHits.map((value) => String(value))
|
||||
: [String(doc.id)];
|
||||
|
||||
const stackDocIdsForDrag = dragAction === DRAG_ACTIONS.dragSelectStack ? stackList : null;
|
||||
@@ -160,9 +160,9 @@ export const applyLongPressSelection = ({ intent, stackDocIds, syntheticEvent, o
|
||||
return;
|
||||
}
|
||||
|
||||
const stackCopy = Array.isArray(stackDocIds) && stackDocIds.length > 0
|
||||
? stackDocIds.slice()
|
||||
: [intent.docId];
|
||||
const stackCopy: string[] = Array.isArray(stackDocIds) && stackDocIds.length > 0
|
||||
? stackDocIds.map((value) => String(value))
|
||||
: [String(intent.docId)];
|
||||
|
||||
safeInvoke(onDocumentStackSelect, stackCopy, syntheticEvent, { replace: true });
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ interface DragGroupItemInternal extends EngineGroupItem {
|
||||
offsetX?: number;
|
||||
offsetY?: number;
|
||||
targetRotation?: number;
|
||||
initialRotation?: number;
|
||||
}
|
||||
|
||||
type EnsureDocumentSizeFn = (doc: DocumentLike | null | undefined) => DocumentSizeInfo | null;
|
||||
@@ -466,9 +467,9 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
|
||||
baseOffsetY,
|
||||
offsetX: baseOffsetX,
|
||||
offsetY: baseOffsetY,
|
||||
initialRotation,
|
||||
targetRotation: initialRotation,
|
||||
displayRotation: initialRotation,
|
||||
targetRotation,
|
||||
|
||||
} satisfies DragGroupItemInternal;
|
||||
});
|
||||
|
||||
@@ -897,6 +898,7 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
|
||||
if (state.moved) {
|
||||
commitActiveDragTransforms([state.docKey]);
|
||||
const inertiaState: EngineInertiaState = {
|
||||
docId: state.docKey,
|
||||
restRotation: state.restRotation,
|
||||
dynamicRotation: state.dynamicRotation,
|
||||
angularVelocity: state.angularVelocity,
|
||||
@@ -904,6 +906,7 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
|
||||
width: state.width,
|
||||
height: state.height,
|
||||
dragScale: state.dragScale || 1,
|
||||
lastTimestamp: state.lastTimestamp,
|
||||
};
|
||||
const docId = state.docKey;
|
||||
finishDrag(event.pointerId);
|
||||
@@ -956,6 +959,7 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
|
||||
|
||||
commitActiveDragTransforms([state.docKey]);
|
||||
const inertiaState: EngineInertiaState = {
|
||||
docId: state.docKey,
|
||||
restRotation: state.restRotation,
|
||||
dynamicRotation: state.dynamicRotation,
|
||||
angularVelocity: state.angularVelocity,
|
||||
@@ -963,6 +967,7 @@ const useDocumentDrag = (options: UseDocumentDragOptions) => {
|
||||
width: state.width,
|
||||
height: state.height,
|
||||
dragScale: state.dragScale || 1,
|
||||
lastTimestamp: state.lastTimestamp,
|
||||
};
|
||||
const docId = state.docKey;
|
||||
finishDrag(event.pointerId);
|
||||
|
||||
Reference in New Issue
Block a user