layout.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { IPage, IPagePopulatedToShowRevision } from '@growi/core';
  2. import { useIsContainerFluid } from '~/stores/context';
  3. import { useEditorMode } from '~/stores/ui';
  4. export const useEditorModeClassName = (): string => {
  5. const { getClassNamesByEditorMode } = useEditorMode();
  6. return `${getClassNamesByEditorMode().join(' ') ?? ''}`;
  7. };
  8. const useDetermineExpandContent = (expandContentWidth?: boolean | null): boolean => {
  9. const { data: dataIsContainerFluid } = useIsContainerFluid();
  10. const isContainerFluidDefault = dataIsContainerFluid;
  11. return expandContentWidth ?? isContainerFluidDefault ?? false;
  12. };
  13. export const useShouldExpandContent = (data?: IPage | IPagePopulatedToShowRevision | boolean | null): boolean => {
  14. const expandContentWidth = (() => {
  15. // when data is null
  16. if (data == null) {
  17. return null;
  18. }
  19. // when data is boolean
  20. if (data === true || data === false) {
  21. return data;
  22. }
  23. // when IPage does not have expandContentWidth
  24. if (!('expandContentWidth' in data)) {
  25. return null;
  26. }
  27. return data.expandContentWidth;
  28. })();
  29. return useDetermineExpandContent(expandContentWidth);
  30. };