AI-native design editor. Open-source Figma alternative.
refactor(app): share document source access types
Danila Poyarkovc45e5e5cef01
diff --git a/src/app/document/io/save.ts b/src/app/document/io/save.tsindex 87cf0c9c9..f86af654c 100644--- a/src/app/document/io/save.ts+++ b/src/app/document/io/save.ts@@ -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: SaveDocumentStatebuildFigFile: () => 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) => voidstartWatchingFile: () => void}diff --git a/src/app/document/io/source.ts b/src/app/document/io/source.tsindex 40b3b1326..e296d8fd3 100644--- a/src/app/document/io/source.ts+++ b/src/app/document/io/source.ts@@ -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: Editorstate: DocumentSourceStatestopWatchingFile: () => voidstartWatchingFile: () => 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) => voidgetRenderer: () => Editor['renderer']}diff --git a/src/app/document/io/types.ts b/src/app/document/io/types.tsindex 48a9a92f5..f890dc649 100644--- a/src/app/document/io/types.ts+++ b/src/app/document/io/types.ts@@ -1,6 +1,23 @@+import type { StorageDocumentBinding } from '@/app/integrations/storage/types'+export type DocumentSourceIdentity = Readonly<{handle: FileSystemFileHandle | nullpath: 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 }