update tldraw functions for update

This commit is contained in:
Jeff Emmett 2025-09-04 16:58:15 +02:00
parent 1abeeaea10
commit 356a262114
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) => {
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 {
id,
type,
x: Number(x),
y: Number(y),
rotation: Number(rotation),
props: {
...props,
text: cast(props.text, String),
},
props: shapeProps,
meta: m,
}
}

View File

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

View File

@ -182,7 +182,7 @@ export class PromptShape extends BaseBoxShapeUtil<IPrompt> {
if (isShapeOfType<TLGeoShape>(sourceShape, "geo")) {
processedPrompt = processedPrompt.replace(
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 sourceText =
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 {
llm(prompt, (partialResponse: string) => {
const targetShape = editor.getShape(edge.to) as TLGeoShape
editor.updateShape({
id: edge.to,
type: "geo",
props: {
...(editor.getShape(edge.to) as TLGeoShape).props,
text: partialResponse,
} as any,
...targetShape.props,
},
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).url,
(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()