-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #620 from taye/feat-snap-edges
snapEdges modifier
- Loading branch information
Showing
13 changed files
with
204 additions
and
55 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
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
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,75 @@ | ||
/** | ||
* @module modifiers/snapEdges | ||
* | ||
* @description | ||
* This module allows snapping of the edges of targets during resize | ||
* interactions. | ||
* | ||
* @example | ||
* interact(target).resizable({ | ||
* snapEdges: { | ||
* targets: [interact.snappers.grid({ x: 100, y: 50 })], | ||
* }, | ||
* }); | ||
* | ||
* interact(target).resizable({ | ||
* snapEdges: { | ||
* targets: [ | ||
* interact.snappers.grid({ | ||
* top: 50, | ||
* left: 50, | ||
* bottom: 100, | ||
* right: 100, | ||
* }), | ||
* ], | ||
* }, | ||
* }); | ||
*/ | ||
|
||
import clone from '@interactjs/utils/clone'; | ||
import extend from '@interactjs/utils/extend'; | ||
import snapSize from './snapSize'; | ||
|
||
function init (scope) { | ||
const { | ||
modifiers, | ||
defaults, | ||
} = scope; | ||
|
||
modifiers.snapEdges = snapEdges; | ||
modifiers.names.push('snapEdges'); | ||
|
||
defaults.perAction.snapEdges = snapEdges.defaults; | ||
} | ||
|
||
function start (arg) { | ||
const edges = arg.interaction.prepared.edges; | ||
|
||
if (!edges) { return null; } | ||
|
||
arg.status.targetFields = arg.status.targetFields || [ | ||
[edges.left ? 'left' : 'right', edges.top ? 'top' : 'bottom'], | ||
]; | ||
|
||
return snapSize.start(arg); | ||
} | ||
|
||
function set (arg) { | ||
return snapSize.set(arg); | ||
} | ||
|
||
function modifyCoords (arg) { | ||
snapSize.modifyCoords(arg); | ||
} | ||
|
||
const snapEdges = { | ||
init, | ||
start, | ||
set, | ||
modifyCoords, | ||
defaults: extend(clone(snapSize.defaults), { | ||
offset: { x: 0, y: 0 }, | ||
}), | ||
}; | ||
|
||
export default snapEdges; |
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.