2020-01-21 15:50:35 +01:00
|
|
|
<script>
|
2020-05-18 17:32:00 +02:00
|
|
|
import { setContext, onMount } from "svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
import PropsView from "./PropsView.svelte"
|
2020-06-15 17:01:24 +02:00
|
|
|
|
2020-03-31 13:16:03 +02:00
|
|
|
import { store } from "builderStore"
|
|
|
|
import IconButton from "components/common/IconButton.svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
import {
|
|
|
|
LayoutIcon,
|
|
|
|
PaintIcon,
|
|
|
|
TerminalIcon,
|
|
|
|
CircleIndicator,
|
|
|
|
EventsIcon,
|
2020-03-31 13:16:03 +02:00
|
|
|
} from "components/common/Icons/"
|
2020-02-03 10:50:30 +01:00
|
|
|
import CodeEditor from "./CodeEditor.svelte"
|
|
|
|
import LayoutEditor from "./LayoutEditor.svelte"
|
|
|
|
import EventsEditor from "./EventsEditor"
|
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 current_view = "design"
|
2020-02-03 10:50:30 +01:00
|
|
|
let codeEditor
|
2020-05-04 17:07:04 +02:00
|
|
|
let flattenedPanel = flattenComponents(panelStructure.categories)
|
|
|
|
let categories = [
|
2020-05-18 17:32:00 +02:00
|
|
|
{ value: "design", name: "Design" },
|
|
|
|
{ value: "settings", name: "Settings" },
|
2020-05-28 21:20:03 +02:00
|
|
|
{ value: "events", name: "Events" },
|
2020-05-04 17:07:04 +02:00
|
|
|
]
|
|
|
|
let selectedCategory = categories[0]
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
$: components = $store.components
|
2020-06-15 17:01:24 +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-06-11 14:15:19 +02:00
|
|
|
|
2020-06-03 23:05:02 +02:00
|
|
|
let panelDefinition = {}
|
2020-06-03 17:19:04 +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-15 17:01:24 +02:00
|
|
|
function onPropChanged(key, value) {
|
|
|
|
if($store.currentView !== "component") {
|
|
|
|
store.setPageOrScreenProp(key, value)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
store.setComponentProp(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
$: displayName = ( $store.currentView === "component" || $store.currentFrontEndType === "screen") && componentInstance._instanceName && componentInstance._component !== "##builtin/screenslot"
|
2020-06-04 19:08:50 +02:00
|
|
|
|
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 => {
|
|
|
|
if ("_component" in c) {
|
|
|
|
components.push(c)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
return components
|
|
|
|
}
|
2020-02-26 10:43:38 +01:00
|
|
|
|
|
|
|
function getProps(obj, keys) {
|
2020-05-06 11:33:30 +02:00
|
|
|
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>
|
|
|
|
|
|
|
|
<div class="root">
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-05-04 17:07:04 +02:00
|
|
|
<CategoryTab
|
|
|
|
onClick={category => (selectedCategory = category)}
|
|
|
|
{categories}
|
|
|
|
{selectedCategory} />
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-06-04 19:08:50 +02:00
|
|
|
{#if displayName}
|
|
|
|
<div class="instance-name">
|
|
|
|
<strong>{componentInstance._instanceName}</strong>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2020-05-04 17:07:04 +02:00
|
|
|
<div class="component-props-container">
|
2020-05-18 17:32:00 +02:00
|
|
|
{#if selectedCategory.value === 'design'}
|
2020-06-03 23:05:02 +02:00
|
|
|
<DesignView {panelDefinition} {componentInstance} {onStyleChanged} />
|
2020-05-18 17:32:00 +02:00
|
|
|
{:else if selectedCategory.value === 'settings'}
|
|
|
|
<SettingsView
|
|
|
|
{componentInstance}
|
2020-05-19 18:00:53 +02:00
|
|
|
{componentDefinition}
|
2020-06-09 20:18:45 +02:00
|
|
|
{panelDefinition}
|
2020-06-04 19:08:50 +02:00
|
|
|
displayNameField={displayName}
|
2020-06-15 17:01:24 +02:00
|
|
|
onChange={onPropChanged}
|
2020-06-12 13:15:17 +02:00
|
|
|
screenOrPageInstance={$store.currentView !== "component" && $store.currentPreviewItem} />
|
2020-06-16 13:17:32 +02:00
|
|
|
|
2020-05-27 22:51:32 +02:00
|
|
|
{:else if selectedCategory.value === 'events'}
|
|
|
|
<EventsEditor component={componentInstance} />
|
2020-05-04 17:07:04 +02:00
|
|
|
{/if}
|
2020-02-10 16:51:09 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-01-24 15:30:17 +01:00
|
|
|
</div>
|
2020-01-21 15:50:35 +01:00
|
|
|
|
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
.root {
|
2020-01-21 15:50:35 +01:00
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-05-29 19:31:47 +02:00
|
|
|
padding: 20px;
|
2020-06-01 23:04:32 +02:00
|
|
|
box-sizing: border-box;
|
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(1) {
|
2020-01-21 15:50:35 +01:00
|
|
|
grid-column-start: name;
|
2020-05-27 13:18:05 +02:00
|
|
|
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-06-04 19:08:50 +02:00
|
|
|
margin-top: 10px;
|
2020-01-21 15:50:35 +01:00
|
|
|
flex: 1 1 auto;
|
2020-06-01 23:04:32 +02:00
|
|
|
min-height: 0;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-06-04 19:08:50 +02:00
|
|
|
|
|
|
|
.instance-name {
|
|
|
|
margin-top: 10px;
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
2020-01-21 15:50:35 +01:00
|
|
|
</style>
|