2020-03-17 20:55:40 +01:00
|
|
|
import {
|
|
|
|
PointerType,
|
|
|
|
ExcalidrawLinearElement,
|
2020-04-08 09:49:52 -07:00
|
|
|
NonDeletedExcalidrawElement,
|
|
|
|
NonDeleted,
|
2020-04-08 21:00:27 +01:00
|
|
|
TextAlign,
|
2020-05-14 17:04:33 +02:00
|
|
|
ExcalidrawElement,
|
2020-05-27 15:14:50 +02:00
|
|
|
FontFamily,
|
2020-05-26 13:07:46 -07:00
|
|
|
GroupId,
|
2020-08-08 21:04:15 -07:00
|
|
|
ExcalidrawBindableElement,
|
2020-12-08 15:02:55 +00:00
|
|
|
Arrowhead,
|
2020-12-27 18:26:30 +02:00
|
|
|
ChartType,
|
2020-03-17 20:55:40 +01:00
|
|
|
} from "./element/types";
|
2020-02-07 18:42:24 +01:00
|
|
|
import { SHAPES } from "./shapes";
|
2020-03-14 21:48:51 -07:00
|
|
|
import { Point as RoughPoint } from "roughjs/bin/geometry";
|
2020-06-01 11:35:44 +02:00
|
|
|
import { LinearElementEditor } from "./element/linearElementEditor";
|
2020-08-08 21:04:15 -07:00
|
|
|
import { SuggestedBinding } from "./element/binding";
|
2020-09-22 21:51:49 +02:00
|
|
|
import { ImportedDataState } from "./data/types";
|
2020-10-11 21:41:26 +05:30
|
|
|
import { ExcalidrawImperativeAPI } from "./components/App";
|
2020-12-05 20:00:53 +05:30
|
|
|
import type { ResolvablePromise } from "./utils";
|
2020-12-27 18:26:30 +02:00
|
|
|
import { Spreadsheet } from "./charts";
|
2021-01-04 02:21:52 +05:30
|
|
|
import { Language } from "./i18n";
|
2020-01-06 20:24:54 +04:00
|
|
|
|
2020-02-19 08:25:01 -08:00
|
|
|
export type FlooredNumber = number & { _brand: "FlooredNumber" };
|
2020-03-14 21:48:51 -07:00
|
|
|
export type Point = Readonly<RoughPoint>;
|
2020-02-19 08:25:01 -08:00
|
|
|
|
2020-06-19 11:36:49 +01:00
|
|
|
export type Collaborator = {
|
|
|
|
pointer?: {
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
};
|
|
|
|
button?: "up" | "down";
|
|
|
|
selectedElementIds?: AppState["selectedElementIds"];
|
|
|
|
username?: string | null;
|
|
|
|
};
|
|
|
|
|
2020-01-06 20:24:54 +04:00
|
|
|
export type AppState = {
|
2020-03-26 18:28:26 +01:00
|
|
|
isLoading: boolean;
|
2020-04-03 12:50:51 +01:00
|
|
|
errorMessage: string | null;
|
2020-04-08 09:49:52 -07:00
|
|
|
draggingElement: NonDeletedExcalidrawElement | null;
|
|
|
|
resizingElement: NonDeletedExcalidrawElement | null;
|
|
|
|
multiElement: NonDeleted<ExcalidrawLinearElement> | null;
|
|
|
|
selectionElement: NonDeletedExcalidrawElement | null;
|
2020-08-08 21:04:15 -07:00
|
|
|
isBindingEnabled: boolean;
|
|
|
|
startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
|
|
|
|
suggestedBindings: SuggestedBinding[];
|
2020-01-19 23:32:24 +01:00
|
|
|
// element being edited, but not necessarily added to elements array yet
|
2020-11-05 19:06:18 +02:00
|
|
|
// (e.g. text element when typing into the input)
|
2020-04-08 09:49:52 -07:00
|
|
|
editingElement: NonDeletedExcalidrawElement | null;
|
2020-06-01 11:35:44 +02:00
|
|
|
editingLinearElement: LinearElementEditor | null;
|
2020-02-07 18:42:24 +01:00
|
|
|
elementType: typeof SHAPES[number]["value"];
|
2020-01-20 15:52:19 -08:00
|
|
|
elementLocked: boolean;
|
2020-01-06 20:24:54 +04:00
|
|
|
exportBackground: boolean;
|
2020-10-13 14:47:07 +02:00
|
|
|
exportEmbedScene: boolean;
|
2020-04-19 20:50:23 +01:00
|
|
|
shouldAddWatermark: boolean;
|
2020-01-06 20:24:54 +04:00
|
|
|
currentItemStrokeColor: string;
|
|
|
|
currentItemBackgroundColor: string;
|
2020-12-11 13:13:23 +02:00
|
|
|
currentItemFillStyle: ExcalidrawElement["fillStyle"];
|
2020-01-25 18:58:57 +01:00
|
|
|
currentItemStrokeWidth: number;
|
2020-05-14 17:04:33 +02:00
|
|
|
currentItemStrokeStyle: ExcalidrawElement["strokeStyle"];
|
2020-01-25 18:58:57 +01:00
|
|
|
currentItemRoughness: number;
|
|
|
|
currentItemOpacity: number;
|
2020-05-27 15:14:50 +02:00
|
|
|
currentItemFontFamily: FontFamily;
|
|
|
|
currentItemFontSize: number;
|
2020-04-08 21:00:27 +01:00
|
|
|
currentItemTextAlign: TextAlign;
|
2020-08-15 00:59:43 +09:00
|
|
|
currentItemStrokeSharpness: ExcalidrawElement["strokeSharpness"];
|
2020-12-12 16:42:30 +00:00
|
|
|
currentItemStartArrowhead: Arrowhead | null;
|
|
|
|
currentItemEndArrowhead: Arrowhead | null;
|
2020-08-15 00:59:43 +09:00
|
|
|
currentItemLinearStrokeSharpness: ExcalidrawElement["strokeSharpness"];
|
2020-01-06 20:24:54 +04:00
|
|
|
viewBackgroundColor: string;
|
2020-02-19 08:25:01 -08:00
|
|
|
scrollX: FlooredNumber;
|
|
|
|
scrollY: FlooredNumber;
|
2020-04-04 16:12:19 +01:00
|
|
|
cursorButton: "up" | "down";
|
2020-02-01 16:52:10 +00:00
|
|
|
scrolledOutside: boolean;
|
2020-12-01 14:00:13 +01:00
|
|
|
name: string;
|
2020-02-03 21:52:21 +04:00
|
|
|
isResizing: boolean;
|
2020-04-02 17:40:26 +09:00
|
|
|
isRotating: boolean;
|
2020-11-04 17:49:15 +00:00
|
|
|
zoom: Zoom;
|
2020-03-01 14:39:03 -05:00
|
|
|
openMenu: "canvas" | "shape" | null;
|
2020-02-21 14:34:18 -05:00
|
|
|
lastPointerDownWith: PointerType;
|
2020-03-08 10:20:55 -07:00
|
|
|
selectedElementIds: { [id: string]: boolean };
|
2020-06-02 18:41:40 +02:00
|
|
|
previousSelectedElementIds: { [id: string]: boolean };
|
2020-03-28 16:59:36 -07:00
|
|
|
shouldCacheIgnoreZoom: boolean;
|
2021-01-17 17:46:23 +01:00
|
|
|
showHelpDialog: boolean;
|
2021-01-15 20:32:46 +05:30
|
|
|
toastMessage: string | null;
|
2020-04-25 18:43:02 +05:30
|
|
|
zenModeEnabled: boolean;
|
2020-08-13 04:35:31 -07:00
|
|
|
appearance: "light" | "dark";
|
2020-06-24 00:24:52 +09:00
|
|
|
gridSize: number | null;
|
2020-05-26 13:07:46 -07:00
|
|
|
|
2020-05-30 22:48:57 +02:00
|
|
|
/** top-most selected groups (i.e. does not include nested groups) */
|
2020-05-26 13:07:46 -07:00
|
|
|
selectedGroupIds: { [groupId: string]: boolean };
|
2020-05-30 22:48:57 +02:00
|
|
|
/** group being edited when you drill down to its constituent element
|
|
|
|
(e.g. when you double-click on a group's element) */
|
2020-05-26 13:07:46 -07:00
|
|
|
editingGroupId: GroupId | null;
|
2020-07-07 20:40:39 +05:30
|
|
|
width: number;
|
|
|
|
height: number;
|
2020-07-27 17:18:49 +05:30
|
|
|
offsetTop: number;
|
|
|
|
offsetLeft: number;
|
2020-07-10 02:20:23 -07:00
|
|
|
|
|
|
|
isLibraryOpen: boolean;
|
2020-10-19 10:53:37 +02:00
|
|
|
fileHandle: import("browser-nativefs").FileSystemHandle | null;
|
2020-12-05 20:00:53 +05:30
|
|
|
collaborators: Map<string, Collaborator>;
|
2020-12-07 18:35:16 +02:00
|
|
|
showStats: boolean;
|
2020-12-27 18:26:30 +02:00
|
|
|
currentChartType: ChartType;
|
|
|
|
pasteDialog:
|
|
|
|
| {
|
|
|
|
shown: false;
|
|
|
|
data: null;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
shown: true;
|
|
|
|
data: Spreadsheet;
|
|
|
|
};
|
2020-01-06 20:24:54 +04:00
|
|
|
};
|
2020-02-21 08:17:20 -05:00
|
|
|
|
2020-11-04 17:49:15 +00:00
|
|
|
export type NormalizedZoomValue = number & { _brand: "normalizedZoom" };
|
|
|
|
|
|
|
|
export type Zoom = Readonly<{
|
|
|
|
value: NormalizedZoomValue;
|
|
|
|
translation: Readonly<{
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}>;
|
|
|
|
}>;
|
|
|
|
|
2020-03-08 19:25:16 -07:00
|
|
|
export type PointerCoords = Readonly<{
|
2020-02-21 08:17:20 -05:00
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export type Gesture = {
|
2020-03-08 19:25:16 -07:00
|
|
|
pointers: Map<number, PointerCoords>;
|
2020-02-21 08:17:20 -05:00
|
|
|
lastCenter: { x: number; y: number } | null;
|
|
|
|
initialDistance: number | null;
|
|
|
|
initialScale: number | null;
|
|
|
|
};
|
2020-03-01 14:39:03 -05:00
|
|
|
|
|
|
|
export declare class GestureEvent extends UIEvent {
|
|
|
|
readonly rotation: number;
|
|
|
|
readonly scale: number;
|
|
|
|
}
|
2020-04-12 16:24:52 +05:30
|
|
|
|
2020-11-08 17:08:22 +01:00
|
|
|
export type LibraryItem = readonly NonDeleted<ExcalidrawElement>[];
|
2020-07-27 15:29:19 +03:00
|
|
|
export type LibraryItems = readonly LibraryItem[];
|
2020-07-11 18:43:20 +05:30
|
|
|
|
2020-12-09 01:35:08 +05:30
|
|
|
// NOTE ready/readyPromise props are optional for host apps' sake (our own
|
|
|
|
// implem guarantees existence)
|
2020-12-05 20:00:53 +05:30
|
|
|
export type ExcalidrawAPIRefValue =
|
2021-01-25 10:47:35 +01:00
|
|
|
| ExcalidrawImperativeAPI
|
2020-12-05 20:00:53 +05:30
|
|
|
| {
|
2020-12-09 01:35:08 +05:30
|
|
|
readyPromise?: ResolvablePromise<ExcalidrawImperativeAPI>;
|
|
|
|
ready?: false;
|
2020-12-05 20:00:53 +05:30
|
|
|
};
|
|
|
|
|
2020-07-11 18:43:20 +05:30
|
|
|
export interface ExcalidrawProps {
|
2020-12-05 20:00:53 +05:30
|
|
|
width?: number;
|
|
|
|
height?: number;
|
2020-10-23 19:06:16 +02:00
|
|
|
/** if not supplied, calculated by Excalidraw */
|
|
|
|
offsetLeft?: number;
|
|
|
|
/** if not supplied, calculated by Excalidraw */
|
|
|
|
offsetTop?: number;
|
2020-08-20 16:45:20 +02:00
|
|
|
onChange?: (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: AppState,
|
|
|
|
) => void;
|
2020-12-05 20:00:53 +05:30
|
|
|
initialData?: ImportedDataState | null | Promise<ImportedDataState | null>;
|
2020-08-20 16:45:20 +02:00
|
|
|
user?: {
|
|
|
|
name?: string | null;
|
|
|
|
};
|
2020-12-05 20:00:53 +05:30
|
|
|
excalidrawRef?: ForwardRef<ExcalidrawAPIRefValue>;
|
|
|
|
onCollabButtonClick?: () => void;
|
|
|
|
isCollaborating?: boolean;
|
|
|
|
onPointerUpdate?: (payload: {
|
|
|
|
pointer: { x: number; y: number };
|
|
|
|
button: "down" | "up";
|
|
|
|
pointersMap: Gesture["pointers"];
|
|
|
|
}) => void;
|
2020-12-20 19:44:04 +05:30
|
|
|
onExportToBackend?: (
|
|
|
|
exportedElements: readonly NonDeletedExcalidrawElement[],
|
|
|
|
appState: AppState,
|
|
|
|
canvas: HTMLCanvasElement | null,
|
|
|
|
) => void;
|
2021-01-04 02:21:52 +05:30
|
|
|
renderFooter?: (isMobile: boolean) => JSX.Element;
|
|
|
|
langCode?: Language["code"];
|
2020-07-11 18:43:20 +05:30
|
|
|
}
|
2020-12-05 20:00:53 +05:30
|
|
|
|
|
|
|
export type SceneData = {
|
|
|
|
elements?: ImportedDataState["elements"];
|
|
|
|
appState?: ImportedDataState["appState"];
|
|
|
|
collaborators?: Map<string, Collaborator>;
|
|
|
|
commitToHistory?: boolean;
|
|
|
|
};
|