update x & y coordinates
This commit is contained in:
parent
c1df50c49b
commit
1b172d7529
|
|
@ -99,6 +99,17 @@ export function applyAutomergePatchesToTLStore(
|
||||||
|
|
||||||
let record = updatedObjects[id] || (existingRecord ? JSON.parse(JSON.stringify(existingRecord)) : defaultRecord)
|
let record = updatedObjects[id] || (existingRecord ? JSON.parse(JSON.stringify(existingRecord)) : defaultRecord)
|
||||||
|
|
||||||
|
// CRITICAL: For shapes, ensure x and y are always present (even if record came from updatedObjects)
|
||||||
|
// This prevents coordinates from being lost when records are created from patches
|
||||||
|
if (record.typeName === 'shape') {
|
||||||
|
if (typeof record.x !== 'number' || record.x === null || isNaN(record.x)) {
|
||||||
|
record = { ...record, x: defaultRecord.x || 0 }
|
||||||
|
}
|
||||||
|
if (typeof record.y !== 'number' || record.y === null || isNaN(record.y)) {
|
||||||
|
record = { ...record, y: defaultRecord.y || 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CRITICAL: Ensure typeName matches ID pattern (fixes misclassification)
|
// CRITICAL: Ensure typeName matches ID pattern (fixes misclassification)
|
||||||
// Note: obsidian_vault records are skipped above, so we don't need to handle them here
|
// Note: obsidian_vault records are skipped above, so we don't need to handle them here
|
||||||
if (typeof id === 'string') {
|
if (typeof id === 'string') {
|
||||||
|
|
@ -328,8 +339,9 @@ export function sanitizeRecord(record: any): TLRecord {
|
||||||
// For shapes, only ensure basic required fields exist
|
// For shapes, only ensure basic required fields exist
|
||||||
if (sanitized.typeName === 'shape') {
|
if (sanitized.typeName === 'shape') {
|
||||||
// Ensure required shape fields exist
|
// Ensure required shape fields exist
|
||||||
if (typeof sanitized.x !== 'number') sanitized.x = 0
|
// CRITICAL: Check for non-number, null, undefined, or NaN values
|
||||||
if (typeof sanitized.y !== 'number') sanitized.y = 0
|
if (typeof sanitized.x !== 'number' || sanitized.x === null || isNaN(sanitized.x)) sanitized.x = 0
|
||||||
|
if (typeof sanitized.y !== 'number' || sanitized.y === null || isNaN(sanitized.y)) sanitized.y = 0
|
||||||
if (typeof sanitized.rotation !== 'number') sanitized.rotation = 0
|
if (typeof sanitized.rotation !== 'number') sanitized.rotation = 0
|
||||||
if (typeof sanitized.isLocked !== 'boolean') sanitized.isLocked = false
|
if (typeof sanitized.isLocked !== 'boolean') sanitized.isLocked = false
|
||||||
if (typeof sanitized.opacity !== 'number') sanitized.opacity = 1
|
if (typeof sanitized.opacity !== 'number') sanitized.opacity = 1
|
||||||
|
|
|
||||||
|
|
@ -1069,11 +1069,12 @@ export class AutomergeDurableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure other required shape properties exist
|
// Ensure other required shape properties exist
|
||||||
if (record.x === undefined) {
|
// CRITICAL: Check for undefined, null, or non-number values (including NaN)
|
||||||
|
if (record.x === undefined || record.x === null || typeof record.x !== 'number' || isNaN(record.x)) {
|
||||||
record.x = 0
|
record.x = 0
|
||||||
needsUpdate = true
|
needsUpdate = true
|
||||||
}
|
}
|
||||||
if (record.y === undefined) {
|
if (record.y === undefined || record.y === null || typeof record.y !== 'number' || isNaN(record.y)) {
|
||||||
record.y = 0
|
record.y = 0
|
||||||
needsUpdate = true
|
needsUpdate = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue