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

T/262: Implemented View#render method #332

Merged
merged 45 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f7aad28
Replaced View#element on-demand rendering with the #render method. Re…
oleq Oct 17, 2017
4034017
Aligned Template class to the View#render API. Changed type of Templa…
oleq Oct 17, 2017
55cc8f9
Aligned the ViewCollection class to the View#render API. Minor refact…
oleq Oct 18, 2017
f08d48d
Created View#setTemplate and View#extendTemplate methods.
oleq Oct 18, 2017
2c8717d
Created View#setTemplate and View#extendTemplate methods.
oleq Oct 18, 2017
53c6647
Aligned ButtonView to the View#render API. Code refactoring in the co…
oleq Oct 18, 2017
f6f712d
Aligned Dropdown and DropdownPanel components to the View#render API.
oleq Oct 18, 2017
7729899
Aligned EditableUIView to the View#render API.
oleq Oct 18, 2017
7fe4f41
Aligned InlineEditableUIView to the View#render API.
oleq Oct 18, 2017
39180de
Aligned BoxedEditorUIView to the View#render API.
oleq Oct 18, 2017
b97f61c
Aligned EditorUIView to the View#render API.
oleq Oct 18, 2017
0680ec1
Aligned IconView to the View#render API. Enhanced icon content manage…
oleq Oct 18, 2017
1f9108a
Aligned IframeView to the View#render API. Code refactoring.
oleq Oct 18, 2017
336a6a7
InputTextViewAligned InputTextView to the View#render API.
oleq Oct 18, 2017
aa0e260
Aligned LabelView to the View#render API.
oleq Oct 18, 2017
78d32f5
Aligned LabeledInputView to the View#render API.
oleq Oct 18, 2017
f09c958
Aligned ListItemView to the View#render API.
oleq Oct 18, 2017
5334b7f
Aligned ListView to the View#render API.
oleq Oct 18, 2017
b7b7bc3
Aligned BalloonPanelView to the View#render API.
oleq Oct 18, 2017
77a50f0
Aligned ContextualBalloon to the View#render API.
oleq Oct 18, 2017
df79c72
Aligned StickyPanel to the View#render API. Massive code refactoring …
oleq Oct 18, 2017
ea121b1
Allowed native DOM nodes as children of a Template.
oleq Oct 20, 2017
41bf575
Aligned ContextualToolbar plugin to the View#render API.
oleq Oct 20, 2017
cdc2f35
Tests: Aligned enableToolbarKeyboardFocus() util tests to the new Vie…
oleq Oct 20, 2017
3188d0f
Aligned ToolbarSeparatorView to the View#render API.
oleq Oct 20, 2017
61564c9
Aligned ToolbarView to the View#render API.
oleq Oct 20, 2017
657291f
Aligned TooltipView to the View#render API.
oleq Oct 20, 2017
00f3a3a
Increated test code coverage in ListView and ToolbarView.
oleq Oct 20, 2017
86a0f5b
Docs: Updated createListDropdown docs with the new View#render API.
oleq Oct 20, 2017
286de91
Docs: Updated preventDefault bindng to the new View#render API.
oleq Oct 20, 2017
019f20b
Updated UI test utils to the latest View#render API.
oleq Oct 20, 2017
b5c79e6
Tests: Aligned createListDropdown helper tests to the View#render API.
oleq Oct 20, 2017
c7daa46
Test: Aligned the image toolbar test to the latest View API.
oleq Oct 20, 2017
e924de0
Updated StickyPanelView styles to match the new structure of the comp…
oleq Oct 20, 2017
16dd217
Docs: Fixed docs build errors.
oleq Oct 20, 2017
b0e2bdb
Tests: Cleaned-up DOM after Template tests.
oleq Oct 23, 2017
3766f2c
Tests: Cleaned-up the document.body after View tests.
oleq Oct 23, 2017
1b8969b
Tests: Cleaned up the document.body after various UI components' tests.
oleq Oct 23, 2017
4a51bd8
Tests: Updated various manual tests to the View#render API.
oleq Oct 23, 2017
9b77f1e
Docs: Aligned Bootstrap UI example to the View#render API.
oleq Oct 24, 2017
ce7f629
Docs: Fixed broken links in the View class.
oleq Oct 24, 2017
7f1c624
Docs: Improved docs in the Bootstrap UI example.
oleq Oct 24, 2017
f7fa99d
Fix: ToolbarView and ListView should add #items upon #render.
oleq Oct 24, 2017
896eb5a
Merge branch 'master' into t/262
oleq Oct 31, 2017
64c7ad5
Simplified the rendering of the IframeView.
oleq Oct 31, 2017
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
4 changes: 2 additions & 2 deletions docs/_snippets/examples/bootstrap-ui-inner.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default class BootstrapEditor extends StandardEditor {

resolve(
editor.initPlugins()
// Initialize the editable view in DOM first.
.then( () => editable.init() )
// Render the editable view in DOM first.
.then( () => editable.render() )
// Replace the editor#element with editor.editable#element.
.then( () => editor._elementReplacer.replace( element, editable.element ) )
// Handle the UI of the editor.
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/guides/external-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export default class BootstrapEditor extends StandardEditor {

resolve(
editor.initPlugins()
// Initialize the editable view in DOM first.
.then( () => editable.init() )
// Render the editable view in DOM first.
.then( () => editable.render() )
// Replace the editor#element with editor.editable#element.
.then( () => editor._elementReplacer.replace( element, editable.element ) )
// Handle the UI of the editor.
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/preventdefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* // ...
*
* this.template = new Template( {
* this.setTemplate( {
* tag: 'div',
*
* on: {
Expand Down
95 changes: 61 additions & 34 deletions src/button/buttonview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import View from '../view';
import Template from '../template';
import IconView from '../icon/iconview';
import TooltipView from '../tooltip/tooltipview';

Expand All @@ -26,7 +25,7 @@ import { getEnvKeystrokeText } from '@ckeditor/ckeditor5-utils/src/keyboard';
* withText: true
* } );
*
* view.init();
* view.render();
*
* document.body.append( view.element );
*
Expand All @@ -39,6 +38,8 @@ export default class ButtonView extends View {
constructor( locale ) {
super( locale );

const bind = this.bindTemplate;

/**
* The label of the button view visible to the user when {@link #withText} is `true`.
* It can also be used to create a {@link #tooltip}.
Expand Down Expand Up @@ -151,6 +152,30 @@ export default class ButtonView extends View {
*/
this.set( 'tabindex', -1 );

/**
* Collection of the child views inside of the button {@link #element}.
*
* @readonly
* @member {module:ui/viewcollection~ViewCollection}
*/
this.children = this.createCollection();

/**
* Tooltip of the button view. It is configurable using the {@link #tooltip tooltip attribute}.
*
* @readonly
* @member {module:ui/tooltip/tooltipview~TooltipView} #tooltipView
*/
this.tooltipView = this._createTooltipView();

/**
* Label of the button view. It is configurable using the {@link #label label attribute}.
*
* @readonly
* @member {module:ui/view~View} #labelView
*/
this.labelView = this._createLabelView();

/**
* Tooltip of the button bound to the template.
*
Expand All @@ -167,24 +192,14 @@ export default class ButtonView extends View {
this._getTooltipString.bind( this )
);

/**
* Tooltip of the button view. It is configurable using the {@link #tooltip tooltip attribute}.
*
* @readonly
* @member {module:ui/tooltip/tooltipview~TooltipView} #tooltipView
*/
this.tooltipView = this._createTooltipView();

/**
* (Optional) The icon view of the button. Only present when the {@link #icon icon attribute} is defined.
*
* @readonly
* @member {module:ui/icon/iconview~IconView} #iconView
*/

const bind = this.bindTemplate;

this.template = new Template( {
this.setTemplate( {
tag: 'button',

attributes: {
Expand All @@ -199,22 +214,7 @@ export default class ButtonView extends View {
tabindex: bind.to( 'tabindex' )
},

children: [
{
tag: 'span',

attributes: {
class: [ 'ck-button__label' ]
},

children: [
{
text: bind.to( 'label' )
}
]
},
this.tooltipView
],
children: this.children,

on: {
mousedown: bind.to( evt => {
Expand Down Expand Up @@ -246,18 +246,19 @@ export default class ButtonView extends View {
/**
* @inheritDoc
*/
init() {
render() {
super.render();

if ( this.icon ) {
const iconView = this.iconView = new IconView();

iconView.bind( 'content' ).to( this, 'icon' );
this.element.insertBefore( iconView.element, this.element.firstChild );

// Make sure the icon will be destroyed along with the button.
this.addChildren( iconView );
this.children.add( iconView );
}

super.init();
this.children.add( this.tooltipView );
this.children.add( this.labelView );
}

/**
Expand All @@ -283,6 +284,32 @@ export default class ButtonView extends View {
return tooltipView;
}

/**
* Creates a label view instance and binds it with button attributes.
*
* @private
* @returns {module:ui/view~View}
*/
_createLabelView() {
const labelView = new View();

labelView.setTemplate( {
tag: 'span',

attributes: {
class: [ 'ck-button__label' ]
},

children: [
{
text: this.bindTemplate.to( 'label' )
}
]
} );

return labelView;
}

/**
* Gets the text for the {@link #tooltipView} from the combination of
* {@link #tooltip}, {@link #label} and {@link #keystroke} attributes.
Expand Down
2 changes: 1 addition & 1 deletion src/dropdown/createdropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import DropdownPanelView from './dropdownpanelview';
*
* const dropdown = createDropdown( model );
*
* dropdown.init();
* dropdown.render();
*
* // Will render a dropdown labeled "A dropdown" with an empty panel.
* document.body.appendChild( dropdown.element );
Expand Down
3 changes: 1 addition & 2 deletions src/dropdown/dropdownpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import View from '../view';
import Template from '../template';

/**
* The dropdown panel view class.
Expand Down Expand Up @@ -46,7 +45,7 @@ export default class DropdownPanelView extends View {
*/
this.children = this.createCollection();

this.template = new Template( {
this.setTemplate( {
tag: 'div',

attributes: {
Expand Down
25 changes: 12 additions & 13 deletions src/dropdown/dropdownview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import View from '../view';
import Template from '../template';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';

Expand All @@ -25,7 +24,7 @@ import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
* withText: true
* } );
*
* dropdown.init();
* dropdown.render();
*
* // Will render a dropdown with a panel containing a "Content of the panel" text.
* document.body.appendChild( dropdown.element );
Expand All @@ -46,7 +45,7 @@ export default class DropdownView extends View {
// Extend button's template before it's registered as a child of the dropdown because
// by doing so, its #element is rendered and any post–render template extension will
// not be reflected in DOM.
Template.extend( buttonView.template, {
buttonView.extendTemplate( {
attributes: {
class: [
'ck-dropdown__button'
Expand Down Expand Up @@ -106,7 +105,7 @@ export default class DropdownView extends View {
*/
this.keystrokes = new KeystrokeHandler();

this.template = new Template( {
this.setTemplate( {
tag: 'div',

attributes: {
Expand All @@ -120,20 +119,22 @@ export default class DropdownView extends View {
panelView
]
} );
}

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

// Toggle the the dropdown when it's button has been clicked.
this.listenTo( buttonView, 'execute', () => {
this.listenTo( this.buttonView, 'execute', () => {
this.isOpen = !this.isOpen;
} );

// Toggle the visibility of the panel when the dropdown becomes open.
panelView.bind( 'isVisible' ).to( this, 'isOpen' );
}
this.panelView.bind( 'isVisible' ).to( this, 'isOpen' );

/**
* @inheritDoc
*/
init() {
// Listen for keystrokes coming from within #element.
this.keystrokes.listenTo( this.element );

Expand Down Expand Up @@ -167,8 +168,6 @@ export default class DropdownView extends View {
// Close the dropdown using the arrow left/escape key.
this.keystrokes.set( 'arrowleft', closeDropdown );
this.keystrokes.set( 'esc', closeDropdown );

super.init();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/dropdown/list/createlistdropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ import createDropdown from '../createdropdown';
*
* const dropdown = createListDropdown( model, locale );
*
* dropdown.init();
*
* // Will render a dropdown labeled "A dropdown" with a list in the panel
* // containing two items.
* dropdown.render()
* document.body.appendChild( dropdown.element );
*
* The model instance remains in control of the dropdown after it has been created. E.g. changes to the
Expand All @@ -54,7 +53,6 @@ import createDropdown from '../createdropdown';
*/
export default function createListDropdown( model, locale ) {
const dropdownView = createDropdown( model, locale );

const listView = dropdownView.listView = new ListView( locale );

listView.items.bindTo( model.items ).using( itemModel => {
Expand Down
13 changes: 6 additions & 7 deletions src/editableui/editableuiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import View from '../view';
import Template from '../template';

/**
* The editable UI view class.
Expand All @@ -32,7 +31,7 @@ export default class EditableUIView extends View {
this.element = this.editableElement = editableElement;
}

this.template = new Template( {
this.setTemplate( {
tag: 'div',
attributes: {
class: [
Expand Down Expand Up @@ -77,17 +76,17 @@ export default class EditableUIView extends View {
}

/**
* Initializes the view by either applying the {@link #template} to the existing
* Renders the view by either applying the {@link #template} to the existing
* {@link #editableElement} or assigning {@link #element} as {@link #editableElement}.
*/
init() {
render() {
super.render();

if ( this.externalElement ) {
this.template.apply( this.externalElement );
this.template.apply( this.element = this.externalElement );
} else {
this.editableElement = this.element;
}

super.init();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/editableui/inline/inlineeditableuiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import EditableUIView from '../../editableui/editableuiview';
import Template from '../../template';

/**
* The inline editable UI class implementing an inline {@link module:ui/editableui/editableuiview~EditableUIView}.
Expand Down Expand Up @@ -42,7 +41,7 @@ export default class InlineEditableUIView extends EditableUIView {
return t( 'Rich Text Editor, %0', [ value ] );
};

Template.extend( this.template, {
this.extendTemplate( {
attributes: {
role: 'textbox',
'aria-label': bind.to( 'name', getLabel ),
Expand Down
3 changes: 1 addition & 2 deletions src/editorui/boxed/boxededitoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import EditorUIView from '../../editorui/editoruiview';
import uid from '@ckeditor/ckeditor5-utils/src/uid';
import Template from '../../template';

/**
* The boxed editor UI view class. This class represents an editor interface
Expand Down Expand Up @@ -47,7 +46,7 @@ export default class BoxedEditorUIView extends EditorUIView {
*/
this.main = this.createCollection();

this.template = new Template( {
this.setTemplate( {
tag: 'div',

attributes: {
Expand Down
Loading