fix(editor): strip placement metadata on commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import { stripTransient } from './placement-math'
|
||||
|
||||
describe('stripTransient', () => {
|
||||
test('removes placement-only metadata flags before commit', () => {
|
||||
expect(stripTransient({ isNew: true, isTransient: true, label: 'copy' })).toEqual({
|
||||
label: 'copy',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -111,13 +111,13 @@ export function isValidWallSideFace(normal: [number, number, number] | undefined
|
||||
return Math.abs(normal[2]) > 0.7
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the `isTransient` flag from node metadata before committing.
|
||||
*/
|
||||
/** Strip placement-only metadata flags before committing a draft. */
|
||||
export function stripTransient(meta: any): any {
|
||||
if (!isObject(meta)) return meta
|
||||
const { isTransient, ...rest } = meta as Record<string, any>
|
||||
return rest
|
||||
const nextMeta = { ...(meta as Record<string, any>) }
|
||||
delete nextMeta.isNew
|
||||
delete nextMeta.isTransient
|
||||
return nextMeta
|
||||
}
|
||||
|
||||
const _up = new Vector3(0, 1, 0)
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
EDITOR_LAYER,
|
||||
getSideFromNormal,
|
||||
isValidWallSideFace,
|
||||
stripPlacementMetadataFlags,
|
||||
triggerSFX,
|
||||
useEditor,
|
||||
} from '@pascal-app/editor'
|
||||
@@ -275,6 +276,7 @@ const MoveDoorTool: React.FC<{ node: DoorNode }> = ({ node: movingDoorNode }) =>
|
||||
|
||||
const cloned = structuredClone(movingDoorNode) as any
|
||||
delete cloned.id
|
||||
cloned.metadata = stripPlacementMetadataFlags(cloned.metadata)
|
||||
const node = DoorNode.parse({
|
||||
...cloned,
|
||||
position: [target.clampedX, target.clampedY, 0],
|
||||
|
||||
Reference in New Issue
Block a user