2019-08-02 15:54:10 +02:00
|
|
|
<script>
|
2020-01-28 22:17:04 +01:00
|
|
|
import ComponentsHierarchyChildren from './ComponentsHierarchyChildren.svelte';
|
|
|
|
|
|
|
|
import {
|
|
|
|
last,
|
|
|
|
sortBy,
|
|
|
|
map,
|
|
|
|
trimCharsStart,
|
|
|
|
trimChars,
|
|
|
|
join,
|
|
|
|
} from "lodash/fp";
|
|
|
|
|
|
|
|
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(" ")
|
|
|
|
]);
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
const lastPartOfName = (c) =>
|
|
|
|
last(c.name ? c.name.split("/") : c._component.split("/"))
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
const isComponentSelected = (current, comp) =>
|
|
|
|
current &&
|
|
|
|
current.component &&
|
|
|
|
comp.component &&
|
|
|
|
current.component.name === comp.component.name
|
2019-08-02 15:54:10 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
const isFolderSelected = (current, folder) =>
|
|
|
|
isInSubfolder(current, folder)
|
2019-08-15 09:49:15 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
$: _components =
|
|
|
|
pipe(components, [
|
|
|
|
map(c => ({component: c, title:lastPartOfName(c)})),
|
|
|
|
sortBy("title")
|
|
|
|
]);
|
2019-08-15 09:49:15 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
function select_component(screen, component) {
|
|
|
|
store.setCurrentScreen(screen);
|
|
|
|
store.selectComponent(component);
|
|
|
|
}
|
2019-08-15 09:49:15 +02:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
const isScreenSelected = component =>
|
|
|
|
component.component &&
|
|
|
|
$store.currentFrontEndItem &&
|
|
|
|
component.component.name === $store.currentFrontEndItem.name;
|
2019-08-15 09:49:15 +02:00
|
|
|
|
2019-08-02 15:54:10 +02:00
|
|
|
</script>
|
|
|
|
|
2020-01-20 17:47:35 +01:00
|
|
|
<div class="root">
|
|
|
|
|
2020-01-24 12:32:13 +01:00
|
|
|
{#each _components as component}
|
2020-01-28 22:17:04 +01:00
|
|
|
<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 />
|
|
|
|
{/if}
|
|
|
|
</span>
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
<span class="title">{component.title}</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if isScreenSelected(component) && component.component.props && component.component.props._children}
|
2020-01-24 15:30:17 +01:00
|
|
|
<ComponentsHierarchyChildren components={component.component.props._children}
|
2020-01-28 22:17:04 +01:00
|
|
|
currentComponent={$store.currentComponentInfo}
|
2020-01-24 16:34:02 +01:00
|
|
|
onSelect={child => select_component(component.component.name, child)} />
|
2020-01-24 12:32:13 +01:00
|
|
|
{/if}
|
2019-08-02 15:54:10 +02:00
|
|
|
{/each}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
.root {
|
2020-01-20 17:47:35 +01:00
|
|
|
font-weight: 500;
|
|
|
|
font-size: 0.9rem;
|
|
|
|
color: #828fa5;
|
2019-08-02 15:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.hierarchy-item {
|
|
|
|
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;
|
2019-08-02 15:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.hierarchy-item:hover {
|
2020-01-20 17:47:35 +01:00
|
|
|
/* color: var(--secondary); */
|
|
|
|
background: #fafafa;
|
2019-08-02 15:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.selected {
|
2020-01-20 17:47:35 +01:00
|
|
|
color: var(--button-text);
|
|
|
|
background: var(--background-button)!important;
|
2019-08-02 15:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
|
|
|
margin-left: 10px;
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
.icon {
|
|
|
|
display: inline-block;
|
|
|
|
transition: 0.2s;
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
}
|
2020-01-20 17:47:35 +01:00
|
|
|
</style>
|