|
@@ -111,7 +111,6 @@ import {
|
111
|
111
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
112
|
112
|
import { mutateElement } from "../element/mutateElement";
|
113
|
113
|
import { deepCopyElement, newFreeDrawElement } from "../element/newElement";
|
114
|
|
-import { MaybeTransformHandleType } from "../element/transformHandles";
|
115
|
114
|
import {
|
116
|
115
|
isBindingElement,
|
117
|
116
|
isBindingElementType,
|
|
@@ -167,9 +166,11 @@ import { findShapeByKey } from "../shapes";
|
167
|
166
|
import {
|
168
|
167
|
AppProps,
|
169
|
168
|
AppState,
|
|
169
|
+ ExcalidrawImperativeAPI,
|
170
|
170
|
Gesture,
|
171
|
171
|
GestureEvent,
|
172
|
172
|
LibraryItems,
|
|
173
|
+ PointerDownState,
|
173
|
174
|
SceneData,
|
174
|
175
|
} from "../types";
|
175
|
176
|
import {
|
|
@@ -180,7 +181,6 @@ import {
|
180
|
181
|
isToolIcon,
|
181
|
182
|
isWritableElement,
|
182
|
183
|
resetCursor,
|
183
|
|
- ResolvablePromise,
|
184
|
184
|
resolvablePromise,
|
185
|
185
|
sceneCoordsToViewportCoords,
|
186
|
186
|
setCursor,
|
|
@@ -222,83 +222,6 @@ const gesture: Gesture = {
|
222
|
222
|
initialScale: null,
|
223
|
223
|
};
|
224
|
224
|
|
225
|
|
-export type PointerDownState = Readonly<{
|
226
|
|
- // The first position at which pointerDown happened
|
227
|
|
- origin: Readonly<{ x: number; y: number }>;
|
228
|
|
- // Same as "origin" but snapped to the grid, if grid is on
|
229
|
|
- originInGrid: Readonly<{ x: number; y: number }>;
|
230
|
|
- // Scrollbar checks
|
231
|
|
- scrollbars: ReturnType<typeof isOverScrollBars>;
|
232
|
|
- // The previous pointer position
|
233
|
|
- lastCoords: { x: number; y: number };
|
234
|
|
- // map of original elements data
|
235
|
|
- originalElements: Map<string, NonDeleted<ExcalidrawElement>>;
|
236
|
|
- resize: {
|
237
|
|
- // Handle when resizing, might change during the pointer interaction
|
238
|
|
- handleType: MaybeTransformHandleType;
|
239
|
|
- // This is determined on the initial pointer down event
|
240
|
|
- isResizing: boolean;
|
241
|
|
- // This is determined on the initial pointer down event
|
242
|
|
- offset: { x: number; y: number };
|
243
|
|
- // This is determined on the initial pointer down event
|
244
|
|
- arrowDirection: "origin" | "end";
|
245
|
|
- // This is a center point of selected elements determined on the initial pointer down event (for rotation only)
|
246
|
|
- center: { x: number; y: number };
|
247
|
|
- };
|
248
|
|
- hit: {
|
249
|
|
- // The element the pointer is "hitting", is determined on the initial
|
250
|
|
- // pointer down event
|
251
|
|
- element: NonDeleted<ExcalidrawElement> | null;
|
252
|
|
- // The elements the pointer is "hitting", is determined on the initial
|
253
|
|
- // pointer down event
|
254
|
|
- allHitElements: NonDeleted<ExcalidrawElement>[];
|
255
|
|
- // This is determined on the initial pointer down event
|
256
|
|
- wasAddedToSelection: boolean;
|
257
|
|
- // Whether selected element(s) were duplicated, might change during the
|
258
|
|
- // pointer interaction
|
259
|
|
- hasBeenDuplicated: boolean;
|
260
|
|
- hasHitCommonBoundingBoxOfSelectedElements: boolean;
|
261
|
|
- };
|
262
|
|
- withCmdOrCtrl: boolean;
|
263
|
|
- drag: {
|
264
|
|
- // Might change during the pointer interation
|
265
|
|
- hasOccurred: boolean;
|
266
|
|
- // Might change during the pointer interation
|
267
|
|
- offset: { x: number; y: number } | null;
|
268
|
|
- };
|
269
|
|
- // We need to have these in the state so that we can unsubscribe them
|
270
|
|
- eventListeners: {
|
271
|
|
- // It's defined on the initial pointer down event
|
272
|
|
- onMove: null | ((event: PointerEvent) => void);
|
273
|
|
- // It's defined on the initial pointer down event
|
274
|
|
- onUp: null | ((event: PointerEvent) => void);
|
275
|
|
- // It's defined on the initial pointer down event
|
276
|
|
- onKeyDown: null | ((event: KeyboardEvent) => void);
|
277
|
|
- // It's defined on the initial pointer down event
|
278
|
|
- onKeyUp: null | ((event: KeyboardEvent) => void);
|
279
|
|
- };
|
280
|
|
-}>;
|
281
|
|
-
|
282
|
|
-export type ExcalidrawImperativeAPI = {
|
283
|
|
- updateScene: InstanceType<typeof App>["updateScene"];
|
284
|
|
- resetScene: InstanceType<typeof App>["resetScene"];
|
285
|
|
- getSceneElementsIncludingDeleted: InstanceType<
|
286
|
|
- typeof App
|
287
|
|
- >["getSceneElementsIncludingDeleted"];
|
288
|
|
- history: {
|
289
|
|
- clear: InstanceType<typeof App>["resetHistory"];
|
290
|
|
- };
|
291
|
|
- scrollToContent: InstanceType<typeof App>["scrollToContent"];
|
292
|
|
- getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
293
|
|
- getAppState: () => InstanceType<typeof App>["state"];
|
294
|
|
- refresh: InstanceType<typeof App>["refresh"];
|
295
|
|
- importLibrary: InstanceType<typeof App>["importLibraryFromUrl"];
|
296
|
|
- setToastMessage: InstanceType<typeof App>["setToastMessage"];
|
297
|
|
- readyPromise: ResolvablePromise<ExcalidrawImperativeAPI>;
|
298
|
|
- ready: true;
|
299
|
|
- id: string;
|
300
|
|
-};
|
301
|
|
-
|
302
|
225
|
class App extends React.Component<AppProps, AppState> {
|
303
|
226
|
canvas: HTMLCanvasElement | null = null;
|
304
|
227
|
rc: RoughCanvas | null = null;
|