Compare commits

...

3 Commits

Author SHA1 Message Date
zsviczian
407ee62a5c
merge upstream (#5821)
* fix: hide canvas-modifying UI in view mode (#5815)

* fix: hide canvas-modifying UI in view mode

* add class for better targeting

* fix missing `key`

* fix: useOutsideClick not working in view mode

* fix: Corrected typo in toggle theme shortcut (#5813)

* fix: incorrectly selecting linear elements on creation while tool-locked (#5785)

* fix: syncing 1-point lines to remote clients (#5677)

* feat: stop deleting whole line when no point select in line editor (#5676)

* feat: stop deleting whole line when no point select in line editor

* Comments typo

Co-authored-by: DanielJGeiger <1852529+DanielJGeiger@users.noreply.github.com>

Co-authored-by: David Luzar <luzar.david@gmail.com>
Co-authored-by: Paul Yi <paulyiengr@gmail.com>
Co-authored-by: DanielJGeiger <1852529+DanielJGeiger@users.noreply.github.com>
2022-11-02 20:36:07 +01:00
zsviczian
49b74cddb9
hide export menu and save file based on UIOptions 2022-11-01 21:45:31 +01:00
zsviczian
377b9fbdff
Update MobileMenu.tsx 2022-11-01 21:22:12 +01:00
11 changed files with 112 additions and 64 deletions

View File

@ -72,13 +72,22 @@ export const actionDeleteSelected = register({
if (!element) { if (!element) {
return false; return false;
} }
if ( // case: no point selected → do nothing, as deleting the whole element
// case: no point selected → delete whole element // is most likely a mistake, where you wanted to delete a specific point
selectedPointsIndices == null || // but failed to select it (or you thought it's selected, while it was
// only in a hover state)
if (selectedPointsIndices == null) {
return false;
}
// case: deleting last remaining point // case: deleting last remaining point
element.points.length < 2 if (element.points.length < 2) {
) { const nextElements = elements.map((el) => {
const nextElements = elements.filter((el) => el.id !== element.id); if (el.id === element.id) {
return newElementWith(el, { isDeleted: true });
}
return el;
});
const nextAppState = handleGroupEditingState(appState, nextElements); const nextAppState = handleGroupEditingState(appState, nextElements);
return { return {

View File

@ -38,7 +38,7 @@ export type ShortcutName =
| "imageExport"; | "imageExport";
const shortcutMap: Record<ShortcutName, string[]> = { const shortcutMap: Record<ShortcutName, string[]> = {
toggleTheme: [getShortcutKey("Shit+Alt+D")], toggleTheme: [getShortcutKey("Shift+Alt+D")],
saveScene: [getShortcutKey("CtrlOrCmd+S")], saveScene: [getShortcutKey("CtrlOrCmd+S")],
loadScene: [getShortcutKey("CtrlOrCmd+O")], loadScene: [getShortcutKey("CtrlOrCmd+O")],
imageExport: [getShortcutKey("CtrlOrCmd+Shift+E")], imageExport: [getShortcutKey("CtrlOrCmd+Shift+E")],

View File

@ -237,7 +237,7 @@ export const ShapesSwitcher = ({
keyBindingLabel={`${numberKey}`} keyBindingLabel={`${numberKey}`}
aria-label={capitalizeString(label)} aria-label={capitalizeString(label)}
aria-keyshortcuts={shortcut} aria-keyshortcuts={shortcut}
data-testid={value} data-testid={`toolbar-${value}`}
onPointerDown={({ pointerType }) => { onPointerDown={({ pointerType }) => {
if (!appState.penDetected && pointerType === "pen") { if (!appState.penDetected && pointerType === "pen") {
setAppState({ setAppState({

View File

@ -4836,10 +4836,6 @@ class App extends React.Component<AppProps, AppState> {
} else { } else {
this.setState((prevState) => ({ this.setState((prevState) => ({
draggingElement: null, draggingElement: null,
selectedElementIds: {
...prevState.selectedElementIds,
[draggingElement.id]: true,
},
})); }));
} }
} }

View File

@ -213,12 +213,15 @@ const LayerUI = ({
padding={2} padding={2}
style={{ zIndex: 1 }} style={{ zIndex: 1 }}
> >
{actionManager.renderAction("loadScene")} {!appState.viewModeEnabled &&
actionManager.renderAction("loadScene")}
{/* // TODO barnabasmolnar/editor-redesign */} {/* // TODO barnabasmolnar/editor-redesign */}
{/* is this fine here? */} {/* is this fine here? */}
{appState.fileHandle && {UIOptions.canvasActions.saveToActiveFile &&
appState.fileHandle &&
actionManager.renderAction("saveToActiveFile")} actionManager.renderAction("saveToActiveFile")}
{renderJSONExportDialog()} {renderJSONExportDialog()}
{UIOptions.canvasActions.export && (
<MenuItem <MenuItem
label={t("buttons.exportImage")} label={t("buttons.exportImage")}
icon={ExportImageIcon} icon={ExportImageIcon}
@ -226,6 +229,7 @@ const LayerUI = ({
onClick={() => setAppState({ openDialog: "imageExport" })} onClick={() => setAppState({ openDialog: "imageExport" })}
shortcut={getShortcutFromShortcutName("imageExport")} shortcut={getShortcutFromShortcutName("imageExport")}
/> />
)}
{onCollabButtonClick && ( {onCollabButtonClick && (
<CollabButton <CollabButton
isCollaborating={isCollaborating} isCollaborating={isCollaborating}
@ -234,7 +238,8 @@ const LayerUI = ({
/> />
)} )}
{actionManager.renderAction("toggleShortcuts", undefined, true)} {actionManager.renderAction("toggleShortcuts", undefined, true)}
{actionManager.renderAction("clearCanvas")} {!appState.viewModeEnabled &&
actionManager.renderAction("clearCanvas")}
<Separator /> <Separator />
<MenuLinks /> <MenuLinks />
<Separator /> <Separator />
@ -249,6 +254,7 @@ const LayerUI = ({
<div style={{ padding: "0 0.625rem" }}> <div style={{ padding: "0 0.625rem" }}>
<LanguageList style={{ width: "100%" }} /> <LanguageList style={{ width: "100%" }} />
</div> </div>
{!appState.viewModeEnabled && (
<div> <div>
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}> <div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
{t("labels.canvasBackground")} {t("labels.canvasBackground")}
@ -257,6 +263,7 @@ const LayerUI = ({
{actionManager.renderAction("changeViewBackgroundColor")} {actionManager.renderAction("changeViewBackgroundColor")}
</div> </div>
</div> </div>
)}
</div> </div>
</Island> </Island>
</Section> </Section>
@ -299,12 +306,12 @@ const LayerUI = ({
return ( return (
<FixedSideContainer side="top"> <FixedSideContainer side="top">
{renderWelcomeScreen && !appState.isLoading && ( {renderWelcomeScreen && !appState.isLoading && (
<WelcomeScreen actionManager={actionManager} /> <WelcomeScreen appState={appState} actionManager={actionManager} />
)} )}
<div className="App-menu App-menu_top"> <div className="App-menu App-menu_top">
<Stack.Col <Stack.Col
gap={6} gap={6}
className={clsx({ className={clsx("App-menu_top__left", {
"disable-pointerEvents": appState.zenModeEnabled, "disable-pointerEvents": appState.zenModeEnabled,
})} })}
> >
@ -405,7 +412,9 @@ const LayerUI = ({
/> />
)} )}
{renderTopRightUI?.(device.isMobile, appState)} {renderTopRightUI?.(device.isMobile, appState)}
{!appState.viewModeEnabled && (
<LibraryButton appState={appState} setAppState={setAppState} /> <LibraryButton appState={appState} setAppState={setAppState} />
)}
</div> </div>
</div> </div>
</FixedSideContainer> </FixedSideContainer>

View File

@ -39,6 +39,7 @@ export const LockButton = (props: LockIconProps) => {
onChange={props.onChange} onChange={props.onChange}
checked={props.checked} checked={props.checked}
aria-label={props.title} aria-label={props.title}
data-testid="toolbar-lock"
/> />
<div className="ToolIcon__icon"> <div className="ToolIcon__icon">
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED} {props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}

View File

@ -75,7 +75,7 @@ export const MobileMenu = ({
return ( return (
<FixedSideContainer side="top" className="App-top-bar"> <FixedSideContainer side="top" className="App-top-bar">
{renderWelcomeScreen && !appState.isLoading && ( {renderWelcomeScreen && !appState.isLoading && (
<WelcomeScreen actionManager={actionManager} /> <WelcomeScreen appState={appState} actionManager={actionManager} />
)} )}
<Section heading="shapes"> <Section heading="shapes">
{(heading: React.ReactNode) => ( {(heading: React.ReactNode) => (
@ -111,8 +111,8 @@ export const MobileMenu = ({
/> />
</Stack.Row> </Stack.Row>
</Island> </Island>
{renderTopRightUI && renderTopRightUI(true, appState)}
<div className="mobile-misc-tools-container"> <div className="mobile-misc-tools-container">
{renderTopRightUI && renderTopRightUI(true, appState)}
<PenModeButton <PenModeButton
checked={appState.penMode} checked={appState.penMode}
onChange={onPenModeToggle} onChange={onPenModeToggle}
@ -127,11 +127,13 @@ export const MobileMenu = ({
title={t("toolBar.lock")} title={t("toolBar.lock")}
isMobile isMobile
/> />
{!appState.viewModeEnabled && (
<LibraryButton <LibraryButton
appState={appState} appState={appState}
setAppState={setAppState} setAppState={setAppState}
isMobile isMobile
/> />
)}
</div> </div>
</Stack.Row> </Stack.Row>
</Stack.Col> </Stack.Col>
@ -187,7 +189,7 @@ export const MobileMenu = ({
} }
return ( return (
<> <>
{actionManager.renderAction("loadScene")} {!appState.viewModeEnabled && actionManager.renderAction("loadScene")}
{renderJSONExportDialog()} {renderJSONExportDialog()}
{renderImageExportDialog()} {renderImageExportDialog()}
<MenuItem <MenuItem
@ -204,10 +206,11 @@ export const MobileMenu = ({
/> />
)} )}
{actionManager.renderAction("toggleShortcuts", undefined, true)} {actionManager.renderAction("toggleShortcuts", undefined, true)}
{actionManager.renderAction("clearCanvas")} {!appState.viewModeEnabled && actionManager.renderAction("clearCanvas")}
<Separator /> <Separator />
<MenuLinks /> <MenuLinks />
<Separator /> <Separator />
{!appState.viewModeEnabled && (
<div style={{ marginBottom: ".5rem" }}> <div style={{ marginBottom: ".5rem" }}>
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}> <div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
{t("labels.canvasBackground")} {t("labels.canvasBackground")}
@ -216,6 +219,7 @@ export const MobileMenu = ({
{actionManager.renderAction("changeViewBackgroundColor")} {actionManager.renderAction("changeViewBackgroundColor")}
</div> </div>
</div> </div>
)}
{actionManager.renderAction("toggleTheme")} {actionManager.renderAction("toggleTheme")}
</> </>
); );

View File

@ -5,6 +5,7 @@ import { getShortcutFromShortcutName } from "../actions/shortcuts";
import { COOKIES } from "../constants"; import { COOKIES } from "../constants";
import { collabDialogShownAtom } from "../excalidraw-app/collab/Collab"; import { collabDialogShownAtom } from "../excalidraw-app/collab/Collab";
import { t } from "../i18n"; import { t } from "../i18n";
import { AppState } from "../types";
import { import {
ExcalLogo, ExcalLogo,
HelpIcon, HelpIcon,
@ -60,7 +61,13 @@ const WelcomeScreenItem = ({
); );
}; };
const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => { const WelcomeScreen = ({
appState,
actionManager,
}: {
appState: AppState;
actionManager: ActionManager;
}) => {
const [, setCollabDialogShown] = useAtom(collabDialogShownAtom); const [, setCollabDialogShown] = useAtom(collabDialogShownAtom);
let subheadingJSX; let subheadingJSX;
@ -68,12 +75,13 @@ const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => {
if (isExcalidrawPlusSignedUser) { if (isExcalidrawPlusSignedUser) {
subheadingJSX = t("welcomeScreen.switchToPlusApp") subheadingJSX = t("welcomeScreen.switchToPlusApp")
.split(/(Excalidraw\+)/) .split(/(Excalidraw\+)/)
.map((bit) => { .map((bit, idx) => {
if (bit === "Excalidraw+") { if (bit === "Excalidraw+") {
return ( return (
<a <a
style={{ pointerEvents: "all" }} style={{ pointerEvents: "all" }}
href={`${process.env.REACT_APP_PLUS_APP}?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenSignedInUser`} href={`${process.env.REACT_APP_PLUS_APP}?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenSignedInUser`}
key={idx}
> >
Excalidraw+ Excalidraw+
</a> </a>
@ -94,6 +102,7 @@ const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => {
{subheadingJSX} {subheadingJSX}
</div> </div>
<div className="WelcomeScreen-items"> <div className="WelcomeScreen-items">
{!appState.viewModeEnabled && (
<WelcomeScreenItem <WelcomeScreenItem
// TODO barnabasmolnar/editor-redesign // TODO barnabasmolnar/editor-redesign
// do we want the internationalized labels here that are currently // do we want the internationalized labels here that are currently
@ -103,6 +112,7 @@ const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => {
shortcut={getShortcutFromShortcutName("loadScene")} shortcut={getShortcutFromShortcutName("loadScene")}
icon={LoadIcon} icon={LoadIcon}
/> />
)}
<WelcomeScreenItem <WelcomeScreenItem
label={t("labels.liveCollaboration")} label={t("labels.liveCollaboration")}
shortcut={null} shortcut={null}

View File

@ -21,10 +21,11 @@ export const useOutsideClickHook = (handler: (event: Event) => void) => {
handler(event); handler(event);
}; };
document.addEventListener("mousedown", listener);
document.addEventListener("pointerdown", listener);
document.addEventListener("touchstart", listener); document.addEventListener("touchstart", listener);
return () => { return () => {
document.removeEventListener("mousedown", listener); document.removeEventListener("pointerdown", listener);
document.removeEventListener("touchstart", listener); document.removeEventListener("touchstart", listener);
}; };
}, },

View File

@ -1,6 +1,7 @@
import { queries, buildQueries } from "@testing-library/react"; import { queries, buildQueries } from "@testing-library/react";
const toolMap = { const toolMap = {
lock: "lock",
selection: "selection", selection: "selection",
rectangle: "rectangle", rectangle: "rectangle",
diamond: "diamond", diamond: "diamond",
@ -15,7 +16,7 @@ export type ToolName = keyof typeof toolMap;
const _getAllByToolName = (container: HTMLElement, tool: string) => { const _getAllByToolName = (container: HTMLElement, tool: string) => {
const toolTitle = toolMap[tool as ToolName]; const toolTitle = toolMap[tool as ToolName];
return queries.getAllByTestId(container, toolTitle); return queries.getAllByTestId(container, `toolbar-${toolTitle}`);
}; };
const getMultipleError = (_container: any, tool: any) => const getMultipleError = (_container: any, tool: any) =>

View File

@ -11,7 +11,8 @@ import * as Renderer from "../renderer/renderScene";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { reseed } from "../random"; import { reseed } from "../random";
import { API } from "./helpers/api"; import { API } from "./helpers/api";
import { Keyboard, Pointer } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";
import { SHAPES } from "../shapes";
// Unmount ReactDOM from root // Unmount ReactDOM from root
ReactDOM.unmountComponentAtNode(document.getElementById("root")!); ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
@ -380,3 +381,19 @@ describe("select single element on the scene", () => {
h.elements.forEach((element) => expect(element).toMatchSnapshot()); h.elements.forEach((element) => expect(element).toMatchSnapshot());
}); });
}); });
describe("tool locking & selection", () => {
it("should not select newly created element while tool is locked", async () => {
await render(<ExcalidrawApp />);
UI.clickTool("lock");
expect(h.state.activeTool.locked).toBe(true);
for (const { value } of Object.values(SHAPES)) {
if (value !== "image" && value !== "selection") {
const element = UI.createElement(value);
expect(h.state.selectedElementIds[element.id]).not.toBe(true);
}
}
});
});