refactor: rename elementType to activeTool and make it an object (#4968)

* refactor: rename elementType to activeTool

* update docs

* fix snap

* update activeToll to be an object and review fixes

* fix tests

* fix
This commit is contained in:
Aakansha Doshi 2022-03-25 20:46:01 +05:30 committed by GitHub
parent 2209e2c1e8
commit 127af9db23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 364 additions and 207 deletions

View file

@ -68,8 +68,10 @@ export const actionClearCanvas = register({
gridSize: appState.gridSize,
showStats: appState.showStats,
pasteDialog: appState.pasteDialog,
elementType:
appState.elementType === "image" ? "selection" : appState.elementType,
activeTool:
appState.activeTool.type === "image"
? { type: "selection" }
: appState.activeTool,
},
commitToHistory: true,
};
@ -299,7 +301,7 @@ export const actionErase = register({
...appState,
selectedElementIds: {},
selectedGroupIds: {},
elementType: isEraserActive(appState) ? "selection" : "eraser",
activeTool: { type: isEraserActive(appState) ? "selection" : "eraser" },
},
commitToHistory: true,
};

View file

@ -133,7 +133,7 @@ export const actionDeleteSelected = register({
elements: nextElements,
appState: {
...nextAppState,
elementType: "selection",
activeTool: { type: "selection" },
multiElement: null,
},
commitToHistory: isSomeElementSelected(

View file

@ -119,13 +119,13 @@ export const actionFinalize = register({
);
}
if (!appState.elementLocked && appState.elementType !== "freedraw") {
if (!appState.elementLocked && appState.activeTool.type !== "freedraw") {
appState.selectedElementIds[multiPointElement.id] = true;
}
}
if (
(!appState.elementLocked && appState.elementType !== "freedraw") ||
(!appState.elementLocked && appState.activeTool.type !== "freedraw") ||
!multiPointElement
) {
resetCursor(canvas);
@ -135,11 +135,11 @@ export const actionFinalize = register({
elements: newElements,
appState: {
...appState,
elementType:
(appState.elementLocked || appState.elementType === "freedraw") &&
activeTool:
(appState.elementLocked || appState.activeTool.type === "freedraw") &&
multiPointElement
? appState.elementType
: "selection",
? appState.activeTool
: { type: "selection" },
draggingElement: null,
multiElement: null,
editingElement: null,
@ -148,7 +148,7 @@ export const actionFinalize = register({
selectedElementIds:
multiPointElement &&
!appState.elementLocked &&
appState.elementType !== "freedraw"
appState.activeTool.type !== "freedraw"
? {
...appState.selectedElementIds,
[multiPointElement.id]: true,
@ -156,7 +156,7 @@ export const actionFinalize = register({
: appState.selectedElementIds,
pendingImageElement: null,
},
commitToHistory: appState.elementType === "freedraw",
commitToHistory: appState.activeTool.type === "freedraw",
};
},
keyTest: (event, appState) =>

View file

@ -847,10 +847,10 @@ export const actionChangeSharpness = register({
);
const shouldUpdateForNonLinearElements = targetElements.length
? targetElements.every((el) => !isLinearElement(el))
: !isLinearElementType(appState.elementType);
: !isLinearElementType(appState.activeTool.type);
const shouldUpdateForLinearElements = targetElements.length
? targetElements.every(isLinearElement)
: isLinearElementType(appState.elementType);
: isLinearElementType(appState.activeTool.type);
return {
elements: changeProperty(elements, appState, (el) =>
newElementWith(el, {
@ -890,8 +890,8 @@ export const actionChangeSharpness = register({
elements,
appState,
(element) => element.strokeSharpness,
(canChangeSharpness(appState.elementType) &&
(isLinearElementType(appState.elementType)
(canChangeSharpness(appState.activeTool.type) &&
(isLinearElementType(appState.activeTool.type)
? appState.currentItemLinearStrokeSharpness
: appState.currentItemStrokeSharpness)) ||
null,