update tldraw functions for update

This commit is contained in:
Jeff Emmett 2025-09-04 16:58:15 +02:00
parent 5fe28ba7f8
commit 947bd12ef3
5 changed files with 24 additions and 14 deletions

View File

@ -77,16 +77,20 @@ const unpackShape = (shape: any) => {
const cast = (prop: any, constructor: (value: any) => any) => { const cast = (prop: any, constructor: (value: any) => any) => {
return prop !== undefined ? constructor(prop) : undefined; return prop !== undefined ? constructor(prop) : undefined;
}; };
// Only add text property for shapes that support it (like text shapes)
const shapeProps = { ...props }
if (type === 'text' && props.text !== undefined) {
shapeProps.text = cast(props.text, String)
}
return { return {
id, id,
type, type,
x: Number(x), x: Number(x),
y: Number(y), y: Number(y),
rotation: Number(rotation), rotation: Number(rotation),
props: { props: shapeProps,
...props,
text: cast(props.text, String),
},
meta: m, meta: m,
} }
} }

View File

@ -41,12 +41,12 @@ export function Inbox() {
props: { props: {
w: shapeWidth, w: shapeWidth,
h: shapeHeight, h: shapeHeight,
text: messageText, fill: "solid",
align: "start", color: "white",
verticalAlign: "start", },
} as any,
meta: { meta: {
id: messageId, id: messageId,
text: messageText, // Store text in meta instead of props
}, },
} }
let found = false let found = false

View File

@ -182,7 +182,7 @@ export class PromptShape extends BaseBoxShapeUtil<IPrompt> {
if (isShapeOfType<TLGeoShape>(sourceShape, "geo")) { if (isShapeOfType<TLGeoShape>(sourceShape, "geo")) {
processedPrompt = processedPrompt.replace( processedPrompt = processedPrompt.replace(
pattern, pattern,
(sourceShape.props as any).text, (sourceShape.meta as any)?.text || "",
) )
} }
} }

View File

@ -355,7 +355,7 @@ export const overrides: TLUiOverrides = {
const sourceShape = editor.getShape(edge.from) const sourceShape = editor.getShape(edge.from)
const sourceText = const sourceText =
sourceShape && sourceShape.type === "geo" sourceShape && sourceShape.type === "geo"
? ((sourceShape as TLGeoShape).props as any).text ? (sourceShape.meta as any)?.text || ""
: "" : ""
@ -366,13 +366,17 @@ export const overrides: TLUiOverrides = {
try { try {
llm(prompt, (partialResponse: string) => { llm(prompt, (partialResponse: string) => {
const targetShape = editor.getShape(edge.to) as TLGeoShape
editor.updateShape({ editor.updateShape({
id: edge.to, id: edge.to,
type: "geo", type: "geo",
props: { props: {
...(editor.getShape(edge.to) as TLGeoShape).props, ...targetShape.props,
text: partialResponse, },
} as any, meta: {
...targetShape.meta,
text: partialResponse, // Store text in meta instead of props
},
}) })
}) })

View File

@ -17,7 +17,9 @@ export const searchText = (editor: Editor) => {
(shape.props as any).value, (shape.props as any).value,
(shape.props as any).url, (shape.props as any).url,
(shape.props as any).description, (shape.props as any).description,
(shape.props as any).content, (shape.props as any).content,
// For geo shapes, also check meta.text
shape.type === 'geo' ? (shape.meta as any)?.text : undefined,
] ]
const termLower = searchTerm.toLowerCase() const termLower = searchTerm.toLowerCase()