diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js
index fb5b9f6c54..5aecd4aff7 100644
--- a/packages/builder/src/builderStore/store/frontend.js
+++ b/packages/builder/src/builderStore/store/frontend.js
@@ -895,13 +895,21 @@ export const getFrontendStore = () => {
component[name] = value
})
},
- ejectBlock: async (id, definition) => {
- // const asset = get(currentAsset)
- // let parent = findComponentParent(asset.props, id)
- // const childIndex = parent._children.findIndex(x => x._id === id)
- // parent._children[childIndex] = definition
- // await store.actions.preview.saveSelected()
- // await store.actions.components.select(definition)
+ ejectBlock: async (componentId, ejectedDefinition) => {
+ await store.actions.screens.patch(screen => {
+ const parent = findComponentParent(screen.props, componentId)
+
+ // Sanity check parent is found
+ if (!parent?._children?.length) {
+ return false
+ }
+
+ // Replace block with ejected definition
+ const childIndex = parent._children.findIndex(
+ child => child._id === componentId
+ )
+ parent._children[childIndex] = ejectedDefinition
+ })
},
},
links: {
diff --git a/packages/client/src/components/Block.svelte b/packages/client/src/components/Block.svelte
index 5605ebb711..10da66dc39 100644
--- a/packages/client/src/components/Block.svelte
+++ b/packages/client/src/components/Block.svelte
@@ -6,6 +6,7 @@
const component = getContext("component")
let structureLookupMap = {}
+
const registerBlockComponent = (id, order, parentId, instance) => {
// Ensure child array exists
if (!structureLookupMap[parentId]) {
@@ -13,7 +14,7 @@
}
// Remove existing instance of this component in case props changed
structureLookupMap[parentId] = structureLookupMap[parentId].filter(
- x => x.instance._id !== id
+ blockComponent => blockComponent.instance._id !== id
)
// Add new instance of this component
structureLookupMap[parentId].push({ order, instance })
diff --git a/packages/client/src/components/BlockComponent.svelte b/packages/client/src/components/BlockComponent.svelte
index 75ad7b57fe..7076aad514 100644
--- a/packages/client/src/components/BlockComponent.svelte
+++ b/packages/client/src/components/BlockComponent.svelte
@@ -1,6 +1,7 @@