-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Gutenberg as a framework: streamline the experience #53874
Comments
https://github.com/Automattic/isolated-block-editor/ is likely a good indicator of the additional scaffolding currently needed to use Gutenberg in a more isolated environment. #46693 has discussions about the potential advantages of reducing the footprint needed to utilize Gutenberg/WordPress packages. |
Thanks for starting this! |
+1 thanks for writing this up!
It could be good to break this out into a separate issue, but just adding a couple of thoughts and previous discussions for this one:
From those discussions, it sounded like dynamic injection was preferable for a few reasons:
Those discussions also raised the downside that 3rd party editors would need their own approach for outputting dynamic styles. So, it's good to raise that here. I like the idea of a canonical approach for 3rd party editors to "switch on" rendering output of block supports in some way via a render function. Overall, is the goal to still move toward a state where styles are all generated dynamically, or is it more of a case-by-case scenario depending on the kind of block supports we're designing/working with?
In terms of how we define when to dynamically inject styles, would a potential solution be to have a boolean flag somewhere, where we flag whether or not to output at render time? Some block supports (e.g. layout and elements) in JS are hooked in to output only within |
@andrewserong Please go ahead with the issue, we can link to it from here. I agree that this deserve its own issue. At the moment, I didn't give too much thoughts and I'm not too opinionated. All what I can say is that we should provide third-party editors with a way to retrieve the final HTML for these static blocks (paragraph, headings....) including all the block supports that are not really dynamic (don't depend on any server-side stored value). I don't think the decision to store the styles inline or not need to change, it's fine we're opinionated there per block support but third-party editors (JS only) should be able to render the posts properly without writing PHP and just calling a function we provide. |
I wonder if each block should be its own package. That's what I was considering for footnotes at first. CKEditor for example does this: https://ckeditor.com/docs/ckeditor5/latest/api/paragraph.html |
Thanks for the extra context @youknowriad! I've opened up a separate issue for this in #54047 and linked it in the issue description. Feel free to edit as needed 🙂 |
It’s already possible to import individual blocks which isn’t that far from as if they were in separate packages and it’s documented in: |
@gziolo oh that's really cool, I missed that I think. it would be cool to have a dedicated entry point in block-library that is for universal blocks only (blocks that don't require server side code to work fully). |
@ellatrix for the typewriter mode, I decided not to bundle it for now. I hesitated about whether I should add a flag to enable it in |
Not sure I understand, components is a dependency of block-editor, right?
Even if we distinguish between WP and generic blocks, block-library has core-data as a dependency so anyone installing it will get that bundled in. Perhaps we could have two packages instead? like |
Yes, but when you do Our packages do ship CSS files but the consumer has to include them manually gutenberg/platform-docs/docs/intro.md Lines 83 to 90 in 1cfad2c
Yes that's one option, that's the work we need to do: rule out all WP specific dependencies and potentially have a way to "augment" the blocks that are "mixed". In the sense that some blocks are in general "universal" but when they are used within WordPress, they need to check the post or something, so we need to figure out if we can have a way to filter/extend/augment these blocks in the wordpress specific package. |
Status update:
There's a lot of remaining work though (and some big undertakings). These are the things I'd love if we could tackle next:
Any help with these things would be highly appreciated. |
Hello, In relation to this issue, I thought it would be helpful if a list of required API endpoints and expected return values were documented for core blocks. *I am currently trying to get gutenberg to work in a ruby on rails environment. For example, I struggled with other issues related And I'm currently tackling to implement Anyway, thank you very much for working on making gutenberg usable as a framework. There are countless wysiwyg editors, but I don't think there is any other wysiwyg editor that is so practical as a "site builder" than gutenberg. |
@kohheepeace oh that's a big undertaking, it's exciting to see where you can take this. While the current issue is about the reusability of the "block-editor" package, I do think we need to tackle the reusability of the "editor" package at a more global level at some point. Which means relying on the "core-data" package as an API abstraction. I'd love if we can at some point offer an official API to build an "adapter" for the "core-data" to connect it within API for persistence (another REST API for instance) |
=> I can't picture it clearly now, but I'm looking forward to it 👍. Additionally, along with this, there is another a bit troublesome task: the generation of the Currently I create I hope this process become easier (maybe JS equivalent of *sorry for my greed to request out-of scope. |
Status update: We now have a temporary location for the Gutenberg as framework website where we can iterate on. As discussed here WordPress/wporg-main-2022#379 we might want to move this to |
There's no intention of abandoning the iframe container. It's kind of the opposite shouldIframe default to true and it's a private API because we want most block editors to always use the iframe. |
No problem at all, I am happy to answer questions and clarify what needs to be clarified :) |
Finally I'm doing the refactoring for the whole Drupal Gutenberg using this framework. From my initial implementation (following the documentation), here's some issues I'm having:
If anyone has any tips to help solve those issues I would appreciate it 😉 cc/ @youknowriad |
@vonloxx Thanks for the comment, Do you think it would be possible to have a codesanbox or something like that with an isolated block editor to be able to reproduce and isolate some of these more easily. |
This seems to be related to the footnotes. I left a comment on #51201 with a potential fix. |
Did you consider a 100% height instead? to avoid double scrollbars... |
I ended up resolving using a component with a resize observer (and mutation observer). It simply observes the content height of the iframe's body and set the iframe's height accordingly. It works great ;) |
It’s a bit of a digression but I'm curious about this. Is the mutation observer used to limit the responses to the resize observer? I ask because trying to size an iframe by its content’s height tends to create infinite loops when heights of any contained elements depend on |
@stokesman Actually adding two mutation observers, one for the closest container of the iframe (to wait for the iframe) and when the iframe is found, disconnect the observer and another observer is added to the iframe to look for the body when available. After the body is found, I add the resize observer to the iframe's body and disconnect the last mutation observer. |
Gutenberg can be used as a platform/framework to build block editors. Mainly thanks to the
@wordpress/block-editor
package. That said, the experience today is not as straightforward as it can be. There can be a lot of small gotchas and hacks you need to do in order to achieve the desired result. This issue is going to serve as an overview issue to collect and fix all these issues.@wordpress/*
packages using npm shows a number of warnings due to unmet peer dependencies, with the latest updates to npm, we should make sure we're using peer dependencies properly. For instance it seems that React shouldn't be a peer dependency for us but instead a real dependency of@wordpress/element
since this package is supposed to be used as a replacement for React.process.env.something
in a lot of places in Gutenberg codebase. All JS environments do not provide these, for instance Vite relies onimport.meta.env
instead. We need to at least not break the JS execution ifprocess
is undefined. Assess whetherimport.meta.env
is a better alternative these days.<BlockEditorProvider><BlockCanvas /></BlockEditorProvider>
should be enough to render the most basic block editor. Today, we're forced to render a number of wrappers and providers or else the experience is broken. Find a way to bundle these providers or make them optional (bundle them if the provider hasn't been rendered already)<BlockEditorKeyboardShortcuts.Register />
Register the block editor keyboard shortcuts automatically when using BlockEditorProvider #53910<WritingFlow>
BlockEditor: Add BlockCanvas component = Iframe + BlockList + WritingFlow #54149<ObserveTyping>
Bundle ObserveTyping within the BlockList component #53875<Popover.Slot />
Components: Make the Popover.Slot optional #53889<ShortcutProvider />
Make the shortcuts provider optional #54080<SlotProvider />
Bundle SlotFillProvider within BlockEditorProvider #53940useClipboardHandler
andCopyHandler
Bundle the block copy handler within the BlockCanvas component #54207useBlockSelectionClearer
andBlockSelectionClearer
Bundle the block selection clearer hook into the BlockCanvas component #54209useTypewriter
andTypewriter
(check if we should bundle or not)cc @WordPress/gutenberg-core
The text was updated successfully, but these errors were encountered: