refactor(app): share document source access types

- Reuse one named source-state contract across save and source actions

- Keep storage bindings and local source identity typed without duplicated shapes
This commit is contained in:
Danila Poyarkov 2026-07-26 15:09:26 +03:00
parent ca80b0e787
commit c45e5e5cef
3 changed files with 21 additions and 28 deletions

View file

@ -3,27 +3,15 @@ import type { EditorState } from '@open-pencil/core/editor'
import { downloadBlob } from '@/app/document/io/browser'
import { documentNameFromFigPath } from '@/app/document/io/names'
import { chooseBrowserFigSaveHandle, chooseTauriFigSavePath } from '@/app/document/io/save-targets'
import type { DocumentSourceIdentity } from '@/app/document/io/types'
import type { DocumentSourceAccess } from '@/app/document/io/types'
import { createDocumentWriter } from '@/app/document/io/write'
import type { StorageDocumentBinding } from '@/app/integrations/storage/types'
import { IS_TAURI } from '@/constants'
type SaveDocumentState = EditorState & { documentName: string }
type SaveActionsOptions = {
type SaveActionsOptions = Omit<DocumentSourceAccess, 'getSavedVersion'> & {
state: SaveDocumentState
buildFigFile: () => Uint8Array | Promise<Uint8Array>
getFilePath: () => string | null
setFilePath: (path: string | null) => void
getFileHandle: () => FileSystemFileHandle | null
setFileHandle: (handle: FileSystemFileHandle | null) => void
getDownloadName: () => string | null
setDownloadName: (name: string | null) => void
getStorageBinding: () => StorageDocumentBinding | null
setStorageBinding: (binding: StorageDocumentBinding | null) => void
setSourceIdentity: (identity: DocumentSourceIdentity) => void
setSavedVersion: (version: number) => void
setLastWriteTime: (time: number) => void
startWatchingFile: () => void
}

View file

@ -9,7 +9,7 @@ import {
} from '@/app/document/io/names'
import { createSaveActions } from '@/app/document/io/save'
import { createDocumentSourceState } from '@/app/document/io/source-state'
import type { DocumentSourceIdentity } from '@/app/document/io/types'
import type { DocumentSourceAccess } from '@/app/document/io/types'
import type { StorageDocumentBinding } from '@/app/integrations/storage/types'
type DocumentSourceState = EditorState & {
@ -19,23 +19,11 @@ type DocumentSourceState = EditorState & {
export { createDocumentSourceState }
type DocumentSourceOptions = {
type DocumentSourceOptions = DocumentSourceAccess & {
editor: Editor
state: DocumentSourceState
stopWatchingFile: () => void
startWatchingFile: () => Promise<void>
getFileHandle: () => FileSystemFileHandle | null
setFileHandle: (handle: FileSystemFileHandle | null) => void
getFilePath: () => string | null
setFilePath: (path: string | null) => void
getDownloadName: () => string | null
setDownloadName: (name: string | null) => void
getStorageBinding: () => StorageDocumentBinding | null
setStorageBinding: (binding: StorageDocumentBinding | null) => void
setSourceIdentity: (identity: DocumentSourceIdentity) => void
getSavedVersion: () => number
setSavedVersion: (version: number) => void
setLastWriteTime: (time: number) => void
getRenderer: () => Editor['renderer']
}

View file

@ -1,6 +1,23 @@
import type { StorageDocumentBinding } from '@/app/integrations/storage/types'
export type DocumentSourceIdentity = Readonly<{
handle: FileSystemFileHandle | null
path: string | null
}>
export type DocumentSourceAccess = {
getFileHandle: () => FileSystemFileHandle | null
setFileHandle: (handle: FileSystemFileHandle | null) => void
getFilePath: () => string | null
setFilePath: (path: string | null) => void
getDownloadName: () => string | null
setDownloadName: (name: string | null) => void
getStorageBinding: () => StorageDocumentBinding | null
setStorageBinding: (binding: StorageDocumentBinding | null) => void
setSourceIdentity: (identity: DocumentSourceIdentity) => void
getSavedVersion: () => number
setSavedVersion: (version: number) => void
setLastWriteTime: (time: number) => void
}
export type ViewportSize = { width: number; height: number }