expose blocks toolbox creation
This commit is contained in:
parent
1f09c05b29
commit
877520461d
2 changed files with 12 additions and 8 deletions
|
|
@ -6,13 +6,14 @@ import generators from './generators.js'
|
|||
|
||||
export const
|
||||
allBlocksJson = [],
|
||||
allBlockCategories = {},
|
||||
allBlocksByCategory = {},
|
||||
allBlockLabels = {},
|
||||
allGenerators = generators
|
||||
|
||||
Object.keys(ALL_BLOCKS).map(key => {
|
||||
const
|
||||
{ json={}, commonType, toolbox, generators } = ALL_BLOCKS[key],
|
||||
block = ALL_BLOCKS[key],
|
||||
{ json={}, commonType, toolbox, generators } = block,
|
||||
type = commonType || json.type
|
||||
|
||||
if(!type) { throw new Error(`No "type" declared for block: ${key}`) }
|
||||
|
|
@ -31,8 +32,8 @@ Object.keys(ALL_BLOCKS).map(key => {
|
|||
// sort blocks into their declared categories
|
||||
const { category, categories=[] } = toolbox
|
||||
categories.concat([category]).forEach(category => {
|
||||
allBlockCategories[category] = (allBlockCategories[category] || [])
|
||||
allBlockCategories[category].push(type)
|
||||
allBlocksByCategory[category] = (allBlocksByCategory[category] || {})
|
||||
allBlocksByCategory[category][type] = block
|
||||
})
|
||||
|
||||
// toolbox labels
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { allBlockCategories, allBlockLabels } from './blocks/index.js'
|
||||
import { reduce } from 'lodash'
|
||||
|
||||
import { allBlocksByCategory, allBlockLabels } from './blocks/index.js'
|
||||
|
||||
|
||||
const
|
||||
|
|
@ -30,11 +32,12 @@ export default {
|
|||
name: category.name,
|
||||
colour: category.colour,
|
||||
...category.extras,
|
||||
contents: (allBlockCategories[category.name] || []).reduce((acc, type) => {
|
||||
contents: reduce(allBlocksByCategory[category.name] || {}, (acc, block, type) => {
|
||||
const { inputs={}, fields={} } = block
|
||||
// add tooltip as a toolbox label, if present
|
||||
allBlockLabels[type] && acc.push({ kind: 'label', text: allBlockLabels[type] })
|
||||
// add the block
|
||||
acc.push({ kind: 'block', type })
|
||||
// add the block. inputs and fields provide defaults, shadows, etc
|
||||
acc.push({ kind: 'block', type, ...{ inputs, fields } })
|
||||
return acc
|
||||
} , [])
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue