Skip to content

Jglweb 1832 cke5 plugin - #126

Open
amalija-ramljak wants to merge 8 commits into
3.0from
JGLWEB-1832-cke5-plugin
Open

amalija-ramljak wants to merge 8 commits into
3.0from
JGLWEB-1832-cke5-plugin

Conversation

@amalija-ramljak

Copy link
Copy Markdown
Member
  • plugin is a regular function instead of arrow - so creating doesn't fail
  • fixed fieldid to use cke5 uid instead of trying to count fields on the edit page
  • fixed config merge to be a deep merge instead of shallow
  • allow storage format for cke5 to be configurable - defaults match what current projects using this plugin have in the db, but change is needed for ibexa and its custom tags handling
  • skip fetch requests for empty fields

@RandyCupic

Copy link
Copy Markdown
Member

Tested this on Sylius (sklepex). The CKEditor 5 plugin breaks there when you insert a new media element.

Clicking the "Netgen Remote Media" toolbar button throws, and nothing is inserted:

(0 , _ckeditor_ckeditor5_utils__WEBPACK_IMPORTED_MODULE_1__.uid) is not a function
    at createFieldId (utils/field-id.js)
    at NetgenRemoteMediaCommand.execute (command.js)

On the current 3.0 the same click inserts the element without errors.

Cause: utils/field-id.js imports uid from @ckeditor/ckeditor5-utils. Sylius does not use the npm CKEditor packages. It has a prebuilt CKEditor build and aliases @ckeditor/ckeditor5-core, -ui, -widget and -utils to it. That build exposes only Editor, Command, ButtonView, toWidget and createElement, so uid resolves to undefined. Webpack gives no warning because the build is a CommonJS module.

The same error also happens on upcast for a stored element without data-field-id, because that path calls createFieldId() too. Existing content with a field id loads fine.

Suggested fix: don't depend on uid from ckeditor5-utils. Generate the suffix locally, e.g. crypto.randomUUID(), or a small counter or random helper in utils/field-id.js. The plugin already imports createElement from -utils, and that one is exported, so it is only the new uid import that breaks.

The other changes look fine for Sylius: the deep merge keeps our allowedVisibilities override, and the text-align style fix only changes markup when content is saved again.

@amalija-ramljak

Copy link
Copy Markdown
Member Author

Okay so, field-id.js no longer imports uid from ckeditor5-utils. Now it generates the uid with crypto.getRandomValues

sklepex/Sylius would otherwise need to expose uid the way it exposes other things from their prebuilt cke5 that are needed for the plugin

@RandyCupic

Copy link
Copy Markdown
Member

@amalija-ramljak Two more issues: Existing content stores data-ngrmcke5-alignment="undefined", because the old plugin never read that attribute back. fromView now reads it as the string "undefined", so opening and saving an unchanged page adds style="text-align:undefined;" to every embedded resource.

Minor: upcast.js now spreads an error response from the selected-image endpoint into selectedImage.

@amalija-ramljak

Copy link
Copy Markdown
Member Author

@RandyCupic both should be fixed now, can you re-test please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants