2020-01-24 12:32:13 +01:00
|
|
|
<script>
|
2020-02-03 10:50:30 +01:00
|
|
|
import { last } from "lodash/fp"
|
|
|
|
import { pipe } from "../common/core"
|
2020-02-20 18:11:41 +01:00
|
|
|
import {
|
|
|
|
XCircleIcon,
|
|
|
|
ChevronUpIcon,
|
|
|
|
ChevronDownIcon,
|
|
|
|
CopyIcon,
|
|
|
|
} from "../common/Icons"
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
export let components = []
|
|
|
|
export let currentComponent
|
|
|
|
export let onSelect = () => {}
|
|
|
|
export let level = 0
|
2020-02-18 17:51:28 +01:00
|
|
|
export let onDeleteComponent
|
2020-02-19 11:17:31 +01:00
|
|
|
export let onMoveUpComponent
|
|
|
|
export let onMoveDownComponent
|
|
|
|
export let onCopyComponent
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
|
2020-02-20 18:11:41 +01:00
|
|
|
const get_name = s => (!s ? "" : last(s.split("/")))
|
2020-02-10 16:51:09 +01:00
|
|
|
|
|
|
|
const get_capitalised_name = name =>
|
|
|
|
pipe(
|
|
|
|
name,
|
|
|
|
[get_name, capitalise]
|
|
|
|
)
|
2020-02-18 17:51:28 +01:00
|
|
|
|
2020-02-20 18:11:41 +01:00
|
|
|
const moveDownComponent = component => {
|
2020-02-19 11:17:31 +01:00
|
|
|
const c = component
|
|
|
|
return () => {
|
|
|
|
return onMoveDownComponent(c)
|
|
|
|
}
|
|
|
|
}
|
2020-01-24 12:32:13 +01:00
|
|
|
</script>
|
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
<ul>
|
2020-02-19 11:17:31 +01:00
|
|
|
{#each components as component, index (component._id)}
|
2020-02-03 10:50:30 +01:00
|
|
|
<li on:click|stopPropagation={() => onSelect(component)}>
|
2020-02-19 11:17:31 +01:00
|
|
|
<div
|
2020-02-24 16:00:48 +01:00
|
|
|
class="budibase__nav-item item"
|
2020-02-03 10:50:30 +01:00
|
|
|
class:selected={currentComponent === component}
|
2020-02-21 12:09:37 +01:00
|
|
|
style="padding-left: {level * 20 + 53}px">
|
2020-02-19 15:12:24 +01:00
|
|
|
<div>{get_capitalised_name(component._component)}</div>
|
2020-02-19 11:17:31 +01:00
|
|
|
<div class="reorder-buttons">
|
|
|
|
{#if index > 0}
|
2020-02-20 18:11:41 +01:00
|
|
|
<button
|
2020-02-21 12:09:37 +01:00
|
|
|
class:solo={index === components.length - 1}
|
2020-02-20 18:11:41 +01:00
|
|
|
on:click|stopPropagation={() => onMoveUpComponent(component)}>
|
|
|
|
<ChevronUpIcon />
|
|
|
|
</button>
|
2020-02-19 11:17:31 +01:00
|
|
|
{/if}
|
2020-02-20 18:11:41 +01:00
|
|
|
{#if index < components.length - 1}
|
2020-02-21 12:09:37 +01:00
|
|
|
<button
|
|
|
|
class:solo={index === 0}
|
|
|
|
on:click|stopPropagation={moveDownComponent(component)}>
|
2020-02-20 18:11:41 +01:00
|
|
|
<ChevronDownIcon />
|
|
|
|
</button>
|
2020-02-19 11:17:31 +01:00
|
|
|
{/if}
|
|
|
|
</div>
|
2020-02-21 12:09:37 +01:00
|
|
|
<button
|
|
|
|
class="copy"
|
|
|
|
on:click|stopPropagation={() => onCopyComponent(component)}>
|
2020-02-20 18:11:41 +01:00
|
|
|
<CopyIcon />
|
2020-02-19 11:17:31 +01:00
|
|
|
</button>
|
2020-02-20 18:11:41 +01:00
|
|
|
<button on:click|stopPropagation={() => onDeleteComponent(component)}>
|
2020-02-18 17:51:28 +01:00
|
|
|
<XCircleIcon />
|
|
|
|
</button>
|
2020-02-19 11:17:31 +01:00
|
|
|
</div>
|
2020-01-24 12:32:13 +01:00
|
|
|
|
|
|
|
{#if component._children}
|
2020-02-03 10:50:30 +01:00
|
|
|
<svelte:self
|
|
|
|
components={component._children}
|
|
|
|
{currentComponent}
|
|
|
|
{onSelect}
|
2020-02-18 17:51:28 +01:00
|
|
|
level={level + 1}
|
2020-02-19 11:17:31 +01:00
|
|
|
{onDeleteComponent}
|
|
|
|
{onMoveUpComponent}
|
|
|
|
{onMoveDownComponent}
|
|
|
|
{onCopyComponent} />
|
2020-01-24 12:32:13 +01:00
|
|
|
{/if}
|
|
|
|
</li>
|
2020-01-28 22:17:04 +01:00
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
ul {
|
|
|
|
list-style: none;
|
|
|
|
padding-left: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
2020-02-19 11:17:31 +01:00
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
.item {
|
2020-02-19 15:12:24 +01:00
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 1fr auto auto auto;
|
2020-02-20 18:09:35 +01:00
|
|
|
padding: 0px 5px 0px 15px;
|
2020-02-19 11:17:31 +01:00
|
|
|
margin: auto 0px;
|
2020-01-28 22:17:04 +01:00
|
|
|
border-radius: 3px;
|
2020-02-20 18:11:41 +01:00
|
|
|
height: 35px;
|
2020-02-19 11:17:31 +01:00
|
|
|
align-items: center;
|
2020-02-20 18:11:41 +01:00
|
|
|
font-weight: normal;
|
2020-01-28 22:17:04 +01:00
|
|
|
}
|
2020-02-18 17:51:28 +01:00
|
|
|
|
2020-02-19 11:17:31 +01:00
|
|
|
.item button {
|
2020-02-18 17:51:28 +01:00
|
|
|
display: none;
|
|
|
|
height: 20px;
|
2020-02-21 12:09:37 +01:00
|
|
|
width: 28px;
|
2020-02-19 11:17:31 +01:00
|
|
|
color: var(--slate);
|
|
|
|
padding: 0px 5px;
|
2020-02-21 12:09:37 +01:00
|
|
|
border-style: none;
|
|
|
|
background: rgba(0, 0, 0, 0);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.item button.copy {
|
|
|
|
width: 26px;
|
2020-02-18 17:51:28 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 22:17:04 +01:00
|
|
|
.item:hover {
|
|
|
|
background: #fafafa;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2020-02-19 11:17:31 +01:00
|
|
|
.item:hover button {
|
2020-02-18 17:51:28 +01:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
2020-02-19 11:17:31 +01:00
|
|
|
.item:hover button:hover {
|
2020-02-18 17:51:28 +01:00
|
|
|
color: var(--button-text);
|
|
|
|
}
|
|
|
|
|
2020-02-19 11:17:31 +01:00
|
|
|
.reorder-buttons {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reorder-buttons > button {
|
|
|
|
flex: 1 1 auto;
|
2020-02-19 15:12:24 +01:00
|
|
|
width: 30px;
|
2020-02-21 12:09:37 +01:00
|
|
|
height: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reorder-buttons > button.solo {
|
|
|
|
padding-top: 2px;
|
2020-02-19 11:17:31 +01:00
|
|
|
}
|
2020-01-28 22:17:04 +01:00
|
|
|
</style>
|