allow children and prevent rerender issue
This commit is contained in:
parent
76d959cd35
commit
0a43ca26ed
|
|
@ -3,6 +3,7 @@
|
||||||
import { LiveImageShapeUtil } from "@/components/live-image";
|
import { LiveImageShapeUtil } from "@/components/live-image";
|
||||||
import * as fal from "@fal-ai/serverless-client";
|
import * as fal from "@fal-ai/serverless-client";
|
||||||
import { Editor, Tldraw } from "@tldraw/tldraw";
|
import { Editor, Tldraw } from "@tldraw/tldraw";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
fal.config({
|
fal.config({
|
||||||
requestMiddleware: fal.withProxy({
|
requestMiddleware: fal.withProxy({
|
||||||
|
|
@ -13,7 +14,7 @@ fal.config({
|
||||||
const shapeUtils = [LiveImageShapeUtil];
|
const shapeUtils = [LiveImageShapeUtil];
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const onEditorMount = (editor: Editor) => {
|
const onEditorMount = useCallback((editor: Editor) => {
|
||||||
// If there isn't a live image shape, create one
|
// If there isn't a live image shape, create one
|
||||||
const liveImage = editor.getCurrentPageShapes().find((shape) => {
|
const liveImage = editor.getCurrentPageShapes().find((shape) => {
|
||||||
return shape.type === "live-image";
|
return shape.type === "live-image";
|
||||||
|
|
@ -28,7 +29,7 @@ export default function Home() {
|
||||||
x: 120,
|
x: 120,
|
||||||
y: 180,
|
y: 180,
|
||||||
});
|
});
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex min-h-screen flex-col items-center justify-between">
|
<main className="flex min-h-screen flex-col items-center justify-between">
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {
|
||||||
ShapeUtil,
|
ShapeUtil,
|
||||||
TLBaseShape,
|
TLBaseShape,
|
||||||
TLEventMapHandler,
|
TLEventMapHandler,
|
||||||
|
TLShape,
|
||||||
useEditor,
|
useEditor,
|
||||||
} from "@tldraw/tldraw";
|
} from "@tldraw/tldraw";
|
||||||
|
|
||||||
|
|
@ -96,7 +97,7 @@ export function LiveImage() {
|
||||||
setImage(result.images[0].url);
|
setImage(result.images[0].url);
|
||||||
}
|
}
|
||||||
}, 16),
|
}, 16),
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -155,6 +156,13 @@ type LiveImageShape = TLBaseShape<"live-image", { w: number; h: number }>;
|
||||||
export class LiveImageShapeUtil extends ShapeUtil<LiveImageShape> {
|
export class LiveImageShapeUtil extends ShapeUtil<LiveImageShape> {
|
||||||
static override type = "live-image" as const;
|
static override type = "live-image" as const;
|
||||||
|
|
||||||
|
override canReceiveNewChildrenOfType = (
|
||||||
|
shape: LiveImageShape,
|
||||||
|
type: TLShape["type"]
|
||||||
|
) => {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
getDefaultProps(): LiveImageShape["props"] {
|
getDefaultProps(): LiveImageShape["props"] {
|
||||||
return {
|
return {
|
||||||
w: 1060,
|
w: 1060,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue