Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/Board/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type BoardActions = {
downloadImage: () => void;
drawObject: (type?: "rectangle" | "polygon") => void;
retrieveObjects: () => CanvasObject[];
retrieveObjectContent: (id: string) => string | null;
};

const Board = React.forwardRef<BoardActions, BoardProps>(
Expand All @@ -58,6 +59,16 @@ const Board = React.forwardRef<BoardActions, BoardProps>(
setCurrentZoom(100);
onResetZoom?.();
},
retrieveObjectContent(id: string) {
const polygonId = fabricUtils.toPolygonId(id);
if (editor?.canvas) {
const obj = fabricUtils.findObjectByName(editor.canvas, polygonId);
return obj
? getObjectInfo(obj as fabricTypes.CustomObject).content ?? null
: null;
}
return null;
},
deselectAll() {
editor?.canvas.discardActiveObject();
},
Expand Down
8 changes: 8 additions & 0 deletions src/components/Board/__docs__/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ const Example: FC<BoardProps> = ({ items, image }) => {
>
Retrieve Objects
</button>
<button
onClick={() => {
const obj = ref.current?.retrieveObjectContent("1");
console.log(obj);
}}
>
Show content of: 1
</button>
</div>
<div style={{ display: "flex", gap: "10px" }}>
<div
Expand Down