import React from "react"; import { alignElements, Alignment } from "../align"; import { AlignBottomIcon, AlignLeftIcon, AlignRightIcon, AlignTopIcon, CenterHorizontallyIcon, CenterVerticallyIcon, } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { getElementMap, getNonDeletedElements } from "../element"; import { ExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { KEYS } from "../keys"; import { getSelectedElements, isSomeElementSelected } from "../scene"; import { AppState } from "../types"; import { getShortcutKey } from "../utils"; import { register } from "./register"; const enableActionGroup = ( elements: readonly ExcalidrawElement[], appState: AppState, ) => getSelectedElements(getNonDeletedElements(elements), appState).length > 1; const alignSelectedElements = ( elements: readonly ExcalidrawElement[], appState: Readonly, alignment: Alignment, ) => { const selectedElements = getSelectedElements( getNonDeletedElements(elements), appState, ); const updatedElements = alignElements(selectedElements, alignment); const updatedElementsMap = getElementMap(updatedElements); return elements.map((element) => updatedElementsMap[element.id] || element); }; export const actionAlignTop = register({ name: "alignTop", perform: (elements, appState) => { return { appState, elements: alignSelectedElements(elements, appState, { position: "start", axis: "y", }), commitToHistory: true, }; }, keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_UP, PanelComponent: ({ elements, appState, updateData }) => (