chore: bump Prettier to the latest (#4185)

This commit is contained in:
Lipis 2021-11-01 15:24:05 +02:00 committed by GitHub
parent 277ffaacb9
commit 1c7056bdaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 226 additions and 284 deletions

View File

@ -69,7 +69,7 @@
"jest-canvas-mock": "2.3.1",
"lint-staged": "11.2.6",
"pepjs": "0.5.3",
"prettier": "2.2.1",
"prettier": "2.4.1",
"rewire": "5.0.0"
},
"engines": {

View File

@ -110,10 +110,8 @@ export const actionDeleteSelected = register({
};
}
let {
elements: nextElements,
appState: nextAppState,
} = deleteSelectedElements(elements, appState);
let { elements: nextElements, appState: nextAppState } =
deleteSelectedElements(elements, appState);
fixBindingsAfterDeletion(
nextElements,
elements.filter(({ id }) => appState.selectedElementIds[id]),

View File

@ -19,11 +19,8 @@ export const actionFinalize = register({
name: "finalize",
perform: (elements, appState, _, { canvas, focusContainer }) => {
if (appState.editingLinearElement) {
const {
elementId,
startBindingElement,
endBindingElement,
} = appState.editingLinearElement;
const { elementId, startBindingElement, endBindingElement } =
appState.editingLinearElement;
const element = LinearElementEditor.getElement(elementId);
if (element) {

View File

@ -99,9 +99,8 @@ export const actionGroup = register({
// to the z order of the highest element in the layer stack
const elementsInGroup = getElementsInGroup(updatedElements, newGroupId);
const lastElementInGroup = elementsInGroup[elementsInGroup.length - 1];
const lastGroupElementIndex = updatedElements.lastIndexOf(
lastElementInGroup,
);
const lastGroupElementIndex =
updatedElements.lastIndexOf(lastElementInGroup);
const elementsAfterGroup = updatedElements.slice(lastGroupElementIndex + 1);
const elementsBeforeGroup = updatedElements
.slice(0, lastGroupElementIndex)

View File

@ -96,10 +96,9 @@ const APP_STATE_STORAGE_CONF = (<
/** server (shareLink/collab/...) */
server: boolean;
},
T extends Record<keyof AppState, Values>
>(
config: { [K in keyof T]: K extends keyof AppState ? T[K] : never },
) => config)({
T extends Record<keyof AppState, Values>,
>(config: { [K in keyof T]: K extends keyof AppState ? T[K] : never }) =>
config)({
theme: { browser: true, export: false, server: false },
collaborators: { browser: false, export: false, server: false },
currentChartType: { browser: true, export: false, server: false },
@ -172,7 +171,7 @@ const APP_STATE_STORAGE_CONF = (<
});
const _clearAppStateForStorage = <
ExportType extends "export" | "browser" | "server"
ExportType extends "export" | "browser" | "server",
>(
appState: Partial<AppState>,
exportType: ExportType,

View File

@ -794,7 +794,8 @@ class App extends React.Component<AppProps, AppState> {
};
public async componentDidMount() {
this.excalidrawContainerValue.container = this.excalidrawContainerRef.current;
this.excalidrawContainerValue.container =
this.excalidrawContainerRef.current;
if (
process.env.NODE_ENV === ENV.TEST ||
@ -836,10 +837,8 @@ class App extends React.Component<AppProps, AppState> {
this.resizeObserver = new ResizeObserver(() => {
// compute isMobile state
// ---------------------------------------------------------------------
const {
width,
height,
} = this.excalidrawContainerRef.current!.getBoundingClientRect();
const { width, height } =
this.excalidrawContainerRef.current!.getBoundingClientRect();
this.isMobile =
width < MQ_MAX_WIDTH_PORTRAIT ||
(height < MQ_MAX_HEIGHT_LANDSCAPE && width < MQ_MAX_WIDTH_LANDSCAPE);
@ -1243,9 +1242,8 @@ class App extends React.Component<AppProps, AppState> {
async (event: ClipboardEvent | null) => {
// #686
const target = document.activeElement;
const isExcalidrawActive = this.excalidrawContainerRef.current?.contains(
target,
);
const isExcalidrawActive =
this.excalidrawContainerRef.current?.contains(target);
if (!isExcalidrawActive) {
return;
}
@ -2207,7 +2205,10 @@ class App extends React.Component<AppProps, AppState> {
}));
this.resetShouldCacheIgnoreZoomDebounced();
} else {
gesture.lastCenter = gesture.initialDistance = gesture.initialScale = null;
gesture.lastCenter =
gesture.initialDistance =
gesture.initialScale =
null;
}
if (isHoldingSpace || isPanning || isDraggingScrollBar) {
@ -2516,13 +2517,11 @@ class App extends React.Component<AppProps, AppState> {
);
}
const onPointerMove = this.onPointerMoveFromPointerDownHandler(
pointerDownState,
);
const onPointerMove =
this.onPointerMoveFromPointerDownHandler(pointerDownState);
const onPointerUp = this.onPointerUpFromPointerDownHandler(
pointerDownState,
);
const onPointerUp =
this.onPointerUpFromPointerDownHandler(pointerDownState);
const onKeyDown = this.onKeyDownFromPointerDownHandler(pointerDownState);
const onKeyUp = this.onKeyUpFromPointerDownHandler(pointerDownState);
@ -2727,10 +2726,11 @@ class App extends React.Component<AppProps, AppState> {
allHitElements: [],
wasAddedToSelection: false,
hasBeenDuplicated: false,
hasHitCommonBoundingBoxOfSelectedElements: this.isHittingCommonBoundingBoxOfSelectedElements(
origin,
selectedElements,
),
hasHitCommonBoundingBoxOfSelectedElements:
this.isHittingCommonBoundingBoxOfSelectedElements(
origin,
selectedElements,
),
},
drag: {
hasOccurred: false,
@ -2807,14 +2807,15 @@ class App extends React.Component<AppProps, AppState> {
const elements = this.scene.getElements();
const selectedElements = getSelectedElements(elements, this.state);
if (selectedElements.length === 1 && !this.state.editingLinearElement) {
const elementWithTransformHandleType = getElementWithTransformHandleType(
elements,
this.state,
pointerDownState.origin.x,
pointerDownState.origin.y,
this.state.zoom,
event.pointerType,
);
const elementWithTransformHandleType =
getElementWithTransformHandleType(
elements,
this.state,
pointerDownState.origin.x,
pointerDownState.origin.y,
this.state.zoom,
event.pointerType,
);
if (elementWithTransformHandleType != null) {
this.setState({
resizingElement: elementWithTransformHandleType.element,
@ -2890,9 +2891,10 @@ class App extends React.Component<AppProps, AppState> {
);
const hitElement = pointerDownState.hit.element;
const someHitElementIsSelected = pointerDownState.hit.allHitElements.some(
(element) => this.isASelectedElement(element),
);
const someHitElementIsSelected =
pointerDownState.hit.allHitElements.some((element) =>
this.isASelectedElement(element),
);
if (
(hitElement === null || !someHitElementIsSelected) &&
!event.shiftKey &&
@ -3554,8 +3556,8 @@ class App extends React.Component<AppProps, AppState> {
? {
// if using ctrl/cmd, select the hitElement only if we
// haven't box-selected anything else
[pointerDownState.hit.element
.id]: !elementsWithinSelection.length,
[pointerDownState.hit.element.id]:
!elementsWithinSelection.length,
}
: null),
},
@ -4429,7 +4431,9 @@ class App extends React.Component<AppProps, AppState> {
// This will only work as of Chrome 86,
// but can be safely ignored on older releases.
const item = event.dataTransfer.items[0];
(file as any).handle = await (item as any).getAsFileSystemHandle();
(file as any).handle = await (
item as any
).getAsFileSystemHandle();
} catch (error: any) {
console.warn(error.name, error.message);
}
@ -4551,10 +4555,8 @@ class App extends React.Component<AppProps, AppState> {
const type = element ? "element" : "canvas";
const container = this.excalidrawContainerRef.current!;
const {
top: offsetTop,
left: offsetLeft,
} = container.getBoundingClientRect();
const { top: offsetTop, left: offsetLeft } =
container.getBoundingClientRect();
const left = event.clientX - offsetLeft;
const top = event.clientY - offsetTop;

View File

@ -13,9 +13,11 @@ export const CheckboxItem: React.FC<{
className={clsx("Checkbox", { "is-checked": checked })}
onClick={(event) => {
onChange(!checked);
((event.currentTarget as HTMLDivElement).querySelector(
".Checkbox-box",
) as HTMLButtonElement).focus();
(
(event.currentTarget as HTMLDivElement).querySelector(
".Checkbox-box",
) as HTMLButtonElement
).focus();
}}
>
<button className="Checkbox-box" role="checkbox" aria-checked={checked}>

View File

@ -426,34 +426,34 @@ const LayerUI = ({
return null;
}
const createExporter = (type: ExportType): ExportCB => async (
exportedElements,
) => {
const fileHandle = await exportCanvas(
type,
exportedElements,
appState,
files,
{
exportBackground: appState.exportBackground,
name: appState.name,
viewBackgroundColor: appState.viewBackgroundColor,
},
)
.catch(muteFSAbortError)
.catch((error) => {
console.error(error);
setAppState({ errorMessage: error.message });
});
const createExporter =
(type: ExportType): ExportCB =>
async (exportedElements) => {
const fileHandle = await exportCanvas(
type,
exportedElements,
appState,
files,
{
exportBackground: appState.exportBackground,
name: appState.name,
viewBackgroundColor: appState.viewBackgroundColor,
},
)
.catch(muteFSAbortError)
.catch((error) => {
console.error(error);
setAppState({ errorMessage: error.message });
});
if (
appState.exportEmbedScene &&
fileHandle &&
isImageFileHandle(fileHandle)
) {
setAppState({ fileHandle });
}
};
if (
appState.exportEmbedScene &&
fileHandle &&
isImageFileHandle(fileHandle)
) {
setAppState({ fileHandle });
}
};
return (
<ImageExportDialog
@ -709,7 +709,8 @@ const LayerUI = ({
{!viewModeEnabled && (
<div
className={clsx("undo-redo-buttons zen-mode-transition", {
"layer-ui__wrapper__footer-left--transition-bottom": zenModeEnabled,
"layer-ui__wrapper__footer-left--transition-bottom":
zenModeEnabled,
})}
>
{actionManager.renderAction("undo", { size: "small" })}
@ -723,7 +724,8 @@ const LayerUI = ({
className={clsx(
"layer-ui__wrapper__footer-center zen-mode-transition",
{
"layer-ui__wrapper__footer-left--transition-bottom": zenModeEnabled,
"layer-ui__wrapper__footer-left--transition-bottom":
zenModeEnabled,
},
)}
>

View File

@ -34,10 +34,8 @@ const updateTooltip = (
width: itemWidth,
} = item.getBoundingClientRect();
const {
width: labelWidth,
height: labelHeight,
} = tooltip.getBoundingClientRect();
const { width: labelWidth, height: labelHeight } =
tooltip.getBoundingClientRect();
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;

View File

@ -30,8 +30,12 @@ export const createIcon = (
d: string | React.ReactNode,
opts: number | Opts = 512,
) => {
const { width = 512, height = width, mirror, style } =
typeof opts === "number" ? ({ width: opts } as Opts) : opts;
const {
width = 512,
height = width,
mirror,
style,
} = typeof opts === "number" ? ({ width: opts } as Opts) : opts;
return (
<svg
aria-hidden="true"

View File

@ -59,7 +59,7 @@ const getFontFamilyByName = (fontFamilyName: string): FontFamilyValues => {
const restoreElementWithProperties = <
T extends ExcalidrawElement,
K extends Pick<T, keyof Omit<Required<T>, keyof ExcalidrawElement>>
K extends Pick<T, keyof Omit<Required<T>, keyof ExcalidrawElement>>,
>(
element: Required<T>,
extra: Pick<
@ -98,11 +98,11 @@ const restoreElementWithProperties = <
boundElementIds: element.boundElementIds ?? [],
};
return ({
return {
...base,
...getNormalizedDimensions(base),
...extra,
} as unknown) as T;
} as unknown as T;
};
const restoreElement = (
@ -113,10 +113,9 @@ const restoreElement = (
let fontSize = element.fontSize;
let fontFamily = element.fontFamily;
if ("font" in element) {
const [fontPx, _fontFamily]: [
string,
string,
] = (element as any).font.split(" ");
const [fontPx, _fontFamily]: [string, string] = (
element as any
).font.split(" ");
fontSize = parseInt(fontPx, 10);
fontFamily = getFontFamilyByName(_fontFamily);
}

View File

@ -137,14 +137,13 @@ export const bindOrUnbindSelectedElements = (
const maybeBindBindableElement = (
bindableElement: NonDeleted<ExcalidrawBindableElement>,
): void => {
getElligibleElementsForBindableElementAndWhere(
bindableElement,
).forEach(([linearElement, where]) =>
bindOrUnbindLinearElement(
linearElement,
where === "end" ? "keep" : bindableElement,
where === "start" ? "keep" : bindableElement,
),
getElligibleElementsForBindableElementAndWhere(bindableElement).forEach(
([linearElement, where]) =>
bindOrUnbindLinearElement(
linearElement,
where === "end" ? "keep" : bindableElement,
where === "start" ? "keep" : bindableElement,
),
);
};
@ -293,9 +292,11 @@ export const updateBoundElements = (
const simultaneouslyUpdatedElementIds = getSimultaneouslyUpdatedElementIds(
simultaneouslyUpdated,
);
(Scene.getScene(changedElement)!.getNonDeletedElements(
boundElementIds,
) as NonDeleted<ExcalidrawLinearElement>[]).forEach((linearElement) => {
(
Scene.getScene(changedElement)!.getNonDeletedElements(
boundElementIds,
) as NonDeleted<ExcalidrawLinearElement>[]
).forEach((linearElement) => {
const bindableElement = changedElement as ExcalidrawBindableElement;
// In case the boundElementIds are stale
if (!doesNeedUpdate(linearElement, bindableElement)) {
@ -580,9 +581,11 @@ export const fixBindingsAfterDuplication = (
});
// Update the linear elements
(sceneElements.filter(({ id }) =>
allBoundElementIds.has(id),
) as ExcalidrawLinearElement[]).forEach((element) => {
(
sceneElements.filter(({ id }) =>
allBoundElementIds.has(id),
) as ExcalidrawLinearElement[]
).forEach((element) => {
const { startBinding, endBinding } = element;
mutateElement(element, {
startBinding: newBindingAfterDuplication(
@ -642,17 +645,17 @@ export const fixBindingsAfterDeletion = (
});
}
});
(sceneElements.filter(({ id }) =>
boundElementIds.has(id),
) as ExcalidrawLinearElement[]).forEach(
(element: ExcalidrawLinearElement) => {
const { startBinding, endBinding } = element;
mutateElement(element, {
startBinding: newBindingAfterDeletion(startBinding, deletedElementIds),
endBinding: newBindingAfterDeletion(endBinding, deletedElementIds),
});
},
);
(
sceneElements.filter(({ id }) =>
boundElementIds.has(id),
) as ExcalidrawLinearElement[]
).forEach((element: ExcalidrawLinearElement) => {
const { startBinding, endBinding } = element;
mutateElement(element, {
startBinding: newBindingAfterDeletion(startBinding, deletedElementIds),
endBinding: newBindingAfterDeletion(endBinding, deletedElementIds),
});
});
};
const newBindingAfterDeletion = (

View File

@ -78,7 +78,7 @@ const getMinMaxXYFromCurvePathOps = (
// move, bcurveTo, lineTo, and curveTo
if (op === "move") {
// change starting point
currentP = (data as unknown) as Point;
currentP = data as unknown as Point;
// move operation does not draw anything; so, it always
// returns false
} else if (op === "bcurveTo") {
@ -227,7 +227,7 @@ export const getArrowheadPoints = (
const prevOp = ops[index - 1];
let p0: Point = [0, 0];
if (prevOp.op === "move") {
p0 = (prevOp.data as unknown) as Point;
p0 = prevOp.data as unknown as Point;
} else if (prevOp.op === "bcurveTo") {
p0 = [prevOp.data[4], prevOp.data[5]];
}

View File

@ -866,7 +866,7 @@ const hitTestRoughShape = (
// move, bcurveTo, lineTo, and curveTo
if (op === "move") {
// change starting point
currentP = (data as unknown) as Point;
currentP = data as unknown as Point;
// move operation does not draw anything; so, it always
// returns false
} else if (op === "bcurveTo") {

View File

@ -150,9 +150,8 @@ export class LinearElementEditor {
)
: null;
binding = {
[activePointIndex === 0
? "startBindingElement"
: "endBindingElement"]: bindingElement,
[activePointIndex === 0 ? "startBindingElement" : "endBindingElement"]:
bindingElement,
};
}
return {
@ -236,10 +235,8 @@ export class LinearElementEditor {
// from the end points of the `linearElement` - this is to allow disabling
// binding (which needs to happen at the point the user finishes moving
// the point).
const {
startBindingElement,
endBindingElement,
} = appState.editingLinearElement;
const { startBindingElement, endBindingElement } =
appState.editingLinearElement;
if (isBindingEnabled(appState) && isBindingElement(element)) {
bindOrUnbindLinearElement(
element,

View File

@ -464,16 +464,12 @@ export const resizeSingleElement = (
}
}
const [
newBoundsX1,
newBoundsY1,
newBoundsX2,
newBoundsY2,
] = getResizedElementAbsoluteCoords(
stateAtResizeStart,
eleNewWidth,
eleNewHeight,
);
const [newBoundsX1, newBoundsY1, newBoundsX2, newBoundsY2] =
getResizedElementAbsoluteCoords(
stateAtResizeStart,
eleNewWidth,
eleNewHeight,
);
const newBoundsWidth = newBoundsX2 - newBoundsX1;
const newBoundsHeight = newBoundsY2 - newBoundsY1;

View File

@ -36,10 +36,8 @@ export const resizeTest = (
return false;
}
const {
rotation: rotationTransformHandle,
...transformHandles
} = getTransformHandles(element, zoom, pointerType);
const { rotation: rotationTransformHandle, ...transformHandles } =
getTransformHandles(element, zoom, pointerType);
if (
rotationTransformHandle &&
@ -49,9 +47,8 @@ export const resizeTest = (
}
const filter = Object.keys(transformHandles).filter((key) => {
const transformHandle = transformHandles[
key as Exclude<TransformHandleType, "rotation">
]!;
const transformHandle =
transformHandles[key as Exclude<TransformHandleType, "rotation">]!;
if (!transformHandle) {
return false;
}
@ -105,9 +102,8 @@ export const getTransformHandleTypeFromCoords = (
);
const found = Object.keys(transformHandles).find((key) => {
const transformHandle = transformHandles[
key as Exclude<TransformHandleType, "rotation">
]!;
const transformHandle =
transformHandles[key as Exclude<TransformHandleType, "rotation">]!;
return (
transformHandle &&
isInsideTransformHandle(transformHandle, scenePointerX, scenePointerY)

View File

@ -17,9 +17,9 @@ export type TransformHandleDirection =
export type TransformHandleType = TransformHandleDirection | "rotation";
export type TransformHandle = [number, number, number, number];
export type TransformHandles = Partial<
{ [T in TransformHandleType]: TransformHandle }
>;
export type TransformHandles = Partial<{
[T in TransformHandleType]: TransformHandle;
}>;
export type MaybeTransformHandleType = TransformHandleType | false;
const transformHandleSizes: { [k in PointerType]: number } = {

View File

@ -419,12 +419,8 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
);
break;
case "MOUSE_LOCATION": {
const {
pointer,
button,
username,
selectedElementIds,
} = decryptedData.payload;
const { pointer, button, username, selectedElementIds } =
decryptedData.payload;
const socketId: SocketUpdateDataSource["MOUSE_LOCATION"]["payload"]["socketId"] =
decryptedData.payload.socketId ||
// @ts-ignore legacy, see #2094 (#2097)
@ -503,12 +499,10 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
};
private loadImageFiles = throttle(async () => {
const {
loadedFiles,
erroredFiles,
} = await this.fetchImageFilesFromFirebase({
elements: this.excalidrawAPI.getSceneElementsIncludingDeleted(),
});
const { loadedFiles, erroredFiles } =
await this.fetchImageFilesFromFirebase({
elements: this.excalidrawAPI.getSceneElementsIncludingDeleted(),
});
this.excalidrawAPI.addFiles(loadedFiles);
@ -591,9 +585,8 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
setCollaborators(sockets: string[]) {
this.setState((state) => {
const collaborators: InstanceType<
typeof CollabWrapper
>["collaborators"] = new Map();
const collaborators: InstanceType<typeof CollabWrapper>["collaborators"] =
new Map();
for (const socketId of sockets) {
if (this.collaborators.has(socketId)) {
collaborators.set(socketId, this.collaborators.get(socketId)!);
@ -695,7 +688,8 @@ class CollabWrapper extends PureComponent<Props, CollabState> {
this.contextValue.initializeSocketClient = this.initializeSocketClient;
this.contextValue.onCollabButtonClick = this.onCollabButtonClick;
this.contextValue.broadcastElements = this.broadcastElements;
this.contextValue.fetchImageFilesFromFirebase = this.fetchImageFilesFromFirebase;
this.contextValue.fetchImageFilesFromFirebase =
this.fetchImageFilesFromFirebase;
return this.contextValue;
};

View File

@ -210,8 +210,8 @@ class Portal {
socketId: this.socket.id,
pointer: payload.pointer,
button: payload.button || "up",
selectedElementIds: this.collab.excalidrawAPI.getAppState()
.selectedElementIds,
selectedElementIds:
this.collab.excalidrawAPI.getAppState().selectedElementIds,
username: this.collab.state.username,
},
};

View File

@ -54,9 +54,8 @@ export const reconcileElements = (
remoteElements: readonly BroadcastedExcalidrawElement[],
localAppState: AppState,
): ReconciledElements => {
const localElementsData = getElementsMapWithIndex<ExcalidrawElement>(
localElements,
);
const localElementsData =
getElementsMapWithIndex<ExcalidrawElement>(localElements);
const reconciledElements: ExcalidrawElement[] = localElements.slice();

View File

@ -14,9 +14,8 @@ export const GitHubCorner = React.memo(
className="rtl-mirror"
style={{
marginTop: "calc(var(--space-factor) * -1)",
[dir === "rtl"
? "marginLeft"
: "marginRight"]: "calc(var(--space-factor) * -1)",
[dir === "rtl" ? "marginLeft" : "marginRight"]:
"calc(var(--space-factor) * -1)",
}}
>
<a

View File

@ -31,15 +31,11 @@ export class FileManager {
getFiles,
saveFiles,
}: {
getFiles: (
fileIds: FileId[],
) => Promise<{
getFiles: (fileIds: FileId[]) => Promise<{
loadedFiles: BinaryFileData[];
erroredFiles: Map<FileId, true>;
}>;
saveFiles: (data: {
addedFiles: Map<FileId, BinaryFileData>;
}) => Promise<{
saveFiles: (data: { addedFiles: Map<FileId, BinaryFileData> }) => Promise<{
savedFiles: Map<FileId, true>;
erroredFiles: Map<FileId, true>;
}>;

View File

@ -13,9 +13,8 @@ import { MIME_TYPES } from "../../constants";
const FIREBASE_CONFIG = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG);
let firebasePromise: Promise<
typeof import("firebase/app").default
> | null = null;
let firebasePromise: Promise<typeof import("firebase/app").default> | null =
null;
let firestorePromise: Promise<any> | null | true = null;
let firebaseStoragePromise: Promise<any> | null | true = null;

View File

@ -78,9 +78,10 @@ export type SocketUpdateDataIncoming =
type: "INVALID_RESPONSE";
};
export type SocketUpdateData = SocketUpdateDataSource[keyof SocketUpdateDataSource] & {
_brand: "socketUpdateData";
};
export type SocketUpdateData =
SocketUpdateDataSource[keyof SocketUpdateDataSource] & {
_brand: "socketUpdateData";
};
export const encryptAESGEM = async (
data: Uint8Array,

View File

@ -286,7 +286,8 @@ const ExcalidrawWrapper = () => {
promise: ResolvablePromise<ImportedDataState | null>;
}>({ promise: null! });
if (!initialStatePromiseRef.current.promise) {
initialStatePromiseRef.current.promise = resolvablePromise<ImportedDataState | null>();
initialStatePromiseRef.current.promise =
resolvablePromise<ImportedDataState | null>();
}
useEffect(() => {
@ -296,10 +297,8 @@ const ExcalidrawWrapper = () => {
}, VERSION_TIMEOUT);
}, []);
const [
excalidrawAPI,
excalidrawRefCallback,
] = useCallbackRefState<ExcalidrawImperativeAPI>();
const [excalidrawAPI, excalidrawRefCallback] =
useCallbackRefState<ExcalidrawImperativeAPI>();
const collabAPI = useContext(CollabContext)?.api;

View File

@ -67,7 +67,7 @@ export const nvector = (value: number = 0, index: number = 0): NVector => {
if (value !== 0) {
result[index] = value;
}
return (result as unknown) as NVector;
return result as unknown as NVector;
};
const STRING_EPSILON = 0.000001;

View File

@ -36,7 +36,7 @@ export const orthogonalThrough = (against: Point, intersection: Point): Line =>
export const parallel = (line: Line, distance: number): Line => {
const result = line.slice();
result[1] -= distance;
return (result as unknown) as Line;
return result as unknown as Line;
};
export const parallelThrough = (line: Line, point: Point): Line =>

7
src/global.d.ts vendored
View File

@ -49,8 +49,7 @@ type MarkRequired<T, RK extends keyof T> = Exclude<T, RK> &
type MarkNonNullable<T, K extends keyof T> = {
[P in K]-?: P extends K ? NonNullable<T[P]> : T[P];
} &
{ [P in keyof T]: T[P] };
} & { [P in keyof T]: T[P] };
// PNG encoding/decoding
// -----------------------------------------------------------------------------
@ -102,10 +101,10 @@ declare module "*.scss";
// (due to TS structural typing)
// https://github.com/microsoft/TypeScript/issues/31311#issuecomment-490690695
interface ArrayBuffer {
private _brand?: "ArrayBuffer";
_brand?: "ArrayBuffer";
}
interface Uint8Array {
private _brand?: "Uint8Array";
_brand?: "Uint8Array";
}
// --------------------------------------------------------------------------—

View File

@ -1,7 +1,7 @@
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const autoprefixer = require("autoprefixer");
module.exports = {

View File

@ -1,7 +1,7 @@
const webpack = require("webpack");
const path = require("path");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = {
mode: "production",

View File

@ -398,16 +398,8 @@ const generateElementShape = (
}
break;
case "diamond": {
const [
topX,
topY,
rightX,
rightY,
bottomX,
bottomY,
leftX,
leftY,
] = getDiamondPoints(element);
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
getDiamondPoints(element);
shape = generator.polygon(
[
[topX, topY],

View File

@ -336,12 +336,8 @@ export const renderScene = (
);
}
if (selectionColors.length) {
const [
elementX1,
elementY1,
elementX2,
elementY2,
] = getElementAbsoluteCoords(element);
const [elementX1, elementY1, elementX2, elementY2] =
getElementAbsoluteCoords(element);
acc.push({
angle: element.angle,
elementX1,
@ -356,9 +352,8 @@ export const renderScene = (
const addSelectionForGroupId = (groupId: GroupId) => {
const groupElements = getElementsInGroup(elements, groupId);
const [elementX1, elementY1, elementX2, elementY2] = getCommonBounds(
groupElements,
);
const [elementX1, elementY1, elementX2, elementY2] =
getCommonBounds(groupElements);
selections.push({
angle: 0,
elementX1,
@ -630,14 +625,8 @@ const renderSelectionBorder = (
selectionColors: string[];
},
) => {
const {
angle,
elementX1,
elementY1,
elementX2,
elementY2,
selectionColors,
} = elementProperties;
const { angle, elementX1, elementY1, elementX2, elementY2, selectionColors } =
elementProperties;
const elementWidth = elementX2 - elementX1;
const elementHeight = elementY2 - elementY1;

View File

@ -180,10 +180,9 @@ export const getExportSize = (
exportPadding: number,
scale: number,
): [number, number] => {
const [, , width, height] = getCanvasSize(
elements,
exportPadding,
).map((dimension) => Math.trunc(dimension * scale));
const [, , width, height] = getCanvasSize(elements, exportPadding).map(
(dimension) => Math.trunc(dimension * scale),
);
return [width, height];
};

View File

@ -30,12 +30,8 @@ export const getScrollBars = (
};
}
// This is the bounding box of all the elements
const [
elementsMinX,
elementsMinY,
elementsMaxX,
elementsMaxY,
] = getCommonBounds(elements);
const [elementsMinX, elementsMinY, elementsMaxX, elementsMaxY] =
getCommonBounds(elements);
// Apply zoom
const viewportWidthWithZoom = viewportWidth / zoom.value;

View File

@ -9,16 +9,11 @@ export const getElementsWithinSelection = (
elements: readonly NonDeletedExcalidrawElement[],
selection: NonDeletedExcalidrawElement,
) => {
const [
selectionX1,
selectionY1,
selectionX2,
selectionY2,
] = getElementAbsoluteCoords(selection);
const [selectionX1, selectionY1, selectionX2, selectionY2] =
getElementAbsoluteCoords(selection);
return elements.filter((element) => {
const [elementX1, elementY1, elementX2, elementY2] = getElementBounds(
element,
);
const [elementX1, elementY1, elementX2, elementY2] =
getElementBounds(element);
return (
element.type !== "selection" &&

View File

@ -91,9 +91,8 @@ describe("contextMenu element", () => {
clientY: 1,
});
const contextMenu = queryContextMenu();
const contextMenuOptions = contextMenu?.querySelectorAll(
".context-menu li",
);
const contextMenuOptions =
contextMenu?.querySelectorAll(".context-menu li");
const expectedShortcutNames: ShortcutName[] = [
"selectAll",
"gridMode",
@ -122,9 +121,8 @@ describe("contextMenu element", () => {
clientY: 1,
});
const contextMenu = queryContextMenu();
const contextMenuOptions = contextMenu?.querySelectorAll(
".context-menu li",
);
const contextMenuOptions =
contextMenu?.querySelectorAll(".context-menu li");
const expectedShortcutNames: ShortcutName[] = [
"copyStyles",
"pasteStyles",
@ -210,9 +208,8 @@ describe("contextMenu element", () => {
});
const contextMenu = queryContextMenu();
const contextMenuOptions = contextMenu?.querySelectorAll(
".context-menu li",
);
const contextMenuOptions =
contextMenu?.querySelectorAll(".context-menu li");
const expectedShortcutNames: ShortcutName[] = [
"copyStyles",
"pasteStyles",
@ -261,9 +258,8 @@ describe("contextMenu element", () => {
});
const contextMenu = queryContextMenu();
const contextMenuOptions = contextMenu?.querySelectorAll(
".context-menu li",
);
const contextMenuOptions =
contextMenu?.querySelectorAll(".context-menu li");
const expectedShortcutNames: ShortcutName[] = [
"copyStyles",
"pasteStyles",

View File

@ -57,7 +57,7 @@ export class API {
};
static createElement = <
T extends Exclude<ExcalidrawElement["type"], "selection">
T extends Exclude<ExcalidrawElement["type"], "selection">,
>({
type,
id,

View File

@ -75,10 +75,10 @@ const test = <U extends `${string}:${"L" | "R"}`>(
const cache: Cache = {};
const _local = idsToElements(local, cache);
const _remote = idsToElements(remote, cache);
const _target = (target.map((uid) => {
const _target = target.map((uid) => {
const [, id, source] = uid.match(/^(\w+):([LR])$/)!;
return (source === "L" ? _local : _remote).find((e) => e.id === id)!;
}) as any) as ReconciledElements;
}) as any as ReconciledElements;
const remoteReconciled = reconcileElements(_local, _remote, {} as AppState);
expect(cleanElements(remoteReconciled)).deep.equal(
cleanElements(_target),

View File

@ -874,14 +874,10 @@ describe("regression tests", () => {
expect(API.getSelectedElements().length).toBe(2);
const {
x: firstElementPrevX,
y: firstElementPrevY,
} = API.getSelectedElements()[0];
const {
x: secondElementPrevX,
y: secondElementPrevY,
} = API.getSelectedElements()[1];
const { x: firstElementPrevX, y: firstElementPrevY } =
API.getSelectedElements()[0];
const { x: secondElementPrevX, y: secondElementPrevY } =
API.getSelectedElements()[1];
// drag elements from point on common bounding box that doesn't hit any of the elements
mouse.reset();

View File

@ -126,7 +126,8 @@ export const mockBoundingClientRect = () => {
};
export const restoreOriginalGetBoundingClientRect = () => {
global.window.HTMLDivElement.prototype.getBoundingClientRect = originalGetBoundingClientRect;
global.window.HTMLDivElement.prototype.getBoundingClientRect =
originalGetBoundingClientRect;
};
export const assertSelectedElements = (

View File

@ -360,7 +360,7 @@ export const resolvablePromise = <T>() => {
* @param func handler taking at most single parameter (event).
*/
export const withBatchedUpdates = <
TFunction extends ((event: any) => void) | (() => void)
TFunction extends ((event: any) => void) | (() => void),
>(
func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never,
) =>

View File

@ -11783,10 +11783,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"
prettier@2.2.1:
version "2.2.1"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz"
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
prettier@2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"
integrity sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==
pretty-bytes@^5.3.0:
version "5.6.0"