Issue #2194Opened August 14, 2019by Ramkumar-Murugesan0 reactions

CKEditor blocks is not editable[QUESTION]

Question

Hi guys, I added the custom CKEditor blocks and its working fine. but the actual issues is I can't able to delete, move or add the traits in the CKEditor blocks. I tried all the possible but nothing is work. I really stuck. can anyone please help me.

my custom blocks:

editor.BlockManager.add('ckeditor', {
      id: 'ckeditor',
      label: `fa fa-check-square`,
      category: 'Basic',
      content: `
      <textarea data-gjs-type="ckeditor5" data-rte="1" name="content" id="ckeditor">This is some sample content.</textarea>
      `,
      draggable: true,
      removable: true
    });

my traits:-

 const comps = editor.DomComponents;
    const defaultType = comps.getType('default');
    const defaultModel = defaultType.model;
    comps.addType(buttonName, {
      model: defaultModel.extend({
        defaults: Object.assign({}, defaultModel.prototype.defaults, {
          draggable: '*',
          droppable: false,
          script: function () {
            const initCKeditor = function () {
              ClassicEditor.create(document.querySelector('#ckeditor'))
                .then(obj => {
                  console.log(obj);
                })
                .catch(error => {
                  console.error(error);
                });
            };
            if (typeof ClassicEditor === 'undefined') {
              const script = document.createElement('script');
              script.onload = initCKeditor;
              script.src = 'https://cdn.ckeditor.com/ckeditor5/11.2.0/classic/ckeditor.js';
              document.body.appendChild(script);
            } else {
              initCKeditor();
            }
          },
          traits: [{
            label: 'name',
            name: 'name',
            changeProp: 1,
            type: 'text'
          }],

        })
      },
        {
          isComponent: function (el) {
            if (el.tagName === buttonName) {
              return {
                type: buttonName
              };
            }
          },
        }),

      // Define the View
      view: defaultType.view,
    });
  }

image

as you can see the above image that I only able to select the div but not the textarea.

Answers (2)

artfAugust 24, 20190 reactions

Well, the textarea can't be selected because it's a static element generated from you component's script so it's not part of the editor, it's all correct.

If your point is to change internal CKEditor configurations you have to rely on your component traits and use string interpolations inside your script (like described in docs)

// ...
script: function () {
	const config1 = '{[ propertyName1 ]}';
	const config2 = '{[ propertyName2 ]}';
	const initCKeditor = function () {
// ...
artfAugust 24, 20190 reactions

BTW don't do this ClassicEditor.create(document.querySelector('#ckeditor')) in this way your integration will break with multiple components of the same time.

I think it would be better for you to update your stuff in this way

// I'm using the new API for component type definition, you should do the same...
defaults: {
          draggable: '*',
          droppable: false,
		  // Default component content
		  components: '<textarea>This is some sample content.</textarea>',
		  script: function () {
			// ...
			const textareaEl = this.firstChild;
			ClassicEditor.create(textareaEl);
		  }

// 
editor.BlockManager.add('ckeditor', {
	  // ...
      content: { type: 'ckeditor5' },
    });

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.