Update block ejection to account for children of blocks

This commit is contained in:
Andrew Kingston 2022-08-24 08:37:53 +01:00
parent 5525f29a57
commit ee484639b5
3 changed files with 22 additions and 6 deletions

View File

@ -912,19 +912,32 @@ export const getFrontendStore = () => {
let nextSelectedComponentId let nextSelectedComponentId
await store.actions.screens.patch(screen => { await store.actions.screens.patch(screen => {
const block = findComponent(screen.props, componentId)
const parent = findComponentParent(screen.props, componentId) const parent = findComponentParent(screen.props, componentId)
// Sanity check parent is found // Sanity check
if (!parent?._children?.length) { if (!block || !parent?._children?.length) {
return false return false
} }
// Attach block children back into ejected definition, using the
// _containsSlot flag to know where to insert them
const slotContainer = findAllMatchingComponents(
ejectedDefinition,
x => x._containsSlot
)[0]
if (slotContainer) {
delete slotContainer._containsSlot
slotContainer._children = [
...(slotContainer._children || []),
...(block._children || []),
]
}
// Replace block with ejected definition // Replace block with ejected definition
const childIndex = parent._children.findIndex(
child => child._id === componentId
)
makeComponentUnique(ejectedDefinition) makeComponentUnique(ejectedDefinition)
parent._children[childIndex] = ejectedDefinition const index = parent._children.findIndex(x => x._id === componentId)
parent._children[index] = ejectedDefinition
nextSelectedComponentId = ejectedDefinition._id nextSelectedComponentId = ejectedDefinition._id
}) })

View File

@ -10,6 +10,7 @@
export let css export let css
export let context export let context
export let order = 0 export let order = 0
export let containsSlot = false
// ID is only exposed as a prop so that it can be bound to from parent // ID is only exposed as a prop so that it can be bound to from parent
// block components // block components
@ -32,6 +33,7 @@
}, },
custom: css, custom: css,
}, },
_containsSlot: containsSlot,
...props, ...props,
} }

View File

@ -44,6 +44,7 @@
<BlockComponent <BlockComponent
type="repeater" type="repeater"
context="repeater" context="repeater"
containsSlot
props={{ props={{
dataProvider: `{{ literal ${safe(providerId)} }}`, dataProvider: `{{ literal ${safe(providerId)} }}`,
noRowsMessage, noRowsMessage,