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

CKEditorError: ckeditor-duplicated-modules #16356

Open
TaoSun01 opened this issue May 15, 2024 · 0 comments
Open

CKEditorError: ckeditor-duplicated-modules #16356

TaoSun01 opened this issue May 15, 2024 · 0 comments
Labels
type:question This issue asks a question (how to...).

Comments

@TaoSun01
Copy link

TaoSun01 commented May 15, 2024

import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
import ButtonView from "@ckeditor/ckeditor5-ui/src/button/buttonview";
as soon as I introduce these two, an error will be reported

master file

<template>
  <div>
    <ckeditor
      :editor="editor"
      v-model="editorData"
      :config="editorConfig"
    ></ckeditor>
  </div>
</template>

<script>
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
import CKEditor from "@ckeditor/ckeditor5-vue2";
import CustomButton from "./CustomButton"; // 引入自定义按钮插件

export default {
  components: {
    ckeditor: CKEditor.component,
  },
  data() {
    return {
      editor: ClassicEditor,
      editorData: "<p>Content of the editor.</p>",
      editorConfig: {
        toolbar: [
          "heading",
          "|",
          "bold",
          "italic",
          "|",
          "bulletedList",
          "numberedList",
          "|",
          "undo",
          "redo",
          "|",
          "customButton", // 这里是自定义按钮
        ],
        extraPlugins: [CustomButton],
      },
    };
  },
};
</script>

<style>
#app {
  margin: 20px;
}
</style>

plug-in

import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
import ButtonView from "@ckeditor/ckeditor5-ui/src/button/buttonview";

export default class CustomButton extends Plugin {
  init() {
    const editor = this.editor;

    editor.ui.componentFactory.add("customButton", (locale) => {
      const view = new ButtonView(locale);

      view.set({
        label: "Custom Button",
        withText: true,
        tooltip: true,
      });

      // 添加按钮的点击事件
      view.on("execute", () => {
        editor.model.change((writer) => {
          const insertPosition =
            editor.model.document.selection.getFirstPosition();
          writer.insertText("Custom Text", insertPosition);
        });
      });

      return view;
    });
  }
}

image
image

@TaoSun01 TaoSun01 added the type:question This issue asks a question (how to...). label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question This issue asks a question (how to...).
Projects
None yet
Development

No branches or pull requests

1 participant