mostly formatting, dependency fix
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import type { PageRef } from "../pdf/pdfTypes";
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import type { PageRef } from '../pdf/pdfTypes';
|
||||
import type {
|
||||
WorkspaceCommand,
|
||||
WorkspaceCommandRecord,
|
||||
WorkspaceCommandState,
|
||||
} from "./workspaceCommands";
|
||||
} from './workspaceCommands';
|
||||
import {
|
||||
createSnapshotCommand,
|
||||
reviveWorkspaceCommand,
|
||||
toWorkspaceCommandRecord,
|
||||
} from "./workspaceCommands";
|
||||
} from './workspaceCommands';
|
||||
|
||||
function createId(prefix: string): string {
|
||||
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function createId(prefix: string): string {
|
||||
}
|
||||
|
||||
export function createWorkspaceId(): string {
|
||||
return createId("workspace");
|
||||
return createId('workspace');
|
||||
}
|
||||
|
||||
export function createPdfId(): string {
|
||||
@@ -28,11 +28,11 @@ export function createPdfId(): string {
|
||||
}
|
||||
|
||||
export function defaultWorkspaceNameFromPdfName(pdfName: string): string {
|
||||
return pdfName.replace(/\.pdf$/i, "") || "Untitled workspace";
|
||||
return pdfName.replace(/\.pdf$/i, '') || 'Untitled workspace';
|
||||
}
|
||||
|
||||
export function createPageRefId(): string {
|
||||
return createId("page");
|
||||
return createId('page');
|
||||
}
|
||||
|
||||
export function createInitialPageRefs(pageCount: number): PageRef[] {
|
||||
@@ -84,7 +84,7 @@ export function useWorkspaceState({
|
||||
|
||||
const setPages = useCallback((action: SetStateAction<PageRef[]>) => {
|
||||
setPagesState((previous) => {
|
||||
const next = typeof action === "function" ? action(previous) : action;
|
||||
const next = typeof action === 'function' ? action(previous) : action;
|
||||
latestPagesRef.current = next;
|
||||
return next;
|
||||
});
|
||||
@@ -92,7 +92,7 @@ export function useWorkspaceState({
|
||||
|
||||
const setSelectedPageIds = useCallback((action: SetStateAction<string[]>) => {
|
||||
setSelectedPageIdsState((previous) => {
|
||||
const next = typeof action === "function" ? action(previous) : action;
|
||||
const next = typeof action === 'function' ? action(previous) : action;
|
||||
selectedPageIdsRef.current = next;
|
||||
return next;
|
||||
});
|
||||
@@ -101,12 +101,12 @@ export function useWorkspaceState({
|
||||
const setLastSelectedVisualIndex = useCallback(
|
||||
(action: SetStateAction<number | null>) => {
|
||||
setLastSelectedVisualIndexState((previous) => {
|
||||
const next = typeof action === "function" ? action(previous) : action;
|
||||
const next = typeof action === 'function' ? action(previous) : action;
|
||||
lastSelectedVisualIndexRef.current = next;
|
||||
return next;
|
||||
});
|
||||
},
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
const getCurrentCommandState = useCallback(
|
||||
@@ -115,7 +115,7 @@ export function useWorkspaceState({
|
||||
selectedPageIds: selectedPageIdsRef.current,
|
||||
lastSelectedVisualIndex: lastSelectedVisualIndexRef.current,
|
||||
}),
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
const applyCommandState = useCallback(
|
||||
@@ -124,7 +124,7 @@ export function useWorkspaceState({
|
||||
setSelectedPageIds(state.selectedPageIds);
|
||||
setLastSelectedVisualIndex(state.lastSelectedVisualIndex);
|
||||
},
|
||||
[setLastSelectedVisualIndex, setPages, setSelectedPageIds],
|
||||
[setLastSelectedVisualIndex, setPages, setSelectedPageIds]
|
||||
);
|
||||
|
||||
const markWorkspaceChanged = useCallback(() => {
|
||||
@@ -142,14 +142,14 @@ export function useWorkspaceState({
|
||||
details?: Record<string, unknown>;
|
||||
}): WorkspaceCommand =>
|
||||
createSnapshotCommand({
|
||||
id: createId("command"),
|
||||
id: createId('command'),
|
||||
type: params.type,
|
||||
label: params.label,
|
||||
before: params.before,
|
||||
after: params.after,
|
||||
details: params.details,
|
||||
}),
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
const executeWorkspaceCommand = useCallback(
|
||||
@@ -164,7 +164,7 @@ export function useWorkspaceState({
|
||||
setRedoHistory([]);
|
||||
markWorkspaceChanged();
|
||||
},
|
||||
[applyCommandState, getCurrentCommandState, markWorkspaceChanged],
|
||||
[applyCommandState, getCurrentCommandState, markWorkspaceChanged]
|
||||
);
|
||||
|
||||
const handleUndo = useCallback(() => {
|
||||
@@ -213,7 +213,7 @@ export function useWorkspaceState({
|
||||
setWorkspaceDirty(state.dirty ?? false);
|
||||
setWorkspaceMessage(state.message ?? null);
|
||||
},
|
||||
[setLastSelectedVisualIndex, setPages, setSelectedPageIds],
|
||||
[setLastSelectedVisualIndex, setPages, setSelectedPageIds]
|
||||
);
|
||||
|
||||
const resetWorkspaceState = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user