Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving the error BlotClass.create is not a function in ReactQuill

Tags:

reactjs

quill

I am trying to create a custom font size drop-down for the toolbar in ReactQuill. I decided to strip out the original code for font-size from quilljs and expand on it (as seen below):

import Parchment from 'parchment';

let SizeClass = new Parchment.Attributor.Class('size', 'ql-size', {
  scope: Parchment.Scope.INLINE,
  whitelist: ['8', '9', '10', '11', '12', '13', '14', '16', '18', '24', '36']
});
let SizeStyle = new Parchment.Attributor.Style('size', 'font-size', {
  scope: Parchment.Scope.INLINE,
  whitelist: ['8px', '9px', '10px', '11px', '12px', '13px', '14px', '16px', '18px', '24px', '36px']
});

export { SizeClass, SizeStyle };

When I try to import and register the SizeStyle in my App.js I am receiving the error in the title.

import React, { Component } from 'react';
import ReactQuill, {Quill} from 'react-quill'
import { SizeClass, SizeStyle } from './font-size'

import { ImageDrop } from 'quill-image-drop-module'
import { ImageResize } from 'quill-image-resize-module'

Quill.register(SizeStyle, true)
Quill.register('modules/imageDrop', ImageDrop)
Quill.register('modules/imageResize', ImageResize)

I then have my own HTML toolbar that has all of the size attributes in a drop down:

<div id="toolbar">
        <select className="ql-size">
            <option value="8px"></option>
            <option value="9px"></option>
            <option value="10px"></option>
            <option value="11px"></option>
            <option value="12"></option>
            <option value="13"></option>
            <option value="14"></option>
            <option value="16"></option>
            <option value="18"></option>
            <option value="24"></option>
            <option value="36"></option>
        </select>
  </div>

any suggestions?!

like image 590
Matthew Benjamin Avatar asked Jun 22 '17 20:06

Matthew Benjamin


1 Answers

I was getting the same error until I changed how I was importing Parchment.

Try var Parchment = Quill.import('parchment'); instead of import Parchment from 'parchment';

like image 73
Briaker Avatar answered Sep 30 '22 12:09

Briaker