html is resizeable
This commit is contained in:
parent
366cba1ec1
commit
3423aeeeb6
|
|
@ -11,7 +11,7 @@ export const SimController = ({ shapes }: { shapes: TLUnknownShape[] }) => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const { addShapes } = usePhysicsSimulation(editor, true);
|
const { addShapes } = usePhysicsSimulation(editor, false);
|
||||||
|
|
||||||
return (<></>);
|
return (<></>);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
import { Rectangle2d, TLBaseShape } from '@tldraw/tldraw';
|
import { Rectangle2d, resizeBox, TLBaseShape, TLOnResizeHandler } from '@tldraw/tldraw';
|
||||||
import { HTMLContainer, ShapeUtil } from 'tldraw'
|
import { HTMLContainer, ShapeUtil } from 'tldraw'
|
||||||
|
|
||||||
export type HTMLShape = TLBaseShape<'html', { w: number; h: number, html: string }>
|
export type HTMLShape = TLBaseShape<'html', { w: number; h: number, html: string }>
|
||||||
|
|
||||||
export class HTMLShapeUtil extends ShapeUtil<HTMLShape> {
|
export class HTMLShapeUtil extends ShapeUtil<HTMLShape> {
|
||||||
static override type = 'html' as const
|
static override type = 'html' as const
|
||||||
|
override canBind = () => true
|
||||||
|
override canEdit = () => false
|
||||||
|
override canResize = () => true
|
||||||
|
override isAspectRatioLocked = () => false
|
||||||
|
|
||||||
getDefaultProps(): HTMLShape['props'] {
|
getDefaultProps(): HTMLShape['props'] {
|
||||||
return {
|
return {
|
||||||
|
|
@ -14,6 +18,10 @@ export class HTMLShapeUtil extends ShapeUtil<HTMLShape> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override onResize: TLOnResizeHandler<any> = (shape, info) => {
|
||||||
|
return resizeBox(shape, info)
|
||||||
|
}
|
||||||
|
|
||||||
getGeometry(shape: IHTMLShape) {
|
getGeometry(shape: IHTMLShape) {
|
||||||
return new Rectangle2d({
|
return new Rectangle2d({
|
||||||
width: shape.props.w,
|
width: shape.props.w,
|
||||||
|
|
@ -24,6 +32,7 @@ export class HTMLShapeUtil extends ShapeUtil<HTMLShape> {
|
||||||
|
|
||||||
component(shape: HTMLShape) {
|
component(shape: HTMLShape) {
|
||||||
return <div dangerouslySetInnerHTML={{ __html: shape.props.html }}></div>
|
return <div dangerouslySetInnerHTML={{ __html: shape.props.html }}></div>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator(shape: HTMLShape) {
|
indicator(shape: HTMLShape) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue