Skip to content
This repository has been archived by the owner on Nov 16, 2017. It is now read-only.

Balloon Panel and related components #60

Merged
merged 32 commits into from
Sep 9, 2016
Merged

Balloon Panel and related components #60

merged 32 commits into from
Sep 9, 2016

Conversation

oskarwrobel
Copy link
Contributor

@oskarwrobel oskarwrobel commented Aug 30, 2016

Fixes #55 and #54

This PR introduces BalloonPanel component and related to LinkBalloonPanel components.

Components are moved from ckeditor5-link repository, little refactored, tested and documented.

FollowUp for missing manual tests: #61
Related to: ckeditor/ckeditor5-theme-lark#34

[Edit] Now I see that this PR could be cut into smaller pieces. There is a lot of code :/

this.hide();
}
};
document.addEventListener( 'keydown', this._keyCloseCallback );
Copy link
Contributor Author

@oskarwrobel oskarwrobel Aug 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide how we want to deal with keyboard events in UI components.
Right now this code is not testable, because it is difficult/not possible to dispatch Keyboard event with specified charCode on Webkit. Mostly we will need listener for Esc to close some popups, balloons etc, but I can imagine components with more advanced keyboard support (like #16).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be done by

this.listenTo( document, 'keydown', () => {}` );
this.stopListening( document, 'keydown' );

which is via DOMEmitterMixin class. See how ListDropdownView works and its tests.

Copy link
Member

@oleq oleq Sep 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulating key(Code) event should be possible via key property instead of keyCode which is marked as deprecated.

document.addEventListener( 'keydown', ( evt ) => console.log( evt ) );
document.dispatchEvent( new KeyboardEvent( 'keydown', { key: '20', keyCode: '20', code: '20' } ) );

BTW: KeyboardEvent.key uses verbal description like "Escape".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was trying by 'key' property too but I'll try your solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Given the above mess I see no other option than:

  1. Checking if this._keyCloseCallback is called at all on document.body.dispatchEvent( new Event( 'keydown' );
  2. Testing what happens if this._keyCloseCallback is called standalone with a synthetic evt object containing different keyCodes (would it call hide then or not?).

Copy link
Member

@Reinmar Reinmar Sep 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tricky thing with keyCode is that key isn't supported in every browser yet. keyCode is (with some exceptions – namely, onscreen keyboard on Android). This means that keyCode is used by everyone anyway, so it doesn't actually change anything that it's deprecated – everyone use it.


// Attach keydown listener for closing panel on Esc press.
this._keyCloseCallback = evt => {
if ( evt.keyCode == 27 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition lacks test coverage.

Copy link
Contributor Author

@oskarwrobel oskarwrobel Sep 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I mentioned about it in comment below. There is a problem with dispatching Keyboard event with specified keyCode.


view = new LabeledInputView();

labeledInput = new LabeledInput( model, view );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can live without LabeledInput here too.

@oleq
Copy link
Member

oleq commented Sep 7, 2016

A more general impression: Do we need BalloonPanelView#hide event? Would not BalloonPanelView.model#change:isVisible do the same job?

@oskarwrobel
Copy link
Contributor Author

A more general impression: Do we need BalloonPanelView#hide event? Would not BalloonPanelView.model#change:isVisible do the same job?

I've removed it.

@oleq
Copy link
Member

oleq commented Sep 7, 2016

I guess there's some refactoring needed in inputs/labels/etc.

  1. LabeledInput should become LabeledInputText or allow passing the class of the input in the constructor. ATM it is strictly bound to InputText but the name of the class does not reflect it.
  2. InputLabel should become just Label. It can label inputs, selects, textareas. It should also be reflected in the CSS class of the component, IMO.
  3. If LabeledInput becomes LabeledInputText, it should land in inputtext/labeled folder. Just like dropdown/list.

@oleq
Copy link
Member

oleq commented Sep 7, 2016

I was also wondering what to do with the Box component.

First of all, some binding between the model and the class attribute would not hurt.

Secondly, I wonder if the component is needed at all. ATM it exists just to wrap some elements in DOM and style them (simply align them to the right/left). It's an overkill to use JS and create yet another branch in the UI's DOM to do this. It might be a little bit easier if LinkBalloonPanelView simply extended the template of BalloonPanelView and created additional child/region with a desired CSS class to accommodate the buttons and eventually align them.

@oleq
Copy link
Member

oleq commented Sep 7, 2016

I checked and it's possible to extend the template with a new children

export default class LinkBalloonPanelView extends BalloonPanelView {
    /**
     * @inheritDoc
     */
    constructor( locale ) {
        super( locale );

        Template.extend( this.template, {
            attributes: {
                class: [
                    'ck-link-balloon-panel',
                ]
            }
        } );

        this.template.definition.children = [
            {
                tag: 'div',
                attributes: {
                    class: [
                        'moo'
                    ]
                }
            }
        ];
    }
}

but it does not work via Template.extend, which has been designed to extend existing children only (like their attributes) in assumption that if the number of children does not match, then it must be a different component (class). I remember talking to @Reinmar about it and we came up with this behaviour, which, TBH, I don't quite consider right anymore in the context of the problem we're facing right now.

WDYT? Is is a different component because it comes with a new container/region for the buttons? Or maybe we should allow this kind of extension for the sake of similar container–like components in the future?

@oskarwrobel
Copy link
Contributor Author

oskarwrobel commented Sep 7, 2016

WDYT? Is is a different component because it comes with a new container/region for the buttons? Or maybe we should allow this kind of extension for the sake of similar container–like components in the future?

I like it, I was trying to do exactly the same (I mean create a new region for buttons instead of using Box component), but i had a problem with CKEditorError: ui-template-extend-children-mismatch: The number of children in extended definition does not match.. Looks like this.template.definition.children solves the problem.

/**
* Input instance.
*
* @member {ui.input.InputText}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here will be more types in the feature.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants