npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quill-toolbar-item

v1.0.2

Published

Quill editor module representing a toolbar item

Downloads

34

Readme

quill-toolbar-item

Module for Quill.js editor toolbar. With this module you can add a custom button or selector. You only need to send the content of the icons in stringify html format.

Screenshot

How to install

npm i quill-toolbar-item
yarn add quill-toolbar-item

How to use

You need to do through three easy steps :

  1. register your module in Quill
  2. configure quill toolbar options
  3. configure quill modules options.

STEP1 Register module

import Quill from 'quill';
import ToolbarItem from 'quill-toolbar-item';
..
Quill.register('modules/toolbar-custom-button', ToolbarItem);
Quill.register('modules/toolbar-custom-selector', ToolbarItem);

STEP2 Configure toolbar

  const itemIcons = {
    tableBorderAll,
    tableBorderBottom,
    tableBorderLeft,
    tableBorderNone,
    tableBorderOutside,
    tableBorderRight,
    tableBorderTop,
  }
..
const toolbarOptions = {
  container: [
    ['bold', 'italic', 'underline', 'strike'],
    ['custom-button'],
    [{ 'custom-selector': Object.keys(itemIcons) }]
  ],
  handlers: {
    'custom-button': () => {},
    'custom-selector': () => {}
    }
}

The key in the container may be anything, but it should be specified in the modules options. And itemIcons - is an object with htiml stringify content for the icons in the selector. For exaple you may put .svg files in assets/icons folder and then to import their:

import tableIcon from '!!raw-loader?!src/assets/icons/table.svg';
import tableBorderAll from '!!raw-loader?!src/assets/icons/table-border-all.svg';
import tableBorderBottom from '!!raw-loader?!src/assets/icons/table-border-bottom.svg';
import tableBorderLeft from '!!raw-loader?!src/assets/icons/table-border-left.svg';
import tableBorderNone from '!!raw-loader?!src/assets/icons/table-border-none.svg';
import tableBorderOutside from '!!raw-loader?!src/assets/icons/table-border-outside.svg';
import tableBorderRight from '!!raw-loader?!src/assets/icons/table-border-right.svg';
import tableBorderTop from '!!raw-loader?!src/assets/icons/table-border-top.svg';

STEP3 Configure modules options

const quill = new Quill(editor, {
  ..
  modules: {
    ..
    toolbar: toolbarOptions,
    "toolbar-custom-button": customButtonOptions,
    "toolbar-custom-selector": customSelectorOptions,
  }
});

In this step you need to configure the modules object by set keys as same name as in registry, and set the values - 'magic' customButtonOptions, customSelectorOptions objects.
These options have the following interface:

export interface QuillToolbarItemOptions {
  toolbarKey: string;
  isToggled?: boolean;
  button?: DataItem | string;
  items?: { [key: string]: DataItem | string };
  saveSelection?: boolean;
  collapseByClick?: boolean;
  clickHandler?: (key: ClickEventArgs) => void;
}

export interface DataItem {
  icon: string;
  title: string;
}

export interface ClickEventArgs {
  toolbarKey: string;
  element?: string;
  isActive?: boolean;
  isExpanded?: boolean;
}

It simple in the button case:

customButtonOptions = { 
  toolbarKey: 'item',
  isToggled: true,
  button: { icon: tableIcon, title: 'Table' },
  clickHandler: (e) => { console.log(e); },
}

And in the selector case you should add the 'items' field:

customButtonOptions = { 
  toolbarKey: 'item',
  isToggled: true,
  button: { icon: tableIcon, title: 'Table' },
  items: {
    tableBorderAll: {
      icon: tableBorderAll,
      title: 'BorderAll'
    },
    tableBorderBottom: {
      icon: tableBorderBottom,
      title: 'BorderBottom'
    },
    tableBorderLeft,
    tableBorderNone,
    tableBorderOutside,
    tableBorderRight,
    tableBorderTop,
  },
  clickHandler: (e) => { console.log(e); },
  collapseByClick: false,
  saveSelection: false,
}

I will publish life demo somelater)