-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
181064b
commit f6e2b65
Showing
20 changed files
with
954 additions
and
1,572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.