vue-quill icon indicating copy to clipboard operation
vue-quill copied to clipboard

Nuxt 3 Support

Open Cersin opened this issue 3 years ago • 13 comments

Hello, Has anyone run the plugin innuxt 3? Is it possible?

Cersin avatar Jan 30 '22 12:01 Cersin

This is possible in Nuxt 3 I'm currently using like this in the Nuxt config I had to define it as a custom components

vue: {
    compilerOptions: {
      isCustomElement: (tag) => ['OtherComponents', 'QuillEditor'].includes(tag),
    },
    config: {
      devtools: DEV_TOOLS,
    },
  },

I created a client side only plugin

import { defineNuxtPlugin } from "#app";

import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css';

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.component('QuillEditor', QuillEditor);
})

Than I used it in a component

      <quill-editor
        theme="snow"
        :toolbar="toolBarOptions()"
      />

lperez22 avatar Feb 12 '22 01:02 lperez22

Also just recently discovered how to pull in quill editor locally in Nuxt 3, in the script you have to dynamically import the component

<template>
  <quill-editor
    theme="snow"
    :toolbar="toolBarOptions()"
  />
</template>

import '@vueup/vue-quill/dist/vue-quill.snow.css';
export default {
 
  async setup() {
    if (!process.server) {
      const { QuillEditor } = await import('@vueup/vue-quill');
      const { vueApp } = useNuxtApp();
      vueApp.component('QuillEditor', QuillEditor);
    }
  },

}

lperez22 avatar Feb 24 '22 17:02 lperez22

Also just recently discovered how to pull in quill editor locally in Nuxt 3, in the script you have to dynamically import the component

<template>
  <quill-editor
    theme="snow"
    :toolbar="toolBarOptions()"
  />
</template>

import '@vueup/vue-quill/dist/vue-quill.snow.css';
export default {
 
  async setup() {
    if (!process.server) {
      const { QuillEditor } = await import('@vueup/vue-quill');
      const { vueApp } = useNuxtApp();
      vueApp.component('QuillEditor', QuillEditor);
    }
  },

}

how import module ? i want use html-button can you show some example?

andysay avatar Apr 02 '22 18:04 andysay

Also just recently discovered how to pull in quill editor locally in Nuxt 3, in the script you have to dynamically import the component

<template>
  <quill-editor
    theme="snow"
    :toolbar="toolBarOptions()"
  />
</template>

import '@vueup/vue-quill/dist/vue-quill.snow.css';
export default {
 
  async setup() {
    if (!process.server) {
      const { QuillEditor } = await import('@vueup/vue-quill');
      const { vueApp } = useNuxtApp();
      vueApp.component('QuillEditor', QuillEditor);
    }
  },

}

how import module ? i want use html-button can you show some example?

I'm able to import a module like so

<template>
  <quill-editor
    theme="snow"
    :modules="modules"
    :toolbar="toolBarOptions()"
  />
</template>


import '@vueup/vue-quill/dist/vue-quill.snow.css';
import htmlEditButton from 'quill-html-edit-button';

export default {
  async setup() {
    if (!process.server) {
      const { vueApp } = useNuxtApp();
      const { QuillEditor } = await import('@vueup/vue-quill');
      // only register the quill component once
      if (!vueApp._context.components.QuillEditor) vueApp.component('QuillEditor', QuillEditor);
    }
    const modules = {
      name: 'htmlButton',
      module: htmlEditButton,
    };
    return { modules };
  },

lperez22 avatar May 03 '22 13:05 lperez22

Or if you wanted to dynamically import the file

  async setup() {
    if (!process.server) {
      const { vueApp } = useNuxtApp();
      const { QuillEditor } = await import('@vueup/vue-quill');
      // only register the quill component once
      if (!vueApp._context.components.QuillEditor) vueApp.component('QuillEditor', QuillEditor);
    }
    const { htmlEditButton } = await import('quill-html-edit-button');
    const modules = {
      name: 'htmlButton',
      module: htmlEditButton,
    };
    return { modules };
  },

lperez22 avatar May 03 '22 13:05 lperez22

I keep on getting the following: Invalid theme undefined. Did you register it and: quill Cannot import themes/snow. Are you sure it was registered?

plugins/quill-editor.client.ts

import { defineNuxtPlugin } from '#app' import { QuillEditor } from '@vueup/vue-quill' import '@vueup/vue-quill/dist/vue-quill.snow.css'; import '@vueup/vue-quill/dist/vue-quill.bubble.css'; export default defineNuxtPlugin(nuxtApp => { // Doing something with nuxtApp nuxtApp.vueApp.component('QuillEditor', QuillEditor); })

@Iperez22 are you using nuxt3 rc?

PMLS3 avatar May 24 '22 12:05 PMLS3

I haven't updated to nuxt3 rc yet, im still on Beta and am waiting for the stable release so that I only have to fix things once and retest everything

lperez22 avatar May 24 '22 21:05 lperez22

I haven't updated to nuxt3 rc yet, im still on Beta and am waiting for the stable release so that I only have to fix things once and retest everything

Your foresight was better than mine :)

PMLS3 avatar May 25 '22 06:05 PMLS3

Hi @PMLS3 and @lperez22 Have you solved the Nuxt3 RC implementation yet.

I have done the following and it does not work yet.

Index page: <ClientOnly> <template #fallback> <!-- this will be rendered on server side --> <p>Loading editor...</p> </template> <Editor> <h2>Editor component has been loaded now...</h2> </Editor> </ClientOnly>

Editor Component:

<template> <slot></slot> <QuillEditor :content="content" theme="bubble"></QuillEditor> </template>

import '@vueup/vue-quill/dist/vue-quill.bubble.css' const { QuillEditor } = await import('@vueup/vue-quill'); const { vueApp } = useNuxtApp(); if (!vueApp._context.components.QuillEditor) vueApp.component('QuillEditor', QuillEditor); const content = ref('Test content in editor!')

Added the following config to nuxt.config.ts vue: { compilerOptions: { isCustomElement: (tag) => ['OtherComponents', 'QuillEditor'].includes(tag), }, },

I don't get any errors, but the editor is not rendered. any clues??

Screenshot 2022-06-08 at 13 11 37

chkb avatar Jun 08 '22 11:06 chkb

@chkb Same here, even thou it used to work a few days ago, now it just refuses to render

ad-on-is avatar Jun 14 '22 07:06 ad-on-is

image

I am the same, but when i check the console, it giving me this error

ProgrZZ avatar Jun 17 '22 01:06 ProgrZZ

Hey I just recently upgraded to nuxt rc-3, I am able to get this to work in plugin like so

plugins/quill.client.js

import { defineNuxtPlugin } from '#app';

import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component('QuillEditor', QuillEditor);
});

Than in a component

<template>
  <div>
      <quill-editor theme="snow" />
  </div>
</template>

or if you dont need a plugin and just want it registered locally make a component like this

components/Test.vue

<template>
  <div>
    <quill-editor theme="snow" />
  </div>
</template>

<script>
import '@vueup/vue-quill/dist/vue-quill.snow.css';
export default {
  async setup() {
    if (!process.server) {
      const { QuillEditor } = await import('@vueup/vue-quill');
      const { vueApp } = useNuxtApp();
      if (!vueApp._context.components.QuillEditor) vueApp.component('QuillEditor', QuillEditor);
    }
  },
};
</script>

I was able to use the bubble theme as well, it looks like nothing renders but bubble doesnt have any menus it just might need some styling so that uses can see a box image

lperez22 avatar Jul 18 '22 13:07 lperez22

[Vue warn]: Failed to resolve component: QuillEditor If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. Everything was fine except for this warning, but when I tried to add

vue: {
    compilerOptions: {
      isCustomElement: (tag) => 'QuillEditor' === tag
    }
  }

The editor component is then not rendered.

@lperez22 Is there any solution?

ikexing-cn avatar Jul 27 '22 09:07 ikexing-cn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 26 '22 08:09 stale[bot]

How woud you add an Image module to it aswell?

wojtekpiskorz avatar Jan 08 '23 07:01 wojtekpiskorz

Hi @lperez22 , Would you mind also showing an example how to use it as plugin with a module (or modules) included. Thank you very very much

Hey I just recently upgraded to nuxt rc-3, I am able to get this to work in plugin like so

plugins/quill.client.js

import { defineNuxtPlugin } from '#app';

import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component('QuillEditor', QuillEditor);
});

Than in a component

<template>
  <div>
      <quill-editor theme="snow" />
  </div>
</template>

klukiyan avatar Jan 19 '23 22:01 klukiyan

Wrap it to component:

<template>
  <QuillEditor theme="snow" />
</template>

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

And add .client to file name for example TextEditor.client.vue. It works for me.

Vesely avatar Jan 20 '23 15:01 Vesely

Wrap it to component:

<template>
  <QuillEditor theme="snow" />
</template>

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

And add .client to file name for example TextEditor.client.vue. It works for me.

Hi, Did you manage to add modules with such setup? Table, html, markdown, etc...

klukiyan avatar Jan 20 '23 16:01 klukiyan

@klukiyan Hi, yes like this

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

<script setup>
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
import MagicUrl from 'quill-magic-url';

const modules = [
  {
    name: 'quill-magic-url',
    module: MagicUrl,
  },
];
</script>

Vesely avatar Jan 22 '23 17:01 Vesely

@Vesely Thank you. It shows typescript error on import. but otherwise it works. thank you very much

@klukiyan Hi, yes like this

klukiyan avatar Jan 22 '23 19:01 klukiyan

Hi guys !! i found very easy solution for that. First of all install quill npm i quill then paste the below code

<template> <div id="editor"></div> </template>

`

export default { setup() { onMounted(async () => { if (process.client) { const Quill = (await import("quill")).default; const quill = new Quill("#editor", { theme: "snow", modules: { toolbar: { container: [ ["image"], ["link", "video"], [{ header: [1, 2, 3, 4, 5, 6, false] }], ], }, }, }); } }); }, }; `

mahfuj10 avatar Feb 16 '23 14:02 mahfuj10

It's my first time using WYSIWYG and it looks like this configuration works for me. I'll try to use this on my project and see if it works well.

Note: don't forget to wrap it with the <ClientOnly> api component.

<script setup lang="ts">
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
</script>
<template>
  <div>
    <ClientOnly>
      <QuillEditor theme="snow" />
    </ClientOnly>
  </div>
</template>

Nuxt: ^3.3.2

Working example. https://stackblitz.com/edit/nuxt-starter-ibc8jw?file=pages/index.vue

ReaganM02 avatar Apr 01 '23 23:04 ReaganM02

I plan to inject custom features, so I went even further. I wrapped it into a custom client side component and call it wherever needed.

Component

//components.TextEditor.client.vue

<script setup lang="ts">
import QuillMarkdown from 'quilljs-markdown'

const props = defineProps<{
  modelValue: any
  placeholder?: string
}>()
const emit = defineEmits(['update:modelValue'])
const switchValue = ref(false as boolean)

const modules = [
  {
    name: 'quilljs-markdown',
    module: QuillMarkdown,
  },
]
const text = computed({
  get() {
    return props.modelValue
  },
  set(value) {
    emit('update:modelValue', value)
  },
})
</script>

<template>
  <span class="p-float-label mt-2">
    <div class="absolute right-2 top-2 text-green-400">
      <InputSwitch v-model="switchValue" />
    </div>
    <QuillEditor v-if="!switchValue" v-model:content="text" :placeholder="placeholder || ''" content-type="html" theme="snow" class="quil-editor" :modules="modules" />
    <QuillEditor v-else v-model:content="text" :placeholder="placeholder || ''" content-type="html" theme="snow" class="quil-editor" toolbar="full" :modules="modules" />
  </span>
</template>

<style>
div.ql-tooltip.ql-editing{
  left: inherit !important;
}
</style>

and call it like such:

<TextEditor v-model="longDescription" placeholder="Enter detailed project description here" />

klukiyan avatar Apr 05 '23 12:04 klukiyan

(!process.server)

Hey so I was able to load in a module in Nuxt 3, it was a little tricky but the main issue is that most of the modules will need to be client side loaded only because they rely on things like the window object, etc

So here are the steps to recap,

  1. Need a client side plugin, or load in the component client side only
/plugins/quill.client.ts
import { defineNuxtPlugin } from "#app";
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css';

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.component('QuillEditor', QuillEditor);
})
  1. Need to register the custom element
nuxt.config.ts
  vue: {
    compilerOptions: {
      isCustomElement: (tag: string) => ['QuillEditor'].includes(tag)
    },
  },
  1. Here is a sample of how I was able to load in the module client side only, I'm using if(!process.server) inside of setup() to ensure it will only be done in client side, but will need to be asynchronous because we are dynamically importing a package, it would be much better to do this in the plugin, but I haven't found much information in the documentation on how to properly do this
/components/Editor.vue
<template>
  <div class="editor-wrapper">
    <ClientOnly>
      <quill-editor
        v-model:content="htmlEditor"
        :toolbar="toolBarOptions"
        :syntax="true"
        :options="{ height: 150 }"
        :modules="modules"
        contentType="html"
        theme="snow"
      />
    </ClientOnly>
  </div>
</template>

<script>

export default {
  name: 'app',
  async setup() {
    if (!process.server) {
      const { htmlEditButton } = await import("quill-html-edit-button");
      const modules = {
        name: 'htmlEditButton',  
        module: htmlEditButton, 
      };
      console.log('-=-=-=-=-=', htmlEditButton);

      return { modules };
    }
  },

luisperez1050 avatar Sep 25 '23 20:09 luisperez1050

It's my first time using WYSIWYG and it looks like this configuration works for me. I'll try to use this on my project and see if it works well.

Note: don't forget to wrap it with the <ClientOnly> api component.

<script setup lang="ts">
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
</script>
<template>
  <div>
    <ClientOnly>
      <QuillEditor theme="snow" />
    </ClientOnly>
  </div>
</template>

Nuxt: ^3.3.2

Working example. https://stackblitz.com/edit/nuxt-starter-ibc8jw?file=pages/index.vue

This worked well but I am unable to get the full toolbar from the modules to work with this implementation.

Does anyone have some guidance with this?

Thank you

getshaun24 avatar Oct 10 '23 15:10 getshaun24

It's my first time using WYSIWYG and it looks like this configuration works for me. I'll try to use this on my project and see if it works well. Note: don't forget to wrap it with the <ClientOnly> api component.

<script setup lang="ts">
import { QuillEditor } from '@vueup/vue-quill';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
</script>
<template>
  <div>
    <ClientOnly>
      <QuillEditor theme="snow" />
    </ClientOnly>
  </div>
</template>

Nuxt: ^3.3.2 Working example. https://stackblitz.com/edit/nuxt-starter-ibc8jw?file=pages/index.vue

This worked well but I am unable to get the full toolbar from the modules to work with this implementation.

Does anyone have some guidance with this?

Thank you

Hi, I was adding modules semi-successfully. Some installed well (like markdown module). Some didn't work (like tables modules) So I abandoned quil editor in favor of Joddit editor. That one had a more difficult initial setup. But it works so great. All tables work. Very easy to customize and copy pasting from Excel/MS Outlook keeps the formatting. It's really amazing if you want something advanced.

klukiyan avatar Oct 10 '23 16:10 klukiyan