mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Prefer arrow functions (#2344)
This commit is contained in:
parent
e05acd6fd9
commit
a20f3240fd
19 changed files with 304 additions and 336 deletions
|
@ -2,11 +2,11 @@ import { GroupId, ExcalidrawElement, NonDeleted } from "./element/types";
|
|||
import { AppState } from "./types";
|
||||
import { getSelectedElements } from "./scene";
|
||||
|
||||
export function selectGroup(
|
||||
export const selectGroup = (
|
||||
groupId: GroupId,
|
||||
appState: AppState,
|
||||
elements: readonly NonDeleted<ExcalidrawElement>[],
|
||||
): AppState {
|
||||
): AppState => {
|
||||
const elementsInGroup = elements.filter((element) =>
|
||||
element.groupIds.includes(groupId),
|
||||
);
|
||||
|
@ -35,42 +35,38 @@ export function selectGroup(
|
|||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If the element's group is selected, don't render an individual
|
||||
* selection border around it.
|
||||
*/
|
||||
export function isSelectedViaGroup(
|
||||
export const isSelectedViaGroup = (
|
||||
appState: AppState,
|
||||
element: ExcalidrawElement,
|
||||
) {
|
||||
return getSelectedGroupForElement(appState, element) != null;
|
||||
}
|
||||
) => getSelectedGroupForElement(appState, element) != null;
|
||||
|
||||
export const getSelectedGroupForElement = (
|
||||
appState: AppState,
|
||||
element: ExcalidrawElement,
|
||||
) => {
|
||||
return element.groupIds
|
||||
) =>
|
||||
element.groupIds
|
||||
.filter((groupId) => groupId !== appState.editingGroupId)
|
||||
.find((groupId) => appState.selectedGroupIds[groupId]);
|
||||
};
|
||||
|
||||
export function getSelectedGroupIds(appState: AppState): GroupId[] {
|
||||
return Object.entries(appState.selectedGroupIds)
|
||||
export const getSelectedGroupIds = (appState: AppState): GroupId[] =>
|
||||
Object.entries(appState.selectedGroupIds)
|
||||
.filter(([groupId, isSelected]) => isSelected)
|
||||
.map(([groupId, isSelected]) => groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* When you select an element, you often want to actually select the whole group it's in, unless
|
||||
* you're currently editing that group.
|
||||
*/
|
||||
export function selectGroupsForSelectedElements(
|
||||
export const selectGroupsForSelectedElements = (
|
||||
appState: AppState,
|
||||
elements: readonly NonDeleted<ExcalidrawElement>[],
|
||||
): AppState {
|
||||
): AppState => {
|
||||
let nextAppState = { ...appState };
|
||||
|
||||
const selectedElements = getSelectedElements(elements, appState);
|
||||
|
@ -91,7 +87,7 @@ export function selectGroupsForSelectedElements(
|
|||
}
|
||||
|
||||
return nextAppState;
|
||||
}
|
||||
};
|
||||
|
||||
export const editGroupForSelectedElement = (
|
||||
appState: AppState,
|
||||
|
@ -107,29 +103,24 @@ export const editGroupForSelectedElement = (
|
|||
};
|
||||
};
|
||||
|
||||
export function isElementInGroup(element: ExcalidrawElement, groupId: string) {
|
||||
return element.groupIds.includes(groupId);
|
||||
}
|
||||
export const isElementInGroup = (element: ExcalidrawElement, groupId: string) =>
|
||||
element.groupIds.includes(groupId);
|
||||
|
||||
export function getElementsInGroup(
|
||||
export const getElementsInGroup = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
groupId: string,
|
||||
) {
|
||||
return elements.filter((element) => isElementInGroup(element, groupId));
|
||||
}
|
||||
) => elements.filter((element) => isElementInGroup(element, groupId));
|
||||
|
||||
export function getSelectedGroupIdForElement(
|
||||
export const getSelectedGroupIdForElement = (
|
||||
element: ExcalidrawElement,
|
||||
selectedGroupIds: { [groupId: string]: boolean },
|
||||
) {
|
||||
return element.groupIds.find((groupId) => selectedGroupIds[groupId]);
|
||||
}
|
||||
) => element.groupIds.find((groupId) => selectedGroupIds[groupId]);
|
||||
|
||||
export function getNewGroupIdsForDuplication(
|
||||
export const getNewGroupIdsForDuplication = (
|
||||
groupIds: ExcalidrawElement["groupIds"],
|
||||
editingGroupId: AppState["editingGroupId"],
|
||||
mapper: (groupId: GroupId) => GroupId,
|
||||
) {
|
||||
) => {
|
||||
const copy = [...groupIds];
|
||||
const positionOfEditingGroupId = editingGroupId
|
||||
? groupIds.indexOf(editingGroupId)
|
||||
|
@ -141,13 +132,13 @@ export function getNewGroupIdsForDuplication(
|
|||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
};
|
||||
|
||||
export function addToGroup(
|
||||
export const addToGroup = (
|
||||
prevGroupIds: ExcalidrawElement["groupIds"],
|
||||
newGroupId: GroupId,
|
||||
editingGroupId: AppState["editingGroupId"],
|
||||
) {
|
||||
) => {
|
||||
// insert before the editingGroupId, or push to the end.
|
||||
const groupIds = [...prevGroupIds];
|
||||
const positionOfEditingGroupId = editingGroupId
|
||||
|
@ -157,11 +148,9 @@ export function addToGroup(
|
|||
positionOfEditingGroupId > -1 ? positionOfEditingGroupId : groupIds.length;
|
||||
groupIds.splice(positionToInsert, 0, newGroupId);
|
||||
return groupIds;
|
||||
}
|
||||
};
|
||||
|
||||
export function removeFromSelectedGroups(
|
||||
export const removeFromSelectedGroups = (
|
||||
groupIds: ExcalidrawElement["groupIds"],
|
||||
selectedGroupIds: { [groupId: string]: boolean },
|
||||
) {
|
||||
return groupIds.filter((groupId) => !selectedGroupIds[groupId]);
|
||||
}
|
||||
) => groupIds.filter((groupId) => !selectedGroupIds[groupId]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue