import { DistributeHorizontallyIcon, DistributeVerticallyIcon, } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { distributeElements, Distribution } from "../distribute"; import { getNonDeletedElements } from "../element"; import { ExcalidrawElement } from "../element/types"; import { updateFrameMembershipOfSelectedElements } from "../frame"; import { t } from "../i18n"; import { CODES, KEYS } from "../keys"; import { getSelectedElements, isSomeElementSelected } from "../scene"; import { AppState } from "../types"; import { arrayToMap, getShortcutKey } from "../utils"; import { register } from "./register"; const enableActionGroup = ( elements: readonly ExcalidrawElement[], appState: AppState, ) => { const selectedElements = getSelectedElements( getNonDeletedElements(elements), appState, ); return ( selectedElements.length > 1 && // TODO enable distributing frames when implemented properly !selectedElements.some((el) => el.type === "frame") ); }; const distributeSelectedElements = ( elements: readonly ExcalidrawElement[], appState: Readonly, distribution: Distribution, ) => { const selectedElements = getSelectedElements( getNonDeletedElements(elements), appState, ); const updatedElements = distributeElements(selectedElements, distribution); const updatedElementsMap = arrayToMap(updatedElements); return updateFrameMembershipOfSelectedElements( elements.map((element) => updatedElementsMap.get(element.id) || element), appState, ); }; export const distributeHorizontally = register({ name: "distributeHorizontally", trackEvent: { category: "element" }, perform: (elements, appState) => { return { appState, elements: distributeSelectedElements(elements, appState, { space: "between", axis: "x", }), commitToHistory: true, }; }, keyTest: (event) => !event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.H, PanelComponent: ({ elements, appState, updateData }) => (