import { TLBaseShape, TLResizeHandle, BaseBoxShapeUtil, //TLShapeUtilFlag, resizeBox, VecModel, Box, TLResizeMode, Rectangle2d, } from 'tldraw' export interface HTMLShape extends TLBaseShape<'html', { w: number; h: number, html: string }> { props: { w: number h: number html: string } } export class HTMLShapeUtil extends BaseBoxShapeUtil { static override type = 'html' as const override canBind = () => true override canEdit = () => false override canResize = () => true override isAspectRatioLocked = () => false getDefaultProps(): HTMLShape['props'] { return { w: 100, h: 100, html: "
" } } override onBeforeUpdate = (prev: HTMLShape, next: HTMLShape): void => { if (prev.x !== next.x || prev.y !== next.y) { this.editor.bringToFront([next.id]); } } override onResize = ( shape: HTMLShape, info: { handle: TLResizeHandle; mode: TLResizeMode; initialBounds: Box; initialShape: HTMLShape; newPoint: VecModel; scaleX: number; scaleY: number; } ) => { const element = document.getElementById(shape.id); if (!element || !element.parentElement) return resizeBox(shape, info); const { width, height } = element.parentElement.getBoundingClientRect(); if (element) { const isOverflowing = element.scrollWidth > width || element.scrollHeight > height; if (isOverflowing) { element.parentElement?.classList.add('overflowing'); } else { element.parentElement?.classList.remove('overflowing'); } } return resizeBox(shape, info) } getGeometry(shape: HTMLShape) { return new Rectangle2d({ width: shape.props.w, height: shape.props.h, isFilled: true, }) } override component(shape: HTMLShape): JSX.Element { return
} override indicator(shape: HTMLShape): JSX.Element { return } }