2019-08-02 15:54:10 +02:00
|
|
|
<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"
|
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-03-31 13:16:03 +02:00
|
|
|
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
|
|
|
|
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-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("/"))
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const isComponentSelected = (current, comp) => current === comp
|
2020-01-20 17:47:35 +01:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
$: _screens = pipe(screens, [
|
|
|
|
map(c => ({ component: c, title: lastPartOfName(c) })),
|
|
|
|
sortBy("title"),
|
|
|
|
])
|
2020-01-28 22:17:04 +01:00
|
|
|
|
2020-02-18 17:51:28 +01:00
|
|
|
const confirmDeleteComponent = component => {
|
|
|
|
componentToDelete = component
|
|
|
|
confirmDeleteDialog.show()
|
|
|
|
}
|
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">
|
2020-02-10 16:51:09 +01:00
|
|
|
{#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}>
|
2020-02-10 16:51:09 +01:00
|
|
|
{#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-20 18:11:41 +01:00
|
|
|
<span class="icon">
|
|
|
|
<ShapeIcon />
|
|
|
|
</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-19 11:17:31 +01:00
|
|
|
onDeleteComponent={confirmDeleteComponent}
|
|
|
|
onMoveUpComponent={store.moveUpComponent}
|
|
|
|
onMoveDownComponent={store.moveDownComponent}
|
2020-02-20 18:11:41 +01:00
|
|
|
onCopyComponent={store.copyComponent} />
|
2020-02-03 10:50:30 +01:00
|
|
|
{/if}
|
|
|
|
{/each}
|
2019-08-02 15:54:10 +02:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-02-20 18:11:41 +01:00
|
|
|
<ConfirmDialog
|
|
|
|
bind:this={confirmDeleteDialog}
|
|
|
|
title="Confirm Delete"
|
2020-02-24 17:41:02 +01:00
|
|
|
body={`Are you sure you wish to delete this '${lastPartOfName(componentToDelete)}' component?`}
|
2020-02-18 17:51:28 +01:00
|
|
|
okText="Delete Component"
|
2020-02-20 18:11:41 +01:00
|
|
|
onOk={() => store.deleteComponent(componentToDelete)} />
|
2020-02-18 17:51:28 +01:00
|
|
|
|
2019-08-02 15:54:10 +02:00
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
.root {
|
2020-02-20 18:11:41 +01:00
|
|
|
font-weight: 400;
|
2020-04-02 18:11:38 +02:00
|
|
|
color: #000333;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
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-20 18:11:41 +01:00
|
|
|
margin-top: 2px;
|
2020-04-02 18:11:38 +02:00
|
|
|
font-size: 13px;
|
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;
|
2020-02-20 18:11:41 +01:00
|
|
|
width: 20px;
|
|
|
|
margin-top: 2px;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
|
|
|
|
.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
|
|
|
}
|
2020-01-20 17:47:35 +01:00
|
|
|
</style>
|