Open xanthipe opened 3 months ago
Your directive editor is actually working correctly. If you start the editor with markdown that includes the directive, it should work as expected. the problem is that insertDirective
wraps the inline nodes into a paragraph. See the implementation as a reference.
A workaround I may suggest is to bypass the insertDirective
and use the Lexical API directly for the insertion. A proper solution is to implement an explicit insertInlineDecoratorNode
-> insertInlineDirective
API.
I will leave this open, I hope I can get to it at some point. If you're interested, I'm happy to accept a PR.
Regarding the types - accessing the TextDirective type is actually fine I think, but I might be wrong. Re-exporting the numerous APIs of Lexical and mdast is close to impossible.
Ah, that all makes sense - I'll use the existing insertDirective tag for now on the project to get the ball rolling, and hopefully (although as you can probably guess by the two week reply delay I don't have a lot of time to work on this) I can have a look at doing a PR for you to sort it properly.
And yes, I can see how doing a full re-export would be a pain in the backside - possibly just a note in the current example? Although I was also getting some type conversion issues as well, but that's probably a side-effect of the same inline-vs-block problem.
If you want to ask for support or request features, sponsor the project and contact me over email.
Describe the bug For a project I'm working on, I need to be able to provide my end-user with the ability to apply some basic text formatting (particular combinations of colour, decoration etc). I've got most of it working with a custom editor, but even though I'm setting things up as an inline text directive it keeps adding a linebrak tag after the editor.
Reproduction Start from https://codesandbox.io/p/sandbox/mdx-editor-base-q8s7zr?file=/src/App.tsx to reproduce the problem so that I can observe the issue on my side and make sure that the fix reliably addresses it.
To Reproduce Steps to reproduce the behavior:
Expected behavior As it's a text directive, I'd expect to be able to continue typing inline - I can do this with the generic editor, but then I can't apply the span formatting I need to display.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context I am very pleased that it's taken me getting into the more fiddly bits of the code before running into an issue.
I've also noticed (and you can see this in the Sandbox) that there's no direct way to get the types for the Directives that I can find - locally I'm importing as
import type { TextDirective } from 'mdast-util-directive'
which feels a bit roundabout?