1
0
Fork 0
mirror of synced 2024-09-14 00:08:25 +12:00

Add full PoC of using a custom component inside the builder, with children and bindings

This commit is contained in:
Andrew Kingston 2022-08-10 16:54:13 +01:00
parent 07909c9ae3
commit 16e42dc5a1
3 changed files with 51 additions and 6 deletions

View file

@ -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) => {

View file

@ -37,6 +37,9 @@ export default `
}
</style>
<script src='{{ CLIENT_LIB_PATH }}'></script>
<script
type="application/javascript"
src="https://cdn.kingston.dev/plugin.min.js"></script>
<script>
function receiveMessage(event) {
if (!event.data) {

View file

@ -24,7 +24,11 @@
$: currentDefinition = store.actions.components.getDefinition(
$selectedComponent?._component
)
$: enrichedStructure = enrichStructure(structure, $store.components)
$: enrichedStructure = enrichStructure(
structure,
$store.components,
$store.customComponents
)
$: filteredStructure = filterStructure(
enrichedStructure,
section,
@ -46,8 +50,18 @@
// Parses the structure in the manifest and returns an enriched structure with
// explicit categories
const enrichStructure = (structure, definitions) => {
const enrichStructure = (structure, definitions, customComponents) => {
let enrichedStructure = []
// Add custom components category
if (customComponents?.length) {
enrichedStructure.push({
name: "Custom components",
isCategory: true,
children: customComponents.map(x => definitions[x]),
})
}
structure.forEach(item => {
if (typeof item === "string") {
const def = definitions[`@budibase/standard-components/${item}`]
@ -65,6 +79,7 @@
})
}
})
return enrichedStructure
}
@ -225,7 +240,7 @@
position: fixed;
right: 0;
z-index: 1;
height: 100%;
height: calc(100% - 60px);
display: flex;
flex-direction: row;
align-items: stretch;