@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
109 lines (107 loc) • 4.47 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { Fragment, lazy, Suspense, useLayoutEffect, useState } from 'react';
import { setRequestForgeryToken } from '../../utils/auth';
import { getStore } from '../../state/store';
import { SnackbarProvider } from 'notistack';
import I18nProvider from '../I18nProvider';
import StoreProvider from '../StoreProvider';
import CrafterThemeProvider from '../CrafterThemeProvider';
import SnackbarCloseButton from '../SnackbarCloseButton';
import { publishCrafterGlobal } from '../../env/craftercms';
import { registerComponents } from '../../env/registerComponents';
import LoadingState from '../LoadingState';
import GlobalStyles from '../GlobalStyles';
import ErrorState from '../ErrorState/ErrorState';
const LegacyConcierge = lazy(() => import('../LegacyConcierge/LegacyConcierge'));
const GlobalDialogManager = lazy(() => import('../GlobalDialogManager/GlobalDialogManager'));
export function CrafterCMSNextBridge(props) {
const [store, setStore] = useState(null);
const [storeError, setStoreError] = useState();
const {
children,
themeOptions,
suspenseFallback = '',
mountCssBaseline = true,
mountGlobalDialogManager = true,
mountSnackbarProvider = true,
mountLegacyConcierge = false
} = props;
const SnackbarOrFragment = mountSnackbarProvider ? SnackbarProvider : Fragment;
const snackbarOrFragmentProps = mountSnackbarProvider
? {
maxSnack: 5,
autoHideDuration: 5000,
anchorOrigin: { vertical: 'bottom', horizontal: 'left' },
action: (id) => React.createElement(SnackbarCloseButton, { id: id })
}
: {};
useLayoutEffect(() => {
registerComponents();
publishCrafterGlobal();
setRequestForgeryToken();
getStore().subscribe({
next: (store) => setStore(store),
error: (message) => setStoreError(message)
});
}, []);
return React.createElement(
CrafterThemeProvider,
{ themeOptions: themeOptions },
React.createElement(
I18nProvider,
null,
React.createElement(
SnackbarOrFragment,
Object.assign({}, snackbarOrFragmentProps),
storeError
? React.createElement(ErrorState, {
title: storeError,
imageUrl: '/studio/static-assets/images/warning_state.svg',
styles: { title: { textAlign: 'center' }, image: { width: 250, marginBottom: 10, marginTop: 10 } }
})
: store
? React.createElement(
StoreProvider,
{ store: store },
React.createElement(Suspense, { fallback: suspenseFallback, children: children }),
mountGlobalDialogManager &&
React.createElement(Suspense, { fallback: '' }, React.createElement(GlobalDialogManager, null)),
mountLegacyConcierge &&
React.createElement(Suspense, { fallback: '' }, React.createElement(LegacyConcierge, null))
)
: React.createElement(LoadingState, null)
)
),
React.createElement(GlobalStyles, { cssBaseline: mountCssBaseline })
);
}
export default CrafterCMSNextBridge;