Return the file (or whatever type you'd like) to allow the extension to handle it.
If the function doesn't return anything, the file will be ignored. No fileLoader node will be created. The event will still be preventDefaulted.
This can be used to filter out mime types you can't handle with a library like mime. Mime type filtering is not handled by the extension since it can be complicated.
Given a file, should insert a fileLoader node with the loadingId set to a unique key that the extension can then use to find the node again. It should return this key if it inserted the node.
Using the file name is not a good idea as it's not guaranteed to be unique if the user inserts the same item twice.
The default FileLoaderHandler.insertLoadingNode inserts a new item node with a fileLoader node inside after in the closest viable position after the insertPos. It uses a nanoid for the loading id.
Where to insert the fileLoader node.
The default @FileLoaderHandler.insertPosition returns the position after the closest parent item node. The idea being one inserts a new item node there with a loading file node inside.
You can override this by returning a different position. If no position is returned, no node is inserted.
Should load/save/upload the file and return the information neccesary to create the loaded node.
The insertId and editor are provided in case you're uploading the file or doing some other heavy operation and want to update the fileLoader node as soon as you can load the image.
A FileLoaderNodeView is provided (but no pre-configured) for these purposes. If you set the node's preview property it will use it as the src for an image.
This can be used to remove the loading node on errors.
The default FileLoaderHandler.onLoadError uses cleanupFileLoaderNodes to remove the parent item node if possible, otherwise it turns the fileLoader node into a paragraph.
After loading the file, if it's successful, this is passed the result and the position of the fileLoader node.
Note that this position points at the node with those attributes, and not it's parent in the case of having inserted a wrapping node.
A partial implementation of IFileLoaderHandler.
Using the defaults of this class, you only need to specify the handler's
loadFileandreplaceLoadingNodeproperties.It assumes the use of the Item extension since it uses the node to wrap the fileLoader node.
To identify each fileLoader node and fetch it again once the file is loaded, it uses a 10 character nanoid.