-
Notifications
You must be signed in to change notification settings - Fork 384
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
Snapping Guidelines #3060
Merged
Merged
Snapping Guidelines #3060
Changes from 107 commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
8db5826
Snapping proof-of-concept
swissspidy 042c0f5
First pass at snapping while dragging
swissspidy a66ed1e
Merge branch 'develop' into add/2875-snapping
swissspidy 477b326
Bail early if we haven’t changed position
swissspidy e2a193d
Fix drag snaps
swissspidy 095fc85
Ensure clientId is passed down
swissspidy 11c0f6e
Rename var
swissspidy 76407cf
Merge branch 'develop' into add/2875-snapping
swissspidy 0bbaf1a
Take block rotation into account when building list of snap targets
swissspidy 5cab0d5
Add todos
swissspidy c0132df
Try clearing snap lines if there are old ones but not new ones
swissspidy d5b9947
Performance improvements for dragging
swissspidy d7ad7d7
Hide resize and rotation handles when dragging
swissspidy 28fb06d
Use getBoundingClientRect when dragging a rotated block
swissspidy 0c1dd96
Check for existing snap lines in reducer
swissspidy 6ddfa88
Return early when parent element wasn’t found
swissspidy be6cf10
Update return description
swissspidy 0632437
Update snapping position while dragging rotated blocks
swissspidy 3874521
Merge branch 'develop' into add/2875-snapping
swissspidy 693b7be
Allow disabling snapping when dragging
swissspidy 7f78824
Fix center calculation
swissspidy 1cca639
Add todo comment
swissspidy 329ff32
Make leftSnap const
swissspidy 416e26f
Add additional resizing snap targets
swissspidy 78ba592
Add some docs
swissspidy 2d1c5a7
Make resize snapping a bit more robust
swissspidy 9e16d06
Fix snap checks when dragging
swissspidy 929554c
Simplify drag-snapping a big
swissspidy 9d68191
Fix getting stuck with left position
miina 0350b01
Fix flickering for right horizontal snap.
miina 64e5ee1
Merge branch 'develop' into add/2875-snapping
swissspidy eb0f48c
Apply fixes for snapping and flickering for vertical snaps as well
swissspidy bb30343
Make findClosestSnap return null
swissspidy 86834b5
Show snap lines when resizing a rotated block
swissspidy ba3c859
Merge branch 'develop' into add/2875-snapping
swissspidy 4f7cc16
Merge branch 'develop' into add/2875-snapping
swissspidy 46b92e6
Merge branch 'develop' into add/2875-snapping
swissspidy 1ea5776
Use same position calculation also for non-rotated blocks
swissspidy 8b078ab
Remove unused consts
swissspidy 67a10f0
Resolve conflits.
miina 9d6a2b3
Merge branch 'develop' into add/2875-snapping
swissspidy 4a74bf7
Merge branch 'develop' into add/2875-snapping
swissspidy 2225b70
Remove specific resizing snap targets for now
swissspidy bbaf355
Fix import order
swissspidy ea5f263
Merge branch 'develop' into add/2875-snapping
swissspidy 7c32015
Remove now unneeded binds
swissspidy 063b24c
Remove actual snapping and only keep indicators for now
swissspidy 301b633
Reimplement snap lines via React Context API
barklund 781b6d9
Import React stuff from element package
swissspidy 85c2577
Lowercase file names
swissspidy 2b5e9e2
Merge branch 'develop' into add/2875-snapping
swissspidy 519efa9
Add missing HOC
swissspidy 3741f23
Prevent erroneously displaying a number instead of snap lines
swissspidy 8091a85
Merge branch 'develop' into add/2875-snapping
swissspidy f2ac5eb
Merge branch 'develop' into add/2875-snapping
swissspidy 57a6923
Get the correct dimensions in case the block is rotated
swissspidy 6ad1928
Add unit tests for new snapping context
barklund 6423e07
Merge branch 'develop' into add/2875-snapping
swissspidy 7ec9388
Update package lock file
swissspidy 398e4f2
Do not pass hasSnapLines to consuming component in SnapContext.Provider
swissspidy 7208db1
Update position values for resizing e2e test
swissspidy 981d6bd
Merge branch 'develop' into add/2875-snapping
swissspidy a606d91
Use helper function to make snapping code more DRY
swissspidy 8e1ebbd
Leverage getRelativeElementPosition helper
swissspidy 5523652
Merge branch 'develop' into add/2875-snapping
swissspidy 36d46a6
prop types fixes
swissspidy 9e42965
Take rotation into account for snapping during resizing
swissspidy 70d5326
Merge branch 'develop' into add/2875-snapping
swissspidy ff01f93
Lint fixes
swissspidy a7e38fd
xMerge branch 'develop' into add/2875-snapping
swissspidy c3c196b
Fix prop type for draggable
swissspidy 0a7b350
Fix prop type for BlockDraggable
swissspidy b66aa3b
Use correct blockElement cor CTA block
swissspidy 81a41d8
Resizing: Prevent flickering by doing snapping _after_ correcting the…
swissspidy 8030d5f
Merge branch 'develop' into add/2875-snapping
swissspidy 75edd44
Lint fix
swissspidy 4fd6193
Move import to new line
swissspidy a9e7e10
Merge branch 'develop' into add/2875-snapping
swissspidy eaef3d4
Fix selector in `getBlockInnerElement`
swissspidy 1198cbb
UX improvements for snap targets
swissspidy e9938c8
Use correct lower and upper bounds for horizontal/vertical snap lines
swissspidy a6de413
Merge branch 'develop' into add/2875-snapping
swissspidy b16e829
Merge branch 'develop' into add/2875-snapping
swissspidy cb3ab61
Make sure snap props are always functions
swissspidy dc8f7d1
Reduce duplicated code
swissspidy 0170cd8
Simplify center and start/end calculations
swissspidy 2b1f977
Get rid of showSnapLines / hideSnapLines logic
swissspidy 5ae88e7
Make sure selector is mocked when importing function
swissspidy 9b4eb81
Moved snap line calculation to helper functions
barklund 9bc8873
Add some tests for findClosestSnap
swissspidy 9ab9c5c
Add test for getRelativeElementPosition
swissspidy 5251aaa
Fix inverted condition to address duplicated snap line issue
swissspidy 8b7a2aa
Add tests for createSnapList
swissspidy 42f205b
Merge branch 'develop' into add/2875-snapping
swissspidy 6815295
Add a simple test for getSnapCalculatorByDimension
swissspidy e5dfb1b
Merge branch 'develop' into add/2875-snapping
swissspidy 1d09043
Merge branch 'develop' into add/2875-snapping
swissspidy cb5c3c3
Fix eported name for isCTABlock
swissspidy afc7ef7
Use isCTABlock helper in more places
swissspidy 11eab12
Merge branch 'develop' into add/2875-snapping
swissspidy 9515bed
Reorganised snap-related helpers
barklund ebff740
Extracted best snap finder to helper function
barklund aca7268
Added unit tests for `getBestMatch` and `getBestSnapLines`
barklund 4e4a6b5
Merge branch 'develop' into add/2875-snapping
swissspidy 3cb2565
Lint fixes
swissspidy a661493
Optimize resizable snapping references
barklund f32cc1b
Merge branch 'develop' into add/2875-snapping
swissspidy 1852207
Make sure snap lines are above draggable overlay
swissspidy 380673c
Merge branch 'develop' into add/2875-snapping
swissspidy 2e2dc62
Update snapshot
swissspidy 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
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,77 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG } from '@wordpress/components'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
import { createContext, useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { STORY_PAGE_INNER_HEIGHT, STORY_PAGE_INNER_WIDTH } from '../../constants'; | ||
|
||
const SnapContext = createContext(); | ||
|
||
const Snapping = ( { children } ) => { | ||
const [ snapLines, setSnapLines ] = useState( [] ); | ||
|
||
const clearSnapLines = () => setSnapLines( [] ); | ||
|
||
const context = { | ||
setSnapLines, | ||
snapLines, | ||
clearSnapLines, | ||
}; | ||
|
||
return ( | ||
<SnapContext.Provider value={ context }> | ||
{ children } | ||
{ Boolean( snapLines.length ) && ( | ||
<SVG | ||
viewBox={ `0 0 ${ STORY_PAGE_INNER_WIDTH } ${ STORY_PAGE_INNER_HEIGHT }` } | ||
style={ { | ||
position: 'absolute', | ||
top: 0, | ||
pointerEvents: 'none', | ||
} } | ||
> | ||
{ snapLines.map( ( [ [ x1, y1 ], [ x2, y2 ] ], index ) => ( | ||
<line | ||
key={ index } | ||
x1={ x1 } | ||
y1={ y1 } | ||
x2={ x2 } | ||
y2={ y2 } | ||
stroke="red" | ||
pointerEvents="none" | ||
/> | ||
) ) } | ||
</SVG> | ||
) } | ||
</SnapContext.Provider> | ||
); | ||
}; | ||
|
||
Snapping.propTypes = { | ||
children: PropTypes.object, | ||
}; | ||
|
||
export default Snapping; | ||
|
||
export const withSnapContext = createHigherOrderComponent( | ||
( WrappedComponent ) => ( props ) => ( | ||
<SnapContext.Consumer> | ||
{ | ||
( snappingProps ) => ( | ||
<WrappedComponent { ...props } { ...snappingProps } /> | ||
) | ||
} | ||
</SnapContext.Consumer> | ||
), | ||
'withSnapContext', | ||
); |
13 changes: 13 additions & 0 deletions
13
assets/src/stories-editor/components/contexts/test/__snapshots__/snapping.js.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Snapping should render a single snap line correctly when set 1`] = ` | ||
<line | ||
key="0" | ||
pointerEvents="none" | ||
stroke="red" | ||
x1={0} | ||
x2={100} | ||
y1={100} | ||
y2={100} | ||
/> | ||
`; |
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.
Why have a button that disables the snaps? Is this documented anywhere? How will users know about this?