multiple node view content #6247
Replies: 2 comments
-
Thank you for contributing with the example! Do you feel like an explanation on how to do multiple node view content is missing in the docs? If so, we encourage you to open a PR to our open source Tiptap Docs repository. |
Beta Was this translation helpful? Give feedback.
-
Exactly, this is an example we actually use, but we found that the documentation doesn't account for nested node-view-content, we'll launch a pr in the doc repository later to explain (this example looks a bit bloated, we'll provide another mininal example). The other issue is that we're having problems with a set of nested node-views and how to pass custom props like vue's parent-child components. Specifically, for |
Beta Was this translation helpful? Give feedback.
-
Description
通过讨论折叠块组件的实现,启发关于multiple node view content的实现思路。
The discussion regarding the implementation of the collapsible block component has provided insights into implementing multiple node view content.
URL
No response
About
How to Implement multiple node view content (Using a Collapsible Block as an Example)?
简体中文 | English
Schema定义
非常关键的点——定义好 schema 的结构:
要保证
multiple node view content
能够正常创建,schema 一定要严格按结构来定义本例子中,折叠块是由
foldBlockHeader
和FoldBlockContent
组合起来的,它们都包含在foldBlock
内部,故 schema 定义如上所示。核心实现
FoldBlock 父组件扩展:
注意:组合起来的这些节点都要是同一个 group,此处为
block
FoldBlock 父组件:
注意:这里要用
<node-view-content>
而不是<foldBlock-header>
+<foldBlock-content>
子组件的形式,因为在创建时 prosemirror 会根据 schema 进行填充。FoldBlockHeader 子组件扩展:
FoldBlockHeader 子组件:
FoldBlockContent 子组件扩展:
FoldBlockContent 子组件:
组件间的控制逻辑
对于折叠块,只需要通过一个按钮控制
foldBlockContent
的折叠与否,但实际上,<node-view-content>
里面的组件并不在父组件里面,而是prosemirror填进去的,所以props和provide/inject/emit都会失效。解决方法:引入动态class:
<node-view-content :class="isFolded ? 'is-folded' : 'not-folded'" />
, 然后通过在子组件里使用css选择器来控制是否显示。至此,可以实现一个简单的折叠块的功能,可以分别在标题处和内容处分别编辑内容,也可以将内容折叠起来,其他类似的均可参照此处实现逻辑。
How to Implement
multiple node view content
(Using a Collapsible Block as an Example)?Schema Definition
A crucial point: define the structure of the schema properly.
To ensure that multiple node view content can be created correctly, the schema must be strictly defined according to the structure.
In this example, the collapsible block is composed of foldBlockHeader and FoldBlockContent, both of which are contained within foldBlock. Therefore, the schema is defined as shown above.
Core Implementation
FoldBlock Parent Component Extension:
Note: All the combined nodes should belong to the same group, which is block here.
FoldBlock Parent Component:
Note: Here you should use
<node-view-content>
instead of the<foldBlock-header>
+<foldBlock-content>
child component form, because prosemirror will fill according to the schema during creation.FoldBlockHeader Child Component Extension:
FoldBlockHeader Child Component:
FoldBlockContent Child Component Extension:
FoldBlockContent Child Component:
Control Logic Between Components
For the collapsible block, only one button is needed to control whether foldBlockContent is collapsed or not. However, the components inside
<node-view-content>
are not in the parent component, but are filled in by prosemirror, so props and provide/inject/emit will be invalid.Solution: Introduce a dynamic class:
<node-view-content :class="isFolded ? 'is-folded' : 'not-folded'" />
, and then control whether to display it by using CSS selectors in the child components.At this point, a simple collapsible block function can be implemented. You can edit the content in the title and content sections separately, and you can also collapse the content. Other similar functions can refer to the implementation logic here.
Type
Document Editor with Collaboration
Other
No response
Beta Was this translation helpful? Give feedback.
All reactions