-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add objectModified handler * feat: resize move add undo stack - middle commit * feat: resize move add undo stack - middle commit 2 * feat: one item undo redo prototype complate * feat: undo chage from group selection = #1 * feat: prototyping complete * feat: add selectionModifyHelper * feat: complate refactoring * refactor: complete refactoring * feat: added test for changeSelection command * test: add selectionModifyHelper test * chore: fix misspelling * chore: apply code review Co-authored-by: lja1018 <jaeeon.lim@nhn.com> Co-authored-by: jinwoo-kim-nhn <jw.kim@nhn.com>
- Loading branch information
1 parent
f9ae2fd
commit 09e5582
Showing
8 changed files
with
300 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @author NHN. FE Development Team <dl_javascript@nhn.com> | ||
* @fileoverview change selection | ||
*/ | ||
import commandFactory from '../factory/command'; | ||
import {Promise} from '../util'; | ||
import {commandNames} from '../consts'; | ||
import {getCachedUndoDataForDimension} from '../helper/selectionModifyHelper'; | ||
|
||
const command = { | ||
name: commandNames.CHANGE_SELECTION, | ||
|
||
execute(graphics, props) { | ||
if (this.isRedo) { | ||
props.forEach(prop => { | ||
graphics.setObjectProperties(prop.id, prop); | ||
}); | ||
} else { | ||
this.undoData = getCachedUndoDataForDimension(); | ||
} | ||
|
||
return Promise.resolve(); | ||
}, | ||
undo(graphics) { | ||
this.undoData.forEach(datum => { | ||
graphics.setObjectProperties(datum.id, datum); | ||
}); | ||
|
||
return Promise.resolve(); | ||
} | ||
}; | ||
|
||
commandFactory.register(command); | ||
|
||
export default command; |
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,84 @@ | ||
/** | ||
* @author NHN. FE Development Team <dl_javascript@nhn.com> | ||
* @fileoverview Selection modification helper | ||
*/ | ||
|
||
import {extend} from 'tui-code-snippet/src/js/object'; | ||
|
||
/** | ||
* Cached selection's info | ||
* @type {Array} | ||
* @private | ||
*/ | ||
let cachedUndoDataForChangeDimension = null; | ||
|
||
/** | ||
* Set cached undo data | ||
* @param {Array} undoData - selection object | ||
* @private | ||
*/ | ||
export function setCachedUndoDataForDimension(undoData) { | ||
cachedUndoDataForChangeDimension = undoData; | ||
} | ||
|
||
/** | ||
* Get cached undo data | ||
* @returns {Object} cached undo data | ||
* @private | ||
*/ | ||
export function getCachedUndoDataForDimension() { | ||
return cachedUndoDataForChangeDimension; | ||
} | ||
|
||
/** | ||
* Make undo data | ||
* @param {fabric.Object} obj - selection object | ||
* @param {Function} undoDatumMaker - make undo datum | ||
* @returns {Array} undoData | ||
* @private | ||
*/ | ||
export function makeSelectionUndoData(obj, undoDatumMaker) { | ||
let undoData; | ||
|
||
if (obj.type === 'activeSelection') { | ||
undoData = obj.getObjects().map(item => { | ||
const {angle, left, top} = item; | ||
|
||
obj.realizeTransform(item); | ||
const result = undoDatumMaker(item); | ||
|
||
item.set({ | ||
angle, | ||
left, | ||
top | ||
}); | ||
|
||
return result; | ||
}); | ||
} else { | ||
undoData = [undoDatumMaker(obj)]; | ||
} | ||
|
||
return undoData; | ||
} | ||
|
||
/** | ||
* Make undo datum | ||
* @param {number} id - object id | ||
* @param {fabric.Object} obj - selection object | ||
* @param {boolean} isSelection - whether or not object is selection | ||
* @returns {Object} undo datum | ||
* @private | ||
*/ | ||
export function makeSelectionUndoDatum(id, obj, isSelection) { | ||
return isSelection ? { | ||
id, | ||
width: obj.width, | ||
height: obj.height, | ||
top: obj.top, | ||
left: obj.left, | ||
angle: obj.angle, | ||
scaleX: obj.scaleX, | ||
scaleY: obj.scaleY | ||
} : extend({id}, obj); | ||
} |
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.