2019-08-02 15:54:10 +02:00
|
|
|
<script>
|
2020-02-03 10:50:30 +01:00
|
|
|
import ComponentsHierarchyChildren from "./ComponentsHierarchyChildren.svelte"
|
2019-08-15 09:49:15 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
import { last, sortBy, map, trimCharsStart, trimChars, join } from "lodash/fp"
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
import { pipe } from "../common/core"
|
|
|
|
import { store } from "../builderStore"
|
|
|
|
import { ArrowDownIcon } from "../common/Icons/"
|
|
|
|
|
|
|
|
export let components = []
|
|
|
|
|
|
|
|
const joinPath = join("/")
|
|
|
|
|
|
|
|
const normalizedName = name =>
|
|
|
|
pipe(name, [
|
|
|
|
trimCharsStart("./"),
|
|
|
|
trimCharsStart("~/"),
|
|
|
|
trimCharsStart("../"),
|
|
|
|
trimChars(" "),
|
|
|
|
])
|
|
|
|
|
|
|
|
const lastPartOfName = c =>
|
|
|
|
last(c.name ? c.name.split("/") : c._component.split("/"))
|
|
|
|
|
|
|
|
const isComponentSelected = (current, comp) =>
|
|
|
|
current &&
|
|
|
|
current.component &&
|
|
|
|
comp.component &&
|
|
|
|
current.component.name === comp.component.name
|
2020-01-20 17:47:35 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const isFolderSelected = (current, folder) => isInSubfolder(current, folder)
|
2020-01-28 22:17:04 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
$: _components = pipe(components, [
|
|
|
|
map(c => ({ component: c, title: lastPartOfName(c) })),
|
|
|
|
sortBy("title"),
|
|
|
|
])
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
function select_component(screen, component) {
|
|
|
|
store.setCurrentScreen(screen)
|
|
|
|
store.selectComponent(component)
|
|
|
|
}
|
2020-01-28 22:17:04 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const isScreenSelected = component =>
|
|
|
|
component.component &&
|
|
|
|
$store.currentFrontEndItem &&
|
|
|
|
component.component.name === $store.currentFrontEndItem.name
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="root">
|
|
|
|
|
|
|
|
{#each _components as component}
|
|
|
|
<div
|
|
|
|
class="hierarchy-item component"
|
|
|
|
class:selected={isComponentSelected($store.currentComponentInfo, component)}
|
|
|
|
on:click|stopPropagation={() => store.setCurrentScreen(component.component.name)}>
|
|
|
|
|
|
|
|
<span
|
|
|
|
class="icon"
|
|
|
|
style="transform: rotate({isScreenSelected(component) ? 0 : -90}deg);">
|
|
|
|
{#if component.component.props && component.component.props._children}
|
|
|
|
<ArrowDownIcon />
|
2020-01-24 12:32:13 +01:00
|
|
|
{/if}
|
2020-02-03 10:50:30 +01:00
|
|
|
</span>
|
|
|
|
|
|
|
|
<span class="title">{component.title}</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if isScreenSelected(component) && component.component.props && component.component.props._children}
|
|
|
|
<ComponentsHierarchyChildren
|
|
|
|
components={component.component.props._children}
|
|
|
|
currentComponent={$store.currentComponentInfo}
|
|
|
|
onSelect={child => select_component(component.component.name, child)} />
|
|
|
|
{/if}
|
|
|
|
{/each}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
.root {
|
2020-01-20 17:47:35 +01:00
|
|
|
font-weight: 500;
|
|
|
|
font-size: 0.9rem;
|
|
|
|
color: #828fa5;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.hierarchy-item {
|
2019-08-02 15:54:10 +02:00
|
|
|
cursor: pointer;
|
2020-01-20 17:47:35 +01:00
|
|
|
padding: 11px 7px;
|
|
|
|
margin: 5px 0;
|
|
|
|
border-radius: 5px;
|
2020-01-28 22:17:04 +01:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.hierarchy-item:hover {
|
2020-01-20 17:47:35 +01:00
|
|
|
/* color: var(--secondary); */
|
|
|
|
background: #fafafa;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.selected {
|
2020-01-20 17:47:35 +01:00
|
|
|
color: var(--button-text);
|
2020-02-03 10:50:30 +01:00
|
|
|
background: var(--background-button) !important;
|
|
|
|
}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.title {
|
2019-08-02 15:54:10 +02:00
|
|
|
margin-left: 10px;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.icon {
|
2020-01-28 22:17:04 +01:00
|
|
|
display: inline-block;
|
|
|
|
transition: 0.2s;
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-20 17:47:35 +01:00
|
|
|
</style>
|