From 0b2c6e531c4d8922ce63a6e641baa168ac7fddf9 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 30 Jul 2023 13:07:01 +0100 Subject: [PATCH 1/2] Export Block and BlockComponent via SDK --- packages/client/src/sdk.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/client/src/sdk.js b/packages/client/src/sdk.js index c9ff1eba36..237334ca57 100644 --- a/packages/client/src/sdk.js +++ b/packages/client/src/sdk.js @@ -18,6 +18,8 @@ import { styleable } from "utils/styleable" import { linkable } from "utils/linkable" import { getAction } from "utils/getAction" import Provider from "components/context/Provider.svelte" +import Block from "components/Block.svelte" +import BlockComponent from "components/BlockComponent.svelte" import { ActionTypes } from "./constants" import { fetchDatasourceSchema } from "./utils/schema.js" import { getAPIKey } from "./utils/api.js" @@ -44,4 +46,6 @@ export default { Provider, ActionTypes, getAPIKey, + Block, + BlockComponent, } From bbe6741ffde4979f8825d69e34a81ce7d281834f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sun, 30 Jul 2023 13:07:14 +0100 Subject: [PATCH 2/2] Support plugins in block components --- .../src/components/BlockComponent.svelte | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/BlockComponent.svelte b/packages/client/src/components/BlockComponent.svelte index 24d9b4dee4..c9516b0d71 100644 --- a/packages/client/src/components/BlockComponent.svelte +++ b/packages/client/src/components/BlockComponent.svelte @@ -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)