question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow the user to specify what block type is "default" in the schema

See original GitHub issue

Do 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:

  1. 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.
  2. Commands such as ‘insertBlock’ could have a good guess on what kind of block type should be inserted when its invoked.
  3. 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
isubasticommented, Mar 3, 2019

@brendancarney you can have a plugin that expose getDefaultBlock query

0reactions
ianstormtaylorcommented, Nov 28, 2019

I 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found