update automerge

This commit is contained in:
Jeff Emmett 2025-11-10 14:44:13 -08:00
parent d2fd1c0fac
commit f250eb3145
2 changed files with 28 additions and 7 deletions

View File

@ -439,12 +439,30 @@ export function useAutomergeStoreV2({
if (!processedRecord.meta || typeof processedRecord.meta !== 'object') processedRecord.meta = {}
if (!processedRecord.index) processedRecord.index = 'a1'
if (!processedRecord.parentId) {
const pageRecord = records.find((r: any) => r.typeName === 'page') as any
// Find all page records
const pageRecords = records.filter((r: any) => r.typeName === 'page') as any[]
// Prefer 'page:page' if it exists, otherwise use the first page found
const pageRecord = pageRecords.find((p: any) => p.id === 'page:page') || pageRecords[0]
if (pageRecord && pageRecord.id) {
processedRecord.parentId = pageRecord.id
} else {
// Default to 'page:page' - TLDraw will create it if needed
processedRecord.parentId = 'page:page'
}
} else {
// Validate that the parentId points to an existing page
const parentPage = records.find((r: any) => r.typeName === 'page' && r.id === processedRecord.parentId)
if (!parentPage) {
// Parent page doesn't exist, assign to first available page or default
const pageRecords = records.filter((r: any) => r.typeName === 'page') as any[]
const pageRecord = pageRecords.find((p: any) => p.id === 'page:page') || pageRecords[0]
if (pageRecord && pageRecord.id) {
console.log(`🔧 Shape ${processedRecord.id} has invalid parentId ${processedRecord.parentId}, reassigning to ${pageRecord.id}`)
processedRecord.parentId = pageRecord.id
} else {
processedRecord.parentId = 'page:page'
}
}
}
if (!processedRecord.props || typeof processedRecord.props !== 'object') processedRecord.props = {}

View File

@ -131,17 +131,19 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
if (!recordToSave.id && recordAny.id) {
recordToSave.id = recordAny.id
}
if (!recordToSave.type && recordAny.type) {
recordToSave.type = recordAny.type
// Use bracket notation to avoid TypeScript errors on union types
if (!recordToSave.type && (recordAny as any).type) {
recordToSave.type = (recordAny as any).type
}
if (!recordToSave.props && recordAny.props) {
recordToSave.props = recordAny.props
if (!recordToSave.props && (recordAny as any).props) {
recordToSave.props = (recordAny as any).props
}
// Copy all enumerable properties that might have been lost
for (const prop in recordAny) {
if (!(prop in recordToSave)) {
try {
recordToSave[prop] = recordAny[prop]
// Use bracket notation with explicit any cast to avoid indexing errors
(recordToSave as any)[prop] = (recordAny as any)[prop]
} catch (e) {
// Skip properties that can't be accessed
}
@ -153,7 +155,8 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
recordToSave = {}
for (const prop in recordAny) {
try {
recordToSave[prop] = recordAny[prop]
// Use bracket notation with explicit any cast to avoid indexing errors
(recordToSave as any)[prop] = (recordAny as any)[prop]
} catch (e) {
// Skip properties that can't be accessed
}