mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-07-03 00:11:21 +02:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
|
import * as actions from '../actions/index.js';
|
||
|
import * as d2Tools from 'src/js/constants/d2Tools.js';
|
||
|
import * as contextTools from 'src/js/constants/contextTools.js';
|
||
|
// import createDebug from 'debug';
|
||
|
// const debug = createDebug('d3d:util:undoFilter');
|
||
|
|
||
|
const INCLUDE = [
|
||
|
`${actions.TRACE_FLOOD_FILL}_FULFILLED`,
|
||
|
`${actions.ADD_IMAGE}_FULFILLED`,
|
||
|
actions.TOGGLE_SELECT,
|
||
|
actions.TRANSFORM_END,
|
||
|
actions.MULTITOUCH_TRANSFORM_END,
|
||
|
actions.SELECT_ALL,
|
||
|
actions.DESELECT_ALL,
|
||
|
actions.STAMP,
|
||
|
actions.SELECT,
|
||
|
actions.D2_TEXT_ADD,
|
||
|
actions.CLEAR,
|
||
|
actions.TWIST_END,
|
||
|
actions.SCULPT_END,
|
||
|
actions.ADD_SCULPT_HANDLE,
|
||
|
actions.REMOVE_SCULPT_HANDLE,
|
||
|
actions.HEIGHT_END,
|
||
|
actions.DELETE_SELECTION,
|
||
|
actions.DUPLICATE_SELECTION,
|
||
|
actions.UNION,
|
||
|
actions.INTERSECT
|
||
|
];
|
||
|
|
||
|
const ACTION_INCLUDES = {
|
||
|
[actions.D2_DRAG_END]: [...d2Tools.SHAPE_TOOLS, ...d2Tools.PEN_TOOLS, d2Tools.ERASER],
|
||
|
[actions.D2_TAP]: [...d2Tools.SHAPE_TOOLS, d2Tools.BUCKET, d2Tools.ERASER]
|
||
|
};
|
||
|
|
||
|
const CONTEXT_TOOL_CHANGES = [
|
||
|
contextTools.ALIGN_LEFT,
|
||
|
contextTools.ALIGN_HORIZONTAL,
|
||
|
contextTools.ALIGN_RIGHT,
|
||
|
contextTools.ALIGN_TOP,
|
||
|
contextTools.ALIGN_VERTICAL,
|
||
|
contextTools.ALIGN_BOTTOM
|
||
|
];
|
||
|
|
||
|
export default function undoFilter(action, currentState) {
|
||
|
if (INCLUDE.indexOf(action.type) !== -1) return true;
|
||
|
if (ACTION_INCLUDES[action.type] && ACTION_INCLUDES[action.type].indexOf(currentState.d2.tool) !== -1) {
|
||
|
return true;
|
||
|
}
|
||
|
if (action.type === actions.CONTEXT_CHANGE_TOOL && CONTEXT_TOOL_CHANGES.includes(action.tool)) return true;
|
||
|
|
||
|
return false;
|
||
|
}
|