diff --git a/src/App.tsx b/src/App.tsx index affbe10..3401bad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,7 @@ import { AgentButton } from "./components/AgentButton"; import { SocialShapeUtil } from "./SocialShapeUtil"; import { SocialShapeTool } from "./SocialShapeTool"; import { CustomToolbar, overrides } from "./ui"; +import { getDocumentMeta, getUserId, getUsersInRoom, setDocumentMeta } from "./storeUtils"; const shapeUtils = [SocialShapeUtil]; const tools = [SocialShapeTool]; @@ -34,6 +35,18 @@ export default function Canvas() { onMount={(editor) => { //@ts-ignore editor.getStateDescendant('select.idle').handleDoubleClickOnCanvas = () => void null; + console.log(editor.store.allRecords()) + const userId = getUserId(editor) + setDocumentMeta(editor, { + [userId]: 123 + }) + // console.log(getDocumentMeta(editor)) + // removeDocumentMeta(editor, 'test') + setTimeout(() => { + console.log(getDocumentMeta(editor)) + console.log(getUsersInRoom(editor)) + }, 2000); + }} components={{ SharePanel: AgentButton, diff --git a/src/SocialShapeUtil.tsx b/src/SocialShapeUtil.tsx index b12b6ec..9143e41 100644 --- a/src/SocialShapeUtil.tsx +++ b/src/SocialShapeUtil.tsx @@ -8,6 +8,7 @@ import { resizeBox, toDomPrecision, } from 'tldraw' +import { getUserId } from './storeUtils' export type ValueType = "scalar" | "boolean" | null @@ -19,6 +20,7 @@ export type ISocialShape = TLBaseShape< text: string selector: string valueType: ValueType + values: Record } > @@ -27,7 +29,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil { override canBind = () => false override canEdit = () => false override getDefaultProps(): ISocialShape['props'] { - return { w: 160 * 2, h: 90 * 2, text: '', selector: '', valueType: null } + return { w: 160 * 2, h: 90 * 2, text: '', selector: '', valueType: null, values: {} } } override onResize: TLOnResizeHandler = (shape, info) => { return resizeBox(shape, info) @@ -39,6 +41,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil { isFilled: true, }) } + indicator(shape: ISocialShape) { const bounds = this.editor.getShapeGeometry(shape).bounds return ( @@ -50,16 +53,22 @@ export class SocialShapeUtil extends BaseBoxShapeUtil { ) } - override component(machine: ISocialShape) { + override component(shape: ISocialShape) { + const currentUser = getUserId(this.editor) + + const handleOnChange = (newValue: any) => { + this.updateProps(shape, { values: { ...shape.props.values, [currentUser]: newValue } }) + console.log(shape.props.values) + } + return ( - -