2020-01-18 00:06:42 +01:00
|
|
|
<script>
|
2020-04-21 15:20:57 +02:00
|
|
|
import { splitName } from "./pagesParsing/splitRootComponentName.js"
|
2020-04-17 09:16:03 +02:00
|
|
|
import components from "./temporaryPanelStructure.js"
|
2020-04-21 15:20:57 +02:00
|
|
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
|
|
|
import {
|
|
|
|
find,
|
|
|
|
sortBy,
|
|
|
|
groupBy,
|
|
|
|
values,
|
|
|
|
filter,
|
|
|
|
map,
|
|
|
|
uniqBy,
|
|
|
|
flatten,
|
|
|
|
} from "lodash/fp"
|
|
|
|
|
|
|
|
import {
|
|
|
|
getRecordNodes,
|
|
|
|
getIndexNodes,
|
|
|
|
getIndexSchema,
|
|
|
|
pipe,
|
|
|
|
} from "components/common/core"
|
|
|
|
|
2020-04-22 08:25:59 +02:00
|
|
|
import Tab from "./ItemTab/Tab.svelte"
|
2020-04-20 16:10:23 +02:00
|
|
|
import { store } from "builderStore"
|
2020-04-17 09:16:03 +02:00
|
|
|
|
2020-04-21 15:20:57 +02:00
|
|
|
export let toggleTab
|
|
|
|
|
|
|
|
let selectTemplateDialog
|
|
|
|
let selectedTemplateInstance
|
|
|
|
let templateInstances = []
|
|
|
|
|
|
|
|
let selectedComponent = null
|
|
|
|
|
2020-04-17 09:16:03 +02:00
|
|
|
const categories = components.categories
|
|
|
|
let selectedCategory = categories[0]
|
2020-04-21 15:20:57 +02:00
|
|
|
|
|
|
|
const onTemplateChosen = template => {
|
|
|
|
selectedComponent = null
|
|
|
|
const { componentName, libName } = splitName(template.name)
|
|
|
|
const templateOptions = {
|
|
|
|
records: getRecordNodes(hierarchy),
|
|
|
|
indexes: getIndexNodes(hierarchy),
|
|
|
|
helpers: {
|
|
|
|
indexSchema: getIndexSchema(hierarchy),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
templateInstances = libraryModules[libName][componentName](templateOptions)
|
|
|
|
if (!templateInstances || templateInstances.length === 0) return
|
|
|
|
selectedTemplateInstance = templateInstances[0].name
|
|
|
|
selectTemplateDialog.show()
|
|
|
|
}
|
|
|
|
|
2020-04-22 08:25:59 +02:00
|
|
|
const onComponentChosen = component => {
|
|
|
|
if (component.template) {
|
|
|
|
onTemplateChosen(component.template)
|
|
|
|
} else {
|
|
|
|
store.addChildComponent(component._component)
|
|
|
|
toggleTab()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:20:57 +02:00
|
|
|
const onTemplateInstanceChosen = () => {
|
|
|
|
selectedComponent = null
|
|
|
|
const instance = templateInstances.find(
|
|
|
|
i => i.name === selectedTemplateInstance
|
|
|
|
)
|
|
|
|
store.addTemplatedComponent(instance.props)
|
|
|
|
toggleTab()
|
|
|
|
}
|
|
|
|
|
|
|
|
$: templatesByComponent = groupBy(t => t.component)($store.templates)
|
|
|
|
$: hierarchy = $store.hierarchy
|
|
|
|
$: libraryModules = $store.libraries
|
|
|
|
$: standaloneTemplates = pipe(
|
|
|
|
templatesByComponent,
|
|
|
|
[
|
|
|
|
values,
|
|
|
|
flatten,
|
|
|
|
filter(t => !$store.components.some(c => c.name === t.component)),
|
|
|
|
map(t => ({ name: splitName(t.component).componentName, template: t })),
|
|
|
|
uniqBy(t => t.name),
|
|
|
|
]
|
|
|
|
)
|
2020-01-18 00:06:42 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="root">
|
2020-04-17 09:16:03 +02:00
|
|
|
<ul class="tabs">
|
|
|
|
{#each categories as category}
|
|
|
|
<li
|
|
|
|
on:click={() => (selectedCategory = category)}
|
|
|
|
class:active={selectedCategory === category}>
|
|
|
|
{category.name}
|
2020-02-19 22:38:21 +01:00
|
|
|
</li>
|
2020-04-17 09:16:03 +02:00
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
<div class="panel">
|
2020-04-22 08:25:59 +02:00
|
|
|
<Tab
|
|
|
|
list={selectedCategory}
|
2020-04-22 14:24:54 +02:00
|
|
|
on:selectItem={e => onComponentChosen(e.detail)}
|
|
|
|
{onTemplateChosen}
|
|
|
|
{toggleTab} />
|
2020-02-19 22:38:21 +01:00
|
|
|
</div>
|
2020-01-18 00:06:42 +01:00
|
|
|
</div>
|
|
|
|
|
2020-04-21 15:20:57 +02:00
|
|
|
<ConfirmDialog
|
|
|
|
bind:this={selectTemplateDialog}
|
|
|
|
title="Choose Template"
|
|
|
|
onCancel={() => (selectedComponent = null)}
|
|
|
|
onOk={onTemplateInstanceChosen}>
|
|
|
|
{#each templateInstances.map(i => i.name) as instance}
|
|
|
|
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid">
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
class="uk-radio"
|
|
|
|
type="radio"
|
|
|
|
bind:group={selectedTemplateInstance}
|
|
|
|
value={instance} />
|
|
|
|
<span class="template-instance-label">{instance}</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</ConfirmDialog>
|
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
<style>
|
2020-04-17 09:16:03 +02:00
|
|
|
.tabs {
|
2020-01-24 12:32:13 +01:00
|
|
|
display: flex;
|
2020-04-17 09:16:03 +02:00
|
|
|
justify-content: center;
|
2020-01-24 12:32:13 +01:00
|
|
|
list-style: none;
|
2020-04-17 09:16:03 +02:00
|
|
|
margin: 0 auto;
|
|
|
|
padding: 0 30px;
|
|
|
|
border-bottom: 1px solid #d8d8d8;
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-02-18 16:41:44 +01:00
|
|
|
font-size: 14px;
|
2020-04-17 09:16:03 +02:00
|
|
|
font-weight: 500;
|
|
|
|
letter-spacing: 0.14px;
|
2020-02-18 16:41:44 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
li {
|
2020-04-17 09:16:03 +02:00
|
|
|
color: #808192;
|
|
|
|
margin: 0 5px;
|
|
|
|
padding: 0 8px;
|
2020-01-24 12:32:13 +01:00
|
|
|
cursor: pointer;
|
2020-04-17 09:16:03 +02:00
|
|
|
}
|
2020-01-24 12:32:13 +01:00
|
|
|
|
2020-04-17 09:16:03 +02:00
|
|
|
.panel {
|
|
|
|
padding: 20px;
|
|
|
|
}
|
2020-02-18 20:24:18 +01:00
|
|
|
|
2020-04-17 09:16:03 +02:00
|
|
|
.active {
|
|
|
|
border-bottom: solid 3px #0055ff;
|
|
|
|
color: #393c44;
|
2020-02-18 20:24:18 +01:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
</style>
|