diff --git a/package-lock.json b/package-lock.json index 22356906b..035370d89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bridge", - "version": "2.7.26", + "version": "2.7.28", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bridge", - "version": "2.7.26", + "version": "2.7.28", "dependencies": { "@bridge-editor/dash-compiler": "^0.11.4", "@bridge-editor/js-runtime": "^0.4.4", diff --git a/package.json b/package.json index aab0d8a16..868e90ec1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bridge", - "version": "2.7.27", + "version": "2.7.28", "private": true, "scripts": { "dev": "vite", diff --git a/src/components/Extensions/Scripts/Modules/fs.ts b/src/components/Extensions/Scripts/Modules/fs.ts index 8b75cdb80..8e360f939 100644 --- a/src/components/Extensions/Scripts/Modules/fs.ts +++ b/src/components/Extensions/Scripts/Modules/fs.ts @@ -1,6 +1,16 @@ import { App } from '/@/App' import { FileSystem } from '/@/components/FileSystem/FileSystem' import { IModuleConfig } from '../types' +import { + AnyDirectoryHandle, + AnyFileHandle, +} from '/@/components/FileSystem/Types' +import { VirtualFileHandle } from '/@/components/FileSystem/Virtual/FileHandle' +import { VirtualDirectoryHandle } from '/@/components/FileSystem/Virtual/DirectoryHandle' +import { + ISerializedDirectoryHandle, + ISerializedFileHandle, +} from '/@/components/FileSystem/Virtual/Comlink' export const FSModule = ({ disposables }: IModuleConfig) => { return new Promise((resolve) => { @@ -9,6 +19,33 @@ export const FSModule = ({ disposables }: IModuleConfig) => { onBridgeFolderSetup: (cb: () => Promise | void) => { disposables.push(app.bridgeFolderSetup.once(cb, true)) }, + serializeHandle(handle: AnyFileHandle | AnyDirectoryHandle) { + if ( + handle instanceof VirtualFileHandle || + handle instanceof VirtualDirectoryHandle + ) { + return handle.serialize() + } + + return handle + }, + deserializeHandle( + serializedHandle: + | FileSystemHandle + | ISerializedFileHandle + | ISerializedDirectoryHandle + ) { + if (serializedHandle instanceof FileSystemHandle) + return serializedHandle + + if (serializedHandle.kind === 'directory') { + return VirtualDirectoryHandle.deserialize( + serializedHandle + ) + } else { + return VirtualFileHandle.deserialize(serializedHandle) + } + }, } // Extensions will destructure the fileSystem instance diff --git a/src/components/FileSystem/Virtual/IDB.ts b/src/components/FileSystem/Virtual/IDB.ts index 615be6763..2f89bd79b 100644 --- a/src/components/FileSystem/Virtual/IDB.ts +++ b/src/components/FileSystem/Virtual/IDB.ts @@ -48,7 +48,7 @@ export class IDBWrapper { return clearRaw(this.store) } async has(key: IDBValidKey) { - return (await get(key)) !== undefined + return (await rawGet(key, this.store)) !== undefined } keys() { return rawKeys(this.store) diff --git a/src/components/FileSystem/Virtual/Stores/Memory.ts b/src/components/FileSystem/Virtual/Stores/Memory.ts index 4a5c78290..8f444f69d 100644 --- a/src/components/FileSystem/Virtual/Stores/Memory.ts +++ b/src/components/FileSystem/Virtual/Stores/Memory.ts @@ -56,6 +56,8 @@ export class MemoryDb extends IDBWrapper { } export class MemoryStore extends IndexedDbStore { + //@ts-ignore + public readonly type = 'memoryStore' protected idb: MemoryDb constructor(storeName?: string, mapData?: [IDBValidKey, any][]) { @@ -63,6 +65,7 @@ export class MemoryStore extends IndexedDbStore { this.idb = new MemoryDb(storeName, mapData) } + //@ts-ignore serialize() { return { type: this.type,