2020-05-24 15:33:25 +00:00
|
|
|
import {
|
|
|
|
defineComponent,
|
2021-03-08 17:13:18 +00:00
|
|
|
inject,
|
|
|
|
reactive,
|
2020-05-28 20:16:35 +00:00
|
|
|
ref,
|
2020-12-27 21:32:43 +00:00
|
|
|
} from 'vue';
|
2021-03-08 17:13:18 +00:00
|
|
|
import { SymBlockLibrary } from '../use-dynamic-blocks';
|
2020-05-20 14:21:08 +00:00
|
|
|
|
|
|
|
import './Block.scss';
|
|
|
|
|
2020-12-30 13:34:23 +00:00
|
|
|
export const SbBlock = defineComponent({
|
2020-05-20 14:21:08 +00:00
|
|
|
name: 'sb-block',
|
|
|
|
|
|
|
|
props: {
|
2020-05-27 15:06:14 +00:00
|
|
|
block: {
|
2021-03-08 17:13:18 +00:00
|
|
|
type: Object,
|
2020-05-27 15:06:14 +00:00
|
|
|
required: true,
|
2020-05-27 13:57:57 +00:00
|
|
|
},
|
2020-05-20 14:21:08 +00:00
|
|
|
},
|
|
|
|
|
2021-03-08 15:29:35 +00:00
|
|
|
setup(props, context) {
|
2021-03-08 17:13:18 +00:00
|
|
|
const el = ref(null);
|
|
|
|
const customBlocks = inject(SymBlockLibrary, reactive({}));
|
|
|
|
const getBlock = (name) => customBlocks[name];
|
2020-05-28 20:16:35 +00:00
|
|
|
|
2020-12-30 20:17:34 +00:00
|
|
|
return () => {
|
2021-03-08 17:13:18 +00:00
|
|
|
const BlockComponent = getBlock(props.block.name)?.component || <span>Missing block {name}</span>;
|
2020-12-30 20:17:34 +00:00
|
|
|
|
|
|
|
return <div
|
|
|
|
ref={el}
|
2021-03-08 17:13:18 +00:00
|
|
|
class="sb-block"
|
2020-12-30 20:17:34 +00:00
|
|
|
>
|
|
|
|
<BlockComponent
|
|
|
|
data={props.block.data}
|
2021-03-07 17:47:28 +00:00
|
|
|
blockId={props.block.id}
|
2021-03-08 17:03:18 +00:00
|
|
|
{...context.attrs}
|
2020-12-30 20:17:34 +00:00
|
|
|
/>
|
|
|
|
</div>;
|
|
|
|
};
|
2020-05-20 14:21:08 +00:00
|
|
|
},
|
|
|
|
});
|