Compare commits

..

4 Commits

Author SHA1 Message Date
zsviczian
60a3584e86 change css back to original 2023-10-07 10:38:46 +02:00
zsviczian
fa0e653236 lint 2023-10-07 10:37:37 +02:00
zsviczian
16de3d9243 add svgContainer offset 2023-10-07 10:35:06 +02:00
zsviczian
c65d6506f7 fix lasertool offset 2023-10-07 08:49:32 +02:00
9 changed files with 22 additions and 92 deletions

View File

@@ -18,7 +18,6 @@ import {
getDefaultAppState, getDefaultAppState,
isEraserActive, isEraserActive,
isHandToolActive, isHandToolActive,
isLaserPointerActive,
} from "../appState"; } from "../appState";
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors"; import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
import { Bounds } from "../element/bounds"; import { Bounds } from "../element/bounds";
@@ -440,44 +439,3 @@ export const actionToggleHandTool = register({
}, },
keyTest: (event) => event.key === KEYS.H, keyTest: (event) => event.key === KEYS.H,
}); });
export const actionToggleLaserPointer = register({
name: "toggleLaserPointerTool",
viewMode: true,
trackEvent: { category: "menu" },
perform(elements, appState, _, app) {
let activeTool: AppState["activeTool"];
if (isLaserPointerActive(appState)) {
activeTool = updateActiveTool(appState, {
...(appState.activeTool.lastActiveTool || {
type: appState.viewModeEnabled ? "hand" : "selection",
}),
lastActiveToolBeforeEraser: null,
});
setCursor(
app.interactiveCanvas,
appState.viewModeEnabled ? CURSOR_TYPE.GRAB : CURSOR_TYPE.POINTER,
);
} else {
activeTool = updateActiveTool(appState, {
type: "laser",
lastActiveToolBeforeEraser: appState.activeTool,
});
setCursor(app.interactiveCanvas, CURSOR_TYPE.CROSSHAIR);
}
return {
appState: {
...appState,
selectedElementIds: {},
selectedGroupIds: {},
activeEmbeddable: null,
activeTool,
},
commitToHistory: true,
};
},
checked: (appState) => appState.activeTool.type === "laser",
contextItemLabel: "labels.laser",
});

View File

@@ -36,7 +36,6 @@ export type ShortcutName =
| "flipVertical" | "flipVertical"
| "hyperlink" | "hyperlink"
| "toggleElementLock" | "toggleElementLock"
| "toggleLaserPointerTool"
> >
| "saveScene" | "saveScene"
| "imageExport"; | "imageExport";
@@ -84,7 +83,6 @@ const shortcutMap: Record<ShortcutName, string[]> = {
viewMode: [getShortcutKey("Alt+R")], viewMode: [getShortcutKey("Alt+R")],
hyperlink: [getShortcutKey("CtrlOrCmd+K")], hyperlink: [getShortcutKey("CtrlOrCmd+K")],
toggleElementLock: [getShortcutKey("CtrlOrCmd+Shift+L")], toggleElementLock: [getShortcutKey("CtrlOrCmd+Shift+L")],
toggleLaserPointerTool: [getShortcutKey("K")],
}; };
export const getShortcutFromShortcutName = (name: ShortcutName) => { export const getShortcutFromShortcutName = (name: ShortcutName) => {

View File

@@ -124,8 +124,7 @@ export type ActionName =
| "setFrameAsActiveTool" | "setFrameAsActiveTool"
| "setEmbeddableAsActiveTool" | "setEmbeddableAsActiveTool"
| "createContainerFromText" | "createContainerFromText"
| "wrapTextInContainer" | "wrapTextInContainer";
| "toggleLaserPointerTool";
export type PanelComponentProps = { export type PanelComponentProps = {
elements: readonly ExcalidrawElement[]; elements: readonly ExcalidrawElement[];

View File

@@ -266,11 +266,3 @@ export const isHandToolActive = ({
}) => { }) => {
return activeTool.type === "hand"; return activeTool.type === "hand";
}; };
export const isLaserPointerActive = ({
activeTool,
}: {
activeTool: AppState["activeTool"];
}) => {
return activeTool.type === "laser";
};

View File

@@ -46,7 +46,6 @@ import {
getDefaultAppState, getDefaultAppState,
isEraserActive, isEraserActive,
isHandToolActive, isHandToolActive,
isLaserPointerActive,
} from "../appState"; } from "../appState";
import { parseClipboard } from "../clipboard"; import { parseClipboard } from "../clipboard";
import { import {
@@ -344,11 +343,7 @@ import {
actionRemoveAllElementsFromFrame, actionRemoveAllElementsFromFrame,
actionSelectAllElementsInFrame, actionSelectAllElementsInFrame,
} from "../actions/actionFrame"; } from "../actions/actionFrame";
import { import { actionToggleHandTool, zoomToFit } from "../actions/actionCanvas";
actionToggleHandTool,
zoomToFit,
actionToggleLaserPointer,
} from "../actions/actionCanvas";
import { jotaiStore } from "../jotai"; import { jotaiStore } from "../jotai";
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog"; import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
import { import {
@@ -2915,22 +2910,7 @@ class App extends React.Component<AppProps, AppState> {
return; return;
} }
if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
if (isLaserPointerActive(this.state)) {
this.setActiveTool({
type: "selection",
});
} else {
this.setActiveTool({ type: "laser" });
}
return;
}
if (this.state.viewModeEnabled) { if (this.state.viewModeEnabled) {
//revert to hand in case a key is pressed (K is handled above)
if (event.key !== KEYS.K) {
this.setActiveTool({ type: "selection" });
}
return; return;
} }
@@ -3080,6 +3060,15 @@ class App extends React.Component<AppProps, AppState> {
} }
} }
if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
if (this.state.activeTool.type === "laser") {
this.setActiveTool({ type: "selection" });
} else {
this.setActiveTool({ type: "laser" });
}
return;
}
if ( if (
event[KEYS.CTRL_OR_CMD] && event[KEYS.CTRL_OR_CMD] &&
(event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE) (event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE)
@@ -3623,18 +3612,6 @@ class App extends React.Component<AppProps, AppState> {
if (this.state.multiElement) { if (this.state.multiElement) {
return; return;
} }
if (this.state.viewModeEnabled) {
if (this.state.activeTool.type === "laser") {
this.setActiveTool({ type: "selection" });
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
} else {
this.setActiveTool({ type: "laser" });
setCursor(this.interactiveCanvas, CURSOR_TYPE.CROSSHAIR);
}
return;
}
// we should only be able to double click when mode is selection // we should only be able to double click when mode is selection
if (this.state.activeTool.type !== "selection") { if (this.state.activeTool.type !== "selection") {
return; return;
@@ -4762,7 +4739,7 @@ class App extends React.Component<AppProps, AppState> {
(event.button === POINTER_BUTTON.WHEEL || (event.button === POINTER_BUTTON.WHEEL ||
(event.button === POINTER_BUTTON.MAIN && isHoldingSpace) || (event.button === POINTER_BUTTON.MAIN && isHoldingSpace) ||
isHandToolActive(this.state) || isHandToolActive(this.state) ||
(this.state.viewModeEnabled && !isLaserPointerActive(this.state))) this.state.viewModeEnabled)
) || ) ||
isTextElement(this.state.editingElement) isTextElement(this.state.editingElement)
) { ) {
@@ -8166,7 +8143,6 @@ class App extends React.Component<AppProps, AppState> {
actionToggleZenMode, actionToggleZenMode,
actionToggleViewMode, actionToggleViewMode,
actionToggleStats, actionToggleStats,
actionToggleLaserPointer,
]; ];
} }

View File

@@ -106,6 +106,13 @@ export class LaserPathManager {
} }
startPath(x: number, y: number) { startPath(x: number, y: number) {
if (this.container) {
this.container.style.top = "0px";
this.container.style.left = "0px";
const { x, y } = this.container.getBoundingClientRect();
this.container.style.top = `${-y}px`;
this.container.style.left = `${-x}px`;
}
this.ownState.currentPath = instantiatePath(); this.ownState.currentPath = instantiatePath();
this.ownState.currentPath.addPoint([x, y, performance.now()]); this.ownState.currentPath.addPoint([x, y, performance.now()]);
this.updatePath(this.ownState); this.updatePath(this.ownState);

View File

@@ -6,7 +6,6 @@
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
z-index: 2; z-index: 2;
.LaserToolOverlayCanvas { .LaserToolOverlayCanvas {

View File

@@ -155,7 +155,9 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
onPointerCancel={props.onPointerCancel} onPointerCancel={props.onPointerCancel}
onTouchMove={props.onTouchMove} onTouchMove={props.onTouchMove}
onPointerDown={props.onPointerDown} onPointerDown={props.onPointerDown}
onDoubleClick={props.onDoubleClick} onDoubleClick={
props.appState.viewModeEnabled ? undefined : props.onDoubleClick
}
> >
{t("labels.drawingCanvas")} {t("labels.drawingCanvas")}
</canvas> </canvas>

View File

@@ -1,6 +1,5 @@
{ {
"labels": { "labels": {
"laser": "Toggle laser pointer",
"paste": "Paste", "paste": "Paste",
"pasteAsPlaintext": "Paste as plaintext", "pasteAsPlaintext": "Paste as plaintext",
"pasteCharts": "Paste charts", "pasteCharts": "Paste charts",