import * as React from "react"; import styled, { css } from "styled-components"; import { sanitizeUrl } from "../../utils/urls"; import { ComponentProps } from "../types"; import { ResizeLeft, ResizeRight } from "./ResizeHandle"; import useComponentSize from "./hooks/useComponentSize"; import useDragResize from "./hooks/useDragResize"; type Props = ComponentProps & { /** Callback triggered when the video is resized */ onChangeSize?: (props: { width: number; height?: number }) => void; children?: React.ReactElement; }; export default function Video(props: Props) { const { isSelected, node, isEditable, children, onChangeSize } = props; const [naturalWidth] = React.useState(node.attrs.width); const [naturalHeight] = React.useState(node.attrs.height); const documentBounds = useComponentSize(props.view.dom); const isResizable = !!onChangeSize; const { width, height, setSize, handlePointerDown, dragging } = useDragResize( { width: node.attrs.width ?? naturalWidth, height: node.attrs.height ?? naturalHeight, minWidth: documentBounds.width * 0.1, maxWidth: documentBounds.width, naturalWidth, naturalHeight, gridWidth: documentBounds.width / 20, onChangeSize, } ); React.useEffect(() => { if (node.attrs.width && node.attrs.width !== width) { setSize({ width: node.attrs.width, height: node.attrs.height, }); } }, [node.attrs.width]); const style: React.CSSProperties = { width: width || "auto", maxHeight: height || "auto", pointerEvents: dragging ? "none" : "all", }; return (