budibase/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte

108 lines
2.5 KiB
Svelte
Raw Normal View History

<script>
2020-04-28 15:28:31 +02:00
import { params, goto } from "@sveltech/routify"
2020-02-03 10:50:30 +01:00
import ComponentsHierarchyChildren from "./ComponentsHierarchyChildren.svelte"
import { last, sortBy, map, trimCharsStart, trimChars, join } from "lodash/fp"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { pipe } from "components/common/core"
import { store } from "builderStore"
import { ArrowDownIcon, ShapeIcon } from "components/common/Icons/"
2020-02-03 10:50:30 +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-04-28 15:28:31 +02:00
pipe(name, [
trimCharsStart("./"),
trimCharsStart("~/"),
trimCharsStart("../"),
trimChars(" "),
])
2020-02-03 10:50:30 +01:00
2020-02-20 18:27:48 +01:00
const lastPartOfName = c => {
if (!c) return ""
const name = c.name ? c.name : c._component ? c._component : c
return last(name.split("/"))
}
const isComponentSelected = (current, comp) => current === comp
2020-05-07 11:53:34 +02:00
$: _screens = pipe(screens, [
map(c => ({ component: c, title: lastPartOfName(c) })),
sortBy("title"),
])
2020-04-28 15:28:31 +02:00
const changeScreen = screen => {
store.setCurrentScreen(screen.title)
$goto(`./:page/${screen.title}`)
}
2020-02-03 10:50:30 +01:00
</script>
<div class="root">
{#each _screens as screen}
2020-02-03 10:50:30 +01:00
<div
2020-02-24 16:00:48 +01:00
class="budibase__nav-item component"
2020-02-20 18:11:41 +01:00
class:selected={$store.currentComponentInfo._id === screen.component.props._id}
2020-04-28 15:28:31 +02:00
on:click|stopPropagation={() => changeScreen(screen)}>
2020-02-03 10:50:30 +01:00
<span
class="icon"
2020-02-20 18:11:41 +01:00
class:rotate={$store.currentPreviewItem.name !== screen.title}>
{#if screen.component.props._children.length}
2020-02-03 10:50:30 +01:00
<ArrowDownIcon />
{/if}
2020-02-03 10:50:30 +01:00
</span>
2020-05-29 19:32:52 +02:00
<i class="ri-artboard-2-fill icon" />
2020-02-20 18:11:41 +01:00
<span class="title">{screen.title}</span>
2020-02-03 10:50:30 +01:00
</div>
{#if $store.currentPreviewItem.name === screen.title && screen.component.props._children}
2020-02-03 10:50:30 +01:00
<ComponentsHierarchyChildren
components={screen.component.props._children}
2020-06-01 11:25:12 +02:00
currentComponent={$store.currentComponentInfo} />
2020-02-03 10:50:30 +01:00
{/if}
{/each}
</div>
<style>
2020-02-03 10:50:30 +01:00
.root {
2020-02-20 18:11:41 +01:00
font-weight: 400;
color: var(--ink);
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.title {
margin-left: 10px;
2020-02-20 18:11:41 +01:00
margin-top: 2px;
font-size: 14px;
font-weight: 400;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.icon {
display: inline-block;
transition: 0.2s;
font-size: 24px;
2020-02-20 18:11:41 +01:00
width: 20px;
margin-top: 2px;
color: var(--ink-light);
2020-02-20 18:11:41 +01:00
}
.icon:nth-of-type(2) {
width: 14px;
margin: 0 0 0 5px;
}
:global(svg) {
transition: 0.2s;
}
.rotate :global(svg) {
transform: rotate(-90deg);
2020-02-03 10:50:30 +01:00
}
</style>