Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/ckeditor5/645: Implemented a 2-step editing, refreshed link UI #165

Merged
merged 23 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8ad8b09
Aligning the package to the new default theme.
oleq Jan 11, 2018
53bafcc
Merge branch 'master' into t/ckeditor5/645
oleq Jan 11, 2018
6a34fb1
Used 1.5px thick icons for better contrast
oleq Jan 12, 2018
8aaf122
Added unlink icon.
oleq Jan 15, 2018
a8362b2
Merge branch 'master' into t/ckeditor5/645
oleq Jan 16, 2018
fd4863e
Simplified the link editing form.
oleq Jan 16, 2018
345f0c2
Implemented LinkActionsView as an intermediate step before editing a …
oleq Jan 16, 2018
a08804e
Used a different icon and changed button order in the link form view.
oleq Jan 16, 2018
7e9a10f
Enabled tooltip for link href preview.
oleq Jan 17, 2018
a12b943
Made the link actions preview an instance of ButtonView.
oleq Jan 17, 2018
65b9090
Made the keystroke and the toolbar button always open the link action…
oleq Jan 18, 2018
99d296f
Updated link and unlink icons.
oleq Jan 24, 2018
1c0ec5a
Merge branch 'master' into t/ckeditor5/645
oleq Jan 24, 2018
f4ed216
Merge branch 'master' into t/ckeditor5/645
oleq Jan 26, 2018
357e321
Refactored link plugin along with tests to support a two-step link UI.
oleq Jan 31, 2018
6c96ccf
Tests: Updated link form view tests.
oleq Jan 31, 2018
75df52b
Tests: Added link actions view tests.
oleq Jan 31, 2018
8a74216
Tests: Fixed wrong letter case in the import.
oleq Jan 31, 2018
2ba8d47
Removed obsolete condition in the link actions view.
oleq Jan 31, 2018
afbc276
Merge branch 'master' into t/ckeditor5/645
oleq Jan 31, 2018
107ab4a
Tests: The UI should hide when the selection expands.
oleq Jan 31, 2018
216bcc0
Docs: Added docs to the link plugin.
oleq Jan 31, 2018
70a55ef
Docs: Fixed broken link in the link plugin.
oleq Jan 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 248 additions & 80 deletions src/link.js

Large diffs are not rendered by default.

235 changes: 235 additions & 0 deletions src/ui/linkactionsview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module link/ui/linkactionsview
*/

import View from '@ckeditor/ckeditor5-ui/src/view';
import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';

import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';

import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';

import unlinkIcon from '../../theme/icons/unlink.svg';
import pencilIcon from '@ckeditor/ckeditor5-core/theme/icons/pencil.svg';
import '../../theme/linkactions.css';

/**
* The link actions view class. This view displays link preview, allows
* unlinking or editing the link.
*
* @extends module:ui/view~View
*/
export default class LinkActionsView extends View {
/**
* @inheritDoc
*/
constructor( locale ) {
super( locale );

const t = locale.t;

/**
* Tracks information about DOM focus in the actions.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();

/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();

/**
* The href preview view.
*
* @member {module:ui/view~View}
*/
this.previewButtonView = this._createPreviewButton();

/**
* The unlink button view.
*
* @member {module:ui/button/buttonview~ButtonView}
*/
this.unlinkButtonView = this._createButton( t( 'Unlink' ), unlinkIcon, 'unlink' );

/**
* The edit link button view.
*
* @member {module:ui/button/buttonview~ButtonView}
*/
this.editButtonView = this._createButton( t( 'Edit link' ), pencilIcon, 'edit' );

/**
* Value of the "href" attribute of the link to use in the {@link #previewButtonView}.
*
* @observable
* @member {String}
*/
this.set( 'href' );

/**
* A collection of views which can be focused in the view.
*
* @readonly
* @protected
* @member {module:ui/viewcollection~ViewCollection}
*/
this._focusables = new ViewCollection();

/**
* Helps cycling over {@link #_focusables} in the view.
*
* @readonly
* @protected
* @member {module:ui/focuscycler~FocusCycler}
*/
this._focusCycler = new FocusCycler( {
focusables: this._focusables,
focusTracker: this.focusTracker,
keystrokeHandler: this.keystrokes,
actions: {
// Navigate fields backwards using the Shift + Tab keystroke.
focusPrevious: 'shift + tab',

// Navigate fields forwards using the Tab key.
focusNext: 'tab'
}
} );

this.setTemplate( {
tag: 'div',

attributes: {
class: [
'ck-link-actions',
],

// https://github.com/ckeditor/ckeditor5-link/issues/90
tabindex: '-1'
},

children: [
this.previewButtonView,
this.editButtonView,
this.unlinkButtonView
]
} );
}

/**
* @inheritDoc
*/
render() {
super.render();

const childViews = [
this.previewButtonView,
this.editButtonView,
this.unlinkButtonView
];

childViews.forEach( v => {
// Register the view as focusable.
this._focusables.add( v );

// Register the view in the focus tracker.
this.focusTracker.add( v.element );
} );

// Start listening for the keystrokes coming from #element.
this.keystrokes.listenTo( this.element );
}

/**
* Focuses the fist {@link #_focusables} in the actions.
*/
focus() {
this._focusCycler.focusFirst();
}

/**
* Creates a button view.
*
* @private
* @param {String} label The button label.
* @param {String} icon The button's icon.
* @param {String} [eventName] An event name that the `ButtonView#execute` event will be delegated to.
* @returns {module:ui/button/buttonview~ButtonView} The button view instance.
*/
_createButton( label, icon, eventName ) {
const button = new ButtonView( this.locale );

button.set( {
label,
icon,
tooltip: true
} );

button.delegate( 'execute' ).to( this, eventName );

return button;
}

/**
* Creates a link href preview button.
*
* @private
* @returns {module:ui/button/buttonview~ButtonView} The button view instance.
*/
_createPreviewButton() {
const button = new ButtonView( this.locale );
const bind = this.bindTemplate;
const t = this.t;

button.set( {
withText: true,
tooltip: t( 'Open link in new tab' )
} );

button.extendTemplate( {
attributes: {
class: [
'ck-link-actions__preview'
],
href: bind.to( 'href' ),
target: '_blank'
}
} );

button.bind( 'label' ).to( this, 'href', href => {
return href || t( 'This link has no URL' );
} );

button.bind( 'isEnabled' ).to( this, 'href', href => !!href );

button.template.tag = 'a';
button.template.eventListeners = {};

return button;
}
}

/**
* Fired when the {@link #editButtonView} is clicked.
*
* @event edit
*/

/**
* Fired when the {@link #unlinkButtonView} is clicked.
*
* @event unlink
*/
51 changes: 15 additions & 36 deletions src/ui/linkformview.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';

import checkIcon from '@ckeditor/ckeditor5-core/theme/icons/check.svg';
import cancelIcon from '@ckeditor/ckeditor5-core/theme/icons/cancel.svg';
import '../../theme/linkform.css';

/**
Expand Down Expand Up @@ -65,22 +67,15 @@ export default class LinkFormView extends View {
*
* @member {module:ui/button/buttonview~ButtonView}
*/
this.saveButtonView = this._createButton( t( 'Save' ) );
this.saveButtonView = this._createButton( t( 'Save' ), checkIcon );
this.saveButtonView.type = 'submit';

/**
* The Cancel button view.
*
* @member {module:ui/button/buttonview~ButtonView}
*/
this.cancelButtonView = this._createButton( t( 'Cancel' ), 'cancel' );

/**
* The Unlink button view.
*
* @member {module:ui/button/buttonview~ButtonView}
*/
this.unlinkButtonView = this._createButton( t( 'Unlink' ), 'unlink' );
this.cancelButtonView = this._createButton( t( 'Cancel' ), cancelIcon, 'cancel' );

/**
* A collection of views which can be focused in the form.
Expand Down Expand Up @@ -133,21 +128,8 @@ export default class LinkFormView extends View {

children: [
this.urlInputView,
{
tag: 'div',

attributes: {
class: [
'ck-link-form__actions'
]
},

children: [
this.saveButtonView,
this.cancelButtonView,
this.unlinkButtonView
]
}
this.saveButtonView,
this.cancelButtonView
]
} );
}
Expand All @@ -165,8 +147,7 @@ export default class LinkFormView extends View {
const childViews = [
this.urlInputView,
this.saveButtonView,
this.cancelButtonView,
this.unlinkButtonView
this.cancelButtonView
];

childViews.forEach( v => {
Expand Down Expand Up @@ -209,15 +190,19 @@ export default class LinkFormView extends View {
* Creates a button view.
*
* @private
* @param {String} label The button label
* @param {String} label The button label.
* @param {String} icon The button's icon.
* @param {String} [eventName] An event name that the `ButtonView#execute` event will be delegated to.
* @returns {module:ui/button/buttonview~ButtonView} The button view instance.
*/
_createButton( label, eventName ) {
_createButton( label, icon, eventName ) {
const button = new ButtonView( this.locale );

button.label = label;
button.withText = true;
button.set( {
label,
icon,
tooltip: true
} );

if ( eventName ) {
button.delegate( 'execute' ).to( this, eventName );
Expand All @@ -239,9 +224,3 @@ export default class LinkFormView extends View {
*
* @event cancel
*/

/**
* Fired when the {@link #unlinkButtonView} is clicked.
*
* @event unlink
*/
Loading