2020-03-17 20:55:40 +01:00
|
|
|
import {
|
|
|
|
ExcalidrawElement,
|
|
|
|
ExcalidrawTextElement,
|
|
|
|
ExcalidrawLinearElement,
|
2020-08-08 21:04:15 -07:00
|
|
|
ExcalidrawBindableElement,
|
2020-12-06 22:39:31 +00:00
|
|
|
ExcalidrawGenericElement,
|
2020-03-17 20:55:40 +01:00
|
|
|
} from "./types";
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-12-06 22:39:31 +00:00
|
|
|
export const isGenericElement = (
|
|
|
|
element: ExcalidrawElement | null,
|
|
|
|
): element is ExcalidrawGenericElement => {
|
|
|
|
return (
|
|
|
|
element != null &&
|
|
|
|
(element.type === "selection" ||
|
|
|
|
element.type === "rectangle" ||
|
|
|
|
element.type === "diamond" ||
|
|
|
|
element.type === "ellipse")
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const isTextElement = (
|
2020-04-06 22:26:54 +02:00
|
|
|
element: ExcalidrawElement | null,
|
2020-05-20 16:21:37 +03:00
|
|
|
): element is ExcalidrawTextElement => {
|
2020-04-06 22:26:54 +02:00
|
|
|
return element != null && element.type === "text";
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-02-24 15:21:13 +01:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const isLinearElement = (
|
2020-03-17 20:55:40 +01:00
|
|
|
element?: ExcalidrawElement | null,
|
2020-05-20 16:21:37 +03:00
|
|
|
): element is ExcalidrawLinearElement => {
|
2020-08-08 21:04:15 -07:00
|
|
|
return element != null && isLinearElementType(element.type);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isLinearElementType = (
|
|
|
|
elementType: ExcalidrawElement["type"],
|
|
|
|
): boolean => {
|
|
|
|
return (
|
|
|
|
elementType === "arrow" || elementType === "line" || elementType === "draw"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isBindingElement = (
|
|
|
|
element?: ExcalidrawElement | null,
|
|
|
|
): element is ExcalidrawLinearElement => {
|
|
|
|
return element != null && isBindingElementType(element.type);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isBindingElementType = (
|
|
|
|
elementType: ExcalidrawElement["type"],
|
|
|
|
): boolean => {
|
|
|
|
return elementType === "arrow";
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isBindableElement = (
|
|
|
|
element: ExcalidrawElement | null,
|
|
|
|
): element is ExcalidrawBindableElement => {
|
2020-03-17 20:55:40 +01:00
|
|
|
return (
|
2020-05-12 20:10:11 +01:00
|
|
|
element != null &&
|
2020-08-08 21:04:15 -07:00
|
|
|
(element.type === "rectangle" ||
|
|
|
|
element.type === "diamond" ||
|
|
|
|
element.type === "ellipse" ||
|
|
|
|
element.type === "text")
|
2020-03-17 20:55:40 +01:00
|
|
|
);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-03-17 20:55:40 +01:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const isExcalidrawElement = (element: any): boolean => {
|
2020-02-24 15:21:13 +01:00
|
|
|
return (
|
|
|
|
element?.type === "text" ||
|
|
|
|
element?.type === "diamond" ||
|
|
|
|
element?.type === "rectangle" ||
|
|
|
|
element?.type === "ellipse" ||
|
|
|
|
element?.type === "arrow" ||
|
2020-05-12 20:10:11 +01:00
|
|
|
element?.type === "draw" ||
|
2020-02-24 15:21:13 +01:00
|
|
|
element?.type === "line"
|
|
|
|
);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|