There is one tool that we forgot to implement which can be used for all kinds of elements, both shapes but also our text elements. And that is the delete tool. So let's go ahead and quickly implement that one. Let's start by going inside of our use editor hook and inside of our build editor here let's quickly add another method. I'm gonna add it right here at the top.
It's simply going to be called delete and inside of here what we're going to do is we're going to get the current selected object so canvas get active objects for each get the object and we are going to call canvas dot remove and we are going to pass in the current object in the iteration. So pass in the object like this. After we've removed the object we have to discard the current active selection. Canvas.discardActiveObject and then we have to call canvas render all. There we go.
So this is how we are going to remove or delete currently selected objects. Now we have to go inside of the types of the editor and we have to add delete. It's a very simple method which is a simple void. Now we have to go inside of our toolbar component right here and let's simply go to the end. Let's copy the last one which is the transparency grid button and we're going to change this one to be the hint delete and the button will simply render the trash icon from Lucid React We're not gonna have any custom class name here.
So this can never be active It can only be clicked and inside instead of calling this it will call editor delete like this Let's go ahead and check it out now. So I'm going to refresh everything here and let me add a shape. There we go. I can now click delete and there we go. It gets deleted.
Let's try with multiple shapes so it should be able to select both of them and click delete. There we go. And finally let's try with text. Delete. Perfect.
So we successfully finished all generic elements for our toolbar and we also have all the elements for our text element. Now what we have to do is we have to implement the image object. So there will be several ways we can add images. The first way will be to call the Unsplash API. Then we're going to implement AI to generate the image and we're also going to have the upload functionality.
Great great job.