mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Set Trailing Cmma to (#525)
This commit is contained in:
parent
25202aec11
commit
ee68af0fd3
53 changed files with 352 additions and 350 deletions
|
@ -8,7 +8,7 @@ export const hasBackground = (elements: readonly ExcalidrawElement[]) =>
|
|||
element.isSelected &&
|
||||
(element.type === "rectangle" ||
|
||||
element.type === "ellipse" ||
|
||||
element.type === "diamond")
|
||||
element.type === "diamond"),
|
||||
);
|
||||
|
||||
export const hasStroke = (elements: readonly ExcalidrawElement[]) =>
|
||||
|
@ -19,7 +19,7 @@ export const hasStroke = (elements: readonly ExcalidrawElement[]) =>
|
|||
element.type === "ellipse" ||
|
||||
element.type === "diamond" ||
|
||||
element.type === "arrow" ||
|
||||
element.type === "line")
|
||||
element.type === "line"),
|
||||
);
|
||||
|
||||
export const hasText = (elements: readonly ExcalidrawElement[]) =>
|
||||
|
@ -28,7 +28,7 @@ export const hasText = (elements: readonly ExcalidrawElement[]) =>
|
|||
export function getElementAtPosition(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
x: number,
|
||||
y: number
|
||||
y: number,
|
||||
) {
|
||||
let hitElement = null;
|
||||
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||
|
@ -45,7 +45,7 @@ export function getElementAtPosition(
|
|||
export function getElementContainingPosition(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
x: number,
|
||||
y: number
|
||||
y: number,
|
||||
) {
|
||||
let hitElement = null;
|
||||
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||
|
|
|
@ -27,19 +27,19 @@ interface DataState {
|
|||
|
||||
export function serializeAsJSON(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState?: AppState
|
||||
appState?: AppState,
|
||||
): string {
|
||||
return JSON.stringify({
|
||||
version: 1,
|
||||
source: window.location.origin,
|
||||
elements: elements.map(({ shape, ...el }) => el),
|
||||
appState: appState || getDefaultAppState()
|
||||
appState: appState || getDefaultAppState(),
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveAsJSON(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState
|
||||
appState: AppState,
|
||||
) {
|
||||
const serialized = serializeAsJSON(elements, appState);
|
||||
|
||||
|
@ -48,9 +48,9 @@ export async function saveAsJSON(
|
|||
new Blob([serialized], { type: "application/json" }),
|
||||
{
|
||||
fileName: name,
|
||||
description: "Excalidraw file"
|
||||
description: "Excalidraw file",
|
||||
},
|
||||
(window as any).handle
|
||||
(window as any).handle,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ export async function loadFromJSON() {
|
|||
const blob = await fileOpen({
|
||||
description: "Excalidraw files",
|
||||
extensions: ["json"],
|
||||
mimeTypes: ["application/json"]
|
||||
mimeTypes: ["application/json"],
|
||||
});
|
||||
if (blob.handle) {
|
||||
(window as any).handle = blob.handle;
|
||||
|
@ -101,12 +101,12 @@ export async function loadFromJSON() {
|
|||
|
||||
export async function exportToBackend(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState
|
||||
appState: AppState,
|
||||
) {
|
||||
const response = await fetch(BACKEND_POST, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: serializeAsJSON(elements, appState)
|
||||
body: serializeAsJSON(elements, appState),
|
||||
});
|
||||
const json = await response.json();
|
||||
if (json.id) {
|
||||
|
@ -117,8 +117,8 @@ export async function exportToBackend(
|
|||
window.alert(
|
||||
i18n.t("alerts.copiedToClipboard", {
|
||||
url: url.toString(),
|
||||
interpolation: { escapeValue: false }
|
||||
})
|
||||
interpolation: { escapeValue: false },
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
window.alert(i18n.t("alerts.couldNotCreateShareableLink"));
|
||||
|
@ -129,7 +129,7 @@ export async function importFromBackend(id: string | null) {
|
|||
let elements: readonly ExcalidrawElement[] = [];
|
||||
let appState: AppState = getDefaultAppState();
|
||||
const response = await fetch(`${BACKEND_GET}${id}.json`).then(data =>
|
||||
data.clone().json()
|
||||
data.clone().json(),
|
||||
);
|
||||
if (response != null) {
|
||||
try {
|
||||
|
@ -152,14 +152,14 @@ export async function exportCanvas(
|
|||
exportPadding = 10,
|
||||
viewBackgroundColor,
|
||||
name,
|
||||
scale = 1
|
||||
scale = 1,
|
||||
}: {
|
||||
exportBackground: boolean;
|
||||
exportPadding?: number;
|
||||
viewBackgroundColor: string;
|
||||
name: string;
|
||||
scale?: number;
|
||||
}
|
||||
},
|
||||
) {
|
||||
if (!elements.length)
|
||||
return window.alert(i18n.t("alerts.cannotExportEmptyCanvas"));
|
||||
|
@ -169,7 +169,7 @@ export async function exportCanvas(
|
|||
exportBackground,
|
||||
viewBackgroundColor,
|
||||
exportPadding,
|
||||
scale
|
||||
scale,
|
||||
});
|
||||
tempCanvas.style.display = "none";
|
||||
document.body.appendChild(tempCanvas);
|
||||
|
@ -180,7 +180,7 @@ export async function exportCanvas(
|
|||
if (blob) {
|
||||
await fileSave(blob, {
|
||||
fileName: fileName,
|
||||
description: "Excalidraw image"
|
||||
description: "Excalidraw image",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -190,7 +190,7 @@ export async function exportCanvas(
|
|||
tempCanvas.toBlob(async function(blob: any) {
|
||||
try {
|
||||
await navigator.clipboard.write([
|
||||
new window.ClipboardItem({ "image/png": blob })
|
||||
new window.ClipboardItem({ "image/png": blob }),
|
||||
]);
|
||||
} catch (err) {
|
||||
window.alert(errorMsg);
|
||||
|
@ -213,7 +213,7 @@ export async function exportCanvas(
|
|||
|
||||
function restore(
|
||||
savedElements: readonly ExcalidrawElement[],
|
||||
savedState: AppState
|
||||
savedState: AppState,
|
||||
): DataState {
|
||||
return {
|
||||
elements: savedElements.map(element => ({
|
||||
|
@ -225,9 +225,9 @@ function restore(
|
|||
opacity:
|
||||
element.opacity === null || element.opacity === undefined
|
||||
? 100
|
||||
: element.opacity
|
||||
: element.opacity,
|
||||
})),
|
||||
appState: savedState
|
||||
appState: savedState,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ export function restoreFromLocalStorage() {
|
|||
if (savedElements) {
|
||||
try {
|
||||
elements = JSON.parse(savedElements).map(
|
||||
({ shape, ...element }: ExcalidrawElement) => element
|
||||
({ shape, ...element }: ExcalidrawElement) => element,
|
||||
);
|
||||
} catch (e) {
|
||||
// Do nothing because elements array is already empty
|
||||
|
@ -260,7 +260,7 @@ export function restoreFromLocalStorage() {
|
|||
|
||||
export function saveToLocalStorage(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
state: AppState
|
||||
state: AppState,
|
||||
) {
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(elements));
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY_STATE, JSON.stringify(state));
|
||||
|
|
|
@ -9,7 +9,7 @@ export function getExportCanvasPreview(
|
|||
exportBackground,
|
||||
exportPadding = 10,
|
||||
viewBackgroundColor,
|
||||
scale = 1
|
||||
scale = 1,
|
||||
}: {
|
||||
exportBackground: boolean;
|
||||
exportPadding?: number;
|
||||
|
@ -18,13 +18,13 @@ export function getExportCanvasPreview(
|
|||
},
|
||||
createCanvas: (width: number, height: number) => any = function(
|
||||
width,
|
||||
height
|
||||
height,
|
||||
) {
|
||||
const tempCanvas = document.createElement("canvas");
|
||||
tempCanvas.width = width * scale;
|
||||
tempCanvas.height = height * scale;
|
||||
return tempCanvas;
|
||||
}
|
||||
},
|
||||
) {
|
||||
// calculate smallest area to fit the contents in
|
||||
let subCanvasX1 = Infinity;
|
||||
|
@ -56,14 +56,14 @@ export function getExportCanvasPreview(
|
|||
{
|
||||
viewBackgroundColor: exportBackground ? viewBackgroundColor : null,
|
||||
scrollX: 0,
|
||||
scrollY: 0
|
||||
scrollY: 0,
|
||||
},
|
||||
{
|
||||
offsetX: -subCanvasX1 + exportPadding,
|
||||
offsetY: -subCanvasY1 + exportPadding,
|
||||
renderScrollbars: false,
|
||||
renderSelection: false
|
||||
}
|
||||
renderSelection: false,
|
||||
},
|
||||
);
|
||||
return tempCanvas;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export {
|
|||
deleteSelectedElements,
|
||||
someElementIsSelected,
|
||||
getElementsWithinSelection,
|
||||
getCommonAttributeOfSelectedElements
|
||||
getCommonAttributeOfSelectedElements,
|
||||
} from "./selection";
|
||||
export {
|
||||
exportCanvas,
|
||||
|
@ -14,13 +14,13 @@ export {
|
|||
restoreFromLocalStorage,
|
||||
saveToLocalStorage,
|
||||
exportToBackend,
|
||||
importFromBackend
|
||||
importFromBackend,
|
||||
} from "./data";
|
||||
export {
|
||||
hasBackground,
|
||||
hasStroke,
|
||||
getElementAtPosition,
|
||||
getElementContainingPosition,
|
||||
hasText
|
||||
hasText,
|
||||
} from "./comparisons";
|
||||
export { createScene } from "./createScene";
|
||||
|
|
|
@ -11,7 +11,7 @@ export function getScrollBars(
|
|||
canvasWidth: number,
|
||||
canvasHeight: number,
|
||||
scrollX: number,
|
||||
scrollY: number
|
||||
scrollY: number,
|
||||
) {
|
||||
let minX = Infinity;
|
||||
let maxX = 0;
|
||||
|
@ -41,14 +41,14 @@ export function getScrollBars(
|
|||
horizontalScrollBar = {
|
||||
x: Math.min(
|
||||
leftOverflow + SCROLLBAR_MARGIN,
|
||||
canvasWidth - SCROLLBAR_MIN_SIZE - SCROLLBAR_MARGIN
|
||||
canvasWidth - SCROLLBAR_MIN_SIZE - SCROLLBAR_MARGIN,
|
||||
),
|
||||
y: canvasHeight - SCROLLBAR_WIDTH - SCROLLBAR_MARGIN,
|
||||
width: Math.max(
|
||||
canvasWidth - rightOverflow - leftOverflow - SCROLLBAR_MARGIN * 2,
|
||||
SCROLLBAR_MIN_SIZE
|
||||
SCROLLBAR_MIN_SIZE,
|
||||
),
|
||||
height: SCROLLBAR_WIDTH
|
||||
height: SCROLLBAR_WIDTH,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -59,19 +59,19 @@ export function getScrollBars(
|
|||
x: canvasWidth - SCROLLBAR_WIDTH - SCROLLBAR_MARGIN,
|
||||
y: Math.min(
|
||||
topOverflow + SCROLLBAR_MARGIN,
|
||||
canvasHeight - SCROLLBAR_MIN_SIZE - SCROLLBAR_MARGIN
|
||||
canvasHeight - SCROLLBAR_MIN_SIZE - SCROLLBAR_MARGIN,
|
||||
),
|
||||
width: SCROLLBAR_WIDTH,
|
||||
height: Math.max(
|
||||
canvasHeight - bottomOverflow - topOverflow - SCROLLBAR_WIDTH * 2,
|
||||
SCROLLBAR_MIN_SIZE
|
||||
)
|
||||
SCROLLBAR_MIN_SIZE,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
horizontal: horizontalScrollBar,
|
||||
vertical: verticalScrollBar
|
||||
vertical: verticalScrollBar,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -82,30 +82,30 @@ export function isOverScrollBars(
|
|||
canvasWidth: number,
|
||||
canvasHeight: number,
|
||||
scrollX: number,
|
||||
scrollY: number
|
||||
scrollY: number,
|
||||
) {
|
||||
const scrollBars = getScrollBars(
|
||||
elements,
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
scrollX,
|
||||
scrollY
|
||||
scrollY,
|
||||
);
|
||||
|
||||
const [isOverHorizontalScrollBar, isOverVerticalScrollBar] = [
|
||||
scrollBars.horizontal,
|
||||
scrollBars.vertical
|
||||
scrollBars.vertical,
|
||||
].map(
|
||||
scrollBar =>
|
||||
scrollBar &&
|
||||
scrollBar.x <= x &&
|
||||
x <= scrollBar.x + scrollBar.width &&
|
||||
scrollBar.y <= y &&
|
||||
y <= scrollBar.y + scrollBar.height
|
||||
y <= scrollBar.y + scrollBar.height,
|
||||
);
|
||||
|
||||
return {
|
||||
isOverHorizontalScrollBar,
|
||||
isOverVerticalScrollBar
|
||||
isOverVerticalScrollBar,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,20 +3,20 @@ import { getElementAbsoluteCoords } from "../element";
|
|||
|
||||
export function getElementsWithinSelection(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
selection: ExcalidrawElement
|
||||
selection: ExcalidrawElement,
|
||||
) {
|
||||
const [
|
||||
selectionX1,
|
||||
selectionY1,
|
||||
selectionX2,
|
||||
selectionY2
|
||||
selectionY2,
|
||||
] = getElementAbsoluteCoords(selection);
|
||||
return elements.filter(element => {
|
||||
const [
|
||||
elementX1,
|
||||
elementY1,
|
||||
elementX2,
|
||||
elementY2
|
||||
elementY2,
|
||||
] = getElementAbsoluteCoords(element);
|
||||
|
||||
return (
|
||||
|
@ -62,14 +62,14 @@ export const someElementIsSelected = (elements: readonly ExcalidrawElement[]) =>
|
|||
*/
|
||||
export function getCommonAttributeOfSelectedElements<T>(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
getAttribute: (element: ExcalidrawElement) => T
|
||||
getAttribute: (element: ExcalidrawElement) => T,
|
||||
): T | null {
|
||||
const attributes = Array.from(
|
||||
new Set(
|
||||
elements
|
||||
.filter(element => element.isSelected)
|
||||
.map(element => getAttribute(element))
|
||||
)
|
||||
.map(element => getAttribute(element)),
|
||||
),
|
||||
);
|
||||
return attributes.length === 1 ? attributes[0] : null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue