Update block ejection with latest codebase
This commit is contained in:
parent
66fc18566a
commit
25454bff9d
|
@ -895,13 +895,21 @@ export const getFrontendStore = () => {
|
||||||
component[name] = value
|
component[name] = value
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
ejectBlock: async (id, definition) => {
|
ejectBlock: async (componentId, ejectedDefinition) => {
|
||||||
// const asset = get(currentAsset)
|
await store.actions.screens.patch(screen => {
|
||||||
// let parent = findComponentParent(asset.props, id)
|
const parent = findComponentParent(screen.props, componentId)
|
||||||
// const childIndex = parent._children.findIndex(x => x._id === id)
|
|
||||||
// parent._children[childIndex] = definition
|
// Sanity check parent is found
|
||||||
// await store.actions.preview.saveSelected()
|
if (!parent?._children?.length) {
|
||||||
// await store.actions.components.select(definition)
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace block with ejected definition
|
||||||
|
const childIndex = parent._children.findIndex(
|
||||||
|
child => child._id === componentId
|
||||||
|
)
|
||||||
|
parent._children[childIndex] = ejectedDefinition
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
links: {
|
links: {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
|
||||||
let structureLookupMap = {}
|
let structureLookupMap = {}
|
||||||
|
|
||||||
const registerBlockComponent = (id, order, parentId, instance) => {
|
const registerBlockComponent = (id, order, parentId, instance) => {
|
||||||
// Ensure child array exists
|
// Ensure child array exists
|
||||||
if (!structureLookupMap[parentId]) {
|
if (!structureLookupMap[parentId]) {
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
}
|
}
|
||||||
// Remove existing instance of this component in case props changed
|
// Remove existing instance of this component in case props changed
|
||||||
structureLookupMap[parentId] = structureLookupMap[parentId].filter(
|
structureLookupMap[parentId] = structureLookupMap[parentId].filter(
|
||||||
x => x.instance._id !== id
|
blockComponent => blockComponent.instance._id !== id
|
||||||
)
|
)
|
||||||
// Add new instance of this component
|
// Add new instance of this component
|
||||||
structureLookupMap[parentId].push({ order, instance })
|
structureLookupMap[parentId].push({ order, instance })
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
|
import { builderStore } from "../stores/builder.js"
|
||||||
import Component from "components/Component.svelte"
|
import Component from "components/Component.svelte"
|
||||||
|
|
||||||
export let type
|
export let type
|
||||||
|
@ -23,7 +24,7 @@
|
||||||
$: instance = {
|
$: instance = {
|
||||||
_component: `@budibase/standard-components/${type}`,
|
_component: `@budibase/standard-components/${type}`,
|
||||||
_id: id,
|
_id: id,
|
||||||
_instanceName: type,
|
_instanceName: type[0].toUpperCase() + type.slice(1),
|
||||||
_styles: {
|
_styles: {
|
||||||
normal: {
|
normal: {
|
||||||
...styles,
|
...styles,
|
||||||
|
@ -31,7 +32,14 @@
|
||||||
},
|
},
|
||||||
...props,
|
...props,
|
||||||
}
|
}
|
||||||
$: block.registerComponent(id, order, $component?.id, instance)
|
|
||||||
|
// Register this block component if we're inside the builder so it can be
|
||||||
|
// ejected later
|
||||||
|
$: {
|
||||||
|
if ($builderStore.inBuilder) {
|
||||||
|
block.registerComponent(id, order, $component?.id, instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Component {instance} isBlock>
|
<Component {instance} isBlock>
|
||||||
|
|
Loading…
Reference in New Issue