standalone templates (templates with no component)

This commit is contained in:
Michael Shanks 2020-02-21 21:27:44 +00:00
parent ec7cc028c5
commit 1398a00212
1 changed files with 18 additions and 5 deletions

View File

@ -1,12 +1,12 @@
<script> <script>
import { splitName } from "./pagesParsing/splitRootComponentName.js" import { splitName } from "./pagesParsing/splitRootComponentName.js"
import { store } from "../builderStore" import { store } from "../builderStore"
import { find, sortBy, groupBy } from "lodash/fp" import { find, sortBy, groupBy, values, filter, map, uniqBy, flatten } from "lodash/fp"
import { ImageIcon, InputIcon, LayoutIcon } from "../common/Icons/" import { ImageIcon, InputIcon, LayoutIcon } from "../common/Icons/"
import Select from "../common/Select.svelte" import Select from "../common/Select.svelte"
import Button from "../common/PlusButton.svelte" import Button from "../common/PlusButton.svelte"
import ConfirmDialog from "../common/ConfirmDialog.svelte" import ConfirmDialog from "../common/ConfirmDialog.svelte"
import { getRecordNodes, getIndexNodes, getIndexSchema } from "../common/core" import { getRecordNodes, getIndexNodes, getIndexSchema, pipe } from "../common/core"
let componentLibraries = [] let componentLibraries = []
let current_view = "text" let current_view = "text"
@ -19,6 +19,13 @@
$: templatesByComponent = groupBy(t => t.component)($store.templates) $: templatesByComponent = groupBy(t => t.component)($store.templates)
$: hierarchy = $store.hierarchy $: hierarchy = $store.hierarchy
$: libraryModules = $store.libraries $: libraryModules = $store.libraries
$: standaloneTemplates = pipe(templatesByComponent, [
values,
flatten,
filter(t => !$store.components.some(c => c.name === t.component)),
map(t => ({ name: splitName(t.component), template: t })),
uniqBy(t => t.name)
])
const addRootComponent = (component, allComponents) => { const addRootComponent = (component, allComponents) => {
const { libName } = splitName(component.name) const { libName } = splitName(component.name)
@ -36,7 +43,13 @@
group.components.push(component) group.components.push(component)
} }
const onComponentChosen = store.addChildComponent const onComponentChosen = component => {
if (component.template) {
onTemplateChosen(component.template)
} else {
store.addChildComponent(component)
}
}
const onTemplateChosen = template => { const onTemplateChosen = template => {
selectedComponent = null selectedComponent = null
@ -61,9 +74,9 @@
} }
function generate_components_list(components) { function generate_components_list(components) {
return $store.currentFrontEndType === "page" return ($store.currentFrontEndType === "page"
? $store.builtins.concat(components) ? $store.builtins.concat(components)
: components : components).concat(standaloneTemplates)
} }
$: { $: {