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

21 lines
489 B
TypeScript
Raw Normal View History

2020-12-30 01:32:46 +00:00
import {
ref,
inject,
reactive,
} from 'vue';
import { IBlockLibrary } from './types';
2022-03-15 23:38:33 +00:00
import { SymMode, SbMode } from './mode';
2020-12-30 01:32:46 +00:00
2021-03-08 15:29:35 +00:00
export const SymBlockLibrary = Symbol('Schlechtenburg block library');
2020-12-30 01:32:46 +00:00
export function useDynamicBlocks() {
2022-03-15 23:38:33 +00:00
const mode = inject(SymMode, ref(SbMode.Edit));
const customBlocks: IBlockLibrary = inject(SymBlockLibrary, reactive({}));
2021-02-22 23:12:06 +00:00
const getBlock = (name: string) => customBlocks[name];
2020-12-30 01:32:46 +00:00
return {
mode,
customBlocks,
getBlock,
};
}