-
Notifications
You must be signed in to change notification settings - Fork 8
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 #46 from ckeditor/t/44
Feature: Allowed attaching the inspector collapsed using a configuration passed to `CKEditorInspector#attach()`. Implemented the `CKEditorInspector#destroy()` method. Unified `CKEditorInspector#attach()` arguments syntax and allowed attaching to multiple instances at a time. Closes #44. Closes #42. Closes #48. BREAKING CHANGE: The `CKEditorInspector.attach( 'editor-name', editor );` syntax was deprecated and replaced by an object literal `CKEditorInspector.attach( { 'editor-name': editor, ... } );`.
- Loading branch information
Showing
14 changed files
with
910 additions
and
473 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
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
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,51 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import Logger from './logger'; | ||
|
||
let unnamedEditorCount = 0; | ||
|
||
export function normalizeArguments( args ) { | ||
const normalized = { | ||
editors: {}, | ||
options: {} | ||
}; | ||
|
||
// Deprecated // attach( 'name', editor ); | ||
if ( typeof args[ 0 ] === 'string' ) { | ||
Logger.warn( | ||
`[CKEditorInspector] The CKEditorInspector.attach( '${ args[ 0 ] }', editor ) syntax has been deprecated ` + | ||
'and will be removed in the near future. To pass a name of an editor instance, use ' + | ||
`CKEditorInspector.attach( { '${ args[ 0 ] }': editor } ) instead.` | ||
); | ||
|
||
normalized.editors[ args[ 0 ] ] = args[ 1 ]; | ||
} else { | ||
// attach( editor ); | ||
if ( isEditorInstance( args[ 0 ] ) ) { | ||
normalized.editors[ getNextEditorName() ] = args[ 0 ]; | ||
} | ||
// attach( { foo: editor1, bar: editor2, ... } ); | ||
else { | ||
for ( const name in args[ 0 ] ) { | ||
normalized.editors[ name ] = args[ 0 ][ name ]; | ||
} | ||
} | ||
|
||
// attach( ..., { options } ); | ||
normalized.options = args[ 1 ] || normalized.options; | ||
} | ||
|
||
return normalized; | ||
} | ||
|
||
function getNextEditorName() { | ||
return `editor-${ ++unnamedEditorCount }`; | ||
} | ||
|
||
function isEditorInstance( arg ) { | ||
// Quack! 🦆 | ||
return !!arg.model; | ||
} |
Oops, something went wrong.