Skip to content
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

Grid interactivity: Experimenting with drag and drop to set column start and row start #59490

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
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 Feb 29, 2024
4be75af
Remove text and icon from drop zone
noisysocks Feb 29, 2024
8d0160a
Don't obscure the in-between block drop zone
noisysocks Feb 29, 2024
59c3994
Output grid-start styling
noisysocks Feb 29, 2024
81f6936
Output grid-start styling
noisysocks Feb 29, 2024
ed4483a
Add Column Start and Row Start controls to block inspector
noisysocks Feb 29, 2024
b8e9a33
Merge branch 'add/grid-column-and-row-start' into add/grid-interactiv…
noisysocks Feb 29, 2024
2fb3f1b
Rename grid-visualizer dir to grid-interactivity
noisysocks Mar 1, 2024
f68c715
Use specificity instead of !important
noisysocks Mar 1, 2024
402eddc
Add 'Pin to grid' button
noisysocks Mar 1, 2024
8eaa61a
Remove weird blank line
noisysocks Mar 1, 2024
577a7eb
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks Mar 14, 2024
bfe3042
Remove pin button for now
noisysocks Mar 14, 2024
e62f090
Revert "Remove pin button for now"
noisysocks Mar 15, 2024
f6a9e0a
Make drop zone 8x8 at minimum
noisysocks Mar 15, 2024
7dcc874
Improve handling of resizing onto empty cells
noisysocks Mar 15, 2024
81463b4
Don't allow blocks with a >1 span to be dragged too close to the edge
noisysocks Mar 18, 2024
8fb6fd6
Delete accidental comment
noisysocks Mar 18, 2024
c9638ec
Treat a block as pinned if it has a column start **or** a row start
noisysocks Mar 18, 2024
5f4aaeb
Adjust toolbar button label if pinned
noisysocks Mar 18, 2024
1726d59
Fix visualizer not appearing when block inspector is closed
noisysocks Mar 18, 2024
0496060
Fix dragging in Chrome
noisysocks Mar 19, 2024
3ff1f86
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks Apr 11, 2024
8c1e9ee
Unpin when re-ordering blocks in the block list
noisysocks Apr 11, 2024
c3d1c1f
Disable dragging a block onto an occupied cell
noisysocks Apr 15, 2024
ff98a89
Split calculateGridRect
noisysocks Apr 16, 2024
665684b
Move the block instead of setting a row/column start when possible
noisysocks Apr 16, 2024
9d5940f
Merge remote-tracking branch 'origin/trunk' into add/grid-interactivi…
noisysocks Apr 16, 2024
2a3e588
Rename blockElement -> gridElement
noisysocks Apr 17, 2024
e675646
Don't moveBlockToPosition() for now. The algorithm needs to be robust
noisysocks Apr 17, 2024
d63b85b
Take span into account when validating drag
noisysocks Apr 17, 2024
073c281
Don't put pin toolbar button in a group
noisysocks Apr 17, 2024
ac5f050
Add translucent background to grid cells
noisysocks Apr 17, 2024
05b0392
Fix input max
noisysocks Apr 17, 2024
b70baee
(Not fully working:) Call moveToPosition() when moving a block to its…
noisysocks Apr 19, 2024
05900ce
Very very rough crack at drag to insert
noisysocks Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ export default function ChildLayoutControl( {
} }
value={ columnStart }
min={ 1 }
max={ parentLayout?.columnCount }
max={
parentLayout?.columnCount
? parentLayout.columnCount -
( columnSpan ?? 1 ) +
1
: undefined
}
/>
</FlexItem>
<FlexItem style={ { width: '50%' } }>
Expand All @@ -241,7 +247,13 @@ export default function ChildLayoutControl( {
} }
value={ rowStart }
min={ 1 }
max={ parentLayout?.columnCount }
max={
parentLayout?.rowCount
? parentLayout.rowCount -
( rowSpan ?? 1 ) +
1
: undefined
}
/>
</FlexItem>
</Flex>
Expand Down
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() {
noisysocks marked this conversation as resolved.
Show resolved Hide resolved
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>
);
}
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>
);
}
Loading
Loading