Merge branch 'master' into dwelle/oxc
# Conflicts: # packages/element/src/binding.ts # packages/element/src/elbowArrow.ts # packages/element/src/linearElementEditor.ts # packages/excalidraw/components/Actions.tsx # packages/excalidraw/components/App.tsx # packages/excalidraw/components/dropdownMenu/DropdownMenuItemLink.tsx # packages/excalidraw/components/dropdownMenu/common.ts # packages/excalidraw/tests/__snapshots__/excalidraw.test.tsx.snap
This commit is contained in:
@@ -62,7 +62,7 @@ export const AppMainMenu: React.FC<{
|
|||||||
{isDevEnv() && (
|
{isDevEnv() && (
|
||||||
<MainMenu.Item
|
<MainMenu.Item
|
||||||
icon={eyeIcon}
|
icon={eyeIcon}
|
||||||
onClick={() => {
|
onSelect={() => {
|
||||||
if (window.visualDebug) {
|
if (window.visualDebug) {
|
||||||
delete window.visualDebug;
|
delete window.visualDebug;
|
||||||
saveDebugState({ enabled: false });
|
saveDebugState({ enabled: false });
|
||||||
@@ -77,6 +77,7 @@ export const AppMainMenu: React.FC<{
|
|||||||
</MainMenu.Item>
|
</MainMenu.Item>
|
||||||
)}
|
)}
|
||||||
<MainMenu.Separator />
|
<MainMenu.Separator />
|
||||||
|
<MainMenu.DefaultItems.Preferences />
|
||||||
<MainMenu.DefaultItems.ToggleTheme
|
<MainMenu.DefaultItems.ToggleTheme
|
||||||
allowSystemTheme
|
allowSystemTheme
|
||||||
theme={props.theme}
|
theme={props.theme}
|
||||||
|
|||||||
@@ -33,7 +33,15 @@ export const AppWelcomeScreen: React.FC<{
|
|||||||
return bit;
|
return bit;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
headingContent = t("welcomeScreen.app.center_heading");
|
headingContent = (
|
||||||
|
<>
|
||||||
|
{t("welcomeScreen.app.center_heading")}
|
||||||
|
<br />
|
||||||
|
{t("welcomeScreen.app.center_heading_line2")}
|
||||||
|
<br />
|
||||||
|
{t("welcomeScreen.app.center_heading_line3")}
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
|
|||||||
<div
|
<div
|
||||||
class="welcome-screen-center__heading welcome-screen-decor excalifont"
|
class="welcome-screen-center__heading welcome-screen-decor excalifont"
|
||||||
>
|
>
|
||||||
All your data is saved locally in your browser.
|
Your drawings are saved in your browser's storage.
|
||||||
|
<br />
|
||||||
|
Browser storage can be cleared unexpectedly.
|
||||||
|
<br />
|
||||||
|
Save your work to a file regularly to avoid losing it.
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="welcome-screen-menu"
|
class="welcome-screen-menu"
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
debug: typeof Debug;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lessPrecise = (num: number, precision = 5) =>
|
const lessPrecise = (num: number, precision = 5) =>
|
||||||
parseFloat(num.toPrecision(precision));
|
parseFloat(num.toPrecision(precision));
|
||||||
|
|
||||||
@@ -157,6 +151,70 @@ export class Debug {
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static CHANGED_CACHE: Record<string, Record<string, unknown>> = {};
|
||||||
|
|
||||||
|
public static logChanged(name: string, obj: Record<string, unknown>) {
|
||||||
|
const prev = Debug.CHANGED_CACHE[name];
|
||||||
|
|
||||||
|
Debug.CHANGED_CACHE[name] = obj;
|
||||||
|
|
||||||
|
if (!prev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allKeys = new Set([...Object.keys(prev), ...Object.keys(obj)]);
|
||||||
|
const changed: Record<string, { prev: unknown; next: unknown }> = {};
|
||||||
|
|
||||||
|
for (const key of allKeys) {
|
||||||
|
const prevVal = prev[key];
|
||||||
|
const nextVal = obj[key];
|
||||||
|
if (!deepEqual(prevVal, nextVal)) {
|
||||||
|
changed[key] = { prev: prevVal, next: nextVal };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(changed).length > 0) {
|
||||||
|
console.info(`[${name}] changed:`, changed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deepEqual(a: unknown, b: unknown): boolean {
|
||||||
|
if (Object.is(a, b)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
a === null ||
|
||||||
|
b === null ||
|
||||||
|
typeof a !== "object" ||
|
||||||
|
typeof b !== "object"
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(a) !== Array.isArray(b)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysA = Object.keys(a as Record<string, unknown>);
|
||||||
|
const keysB = Object.keys(b as Record<string, unknown>);
|
||||||
|
|
||||||
|
if (keysA.length !== keysB.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key of keysA) {
|
||||||
|
if (
|
||||||
|
!deepEqual(
|
||||||
|
(a as Record<string, unknown>)[key],
|
||||||
|
(b as Record<string, unknown>)[key],
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
//@ts-ignore
|
|
||||||
window.debug = Debug;
|
|
||||||
@@ -349,7 +349,7 @@ export const normalizeInputColor = (color: string): string | null => {
|
|||||||
if (tc.isValid()) {
|
if (tc.isValid()) {
|
||||||
// testing for `#` first fixes a bug on Electron (more specfically, an
|
// testing for `#` first fixes a bug on Electron (more specfically, an
|
||||||
// Obsidian popout window), where a hex color without `#` is considered valid
|
// Obsidian popout window), where a hex color without `#` is considered valid
|
||||||
if (tc.getFormat() === "hex" && !color.startsWith("#")) {
|
if (["hex", "hex8"].includes(tc.getFormat()) && !color.startsWith("#")) {
|
||||||
return `#${color}`;
|
return `#${color}`;
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export const CLASSES = {
|
|||||||
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
||||||
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
||||||
FRAME_NAME: "frame-name",
|
FRAME_NAME: "frame-name",
|
||||||
|
DROPDOWN_MENU_EVENT_WRAPPER: "dropdown-menu-event-wrapper",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FONT_SIZES = {
|
export const FONT_SIZES = {
|
||||||
@@ -251,6 +252,7 @@ export const STRING_MIME_TYPES = {
|
|||||||
json: "application/json",
|
json: "application/json",
|
||||||
// excalidraw data
|
// excalidraw data
|
||||||
excalidraw: "application/vnd.excalidraw+json",
|
excalidraw: "application/vnd.excalidraw+json",
|
||||||
|
excalidrawClipboard: "application/vnd.excalidraw.clipboard+json",
|
||||||
// LEGACY: fully-qualified library JSON data
|
// LEGACY: fully-qualified library JSON data
|
||||||
excalidrawlib: "application/vnd.excalidrawlib+json",
|
excalidrawlib: "application/vnd.excalidrawlib+json",
|
||||||
// list of excalidraw library item ids
|
// list of excalidraw library item ids
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ export * from "./url";
|
|||||||
export * from "./utils";
|
export * from "./utils";
|
||||||
export * from "./emitter";
|
export * from "./emitter";
|
||||||
export * from "./editorInterface";
|
export * from "./editorInterface";
|
||||||
|
export { Debug } from "../debug";
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { average } from "@excalidraw/math";
|
import { average } from "@excalidraw/math";
|
||||||
|
|
||||||
|
import type { GlobalCoord } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { FontFamilyValues, FontString } from "@excalidraw/element/types";
|
import type { FontFamilyValues, FontString } from "@excalidraw/element/types";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -441,7 +443,7 @@ export const viewportCoordsToSceneCoords = (
|
|||||||
const x = (clientX - offsetLeft) / zoom.value - scrollX;
|
const x = (clientX - offsetLeft) / zoom.value - scrollX;
|
||||||
const y = (clientY - offsetTop) / zoom.value - scrollY;
|
const y = (clientY - offsetTop) / zoom.value - scrollY;
|
||||||
|
|
||||||
return { x, y };
|
return { x, y } as GlobalCoord;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sceneCoordsToViewportCoords = (
|
export const sceneCoordsToViewportCoords = (
|
||||||
@@ -1339,3 +1341,10 @@ export const setFeatureFlag = <F extends keyof FEATURE_FLAGS>(
|
|||||||
console.error("unable to set feature flag", e);
|
console.error("unable to set feature flag", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const oneOf = <N extends string | number | symbol | null, H extends N>(
|
||||||
|
needle: N,
|
||||||
|
haystack: readonly H[],
|
||||||
|
): needle is H => {
|
||||||
|
return haystack.includes(needle as any);
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,558 @@
|
|||||||
|
import { pointDistance, pointFrom, type GlobalPoint } from "@excalidraw/math";
|
||||||
|
import { invariant } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import type { AppState, NullableGridSize } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
|
import {
|
||||||
|
bindBindingElement,
|
||||||
|
calculateFixedPointForNonElbowArrowBinding,
|
||||||
|
FOCUS_POINT_SIZE,
|
||||||
|
getBindingGap,
|
||||||
|
getGlobalFixedPointForBindableElement,
|
||||||
|
isBindingEnabled,
|
||||||
|
maxBindingDistance_simple,
|
||||||
|
unbindBindingElement,
|
||||||
|
updateBoundPoint,
|
||||||
|
} from "../binding";
|
||||||
|
import {
|
||||||
|
isBindableElement,
|
||||||
|
isBindingElement,
|
||||||
|
isElbowArrow,
|
||||||
|
} from "../typeChecks";
|
||||||
|
import { LinearElementEditor } from "../linearElementEditor";
|
||||||
|
import { getHoveredElementForFocusPoint, hitElementItself } from "../collision";
|
||||||
|
import { moveArrowAboveBindable } from "../zindex";
|
||||||
|
|
||||||
|
import type {
|
||||||
|
ElementsMap,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
|
ExcalidrawBindableElement,
|
||||||
|
NonDeletedSceneElementsMap,
|
||||||
|
PointsPositionUpdates,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
import type { Scene } from "../Scene";
|
||||||
|
|
||||||
|
export const isFocusPointVisible = (
|
||||||
|
focusPoint: GlobalPoint,
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
bindableElement: ExcalidrawBindableElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
appState: {
|
||||||
|
isBindingEnabled: AppState["isBindingEnabled"];
|
||||||
|
zoom: AppState["zoom"];
|
||||||
|
},
|
||||||
|
startOrEnd: "start" | "end",
|
||||||
|
ignoreOverlap = false,
|
||||||
|
): boolean => {
|
||||||
|
// No focus point management for elbow arrows, because elbow arrows
|
||||||
|
// always have their focus point at the arrow point itself
|
||||||
|
if (
|
||||||
|
isElbowArrow(arrow) ||
|
||||||
|
!isBindingEnabled(appState) ||
|
||||||
|
arrow.points.length !== 2
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avoid showing the focus point indicator if the focus point is essentially
|
||||||
|
// on top of the arrow point it belongs to itself, if not ignoring specifically
|
||||||
|
if (!ignoreOverlap) {
|
||||||
|
const associatedPointIdx =
|
||||||
|
arrow.startBinding?.elementId === bindableElement.id
|
||||||
|
? 0
|
||||||
|
: arrow.points.length - 1;
|
||||||
|
const associatedArrowPoint =
|
||||||
|
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
arrow,
|
||||||
|
associatedPointIdx,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
pointDistance(focusPoint, associatedArrowPoint) <
|
||||||
|
(FOCUS_POINT_SIZE * 1.5) / appState.zoom.value
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const arrowPoint = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
arrow,
|
||||||
|
startOrEnd === "end" ? arrow.points.length - 1 : 0,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if the focus point is within the element's shape bounds
|
||||||
|
// Endpoint dragging takes precedence
|
||||||
|
return (
|
||||||
|
pointDistance(focusPoint, arrowPoint) >=
|
||||||
|
(FOCUS_POINT_SIZE * 1.5) / appState.zoom.value &&
|
||||||
|
hitElementItself({
|
||||||
|
element: bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
point: focusPoint,
|
||||||
|
threshold: getBindingGap(bindableElement, arrow),
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Updates the arrow endpoints in "orbit" configuration
|
||||||
|
const focusPointUpdate = (
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
bindableElement: ExcalidrawBindableElement | null,
|
||||||
|
isStartBinding: boolean,
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
|
switchToInsideBinding: boolean,
|
||||||
|
) => {
|
||||||
|
const pointUpdates = new Map();
|
||||||
|
|
||||||
|
const bindingField = isStartBinding ? "startBinding" : "endBinding";
|
||||||
|
const adjacentBindingField = isStartBinding ? "endBinding" : "startBinding";
|
||||||
|
let currentBinding = arrow[bindingField];
|
||||||
|
let adjacentBinding = arrow[adjacentBindingField];
|
||||||
|
|
||||||
|
// Update the dragged focus point related end
|
||||||
|
if (currentBinding && bindableElement) {
|
||||||
|
// Update the targeted bindings
|
||||||
|
const boundToSameElement =
|
||||||
|
bindableElement &&
|
||||||
|
adjacentBinding &&
|
||||||
|
currentBinding.elementId === adjacentBinding.elementId;
|
||||||
|
if (switchToInsideBinding || boundToSameElement) {
|
||||||
|
currentBinding = {
|
||||||
|
...currentBinding,
|
||||||
|
mode: "inside",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
currentBinding = {
|
||||||
|
...currentBinding,
|
||||||
|
mode: "orbit",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const pointIndex = isStartBinding ? 0 : arrow.points.length - 1;
|
||||||
|
const newPoint = updateBoundPoint(
|
||||||
|
arrow,
|
||||||
|
bindingField as "startBinding" | "endBinding",
|
||||||
|
currentBinding,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newPoint) {
|
||||||
|
pointUpdates.set(pointIndex, { point: newPoint });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also update the adjacent end if it has a binding
|
||||||
|
if (adjacentBinding && adjacentBinding.mode === "orbit") {
|
||||||
|
const adjacentBindableElement = elementsMap.get(
|
||||||
|
adjacentBinding.elementId,
|
||||||
|
) as ExcalidrawBindableElement;
|
||||||
|
|
||||||
|
if (
|
||||||
|
adjacentBindableElement &&
|
||||||
|
isBindableElement(adjacentBindableElement) &&
|
||||||
|
isBindingEnabled(appState)
|
||||||
|
) {
|
||||||
|
// Same shape bound on both ends
|
||||||
|
const boundToSameElementAfterUpdate =
|
||||||
|
bindableElement && adjacentBinding.elementId === bindableElement.id;
|
||||||
|
if (switchToInsideBinding || boundToSameElementAfterUpdate) {
|
||||||
|
adjacentBinding = {
|
||||||
|
...adjacentBinding,
|
||||||
|
mode: "inside",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
adjacentBinding = {
|
||||||
|
...adjacentBinding,
|
||||||
|
mode: "orbit",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const adjacentPointIndex = isStartBinding ? arrow.points.length - 1 : 0;
|
||||||
|
const adjacentNewPoint = updateBoundPoint(
|
||||||
|
arrow,
|
||||||
|
adjacentBindingField,
|
||||||
|
adjacentBinding,
|
||||||
|
adjacentBindableElement,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (adjacentNewPoint) {
|
||||||
|
pointUpdates.set(adjacentPointIndex, {
|
||||||
|
point: adjacentNewPoint,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointUpdates.size > 0) {
|
||||||
|
LinearElementEditor.movePoints(arrow, scene, pointUpdates, {
|
||||||
|
[bindingField]: currentBinding,
|
||||||
|
[adjacentBindingField]: adjacentBinding,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleFocusPointDrag = (
|
||||||
|
linearElementEditor: LinearElementEditor,
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
pointerCoords: { x: number; y: number },
|
||||||
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
|
gridSize: NullableGridSize,
|
||||||
|
switchToInsideBinding: boolean,
|
||||||
|
) => {
|
||||||
|
const arrow = LinearElementEditor.getElement(
|
||||||
|
linearElementEditor.elementId,
|
||||||
|
elementsMap,
|
||||||
|
) as any;
|
||||||
|
|
||||||
|
// Sanity checks
|
||||||
|
if (
|
||||||
|
!arrow ||
|
||||||
|
!isBindingElement(arrow) ||
|
||||||
|
isElbowArrow(arrow) ||
|
||||||
|
!linearElementEditor.hoveredFocusPointBinding ||
|
||||||
|
!linearElementEditor.draggedFocusPointBinding
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isStartBinding =
|
||||||
|
linearElementEditor.draggedFocusPointBinding === "start";
|
||||||
|
const binding = isStartBinding ? arrow.startBinding : arrow.endBinding;
|
||||||
|
const { x: offsetX, y: offsetY } = linearElementEditor.pointerOffset;
|
||||||
|
const point = pointFrom<GlobalPoint>(
|
||||||
|
pointerCoords.x - offsetX,
|
||||||
|
pointerCoords.y - offsetY,
|
||||||
|
);
|
||||||
|
const bindingField = isStartBinding ? "startBinding" : "endBinding";
|
||||||
|
const hit = getHoveredElementForFocusPoint(
|
||||||
|
point,
|
||||||
|
arrow,
|
||||||
|
scene.getNonDeletedElements(),
|
||||||
|
elementsMap,
|
||||||
|
maxBindingDistance_simple(appState.zoom),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Hovering a bindable element
|
||||||
|
if (hit && isBindingEnabled(appState)) {
|
||||||
|
// Break existing binding if bound to another shape or if binding is disabled
|
||||||
|
if (arrow[bindingField] && hit.id !== binding?.elementId) {
|
||||||
|
unbindBindingElement(
|
||||||
|
arrow,
|
||||||
|
linearElementEditor.draggedFocusPointBinding,
|
||||||
|
scene,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle binding mode switch
|
||||||
|
const newMode =
|
||||||
|
switchToInsideBinding && arrow[bindingField]?.mode === "orbit"
|
||||||
|
? "inside"
|
||||||
|
: !switchToInsideBinding && arrow[bindingField]?.mode === "inside"
|
||||||
|
? "orbit"
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// If no existing binding, create it
|
||||||
|
if (!arrow[bindingField] || newMode) {
|
||||||
|
// Create a new binding if none exists
|
||||||
|
bindBindingElement(
|
||||||
|
arrow,
|
||||||
|
hit,
|
||||||
|
newMode || "orbit",
|
||||||
|
linearElementEditor.draggedFocusPointBinding,
|
||||||
|
scene,
|
||||||
|
point,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the binding's fixed point
|
||||||
|
scene.mutateElement(arrow, {
|
||||||
|
[bindingField]: {
|
||||||
|
...arrow[bindingField],
|
||||||
|
elementId: hit.id,
|
||||||
|
mode: newMode || arrow[bindingField]?.mode || "orbit",
|
||||||
|
...calculateFixedPointForNonElbowArrowBinding(
|
||||||
|
arrow,
|
||||||
|
hit,
|
||||||
|
linearElementEditor.draggedFocusPointBinding,
|
||||||
|
elementsMap,
|
||||||
|
point,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Not hovering any bindable element, move the arrow endpoint
|
||||||
|
const pointUpdates: PointsPositionUpdates = new Map();
|
||||||
|
const pointIndex = isStartBinding ? 0 : arrow.points.length - 1;
|
||||||
|
pointUpdates.set(pointIndex, {
|
||||||
|
point: LinearElementEditor.createPointAt(
|
||||||
|
arrow,
|
||||||
|
elementsMap,
|
||||||
|
point[0],
|
||||||
|
point[1],
|
||||||
|
gridSize,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
LinearElementEditor.movePoints(arrow, scene, pointUpdates);
|
||||||
|
if (arrow[bindingField]) {
|
||||||
|
unbindBindingElement(arrow, isStartBinding ? "start" : "end", scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the arrow endpoints
|
||||||
|
focusPointUpdate(
|
||||||
|
arrow,
|
||||||
|
hit,
|
||||||
|
isStartBinding,
|
||||||
|
elementsMap,
|
||||||
|
scene,
|
||||||
|
appState,
|
||||||
|
switchToInsideBinding,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hit && isBindingEnabled(appState)) {
|
||||||
|
moveArrowAboveBindable(
|
||||||
|
point,
|
||||||
|
arrow,
|
||||||
|
scene.getElementsIncludingDeleted(),
|
||||||
|
elementsMap,
|
||||||
|
scene,
|
||||||
|
hit,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleFocusPointPointerDown = (
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
pointerDownState: { origin: { x: number; y: number } },
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
appState: AppState,
|
||||||
|
): {
|
||||||
|
hitFocusPoint: "start" | "end" | null;
|
||||||
|
pointerOffset: { x: number; y: number };
|
||||||
|
} => {
|
||||||
|
const pointerPos = pointFrom(
|
||||||
|
pointerDownState.origin.x,
|
||||||
|
pointerDownState.origin.y,
|
||||||
|
);
|
||||||
|
const hitThreshold = (FOCUS_POINT_SIZE * 1.5) / appState.zoom.value;
|
||||||
|
|
||||||
|
// Check start binding focus point
|
||||||
|
if (arrow.startBinding?.elementId) {
|
||||||
|
const bindableElement = elementsMap.get(arrow.startBinding.elementId);
|
||||||
|
if (
|
||||||
|
bindableElement &&
|
||||||
|
isBindableElement(bindableElement) &&
|
||||||
|
!bindableElement.isDeleted
|
||||||
|
) {
|
||||||
|
const focusPoint = getGlobalFixedPointForBindableElement(
|
||||||
|
arrow.startBinding.fixedPoint,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isFocusPointVisible(
|
||||||
|
focusPoint,
|
||||||
|
arrow,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
appState,
|
||||||
|
"start",
|
||||||
|
) &&
|
||||||
|
pointDistance(pointerPos, focusPoint) <= hitThreshold
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
hitFocusPoint: "start",
|
||||||
|
pointerOffset: {
|
||||||
|
x: pointerPos[0] - focusPoint[0],
|
||||||
|
y: pointerPos[1] - focusPoint[1],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check end binding focus point (only if start not already hit)
|
||||||
|
if (arrow.endBinding?.elementId) {
|
||||||
|
const bindableElement = elementsMap.get(arrow.endBinding.elementId);
|
||||||
|
if (
|
||||||
|
bindableElement &&
|
||||||
|
isBindableElement(bindableElement) &&
|
||||||
|
!bindableElement.isDeleted
|
||||||
|
) {
|
||||||
|
const focusPoint = getGlobalFixedPointForBindableElement(
|
||||||
|
arrow.endBinding.fixedPoint,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isFocusPointVisible(
|
||||||
|
focusPoint,
|
||||||
|
arrow,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
appState,
|
||||||
|
"end",
|
||||||
|
) &&
|
||||||
|
pointDistance(pointerPos, focusPoint) <= hitThreshold
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
hitFocusPoint: "end",
|
||||||
|
pointerOffset: {
|
||||||
|
x: pointerPos[0] - focusPoint[0],
|
||||||
|
y: pointerPos[1] - focusPoint[1],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
hitFocusPoint: null,
|
||||||
|
pointerOffset: { x: 0, y: 0 },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleFocusPointPointerUp = (
|
||||||
|
linearElementEditor: LinearElementEditor,
|
||||||
|
scene: Scene,
|
||||||
|
) => {
|
||||||
|
invariant(
|
||||||
|
linearElementEditor.draggedFocusPointBinding,
|
||||||
|
"Must have a dragged focus point at pointer release",
|
||||||
|
);
|
||||||
|
|
||||||
|
const arrow = LinearElementEditor.getElement<ExcalidrawArrowElement>(
|
||||||
|
linearElementEditor.elementId,
|
||||||
|
scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
invariant(arrow, "Arrow must be in the scene");
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
const bindingKey =
|
||||||
|
linearElementEditor.draggedFocusPointBinding === "start"
|
||||||
|
? "startBinding"
|
||||||
|
: "endBinding";
|
||||||
|
const otherBindingKey =
|
||||||
|
linearElementEditor.draggedFocusPointBinding === "start"
|
||||||
|
? "endBinding"
|
||||||
|
: "startBinding";
|
||||||
|
const boundElementId = arrow[bindingKey]?.elementId;
|
||||||
|
const otherBoundElementId = arrow[otherBindingKey]?.elementId;
|
||||||
|
const oldBoundElement =
|
||||||
|
boundElementId &&
|
||||||
|
scene
|
||||||
|
.getNonDeletedElements()
|
||||||
|
.find(
|
||||||
|
(element) =>
|
||||||
|
element.id !== boundElementId &&
|
||||||
|
element.id !== otherBoundElementId &&
|
||||||
|
isBindableElement(element) &&
|
||||||
|
element.boundElements?.find(({ id }) => id === arrow.id),
|
||||||
|
);
|
||||||
|
if (oldBoundElement) {
|
||||||
|
scene.mutateElement(oldBoundElement, {
|
||||||
|
boundElements: oldBoundElement.boundElements?.filter(
|
||||||
|
({ id }) => id !== arrow.id,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record the new bound element
|
||||||
|
const boundElement =
|
||||||
|
boundElementId && scene.getNonDeletedElementsMap().get(boundElementId);
|
||||||
|
if (boundElement) {
|
||||||
|
scene.mutateElement(boundElement, {
|
||||||
|
boundElements: [
|
||||||
|
...(boundElement.boundElements || [])?.filter(
|
||||||
|
({ id }) => id !== arrow.id,
|
||||||
|
),
|
||||||
|
{
|
||||||
|
id: arrow.id,
|
||||||
|
type: "arrow",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleFocusPointHover = (
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
scenePointerX: number,
|
||||||
|
scenePointerY: number,
|
||||||
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
|
): "start" | "end" | null => {
|
||||||
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
const pointerPos = pointFrom(scenePointerX, scenePointerY);
|
||||||
|
const hitThreshold = (FOCUS_POINT_SIZE * 1.5) / appState.zoom.value;
|
||||||
|
|
||||||
|
// Check start binding focus point
|
||||||
|
if (arrow.startBinding?.elementId) {
|
||||||
|
const bindableElement = elementsMap.get(arrow.startBinding.elementId);
|
||||||
|
if (
|
||||||
|
bindableElement &&
|
||||||
|
isBindableElement(bindableElement) &&
|
||||||
|
!bindableElement.isDeleted
|
||||||
|
) {
|
||||||
|
const focusPoint = getGlobalFixedPointForBindableElement(
|
||||||
|
arrow.startBinding.fixedPoint,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isFocusPointVisible(
|
||||||
|
focusPoint,
|
||||||
|
arrow,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
appState,
|
||||||
|
"start",
|
||||||
|
) &&
|
||||||
|
pointDistance(pointerPos, focusPoint) <= hitThreshold
|
||||||
|
) {
|
||||||
|
return "start";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check end binding focus point (only if start not already hovered)
|
||||||
|
if (arrow.endBinding?.elementId) {
|
||||||
|
const bindableElement = elementsMap.get(arrow.endBinding.elementId);
|
||||||
|
if (
|
||||||
|
bindableElement &&
|
||||||
|
isBindableElement(bindableElement) &&
|
||||||
|
!bindableElement.isDeleted
|
||||||
|
) {
|
||||||
|
const focusPoint = getGlobalFixedPointForBindableElement(
|
||||||
|
arrow.endBinding.fixedPoint,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isFocusPointVisible(
|
||||||
|
focusPoint,
|
||||||
|
arrow,
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
appState,
|
||||||
|
"end",
|
||||||
|
) &&
|
||||||
|
pointDistance(pointerPos, focusPoint) <= hitThreshold
|
||||||
|
) {
|
||||||
|
return "end";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import type { App } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
|
import { LinearElementEditor } from "../linearElementEditor";
|
||||||
|
|
||||||
|
import { handleFocusPointDrag } from "./focus";
|
||||||
|
|
||||||
|
export const maybeHandleArrowPointlikeDrag = ({
|
||||||
|
app,
|
||||||
|
event,
|
||||||
|
}: {
|
||||||
|
app: App;
|
||||||
|
event: KeyboardEvent | React.KeyboardEvent<Element> | PointerEvent;
|
||||||
|
}): boolean => {
|
||||||
|
const appState = app.state;
|
||||||
|
if (appState.selectedLinearElement && app.lastPointerMoveCoords) {
|
||||||
|
// Update focus point status if the binding mode is changing
|
||||||
|
if (appState.selectedLinearElement.draggedFocusPointBinding) {
|
||||||
|
handleFocusPointDrag(
|
||||||
|
appState.selectedLinearElement,
|
||||||
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
app.lastPointerMoveCoords,
|
||||||
|
app.scene,
|
||||||
|
appState,
|
||||||
|
app.getEffectiveGridSize(),
|
||||||
|
event.altKey,
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} else if (
|
||||||
|
appState.selectedLinearElement.hoverPointIndex !== null &&
|
||||||
|
app.lastPointerMoveEvent &&
|
||||||
|
appState.selectedLinearElement.initialState.lastClickedPoint >= 0 &&
|
||||||
|
appState.selectedLinearElement.isDragging
|
||||||
|
) {
|
||||||
|
LinearElementEditor.handlePointDragging(
|
||||||
|
app.lastPointerMoveEvent,
|
||||||
|
app,
|
||||||
|
app.lastPointerMoveCoords.x,
|
||||||
|
app.lastPointerMoveCoords.y,
|
||||||
|
appState.selectedLinearElement,
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
+339
-206
@@ -27,14 +27,11 @@ import type { AppState } from "@excalidraw/excalidraw/types";
|
|||||||
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
||||||
import type { Bounds } from "@excalidraw/common";
|
import type { Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import { getCenterForBounds } from "./bounds";
|
||||||
doBoundsIntersect,
|
|
||||||
getCenterForBounds,
|
|
||||||
getElementBounds,
|
|
||||||
} from "./bounds";
|
|
||||||
import {
|
import {
|
||||||
getAllHoveredElementAtPoint,
|
getAllHoveredElementAtPoint,
|
||||||
getHoveredElementForBinding,
|
getHoveredElementForBinding,
|
||||||
|
hitElementItself,
|
||||||
intersectElementWithLineSegment,
|
intersectElementWithLineSegment,
|
||||||
isBindableElementInsideOtherBindable,
|
isBindableElementInsideOtherBindable,
|
||||||
isPointInElement,
|
isPointInElement,
|
||||||
@@ -113,8 +110,10 @@ export type BindingStrategy =
|
|||||||
*
|
*
|
||||||
* IMPORTANT: currently must be > 0 (this also applies to the computed gap)
|
* IMPORTANT: currently must be > 0 (this also applies to the computed gap)
|
||||||
*/
|
*/
|
||||||
export const BASE_BINDING_GAP = 10;
|
export const BASE_BINDING_GAP = 5;
|
||||||
export const BASE_BINDING_GAP_ELBOW = 5;
|
export const BASE_BINDING_GAP_ELBOW = 5;
|
||||||
|
export const BASE_ARROW_MIN_LENGTH = 10;
|
||||||
|
export const FOCUS_POINT_SIZE = 10 / 1.5;
|
||||||
|
|
||||||
export const getBindingGap = (
|
export const getBindingGap = (
|
||||||
bindTarget: ExcalidrawBindableElement,
|
bindTarget: ExcalidrawBindableElement,
|
||||||
@@ -144,7 +143,9 @@ export const shouldEnableBindingForPointerEvent = (
|
|||||||
return !event[KEYS.CTRL_OR_CMD];
|
return !event[KEYS.CTRL_OR_CMD];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isBindingEnabled = (appState: AppState): boolean => {
|
export const isBindingEnabled = (appState: {
|
||||||
|
isBindingEnabled: AppState["isBindingEnabled"];
|
||||||
|
}): boolean => {
|
||||||
return appState.isBindingEnabled;
|
return appState.isBindingEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -258,7 +259,7 @@ const bindingStrategyForElbowArrowEndpointDragging = (
|
|||||||
globalPoint,
|
globalPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
() => maxBindingDistance_simple(zoom),
|
maxBindingDistance_simple(zoom),
|
||||||
);
|
);
|
||||||
|
|
||||||
const current = hit
|
const current = hit
|
||||||
@@ -677,7 +678,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
globalPoint,
|
globalPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
() => maxBindingDistance_simple(appState.zoom),
|
maxBindingDistance_simple(appState.zoom),
|
||||||
);
|
);
|
||||||
const pointInElement =
|
const pointInElement =
|
||||||
hit &&
|
hit &&
|
||||||
@@ -704,7 +705,13 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
const otherFocusPointIsInElement =
|
const otherFocusPointIsInElement =
|
||||||
otherBindableElement &&
|
otherBindableElement &&
|
||||||
otherFocusPoint &&
|
otherFocusPoint &&
|
||||||
isPointInElement(otherFocusPoint, otherBindableElement, elementsMap);
|
hitElementItself({
|
||||||
|
point: otherFocusPoint,
|
||||||
|
element: otherBindableElement,
|
||||||
|
elementsMap,
|
||||||
|
threshold: 0,
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
});
|
||||||
|
|
||||||
// Handle outside-outside binding to the same element
|
// Handle outside-outside binding to the same element
|
||||||
if (otherBinding && otherBinding.elementId === hit?.id) {
|
if (otherBinding && otherBinding.elementId === hit?.id) {
|
||||||
@@ -784,6 +791,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
hit,
|
hit,
|
||||||
startDragged ? "start" : "end",
|
startDragged ? "start" : "end",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
appState.zoom,
|
||||||
) || globalPoint,
|
) || globalPoint,
|
||||||
}
|
}
|
||||||
: { mode: null };
|
: { mode: null };
|
||||||
@@ -793,30 +801,45 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
startDragged ? -1 : 0,
|
startDragged ? -1 : 0,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
const pointIsCloseToOtherElement =
|
||||||
const other: BindingStrategy =
|
otherFocusPoint &&
|
||||||
otherBindableElement &&
|
otherBindableElement &&
|
||||||
!otherFocusPointIsInElement &&
|
hitElementItself({
|
||||||
appState.selectedLinearElement?.initialState.altFocusPoint
|
point: globalPoint,
|
||||||
|
element: otherBindableElement,
|
||||||
|
elementsMap,
|
||||||
|
threshold: maxBindingDistance_simple(appState.zoom),
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
});
|
||||||
|
const otherNeverOverride = opts?.newArrow
|
||||||
|
? appState.selectedLinearElement?.initialState.arrowStartIsInside
|
||||||
|
: otherBinding?.mode === "inside";
|
||||||
|
const other: BindingStrategy = !otherNeverOverride
|
||||||
|
? otherBindableElement &&
|
||||||
|
!otherFocusPointIsInElement &&
|
||||||
|
!pointIsCloseToOtherElement &&
|
||||||
|
appState.selectedLinearElement?.initialState.altFocusPoint
|
||||||
? {
|
? {
|
||||||
mode: "orbit",
|
mode: "orbit",
|
||||||
element: otherBindableElement,
|
element: otherBindableElement,
|
||||||
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint,
|
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint,
|
||||||
}
|
}
|
||||||
: opts?.angleLocked && otherBindableElement
|
: opts?.angleLocked && otherBindableElement
|
||||||
? {
|
? {
|
||||||
mode: "orbit",
|
mode: "orbit",
|
||||||
element: otherBindableElement,
|
element: otherBindableElement,
|
||||||
focusPoint:
|
focusPoint:
|
||||||
projectFixedPointOntoDiagonal(
|
projectFixedPointOntoDiagonal(
|
||||||
arrow,
|
arrow,
|
||||||
otherEndpoint,
|
otherEndpoint,
|
||||||
otherBindableElement,
|
otherBindableElement,
|
||||||
startDragged ? "end" : "start",
|
startDragged ? "end" : "start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
) || otherEndpoint,
|
appState.zoom,
|
||||||
}
|
) || otherEndpoint,
|
||||||
: { mode: undefined };
|
}
|
||||||
|
: { mode: undefined }
|
||||||
|
: { mode: undefined };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: startDragged ? current : other,
|
start: startDragged ? current : other,
|
||||||
@@ -1080,7 +1103,7 @@ export const updateBoundElements = (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
boundElementsVisitor(elementsMap, changedElement, (element) => {
|
const visitor = (element: ExcalidrawElement | undefined) => {
|
||||||
if (!isArrowElement(element) || element.isDeleted) {
|
if (!isArrowElement(element) || element.isDeleted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1152,7 +1175,71 @@ export const updateBoundElements = (
|
|||||||
if (boundText && !boundText.isDeleted) {
|
if (boundText && !boundText.isDeleted) {
|
||||||
handleBindTextResize(element, scene, false);
|
handleBindTextResize(element, scene, false);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
boundElementsVisitor(elementsMap, changedElement, visitor);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateArrowBindings = (
|
||||||
|
latestElement: ExcalidrawArrowElement,
|
||||||
|
startOrEnd: "startBinding" | "endBinding",
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
scene: Scene,
|
||||||
|
appState: AppState,
|
||||||
|
) => {
|
||||||
|
invariant(
|
||||||
|
!isElbowArrow(latestElement),
|
||||||
|
"Elbow arrows not supported for indirect updates",
|
||||||
|
);
|
||||||
|
|
||||||
|
const binding = latestElement[startOrEnd];
|
||||||
|
const bindableElement =
|
||||||
|
binding &&
|
||||||
|
(elementsMap.get(binding.elementId) as ExcalidrawBindableElement);
|
||||||
|
const point = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
latestElement,
|
||||||
|
startOrEnd === "startBinding" ? 0 : -1,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const hit =
|
||||||
|
bindableElement &&
|
||||||
|
hitElementItself({
|
||||||
|
element: bindableElement,
|
||||||
|
point,
|
||||||
|
elementsMap,
|
||||||
|
threshold: maxBindingDistance_simple(appState.zoom),
|
||||||
|
});
|
||||||
|
const strategyName = startOrEnd === "startBinding" ? "start" : "end";
|
||||||
|
unbindBindingElement(latestElement, strategyName, scene);
|
||||||
|
if (hit) {
|
||||||
|
const pointIdx =
|
||||||
|
startOrEnd === "startBinding" ? 0 : latestElement.points.length - 1;
|
||||||
|
const localPoint = latestElement.points[pointIdx];
|
||||||
|
const strategy =
|
||||||
|
getBindingStrategyForDraggingBindingElementEndpoints_simple(
|
||||||
|
latestElement,
|
||||||
|
new Map([[pointIdx, { point: localPoint }]]),
|
||||||
|
point[0],
|
||||||
|
point[1],
|
||||||
|
elementsMap,
|
||||||
|
scene.getNonDeletedElements(),
|
||||||
|
appState,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
strategy[strategyName] &&
|
||||||
|
strategy[strategyName].element?.id === bindableElement.id &&
|
||||||
|
strategy[strategyName].mode
|
||||||
|
) {
|
||||||
|
bindBindingElement(
|
||||||
|
latestElement,
|
||||||
|
bindableElement,
|
||||||
|
strategy[strategyName].mode,
|
||||||
|
strategyName,
|
||||||
|
scene,
|
||||||
|
strategy[strategyName].focusPoint,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateBindings = (
|
export const updateBindings = (
|
||||||
@@ -1165,14 +1252,27 @@ export const updateBindings = (
|
|||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
if (isArrowElement(latestElement)) {
|
if (isArrowElement(latestElement)) {
|
||||||
bindOrUnbindBindingElement(
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
latestElement,
|
|
||||||
new Map(),
|
if (latestElement.startBinding) {
|
||||||
Infinity,
|
updateArrowBindings(
|
||||||
Infinity,
|
latestElement,
|
||||||
scene,
|
"startBinding",
|
||||||
appState,
|
elementsMap,
|
||||||
);
|
scene,
|
||||||
|
appState,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (latestElement.endBinding) {
|
||||||
|
updateArrowBindings(
|
||||||
|
latestElement,
|
||||||
|
"endBinding",
|
||||||
|
elementsMap,
|
||||||
|
scene,
|
||||||
|
appState,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
updateBoundElements(latestElement, scene, {
|
updateBoundElements(latestElement, scene, {
|
||||||
...options,
|
...options,
|
||||||
@@ -1286,14 +1386,16 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
headingForPointFromElement(bindableElement, aabb, point),
|
headingForPointFromElement(bindableElement, aabb, point),
|
||||||
);
|
);
|
||||||
const snapPoint = snapToMid(
|
const snapPoint = snapToMid(
|
||||||
arrowElement,
|
|
||||||
bindableElement,
|
bindableElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
edgePoint,
|
edgePoint,
|
||||||
|
0.05,
|
||||||
|
arrowElement,
|
||||||
);
|
);
|
||||||
|
const resolved = snapPoint || point;
|
||||||
const otherPoint = pointFrom<GlobalPoint>(
|
const otherPoint = pointFrom<GlobalPoint>(
|
||||||
isHorizontal ? bindableCenter[0] : snapPoint[0],
|
isHorizontal ? bindableCenter[0] : resolved[0],
|
||||||
!isHorizontal ? bindableCenter[1] : snapPoint[1],
|
!isHorizontal ? bindableCenter[1] : resolved[1],
|
||||||
);
|
);
|
||||||
const intersector =
|
const intersector =
|
||||||
customIntersector ??
|
customIntersector ??
|
||||||
@@ -1301,7 +1403,7 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
otherPoint,
|
otherPoint,
|
||||||
pointFromVector(
|
pointFromVector(
|
||||||
vectorScale(
|
vectorScale(
|
||||||
vectorNormalize(vectorFromPoint(snapPoint, otherPoint)),
|
vectorNormalize(vectorFromPoint(resolved, otherPoint)),
|
||||||
Math.max(bindableElement.width, bindableElement.height) * 2,
|
Math.max(bindableElement.width, bindableElement.height) * 2,
|
||||||
),
|
),
|
||||||
otherPoint,
|
otherPoint,
|
||||||
@@ -1316,14 +1418,14 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
|
|
||||||
if (!intersection) {
|
if (!intersection) {
|
||||||
const anotherPoint = pointFrom<GlobalPoint>(
|
const anotherPoint = pointFrom<GlobalPoint>(
|
||||||
!isHorizontal ? bindableCenter[0] : snapPoint[0],
|
!isHorizontal ? bindableCenter[0] : resolved[0],
|
||||||
isHorizontal ? bindableCenter[1] : snapPoint[1],
|
isHorizontal ? bindableCenter[1] : resolved[1],
|
||||||
);
|
);
|
||||||
const anotherIntersector = lineSegment(
|
const anotherIntersector = lineSegment(
|
||||||
anotherPoint,
|
anotherPoint,
|
||||||
pointFromVector(
|
pointFromVector(
|
||||||
vectorScale(
|
vectorScale(
|
||||||
vectorNormalize(vectorFromPoint(snapPoint, anotherPoint)),
|
vectorNormalize(vectorFromPoint(resolved, anotherPoint)),
|
||||||
Math.max(bindableElement.width, bindableElement.height) * 2,
|
Math.max(bindableElement.width, bindableElement.height) * 2,
|
||||||
),
|
),
|
||||||
anotherPoint,
|
anotherPoint,
|
||||||
@@ -1470,18 +1572,18 @@ export const avoidRectangularCorner = (
|
|||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
const snapToMid = (
|
export const snapToMid = (
|
||||||
arrowElement: ExcalidrawArrowElement,
|
|
||||||
bindTarget: ExcalidrawBindableElement,
|
bindTarget: ExcalidrawBindableElement,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
p: GlobalPoint,
|
p: GlobalPoint,
|
||||||
tolerance: number = 0.05,
|
tolerance: number = 0.05,
|
||||||
): GlobalPoint => {
|
arrowElement?: ExcalidrawArrowElement,
|
||||||
|
): GlobalPoint | undefined => {
|
||||||
const { x, y, width, height, angle } = bindTarget;
|
const { x, y, width, height, angle } = bindTarget;
|
||||||
const center = elementCenterPoint(bindTarget, elementsMap, -0.1, -0.1);
|
const center = elementCenterPoint(bindTarget, elementsMap, -0.1, -0.1);
|
||||||
const nonRotated = pointRotateRads(p, center, -angle as Radians);
|
const nonRotated = pointRotateRads(p, center, -angle as Radians);
|
||||||
|
|
||||||
const bindingGap = getBindingGap(bindTarget, arrowElement);
|
const bindingGap = arrowElement ? getBindingGap(bindTarget, arrowElement) : 0;
|
||||||
|
|
||||||
// snap-to-center point is adaptive to element size, but we don't want to go
|
// snap-to-center point is adaptive to element size, but we don't want to go
|
||||||
// above and below certain px distance
|
// above and below certain px distance
|
||||||
@@ -1490,7 +1592,7 @@ const snapToMid = (
|
|||||||
|
|
||||||
// Too close to the center makes it hard to resolve direction precisely
|
// Too close to the center makes it hard to resolve direction precisely
|
||||||
if (pointDistance(center, nonRotated) < bindingGap) {
|
if (pointDistance(center, nonRotated) < bindingGap) {
|
||||||
return p;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -1499,8 +1601,8 @@ const snapToMid = (
|
|||||||
nonRotated[1] < center[1] + verticalThreshold
|
nonRotated[1] < center[1] + verticalThreshold
|
||||||
) {
|
) {
|
||||||
// LEFT
|
// LEFT
|
||||||
return pointRotateRads<GlobalPoint>(
|
return pointRotateRads(
|
||||||
pointFrom(x - bindingGap, center[1]),
|
pointFrom<GlobalPoint>(x - bindingGap, center[1]),
|
||||||
center,
|
center,
|
||||||
angle,
|
angle,
|
||||||
);
|
);
|
||||||
@@ -1510,7 +1612,11 @@ const snapToMid = (
|
|||||||
nonRotated[0] < center[0] + horizontalThreshold
|
nonRotated[0] < center[0] + horizontalThreshold
|
||||||
) {
|
) {
|
||||||
// TOP
|
// TOP
|
||||||
return pointRotateRads(pointFrom(center[0], y - bindingGap), center, angle);
|
return pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(center[0], y - bindingGap),
|
||||||
|
center,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
} else if (
|
} else if (
|
||||||
nonRotated[0] >= x + width / 2 &&
|
nonRotated[0] >= x + width / 2 &&
|
||||||
nonRotated[1] > center[1] - verticalThreshold &&
|
nonRotated[1] > center[1] - verticalThreshold &&
|
||||||
@@ -1518,7 +1624,7 @@ const snapToMid = (
|
|||||||
) {
|
) {
|
||||||
// RIGHT
|
// RIGHT
|
||||||
return pointRotateRads(
|
return pointRotateRads(
|
||||||
pointFrom(x + width + bindingGap, center[1]),
|
pointFrom<GlobalPoint>(x + width + bindingGap, center[1]),
|
||||||
center,
|
center,
|
||||||
angle,
|
angle,
|
||||||
);
|
);
|
||||||
@@ -1529,7 +1635,7 @@ const snapToMid = (
|
|||||||
) {
|
) {
|
||||||
// DOWN
|
// DOWN
|
||||||
return pointRotateRads(
|
return pointRotateRads(
|
||||||
pointFrom(center[0], y + height + bindingGap),
|
pointFrom<GlobalPoint>(center[0], y + height + bindingGap),
|
||||||
center,
|
center,
|
||||||
angle,
|
angle,
|
||||||
);
|
);
|
||||||
@@ -1578,13 +1684,44 @@ const snapToMid = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const compareElementArea = (
|
const extractBinding = (
|
||||||
a: ExcalidrawBindableElement,
|
arrow: ExcalidrawArrowElement,
|
||||||
b: ExcalidrawBindableElement,
|
startOrEnd: "startBinding" | "endBinding",
|
||||||
) => b.width ** 2 + b.height ** 2 - (a.width ** 2 + a.height ** 2);
|
elementsMap: ElementsMap,
|
||||||
|
) => {
|
||||||
|
const binding = arrow[startOrEnd];
|
||||||
|
if (!binding) {
|
||||||
|
return {
|
||||||
|
element: null,
|
||||||
|
fixedPoint: null,
|
||||||
|
focusPoint: null,
|
||||||
|
binding,
|
||||||
|
mode: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const element = elementsMap.get(
|
||||||
|
binding.elementId,
|
||||||
|
) as ExcalidrawBindableElement;
|
||||||
|
|
||||||
|
return {
|
||||||
|
element,
|
||||||
|
fixedPoint: binding.fixedPoint,
|
||||||
|
focusPoint: getGlobalFixedPointForBindableElement(
|
||||||
|
normalizeFixedPoint(binding.fixedPoint),
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
binding,
|
||||||
|
mode: binding.mode,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const elementArea = (element: ExcalidrawBindableElement) =>
|
||||||
|
element.width * element.height;
|
||||||
|
|
||||||
export const updateBoundPoint = (
|
export const updateBoundPoint = (
|
||||||
arrow: NonDeleted<ExcalidrawArrowElement>,
|
arrow: NonDeleted<ExcalidrawArrowElement>,
|
||||||
@@ -1592,7 +1729,7 @@ export const updateBoundPoint = (
|
|||||||
binding: FixedPointBinding | null | undefined,
|
binding: FixedPointBinding | null | undefined,
|
||||||
bindableElement: ExcalidrawBindableElement,
|
bindableElement: ExcalidrawBindableElement,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
customIntersector?: LineSegment<GlobalPoint>,
|
dragging?: boolean,
|
||||||
): LocalPoint | null => {
|
): LocalPoint | null => {
|
||||||
if (
|
if (
|
||||||
binding == null ||
|
binding == null ||
|
||||||
@@ -1607,152 +1744,136 @@ export const updateBoundPoint = (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const global = getGlobalFixedPointForBindableElement(
|
const focusPoint = getGlobalFixedPointForBindableElement(
|
||||||
normalizeFixedPoint(binding.fixedPoint),
|
normalizeFixedPoint(binding.fixedPoint),
|
||||||
bindableElement,
|
bindableElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const pointIndex =
|
|
||||||
startOrEnd === "startBinding" ? 0 : arrow.points.length - 1;
|
|
||||||
const elbowed = isElbowArrow(arrow);
|
|
||||||
const otherBinding =
|
|
||||||
startOrEnd === "startBinding" ? arrow.endBinding : arrow.startBinding;
|
|
||||||
const otherBindableElement =
|
|
||||||
otherBinding &&
|
|
||||||
(elementsMap.get(otherBinding.elementId)! as ExcalidrawBindableElement);
|
|
||||||
const bounds = getElementBounds(bindableElement, elementsMap);
|
|
||||||
const otherBounds =
|
|
||||||
otherBindableElement && getElementBounds(otherBindableElement, elementsMap);
|
|
||||||
const isLargerThanOther =
|
|
||||||
otherBindableElement &&
|
|
||||||
compareElementArea(bindableElement, otherBindableElement) <
|
|
||||||
// if both shapes the same size, pretend the other is larger
|
|
||||||
(startOrEnd === "endBinding" ? 1 : 0);
|
|
||||||
const isOverlapping = otherBounds && doBoundsIntersect(bounds, otherBounds);
|
|
||||||
|
|
||||||
// GOAL: If the arrow becomes too short, we want to jump the arrow endpoints
|
// 0. Short-circuit for inside binding as it doesn't require any
|
||||||
// to the exact focus points on the elements.
|
// calculations and is not affected by other bindings
|
||||||
// INTUITION: We're not interested in the exacts length of the arrow (which
|
if (binding.mode === "inside") {
|
||||||
// will change if we change where we route it), we want to know the length of
|
return LinearElementEditor.createPointAt(
|
||||||
// the part which lies outside of both shapes and consider that as a trigger
|
|
||||||
// to change where we point the arrow. Avoids jumping the arrow in and out
|
|
||||||
// at every frame.
|
|
||||||
let arrowTooShort = false;
|
|
||||||
if (
|
|
||||||
!isOverlapping &&
|
|
||||||
!elbowed &&
|
|
||||||
arrow.startBinding &&
|
|
||||||
arrow.endBinding &&
|
|
||||||
otherBindableElement &&
|
|
||||||
arrow.points.length === 2
|
|
||||||
) {
|
|
||||||
const startFocusPoint = getGlobalFixedPointForBindableElement(
|
|
||||||
arrow.startBinding.fixedPoint,
|
|
||||||
startOrEnd === "startBinding" ? bindableElement : otherBindableElement,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
const endFocusPoint = getGlobalFixedPointForBindableElement(
|
|
||||||
arrow.endBinding.fixedPoint,
|
|
||||||
startOrEnd === "endBinding" ? bindableElement : otherBindableElement,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
const segment = lineSegment(startFocusPoint, endFocusPoint);
|
|
||||||
const startIntersection = intersectElementWithLineSegment(
|
|
||||||
startOrEnd === "endBinding" ? bindableElement : otherBindableElement,
|
|
||||||
elementsMap,
|
|
||||||
segment,
|
|
||||||
0,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
const endIntersection = intersectElementWithLineSegment(
|
|
||||||
startOrEnd === "startBinding" ? bindableElement : otherBindableElement,
|
|
||||||
elementsMap,
|
|
||||||
segment,
|
|
||||||
0,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
if (startIntersection.length > 0 && endIntersection.length > 0) {
|
|
||||||
const len = pointDistance(startIntersection[0], endIntersection[0]);
|
|
||||||
arrowTooShort = len < 40;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const isNested = (arrowTooShort || isOverlapping) && isLargerThanOther;
|
|
||||||
|
|
||||||
let _customIntersector = customIntersector;
|
|
||||||
if (!elbowed && !_customIntersector) {
|
|
||||||
const [x1, y1, x2, y2] = LinearElementEditor.getElementAbsoluteCoords(
|
|
||||||
arrow,
|
arrow,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
focusPoint[0],
|
||||||
const center = pointFrom<GlobalPoint>((x1 + x2) / 2, (y1 + y2) / 2);
|
focusPoint[1],
|
||||||
const edgePoint = isRectanguloidElement(bindableElement)
|
null,
|
||||||
? avoidRectangularCorner(arrow, bindableElement, elementsMap, global)
|
|
||||||
: global;
|
|
||||||
const adjacentPoint = pointRotateRads(
|
|
||||||
pointFrom<GlobalPoint>(
|
|
||||||
arrow.x +
|
|
||||||
arrow.points[pointIndex === 0 ? 1 : arrow.points.length - 2][0],
|
|
||||||
arrow.y +
|
|
||||||
arrow.points[pointIndex === 0 ? 1 : arrow.points.length - 2][1],
|
|
||||||
),
|
|
||||||
center,
|
|
||||||
arrow.angle as Radians,
|
|
||||||
);
|
|
||||||
const bindingGap = getBindingGap(bindableElement, arrow);
|
|
||||||
const halfVector = vectorScale(
|
|
||||||
vectorNormalize(vectorFromPoint(edgePoint, adjacentPoint)),
|
|
||||||
pointDistance(edgePoint, adjacentPoint) +
|
|
||||||
Math.max(bindableElement.width, bindableElement.height) +
|
|
||||||
bindingGap * 2,
|
|
||||||
);
|
|
||||||
_customIntersector = lineSegment(
|
|
||||||
pointFromVector(halfVector, adjacentPoint),
|
|
||||||
pointFromVector(vectorScale(halfVector, -1), adjacentPoint),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeOutlineGlobal =
|
const { element: otherBindable, focusPoint: otherFocusPoint } =
|
||||||
binding.mode === "orbit" && bindableElement
|
extractBinding(
|
||||||
? isNested
|
arrow,
|
||||||
? global
|
startOrEnd === "startBinding" ? "endBinding" : "startBinding",
|
||||||
: bindPointToSnapToElementOutline(
|
elementsMap,
|
||||||
{
|
);
|
||||||
...arrow,
|
const otherArrowPoint = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
points: [
|
arrow,
|
||||||
pointIndex === 0
|
startOrEnd === "startBinding" ? -1 : 0,
|
||||||
? LinearElementEditor.createPointAt(
|
elementsMap,
|
||||||
arrow,
|
);
|
||||||
elementsMap,
|
const otherFocusPointOrArrowPoint = otherFocusPoint || otherArrowPoint;
|
||||||
global[0],
|
const intersector =
|
||||||
global[1],
|
otherFocusPointOrArrowPoint &&
|
||||||
null,
|
lineSegment(focusPoint, otherFocusPointOrArrowPoint);
|
||||||
)
|
const otherOutlinePoint =
|
||||||
: arrow.points[0],
|
otherBindable &&
|
||||||
...arrow.points.slice(1, -1),
|
intersector &&
|
||||||
pointIndex === arrow.points.length - 1
|
intersectElementWithLineSegment(
|
||||||
? LinearElementEditor.createPointAt(
|
otherBindable,
|
||||||
arrow,
|
elementsMap,
|
||||||
elementsMap,
|
intersector,
|
||||||
global[0],
|
getBindingGap(otherBindable, arrow),
|
||||||
global[1],
|
).sort(
|
||||||
null,
|
(a, b) => pointDistanceSq(a, focusPoint) - pointDistanceSq(b, focusPoint),
|
||||||
)
|
)[0];
|
||||||
: arrow.points[arrow.points.length - 1],
|
const outlinePoint =
|
||||||
],
|
intersector &&
|
||||||
},
|
intersectElementWithLineSegment(
|
||||||
bindableElement,
|
bindableElement,
|
||||||
pointIndex === 0 ? "start" : "end",
|
elementsMap,
|
||||||
elementsMap,
|
intersector,
|
||||||
_customIntersector,
|
getBindingGap(bindableElement, arrow),
|
||||||
)
|
).sort(
|
||||||
: global;
|
(a, b) =>
|
||||||
|
pointDistanceSq(a, otherFocusPointOrArrowPoint) -
|
||||||
|
pointDistanceSq(b, otherFocusPointOrArrowPoint),
|
||||||
|
)[0];
|
||||||
|
const startHasArrowhead = arrow.startArrowhead !== null;
|
||||||
|
const endHasArrowhead = arrow.endArrowhead !== null;
|
||||||
|
const resolvedTarget =
|
||||||
|
(!startHasArrowhead && !endHasArrowhead) ||
|
||||||
|
(startOrEnd === "startBinding" && startHasArrowhead) ||
|
||||||
|
(startOrEnd === "endBinding" && endHasArrowhead)
|
||||||
|
? focusPoint
|
||||||
|
: outlinePoint || focusPoint;
|
||||||
|
|
||||||
|
// 1. Handle case when the outline point (or focus point) is inside
|
||||||
|
// the other shape by short-circuiting to the focus point, otherwise
|
||||||
|
// the arrow would invert
|
||||||
|
if (
|
||||||
|
otherBindable &&
|
||||||
|
outlinePoint &&
|
||||||
|
!dragging &&
|
||||||
|
// Arbitrary threshold to handle wireframing use cases
|
||||||
|
elementArea(otherBindable) < elementArea(bindableElement) * 2 &&
|
||||||
|
hitElementItself({
|
||||||
|
element: otherBindable,
|
||||||
|
point: outlinePoint,
|
||||||
|
elementsMap,
|
||||||
|
threshold: getBindingGap(otherBindable, arrow),
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
return LinearElementEditor.createPointAt(
|
||||||
|
arrow,
|
||||||
|
elementsMap,
|
||||||
|
resolvedTarget[0],
|
||||||
|
resolvedTarget[1],
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const otherTargetPoint = otherBindable
|
||||||
|
? otherOutlinePoint || otherFocusPoint || otherArrowPoint
|
||||||
|
: otherArrowPoint;
|
||||||
|
const arrowTooShort =
|
||||||
|
pointDistance(otherTargetPoint, outlinePoint || focusPoint) <=
|
||||||
|
BASE_ARROW_MIN_LENGTH;
|
||||||
|
|
||||||
|
// 2. If the arrow is unconnected at the other end, just check arrow size
|
||||||
|
// and short-circuit to the focus point if the arrow is too short to
|
||||||
|
// avoid inversion
|
||||||
|
if (!otherBindable) {
|
||||||
|
return LinearElementEditor.createPointAt(
|
||||||
|
arrow,
|
||||||
|
elementsMap,
|
||||||
|
arrowTooShort ? focusPoint[0] : outlinePoint?.[0] ?? focusPoint[0],
|
||||||
|
arrowTooShort ? focusPoint[1] : outlinePoint?.[1] ?? focusPoint[1],
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. If the arrow is too short while connected on both ends and
|
||||||
|
// the other arrow endpoint will not be inside the bindable, just
|
||||||
|
// check the arrow size and make a decision based on that
|
||||||
|
if (arrowTooShort) {
|
||||||
|
return LinearElementEditor.createPointAt(
|
||||||
|
arrow,
|
||||||
|
elementsMap,
|
||||||
|
resolvedTarget?.[0] || focusPoint[0],
|
||||||
|
resolvedTarget?.[1] || focusPoint[1],
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. In the general case, snap to the outline if possible
|
||||||
return LinearElementEditor.createPointAt(
|
return LinearElementEditor.createPointAt(
|
||||||
arrow,
|
arrow,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
maybeOutlineGlobal[0],
|
outlinePoint?.[0] || focusPoint[0],
|
||||||
maybeOutlineGlobal[1],
|
outlinePoint?.[1] || focusPoint[1],
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1802,7 +1923,7 @@ export const calculateFixedPointForNonElbowArrowBinding = (
|
|||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
focusPoint?: GlobalPoint,
|
focusPoint?: GlobalPoint,
|
||||||
): { fixedPoint: FixedPoint } => {
|
): { fixedPoint: FixedPoint } => {
|
||||||
const edgePoint = focusPoint
|
const edgePoint: GlobalPoint = focusPoint
|
||||||
? focusPoint
|
? focusPoint
|
||||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
linearElement,
|
linearElement,
|
||||||
@@ -1810,11 +1931,7 @@ export const calculateFixedPointForNonElbowArrowBinding = (
|
|||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert the global point to element-local coordinates
|
const elementCenter = elementCenterPoint(hoveredElement, elementsMap);
|
||||||
const elementCenter = pointFrom(
|
|
||||||
hoveredElement.x + hoveredElement.width / 2,
|
|
||||||
hoveredElement.y + hoveredElement.height / 2,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Rotate the point to account for element rotation
|
// Rotate the point to account for element rotation
|
||||||
const nonRotatedPoint = pointRotateRads(
|
const nonRotatedPoint = pointRotateRads(
|
||||||
@@ -2324,21 +2441,37 @@ export const getArrowLocalFixedPoints = (
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const normalizeFixedPoint = <T extends FixedPoint | null>(
|
export const isFixedPoint = (
|
||||||
|
fixedPoint: any,
|
||||||
|
): fixedPoint is FixedPointBinding["fixedPoint"] => {
|
||||||
|
return (
|
||||||
|
Array.isArray(fixedPoint) &&
|
||||||
|
fixedPoint.length === 2 &&
|
||||||
|
fixedPoint.every((coord) => Number.isFinite(coord))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const normalizeFixedPoint = <T extends FixedPoint>(
|
||||||
fixedPoint: T,
|
fixedPoint: T,
|
||||||
): T extends null ? null : FixedPoint => {
|
): FixedPoint => {
|
||||||
|
if (!isFixedPoint(fixedPoint)) {
|
||||||
|
return [0.5001, 0.5001];
|
||||||
|
}
|
||||||
|
|
||||||
|
const EPSILON = 0.0001;
|
||||||
|
|
||||||
// Do not allow a precise 0.5 for fixed point ratio
|
// Do not allow a precise 0.5 for fixed point ratio
|
||||||
// to avoid jumping arrow heading due to floating point imprecision
|
// to avoid jumping arrow heading due to floating point imprecision
|
||||||
if (
|
if (
|
||||||
fixedPoint &&
|
Math.abs(fixedPoint[0] - 0.5) < EPSILON ||
|
||||||
(Math.abs(fixedPoint[0] - 0.5) < 0.0001 ||
|
Math.abs(fixedPoint[1] - 0.5) < EPSILON
|
||||||
Math.abs(fixedPoint[1] - 0.5) < 0.0001)
|
|
||||||
) {
|
) {
|
||||||
return fixedPoint.map((ratio) =>
|
return fixedPoint.map((ratio) =>
|
||||||
Math.abs(ratio - 0.5) < 0.0001 ? 0.5001 : ratio,
|
Math.abs(ratio - 0.5) < EPSILON ? 0.5001 : ratio,
|
||||||
) as T extends null ? null : FixedPoint;
|
) as FixedPoint;
|
||||||
}
|
}
|
||||||
return fixedPoint as any as T extends null ? null : FixedPoint;
|
|
||||||
|
return fixedPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Side =
|
type Side =
|
||||||
|
|||||||
@@ -59,8 +59,11 @@ import { LinearElementEditor } from "./linearElementEditor";
|
|||||||
|
|
||||||
import { distanceToElement } from "./distance";
|
import { distanceToElement } from "./distance";
|
||||||
|
|
||||||
|
import { getBindingGap } from "./binding";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawBindableElement,
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -105,6 +108,12 @@ export type HitTestArgs = {
|
|||||||
overrideShouldTestInside?: boolean;
|
overrideShouldTestInside?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let cachedPoint: GlobalPoint | null = null;
|
||||||
|
let cachedElement: WeakRef<ExcalidrawElement> | null = null;
|
||||||
|
let cachedThreshold: number = Infinity;
|
||||||
|
let cachedHit: boolean = false;
|
||||||
|
let cachedOverrideShouldTestInside = false;
|
||||||
|
|
||||||
export const hitElementItself = ({
|
export const hitElementItself = ({
|
||||||
point,
|
point,
|
||||||
element,
|
element,
|
||||||
@@ -113,6 +122,24 @@ export const hitElementItself = ({
|
|||||||
frameNameBound = null,
|
frameNameBound = null,
|
||||||
overrideShouldTestInside = false,
|
overrideShouldTestInside = false,
|
||||||
}: HitTestArgs) => {
|
}: HitTestArgs) => {
|
||||||
|
// Return cached result if the same point and element version is tested again
|
||||||
|
if (
|
||||||
|
cachedPoint &&
|
||||||
|
pointsEqual(point, cachedPoint) &&
|
||||||
|
cachedThreshold <= threshold &&
|
||||||
|
overrideShouldTestInside === cachedOverrideShouldTestInside
|
||||||
|
) {
|
||||||
|
const derefElement = cachedElement?.deref();
|
||||||
|
if (
|
||||||
|
derefElement &&
|
||||||
|
derefElement.id === element.id &&
|
||||||
|
derefElement.version === element.version &&
|
||||||
|
derefElement.versionNonce === element.versionNonce
|
||||||
|
) {
|
||||||
|
return cachedHit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hit test against a frame's name
|
// Hit test against a frame's name
|
||||||
const hitFrameName = frameNameBound
|
const hitFrameName = frameNameBound
|
||||||
? isPointWithinBounds(
|
? isPointWithinBounds(
|
||||||
@@ -153,7 +180,16 @@ export const hitElementItself = ({
|
|||||||
isPointOnElementOutline(point, element, elementsMap, threshold)
|
isPointOnElementOutline(point, element, elementsMap, threshold)
|
||||||
: isPointOnElementOutline(point, element, elementsMap, threshold);
|
: isPointOnElementOutline(point, element, elementsMap, threshold);
|
||||||
|
|
||||||
return hitElement || hitFrameName;
|
const result = hitElement || hitFrameName;
|
||||||
|
|
||||||
|
// Cache end result
|
||||||
|
cachedPoint = point;
|
||||||
|
cachedElement = new WeakRef(element);
|
||||||
|
cachedThreshold = threshold;
|
||||||
|
cachedOverrideShouldTestInside = overrideShouldTestInside;
|
||||||
|
cachedHit = result;
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hitElementBoundingBox = (
|
export const hitElementBoundingBox = (
|
||||||
@@ -257,7 +293,7 @@ export const getAllHoveredElementAtPoint = (
|
|||||||
point: Readonly<GlobalPoint>,
|
point: Readonly<GlobalPoint>,
|
||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
toleranceFn?: (element: ExcalidrawBindableElement) => number,
|
tolerance?: number,
|
||||||
): NonDeleted<ExcalidrawBindableElement>[] => {
|
): NonDeleted<ExcalidrawBindableElement>[] => {
|
||||||
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
||||||
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||||
@@ -273,7 +309,7 @@ export const getAllHoveredElementAtPoint = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
isBindableElement(element, false) &&
|
isBindableElement(element, false) &&
|
||||||
bindingBorderTest(element, point, elementsMap, toleranceFn?.(element))
|
bindingBorderTest(element, point, elementsMap, tolerance)
|
||||||
) {
|
) {
|
||||||
candidateElements.push(element);
|
candidateElements.push(element);
|
||||||
|
|
||||||
@@ -290,13 +326,13 @@ export const getHoveredElementForBinding = (
|
|||||||
point: Readonly<GlobalPoint>,
|
point: Readonly<GlobalPoint>,
|
||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
toleranceFn?: (element: ExcalidrawBindableElement) => number,
|
tolerance?: number,
|
||||||
): NonDeleted<ExcalidrawBindableElement> | null => {
|
): NonDeleted<ExcalidrawBindableElement> | null => {
|
||||||
const candidateElements = getAllHoveredElementAtPoint(
|
const candidateElements = getAllHoveredElementAtPoint(
|
||||||
point,
|
point,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
toleranceFn,
|
tolerance,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!candidateElements || candidateElements.length === 0) {
|
if (!candidateElements || candidateElements.length === 0) {
|
||||||
@@ -315,6 +351,56 @@ export const getHoveredElementForBinding = (
|
|||||||
.pop() as NonDeleted<ExcalidrawBindableElement>;
|
.pop() as NonDeleted<ExcalidrawBindableElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getHoveredElementForFocusPoint = (
|
||||||
|
point: GlobalPoint,
|
||||||
|
arrow: ExcalidrawArrowElement,
|
||||||
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
|
tolerance?: number,
|
||||||
|
): ExcalidrawBindableElement | null => {
|
||||||
|
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
||||||
|
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||||
|
// because array is ordered from lower z-index to highest and we want element z-index
|
||||||
|
// with higher z-index
|
||||||
|
for (let index = elements.length - 1; index >= 0; --index) {
|
||||||
|
const element = elements[index];
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
!element.isDeleted,
|
||||||
|
"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
isBindableElement(element, false) &&
|
||||||
|
bindingBorderTest(element, point, elementsMap, tolerance)
|
||||||
|
) {
|
||||||
|
candidateElements.push(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!candidateElements || candidateElements.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidateElements.length === 1) {
|
||||||
|
return candidateElements[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const distanceFilteredCandidateElements = candidateElements
|
||||||
|
// Resolve by distance
|
||||||
|
.filter(
|
||||||
|
(el) =>
|
||||||
|
distanceToElement(el, elementsMap, point) <= getBindingGap(el, arrow) ||
|
||||||
|
isPointInElement(point, el, elementsMap),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (distanceFilteredCandidateElements.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return distanceFilteredCandidateElements[0] as NonDeleted<ExcalidrawBindableElement>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intersect a line with an element for binding test
|
* Intersect a line with an element for binding test
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
|
import { updateBoundElements } from "./binding";
|
||||||
import { getCommonBoundingBox } from "./bounds";
|
import { getCommonBoundingBox } from "./bounds";
|
||||||
import { newElementWith } from "./mutateElement";
|
|
||||||
|
|
||||||
import { getSelectedElementsByGroup } from "./groups";
|
import { getSelectedElementsByGroup } from "./groups";
|
||||||
|
|
||||||
|
import type { Scene } from "./Scene";
|
||||||
|
|
||||||
import type { ElementsMap, ExcalidrawElement } from "./types";
|
import type { ElementsMap, ExcalidrawElement } from "./types";
|
||||||
|
|
||||||
export interface Distribution {
|
export interface Distribution {
|
||||||
@@ -17,6 +19,7 @@ export const distributeElements = (
|
|||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
distribution: Distribution,
|
distribution: Distribution,
|
||||||
appState: Readonly<AppState>,
|
appState: Readonly<AppState>,
|
||||||
|
scene: Scene,
|
||||||
): ExcalidrawElement[] => {
|
): ExcalidrawElement[] => {
|
||||||
const [start, mid, end, extent] =
|
const [start, mid, end, extent] =
|
||||||
distribution.axis === "x"
|
distribution.axis === "x"
|
||||||
@@ -66,12 +69,16 @@ export const distributeElements = (
|
|||||||
translation[distribution.axis] = pos - box[mid];
|
translation[distribution.axis] = pos - box[mid];
|
||||||
}
|
}
|
||||||
|
|
||||||
return group.map((element) =>
|
return group.map((element) => {
|
||||||
newElementWith(element, {
|
const updatedElement = scene.mutateElement(element, {
|
||||||
x: element.x + translation.x,
|
x: element.x + translation.x,
|
||||||
y: element.y + translation.y,
|
y: element.y + translation.y,
|
||||||
}),
|
});
|
||||||
);
|
updateBoundElements(element, scene, {
|
||||||
|
simultaneouslyUpdated: group,
|
||||||
|
});
|
||||||
|
return updatedElement;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +97,15 @@ export const distributeElements = (
|
|||||||
pos += step;
|
pos += step;
|
||||||
pos += box[extent];
|
pos += box[extent];
|
||||||
|
|
||||||
return group.map((element) =>
|
return group.map((element) => {
|
||||||
newElementWith(element, {
|
const updatedElement = scene.mutateElement(element, {
|
||||||
x: element.x + translation.x,
|
x: element.x + translation.x,
|
||||||
y: element.y + translation.y,
|
y: element.y + translation.y,
|
||||||
}),
|
});
|
||||||
);
|
updateBoundElements(element, scene, {
|
||||||
|
simultaneouslyUpdated: group,
|
||||||
|
});
|
||||||
|
return updatedElement;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2277,7 +2277,10 @@ const getHoveredElement = (
|
|||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
zoom?: AppState["zoom"],
|
zoom?: AppState["zoom"],
|
||||||
) => {
|
) => {
|
||||||
return getHoveredElementForBinding(origPoint, elements, elementsMap, () =>
|
return getHoveredElementForBinding(
|
||||||
|
origPoint,
|
||||||
|
elements,
|
||||||
|
elementsMap,
|
||||||
maxBindingDistance_simple(zoom),
|
maxBindingDistance_simple(zoom),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ const RE_REDDIT =
|
|||||||
const RE_REDDIT_EMBED =
|
const RE_REDDIT_EMBED =
|
||||||
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
||||||
|
|
||||||
const parseYouTubeTimestamp = (url: string): number => {
|
const parseYouTubeLikeTimestamp = (url: string): number => {
|
||||||
let timeParam: string | null | undefined;
|
let timeParam: string | null | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -85,11 +85,57 @@ const parseYouTubeTimestamp = (url: string): number => {
|
|||||||
return parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
|
return parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseGoogleDriveVideoLink = (
|
||||||
|
url: string,
|
||||||
|
): { fileId: string; resourceKey?: string; timestamp?: number } | null => {
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(url.startsWith("http") ? url : `https://${url}`);
|
||||||
|
const hostname = urlObj.hostname.replace(/^www\./, "");
|
||||||
|
if (hostname !== "drive.google.com") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileId: string | null = null;
|
||||||
|
const pathMatch = urlObj.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);
|
||||||
|
if (pathMatch?.[1]) {
|
||||||
|
fileId = pathMatch[1];
|
||||||
|
} else if (urlObj.pathname === "/open" || urlObj.pathname === "/uc") {
|
||||||
|
// Shared Drive links can be emitted as:
|
||||||
|
// - /open?id=<fileId> (common "open in Drive" format)
|
||||||
|
// - /uc?...&id=<fileId> (download/export endpoint often seen in copied links)
|
||||||
|
fileId = urlObj.searchParams.get("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileId || !/^[a-zA-Z0-9_-]+$/.test(fileId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some Drive share links include `resourcekey` for access to link-shared
|
||||||
|
// files; preserve it in the preview URL so embeds keep working.
|
||||||
|
const resourceKey = urlObj.searchParams.get("resourcekey");
|
||||||
|
const timestamp = parseYouTubeLikeTimestamp(urlObj.toString());
|
||||||
|
|
||||||
|
return {
|
||||||
|
fileId,
|
||||||
|
resourceKey:
|
||||||
|
resourceKey && /^[a-zA-Z0-9_-]+$/.test(resourceKey)
|
||||||
|
? resourceKey
|
||||||
|
: undefined,
|
||||||
|
// Drive accepts YouTube-like `t` formats (e.g. `t=90`, `t=1m30s`);
|
||||||
|
// normalize to seconds for a stable preview URL.
|
||||||
|
timestamp: timestamp > 0 ? timestamp : undefined,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const ALLOWED_DOMAINS = new Set([
|
const ALLOWED_DOMAINS = new Set([
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"youtu.be",
|
"youtu.be",
|
||||||
"vimeo.com",
|
"vimeo.com",
|
||||||
"player.vimeo.com",
|
"player.vimeo.com",
|
||||||
|
"drive.google.com",
|
||||||
"figma.com",
|
"figma.com",
|
||||||
"link.excalidraw.com",
|
"link.excalidraw.com",
|
||||||
"gist.github.com",
|
"gist.github.com",
|
||||||
@@ -108,6 +154,7 @@ const ALLOW_SAME_ORIGIN = new Set([
|
|||||||
"youtu.be",
|
"youtu.be",
|
||||||
"vimeo.com",
|
"vimeo.com",
|
||||||
"player.vimeo.com",
|
"player.vimeo.com",
|
||||||
|
"drive.google.com",
|
||||||
"figma.com",
|
"figma.com",
|
||||||
"twitter.com",
|
"twitter.com",
|
||||||
"x.com",
|
"x.com",
|
||||||
@@ -142,7 +189,7 @@ export const getEmbedLink = (
|
|||||||
let aspectRatio = { w: 560, h: 840 };
|
let aspectRatio = { w: 560, h: 840 };
|
||||||
const ytLink = link.match(RE_YOUTUBE);
|
const ytLink = link.match(RE_YOUTUBE);
|
||||||
if (ytLink?.[2]) {
|
if (ytLink?.[2]) {
|
||||||
const startTime = parseYouTubeTimestamp(originalLink);
|
const startTime = parseYouTubeLikeTimestamp(originalLink);
|
||||||
const time = startTime > 0 ? `&start=${startTime}` : ``;
|
const time = startTime > 0 ? `&start=${startTime}` : ``;
|
||||||
const isPortrait = link.includes("shorts");
|
const isPortrait = link.includes("shorts");
|
||||||
type = "video";
|
type = "video";
|
||||||
@@ -201,6 +248,36 @@ export const getEmbedLink = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const googleDriveVideo = parseGoogleDriveVideoLink(link);
|
||||||
|
if (googleDriveVideo) {
|
||||||
|
type = "video";
|
||||||
|
const searchParams = new URLSearchParams();
|
||||||
|
if (googleDriveVideo.resourceKey) {
|
||||||
|
searchParams.set("resourcekey", googleDriveVideo.resourceKey);
|
||||||
|
}
|
||||||
|
if (googleDriveVideo.timestamp) {
|
||||||
|
searchParams.set("t", `${googleDriveVideo.timestamp}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const search = searchParams.toString();
|
||||||
|
link = `https://drive.google.com/file/d/${googleDriveVideo.fileId}/preview${
|
||||||
|
search ? `?${search}` : ""
|
||||||
|
}`;
|
||||||
|
aspectRatio = { w: 560, h: 315 };
|
||||||
|
embeddedLinkCache.set(originalLink, {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
link,
|
||||||
|
intrinsicSize: aspectRatio,
|
||||||
|
type,
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const figmaLink = link.match(RE_FIGMA);
|
const figmaLink = link.match(RE_FIGMA);
|
||||||
if (figmaLink) {
|
if (figmaLink) {
|
||||||
type = "generic";
|
type = "generic";
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export * from "./elbowArrow";
|
|||||||
export * from "./elementLink";
|
export * from "./elementLink";
|
||||||
export * from "./embeddable";
|
export * from "./embeddable";
|
||||||
export * from "./flowchart";
|
export * from "./flowchart";
|
||||||
|
export * from "./arrows/focus";
|
||||||
export * from "./fractionalIndex";
|
export * from "./fractionalIndex";
|
||||||
export * from "./frame";
|
export * from "./frame";
|
||||||
export * from "./groups";
|
export * from "./groups";
|
||||||
@@ -97,3 +98,4 @@ export * from "./transformHandles";
|
|||||||
export * from "./typeChecks";
|
export * from "./typeChecks";
|
||||||
export * from "./utils";
|
export * from "./utils";
|
||||||
export * from "./zindex";
|
export * from "./zindex";
|
||||||
|
export * from "./arrows/helpers";
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
vectorFromPoint,
|
vectorFromPoint,
|
||||||
curveLength,
|
curveLength,
|
||||||
curvePointAtLength,
|
curvePointAtLength,
|
||||||
lineSegment,
|
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { getCurvePathOps } from "@excalidraw/utils/shape";
|
import { getCurvePathOps } from "@excalidraw/utils/shape";
|
||||||
@@ -27,6 +26,7 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
deconstructLinearOrFreeDrawElement,
|
deconstructLinearOrFreeDrawElement,
|
||||||
|
getSnapOutlineMidPoint,
|
||||||
isPathALoop,
|
isPathALoop,
|
||||||
moveArrowAboveBindable,
|
moveArrowAboveBindable,
|
||||||
projectFixedPointOntoDiagonal,
|
projectFixedPointOntoDiagonal,
|
||||||
@@ -49,6 +49,7 @@ import {
|
|||||||
calculateFixedPointForNonElbowArrowBinding,
|
calculateFixedPointForNonElbowArrowBinding,
|
||||||
getBindingStrategyForDraggingBindingElementEndpoints,
|
getBindingStrategyForDraggingBindingElementEndpoints,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
|
snapToMid,
|
||||||
updateBoundPoint,
|
updateBoundPoint,
|
||||||
} from "./binding";
|
} from "./binding";
|
||||||
import {
|
import {
|
||||||
@@ -150,6 +151,8 @@ export class LinearElementEditor {
|
|||||||
public readonly pointerOffset: Readonly<{ x: number; y: number }>;
|
public readonly pointerOffset: Readonly<{ x: number; y: number }>;
|
||||||
public readonly hoverPointIndex: number;
|
public readonly hoverPointIndex: number;
|
||||||
public readonly segmentMidPointHoveredCoords: GlobalPoint | null;
|
public readonly segmentMidPointHoveredCoords: GlobalPoint | null;
|
||||||
|
public readonly hoveredFocusPointBinding: "start" | "end" | null;
|
||||||
|
public readonly draggedFocusPointBinding: "start" | "end" | null;
|
||||||
public readonly elbowed: boolean;
|
public readonly elbowed: boolean;
|
||||||
public readonly customLineAngle: number | null;
|
public readonly customLineAngle: number | null;
|
||||||
public readonly isEditing: boolean;
|
public readonly isEditing: boolean;
|
||||||
@@ -195,6 +198,8 @@ export class LinearElementEditor {
|
|||||||
};
|
};
|
||||||
this.hoverPointIndex = -1;
|
this.hoverPointIndex = -1;
|
||||||
this.segmentMidPointHoveredCoords = null;
|
this.segmentMidPointHoveredCoords = null;
|
||||||
|
this.hoveredFocusPointBinding = null;
|
||||||
|
this.draggedFocusPointBinding = null;
|
||||||
this.elbowed = isElbowArrow(element) && element.elbowed;
|
this.elbowed = isElbowArrow(element) && element.elbowed;
|
||||||
this.customLineAngle = null;
|
this.customLineAngle = null;
|
||||||
this.isEditing = isEditing;
|
this.isEditing = isEditing;
|
||||||
@@ -352,6 +357,7 @@ export class LinearElementEditor {
|
|||||||
app,
|
app,
|
||||||
shouldRotateWithDiscreteAngle(event),
|
shouldRotateWithDiscreteAngle(event),
|
||||||
event.altKey,
|
event.altKey,
|
||||||
|
linearElementEditor,
|
||||||
);
|
);
|
||||||
|
|
||||||
LinearElementEditor.movePoints(element, app.scene, positions, {
|
LinearElementEditor.movePoints(element, app.scene, positions, {
|
||||||
@@ -405,13 +411,14 @@ export class LinearElementEditor {
|
|||||||
altFocusPoint:
|
altFocusPoint:
|
||||||
!linearElementEditor.initialState.altFocusPoint &&
|
!linearElementEditor.initialState.altFocusPoint &&
|
||||||
startBindingElement &&
|
startBindingElement &&
|
||||||
updates?.suggestedBinding?.id !== startBindingElement.id
|
updates?.suggestedBinding?.element.id !== startBindingElement.id
|
||||||
? projectFixedPointOntoDiagonal(
|
? projectFixedPointOntoDiagonal(
|
||||||
element,
|
element,
|
||||||
pointFrom<GlobalPoint>(element.x, element.y),
|
pointFrom<GlobalPoint>(element.x, element.y),
|
||||||
startBindingElement,
|
startBindingElement,
|
||||||
"start",
|
"start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
app.state.zoom,
|
||||||
)
|
)
|
||||||
: linearElementEditor.initialState.altFocusPoint,
|
: linearElementEditor.initialState.altFocusPoint,
|
||||||
},
|
},
|
||||||
@@ -529,6 +536,7 @@ export class LinearElementEditor {
|
|||||||
app,
|
app,
|
||||||
shouldRotateWithDiscreteAngle(event) && singlePointDragged,
|
shouldRotateWithDiscreteAngle(event) && singlePointDragged,
|
||||||
event.altKey,
|
event.altKey,
|
||||||
|
linearElementEditor,
|
||||||
);
|
);
|
||||||
|
|
||||||
LinearElementEditor.movePoints(element, app.scene, positions, {
|
LinearElementEditor.movePoints(element, app.scene, positions, {
|
||||||
@@ -604,13 +612,13 @@ export class LinearElementEditor {
|
|||||||
const altFocusPointBindableElement =
|
const altFocusPointBindableElement =
|
||||||
endIsSelected && // The "other" end (i.e. "end") is dragged
|
endIsSelected && // The "other" end (i.e. "end") is dragged
|
||||||
startBindingElement &&
|
startBindingElement &&
|
||||||
updates?.suggestedBinding?.id !== startBindingElement.id // The end point is not hovering the start bindable + it's binding gap
|
updates?.suggestedBinding?.element.id !== startBindingElement.id // The end point is not hovering the start bindable + it's binding gap
|
||||||
? startBindingElement
|
? startBindingElement
|
||||||
: startIsSelected && // The "other" end (i.e. "start") is dragged
|
: startIsSelected && // The "other" end (i.e. "start") is dragged
|
||||||
endBindingElement &&
|
endBindingElement &&
|
||||||
updates?.suggestedBinding?.id !== endBindingElement.id // The start point is not hovering the end bindable + it's binding gap
|
updates?.suggestedBinding?.element.id !== endBindingElement.id // The start point is not hovering the end bindable + it's binding gap
|
||||||
? endBindingElement
|
? endBindingElement
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const newLinearElementEditor: LinearElementEditor = {
|
const newLinearElementEditor: LinearElementEditor = {
|
||||||
...linearElementEditor,
|
...linearElementEditor,
|
||||||
@@ -628,6 +636,7 @@ export class LinearElementEditor {
|
|||||||
altFocusPointBindableElement,
|
altFocusPointBindableElement,
|
||||||
"start",
|
"start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
app.state.zoom,
|
||||||
)
|
)
|
||||||
: linearElementEditor.initialState.altFocusPoint,
|
: linearElementEditor.initialState.altFocusPoint,
|
||||||
},
|
},
|
||||||
@@ -725,7 +734,6 @@ export class LinearElementEditor {
|
|||||||
? [pointerDownState.lastClickedPoint]
|
? [pointerDownState.lastClickedPoint]
|
||||||
: selectedPointsIndices,
|
: selectedPointsIndices,
|
||||||
isDragging: false,
|
isDragging: false,
|
||||||
pointerOffset: { x: 0, y: 0 },
|
|
||||||
customLineAngle: null,
|
customLineAngle: null,
|
||||||
initialState: {
|
initialState: {
|
||||||
...editingLinearElement.initialState,
|
...editingLinearElement.initialState,
|
||||||
@@ -2078,6 +2086,7 @@ const pointDraggingUpdates = (
|
|||||||
app: AppClassProperties,
|
app: AppClassProperties,
|
||||||
angleLocked: boolean,
|
angleLocked: boolean,
|
||||||
altKey: boolean,
|
altKey: boolean,
|
||||||
|
linearElementEditor: LinearElementEditor,
|
||||||
): {
|
): {
|
||||||
positions: PointsPositionUpdates;
|
positions: PointsPositionUpdates;
|
||||||
updates?: PointMoveOtherUpdates;
|
updates?: PointMoveOtherUpdates;
|
||||||
@@ -2125,18 +2134,89 @@ const pointDraggingUpdates = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isElbowArrow(element)) {
|
if (isElbowArrow(element)) {
|
||||||
|
const suggestedBindingElement = startIsDragged
|
||||||
|
? start.element
|
||||||
|
: endIsDragged
|
||||||
|
? end.element
|
||||||
|
: null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
positions: naiveDraggingPoints,
|
positions: naiveDraggingPoints,
|
||||||
updates: {
|
updates: {
|
||||||
suggestedBinding: startIsDragged
|
suggestedBinding: suggestedBindingElement
|
||||||
? start.element
|
? {
|
||||||
: endIsDragged
|
element: suggestedBindingElement,
|
||||||
? end.element
|
midPoint: snapToMid(
|
||||||
: null,
|
suggestedBindingElement,
|
||||||
|
elementsMap,
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
||||||
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the case where neither endpoint is being dragged
|
||||||
|
// but we need to update bound endpoints
|
||||||
|
if (!startIsDragged && !endIsDragged) {
|
||||||
|
const nextArrow = {
|
||||||
|
...element,
|
||||||
|
points: element.points.map((p, idx) => {
|
||||||
|
return naiveDraggingPoints.get(idx)?.point ?? p;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
const positions = new Map(naiveDraggingPoints);
|
||||||
|
|
||||||
|
if (element.startBinding) {
|
||||||
|
const startBindable = elementsMap.get(element.startBinding.elementId) as
|
||||||
|
| ExcalidrawBindableElement
|
||||||
|
| undefined;
|
||||||
|
if (startBindable) {
|
||||||
|
const startPoint =
|
||||||
|
updateBoundPoint(
|
||||||
|
nextArrow,
|
||||||
|
"startBinding",
|
||||||
|
element.startBinding,
|
||||||
|
startBindable,
|
||||||
|
elementsMap,
|
||||||
|
) ?? null;
|
||||||
|
if (startPoint) {
|
||||||
|
positions.set(0, { point: startPoint, isDragging: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.endBinding) {
|
||||||
|
const endBindable = elementsMap.get(element.endBinding.elementId) as
|
||||||
|
| ExcalidrawBindableElement
|
||||||
|
| undefined;
|
||||||
|
if (endBindable) {
|
||||||
|
const endPoint =
|
||||||
|
updateBoundPoint(
|
||||||
|
nextArrow,
|
||||||
|
"endBinding",
|
||||||
|
element.endBinding,
|
||||||
|
endBindable,
|
||||||
|
elementsMap,
|
||||||
|
) ?? null;
|
||||||
|
if (endPoint) {
|
||||||
|
positions.set(element.points.length - 1, {
|
||||||
|
point: endPoint,
|
||||||
|
isDragging: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
positions,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (startIsDragged === endIsDragged) {
|
if (startIsDragged === endIsDragged) {
|
||||||
return {
|
return {
|
||||||
positions: naiveDraggingPoints,
|
positions: naiveDraggingPoints,
|
||||||
@@ -2167,7 +2247,20 @@ const pointDraggingUpdates = (
|
|||||||
(updates.startBinding.mode === "orbit" ||
|
(updates.startBinding.mode === "orbit" ||
|
||||||
!getFeatureFlag("COMPLEX_BINDINGS"))
|
!getFeatureFlag("COMPLEX_BINDINGS"))
|
||||||
) {
|
) {
|
||||||
updates.suggestedBinding = start.element;
|
updates.suggestedBinding = start.element
|
||||||
|
? {
|
||||||
|
element: start.element,
|
||||||
|
midPoint: getSnapOutlineMidPoint(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
||||||
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
||||||
|
),
|
||||||
|
start.element,
|
||||||
|
elementsMap,
|
||||||
|
app.state.zoom,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
} else if (startIsDragged) {
|
} else if (startIsDragged) {
|
||||||
updates.suggestedBinding = app.state.suggestedBinding;
|
updates.suggestedBinding = app.state.suggestedBinding;
|
||||||
@@ -2193,7 +2286,20 @@ const pointDraggingUpdates = (
|
|||||||
(updates.endBinding.mode === "orbit" ||
|
(updates.endBinding.mode === "orbit" ||
|
||||||
!getFeatureFlag("COMPLEX_BINDINGS"))
|
!getFeatureFlag("COMPLEX_BINDINGS"))
|
||||||
) {
|
) {
|
||||||
updates.suggestedBinding = end.element;
|
updates.suggestedBinding = end.element
|
||||||
|
? {
|
||||||
|
element: end.element,
|
||||||
|
midPoint: getSnapOutlineMidPoint(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
||||||
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
||||||
|
),
|
||||||
|
end.element,
|
||||||
|
elementsMap,
|
||||||
|
app.state.zoom,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
} else if (endIsDragged) {
|
} else if (endIsDragged) {
|
||||||
updates.suggestedBinding = app.state.suggestedBinding;
|
updates.suggestedBinding = app.state.suggestedBinding;
|
||||||
@@ -2233,19 +2339,6 @@ const pointDraggingUpdates = (
|
|||||||
: updates.endBinding,
|
: updates.endBinding,
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to use a custom intersector to ensure that if there is a big "jump"
|
|
||||||
// in the arrow's position, we can position it with outline avoidance
|
|
||||||
// pixel-perfectly and avoid "dancing" arrows.
|
|
||||||
// NOTE: Direction matters here, so we create two intersectors
|
|
||||||
const startCustomIntersector =
|
|
||||||
start.focusPoint && end.focusPoint
|
|
||||||
? lineSegment(start.focusPoint, end.focusPoint)
|
|
||||||
: undefined;
|
|
||||||
const endCustomIntersector =
|
|
||||||
start.focusPoint && end.focusPoint
|
|
||||||
? lineSegment(end.focusPoint, start.focusPoint)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// Needed to handle a special case where an existing arrow is dragged over
|
// Needed to handle a special case where an existing arrow is dragged over
|
||||||
// the same element it is bound to on the other side
|
// the same element it is bound to on the other side
|
||||||
const startIsDraggingOverEndElement =
|
const startIsDraggingOverEndElement =
|
||||||
@@ -2271,19 +2364,19 @@ const pointDraggingUpdates = (
|
|||||||
const endLocalPoint = startIsDraggingOverEndElement
|
const endLocalPoint = startIsDraggingOverEndElement
|
||||||
? nextArrow.points[nextArrow.points.length - 1]
|
? nextArrow.points[nextArrow.points.length - 1]
|
||||||
: endIsDraggingOverStartElement &&
|
: endIsDraggingOverStartElement &&
|
||||||
app.state.bindMode !== "inside" &&
|
app.state.bindMode !== "inside" &&
|
||||||
getFeatureFlag("COMPLEX_BINDINGS")
|
getFeatureFlag("COMPLEX_BINDINGS")
|
||||||
? nextArrow.points[0]
|
? nextArrow.points[0]
|
||||||
: endBindable
|
: endBindable
|
||||||
? updateBoundPoint(
|
? updateBoundPoint(
|
||||||
element,
|
element,
|
||||||
"endBinding",
|
"endBinding",
|
||||||
nextArrow.endBinding,
|
nextArrow.endBinding,
|
||||||
endBindable,
|
endBindable,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
endCustomIntersector,
|
endIsDragged,
|
||||||
) || nextArrow.points[nextArrow.points.length - 1]
|
) || nextArrow.points[nextArrow.points.length - 1]
|
||||||
: nextArrow.points[nextArrow.points.length - 1];
|
: nextArrow.points[nextArrow.points.length - 1];
|
||||||
|
|
||||||
// We need to keep the simulated next arrow up-to-date, because
|
// We need to keep the simulated next arrow up-to-date, because
|
||||||
// updateBoundPoint looks at the opposite point
|
// updateBoundPoint looks at the opposite point
|
||||||
@@ -2302,25 +2395,28 @@ const pointDraggingUpdates = (
|
|||||||
endIsDraggingOverStartElement && getFeatureFlag("COMPLEX_BINDINGS")
|
endIsDraggingOverStartElement && getFeatureFlag("COMPLEX_BINDINGS")
|
||||||
? nextArrow.points[0]
|
? nextArrow.points[0]
|
||||||
: startIsDraggingOverEndElement &&
|
: startIsDraggingOverEndElement &&
|
||||||
app.state.bindMode !== "inside" &&
|
app.state.bindMode !== "inside" &&
|
||||||
getFeatureFlag("COMPLEX_BINDINGS")
|
getFeatureFlag("COMPLEX_BINDINGS")
|
||||||
? nextArrow.points[nextArrow.points.length - 1]
|
? endLocalPoint
|
||||||
: startBindable
|
: startBindable
|
||||||
? updateBoundPoint(
|
? updateBoundPoint(
|
||||||
element,
|
element,
|
||||||
"startBinding",
|
"startBinding",
|
||||||
nextArrow.startBinding,
|
nextArrow.startBinding,
|
||||||
startBindable,
|
startBindable,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
startCustomIntersector,
|
startIsDragged,
|
||||||
) || nextArrow.points[0]
|
) || nextArrow.points[0]
|
||||||
: nextArrow.points[0];
|
: nextArrow.points[0];
|
||||||
|
|
||||||
const endChanged =
|
const endChanged =
|
||||||
pointDistance(
|
!startIsDraggingOverEndElement &&
|
||||||
endLocalPoint,
|
!(
|
||||||
nextArrow.points[nextArrow.points.length - 1],
|
endIsDraggingOverStartElement &&
|
||||||
) !== 0;
|
app.state.bindMode !== "inside" &&
|
||||||
|
getFeatureFlag("COMPLEX_BINDINGS")
|
||||||
|
) &&
|
||||||
|
!!endBindable;
|
||||||
const startChanged =
|
const startChanged =
|
||||||
pointDistance(startLocalPoint, nextArrow.points[0]) !== 0;
|
pointDistance(startLocalPoint, nextArrow.points[0]) !== 0;
|
||||||
|
|
||||||
@@ -2334,13 +2430,7 @@ const pointDraggingUpdates = (
|
|||||||
const indices = Array.from(indicesSet);
|
const indices = Array.from(indicesSet);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updates:
|
updates,
|
||||||
updates.startBinding || updates.suggestedBinding
|
|
||||||
? {
|
|
||||||
startBinding: updates.startBinding,
|
|
||||||
suggestedBinding: updates.suggestedBinding,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
positions: new Map(
|
positions: new Map(
|
||||||
indices.map((idx) => {
|
indices.map((idx) => {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
getVerticalOffset,
|
getVerticalOffset,
|
||||||
invariant,
|
invariant,
|
||||||
applyDarkModeFilter,
|
applyDarkModeFilter,
|
||||||
|
isSafari,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -360,8 +361,9 @@ IMAGE_ERROR_PLACEHOLDER_IMG.src = `data:${MIME_TYPES.svg},${encodeURIComponent(
|
|||||||
const drawImagePlaceholder = (
|
const drawImagePlaceholder = (
|
||||||
element: ExcalidrawImageElement,
|
element: ExcalidrawImageElement,
|
||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
|
theme: StaticCanvasRenderConfig["theme"],
|
||||||
) => {
|
) => {
|
||||||
context.fillStyle = "#E7E7E7";
|
context.fillStyle = theme === THEME.DARK ? "#2E2E2E" : "#E7E7E7";
|
||||||
context.fillRect(0, 0, element.width, element.height);
|
context.fillRect(0, 0, element.width, element.height);
|
||||||
|
|
||||||
const imageMinWidthOrHeight = Math.min(element.width, element.height);
|
const imageMinWidthOrHeight = Math.min(element.width, element.height);
|
||||||
@@ -443,13 +445,6 @@ const drawElementOnCanvas = (
|
|||||||
? cacheEntry?.image
|
? cacheEntry?.image
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const shouldInvertImage =
|
|
||||||
renderConfig.theme === THEME.DARK &&
|
|
||||||
cacheEntry?.mimeType === MIME_TYPES.svg;
|
|
||||||
|
|
||||||
if (shouldInvertImage) {
|
|
||||||
context.filter = DARK_THEME_FILTER;
|
|
||||||
}
|
|
||||||
if (img != null && !(img instanceof Promise)) {
|
if (img != null && !(img instanceof Promise)) {
|
||||||
if (element.roundness && context.roundRect) {
|
if (element.roundness && context.roundRect) {
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
@@ -472,19 +467,78 @@ const drawElementOnCanvas = (
|
|||||||
height: img.naturalHeight,
|
height: img.naturalHeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
context.drawImage(
|
const shouldInvertImage =
|
||||||
img,
|
renderConfig.theme === THEME.DARK &&
|
||||||
x,
|
cacheEntry?.mimeType === MIME_TYPES.svg;
|
||||||
y,
|
|
||||||
width,
|
if (shouldInvertImage && isSafari) {
|
||||||
height,
|
const devicePixelRatio = window.devicePixelRatio || 1;
|
||||||
0 /* hardcoded for the selection box*/,
|
const tempCanvas = document.createElement("canvas");
|
||||||
0,
|
tempCanvas.width = element.width * devicePixelRatio;
|
||||||
element.width,
|
tempCanvas.height = element.height * devicePixelRatio;
|
||||||
element.height,
|
const tempContext = tempCanvas.getContext("2d");
|
||||||
);
|
|
||||||
|
if (tempContext) {
|
||||||
|
tempContext.scale(devicePixelRatio, devicePixelRatio);
|
||||||
|
tempContext.drawImage(
|
||||||
|
img,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
element.width,
|
||||||
|
element.height,
|
||||||
|
);
|
||||||
|
|
||||||
|
const imageData = tempContext.getImageData(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
tempCanvas.width,
|
||||||
|
tempCanvas.height,
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = imageData.data;
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
data[i] = 255 - data[i];
|
||||||
|
data[i + 1] = 255 - data[i + 1];
|
||||||
|
data[i + 2] = 255 - data[i + 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
tempContext.putImageData(imageData, 0, 0);
|
||||||
|
context.drawImage(
|
||||||
|
tempCanvas,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
tempCanvas.width,
|
||||||
|
tempCanvas.height,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
element.width,
|
||||||
|
element.height,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (shouldInvertImage) {
|
||||||
|
context.filter = DARK_THEME_FILTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.drawImage(
|
||||||
|
img,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
0 /* hardcoded for the selection box*/,
|
||||||
|
0,
|
||||||
|
element.width,
|
||||||
|
element.height,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
drawImagePlaceholder(element, context);
|
drawImagePlaceholder(element, context, renderConfig.theme);
|
||||||
}
|
}
|
||||||
context.restore();
|
context.restore();
|
||||||
break;
|
break;
|
||||||
|
|||||||
+149
-26
@@ -7,6 +7,7 @@ import {
|
|||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
bezierEquation,
|
||||||
curve,
|
curve,
|
||||||
curveCatmullRomCubicApproxPoints,
|
curveCatmullRomCubicApproxPoints,
|
||||||
curveOffsetPoints,
|
curveOffsetPoints,
|
||||||
@@ -27,19 +28,30 @@ import {
|
|||||||
|
|
||||||
import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";
|
import type {
|
||||||
|
AppState,
|
||||||
|
NormalizedZoomValue,
|
||||||
|
Zoom,
|
||||||
|
} from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
import { elementCenterPoint, getDiamondPoints } from "./bounds";
|
import { elementCenterPoint, getDiamondPoints } from "./bounds";
|
||||||
|
|
||||||
import { generateLinearCollisionShape } from "./shape";
|
import { generateLinearCollisionShape } from "./shape";
|
||||||
|
|
||||||
import { isPointInElement } from "./collision";
|
import { hitElementItself, isPointInElement } from "./collision";
|
||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { isRectangularElement } from "./typeChecks";
|
import { isRectangularElement } from "./typeChecks";
|
||||||
|
import { maxBindingDistance_simple } from "./binding";
|
||||||
|
|
||||||
|
import {
|
||||||
|
getGlobalFixedPointForBindableElement,
|
||||||
|
normalizeFixedPoint,
|
||||||
|
} from "./binding";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
ExcalidrawArrowElement,
|
ExcalidrawArrowElement,
|
||||||
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawFreeDrawElement,
|
ExcalidrawFreeDrawElement,
|
||||||
@@ -329,24 +341,10 @@ export function deconstructRectanguloidElement(
|
|||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function getDiamondBaseCorners(
|
||||||
* Get the **unrotated** building components of a diamond element
|
|
||||||
* in the form of line segments and curves as a tuple, in this order.
|
|
||||||
*
|
|
||||||
* @param element The element to deconstruct
|
|
||||||
* @param offset An optional offset
|
|
||||||
* @returns Tuple of line **unrotated** segments (0) and curves (1)
|
|
||||||
*/
|
|
||||||
export function deconstructDiamondElement(
|
|
||||||
element: ExcalidrawDiamondElement,
|
element: ExcalidrawDiamondElement,
|
||||||
offset: number = 0,
|
offset: number = 0,
|
||||||
): [LineSegment<GlobalPoint>[], Curve<GlobalPoint>[]] {
|
): Curve<GlobalPoint>[] {
|
||||||
const cachedShape = getElementShapesCacheEntry(element, offset);
|
|
||||||
|
|
||||||
if (cachedShape) {
|
|
||||||
return cachedShape;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
|
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
|
||||||
getDiamondPoints(element);
|
getDiamondPoints(element);
|
||||||
const verticalRadius = element.roundness
|
const verticalRadius = element.roundness
|
||||||
@@ -363,7 +361,7 @@ export function deconstructDiamondElement(
|
|||||||
pointFrom(element.x + leftX, element.y + leftY),
|
pointFrom(element.x + leftX, element.y + leftY),
|
||||||
];
|
];
|
||||||
|
|
||||||
const baseCorners = [
|
return [
|
||||||
curve(
|
curve(
|
||||||
pointFrom<GlobalPoint>(
|
pointFrom<GlobalPoint>(
|
||||||
right[0] - verticalRadius,
|
right[0] - verticalRadius,
|
||||||
@@ -413,6 +411,27 @@ export function deconstructDiamondElement(
|
|||||||
),
|
),
|
||||||
), // TOP
|
), // TOP
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the **unrotated** building components of a diamond element
|
||||||
|
* in the form of line segments and curves as a tuple, in this order.
|
||||||
|
*
|
||||||
|
* @param element The element to deconstruct
|
||||||
|
* @param offset An optional offset
|
||||||
|
* @returns Tuple of line **unrotated** segments (0) and curves (1)
|
||||||
|
*/
|
||||||
|
export function deconstructDiamondElement(
|
||||||
|
element: ExcalidrawDiamondElement,
|
||||||
|
offset: number = 0,
|
||||||
|
): [LineSegment<GlobalPoint>[], Curve<GlobalPoint>[]] {
|
||||||
|
const cachedShape = getElementShapesCacheEntry(element, offset);
|
||||||
|
|
||||||
|
if (cachedShape) {
|
||||||
|
return cachedShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseCorners = getDiamondBaseCorners(element, offset);
|
||||||
|
|
||||||
const corners = baseCorners.map(
|
const corners = baseCorners.map(
|
||||||
(corner) =>
|
(corner) =>
|
||||||
@@ -570,28 +589,128 @@ const getDiagonalsForBindableElement = (
|
|||||||
return [diagonalOne, diagonalTwo];
|
return [diagonalOne, diagonalTwo];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getSnapOutlineMidPoint = (
|
||||||
|
point: GlobalPoint,
|
||||||
|
element: ExcalidrawBindableElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
zoom: AppState["zoom"],
|
||||||
|
) => {
|
||||||
|
const center = elementCenterPoint(element, elementsMap);
|
||||||
|
const sideMidpoints =
|
||||||
|
element.type === "diamond"
|
||||||
|
? getDiamondBaseCorners(element).map((curve) => {
|
||||||
|
const point = bezierEquation(curve, 0.5);
|
||||||
|
const rotatedPoint = pointRotateRads(point, center, element.angle);
|
||||||
|
|
||||||
|
return pointFrom<GlobalPoint>(rotatedPoint[0], rotatedPoint[1]);
|
||||||
|
})
|
||||||
|
: [
|
||||||
|
// RIGHT midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width,
|
||||||
|
element.y + element.height / 2,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// BOTTOM midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width / 2,
|
||||||
|
element.y + element.height,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// LEFT midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x, element.y + element.height / 2),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// TOP midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x + element.width / 2, element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
const candidate = sideMidpoints.find(
|
||||||
|
(midpoint) =>
|
||||||
|
pointDistance(point, midpoint) <=
|
||||||
|
maxBindingDistance_simple(zoom) + element.strokeWidth / 2 &&
|
||||||
|
!hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 0,
|
||||||
|
elementsMap,
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return candidate;
|
||||||
|
};
|
||||||
|
|
||||||
export const projectFixedPointOntoDiagonal = (
|
export const projectFixedPointOntoDiagonal = (
|
||||||
arrow: ExcalidrawArrowElement,
|
arrow: ExcalidrawArrowElement,
|
||||||
point: GlobalPoint,
|
point: GlobalPoint,
|
||||||
element: ExcalidrawElement,
|
element: ExcalidrawBindableElement,
|
||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
|
zoom: AppState["zoom"],
|
||||||
): GlobalPoint | null => {
|
): GlobalPoint | null => {
|
||||||
invariant(arrow.points.length >= 2, "Arrow must have at least two points");
|
invariant(arrow.points.length >= 2, "Arrow must have at least two points");
|
||||||
if (arrow.width < 3 && arrow.height < 3) {
|
if (arrow.width < 3 && arrow.height < 3) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sideMidPoint = getSnapOutlineMidPoint(
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
elementsMap,
|
||||||
|
zoom,
|
||||||
|
);
|
||||||
|
if (sideMidPoint) {
|
||||||
|
return sideMidPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the projection onto the diagonals (or center lines
|
||||||
|
// for non-rectangular shapes)
|
||||||
const [diagonalOne, diagonalTwo] = getDiagonalsForBindableElement(
|
const [diagonalOne, diagonalTwo] = getDiagonalsForBindableElement(
|
||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
|
||||||
const a = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
// To avoid working with stale arrow state, we use the opposite focus point
|
||||||
|
// of the current endpoint, which will always be unchanged during moving of
|
||||||
|
// the endpoint. This is only needed when the arrow has only two points.
|
||||||
|
let a = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
arrow,
|
arrow,
|
||||||
startOrEnd === "start" ? 1 : arrow.points.length - 2,
|
startOrEnd === "start" ? 1 : arrow.points.length - 2,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
|
if (arrow.points.length === 2) {
|
||||||
|
const otherBinding =
|
||||||
|
startOrEnd === "start" ? arrow.endBinding : arrow.startBinding;
|
||||||
|
const otherBindable =
|
||||||
|
otherBinding &&
|
||||||
|
(elementsMap.get(otherBinding.elementId) as
|
||||||
|
| ExcalidrawBindableElement
|
||||||
|
| undefined);
|
||||||
|
const otherFocusPoint =
|
||||||
|
otherBinding &&
|
||||||
|
otherBindable &&
|
||||||
|
getGlobalFixedPointForBindableElement(
|
||||||
|
normalizeFixedPoint(otherBinding.fixedPoint),
|
||||||
|
otherBindable,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
if (otherFocusPoint) {
|
||||||
|
a = otherFocusPoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const b = pointFromVector<GlobalPoint>(
|
const b = pointFromVector<GlobalPoint>(
|
||||||
vectorScale(
|
vectorScale(
|
||||||
vectorFromPoint(point, a),
|
vectorFromPoint(point, a),
|
||||||
@@ -603,18 +722,22 @@ export const projectFixedPointOntoDiagonal = (
|
|||||||
),
|
),
|
||||||
a,
|
a,
|
||||||
);
|
);
|
||||||
const intersector = lineSegment<GlobalPoint>(point, b);
|
const intersector = lineSegment<GlobalPoint>(b, a);
|
||||||
const p1 = lineSegmentIntersectionPoints(diagonalOne, intersector);
|
const p1 = lineSegmentIntersectionPoints(diagonalOne, intersector);
|
||||||
const p2 = lineSegmentIntersectionPoints(diagonalTwo, intersector);
|
const p2 = lineSegmentIntersectionPoints(diagonalTwo, intersector);
|
||||||
const d1 = p1 && pointDistance(a, p1);
|
const d1 = p1 && pointDistance(a, p1);
|
||||||
const d2 = p2 && pointDistance(a, p2);
|
const d2 = p2 && pointDistance(a, p2);
|
||||||
|
|
||||||
let p = null;
|
let projection = null;
|
||||||
if (d1 != null && d2 != null) {
|
if (d1 != null && d2 != null) {
|
||||||
p = d1 < d2 ? p1 : p2;
|
projection = d1 < d2 ? p1 : p2;
|
||||||
} else {
|
} else {
|
||||||
p = p1 || p2 || null;
|
projection = p1 || p2 || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p && isPointInElement(p, element, elementsMap) ? p : null;
|
if (projection && isPointInElement(projection, element, elementsMap)) {
|
||||||
|
return projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,12 +156,11 @@ export const moveArrowAboveBindable = (
|
|||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
|
hit?: NonDeletedExcalidrawElement,
|
||||||
): readonly OrderedExcalidrawElement[] => {
|
): readonly OrderedExcalidrawElement[] => {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = hit
|
||||||
point,
|
? hit
|
||||||
elements,
|
: getHoveredElementForBinding(point, elements, elementsMap);
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!hoveredElement) {
|
if (!hoveredElement) {
|
||||||
return elements;
|
return elements;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
import { arrayToMap } from "@excalidraw/common";
|
||||||
import { type GlobalPoint, type LocalPoint, pointFrom } from "@excalidraw/math";
|
import { type GlobalPoint, type LocalPoint, pointFrom } from "@excalidraw/math";
|
||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
|
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
||||||
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
|
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
|
||||||
import "@excalidraw/utils/test-utils";
|
import "@excalidraw/utils/test-utils";
|
||||||
import { render } from "@excalidraw/excalidraw/tests/test-utils";
|
import { render } from "@excalidraw/excalidraw/tests/test-utils";
|
||||||
|
|
||||||
|
import * as distance from "../src/distance";
|
||||||
import { hitElementItself } from "../src/collision";
|
import { hitElementItself } from "../src/collision";
|
||||||
|
|
||||||
describe("check rotated elements can be hit:", () => {
|
describe("check rotated elements can be hit:", () => {
|
||||||
@@ -25,8 +28,6 @@ describe("check rotated elements can be hit:", () => {
|
|||||||
[-4, -302],
|
[-4, -302],
|
||||||
] as LocalPoint[],
|
] as LocalPoint[],
|
||||||
});
|
});
|
||||||
//const p = [120, -211];
|
|
||||||
//const p = [0, 13];
|
|
||||||
const hit = hitElementItself({
|
const hit = hitElementItself({
|
||||||
point: pointFrom<GlobalPoint>(88, -68),
|
point: pointFrom<GlobalPoint>(88, -68),
|
||||||
element: window.h.elements[0],
|
element: window.h.elements[0],
|
||||||
@@ -36,3 +37,182 @@ describe("check rotated elements can be hit:", () => {
|
|||||||
expect(hit).toBe(true);
|
expect(hit).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("hitElementItself cache", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
// reset cache
|
||||||
|
hitElementItself({
|
||||||
|
point: pointFrom<GlobalPoint>(50, 50),
|
||||||
|
element: API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
}),
|
||||||
|
threshold: Infinity,
|
||||||
|
elementsMap: new Map([]),
|
||||||
|
});
|
||||||
|
|
||||||
|
localStorage.clear();
|
||||||
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reuses cached result when threshold increases", () => {
|
||||||
|
const element = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
});
|
||||||
|
const elementsMap = arrayToMap([element]);
|
||||||
|
const point = pointFrom<GlobalPoint>(100.5, 50);
|
||||||
|
|
||||||
|
const distanceSpy = jest.spyOn(distance, "distanceToElement");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 1,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 10,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
distanceSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not reuse cache when threshold decreases", () => {
|
||||||
|
const element = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
});
|
||||||
|
const elementsMap = arrayToMap([element]);
|
||||||
|
const point = pointFrom<GlobalPoint>(105, 50);
|
||||||
|
|
||||||
|
const distanceSpy = jest.spyOn(distance, "distanceToElement");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 10,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 6,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(2);
|
||||||
|
distanceSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invalidates cache when element version changes", () => {
|
||||||
|
const element = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
});
|
||||||
|
const elementsMap = arrayToMap([element]);
|
||||||
|
const point = pointFrom<GlobalPoint>(100.5, 50);
|
||||||
|
|
||||||
|
const distanceSpy = jest.spyOn(distance, "distanceToElement");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 1,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
const movedElement = {
|
||||||
|
...element,
|
||||||
|
version: element.version + 1,
|
||||||
|
versionNonce: element.versionNonce + 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element: movedElement,
|
||||||
|
threshold: 1,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(2);
|
||||||
|
distanceSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("override does not affect caching", () => {
|
||||||
|
const element = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
});
|
||||||
|
const elementsMap = arrayToMap([element]);
|
||||||
|
const point = pointFrom<GlobalPoint>(50, 50);
|
||||||
|
|
||||||
|
const distanceSpy = jest.spyOn(distance, "distanceToElement");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 10,
|
||||||
|
elementsMap,
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
|
|
||||||
|
expect(distanceSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
hitElementItself({
|
||||||
|
point,
|
||||||
|
element,
|
||||||
|
threshold: 10,
|
||||||
|
elementsMap,
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getEmbedLink } from "../src/embeddable";
|
import { embeddableURLValidator, getEmbedLink } from "../src/embeddable";
|
||||||
|
|
||||||
describe("YouTube timestamp parsing", () => {
|
describe("YouTube timestamp parsing", () => {
|
||||||
it("should parse YouTube URLs with timestamp in seconds", () => {
|
it("should parse YouTube URLs with timestamp in seconds", () => {
|
||||||
@@ -151,3 +151,83 @@ describe("YouTube timestamp parsing", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Google Drive video embedding", () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
url: "https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/view?usp=sharing",
|
||||||
|
expectedLink:
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://drive.google.com/open?id=1AbCdEfGhIjKlMnOpQrStUvWxYz123456",
|
||||||
|
expectedLink:
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://drive.google.com/uc?export=download&id=1AbCdEfGhIjKlMnOpQrStUvWxYz123456",
|
||||||
|
expectedLink:
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview",
|
||||||
|
},
|
||||||
|
])("should normalize Google Drive link: $url", ({ url, expectedLink }) => {
|
||||||
|
const result = getEmbedLink(url);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result?.type).toBe("video");
|
||||||
|
if (result?.type === "video" || result?.type === "generic") {
|
||||||
|
expect(result.link).toBe(expectedLink);
|
||||||
|
}
|
||||||
|
expect(result?.intrinsicSize).toEqual({ w: 560, h: 315 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve resourcekey when available", () => {
|
||||||
|
const url =
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/view?resourcekey=0-abcdef123456";
|
||||||
|
const result = getEmbedLink(url);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result?.type).toBe("video");
|
||||||
|
if (result?.type === "video" || result?.type === "generic") {
|
||||||
|
expect(result.link).toBe(
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview?resourcekey=0-abcdef123456",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve timestamp when available", () => {
|
||||||
|
const url =
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/view?t=9";
|
||||||
|
const result = getEmbedLink(url);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result?.type).toBe("video");
|
||||||
|
if (result?.type === "video" || result?.type === "generic") {
|
||||||
|
expect(result.link).toBe(
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview?t=9",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve resourcekey and timestamp together", () => {
|
||||||
|
const url =
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/view?resourcekey=0-abcdef123456&t=9";
|
||||||
|
const result = getEmbedLink(url);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result?.type).toBe("video");
|
||||||
|
if (result?.type === "video" || result?.type === "generic") {
|
||||||
|
expect(result.link).toBe(
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/preview?resourcekey=0-abcdef123456&t=9",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should validate Google Drive domain by default", () => {
|
||||||
|
expect(
|
||||||
|
embeddableURLValidator(
|
||||||
|
"https://drive.google.com/file/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456/view",
|
||||||
|
undefined,
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ describe("Test Linear Elements", () => {
|
|||||||
// drag line from midpoint
|
// drag line from midpoint
|
||||||
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(`8`);
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(`8`);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
expect(line.points.length).toEqual(3);
|
expect(line.points.length).toEqual(3);
|
||||||
expect(line.points).toMatchInlineSnapshot(`
|
expect(line.points).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
@@ -378,7 +378,7 @@ describe("Test Linear Elements", () => {
|
|||||||
// drag line from midpoint
|
// drag line from midpoint
|
||||||
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
drag(midpoint, pointFrom(midpoint[0] + delta, midpoint[1] + delta));
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -419,7 +419,7 @@ describe("Test Linear Elements", () => {
|
|||||||
fireEvent.click(screen.getByTitle("Round"));
|
fireEvent.click(screen.getByTitle("Round"));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`9`,
|
`10`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`6`);
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(startPoint, endPoint);
|
drag(startPoint, endPoint);
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -548,7 +548,7 @@ describe("Test Linear Elements", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`15`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
||||||
|
|
||||||
@@ -599,7 +599,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] - delta, hitCoords[1] - delta));
|
drag(hitCoords, pointFrom(hitCoords[0] - delta, hitCoords[1] - delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -640,7 +640,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -688,7 +688,7 @@ describe("Test Linear Elements", () => {
|
|||||||
deletePoint(points[2]);
|
deletePoint(points[2]);
|
||||||
expect(line.points.length).toEqual(3);
|
expect(line.points.length).toEqual(3);
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`17`,
|
`18`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`10`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`10`);
|
||||||
|
|
||||||
@@ -746,7 +746,7 @@ describe("Test Linear Elements", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`14`,
|
`15`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`9`);
|
||||||
expect(line.points.length).toEqual(5);
|
expect(line.points.length).toEqual(5);
|
||||||
@@ -844,7 +844,7 @@ describe("Test Linear Elements", () => {
|
|||||||
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
drag(hitCoords, pointFrom(hitCoords[0] + delta, hitCoords[1] + delta));
|
||||||
|
|
||||||
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot(
|
||||||
`11`,
|
`12`,
|
||||||
);
|
);
|
||||||
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`7`);
|
||||||
|
|
||||||
@@ -1317,7 +1317,7 @@ describe("Test Linear Elements", () => {
|
|||||||
const textElement = h.elements[2] as ExcalidrawTextElementWithContainer;
|
const textElement = h.elements[2] as ExcalidrawTextElementWithContainer;
|
||||||
|
|
||||||
expect(arrow.endBinding?.elementId).toBe(rect.id);
|
expect(arrow.endBinding?.elementId).toBe(rect.id);
|
||||||
expect(arrow.width).toBeCloseTo(399);
|
expect(arrow.width).toBeCloseTo(404);
|
||||||
expect(rect.x).toBe(400);
|
expect(rect.x).toBe(400);
|
||||||
expect(rect.y).toBe(0);
|
expect(rect.y).toBe(0);
|
||||||
expect(
|
expect(
|
||||||
@@ -1336,7 +1336,7 @@ describe("Test Linear Elements", () => {
|
|||||||
mouse.downAt(rect.x, rect.y);
|
mouse.downAt(rect.x, rect.y);
|
||||||
mouse.moveTo(200, 0);
|
mouse.moveTo(200, 0);
|
||||||
mouse.upAt(200, 0);
|
mouse.upAt(200, 0);
|
||||||
expect(arrow.width).toBeCloseTo(199);
|
expect(arrow.width).toBeCloseTo(204);
|
||||||
expect(rect.x).toBe(200);
|
expect(rect.x).toBe(200);
|
||||||
expect(rect.y).toBe(0);
|
expect(rect.y).toBe(0);
|
||||||
expect(handleBindTextResizeSpy).toHaveBeenCalledWith(
|
expect(handleBindTextResizeSpy).toHaveBeenCalledWith(
|
||||||
|
|||||||
@@ -1350,8 +1350,8 @@ describe("multiple selection", () => {
|
|||||||
|
|
||||||
expect(boundArrow.x).toBeCloseTo(380 * scaleX);
|
expect(boundArrow.x).toBeCloseTo(380 * scaleX);
|
||||||
expect(boundArrow.y).toBeCloseTo(240 * scaleY);
|
expect(boundArrow.y).toBeCloseTo(240 * scaleY);
|
||||||
expect(boundArrow.points[1][0]).toBeCloseTo(59.7979);
|
expect(boundArrow.points[1][0]).toBeCloseTo(63.40354208105561);
|
||||||
expect(boundArrow.points[1][1]).toBeCloseTo(-79.7305);
|
expect(boundArrow.points[1][1]).toBeCloseTo(-84.53805610807356);
|
||||||
|
|
||||||
expect(arrowLabelPos.x + arrowLabel.width / 2).toBeCloseTo(
|
expect(arrowLabelPos.x + arrowLabel.width / 2).toBeCloseTo(
|
||||||
boundArrow.x + boundArrow.points[1][0] / 2,
|
boundArrow.x + boundArrow.points[1][0] / 2,
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ const distributeSelectedElements = (
|
|||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
distribution,
|
distribution,
|
||||||
appState,
|
appState,
|
||||||
|
app.scene,
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedElementsMap = arrayToMap(updatedElements);
|
const updatedElementsMap = arrayToMap(updatedElements);
|
||||||
|
|||||||
@@ -98,19 +98,21 @@ export const actionFinalize = register<FormData>({
|
|||||||
map.set(index, {
|
map.set(index, {
|
||||||
point: LinearElementEditor.pointFromAbsoluteCoords(
|
point: LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
element,
|
element,
|
||||||
pointFrom<GlobalPoint>(sceneCoords.x, sceneCoords.y),
|
pointFrom<GlobalPoint>(
|
||||||
|
sceneCoords.x - linearElementEditor.pointerOffset.x,
|
||||||
|
sceneCoords.y - linearElementEditor.pointerOffset.y,
|
||||||
|
),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}, new Map()) ?? new Map();
|
}, new Map()) ?? new Map();
|
||||||
|
|
||||||
bindOrUnbindBindingElement(
|
bindOrUnbindBindingElement(
|
||||||
element,
|
element,
|
||||||
draggedPoints,
|
draggedPoints,
|
||||||
sceneCoords.x,
|
sceneCoords.x - linearElementEditor.pointerOffset.x,
|
||||||
sceneCoords.y,
|
sceneCoords.y - linearElementEditor.pointerOffset.y,
|
||||||
scene,
|
scene,
|
||||||
appState,
|
appState,
|
||||||
{
|
{
|
||||||
@@ -173,6 +175,7 @@ export const actionFinalize = register<FormData>({
|
|||||||
...linearElementEditor.initialState,
|
...linearElementEditor.initialState,
|
||||||
lastClickedPoint: -1,
|
lastClickedPoint: -1,
|
||||||
},
|
},
|
||||||
|
pointerOffset: { x: 0, y: 0 },
|
||||||
},
|
},
|
||||||
selectionElement: null,
|
selectionElement: null,
|
||||||
suggestedBinding: null,
|
suggestedBinding: null,
|
||||||
|
|||||||
@@ -1555,7 +1555,7 @@ const getArrowheadOptions = (flip: boolean) => {
|
|||||||
value: null,
|
value: null,
|
||||||
text: t("labels.arrowhead_none"),
|
text: t("labels.arrowhead_none"),
|
||||||
keyBinding: "q",
|
keyBinding: "q",
|
||||||
icon: ArrowheadNoneIcon,
|
icon: <ArrowheadNoneIcon flip={flip} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "arrow",
|
value: "arrow",
|
||||||
@@ -1683,7 +1683,8 @@ export const actionChangeArrowhead = register<{
|
|||||||
? element.startArrowhead
|
? element.startArrowhead
|
||||||
: appState.currentItemStartArrowhead,
|
: appState.currentItemStartArrowhead,
|
||||||
true,
|
true,
|
||||||
appState.currentItemStartArrowhead,
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemStartArrowhead,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData({ position: "start", type: value })}
|
onChange={(value) => updateData({ position: "start", type: value })}
|
||||||
numberOfOptionsToAlwaysShow={4}
|
numberOfOptionsToAlwaysShow={4}
|
||||||
@@ -1700,7 +1701,8 @@ export const actionChangeArrowhead = register<{
|
|||||||
? element.endArrowhead
|
? element.endArrowhead
|
||||||
: appState.currentItemEndArrowhead,
|
: appState.currentItemEndArrowhead,
|
||||||
true,
|
true,
|
||||||
appState.currentItemEndArrowhead,
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemEndArrowhead,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData({ position: "end", type: value })}
|
onChange={(value) => updateData({ position: "end", type: value })}
|
||||||
numberOfOptionsToAlwaysShow={4}
|
numberOfOptionsToAlwaysShow={4}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ export type ShortcutName =
|
|||||||
| "saveScene"
|
| "saveScene"
|
||||||
| "imageExport"
|
| "imageExport"
|
||||||
| "commandPalette"
|
| "commandPalette"
|
||||||
| "searchMenu";
|
| "searchMenu"
|
||||||
|
| "toolLock";
|
||||||
|
|
||||||
const shortcutMap: Record<ShortcutName, string[]> = {
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
||||||
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
||||||
@@ -117,6 +118,7 @@ const shortcutMap: Record<ShortcutName, string[]> = {
|
|||||||
toggleShortcuts: [getShortcutKey("?")],
|
toggleShortcuts: [getShortcutKey("?")],
|
||||||
searchMenu: [getShortcutKey("CtrlOrCmd+F")],
|
searchMenu: [getShortcutKey("CtrlOrCmd+F")],
|
||||||
wrapSelectionInFrame: [],
|
wrapSelectionInFrame: [],
|
||||||
|
toolLock: [getShortcutKey("Q")],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getShortcutFromShortcutName = (name: ShortcutName, idx = 0) => {
|
export const getShortcutFromShortcutName = (name: ShortcutName, idx = 0) => {
|
||||||
|
|||||||
@@ -204,8 +204,13 @@ export const copyToClipboard = async (
|
|||||||
/** supply if available to make the operation more certain to succeed */
|
/** supply if available to make the operation more certain to succeed */
|
||||||
clipboardEvent?: ClipboardEvent | null,
|
clipboardEvent?: ClipboardEvent | null,
|
||||||
) => {
|
) => {
|
||||||
|
const json = serializeAsClipboardJSON({ elements, files });
|
||||||
|
|
||||||
await copyTextToSystemClipboard(
|
await copyTextToSystemClipboard(
|
||||||
serializeAsClipboardJSON({ elements, files }),
|
{
|
||||||
|
[MIME_TYPES.excalidrawClipboard]: json,
|
||||||
|
[MIME_TYPES.text]: json,
|
||||||
|
},
|
||||||
clipboardEvent,
|
clipboardEvent,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -401,7 +406,7 @@ export type ParsedDataTransferFile = Extract<
|
|||||||
{ kind: "file" }
|
{ kind: "file" }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type ParsedDataTranferList = ParsedDataTransferItem[] & {
|
export type ParsedDataTranferList = ParsedDataTransferItem[] & {
|
||||||
/**
|
/**
|
||||||
* Only allows filtering by known `string` data types, since `file`
|
* Only allows filtering by known `string` data types, since `file`
|
||||||
* types can have multiple items of the same type (e.g. multiple image files)
|
* types can have multiple items of the same type (e.g. multiple image files)
|
||||||
@@ -452,6 +457,29 @@ const getDataTransferFiles = function (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @returns list of MIME types, synchronously */
|
||||||
|
export const parseDataTransferEventMimeTypes = (
|
||||||
|
event: ClipboardEvent | DragEvent | React.DragEvent<HTMLDivElement>,
|
||||||
|
): Set<string> => {
|
||||||
|
let items: DataTransferItemList | undefined = undefined;
|
||||||
|
|
||||||
|
if (isClipboardEvent(event)) {
|
||||||
|
items = event.clipboardData?.items;
|
||||||
|
} else {
|
||||||
|
items = event.dataTransfer?.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
const types: Set<string> = new Set();
|
||||||
|
|
||||||
|
for (const item of Array.from(items || [])) {
|
||||||
|
if (!types.has(item.type)) {
|
||||||
|
types.add(item.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
};
|
||||||
|
|
||||||
export const parseDataTransferEvent = async (
|
export const parseDataTransferEvent = async (
|
||||||
event: ClipboardEvent | DragEvent | React.DragEvent<HTMLDivElement>,
|
event: ClipboardEvent | DragEvent | React.DragEvent<HTMLDivElement>,
|
||||||
): Promise<ParsedDataTranferList> => {
|
): Promise<ParsedDataTranferList> => {
|
||||||
@@ -460,8 +488,7 @@ export const parseDataTransferEvent = async (
|
|||||||
if (isClipboardEvent(event)) {
|
if (isClipboardEvent(event)) {
|
||||||
items = event.clipboardData?.items;
|
items = event.clipboardData?.items;
|
||||||
} else {
|
} else {
|
||||||
const dragEvent = event;
|
items = event.dataTransfer?.items;
|
||||||
items = dragEvent.dataTransfer?.items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataItems = (
|
const dataItems = (
|
||||||
@@ -567,7 +594,7 @@ export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
|||||||
// ClipboardItem constructor, but throws on an unrelated MIME type error.
|
// ClipboardItem constructor, but throws on an unrelated MIME type error.
|
||||||
// So we need to await this and fallback to awaiting the blob if applicable.
|
// So we need to await this and fallback to awaiting the blob if applicable.
|
||||||
await navigator.clipboard.write([
|
await navigator.clipboard.write([
|
||||||
new window.ClipboardItem({
|
new ClipboardItem({
|
||||||
[MIME_TYPES.png]: blob,
|
[MIME_TYPES.png]: blob,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
@@ -576,7 +603,7 @@ export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
|||||||
// with resolution value instead
|
// with resolution value instead
|
||||||
if (isPromiseLike(blob)) {
|
if (isPromiseLike(blob)) {
|
||||||
await navigator.clipboard.write([
|
await navigator.clipboard.write([
|
||||||
new window.ClipboardItem({
|
new ClipboardItem({
|
||||||
[MIME_TYPES.png]: await blob,
|
[MIME_TYPES.png]: await blob,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
@@ -586,28 +613,27 @@ export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyTextToSystemClipboard = async (
|
export const copyTextToSystemClipboard = async <
|
||||||
text: string | null,
|
MimeType extends ValueOf<typeof STRING_MIME_TYPES>,
|
||||||
|
>(
|
||||||
|
text: string | { [K in MimeType]: string } | null,
|
||||||
clipboardEvent?: ClipboardEvent | null,
|
clipboardEvent?: ClipboardEvent | null,
|
||||||
) => {
|
) => {
|
||||||
// (1) first try using Async Clipboard API
|
text = text || "";
|
||||||
if (probablySupportsClipboardWriteText) {
|
|
||||||
try {
|
|
||||||
// NOTE: doesn't work on FF on non-HTTPS domains, or when document
|
|
||||||
// not focused
|
|
||||||
await navigator.clipboard.writeText(text || "");
|
|
||||||
return;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// (2) if fails and we have access to ClipboardEvent, use plain old setData()
|
const entries = Object.entries(
|
||||||
|
typeof text === "string" ? { [MIME_TYPES.text]: text } : text,
|
||||||
|
);
|
||||||
|
|
||||||
|
// (1) if we have clipboardEvent, try using it first as it's the most
|
||||||
|
// versatile
|
||||||
try {
|
try {
|
||||||
if (clipboardEvent) {
|
if (clipboardEvent) {
|
||||||
clipboardEvent.clipboardData?.setData(MIME_TYPES.text, text || "");
|
for (const [mimeType, value] of entries) {
|
||||||
if (clipboardEvent.clipboardData?.getData(MIME_TYPES.text) !== text) {
|
clipboardEvent.clipboardData?.setData(mimeType, value);
|
||||||
throw new Error("Failed to setData on clipboardEvent");
|
if (clipboardEvent.clipboardData?.getData(mimeType) !== value) {
|
||||||
|
throw new Error("Failed to setData on clipboardEvent");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -615,8 +641,26 @@ export const copyTextToSystemClipboard = async (
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (3) if that fails, use document.execCommand
|
const plainTextEntry = entries.find(
|
||||||
if (!copyTextViaExecCommand(text)) {
|
([mimeType]) => mimeType === MIME_TYPES.text,
|
||||||
|
);
|
||||||
|
|
||||||
|
// (2) if we don't have access to clipboardEvent, or that fails,
|
||||||
|
// at least try setting text/plain via navigator.clipboard.writeText
|
||||||
|
// (navigator.clipboard.write doesn't work with non-standard mime types)
|
||||||
|
if (probablySupportsClipboardWriteText && plainTextEntry) {
|
||||||
|
try {
|
||||||
|
// NOTE: doesn't work on FF on non-HTTPS domains, or when document
|
||||||
|
// not focused
|
||||||
|
await navigator.clipboard.writeText(plainTextEntry[1]);
|
||||||
|
return;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// (3) if previous fails, use document.execCommand
|
||||||
|
if (plainTextEntry && !copyTextViaExecCommand(plainTextEntry[1])) {
|
||||||
throw new Error("Error copying to clipboard.");
|
throw new Error("Error copying to clipboard.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CLASSES,
|
CLASSES,
|
||||||
@@ -1081,8 +1081,9 @@ export const ShapesSwitcher = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{getToolbarTools(app).map(
|
{getToolbarTools(app).map(
|
||||||
({ value, icon, key, numericKey, fillable }) => {
|
({ value, icon, key, numericKey, fillable, toolbar }) => {
|
||||||
if (
|
if (
|
||||||
|
toolbar === false ||
|
||||||
UIOptions.tools?.[
|
UIOptions.tools?.[
|
||||||
value as Extract<
|
value as Extract<
|
||||||
typeof value,
|
typeof value,
|
||||||
@@ -1099,6 +1100,9 @@ export const ShapesSwitcher = ({
|
|||||||
const shortcut = letter
|
const shortcut = letter
|
||||||
? `${letter} ${t("helpDialog.or")} ${numericKey}`
|
? `${letter} ${t("helpDialog.or")} ${numericKey}`
|
||||||
: `${numericKey}`;
|
: `${numericKey}`;
|
||||||
|
const keybindingLabel =
|
||||||
|
value === "hand" ? undefined : numericKey || letter;
|
||||||
|
|
||||||
// when in compact styles panel mode (tablet)
|
// when in compact styles panel mode (tablet)
|
||||||
// use a ToolPopover for selection/lasso toggle as well
|
// use a ToolPopover for selection/lasso toggle as well
|
||||||
if (
|
if (
|
||||||
@@ -1143,7 +1147,7 @@ export const ShapesSwitcher = ({
|
|||||||
checked={activeTool.type === value}
|
checked={activeTool.type === value}
|
||||||
name="editor-current-shape"
|
name="editor-current-shape"
|
||||||
title={`${capitalizeString(label)} — ${shortcut}`}
|
title={`${capitalizeString(label)} — ${shortcut}`}
|
||||||
keyBindingLabel={numericKey || letter}
|
keyBindingLabel={keybindingLabel}
|
||||||
aria-label={capitalizeString(label)}
|
aria-label={capitalizeString(label)}
|
||||||
aria-keyshortcuts={shortcut}
|
aria-keyshortcuts={shortcut}
|
||||||
data-testid={`toolbar-${value}`}
|
data-testid={`toolbar-${value}`}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
pointDistance,
|
pointDistance,
|
||||||
vector,
|
vector,
|
||||||
pointRotateRads,
|
pointRotateRads,
|
||||||
vectorScale,
|
|
||||||
vectorFromPoint,
|
vectorFromPoint,
|
||||||
vectorSubtract,
|
vectorSubtract,
|
||||||
vectorDot,
|
vectorDot,
|
||||||
@@ -110,6 +109,7 @@ import {
|
|||||||
loadDesktopUIModePreference,
|
loadDesktopUIModePreference,
|
||||||
setDesktopUIMode,
|
setDesktopUIMode,
|
||||||
isSelectionLikeTool,
|
isSelectionLikeTool,
|
||||||
|
oneOf,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -251,6 +251,13 @@ import {
|
|||||||
maxBindingDistance_simple,
|
maxBindingDistance_simple,
|
||||||
convertToExcalidrawElements,
|
convertToExcalidrawElements,
|
||||||
type ExcalidrawElementSkeleton,
|
type ExcalidrawElementSkeleton,
|
||||||
|
getSnapOutlineMidPoint,
|
||||||
|
handleFocusPointDrag,
|
||||||
|
handleFocusPointHover,
|
||||||
|
handleFocusPointPointerDown,
|
||||||
|
handleFocusPointPointerUp,
|
||||||
|
maybeHandleArrowPointlikeDrag,
|
||||||
|
getUncroppedWidthAndHeight,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
|
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
|
||||||
@@ -437,10 +444,7 @@ import { searchItemInFocusAtom } from "./SearchMenu";
|
|||||||
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
|
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
|
||||||
import { StaticCanvas, InteractiveCanvas } from "./canvases";
|
import { StaticCanvas, InteractiveCanvas } from "./canvases";
|
||||||
import NewElementCanvas from "./canvases/NewElementCanvas";
|
import NewElementCanvas from "./canvases/NewElementCanvas";
|
||||||
import {
|
import { isPointHittingLink } from "./hyperlink/helpers";
|
||||||
isPointHittingLink,
|
|
||||||
isPointHittingLinkIcon,
|
|
||||||
} from "./hyperlink/helpers";
|
|
||||||
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
||||||
import { Toast } from "./Toast";
|
import { Toast } from "./Toast";
|
||||||
|
|
||||||
@@ -644,7 +648,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
lastPointerUpEvent: React.PointerEvent<HTMLElement> | PointerEvent | null =
|
lastPointerUpEvent: React.PointerEvent<HTMLElement> | PointerEvent | null =
|
||||||
null;
|
null;
|
||||||
lastPointerMoveEvent: PointerEvent | null = null;
|
lastPointerMoveEvent: PointerEvent | null = null;
|
||||||
|
/** current frame pointer cords */
|
||||||
lastPointerMoveCoords: { x: number; y: number } | null = null;
|
lastPointerMoveCoords: { x: number; y: number } | null = null;
|
||||||
|
/** previous frame pointer coords */
|
||||||
|
previousPointerMoveCoords: { x: number; y: number } | null = null;
|
||||||
lastViewportPosition = { x: 0, y: 0 };
|
lastViewportPosition = { x: 0, y: 0 };
|
||||||
|
|
||||||
animationFrameHandler = new AnimationFrameHandler();
|
animationFrameHandler = new AnimationFrameHandler();
|
||||||
@@ -1202,12 +1209,112 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return this.iFrameRefs.get(element.id);
|
return this.iFrameRefs.get(element.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleEmbeddableCenterClick(element: ExcalidrawIframeLikeElement) {
|
private handleIframeLikeElementHover = ({
|
||||||
|
hitElement,
|
||||||
|
scenePointer,
|
||||||
|
moveEvent,
|
||||||
|
}: {
|
||||||
|
hitElement: NonDeleted<ExcalidrawElement> | null;
|
||||||
|
scenePointer: { x: number; y: number };
|
||||||
|
moveEvent: React.PointerEvent<HTMLCanvasElement>;
|
||||||
|
}): boolean => {
|
||||||
if (
|
if (
|
||||||
this.state.activeEmbeddable?.element === element &&
|
hitElement &&
|
||||||
|
isIframeLikeElement(hitElement) &&
|
||||||
|
(this.state.viewModeEnabled ||
|
||||||
|
this.state.activeTool.type === "laser" ||
|
||||||
|
this.isIframeLikeElementCenter(
|
||||||
|
hitElement,
|
||||||
|
moveEvent,
|
||||||
|
scenePointer.x,
|
||||||
|
scenePointer.y,
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.POINTER);
|
||||||
|
this.setState({
|
||||||
|
activeEmbeddable: { element: hitElement, state: "hover" },
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else if (this.state.activeEmbeddable?.state === "hover") {
|
||||||
|
this.setState({ activeEmbeddable: null });
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @returns true if iframe-like element click handled */
|
||||||
|
private handleIframeLikeCenterClick(): boolean {
|
||||||
|
if (
|
||||||
|
!this.lastPointerDownEvent ||
|
||||||
|
!this.lastPointerUpEvent ||
|
||||||
|
// middle-click or something other than primary
|
||||||
|
this.lastPointerDownEvent.button !== POINTER_BUTTON.MAIN ||
|
||||||
|
// panning
|
||||||
|
isHoldingSpace ||
|
||||||
|
// wrong tool
|
||||||
|
!oneOf(this.state.activeTool.type, ["laser", "selection", "lasso"])
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const viewportClickStart_scenePoint = pointFrom(
|
||||||
|
viewportCoordsToSceneCoords(
|
||||||
|
{
|
||||||
|
clientX: this.lastPointerDownEvent.clientX,
|
||||||
|
clientY: this.lastPointerDownEvent.clientY,
|
||||||
|
},
|
||||||
|
this.state,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const viewportClickEnd_scenePoint = pointFrom(
|
||||||
|
viewportCoordsToSceneCoords(
|
||||||
|
{
|
||||||
|
clientX: this.lastPointerUpEvent.clientX,
|
||||||
|
clientY: this.lastPointerUpEvent.clientY,
|
||||||
|
},
|
||||||
|
this.state,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const draggedDistance = pointDistance(
|
||||||
|
viewportClickStart_scenePoint,
|
||||||
|
viewportClickEnd_scenePoint,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (draggedDistance > DRAGGING_THRESHOLD) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hitElement = this.getElementAtPosition(
|
||||||
|
viewportClickStart_scenePoint[0],
|
||||||
|
viewportClickStart_scenePoint[1],
|
||||||
|
);
|
||||||
|
|
||||||
|
const shouldActivate =
|
||||||
|
hitElement &&
|
||||||
|
this.lastPointerUpEvent.timeStamp - this.lastPointerDownEvent.timeStamp <=
|
||||||
|
300 &&
|
||||||
|
gesture.pointers.size < 2 &&
|
||||||
|
isIframeLikeElement(hitElement) &&
|
||||||
|
(this.state.viewModeEnabled ||
|
||||||
|
this.state.activeTool.type === "laser" ||
|
||||||
|
this.isIframeLikeElementCenter(
|
||||||
|
hitElement,
|
||||||
|
this.lastPointerUpEvent,
|
||||||
|
viewportClickEnd_scenePoint[0],
|
||||||
|
viewportClickEnd_scenePoint[1],
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!shouldActivate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iframeLikeElement = hitElement;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.state.activeEmbeddable?.element === iframeLikeElement &&
|
||||||
this.state.activeEmbeddable?.state === "active"
|
this.state.activeEmbeddable?.state === "active"
|
||||||
) {
|
) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The delay serves two purposes
|
// The delay serves two purposes
|
||||||
@@ -1218,31 +1325,34 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
// in fullscreen mode
|
// in fullscreen mode
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
activeEmbeddable: { element, state: "active" },
|
activeEmbeddable: { element: iframeLikeElement, state: "active" },
|
||||||
selectedElementIds: { [element.id]: true },
|
selectedElementIds: { [iframeLikeElement.id]: true },
|
||||||
newElement: null,
|
newElement: null,
|
||||||
selectionElement: null,
|
selectionElement: null,
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
if (isIframeElement(element)) {
|
if (isIframeElement(iframeLikeElement)) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const iframe = this.getHTMLIFrameElement(element);
|
const iframe = this.getHTMLIFrameElement(iframeLikeElement);
|
||||||
|
|
||||||
if (!iframe?.contentWindow) {
|
if (!iframe?.contentWindow) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iframe.src.includes("youtube")) {
|
if (iframe.src.includes("youtube")) {
|
||||||
const state = YOUTUBE_VIDEO_STATES.get(element.id);
|
const state = YOUTUBE_VIDEO_STATES.get(iframeLikeElement.id);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
YOUTUBE_VIDEO_STATES.set(element.id, YOUTUBE_STATES.UNSTARTED);
|
YOUTUBE_VIDEO_STATES.set(
|
||||||
|
iframeLikeElement.id,
|
||||||
|
YOUTUBE_STATES.UNSTARTED,
|
||||||
|
);
|
||||||
iframe.contentWindow.postMessage(
|
iframe.contentWindow.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
event: "listening",
|
event: "listening",
|
||||||
id: element.id,
|
id: iframeLikeElement.id,
|
||||||
}),
|
}),
|
||||||
"*",
|
"*",
|
||||||
);
|
);
|
||||||
@@ -1279,6 +1389,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
"*",
|
"*",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isIframeLikeElementCenter(
|
private isIframeLikeElementCenter(
|
||||||
@@ -4737,14 +4849,86 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle Alt key for bind mode
|
// Handle Alt key for bind mode
|
||||||
if (event.key === KEYS.ALT && getFeatureFlag("COMPLEX_BINDINGS")) {
|
if (event.key === KEYS.ALT) {
|
||||||
this.handleSkipBindMode();
|
if (getFeatureFlag("COMPLEX_BINDINGS")) {
|
||||||
|
this.handleSkipBindMode();
|
||||||
|
} else {
|
||||||
|
maybeHandleArrowPointlikeDrag({ app: this, event });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.actionManager.handleKeyDown(event)) {
|
if (this.actionManager.handleKeyDown(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// view mode hardcoded from upstream -> disable tool switching for now
|
||||||
|
const shouldPreventToolSwitching = this.props.viewModeEnabled === true;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!shouldPreventToolSwitching &&
|
||||||
|
this.state.viewModeEnabled &&
|
||||||
|
event.key === KEYS.ESCAPE
|
||||||
|
) {
|
||||||
|
this.setActiveTool({ type: "hand" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!shouldPreventToolSwitching &&
|
||||||
|
!event.ctrlKey &&
|
||||||
|
!event.altKey &&
|
||||||
|
!event.metaKey &&
|
||||||
|
!this.state.newElement &&
|
||||||
|
!this.state.selectionElement &&
|
||||||
|
!this.state.selectedElementsAreBeingDragged
|
||||||
|
) {
|
||||||
|
const shape = findShapeByKey(event.key, this);
|
||||||
|
|
||||||
|
if (this.state.viewModeEnabled && !oneOf(shape, ["laser", "hand"])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shape) {
|
||||||
|
if (this.state.activeTool.type !== shape) {
|
||||||
|
trackEvent(
|
||||||
|
"toolbar",
|
||||||
|
shape,
|
||||||
|
`keyboard (${
|
||||||
|
this.editorInterface.formFactor === "phone"
|
||||||
|
? "mobile"
|
||||||
|
: "desktop"
|
||||||
|
})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (shape === "arrow" && this.state.activeTool.type === "arrow") {
|
||||||
|
this.setState((prevState) => ({
|
||||||
|
currentItemArrowType:
|
||||||
|
prevState.currentItemArrowType === ARROW_TYPE.sharp
|
||||||
|
? ARROW_TYPE.round
|
||||||
|
: prevState.currentItemArrowType === ARROW_TYPE.round
|
||||||
|
? ARROW_TYPE.elbow
|
||||||
|
: ARROW_TYPE.sharp,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shape === "lasso" && this.state.activeTool.type === "laser") {
|
||||||
|
this.setActiveTool({
|
||||||
|
type: this.state.preferredSelectionTool.type,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setActiveTool({ type: shape });
|
||||||
|
}
|
||||||
|
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (event.key === KEYS.Q) {
|
||||||
|
this.toggleLock("keyboard");
|
||||||
|
event.stopPropagation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.viewModeEnabled) {
|
if (this.state.viewModeEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4754,7 +4938,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.resetDelayedBindMode();
|
this.resetDelayedBindMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ isBindingEnabled: false });
|
flushSync(() => {
|
||||||
|
this.setState({ isBindingEnabled: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
maybeHandleArrowPointlikeDrag({ app: this, event });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isArrowKey(event.key)) {
|
if (isArrowKey(event.key)) {
|
||||||
@@ -4874,44 +5062,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (
|
|
||||||
!event.ctrlKey &&
|
|
||||||
!event.altKey &&
|
|
||||||
!event.metaKey &&
|
|
||||||
!this.state.newElement &&
|
|
||||||
!this.state.selectionElement &&
|
|
||||||
!this.state.selectedElementsAreBeingDragged
|
|
||||||
) {
|
|
||||||
const shape = findShapeByKey(event.key, this);
|
|
||||||
if (shape) {
|
|
||||||
if (this.state.activeTool.type !== shape) {
|
|
||||||
trackEvent(
|
|
||||||
"toolbar",
|
|
||||||
shape,
|
|
||||||
`keyboard (${
|
|
||||||
this.editorInterface.formFactor === "phone"
|
|
||||||
? "mobile"
|
|
||||||
: "desktop"
|
|
||||||
})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (shape === "arrow" && this.state.activeTool.type === "arrow") {
|
|
||||||
this.setState((prevState) => ({
|
|
||||||
currentItemArrowType:
|
|
||||||
prevState.currentItemArrowType === ARROW_TYPE.sharp
|
|
||||||
? ARROW_TYPE.round
|
|
||||||
: prevState.currentItemArrowType === ARROW_TYPE.round
|
|
||||||
? ARROW_TYPE.elbow
|
|
||||||
: ARROW_TYPE.sharp,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
this.setActiveTool({ type: shape });
|
|
||||||
event.stopPropagation();
|
|
||||||
} else if (event.key === KEYS.Q) {
|
|
||||||
this.toggleLock("keyboard");
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
|
if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
|
||||||
isHoldingSpace = true;
|
isHoldingSpace = true;
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
||||||
@@ -4975,15 +5127,6 @@ 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: this.state.preferredSelectionTool.type });
|
|
||||||
} 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)
|
||||||
@@ -5010,7 +5153,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
private onKeyUp = withBatchedUpdates((event: KeyboardEvent) => {
|
private onKeyUp = withBatchedUpdates((event: KeyboardEvent) => {
|
||||||
if (event.key === KEYS.SPACE) {
|
if (event.key === KEYS.SPACE) {
|
||||||
if (
|
if (
|
||||||
this.state.viewModeEnabled ||
|
(this.state.viewModeEnabled &&
|
||||||
|
this.state.activeTool.type !== "laser") ||
|
||||||
this.state.openDialog?.name === "elementLinkSelector"
|
this.state.openDialog?.name === "elementLinkSelector"
|
||||||
) {
|
) {
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
||||||
@@ -5027,6 +5171,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
isHoldingSpace = false;
|
isHoldingSpace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.key === KEYS.ALT) {
|
||||||
|
maybeHandleArrowPointlikeDrag({ app: this, event });
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(event.key === KEYS.ALT && this.state.bindMode === "skip") ||
|
(event.key === KEYS.ALT && this.state.bindMode === "skip") ||
|
||||||
(!event[KEYS.CTRL_OR_CMD] && !isBindingEnabled(this.state))
|
(!event[KEYS.CTRL_OR_CMD] && !isBindingEnabled(this.state))
|
||||||
@@ -5037,7 +5186,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Restart the timer if we're creating/editing a linear element and hovering over an element
|
// Restart the timer if we're creating/editing a linear element and hovering over an element
|
||||||
if (this.lastPointerMoveEvent) {
|
if (this.lastPointerMoveEvent && getFeatureFlag("COMPLEX_BINDINGS")) {
|
||||||
const scenePointer = viewportCoordsToSceneCoords(
|
const scenePointer = viewportCoordsToSceneCoords(
|
||||||
{
|
{
|
||||||
clientX: this.lastPointerMoveEvent.clientX,
|
clientX: this.lastPointerMoveEvent.clientX,
|
||||||
@@ -5058,14 +5207,18 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isBindingElement(element) && getFeatureFlag("COMPLEX_BINDINGS")) {
|
if (isBindingElement(element)) {
|
||||||
this.handleDelayedBindModeChange(element, hoveredElement);
|
this.handleDelayedBindModeChange(element, hoveredElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!event[KEYS.CTRL_OR_CMD] && !this.state.isBindingEnabled) {
|
if (!event[KEYS.CTRL_OR_CMD] && !this.state.isBindingEnabled) {
|
||||||
this.setState({ isBindingEnabled: true });
|
flushSync(() => {
|
||||||
|
this.setState({ isBindingEnabled: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
maybeHandleArrowPointlikeDrag({ app: this, event });
|
||||||
}
|
}
|
||||||
if (isArrowKey(event.key)) {
|
if (isArrowKey(event.key)) {
|
||||||
bindOrUnbindBindingElements(
|
bindOrUnbindBindingElements(
|
||||||
@@ -6115,7 +6268,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private redirectToLink = (event: React.PointerEvent<HTMLCanvasElement>) => {
|
private handleElementLinkClick = (
|
||||||
|
event: React.PointerEvent<HTMLCanvasElement>,
|
||||||
|
) => {
|
||||||
const draggedDistance = pointDistance(
|
const draggedDistance = pointDistance(
|
||||||
pointFrom(
|
pointFrom(
|
||||||
this.lastPointerDownEvent!.clientX,
|
this.lastPointerDownEvent!.clientX,
|
||||||
@@ -6375,15 +6530,28 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
// and point
|
// and point
|
||||||
const { newElement } = this.state;
|
const { newElement } = this.state;
|
||||||
if (!newElement && isBindingEnabled(this.state)) {
|
if (!newElement && isBindingEnabled(this.state)) {
|
||||||
|
const globalPoint = pointFrom<GlobalPoint>(
|
||||||
|
scenePointerX,
|
||||||
|
scenePointerY,
|
||||||
|
);
|
||||||
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
globalPoint,
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
elementsMap,
|
||||||
() => maxBindingDistance_simple(this.state.zoom),
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
if (hoveredElement) {
|
if (hoveredElement) {
|
||||||
this.setState({
|
this.setState({
|
||||||
suggestedBinding: hoveredElement,
|
suggestedBinding: {
|
||||||
|
element: hoveredElement,
|
||||||
|
midPoint: getSnapOutlineMidPoint(
|
||||||
|
globalPoint,
|
||||||
|
hoveredElement,
|
||||||
|
elementsMap,
|
||||||
|
this.state.zoom,
|
||||||
|
),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} else if (this.state.suggestedBinding) {
|
} else if (this.state.suggestedBinding) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -6410,7 +6578,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
() => maxBindingDistance_simple(this.state.zoom),
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
if (hoveredElement) {
|
if (hoveredElement) {
|
||||||
this.actionManager.executeAction(actionFinalize, "ui", {
|
this.actionManager.executeAction(actionFinalize, "ui", {
|
||||||
@@ -6564,26 +6732,33 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
() => maxBindingDistance_simple(this.state.zoom),
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
if (
|
const scenePointer = pointFrom<GlobalPoint>(scenePointerX, scenePointerY);
|
||||||
hit &&
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
!isPointInElement(
|
if (hit && !isPointInElement(scenePointer, hit, elementsMap)) {
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
|
||||||
hit,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
suggestedBinding: hit,
|
suggestedBinding: {
|
||||||
|
element: hit,
|
||||||
|
midPoint: getSnapOutlineMidPoint(
|
||||||
|
scenePointer,
|
||||||
|
hit,
|
||||||
|
elementsMap,
|
||||||
|
this.state.zoom,
|
||||||
|
),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasDeselectedButton = Boolean(event.buttons);
|
const isPressingAnyButton = Boolean(event.buttons);
|
||||||
|
const isLaserTool = this.state.activeTool.type === "laser";
|
||||||
if (
|
if (
|
||||||
hasDeselectedButton ||
|
isPressingAnyButton ||
|
||||||
(this.state.activeTool.type !== "selection" &&
|
// checking against laser so that if you mouseover with a laser tool
|
||||||
|
// over a link/embeddable, we change the cursor
|
||||||
|
(!isLaserTool &&
|
||||||
|
this.state.activeTool.type !== "selection" &&
|
||||||
this.state.activeTool.type !== "lasso" &&
|
this.state.activeTool.type !== "lasso" &&
|
||||||
this.state.activeTool.type !== "text" &&
|
this.state.activeTool.type !== "text" &&
|
||||||
this.state.activeTool.type !== "eraser")
|
this.state.activeTool.type !== "eraser")
|
||||||
@@ -6668,6 +6843,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isEraserActive(this.state)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const hitElementMightBeLocked = this.getElementAtPosition(
|
const hitElementMightBeLocked = this.getElementAtPosition(
|
||||||
scenePointerX,
|
scenePointerX,
|
||||||
scenePointerY,
|
scenePointerY,
|
||||||
@@ -6684,18 +6863,25 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
hitElement = hitElementMightBeLocked;
|
hitElement = hitElementMightBeLocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hitLinkElement = this.getElementLinkAtPosition(
|
if (
|
||||||
scenePointer,
|
!this.handleIframeLikeElementHover({
|
||||||
hitElementMightBeLocked,
|
hitElement,
|
||||||
);
|
scenePointer,
|
||||||
if (isEraserActive(this.state)) {
|
moveEvent: event,
|
||||||
return;
|
})
|
||||||
|
) {
|
||||||
|
this.hitLinkElement = this.getElementLinkAtPosition(
|
||||||
|
scenePointer,
|
||||||
|
hitElementMightBeLocked,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.hitLinkElement &&
|
this.hitLinkElement &&
|
||||||
!this.state.selectedElementIds[this.hitLinkElement.id]
|
!this.state.selectedElementIds[this.hitLinkElement.id]
|
||||||
) {
|
) {
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.POINTER);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.POINTER);
|
||||||
|
|
||||||
showHyperlinkTooltip(
|
showHyperlinkTooltip(
|
||||||
this.hitLinkElement,
|
this.hitLinkElement,
|
||||||
this.state,
|
this.state,
|
||||||
@@ -6703,6 +6889,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
hideHyperlinkToolip();
|
hideHyperlinkToolip();
|
||||||
|
if (isLaserTool) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
hitElement &&
|
hitElement &&
|
||||||
(hitElement.link || isEmbeddableElement(hitElement)) &&
|
(hitElement.link || isEmbeddableElement(hitElement)) &&
|
||||||
@@ -6735,20 +6924,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
!hitElement?.locked
|
!hitElement?.locked
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
hitElement &&
|
|
||||||
isIframeLikeElement(hitElement) &&
|
|
||||||
this.isIframeLikeElementCenter(
|
|
||||||
hitElement,
|
|
||||||
event,
|
|
||||||
scenePointerX,
|
|
||||||
scenePointerY,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.POINTER);
|
|
||||||
this.setState({
|
|
||||||
activeEmbeddable: { element: hitElement, state: "hover" },
|
|
||||||
});
|
|
||||||
} else if (
|
|
||||||
!hitElement ||
|
!hitElement ||
|
||||||
// Elbow arrows can only be moved when unconnected
|
// Elbow arrows can only be moved when unconnected
|
||||||
!isElbowArrow(hitElement) ||
|
!isElbowArrow(hitElement) ||
|
||||||
@@ -6760,9 +6935,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
) {
|
) {
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.MOVE);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.MOVE);
|
||||||
}
|
}
|
||||||
if (this.state.activeEmbeddable?.state === "hover") {
|
|
||||||
this.setState({ activeEmbeddable: null });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -6923,6 +7095,37 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for focus point hover
|
||||||
|
let hoveredFocusPointBinding: "start" | "end" | null = null;
|
||||||
|
const arrow = element as any;
|
||||||
|
if (arrow.startBinding || arrow.endBinding) {
|
||||||
|
hoveredFocusPointBinding = handleFocusPointHover(
|
||||||
|
element as ExcalidrawArrowElement,
|
||||||
|
scenePointerX,
|
||||||
|
scenePointerY,
|
||||||
|
this.scene,
|
||||||
|
this.state,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.state.selectedLinearElement.hoveredFocusPointBinding !==
|
||||||
|
hoveredFocusPointBinding
|
||||||
|
) {
|
||||||
|
this.setState({
|
||||||
|
selectedLinearElement: {
|
||||||
|
...this.state.selectedLinearElement,
|
||||||
|
isDragging: false,
|
||||||
|
hoveredFocusPointBinding,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set cursor to pointer when hovering over a focus point
|
||||||
|
if (hoveredFocusPointBinding) {
|
||||||
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.POINTER);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.AUTO);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.AUTO);
|
||||||
}
|
}
|
||||||
@@ -7385,26 +7588,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
x: scenePointerX,
|
x: scenePointerX,
|
||||||
y: scenePointerY,
|
y: scenePointerY,
|
||||||
};
|
};
|
||||||
const clicklength =
|
|
||||||
event.timeStamp - (this.lastPointerDownEvent?.timeStamp ?? 0);
|
|
||||||
|
|
||||||
if (this.editorInterface.formFactor === "phone" && clicklength < 300) {
|
if (this.handleIframeLikeCenterClick()) {
|
||||||
const hitElement = this.getElementAtPosition(
|
return;
|
||||||
scenePointer.x,
|
|
||||||
scenePointer.y,
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
isIframeLikeElement(hitElement) &&
|
|
||||||
this.isIframeLikeElementCenter(
|
|
||||||
hitElement,
|
|
||||||
event,
|
|
||||||
scenePointer.x,
|
|
||||||
scenePointer.y,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.handleEmbeddableCenterClick(hitElement);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.editorInterface.isTouchScreen) {
|
if (this.editorInterface.isTouchScreen) {
|
||||||
@@ -7425,20 +7611,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.hitLinkElement &&
|
this.hitLinkElement &&
|
||||||
!this.state.selectedElementIds[this.hitLinkElement.id]
|
!this.state.selectedElementIds[this.hitLinkElement.id]
|
||||||
) {
|
) {
|
||||||
if (
|
this.handleElementLinkClick(event);
|
||||||
clicklength < 300 &&
|
|
||||||
isIframeLikeElement(this.hitLinkElement) &&
|
|
||||||
!isPointHittingLinkIcon(
|
|
||||||
this.hitLinkElement,
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
this.state,
|
|
||||||
pointFrom(scenePointer.x, scenePointer.y),
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.handleEmbeddableCenterClick(this.hitLinkElement);
|
|
||||||
} else {
|
|
||||||
this.redirectToLink(event);
|
|
||||||
}
|
|
||||||
} else if (this.state.viewModeEnabled) {
|
} else if (this.state.viewModeEnabled) {
|
||||||
this.setState({
|
this.setState({
|
||||||
activeEmbeddable: null,
|
activeEmbeddable: null,
|
||||||
@@ -7498,7 +7671,8 @@ 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)
|
(this.state.viewModeEnabled &&
|
||||||
|
this.state.activeTool.type !== "laser"))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
@@ -7576,7 +7750,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
lastPointerUp = null;
|
lastPointerUp = null;
|
||||||
isPanning = false;
|
isPanning = false;
|
||||||
if (!isHoldingSpace) {
|
if (!isHoldingSpace) {
|
||||||
if (this.state.viewModeEnabled) {
|
if (
|
||||||
|
this.state.viewModeEnabled &&
|
||||||
|
this.state.activeTool.type !== "laser"
|
||||||
|
) {
|
||||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
||||||
} else {
|
} else {
|
||||||
setCursorForShape(this.interactiveCanvas, this.state);
|
setCursorForShape(this.interactiveCanvas, this.state);
|
||||||
@@ -7847,6 +8024,37 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
if (ret.didAddPoint) {
|
if (ret.didAddPoint) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also check at current pointer position if focus point is being hovered
|
||||||
|
// (in case we're clicking directly without a prior move event)
|
||||||
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
|
const arrow = LinearElementEditor.getElement(
|
||||||
|
linearElementEditor.elementId,
|
||||||
|
elementsMap,
|
||||||
|
) as any;
|
||||||
|
|
||||||
|
if (arrow && isBindingElement(arrow)) {
|
||||||
|
const { hitFocusPoint, pointerOffset } =
|
||||||
|
handleFocusPointPointerDown(
|
||||||
|
arrow,
|
||||||
|
pointerDownState,
|
||||||
|
elementsMap,
|
||||||
|
this.state,
|
||||||
|
);
|
||||||
|
|
||||||
|
// If focus point is hit, update state and prevent element selection
|
||||||
|
if (hitFocusPoint) {
|
||||||
|
this.setState({
|
||||||
|
selectedLinearElement: {
|
||||||
|
...linearElementEditor,
|
||||||
|
hoveredFocusPointBinding: hitFocusPoint,
|
||||||
|
draggedFocusPointBinding: hitFocusPoint,
|
||||||
|
pointerOffset,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allHitElements = this.getElementsAtPosition(
|
const allHitElements = this.getElementsAtPosition(
|
||||||
@@ -8661,6 +8869,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
selectedPointsIndices: [endIdx],
|
selectedPointsIndices: [endIdx],
|
||||||
initialState: {
|
initialState: {
|
||||||
...linearElementEditor.initialState,
|
...linearElementEditor.initialState,
|
||||||
|
arrowStartIsInside: event.altKey,
|
||||||
lastClickedPoint: endIdx,
|
lastClickedPoint: endIdx,
|
||||||
origin: pointFrom<GlobalPoint>(
|
origin: pointFrom<GlobalPoint>(
|
||||||
pointerDownState.origin.x,
|
pointerDownState.origin.x,
|
||||||
@@ -8679,7 +8888,18 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
bindMode: "orbit",
|
bindMode: "orbit",
|
||||||
newElement: element,
|
newElement: element,
|
||||||
startBoundElement: boundElement,
|
startBoundElement: boundElement,
|
||||||
suggestedBinding: boundElement || null,
|
suggestedBinding:
|
||||||
|
boundElement && isBindingElement(element)
|
||||||
|
? {
|
||||||
|
element: boundElement,
|
||||||
|
midPoint: getSnapOutlineMidPoint(
|
||||||
|
point,
|
||||||
|
boundElement,
|
||||||
|
elementsMap,
|
||||||
|
this.state.zoom,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
selectedElementIds: nextSelectedElementIds,
|
selectedElementIds: nextSelectedElementIds,
|
||||||
selectedLinearElement: linearElementEditor,
|
selectedLinearElement: linearElementEditor,
|
||||||
};
|
};
|
||||||
@@ -8943,8 +9163,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lastPointerCoords =
|
const lastPointerCoords =
|
||||||
this.lastPointerMoveCoords ?? pointerDownState.origin;
|
this.previousPointerMoveCoords ?? pointerDownState.origin;
|
||||||
this.lastPointerMoveCoords = pointerCoords;
|
this.previousPointerMoveCoords = pointerCoords;
|
||||||
|
|
||||||
// We need to initialize dragOffsetXY only after we've updated
|
// We need to initialize dragOffsetXY only after we've updated
|
||||||
// `state.selectedElementIds` on pointerDown. Doing it here in pointerMove
|
// `state.selectedElementIds` on pointerDown. Doing it here in pointerMove
|
||||||
@@ -8998,6 +9218,31 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
if (this.state.selectedLinearElement) {
|
if (this.state.selectedLinearElement) {
|
||||||
const linearElementEditor = this.state.selectedLinearElement;
|
const linearElementEditor = this.state.selectedLinearElement;
|
||||||
|
|
||||||
|
// Handle focus point dragging if needed
|
||||||
|
if (linearElementEditor.draggedFocusPointBinding) {
|
||||||
|
handleFocusPointDrag(
|
||||||
|
linearElementEditor,
|
||||||
|
elementsMap,
|
||||||
|
pointerCoords,
|
||||||
|
this.scene,
|
||||||
|
this.state,
|
||||||
|
this.getEffectiveGridSize(),
|
||||||
|
event.altKey,
|
||||||
|
);
|
||||||
|
this.setState({
|
||||||
|
selectedLinearElement: {
|
||||||
|
...linearElementEditor,
|
||||||
|
isDragging: false,
|
||||||
|
selectedPointsIndices: [],
|
||||||
|
initialState: {
|
||||||
|
...linearElementEditor.initialState,
|
||||||
|
lastClickedPoint: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
LinearElementEditor.shouldAddMidpoint(
|
LinearElementEditor.shouldAddMidpoint(
|
||||||
this.state.selectedLinearElement,
|
this.state.selectedLinearElement,
|
||||||
@@ -9236,14 +9481,21 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.imageCache.get(croppingElement.fileId)?.image;
|
this.imageCache.get(croppingElement.fileId)?.image;
|
||||||
|
|
||||||
if (image && !(image instanceof Promise)) {
|
if (image && !(image instanceof Promise)) {
|
||||||
const instantDragOffset = vectorScale(
|
const uncroppedSize =
|
||||||
vector(
|
getUncroppedWidthAndHeight(croppingElement);
|
||||||
pointerCoords.x - lastPointerCoords.x,
|
const instantDragOffset = vector(
|
||||||
pointerCoords.y - lastPointerCoords.y,
|
pointerCoords.x - lastPointerCoords.x,
|
||||||
),
|
pointerCoords.y - lastPointerCoords.y,
|
||||||
Math.max(this.state.zoom.value, 2),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// to reduce cursor:image drift, we need to take into account
|
||||||
|
// the canvas image element scaling so we can accurately
|
||||||
|
// track the pixels on movement
|
||||||
|
instantDragOffset[0] *=
|
||||||
|
image.naturalWidth / uncroppedSize.width;
|
||||||
|
instantDragOffset[1] *=
|
||||||
|
image.naturalHeight / uncroppedSize.height;
|
||||||
|
|
||||||
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(
|
const [x1, y1, x2, y2, cx, cy] = getElementAbsoluteCoords(
|
||||||
croppingElement,
|
croppingElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@@ -9286,13 +9538,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const nextCrop = {
|
const nextCrop = {
|
||||||
...crop,
|
...crop,
|
||||||
x: clamp(
|
x: clamp(
|
||||||
crop.x +
|
crop.x -
|
||||||
offsetVector[0] * Math.sign(croppingElement.scale[0]),
|
offsetVector[0] * Math.sign(croppingElement.scale[0]),
|
||||||
0,
|
0,
|
||||||
image.naturalWidth - crop.width,
|
image.naturalWidth - crop.width,
|
||||||
),
|
),
|
||||||
y: clamp(
|
y: clamp(
|
||||||
crop.y +
|
crop.y -
|
||||||
offsetVector[1] * Math.sign(croppingElement.scale[1]),
|
offsetVector[1] * Math.sign(croppingElement.scale[1]),
|
||||||
0,
|
0,
|
||||||
image.naturalHeight - crop.height,
|
image.naturalHeight - crop.height,
|
||||||
@@ -9785,6 +10037,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
// just in case, tool changes mid drag, always clean up
|
// just in case, tool changes mid drag, always clean up
|
||||||
this.lassoTrail.endPath();
|
this.lassoTrail.endPath();
|
||||||
|
this.previousPointerMoveCoords = null;
|
||||||
|
|
||||||
SnapCache.setReferenceSnapPoints(null);
|
SnapCache.setReferenceSnapPoints(null);
|
||||||
SnapCache.setVisibleGaps(null);
|
SnapCache.setVisibleGaps(null);
|
||||||
@@ -9868,12 +10121,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
// and sets binding element
|
// and sets binding element
|
||||||
if (
|
if (
|
||||||
this.state.selectedLinearElement?.isEditing &&
|
this.state.selectedLinearElement?.isEditing &&
|
||||||
!this.state.newElement
|
!this.state.newElement &&
|
||||||
|
this.state.selectedLinearElement.draggedFocusPointBinding === null
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
!pointerDownState.boxSelection.hasOccurred &&
|
!pointerDownState.boxSelection.hasOccurred &&
|
||||||
pointerDownState.hit?.element?.id !==
|
pointerDownState.hit?.element?.id !==
|
||||||
this.state.selectedLinearElement.elementId
|
this.state.selectedLinearElement.elementId &&
|
||||||
|
this.state.selectedLinearElement.draggedFocusPointBinding === null
|
||||||
) {
|
) {
|
||||||
this.actionManager.executeAction(actionFinalize);
|
this.actionManager.executeAction(actionFinalize);
|
||||||
} else {
|
} else {
|
||||||
@@ -9909,7 +10164,18 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this.state.selectedLinearElement.draggedFocusPointBinding) {
|
||||||
|
handleFocusPointPointerUp(
|
||||||
|
this.state.selectedLinearElement,
|
||||||
|
this.scene,
|
||||||
|
);
|
||||||
|
this.setState({
|
||||||
|
selectedLinearElement: {
|
||||||
|
...this.state.selectedLinearElement,
|
||||||
|
draggedFocusPointBinding: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (
|
||||||
pointerDownState.hit?.element?.id !==
|
pointerDownState.hit?.element?.id !==
|
||||||
this.state.selectedLinearElement.elementId
|
this.state.selectedLinearElement.elementId
|
||||||
) {
|
) {
|
||||||
@@ -9919,6 +10185,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState({ selectedLinearElement: null });
|
this.setState({ selectedLinearElement: null });
|
||||||
}
|
}
|
||||||
} else if (this.state.selectedLinearElement.isDragging) {
|
} else if (this.state.selectedLinearElement.isDragging) {
|
||||||
|
this.setState({
|
||||||
|
selectedLinearElement: {
|
||||||
|
...this.state.selectedLinearElement,
|
||||||
|
isDragging: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
this.actionManager.executeAction(actionFinalize, "ui", {
|
this.actionManager.executeAction(actionFinalize, "ui", {
|
||||||
event: childEvent,
|
event: childEvent,
|
||||||
sceneCoords,
|
sceneCoords,
|
||||||
@@ -10693,25 +10965,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
suggestedBinding: null,
|
suggestedBinding: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
hitElement &&
|
|
||||||
this.lastPointerUpEvent &&
|
|
||||||
this.lastPointerDownEvent &&
|
|
||||||
this.lastPointerUpEvent.timeStamp -
|
|
||||||
this.lastPointerDownEvent.timeStamp <
|
|
||||||
300 &&
|
|
||||||
gesture.pointers.size <= 1 &&
|
|
||||||
isIframeLikeElement(hitElement) &&
|
|
||||||
this.isIframeLikeElementCenter(
|
|
||||||
hitElement,
|
|
||||||
this.lastPointerUpEvent,
|
|
||||||
pointerDownState.origin.x,
|
|
||||||
pointerDownState.origin.y,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.handleEmbeddableCenterClick(hitElement);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useRef, useEffect } from "react";
|
import { useRef, useEffect } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export type CommandPaletteItem = {
|
|||||||
category: string;
|
category: string;
|
||||||
order?: number;
|
order?: number;
|
||||||
predicate?: boolean | Action["predicate"];
|
predicate?: boolean | Action["predicate"];
|
||||||
shortcut?: string;
|
shortcut?: string | null;
|
||||||
/** if false, command will not show while in view mode */
|
/** if false, command will not show while in view mode */
|
||||||
viewMode?: boolean;
|
viewMode?: boolean;
|
||||||
perform: (data: {
|
perform: (data: {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
&.ExcButton--status-loading,
|
&.ExcButton--status-loading,
|
||||||
&.ExcButton--status-success {
|
&.ExcButton--status-success {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
background-color: var(--color-success);
|
||||||
|
|
||||||
.ExcButton__contents {
|
.ExcButton__contents {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { KEYS } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { Excalidraw } from "../..";
|
||||||
|
import { Keyboard } from "../../tests/helpers/ui";
|
||||||
|
import { act, render } from "../../tests/test-utils";
|
||||||
|
|
||||||
|
describe("FontPicker", () => {
|
||||||
|
it("should be able to open font picker", async () => {
|
||||||
|
(global as any).ResizeObserver =
|
||||||
|
(global as any).ResizeObserver ||
|
||||||
|
class ResizeObserver {
|
||||||
|
observe() {}
|
||||||
|
unobserve() {}
|
||||||
|
disconnect() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
const { queryByTestId } = await render(
|
||||||
|
<Excalidraw handleKeyboardGlobally={true} />,
|
||||||
|
);
|
||||||
|
|
||||||
|
Keyboard.keyPress(KEYS.T);
|
||||||
|
|
||||||
|
const fontPickerTrigger = queryByTestId("font-family-show-fonts");
|
||||||
|
|
||||||
|
expect(fontPickerTrigger).not.toBeNull();
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
fontPickerTrigger!.click();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { useCallback, useMemo } from "react";
|
import React, { useCallback, useMemo } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,12 @@ import { PropertiesPopover } from "../PropertiesPopover";
|
|||||||
import { QuickSearch } from "../QuickSearch";
|
import { QuickSearch } from "../QuickSearch";
|
||||||
import { ScrollableList } from "../ScrollableList";
|
import { ScrollableList } from "../ScrollableList";
|
||||||
import DropdownMenuGroup from "../dropdownMenu/DropdownMenuGroup";
|
import DropdownMenuGroup from "../dropdownMenu/DropdownMenuGroup";
|
||||||
import DropdownMenuItem, {
|
import {
|
||||||
DropDownMenuItemBadgeType,
|
DropDownMenuItemBadgeType,
|
||||||
DropDownMenuItemBadge,
|
DropDownMenuItemBadge,
|
||||||
} from "../dropdownMenu/DropdownMenuItem";
|
} from "../dropdownMenu/DropdownMenuItem";
|
||||||
|
import MenuItemContent from "../dropdownMenu/DropdownMenuItemContent";
|
||||||
|
import { getDropdownMenuItemClassName } from "../dropdownMenu/common";
|
||||||
import {
|
import {
|
||||||
FontFamilyCodeIcon,
|
FontFamilyCodeIcon,
|
||||||
FontFamilyHeadingIcon,
|
FontFamilyHeadingIcon,
|
||||||
@@ -267,45 +269,74 @@ export const FontPickerList = React.memo(
|
|||||||
[filteredFonts, sceneFamilies],
|
[filteredFonts, sceneFamilies],
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderFont = (font: FontDescriptor, index: number) => (
|
const FontPickerListItem = ({
|
||||||
<DropdownMenuItem
|
font,
|
||||||
key={font.value}
|
order,
|
||||||
icon={font.icon}
|
}: {
|
||||||
value={font.value}
|
font: FontDescriptor;
|
||||||
order={index}
|
order: number;
|
||||||
textStyle={{
|
}) => {
|
||||||
fontFamily: getFontFamilyString({ fontFamily: font.value }),
|
const ref = useRef<HTMLButtonElement>(null);
|
||||||
}}
|
const isHovered = font.value === hoveredFont?.value;
|
||||||
hovered={font.value === hoveredFont?.value}
|
const isSelected = font.value === selectedFontFamily;
|
||||||
selected={font.value === selectedFontFamily}
|
|
||||||
// allow to tab between search and selected font
|
useEffect(() => {
|
||||||
tabIndex={font.value === selectedFontFamily ? 0 : -1}
|
if (!isHovered) {
|
||||||
onClick={(e) => {
|
return;
|
||||||
wrappedOnSelect(Number(e.currentTarget.value));
|
|
||||||
}}
|
|
||||||
onMouseMove={() => {
|
|
||||||
if (hoveredFont?.value !== font.value) {
|
|
||||||
onHover(font.value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
badge={
|
|
||||||
font.badge && (
|
|
||||||
<DropDownMenuItemBadge type={font.badge.type}>
|
|
||||||
{font.badge.placeholder}
|
|
||||||
</DropDownMenuItemBadge>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
if (order === 0) {
|
||||||
{font.text}
|
// scroll into the first item differently, so it's visible what is above (i.e. group title)
|
||||||
</DropdownMenuItem>
|
ref.current?.scrollIntoView?.({ block: "end" });
|
||||||
);
|
} else {
|
||||||
|
ref.current?.scrollIntoView?.({ block: "nearest" });
|
||||||
|
}
|
||||||
|
}, [isHovered, order]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
ref={ref}
|
||||||
|
type="button"
|
||||||
|
value={font.value}
|
||||||
|
className={getDropdownMenuItemClassName("", isSelected, isHovered)}
|
||||||
|
title={font.text}
|
||||||
|
// allow to tab between search and selected font
|
||||||
|
tabIndex={isSelected ? 0 : -1}
|
||||||
|
onClick={(e) => {
|
||||||
|
wrappedOnSelect(Number(e.currentTarget.value));
|
||||||
|
}}
|
||||||
|
onMouseMove={() => {
|
||||||
|
if (hoveredFont?.value !== font.value) {
|
||||||
|
onHover(font.value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MenuItemContent
|
||||||
|
icon={font.icon}
|
||||||
|
badge={
|
||||||
|
font.badge && (
|
||||||
|
<DropDownMenuItemBadge type={font.badge.type}>
|
||||||
|
{font.badge.placeholder}
|
||||||
|
</DropDownMenuItemBadge>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
textStyle={{
|
||||||
|
fontFamily: getFontFamilyString({ fontFamily: font.value }),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{font.text}
|
||||||
|
</MenuItemContent>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const groups = [];
|
const groups = [];
|
||||||
|
|
||||||
if (sceneFilteredFonts.length) {
|
if (sceneFilteredFonts.length) {
|
||||||
groups.push(
|
groups.push(
|
||||||
<DropdownMenuGroup title={t("fontList.sceneFonts")} key="group_1">
|
<DropdownMenuGroup title={t("fontList.sceneFonts")} key="group_1">
|
||||||
{sceneFilteredFonts.map(renderFont)}
|
{sceneFilteredFonts.map((font, index) => (
|
||||||
|
<FontPickerListItem key={font.value} font={font} order={index} />
|
||||||
|
))}
|
||||||
</DropdownMenuGroup>,
|
</DropdownMenuGroup>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -313,9 +344,13 @@ export const FontPickerList = React.memo(
|
|||||||
if (availableFilteredFonts.length) {
|
if (availableFilteredFonts.length) {
|
||||||
groups.push(
|
groups.push(
|
||||||
<DropdownMenuGroup title={t("fontList.availableFonts")} key="group_2">
|
<DropdownMenuGroup title={t("fontList.availableFonts")} key="group_2">
|
||||||
{availableFilteredFonts.map((font, index) =>
|
{availableFilteredFonts.map((font, index) => (
|
||||||
renderFont(font, index + sceneFilteredFonts.length),
|
<FontPickerListItem
|
||||||
)}
|
key={font.value}
|
||||||
|
font={font}
|
||||||
|
order={index + sceneFilteredFonts.length}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</DropdownMenuGroup>,
|
</DropdownMenuGroup>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
|
|
||||||
import { MOBILE_ACTION_BUTTON_BG } from "@excalidraw/common";
|
import { MOBILE_ACTION_BUTTON_BG } from "@excalidraw/common";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
|||||||
|
|
||||||
import { actionToggleStats } from "../actions";
|
import { actionToggleStats } from "../actions";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import { isHandToolActive } from "../appState";
|
|
||||||
import { TunnelsContext, useInitializeTunnels } from "../context/tunnels";
|
import { TunnelsContext, useInitializeTunnels } from "../context/tunnels";
|
||||||
import { UIAppStateContext } from "../context/ui-appState";
|
import { UIAppStateContext } from "../context/ui-appState";
|
||||||
import { useAtom, useAtomValue } from "../editor-jotai";
|
import { useAtom, useAtomValue } from "../editor-jotai";
|
||||||
@@ -55,7 +54,6 @@ import ElementLinkDialog from "./ElementLinkDialog";
|
|||||||
import { ErrorDialog } from "./ErrorDialog";
|
import { ErrorDialog } from "./ErrorDialog";
|
||||||
import { EyeDropper, activeEyeDropperAtom } from "./EyeDropper";
|
import { EyeDropper, activeEyeDropperAtom } from "./EyeDropper";
|
||||||
import { FixedSideContainer } from "./FixedSideContainer";
|
import { FixedSideContainer } from "./FixedSideContainer";
|
||||||
import { HandButton } from "./HandButton";
|
|
||||||
import { HelpDialog } from "./HelpDialog";
|
import { HelpDialog } from "./HelpDialog";
|
||||||
import { HintViewer } from "./HintViewer";
|
import { HintViewer } from "./HintViewer";
|
||||||
import { ImageExportDialog } from "./ImageExportDialog";
|
import { ImageExportDialog } from "./ImageExportDialog";
|
||||||
@@ -359,13 +357,6 @@ const LayerUI = ({
|
|||||||
|
|
||||||
<div className="App-toolbar__divider" />
|
<div className="App-toolbar__divider" />
|
||||||
|
|
||||||
<HandButton
|
|
||||||
checked={isHandToolActive(appState)}
|
|
||||||
onChange={() => onHandToolToggle()}
|
|
||||||
title={t("toolBar.hand")}
|
|
||||||
isMobile
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ShapesSwitcher
|
<ShapesSwitcher
|
||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
activeTool={appState.activeTool}
|
activeTool={appState.activeTool}
|
||||||
|
|||||||
@@ -126,9 +126,10 @@
|
|||||||
|
|
||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
width: 196px;
|
width: 196px;
|
||||||
box-shadow: var(--library-dropdown-shadow);
|
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
padding: 0.25rem 0.5rem;
|
padding: 0.25rem 0.5rem;
|
||||||
|
|
||||||
|
--box-shadow: var(--library-dropdown-shadow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ export const MobileToolBar = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Other Shapes */}
|
{/* Other Shapes */}
|
||||||
<DropdownMenu open={isOtherShapesMenuOpen} placement="top">
|
<DropdownMenu open={isOtherShapesMenuOpen}>
|
||||||
<DropdownMenu.Trigger
|
<DropdownMenu.Trigger
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",
|
"App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",
|
||||||
@@ -403,6 +403,7 @@ export const MobileToolBar = ({
|
|||||||
onClickOutside={() => setIsOtherShapesMenuOpen(false)}
|
onClickOutside={() => setIsOtherShapesMenuOpen(false)}
|
||||||
onSelect={() => setIsOtherShapesMenuOpen(false)}
|
onSelect={() => setIsOtherShapesMenuOpen(false)}
|
||||||
className="App-toolbar__extra-tools-dropdown"
|
className="App-toolbar__extra-tools-dropdown"
|
||||||
|
align="start"
|
||||||
>
|
>
|
||||||
{!showTextToolOutside && (
|
{!showTextToolOutside && (
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { type ReactNode } from "react";
|
import React, { type ReactNode } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
import type { SidebarTabName } from "../../types";
|
import type { SidebarTabName } from "../../types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
import type { SidebarTabName } from "../../types";
|
import type { SidebarTabName } from "../../types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
export const SidebarTabTriggers = ({
|
export const SidebarTabTriggers = ({
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
import { useUIAppState } from "../../context/ui-appState";
|
import { useUIAppState } from "../../context/ui-appState";
|
||||||
import { useExcalidrawSetAppState } from "../App";
|
import { useExcalidrawSetAppState } from "../App";
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ describe("binding with linear elements", () => {
|
|||||||
) as HTMLInputElement;
|
) as HTMLInputElement;
|
||||||
expect(linear.startBinding).not.toBe(null);
|
expect(linear.startBinding).not.toBe(null);
|
||||||
expect(inputX).not.toBeNull();
|
expect(inputX).not.toBeNull();
|
||||||
UI.updateInput(inputX, String("186"));
|
UI.updateInput(inputX, String("184"));
|
||||||
expect(linear.startBinding).not.toBe(null);
|
expect(linear.startBinding).not.toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ $verticalBreakpoint: 861px;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__empty-state {
|
&__welcome-screen {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
|
|
||||||
&-content {
|
&__welcome-message {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
|
|||||||
@@ -52,11 +52,7 @@ export const ChatHistoryMenu = ({
|
|||||||
>
|
>
|
||||||
{historyIcon}
|
{historyIcon}
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
<DropdownMenu.Content
|
<DropdownMenu.Content onClickOutside={onClose} onSelect={onClose}>
|
||||||
onClickOutside={onClose}
|
|
||||||
onSelect={onClose}
|
|
||||||
placement="bottom"
|
|
||||||
>
|
|
||||||
<>
|
<>
|
||||||
{savedChats.map((chat) => (
|
{savedChats.map((chat) => (
|
||||||
<DropdownMenu.ItemCustom
|
<DropdownMenu.ItemCustom
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { InlineIcon } from "../../InlineIcon";
|
|||||||
|
|
||||||
import { t } from "../../../i18n";
|
import { t } from "../../../i18n";
|
||||||
|
|
||||||
|
import { TTDWelcomeMessage } from "../TTDWelcomeMessage";
|
||||||
|
|
||||||
import { ChatMessage } from "./ChatMessage";
|
import { ChatMessage } from "./ChatMessage";
|
||||||
|
|
||||||
import type { TChat, TTTDDialog } from "../types";
|
import type { TChat, TTTDDialog } from "../types";
|
||||||
@@ -20,13 +22,13 @@ export const ChatInterface = ({
|
|||||||
onGenerate,
|
onGenerate,
|
||||||
isGenerating,
|
isGenerating,
|
||||||
rateLimits,
|
rateLimits,
|
||||||
placeholder,
|
|
||||||
onAbort,
|
onAbort,
|
||||||
onMermaidTabClick,
|
onMermaidTabClick,
|
||||||
onAiRepairClick,
|
onAiRepairClick,
|
||||||
onDeleteMessage,
|
onDeleteMessage,
|
||||||
onInsertMessage,
|
onInsertMessage,
|
||||||
onRetry,
|
onRetry,
|
||||||
|
renderWelcomeScreen,
|
||||||
renderWarning,
|
renderWarning,
|
||||||
}: {
|
}: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
@@ -41,17 +43,13 @@ export const ChatInterface = ({
|
|||||||
} | null;
|
} | null;
|
||||||
onViewAsMermaid?: () => void;
|
onViewAsMermaid?: () => void;
|
||||||
generatedResponse?: string | null;
|
generatedResponse?: string | null;
|
||||||
placeholder: {
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
hint: string;
|
|
||||||
};
|
|
||||||
onAbort?: () => void;
|
onAbort?: () => void;
|
||||||
onMermaidTabClick?: (message: TChat.ChatMessage) => void;
|
onMermaidTabClick?: (message: TChat.ChatMessage) => void;
|
||||||
onAiRepairClick?: (message: TChat.ChatMessage) => void;
|
onAiRepairClick?: (message: TChat.ChatMessage) => void;
|
||||||
onDeleteMessage?: (messageId: string) => void;
|
onDeleteMessage?: (messageId: string) => void;
|
||||||
onInsertMessage?: (message: TChat.ChatMessage) => void;
|
onInsertMessage?: (message: TChat.ChatMessage) => void;
|
||||||
onRetry?: (message: TChat.ChatMessage) => void;
|
onRetry?: (message: TChat.ChatMessage) => void;
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
}) => {
|
}) => {
|
||||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -113,12 +111,12 @@ export const ChatInterface = ({
|
|||||||
<div className="chat-interface">
|
<div className="chat-interface">
|
||||||
<div className="chat-interface__messages">
|
<div className="chat-interface__messages">
|
||||||
{messages.length === 0 ? (
|
{messages.length === 0 ? (
|
||||||
<div className="chat-interface__empty-state">
|
<div className="chat-interface__welcome-screen">
|
||||||
<div className="chat-interface__empty-state-content">
|
{renderWelcomeScreen ? (
|
||||||
<h3>{placeholder.title}</h3>
|
renderWelcomeScreen({ rateLimits: rateLimits ?? null })
|
||||||
<p>{placeholder.description}</p>
|
) : (
|
||||||
<p>{placeholder.hint}</p>
|
<TTDWelcomeMessage />
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
messages.map((message, index) => (
|
messages.map((message, index) => (
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export const TTDChatPanel = ({
|
|||||||
onInsertMessage,
|
onInsertMessage,
|
||||||
onRetry,
|
onRetry,
|
||||||
onViewAsMermaid,
|
onViewAsMermaid,
|
||||||
|
renderWelcomeScreen,
|
||||||
renderWarning,
|
renderWarning,
|
||||||
}: {
|
}: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
@@ -68,6 +69,7 @@ export const TTDChatPanel = ({
|
|||||||
|
|
||||||
onViewAsMermaid: () => void;
|
onViewAsMermaid: () => void;
|
||||||
|
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
}) => {
|
}) => {
|
||||||
const [rateLimits] = useAtom(rateLimitsAtom);
|
const [rateLimits] = useAtom(rateLimitsAtom);
|
||||||
@@ -151,11 +153,7 @@ export const TTDChatPanel = ({
|
|||||||
onInsertMessage={onInsertMessage}
|
onInsertMessage={onInsertMessage}
|
||||||
onRetry={onRetry}
|
onRetry={onRetry}
|
||||||
rateLimits={rateLimits}
|
rateLimits={rateLimits}
|
||||||
placeholder={{
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
title: t("chat.placeholder.title"),
|
|
||||||
description: t("chat.placeholder.description"),
|
|
||||||
hint: t("chat.placeholder.hint"),
|
|
||||||
}}
|
|
||||||
renderWarning={renderWarning}
|
renderWarning={renderWarning}
|
||||||
/>
|
/>
|
||||||
</TTDDialogPanel>
|
</TTDDialogPanel>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { TTDDialogTab } from "./TTDDialogTab";
|
|||||||
|
|
||||||
import "./TTDDialog.scss";
|
import "./TTDDialog.scss";
|
||||||
|
|
||||||
|
import { TTDWelcomeMessage } from "./TTDWelcomeMessage";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
MermaidToExcalidrawLibProps,
|
MermaidToExcalidrawLibProps,
|
||||||
TTDPersistenceAdapter,
|
TTDPersistenceAdapter,
|
||||||
@@ -25,6 +27,7 @@ export const TTDDialog = (
|
|||||||
props:
|
props:
|
||||||
| {
|
| {
|
||||||
onTextSubmit: TTTDDialog.onTextSubmit;
|
onTextSubmit: TTTDDialog.onTextSubmit;
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
persistenceAdapter: TTDPersistenceAdapter;
|
persistenceAdapter: TTDPersistenceAdapter;
|
||||||
}
|
}
|
||||||
@@ -39,6 +42,8 @@ export const TTDDialog = (
|
|||||||
return <TTDDialogBase {...props} tab={appState.openDialog.tab} />;
|
return <TTDDialogBase {...props} tab={appState.openDialog.tab} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TTDDialog.WelcomeMessage = TTDWelcomeMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text to diagram (TTD) dialog
|
* Text to diagram (TTD) dialog
|
||||||
*/
|
*/
|
||||||
@@ -54,6 +59,7 @@ const TTDDialogBase = withInternalFallback(
|
|||||||
onTextSubmit(
|
onTextSubmit(
|
||||||
props: TTTDDialog.OnTextSubmitProps,
|
props: TTTDDialog.OnTextSubmitProps,
|
||||||
): Promise<TTTDDialog.OnTextSubmitRetValue>;
|
): Promise<TTTDDialog.OnTextSubmitRetValue>;
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
persistenceAdapter: TTDPersistenceAdapter;
|
persistenceAdapter: TTDPersistenceAdapter;
|
||||||
}
|
}
|
||||||
@@ -110,6 +116,7 @@ const TTDDialogBase = withInternalFallback(
|
|||||||
<TextToDiagram
|
<TextToDiagram
|
||||||
mermaidToExcalidrawLib={mermaidToExcalidrawLib}
|
mermaidToExcalidrawLib={mermaidToExcalidrawLib}
|
||||||
onTextSubmit={rest.onTextSubmit}
|
onTextSubmit={rest.onTextSubmit}
|
||||||
|
renderWelcomeScreen={rest.renderWelcomeScreen}
|
||||||
renderWarning={rest.renderWarning}
|
renderWarning={rest.renderWarning}
|
||||||
persistenceAdapter={rest.persistenceAdapter}
|
persistenceAdapter={rest.persistenceAdapter}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
export const TTDDialogTab = ({
|
export const TTDDialogTab = ({
|
||||||
tab,
|
tab,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
export const TTDDialogTabTrigger = ({
|
export const TTDDialogTabTrigger = ({
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
|
|
||||||
export const TTDDialogTabTriggers = ({
|
export const TTDDialogTabTriggers = ({
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as RadixTabs from "@radix-ui/react-tabs";
|
import { Tabs as RadixTabs } from "radix-ui";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
|
|
||||||
import { isMemberOf } from "@excalidraw/common";
|
import { isMemberOf } from "@excalidraw/common";
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { t } from "../../i18n";
|
||||||
|
|
||||||
|
export const TTDWelcomeMessage = () => {
|
||||||
|
return (
|
||||||
|
<div className="chat-interface__welcome-screen__welcome-message">
|
||||||
|
<h3>{t("chat.placeholder.title")}</h3>
|
||||||
|
<p>{t("chat.placeholder.description")}</p>
|
||||||
|
<p>{t("chat.placeholder.hint")}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -35,6 +35,7 @@ import type {
|
|||||||
const TextToDiagramContent = ({
|
const TextToDiagramContent = ({
|
||||||
mermaidToExcalidrawLib,
|
mermaidToExcalidrawLib,
|
||||||
onTextSubmit,
|
onTextSubmit,
|
||||||
|
renderWelcomeScreen,
|
||||||
renderWarning,
|
renderWarning,
|
||||||
persistenceAdapter,
|
persistenceAdapter,
|
||||||
}: {
|
}: {
|
||||||
@@ -42,6 +43,7 @@ const TextToDiagramContent = ({
|
|||||||
onTextSubmit: (
|
onTextSubmit: (
|
||||||
props: TTTDDialog.OnTextSubmitProps,
|
props: TTTDDialog.OnTextSubmitProps,
|
||||||
) => Promise<TTTDDialog.OnTextSubmitRetValue>;
|
) => Promise<TTTDDialog.OnTextSubmitRetValue>;
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
persistenceAdapter: TTDPersistenceAdapter;
|
persistenceAdapter: TTDPersistenceAdapter;
|
||||||
}) => {
|
}) => {
|
||||||
@@ -220,6 +222,7 @@ const TextToDiagramContent = ({
|
|||||||
onRetry={handleRetry}
|
onRetry={handleRetry}
|
||||||
onViewAsMermaid={onViewAsMermaid}
|
onViewAsMermaid={onViewAsMermaid}
|
||||||
renderWarning={renderWarning}
|
renderWarning={renderWarning}
|
||||||
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
/>
|
/>
|
||||||
{showPreview && (
|
{showPreview && (
|
||||||
<TTDPreviewPanel
|
<TTDPreviewPanel
|
||||||
@@ -237,6 +240,7 @@ const TextToDiagramContent = ({
|
|||||||
export const TextToDiagram = ({
|
export const TextToDiagram = ({
|
||||||
mermaidToExcalidrawLib,
|
mermaidToExcalidrawLib,
|
||||||
onTextSubmit,
|
onTextSubmit,
|
||||||
|
renderWelcomeScreen,
|
||||||
renderWarning,
|
renderWarning,
|
||||||
persistenceAdapter,
|
persistenceAdapter,
|
||||||
}: {
|
}: {
|
||||||
@@ -244,6 +248,7 @@ export const TextToDiagram = ({
|
|||||||
onTextSubmit(
|
onTextSubmit(
|
||||||
props: TTTDDialog.OnTextSubmitProps,
|
props: TTTDDialog.OnTextSubmitProps,
|
||||||
): Promise<TTTDDialog.OnTextSubmitRetValue>;
|
): Promise<TTTDDialog.OnTextSubmitRetValue>;
|
||||||
|
renderWelcomeScreen?: TTTDDialog.renderWelcomeScreen;
|
||||||
renderWarning?: TTTDDialog.renderWarning;
|
renderWarning?: TTTDDialog.renderWarning;
|
||||||
persistenceAdapter: TTDPersistenceAdapter;
|
persistenceAdapter: TTDPersistenceAdapter;
|
||||||
}) => {
|
}) => {
|
||||||
@@ -251,6 +256,7 @@ export const TextToDiagram = ({
|
|||||||
<TextToDiagramContent
|
<TextToDiagramContent
|
||||||
mermaidToExcalidrawLib={mermaidToExcalidrawLib}
|
mermaidToExcalidrawLib={mermaidToExcalidrawLib}
|
||||||
onTextSubmit={onTextSubmit}
|
onTextSubmit={onTextSubmit}
|
||||||
|
renderWelcomeScreen={renderWelcomeScreen}
|
||||||
renderWarning={renderWarning}
|
renderWarning={renderWarning}
|
||||||
persistenceAdapter={persistenceAdapter}
|
persistenceAdapter={persistenceAdapter}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -116,4 +116,9 @@ export namespace TTTDDialog {
|
|||||||
export type renderWarning = (
|
export type renderWarning = (
|
||||||
chatMessage: TChat.ChatMessage,
|
chatMessage: TChat.ChatMessage,
|
||||||
) => React.ReactNode | undefined;
|
) => React.ReactNode | undefined;
|
||||||
|
|
||||||
|
export type renderWelcomeScreen = (props: {
|
||||||
|
/** null if not rate limit data currently available */
|
||||||
|
rateLimits: RateLimits | null;
|
||||||
|
}) => React.ReactNode | undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import clsx from "clsx";
|
|||||||
|
|
||||||
import { capitalizeString } from "@excalidraw/common";
|
import { capitalizeString } from "@excalidraw/common";
|
||||||
|
|
||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
|
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import { Popover } from "radix-ui";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { useLayoutEffect } from "react";
|
import React, { useLayoutEffect } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -202,9 +202,11 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
|
|||||||
style={{
|
style={{
|
||||||
width: props.appState.width,
|
width: props.appState.width,
|
||||||
height: props.appState.height,
|
height: props.appState.height,
|
||||||
cursor: props.appState.viewModeEnabled
|
cursor:
|
||||||
? CURSOR_TYPE.GRAB
|
props.appState.viewModeEnabled &&
|
||||||
: CURSOR_TYPE.AUTO,
|
props.appState.activeTool.type !== "laser"
|
||||||
|
? CURSOR_TYPE.GRAB
|
||||||
|
: CURSOR_TYPE.AUTO,
|
||||||
}}
|
}}
|
||||||
width={props.appState.width * props.scale}
|
width={props.appState.width * props.scale}
|
||||||
height={props.appState.height * props.scale}
|
height={props.appState.height * props.scale}
|
||||||
@@ -233,6 +235,7 @@ const getRelevantAppStateProps = (
|
|||||||
width: appState.width,
|
width: appState.width,
|
||||||
height: appState.height,
|
height: appState.height,
|
||||||
viewModeEnabled: appState.viewModeEnabled,
|
viewModeEnabled: appState.viewModeEnabled,
|
||||||
|
activeTool: appState.activeTool,
|
||||||
openDialog: appState.openDialog,
|
openDialog: appState.openDialog,
|
||||||
editingGroupId: appState.editingGroupId,
|
editingGroupId: appState.editingGroupId,
|
||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
|
|||||||
@@ -2,24 +2,35 @@
|
|||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
position: absolute;
|
|
||||||
top: 2.5rem;
|
|
||||||
margin-top: 0.5rem;
|
|
||||||
max-width: 16rem;
|
max-width: 16rem;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
&--placement-top {
|
&--placement-top {
|
||||||
top: auto;
|
|
||||||
bottom: 100%;
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__submenu-trigger {
|
||||||
|
&[aria-expanded="true"] {
|
||||||
|
.dropdown-menu-item {
|
||||||
|
background-color: var(--button-hover-bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__submenu-trigger-icon {
|
||||||
|
margin-left: auto;
|
||||||
|
opacity: 0.5;
|
||||||
|
svg g {
|
||||||
|
stroke-width: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&--mobile {
|
&--mobile {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
row-gap: 0.75rem;
|
row-gap: 0.75rem;
|
||||||
|
|
||||||
// When main menu is in the top toolbar, position relative to trigger
|
// When main menu is in the top toolbar, position relative to trigger
|
||||||
&.main-menu-dropdown {
|
&.main-menu {
|
||||||
min-width: 232px;
|
min-width: 232px;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
@@ -32,10 +43,6 @@
|
|||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
padding: 8px 8px;
|
padding: 8px 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
max-height: calc(
|
|
||||||
100svh - var(--editor-container-padding) * 2 - 2.25rem
|
|
||||||
);
|
|
||||||
box-shadow: var(--shadow-island);
|
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
position: relative;
|
position: relative;
|
||||||
transition: box-shadow 0.5s ease-in-out;
|
transition: box-shadow 0.5s ease-in-out;
|
||||||
@@ -51,14 +58,25 @@
|
|||||||
|
|
||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
--gap: 2;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
|
||||||
|
box-shadow: var(--box-shadow, var(--shadow-island));
|
||||||
|
|
||||||
|
max-height: calc(100svh - var(--editor-container-padding) * 2 - 2.25rem);
|
||||||
|
|
||||||
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
box-shadow: var(--box-shadow, var(--shadow-island)),
|
||||||
|
0 0 0 1px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-menu-item-base {
|
.dropdown-menu-item-base {
|
||||||
display: flex;
|
display: flex;
|
||||||
column-gap: 0.625rem;
|
column-gap: 0.625rem;
|
||||||
|
padding: 0 0.5rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -115,11 +133,9 @@
|
|||||||
|
|
||||||
.dropdown-menu-item {
|
.dropdown-menu-item {
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
margin: 1px;
|
|
||||||
padding: 0 0.5rem;
|
padding: 0 0.5rem;
|
||||||
width: calc(100% - 2px);
|
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: 1px solid transparent;
|
border: none;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: var(--border-radius-md);
|
border-radius: var(--border-radius-md);
|
||||||
@@ -162,7 +178,7 @@
|
|||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
background-color: var(--button-hover-bg);
|
background-color: var(--button-hover-bg);
|
||||||
border-color: var(--color-brand-active);
|
box-shadow: 0 0 0 1px var(--color-brand-active);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@@ -223,7 +239,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
border-color: var(--color-primary);
|
box-shadow: 0 0 0 1px var(--color-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
&[disabled] {
|
&[disabled] {
|
||||||
@@ -235,7 +251,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
border-color: transparent;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@at-root .excalidraw.theme--dark#{&} {
|
@at-root .excalidraw.theme--dark#{&} {
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import { CLASSES } from "@excalidraw/common";
|
||||||
|
|
||||||
import DropdownMenuContent from "./DropdownMenuContent";
|
import DropdownMenuContent from "./DropdownMenuContent";
|
||||||
import DropdownMenuGroup from "./DropdownMenuGroup";
|
import DropdownMenuGroup from "./DropdownMenuGroup";
|
||||||
import DropdownMenuItem from "./DropdownMenuItem";
|
import DropdownMenuItem from "./DropdownMenuItem";
|
||||||
import DropdownMenuItemCustom from "./DropdownMenuItemCustom";
|
import DropdownMenuItemCustom from "./DropdownMenuItemCustom";
|
||||||
import DropdownMenuItemLink from "./DropdownMenuItemLink";
|
import DropdownMenuItemLink from "./DropdownMenuItemLink";
|
||||||
import MenuSeparator from "./DropdownMenuSeparator";
|
import MenuSeparator from "./DropdownMenuSeparator";
|
||||||
|
import DropdownMenuSub from "./DropdownMenuSub";
|
||||||
import DropdownMenuTrigger from "./DropdownMenuTrigger";
|
import DropdownMenuTrigger from "./DropdownMenuTrigger";
|
||||||
|
import DropdownMenuItemCheckbox from "./DropdownMenuItemCheckbox";
|
||||||
import {
|
import {
|
||||||
getMenuContentComponent,
|
getMenuContentComponent,
|
||||||
getMenuTriggerComponent,
|
getMenuTriggerComponent,
|
||||||
@@ -17,44 +23,47 @@ import "./DropdownMenu.scss";
|
|||||||
const DropdownMenu = ({
|
const DropdownMenu = ({
|
||||||
children,
|
children,
|
||||||
open,
|
open,
|
||||||
placement,
|
|
||||||
}: {
|
}: {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
placement?: "top" | "bottom";
|
|
||||||
}) => {
|
}) => {
|
||||||
const MenuTriggerComp = getMenuTriggerComponent(children);
|
const MenuTriggerComp = getMenuTriggerComponent(children);
|
||||||
const MenuContentComp = getMenuContentComponent(children);
|
const MenuContentComp = getMenuContentComponent(children);
|
||||||
|
const MenuContentWithState =
|
||||||
// clone the MenuContentComp to pass the placement prop
|
|
||||||
const MenuContentCompWithPlacement =
|
|
||||||
MenuContentComp && React.isValidElement(MenuContentComp)
|
MenuContentComp && React.isValidElement(MenuContentComp)
|
||||||
? React.cloneElement(MenuContentComp as React.ReactElement<any>, {
|
? React.cloneElement(
|
||||||
placement,
|
MenuContentComp as React.ReactElement<
|
||||||
})
|
React.ComponentProps<typeof DropdownMenuContent>
|
||||||
|
>,
|
||||||
|
{ open },
|
||||||
|
)
|
||||||
: MenuContentComp;
|
: MenuContentComp;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<DropdownMenuPrimitive.Root open={open} modal={false}>
|
||||||
className="dropdown-menu-container"
|
<div
|
||||||
style={{
|
className={CLASSES.DROPDOWN_MENU_EVENT_WRAPPER}
|
||||||
// remove this div from box layout
|
style={{
|
||||||
display: "contents",
|
// remove this div from box layout
|
||||||
}}
|
display: "contents",
|
||||||
>
|
}}
|
||||||
{MenuTriggerComp}
|
>
|
||||||
{open && MenuContentCompWithPlacement}
|
{MenuTriggerComp}
|
||||||
</div>
|
{MenuContentWithState}
|
||||||
|
</div>
|
||||||
|
</DropdownMenuPrimitive.Root>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
DropdownMenu.Trigger = DropdownMenuTrigger;
|
DropdownMenu.Trigger = DropdownMenuTrigger;
|
||||||
DropdownMenu.Content = DropdownMenuContent;
|
DropdownMenu.Content = DropdownMenuContent;
|
||||||
DropdownMenu.Item = DropdownMenuItem;
|
DropdownMenu.Item = DropdownMenuItem;
|
||||||
|
DropdownMenu.ItemCheckbox = DropdownMenuItemCheckbox;
|
||||||
DropdownMenu.ItemLink = DropdownMenuItemLink;
|
DropdownMenu.ItemLink = DropdownMenuItemLink;
|
||||||
DropdownMenu.ItemCustom = DropdownMenuItemCustom;
|
DropdownMenu.ItemCustom = DropdownMenuItemCustom;
|
||||||
DropdownMenu.Group = DropdownMenuGroup;
|
DropdownMenu.Group = DropdownMenuGroup;
|
||||||
DropdownMenu.Separator = MenuSeparator;
|
DropdownMenu.Separator = MenuSeparator;
|
||||||
|
DropdownMenu.Sub = DropdownMenuSub;
|
||||||
|
|
||||||
export default DropdownMenu;
|
export default DropdownMenu;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import React, { useEffect, useRef } from "react";
|
import React, { useCallback, useEffect, useRef } from "react";
|
||||||
|
|
||||||
import { EVENT, KEYS } from "@excalidraw/common";
|
import { CLASSES, EVENT, KEYS } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import { useOutsideClick } from "../../hooks/useOutsideClick";
|
import { useOutsideClick } from "../../hooks/useOutsideClick";
|
||||||
import { useStable } from "../../hooks/useStable";
|
import { useStable } from "../../hooks/useStable";
|
||||||
@@ -16,8 +18,9 @@ const MenuContent = ({
|
|||||||
onClickOutside,
|
onClickOutside,
|
||||||
className = "",
|
className = "",
|
||||||
onSelect,
|
onSelect,
|
||||||
|
open = true,
|
||||||
|
align = "end",
|
||||||
style,
|
style,
|
||||||
placement = "bottom",
|
|
||||||
}: {
|
}: {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
onClickOutside?: () => void;
|
onClickOutside?: () => void;
|
||||||
@@ -26,26 +29,36 @@ const MenuContent = ({
|
|||||||
* Called when any menu item is selected (clicked on).
|
* Called when any menu item is selected (clicked on).
|
||||||
*/
|
*/
|
||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
|
open?: boolean;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
placement?: "top" | "bottom";
|
align?: "start" | "center" | "end";
|
||||||
}) => {
|
}) => {
|
||||||
const editorInterface = useEditorInterface();
|
const editorInterface = useEditorInterface();
|
||||||
const menuRef = useRef<HTMLDivElement>(null);
|
const menuRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const callbacksRef = useStable({ onClickOutside });
|
const callbacksRef = useStable({ onClickOutside });
|
||||||
|
|
||||||
useOutsideClick(menuRef, (event) => {
|
useOutsideClick(
|
||||||
// prevents closing if clicking on the trigger button
|
menuRef,
|
||||||
if (
|
useCallback(
|
||||||
!menuRef.current
|
(event) => {
|
||||||
?.closest(".dropdown-menu-container")
|
// prevents closing if clicking on the trigger button
|
||||||
?.contains(event.target)
|
if (
|
||||||
) {
|
!menuRef.current
|
||||||
callbacksRef.onClickOutside?.();
|
?.closest(`.${CLASSES.DROPDOWN_MENU_EVENT_WRAPPER}`)
|
||||||
}
|
?.contains(event.target)
|
||||||
});
|
) {
|
||||||
|
callbacksRef.onClickOutside?.();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[callbacksRef],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const onKeyDown = (event: KeyboardEvent) => {
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
if (event.key === KEYS.ESCAPE) {
|
if (event.key === KEYS.ESCAPE) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
@@ -63,35 +76,33 @@ const MenuContent = ({
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener(EVENT.KEYDOWN, onKeyDown, option);
|
document.removeEventListener(EVENT.KEYDOWN, onKeyDown, option);
|
||||||
};
|
};
|
||||||
}, [callbacksRef]);
|
}, [callbacksRef, open]);
|
||||||
|
|
||||||
const classNames = clsx(`dropdown-menu ${className}`, {
|
const classNames = clsx(`dropdown-menu ${className}`, {
|
||||||
"dropdown-menu--mobile": editorInterface.formFactor === "phone",
|
"dropdown-menu--mobile": editorInterface.formFactor === "phone",
|
||||||
"dropdown-menu--placement-top": placement === "top",
|
|
||||||
}).trim();
|
}).trim();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenuContentPropsContext.Provider value={{ onSelect }}>
|
<DropdownMenuContentPropsContext.Provider value={{ onSelect }}>
|
||||||
<div
|
<DropdownMenuPrimitive.Content
|
||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
className={classNames}
|
className={classNames}
|
||||||
style={style}
|
style={style}
|
||||||
data-testid="dropdown-menu"
|
data-testid="dropdown-menu"
|
||||||
|
align={align}
|
||||||
|
sideOffset={8}
|
||||||
|
onCloseAutoFocus={(event: Event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
||||||
{editorInterface.formFactor === "phone" ? (
|
{editorInterface.formFactor === "phone" ? (
|
||||||
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
||||||
) : (
|
) : (
|
||||||
<Island
|
<Island className="dropdown-menu-container" padding={2}>
|
||||||
className="dropdown-menu-container"
|
|
||||||
padding={2}
|
|
||||||
style={{ zIndex: 2 }}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</Island>
|
</Island>
|
||||||
)}
|
)}
|
||||||
</div>
|
</DropdownMenuPrimitive.Content>
|
||||||
</DropdownMenuContentPropsContext.Provider>
|
</DropdownMenuContentPropsContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,78 +1,62 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { THEME } from "@excalidraw/common";
|
import { THEME } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import type { ValueOf } from "@excalidraw/common/utility-types";
|
import type { ValueOf } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import { useExcalidrawAppState } from "../App";
|
import { useExcalidrawAppState } from "../App";
|
||||||
|
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
|
||||||
import {
|
import {
|
||||||
getDropdownMenuItemClassName,
|
getDropdownMenuItemClassName,
|
||||||
useHandleDropdownMenuItemClick,
|
useHandleDropdownMenuItemSelect,
|
||||||
} from "./common";
|
} from "./common";
|
||||||
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||||||
|
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
|
|
||||||
const DropdownMenuItem = ({
|
export type DropdownMenuItemProps = {
|
||||||
icon,
|
|
||||||
value,
|
|
||||||
order,
|
|
||||||
children,
|
|
||||||
shortcut,
|
|
||||||
className,
|
|
||||||
hovered,
|
|
||||||
selected,
|
|
||||||
textStyle,
|
|
||||||
onSelect,
|
|
||||||
onClick,
|
|
||||||
badge,
|
|
||||||
...rest
|
|
||||||
}: {
|
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
|
badge?: React.ReactNode;
|
||||||
value?: string | number | undefined;
|
value?: string | number | undefined;
|
||||||
order?: number;
|
|
||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
hovered?: boolean;
|
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
textStyle?: React.CSSProperties;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
badge?: React.ReactNode;
|
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">;
|
||||||
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
|
||||||
const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect);
|
|
||||||
const ref = useRef<HTMLButtonElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const DropdownMenuItem = ({
|
||||||
if (hovered) {
|
icon,
|
||||||
if (order === 0) {
|
badge,
|
||||||
// scroll into the first item differently, so it's visible what is above (i.e. group title)
|
value,
|
||||||
ref.current?.scrollIntoView({ block: "end" });
|
children,
|
||||||
} else {
|
shortcut,
|
||||||
ref.current?.scrollIntoView({ block: "nearest" });
|
className,
|
||||||
}
|
selected,
|
||||||
}
|
onSelect,
|
||||||
}, [hovered, order]);
|
...rest
|
||||||
|
}: DropdownMenuItemProps) => {
|
||||||
|
const handleSelect = useHandleDropdownMenuItemSelect(onSelect);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<DropdownMenuPrimitive.Item
|
||||||
{...rest}
|
className="radix-menu-item"
|
||||||
ref={ref}
|
onSelect={handleSelect}
|
||||||
value={value}
|
asChild
|
||||||
onClick={handleClick}
|
|
||||||
className={getDropdownMenuItemClassName(className, selected, hovered)}
|
|
||||||
title={rest.title ?? rest["aria-label"]}
|
|
||||||
>
|
>
|
||||||
<MenuItemContent
|
<button
|
||||||
textStyle={textStyle}
|
{...rest}
|
||||||
icon={icon}
|
value={value}
|
||||||
shortcut={shortcut}
|
className={getDropdownMenuItemClassName(className, selected)}
|
||||||
badge={badge}
|
title={rest.title ?? rest["aria-label"]}
|
||||||
>
|
>
|
||||||
{children}
|
<MenuItemContent icon={icon} shortcut={shortcut} badge={badge}>
|
||||||
</MenuItemContent>
|
{children}
|
||||||
</button>
|
</MenuItemContent>
|
||||||
|
</button>
|
||||||
|
</DropdownMenuPrimitive.Item>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
DropdownMenuItem.displayName = "DropdownMenuItem";
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { checkIcon, emptyIcon } from "../icons";
|
||||||
|
|
||||||
|
import DropdownMenuItem from "./DropdownMenuItem";
|
||||||
|
|
||||||
|
import type { DropdownMenuItemProps } from "./DropdownMenuItem";
|
||||||
|
|
||||||
|
const DropdownMenuItemCheckbox = (
|
||||||
|
props: Omit<DropdownMenuItemProps, "icon"> & { checked: boolean },
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuItem {...props} icon={props.checked ? checkIcon : emptyIcon} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DropdownMenuItemCheckbox;
|
||||||
@@ -27,9 +27,7 @@ const DropdownMenuItemContentRadio = <T,>({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="dropdown-menu-item-base dropdown-menu-item-bare">
|
<div className="dropdown-menu-item-base dropdown-menu-item-bare">
|
||||||
<label className="dropdown-menu-item__text" htmlFor={name}>
|
<label className="dropdown-menu-item__text">{children}</label>
|
||||||
{children}
|
|
||||||
</label>
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
name={name}
|
name={name}
|
||||||
value={value}
|
value={value}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||||||
import {
|
import {
|
||||||
getDropdownMenuItemClassName,
|
getDropdownMenuItemClassName,
|
||||||
useHandleDropdownMenuItemClick,
|
useHandleDropdownMenuItemSelect,
|
||||||
} from "./common";
|
} from "./common";
|
||||||
|
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
@@ -28,23 +30,28 @@ const DropdownMenuItemLink = ({
|
|||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
rel?: string;
|
rel?: string;
|
||||||
} & React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
} & React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
||||||
const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
|
const handleSelect = useHandleDropdownMenuItemSelect(onSelect);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<DropdownMenuPrimitive.Item
|
||||||
{...rest}
|
className="radix-menu-item"
|
||||||
href={href}
|
onSelect={handleSelect}
|
||||||
// oxlint-disable-next-line react/jsx-no-target-blank
|
asChild
|
||||||
target="_blank"
|
|
||||||
rel={`noopener ${rel || ""}`}
|
|
||||||
className={getDropdownMenuItemClassName(className, selected)}
|
|
||||||
title={rest.title ?? rest["aria-label"]}
|
|
||||||
onClick={handleClick}
|
|
||||||
>
|
>
|
||||||
<MenuItemContent icon={icon} shortcut={shortcut}>
|
<a
|
||||||
{children}
|
{...rest}
|
||||||
</MenuItemContent>
|
href={href}
|
||||||
</a>
|
// oxlint-disable-next-line react/jsx-no-target-blank
|
||||||
|
target="_blank"
|
||||||
|
rel={`noopener ${rel || ""}`}
|
||||||
|
className={getDropdownMenuItemClassName(className, selected)}
|
||||||
|
title={rest.title ?? rest["aria-label"]}
|
||||||
|
>
|
||||||
|
<MenuItemContent icon={icon} shortcut={shortcut}>
|
||||||
|
{children}
|
||||||
|
</MenuItemContent>
|
||||||
|
</a>
|
||||||
|
</DropdownMenuPrimitive.Item>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const MenuSeparator = () => (
|
|||||||
style={{
|
style={{
|
||||||
height: "1px",
|
height: "1px",
|
||||||
backgroundColor: "var(--default-border-color)",
|
backgroundColor: "var(--default-border-color)",
|
||||||
margin: ".5rem 0",
|
margin: "6px 0",
|
||||||
flex: "0 0 auto",
|
flex: "0 0 auto",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import DropdownMenuSubContent from "./DropdownMenuSubContent";
|
||||||
|
import DropdownMenuSubTrigger from "./DropdownMenuSubTrigger";
|
||||||
|
import {
|
||||||
|
getSubMenuContentComponent,
|
||||||
|
getSubMenuTriggerComponent,
|
||||||
|
} from "./dropdownMenuUtils";
|
||||||
|
|
||||||
|
const DropdownMenuSub = ({ children }: { children?: React.ReactNode }) => {
|
||||||
|
const MenuTriggerComp = getSubMenuTriggerComponent(children);
|
||||||
|
const MenuContentComp = getSubMenuContentComponent(children);
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Sub>
|
||||||
|
{MenuTriggerComp}
|
||||||
|
{MenuContentComp}
|
||||||
|
</DropdownMenuPrimitive.Sub>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
DropdownMenuSub.Trigger = DropdownMenuSubTrigger;
|
||||||
|
DropdownMenuSub.Content = DropdownMenuSubContent;
|
||||||
|
|
||||||
|
DropdownMenuSub.displayName = "DropdownMenuSub";
|
||||||
|
|
||||||
|
export default DropdownMenuSub;
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
|
import { useEditorInterface } from "../App";
|
||||||
|
import { Island } from "../Island";
|
||||||
|
import Stack from "../Stack";
|
||||||
|
|
||||||
|
const BASE_ALIGN_OFFSET = -4;
|
||||||
|
const BASE_SIDE_OFFSET = 4;
|
||||||
|
|
||||||
|
const DropdownMenuSubContent = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}) => {
|
||||||
|
const editorInterface = useEditorInterface();
|
||||||
|
|
||||||
|
const classNames = clsx(`dropdown-menu dropdown-submenu ${className}`, {
|
||||||
|
"dropdown-menu--mobile": editorInterface.formFactor === "phone",
|
||||||
|
}).trim();
|
||||||
|
|
||||||
|
const callbacksRef = useCallback((node: HTMLDivElement | null) => {
|
||||||
|
if (node) {
|
||||||
|
const parentContainer = node.closest(".dropdown-menu-container");
|
||||||
|
const parentRect = parentContainer?.getBoundingClientRect();
|
||||||
|
if (parentRect) {
|
||||||
|
const menuWidth = node.getBoundingClientRect().width;
|
||||||
|
|
||||||
|
const viewportWidth = window.innerWidth;
|
||||||
|
const spaceRemaining = viewportWidth - parentRect.right;
|
||||||
|
if (spaceRemaining < menuWidth + 20) {
|
||||||
|
setSideOffset(spaceRemaining - menuWidth + BASE_ALIGN_OFFSET);
|
||||||
|
setAlignOffset(BASE_ALIGN_OFFSET + 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const [sideOffset, setSideOffset] = useState(BASE_SIDE_OFFSET);
|
||||||
|
const [alignOffset, setAlignOffset] = useState(BASE_ALIGN_OFFSET);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
className={classNames}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
alignOffset={alignOffset}
|
||||||
|
collisionPadding={8}
|
||||||
|
ref={callbacksRef}
|
||||||
|
>
|
||||||
|
{editorInterface.formFactor === "phone" ? (
|
||||||
|
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
||||||
|
) : (
|
||||||
|
<Island
|
||||||
|
className="dropdown-menu-container"
|
||||||
|
padding={2}
|
||||||
|
style={{ zIndex: 1 }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Island>
|
||||||
|
)}
|
||||||
|
</DropdownMenuPrimitive.SubContent>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DropdownMenuSubContent;
|
||||||
|
DropdownMenuSubContent.displayName = "DropdownMenuSubContent";
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import { chevronRight } from "../icons";
|
||||||
|
|
||||||
|
import { getDropdownMenuItemClassName } from "./common";
|
||||||
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||||||
|
|
||||||
|
import type { JSX } from "react";
|
||||||
|
|
||||||
|
const DropdownMenuSubTrigger = ({
|
||||||
|
children,
|
||||||
|
icon,
|
||||||
|
shortcut,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
icon?: JSX.Element;
|
||||||
|
shortcut?: string;
|
||||||
|
className?: string;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
className={`${getDropdownMenuItemClassName(
|
||||||
|
className,
|
||||||
|
)} dropdown-menu__submenu-trigger`}
|
||||||
|
>
|
||||||
|
<MenuItemContent icon={icon} shortcut={shortcut}>
|
||||||
|
{children}
|
||||||
|
</MenuItemContent>
|
||||||
|
<div className="dropdown-menu__submenu-trigger-icon">{chevronRight}</div>
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DropdownMenuSubTrigger;
|
||||||
|
DropdownMenuSubTrigger.displayName = "DropdownMenuSubTrigger";
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import { useEditorInterface } from "../App";
|
import { useEditorInterface } from "../App";
|
||||||
|
|
||||||
const MenuTrigger = ({
|
const MenuTrigger = ({
|
||||||
@@ -23,7 +25,7 @@ const MenuTrigger = ({
|
|||||||
},
|
},
|
||||||
).trim();
|
).trim();
|
||||||
return (
|
return (
|
||||||
<button
|
<DropdownMenuPrimitive.Trigger
|
||||||
className={classNames}
|
className={classNames}
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -32,7 +34,7 @@ const MenuTrigger = ({
|
|||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</DropdownMenuPrimitive.Trigger>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
|
|
||||||
import { EVENT, composeEventHandlers } from "@excalidraw/common";
|
import { composeEventHandlers } from "@excalidraw/common";
|
||||||
|
|
||||||
export const DropdownMenuContentPropsContext = React.createContext<{
|
export const DropdownMenuContentPropsContext = React.createContext<{
|
||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
@@ -11,28 +11,17 @@ export const getDropdownMenuItemClassName = (
|
|||||||
selected = false,
|
selected = false,
|
||||||
hovered = false,
|
hovered = false,
|
||||||
) => {
|
) => {
|
||||||
return `dropdown-menu-item dropdown-menu-item-base ${className}
|
return `dropdown-menu-item dropdown-menu-item-base ${className} ${
|
||||||
${selected ? "dropdown-menu-item--selected" : ""} ${
|
selected ? "dropdown-menu-item--selected" : ""
|
||||||
hovered ? "dropdown-menu-item--hovered" : ""
|
} ${hovered ? "dropdown-menu-item--hovered" : ""}`.trim();
|
||||||
}`.trim();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useHandleDropdownMenuItemClick = (
|
export const useHandleDropdownMenuItemSelect = (
|
||||||
origOnClick:
|
|
||||||
| React.MouseEventHandler<HTMLAnchorElement | HTMLButtonElement>
|
|
||||||
| undefined,
|
|
||||||
onSelect: ((event: Event) => void) | undefined,
|
onSelect: ((event: Event) => void) | undefined,
|
||||||
) => {
|
) => {
|
||||||
const DropdownMenuContentProps = useContext(DropdownMenuContentPropsContext);
|
const DropdownMenuContentProps = useContext(DropdownMenuContentPropsContext);
|
||||||
|
|
||||||
return composeEventHandlers(origOnClick, () => {
|
return composeEventHandlers(onSelect, (event) => {
|
||||||
const itemSelectEvent = new CustomEvent(EVENT.MENU_ITEM_SELECT, {
|
DropdownMenuContentProps.onSelect?.(event);
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
});
|
|
||||||
onSelect?.(itemSelectEvent);
|
|
||||||
if (!itemSelectEvent.defaultPrevented) {
|
|
||||||
DropdownMenuContentProps.onSelect?.(itemSelectEvent);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export const getMenuTriggerComponent = (children: React.ReactNode) => {
|
const getMenuComponent = (component: string) => (children: React.ReactNode) => {
|
||||||
const comp = React.Children.toArray(children).find(
|
const comp = React.Children.toArray(children).find(
|
||||||
(child) =>
|
(child) =>
|
||||||
React.isValidElement(child) &&
|
React.isValidElement(child) &&
|
||||||
@@ -8,7 +8,7 @@ export const getMenuTriggerComponent = (children: React.ReactNode) => {
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
child?.type.displayName &&
|
child?.type.displayName &&
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
child.type.displayName === "DropdownMenuTrigger",
|
child.type.displayName === component,
|
||||||
);
|
);
|
||||||
if (!comp) {
|
if (!comp) {
|
||||||
return null;
|
return null;
|
||||||
@@ -17,19 +17,11 @@ export const getMenuTriggerComponent = (children: React.ReactNode) => {
|
|||||||
return comp;
|
return comp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMenuContentComponent = (children: React.ReactNode) => {
|
export const getMenuTriggerComponent = getMenuComponent("DropdownMenuTrigger");
|
||||||
const comp = React.Children.toArray(children).find(
|
export const getMenuContentComponent = getMenuComponent("DropdownMenuContent");
|
||||||
(child) =>
|
export const getSubMenuTriggerComponent = getMenuComponent(
|
||||||
React.isValidElement(child) &&
|
"DropdownMenuSubTrigger",
|
||||||
typeof child.type !== "string" &&
|
);
|
||||||
//@ts-ignore
|
export const getSubMenuContentComponent = getMenuComponent(
|
||||||
child?.type.displayName &&
|
"DropdownMenuSubContent",
|
||||||
//@ts-ignore
|
);
|
||||||
child.type.displayName === "DropdownMenuContent",
|
|
||||||
);
|
|
||||||
if (!comp) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
//@ts-ignore
|
|
||||||
return comp;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1285,13 +1285,21 @@ export const EdgeRoundIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ArrowheadNoneIcon = createIcon(
|
export const ArrowheadNoneIcon = React.memo(
|
||||||
<g stroke="currentColor" opacity={0.3} strokeWidth={2}>
|
({ flip = false }: { flip?: boolean }) =>
|
||||||
<path d="M12 12l9 0" />
|
createIcon(
|
||||||
<path d="M3 9l6 6" />
|
<g
|
||||||
<path d="M3 15l6 -6" />
|
transform={flip ? "translate(24, 0) scale(-1, 1)" : ""}
|
||||||
</g>,
|
stroke="currentColor"
|
||||||
tablerIconProps,
|
opacity={0.3}
|
||||||
|
strokeWidth={2}
|
||||||
|
>
|
||||||
|
<path d="M12 12l-9 0" />
|
||||||
|
<path d="M21 9l-6 6" />
|
||||||
|
<path d="M21 15l-6 -6" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ArrowheadArrowIcon = React.memo(
|
export const ArrowheadArrowIcon = React.memo(
|
||||||
@@ -2394,3 +2402,32 @@ export const presentationIcon = createIcon(
|
|||||||
</g>,
|
</g>,
|
||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// empty placeholder icon (used for alignment in menus)
|
||||||
|
export const emptyIcon = <div style={{ width: "1rem", height: "1rem" }} />;
|
||||||
|
|
||||||
|
//tabler-icons: chevron-right
|
||||||
|
export const chevronRight = createIcon(
|
||||||
|
<g strokeWidth="1.5">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<polyline points="9 6 15 12 9 18" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
|
// tabler-icons: adjustments-horizontal
|
||||||
|
export const settingsIcon = createIcon(
|
||||||
|
<g strokeWidth={1.25}>
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
||||||
|
<path d="M4 6l8 0" />
|
||||||
|
<path d="M16 6l4 0" />
|
||||||
|
<path d="M8 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
||||||
|
<path d="M4 12l2 0" />
|
||||||
|
<path d="M10 12l10 0" />
|
||||||
|
<path d="M17 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
||||||
|
<path d="M4 18l11 0" />
|
||||||
|
<path d="M19 18l1 0" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|||||||
@@ -9,9 +9,14 @@ import {
|
|||||||
actionLoadScene,
|
actionLoadScene,
|
||||||
actionSaveToActiveFile,
|
actionSaveToActiveFile,
|
||||||
actionShortcuts,
|
actionShortcuts,
|
||||||
|
actionToggleGridMode,
|
||||||
|
actionToggleObjectsSnapMode,
|
||||||
actionToggleSearchMenu,
|
actionToggleSearchMenu,
|
||||||
|
actionToggleStats,
|
||||||
actionToggleTheme,
|
actionToggleTheme,
|
||||||
|
actionToggleZenMode,
|
||||||
} from "../../actions";
|
} from "../../actions";
|
||||||
|
import { actionToggleViewMode } from "../../actions/actionToggleViewMode";
|
||||||
import { getShortcutFromShortcutName } from "../../actions/shortcuts";
|
import { getShortcutFromShortcutName } from "../../actions/shortcuts";
|
||||||
import { trackEvent } from "../../analytics";
|
import { trackEvent } from "../../analytics";
|
||||||
import { useUIAppState } from "../../context/ui-appState";
|
import { useUIAppState } from "../../context/ui-appState";
|
||||||
@@ -23,13 +28,16 @@ import {
|
|||||||
useExcalidrawActionManager,
|
useExcalidrawActionManager,
|
||||||
useExcalidrawElements,
|
useExcalidrawElements,
|
||||||
useAppProps,
|
useAppProps,
|
||||||
|
useApp,
|
||||||
} from "../App";
|
} from "../App";
|
||||||
import { openConfirmModal } from "../OverwriteConfirm/OverwriteConfirmState";
|
import { openConfirmModal } from "../OverwriteConfirm/OverwriteConfirmState";
|
||||||
import Trans from "../Trans";
|
import Trans from "../Trans";
|
||||||
import DropdownMenuItem from "../dropdownMenu/DropdownMenuItem";
|
import DropdownMenuItem from "../dropdownMenu/DropdownMenuItem";
|
||||||
|
import DropdownMenuItemCheckbox from "../dropdownMenu/DropdownMenuItemCheckbox";
|
||||||
import DropdownMenuItemContentRadio from "../dropdownMenu/DropdownMenuItemContentRadio";
|
import DropdownMenuItemContentRadio from "../dropdownMenu/DropdownMenuItemContentRadio";
|
||||||
import DropdownMenuItemLink from "../dropdownMenu/DropdownMenuItemLink";
|
import DropdownMenuItemLink from "../dropdownMenu/DropdownMenuItemLink";
|
||||||
import { GithubIcon, DiscordIcon, XBrandIcon } from "../icons";
|
import DropdownMenuSub from "../dropdownMenu/DropdownMenuSub";
|
||||||
|
import { GithubIcon, DiscordIcon, XBrandIcon, settingsIcon } from "../icons";
|
||||||
import {
|
import {
|
||||||
boltIcon,
|
boltIcon,
|
||||||
DeviceDesktopIcon,
|
DeviceDesktopIcon,
|
||||||
@@ -306,10 +314,14 @@ export const ChangeCanvasBackground = () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div style={{ marginTop: "0.5rem" }}>
|
<div style={{ marginTop: "0.75rem" }}>
|
||||||
<div
|
<div
|
||||||
data-testid="canvas-background-label"
|
data-testid="canvas-background-label"
|
||||||
style={{ fontSize: ".75rem", marginBottom: ".5rem" }}
|
style={{
|
||||||
|
fontSize: "0.875rem",
|
||||||
|
marginBottom: "0.25rem",
|
||||||
|
marginLeft: "0.5rem",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{t("labels.canvasBackground")}
|
{t("labels.canvasBackground")}
|
||||||
</div>
|
</div>
|
||||||
@@ -393,3 +405,152 @@ export const LiveCollaborationTrigger = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
LiveCollaborationTrigger.displayName = "LiveCollaborationTrigger";
|
LiveCollaborationTrigger.displayName = "LiveCollaborationTrigger";
|
||||||
|
|
||||||
|
const PreferencesToggleToolLockItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const app = useApp();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.activeTool.locked}
|
||||||
|
shortcut={getShortcutFromShortcutName("toolLock")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
app.toggleLock();
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("labels.preferences_toolLock")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PreferencesToggleSnapModeItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.objectsSnapModeEnabled}
|
||||||
|
shortcut={getShortcutFromShortcutName("objectsSnapMode")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
actionManager.executeAction(actionToggleObjectsSnapMode);
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("buttons.objectsSnapMode")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PreferencesToggleGridModeItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.gridModeEnabled}
|
||||||
|
shortcut={getShortcutFromShortcutName("gridMode")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
actionManager.executeAction(actionToggleGridMode);
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("labels.toggleGrid")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PreferencesToggleZenModeItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.zenModeEnabled}
|
||||||
|
shortcut={getShortcutFromShortcutName("zenMode")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
actionManager.executeAction(actionToggleZenMode);
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("buttons.zenMode")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PreferencesToggleViewModeItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.viewModeEnabled}
|
||||||
|
shortcut={getShortcutFromShortcutName("viewMode")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
actionManager.executeAction(actionToggleViewMode);
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("labels.viewMode")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PreferencesToggleElementPropertiesItem = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appState = useUIAppState();
|
||||||
|
return (
|
||||||
|
<DropdownMenuItemCheckbox
|
||||||
|
checked={appState.stats.open}
|
||||||
|
shortcut={getShortcutFromShortcutName("stats")}
|
||||||
|
onSelect={(event) => {
|
||||||
|
actionManager.executeAction(actionToggleStats);
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("stats.fullTitle")}
|
||||||
|
</DropdownMenuItemCheckbox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Preferences = ({
|
||||||
|
children,
|
||||||
|
additionalItems,
|
||||||
|
}: {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
additionalItems?: React.ReactNode;
|
||||||
|
}) => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
return (
|
||||||
|
<DropdownMenuSub>
|
||||||
|
<DropdownMenuSub.Trigger icon={settingsIcon}>
|
||||||
|
{t("labels.preferences")}
|
||||||
|
</DropdownMenuSub.Trigger>
|
||||||
|
<DropdownMenuSub.Content className="excalidraw-main-menu-preferences-submenu">
|
||||||
|
{children || (
|
||||||
|
<>
|
||||||
|
<PreferencesToggleToolLockItem />
|
||||||
|
<PreferencesToggleSnapModeItem />
|
||||||
|
<PreferencesToggleGridModeItem />
|
||||||
|
<PreferencesToggleZenModeItem />
|
||||||
|
<PreferencesToggleViewModeItem />
|
||||||
|
<PreferencesToggleElementPropertiesItem />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{additionalItems}
|
||||||
|
</DropdownMenuSub.Content>
|
||||||
|
</DropdownMenuSub>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Preferences.ToggleToolLock = PreferencesToggleToolLockItem;
|
||||||
|
Preferences.ToggleSnapMode = PreferencesToggleSnapModeItem;
|
||||||
|
Preferences.ToggleGridMode = PreferencesToggleGridModeItem;
|
||||||
|
Preferences.ToggleZenMode = PreferencesToggleZenModeItem;
|
||||||
|
Preferences.ToggleViewMode = PreferencesToggleViewModeItem;
|
||||||
|
Preferences.ToggleElementProperties = PreferencesToggleElementPropertiesItem;
|
||||||
|
|
||||||
|
Preferences.displayName = "Preferences";
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { t } from "../../i18n";
|
|||||||
import { useEditorInterface, useExcalidrawSetAppState } from "../App";
|
import { useEditorInterface, useExcalidrawSetAppState } from "../App";
|
||||||
import { UserList } from "../UserList";
|
import { UserList } from "../UserList";
|
||||||
import DropdownMenu from "../dropdownMenu/DropdownMenu";
|
import DropdownMenu from "../dropdownMenu/DropdownMenu";
|
||||||
|
import DropdownMenuSub from "../dropdownMenu/DropdownMenuSub";
|
||||||
import { withInternalFallback } from "../hoc/withInternalFallback";
|
import { withInternalFallback } from "../hoc/withInternalFallback";
|
||||||
import { HamburgerMenuIcon } from "../icons";
|
import { HamburgerMenuIcon } from "../icons";
|
||||||
|
|
||||||
@@ -52,12 +53,8 @@ const MainMenu = Object.assign(
|
|||||||
onSelect={composeEventHandlers(onSelect, () => {
|
onSelect={composeEventHandlers(onSelect, () => {
|
||||||
setAppState({ openMenu: null });
|
setAppState({ openMenu: null });
|
||||||
})}
|
})}
|
||||||
placement="bottom"
|
className="main-menu"
|
||||||
className={
|
align="start"
|
||||||
editorInterface.formFactor === "phone"
|
|
||||||
? "main-menu-dropdown"
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{editorInterface.formFactor === "phone" &&
|
{editorInterface.formFactor === "phone" &&
|
||||||
@@ -84,6 +81,7 @@ const MainMenu = Object.assign(
|
|||||||
ItemCustom: DropdownMenu.ItemCustom,
|
ItemCustom: DropdownMenu.ItemCustom,
|
||||||
Group: DropdownMenu.Group,
|
Group: DropdownMenu.Group,
|
||||||
Separator: DropdownMenu.Separator,
|
Separator: DropdownMenu.Separator,
|
||||||
|
Sub: DropdownMenuSub,
|
||||||
DefaultItems,
|
DefaultItems,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,17 +11,28 @@ import {
|
|||||||
TextIcon,
|
TextIcon,
|
||||||
ImageIcon,
|
ImageIcon,
|
||||||
EraserIcon,
|
EraserIcon,
|
||||||
|
laserPointerToolIcon,
|
||||||
|
handIcon,
|
||||||
} from "./icons";
|
} from "./icons";
|
||||||
|
|
||||||
import type { AppClassProperties } from "../types";
|
import type { AppClassProperties } from "../types";
|
||||||
|
|
||||||
export const SHAPES = [
|
export const SHAPES = [
|
||||||
|
{
|
||||||
|
icon: handIcon,
|
||||||
|
value: "hand",
|
||||||
|
key: KEYS.H,
|
||||||
|
numericKey: null,
|
||||||
|
fillable: false,
|
||||||
|
toolbar: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: SelectionIcon,
|
icon: SelectionIcon,
|
||||||
value: "selection",
|
value: "selection",
|
||||||
key: KEYS.V,
|
key: KEYS.V,
|
||||||
numericKey: KEYS["1"],
|
numericKey: KEYS["1"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: RectangleIcon,
|
icon: RectangleIcon,
|
||||||
@@ -29,6 +40,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.R,
|
key: KEYS.R,
|
||||||
numericKey: KEYS["2"],
|
numericKey: KEYS["2"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: DiamondIcon,
|
icon: DiamondIcon,
|
||||||
@@ -36,6 +48,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.D,
|
key: KEYS.D,
|
||||||
numericKey: KEYS["3"],
|
numericKey: KEYS["3"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: EllipseIcon,
|
icon: EllipseIcon,
|
||||||
@@ -43,6 +56,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.O,
|
key: KEYS.O,
|
||||||
numericKey: KEYS["4"],
|
numericKey: KEYS["4"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: ArrowIcon,
|
icon: ArrowIcon,
|
||||||
@@ -50,6 +64,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.A,
|
key: KEYS.A,
|
||||||
numericKey: KEYS["5"],
|
numericKey: KEYS["5"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: LineIcon,
|
icon: LineIcon,
|
||||||
@@ -57,6 +72,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.L,
|
key: KEYS.L,
|
||||||
numericKey: KEYS["6"],
|
numericKey: KEYS["6"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: FreedrawIcon,
|
icon: FreedrawIcon,
|
||||||
@@ -64,6 +80,7 @@ export const SHAPES = [
|
|||||||
key: [KEYS.P, KEYS.X],
|
key: [KEYS.P, KEYS.X],
|
||||||
numericKey: KEYS["7"],
|
numericKey: KEYS["7"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: TextIcon,
|
icon: TextIcon,
|
||||||
@@ -71,6 +88,7 @@ export const SHAPES = [
|
|||||||
key: KEYS.T,
|
key: KEYS.T,
|
||||||
numericKey: KEYS["8"],
|
numericKey: KEYS["8"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: ImageIcon,
|
icon: ImageIcon,
|
||||||
@@ -78,6 +96,7 @@ export const SHAPES = [
|
|||||||
key: null,
|
key: null,
|
||||||
numericKey: KEYS["9"],
|
numericKey: KEYS["9"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: EraserIcon,
|
icon: EraserIcon,
|
||||||
@@ -85,6 +104,15 @@ export const SHAPES = [
|
|||||||
key: KEYS.E,
|
key: KEYS.E,
|
||||||
numericKey: KEYS["0"],
|
numericKey: KEYS["0"],
|
||||||
fillable: false,
|
fillable: false,
|
||||||
|
toolbar: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: laserPointerToolIcon,
|
||||||
|
value: "laser",
|
||||||
|
key: KEYS.K,
|
||||||
|
numericKey: null,
|
||||||
|
fillable: false,
|
||||||
|
toolbar: false,
|
||||||
},
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
@@ -97,6 +125,7 @@ export const getToolbarTools = (app: AppClassProperties) => {
|
|||||||
key: KEYS.V,
|
key: KEYS.V,
|
||||||
numericKey: KEYS["1"],
|
numericKey: KEYS["1"],
|
||||||
fillable: true,
|
fillable: true,
|
||||||
|
toolbar: true,
|
||||||
},
|
},
|
||||||
...SHAPES.slice(1),
|
...SHAPES.slice(1),
|
||||||
] as const)
|
] as const)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
.welcome-screen-decor-hint {
|
.welcome-screen-decor-hint {
|
||||||
@media (max-height: 599px) {
|
@media (max-height: 780px) {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +148,7 @@
|
|||||||
.welcome-screen-center__heading {
|
.welcome-screen-center__heading {
|
||||||
font-size: 1.125rem;
|
font-size: 1.125rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
line-height: 1.35rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome-screen-menu {
|
.welcome-screen-menu {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
--zIndex-ui-context-menu: 90;
|
--zIndex-ui-context-menu: 90;
|
||||||
--zIndex-ui-styles-popup: 100;
|
--zIndex-ui-styles-popup: 100;
|
||||||
--zIndex-ui-top: 100;
|
--zIndex-ui-top: 100;
|
||||||
|
--zIndex-ui-main-menu: 110;
|
||||||
--zIndex-ui-library: 120;
|
--zIndex-ui-library: 120;
|
||||||
|
|
||||||
--zIndex-modal: 1000;
|
--zIndex-modal: 1000;
|
||||||
@@ -224,6 +225,18 @@ body.excalidraw-cursor-resize * {
|
|||||||
box-shadow: 0 0 0 1px var(--color-brand-hover);
|
box-shadow: 0 0 0 1px var(--color-brand-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// radix doesn't allow differntiating between hover and keyboard active
|
||||||
|
// states (it's forcing :focus on both).
|
||||||
|
//
|
||||||
|
// proper handling would be to disable :focus-visible by default, and enable
|
||||||
|
// on keyboard arrows (it'd then have to be disabled again, e.g. on keydown
|
||||||
|
// or container focus)
|
||||||
|
//
|
||||||
|
// alas, that is left for another day
|
||||||
|
[data-radix-collection-item]:focus-visible {
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
.buttonList {
|
.buttonList {
|
||||||
.ToolIcon__icon {
|
.ToolIcon__icon {
|
||||||
all: unset !important;
|
all: unset !important;
|
||||||
@@ -677,6 +690,9 @@ body.excalidraw-cursor-resize * {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main-menu {
|
||||||
|
z-index: var(--zIndex-ui-main-menu);
|
||||||
|
}
|
||||||
.main-menu-trigger {
|
.main-menu-trigger {
|
||||||
@include filledButtonOnCanvas;
|
@include filledButtonOnCanvas;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,12 @@ import {
|
|||||||
getNormalizedZoom,
|
getNormalizedZoom,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
|
|
||||||
import type { AppState, BinaryFiles, LibraryItem } from "../types";
|
import type {
|
||||||
|
AppState,
|
||||||
|
BinaryFiles,
|
||||||
|
LibraryItem,
|
||||||
|
NormalizedZoomValue,
|
||||||
|
} from "../types";
|
||||||
import type { ImportedDataState, LegacyAppState } from "./types";
|
import type { ImportedDataState, LegacyAppState } from "./types";
|
||||||
|
|
||||||
type RestoredAppState = Omit<
|
type RestoredAppState = Omit<
|
||||||
@@ -150,7 +155,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
|||||||
| ExcalidrawElbowArrowElement["startBinding"]
|
| ExcalidrawElbowArrowElement["startBinding"]
|
||||||
| ExcalidrawElbowArrowElement["endBinding"] = {
|
| ExcalidrawElbowArrowElement["endBinding"] = {
|
||||||
...binding,
|
...binding,
|
||||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint ?? [0, 0]),
|
fixedPoint: normalizeFixedPoint(binding.fixedPoint),
|
||||||
mode: binding.mode || "orbit",
|
mode: binding.mode || "orbit",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,7 +176,7 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
|||||||
return {
|
return {
|
||||||
elementId: binding.elementId,
|
elementId: binding.elementId,
|
||||||
mode: binding.mode,
|
mode: binding.mode,
|
||||||
fixedPoint: normalizeFixedPoint(binding.fixedPoint || [0.5, 0.5]),
|
fixedPoint: normalizeFixedPoint(binding.fixedPoint),
|
||||||
} as FixedPointBinding | null;
|
} as FixedPointBinding | null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -180,15 +185,14 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
|||||||
// binding schema v1 (legacy) -> attempt to migrate to v2
|
// binding schema v1 (legacy) -> attempt to migrate to v2
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const targetBoundElement =
|
const targetBoundElement = targetElementsMap.get(binding.elementId) as
|
||||||
(targetElementsMap.get(binding.elementId) as ExcalidrawBindableElement) ||
|
| ExcalidrawBindableElement
|
||||||
undefined;
|
| undefined;
|
||||||
const boundElement =
|
const boundElement =
|
||||||
targetBoundElement ||
|
targetBoundElement ||
|
||||||
(existingElementsMap?.get(
|
(existingElementsMap?.get(binding.elementId) as
|
||||||
binding.elementId,
|
| ExcalidrawBindableElement
|
||||||
) as ExcalidrawBindableElement) ||
|
| undefined);
|
||||||
undefined;
|
|
||||||
const elementsMap = targetBoundElement
|
const elementsMap = targetBoundElement
|
||||||
? targetElementsMap
|
? targetElementsMap
|
||||||
: existingElementsMap;
|
: existingElementsMap;
|
||||||
@@ -203,18 +207,36 @@ const repairBinding = <T extends ExcalidrawArrowElement>(
|
|||||||
const mode = isPointInElement(p, boundElement, elementsMap)
|
const mode = isPointInElement(p, boundElement, elementsMap)
|
||||||
? "inside"
|
? "inside"
|
||||||
: "orbit";
|
: "orbit";
|
||||||
|
const safeElement = {
|
||||||
|
...element,
|
||||||
|
startBinding: element.startBinding?.elementId
|
||||||
|
? {
|
||||||
|
...element.startBinding,
|
||||||
|
mode,
|
||||||
|
fixedPoint: normalizeFixedPoint(element.startBinding.fixedPoint),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
endBinding: element.endBinding?.elementId
|
||||||
|
? {
|
||||||
|
...element.endBinding,
|
||||||
|
mode,
|
||||||
|
fixedPoint: normalizeFixedPoint(element.endBinding.fixedPoint),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
};
|
||||||
const focusPoint =
|
const focusPoint =
|
||||||
mode === "inside"
|
mode === "inside"
|
||||||
? p
|
? p
|
||||||
: projectFixedPointOntoDiagonal(
|
: projectFixedPointOntoDiagonal(
|
||||||
element,
|
safeElement,
|
||||||
p,
|
p,
|
||||||
boundElement,
|
boundElement,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
{ value: 1 as NormalizedZoomValue },
|
||||||
) || p;
|
) || p;
|
||||||
const { fixedPoint } = calculateFixedPointForNonElbowArrowBinding(
|
const { fixedPoint } = calculateFixedPointForNonElbowArrowBinding(
|
||||||
element,
|
safeElement,
|
||||||
boundElement,
|
boundElement,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
|
|||||||
@@ -317,3 +317,5 @@ export { getDataURL } from "./data/blob";
|
|||||||
export { isElementLink } from "@excalidraw/element";
|
export { isElementLink } from "@excalidraw/element";
|
||||||
|
|
||||||
export { setCustomTextMetricsProvider } from "@excalidraw/element";
|
export { setCustomTextMetricsProvider } from "@excalidraw/element";
|
||||||
|
|
||||||
|
export { CommandPalette } from "./components/CommandPalette/CommandPalette";
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "جميع بياناتك محفوظة محليًا في المتصفح الخاص بك.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "هل تريد الانتقال إلى Excalidraw+ بدلاً من ذلك؟",
|
"center_heading_plus": "هل تريد الانتقال إلى Excalidraw+ بدلاً من ذلك؟",
|
||||||
"menuHint": "التصدير، التفضيلات، اللغات..."
|
"menuHint": "التصدير، التفضيلات، اللغات..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "إدراج",
|
"button": "إدراج",
|
||||||
"description": "حاليًا، يتم دعم <flowchartLink>مخططات التدفق</flowchartLink>، <sequenceLink>التسلسلات</sequenceLink>، و<classLink>الفئات</classLink> فقط. سيتم عرض الأنواع الأخرى كصورة في Excalidraw.",
|
"description": "حاليًا، يتم دعم <flowchartLink>مخططات التدفق</flowchartLink>، <sequenceLink>التسلسلات</sequenceLink>، و<classLink>الفئات</classLink> فقط. سيتم عرض الأنواع الأخرى كصورة في Excalidraw.",
|
||||||
"syntax": "صيغة Mermaid",
|
"syntax": "صيغة Mermaid",
|
||||||
"preview": "معاينة"
|
"preview": "معاينة",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "بحث سريع"
|
"placeholder": "بحث سريع"
|
||||||
|
|||||||
@@ -558,6 +558,8 @@
|
|||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "",
|
"center_heading_plus": "",
|
||||||
"menuHint": ""
|
"menuHint": ""
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "",
|
"button": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "",
|
"syntax": "",
|
||||||
"preview": ""
|
"preview": "",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Всичките Ви данни са запазени локално в браузъра Ви.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "",
|
"center_heading_plus": "",
|
||||||
"menuHint": "Експорт, предпочитания, езици, ..."
|
"menuHint": "Експорт, предпочитания, езици, ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Вмъкни",
|
"button": "Вмъкни",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "Mermaid Синтаксис",
|
"syntax": "Mermaid Синтаксис",
|
||||||
"preview": "Преглед"
|
"preview": "Преглед",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -558,6 +558,8 @@
|
|||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "",
|
"center_heading_plus": "",
|
||||||
"menuHint": ""
|
"menuHint": ""
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "",
|
"button": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "",
|
"syntax": "",
|
||||||
"preview": ""
|
"preview": "",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -558,6 +558,8 @@
|
|||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "",
|
"center_heading_plus": "",
|
||||||
"menuHint": ""
|
"menuHint": ""
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "",
|
"button": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "",
|
"syntax": "",
|
||||||
"preview": ""
|
"preview": "",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Totes les vostres dades es guarden localment al vostre navegador.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Vols anar a Excalidraw+ en comptes?",
|
"center_heading_plus": "Vols anar a Excalidraw+ en comptes?",
|
||||||
"menuHint": "Exportar, preferències, llenguatges..."
|
"menuHint": "Exportar, preferències, llenguatges..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Inseriu",
|
"button": "Inseriu",
|
||||||
"description": "Actualment només s'admeten els diagrames <flowchartLink>Flowchart</flowchartLink>, <sequenceLink> Sequence, </sequenceLink> i <classLink> Class </classLink>. Els altres tipus es representaran com a imatge a Excalidraw.",
|
"description": "Actualment només s'admeten els diagrames <flowchartLink>Flowchart</flowchartLink>, <sequenceLink> Sequence, </sequenceLink> i <classLink> Class </classLink>. Els altres tipus es representaran com a imatge a Excalidraw.",
|
||||||
"syntax": "Sintaxi de Mermaid",
|
"syntax": "Sintaxi de Mermaid",
|
||||||
"preview": "Previsualització"
|
"preview": "Previsualització",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Cerca ràpida"
|
"placeholder": "Cerca ràpida"
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Všechna vaše data jsou uložena lokálně ve vašem prohlížeči.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Chcete místo toho přejít na Excalidraw+?",
|
"center_heading_plus": "Chcete místo toho přejít na Excalidraw+?",
|
||||||
"menuHint": "Export, nastavení, jazyky, ..."
|
"menuHint": "Export, nastavení, jazyky, ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Vložit",
|
"button": "Vložit",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "Mermaid syntaxe",
|
"syntax": "Mermaid syntaxe",
|
||||||
"preview": "Náhled"
|
"preview": "Náhled",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Rychlé vyhledávání"
|
"placeholder": "Rychlé vyhledávání"
|
||||||
|
|||||||
@@ -558,6 +558,8 @@
|
|||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "",
|
"center_heading_plus": "",
|
||||||
"menuHint": ""
|
"menuHint": ""
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "",
|
"button": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"syntax": "",
|
"syntax": "",
|
||||||
"preview": ""
|
"preview": "",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -196,7 +196,7 @@
|
|||||||
"multipleResults": "Ergebnisse",
|
"multipleResults": "Ergebnisse",
|
||||||
"placeholder": "Text auf Zeichenfläche suchen...",
|
"placeholder": "Text auf Zeichenfläche suchen...",
|
||||||
"frames": "",
|
"frames": "",
|
||||||
"texts": ""
|
"texts": "Texte"
|
||||||
},
|
},
|
||||||
"buttons": {
|
"buttons": {
|
||||||
"clearReset": "Zeichenfläche löschen & Hintergrundfarbe zurücksetzen",
|
"clearReset": "Zeichenfläche löschen & Hintergrundfarbe zurücksetzen",
|
||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Alle Daten werden lokal in Deinem Browser gespeichert.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Möchtest du stattdessen zu Excalidraw+ gehen?",
|
"center_heading_plus": "Möchtest du stattdessen zu Excalidraw+ gehen?",
|
||||||
"menuHint": "Exportieren, Einstellungen, Sprachen, ..."
|
"menuHint": "Exportieren, Einstellungen, Sprachen, ..."
|
||||||
},
|
},
|
||||||
@@ -569,7 +571,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"colorPicker": {
|
"colorPicker": {
|
||||||
"color": "",
|
"color": "Farbe",
|
||||||
"mostUsedCustomColors": "Beliebteste benutzerdefinierte Farben",
|
"mostUsedCustomColors": "Beliebteste benutzerdefinierte Farben",
|
||||||
"colors": "Farben",
|
"colors": "Farben",
|
||||||
"shades": "Schattierungen",
|
"shades": "Schattierungen",
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Einfügen",
|
"button": "Einfügen",
|
||||||
"description": "Derzeit werden nur <flowchartLink>Flussdiagramme</flowchartLink>, <sequenceLink>Sequenzdiagramme</sequenceLink> und <classLink>Klassendiagramme</classLink> unterstützt. Die anderen Typen werden als Bild in Excalidraw dargestellt.",
|
"description": "Derzeit werden nur <flowchartLink>Flussdiagramme</flowchartLink>, <sequenceLink>Sequenzdiagramme</sequenceLink> und <classLink>Klassendiagramme</classLink> unterstützt. Die anderen Typen werden als Bild in Excalidraw dargestellt.",
|
||||||
"syntax": "Mermaid-Syntax",
|
"syntax": "Mermaid-Syntax",
|
||||||
"preview": "Vorschau"
|
"preview": "Vorschau",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Schnellsuche"
|
"placeholder": "Schnellsuche"
|
||||||
@@ -651,15 +701,15 @@
|
|||||||
"shortcutHint": "Benutze {{shortcut}} für Befehlspalette"
|
"shortcutHint": "Benutze {{shortcut}} für Befehlspalette"
|
||||||
},
|
},
|
||||||
"keys": {
|
"keys": {
|
||||||
"ctrl": "",
|
"ctrl": "Strg",
|
||||||
"option": "",
|
"option": "",
|
||||||
"cmd": "",
|
"cmd": "",
|
||||||
"alt": "",
|
"alt": "",
|
||||||
"escape": "",
|
"escape": "",
|
||||||
"enter": "",
|
"enter": "",
|
||||||
"shift": "",
|
"shift": "",
|
||||||
"spacebar": "",
|
"spacebar": "Leertaste",
|
||||||
"delete": "",
|
"delete": "Löschen",
|
||||||
"mmb": ""
|
"mmb": "Mausrad"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Alle Daten werden lokal in Deinem Browser gespeichert.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Möchtest du stattdessen zu Excalidraw+ gehen?",
|
"center_heading_plus": "Möchtest du stattdessen zu Excalidraw+ gehen?",
|
||||||
"menuHint": "Exportieren, Einstellungen, Sprachen, ..."
|
"menuHint": "Exportieren, Einstellungen, Sprachen, ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Einfügen",
|
"button": "Einfügen",
|
||||||
"description": "Derzeit werden nur <flowchartLink>Flussdiagramme</flowchartLink>, <sequenceLink>Sequenzdiagramme</sequenceLink> und <classLink>Klassendiagramme</classLink> unterstützt. Die anderen Typen werden als Bild in Excalidraw dargestellt.",
|
"description": "Derzeit werden nur <flowchartLink>Flussdiagramme</flowchartLink>, <sequenceLink>Sequenzdiagramme</sequenceLink> und <classLink>Klassendiagramme</classLink> unterstützt. Die anderen Typen werden als Bild in Excalidraw dargestellt.",
|
||||||
"syntax": "Mermaid-Syntax",
|
"syntax": "Mermaid-Syntax",
|
||||||
"preview": "Vorschau"
|
"preview": "Vorschau",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Schnellsuche"
|
"placeholder": "Schnellsuche"
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Όλα τα δεδομένα σας αποθηκεύονται τοπικά στο πρόγραμμα περιήγησης.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Μήπως θέλατε να πάτε στο Excalidraw+;",
|
"center_heading_plus": "Μήπως θέλατε να πάτε στο Excalidraw+;",
|
||||||
"menuHint": "Εξαγωγή, προτιμήσεις, γλώσσες, ..."
|
"menuHint": "Εξαγωγή, προτιμήσεις, γλώσσες, ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Εισαγωγή",
|
"button": "Εισαγωγή",
|
||||||
"description": "Επί του παρόντος υποστηρίζονται μόνο Διαγράμματα <flowchartLink>Ροής</flowchartLink>,<sequenceLink> Ακολουθίας, </sequenceLink> και <classLink>Κλάσεων</classLink>. Οι άλλοι τύποι θα αποδοθούν ως εικόνα στο Excalidraw.",
|
"description": "Επί του παρόντος υποστηρίζονται μόνο Διαγράμματα <flowchartLink>Ροής</flowchartLink>,<sequenceLink> Ακολουθίας, </sequenceLink> και <classLink>Κλάσεων</classLink>. Οι άλλοι τύποι θα αποδοθούν ως εικόνα στο Excalidraw.",
|
||||||
"syntax": "Σύνταξη Mermaid",
|
"syntax": "Σύνταξη Mermaid",
|
||||||
"preview": "Προεπισκόπηση"
|
"preview": "Προεπισκόπηση",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Γρήγορη αναζήτηση"
|
"placeholder": "Γρήγορη αναζήτηση"
|
||||||
|
|||||||
@@ -171,7 +171,9 @@
|
|||||||
"linkToElement": "Link to object",
|
"linkToElement": "Link to object",
|
||||||
"wrapSelectionInFrame": "Wrap selection in frame",
|
"wrapSelectionInFrame": "Wrap selection in frame",
|
||||||
"tab": "Tab",
|
"tab": "Tab",
|
||||||
"shapeSwitch": "Switch shape"
|
"shapeSwitch": "Switch shape",
|
||||||
|
"preferences": "Preferences",
|
||||||
|
"preferences_toolLock": "Tool lock"
|
||||||
},
|
},
|
||||||
"elementLink": {
|
"elementLink": {
|
||||||
"title": "Link to object",
|
"title": "Link to object",
|
||||||
@@ -557,7 +559,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "All your data is saved locally in your browser.",
|
"center_heading": "Your drawings are saved in your browser's storage.",
|
||||||
|
"center_heading_line2": "Browser storage can be cleared unexpectedly.",
|
||||||
|
"center_heading_line3": "Save your work to a file regularly to avoid losing it.",
|
||||||
"center_heading_plus": "Did you want to go to the Excalidraw+ instead?",
|
"center_heading_plus": "Did you want to go to the Excalidraw+ instead?",
|
||||||
"menuHint": "Export, preferences, languages, ..."
|
"menuHint": "Export, preferences, languages, ..."
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Toda su información es guardada localmente en su navegador.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "¿Quieres ir a Excalidraw+?",
|
"center_heading_plus": "¿Quieres ir a Excalidraw+?",
|
||||||
"menuHint": "Exportar, preferencias, idiomas, ..."
|
"menuHint": "Exportar, preferencias, idiomas, ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Insertar",
|
"button": "Insertar",
|
||||||
"description": "Actualmente sólo estos tipos de <flowchartLink>diagrama de flujo</flowchartLink>,<sequenceLink> Secuencia, </sequenceLink> y <classLink>Clase </classLink> son soportados. Los otros tipos de diagramas se renderizarán como imagen en Excalidraw.",
|
"description": "Actualmente sólo estos tipos de <flowchartLink>diagrama de flujo</flowchartLink>,<sequenceLink> Secuencia, </sequenceLink> y <classLink>Clase </classLink> son soportados. Los otros tipos de diagramas se renderizarán como imagen en Excalidraw.",
|
||||||
"syntax": "Sintaxis Mermaid",
|
"syntax": "Sintaxis Mermaid",
|
||||||
"preview": "Vista previa"
|
"preview": "Vista previa",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "Búsqueda rápida"
|
"placeholder": "Búsqueda rápida"
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "Zure datu guztiak lokalean gordetzen dira zure nabigatzailean.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "Horren ordez Excalidraw+-era joan nahi al zenuen?",
|
"center_heading_plus": "Horren ordez Excalidraw+-era joan nahi al zenuen?",
|
||||||
"menuHint": "Esportatu, hobespenak, hizkuntzak..."
|
"menuHint": "Esportatu, hobespenak, hizkuntzak..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "Txertatu",
|
"button": "Txertatu",
|
||||||
"description": "Momentu honetan <flowchartLink>Flowchart</flowchartLink>, <sequenceLink> Sequence, </sequenceLink> eta <classLink>Class </classLink>Diagramak onartzen dira. Beste motak irudi gisa errendatuko dira Excalidrawn.",
|
"description": "Momentu honetan <flowchartLink>Flowchart</flowchartLink>, <sequenceLink> Sequence, </sequenceLink> eta <classLink>Class </classLink>Diagramak onartzen dira. Beste motak irudi gisa errendatuko dira Excalidrawn.",
|
||||||
"syntax": "Mermaid sintaxia",
|
"syntax": "Mermaid sintaxia",
|
||||||
"preview": "Aurrebista"
|
"preview": "Aurrebista",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": ""
|
"placeholder": ""
|
||||||
|
|||||||
@@ -557,7 +557,9 @@
|
|||||||
},
|
},
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"app": {
|
"app": {
|
||||||
"center_heading": "تمام داده های شما به صورت محلی در مرورگر شما ذخیره می شود.",
|
"center_heading": "",
|
||||||
|
"center_heading_line2": "",
|
||||||
|
"center_heading_line3": "",
|
||||||
"center_heading_plus": "آیا میخواهید به جای آن به Excalidraw+ بروید؟",
|
"center_heading_plus": "آیا میخواهید به جای آن به Excalidraw+ بروید؟",
|
||||||
"menuHint": "خروجی، ترجیحات، زبان ها، ..."
|
"menuHint": "خروجی، ترجیحات، زبان ها، ..."
|
||||||
},
|
},
|
||||||
@@ -612,7 +614,55 @@
|
|||||||
"button": "درج",
|
"button": "درج",
|
||||||
"description": "فعلا فقط <flowchartLink> فلوچارت </flowchartLink> ، <sequenceLink> توالی </sequenceLink> و <classLink> کلاس </classLink> نمودارها پشتیبانی می شوند. انواع دیگر به صورت تصویر در Excalidraw ارائه خواهند شد.",
|
"description": "فعلا فقط <flowchartLink> فلوچارت </flowchartLink> ، <sequenceLink> توالی </sequenceLink> و <classLink> کلاس </classLink> نمودارها پشتیبانی می شوند. انواع دیگر به صورت تصویر در Excalidraw ارائه خواهند شد.",
|
||||||
"syntax": "مرمید syntax",
|
"syntax": "مرمید syntax",
|
||||||
"preview": "پیشنمایش"
|
"preview": "پیشنمایش",
|
||||||
|
"label": "",
|
||||||
|
"inputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"ttd": {
|
||||||
|
"error": ""
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"inputPlaceholder": "",
|
||||||
|
"inputPlaceholderWithMessages": "",
|
||||||
|
"generating": "",
|
||||||
|
"rateLimitRemaining": "",
|
||||||
|
"role": {
|
||||||
|
"user": "",
|
||||||
|
"assistant": "",
|
||||||
|
"system": ""
|
||||||
|
},
|
||||||
|
"aiBeta": "",
|
||||||
|
"label": "",
|
||||||
|
"menu": "",
|
||||||
|
"newChat": "",
|
||||||
|
"deleteChat": "",
|
||||||
|
"deleteMessage": "",
|
||||||
|
"viewAsMermaid": "",
|
||||||
|
"placeholder": {
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"hint": ""
|
||||||
|
},
|
||||||
|
"preview": "",
|
||||||
|
"insert": "",
|
||||||
|
"retry": "",
|
||||||
|
"errors": {
|
||||||
|
"promptTooShort": "",
|
||||||
|
"promptTooLong": "",
|
||||||
|
"generationFailed": "",
|
||||||
|
"invalidDiagram": "",
|
||||||
|
"fixInMermaid": "",
|
||||||
|
"aiRepair": "",
|
||||||
|
"requestAborted": "",
|
||||||
|
"requestFailed": "",
|
||||||
|
"mermaidParseError": ""
|
||||||
|
},
|
||||||
|
"rateLimit": {
|
||||||
|
"messageLimit": "",
|
||||||
|
"generalRateLimit": "",
|
||||||
|
"messageLimitInputPlaceholder": ""
|
||||||
|
},
|
||||||
|
"upsellBtnLabel": ""
|
||||||
},
|
},
|
||||||
"quickSearch": {
|
"quickSearch": {
|
||||||
"placeholder": "جستجو فوری"
|
"placeholder": "جستجو فوری"
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user