Quill Blot Formatter
A
quill
module to format document
blots
. Heavily inspired by
quill-image-resize-module
. Out of the box supports resizing and realigning images and iframe videos, but can be easily extended using
BlotSpec
and
Action
.
Installation
Using
yarn
:
yarn add quill-blot-formatter
Using
npm
:
npm install --save quill-blot-formatter
Usage
As Module
; // from the index, which exports a lot of useful modules; // or, from each individual module
; Quill; const quill = ... modules: ... blotFormatter: // see config options below ;
Script Tag
quill-blot-formatter.min.js
is provided which exports the same modules as
index.js
under the global
QuillBlotFormatter
.
BlotSpec
The
BlotSpec
classes define how
BlotFormatter
interacts with blots. They take the
BlotFormatter
as a constructor arg and have the following functions:
init(): void
Called after all specs have been constructed. Use this to bind to quill events to determine when to activate a specific spec.
getActions(): Class<Action>[]
The
actions
that are allowed on this blot. The default is
[AlignAction, ResizeAction, DeleteAction]
.
getTargetElement(): ?HTMLElement
When the spec is active this should return the element that is to be formatter
getOverlayElement(): ?HTMLElement
When the spec is active this should return the element to display the formatting overlay. This defaults to
return getTargetElement()
since they will typically be the same element.
setSelection(): void
After the spec is activated this should set the quill selection using
setSelection
. Defaults to
quill.setSelection(null)
.
onHide(): void
Called when the spec is deactivated by the user clicking away from the blot. Use this to clean up any state in the spec during activation.
Notes
Each spec should call
this.formatter.show(this);
to request activation. See
specs/
for the built-in specs.
Action
The
Action
classes define the actions available to a blot once its spec is activated. They take the
BlotFormatter
as a constructor arg and have the following functions:
onCreate(): void
Called immediately after the action is created. Use this to bind quill events and create elements to attach to the overlay.
onUpdate(): void
Called when the formatter has changed something on the blot. Use this to update any internal state.
onDestroy(): void
Called when the formatter is hidden by the user.
See
actions/
for the existing actions.
Options
Using quill module options it's easy to disable existing specs, actions, or to override any of the styles provided by this module. For example: if you wanted to remove resizing, support only images, and change the overlay border the following config would work:
;
// from main module // or, from individual modules;;;; Quill; { return AlignAction DeleteAction; } const quill = ... modules: ... blotFormatter: specs: CustomImageSpec overlay: style: border: '2px solid red' ;
Notes
Options
.
overlay.style
,
resize.handleStyle
, etc) set those to
null