Allow the user to specify what block type is "default" in the schema
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What’s the current behavior?
In userland, there is what I would estimate to be a nearly universal need to have some concept of a “default” block type. Some use cases for where the concept of the default block is important are:
- Preventing states where the editor is empty (this is probably handled manually by the vast majority of slate editors)
- Knowing what kind of block type to create when a block is split (this is not a core behavior but is sometimes overridden when splitBlock should not copy type)
- Knowing what kind of block type to return to when “toggling” block types from a toolbar (IE Paragraph -> H1, H1 -> Paragraph)
- Knowing what kind of block type to insert to provide padding between some void blocks, or blocks that need to be padded by at least one “simple” block (IE, I place a paragraph between two tables to keep them separated)
- Many plugins I have written or use require knowledge of the default block type, so this has to be passed in via props. It would be nice to for plugins to be able to query the editor for what the default block is instead of having to have it be specified by the user everytime the plugin is contructed
There’s some others.
What’s the expected behavior?
It would be useful for the editor to have some awareness of what the default block type is. This would afford several advantages:
- Most importantly, we could have a core schema rule that prevents the editor from ever being empty, which is a source of many bugs and has to be implemented manually by most users.
- Commands such as ‘insertBlock’ could have a good guess on what kind of block type should be inserted when its invoked.
- We could prevent cases where a block type is somehow missing due to user error by falling back to the default type (debatable).
My recommendation is to provide a top level schema property called default
which is
{
default: String | Object | Fn
}
Where default is either the type string of the block, an object containing the properties of the default block, or a function that generates the default block.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Ownership and user-schema separation in SQL Server
Learn how user-schema separation allows flexibility in managing SQL Server database object permissions. Schemas group objects into separate ...
Read more >GraphQL schema basics
This article describes the fundamental building blocks of a schema and how to create one for your GraphQL server.
Read more >Section schema - Shopify.dev
All block names and types must be unique within each section, and all setting IDs must be unique within each block. Having duplicates...
Read more >Default Schema - an overview | ScienceDirect Topics
Setting the default schema for a user, either a Windows Group (in SQL Server 2012 or higher) or a specific user is an...
Read more >Block - Sanity.io
The block text type supports block styles, lists, decorators (bold, italic, etc.), custom content types (embedded objects), inline objects, and even marking up ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@brendancarney you can have a plugin that expose
getDefaultBlock
queryI believe that this may be fixed by https://github.com/ianstormtaylor/slate/pull/3093, which has changed a lot of the logic in Slate and
slate-react
especially. I’m going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.