-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Change viewportTopOffset config. Make viewportTopOffset writable in runtime #10352
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the right direction 👍
I read your comments @dawidurbanski but instead of replying under individual lines of code, I decided to fork your solution (ck/9672-modify-viewporTopOffset-in-runtime-v2
) with a single commit so it is easier to understand what direction I think would be the best. And besides, unlike GH comments, you can run it straight away 😀
In short,
- to avoid code duplication, I'm for moving the offset normalization to
EditorUI
. All editors with the UI inherit from this class so it's a safe spot IMO.- this makes the runtime config available for developers under
editor.ui.viewportOffset
- alternatively: this could be moved from
EditorUI
toEditorUIView
. The only drawback is that the view needs to obtain the editor config via constructure which is, um..., an antipattern (our architecture assumes UI views are completely decoupled from the editor), but I guess this would also work. The property would beeditor.ui.view.viewportOffset
. - now that I think about it,
EditorUIView
could be a better place becauseEditorUI
is a controller (glue) and this whole situation is just pure geometry (presentation). All editors with the UI useEditorUIView
at some point. WDYT?
- this makes the runtime config available for developers under
- speaking of
viewportOffset
(instead ofviewportTopOffset
), I think it would be best if we made it future-proof and, as you correctly assumed in your code, used an object withtop
,bottom
,left
,right
properties. For now, only thetop
makes sense but this will change one day.- the implementation in the twin issue (the one with the "sticky position") allows restricting the viewport Rect from all sides, anyway, so these changes would work together out-of-the-box.
- moving on, I bound
editor.ui.view.stickyPanel.viewportTopOffset
(Classic) andInlineEditorUIView.viewportTopOffset
(Inline) toEditorUI#viewportOffset
.- this way, the whole viewport offset situation is transparent to developers. They don't need to worry about which editor type is used and which property should be changed in the runtime. There's a single source of truth for all editors with UI.
Thanks @oleq !
Let's stick to the the I rebased your I also added some missing pieces, small refactoring, tests, some initial docs, and proper comments in 83b130c commit. The only thing left now is to update rest of the docs including snippets and it should be job done. I'm going to complete it soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm done with my review. The change works - the top offset is writable in runtime.
There are two things that I'd want to add:
- The migration guide is necessary and it doesn't need to be part of this ticket, but we need to do it. Please open a followup and ping me about it.
- It's a pity that the toolbar doesn't change its position once you update
editor.ui.viewportOffset
. I also checked if callingeditor.ui.update()
works but it doesn't. Could you make a quick check whether there's an option to update (recalculate) the position of it on demand. If so, please report a followup ticket too.
…ocusing out of the editor
Done: #10401
In these two tests:
We actually just set new Apparently focusing out and back in is sufficient to reposition the toolbar. Example: const newOffset = 200;
document.documentElement.style.setProperty( '--top-offset', `${ newOffset }px` );
editor.ui.viewportOffset = { top: newOffset };
editor.editing.view.focus(); I added an additional, naive case to both of these tests. An another button to start updating top offset randomly in two seconds interval. This way we do keep focused in the editor while offset is being updated. Indeed in such case editor toolbar does not get updated. I found we just need to fire Example: const newOffset = 200;
document.documentElement.style.setProperty( '--top-offset', `${ newOffset }px` );
editor.ui.viewportOffset = { top: newOffset };
editor.editing.view.document.fire( 'layoutChanged' ); In my opinion It's just a matter of proper docs to describe these cases. I created a ticket for it as well: #10402 |
That's the case to worry about. It's clear that re-focusing resolves this issue. And it's good there's even a better workaround with |
FYI: The merge commit message that I went with:
|
…rTopOffset-in-runtime Feature: Introduced `editor.ui.viewportOffset` that allows modifying the viewport's offset in runtime. This value is used by the editor to e.g. position its sticky toolbar and contextual balloons. Additionally, the `config.toolbar.viewportTopOffset` property was moved to `config.ui.viewportOffset` and it now accepts an object. Closes ckeditor#9672. BREAKING CHANGE: The `config.toolbar.viewportTopOffset` property was moved to `config.ui.viewportOffset` and it now accepts an object.
Looks like this also unblocked https://www.drupal.org/project/drupal/issues/3259380 per @lauriii! 🥳 |
WIP (check additional information)
Suggested merge commit message (convention)
Type: Change viewportTopOffset config. Make viewportTopOffset writable in runtime. Closes #9672.
Additional information
I added couple
TODO
comments to point out some stuff that could be improved in this PR IMO.@oleq if you would find some time to check this one it would be awesome.
These two manual tests are best to see this in action:
Follow ups on this one:
Update all our tests to use the new config (done in d114b6bui.viewportOffset.top
instead oftoolbar.viewportTopOffset
)Update all docs snippets to use the new configdone in e4429e5Update docs to reflect this changedone in be2339dUpdate TODOs when discusseddone in 39597fd and 83b130c