diff --git a/src/App.tsx b/src/App.tsx index 8659c84..affbe10 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,14 @@ -import { Tldraw, track, useEditor } from "tldraw"; import "tldraw/tldraw.css"; -// import { DevShapeTool } from "./DevShape/DevShapeTool"; -// import { DevShapeUtil } from "./DevShape/DevShapeUtil"; -// import { DevUi } from "./DevUI"; -// import { uiOverrides } from "./ui-overrides"; +import { Tldraw } from "tldraw"; import { useYjsStore } from "./useYjsStore"; import { AgentButton } from "./components/AgentButton"; +import { SocialShapeUtil } from "./SocialShapeUtil"; +import { SocialShapeTool } from "./SocialShapeTool"; +import { CustomToolbar, overrides } from "./ui"; + +const shapeUtils = [SocialShapeUtil]; +const tools = [SocialShapeTool]; -// const customShapeUtils = [DevShapeUtil]; -// const customTools = [DevShapeTool]; const HOST_URL = import.meta.env.DEV ? "ws://localhost:1234" @@ -20,7 +20,7 @@ export default function Canvas() { const store = useYjsStore({ roomId: roomId, hostUrl: HOST_URL, - // shapeUtils: customShapeUtils, + shapeUtils: shapeUtils, }); return ( @@ -28,66 +28,69 @@ export default function Canvas() { { + //@ts-ignore + editor.getStateDescendant('select.idle').handleDoubleClickOnCanvas = () => void null; + }} components={{ SharePanel: AgentButton, + Toolbar: CustomToolbar, }} - // shapeUtils={customShapeUtils} - // tools={customTools} - // overrides={uiOverrides} - > - {/* */} - + /> ); } -const NameEditor = track(() => { - const editor = useEditor(); +// const NameEditor = track(() => { +// const editor = useEditor(); - const { color, name } = editor.user.getUserPreferences(); +// const { color, name } = editor.user.getUserPreferences(); - return ( -
- { - editor.user.updateUserPreferences({ - color: e.currentTarget.value, - }); - }} - /> - { - editor.user.updateUserPreferences({ - name: e.currentTarget.value, - }); - }} - /> -
- ); -}); +// return ( +//
+// { +// editor.user.updateUserPreferences({ +// color: e.currentTarget.value, +// }); +// }} +// /> +// { +// editor.user.updateUserPreferences({ +// name: e.currentTarget.value, +// }); +// }} +// /> +//
+// ); +// }); diff --git a/src/SocialShapeTool.ts b/src/SocialShapeTool.ts new file mode 100644 index 0000000..7403827 --- /dev/null +++ b/src/SocialShapeTool.ts @@ -0,0 +1,9 @@ +import { BaseBoxShapeTool } from 'tldraw' + +export class SocialShapeTool extends BaseBoxShapeTool { + static override id = 'social' + static override initial = 'idle' + override shapeType = 'social' + +} + diff --git a/src/SocialShapeUtil.tsx b/src/SocialShapeUtil.tsx new file mode 100644 index 0000000..b12b6ec --- /dev/null +++ b/src/SocialShapeUtil.tsx @@ -0,0 +1,87 @@ +import { + BaseBoxShapeUtil, + Geometry2d, + HTMLContainer, + Rectangle2d, + TLBaseShape, + TLOnResizeHandler, + resizeBox, + toDomPrecision, +} from 'tldraw' + +export type ValueType = "scalar" | "boolean" | null + +export type ISocialShape = TLBaseShape< + "social", + { + w: number + h: number + text: string + selector: string + valueType: ValueType + } +> + +export class SocialShapeUtil extends BaseBoxShapeUtil { + static override type = 'social' as const + override canBind = () => false + override canEdit = () => false + override getDefaultProps(): ISocialShape['props'] { + return { w: 160 * 2, h: 90 * 2, text: '', selector: '', valueType: null } + } + override onResize: TLOnResizeHandler = (shape, info) => { + return resizeBox(shape, info) + } + override getGeometry(shape: ISocialShape): Geometry2d { + return new Rectangle2d({ + width: shape.props.w, + height: shape.props.h, + isFilled: true, + }) + } + indicator(shape: ISocialShape) { + const bounds = this.editor.getShapeGeometry(shape).bounds + return ( + + ) + } + + override component(machine: ISocialShape) { + return ( + +