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"
|
2020-02-18 17:51:28 +01:00
|
|
|
import ConfirmDialog from "../common/ConfirmDialog.svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
import { pipe } from "../common/core"
|
|
|
|
import { store } from "../builderStore"
|
|
|
|
import { ArrowDownIcon } from "../common/Icons/"
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
export let screens = []
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-02-18 17:51:28 +01:00
|
|
|
let confirmDeleteDialog
|
|
|
|
let componentToDelete = ""
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const joinPath = join("/")
|
|
|
|
|
|
|
|
const normalizedName = name =>
|
2020-02-10 16:51:09 +01:00
|
|
|
pipe(
|
|
|
|
name,
|
|
|
|
[
|
|
|
|
trimCharsStart("./"),
|
|
|
|
trimCharsStart("~/"),
|
|
|
|
trimCharsStart("../"),
|
|
|
|
trimChars(" "),
|
|
|
|
]
|
|
|
|
)
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
const lastPartOfName = c =>
|
2020-02-18 17:51:28 +01:00
|
|
|
c &&
|
2020-02-03 10:50:30 +01:00
|
|
|
last(c.name ? c.name.split("/") : c._component.split("/"))
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const isComponentSelected = (current, comp) => current === comp
|
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-10 16:51:09 +01:00
|
|
|
$: _screens = pipe(
|
|
|
|
screens,
|
|
|
|
[map(c => ({ component: c, title: lastPartOfName(c) })), sortBy("title")]
|
|
|
|
)
|
2020-01-28 22:17:04 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const isScreenSelected = component =>
|
|
|
|
component.component &&
|
2020-02-10 16:51:09 +01:00
|
|
|
$store.currentPreviewItem &&
|
|
|
|
component.component.name === $store.currentPreviewItem.name
|
2020-02-18 17:51:28 +01:00
|
|
|
|
|
|
|
const confirmDeleteComponent = component => {
|
|
|
|
componentToDelete = component
|
|
|
|
confirmDeleteDialog.show()
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="root">
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
{#each _screens as screen}
|
2020-02-03 10:50:30 +01:00
|
|
|
<div
|
|
|
|
class="hierarchy-item component"
|
2020-02-10 16:51:09 +01:00
|
|
|
class:selected={$store.currentPreviewItem.name === screen.title}
|
|
|
|
on:click|stopPropagation={() => store.setCurrentScreen(screen.title)}>
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
<span
|
|
|
|
class="icon"
|
2020-02-10 16:51:09 +01:00
|
|
|
style="transform: rotate({$store.currentPreviewItem.name === screen.title ? 0 : -90}deg);">
|
|
|
|
{#if screen.component.props._children.length}
|
2020-02-03 10:50:30 +01:00
|
|
|
<ArrowDownIcon />
|
2020-01-24 12:32:13 +01:00
|
|
|
{/if}
|
2020-02-03 10:50:30 +01:00
|
|
|
</span>
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
<span class="title">{screen.title}</span>
|
2020-02-03 10:50:30 +01:00
|
|
|
</div>
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
{#if $store.currentPreviewItem.name === screen.title && screen.component.props._children}
|
2020-02-03 10:50:30 +01:00
|
|
|
<ComponentsHierarchyChildren
|
2020-02-10 16:51:09 +01:00
|
|
|
components={screen.component.props._children}
|
2020-02-03 10:50:30 +01:00
|
|
|
currentComponent={$store.currentComponentInfo}
|
2020-02-18 17:51:28 +01:00
|
|
|
onSelect={store.selectComponent}
|
|
|
|
onDeleteComponent={confirmDeleteComponent}/>
|
2020-02-03 10:50:30 +01:00
|
|
|
{/if}
|
|
|
|
{/each}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-02-18 17:51:28 +01:00
|
|
|
<ConfirmDialog
|
|
|
|
bind:this={confirmDeleteDialog}
|
|
|
|
title="Confirm Delete"
|
|
|
|
body={`Are you sure you wish to delete this '${lastPartOfName(componentToDelete._component)}' component`}
|
|
|
|
okText="Delete Component"
|
|
|
|
onOk={() => store.deleteComponent(componentToDelete)}/>
|
|
|
|
|
2019-08-02 15:54:10 +02:00
|
|
|
<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>
|