From 737d5e1ef335c7adadc54e5ac88afe9b431f9842 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 10 Aug 2022 16:54:13 +0100 Subject: [PATCH] Add full PoC of using a custom component inside the builder, with children and bindings --- .../src/builderStore/store/frontend.js | 33 +++++++++++++++++-- .../[screenId]/_components/iframeTemplate.js | 3 ++ .../new/_components/NewComponentPanel.svelte | 21 ++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 58d803aa03..7903210f53 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -92,11 +92,41 @@ export const getFrontendStore = () => { // Allow errors to propagate. let components = await API.fetchComponentLibDefinitions(application.appId) + // Extend definitions with custom components + components["test"] = { + component: "test", + name: "Super cool component", + icon: "Text", + description: "A custom component", + showSettingsBar: false, + hasChildren: true, + settings: [ + { + type: "text", + key: "text", + label: "Text", + }, + ], + context: { + type: "static", + values: [ + { + label: "Text prop", + key: "text", + }, + ], + }, + } + + // Filter out custom component keys so we can flag them + let customComponents = ["test"] + // Reset store state store.update(state => ({ ...state, libraries: application.componentLibraries, components, + customComponents, clientFeatures: { ...INITIAL_FRONTEND_STATE.clientFeatures, ...components.features, @@ -397,9 +427,6 @@ export const getFrontendStore = () => { if (!componentName) { return null } - if (!componentName.startsWith("@budibase")) { - componentName = `@budibase/standard-components/${componentName}` - } return get(store).components[componentName] }, createInstance: (componentName, presetProps) => { diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/iframeTemplate.js b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/iframeTemplate.js index 1c789d858e..64a05c7246 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/iframeTemplate.js +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/_components/iframeTemplate.js @@ -37,6 +37,9 @@ export default ` } +