diff --git a/packages/dev/src/core/box.tsx b/packages/dev/src/core/box.tsx index b6a9524a4..b2756cf78 100644 --- a/packages/dev/src/core/box.tsx +++ b/packages/dev/src/core/box.tsx @@ -2,16 +2,7 @@ /* refresh-reset */ import * as React from 'react' -import { - TLShape, - Utils, - TLBounds, - TLShapeUtil, - HTMLContainer, - TLComponent, - SVGContainer, - TLIndicator, -} from '@tldraw/core' +import { TLShape, Utils, TLBounds, TLShapeUtil, HTMLContainer, SVGContainer } from '@tldraw/core' // Define a custom shape @@ -37,86 +28,84 @@ export const boxShape: BoxShape = { export class BoxUtil extends TLShapeUtil { age = 100 - Component: TLComponent = ( - { shape, events, onShapeChange, isEditing, meta }, - ref - ) => { - console.log('hi') - const color = meta.isDarkMode ? 'white' : 'black' + Component = TLShapeUtil.Component( + ({ shape, events, onShapeChange, isEditing, meta }, ref) => { + const color = meta.isDarkMode ? 'white' : 'black' - const rInput = React.useRef(null) + const rInput = React.useRef(null) - function updateShapeSize() { - const elm = rInput.current! + function updateShapeSize() { + const elm = rInput.current! - onShapeChange?.({ - ...shape, - text: elm.innerText, - size: [elm.offsetWidth + 44, elm.offsetHeight + 44], - }) - } - - React.useLayoutEffect(() => { - const elm = rInput.current! - - const observer = new MutationObserver(updateShapeSize) - - observer.observe(elm, { - attributes: true, - characterData: true, - subtree: true, - }) - - elm.innerText = shape.text - updateShapeSize() - - return () => { - observer.disconnect() + onShapeChange?.({ + ...shape, + text: elm.innerText, + size: [elm.offsetWidth + 44, elm.offsetHeight + 44], + }) } - }, []) - React.useEffect(() => { - if (isEditing) { - rInput.current!.focus() - } - }, [isEditing]) + React.useLayoutEffect(() => { + const elm = rInput.current! - return ( - -
-
isEditing && e.stopPropagation()}> -
+ const observer = new MutationObserver(updateShapeSize) + + observer.observe(elm, { + attributes: true, + characterData: true, + subtree: true, + }) + + elm.innerText = shape.text + updateShapeSize() + + return () => { + observer.disconnect() + } + }, []) + + React.useEffect(() => { + if (isEditing) { + rInput.current!.focus() + } + }, [isEditing]) + + return ( + +
+
isEditing && e.stopPropagation()}> +
+
-
-
- ) - } + + ) + } + ) - Indicator: TLIndicator = ({ shape }) => { + Indicator = TLShapeUtil.Indicator(({ shape }) => { return ( { /> ) - } + }) getBounds = (shape: BoxShape) => { const bounds = Utils.getFromCache(this.boundsCache, shape, () => { diff --git a/packages/dev/tsconfig.json b/packages/dev/tsconfig.json index 51d1ad275..b174c09cc 100644 --- a/packages/dev/tsconfig.json +++ b/packages/dev/tsconfig.json @@ -9,7 +9,6 @@ "emitDeclarationOnly": false, "paths": { "+*": ["./*"], - "@tldraw/core": ["../core"], "@tldraw/tldraw": ["../tldraw"] } }, diff --git a/packages/tldraw/tsconfig.json b/packages/tldraw/tsconfig.json index 5a4822363..734330bef 100644 --- a/packages/tldraw/tsconfig.json +++ b/packages/tldraw/tsconfig.json @@ -8,7 +8,6 @@ "baseUrl": "src", "paths": { "~*": ["./*"], - "@tldraw/core": ["../core"], "@tldraw/vec": ["../vec"], "@tldraw/intersect": ["../intersect"] }