imnapo / react-native-cn-quill

Quill rich-text editor for react-native
MIT License
187 stars 74 forks source link

CustomJS is working correctly? #63

Closed LOMFM closed 3 years ago

LOMFM commented 3 years ago

I'd like to insert the new blot to the Quill Editor using this code.

const Embed = Quill.import('blots/embed');
class ImageLink extends Embed {
    static tagName = 'a';
    static className = 'image-object';
    static blotName = 'imageLink';
    static create(data) {
      if (!data || !data.href || !data.preview) {
        return;
      }
      const node = super.create();
      node.setAttribute('href', '{{' + data.href+ '}}');
      node.setAttribute('contenteditable', false);
      const img = document.createElement(img);
      img.setAttribute('src', data.preview);
      node.appendChild(img);
      return node;
    }
  }
  Quill.register(ImageLink, true);

React Native code is following. this.richText.current.insertEmbed(cursor, 'imageLink', {href: 'href', preview: 'image url'});

but this is not working. Where is my mistake? Thanks.

arunim2405 commented 3 years ago

Are you on Android or iOS? @LOMFM

LOMFM commented 3 years ago

@arunim2405 On both, this is not working.

arunim2405 commented 3 years ago

@LOMFM On iOS you can use safari debugger to open webview console, use console.log(Quill.imports) to check whether your blot was successfully registered or not image

LOMFM commented 3 years ago

@arunim2405 This returns Quill is undefined error.

arunim2405 commented 3 years ago

@LOMFM are you sure you're opening the iPhone simulator webview debugger?

LOMFM commented 3 years ago

@arunim2405 I have opened the RN Debugger(8081 port). I will retest again. Thanks for your reply.

LOMFM commented 3 years ago

@arunim2405 I have found the error reason. There is a little bug in my code.

I have experienced a wired bug with this customJS. ( at first this is not working with the correct custom JS code, so I inserted the console.log code to the package code. After inserting the console.log test code, this started to work.) If I found this error again in the future, I will open another issue ticket.

Thanks.