Ckeditor5: Toolbar positioning affected by Highlight plugin

Created on 17 Dec 2018  路  4Comments  路  Source: ckeditor/ckeditor5

import InlineEditorBase from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';

import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
import UploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter';
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import Font from '@ckeditor/ckeditor5-font/src/font';
import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
import Link from '@ckeditor/ckeditor5-link/src/link';
import List from '@ckeditor/ckeditor5-list/src/list';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Table from '@ckeditor/ckeditor5-table/src/table';
import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';

Seems like when I import the Highlight plugin to the Inline Editor, it repositions the toolbar to the bottom of the editor. Without the Highlight plugin, the toolbar is at the top.

I was able to compare the generated styles.css with and without the Highlight plugin. It seems like the Highlight plugin generated some duplicate css. When I removed the additional css generated by the Highlight plugin, the toolbar was properly positioned on top of the editor.

Also when I removed the css generated by the Highlight plugin, the toolbar was at the top but the toolbar Highlight button styling was a little off.

With Highlight css
screen shot 2018-12-17 at 4 50 08 pm

Without Highlight css
screen shot 2018-12-17 at 4 51 41 pm

I am extracting the css into a separate file as per the documentation.

highlight feedback bug

Most helpful comment

Hi @oleq,

I downloaded the stable branch of the @ckeditor/ckeditor5-inline some time ago and I think when I was looking into CKE I did this manually and skipped that first step of cloning (I probably just downloaded the copy where I was reading the docs on github) .

I did not get the build version, @ckeditor5-build-inline.

I was now able to get everything working properly following your steps.

Thanks for your help!

All 4 comments

Unchecking the duplicate css (look at css block 3) made the toolbar appear on top. Now what is creating the duplicate css. Notice css block 3 and 6 are identical.

.ck.ck-reset, .ck.ck-reset_all, .ck.ck-reset_all * {
box-sizing: border-box;
width: auto;
height: auto;
position: static;
}

screen shot 2018-12-17 at 5 10 41 pm

Hi it looks like another issue related to how plugins are bundled.

@markopfc please check my reply in ckeditor/ckeditor5-highlight#31 it might solve your issue. Also please could you post how do you build & configure your editor?

/cc @oleq

@markopfc I couldn't reproduce the issue. What I did was:

  1. Clone https://github.com/ckeditor/ckeditor5-build-inline.
  2. Added
"@ckeditor/ckeditor5-highlight": "^10.0.4",
"@ckeditor/ckeditor5-font": "^10.0.4",`

to package.json (npm i)

  1. Used the following ckeditor.js
import InlineEditorBase from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';

import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
import Font from '@ckeditor/ckeditor5-font/src/font';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';
import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import Link from '@ckeditor/ckeditor5-link/src/link';
import List from '@ckeditor/ckeditor5-list/src/list';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Table from '@ckeditor/ckeditor5-table/src/table';
import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';
import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';

export default class InlineEditor extends InlineEditorBase {}

// Plugins to include in the build.
InlineEditor.builtinPlugins = [
    Autoformat,
    BlockQuote,
    Bold,
    CKFinder,
    EasyImage,
    Essentials,
    Font,
    Heading,
    Highlight,
    Image,
    ImageCaption,
    ImageStyle,
    ImageToolbar,
    ImageUpload,
    Italic,
    Link,
    List,
    MediaEmbed,
    Paragraph,
    Table,
    TableToolbar,
    Underline
];

// Editor configuration.
InlineEditor.defaultConfig = {
    toolbar: {
        items: [
            'heading',
            '|',
            'bold',
            'italic',
            'link',
            'bulletedList',
            'numberedList',
            'imageUpload',
            'blockQuote',
            'insertTable',
            'mediaEmbed',
            'undo',
            'redo',
            'highlight'
        ]
    },
    image: {
        toolbar: [
            'imageStyle:full',
            'imageStyle:side',
            '|',
            'imageTextAlternative'
        ]
    },
    table: {
        contentToolbar: [
            'tableColumn',
            'tableRow',
            'mergeTableCells'
        ]
    },
    // This value must be kept in sync with the language defined in webpack.config.js.
    language: 'en'
};
  1. Installed dependencies required to extract CSS
npm install --save \    
    mini-css-extract-plugin \
    css-loader
  1. Used the following webpack config
/**
 * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

/* eslint-env node */

const path = require( 'path' );
const webpack = require( 'webpack' );
const { bundler, styles } = require( '@ckeditor/ckeditor5-dev-utils' );
const CKEditorWebpackPlugin = require( '@ckeditor/ckeditor5-dev-webpack-plugin' );
const UglifyJsWebpackPlugin = require( 'uglifyjs-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );

module.exports = {
    devtool: 'source-map',
    performance: { hints: false },

    entry: path.resolve( __dirname, 'src', 'ckeditor.js' ),

    output: {
        // The name under which the editor will be exported.
        library: 'InlineEditor',

        path: path.resolve( __dirname, 'build' ),
        filename: 'ckeditor.js',
        libraryTarget: 'umd',
        libraryExport: 'default'
    },

    optimization: {
        minimizer: [
            new UglifyJsWebpackPlugin( {
                sourceMap: true,
                uglifyOptions: {
                    output: {
                        // Preserve CKEditor 5 license comments.
                        comments: /^!/
                    }
                }
            } )
        ]
    },

    plugins: [
        new CKEditorWebpackPlugin( {
            // UI language. Language codes follow the https://en.wikipedia.org/wiki/ISO_639-1 format.
            // When changing the built-in language, remember to also change it in the editor's configuration (src/ckeditor.js).
            language: 'en',
            additionalLanguages: 'all'
        } ),
        new webpack.BannerPlugin( {
            banner: bundler.getLicenseBanner(),
            raw: true
        } ),
        new MiniCssExtractPlugin( {
            filename: 'styles.css'
        } )
    ],

    module: {
        rules: [
            {
                test: /\.svg$/,
                use: [ 'raw-loader' ]
            },
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    {
                        loader: 'postcss-loader',
                        options: styles.getPostCssConfig( {
                            themeImporter: {
                                themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
                            },
                            minify: true
                        } )
                    },
                ]
            }
        ]
    }
};
  1. npm run build

Everything looks fine, no mangled highlight dropdown arrow, correct toolbar position

image


Just to make sure we're on the same page, are you 100% sure you used @ckeditor/ckeditor5-editor-classic, not @ckeditor/ckeditor5-build-classic?

Because if you used the later, something like that must actually happen (both JS and CSS files will duplicate), as is stated in our docs:

One of the possible mistakes is trying to add a plugin in this way to an existing (bundled) editor build. Installing an existing build and then trying to add a plugin to it may not work if that plugin needs to import any of the source editor modules.

The reason why this method will not work is that dependencies of the added plugin may duplicate the code already bundled in the used editor build. In the best scenario, this is going to raise the overall code size. In the worst scenario, an application built this way may be unstable.

Hi @oleq,

I downloaded the stable branch of the @ckeditor/ckeditor5-inline some time ago and I think when I was looking into CKE I did this manually and skipped that first step of cloning (I probably just downloaded the copy where I was reading the docs on github) .

I did not get the build version, @ckeditor5-build-inline.

I was now able to get everything working properly following your steps.

Thanks for your help!

Was this page helpful?
0 / 5 - 0 ratings