Я сделал собственную сборку из CKEditor 5 Online Builder и загрузил ее, но она собрана в Webpack, а я использую Vite в Vue 3 Project.
Я попробовал код ниже:
<script setup>
import CKEditor from "@/ckeditor5-custom-build/build/ckeditor"
import { component as ckeditor } from "@ckeditor/ckeditor5-vue";
const editor = ref(CKEditor);
const editorData = ref("");
const editorConfig = ref({});
</script>
<template>
<ckeditor :editor = "editor" :config = "editorConfig" v-model = "editorData"></ckeditor>
</template>
Я получаю ошибку ниже:
Модуль не найден: Ошибка: невозможно разрешить «ckeditor5-custom-build/build/ckeditor».
После загрузки zip-файла сборки из CKEditor 5 Online Builder. Распакуйте zip-архив и перейдите в папку, откройте файл package.json.
{
...
"dependencies": {
"@ckeditor/ckeditor5-alignment": "41.2.1",
"@ckeditor/ckeditor5-autoformat": "41.2.1",
"@ckeditor/ckeditor5-basic-styles": "41.2.1",
"@ckeditor/ckeditor5-block-quote": "41.2.1",
"@ckeditor/ckeditor5-cloud-services": "41.2.1",
"@ckeditor/ckeditor5-editor-classic": "41.2.1",
"@ckeditor/ckeditor5-essentials": "41.2.1",
"@ckeditor/ckeditor5-font": "41.2.1",
"@ckeditor/ckeditor5-heading": "41.2.1",
"@ckeditor/ckeditor5-image": "41.2.1",
"@ckeditor/ckeditor5-indent": "41.2.1",
"@ckeditor/ckeditor5-link": "41.2.1",
"@ckeditor/ckeditor5-list": "41.2.1",
"@ckeditor/ckeditor5-media-embed": "41.2.1",
"@ckeditor/ckeditor5-paragraph": "41.2.1",
"@ckeditor/ckeditor5-paste-from-office": "41.2.1",
"@ckeditor/ckeditor5-table": "41.2.1",
"@ckeditor/ckeditor5-typing": "41.2.1",
"@ckeditor/ckeditor5-undo": "41.2.1",
"@ckeditor/ckeditor5-upload": "41.2.1"
},
...
}
Скопируйте все зависимости из файла package.json, кроме devDependency, и вставьте их в файл package.json вашего проекта и запустите команду npm i
.
Перейдите в подпапку src
в извлеченной папке и откройте ckeditor.ts
.
файл
/**
* @license Copyright (c) 2014-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { Alignment } from '@ckeditor/ckeditor5-alignment';
import { Autoformat } from '@ckeditor/ckeditor5-autoformat';
import { Bold, Italic, Strikethrough, Underline } from '@ckeditor/ckeditor5-basic-styles';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import type { EditorConfig } from '@ckeditor/ckeditor5-core';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { FontBackgroundColor, FontColor, FontFamily, FontSize } from '@ckeditor/ckeditor5-font';
import { Heading } from '@ckeditor/ckeditor5-heading';
import {
AutoImage,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload
} from '@ckeditor/ckeditor5-image';
import { Indent } from '@ckeditor/ckeditor5-indent';
import { AutoLink, Link, LinkImage } from '@ckeditor/ckeditor5-link';
import { List, ListProperties } from '@ckeditor/ckeditor5-list';
import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
import { PasteFromOffice } from '@ckeditor/ckeditor5-paste-from-office';
import {
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar
} from '@ckeditor/ckeditor5-table';
import { TextTransformation } from '@ckeditor/ckeditor5-typing';
import { Undo } from '@ckeditor/ckeditor5-undo';
import { Base64UploadAdapter } from '@ckeditor/ckeditor5-upload';
// You can read more about extending the build with additional plugins in the "Installing plugins" guide.
// See https://ckeditor.com/docs/ckeditor5/latest/installation/plugins/installing-plugins.html for details.
class Editor extends ClassicEditor {
public static override builtinPlugins = [
Alignment,
AutoImage,
AutoLink,
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
CloudServices,
Essentials,
FontBackgroundColor,
FontColor,
FontFamily,
FontSize,
Heading,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
LinkImage,
List,
ListProperties,
MediaEmbed,
Paragraph,
PasteFromOffice,
Strikethrough,
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar,
TextTransformation,
Underline,
Undo
];
public static override defaultConfig: EditorConfig = {
toolbar: {
items: [
'heading',
'|',
'bold',
'italic',
'underline',
'alignment',
'|',
'link',
'strikethrough',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
'|',
'fontSize',
'fontFamily',
'|',
'fontBackgroundColor',
'fontColor',
'|',
'imageUpload',
'|',
'undo',
'redo'
]
},
language: 'en',
image: {
toolbar: [
'imageTextAlternative',
'toggleImageCaption',
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side',
'linkImage'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
}
};
}
export default Editor;
Скопируйте все операторы импорта из файла ckeditor.ts
.
Создайте новый файл Vue с именем Editor.vue
и вставьте операторы импорта.
Редактор.vue
<script setup>
import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { Alignment } from '@ckeditor/ckeditor5-alignment';
import { Autoformat } from '@ckeditor/ckeditor5-autoformat';
import { Bold, Italic, Strikethrough, Underline } from '@ckeditor/ckeditor5-basic-styles';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import type { EditorConfig } from '@ckeditor/ckeditor5-core';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { FontBackgroundColor, FontColor, FontFamily, FontSize } from '@ckeditor/ckeditor5-font';
import { Heading } from '@ckeditor/ckeditor5-heading';
import {
AutoImage,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload
} from '@ckeditor/ckeditor5-image';
import { Indent } from '@ckeditor/ckeditor5-indent';
import { AutoLink, Link, LinkImage } from '@ckeditor/ckeditor5-link';
import { List, ListProperties } from '@ckeditor/ckeditor5-list';
import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
import { PasteFromOffice } from '@ckeditor/ckeditor5-paste-from-office';
import {
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar
} from '@ckeditor/ckeditor5-table';
import { TextTransformation } from '@ckeditor/ckeditor5-typing';
import { Undo } from '@ckeditor/ckeditor5-undo';
import { Base64UploadAdapter } from '@ckeditor/ckeditor5-upload';
<script>
Установите следующие пакеты
@ckeditor/ckeditor5-vue
@ckeditor/vite-plugin-ckeditor5
@ckeditor/ckeditor5-theme-lark
Установите плагин @ckeditor/vite-plugin-ckeditor5
в vite.config.js.
import ckeditor5 from "@ckeditor/vite-plugin-ckeditor5";
import { createRequire } from 'node:module';
const require = createRequire( import.meta.url ); /** Resolve Error: require.resolve is not a function **/
{
...
plugins: [
vue(),
ckeditor5({
theme: require.resolve("@ckeditor/ckeditor5-theme-lark"),
}),
],
...
},
Используйте @ckeditor/ckeditor5-vue
официальный пакет
<script setup>
...
import { component as ckeditor } from "@ckeditor/ckeditor5-vue"; /** <-- Here like this **/
const editor = ref(ClassicEditor);
const editorData = defineModel();
const editorConfig = ref({
plugins: []
})
<script>
<template>
<ckeditor :editor = "editor" :config = "editorConfig" v-model = "editorData"></ckeditor>
</template>
Откройте ckeditor.ts
и скопируйте все элементы из встроенного массива Plugins.
...
class Editor extends ClassicEditor {
public static override builtinPlugins = [
Alignment,
AutoImage,
AutoLink,
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
CloudServices,
Essentials,
FontBackgroundColor,
FontColor,
FontFamily,
FontSize,
Heading,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
LinkImage,
List,
ListProperties,
MediaEmbed,
Paragraph,
PasteFromOffice,
Strikethrough,
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar,
TextTransformation,
Underline,
Undo
];
...
Вернитесь к файлу Editor.vue и вставьте его в свойство переменных плагинов editorConfig
.
...
const editor = ref(ClassicEditor);
const editorData = defineModel();
const editorConfig = ref({
plugins: [
Alignment,
AutoImage,
AutoLink,
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
CloudServices,
Essentials,
FontBackgroundColor,
FontColor,
FontFamily,
FontSize,
Heading,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
LinkImage,
List,
ListProperties,
MediaEmbed,
Paragraph,
Strikethrough,
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar,
TextTransformation,
Underline,
Undo
],
});
...
Откройте ckeditor.ts, а также скопируйте все свойства со значениями из defaultConfig
и вставьте их в Editor.vue.
<script setup>
import { ref } from 'vue';
import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { Alignment } from '@ckeditor/ckeditor5-alignment';
import { Autoformat } from '@ckeditor/ckeditor5-autoformat';
import { Bold, Italic, Strikethrough, Underline } from '@ckeditor/ckeditor5-basic-styles';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { FontBackgroundColor, FontColor, FontFamily, FontSize } from '@ckeditor/ckeditor5-font';
import { Heading } from '@ckeditor/ckeditor5-heading';
import {
AutoImage,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload
} from '@ckeditor/ckeditor5-image';
import { Indent } from '@ckeditor/ckeditor5-indent';
import { AutoLink, Link, LinkImage } from '@ckeditor/ckeditor5-link';
import { List, ListProperties } from '@ckeditor/ckeditor5-list';
import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
import {
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar
} from '@ckeditor/ckeditor5-table';
import { TextTransformation } from '@ckeditor/ckeditor5-typing';
import { Undo } from '@ckeditor/ckeditor5-undo';
import { Base64UploadAdapter } from '@ckeditor/ckeditor5-upload';
import { component as ckeditor } from "@ckeditor/ckeditor5-vue";
const editor = ref(ClassicEditor);
const editorData = defineModel();
const editorConfig = ref({
plugins: [
Alignment,
AutoImage,
AutoLink,
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
CloudServices,
Essentials,
FontBackgroundColor,
FontColor,
FontFamily,
FontSize,
Heading,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
LinkImage,
List,
ListProperties,
MediaEmbed,
Paragraph,
Strikethrough,
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar,
TextTransformation,
Underline,
Undo
],
toolbar: {
items: [
'heading',
'|',
'bold',
'italic',
'underline',
'alignment',
'|',
'link',
'strikethrough',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
'|',
'fontSize',
'fontFamily',
'|',
'fontBackgroundColor',
'fontColor',
'|',
'imageUpload',
'|',
'undo',
'redo'
]
},
language: 'en',
image: {
toolbar: [
'imageTextAlternative',
'toggleImageCaption',
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side',
'linkImage'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
},
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
{ model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
{ model: 'heading5', view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },
{ model: 'heading6', view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }
]
}
});
</script>
<template>
<ckeditor :editor = "editor" :config = "editorConfig" v-model = "editorData"></ckeditor>
</template>
Теперь импортируйте компонент редактора в любое место вашего проекта.
<script setup>
import { ref } from "vue";
import Editor from '@/components/Editor';
const description = ref("");
<script>
<template>
<Editor v-model = "description"/>
<template>