I only wanted to have a button to open and close the sidebar, like
“regular” site editor does in WordPress. Apparently, this is done via
a “pinned” slot/fill thing, that make the visibility of that button a
user decision, by default—WordPress removes the pin button to avoid
that.
The thing is that it does not work: ComplementaryArea adds a
ComplementaryAreaToggle in the PinnedItems fill, and that toggle is a
button-like compenent that calls enableComplementaryArea or
disableComplementaryArea on the interface store, however
disableComplementaryArea does **not** update the interface store,
instead updates preferences, meaning that the useSelect inside the
toggle, that only subscribes to the interface store, is never called
when the area is disabled, and can not be enabled again with that
toggle button.
I worked around the issue by adding
dispatch({
type: 'ENABLE_COMPLEMENTARY_AREA',
scope,
area: undefined
});
at the end of disableComplementaryArea. I suspect this is not the
proper solution, and that there must be another way, because WordPress
does not exhibit that behaviour, however it signals that there _is_ an
error in the library, but i could not find any bug report within the
5k+ issues currently reported to Gutenberg’s project.
For now, it will do.
It makes more sense, i believe, to enable the sidebar complementary
area from within the sidebar component, as this is called when the
component is included in the hierarchy.
I also moved the scope string to a constants file, so i can find where
it is used with code analysis instead of relaying on grep.
I want this only to later on show the sidebars with the inserter and
inspector, but for now, since i do not understand yet how i am
supposed to use ComplementaryArea, i add the interface with the
breadcrumb at the bottom.
The FullscreenMode block is to “cancel out” the 160px margin on the
left, and 32px on the top, that @wordpress/interface’s style add by
default.
Despite the fact that Gutenberg developers did not care at all about
uses of this library outside WordPress until last year[0], and that it
is almost impossible to do something that goes beyond the very basic
without using “private APIs”, they insist that the isolated block
editor should be “deprecated”[1].
I do not particularly care much about the isolated block editor, as it
_does_ use all these private APIs and, thus, it is very difficult to
use unless you use the exact same dependencies, otherwise it emits a
weird error regarding “unlocking” things that are not “locked” (i.e.,
the new-fangled way of “protecting” private APIs[2]). And,
apparently, things got easier with Gutenberg 18.5 with the
introduction of the BlockCanvas.
However, it is still a very frustrating experience, and the
documentation for most components and packages is next to
non-existent.
Nevertheless, i managed to get a barely functional editor that still
has some missing features, like the color of rich texts’ highlight
format[3], but it i believe it is a good base to grow the custom
editor on top of.
[0]: https://github.com/WordPress/gutenberg/issues/53874
[1]: https://github.com/WordPress/gutenberg/issues/57672#issuecomment-1883119040
[2]: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-private-apis/
[3]: https://github.com/WordPress/gutenberg/issues/55036
Gutenberg uses its own @wordpress/i18n for internationalization, which
is not much more than a wrapper around tannin[0], a reimplementation of
Jed[1].
It uses the same brain-damaged idea of all JavaScript applications: load
a really huge JavaScript object with the source text as key, and the
translations, if there are plurals, as values. That is what they call
“a gettext localization library”.
The problem now becomes: how do i extract the translatable strings from
the libraries?
Isolated Block Editor’s maintainer stance is very clear: “It’s
Gutenberg, so whatever you need to do there will work the same”[2]. In
other words, “don’t know; don’t care”.
Let’s see what Gutenberg people say.
Well, Gutenberg may not require WordPress, but their developers sure
assume that you are using WordPress[3], and if you complain then their
response is “Why do you think using wp-cli is not easy enough?”[4].
Apparently, before wp-cli they used @wordpress/babel-plugin-makepot,
that creates a POT file for each JavasScript processed with WebPack,
but does not extract the strings from imported packages. Which is kind
of logical, but then where do i get the required JSON files i need to
load to translate their fucking overly complex piece of crap?
Or, said in another way, how does WordPress do it? Apparently, they do
the same they do for every other plugin[5]: with GlotPress[6].
That _would_ work if i used the exact same versions as the plugin does,
but it would not help me translate the strings from
@automattic/isolated-block-editor because they are **not** a WordPress
plugin. And, as we saw previously, the maintainer does not care.
Well, i have to extract them myself somehow. Using the uglies hack i
could muster, apparently, because wp-cli i18n refuses to extract strings
from inside node_modules: create a symlink from each source directory i
need to translate into my po folder, and use their beloved wp-cli i18n
to create the po, including the strings from my source.
Then i downloaded the plugin PO file to include the official translation
to Spanish, and wrote a couple to test whether these from Isolated Block
Editor were being correctly extracted.
However, i can **not** use wp-cli i18n to generate the JSON file because
the fucking thing wants to generate a single JSON file for each
JavaScript source file, thus generates around 650 JSON files.
Are we mad?!
The author of Jed recommends po2json and at this point i do not really
care if i need yet another fucking tool for this. Just do it, but make
sure it is Jed’s 1.x version, otherwise “modern” Gutenberg does not know
what to do with the translations.
What a shitshow.
[0]: https://github.com/aduth/tannin
[1]: https://github.com/messageformat/Jed.
[2]: https://github.com/Automattic/isolated-block-editor/issues/195#issuecomment-1359566724
[3]: https://github.com/WordPress/gutenberg/issues/14803#issuecomment-479823416
[4]: https://github.com/WordPress/gutenberg/issues/14803#issuecomment-479581903
[5]: https://github.com/WordPress/gutenberg/issues/13535#issuecomment-458678681
[6]: https://developer.wordpress.org/block-editor/contributors/localizing/
I am using it to create the editor element, and it is already pulled
by @automattic/isolated-block-editor, but IntelliJ complains that i do
not have it in **my** package.json.
It seems that IntelliJ has problems with the idea of keeping objects
in a schema other than public, and freaks out when it can not find the
relations in the code that he clearly lists on the sidebar.
It is just a test to see whether the block editor loads, because it is
not so easy: it requires specific versions of the dependencies, or it
will fail with some idiotic syntax errors after failing to “convert” the
libraries code.
And it is impossible to use with Vite: it refuses to accept incorrect
SCSS code, that WordPress has a lot of, with things as `::after::after`.
What i did is write my package.json, replace the generated lock file
with the one from Isolated Block Editor, and npm install again, to
“clean up” the lock file.
Most of the code comes from Numerus, except that i replaced the router
with a simpler chain of handlers that i already used with some success
in other projects that feels a little cleaner.