budibase/packages/builder/src/components/userInterface/ComponentPropertiesPanel.sv...

115 lines
3.0 KiB
Svelte
Raw Normal View History

2020-01-21 15:50:35 +01:00
<script>
import { store } from "builderStore"
2020-05-04 17:07:04 +02:00
import panelStructure from "./temporaryPanelStructure.js"
import CategoryTab from "./CategoryTab.svelte"
import DesignView from "./DesignView.svelte"
2020-05-18 17:32:00 +02:00
import SettingsView from "./SettingsView.svelte"
2020-05-04 17:07:04 +02:00
let flattenedPanel = flattenComponents(panelStructure.categories)
let categories = [
2020-05-18 17:32:00 +02:00
{ value: "settings", name: "Settings" },
{ value: "design", name: "Design" },
2020-05-04 17:07:04 +02:00
]
let selectedCategory = categories[0]
2020-02-03 10:50:30 +01:00
2020-06-25 17:02:30 +02:00
$: componentInstance =
$store.currentView !== "component"
? { ...$store.currentPreviewItem, ...$store.currentComponentInfo }
: $store.currentComponentInfo
2020-05-18 17:32:00 +02:00
$: componentDefinition = $store.components[componentInstance._component]
2020-05-20 12:55:25 +02:00
$: componentPropDefinition =
flattenedPanel.find(
//use for getting controls for each component property
(c) => c._component === componentInstance._component
2020-05-20 12:55:25 +02:00
) || {}
2020-06-11 14:15:19 +02:00
2020-06-15 18:08:59 +02:00
$: panelDefinition =
componentPropDefinition.properties &&
componentPropDefinition.properties[selectedCategory.value]
2020-05-04 17:07:04 +02:00
2020-02-03 10:50:30 +01:00
const onStyleChanged = store.setComponentStyle
2020-02-26 10:43:38 +01:00
2020-06-25 17:02:30 +02:00
$: isComponentOrScreen =
$store.currentView === "component" ||
$store.currentFrontEndType === "screen"
2020-06-24 17:16:06 +02:00
$: isNotScreenslot = componentInstance._component !== "##builtin/screenslot"
2020-06-25 17:02:30 +02:00
$: displayName =
isComponentOrScreen && componentInstance._instanceName && isNotScreenslot
2020-05-04 17:07:04 +02:00
function walkProps(component, action) {
action(component)
if (component.children) {
for (let child of component.children) {
walkProps(child, action)
}
}
}
function flattenComponents(props) {
const components = []
props.forEach((comp) =>
walkProps(comp, (c) => {
2020-05-04 17:07:04 +02:00
if ("_component" in c) {
components.push(c)
}
})
)
return components
}
2020-02-26 10:43:38 +01:00
function getProps(obj, keys) {
return keys.map((key, i) => [key, obj[key], obj.props._id + i])
2020-02-26 10:43:38 +01:00
}
2020-01-21 15:50:35 +01:00
</script>
<CategoryTab
onClick={(category) => (selectedCategory = category)}
{categories}
{selectedCategory} />
{#if displayName}
<div class="instance-name">{componentInstance._instanceName}</div>
{/if}
<div class="component-props-container">
{#if selectedCategory.value === 'design'}
<DesignView {panelDefinition} {componentInstance} {onStyleChanged} />
{:else if selectedCategory.value === 'settings'}
<SettingsView
{componentInstance}
{componentDefinition}
{panelDefinition}
displayNameField={displayName}
onChange={store.setComponentProp}
onScreenPropChange={store.setPageOrScreenProp}
screenOrPageInstance={$store.currentView !== 'component' && $store.currentPreviewItem} />
2020-06-25 17:02:30 +02:00
{/if}
</div>
2020-01-21 15:50:35 +01:00
<style>
2020-02-03 10:50:30 +01:00
.title > div:nth-child(1) {
2020-01-21 15:50:35 +01:00
grid-column-start: name;
color: var(--ink);
2020-02-03 10:50:30 +01:00
}
2020-01-21 15:50:35 +01:00
2020-02-03 10:50:30 +01:00
.title > div:nth-child(2) {
2020-01-21 15:50:35 +01:00
grid-column-start: actions;
2020-02-03 10:50:30 +01:00
}
2020-01-21 15:50:35 +01:00
2020-02-03 10:50:30 +01:00
.component-props-container {
2020-01-21 15:50:35 +01:00
flex: 1 1 auto;
2020-06-01 23:04:32 +02:00
min-height: 0;
2020-07-28 15:19:46 +02:00
overflow-y: auto;
margin-left: -20px;
margin-right: -20px;
padding: 0 20px;
2020-02-03 10:50:30 +01:00
}
.instance-name {
font-size: 14px;
font-weight: 500;
color: var(--grey-7);
}
2020-01-21 15:50:35 +01:00
</style>