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

124 lines
3.1 KiB
Svelte
Raw Normal View History

2020-02-20 18:11:41 +01:00
<script>
2020-04-28 15:28:31 +02:00
import { goto } from "@sveltech/routify"
2020-02-20 18:11:41 +01:00
// import { tick } from "svelte"
import ComponentsHierarchyChildren from "./ComponentsHierarchyChildren.svelte"
import { last, sortBy, map, trimCharsStart, trimChars, join, compose } from "lodash/fp"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { pipe } from "components/common/core"
import { store } from "builderStore"
import { ArrowDownIcon, GridIcon } from "components/common/Icons/"
2020-02-20 18:11:41 +01:00
export let layout
let confirmDeleteDialog
let componentToDelete = ""
const joinPath = join("/")
const lastPartOfName = c =>
c && last(c.name ? c.name.split("/") : c._component.split("/"))
const isComponentSelected = (current, comp) => current === comp
$: _layout = {
component: layout,
title: lastPartOfName(layout)
}
2020-02-20 18:11:41 +01:00
const isScreenSelected = component =>
component.component &&
$store.currentPreviewItem &&
component.component.name === $store.currentPreviewItem.name
const confirmDeleteComponent = async component => {
componentToDelete = component
confirmDeleteDialog.show()
}
2020-04-28 15:28:31 +02:00
const setCurrentScreenToLayout = () => {
store.setScreenType("page")
$goto("./:page/page-layout")
}
2020-02-20 18:11:41 +01:00
</script>
<div class="pagelayoutSection">
<div class="components-nav-page">Page Layout</div>
2020-02-25 00:23:33 +01:00
<div
class="budibase__nav-item root"
2020-02-25 00:23:33 +01:00
class:selected={$store.currentComponentInfo._id === _layout.component.props._id}
2020-04-28 15:28:31 +02:00
on:click|stopPropagation={setCurrentScreenToLayout}>
2020-02-20 18:11:41 +01:00
<span
class="icon"
class:rotate={$store.currentPreviewItem.name !== _layout.title}>
<ArrowDownIcon />
2020-02-20 18:11:41 +01:00
</span>
<span class="icon">
<GridIcon />
</span>
<span class="title">Page Layout</span>
2020-02-20 18:11:41 +01:00
</div>
{#if $store.currentPreviewItem.name === _layout.title && _layout.component.props._children}
<ComponentsHierarchyChildren
thisComponent={_layout.component.props}
2020-02-20 18:11:41 +01:00
components={_layout.component.props._children}
currentComponent={$store.currentComponentInfo}
onDeleteComponent={confirmDeleteComponent}
onMoveUpComponent={store.moveUpComponent}
onMoveDownComponent={store.moveDownComponent}
onCopyComponent={store.copyComponent} />
{/if}
</div>
<ConfirmDialog
bind:this={confirmDeleteDialog}
title="Confirm Delete"
body={`Are you sure you wish to delete this '${lastPartOfName(componentToDelete)}' component?`}
2020-02-20 18:11:41 +01:00
okText="Delete Component"
onOk={() => store.deleteComponent(componentToDelete)} />
<style>
2020-04-28 15:28:31 +02:00
.components-nav-page {
font-size: 13px;
color: #000333;
text-transform: uppercase;
margin-bottom: 10px;
padding-left: 20px;
font-weight: 600;
opacity: 0.4;
letter-spacing: 1px;
}
2020-04-28 15:28:31 +02:00
.pagelayoutSection {
margin: 20px 0px 20px 0px;
}
2020-02-20 18:11:41 +01:00
.title {
margin-left: 10px;
font-size: 13px;
2020-02-20 18:11:41 +01:00
}
.icon {
display: inline-block;
transition: 0.2s;
width: 20px;
margin-top: 2px;
color: #000333;
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);
}
</style>