Syncing ephemeral element updates

This commit is contained in:
Marcel Mraz 2025-01-20 15:07:37 +01:00
parent c57249481e
commit 310a9ae4e0
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
60 changed files with 1104 additions and 906 deletions

View file

@ -1,4 +1,4 @@
import { StoreAction } from "../../packages/excalidraw";
import { SnapshotAction } from "../../packages/excalidraw";
import { compressData } from "../../packages/excalidraw/data/encode";
import { newElementWith } from "../../packages/excalidraw/element/mutateElement";
import { isInitializedImageElement } from "../../packages/excalidraw/element/typeChecks";
@ -268,6 +268,6 @@ export const updateStaleImageStatuses = (params: {
}
return element;
}),
storeAction: StoreAction.UPDATE,
snapshotAction: SnapshotAction.UPDATE,
});
};

View file

@ -45,7 +45,7 @@ import { SAVE_TO_LOCAL_STORAGE_TIMEOUT, STORAGE_KEYS } from "../app_constants";
import { FileManager } from "./FileManager";
import { Locker } from "./Locker";
import { updateBrowserStateVersion } from "./tabSync";
import { StoreIncrement } from "../../packages/excalidraw/store";
import { StoreDelta } from "../../packages/excalidraw/store";
const filesStore = createStore("files-db", "files-store");
@ -260,7 +260,7 @@ export class LibraryLocalStorageMigrationAdapter {
}
}
type SyncIncrementPersistedData = DTO<StoreIncrement>[];
type SyncDeltaPersistedData = DTO<StoreDelta>[];
type SyncMetaPersistedData = {
lastAcknowledgedVersion: number;
@ -270,7 +270,7 @@ export class SyncIndexedDBAdapter {
/** IndexedDB database and store name */
private static idb_name = STORAGE_KEYS.IDB_SYNC;
/** library data store keys */
private static incrementsKey = "increments";
private static deltasKey = "deltas";
private static metadataKey = "metadata";
private static store = createStore(
@ -278,24 +278,22 @@ export class SyncIndexedDBAdapter {
`${SyncIndexedDBAdapter.idb_name}-store`,
);
static async loadIncrements() {
const increments = await get<SyncIncrementPersistedData>(
SyncIndexedDBAdapter.incrementsKey,
static async loadDeltas() {
const deltas = await get<SyncDeltaPersistedData>(
SyncIndexedDBAdapter.deltasKey,
SyncIndexedDBAdapter.store,
);
if (increments?.length) {
return increments.map((storeIncrementDTO) =>
StoreIncrement.restore(storeIncrementDTO),
);
if (deltas?.length) {
return deltas.map((storeDeltaDTO) => StoreDelta.restore(storeDeltaDTO));
}
return null;
}
static async saveIncrements(data: SyncIncrementPersistedData): Promise<void> {
static async saveDeltas(data: SyncDeltaPersistedData): Promise<void> {
return set(
SyncIndexedDBAdapter.incrementsKey,
SyncIndexedDBAdapter.deltasKey,
data,
SyncIndexedDBAdapter.store,
);