schlechtenburg/src/components/internal/BlockPicker.tsx

39 lines
950 B
TypeScript
Raw Normal View History

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