npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ckeditor5-webcomponent

v2.0.5

Published

ckeditor5 webcomponent

Downloads

18

Readme

Built With Stencil

ckeditor5-webcomponent

This package wraps the ckeditor5 in a webcomponent named x-ckeditor.

Install

$ npm install --save ckeditor5-webcomponent

In order to be able to use this component you will have to install polyfills for webcomponents (v1 spec), and ckeditor

Usage

Because CKEditor 5 is very modular it was hard to design a webcomponent that was able to be that modular, allowing anyone to create and add new plugins to their editor without having to create new webcomponents.

That's why I decided to add another layer to this webcomponent: an Editor Manager.

The goal of this editor manager is to register ckeditor builds you want to use in your application. This way, when you use the x-ckeditor you only need to specify which ckeditor build you want to use.

Here is an example:

Let's say you want to use the ClassicEditor build. All you need is to install it and register it to the Editor Manager:

npm install --save @ckeditor/ckeditor5-build-classic

index.js

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import EditorManager from 'ckeditor5-webcomponent/dist/collection/editor-manager.js';
import { defineCustomElements } from 'ckeditor5-webcomponent/dist/esm/es2017/x-ckeditor.define.js';

defineCustomElements(window);

// We register the ClassicEditor under the name 'classic'
EditorManager.register('classic', ClassicEditor);

Once you did that, you can use the webcomponent with this particular editor:

index.html

<html>
    <body>
        <x-ckeditor editor="classic"></x-ckeditor>
    </body>
</html>

Using 2 or more ckeditor builds

Following the previous example, you can register more ckeditor builds.

Let's say you just followed the custom build tutorial and created a new build:

my-build.js

'use strict';

// The editor creator to use.
import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

import EssentialsPlugin from '@ckeditor/ckeditor5-essentials/src/essentials';
import AutoformatPlugin from '@ckeditor/ckeditor5-autoformat/src/autoformat';
import BoldPlugin from '@ckeditor/ckeditor5-basic-styles/src/bold';
import ItalicPlugin from '@ckeditor/ckeditor5-basic-styles/src/italic';
import HeadingPlugin from '@ckeditor/ckeditor5-heading/src/heading';
import LinkPlugin from '@ckeditor/ckeditor5-link/src/link';
import ListPlugin from '@ckeditor/ckeditor5-list/src/list';
import ParagraphPlugin from '@ckeditor/ckeditor5-paragraph/src/paragraph';

import CustomPlugin from 'ckeditor5-custom-package/src/customplugin';
import OtherCustomPlugin from '../relative/path/to/some/othercustomplugin';

export default class ClassicEditor extends ClassicEditorBase {}

// Plugins to include in the build.
ClassicEditor.builtinPlugins = [
    EssentialsPlugin,
    AutoformatPlugin,
    BoldPlugin,
    ItalicPlugin,
    HeadingPlugin,
    LinkPlugin,
    ListPlugin,
    ParagraphPlugin,

    CustomPlugin,
    OtherCustomPlugin
];

ClassicEditor.defaultConfig = {
    toolbar: [ 'heading', '|', 'bold', 'italic', 'custombutton' ],

    // This value must be kept in sync with the language defined in webpack.config.js.
    language: 'en'
};

If you follow this example you will have to install all dependencies for all plugins used

Now you can register your new build:

index.js

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import NewClassicEditor from './my-build';
import EditorManager from 'ckeditor5-webcomponent/dist/collection/editor-manager.js';
import { defineCustomElements } from 'ckeditor5-webcomponent/dist/esm/es2017/x-ckeditor.define.js';

defineCustomElements(window);

// We register the ClassicEditor under the name 'classic'
EditorManager.register('classic', ClassicEditor);
// We register the NewClassicEditor under the name 'new-classic'
EditorManager.register('new-classic', NewClassicEditor);

And you can use it with the webcomponent:

index.html

<html>
    <body>
        <x-ckeditor editor="classic"></x-ckeditor>
        <x-ckeditor editor="new-classic"></x-ckeditor>
    </body>
</html>

Options

| Property | Type | Description | | ----------- | -------- | --------------------------------------------------------------------------------------------------------- | | config | string | (optional) CKEditor config | | content | string | (optional) HTML string of the editor content | | editor | string | The name of the registered build | | target-id | string | (optional) The id of the element to bind to. If left empty the editor will render for this webcomponent |

config

config must be a stringified json object. For instance, if you want to support more languages you could follow this tutorial and then set the configuration to:

<x-ckeditor editor="classic" config="{\"language\": \"fr\"}"></x-ckeditor>

Events

| Event | Type | Description | | ---------------- | ------------------ | ------------------------------------------------------------------------------------ | | ckeditorchange | {detail: string} | Fired when the CKEditor content changes, event.detail contains the new HTML string |