Code Monkey home page Code Monkey logo

ckeditor5-react's Introduction

CKEditor 5 rich text editor component for React

npm version CircleCI Coverage Status Dependency Status

Official CKEditor 5 rich text editor component for React.

See the "Rich text editor component for React" guide in the CKEditor 5 documentation to learn more:

Contributing

After cloning this repository, install necessary dependencies:

npm install

You can also use Yarn.

Executing tests

Before starting tests execution, you need to build the package. You can use npm run build in order to build the production-ready version or npm run develop which produces a development version with attached watcher for all sources files.

npm run test -- [additional options]
# or
npm t -- [additional options]

The command accepts the following options:

  • --coverage (-c) โ€“ Whether to generate the code coverage.
  • --source-map (-s) โ€“ Whether to attach the source maps.
  • --watch (-w) โ€“ Whether to watch test files.
  • --reporter (-r) โ€“ Reporter for Karma (default: mocha, can be changed to dots).
  • --browsers (-b) โ€“ Browsers that will be used to run tests (default: Chrome, available: Firefox).

Building the package

Build a minified version of the package that is ready to publish:

npm run build

Releasing package

Changelog

Before starting the release process, you need to generate the changelog:

npm run changelog

Publishing

After generating the changelog, you are able to release the package.

First, you need to bump the version:

npm run release:prepare-packages

After bumping the version, you can publish the changes:

npm run release:publish-packages

Note: The release/ directory will be published.

License

Licensed under the terms of GNU General Public License Version 2 or later. For full details about the license, please check the LICENSE.md file.

ckeditor5-react's People

Contributors

annatomanek avatar corymharper avatar dawehner avatar dawidkossowski avatar dependabot[bot] avatar filipsobol avatar ma2ciek avatar martnpaneq avatar mati365 avatar mgsy avatar mlewand avatar niegowski avatar oleq avatar oskarwrobel avatar pomek avatar przemyslaw-zan avatar psmyrek avatar reinmar avatar scofalik avatar szymonkups avatar tx-michael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ckeditor5-react's Issues

Empty state value when I write nothing.

Is there a way to get empty value when I write nothing?

Example: if I write something and then delete it, data is:

<p>&nbsp;</p>

And if I use an Enter button on my keyboard it is:

<p>&nbsp;</p><p>&nbsp;</p>

I need to get nothing really. Empty state like this: "".

How to?

CKEditor5 - Paste Image and upload to Shared server

Hello Team,

I had setup CKEditor5 for my React application as source and building it with my application as we need to make some customization as per client needs.

Requirement - User should be able to paste or drag and drop image to editor and once dropped or pasted a call should go to upload image to shared server (our owned application shared server for such resources) and then we will save id of that image to db and then return URL of that image to UI for editor to bind that URL with image. Any working example and guidance would be of great help.

Thanks.

Any documentation on how to include and configure additional languages?

I got it working, but it would be nice to add the steps on the documentation page

import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import '@ckeditor/ckeditor5-build-classic/build/translations/ja';

<CKEditor
  editor={ClassicEditor}
  config={{
    language: 'ja',
  }}
/>

We do still need componentWillReceiveProps?

What this means really?

  componentWillReceiveProps(newProps) {
    if (this.editorInstance && newProps.data) {
      this.editorInstance.setData(newProps.data);
    }
  }

We do still need it (which would be UNSAFE_componentWillReceiveProps)?

Refactor ckeditor.js (eslint warning and other).

Because of #7 I copied all the code from ckeditor.js in my project (in a new component file).

I'm using create-react-app and eslint. So the errors:

  • [eslint] componentWillReceiveProps is deprecated since React 16.3.0, use UNSAFE_componentWillReceiveProps instead, see https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops (react/no-deprecated)

  • [eslint] shouldComponentUpdate should be placed after UNSAFE_componentWillReceiveProps (react/sort-comp)

  • [eslint] shouldComponentUpdate should be placed after componentDidMount (react/sort-comp)

  • [eslint] render should be placed after _destroyEditor (react/sort-comp)

  • [eslint] Default prop types declarations should be sorted alphabetically (react/jsx-sort-default-props)

  • [eslint] Must use destructuring props assignment (react/destructuring-assignment)

What is still a problem (and I don't know how to fix):

  • [eslint] UNSAFE_componentWillReceiveProps is unsafe for use in async rendering, see https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html (react/no-unsafe)

  • Unexpected console statement. (no-console) (62, 9)

  • JSX props should not use arrow functions (react/jsx-no-bind) (68, 17)

  • Prop type object is forbidden (react/forbid-prop-types) (74, 3)

  • propType "onChange" is not required, but has no corresponding defaultProp declaration. (react/require-default-props) (77, 3)

  • propType "onInit" is not required, but has no corresponding defaultProp declaration. (react/require-default-props) (78, 3)

I opened a PR: #8

Toolbar doesn't work properly when rendering two editors on the same page.

hi, I met this issue:

When I try to render/import two ck-editor elements on the same page. the Font Size control options changed to ['full size Image', 'Side image', 'Enter image caption', 'Left aligned image', 'Centered image'] instead of the expected ['tiny', 'small', 'default'....]

I tried to reproduce it in JSFiddle hope it could be of help:
https://jsfiddle.net/dchmn7pz/4/

I am importing

<script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/decoupled-document/ckeditor.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/inline/ckeditor.js"></script>

on the top of the script. In this case, the options of Font Size Control is showing image control options..

When I remove

<script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/inline/ckeditor.js"></script>

and leave <script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/decoupled-document/ckeditor.js"></script> alone. The problem disappeared.

I am wondering if I did something wrong here or this is expected?

Thanks in advance!

Using CKEditor Source with React JS

We are trying to use CKEditor5 with React app and we want to customize some of the feaures of CkEditor5 for our application. We are following the below steps:

  1. Downloaded ckeditor5-react from npm.

  2. Downloaded ckeditor5-classiceditor from npm.

  3. Create a class ClassicEditor which is extending the classiceditor class.

  4. The above class we have imported in our component which is responsible for rendering the CKEditor.

  5. We are using the below code for rendering the CKEditor ๐Ÿ‘

  6. On rendering it gives an error on console

TypeError: Cannot read property 'getAttribute' of null in ckeditor.js of the ckeditor5-react module

Note : If we try to use ckeditor5-build-classic directly from the node_module the above code works and the editor is rendered. But since we need customization we cannot use the minified file from npm.

Can anyone please suggest some help.

Allow other events (e.g. onBlur) on editable container

In our application, we validate form fields after the user has entered data by hooking onto the onBlur event. However, this behavior doesn't work with the current implementation of the CKEditor React component.

It'd be nice if we could pass extra props (data-* attributes, event handlers, etc) to the editor component and have them rendered along with the existing properties.

Adding new plugins to CKEditor 5 (Cannot read property 'getAttribute' of null)

Hello! I'm trying to add new plugin(s) into the react component of CKEditor. I tried to follow your docs (installation from source), but I can't seem to get this to work.

I want to add plugin Font to editor, and do it like this

import Font from "@ckeditor/ckeditor5-font/src/font";
<CKEditor
    editor={ClassicEditor}
    data={this.props.value}
    onInit={(editor) => {
      console.log(editor);
    }}
    config={{
       plugins: [Font],
       toolbar: ["fontSize", "fontFamily"],
    }}
     onChange={(event, editor) => {
       this.onEditorChange(event, editor);
    }}
/>

After this i had error at console:

ckeditor.js:5 TypeError: Cannot read property 'getAttribute' of null
    at IconView._updateXMLContent (iconview.js:100)
    at IconView.render (iconview.js:76)
    at IconView.on (observablemixin.js:249)
    at IconView.fire (emittermixin.js:196)
    at IconView.(anonymous function) [as render] (http://localhost:3030/js/bundle.js:27142:16)
    at ViewCollection.on (viewcollection.js:68)
    at ViewCollection.fire (emittermixin.js:196)
    at ViewCollection.add (collection.js:182)
    at DropdownButtonView.render (buttonview.js:168)
    at DropdownButtonView.render (dropdownbuttonview.js:64)

As i mentioned above, i followed to documentation installing and also configured my webpack.config.js

My webpack config

const path = require("path");
const webpack = require("webpack");
const { styles } = require("@ckeditor/ckeditor5-dev-utils");

module.exports = {
  devtool: "cheap-module-source-map",
  entry: ["webpack-hot-middleware/client", "./dev/js/index"],
  output: {
    path: path.join(__dirname, "dist/js"),
    publicPath: "/js/",
    filename: "bundle.js",
  },
  module: {
    loaders: [
      {
        loader: require.resolve("file-loader"),
        // Exclude `js` files to keep the "css" loader working as it injects
        // its runtime that would otherwise be processed through the "file" loader.
        // Also exclude `html` and `json` extensions so they get processed
        // by webpack's internal loaders.
        exclude: [
          /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
          /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/,
        ],
        options: {
          name: "static/media/[name].[hash:8].[ext]",
        },
      },
      {
        test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
        use: ["raw-loader"],
      },
      {
        test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/,
        use: [
          {
            loader: "style-loader",
            options: {
              singleton: true,
            },
          },
          {
            loader: "postcss-loader",
            options: styles.getPostCssConfig({
              themeImporter: {
                themePath: require.resolve("@ckeditor/ckeditor5-theme-lark"),
              },
              minify: true,
            }),
          },
        ],
      },
      {
        test: /\.js$/,
        include: path.join(__dirname, "dev/js"),
        exclude: /node_modules/,
        loader: "babel-loader",
        options: {
          presets: ["react", "es2015", "stage-0"],
        },
      },
      {
        test: /\.(sass|scss)/,
        include: path.join(__dirname, "dev/sass"),
        loader: "style-loader!css-loader!sass-loader",
      },
      {
        test: /\.css$/,
        exclude: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/,
        loader: "style-loader!css-loader",
      },
      {
        test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
        loaders: ["url-loader"],
      },
      {
        test: /\.(png|jpg)$/,
        loader: "url-loader",
      },
    ],
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("development"),
      },
    }),
  ],
};

I use my own config, without create-react-app

Version of editor react component - "@ckeditor/ckeditor5-react": "^1.0.0"
Version of type of editor - "@ckeditor/ckeditor5-build-classic": "^11.1.1"
Version of plugin - "@ckeditor/ckeditor5-font": "^10.0.3"

Helpers -

{
  "@ckeditor/ckeditor5-dev-utils": "^11.0.1",
  "@ckeditor/ckeditor5-theme-lark": "^11.1.0",
  "raw-loader": "^0.5.1",
  "webpack": "3.5.0",
}

Cannot integrate CKEditor 5 with React

I am desperately trying to integrate CKEditor 5 with React, but it doesn't work. I have strictly followed the docs: I am aware of the Babel bug, I have tried to create the React app with both the versions 1 and 2 of create-react-app, I have tried to replace some parts of the ejected configuration (as specified in the relative issue facebook/create-react-app#5387), but none of these attempts have made my app work. The error is always the same: TypeError: Cannot read property '0' of undefined. I also noticed that in the WebPack configuration file Tenser is used as minification tool, not Uglify.

> node -v
8.12.0
> npm -v
6.4.1

Cannot find module '@ckeditor/ckeditor5-image'

I'm trying to add @ckeditor/ckeditor5-image plugin to my react app, but it says cannot find the module even though I added. I'm using custom webpack instead of create-react-app, and the webpack configuration is as follows:


const HtmlWebPackPlugin = require('html-webpack-plugin');
const webpackDashboard = require('webpack-dashboard/plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const InterpolateHtmlPlugin = require('interpolate-html-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin');
const Dotenv = require('dotenv-webpack');

const PORT = 4000;

module.exports = {
  mode: 'development',
  entry: path.join(__dirname, 'src/index.js'),
  devtool: 'inline-source-map',
  output: {
    path: path.join(__dirname, 'build'),
    filename: '[name].js',
    chunkFilename: '[name].js'
  },
  devServer: {
    open: true,
    inline: true,
    contentBase: './public',
    port: PORT,
    publicPath: '/',
    historyApiFallback: true,
    quiet: true
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: 'html-loader'
          }
        ]
      },
      {
        test: /\.(css)$/,
        use: ['style-loader', 'css-loader']
      }
    ]
  },
  plugins: [
    new Dotenv(),
    new ErrorOverlayPlugin(),
    new CleanWebpackPlugin(['build']),
    new HtmlWebPackPlugin({
      template: path.join(__dirname, '/public/index.html'),
      filename: 'index.html',
      inject: 'body'
    }),
    new webpackDashboard(),
    new MiniCssExtractPlugin({
      filename: '[name].css',
      chunkFilename: '[id].css'
    }),
    new InterpolateHtmlPlugin({
      PUBLIC_URL: './public'
    }),
    new FriendlyErrorsWebpackPlugin({
      compilationSuccessInfo: {
        messages: [`Application is running here http://localhost:${PORT}`]
      }
    })
  ]
};

This is how I'm trying to add the plugin:

import React, { PureComponent } from 'react';
import CKEditor from '@ckeditor/ckeditor5-react';
import BallonEditor from '@ckeditor/ckeditor5-build-balloon';
import Image from '@ckeditor/ckeditor5-image';

class Editor extends PureComponent {
  render() {
    return (
          <CKEditor
            editor={BallonEditor}
            data="<p>Default Content</p>"
            config={{
              toolbar: [
                'heading',
                '|',
                'bold',
                'italic',
                'link',
                'bulletedList',
                'numberedList',
                'image',
                'mediaEmbed'
              ],
              plugin: [Image],
              }
            }}
            onInit={editor => {
              // You can store the "editor" and use when it is needed.
              console.log('Editor is ready to use!', editor);
            }}
            onChange={(event, editor) => {
              const data = editor.getData();
              console.log({ event, editor, data });
            }}
            onBlur={editor => {
              console.log('Blur.', editor);
            }}
            onFocus={editor => {
              console.log('Focus.', editor);
            }}
          />
    );
  }
}

export default Editor;

I restarted the webpack-dev-server after installing the dependency, but still doesn't help.

unable to install packages - tokens invalidated (https://status.npmjs.org/incidents/dn7c1fgrr7ng)

npm install --save @ckeditor/ckeditor5-react @ckeditor/ckeditor5-build-inline
npm WARN notice Due to a recent security incident, all user tokens have been invalidated. Please see https://status.npmjs.org/incidents/dn7c1fgrr7ng for more details. To generate a new token, visit https://www.npmjs.com/settings/~/tokens or run "npm login".
npm ERR! code E404
npm ERR! 404 Not Found: @ckeditor/ckeditor5-react@latest

Module parse failed: Unexpected token (36:9). You may need an appropriate loader to handle this file type.

I'm using this in package.json:

...
"cke5-react": "github:ckeditor/ckeditor5-react",
"@ckeditor/ckeditor5-build-classic": "10.1.0",
...

in my code this:

...
import CKEditor from "cke5-react/src/ckeditor";
import ClassicEditorBuild from "@ckeditor/ckeditor5-build-classic";
...

but it says:

./node_modules/cke5-react/src/ckeditor.js
Module parse failed: Unexpected token (36:9)
You may need an appropriate loader to handle this file type.
|       // Render <div> element which will be replaced by CKEditor.
|       render() {
|               return <div ref={ ref => ( this.domContainer = ref ) }></div>;
|       }
|

Why?

Add some tests

They will be a great example of how to use the component.

Of course, they also will prevent us before some regression.

autoFocus prop

I added autoFocus prop with this code:

_initializeEditor() {
    const { editor, config, data, onInit, onChange, autoFocus } = this.props;
...
if (autoFocus) this.editorInstance.editing.view.focus();

and using it like this:

<CKEditor autoFocus />.

Is it worth adding it?

ReferenceError: window is not defined

ReferenceError: window is not defined
    at Object.<anonymous> (/my_path/node_modules/@ckeditor/ckeditor5-react/dist/webpack:/CKEditor/webpack/universalModuleDefinition:10:2)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/son/Nodejs/dustgo/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/son/Nodejs/dustgo/client/modules/Blog/Post/pages/Admin/Edit.js:10:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at loader (/Users/son/Nodejs/dustgo/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/son/Nodejs/dustgo/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

How to fix it please?

Adding CKEditor5 Plugins

Greetings! I'm trying to add the alignment plugin into the react component built using the InlineEditor. I tried to follow your docs, but no matter what I do I can't seem to get this to work. Any time I pass in the new Alignment plugin into the plugins inside the config prop, whether by itself or with the rest of the default plugins, the toolbar doesn't show up anymore, even if I specify the toolbar layout as follows:

import React, {Component} from 'react'
import CKEditor from '@ckeditor/ckeditor5-react'

import InlineEditor from '@ckeditor/ckeditor5-build-inline'
/** Essentials, Heading, Paragraph, Bold, Italic, BlockQuote, Alignment, List, Link **/

import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials'
import Heading from '@ckeditor/ckeditor5-heading/src/heading'
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold'
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic'
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote'
import List from '@ckeditor/ckeditor5-list/src/list'
import Link from '@ckeditor/ckeditor5-link/src/link'

export default class MyComponent extends Component {
  handleEditorChange = () => {} //TO-DO: Write event handler
  render(){
    return (
      <div style={{height: '100%'}}>
        <CKEditor
          config={{
            plugins: [Essentials, Heading, Paragraph, Bold, Italic, BlockQuote, Alignment, List, Link],
            toolbar: ['Heading', '|', 'Bold', 'Italic', 'Alignment', 'Link', 'List', 'ListUI', 'BlockQuote', 'Undo', 'Redo'],
            removePlugins: ['Image', 'ImageCaption', 'ImageStyle', 'ImageToolbar', 'ImageUpload']
          }}
          editor={InlineEditor}
          data={this.state.content.value || ''}
          onChange={this.handleEditorChange}
        />
      </div>
    )
  }
}

As stated above, I've also tried it without the toolbar option, and even with plugins literally only containing Alignment, but nothing seems to work. I've also tried it without importing the other plugins with no luck.

Does not work with react-scripts 2.0.4

I upgraded react-scripts to 2.0.4 and Ckeditor stopped working. It produces empty div. Following are package.json and react component.

package.json:

{
  "name": "blank",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@ckeditor/ckeditor5-build-classic": "^11.0.1",
    "@ckeditor/ckeditor5-react": "^1.0.0-beta.1",
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^2.0.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

Simple react code:

import * as React from 'react';
import { HashRouter} from 'react-router-dom';
import CKEditor from '@ckeditor/ckeditor5-react';
import BalloonEditor from '@ckeditor/ckeditor5-build-classic';


export class Main extends React.Component {
    constructor(props) {
        //console.log( ' IN THE Constructor' );
        super(props);
                
    }

    render() {
                return (
            
            <HashRouter>
                <div className="container d-flex flex-column">
                    <div>CKEditor:
                        
                    <CKEditor editor={BalloonEditor} data={'Test Test Test'}
                    />
                    </div>

                </div>
            </HashRouter>
        );

    }

}

Set data to state making browser stuck (not responding)

Im new on ckeditor, i follow the documentation ckeditor for React
Here my code

<Editor onChange={(ev, ed) => this.setState({ content: ed.getData()})}/>

But when i start typing on ckeditor section, my browser not responding and the content not showing on the textarea

When i try to alert() the data is working

Configuration class property conflict

I'm trying to set the editor configuration, but it gives an error.

<CKEditor
    editor={BaloonEditor}
    data={this.props.data}
    config={{
            toolbar: ["heading", "|", "bold", "italic"],
            heading: {
              options: [
                {
                  model: "paragraph",
                  title: "Paragraph",
                  class: "ck-heading_paragraph"
                }
              ]
            }
       }}
      onChange={(event, editor) => {
          const data = editor.getData();
          this.props.onChange(data);
     }}
   />

The class property of config.heading.options[0] conflicts with the JS class keyword. I tried using className, but that doesn't work.

How to get the editor value?

I implemented the ckeditor-react module described in your documentation.
But there i only get en eventInfo and the editor instance.

How do i get the value the user entered?

How upload Image

console.error is filerepository-no-upload-adapter: Upload adapter is not defined
Could you provide a demo? Thanks

Containers not being created

The toolbar and editable are directly rendered into the DOM without any containers. It would be helpful if these containers were automatically created to better match the styling documentation which assumes that these containers exist already.

Will there be a react-native version?

Documentation on how to use this within react-native would be nice.

(Edit by @Reinmar) If you'd like to see support for react-native version please ๐Ÿ‘ this ticket. Also, see the discussion below.

Introduce [disabled] property

Both integrations (Angular and Vue) allows changing the editor to read-only mode.

In React you can do it by saving the editor from onInit() callback. If we will introduce the [disabled] property, switching between those modes should be easier.

Small syntax error in the README

Just noticed you have a syntax error in the README:

import React, { Component } from 'react';
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

class App extends Component {
    render() {
        return (
            <div className="App">
                <h2>Using CKEditor 5 build in React</h2>
                <CKEditor
                    editor={ ClassicEditor }
                    data="<p>Hello from CKEditor 5!</p>"
                    onInit={ editor => {
                        // You can store the "editor" and use when it's needed.
                        console.log( 'Editor is ready to use!', editor );
                    } }
                    onChange={ ( event, editor ) => {
                        const data = editor.getData();
                        console.log( { event, editor, data } );
                    } ) }
                />
            </div>
        );
    }
}

export default App;

There's an extra ) at the end of where you're passing the onChange prop

CKEditor5 - How to set property at run time.

I want to make CKeditor5 readonly at runtime depending on condition. Although I got that there is a property "isReadOnly" to make CKEditor5 as read only but how to set this property at runtime, I got stuck something at. Is there any documentation which I can follow to achieve the same. FYI - I am integrating CKeditor5 source into my react application.

Placeholder in a CKEDITOR is not working

Am trying to add a placeholder in the CKeditor but it's not working, how will I go around on that ?

<CKEditor
		onInit={editor => {
		// Insert the toolbar before the editable area.
		editor.ui.view.editable.element.parentElement.insertBefore(
	        editor.ui.view.toolbar.element,
		editor.ui.view.editable.element
		);
	       }}
		config.placeholder ='Type '
		name={this.state.body}
		onChange={this.handleEditorChange}
		editor={DecoupledEditor}
		data={this.state.body}
	       />

Reference issues while installing ckeditor5 plugins in React

I've been trying to implement comments only feature and been getting a lot of problems.
This is the error i am getting:
Module not found: Can't resolve './@ckeditor/ckeditor5-collaboration-core/src/users/users.css'

My Webpack Config

'use strict';

const autoprefixer = require('autoprefixer');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const getClientEnvironment = require('./env');
const paths = require('./paths');

const { styles } = require('@ckeditor/ckeditor5-dev-utils');
const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');

// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
const publicUrl = '';
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
module.exports = {
  // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
  // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
  devtool: 'cheap-module-source-map',
  // These are the "entry points" to our application.
  // This means they will be the "root" imports that are included in JS bundle.
  // The first two entry points enable "hot" CSS and auto-refreshes for JS.
  entry: [
    // We ship a few polyfills by default:
    require.resolve('./polyfills'),
    // Include an alternative client for WebpackDevServer. A client's job is to
    // connect to WebpackDevServer by a socket and get notified about changes.
    // When you save a file, the client will either apply hot updates (in case
    // of CSS changes), or refresh the page (in case of JS changes). When you
    // make a syntax error, this client will display a syntax error overlay.
    // Note: instead of the default WebpackDevServer client, we use a custom one
    // to bring better experience for Create React App users. You can replace
    // the line below with these two lines if you prefer the stock client:
    // require.resolve('webpack-dev-server/client') + '?/',
    // require.resolve('webpack/hot/dev-server'),
    require.resolve('react-dev-utils/webpackHotDevClient'),
    // Finally, this is your app's code:
    paths.appIndexJs
    // We include the app code last so that if there is a runtime error during
    // initialization, it doesn't blow up the WebpackDevServer client, and
    // changing JS code would still trigger a refresh.
  ],
  output: {
    // Add /* filename */ comments to generated require()s in the output.
    pathinfo: true,
    // This does not produce a real file. It's just the virtual path that is
    // served by WebpackDevServer in development. This is the JS bundle
    // containing code from all our entry points, and the Webpack runtime.
    filename: 'static/js/bundle.js',
    // There are also additional JS chunk files if you use code splitting.
    chunkFilename: 'static/js/[name].chunk.js',
    // This is the URL that app is served from. We use "/" in development.
    publicPath: publicPath,
    // Point sourcemap entries to original disk location (format as URL on Windows)
    devtoolModuleFilenameTemplate: info =>
      path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')
  },
  resolve: {
    // This allows you to set a fallback for where Webpack should look for modules.
    // We placed these paths second because we want `node_modules` to "win"
    // if there are any conflicts. This matches Node resolution mechanism.
    // https://github.com/facebookincubator/create-react-app/issues/253
    modules: ['node_modules', paths.appNodeModules].concat(
      // It is guaranteed to exist because we tweak it in `env.js`
      process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
    ),
    // These are the reasonable defaults supported by the Node ecosystem.
    // We also include JSX as a common component filename extension to support
    // some tools, although we do not recommend using it, see:
    // https://github.com/facebookincubator/create-react-app/issues/290
    // `web` extension prefixes have been added for better support
    // for React Native Web.
    extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
    alias: {
      // Support React Native Web
      // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
      'react-native': 'react-native-web'
    },
    plugins: [
      // Prevents users from importing files from outside of src/ (or node_modules/).
      // This often causes confusion because we only process files within src/ with babel.
      // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
      // please link the files into your node_modules/ and let module-resolution kick in.
      // Make sure your source files are compiled, as they will not be processed in any way.
      new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson])
    ]
  },
  module: {
    strictExportPresence: true,
    rules: [
      // TODO: Disable require.ensure as it's not a standard language feature.
      // We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
      // { parser: { requireEnsure: false } },

      // First, run the linter.
      // It's important to do this before Babel processes the JS.
      {
        test: /\.(js|jsx|mjs)$/,
        enforce: 'pre',
        use: [
          {
            options: {
              formatter: eslintFormatter,
              eslintPath: require.resolve('eslint')
            },
            loader: require.resolve('eslint-loader')
          }
        ],
        include: paths.appSrc
      },
      {
        // "oneOf" will traverse all following loaders until one will
        // match the requirements. When no loader matches it will fall
        // back to the "file" loader at the end of the loader list.
        oneOf: [
          // "url" loader works like "file" loader except that it embeds assets
          // smaller than specified limit in bytes as data URLs to avoid requests.
          // A missing `test` is equivalent to a match.
          {
            test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
            loader: require.resolve('url-loader'),
            options: {
              limit: 10000,
              name: 'static/media/[name].[hash:8].[ext]'
            }
          },
          // CKEditor5
          {
            test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
            use: ['raw-loader']
          },
          {
            test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/,
            use: [
              {
                loader: 'style-loader',
                options: {
                  singleton: true
                }
              },
              {
                loader: 'postcss-loader',
                options: styles.getPostCssConfig({
                  themeImporter: {
                    themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
                  },
                  minify: true
                })
              }
            ]
          },
          // Process JS with Babel.
          {
            test: /\.(js|jsx|mjs)$/,
            include: paths.appSrc,
            loader: require.resolve('babel-loader'),
            options: {
              // This is a feature of `babel-loader` for webpack (not Babel itself).
              // It enables caching results in ./node_modules/.cache/babel-loader/
              // directory for faster rebuilds.
              cacheDirectory: true
            }
          },
          // "postcss" loader applies autoprefixer to our CSS.
          // "css" loader resolves paths in CSS and adds assets as dependencies.
          // "style" loader turns CSS into JS modules that inject <style> tags.
          // In production, we use a plugin to extract that CSS to a file, but
          // in development "style" loader enables hot editing of CSS.
          {
            test: /\.css$/,
            exclude: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/,
            use: [
              require.resolve('style-loader'),
              {
                loader: require.resolve('css-loader'),
                options: {
                  importLoaders: 1
                }
              },
              {
                loader: require.resolve('postcss-loader'),
                options: {
                  // Necessary for external CSS imports to work
                  // https://github.com/facebookincubator/create-react-app/issues/2677
                  ident: 'postcss',
                  plugins: () => [
                    require('postcss-flexbugs-fixes'),
                    autoprefixer({
                      browsers: [
                        '>1%',
                        'last 4 versions',
                        'Firefox ESR',
                        'not ie < 9' // React doesn't support IE8 anyway
                      ],
                      flexbox: 'no-2009'
                    })
                  ]
                }
              }
            ]
          },
          // "file" loader makes sure those assets get served by WebpackDevServer.
          // When you `import` an asset, you get its (virtual) filename.
          // In production, they would get copied to the `build` folder.
          // This loader doesn't use a "test" so it will catch all modules
          // that fall through the other loaders.
          {
            // Exclude `js` files to keep "css" loader working as it injects
            // its runtime that would otherwise processed through "file" loader.
            // Also exclude `html` and `json` extensions so they get processed
            // by webpacks internal loaders.
            exclude: [
              /\.(js|jsx|mjs)$/,
              /\.html$/,
              /\.json$/,
              /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
              /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/
            ],
            loader: require.resolve('file-loader'),
            options: {
              name: 'static/media/[name].[hash:8].[ext]'
            }
          }
        ]
      }
      // ** STOP ** Are you adding a new loader?
      // Make sure to add the new loader(s) before the "file" loader.
    ]
  },
  plugins: [
    // Makes some environment variables available in index.html.
    // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
    // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    // In development, this will be an empty string.
    new InterpolateHtmlPlugin(env.raw),
    // Generates an `index.html` file with the <script> injected.
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml
    }),
    // For CKEditor 5
    new UglifyJsWebpackPlugin({
      uglifyOptions: {
        compress: {
          warnings: false,
          // Disabled because of an issue with Uglify breaking seemingly valid code:
          // https://github.com/facebookincubator/create-react-app/issues/2376
          // Pending further investigation:
          // https://github.com/mishoo/UglifyJS2/issues/2011
          comparisons: false
        },
        mangle: {
          safari10: true
        },
        output: {
          comments: false,
          // Turned on because emoji and regex is not minified properly using default
          // https://github.com/facebookincubator/create-react-app/issues/2488
          ascii_only: true
        }
      },
      // sourceMap: shouldUseSourceMap
      sourceMap: true
    }),

    // Add module names to factory functions so they appear in browser profiler.
    new webpack.NamedModulesPlugin(),
    // Makes some environment variables available to the JS code, for example:
    // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
    new webpack.DefinePlugin(env.stringified),
    // This is necessary to emit hot updates (currently CSS only):
    new webpack.HotModuleReplacementPlugin(),
    // Watcher doesn't work well if you mistype casing in a path so we use
    // a plugin that prints an error when you attempt to do this.
    // See https://github.com/facebookincubator/create-react-app/issues/240
    new CaseSensitivePathsPlugin(),
    // If you require a missing module and then `npm install` it, you still have
    // to restart the development server for Webpack to discover it. This plugin
    // makes the discovery automatic so you don't have to restart.
    // See https://github.com/facebookincubator/create-react-app/issues/186
    new WatchMissingNodeModulesPlugin(paths.appNodeModules),
    // Moment.js is an extremely popular library that bundles large locale files
    // by default due to how Webpack interprets its code. This is a practical
    // solution that requires the user to opt into importing specific locales.
    // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
    // You can remove this if you don't use Moment.js:
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  ],
  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    dgram: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty',
    child_process: 'empty'
  },
  // Turn off performance hints during development because we don't do any
  // splitting or minification in interest of speed. These warnings become
  // cumbersome.
  performance: {
    hints: false
  }
};

Package.json

{
  "name": "text-editor",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@ckeditor/ckeditor5-basic-styles": "^10.1.0",
    "@ckeditor/ckeditor5-build-classic": "^11.2.0",
    "@ckeditor/ckeditor5-comments": "^1.0.1",
    "@ckeditor/ckeditor5-editor-classic": "^11.0.2",
    "@ckeditor/ckeditor5-essentials": "^10.1.3",
    "@ckeditor/ckeditor5-heading": "^10.1.1",
    "@ckeditor/ckeditor5-paragraph": "^10.0.4",
    "@ckeditor/ckeditor5-react": "^1.1.0",
    "autoprefixer": "7.1.6",
    "babel-core": "6.26.0",
    "babel-eslint": "7.2.3",
    "babel-jest": "20.0.3",
    "babel-loader": "7.1.2",
    "babel-preset-react-app": "^3.1.2",
    "babel-runtime": "6.26.0",
    "case-sensitive-paths-webpack-plugin": "2.1.1",
    "chalk": "1.1.3",
    "css-loader": "0.28.7",
    "dotenv": "4.0.0",
    "dotenv-expand": "4.2.0",
    "eslint": "4.10.0",
    "eslint-config-react-app": "^2.1.0",
    "eslint-loader": "1.9.0",
    "eslint-plugin-flowtype": "2.39.1",
    "eslint-plugin-import": "2.8.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-react": "7.4.0",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "1.1.5",
    "fs-extra": "3.0.1",
    "html-webpack-plugin": "2.29.0",
    "jest": "20.0.4",
    "object-assign": "4.1.1",
    "postcss-flexbugs-fixes": "3.2.0",
    "postcss-loader": "2.0.8",
    "promise": "8.0.1",
    "raf": "3.4.0",
    "react": "^16.8.1",
    "react-dev-utils": "^5.0.2",
    "react-dom": "^16.8.1",
    "resolve": "1.6.0",
    "style-loader": "0.19.0",
    "sw-precache-webpack-plugin": "0.11.4",
    "url-loader": "0.6.2",
    "webpack": "3.8.1",
    "webpack-dev-server": "2.11.3",
    "webpack-manifest-plugin": "1.3.2",
    "whatwg-fetch": "2.0.3"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@ckeditor/ckeditor5-alignment": "^10.0.4",
    "@ckeditor/ckeditor5-dev-utils": "^11.0.2",
    "@ckeditor/ckeditor5-theme-lark": "^12.0.0",
    "raw-loader": "^1.0.0",
    "uglifyjs-webpack-plugin": "^1.2.7"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,mjs}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node",
      "mjs"
    ]
  },
  "babel": {
    "presets": [
      "react-app"
    ]
  }
}

App.js

import React, { Component } from 'react';
import CKEditor from '@ckeditor/ckeditor5-react';

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';

import Comments from '@ckeditor/ckeditor5-comments/src/comments';
import CommentsOnly from '@ckeditor/ckeditor5-comments/src/commentsonly';

class App extends Component {
  render() {
    return (
      <div className="App">
        <h2>Using CKEditor 5 Framework in React</h2>
        <CKEditor
          onInit={editor => console.log('Editor is ready to use!', editor)}
          onChange={(event, editor) => console.log({ event, editor })}
          config={{
            plugins: [
              Essentials,
              Paragraph,
              Bold,
              Italic,
              Heading,
              Comments,
              CommentsOnly
            ],
            toolbar: [
              'heading',
              '|',
              'bold',
              'italic',
              '|',
              'undo',
              'redo',
              'comment'
            ],
            image: {
              toolbar: ['comment']
            },
            language: 'en'
          }}
          editor={ClassicEditor}
          data="<p>Hello from CKEditor 5!</p>"
        />
      </div>
    );
  }
}

export default App;

Please let me know If i am doing something wrong here.

Error when building with create-react-app.

I'm using [email protected] and when I build using npm run build it says:

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

        ./node_modules/@ckeditor/ckeditor5-build-classic/build/ckeditor.js:5:7374

Read more here: http://bit.ly/2tRViJ9

error Command failed with exit code 1.

How to do?

Maybe is there a way to disable es5 using just es6 in CRA?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.