-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block conversion update: ability to convert objects with advanced configuration #2824
base: next
Are you sure you want to change the base?
Conversation
According to the workflow script from the documentation: https://editorjs.io/tools-api/#conversionconfig
Thanks for the PR. Could you show the example of the conversion configs in Image Tool and Gallery tools? |
For example, the SimpleImage export I did it this way: export: function (blockData) {
return {
'url': blockData.url,
'caption': blockData.caption
}
} And for ImageTool this way: export: function (blockData) {
return {
'file': blockData.file,
'caption': blockData.caption
}
} And for Gallery I made a universal way to handle both variants, otherwise returning undefined: import: function (exportData) {
if (typeof exportData !== 'object') return;
let blockData = {};
if (exportData.url) {
blockData.files = [{ url: exportData.url }];
} else if (exportData.file) {
blockData.files = [exportData.file];
} else {
return;
}
if (exportData.caption) {
blockData.caption = exportData.caption;
}
return blockData;
} |
The problem now is that Gallery tool in your example knows about other tools: SimpleImage and ImageTool. It is a bad practice for our design. That is why we designed conversion through the string data. As a solution, we can improve ImageTool by supporting multiple images in a gallery-view. |
I interpret this not as the block knows about these tools, but that this block is ready to accept data in a certain format. And Image blocks give their data in a more structured format. So it doesn't mean that Gallery only works with these Image blocks, and that Image blocks will only work with Gallery. They will only be able to have more extended interfaces for sharing structured data. |
Or maybe do something similar to Clipboard, allowing export to text/plain and text/html. HTML5 is advanced enough that it can be used to explicitly deliver various data structures, including lists, image galleries, etc. |
I don't see any options at the moment. Transferring data should be abstracted away from any tool's data format. Maybe markdown would work better that just simple strings. We'll think about it when we'll design a markdown support (in Tools API first of all) |
Hello!
Right now block conversions are performed using a string only, which does not allow for complex conversions.
For example, it will not be possible to convert text blocks separately and image blocks separately, like this:
Right now it is not possible to send a complex configuration from an image block to a gallery block (file data + caption) via string. In addition, there is no conversion filtering now, so if a block exports something, it will be listed for import in all blocks, even if it is not suitable for conversion.
I made a few changes to make it all possible: