Skip to content

Commit

Permalink
Feature/grid panes (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsbajorics authored Sep 22, 2023
1 parent 181064b commit f6e2b65
Show file tree
Hide file tree
Showing 20 changed files with 954 additions and 1,572 deletions.
2 changes: 2 additions & 0 deletions editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@svgr/plugin-jsx": "5.5.0",
"@tippyjs/react": "4.1.0",
"@types/fontfaceobserver": "0.0.6",
"@types/lodash.findlastindex": "4.6.7",
"@types/react-syntax-highlighter": "11.0.4",
"@types/w3c-css-typed-object-model-level-1": "^20180410.0.5",
"@use-it/interval": "0.1.3",
Expand Down Expand Up @@ -159,6 +160,7 @@
"keycode": "2.2.1",
"localforage": "1.7.3",
"lodash.clamp": "4.0.3",
"lodash.findlastindex": "4.6.0",
"lru-cache": "7.10.1",
"matter-js": "git://github.com/liabru/matter-js.git#e909b0466cea2051267bab92a38ccaa9bf7f154e",
"mime-types": "2.1.24",
Expand Down
20 changes: 19 additions & 1 deletion editor/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions editor/src/components/canvas/canvas-error-overlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react'
import { useErrorOverlayRecords } from '../../core/shared/runtime-report-logs'
import { ReactErrorOverlay } from '../../third-party/react-error-overlay/react-error-overlay'
import { setFocus } from '../common/actions'
import {
clearHighlightedViews,
openCodeEditorFile,
switchEditorMode,
} from '../editor/actions/action-creators'
import { EditorModes } from '../editor/editor-modes'
import { useDispatch } from '../editor/store/dispatch-context'
import { useRefEditorState } from '../editor/store/store-hook'
import CanvasActions from './canvas-actions'
import { shouldShowErrorOverlay } from './canvas-utils'

export const ErrorOverlayComponent = React.memo(() => {
const { errorRecords, overlayErrors } = useErrorOverlayRecords()
const overlayWillShow = shouldShowErrorOverlay(errorRecords, overlayErrors)

const dispatch = useDispatch()

const onOpenFile = React.useCallback(
(path: string) => {
dispatch([openCodeEditorFile(path, true), setFocus('codeEditor')])
},
[dispatch],
)

const postActionSessionInProgressRef = useRefEditorState(
(store) => store.postActionInteractionSession != null,
)

React.useEffect(() => {
if (overlayWillShow) {
if (postActionSessionInProgressRef.current) {
return
}

// If this is showing, we need to clear any canvas drag state and apply the changes it would have resulted in,
// since that might have been the cause of the error being thrown, as well as switching back to select mode
setTimeout(() => {
// wrapping in a setTimeout so we don't dispatch from inside React lifecycle

dispatch([
CanvasActions.clearInteractionSession(true),
switchEditorMode(EditorModes.selectMode(null, false, 'none')),
clearHighlightedViews(),
])
}, 0)
}
}, [dispatch, overlayWillShow, postActionSessionInProgressRef])

return (
<ReactErrorOverlay
currentBuildErrorRecords={errorRecords}
currentRuntimeErrorRecords={overlayErrors}
onOpenFile={onOpenFile}
overlayOffset={0}
/>
)
})
ErrorOverlayComponent.displayName = 'ErrorOverlayComponent'
46 changes: 46 additions & 0 deletions editor/src/components/canvas/canvas-floating-toolbars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import { FlexRow } from '../../uuiui'
import { CanvasToolbar } from '../editor/canvas-toolbar'
import { Substores, useEditorState } from '../editor/store/store-hook'
import { ErrorOverlayComponent } from './canvas-error-overlay'
import { SafeModeErrorOverlay } from './canvas-wrapper-component'
import { CanvasStrategyPicker } from './controls/select-mode/canvas-strategy-picker'

export const CanvasFloatingToolbars = React.memo((props: { style: React.CSSProperties }) => {
const safeMode = useEditorState(
Substores.restOfEditor,
(store) => {
return store.editor.safeMode
},
'CanvasFloatingPanels safeMode',
)

return (
<FlexRow
style={{
position: 'absolute',
width: '100%',
height: '100%',
transform: 'translateZ(0)', // to keep this from tarnishing canvas render performance, we force it to a new layer
pointerEvents: 'none', // you need to re-enable pointerevents for the various overlays
...props.style,
}}
>
<FlexRow
style={{
position: 'absolute',
top: 0,
alignItems: 'flex-start',
margin: 10,
gap: 10,
}}
>
<CanvasToolbar />
<CanvasStrategyPicker />
</FlexRow>
{/* The error overlays are deliberately the last here so they hide other canvas UI */}
{safeMode ? <SafeModeErrorOverlay /> : <ErrorOverlayComponent />}
</FlexRow>
)
})
CanvasFloatingToolbars.displayName = 'CanvasFloatingToolbars'
84 changes: 8 additions & 76 deletions editor/src/components/canvas/canvas-wrapper-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import { useDispatch } from '../editor/store/dispatch-context'
import { shouldShowErrorOverlay } from './canvas-utils'
import { useErrorOverlayRecords } from '../../core/shared/runtime-report-logs'
import { FloatingPostActionMenu } from './controls/select-mode/post-action-menu'
import { FloatingPanelSizesAtom } from './floating-panels'
import { isFeatureEnabled } from '../../utils/feature-switches'
import { unless } from '../../utils/react-conditionals'
import type { StandardLonghandProperties } from 'csstype'
import { CanvasFloatingToolbars } from './canvas-floating-toolbars'

export function filterOldPasses(errorMessages: Array<ErrorMessage>): Array<ErrorMessage> {
let passTimes: { [key: string]: number } = {}
Expand Down Expand Up @@ -106,7 +108,6 @@ export const CanvasWrapperComponent = React.memo(() => {
const scale = useEditorState(Substores.canvas, (store) => store.editor.canvas.scale, 'scale')

const leftPanelWidthAtom = usePubSubAtomReadOnly(LeftPanelWidthAtom, AlwaysTrue)
const columnSize = usePubSubAtomReadOnly(FloatingPanelSizesAtom, AlwaysTrue)
const leftPanelWidth = React.useMemo(
() => (isNavigatorOverCanvas ? leftPanelWidthAtom + 10 : 0),
[leftPanelWidthAtom, isNavigatorOverCanvas],
Expand Down Expand Up @@ -162,33 +163,11 @@ export const CanvasWrapperComponent = React.memo(() => {
dispatch={dispatch}
/>
) : null}
<FlexRow
style={{
position: 'absolute',
width: '100%',
height: '100%',
transform: 'translateZ(0)', // to keep this from tarnishing canvas render performance, we force it to a new layer
pointerEvents: 'none', // you need to re-enable pointerevents for the various overlays
left: isFeatureEnabled('Draggable Floating Panels')
? columnSize.left
: leftPanelWidth + codeEditorWidth,
}}
>
<FlexRow
style={{
position: 'absolute',
top: 0,
alignItems: 'flex-start',
margin: 10,
gap: 10,
}}
>
<CanvasToolbar />
<CanvasStrategyPicker />
</FlexRow>
{/* The error overlays are deliberately the last here so they hide other canvas UI */}
{safeMode ? <SafeModeErrorOverlay /> : <ErrorOverlayComponent />}
</FlexRow>
{unless(
isFeatureEnabled('Draggable Floating Panels'),
<CanvasFloatingToolbars style={{ left: leftPanelWidth + codeEditorWidth }} />,
)}

<FlexRow
style={{
position: 'absolute',
Expand Down Expand Up @@ -217,53 +196,6 @@ export const CanvasWrapperComponent = React.memo(() => {
)
})

const ErrorOverlayComponent = React.memo(() => {
const { errorRecords, overlayErrors } = useErrorOverlayRecords()
const overlayWillShow = shouldShowErrorOverlay(errorRecords, overlayErrors)

const dispatch = useDispatch()

const onOpenFile = React.useCallback(
(path: string) => {
dispatch([openCodeEditorFile(path, true), setFocus('codeEditor')])
},
[dispatch],
)

const postActionSessionInProgressRef = useRefEditorState(
(store) => store.postActionInteractionSession != null,
)

React.useEffect(() => {
if (overlayWillShow) {
if (postActionSessionInProgressRef.current) {
return
}

// If this is showing, we need to clear any canvas drag state and apply the changes it would have resulted in,
// since that might have been the cause of the error being thrown, as well as switching back to select mode
setTimeout(() => {
// wrapping in a setTimeout so we don't dispatch from inside React lifecycle

dispatch([
CanvasActions.clearInteractionSession(true),
switchEditorMode(EditorModes.selectMode(null, false, 'none')),
clearHighlightedViews(),
])
}, 0)
}
}, [dispatch, overlayWillShow, postActionSessionInProgressRef])

return (
<ReactErrorOverlay
currentBuildErrorRecords={errorRecords}
currentRuntimeErrorRecords={overlayErrors}
onOpenFile={onOpenFile}
overlayOffset={0}
/>
)
})

export const SafeModeErrorOverlay = React.memo(() => {
const dispatch = useDispatch()
const onTryAgain = React.useCallback(() => {
Expand Down
Loading

0 comments on commit f6e2b65

Please sign in to comment.