mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
* Add support for npm extensions * Allow extensions to import vue from the main app * Bundle app extensions on server startup * Fix return type of useLayoutState * Add shared package * Add extension-sdk package * Add type declaration files to allow deep import of shared package * Add extension loading to shared * Refactor extension loading to use shared package * Remove app bundle newline replacement * Fix extension loading in development * Rename extension entrypoints * Update extension build instructions * Remove vite auto-replacement workaround * Update package-lock.json * Remove newline from generated extension entrypoint * Update package-lock.json * Build shared package as cjs and esm * Move useLayoutState composable to shared * Reverse vite base env check * Share useLayoutState composable through extension-sdk * Update layout docs * Update package versions * Small cleanup * Fix layout docs * Fix imports * Add nickrum to codeowners * Fix typo * Add 'em to vite config too * Fix email Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
27 lines
866 B
TypeScript
27 lines
866 B
TypeScript
import { getLayouts } from '@/layouts';
|
|
import { computed, reactive, provide, Ref, UnwrapRef } from 'vue';
|
|
import { LayoutProps, LayoutState } from '@directus/shared/types';
|
|
import { LAYOUT_SYMBOL } from '@directus/shared/constants';
|
|
|
|
export function useLayout<Options = any, Query = any>(
|
|
layoutName: Ref<string>,
|
|
props: LayoutProps<Options, Query>
|
|
): Ref<UnwrapRef<LayoutState<Record<string, any>, Options, Query>>> {
|
|
const { layouts } = getLayouts();
|
|
|
|
const setupLayouts: Record<string, Record<string, any>> = layouts.value.reduce(
|
|
(acc, { id, setup }) => ({ ...acc, [id]: setup(props) }),
|
|
{}
|
|
);
|
|
|
|
const layoutState = computed(() => {
|
|
const setupResult = setupLayouts[layoutName.value];
|
|
|
|
return reactive<LayoutState<Record<string, any>, Options, Query>>({ ...setupResult, props });
|
|
});
|
|
|
|
provide(LAYOUT_SYMBOL, layoutState);
|
|
|
|
return layoutState;
|
|
}
|