-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor to match Gutenberg architecture #561
Comments
Also noting that there is a difference between the mime types supported by WordPress and the mime types supported by the media queue. For example, WordPress might not support HEIC by default and would block the file upload. However, the media queue happily takes that file and converts it to a JPEG. |
@youknowriad @ntsekouras Pinging you two directly since you expressed interest in reviewing the code further. Feel free to ping others as well. I did the main change now, which was to separate the processing & upload concerns. In a nutshell, it currently looks like this:
It didn't feel right to move more out of I would appreciate it if you could take some time to test the plugin, go through the code and provide some high level feedback about it. Each package and each action, reducer and selector has extensive documentation and there's good e2e test coverage as well. That should make it possible to delve into the project and gain a better understanding. |
Does this mean that we could apply this for suggesting WP allowed mime types, that a user would have to convert in order to upload? What other applications would this have in WP context? |
That's how it works today in WP: if you drop an exotic file into the editor, you will get a notification that the mime type is not supported. Then you would need to convert it manually in order to upload. HEIC is such an example (depending on server support). This project now makes it possible to convert such files automatically in the browser before upload, so that you don't have to worry about it. Does that answer your question? |
Been looking at the codebase for a bit and it seems to me it's in the right direction. There's so much code though, that more eyes are needed. I'd expect when we integrate this to GB, references and usage of Also noting that while testing by downloading the plugin, if I had GB trunk enabled it would break the editor. Not sure why.. |
It would probably help if we start having some GB PRs for integrating the functionality. It's going to be easier to review specific change sets and will reveal any challenges and changes needed to follow the suggested architecture. |
No. The only references to
Hmm I will need to look into that. It's related to the cross-origin isolation and the iframed editor. Not sure when that changed, as I used to run GB trunk frequently in the past.
I would appreciate a high-level review first before I spend a significant time porting over the first chunks only to realize that XYZ is missing or wrong and I need to redo the whole thing. The After that, yes, the idea is to start with some smaller PRs step by step. You can see the proposed roadmap at WordPress/gutenberg#61447 |
Personally I feel that the high level feedback was about the store and where parts of the code would fit in GB packages. The queue seems fine and could potentially be used for other parts in GB in the future and you've already made updates to decouple WP specific parts from media-utils, etc.. We can wait for more opinions though.. The UI will need design feedback of course, but that will be part of the GB PRs. With such PRs, possible integration issues will be easier to identify and some review questions about implementation details might be raised. In general by testing the plugin, everything seems to be working quite well and it seems to be in the right direction to integrate. I guess something that I haven't checked and we need to know, is whether the libraries used here are compatible with GB licence. I'm not an expert in this domain though and if there is some uncertainty, we should ping some folks who know more about this. |
For the initial implementation as per the suggested roadmap there are no license concerns, all dependencies are fully GPL compatible. See #322. The only question mark is about libheif-js, as previously discussed in this thread. See also #483. As long as there is this question mark, it will not be added to GB. In the meantime, other folks are working on server-side HEIC conversion, where the license isn't an issue. |
@youknowriad @ntsekouras I started a draft PR at WordPress/gutenberg#64278. Still in early stages with failing tests etc. but it's getting there. Maybe you wanna already take a look. |
From working on WordPress/gutenberg#64845 I noticed how customized Gutenberg's build tooling is, so it took a bit to make things like wasm & web workers work. In WordPress/gutenberg#64278 I noticed how different it would be to pass block editor settings and the like. |
I'm splitting this out from WordPress/gutenberg#61447 (comment) where @youknowriad has asked to basically split up the media handling/queue logic from the WP-specific upload logic so that the whole queue store can live in
@wordpress/block-editor
.The
uploadMedia()
function itself from@wordpress/media-utils
would be basically the same, just taking a file and uploading it to a server. This way, every block editor implementation can benefit from the image processing capabilities, andmedia-utils
remains stateless.So far, the code has been written with this architecture in mind:
block-editor
requires amediaUpload
setting, and without it does not support uploads by default. Is platform-agnostic.media-utils
exposes amediaUpload
function that validates files, adds items to a queue, handles compression, etc. Is WordPress-specific.editor
package wrapsmediaUpload
frommedia-utils
to add the post ID and provides the function as a setting toblock-editor
. Is WordPress-specific.But the goal is:
block-editor
should now gain all the capabilities for the upload queue and compression etc. The final file is passed to themediaUpload
function passed via settings. If the setting is missing, it still doesn't support uploads by default.media-utils
does not change, it simply takes a file and uploads it to WordPress.editor
also does not change, it still wrapsmedia-utils
to provide the post ID.Things like sideloading will require either additional arguments to
mediaUpload
or a newmediaSideload
setting or so.I'm using this issue to keep track of all the work to make this happen, and write down ideas.
Thoughts / questions so far:
@wordpress/editor
callswp.data.dispatch( 'core/block-editor').updateSettings()
to pass themediaUpload
function for uploading to WordPress.wp.data.select( 'core/block-editor' ).getSettings.mediaUpload()
for uploading. But that one must first add items to a queue and then call the actual one passed from@wordpress/editor
. So it must not actually expose the "raw" upload function.block-editor
will want do basic mime type validation likeuploadMedia
does before adding to the queue. Require another setting for this?block-editor
usesgetSettings().validateMedia
-> add to its queue -> once finished, callgetSettings.uploadMedia()
block-editor
(or the upload package it depends on) must expose some more functionality than justuploadMedia
, like the various state selectors, etc.optimizeExistingItem
for optimizing an existing image/video orisUploadingById
for knowing whether a current image in the editor is already being processed.upload-media
package:mediaSourceTerms
will need to be handled at theeditor
level — or simply removed.mediaUpload
frommedia-utils
? So move that post-upload logic there? 🤔The text was updated successfully, but these errors were encountered: