Compare commits

..

1 Commits

Author SHA1 Message Date
dwelle
b9fee5cf9c wip 2025-05-21 22:17:54 +02:00
7 changed files with 62 additions and 29 deletions

View File

@ -1,5 +1,5 @@
VITE_APP_BACKEND_V2_GET_URL=https://ex.dylanbanta.com/api/v2/scenes/
VITE_APP_BACKEND_V2_POST_URL=https://ex.dylanbanta.com/api/v2/scenes/
VITE_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/
VITE_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/
VITE_APP_LIBRARY_URL=https://libraries.excalidraw.com
VITE_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries

View File

@ -19,7 +19,7 @@ services:
- ./:/opt/node_app/app:delegated
- ./package.json:/opt/node_app/package.json
- ./yarn.lock:/opt/node_app/yarn.lock
# - notused:/opt/node_app/app/node_modules
- notused:/opt/node_app/app/node_modules
# volumes:
# notused:
volumes:
notused:

View File

@ -926,22 +926,17 @@ const ExcalidrawWrapper = () => {
<ShareDialog
collabAPI={collabAPI}
onExportToBackend={async () => {
if (!excalidrawAPI) {
return;
}
if (excalidrawAPI) {
try {
const { url, errorMessage } = await exportToBackend(
await onExportToBackend(
excalidrawAPI.getSceneElements(),
excalidrawAPI.getAppState(),
excalidrawAPI.getFiles(),
);
if (errorMessage) {
throw new Error(errorMessage);
}
setLatestShareableLink(url);
} catch (error: any) {
setErrorMessage(error.message);
}
}
}}
/>

View File

@ -41,8 +41,8 @@
"prettier": "@excalidraw/prettier-config",
"scripts": {
"build-node": "node ./scripts/build-node.js",
"build:app:docker": "vite build",
"build:app": "vite build",
"build:app:docker": "cross-env VITE_APP_DISABLE_SENTRY=true vite build",
"build:app": "cross-env VITE_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA cross-env VITE_APP_ENABLE_TRACKING=true vite build",
"build:version": "node ../scripts/build-version.js",
"build": "yarn build:app && yarn build:version",
"start": "yarn && vite",

View File

@ -39,6 +39,7 @@ const handleDimensionChange: DragInputCallbackType<
shouldKeepAspectRatio,
shouldChangeByStepSize,
nextValue,
ratio,
property,
originalAppState,
instantChange,
@ -154,6 +155,12 @@ const handleDimensionChange: DragInputCallbackType<
}
if (nextValue !== undefined) {
if (ratio) {
ratio = property === "width" ? ratio : [ratio[1], ratio[0]];
nextValue = (origElement[property] / ratio[0]) * ratio[1];
property = property === "width" ? "height" : "width";
}
const nextWidth = Math.max(
property === "width"
? nextValue

View File

@ -33,6 +33,7 @@ export type DragInputCallbackType<
shouldChangeByStepSize: boolean;
scene: Scene;
nextValue?: number;
ratio?: [number, number] | null;
property: P;
originalAppState: AppState;
setInputValue: (value: number) => void;
@ -109,11 +110,22 @@ const StatsDragInput = <
}
stateRef.current.updatePending = false;
const ratioMatch = updatedValue
.trim()
.match(/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/);
let ratio: [number, number] | null = null;
if (ratioMatch) {
ratio = [Number(ratioMatch[1]), Number(ratioMatch[2])];
}
const parsed = Number(updatedValue);
if (isNaN(parsed)) {
setInputValue(value.toString());
if (!ratio) {
return;
}
}
const rounded = Number(parsed.toFixed(2));
const original = Number(value);
@ -123,7 +135,11 @@ const StatsDragInput = <
// 2. original was not "Mixed" and the difference between a new value and previous value is greater
// than the smallest delta allowed, which is 0.01
// reason: idempotent to avoid unnecessary
if (isNaN(original) || Math.abs(rounded - original) >= SMALLEST_DELTA) {
if (
isNaN(original) ||
ratio ||
Math.abs(rounded - original) >= SMALLEST_DELTA
) {
stateRef.current.lastUpdatedValue = updatedValue;
dragInputCallback({
accumulatedChange: 0,
@ -134,6 +150,7 @@ const StatsDragInput = <
shouldChangeByStepSize: false,
scene,
nextValue: rounded,
ratio,
property,
originalAppState: appState,
setInputValue: (value) => setInputValue(String(value)),

View File

@ -151,6 +151,7 @@ const handleDimensionChange: DragInputCallbackType<
originalAppState,
shouldChangeByStepSize,
nextValue,
ratio,
scene,
property,
}) => {
@ -202,9 +203,22 @@ const handleDimensionChange: DragInputCallbackType<
origElement &&
isPropertyEditable(latestElement, property)
) {
let _nextValue = nextValue;
let _property = property;
if (ratio) {
let _ratio = ratio;
if (ratio) {
_ratio = _property === "width" ? _ratio : [_ratio[1], _ratio[0]];
_nextValue = (origElement[_property] / _ratio[0]) * _ratio[1];
_property = _property === "width" ? "height" : "width";
}
}
let nextWidth =
property === "width" ? Math.max(0, nextValue) : latestElement.width;
if (property === "width") {
_property === "width"
? Math.max(0, _nextValue)
: latestElement.width;
if (_property === "width") {
if (shouldChangeByStepSize) {
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
} else {
@ -213,10 +227,10 @@ const handleDimensionChange: DragInputCallbackType<
}
let nextHeight =
property === "height"
? Math.max(0, nextValue)
_property === "height"
? Math.max(0, _nextValue)
: latestElement.height;
if (property === "height") {
if (_property === "height") {
if (shouldChangeByStepSize) {
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
} else {
@ -234,7 +248,7 @@ const handleDimensionChange: DragInputCallbackType<
origElement,
originalElementsMap,
scene,
property === "width" ? "e" : "s",
_property === "width" ? "e" : "s",
{
shouldInformMutation: false,
},