Open electroluxcode opened 2 months ago
Adding nodes should not use setNodes, but rather APIs such as insertNodes
Adding nodes should not use setNodes, but rather APIs such as insertNodes
hi, @WindrunnerMax thanks for your reply
I understand your point; indeed, I can use the insertNode
API. However, my requirement is to transform a section of nodes entirely into another node.
For example, in Markdown syntax, inputting - Your content
automatically transforms into a ul (unordered list).
Currently, my workaround is to first use the removeNode
API and then the insertNode
API to replace setNodes
, but this approach doesn't seem to be expectations and semantics.
for example,After removing
andinsert
nodes, the cursor will be positioned on the next line. You need to manually control the cursor position by developer
@electroluxcode Changing the content using setNodes
wouldn't solve the selection problem. This isn't supported by Slate for the same reason that Slate isn't a controlled component. I wrote the following essay explaining why.
https://github.com/ianstormtaylor/slate/issues/5281#issuecomment-2234431664
slate-diff
can indeed solve the problem of setNodes. However, I think that slate
should import the slate-diff
library and use it as the logic of setNodes instead of making users perform additional operations.
slate-diff
can indeed solve the problem of setNodes. However, I think thatslate
should import theslate-diff
library and use it as the logic of setNodes instead of making users perform additional operations.
Unfortunately, that would severely increase Slate's bundle size and code complexity, and harm the predictability of its API. I don't think it's a good candidate for inclusion in core.
Description
it refer https://docs.slatejs.org/api/transforms#transforms.setnodes-editor-editor-props-partial-less-than-node-greater-than-options
props: Partial<Node>
has a prop namedchildren
,However, when I read the source code in pathpackages\slate\src\interfaces\transforms\general.ts
, I found that the props parameter namedchildren
did not render . There's this codethis code makes it impossible for setNodes to handle nested cases with 'children'
Expectation
maybe setNodes should be able to handle nested cases with 'children'
Environment
eg
for example
this code will only render first level and missing
children
it seem deliberate in reading source,i have quesion why would do that
thanks