mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
654d373655
* Update dependency ember-power-select to v4 * Fixed trigger component override collision when building - move the "override" into our own namespace - update all `<PowerSelect>` usage to explicitly reference our customised trigger component * Bumped ember-power-datepicker - bumps `ember-basic-dropdown` sub-dependency - resolves "Error: Could not find module `ember-compatibility-helpers` imported from `@glimmer/component/index`" - https://github.com/cibernox/ember-basic-dropdown/issues/551 * Updated trigger to use class syntax - it's not possible to use `.extend()` on an imported class * Updated <GhBasicDropdown> - match updated ember-basic-dropdown code * Added `autofocus` modifier - added `ember-modifier` dependency so that we can create our own render modifiers * Updated <GhSearchInputTrigger> to a glimmer component * Updated gh-token-input components * Fixed tests - wrap `<PowerSelect>` with `<div>` to maintain test selectors - fixed `<GhBasicDropdown>` not rendering anything due to not having a local template Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
import $ from 'jquery';
|
|
import PowerSelectMultiple from 'ember-power-select/components/power-select-multiple';
|
|
import templateLayout from '../../templates/components/gh-token-input/select-multiple';
|
|
import {action} from '@ember/object';
|
|
import {bind} from '@ember/runloop';
|
|
import {layout, tagName} from '@ember-decorators/component';
|
|
|
|
// TODO: convert from jQuery to native DOM
|
|
const END_ACTIONS = 'click.ghToken mouseup.ghToken touchend.ghToken';
|
|
|
|
// triggering focus on the search input within ESA's onfocus event breaks the
|
|
// drag-n-drop functionality in ember-drag-drop so we watch for events that
|
|
// could be the start of a drag and disable the default focus behaviour until
|
|
// we get another event signalling the end of a drag
|
|
|
|
@tagName('div')
|
|
@layout(templateLayout)
|
|
class GhTokenInputSelectMultiple extends PowerSelectMultiple {
|
|
_canFocus = true;
|
|
|
|
willDestroyElement() {
|
|
super.willDestroyElement(...arguments);
|
|
|
|
if (this._allowFocusListener) {
|
|
$(window).off(END_ACTIONS, this._allowFocusListener);
|
|
}
|
|
}
|
|
|
|
// actions
|
|
|
|
@action
|
|
optionMouseDown(event) {
|
|
if (event.which === 1 && !event.ctrlKey) {
|
|
this._denyFocus(event);
|
|
}
|
|
}
|
|
|
|
@action
|
|
optionTouchStart(event) {
|
|
this._denyFocus(event);
|
|
}
|
|
|
|
@action
|
|
handleFocus() {
|
|
if (this._canFocus) {
|
|
super.handleFocus(...arguments);
|
|
}
|
|
}
|
|
|
|
// internal
|
|
|
|
_denyFocus() {
|
|
if (this._canFocus) {
|
|
this._canFocus = false;
|
|
|
|
this._allowFocusListener = bind(this, this._allowFocus);
|
|
|
|
$(window).on(END_ACTIONS, this._allowFocusListener);
|
|
}
|
|
}
|
|
|
|
_allowFocus() {
|
|
this._canFocus = true;
|
|
|
|
$(window).off(END_ACTIONS, this._allowFocusListener);
|
|
this._allowFocusListener = null;
|
|
}
|
|
}
|
|
|
|
export default GhTokenInputSelectMultiple;
|