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 2
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 #9 from ckeditor/i/5817
Feature: Added the special character info bar that makes the feature more user–friendly. Closes ckeditor/ckeditor5#5817.
- Loading branch information
Showing
7 changed files
with
286 additions
and
15 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,111 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module special-characters/ui/characterinfoview | ||
*/ | ||
|
||
import View from '@ckeditor/ckeditor5-ui/src/view'; | ||
|
||
import '../../theme/characterinfo.css'; | ||
|
||
/** | ||
* The view displaying detailed information about a special character glyph, e.g. upon | ||
* hovering it with a mouse. | ||
* | ||
* @extends module:ui/view~View | ||
*/ | ||
export default class CharacterInfoView extends View { | ||
constructor( locale ) { | ||
super( locale ); | ||
|
||
const bind = this.bindTemplate; | ||
|
||
/** | ||
* The character which info is displayed by the view. For instance, | ||
* "∑" or "¿". | ||
* | ||
* @observable | ||
* @member {String|null} #character | ||
*/ | ||
this.set( 'character', null ); | ||
|
||
/** | ||
* The name of the {@link #character}. For instance, | ||
* "N-ary summation" or "Inverted question mark". | ||
* | ||
* @observable | ||
* @member {String|null} #name | ||
*/ | ||
this.set( 'name', null ); | ||
|
||
/** | ||
* The "Unicode string" of the {@link #character}. For instance, | ||
* "U+0061". | ||
* | ||
* @observable | ||
* @readonly | ||
* @member {String} #code | ||
*/ | ||
this.bind( 'code' ).to( this, 'character', characterToUnicodeString ); | ||
|
||
this.setTemplate( { | ||
tag: 'div', | ||
children: [ | ||
{ | ||
tag: 'span', | ||
attributes: { | ||
class: [ | ||
'ck-character-info__name' | ||
] | ||
}, | ||
children: [ | ||
{ | ||
// Note: ZWSP to prevent vertical collapsing. | ||
text: bind.to( 'name', name => name ? name : '\u200B' ) | ||
} | ||
] | ||
}, | ||
{ | ||
tag: 'span', | ||
attributes: { | ||
class: [ | ||
'ck-character-info__code' | ||
] | ||
}, | ||
children: [ | ||
{ | ||
text: bind.to( 'code' ) | ||
} | ||
] | ||
} | ||
], | ||
attributes: { | ||
class: [ | ||
'ck', | ||
'ck-character-info' | ||
] | ||
} | ||
} ); | ||
} | ||
} | ||
|
||
// Converts a character into a "Unicode string", for instance: | ||
// | ||
// "$" -> "U+0024" | ||
// | ||
// Returns empty string when character is `null`. | ||
// | ||
// @param {String} character | ||
// @returns {String} | ||
function characterToUnicodeString( character ) { | ||
if ( character === null ) { | ||
return ''; | ||
} | ||
|
||
const hexCode = character.codePointAt( 0 ).toString( 16 ); | ||
|
||
return 'U+' + ( '0000' + hexCode ).slice( -4 ); | ||
} |
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,74 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
import CharacterInfoView from '../../src/ui/characterinfoview'; | ||
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; | ||
|
||
describe( 'CharacterInfoView', () => { | ||
let view; | ||
|
||
testUtils.createSinonSandbox(); | ||
|
||
beforeEach( () => { | ||
view = new CharacterInfoView(); | ||
view.render(); | ||
} ); | ||
|
||
afterEach( () => { | ||
view.destroy(); | ||
} ); | ||
|
||
describe( 'constructor()', () => { | ||
describe( '#character', () => { | ||
it( 'is defined', () => { | ||
expect( view.character ).to.equal( null ); | ||
} ); | ||
} ); | ||
|
||
describe( '#name', () => { | ||
it( 'is defined', () => { | ||
expect( view.name ).to.equal( null ); | ||
} ); | ||
} ); | ||
|
||
describe( '#code', () => { | ||
it( 'is defined', () => { | ||
expect( view.code ).to.equal( '' ); | ||
} ); | ||
|
||
it( 'is bound to #character', () => { | ||
view.set( 'character', 'A' ); | ||
|
||
expect( view.code ).to.equal( 'U+0041' ); | ||
} ); | ||
} ); | ||
|
||
describe( '#element', () => { | ||
it( 'is being created from template', () => { | ||
expect( view.element.classList.contains( 'ck' ) ).to.be.true; | ||
expect( view.element.classList.contains( 'ck-character-info' ) ).to.be.true; | ||
|
||
expect( view.element.firstElementChild.classList.contains( 'ck-character-info__name' ) ).to.be.true; | ||
expect( view.element.lastElementChild.classList.contains( 'ck-character-info__code' ) ).to.be.true; | ||
} ); | ||
|
||
it( 'is being updated when #code and #name have changed', () => { | ||
const infoEl = view.element.firstElementChild; | ||
const codeEl = view.element.lastElementChild; | ||
|
||
expect( infoEl.innerText ).to.equal( '\u200B' ); | ||
expect( codeEl.innerText ).to.equal( '' ); | ||
|
||
view.set( { | ||
character: 'A', | ||
name: 'SYMBOL: A' | ||
} ); | ||
|
||
expect( infoEl.innerText ).to.equal( 'SYMBOL: A' ); | ||
expect( codeEl.innerText ).to.equal( 'U+0041' ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
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,9 @@ | ||
/* | ||
* Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
.ck.ck-character-info { | ||
display: flex; | ||
justify-content: space-between; | ||
} |