-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore/mini grid design fixes #4275
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4ab977
changing the padding around window borders to 8px
balazsbajorics 9c2c2c2
adding two big pane reorder drag targets over the canvas
balazsbajorics 863c0f5
TitleBarCode
balazsbajorics a55ea01
Merge branch 'master' into chore/mini-grid-design-fixes
balazsbajorics 374aceb
do not show the navigator DND preview when dragging the panels and no…
balazsbajorics dae5e97
re-enable canDrop check for Pane reorder
balazsbajorics 62ed63a
oops we accidentally mutated the original layout
balazsbajorics 7fce925
working minimize maximize buttons for the code editor
balazsbajorics 6b9984a
Update editor/src/components/titlebar/title-bar.tsx
balazsbajorics File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
|
@@ -10,8 +10,9 @@ import { | |
} from '../inspector/common/inspector-utils' | ||
import invariant from '../../third-party/remix/invariant' | ||
import { useKeepShallowReferenceEquality } from '../../utils/react-performance' | ||
import { atom, useAtom, useAtomValue } from 'jotai' | ||
import { atom, useAtom, useAtomValue, useSetAtom, useStore } from 'jotai' | ||
import immutableUpdate from 'immutability-helper' | ||
import { deepFreeze } from '../../utils/deep-freeze' | ||
|
||
export const GridMenuWidth = 268 | ||
export const GridMenuMinWidth = 200 | ||
|
@@ -23,9 +24,9 @@ export const NumberOfColumns = 4 | |
export const IndexOfCanvas = 2 | ||
|
||
export const GridPanelVerticalGapHalf = 6 | ||
export const GridVerticalExtraPadding = 4 | ||
export const GridVerticalExtraPadding = -4 | ||
export const GridPanelHorizontalGapHalf = 6 | ||
export const GridHorizontalExtraPadding = 4 | ||
export const GridHorizontalExtraPadding = -4 | ||
|
||
export const ExtraHorizontalDropTargetPadding = 45 | ||
|
||
|
@@ -160,6 +161,8 @@ export function updateLayout( | |
const panelToInsert = storedPanel(paneToMove) | ||
|
||
function insertPanel(layout: StoredLayout) { | ||
deepFreeze(layout) | ||
|
||
if (update.type === 'before-column' || update.type === 'after-column') { | ||
const atLeastOneEmptyColumn = layout.some((col) => col.panels.length === 0) | ||
if (!atLeastOneEmptyColumn) { | ||
|
@@ -189,23 +192,21 @@ export function updateLayout( | |
const working = [...layout] | ||
|
||
// insert | ||
working[update.columnIndex].panels = insert( | ||
update.indexInColumn, | ||
panelToInsert, | ||
working[update.columnIndex].panels, | ||
) | ||
working[update.columnIndex] = { | ||
...working[update.columnIndex], | ||
panels: insert(update.indexInColumn, panelToInsert, working[update.columnIndex].panels), | ||
} | ||
|
||
return removeOldPanel(working) | ||
} | ||
if (update.type === 'after-index') { | ||
const working = [...layout] | ||
|
||
// insert | ||
working[update.columnIndex].panels = insert( | ||
update.indexInColumn + 1, | ||
panelToInsert, | ||
working[update.columnIndex].panels, | ||
) | ||
working[update.columnIndex] = { | ||
...working[update.columnIndex], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracting out the existing value into a variable would probably make this a little cleaner. |
||
panels: insert(update.indexInColumn + 1, panelToInsert, working[update.columnIndex].panels), | ||
} | ||
|
||
return removeOldPanel(working) | ||
} | ||
|
@@ -259,6 +260,65 @@ export function updateLayout( | |
return withEmptyColumnsInMiddle | ||
} | ||
|
||
export function useUpdateGridPanelLayout(): (panelName: PanelName, update: LayoutUpdate) => void { | ||
const setStoredState = useSetAtom(GridPanelsStateAtom) | ||
|
||
return React.useCallback( | ||
(panelName: PanelName, update: LayoutUpdate) => { | ||
setStoredState((stored) => { | ||
const paneToMove: StoredPanel = (() => { | ||
for (const column of stored) { | ||
for (const panel of column.panels) { | ||
if (panel.name === panelName) { | ||
return panel | ||
} | ||
} | ||
} | ||
throw new Error(`Invariant error: we should have found a panel by now: '${panelName}'`) | ||
})() | ||
return updateLayout(stored, paneToMove, update) | ||
}) | ||
}, | ||
[setStoredState], | ||
) | ||
} | ||
|
||
export function useUpdateGridPanelLayoutPutCodeEditorBelowNavigator(): () => void { | ||
const setStoredState = useSetAtom(GridPanelsStateAtom) | ||
|
||
return React.useCallback(() => { | ||
setStoredState((stored) => { | ||
const codeEditorPane: StoredPanel = (() => { | ||
for (const column of stored) { | ||
for (const panel of column.panels) { | ||
if (panel.name === 'code-editor') { | ||
return panel | ||
} | ||
} | ||
} | ||
throw new Error('Invariant error: we should have found a code-editor panel by now') | ||
})() | ||
const update: LayoutUpdate = (() => { | ||
for (let columnIndex = 0; columnIndex < stored.length; columnIndex++) { | ||
const column = stored[columnIndex] | ||
for (let indexInColumn = 0; indexInColumn < column.panels.length; indexInColumn++) { | ||
const panel = column.panels[indexInColumn] | ||
if (panel.name === 'navigator') { | ||
return { | ||
type: 'after-index', | ||
columnIndex: columnIndex, | ||
indexInColumn: indexInColumn, | ||
} | ||
} | ||
} | ||
} | ||
throw new Error('Invariant error: we should have found a navigator panel by now') | ||
})() | ||
return updateLayout(stored, codeEditorPane, update) | ||
}) | ||
}, [setStoredState]) | ||
} | ||
|
||
export function useColumnWidths(): [ | ||
Array<number>, | ||
(columnIndex: number, newWidth: number) => void, | ||
|
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting out the existing value into a variable would probably make this a little cleaner.