Rich Editor: why does a null state become a paragraph? Working on a PR for forced content structures
Hi!
I am currently working on a PR to support forced content structures (as seen in https://tiptap.dev/docs/examples/advanced/forced-content-structure) in the Rich Editor which will allow you to do something like this:
I quickly ran into the issue that the Rich Editor always forces an empty paragraph when the state is null, as seen here:
Snippet from RichEditorStateCast.php
This conflicts with the contentStructure feature, since you could configure that to start with a heading - or any other block - instead. I'm sure there is a good reason for the empty paragraph state which I would love to know about. I'm considering a few options to solve this in my PR:
Option 1: leave the state at
null
in RichEditorStateCast.php
whenever a contentStructure is specified
Option 2: add something like RichEditor::make('content')->contentStructure('heading block*')->omitInitialParagraph()
Option 3: leave it to the user to pass a default structure when using contentStructure, for example: However: this seems to cause issues with the ->require()
validation
Would love your input for this matter!2 Replies
I think it's just the default of TipTap. Nothing that Filament applies.
@Dennis Koch it is something that Filament applies though, see the
RichEditorStateCast.php
snippet in my post. I didn't encounter that behaviour in the filament-tiptap-editor package or Tiptap itself when I applied a content structure there. So that made me wonder why an empty paragraph is the default state, since there might have been a good reason it has been put there