1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Support plugins in block components

This commit is contained in:
Andrew Kingston 2023-07-30 13:07:14 +01:00
parent 0b2c6e531c
commit bbe6741ffd

View file

@ -26,9 +26,9 @@
$: parentId = $component?.id
$: inBuilder = $builderStore.inBuilder
$: instance = {
_component: `@budibase/standard-components/${type}`,
_component: getComponent(type),
_id: id,
_instanceName: name || type[0].toUpperCase() + type.slice(1),
_instanceName: getInstanceName(name, type),
_styles: {
...styles,
normal: styles?.normal || {},
@ -45,6 +45,30 @@
}
}
const getComponent = type => {
if (!type) {
return null
}
if (type.startsWith("plugin/")) {
return type
} else {
return `@budibase/standard-components/${type}`
}
}
const getInstanceName = (name, type) => {
if (name) {
return name
}
if (!type) {
return "New component"
}
if (type.startsWith("plugin/")) {
type = type.split("plugin/")[1]
}
return type[0].toUpperCase() + type.slice(1)
}
onDestroy(() => {
if (inBuilder) {
block.unregisterComponent(id, parentId)