mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
* Disable text selection * Set content-editable=plaintext-only to disable Touch Bar formatting buttons * Enlarge resize handle tap targets for pen/touch * Make the lock button a button in mobile mode * Use icons instead of Unicode characters; add an alternate toolbar for creating multipoint lines * Allow buttons to hide themselves * Fix heuristic for showing shape actions * Refactor icons * Fix label for edit button * Switch edit button icon * Remove lock button on mobile * Add language selector on mobile * Fix showing edit button on mobile * Fix showing edit button on mobile, part 2 * Fix handle touch regions * Fix scroll-back button position * Allow using the text tool on a text object to start editing it * Fix deletion of last point in line
68 lines
2 KiB
TypeScript
68 lines
2 KiB
TypeScript
import { Action } from "./types";
|
|
import { KEYS } from "../keys";
|
|
import { clearSelection } from "../scene";
|
|
import { isInvisiblySmallElement } from "../element";
|
|
import { resetCursor } from "../utils";
|
|
import React from "react";
|
|
import { ToolButton } from "../components/ToolButton";
|
|
import { done } from "../components/icons";
|
|
import { t } from "../i18n";
|
|
|
|
export const actionFinalize: Action = {
|
|
name: "finalize",
|
|
perform: (elements, appState) => {
|
|
let newElements = clearSelection(elements);
|
|
if (window.document.activeElement instanceof HTMLElement) {
|
|
window.document.activeElement.blur();
|
|
}
|
|
if (appState.multiElement) {
|
|
// pen and mouse have hover
|
|
if (appState.lastPointerDownWith !== "touch") {
|
|
appState.multiElement.points = appState.multiElement.points.slice(
|
|
0,
|
|
appState.multiElement.points.length - 1,
|
|
);
|
|
}
|
|
if (isInvisiblySmallElement(appState.multiElement)) {
|
|
newElements = newElements.slice(0, -1);
|
|
}
|
|
appState.multiElement.shape = null;
|
|
}
|
|
if (!appState.elementLocked || !appState.multiElement) {
|
|
resetCursor();
|
|
}
|
|
return {
|
|
elements: newElements,
|
|
appState: {
|
|
...appState,
|
|
elementType:
|
|
appState.elementLocked && appState.multiElement
|
|
? appState.elementType
|
|
: "selection",
|
|
draggingElement: null,
|
|
multiElement: null,
|
|
},
|
|
};
|
|
},
|
|
keyTest: (event, appState) =>
|
|
(event.key === KEYS.ESCAPE &&
|
|
!appState.draggingElement &&
|
|
appState.multiElement === null) ||
|
|
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
|
|
appState.multiElement !== null),
|
|
PanelComponent: ({ appState, updateData }) => (
|
|
<div
|
|
style={{
|
|
visibility: appState.multiElement != null ? "visible" : "hidden",
|
|
}}
|
|
>
|
|
<ToolButton
|
|
type="button"
|
|
icon={done}
|
|
title={t("buttons.done")}
|
|
aria-label={t("buttons.done")}
|
|
onClick={() => updateData(null)}
|
|
/>
|
|
</div>
|
|
),
|
|
};
|