You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
2 years ago
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||
|
import { isLinearElement } from "../element/typeChecks";
|
||
|
import { ExcalidrawLinearElement } from "../element/types";
|
||
|
import { register } from "./register";
|
||
|
|
||
|
export const actionToggleLinearEditor = register({
|
||
|
name: "toggleLinearEditor",
|
||
|
trackEvent: {
|
||
|
category: "element",
|
||
|
},
|
||
2 years ago
|
predicate: (elements, appState, _, app) => {
|
||
|
const selectedElements = app.scene.getSelectedElements(appState);
|
||
2 years ago
|
if (selectedElements.length === 1 && isLinearElement(selectedElements[0])) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
perform(elements, appState, _, app) {
|
||
2 years ago
|
const selectedElement = app.scene.getSelectedElements({
|
||
|
selectedElementIds: appState.selectedElementIds,
|
||
|
includeBoundTextElement: true,
|
||
|
})[0] as ExcalidrawLinearElement;
|
||
2 years ago
|
|
||
|
const editingLinearElement =
|
||
|
appState.editingLinearElement?.elementId === selectedElement.id
|
||
|
? null
|
||
|
: new LinearElementEditor(selectedElement, app.scene);
|
||
|
return {
|
||
|
appState: {
|
||
|
...appState,
|
||
|
editingLinearElement,
|
||
|
},
|
||
|
commitToHistory: false,
|
||
|
};
|
||
|
},
|
||
2 years ago
|
contextItemLabel: (elements, appState, app) => {
|
||
|
const selectedElement = app.scene.getSelectedElements({
|
||
|
selectedElementIds: appState.selectedElementIds,
|
||
|
includeBoundTextElement: true,
|
||
|
})[0] as ExcalidrawLinearElement;
|
||
2 years ago
|
return appState.editingLinearElement?.elementId === selectedElement.id
|
||
|
? "labels.lineEditor.exit"
|
||
|
: "labels.lineEditor.edit";
|
||
|
},
|
||
|
});
|