schlechtenburg/packages/core/lib/use-dynamic-blocks.ts

21 lines
510 B
TypeScript
Raw Normal View History

2020-12-30 01:32:46 +00:00
import {
ref,
inject,
reactive,
} from 'vue';
2020-12-30 13:34:23 +00:00
import { BlockLibraryDefinition } from './blocks';
import { Mode, SbMode } from './mode';
2020-12-30 01:32:46 +00:00
export const BlockLibrary = Symbol('Schlechtenburg block library');
export function useDynamicBlocks() {
const mode = inject(Mode, ref(SbMode.Edit));
const customBlocks: BlockLibraryDefinition = inject(BlockLibrary, reactive({}));
2020-12-30 20:17:34 +00:00
const getBlock = (name: string) => customBlocks[name]?.[mode.value];
2020-12-30 01:32:46 +00:00
return {
mode,
customBlocks,
getBlock,
};
}