# API design for making Cristal & XWiki editor-agnostic

**URL:** <https://forum.xwiki.org/t/api-design-for-making-cristal-xwiki-editor-agnostic/16566>\
**Category:** Cristal\
**Tags:** proposal\
**Created:** [February 25, 2025, 8:19am UTC](https://forum.xwiki.org/t/api-design-for-making-cristal-xwiki-editor-agnostic/16566 "2025-02-25T08:19:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClementEXWiki](https://forum.xwiki.org/user_avatar/forum.xwiki.org/clementexwiki/32/8428_2.png) [@ClementEXWiki](https://forum.xwiki.org/u/ClementEXWiki)\
**Post date:** [February 25, 2025, 8:19am UTC](https://forum.xwiki.org/t/api-design-for-making-cristal-xwiki-editor-agnostic/16566/1 "2025-02-25T08:19:36Z")

</div>

As we want to allow both Cristal and XWiki user to replace the default provided WYSIWYG editor with another through e.g. extensions, we need a way to make these two projects editor-agnostic.

The proposal would be to create a TypeScript API defining some methods and types an editor must expose, and use this as a common denominator to plug any editor to any of these two projects. Each ‘official’ editor (such as BlockNote) would then be provided as a separate Node.js package. Others could be brought through extensions.

Basically, we would have: Cristal / XWiki ↔ documented API ↔ any editor implementing the API

The API is still to be designed, but would need to be carefully thought in order to not make bad initial decisions as the API will need to be backwards-compatible.

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [March 7, 2025, 11:40am UTC](https://forum.xwiki.org/t/api-design-for-making-cristal-xwiki-editor-agnostic/16566/2 "2025-03-07T11:40:29Z")

</div>

Hi Clement,

Note that XWiki is already “editor-agnostic” on the **server-side**. See [https://extensions.xwiki.org/xwiki/bin/view/Extension/Edit%20Module](https://extensions.xwiki.org/xwiki/bin/view/Extension/Edit%20Module) . The CKEditor module provides a component implementation for role `Editor<org.xwiki.rendering.syntax.SyntaxContent>` (hint `ckeditor`). And there’s an administration section [https://extensions.xwiki.org/xwiki/bin/view/Extension/WYSIWYG%20Editor%20Module/#HAdministrationSection](https://extensions.xwiki.org/xwiki/bin/view/Extension/WYSIWYG%20Editor%20Module/#HAdministrationSection) that allows you to select the WYSIWYG editor implementation to be used. There’s only one implementation available ATM, the CKEditor one, but XWiki extensions can already provide a new WYSIWYG editor implementation.

There’s no abstraction layer on the **client-side** currently, because we didn’t need it (badly enough so far):

- when the WYSIWYG editor is enhancing a plain text area, we set the value of the text area and get the value from the text area
- when the WYSIWYG editor is enhancing a DIV, we set the inner HTML and get the inner HTML from the DIV
- the editor loading is triggered from the server-side, see for instance [https://extensions.xwiki.org/xwiki/bin/view/Extension/Edit%20Module#HUsetheWYSIWYGEditorinaForm](https://extensions.xwiki.org/xwiki/bin/view/Extension/Edit%20Module#HUsetheWYSIWYGEditorinaForm) , by loading the required JS/CSS resources and marking the place (with a CSS class) where the editor should be loaded

+1 to introduce a client-side abstraction layer. I think the main needs are:

- create an editor instance client-side (passing the element to hook to)
- destroy the editor instance
- get the edited content (e.g. to save it)
- set the edited content

Thanks,  
Marius
