Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion on How to use this with vue-quill #97

Closed
eokwukwe opened this issue Aug 31, 2023 · 8 comments
Closed

Suggestion on How to use this with vue-quill #97

eokwukwe opened this issue Aug 31, 2023 · 8 comments

Comments

@eokwukwe
Copy link
Contributor

Has anyone tried using this package with vue-quill? I need help on how to integrate the vue-quill.

@c-w
Copy link
Owner

c-w commented Aug 31, 2023

What issues are you facing?

@eokwukwe
Copy link
Contributor Author

eokwukwe commented Sep 1, 2023

@c-w. The custom operator buttons are not showing. This is my component:

<script setup>
// KaTeX dependency
import katex from 'katex';
window.katex = katex;
import 'katex/dist/katex.css';

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

import '@edtr-io/mathquill/build/mathquill.js';
import '@edtr-io/mathquill/build/mathquill.css';

// mathquill4quill include
import mathquill4quill from 'mathquill4quill';
import 'mathquill4quill/mathquill4quill.css';

import { onBeforeMount, onMounted, ref } from 'vue';

const operators = [
  ['\\pm', '\\pm'],
  ['\\sqrt{x}', '\\sqrt'],
  ['\\sqrt[3]{x}', '\\sqrt[3]{}'],
  ['\\sqrt[n]{x}', '\\nthroot'],
  ['\\frac{x}{y}', '\\frac'],
  ['\\sum^{s}_{x}{d}', '\\sum'],
  ['\\prod^{s}_{x}{d}', '\\prod'],
  ['\\coprod^{s}_{x}{d}', '\\coprod'],
  ['\\int^{s}_{x}{d}', '\\int'],
  ['\\binom{n}{k}', '\\binom'],
];

const quill = ref();
const content = ref('');

onMounted(() => {
  console.log('mounted', quill.value);
  const enableMathQuillFormulaAuthoring = mathquill4quill({ Quill, katex });

  enableMathQuillFormulaAuthoring(quill, {
    operators,
  });
});

const textChange = (prop) => {
  console.log('textChange', content.value);
};
</script>

<template>
  <div>
    <QuillEditor
      id="quill-editor"
      v-model:content="content"
      theme="snow"
      placeholder="Type text here, or click on the formula button to enter math."
      ref="quill"
      :options="{
        modules: {
          formula: true,
          toolbar: [['bold', 'italic', 'underline'], ['formula']],
        },
      }"
      @editorChange="textChange"
    />
  </div>
</template>

When I load the page, check the error:
image

The error is coming from this line

  enableMathQuillFormulaAuthoring(quill, {
    operators,
  });

I have tried using quill.value like this:

  enableMathQuillFormulaAuthoring(quill.value, {
    operators,
  });

but I get the error:
image

@c-w
Copy link
Owner

c-w commented Sep 3, 2023

I don’t regularly use Vue, but if you open a pull request with a minimal setup/demo project (like this one for React), I can take a look and fix/integrate it.

@eokwukwe
Copy link
Contributor Author

eokwukwe commented Sep 4, 2023

@c-w. I just added the PR.

@c-w
Copy link
Owner

c-w commented Sep 6, 2023

Thanks for the PR, will review by end of week.

@c-w
Copy link
Owner

c-w commented Sep 29, 2023

@eokwukwe Apologies for the delay and thank you for providing the sample code. I now found some time to look into this and found the issue. It turns out that unlike the main quill library, vue-quill doesn't expose the .container property on the quill reference. Injecting this value manually into the object that's passed down to mathquill4quill like shown in the patch below will fix the integration.

diff --git a/rvuejs/src/components/TextEditor.vue b/rvuejs/src/components/TextEditor.vue
index 6aec045..2f96db0 100644
--- a/rvuejs/src/components/TextEditor.vue
+++ b/rvuejs/src/components/TextEditor.vue
@@ -33,6 +33,7 @@ const content = ref('');
 
 onMounted(() => {
   console.log('mounted', quill.value);
+  quill.value.container = quill.value.getEditor();
   const enableMathQuillFormulaAuthoring = mathquill4quill({ Quill, katex });
 
   enableMathQuillFormulaAuthoring(quill.value, {

For now, you can work around the issue like shown above, but ideally this is something that would be fixed in the upstream vue-quill project. Feel free to submit an issue linked to this one and let's see if vue-quill is willing to fix the problem.

@c-w c-w mentioned this issue Sep 29, 2023
@c-w c-w closed this as completed Oct 4, 2023
@digitalboy
Copy link

digitalboy commented Dec 3, 2023

<template>
    <QuillEditor id="quill-editor" ref="quillEditor" theme="snow" v-model:content="content" :options="editorOptions" />
</template>

<script lang="ts">
import "./jquery";
import katex from 'katex';
window.katex = katex;
import { ref, onMounted, defineComponent} from 'vue';
import { QuillEditor, Quill } from '@vueup/vue-quill';
import mathquill4quill from 'mathquill4quill';
import '@edtr-io/mathquill/build/mathquill.js';
import '@vueup/vue-quill/dist/vue-quill.snow.css';
import 'katex/dist/katex.min.css';
import '@edtr-io/mathquill/build/mathquill.css';
import 'mathquill4quill/mathquill4quill.css';

export default defineComponent({
    components: { QuillEditor },
    setup() {
        const content = ref('');
        const quillEditor =  ref();

        // 定义 operators 数组
        const operators = [
            ["\\pm", "\\pm"],
            ["\\sqrt{x}", "\\sqrt"],
            ["\\sqrt[3]{x}", "\\sqrt[3]{}"],
            ["\\sqrt[n]{x}", "\\nthroot"],
            ["\\frac{x}{y}", "\\frac"],
            ["\\sum^{s}_{x}{d}", "\\sum"],
            ["\\prod^{s}_{x}{d}", "\\prod"],
            ["\\coprod^{s}_{x}{d}", "\\coprod"],
            ["\\int^{s}_{x}{d}", "\\int"],
            ["\\binom{n}{k}", "\\binom"]
        ];

        const editorOptions = {
            modules: {
                toolbar: [['formula']],
            },
        };

        onMounted(() => {
            if (quillEditor.value && quillEditor.value.$quill) {
                const quillInstance = quillEditor.value.$quill;
                quillInstance.container = quillInstance.getEditor();
                const enableMathQuillFormulaAuthoring = mathquill4quill({ Quill, katex });
                enableMathQuillFormulaAuthoring(quillInstance, {
                    operators: operators
                });
            }

        });

        return { content, quillEditor, editorOptions };
    },
});
</script>

there is not operators, could you tell me the reason? thanks.

@c-w
Copy link
Owner

c-w commented Dec 4, 2023

@digitalboy Take a look at the VueJS demo and code for how to integrate operators correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants