Giter Club home page Giter Club logo

quill-blot-formatter's Introduction

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.

Demo

demo

Installation

Using yarn:

yarn add quill-blot-formatter

Using npm:

npm install --save quill-blot-formatter

Usage

As Module

import Quill from 'quill';

// from the index, which exports a lot of useful modules
import BlotFormatter from 'quill-blot-formatter';

// or, from each individual module
import BlotFormatter from 'quill-blot-formatter/dist/BlotFormatter';

Quill.register('modules/blotFormatter', BlotFormatter);

const quill = new 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.

<script src="<quill>"></script>
<script src="node_modules/quill-blot-formatter/dist/quill-blot-formatter.min.js"></script>
<script>
  Quill.register('modules/blotFormatter', QuillBlotFormatter.default);
  const quill = new Quill(..., {
      modules: {
          ...
          blotFormatter: {
            // see config options below
          }
      }
    }
  });
</script>

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:

import Quill from 'quill';

// from main module
import BlotFormatter, { AlignAction, DeleteAction, ImageSpec } from 'quill-blot-formatter'

// or, from individual modules
import BlotFormatter from 'quill-blot-formatter/dist/BlotFormatter';
import AlignAction from 'quill-blot-formatter/dist/actions/align/AlignAction';
import DeleteAction from 'quill-blot-formatter/dist/actions/DeleteAction';
import ImageSpec from 'quill-blot-formatter/dist/specs/ImageSpec';

Quill.register('modules/blotFormatter', BlotFormatter);

class CustomImageSpec extends ImageSpec {
    getActions() {
        return [AlignAction, DeleteAction];
    }
}

const quill = new Quill(..., {
  modules: {
    ...
    blotFormatter: {
      specs: [
        CustomImageSpec,
      ],
      overlay: {
        style: {
          border: '2px solid red',
        }
      }
    }
  }
});

Notes

  • For all supported options as well as the default see Options.
  • object properties are merged, but array properties override the defaults.
  • To completely disable styles (overlay.style, resize.handleStyle, etc) set those to null

quill-blot-formatter's People

Contributors

guillaume-ro-fr avatar nmonterroso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

quill-blot-formatter's Issues

Quill 2 Support

Hi, now that Quill Version 2.0.0-rc.2 is there, do you have plans to support it?

npm ERR! Could not resolve dependency:
npm ERR! peer quill@"^1.3.4" from [email protected]
npm ERR! node_modules/quill-blot-formatter
npm ERR! quill-blot-formatter@"*" from the root project

Thanks.

Integrating with vue-quill on Vue3 gives error.

<template>
  <section>
    <quill-editor
      theme="snow"
      toolbar="full"
      v-model:content="content"
      :options="options"
      :modules="modules"
    />
  </section>
</template>

<script>
import { QuillEditor } from "@vueup/vue-quill";
import BlotFormatter from "quill-blot-formatter";

export default {
  name: "QEditor",
  components: {QuillEditor},
  data() {
    return {
      content: {},
      options: {
        placeholder: "Create a story...",
      },
      modules: {
        name: "blotFormatter",
        module: BlotFormatter,
        options: {/* options */},
      },
    };
  },
};
</script>

This is my code to integrate quill-blot-formatter with vue-quill but I am getting this console error. I followed this reference: https://vueup.github.io/vue-quill/guide/modules.html#example

quill-blot-formatter.js:187 Uncaught (in promise) TypeError: Cannot read property 'className' of undefined
    at new BlotFormatter (quill-blot-formatter.js:187)
    at SnowTheme.addModule (quill-59b73590.js:6093)
    at SnowTheme.addModule (quill-59b73590.js:6719)
    at quill-59b73590.js:6085
    at Array.forEach (<anonymous>)
    at SnowTheme.init (quill-59b73590.js:6083)
    at new Quill (quill-59b73590.js:1182)
    at initialize (vue-quill.js:1611)
    at vue-quill.js:1585
    at callWithErrorHandling (runtime-dom.esm-bundler-5d8bbcf1.js:1337)

Am I missing something in configuration or is it really an issue?

Some additional info from my debugging:
On putting breakpoints in quill-blot-formatter.js I found in this line,
this.options = deepmerge(DefaultOptions, options, { arrayMerge: dontMerge });
DefaultOptions is not getting populated and coming as undefined for me.

I installed quill-blot-formatter using npm. The version I am using is: "quill-blot-formatter": "1.0.5"

How to hide align buttons from toolbar?

When I align image from the main toolbar of quill then alignments remains in quill. While If I use the align buttons from quill-blot-formatter then alignments does not save in quill. If I dont user alignAction then resizer for video stops working.

So I just want to hide the three buttons of alignments from quill-blot-formatter.
How to do that?

I am using this package in angular 7 along with ngx-quill.

width and height are being removed when render in Editor

I've followed the instruction in the readme. It works well with resizing. However, after rendering from saved HTML, width and height of iframe seem being removed and the video size (the same issue for image) is back to default size 300x150. Do we have any solutions for this case?

Thank you.

Add more fonts to Quill

Hello good people... I added this to Quill, however Font doesn't change, other functions works fine... any ideas??

<quill-editor
[(ngModel)]="content"
trackChanges="all"
[modules]="modules"
(onEditorCreated)="addBindingCreated($event)"

<div quill-editor-toolbar>
  <span class="ql-formats">
    <select class="ql-font">
      <option selected>Sans Serif</option>
      <option value="serif"></option>
      <option value="monospace"></option>
      <option value="inconsolata">Inconsolata</option>
      <option value="roboto">Roboto</option>
      <option value="mirza">Mirza</option>
      <option value="arial">Arial</option>
    </select>
  </span>
  <span class="ql-formats">
    <select class="ql-size">
      <option value="small"></option>
      <option selected></option>
      <option value="large"></option>
      <option value="huge"></option>
    </select>
  </span>
  <span class="ql-formats">
    <button class="ql-bold"></button>
    <button class="ql-italic"></button>
    <button class="ql-underline"></button>
    <button class="ql-strike"></button>
  </span>
  <span class="ql-formats">
    <select class="ql-color"></select>
    <select class="ql-background"></select>
  </span>
  <span class="ql-formats">
    <button class="ql-list" value="ordered"></button>
    <button class="ql-list" value="bullet"></button>
    <select class="ql-align">
      <option selected></option>
      <option value="center"></option>
      <option value="right"></option>
      <option value="justify"></option>
    </select>
  </span>
  <span class="ql-formats">
    <button class="ql-link"></button>
    <button class="ql-image"></button>
  </span>
</div>

The proper way to get & set quill contents data

Blot formatter plugin do not write styles in to quill content data.

Reproduction steps:

  1. create quill instance with plugin
var quill = new Quill('#quill', {
            modules: {
                blotFormatter: {},
            },
        });

  1. create event handler on blur
quill.on('selection-change', (range, oldRange, source) => {
        if (range === null && oldRange !== null) {
            console.log(quill.getContents())
      }
});
  1. add any image to quill and resize it .
  2. de focus quill to trigger selection-change event

Actual result:
Quill returns blob without image atributes

Expected result:
Resizing should update quill model state and be available through function getContents()

This project is abandoned; a maintained fork is now available

Thank you to @Fandom-OSS for the original work on this excellent plugin; it has not been maintained since 2017, which leaves a lot of its users in an uncomfortable position.

Please see my TypeScript port of this package. It is available on npmjs.org as @xeger/quill-image-actions and @xeger/quill-image-formats and has working examples of how to use. Bug reports and pull requests are welcome!

How to include the file?

Error:

index.html:36 Uncaught ReferenceError: BlotFormatter is not defined
    at index.html:36
<link href="resources/quill.snow.css" rel="stylesheet">
	<link href="resources/quill-better-table.css" rel="stylesheet">
	<script src="resources/quill_2004.min.js"></script>
	<script src="resources/quill-better-table.min.js"></script>
	<script src="resources/quill-image-drop-and-paste.min.js"></script>
	<script src="resources/quill-blot-formatter.min.js"></script>
	<script src="resources/quill-cursors.min.js"></script>
<script>
Quill.register('modules/blotFormatter', BlotFormatter);
	editor = new Quill('#editor', {
        theme: 'snow',
        modules: {
					cursors: true,
          table: true,
          toolbar: {
						container: '#toolbar-container',
						handlers: {
							image: image_upload
						}
					},
					imageDropAndPaste: {
  					handler: image_upload
  				},
					blotFormatter: {
	          // displayStyles: {
	          //   backgroundColor: 'black',
	          //   border: 'none',
	          //   color: 'white'
	          // },
	          // modules: ['Resize', 'DisplaySize', 'Toolbar']
	        },
}
</script>

Thank you!

Super expression must either be null or a function, not undefined

Everything works fine on dev (npm run dev) but after build I have this error:

Super expression must either be null or a function, not undefined.

Without BlotFormatter module it also works fine.
It is laravel + vue + inertia + vite + VueQuill

<template>
    <div>
        <QuillEditor theme="snow" :modules="modules"/>
    </div>
</template>

<script>
    import { QuillEditor } from '@vueup/vue-quill'
    import BlotFormatter from 'quill-blot-formatter'
    import '@vueup/vue-quill/dist/vue-quill.snow.css';

    export default  {
        components: {
            QuillEditor
        },
        setup: () => {
            const modules = {
                name: 'blotFormatter',  
                module: BlotFormatter, 
                options: {/* options */}
            }
        return { modules }
    },
}
</script>

How can I create local build ?

Due to some requirement, I need to update your plugin so I have updated, and it's work.

How can I build locally and install it. How can I build .tgz file so locally I can install as package.

Thanks,
Jitendra Prajapati

Video does not play

On the example I cannot hit the play button on the video frame...

Any advice to get it working?

How to reload the updated contents?

Hi.
I am using this library within react-quill ( https://www.npmjs.com/package/react-quill)
The blot works well to change size and align of images.
I can get the updated contents by using getContents.
<img src="https://cdn.sstatic.net/Img/unified/sprites.svg" width="83" height="232.7278891509434" style="display: block; margin: auto; cursor: nwse-resize;" data-align="center">

The width, height and style are updated by the formatter.
But I can't reload the html.
When I open the editor with the value, the props are removed as follow.
<img src="https://cdn.sstatic.net/Img/unified/sprites.svg">

Could you let me know how to reload the updated html contents?

Many thanks!

Formats are not present in quill delta, only in on-screen HTML representation

Although I like the design of this module more than image-resize-module, it has the same basic flaw: it doesn't play well with Quill's native data model! All it does is change the presentation of blots in the contentEditable, i.e., it is only useful if you're snapshotting the DOM.

I'm reading and writing Quill deltas, and so, this plugin is of no use to me. Any plans to enhance it so it works with Quill's native data model?

how to use in image editor

I'd like to only start blotFormatter when I click on a button in my image editor toolbar, rather than having it start automatically when I click on an image or an iframe (video). Is that possible?

Respect quill.enable

I added quill-blot-formatter to a QuillJS editor. This correctly shows the controls to resize any image.
Yet, after disabling Quill via quill.enable(false), I'd expect the resizing control to be not available.

className is not undefined in BlotFormatter.js

After packaging, “this.options” have an object of “default” in “BlotFormatter.js” ,“this.options” can not direct access “overlay“ and “specs” , Access is only through “default”, for example: “this.options.default.overlay.className”, “this.options.default.overlay.style”.

issues when using backspace key to remove image in Firefox

In firefox, backspace key is shortcut key for 'go back one page'.
Steps to reproduce the issue

  1. using Firefox to go to any web page first, so that browser has previous page to go back.
  2. use the same browser window to open a page, e.g (https://codesandbox.io/s/4wnwllnnl9) which has quill-blot-formatter to insert image,
  3. click on the image to select it.
  4. use 'backspace' key to remove the image
    Expected: image is being removed
    Problem: the browser goes back to previous web page

New Feature Request: Add an option to toggle overlay on click

It would be great if you could toggle the overlay off by tapping on it (not the resize handles of course). The motivation behind this is that, more often than not, when you load an image, it will take up the entire editor width. If your editor container has a constrained height and the image causes the container to overflow, you won't be able to scroll while the overlay is shown since you are trying to scroll the overlay. In short, when images are that big, its difficult to find the area to scroll as well as hide the overlay. Hopefully that makes sense.

I think this would be fairly easy if you change the overlay HTML by adding a div in the current container that acts as the overlay click handler. The divs representing the resize handles would then need to be laid on top and likely made larger for better click/touch targets to resize without accidentally toggling off the overlay.

Awesome library and very well written! Thank you so much.

image and video alignments do not save in quill.

Hi,
Thank you for making this library. I have an issue with image and video alignments.
When I click on an image or video I inserted in the quill editor (I am using react-quill), I can align left, right, and center using the resizer box provided by quill-blot-formatter. But, as soon as I remove the editor and display the content in <div class="ql-editor" dangerouslySetInnerHTML={{ __html: content }} />, all the contents, images and videos are there but alignments are ignored.

Could you tell me what I may be missing?
or at least can I hide the alignment boxes in quill-blot-formatter so that users can just use the alignment options in the quill-toolbar?

Thanks

How to preserve the original style of image?

While using quill.setContents(quill.clipboard.convert(value)) to set editor conent, the module will remove its style attribute.

Some html string like:

<p><img src="..." style="display:block;margin:0 auto;" /></p>

After setContents it will to be:

<p><img src="..." /></p>

But I hope it can preserve the style attribute and show its real align.

How to impl this feature?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.