This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from ckeditor/t/115
Fix: Removed `StandardEditor` class in favor of `DataInterface` and `ElementInterface` mixins. Added `EditorWithUI` interface. Closes #115. Closes #113. Closes ckeditor/ckeditor5#303. BREAKING CHANGE: `StandardEditor` class is removed. Use `Editor` class with `DataInterface` and `ElementInterface` mixins.
- Loading branch information
Showing
21 changed files
with
664 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module core/editor/editorwithui | ||
*/ | ||
|
||
/** | ||
* Interface defining UI part of the editor. Most editor (like {@link module:editor-classic/classiceditor~ClassicEditor} or | ||
* {@link module:editor-inline/inlineeditor~InlineEditor}) implements this interface, however it is not required to do so. Editors with external UI (i.e. Bootstrap based) or headless editor may not implement this interface. Keep it in mind when developing features. | ||
* | ||
* @interface EditorWithUI | ||
*/ | ||
|
||
/** | ||
* Editor UI instance. | ||
* | ||
* @readonly | ||
* @member {module:core/editor/editorui~EditorUI} #ui | ||
*/ | ||
|
||
/** | ||
* Fired when the editor UI is ready. | ||
* | ||
* Fired after {@link module:core/editor/editor~Editor#event:pluginsReady}, before | ||
* {@link module:core/editor/editor~Editor#event:dataReady}. | ||
* | ||
* @event uiReady | ||
*/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import isFunction from '@ckeditor/ckeditor5-utils/src/lib/lodash/isFunction'; | ||
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror'; | ||
|
||
/** | ||
* @module core/editor/utils/attachtoform | ||
*/ | ||
|
||
/** | ||
* Checks if editor is initialized on textarea element that belongs to a form. If yes - updates editor's element | ||
* contents before submitting the form. | ||
* | ||
* This helper requires {@link module:core/editor/utils/elementapimixin~ElementApi ElementApi interface}. | ||
* | ||
* @param {module:core/editor/editor~Editor} editor Editor instance. | ||
*/ | ||
export default function attachToForm( editor ) { | ||
if ( !isFunction( editor.updateElement ) ) { | ||
/** | ||
* {@link module:core/editor/utils/elementapimixin~ElementApi ElementApi interface} is required. | ||
* | ||
* @error attachtoform-missing-elementapi-interface | ||
*/ | ||
throw new CKEditorError( 'attachtoform-missing-elementapi-interface: ElementApi interface is required.' ); | ||
} | ||
|
||
const element = editor.element; | ||
|
||
// Only when replacing a textarea which is inside of a form element. | ||
if ( element && element.tagName.toLowerCase() === 'textarea' && element.form ) { | ||
let originalSubmit; | ||
const form = element.form; | ||
const onSubmit = () => editor.updateElement(); | ||
|
||
// Replace the original form#submit() to call a custom submit function first. | ||
// Check if #submit is a function because the form might have an input named "submit". | ||
if ( isFunction( form.submit ) ) { | ||
originalSubmit = form.submit; | ||
|
||
form.submit = () => { | ||
onSubmit(); | ||
originalSubmit.apply( form ); | ||
}; | ||
} | ||
|
||
// Update the replaced textarea with data before each form#submit event. | ||
form.addEventListener( 'submit', onSubmit ); | ||
|
||
// Remove the submit listener and revert the original submit method on | ||
// editor#destroy. | ||
editor.on( 'destroy', () => { | ||
form.removeEventListener( 'submit', onSubmit ); | ||
|
||
if ( originalSubmit ) { | ||
form.submit = originalSubmit; | ||
} | ||
} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module core/editor/utils/dataapimixin | ||
*/ | ||
|
||
/** | ||
* Implementation of the {@link module:core/editor/utils/dataapimixin~DataApi}. | ||
* | ||
* @mixin DataApiMixin | ||
* @implements module:core/editor/utils/dataapimixin~DataApi | ||
*/ | ||
const DataApiMixin = { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
setData( data ) { | ||
this.data.set( data ); | ||
}, | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
getData() { | ||
return this.data.get(); | ||
} | ||
}; | ||
|
||
export default DataApiMixin; | ||
|
||
/** | ||
* Mixin provides methods for setting and getting data to/from editor main root element of the model tree | ||
* using {@link module:core/editor/editor~Editor#data data pipeline}. | ||
* | ||
* @interface DataApi | ||
*/ | ||
|
||
/** | ||
* Sets the data in the editor's main root. | ||
* | ||
* @method #setData | ||
* @param {String} data Input data. | ||
*/ | ||
|
||
/** | ||
* Gets the data from the editor's main root. | ||
* | ||
* @method #getData | ||
* @returns {String} Output data. | ||
*/ |
Oops, something went wrong.