简体   繁体   English

无限CkEditor5视图值

[英]Unbounded CkEditor5 view values

I am currently trying to build a color plugin for CkEditor5 to mimic the one that was available for CkEditor4. 我目前正在尝试为CkEditor5构建颜色插件,以模仿可用于CkEditor4的插件。

I have an input method, but mapping the model values to view values is my stumbling block. 我有一个输入法,但是将模型值映射到视图值是我的绊脚石。 The System appears to be set up so that every possible value is known in advance and mapped - which for hex values is obviously impractical. 系统似乎已设置好,因此每个可能的值都已预先知道并映射了-对于十六进制值,这显然是不切实际的。

Is there any way to tell CkEditor to just directly use the model value in the view style tag and the view value in the model? 有什么方法可以告诉CkEditor直接使用视图样式标签中的模型值和模型中的视图值?

I assume that you are creating a plugin with a colorpicker UI. 我假设您正在使用colorpicker UI创建一个插件。

You won't be able to couple that with the existing highlight plugin available for CKE5. 您将无法将其与可用于CKE5的现有高亮插件相结合。 Instead, I recommend creating a new plugin. 相反,我建议创建一个新插件。 You may check out highlight plugin to see what needs to be done to provide a plugin. 您可以查看突出显示插件以查看提供插件需要做什么。

Is there any way to tell CKEditor to just directly use the model value in the view style tag and the view value in the model? 有什么方法可以告诉CKEditor直接使用视图样式标签中的模型值和模型中的视图值?

Yes. 是。 You need to set up a proper downcast (model->view) and upcast (view->model) conversion. 您需要设置适当的下转换(模型->视图)和上转换(视图->模型)转换。 For that you will need to provide a function which will generate a model/view element. 为此,您将需要提供一个将生成模型/视图元素的函数。

See docs for downcastAttributeToElement and upcastElementToAttribute() . 请参阅文档以了解downcastAttributeToElementupcastElementToAttribute() In those docs, there are examples of how to set up a conversion that uses style attribute value. 在这些文档中,有一些有关如何设置使用style属性值的转换的示例。 Upcast converter shows a more complicated example but you can simply return the value from view. Upcast转换器显示了一个更复杂的示例,但是您只需从视图中返回该值即可。

To add such converter you need to use model.Conversion#for..#add construction : 要添加这样的转换器,您需要使用model.Conversion#for..#add结构

  • editor.conversion.for( 'downcast' ).add( downcastAttributeToElement( downcastConfig ) )
  • editor.conversion.for( 'upcast' ).add( upcastElementToAttribute( upcastConfig ) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM