2020-01-18 00:06:42 +01:00
|
|
|
<script>
|
2020-02-03 10:50:30 +01:00
|
|
|
import { splitName } from "./pagesParsing/splitRootComponentName.js"
|
|
|
|
import { store } from "../builderStore"
|
|
|
|
import { find, sortBy } from "lodash/fp"
|
|
|
|
import { ImageIcon, InputIcon, LayoutIcon } from "../common/Icons/"
|
2020-02-18 16:41:44 +01:00
|
|
|
import Select from "../common/Select.svelte"
|
2020-02-18 20:24:18 +01:00
|
|
|
import Button from "../common/PlusButton.svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
let componentLibraries = []
|
|
|
|
let current_view = "text"
|
2020-02-18 16:41:44 +01:00
|
|
|
let selectedComponent = null
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
const addRootComponent = (component, allComponents) => {
|
|
|
|
const { libName } = splitName(component.name)
|
|
|
|
let group = find(r => r.libName === libName)(allComponents)
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
if (!group) {
|
|
|
|
group = {
|
|
|
|
libName,
|
|
|
|
components: [],
|
|
|
|
}
|
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
allComponents.push(group)
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-28 22:17:04 +01:00
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
group.components.push(component)
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
const onComponentChosen = store.addChildComponent
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
$: {
|
|
|
|
const newComponentLibraries = []
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
for (let comp of sortBy(["name"])($store.components)) {
|
|
|
|
addRootComponent(comp, newComponentLibraries)
|
2020-01-28 22:17:04 +01:00
|
|
|
}
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
componentLibraries = newComponentLibraries
|
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="root">
|
2020-02-18 16:41:44 +01:00
|
|
|
<Select>
|
|
|
|
{#each componentLibraries as componentLibrary}
|
|
|
|
<option value={componentLibrary.libName}>
|
|
|
|
{componentLibrary.libName}
|
|
|
|
</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
|
|
|
{#each componentLibraries as componentLibrary}
|
2020-01-18 00:06:42 +01:00
|
|
|
<div class="library-container">
|
2020-02-03 10:50:30 +01:00
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
class:selected={current_view === 'text'}
|
|
|
|
on:click={() => (current_view = 'text')}>
|
|
|
|
<InputIcon />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
class:selected={current_view === 'layout'}
|
|
|
|
on:click={() => (current_view = 'layout')}>
|
|
|
|
<LayoutIcon />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
class:selected={current_view === 'media'}
|
|
|
|
on:click={() => (current_view = 'media')}>
|
|
|
|
<ImageIcon />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
{#each $store.builtins.concat(componentLibrary.components) as component}
|
|
|
|
<div class="component-container">
|
|
|
|
<div
|
|
|
|
class="component"
|
|
|
|
on:click={() => onComponentChosen(component.name)}>
|
|
|
|
<div class="name">{splitName(component.name).componentName}</div>
|
|
|
|
{#if component.presets && component.name === selectedComponent}
|
|
|
|
<ul class="preset-menu">
|
|
|
|
<span>{splitName(component.name).componentName} Presets</span>
|
|
|
|
{#each Object.keys(component.presets) as preset}
|
2020-02-18 20:24:18 +01:00
|
|
|
<li
|
|
|
|
on:click|stopPropagation={() => onComponentChosen(component.name, preset)}>
|
2020-02-18 16:41:44 +01:00
|
|
|
{preset}
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{#if component.presets}
|
2020-02-18 20:24:18 +01:00
|
|
|
<Button
|
2020-02-18 16:41:44 +01:00
|
|
|
on:click={() => {
|
2020-02-18 20:24:18 +01:00
|
|
|
selectedComponent = selectedComponent ? null : component.name
|
|
|
|
}}>
|
|
|
|
<span
|
|
|
|
class="open-presets"
|
|
|
|
class:open={selectedComponent === component.name}>
|
|
|
|
...
|
|
|
|
</span>
|
|
|
|
</Button>
|
2020-02-18 16:41:44 +01:00
|
|
|
{/if}
|
2020-01-18 00:06:42 +01:00
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
{/each}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
{/each}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
.root {
|
2020-01-18 00:06:42 +01:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.library-container {
|
2020-01-18 00:06:42 +01:00
|
|
|
padding: 0 0 10px 10px;
|
|
|
|
flex: 1 1 auto;
|
|
|
|
min-height: 0px;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
.component-container {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.component {
|
2020-02-18 16:41:44 +01:00
|
|
|
position: relative;
|
2020-01-24 12:32:13 +01:00
|
|
|
padding: 0 15px;
|
2020-01-18 00:06:42 +01:00
|
|
|
cursor: pointer;
|
2020-02-18 16:41:44 +01:00
|
|
|
border: 1px solid #ebebeb;
|
2020-01-24 12:32:13 +01:00
|
|
|
border-radius: 2px;
|
|
|
|
margin: 10px 0;
|
|
|
|
height: 40px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
color: #163057;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-02-18 16:41:44 +01:00
|
|
|
flex: 1;
|
|
|
|
margin-right: 5px;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.component:hover {
|
2020-01-18 00:06:42 +01:00
|
|
|
background-color: var(--lightslate);
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.component > .name {
|
2020-01-24 12:32:13 +01:00
|
|
|
color: #163057;
|
2020-01-18 00:06:42 +01:00
|
|
|
display: inline-block;
|
2020-01-24 12:32:13 +01:00
|
|
|
font-size: 12px;
|
|
|
|
font-weight: bold;
|
|
|
|
opacity: 0.6;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
ul {
|
2020-01-24 12:32:13 +01:00
|
|
|
list-style: none;
|
|
|
|
display: flex;
|
|
|
|
padding: 0;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
.preset-menu {
|
|
|
|
flex-direction: column;
|
|
|
|
position: absolute;
|
|
|
|
top: 25px;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
z-index: 1;
|
|
|
|
background: #fafafa;
|
|
|
|
padding: 10px;
|
|
|
|
border-radius: 2px;
|
|
|
|
color: rgba(22, 48, 87, 0.6);
|
|
|
|
}
|
|
|
|
|
|
|
|
.preset-menu > span {
|
|
|
|
font-size: 12px;
|
|
|
|
font-weight: bold;
|
|
|
|
text-transform: uppercase;
|
|
|
|
}
|
|
|
|
|
|
|
|
.preset-menu li {
|
|
|
|
font-size: 14px;
|
|
|
|
margin-top: 13px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.preset-menu li:hover {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
li {
|
2020-01-24 12:32:13 +01:00
|
|
|
margin-right: 20px;
|
|
|
|
background: none;
|
|
|
|
border-radius: 5px;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
li button {
|
2020-01-24 12:32:13 +01:00
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
|
|
|
padding: 12px;
|
|
|
|
outline: none;
|
|
|
|
cursor: pointer;
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
.selected {
|
2020-01-24 12:32:13 +01:00
|
|
|
color: var(--button-text);
|
2020-02-03 10:50:30 +01:00
|
|
|
background: var(--background-button) !important;
|
|
|
|
}
|
2020-02-18 20:24:18 +01:00
|
|
|
|
|
|
|
.open {
|
|
|
|
color: rgba(0, 85, 255, 1);
|
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
</style>
|