VueQuill

repository·master·Indexed 23 days ago

https://github.com/vueup/vue-quill

A Vue 3 rich text editor component built on the Quill 2 engine. It is fully typed with TypeScript, compatible with SSR environments, and supports content binding via v-model:content using Delta objects, HTML, or plain text. The library provides the QuillEditor component along with utilities like loadQuill for asynchronous browser runtime loading in SSR applications.

Tokens
11.1K
Snippets
30
Records
68
Agent score
79%

What's inside VueQuill

  1. Overview of VueQuill features

    master

    VueQuill is a rich text editor component for Vue 3 built on top of Quill 2. Key features include:

    • TypeScript Support: Fully written in TypeScript.
    • Quill 2 Ready: Includes Quill 2 as a dependency and provides access to the underlying Quill instance.
    • SSR Friendly: Designed to work in Vue Server-Side Rendering applications by initializing Quill in the browser.
    • Simple API: Easy to implement via a straightforward component interface.
  2. Patterns covered in the Vue Quill example

    master

    The example source demonstrates the following implementation patterns for @vueup/vue-quill:

    Editor Configuration & Content

    • Basic usage: Standard implementation of the QuillEditor component.
    • HTML Content: Using v-model:content to bind HTML strings.
    • Delta Content: Initializing the editor using Delta objects.
    • Themes: Using Snow, Bubble, and core theme variants.
    • States: Implementing placeholder, read-only, and live enable states.

    Toolbars

    • Built-in toolbars
    • Array-based toolbars (passing an array of options)
    • Custom container toolbars

    Events & API

    • Events: Handling ready, focus, blur, textChange, selectionChange, and editorChange.
    • Ref Methods: Accessing editor methods via template refs, such as focus(), setHTML(), and getHTML().

    Integration

    • Form Validation: Implementing form-style validation and submission states using the editor.
  3. Manage Vue Quill Dependencies in Nuxt

    master

    When working with this example, you can control whether you are using the local workspace source or the published npm package using environment variables and specific scripts:

    Using Local Workspace Source

    By default, npm run dev, npm run build, and npm run generate use the local workspace source from ../../packages/vue-quill (if available). This is useful for validating unreleased changes.

    Using the Released NPM Package

    To force the use of the released npm package, use the NUXT_VUE_QUILL_SOURCE=npm environment variable with these commands:

    • npm run dev:npm
    • npm run build:npm
    • npm run generate:npm

    Static Output for GitHub Pages

    To build static output specifically for deployment under /vue-quill/examples/nuxt-app/ on GitHub Pages, use: npm run generate:pages

  4. Use loadQuill for SSR compatibility

    master

    In Server-Side Rendering (SSR) applications, you should not access Quill APIs directly during the initial setup as they require a browser environment. Instead, use loadQuill to load the Quill browser runtime asynchronously. This should be called within browser-only lifecycle hooks, such as onMounted in Vue components.

    To retrieve the runtime once it has been loaded, you can use getLoadedQuill.

  5. Registering Formats and Blots

    master

    When a package exposes formats or blots that must be registered before the module can function, use a full Quill registration path in the name property.

    • Use a path like blots/name to register a Quill blot. These are not added to the module options.
    • Use a path like modules/name to register a Quill module. The options provided will be passed to Quill as modules.name.

    If you are using the formats option on QuillEditor, ensure you include the blot name in the allowed formats array so Quill permits those embeds in the editor content.

    import { Mention, MentionBlot } from 'quill-mention'
    
    const modules = [
      {
        name: 'blots/mention',
        module: MentionBlot,
      },
      {
        name: 'modules/mention',
        module: Mention,
        options: {
          mentionDenotationChars: ['@'],
          source: (searchTerm, renderList) => {
            renderList([], searchTerm)
          },
        },
      },
    ]
    
    // To allow the blot in the editor:
    const options = {
      formats: ['bold', 'italic', 'mention'],
    }
  6. Important notice regarding VueQuill beta status

    master

    ⚠️ VueQuill is currently in @beta.

    It is not recommended for production use in serious projects yet. The focus is currently on stability and feature completeness. Some features are not finalized and may undergo breaking changes as better solutions are discovered.

  7. Configure Quill using the globalOptions prop

    master

    When registering the QuillEditor component globally, use the globalOptions prop to set default configurations for all instances. To implement this, you must set the default value of QuillEditor.props.globalOptions before registering the component with your Vue app.

    import { createApp } from 'vue'
    import { QuillEditor } from '@vueup/vue-quill'
    
    const app = createApp()
    
    // define your options
    const globalOptions = {
      debug: 'info',
      modules: {
        toolbar: ['bold', 'italic', 'underline']
      },
      placeholder: 'Compose an epic...',
      readOnly: true,
      theme: 'snow'
    }
    
    // set default globalOptions prop
    QuillEditor.props.globalOptions.default = () => globalOptions
    
    // register QuillEditor component
    app.component('QuillEditor', QuillEditor)
    import { createApp } from 'vue'
    import { QuillEditor } from '@vueup/vue-quill'
    
    const app = createApp()
    const globalOptions = {
      debug: 'info',
      modules: {
        toolbar: ['bold', 'italic', 'underline']
      },
      placeholder: 'Compose an epic...',
      readOnly: true,
      theme: 'snow'
    }
    
    QuillEditor.props.globalOptions.default = () => globalOptions
    app.component('QuillEditor', QuillEditor)
  8. Configure the toolbar using pre-configured options

    master

    VueQuill provides several built-in toolbar presets to quickly set up common formatting options. You can pass these presets as a string to the toolbar prop:

    • essential: A basic set of tools.
    • minimal: A minimal set of tools.
    • full: A comprehensive set of tools.
    • "" (empty string): Uses the default Quill options.
    <template>
      <QuillEditor toolbar="minimal" .../>
    </template>
  9. Configure Quill using the options prop

    master

    When registering the QuillEditor component locally, use the options prop to pass a configuration object. This object allows you to customize the editor's behavior, modules, and appearance for that specific instance.

    import { QuillEditor } from '@vueup/vue-quill'
    import '@vueup/vue-quill/dist/vue-quill.snow.css';
    
    export default {
      components: {
        QuillEditor
      },
      data() {
        return {
          options: {
            debug: 'info',
            modules: {
              toolbar: ['bold', 'italic', 'underline']
            },
            placeholder: 'Compose an epic...',
            readOnly: true,
            theme: 'snow'
          }
        }
      },
    }

    In your template, bind the object to the component:

    <template>
      <QuillEditor :options="options" />
    </template>
    import { QuillEditor } from '@vueup/vue-quill'
    import '@vueup/vue-quill/dist/vue-quill.snow.css';
    
    export default {
      components: {
        QuillEditor
      },
      data() {
        return {
          options: {
            debug: 'info',
            modules: {
              toolbar: ['bold', 'italic', 'underline']
            },
            placeholder: 'Compose an epic...',
            readOnly: true,
            theme: 'snow'
          }
        }
      },
    }
    
    // In template:
    // <QuillEditor :options="options" />