Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vue-document-editor

motla3.8kMIT2.3.2

Paper-sized WYSIWYG document editor for Vue apps

vue, vuejs, document, editor, wysiwyg, page, a4, text, processor, application

readme

vue-document-editor

vue-document-editor is a rich-text editor built on top of Vue.js, using the native contenteditable browser implementation and some JavaScript trickery to spread content over paper-sized pages. It is mainly designed to allow targeted modifications to pre-formatted documents using HTML or interactive templates.

:speech_balloon: This package does not intend to replace a proper document editor with full functionality. If you're looking for a powerful word processor, check out CKEditor for Vue.js or Collabora Online Development Edition.

Features

:rocket: See live demo

  • Use Vue.js components as interactive page templates
  • Word-by-word page splitting (still experimental - only for plain HTML content)
  • Native Print compatible
  • Dynamic document format and margins in millimeters
  • Custom page overlays (headers, footers, page numbers)
  • Page breaks
  • Smart zoom and page display modes
  • Computes text style at caret position
  • Migrated to Vue.js 3.x (to use with Vue 2.x, select library version 1.x)
:speech_balloon: This package doesn't include any toolbar. The demo features vue-file-toolbar-menu for the toolbar.

Installation

In your Vue.js 3.x project:
npm install vue-document-editor
In your Vue.js 2.x project:
npm install vue-document-editor@1
:speech_balloon: If you prefer static files, import assets from the dist folder

Basic example

MyComponent.vue
<template>
  <div style="font-family: Avenir, sans-serif">
    <vue-document-editor v-model:content="content" /> <!-- Vue 3 syntax -->
    <!-- <vue-document-editor :content.sync="content" /> --> <!-- Vue 2 syntax -->
  </div>
</template>

<script>
import VueDocumentEditor from 'vue-document-editor'

export default {
  components: { VueDocumentEditor },
  data () {
    return { 
      content: ["<h1>Hello!</h1>Fill this page with text and new pages will be created as it overflows."]
    }
  }
}
</script>
<summary>same example using static files loaded with a CDN (Vue 3)</summary>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue-document-editor@2/dist/VueDocumentEditor.umd.min.js"></script>
  <link href="https://cdn.jsdelivr.net/npm/vue-document-editor@2/dist/VueDocumentEditor.css" rel="stylesheet">
</head>
<body>
  <div id="app">
    <div style="font-family: Avenir, sans-serif">
      <vue-document-editor v-model:content="content" />
    </div>
  </div>
  <script>
  const app = Vue.createApp({
    components: { VueDocumentEditor },
    data () {
      return { 
        content: ["<h1>Hello!</h1>Fill this page with text and new pages will be created as it overflows."]
      }
    }
  }).mount('#app');
  </script>
</body>
</html>
<summary>same example using static files loaded with a CDN (Vue 2)</summary>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue-document-editor@1/dist/VueDocumentEditor.umd.min.js"></script>
  <link href="https://cdn.jsdelivr.net/npm/vue-document-editor@1/dist/VueDocumentEditor.css" rel="stylesheet">
</head>
<body>
  <div id="app">
    <div style="font-family: Avenir, sans-serif">
      <vue-document-editor :content.sync="content" />
    </div>
  </div>
  <script>
  var app = new Vue({
    el: '#app',
    components: { VueDocumentEditor },
    data () {
      return { 
        content: ["<h1>Hello!</h1>Fill this page with text and new pages will be created as it overflows."]
      }
    }
  })
  </script>
</body>
</html>

Complete example

See the Demo.vue file and the InvoiceTemplate.ce.vue file corresponding to the live demo.

API

For the list of props, data and styling variables: :blue_book: read the API.

Known issues / limitations

  • Undo / Redo: Native undo/redo needs to be rewritten as the split mechanism modifies the HTML content at every input, so the navigator is lost. You have to implement it yourself by watching content updates and storing them in a stack, then restoring them. Demo.vue implements this. Also your interactive templates need to have a custom undo/redo management if their editable fields are not synced with the content.
  • Performance: For now, large texts must be divided into multiple paragraphs and large page numbers can slow down the entire document (see Issue 14).
  • Safari print: Safari adds print margins unless you choose a borderless paper format in the print box. This has to be done manually. I guess there is no workaround for this issue yet.
  • Tables, images: Image/table placement and sizing is not included. You can implement it specifically for your needs. However, table rows split fine over multiple pages.
  • Page splitting doesn't work with Vue page templates: This library cannot act on the content managed by Vue (like .vue page templates), because then Vue is lost and the template pages are no longer interactive. The only choice you have is writing plain HTML in the content instead of using .vue templates. You can do interactivity by using HTML elements with the attributes contenteditable="false" and onclick="..." containing your own JavaScript code.

Project development

  • npm run serve compiles and hot-reloads demo for development
  • npm run build compiles and minifies production files and demo

Licensing

Copyright (c) 2020 Romain Lamothe, MIT License

changelog

Vue 3

v2.3.2

  • Fix Issue 36: Better handling of deleting on an empty page (no more user action is prevented on the keydown event, instead we deal with the result in the input event and ensure at least a <div><br></div> is always present in the content).
  • Fix a Safari bug with the cursor, which appeared only on recent versions of Safari (normalize() must now be called before selection <null> tags removal)

v2.3.1

v2.3.0

  • Improvement on Issue 28: Table Page Break. Now table rows don't split over pages but are simply moved if they overflow
  • Implementation of Issue 27: Unwanted page break with :do_not_break parameter
  • Fix a part of Issue 26:
    • A blank page could appear at the end when printing with page overlays

v2.2.2

  • Fix Issue 24: Backspace key is broken with one page content
  • Bugfix: All pages were not removed after a content reset

v2.2.1

  • Bugfix: Display update was not triggered after exiting printing mode

v2.2.0

  • User can now provide a function for page_margins, to set margins specific to the page number (for more info read the API)

v2.1.2

  • Bugfix: Cursor is blurred when editing contenteditable fields inside components

v2.1.1

  • Bugfix: Display update was not triggered when changing display or zoom props

v2.1.0

  • This library core has been rewritten for Vue3 using an hoisted static <div> for pages content to manage page manually and avoid conflicts between DOM contenteditable elements and Vue.js. More info here
  • SCSS has been converted to basic CSS, so you don't have to install a SCSS compiler anymore
  • Updating dependencies
  • Removing ESLint for a lighter project
  • Fix Issue 16: The component breaks if you remove all the content
  • :warning: Warning: starting from this version, the new core implies that for using templates with custom CSS you must rename your single file components with .ce.vue extension. More info here

v2.0.7

  • Fix: 2.0.6 static libraries and docs (demo) were faulty because compiled with vue2. Recompiled with vue3.

v2.0.6

  • Fix Issue 19: Any custom CSS formatting other than the one on <body> was not taken into account in print mode

v2.0.5

  • Fix Issue 17: In some cases, multiple instances of reset_content were launched simultaneously which could cause errors.

v2.0.4

  • Fix Issue 16: The component breaks if you remove the last character
  • Fix warnings about deprecated ::v-deep and print-color-adjust
  • Dev dependencies upgrade

v2.0.3

  • Bug fixing: prevent applying normalize() to template pages HTML as it can break Vue behavior (only Vue3)
  • Dependencies upgrade

v2.0.2

  • Fixing the contenteditable field highlight to the Invoice Template of the Demo
  • Adding back Vue2 syntax to the basic example

v2.0.1

  • Workaround for the Chrome "return from print" bug. Now displays a return arrow to let the user go back to the editor when this bug happens.

v2.0.0

  • Switching master branch to Vue3 (we provide vue2 compatibility on the vue2 branch / @1.x version of this library)
  • Dependencies upgrade

Vue 2

v1.5.2

  • Fix Issue 36: Better handling of deleting on an empty page (no more user action is prevented on the keydown event, instead we deal with the result in the input event and ensure at least a <div><br></div> is always present in the content).
  • Fix a Safari bug with the cursor, which appeared only on recent versions of Safari (normalize() must now be called before selection <null> tags removal)

v1.5.1

v1.5.0

  • Improvement on Issue 28: Table Page Break. Now table rows don't split over pages but are simply moved if they overflow
  • Implementation of Issue 27: Unwanted page break with :do_not_break parameter
  • Fix a part of Issue 26:
    • A blank page could appear at the end when printing with page overlays

v1.4.1

  • Fix Issue 24: Backspace key is broken with one page content

v1.4.0

  • User can now provide a function for page_margins, to set margins specific to the page number (for more info read the API)

v1.3.0

  • SCSS has been converted to basic CSS, so you don't have to install a SCSS compiler anymore
  • Updating dependencies
  • Removing ESLint for a lighter project
  • Fix Issue 16: The component breaks if you remove all the content

v1.2.8

  • Fix Issue 19: Any custom CSS formatting other than the one on <body> was not taken into account in print mode

v1.2.7

  • Fix Issue 16: The component breaks if you remove the last character
  • Fix warnings about deprecated ::v-deep and print-color-adjust
  • Dev dependencies upgrade

v1.2.6

  • Workaround for the Chrome "return from print" bug. Now displays a return arrow to let the user go back to the editor when this bug happens.

v1.2.5

  • Fix Issue 11: Using editable prop to provide read only view

v1.2.4

  • Removing pages manually from the DOM now remove corresponding items from the content you provide
  • Adding data-page-idx to pages <div>s for custom user scripts convenience
  • [Demo] Add dynamic page break functionality example (still experimental)
  • [Demo] Restrict nb of table lines in the invoice template page, fix CSS for printing

v1.2.3

  • Removing useless surrounding <div>s from the synchronized document content
  • Fix content synchronizing from an empty content array
  • Fix content update was not triggered after some of the executeCommand functions
  • [Demo] Reset the history stack after new document creation
  • Dependencies upgrade

v1.2.2

  • Fix Issue 4: problem with ?. operator

v1.2.1

  • Force white page background when printing

v1.2.0

  • Adding overlay functionality and documentation
  • Enable printing of CSS background colors/image
  • Dependencies upgrade

v1.1.2

  • Fix Issue 3
    • Renaming the static library "VueDocumentEditor"
    • Adding UMD example to README.md

v1.1.1

  • Bugfix Issue 2: Enter key to create new line doesn't seem to work on the demo site
  • Bugfix: restoring a new document when user wipes out the entire document

v1.1.0

  • Undo/Redo mechanism moved to Demo.vue in order to let custom implementation in application
  • Bugfix: preserving text selection when calling execCommand
  • Minor display improvements in the Demo about scrollbars
  • Better overall compatibility for Firefox

v1.0.0

Initial release