feat(plugin): multiline text editing plugin with dynamic sizing#675
feat(plugin): multiline text editing plugin with dynamic sizing#675UmbraCi wants to merge 3 commits intohizzgdev:masterfrom
Conversation
|
@hizzgdev 当前插件系统异步初始化, 插件在渲染后才初始化,无法直接影响初始渲染,初始化渲染的逻辑在ViewProvider 类中,且打包出来的UMD 模块有作用域隔离。
|
这个插件是一个 editor 吧,它为什么需要在初始化的时候加载呢?在脑图没有画出来之前就已经需要用到 editor 了吗?还是说这个插件其实也修改了 render 逻辑?如果修改了,那为什么需要修改呢? |
因为如果需要脑图的节点支持多行文本,那么需要1.渲染多行文本功能;2.编辑多行文本功能;3.编辑后的保存多行文本功能; |
目前的可以支持多行文本,只需要按 html 的方式去支持就好了。 如果你需要用不同的渲染逻辑来支持多行文本,那其实是在定义另一种数据格式,如果是这样的话,你可以使用 custom_node_render,并且在你的插件里对这种节点进行更好的编辑支持。 |
好的,我按照这个思路再重构一下这个PR的插件,先不用CR代码 |
还有个问题,目前jsmind的插件流程如下:
因为插件异步且在脑图初始化渲染后才会被注册,那么自定义渲染函数custom_node_render或者html的逻辑,如果我写在插件中,是不是首次渲染还是走的ViewProvider中的默认单行渲染函数render,如果我要初始化脑图的时候就支持多行渲染,岂不是还需要用户自己再去jsmind的custom_node_render入参传入一个自定义渲染函数才行; |
你说的确实如此。我上面说的思路其实是这样的:
这是两步操作。 但我理解你希望的是做一个插件,同时支持编辑器和渲染逻辑。那么你可以做一个独立的library,让它包装一下jsmind,比如 multiline-jsmind 在构造你的类时,自动在option里添加 custom_node_render参数和插件。 另一种思路是你让编辑器生成jsmind能渲染的格式,这样就只需要做editor,为了能够实现你说的保存和再次编辑,你可以在插件里同时把你的特殊的格式保存到节点的 data 里,这样相当于node的topic里保存的是jsmind能直接渲染的数据,data里保存的是editor要使用的格式,相当于把生成的数据和源码一起存起来了。 |
考虑了下,其实目前无法直接通过一个插件就增加自定义节点显示和编辑功能,本质是卡在插件加载时序上导致无法覆写jsmind依赖的view等class中的渲染、编辑方法,为了解决这个问题,也可以为了后续其他插件的拓展能力,我能否提个PR给库增加一个同步注册插件方法usePlugin呢,区别于之前的插件在实例化后的异步注册,这样可以让编写的插件可以在实例化之前就对原本的class覆写。我看了下其他两个库例Mind-Elixir-Core、Simple-Mind-Map都是同步式的插件加载,并且也支持插件移除 @hizzgdev |
Features: - Multiline text display with word wrapping - Contenteditable-based editor for multiline editing - Auto-expand editor height based on content - Keyboard shortcuts (Shift+Enter for newline, Enter to save, Esc to cancel) - Text normalization (trim whitespace, normalize line endings) Implementation: - Created src/plugins/jsmind.multiline-text.js plugin - Added createMultilineRender() function for custom node rendering - Overrode edit_node_begin/end for contenteditable editor - Editor matches node dimensions with no border - Auto-expands height on input without scrollbar Configuration: - text_width: Maximum width for multiline text nodes (default: 200) - line_height: Line height for text (default: '1.5') Documentation: - Added English documentation (docs/en/plugin-multiline-text.md) - Added Chinese documentation (docs/zh/plugin-multiline-text.md) - Integrated plugin into example/demo.html Build: - Added plugin to rollup.config.js - Fixed external dependency to prevent bundling jsMind core - Generated UMD build (es6/jsmind.multiline-text.js) Breaking Changes: - Removed standalone multiline-text-demo.html (integrated into demo.html) - Removed .d.ts file (using JSDoc instead)
fe412dc to
6b0f2ed
Compare
|
@hizzgdev 重构了下,目前导出一个自定义节点渲染函数,插件init函数修改默认edit行为改成多行文本。 |
| custom_node_render: jsMindMultilineText.createMultilineRender({ | ||
| text_width: 200, | ||
| line_height: '1.5', | ||
| }), |
There was a problem hiding this comment.
这段的意思是说,即使使用了这个插件,还是需要手动配置这个 custom_node_render 吗?
有没有办法设置了插件后就不再需要用户另外设置这个参数?
Overview
This PR refactors the multiline text editing functionality into an independent plugin form, following the maintainer's recommendations.
Key Changes
jsmind.multiline-text.jspluginTechnical Implementation
contenteditablefor multiline editingShift+Enterfor line breaks,Enterto finish editingUsage
Backward Compatibility
Testing