schlechtenburg/packages/core/lib/use-dynamic-blocks.ts
2021-03-08 16:29:35 +01:00

21 lines
481 B
TypeScript

import {
ref,
inject,
reactive,
} from 'vue';
import { BlockLibrary } from './types';
import { Mode, SbMode } from './mode';
export const SymBlockLibrary = Symbol('Schlechtenburg block library');
export function useDynamicBlocks() {
const mode = inject(Mode, ref(SbMode.Edit));
const customBlocks: BlockLibrary = inject(SymBlockLibrary, reactive({}));
const getBlock = (name: string) => customBlocks[name];
return {
mode,
customBlocks,
getBlock,
};
}