mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Prefer arrow functions and callbacks (#1210)
This commit is contained in:
parent
33fe223b5d
commit
c427aa3cce
64 changed files with 784 additions and 847 deletions
|
@ -6,10 +6,10 @@ import { getElementAbsoluteCoords, getElementBounds } from "../element";
|
|||
import { AppState } from "../types";
|
||||
import { newElementWith } from "../element/mutateElement";
|
||||
|
||||
export function getElementsWithinSelection(
|
||||
export const getElementsWithinSelection = (
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
selection: NonDeletedExcalidrawElement,
|
||||
) {
|
||||
) => {
|
||||
const [
|
||||
selectionX1,
|
||||
selectionY1,
|
||||
|
@ -29,12 +29,12 @@ export function getElementsWithinSelection(
|
|||
selectionY2 >= elementY2
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export function deleteSelectedElements(
|
||||
export const deleteSelectedElements = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState,
|
||||
) {
|
||||
) => {
|
||||
return {
|
||||
elements: elements.map((el) => {
|
||||
if (appState.selectedElementIds[el.id]) {
|
||||
|
@ -47,24 +47,24 @@ export function deleteSelectedElements(
|
|||
selectedElementIds: {},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export function isSomeElementSelected(
|
||||
export const isSomeElementSelected = (
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
): boolean {
|
||||
): boolean => {
|
||||
return elements.some((element) => appState.selectedElementIds[element.id]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns common attribute (picked by `getAttribute` callback) of selected
|
||||
* elements. If elements don't share the same value, returns `null`.
|
||||
*/
|
||||
export function getCommonAttributeOfSelectedElements<T>(
|
||||
export const getCommonAttributeOfSelectedElements = <T>(
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
getAttribute: (element: ExcalidrawElement) => T,
|
||||
): T | null {
|
||||
): T | null => {
|
||||
const attributes = Array.from(
|
||||
new Set(
|
||||
getSelectedElements(elements, appState).map((element) =>
|
||||
|
@ -73,20 +73,20 @@ export function getCommonAttributeOfSelectedElements<T>(
|
|||
),
|
||||
);
|
||||
return attributes.length === 1 ? attributes[0] : null;
|
||||
}
|
||||
};
|
||||
|
||||
export function getSelectedElements(
|
||||
export const getSelectedElements = (
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
) {
|
||||
) => {
|
||||
return elements.filter((element) => appState.selectedElementIds[element.id]);
|
||||
}
|
||||
};
|
||||
|
||||
export function getTargetElement(
|
||||
export const getTargetElement = (
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: AppState,
|
||||
) {
|
||||
) => {
|
||||
return appState.editingElement
|
||||
? [appState.editingElement]
|
||||
: getSelectedElements(elements, appState);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue