1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Reset grid position metadata when copying and pasting between screens

This commit is contained in:
Andrew Kingston 2024-08-15 09:54:47 +01:00
parent 0fc602dfc2
commit 6783f9b4ee
No known key found for this signature in database

View file

@ -619,6 +619,7 @@ export class ComponentStore extends BudiStore {
this.update(state => {
state.componentToPaste = cloneDeep(component)
state.componentToPaste.isCut = cut
state.componentToPaste.screenId = get(screenStore).selectedScreenId
return state
})
@ -677,8 +678,10 @@ export class ComponentStore extends BudiStore {
return false
}
const cut = componentToPaste.isCut
const sourceScreenId = componentToPaste.screenId
const originalId = componentToPaste._id
delete componentToPaste.isCut
delete componentToPaste.screenId
// Make new component unique if copying
if (!cut) {
@ -686,6 +689,19 @@ export class ComponentStore extends BudiStore {
}
newComponentId = componentToPaste._id
// Strip grid position metadata if pasting into a new screen, but keep
// alignment metadata
if (sourceScreenId && sourceScreenId !== screen._id) {
for (let style of Object.keys(componentToPaste._styles?.normal || {})) {
if (
style.startsWith("--grid") &&
(style.endsWith("-start") || style.endsWith("-end"))
) {
delete componentToPaste._styles.normal[style]
}
}
}
// Delete old component if cutting
if (cut) {
const parent = findComponentParent(screen.props, originalId)