Fix tests.
This commit is contained in:
parent
59e74f94e6
commit
08f430b3ac
@ -23,6 +23,7 @@ import {
|
|||||||
} from "../utils";
|
} from "../utils";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
|
import { SubtypeToggles } from "./SubtypeButton";
|
||||||
import { hasStrokeColor } from "../scene/comparisons";
|
import { hasStrokeColor } from "../scene/comparisons";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { hasBoundTextElement } from "../element/typeChecks";
|
import { hasBoundTextElement } from "../element/typeChecks";
|
||||||
@ -270,6 +271,7 @@ export const ShapesSwitcher = ({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
<SubtypeToggles />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -235,8 +235,6 @@ import { actionToggleViewMode } from "../actions/actionToggleViewMode";
|
|||||||
import {
|
import {
|
||||||
SubtypeRecord,
|
SubtypeRecord,
|
||||||
SubtypePrepFn,
|
SubtypePrepFn,
|
||||||
getSubtypeNames,
|
|
||||||
hasAlwaysEnabledActions,
|
|
||||||
prepareSubtype,
|
prepareSubtype,
|
||||||
selectSubtype,
|
selectSubtype,
|
||||||
} from "../subtypes";
|
} from "../subtypes";
|
||||||
@ -616,14 +614,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
value={this.actionManager}
|
value={this.actionManager}
|
||||||
>
|
>
|
||||||
<LayerUI
|
<LayerUI
|
||||||
renderShapeToggles={getSubtypeNames().map((subtype) =>
|
|
||||||
this.actionManager.renderAction(
|
|
||||||
subtype,
|
|
||||||
hasAlwaysEnabledActions(subtype)
|
|
||||||
? { onContextMenu: this.handleCustomContextMenu }
|
|
||||||
: {},
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
canvas={this.canvas}
|
canvas={this.canvas}
|
||||||
appState={this.state}
|
appState={this.state}
|
||||||
files={this.files}
|
files={this.files}
|
||||||
@ -6047,28 +6037,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleCustomContextMenu = (
|
|
||||||
event: React.MouseEvent<HTMLButtonElement>,
|
|
||||||
source: string,
|
|
||||||
) => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const container = this.excalidrawContainerRef.current!;
|
|
||||||
const { top: offsetTop, left: offsetLeft } =
|
|
||||||
container.getBoundingClientRect();
|
|
||||||
const left = event.clientX - offsetLeft;
|
|
||||||
const top = event.clientY - offsetTop;
|
|
||||||
this.setState({}, () => {
|
|
||||||
this.setState({
|
|
||||||
contextMenu: {
|
|
||||||
top,
|
|
||||||
left,
|
|
||||||
items: this.getContextMenuItems("custom", source),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleCanvasContextMenu = (
|
private handleCanvasContextMenu = (
|
||||||
event: React.PointerEvent<HTMLCanvasElement>,
|
event: React.PointerEvent<HTMLCanvasElement>,
|
||||||
) => {
|
) => {
|
||||||
|
@ -64,7 +64,6 @@ interface LayerUIProps {
|
|||||||
showExitZenModeBtn: boolean;
|
showExitZenModeBtn: boolean;
|
||||||
langCode: Language["code"];
|
langCode: Language["code"];
|
||||||
isCollaborating: boolean;
|
isCollaborating: boolean;
|
||||||
renderShapeToggles?: (JSX.Element | null)[];
|
|
||||||
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
||||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
||||||
renderCustomSidebar?: ExcalidrawProps["renderSidebar"];
|
renderCustomSidebar?: ExcalidrawProps["renderSidebar"];
|
||||||
@ -90,7 +89,6 @@ const LayerUI = ({
|
|||||||
onInsertElements,
|
onInsertElements,
|
||||||
showExitZenModeBtn,
|
showExitZenModeBtn,
|
||||||
isCollaborating,
|
isCollaborating,
|
||||||
renderShapeToggles,
|
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
renderCustomSidebar,
|
renderCustomSidebar,
|
||||||
@ -327,7 +325,6 @@ const LayerUI = ({
|
|||||||
{/* {actionManager.renderAction("eraser", {
|
{/* {actionManager.renderAction("eraser", {
|
||||||
// size: "small",
|
// size: "small",
|
||||||
})} */}
|
})} */}
|
||||||
{renderShapeToggles}
|
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Island>
|
</Island>
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
@ -414,7 +411,6 @@ const LayerUI = ({
|
|||||||
onLockToggle={() => onLockToggle()}
|
onLockToggle={() => onLockToggle()}
|
||||||
onPenModeToggle={onPenModeToggle}
|
onPenModeToggle={onPenModeToggle}
|
||||||
canvas={canvas}
|
canvas={canvas}
|
||||||
renderShapeToggles={renderShapeToggles}
|
|
||||||
onImageAction={onImageAction}
|
onImageAction={onImageAction}
|
||||||
renderTopRightUI={renderTopRightUI}
|
renderTopRightUI={renderTopRightUI}
|
||||||
renderCustomStats={renderCustomStats}
|
renderCustomStats={renderCustomStats}
|
||||||
|
@ -33,7 +33,6 @@ type MobileMenuProps = {
|
|||||||
onLockToggle: () => void;
|
onLockToggle: () => void;
|
||||||
onPenModeToggle: () => void;
|
onPenModeToggle: () => void;
|
||||||
canvas: HTMLCanvasElement | null;
|
canvas: HTMLCanvasElement | null;
|
||||||
renderShapeToggles?: (JSX.Element | null)[];
|
|
||||||
|
|
||||||
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void;
|
||||||
renderTopRightUI?: (
|
renderTopRightUI?: (
|
||||||
@ -55,7 +54,6 @@ export const MobileMenu = ({
|
|||||||
onLockToggle,
|
onLockToggle,
|
||||||
onPenModeToggle,
|
onPenModeToggle,
|
||||||
canvas,
|
canvas,
|
||||||
renderShapeToggles,
|
|
||||||
onImageAction,
|
onImageAction,
|
||||||
renderTopRightUI,
|
renderTopRightUI,
|
||||||
renderCustomStats,
|
renderCustomStats,
|
||||||
@ -86,7 +84,6 @@ export const MobileMenu = ({
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{renderShapeToggles}
|
|
||||||
</Stack.Row>
|
</Stack.Row>
|
||||||
</Island>
|
</Island>
|
||||||
{renderTopRightUI && renderTopRightUI(true, appState)}
|
{renderTopRightUI && renderTopRightUI(true, appState)}
|
||||||
|
@ -3,8 +3,20 @@ import { t } from "../i18n";
|
|||||||
import { Action } from "../actions/types";
|
import { Action } from "../actions/types";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { Subtype, isValidSubtype, subtypeCollides } from "../subtypes";
|
import {
|
||||||
|
Subtype,
|
||||||
|
getSubtypeNames,
|
||||||
|
hasAlwaysEnabledActions,
|
||||||
|
isValidSubtype,
|
||||||
|
subtypeCollides,
|
||||||
|
} from "../subtypes";
|
||||||
import { ExcalidrawElement, Theme } from "../element/types";
|
import { ExcalidrawElement, Theme } from "../element/types";
|
||||||
|
import {
|
||||||
|
useExcalidrawActionManager,
|
||||||
|
useExcalidrawContainer,
|
||||||
|
useExcalidrawSetAppState,
|
||||||
|
} from "./App";
|
||||||
|
import { ContextMenuItems } from "./ContextMenu";
|
||||||
|
|
||||||
export const SubtypeButton = (
|
export const SubtypeButton = (
|
||||||
subtype: Subtype,
|
subtype: Subtype,
|
||||||
@ -101,3 +113,44 @@ export const SubtypeButton = (
|
|||||||
}
|
}
|
||||||
return subtypeAction;
|
return subtypeAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SubtypeToggles = () => {
|
||||||
|
const am = useExcalidrawActionManager();
|
||||||
|
const { container } = useExcalidrawContainer();
|
||||||
|
const setAppState = useExcalidrawSetAppState();
|
||||||
|
|
||||||
|
const onContextMenu = (
|
||||||
|
event: React.MouseEvent<HTMLButtonElement>,
|
||||||
|
source: string,
|
||||||
|
) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const { top: offsetTop, left: offsetLeft } =
|
||||||
|
container!.getBoundingClientRect();
|
||||||
|
const left = event.clientX - offsetLeft;
|
||||||
|
const top = event.clientY - offsetTop;
|
||||||
|
|
||||||
|
const items: ContextMenuItems = [];
|
||||||
|
am.getCustomActions({ data: { source } }).forEach((action) =>
|
||||||
|
items.push(action),
|
||||||
|
);
|
||||||
|
setAppState({}, () => {
|
||||||
|
setAppState({
|
||||||
|
contextMenu: { top, left, items },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{getSubtypeNames().map((subtype) =>
|
||||||
|
am.renderAction(
|
||||||
|
subtype,
|
||||||
|
hasAlwaysEnabledActions(subtype) ? { onContextMenu } : {},
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SubtypeToggles.displayName = "SubtypeToggles";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user