You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow draft-aware editor actions and panels for plugins that have a React admin entry
#5082
A trusted native plugin has a React admin (admin.entry) for its settings and dashboard pages. It also wants an editor toolbar action that reads the unsaved draft (admin.editor-draft:read) and proposes changes to it (admin.editor-draft:patch). For example: analyze the draft, then add links and fill in missing image alt text before the entry is published.
The Block Kit editor actions added in 1.5 fit this well: the draft snapshot, the patch, the "Review proposed changes" dialog and the staleness checks are all there.
What happens
Once a plugin has an admin entry, its admin.editorActions and admin.editorPanels are ignored:
React editor panels receive { collection, entry, locale } (ContentEditorPanelContext): the saved entry, not the unsaved draft, and no way to propose a patch.
So a plugin with a React admin has no way to add a draft-aware editor action. The workaround is a second plugin with no admin entry that declares the action and forwards the call to the first plugin. That depends on internals such as locals.emdash.handlePluginApiRoute, which is fragile.
Proposal
Either of these would solve it:
Allow editor extensions next to an admin entry. Let configured plugins with admin.entry also declare editorPanels and editorActions. List them in the manifest separately from adminMode (for example, a hasEditorExtensions flag, or a list the admin reads whatever the mode), and remove the admin.entry early return in getPluginEditorExtension(). Capabilities, draft validation and patch validation stay as they are.
Give React editor panels draft access. Pass the validated draft snapshot to a React panel whose plugin declares admin.editor-draft:read, and give it a way to propose an editor-draft-patch when it declares admin.editor-draft:patch, using the same review dialog.
Option 1 looks smaller and keeps one draft-access path.
Related, smaller
When EmDash rejects a draft before the plugin route runs (a field over the 64 KB limit, or a stale base revision), the admin shows the generic "Plugin action failed". If the admin showed a message for those error codes instead (for example, "This entry is too large for this action" for EDITOR_DRAFT_TOO_LARGE), people would know what happened and what to do.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Use case
A trusted native plugin has a React admin (
admin.entry) for its settings and dashboard pages. It also wants an editor toolbar action that reads the unsaved draft (admin.editor-draft:read) and proposes changes to it (admin.editor-draft:patch). For example: analyze the draft, then add links and fill in missing image alt text before the entry is published.The Block Kit editor actions added in 1.5 fit this well: the draft snapshot, the patch, the "Review proposed changes" dialog and the staleness checks are all there.
What happens
Once a plugin has an admin entry, its
admin.editorActionsandadmin.editorPanelsare ignored:getPluginEditorExtension()returnsnullfor a configured plugin with an admin entry (packages/core/src/emdash-runtime.tsL6649):adminMode: "react"(L4001-L4006), and the admin lists editor extensions only foradminMode === "blocks"plugins (packages/admin/src/lib/sandboxed-editor-extensions.tsL72 and L98).{ collection, entry, locale }(ContentEditorPanelContext): the saved entry, not the unsaved draft, and no way to propose a patch.So a plugin with a React admin has no way to add a draft-aware editor action. The workaround is a second plugin with no admin entry that declares the action and forwards the call to the first plugin. That depends on internals such as
locals.emdash.handlePluginApiRoute, which is fragile.Proposal
Either of these would solve it:
admin.entryalso declareeditorPanelsandeditorActions. List them in the manifest separately fromadminMode(for example, ahasEditorExtensionsflag, or a list the admin reads whatever the mode), and remove theadmin.entryearly return ingetPluginEditorExtension(). Capabilities, draft validation and patch validation stay as they are.admin.editor-draft:read, and give it a way to propose aneditor-draft-patchwhen it declaresadmin.editor-draft:patch, using the same review dialog.Option 1 looks smaller and keeps one draft-access path.
Related, smaller
When EmDash rejects a draft before the plugin route runs (a field over the 64 KB limit, or a stale base revision), the admin shows the generic "Plugin action failed". If the admin showed a message for those error codes instead (for example, "This entry is too large for this action" for
EDITOR_DRAFT_TOO_LARGE), people would know what happened and what to do.Environment
main(1.6.0, b1f93a1)All reactions