2020-05-24 20:00:14 +00:00
|
|
|
import { computed, defineComponent } from '@vue/composition-api';
|
2020-05-25 21:10:21 +00:00
|
|
|
import {
|
|
|
|
useDynamicBlocks,
|
|
|
|
BlockDefinition,
|
|
|
|
} from '../TreeElement';
|
2020-05-24 20:00:14 +00:00
|
|
|
|
|
|
|
import './BlockPicker.scss';
|
2020-05-20 14:21:08 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
2020-05-25 21:10:21 +00:00
|
|
|
name: 'sb-block-picker',
|
|
|
|
|
2020-05-24 15:33:25 +00:00
|
|
|
props: {},
|
2020-05-20 14:21:08 +00:00
|
|
|
|
2020-05-25 21:10:21 +00:00
|
|
|
setup(props, context) {
|
2020-05-24 20:00:14 +00:00
|
|
|
const { customBlocks } = useDynamicBlocks();
|
|
|
|
|
|
|
|
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
|
2020-05-20 14:21:08 +00:00
|
|
|
|
2020-05-25 21:10:21 +00:00
|
|
|
return () => (
|
2020-05-24 15:33:25 +00:00
|
|
|
<div class="sb-block-picker">
|
2020-05-25 21:10:21 +00:00
|
|
|
{...blockList.value.map((block: BlockDefinition) => (
|
2020-05-24 20:00:14 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
{...{
|
|
|
|
on: {
|
2020-05-25 21:10:21 +00:00
|
|
|
click: () => context.emit('picked-block', {
|
2020-05-24 20:00:14 +00:00
|
|
|
name: block.name,
|
2020-05-25 21:10:21 +00:00
|
|
|
blockId: `${+(new Date())}`,
|
2020-05-24 20:00:14 +00:00
|
|
|
data: block.getDefaultData(),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>{block.name}</button>
|
|
|
|
))}
|
2020-05-20 14:21:08 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|