UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

113 lines (111 loc) 4.13 kB
/* * 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/>. */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === 'function') for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useRef } from 'react'; import { useIntl } from 'react-intl'; import DialogHeader from '../DialogHeader'; import { EmbeddedLegacyContainer } from './EmbeddedLegacyContainer'; import MinimizedBar from '../MinimizedBar'; import Dialog from '@mui/material/Dialog'; import { useStyles } from './styles'; import { translations } from './translations'; export function LegacyFormDialog(props) { const { formatMessage } = useIntl(); const { classes } = useStyles(); const { open, inProgress, disableOnClose, disableHeader, isMinimized, onMaximize, onMinimize } = props, rest = __rest(props, [ 'open', 'inProgress', 'disableOnClose', 'disableHeader', 'isMinimized', 'onMaximize', 'onMinimize' ]); const iframeRef = useRef(); const title = formatMessage(translations.title); const onClose = (e, reason) => { // The form engine is too expensive to load to lose it with an unintentional // backdrop click. Disabling backdrop click until form engine 2. if ('backdropClick' !== reason) { if (inProgress) { props === null || props === void 0 ? void 0 : props.onClose(); } iframeRef.current.contentWindow.postMessage({ type: 'LEGACY_FORM_DIALOG_CANCEL_REQUEST' }, '*'); } }; const onCloseButtonClick = (e) => { onClose(e); }; return React.createElement( React.Fragment, null, React.createElement( Dialog, { open: open && !isMinimized, keepMounted: isMinimized, fullWidth: true, maxWidth: 'xl', classes: { paper: classes.dialog }, onClose: onClose }, !disableHeader && React.createElement(DialogHeader, { title: title, disabled: disableOnClose, onCloseButtonClick: onCloseButtonClick, rightActions: [ { icon: { id: '@mui/icons-material/RemoveRounded' }, onClick: onMinimize } ] }), React.createElement( EmbeddedLegacyContainer, Object.assign({ ref: iframeRef, inProgress: inProgress, onMinimize: onMinimize }, rest) ) ), React.createElement(MinimizedBar, { open: isMinimized, onMaximize: onMaximize, title: title }) ); } export default LegacyFormDialog;