Compare commits

..

1 Commits

Author SHA1 Message Date
zsviczian
347177f873 fix sequence of events 2023-11-25 12:01:19 +01:00
9 changed files with 24 additions and 57 deletions

View File

@@ -1038,10 +1038,6 @@ class App extends React.Component<AppProps, AppState> {
this.state.activeEmbeddable?.element === el && this.state.activeEmbeddable?.element === el &&
this.state.activeEmbeddable?.state === "hover"; this.state.activeEmbeddable?.state === "hover";
// Modify the scale based on el.scale property
const [xScale, yScale] = el.scale ?? [1, 1];
const scaledTransform = `scale(${scale * xScale}, ${scale * yScale})`;
return ( return (
<div <div
key={el.id} key={el.id}
@@ -1052,13 +1048,14 @@ class App extends React.Component<AppProps, AppState> {
transform: isVisible transform: isVisible
? `translate(${x - this.state.offsetLeft}px, ${ ? `translate(${x - this.state.offsetLeft}px, ${
y - this.state.offsetTop y - this.state.offsetTop
}px) ${scaledTransform}` }px) scale(${scale})`
: "none", : "none",
display: isVisible ? "block" : "none", display: isVisible ? "block" : "none",
opacity: el.opacity / 100, opacity: el.opacity / 100,
["--embeddable-radius" as string]: `${ ["--embeddable-radius" as string]: `${getCornerRadius(
getCornerRadius(Math.min(el.width, el.height), el) / xScale Math.min(el.width, el.height),
}px`, el,
)}px`,
}} }}
> >
<div <div
@@ -1080,8 +1077,8 @@ class App extends React.Component<AppProps, AppState> {
}}*/ }}*/
className="excalidraw__embeddable-container__inner" className="excalidraw__embeddable-container__inner"
style={{ style={{
width: isVisible ? `${el.width / xScale}px` : 0, width: isVisible ? `${el.width}px` : 0,
height: isVisible ? `${el.height / yScale}px` : 0, height: isVisible ? `${el.height}px` : 0,
transform: isVisible ? `rotate(${el.angle}rad)` : "none", transform: isVisible ? `rotate(${el.angle}rad)` : "none",
pointerEvents: isActive pointerEvents: isActive
? POINTER_EVENTS.enabled ? POINTER_EVENTS.enabled
@@ -1096,7 +1093,7 @@ class App extends React.Component<AppProps, AppState> {
<div <div
className="excalidraw__embeddable__outer" className="excalidraw__embeddable__outer"
style={{ style={{
padding: `${el.strokeWidth / el.scale[0]}px`, padding: `${el.strokeWidth}px`,
}} }}
> >
{(isEmbeddableElement(el) {(isEmbeddableElement(el)

View File

@@ -294,15 +294,11 @@ const restoreElement = (
case "ellipse": case "ellipse":
case "rectangle": case "rectangle":
case "diamond": case "diamond":
return restoreElementWithProperties(element, {});
case "iframe": case "iframe":
return restoreElementWithProperties(element, { return restoreElementWithProperties(element, {});
scale: element.scale ?? [1, 1],
});
case "embeddable": case "embeddable":
return restoreElementWithProperties(element, { return restoreElementWithProperties(element, {
validated: null, validated: null,
scale: element.scale ?? [1, 1],
}); });
case "magicframe": case "magicframe":
case "frame": case "frame":

View File

@@ -1,10 +1,10 @@
import { sanitizeUrl } from "@braintree/sanitize-url"; import { sanitizeUrl } from "@braintree/sanitize-url";
export const normalizeLink = (link: string) => { export const normalizeLink = (link: string) => {
link = link.trim();
if (!link) { if (!link) {
return link; return link;
} }
link = link.trim();
return sanitizeUrl(link); return sanitizeUrl(link);
}; };

View File

@@ -21,7 +21,7 @@ import {
const embeddedLinkCache = new Map<string, IframeData>(); const embeddedLinkCache = new Map<string, IframeData>();
const RE_YOUTUBE = const RE_YOUTUBE =
/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|.*&t=|\?start=|.*&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/; /^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/;
const RE_VIMEO = const RE_VIMEO =
/^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/; /^(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/;

View File

@@ -142,7 +142,6 @@ export const newEmbeddableElement = (
return { return {
..._newElementBase<ExcalidrawEmbeddableElement>("embeddable", opts), ..._newElementBase<ExcalidrawEmbeddableElement>("embeddable", opts),
validated: opts.validated, validated: opts.validated,
scale: [1, 1],
}; };
}; };
@@ -153,7 +152,6 @@ export const newIframeElement = (
): NonDeleted<ExcalidrawIframeElement> => { ): NonDeleted<ExcalidrawIframeElement> => {
return { return {
..._newElementBase<ExcalidrawIframeElement>("iframe", opts), ..._newElementBase<ExcalidrawIframeElement>("iframe", opts),
scale: [1, 1],
}; };
}; };

View File

@@ -27,7 +27,6 @@ import {
import { import {
isArrowElement, isArrowElement,
isBoundToContainer, isBoundToContainer,
isIframeLikeElement,
isFrameLikeElement, isFrameLikeElement,
isFreeDrawElement, isFreeDrawElement,
isImageElement, isImageElement,
@@ -587,21 +586,6 @@ export const resizeSingleElement = (
}; };
if ("scale" in element && "scale" in stateAtResizeStart) { if ("scale" in element && "scale" in stateAtResizeStart) {
if (isIframeLikeElement(element)) {
if (shouldMaintainAspectRatio) {
const scale: [number, number] = [
Math.abs(
eleNewWidth /
(stateAtResizeStart.width / stateAtResizeStart.scale[0]),
),
Math.abs(
eleNewHeight /
(stateAtResizeStart.height / stateAtResizeStart.scale[1]),
),
];
mutateElement(element, { scale });
}
} else {
mutateElement(element, { mutateElement(element, {
scale: [ scale: [
// defaulting because scaleX/Y can be 0/-0 // defaulting because scaleX/Y can be 0/-0
@@ -612,7 +596,6 @@ export const resizeSingleElement = (
], ],
}); });
} }
}
if ( if (
isArrowElement(element) && isArrowElement(element) &&

View File

@@ -96,7 +96,6 @@ export type ExcalidrawEmbeddableElement = _ExcalidrawElementBase &
* may not have access to host-app supplied url validator during restore. * may not have access to host-app supplied url validator during restore.
*/ */
validated: boolean | null; validated: boolean | null;
scale: [number, number];
}>; }>;
export type ExcalidrawIframeElement = _ExcalidrawElementBase & export type ExcalidrawIframeElement = _ExcalidrawElementBase &
@@ -104,7 +103,6 @@ export type ExcalidrawIframeElement = _ExcalidrawElementBase &
type: "iframe"; type: "iframe";
// TODO move later to AI-specific frame // TODO move later to AI-specific frame
customData?: { generationData?: MagicCacheData }; customData?: { generationData?: MagicCacheData };
scale: [number, number];
}>; }>;
export type ExcalidrawIframeLikeElement = export type ExcalidrawIframeLikeElement =

View File

@@ -13,7 +13,6 @@ import {
isInitializedImageElement, isInitializedImageElement,
isArrowElement, isArrowElement,
hasBoundTextElement, hasBoundTextElement,
isIframeLikeElement,
isMagicFrameElement, isMagicFrameElement,
} from "../element/typeChecks"; } from "../element/typeChecks";
import { getElementAbsoluteCoords } from "../element/bounds"; import { getElementAbsoluteCoords } from "../element/bounds";
@@ -521,8 +520,7 @@ const drawElementFromCanvas = (
if ( if (
"scale" in elementWithCanvas.element && "scale" in elementWithCanvas.element &&
!isPendingImageElement(element, renderConfig) && !isPendingImageElement(element, renderConfig)
!isIframeLikeElement(element)
) { ) {
context.scale( context.scale(
elementWithCanvas.element.scale[0], elementWithCanvas.element.scale[0],
@@ -998,8 +996,6 @@ export const renderElementToSvg = (
renderConfig, renderConfig,
); );
const scaleX = element.scale?.[0] || 1;
const scaleY = element.scale?.[1] || 1;
// render embeddable element + iframe // render embeddable element + iframe
const embeddableNode = roughSVGDrawWithPrecision( const embeddableNode = roughSVGDrawWithPrecision(
rsvg, rsvg,
@@ -1011,7 +1007,7 @@ export const renderElementToSvg = (
"transform", "transform",
`translate(${offsetX || 0} ${ `translate(${offsetX || 0} ${
offsetY || 0 offsetY || 0
}) rotate(${degree} ${cx} ${cy}) scale(${scaleX}, ${scaleY})`, }) rotate(${degree} ${cx} ${cy})`,
); );
while (embeddableNode.firstChild) { while (embeddableNode.firstChild) {
embeddableNode.removeChild(embeddableNode.firstChild); embeddableNode.removeChild(embeddableNode.firstChild);
@@ -1042,8 +1038,8 @@ export const renderElementToSvg = (
SVG_NS, SVG_NS,
"foreignObject", "foreignObject",
); );
foreignObject.style.width = `${element.width / scaleX}px`; foreignObject.style.width = `${element.width}px`;
foreignObject.style.height = `${element.height / scaleY}px`; foreignObject.style.height = `${element.height}px`;
foreignObject.style.border = "none"; foreignObject.style.border = "none";
const div = foreignObject.ownerDocument!.createElementNS(SVG_NS, "div"); const div = foreignObject.ownerDocument!.createElementNS(SVG_NS, "div");
div.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"); div.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");

View File

@@ -35,7 +35,6 @@ export const embeddableFixture: ExcalidrawElement = {
...elementBase, ...elementBase,
type: "embeddable", type: "embeddable",
validated: null, validated: null,
scale: [1, 1],
}; };
export const ellipseFixture: ExcalidrawElement = { export const ellipseFixture: ExcalidrawElement = {
...elementBase, ...elementBase,