fix: remove embeddable from generic elements (#6853)

This commit is contained in:
David Luzar 2023-08-04 15:16:55 +02:00 committed by GitHub
parent bb985eba3a
commit 083bcf802c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 16 deletions

View File

@ -5395,7 +5395,7 @@ class App extends React.Component<AppProps, AppState> {
width: embedLink.aspectRatio.w, width: embedLink.aspectRatio.w,
height: embedLink.aspectRatio.h, height: embedLink.aspectRatio.h,
link, link,
validated: undefined, validated: null,
}); });
this.scene.replaceAllElements([ this.scene.replaceAllElements([
@ -5583,7 +5583,7 @@ class App extends React.Component<AppProps, AppState> {
} }
private createGenericElementOnPointerDown = ( private createGenericElementOnPointerDown = (
elementType: ExcalidrawGenericElement["type"], elementType: ExcalidrawGenericElement["type"] | "embeddable",
pointerDownState: PointerDownState, pointerDownState: PointerDownState,
): void => { ): void => {
const [gridX, gridY] = getGridPoint( const [gridX, gridY] = getGridPoint(
@ -5597,8 +5597,7 @@ class App extends React.Component<AppProps, AppState> {
y: gridY, y: gridY,
}); });
const element = newElement({ const baseElementAttributes = {
type: elementType,
x: gridX, x: gridX,
y: gridY, y: gridY,
strokeColor: this.state.currentItemStrokeColor, strokeColor: this.state.currentItemStrokeColor,
@ -5611,8 +5610,21 @@ class App extends React.Component<AppProps, AppState> {
roundness: this.getCurrentItemRoundness(elementType), roundness: this.getCurrentItemRoundness(elementType),
locked: false, locked: false,
frameId: topLayerFrame ? topLayerFrame.id : null, frameId: topLayerFrame ? topLayerFrame.id : null,
...(elementType === "embeddable" ? { validated: false } : {}), } as const;
});
let element;
if (elementType === "embeddable") {
element = newEmbeddableElement({
type: "embeddable",
validated: null,
...baseElementAttributes,
});
} else {
element = newElement({
type: elementType,
...baseElementAttributes,
});
}
if (element.type === "selection") { if (element.type === "selection") {
this.setState({ this.setState({

View File

@ -286,7 +286,7 @@ const restoreElement = (
return restoreElementWithProperties(element, {}); return restoreElementWithProperties(element, {});
case "embeddable": case "embeddable":
return restoreElementWithProperties(element, { return restoreElementWithProperties(element, {
validated: undefined, validated: null,
}); });
case "frame": case "frame":
return restoreElementWithProperties(element, { return restoreElementWithProperties(element, {

View File

@ -134,7 +134,7 @@ export const newElement = (
export const newEmbeddableElement = ( export const newEmbeddableElement = (
opts: { opts: {
type: "embeddable"; type: "embeddable";
validated: boolean | undefined; validated: ExcalidrawEmbeddableElement["validated"];
} & ElementConstructorOpts, } & ElementConstructorOpts,
): NonDeleted<ExcalidrawEmbeddableElement> => { ): NonDeleted<ExcalidrawEmbeddableElement> => {
return { return {

View File

@ -86,15 +86,15 @@ export type ExcalidrawEllipseElement = _ExcalidrawElementBase & {
export type ExcalidrawEmbeddableElement = _ExcalidrawElementBase & export type ExcalidrawEmbeddableElement = _ExcalidrawElementBase &
Readonly<{ Readonly<{
type: "embeddable";
/** /**
* indicates whether the embeddable src (url) has been validated for rendering. * indicates whether the embeddable src (url) has been validated for rendering.
* nullish value indicates that the validation is pending. We reset the * null value indicates that the validation is pending. We reset the
* value on each restore (or url change) so that we can guarantee * value on each restore (or url change) so that we can guarantee
* the validation came from a trusted source (the editor). Also because we * the validation came from a trusted source (the editor). Also because we
* 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; validated: boolean | null;
type: "embeddable";
}>; }>;
export type ExcalidrawImageElement = _ExcalidrawElementBase & export type ExcalidrawImageElement = _ExcalidrawElementBase &
@ -123,7 +123,6 @@ export type ExcalidrawFrameElement = _ExcalidrawElementBase & {
export type ExcalidrawGenericElement = export type ExcalidrawGenericElement =
| ExcalidrawSelectionElement | ExcalidrawSelectionElement
| ExcalidrawRectangleElement | ExcalidrawRectangleElement
| ExcalidrawEmbeddableElement
| ExcalidrawDiamondElement | ExcalidrawDiamondElement
| ExcalidrawEllipseElement; | ExcalidrawEllipseElement;
@ -138,7 +137,8 @@ export type ExcalidrawElement =
| ExcalidrawLinearElement | ExcalidrawLinearElement
| ExcalidrawFreeDrawElement | ExcalidrawFreeDrawElement
| ExcalidrawImageElement | ExcalidrawImageElement
| ExcalidrawFrameElement; | ExcalidrawFrameElement
| ExcalidrawEmbeddableElement;
export type NonDeleted<TElement extends ExcalidrawElement> = TElement & { export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
isDeleted: boolean; isDeleted: boolean;

View File

@ -34,6 +34,7 @@ export const rectangleFixture: ExcalidrawElement = {
export const embeddableFixture: ExcalidrawElement = { export const embeddableFixture: ExcalidrawElement = {
...elementBase, ...elementBase,
type: "embeddable", type: "embeddable",
validated: null,
}; };
export const ellipseFixture: ExcalidrawElement = { export const ellipseFixture: ExcalidrawElement = {
...elementBase, ...elementBase,

View File

@ -15,7 +15,11 @@ import fs from "fs";
import util from "util"; import util from "util";
import path from "path"; import path from "path";
import { getMimeType } from "../../data/blob"; import { getMimeType } from "../../data/blob";
import { newFreeDrawElement, newImageElement } from "../../element/newElement"; import {
newEmbeddableElement,
newFreeDrawElement,
newImageElement,
} from "../../element/newElement";
import { Point } from "../../types"; import { Point } from "../../types";
import { getSelectedElements } from "../../scene/selection"; import { getSelectedElements } from "../../scene/selection";
import { isLinearElementType } from "../../element/typeChecks"; import { isLinearElementType } from "../../element/typeChecks";
@ -178,14 +182,20 @@ export class API {
case "rectangle": case "rectangle":
case "diamond": case "diamond":
case "ellipse": case "ellipse":
case "embeddable":
element = newElement({ element = newElement({
type: type as "rectangle" | "diamond" | "ellipse" | "embeddable", type: type as "rectangle" | "diamond" | "ellipse",
width, width,
height, height,
...base, ...base,
}); });
break; break;
case "embeddable":
element = newEmbeddableElement({
type: "embeddable",
...base,
validated: null,
});
break;
case "text": case "text":
const fontSize = rest.fontSize ?? appState.currentItemFontSize; const fontSize = rest.fontSize ?? appState.currentItemFontSize;
const fontFamily = rest.fontFamily ?? appState.currentItemFontFamily; const fontFamily = rest.fontFamily ?? appState.currentItemFontFamily;