-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Grid interactivity: Experimenting with drag and drop to set column start and row start #59490
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
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0bd9683
Use DropZones in GridVisualizer to set positions of grid items
noisysocks 4be75af
Remove text and icon from drop zone
noisysocks 8d0160a
Don't obscure the in-between block drop zone
noisysocks 59c3994
Output grid-start styling
noisysocks 81f6936
Output grid-start styling
noisysocks ed4483a
Add Column Start and Row Start controls to block inspector
noisysocks b8e9a33
Merge branch 'add/grid-column-and-row-start' into add/grid-interactiv…
noisysocks 2fb3f1b
Rename grid-visualizer dir to grid-interactivity
noisysocks f68c715
Use specificity instead of !important
noisysocks 402eddc
Add 'Pin to grid' button
noisysocks 8eaa61a
Remove weird blank line
noisysocks 577a7eb
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks bfe3042
Remove pin button for now
noisysocks e62f090
Revert "Remove pin button for now"
noisysocks f6a9e0a
Make drop zone 8x8 at minimum
noisysocks 7dcc874
Improve handling of resizing onto empty cells
noisysocks 81463b4
Don't allow blocks with a >1 span to be dragged too close to the edge
noisysocks 8fb6fd6
Delete accidental comment
noisysocks c9638ec
Treat a block as pinned if it has a column start **or** a row start
noisysocks 5f4aaeb
Adjust toolbar button label if pinned
noisysocks 1726d59
Fix visualizer not appearing when block inspector is closed
noisysocks 0496060
Fix dragging in Chrome
noisysocks 3ff1f86
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks 8c1e9ee
Unpin when re-ordering blocks in the block list
noisysocks c3d1c1f
Disable dragging a block onto an occupied cell
noisysocks ff98a89
Split calculateGridRect
noisysocks 665684b
Move the block instead of setting a row/column start when possible
noisysocks 9d5940f
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks 2a3e588
Rename blockElement -> gridElement
noisysocks e675646
Don't moveBlockToPosition() for now. The algorithm needs to be robust
noisysocks d63b85b
Take span into account when validating drag
noisysocks 073c281
Don't put pin toolbar button in a group
noisysocks ac5f050
Add translucent background to grid cells
noisysocks 05b0392
Fix input max
noisysocks b70baee
(Not fully working:) Call moveToPosition() when moving a block to its…
noisysocks 05900ce
Very very rough crack at drag to insert
noisysocks 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
packages/block-editor/src/components/grid-interactivity/grid-item-pin-toolbar-item.js
This file contains hidden or 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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { pin as pinIcon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockControls from '../block-controls'; | ||
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs'; | ||
import { getGridItemRect } from './utils'; | ||
|
||
export function GridItemPinToolbarItem( { clientId, layout, onChange } ) { | ||
const blockElement = useBlockElement( clientId ); | ||
if ( ! blockElement ) { | ||
return null; | ||
} | ||
|
||
const isPinned = !! layout?.columnStart || !! layout?.rowStart; | ||
|
||
function unpinBlock() { | ||
onChange( { | ||
columnStart: undefined, | ||
rowStart: undefined, | ||
} ); | ||
} | ||
|
||
function pinBlock() { | ||
const rect = getGridItemRect( blockElement ); | ||
onChange( { | ||
columnStart: rect.columnStart, | ||
rowStart: rect.rowStart, | ||
} ); | ||
} | ||
|
||
return ( | ||
<BlockControls group="parent"> | ||
<ToolbarButton | ||
icon={ pinIcon } | ||
label={ | ||
isPinned ? __( 'Pinned to grid' ) : __( 'Pin to grid' ) | ||
} | ||
isPressed={ isPinned } | ||
onClick={ isPinned ? unpinBlock : pinBlock } | ||
/> | ||
</BlockControls> | ||
); | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/grid-interactivity/grid-item-resizer.js
This file contains hidden or 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,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ResizableBox } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs'; | ||
import BlockPopoverCover from '../block-popover/cover'; | ||
import { getGridRect } from './utils'; | ||
|
||
export function GridItemResizer( { clientId, onChange } ) { | ||
const blockElement = useBlockElement( clientId ); | ||
if ( ! blockElement ) { | ||
return null; | ||
} | ||
return ( | ||
<BlockPopoverCover | ||
className="block-editor-grid-item-resizer" | ||
clientId={ clientId } | ||
__unstablePopoverSlot="block-toolbar" | ||
> | ||
<ResizableBox | ||
className="block-editor-grid-item-resizer__box" | ||
size={ { | ||
width: '100%', | ||
height: '100%', | ||
} } | ||
enable={ { | ||
bottom: true, | ||
bottomLeft: false, | ||
bottomRight: false, | ||
left: false, | ||
right: true, | ||
top: false, | ||
topLeft: false, | ||
topRight: false, | ||
} } | ||
onResizeStop={ ( event, direction, boxElement ) => { | ||
const rect = getGridRect( | ||
blockElement.parentElement, | ||
new window.DOMRect( | ||
blockElement.offsetLeft, | ||
blockElement.offsetTop, | ||
boxElement.offsetWidth, | ||
boxElement.offsetHeight | ||
) | ||
); | ||
onChange( { | ||
columnSpan: rect.columnSpan, | ||
rowSpan: rect.rowSpan, | ||
} ); | ||
} } | ||
/> | ||
</BlockPopoverCover> | ||
); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.