@@ -3,8 +3,8 @@ import { get as getFromStore } from "svelte/store";
33
44import { type Editor } from "@graphite/editor" ;
55import {
6- TriggerIndexedDbWriteDocument ,
7- TriggerIndexedDbRemoveDocument ,
6+ TriggerPersistenceWriteDocument ,
7+ TriggerPersistenceRemoveDocument ,
88 TriggerSavePreferences ,
99 TriggerLoadPreferences ,
1010 TriggerLoadFirstAutoSaveDocument ,
@@ -27,23 +27,23 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
2727 await set ( "current_document_id" , String ( documentId ) , graphiteStore ) ;
2828 }
2929
30- async function storeDocument ( autoSaveDocument : TriggerIndexedDbWriteDocument ) {
31- await update < Record < string , TriggerIndexedDbWriteDocument > > (
30+ async function storeDocument ( autoSaveDocument : TriggerPersistenceWriteDocument ) {
31+ await update < Record < string , TriggerPersistenceWriteDocument > > (
3232 "documents" ,
3333 ( old ) => {
3434 const documents = old || { } ;
35- documents [ autoSaveDocument . details . id ] = autoSaveDocument ;
35+ documents [ autoSaveDocument . documentId ] = autoSaveDocument ;
3636 return documents ;
3737 } ,
3838 graphiteStore ,
3939 ) ;
4040
4141 await storeDocumentOrder ( ) ;
42- await storeCurrentDocumentId ( autoSaveDocument . details . id ) ;
42+ await storeCurrentDocumentId ( autoSaveDocument . documentId ) ;
4343 }
4444
4545 async function removeDocument ( id : string ) {
46- await update < Record < string , TriggerIndexedDbWriteDocument > > (
46+ await update < Record < string , TriggerPersistenceWriteDocument > > (
4747 "documents" ,
4848 ( old ) => {
4949 const documents = old || { } ;
@@ -77,7 +77,7 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
7777 }
7878
7979 async function loadFirstDocument ( ) {
80- const previouslySavedDocuments = await get < Record < string , TriggerIndexedDbWriteDocument > > ( "documents" , graphiteStore ) ;
80+ const previouslySavedDocuments = await get < Record < string , TriggerPersistenceWriteDocument > > ( "documents" , graphiteStore ) ;
8181 const documentOrder = await get < string [ ] > ( "documents_tab_order" , graphiteStore ) ;
8282 const currentDocumentId = await get < string > ( "current_document_id" , graphiteStore ) ;
8383 if ( ! previouslySavedDocuments || ! documentOrder ) return ;
@@ -86,54 +86,54 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
8686
8787 if ( currentDocumentId && currentDocumentId in previouslySavedDocuments ) {
8888 const doc = previouslySavedDocuments [ currentDocumentId ] ;
89- editor . handle . openAutoSavedDocument ( BigInt ( doc . details . id ) , doc . details . name , doc . details . isSaved , doc . document , false ) ;
89+ editor . handle . openAutoSavedDocument ( BigInt ( doc . documentId ) , doc . details . name , doc . details . isSaved , doc . document , false ) ;
9090 editor . handle . selectDocument ( BigInt ( currentDocumentId ) ) ;
9191 } else {
9292 const len = orderedSavedDocuments . length ;
9393 if ( len > 0 ) {
9494 const doc = orderedSavedDocuments [ len - 1 ] ;
95- editor . handle . openAutoSavedDocument ( BigInt ( doc . details . id ) , doc . details . name , doc . details . isSaved , doc . document , false ) ;
96- editor . handle . selectDocument ( BigInt ( doc . details . id ) ) ;
95+ editor . handle . openAutoSavedDocument ( BigInt ( doc . documentId ) , doc . details . name , doc . details . isSaved , doc . document , false ) ;
96+ editor . handle . selectDocument ( BigInt ( doc . documentId ) ) ;
9797 }
9898 }
9999 }
100100
101101 async function loadRestDocuments ( ) {
102- const previouslySavedDocuments = await get < Record < string , TriggerIndexedDbWriteDocument > > ( "documents" , graphiteStore ) ;
102+ const previouslySavedDocuments = await get < Record < string , TriggerPersistenceWriteDocument > > ( "documents" , graphiteStore ) ;
103103 const documentOrder = await get < string [ ] > ( "documents_tab_order" , graphiteStore ) ;
104104 const currentDocumentId = await get < string > ( "current_document_id" , graphiteStore ) ;
105105 if ( ! previouslySavedDocuments || ! documentOrder ) return ;
106106
107107 const orderedSavedDocuments = documentOrder . flatMap ( ( id ) => ( previouslySavedDocuments [ id ] ? [ previouslySavedDocuments [ id ] ] : [ ] ) ) ;
108108
109109 if ( currentDocumentId ) {
110- const currentIndex = orderedSavedDocuments . findIndex ( ( doc ) => doc . details . id === currentDocumentId ) ;
110+ const currentIndex = orderedSavedDocuments . findIndex ( ( doc ) => doc . documentId === currentDocumentId ) ;
111111 const beforeCurrentIndex = currentIndex - 1 ;
112112 const afterCurrentIndex = currentIndex + 1 ;
113113
114114 for ( let i = beforeCurrentIndex ; i >= 0 ; i -- ) {
115- const { document, details } = orderedSavedDocuments [ i ] ;
116- const { id , name, isSaved } = details ;
117- editor . handle . openAutoSavedDocument ( BigInt ( id ) , name , isSaved , document , true ) ;
115+ const { documentId , document, details } = orderedSavedDocuments [ i ] ;
116+ const { name, isSaved } = details ;
117+ editor . handle . openAutoSavedDocument ( BigInt ( documentId ) , name , isSaved , document , true ) ;
118118 }
119119 for ( let i = afterCurrentIndex ; i < orderedSavedDocuments . length ; i ++ ) {
120- const { document, details } = orderedSavedDocuments [ i ] ;
121- const { id , name, isSaved } = details ;
122- editor . handle . openAutoSavedDocument ( BigInt ( id ) , name , isSaved , document , false ) ;
120+ const { documentId , document, details } = orderedSavedDocuments [ i ] ;
121+ const { name, isSaved } = details ;
122+ editor . handle . openAutoSavedDocument ( BigInt ( documentId ) , name , isSaved , document , false ) ;
123123 }
124124
125125 editor . handle . selectDocument ( BigInt ( currentDocumentId ) ) ;
126126 } else {
127127 const length = orderedSavedDocuments . length ;
128128
129129 for ( let i = length - 2 ; i >= 0 ; i -- ) {
130- const { document, details } = orderedSavedDocuments [ i ] ;
131- const { id , name, isSaved } = details ;
132- editor . handle . openAutoSavedDocument ( BigInt ( id ) , name , isSaved , document , true ) ;
130+ const { documentId , document, details } = orderedSavedDocuments [ i ] ;
131+ const { name, isSaved } = details ;
132+ editor . handle . openAutoSavedDocument ( BigInt ( documentId ) , name , isSaved , document , true ) ;
133133 }
134134
135135 if ( length > 0 ) {
136- const id = orderedSavedDocuments [ length - 1 ] . details . id ;
136+ const id = orderedSavedDocuments [ length - 1 ] . documentId ;
137137 editor . handle . selectDocument ( BigInt ( id ) ) ;
138138 }
139139 }
@@ -161,10 +161,10 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
161161 editor . subscriptions . subscribeJsMessage ( TriggerLoadPreferences , async ( ) => {
162162 await loadPreferences ( ) ;
163163 } ) ;
164- editor . subscriptions . subscribeJsMessage ( TriggerIndexedDbWriteDocument , async ( autoSaveDocument ) => {
164+ editor . subscriptions . subscribeJsMessage ( TriggerPersistenceWriteDocument , async ( autoSaveDocument ) => {
165165 await storeDocument ( autoSaveDocument ) ;
166166 } ) ;
167- editor . subscriptions . subscribeJsMessage ( TriggerIndexedDbRemoveDocument , async ( removeAutoSaveDocument ) => {
167+ editor . subscriptions . subscribeJsMessage ( TriggerPersistenceRemoveDocument , async ( removeAutoSaveDocument ) => {
168168 await removeDocument ( removeAutoSaveDocument . documentId ) ;
169169 } ) ;
170170 editor . subscriptions . subscribeJsMessage ( TriggerLoadFirstAutoSaveDocument , async ( ) => {
@@ -175,7 +175,7 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
175175 } ) ;
176176 editor . subscriptions . subscribeJsMessage ( TriggerSaveActiveDocument , async ( triggerSaveActiveDocument ) => {
177177 const documentId = String ( triggerSaveActiveDocument . documentId ) ;
178- const previouslySavedDocuments = await get < Record < string , TriggerIndexedDbWriteDocument > > ( "documents" , graphiteStore ) ;
178+ const previouslySavedDocuments = await get < Record < string , TriggerPersistenceWriteDocument > > ( "documents" , graphiteStore ) ;
179179 if ( ! previouslySavedDocuments ) return ;
180180 if ( documentId in previouslySavedDocuments ) {
181181 await storeCurrentDocumentId ( documentId ) ;
0 commit comments