GithubHelp home page GithubHelp logo

codeslayer1 / react-ckeditor Goto Github PK

View Code? Open in Web Editor NEW
130.0 130.0 34.0 16 KB

CKEditor component for React with plugin and custom event listeners support

License: MIT License

JavaScript 86.41% HTML 13.59%
ckeditor npm npm-module npm-package react react-ckeditor react-component react-library

react-ckeditor's People

Contributors

codeslayer1 avatar mihaiblaga89 avatar r0nd avatar xfields 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

react-ckeditor's Issues

change event not called when using scriptUrl

When using scriptUrl="static/ckeditor/ckeditor.js" change events aren't called.

Identical code works without scriptUrl. scriptUrl is referring to a valid custom ckeditor build.

Accept onBlur prop (or more generally, accept arbitrary hooks for CKEditor's 'on' method)

It would be nice if we could hook additional events in the CKEditor such as "blur".

The simplest change would be to provide an additional prop, "onBlur", which you would handle much like you currently handle the onChange prop.

A more general approach would be to take an "events" prop akin to the current "config" prop, which would map various CKEditor event strings to callbacks, allowing something like:

        <CKEditor
            content={this.state.text}
            onChange={this.onChange}
            config={{
                readOnly: this.props.readOnly,
                ...this.props.config
            }}
            events={{
                blur: this.onBlur
            }}
        />

If it's already possible to configure event handlers via config, I apologise - I'm not that familiar with CKEditor.

Also, apologies for abusing the Issues tracker to make a feature request.

Thank you for this handy react component!

CKEditor not found

Doing local development as per usual, all is well and I praise you for creating this.

I attempted to check it out via SSR. I get a ckeditor.js:77 CKEditor not found exception in the console. I'm not sure what would cause this since I wouldn't think SSR would matter at all for this.

Any help is welcome, and If you need more info to help out please let me know.
Thank you for this awesome package :)

Image upload from computer not working

Here is my code which I used in react:
<CKEditor activeClass="p10" content={props.content} config={{ allowedContent:true, filebrowserImageUploadUrl: 'http://localhost/core/upload.php' }} events={{ change: props.handleChange }} />

Request URL: http://localhost/core/upload.php?CKEditor=editor1&CKEditorFuncNum=1&langCode=en
Here is my upload .php response

<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(1, 'http://localhost/core/images/5.jpg', '')</script>

After pressing send to server button I got following error in console

Uncaught DOMException: Blocked a frame with origin "http://localhost" from accessing a cross-origin frame.
at http://localhost/core/upload.php?CKEditor=editor1&CKEditorFuncNum=1&langCode=en:1:47

When I clicked Ok button I got error "Image source URL is missing"

I receview error 'Uncaught TypeError: Cannot read property 'unselectable' of null ' and somtimes Ckeditor won't load

Hi, thanks a lot for this component.
Sometimes about one tenth of the time CkEditor will not load with error, most of the time this error is nonexistent. With included CkEditor

Uncaught TypeError: Cannot read property 'unselectable' of null
   at b (ckeditor.js:345)
   at a.<anonymous> (ckeditor.js:341)
   at a.p (ckeditor.js:10)
   at a.<anonymous> (ckeditor.js:12)
   at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
   at a.fireOnce (ckeditor.js:12)
   at a.CKEDITOR.editor.CKEDITOR.editor.fireOnce (ckeditor.js:13)
   at Object.<anonymous> (ckeditor.js:264)
   at f (ckeditor.js:244)
   at Object.load (ckeditor.js:244)


And with newer version of CkEditor 4.8.0 i have the similar error:

Uncaught TypeError: Cannot read property 'unselectable' of null
    at b (ckeditor.js:345)
    at a.<anonymous> (ckeditor.js:341)
    at a.p (ckeditor.js:10)
    at a.<anonymous> (ckeditor.js:12)
    at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
    at a.fireOnce (ckeditor.js:12)
    at a.CKEDITOR.editor.CKEDITOR.editor.fireOnce (ckeditor.js:13)
    at Object.<anonymous> (ckeditor.js:264)
    at f (ckeditor.js:244)
    at Object.load (ckeditor.js:244)
    at ckeditor.js:263
    at CKEDITOR.resourceManager.<anonymous> (ckeditor.js:251)
    at CKEDITOR.resourceManager.<anonymous> (ckeditor.js:249)
    at f (ckeditor.js:244)
    at Object.load (ckeditor.js:244)
    at CKEDITOR.resourceManager.load (ckeditor.js:249)
    at CKEDITOR.resourceManager.k (ckeditor.js:250)
    at CKEDITOR.resourceManager.load (ckeditor.js:251)
    at B (ckeditor.js:262)
    at ckeditor.js:261
    at ckeditor.js:491
    at CKEDITOR.resourceManager.<anonymous> (ckeditor.js:249)
    at f (ckeditor.js:244)
    at Array.B (ckeditor.js:244)
    at u (ckeditor.js:244)
    at ckeditor.js:245

Sometimes CKEditor won't even load with following error (4.8.0) and with version included in component

TypeError: a.ui.space(...) is null
ckeditor.js:329:102
b
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:329:102
a/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:325:416
c
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:10:68
CKEDITOR.event.prototype</<.fire</<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:11:428
CKEDITOR.editor.prototype.fire
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:13:67
fireOnce
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:12:81
CKEDITOR.editor.prototype.fireOnce
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:13:219
n/</<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:255:339
f
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:320
load
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:345
n/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:254:401
k/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:243:24
load/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:241:343
f
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:320
load
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:345
load
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:241:74
k
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:242:50
CKEDITOR.plugins.load</<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:243:53
n
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:253:260
f/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:252:436
getStylesSet/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:479:280
load/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:241:343
f
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:320
n
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:236:465
p
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:237:40
q/f.$.onload/<
https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js:237:468

Plugins loading docs needed

Hi. At first, thanks for this awesome component.
I know that issues is not a right place for asking questions, but how can I load a plugins? Is it even possible?
I am trying to pass a path for plugin js-file directly into "scriptUrl" props,

scriptUrl={'./cke-plugins/justify/plugin.js'}

but this leads to an error.

CKEditor not found

CKEdtior renders with empty content although it exists in the props

I have a React\Flux app. When entering the parent component of the CKEditor, I'm fetching data from the server, so in the initial loading, the 'content' prop of the CKEditor is empty, and after a few moments (when the fetching is done) the CKEditor component receives the content (props.content), but it doesn't always show it.
It actually depends on the loading of the parent component, when the user refreshes the page then everything works good, but if the user navigates from another component (different route) then the props.content in the CKEditor contains the content, but nothing is being shown in the CKEditor text box.
(Just to make it clear - in both cases the props.content of the CKEditor (eventually) contains the real content, but only in one case it shows it (meaning, working properly)).
Could you please assist?
Thanks,

Problem populating with CKeditor with data fetched from rest api

HI i am new with ckeditor in react , i need some help please ,if anybody can help that would be so great . I understand content prop is for setting the default value in the editor . but how do i use the setdata method ? for exemple what i am trying to do is i am fetching data from a rest api ,wich i filling my form values everytime that i click on a button. When i get the value from the rest api , i pass it to the content prop , but i am not seeing the value in the editor ..
thanks in advance.

Take an onLoad param or avoid local state to solve race condition

When both the script and the default content are loaded async there is no sure why to set the correct content.

If content is loaded before script:
Component renders and mounts. user can't pass the default content since It is not loaded yet
Component copies empty content from props to state
Content loads, user pass a new value as the content props, but this has no effect
ckeditor is not ready so the user can't setData
Script loads, setting the content to the default value that is not the real content because it is getting the content from the component state not from the prop that now is set to the content that was loaded

A way to solve this is to be able to pass a callback function to be called when the script has loaded.

Another way (better I think) would be to not have state at all in this component, and use the props directly, this way if the default content gets updated between the component mount and the script loading you are going to be setting the correct content.

Paste inline images

Hello,

First of all I'd like to thank you for putting this together, I've been trying to integrate CKEditor 4 & 5 within a react components library and I know how painful it is to integrate with a vDom, specially when not using a index.html file, so this is really helpful.

Now to the problem at hand:

I'm trying to set up the inline image pasting feature of CKEditor 4, I realize you use version 4.6 so it shouldn't be a problem.

However, I'm encountering two blockers, that I'm sure you already thought/faced them before:

  1. As pointed in https://docs.ckeditor.com/ckeditor4/latest/guide/dev_file_upload.html#basic-configuration, I'd like to set some parameters to configure the file upload plugin, like the upload URL. But when trying to pass these parameters as a config prop to your component, I'm getting this error (sorry for no screenshots, I'm behind a proxy right now so cant upload):

Error: [CKEDITOR.resourceManager.load] Resource name "uploadimage" was not found at "https://cdn.ckeditor.com/4.6.2/standard/plugins/uploadimage/plugin.js?t=H0CG".

My configuration object:

{ extraPlugins: 'uploadimage' }

  1. I'd like to subscribe to the fileUploadRequest event of the editor, as shown in https://docs.ckeditor.com/ckeditor4/latest/guide/dev_file_upload.html#request-2, so the first problem I encountered is that I'm not sure how to get the instance of my CKEditor? so I thought of getting it from one of the events defined in your events prop, I wrote this:

onEditorAfterPaste = event => { event.editor.on('fileUploadRequest', evt => { console.log('file fileUploadRequest fired, ', evt); }); };

Hoping it would fire when trying to paste an image in. Of course it didn't fire the console.log.
I'm passing this onEditorAfterPaste callback on the events prop as the afterPaste value, and I already made sure that when pasting it triggers the callback, but the subscription isn't happening, so maybe getting the instance of the editor through one of the events method is not the right thing to do it?

Thanks in advance for reading this and keep slaying!

CKEditor component not working in IE

Editor works fine without any issues when it loads for the first time with content. But when I change/update the editor content programmatically, content in editor changes, but the editor gets freezed(unable to select/focus/edit the content). It occurs only in IE. All other browsers its working fine. I tried without any props values, but still not working.

Does this component supports IE 11?

Refresh page - CKEditor does not re-render

Im not sure why this happens. The editor renders when the component loads but when I refresh the page the editor does not re-render and I get this message in the console.

ckeditor.js:95 GET http://cdn.ckeditor.com/4.6.2/standard/plugins/tableselection/styles/tableselection.css/ net::ERR_ABORTED

ckeditor.js:95 GET http://cdn.ckeditor.com/4.6.2/standard/plugins/scayt/dialogs/dialog.css/ net::ERR_ABORTED

ckeditor.js:95 GET http://cdn.ckeditor.com/4.6.2/standard/plugins/copyformatting/lang/en.js/ net::ERR_ABORTED

ckeditor.js:95 GET http://cdn.ckeditor.com/4.6.2/standard/skins/bootstrapck/editor.css/ net::ERR_ABORTED

Uncaught TypeError: Cannot read property 'ltr' of undefined at Object.init (ckeditor.js:645) at Object.<anonymous> (ckeditor.js:267) at f (ckeditor.js:247) at Array.D (ckeditor.js:247) at w (ckeditor.js:247) at HTMLScriptElement.A.CKEDITOR.env.ie.f.$.onerror (ckeditor.js:248)

Can we set editor to readOnly based on state?

Is there a way to set the component as readOnly?
I've tried to set the config property readOnly using a state property called submitLoading that will be true or false.

It seems that dynamically using state to set this property won't change the property since the component is already initialized.

Here's what I got goin on:

<CKEditor
    scriptUrl="/ckeditor/ckeditor.js"
    content={data.notes}
    config={{
        removePlugins: "elementspath,uploadimage,uploadfile",
        toolbar: "None",
        readOnly: submitLoading
    }}
    events={{ instanceReady: editorReady.bind(this), change: this.editorChange.bind(this) }}
 />

Any ideas?

how to disable inline styles ?

I have some elements using contenteditable property, it will add ckeditor toolbar automatically, is there any solution for that?

Underline is missing from toolBar

I need to only show three options to the user: Bold, Italic and Underline
But somehow the Underline option doesn't show up. I used the same config on the demo link and it works fine there.

config={{
toolbar: [
{ name: 'basicstyles', items: [ 'Underline', 'Italic', 'Bold' ] } ]
}}

screen shot 2018-04-10 at 12 49 14 pm

screen shot 2018-04-10 at 12 46 10 pm

cant type inside pop up inputs

I am trying to add image URL but when clicking on the image symbol ...a popup window open with input fields but none of them accept typing
I can't type image URL or even paste inside

thanks

Add support for setting content state outside of an event listener

I have a modal that have a list of text options with a copy button beside each. When you click the copy button it should take that takes and updates content which would render CKEditor with the correct content copied over showing. I have it wired up where onClick of the copy button updates editor content state, which works, but it doesn't update what the editor shows in the UI since it seems it only updates via one of the set eventListeners.

File Upload Events not working

Hey,
I am trying to use imageUpload plugin and while uploading the image i want to pass on extra parameters to the api request but the event is not firing.

onUploadRequest = (event) => {
   console.log(event)
}

<CKEditor
        ref={(editor) => { this.editor = editor; }}
        content={value}
        config={{
          filebrowserUploadUrl: '/image_upload',
        }}
        events={{
          change: this.onEditorChange,
          fileUploadRequest: this.onUploadRequest,
        }}
 />

How to clear inputed data.

Some problem with subj.
When i click on button state.content become equal "", but in input field it still not changed

class App extends Component {
    constructor(props) {
        super(props);

        this.state = {
            content: 'content',
        }

        this.onChange = this.onChange.bind(this)
        this.clearData = this.clearData.bind(this)
    }

    onChange(evt){
      console.log("onChange fired with event info: ", evt.editor.getData());
      var newContent = evt.editor.getData();
      this.setState({
        content: newContent
      })
    }

    clearData() {
        this.setState({
            content: ""
        })
    }

    render() {
        return (
            <div>
                <CKEditor 
                    activeClass="p10" 
                    content={this.state.content} 
                    events={{
                        "change": this.onChange
                    }}
                />
                <button onClick={this.clearData}>Clear data</button>
            </div>
        )
    }
}

Cannot read property 'call' of undefined in ckeditor.js | React 16

ckeditor.js:10 Uncaught TypeError: Cannot read property 'call' of undefined
at a.p (ckeditor.js:10)
at a. (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at CKEDITOR.plugins.undo.UndoManager.save (ckeditor.js:1020)
at a. (ckeditor.js:1016)
at a.p (ckeditor.js:10)
at a. (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at ckeditor.js:576

Color Dialog

How can I enable the color dialog in ckeditor?

How can I check that editor gets loaded ?

I want setState to content but it shows me empty content in an editor after it gets loaded.
This is due to delay in initialize the editor. How we can overcome this delay.

Image File Browser

Is there a way to utilize CKEditor plugins with this? For example i am looking for a way to browse the system for images to upload. CKEditor has plugins for that but how could I use those plugins, if possible?

State not loaded with nginx and redux form

I interact with redux-form. When I set the default state from the Redux-forms, it does not working if file of editor cached by browser

class renderCKEditor extends React.Component {
  constructor(props) {
    super(props)
    const {value} = props.input
    this.updateContent = this.updateContent.bind(this)
    this.setContent = this.setContent.bind(this)
    this.state = {
      content: value
    }
  }

  componentDidMount() {
    const {value} = this.props.input
    this.setContent(value)
  }

  componentDidUpdate(prevProps, prevState) {
    const {value} = this.props.input;
    const {content} = this.state
    if ((!content || content === '<p><br></p>') && value && !prevProps.value) {
      this.setContent(value)
    }
  }

  setContent(newContent) {
    this.setState({
      content: newContent
    })
  }

  updateContent(newContent) {
    const {onChange} = this.props.input
    onChange(newContent)
    this.setContent(newContent)
  }

  render() {
    const {label, input, meta: {touched, error, invalid, warning}} = this.props
    return (
      <div className='form-group'>
        <label className="control-label">{label}</label>
        <CKEditor activeClass="p10" content={this.state.content} scriptUrl='/app/ckeditor/ckeditor.js'
                  onChange={this.updateContent}/>
        <hr/>
        <div className="help-block">
          {touched && ((error && <span>{error}</span>) || (warning && <span>{warning}</span>))}
        </div>
      </div>
    )
  }
}

CKEditor with redux-form

I'm trying to use CKEditor with redux-form, but I'm not exactly sure how to use it within a component correctly. I've tried this:

<Field
  label="Content"
  name="content"
  component={CKEditor}
/>

But when I do a simple test with:

onSubmit(values) {
  console.log(values);
}

I'm not getting anything back. I assume I'll need to use the content prop to get it to include the editor content into the values argument, but I'm not sure how I might do that.

Thanks in advance for your help.

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.