Replies: 1 comment
-
@gziolo asked a question on slack, thought I'd answer it here:
I don't believe this exists in a single place. I think there are two things the block editing modes are used for: Distinguishing between local and global content.There's some relevant discussion in this issue: Ensuring local content is not added at the global scope, and vice versa The block editing modes are used when editing to disable the content that's global so that users don't accidentally edit something that applies across a site. It applies to:
Write mode / Zoomed Out / contentOnly lockingissue: Writing and contentOnly modes. These are tools within an editor that aim to reduce the complexity of the block hierarchy by only enabling selection/editing of particular blocks:
After reading this, I think it's also possible to combine the two categories, both aim to lock the design of a piece of content (the structure is locked), while still leaving it possible to edit text and media. Since the question asked about flows, I think it's good to make a distinction between the parts of the editing experience that are implicit (synced patterns, page editing) and those that are optional tools (write mode, zoom out), so that's why I've broken them into two. |
Beta Was this translation helpful? Give feedback.
-
For a while, Gutenberg/WordPress have shipped a stable (but mostly undocumented) feature called 'Block Editing Modes'.
A breakdown of how this feature works:
setBlockEditingMode( clientId, mode )
, wheremode
is one of three options:unsetBlockEditingMode
is an action that removes one of those modes, and the block (usually) implicitly has thedefault
mode again.getBlockEditingMode( clientId )
is a selector that can be used to retrieve the block editing mode for any block.const currentMode = useBlockEditingMode( newMode )
is a hook that can be used as both a getter and a setter. It's used within a block'sedit
function, and automatically determines the block's clientId from React context.This API seems to be increasingly important as it underpins how blocks are interacted for a host of different features (Zoom Out, Write Mode, Synced Patterns, Page Editing, contentOnly template locking).
The API has noble goals, but there are some problems I've noticed or seen discussed. I've listed them below with the initial implementation. It'd be great to discuss ways that this can be improved.
Problems
At the surface, it might seem like quite a simple API, but there are a few problems:
getBlockEditingMode
itself is recursive, but there are also other recursive selectors that call it likeisBlockSubtreeDisabled
. This is exacerbated by the waysetBlockEditingMode( 'disabled' )
oruseBlockEditingMode( 'disabled' )
feel like cheap calls, but can be called from components that aren't well optimized, resulting in repeated setting/unsetting of block editing modes (DisabledNonPageContentBlocks
has this kind of effect when the dependencies change 😓 ).contentOnly
template locking. However, other types of template locking are not built using block editing modes. This results in overly complex logic when determining things likesetBlockEditingMode
is called for the same clientId from different call sites, it results in race conditions, the last call wins.contentOnly
is used for both container blocks (group, pattern etc.) and content blocks (paragraph, heading, image). Other contextual clues are often used to change the way a block works (is the block a section?, what's the block's type?). I think this leads to some hard to answer existential questions like "does this block work like this because it's contentOnly, or because it's a section?".Beta Was this translation helpful? Give feedback.
All reactions