|
@@ -13,19 +13,18 @@ import { ExcalidrawElement } from "../element/types";
|
|
|
import { updateFrameMembershipOfSelectedElements } from "../frame";
|
|
|
import { t } from "../i18n";
|
|
|
import { KEYS } from "../keys";
|
|
|
-import { getSelectedElements, isSomeElementSelected } from "../scene";
|
|
|
-import { AppState } from "../types";
|
|
|
+import { isSomeElementSelected } from "../scene";
|
|
|
+import { AppClassProperties, AppState } from "../types";
|
|
|
import { arrayToMap, getShortcutKey } from "../utils";
|
|
|
import { register } from "./register";
|
|
|
|
|
|
const alignActionsPredicate = (
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
appState: AppState,
|
|
|
+ _: unknown,
|
|
|
+ app: AppClassProperties,
|
|
|
) => {
|
|
|
- const selectedElements = getSelectedElements(
|
|
|
- getNonDeletedElements(elements),
|
|
|
- appState,
|
|
|
- );
|
|
|
+ const selectedElements = app.scene.getSelectedElements(appState);
|
|
|
return (
|
|
|
selectedElements.length > 1 &&
|
|
|
// TODO enable aligning frames when implemented properly
|
|
@@ -36,12 +35,10 @@ const alignActionsPredicate = (
|
|
|
const alignSelectedElements = (
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
appState: Readonly<AppState>,
|
|
|
+ app: AppClassProperties,
|
|
|
alignment: Alignment,
|
|
|
) => {
|
|
|
- const selectedElements = getSelectedElements(
|
|
|
- getNonDeletedElements(elements),
|
|
|
- appState,
|
|
|
- );
|
|
|
+ const selectedElements = app.scene.getSelectedElements(appState);
|
|
|
|
|
|
const updatedElements = alignElements(selectedElements, alignment);
|
|
|
|
|
@@ -50,6 +47,7 @@ const alignSelectedElements = (
|
|
|
return updateFrameMembershipOfSelectedElements(
|
|
|
elements.map((element) => updatedElementsMap.get(element.id) || element),
|
|
|
appState,
|
|
|
+ app,
|
|
|
);
|
|
|
};
|
|
|
|
|
@@ -57,10 +55,10 @@ export const actionAlignTop = register({
|
|
|
name: "alignTop",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "start",
|
|
|
axis: "y",
|
|
|
}),
|
|
@@ -69,9 +67,9 @@ export const actionAlignTop = register({
|
|
|
},
|
|
|
keyTest: (event) =>
|
|
|
event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_UP,
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={AlignTopIcon}
|
|
|
onClick={() => updateData(null)}
|
|
@@ -88,10 +86,10 @@ export const actionAlignBottom = register({
|
|
|
name: "alignBottom",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "end",
|
|
|
axis: "y",
|
|
|
}),
|
|
@@ -100,9 +98,9 @@ export const actionAlignBottom = register({
|
|
|
},
|
|
|
keyTest: (event) =>
|
|
|
event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_DOWN,
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={AlignBottomIcon}
|
|
|
onClick={() => updateData(null)}
|
|
@@ -119,10 +117,10 @@ export const actionAlignLeft = register({
|
|
|
name: "alignLeft",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "start",
|
|
|
axis: "x",
|
|
|
}),
|
|
@@ -131,9 +129,9 @@ export const actionAlignLeft = register({
|
|
|
},
|
|
|
keyTest: (event) =>
|
|
|
event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_LEFT,
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={AlignLeftIcon}
|
|
|
onClick={() => updateData(null)}
|
|
@@ -150,10 +148,10 @@ export const actionAlignRight = register({
|
|
|
name: "alignRight",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "end",
|
|
|
axis: "x",
|
|
|
}),
|
|
@@ -162,9 +160,9 @@ export const actionAlignRight = register({
|
|
|
},
|
|
|
keyTest: (event) =>
|
|
|
event[KEYS.CTRL_OR_CMD] && event.shiftKey && event.key === KEYS.ARROW_RIGHT,
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={AlignRightIcon}
|
|
|
onClick={() => updateData(null)}
|
|
@@ -181,19 +179,19 @@ export const actionAlignVerticallyCentered = register({
|
|
|
name: "alignVerticallyCentered",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "center",
|
|
|
axis: "y",
|
|
|
}),
|
|
|
commitToHistory: true,
|
|
|
};
|
|
|
},
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={CenterVerticallyIcon}
|
|
|
onClick={() => updateData(null)}
|
|
@@ -208,19 +206,19 @@ export const actionAlignHorizontallyCentered = register({
|
|
|
name: "alignHorizontallyCentered",
|
|
|
trackEvent: { category: "element" },
|
|
|
predicate: alignActionsPredicate,
|
|
|
- perform: (elements, appState) => {
|
|
|
+ perform: (elements, appState, _, app) => {
|
|
|
return {
|
|
|
appState,
|
|
|
- elements: alignSelectedElements(elements, appState, {
|
|
|
+ elements: alignSelectedElements(elements, appState, app, {
|
|
|
position: "center",
|
|
|
axis: "x",
|
|
|
}),
|
|
|
commitToHistory: true,
|
|
|
};
|
|
|
},
|
|
|
- PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
+ PanelComponent: ({ elements, appState, updateData, app }) => (
|
|
|
<ToolButton
|
|
|
- hidden={!alignActionsPredicate(elements, appState)}
|
|
|
+ hidden={!alignActionsPredicate(elements, appState, null, app)}
|
|
|
type="button"
|
|
|
icon={CenterHorizontallyIcon}
|
|
|
onClick={() => updateData(null)}
|