Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx-Quill - Problems with importing Parchment #1357

Closed
aleksgrunwald opened this issue Sep 3, 2021 · 8 comments
Closed

ngx-Quill - Problems with importing Parchment #1357

aleksgrunwald opened this issue Sep 3, 2021 · 8 comments

Comments

@aleksgrunwald
Copy link

aleksgrunwald commented Sep 3, 2021

This is my issue:

  • Font size of the bulleted list and numbered list doesn't follow the font size of the active text, they are always Normal size regardless what size has a text, and it's not possible to change it.

I've made some internet searching and so I'm trying to overwrite Parchment/Quill method based on this :

slab/quill#409

class CustomColor extends Parchment.Attributor.Style {
  value(node) {
    let value = super.value(node);

    if (!value.startsWith('rgb(')) return value;

    value = value.replace(/^[^\d]+/, '').replace(/[^\d]+$/, '');

    return '#' + value.split(',').map(function(component) {
      return ('00' + parseInt(component, 10).toString(16)).slice(-2);
    }).join('');
  }
}

const customColorAttributor = new CustomColor('custom-color', 'color', {
    scope: Parchment.Scope.BLOCK,
});

Quill.register(customColorAttributor);

and I was getting:

Cannot read properties of undefined (reading 'Attributor')

How to properly import Parchment?

Now, after reading some more advice on the internet, I don't have any errors in the console, but I don't think my code is overwriting a native Quill/Parchment method.
What I've got in my component now:

public Parchment = Quill.import('parchment');

public CustomColor = class extends this.Parchment.Attributor.Style {
    constructor(attrName: string, keyName: string, options: AttributorOptions) {
      super();
      this.attrName = attrName;
      this.keyName = keyName;
      this.options = options;
    }
    public value(node) {
      console.log('my parchment!!!!');
      let value = super.value(node);

      if (!value.startsWith('rgb(')) return value;

      value = value.replace(/^[^\d]+/, '').replace(/[^\d]+$/, '');

      return (
        '#' +
        value
          .split(',')
          .map(function (component) {
            return ('00' + parseInt(component, 10).toString(16)).slice(-2);
          })
          .join('')
      );
    }
  };`

constructor(private editQuoteTextTemplatesModalService: EditQuoteTextTemplatesModalService) {
    const customColorAttributor = new this.CustomColor('custom-color', 'color', {
      scope: this.Parchment.Scope.BLOCK,
    });
    Quill.register(customColorAttributor);
  }

I have a custom toolbar but I''m using a native quill format methods:

public colorHandler: (c: string) => void = (color: string) => {
   this.quill.format('color', color);
   this.setCursorToLastPosition();
 };

I'm getting a quill instance by this:

public afterCreation(event): void {
    this.quill = event;
  }
@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Sep 3, 2021 via email

@aleksgrunwald
Copy link
Author

oh. OK :(

But maybe do you have any new idea how to solve this initial issue? ;) :

Font size of the bulleted list and numbered list doesn't follow the font size of the active text, they are always Normal size regardless what size has a text, and it's not possible to change it.

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Sep 3, 2021 via email

@aleksgrunwald
Copy link
Author

aleksgrunwald commented Sep 3, 2021

Yes. I think this is the problem - that I'm using this.Parchemnt -> so probably I'm not overwriting this package Parchemnt tha Quill actually uses.
I tried to do this:

import Parchment from 'parchment';

But It gave me errors.
Then I've read this:
https://stackoverflow.com/questions/41086454/having-problems-extending-quill

It says to do this:

let Parchment = Quill.import('parchment');

But in angular I am within a component class, so I can't really do exactly this hence I've tried to

public Parchment = Quill.import('parchment');

What I really need to do, what maybe would work is to import Parchment like I can import Quill:

import Quill from 'quill';

@KillerCodeMonkey
Copy link
Owner

KillerCodeMonkey commented Sep 3, 2021 via email

@aleksgrunwald
Copy link
Author

Yeeeah.. That's true. I'm just trying to do this. ;)

@aleksgrunwald
Copy link
Author

Above @component, I've got this:

let Parchment = Quill.import('parchment');

class CustomColor extends Parchment.Attributor.Style {
    constructor(attrName: string, keyName: string, options: AttributorOptions) {
      super();
      this.attrName = attrName;
      this.keyName = keyName;
      this.options = options;
    }

  public value(node) {
    let value = super.value(node);
    console.log('my parchment');

    if (!value.startsWith('rgb(')) return value;

    value = value.replace(/^[^\d]+/, '').replace(/[^\d]+$/, '');

    return '#' + value.split(',').map(function(component) {
      return ('00' + parseInt(component, 10).toString(16)).slice(-2);
    }).join('');
  }
}

const customColorAttributor = new CustomColor('custom-color', 'color', {
  scope: Parchment.Scope.BLOCK,
});

Quill.register(customColorAttributor);

I guess, I should get this above console.log if this part of code works and I don't get it logged..

@KillerCodeMonkey
Copy link
Owner

so i will close this one here,

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

No branches or pull requests

2 participants