From e55804a9306b5fe986fb5a1a6ea42e657f84ee91 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Mon, 19 Sep 2022 22:28:01 -0400 Subject: [PATCH] Fix preview panel --- .../src/components/Editor/EditorInterface.js | 59 ++++++------------- .../Editor/EditorPreviewPane/EditorPreview.js | 4 ++ .../EditorPreviewContent.tsx | 14 ++++- packages/netlify-cms-ui-default/src/styles.js | 8 +-- 4 files changed, 40 insertions(+), 45 deletions(-) diff --git a/packages/netlify-cms-core/src/components/Editor/EditorInterface.js b/packages/netlify-cms-core/src/components/Editor/EditorInterface.js index db6e2a69..27510a8e 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorInterface.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorInterface.js @@ -3,7 +3,6 @@ import React, { Component } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { css, Global } from '@emotion/core'; import styled from '@emotion/styled'; -import SplitPane from 'react-split-pane'; import { colors, colorsRaw, @@ -23,7 +22,6 @@ import { getFileFromSlug } from '../../reducers/collections'; const PREVIEW_VISIBLE = 'cms.preview-visible'; const SCROLL_SYNC_ENABLED = 'cms.scroll-sync-enabled'; -const SPLIT_PANE_POSITION = 'cms.split-pane-position'; const I18N_VISIBLE = 'cms.i18n-visible'; const styles = { @@ -34,7 +32,6 @@ const styles = { `, pane: css` height: 100%; - overflow-y: auto; `, }; @@ -72,14 +69,18 @@ function ReactSplitPaneGlobalStyles() { ); } -const StyledSplitPane = styled(SplitPane)` - ${styles.splitPane}; +const StyledSplitPane = styled.div` + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); + height: 100%; - /** - * Quick fix for preview pane not fully displaying in Safari - */ - .Pane { + div:nth-child(2)::before { + content: ''; + width: 2px; height: 100%; + position: relative; + background-color: rgb(223, 223, 227); + display: block; } `; @@ -96,7 +97,6 @@ const EditorContainer = styled.div` left: 0; overflow: hidden; padding-top: 66px; - background-color: ${colors.background}; `; const Editor = styled.div` @@ -120,7 +120,7 @@ const ControlPaneContainer = styled(PreviewPaneContainer)` const ViewControls = styled.div` position: absolute; top: 10px; - right: 10px; + right: 28px; z-index: ${zIndex.zIndex299}; `; @@ -151,20 +151,11 @@ function isPreviewEnabled(collection, entry) { class EditorInterface extends Component { state = { - showEventBlocker: false, previewVisible: localStorage.getItem(PREVIEW_VISIBLE) !== 'false', scrollSyncEnabled: localStorage.getItem(SCROLL_SYNC_ENABLED) !== 'false', i18nVisible: localStorage.getItem(I18N_VISIBLE) !== 'false', }; - handleSplitPaneDragStart = () => { - this.setState({ showEventBlocker: true }); - }; - - handleSplitPaneDragFinished = () => { - this.setState({ showEventBlocker: false }); - }; - handleOnPersist = async (opts = {}) => { const { createNew = false, duplicate = false } = opts; await this.controlPaneRef.switchToDefaultLocale(); @@ -234,7 +225,7 @@ class EditorInterface extends Component { t, } = this.props; - const { scrollSyncEnabled, showEventBlocker } = this.state; + const { scrollSyncEnabled } = this.state; const previewEnabled = isPreviewEnabled(collection, entry); @@ -252,7 +243,7 @@ class EditorInterface extends Component { const leftPanelLocale = this.state.leftPanelLocale || locales?.[0]; const editor = ( - + (this.controlPaneRef = c)} @@ -264,7 +255,7 @@ class EditorInterface extends Component { ); const editor2 = ( - + ); @@ -275,17 +266,11 @@ class EditorInterface extends Component { const editorWithPreview = ( -
+ <> - localStorage.setItem(SPLIT_PANE_POSITION, size)} - onDragStarted={this.handleSplitPaneDragStart} - onDragFinished={this.handleSplitPaneDragFinished} - > + {editor} - + -
+
); const editorWithEditor = (
- localStorage.setItem(SPLIT_PANE_POSITION, size)} - onDragStarted={this.handleSplitPaneDragStart} - onDragFinished={this.handleSplitPaneDragFinished} - > + {editor} {editor2} diff --git a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreview.js b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreview.js index ea8a96b5..a5d1132c 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreview.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreview.js @@ -8,6 +8,10 @@ function isVisible(field) { } const PreviewContainer = styled.div` + overflow-y: auto; + height: 100%; + padding: 24px; + box-sizing: border-box; font-family: Roboto, 'Helvetica Neue', HelveticaNeue, Helvetica, Arial, sans-serif; `; diff --git a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewContent.tsx b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewContent.tsx index 8ee46df4..5fe8d3fc 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewContent.tsx +++ b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewContent.tsx @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* eslint-disable func-style */ +import styled from '@emotion/styled'; import { CmsWidgetPreviewProps } from 'netlify-cms-core'; import React, { ComponentType, ReactNode, useMemo } from 'react'; import ReactDOM from 'react-dom'; @@ -11,6 +12,14 @@ interface PreviewContentProps { previewProps: CmsWidgetPreviewProps; } +const StyledPreviewContent = styled.div` + width: calc(50% - 2px); + top: 66px; + right: 0; + position: absolute; + height: calc(100% - 66px); +`; + const PreviewContent = ({ previewComponent, previewProps }: PreviewContentProps) => { const element = useMemo(() => document.getElementById('nc-root'), []); @@ -28,7 +37,10 @@ const PreviewContent = ({ previewComponent, previewProps }: PreviewContentProps) children = React.createElement(previewComponent, previewProps); } - return ReactDOM.createPortal(
{children}
, element); + return ReactDOM.createPortal( + {children}, + element, + ); }, [previewComponent, previewProps, element]); }; diff --git a/packages/netlify-cms-ui-default/src/styles.js b/packages/netlify-cms-ui-default/src/styles.js index 7f5e5479..b624f123 100644 --- a/packages/netlify-cms-ui-default/src/styles.js +++ b/packages/netlify-cms-ui-default/src/styles.js @@ -497,6 +497,10 @@ function GlobalStyles() { margin: 0; } + img { + max-width: 100%; + } + ${quantifier} { font-family: ${fonts.primary}; font-weight: normal; @@ -555,10 +559,6 @@ function GlobalStyles() { text-decoration: none; } - img { - max-width: 100%; - } - textarea { resize: none; }