Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKEditor 5 integration for Angular 2+ #1020

Closed
oleq opened this issue May 14, 2018 · 27 comments
Closed

CKEditor 5 integration for Angular 2+ #1020

oleq opened this issue May 14, 2018 · 27 comments
Assignees
Labels
type:feature This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone

Comments

@oleq
Copy link
Member

oleq commented May 14, 2018

Update:

The ckeditor5-angular package has been published on the NPM 🎉

See our docs to check how you can customize and integrate the <ckeditor> component in your Angular application. If you have any trouble, please, report it in the ckeditor/ckeditor5-angular repository. Feature request are welcome too :)

All feedback is welcome!

@oleq oleq added type:feature This issue reports a feature request (an idea for a new functionality or a missing option). status:confirmed labels May 14, 2018
@oleq oleq added this to the next milestone May 14, 2018
@oleq oleq self-assigned this May 14, 2018
@ma2ciek
Copy link
Contributor

ma2ciek commented May 14, 2018

ATM only the first option is possible and yet it is very, very ugly:

import( `../../../node_modules/@ckeditor/ckeditor5-build-${ buildName }/build/ckeditor.js` )
  .then( EditorBuild => this.createEditor( EditorBuild ) );```

Isn't better to statically specify the editor type and use the static import? Does someone want to dynamically pick the editor type? Or you did it to create a lighter bundle and import editor's build when the it's needed?

@ma2ciek
Copy link
Contributor

ma2ciek commented May 14, 2018

Note, that in TS lowercase is used for basic types and uppercase for e.g. boxed types (like new String()), so you should use string instead of String - https://www.typescriptlang.org/docs/handbook/basic-types.html.

@Reinmar
Copy link
Member

Reinmar commented May 14, 2018

Isn't better to statically specify the editor type and use the static import? Does someone want to dynamically pick the editor type? Or you did it to create a lighter bundle and import editor's build when the it's needed?

The import should be somewhere in the component's consumer code. It must not be in the component's code itself. The component must work with any build of your choice.

@Reinmar
Copy link
Member

Reinmar commented May 14, 2018

To exemplify what I mean – that's how we see the use of the React component:

import React, { Component } from 'react';
import './App.css';
import CKEditor from 'cke5-react';
import ClassicEditorBuild from '@ckeditor/ckeditor5-build-classic';


class App extends Component {
	render() {
		return (
			<div className="App">
				<h2>CKEditor 5 using build-classic</h2>
				<CKEditor
					editor={ ClassicEditorBuild }
					data="<p>Hello from CKEditor 5</p>"
					onChange={ data => console.log( data ) }
				/>
			</div>
		);
	}
}

export default App;

The ClassicEditorBuild is imported by the consumer and passed to the component in one of its attributes.

@ma2ciek
Copy link
Contributor

ma2ciek commented May 14, 2018

So it can be done similarly from the parent component:

import { Component } from '@angular/core';

import * as ClassicEditorBuild from '@ckeditor/ckeditor5-build-classic';

@Component( {
	selector: 'my-app',
	template:
		`<main>
			<ckeditor [editor]="editor" [data]="data"></ckeditor>
		</main>`
} )
export class AppComponent {
	private editor = ClassicEditorBuild;
	private data = "<p>Some content</p>"
}

So later the editor constructor will be visible in the ckeditor component and can be imported via @Input.

The only thing is, that we don't have any TS typings for our JS files, so there is a warning when importing some CKEditor5 stuff.

@pburrows
Copy link

pburrows commented May 14, 2018

I think for:

use customized editor builds, e.g. to narrow or extend the set of the features, which can be achieved in 2 ways:
building the editor beside the Angular project, and then including it like an official build,
integration of the building process witin the Angular project

you will need to use an implementation of an abstract factory with componentFactoryResolver where either a known build name is passed in (such as ckeditor5-build-classic) or another component is passed in (for people who are building their own and including it in their projects) and you make the decision on which to instantiate.

You might do it with a switch statement around your dynamic import in ngOnInit, or, more elegantly, as separate named components of their own (where there is a CkEditorClassicBuildComponent installed via a separate npm package).

@keatkeat87

This comment has been minimized.

@oleq

This comment has been minimized.

@pomek

This comment has been minimized.

@Reinmar

This comment has been minimized.

@Reinmar

This comment has been minimized.

@ayyash
Copy link

ayyash commented May 16, 2018

Looking at it, I assume (change)="something()" is the way to catch event, but that did not fire anything, what is the way to catch events?

@ma2ciek
Copy link
Contributor

ma2ciek commented May 16, 2018

@ayyash, I guess, for that CKEditorComponent would need a property @Output change = new EventEmitter<void>(); and then you should delegate the CKEditor's change event inside the setUpEditorEvents method via this.change.emit().

@ayyash
Copy link

ayyash commented May 16, 2018

Okay I have a problem, this line editor.on( 'change', () => { ... never really gets caught, nor did 'blur', am I missing anything?

@ma2ciek
Copy link
Contributor

ma2ciek commented May 16, 2018

There's editor.model.document.on( 'change', () => {} ) event, which you can use. See https://docs.ckeditor.com/ckeditor5/latest/api/module_engine_model_document-Document.html.

@Reinmar
Copy link
Member

Reinmar commented May 25, 2018

And we've got a first pull request: ckeditor/ckeditor5-angular#2 by @oleq.

Feedback needed :)

@piernik
Copy link

piernik commented Jul 12, 2018

Any updates on this??

@ma2ciek
Copy link
Contributor

ma2ciek commented Jul 12, 2018

Any updates on this??

I'm actively working on this, so I'll keep you updated.

@piernik
Copy link

piernik commented Jul 12, 2018

@ma2ciek That's great news - powodzenia!

@ma2ciek
Copy link
Contributor

ma2ciek commented Jul 13, 2018

@piernik, you can check out the current implementation on the ckeditor/ckeditor5-angular#2 I've updated many things and this implementation should work well with angular@6 :) We'll be releasing it soon.

@piernik
Copy link

piernik commented Jul 14, 2018

Is it available on npm?

@oleq
Copy link
Member Author

oleq commented Jul 17, 2018

@piernik Not yet, but there's an issue for that.

@ma2ciek
Copy link
Contributor

ma2ciek commented Jul 26, 2018

Update: The ckeditor5-angular package has just been published - https://www.npmjs.com/package/@ckeditor/ckeditor5-angular 🎉

Run npm install @ckeditor/ckeditor5-angular to play with it.

If you have any trouble, please, report it in the https://github.com/ckeditor/ckeditor5-angular.

All feedback is welcomed!

@ma2ciek ma2ciek closed this as completed Jul 26, 2018
@Reinmar Reinmar modified the milestones: next, iteration 20 Jul 26, 2018
@Sovai
Copy link

Sovai commented Aug 10, 2018

Does it work with Angular 6?

@pomek
Copy link
Member

pomek commented Aug 10, 2018

Yes, it should work.

@AlanObject

This comment has been minimized.

@ma2ciek
Copy link
Contributor

ma2ciek commented Jan 29, 2019

Hi, @AlanObject.

Could you post the issue in the https://github.com/ckeditor/ckeditor5-angular?
Docs for the ckeditor5-angular package are available here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature This issue reports a feature request (an idea for a new functionality or a missing option).
Projects
None yet
Development

No branches or pull requests

10 participants