Dev*_*ght 5 ckeditor ckeditor5 angular7
我试图添加一个自定义插件以添加到ckeditor5-build-decoupled-document编辑器中。当我将自定义插件添加到ckeditor5-build-decoupled-document构建代码并运行时npm run build
。但是,当我将ckeditor.js构建文件添加到我的角度项目中时,出现错误TypeError:无法读取未定义的属性“ 0”。
编辑器工具栏不再显示在屏幕上,并且我无法编辑文本,但是,该插件似乎正在执行其允许在编辑器中使用内联样式的目的。
我有两个问题:
这些是我遵循的步骤以及所使用的代码
创建的插件
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
export default class Extension extends Plugin {
constructor( editor ) {
super( editor );
}
init() {
const editor = this.editor;
let allowedAttributes = [
'width', 'height', 'style', 'stylex', 'target', 'class', 'id', 'name', 'title', 'type', 'olddisplay', 'text-align', 'align',
'border', 'cellspacing','padding', 'cellpadding', 'color', 'valign', 'clear', 'src', 'shapes', '&',
'prefix', 'tagtype', 'datetime', 'cite', 'cols', 'colspan', 'noshade', 'text-decoration',
'shape', 'start', 'alt', 'strong', 'files', 'hr', 'font-size',
'com', 'background-color', 'rowspan', 'span', 'page', 'content',
'action', 'value', 'autofocus', 'maxlength', 'rows', 'for', 'aria-label', 'checked', 'selected',
'rel', 'scope', 'location', 'cellpacing', 'block-id', 'lang',
'original-style', 'datatype', 'property', 'controls', 'controlslist', 'data-attr', 'poster', 'preload',
'tabindex', 'role', 'aria-describedby', 'aria-disabled','aria-haspopup',
'href', 'col', 'doc', 'attach', 'pls', 'vspace', 'hspace', 'slatepath'];
//creates a new schema to to keep preexisting styles
editor.model.schema.extend('$root', { allowAttributes: allowedAttributes });
editor.model.schema.extend('$block', { allowAttributes: allowedAttributes });
editor.model.schema.extend('$text', { allowAttributes: allowedAttributes });
for (var i = 0; i < allowedAttributes.length; i++) {
editor.conversion.attributeToAttribute({ model: this.allowedAttributes[i], view: this.allowedAttributes[i] });
}
editor.model.schema.extend('paragraph', { allowAttributes: '__style' });
editor.conversion.for('upcast').attributeToAttribute({
model: {
key: '__style',
name: 'paragraph'
},
view: 'style'
});
editor.conversion.for('downcast').add(dispatcher => {
dispatcher.on('attribute:__style:paragraph', (evt, data, conversionApi) => {
conversionApi.consumable.consume(data.item, evt.name);
const viewElement = conversionApi.mapper.toViewElement(data.item);
conversionApi.writer.setAttribute('style', data.attributeNewValue, viewElement);
});
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我将插件添加到ckeditor.js文件中
import Extension from "../ckeditor5-extension/src/extension.js";
DecoupledEditor.builtinPlugins = [
*
*
PasteFromOffice,
Table,
TableToolbar,
Extension
];
Run Code Online (Sandbox Code Playgroud)
之后,我运行npm run build
该命令,在build文件夹中生成ckeditor.js。接下来,我将ckeditor.js(和相应的转换文件)从build文件夹复制到我的角度项目的资产文件夹中。
然后将我的自定义编辑器添加到我的文件中。
import * as CustomEditor from 'src/assets/ckeditor.js';
public Editor = CustomEditor;
Run Code Online (Sandbox Code Playgroud)
在tsconfig.json中
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
Run Code Online (Sandbox Code Playgroud)
在控制台中,当我为编辑器打印出插件时,我的自定义插件显示为未定义。
["Essentials", "Alignment", "FontSize", "FontFamily", "Highlight", "CKFinderUploadAdapter", "Autoformat", "Bold", "Italic", "Strikethrough", "Underline", "BlockQuote", "CKFinder", "EasyImage", "Heading", "Image", "ImageCaption", "ImageStyle", "ImageToolbar", "ImageUpload", "Link", "List", "MediaEmbed", "Paragraph", "PasteFromOffice", "Table", "TableToolbar", undefined]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
230 次 |
最近记录: |