Ghost/ghost/admin/app/components/gh-token-input/trigger.js
Kevin Ansfield 352c4af1d7 Refactored usage of .get('property') with es5 getters
no issue
- ran [es5-getter-ember-codemod](https://github.com/rondale-sc/es5-getter-ember-codemod)
- [es5 getters RFC](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md)
- updates the majority of `object.get('property')` with `object.property` with exceptions:
  - `.get('nested.property')` - it's not possible to determine if this is relying on "safe" path chaining for when `nested` doesn't exist
  - `.get('config.x')` and `.get('settings.x')` - both our `config` and `settings` services are proxy objects which do not support es5 getters
- this PR is not exhaustive, there are still a number of places where `.get('service.foo')` and similar could be replaced but it gets us a long way there in a quick and automated fashion
2019-03-06 13:54:14 +00:00

69 lines
2.8 KiB
JavaScript

import EmberPowerSelectMultipleTrigger from 'ember-power-select/components/power-select-multiple/trigger';
import {assert} from '@ember/debug';
import {get} from '@ember/object';
import {isBlank} from '@ember/utils';
export default EmberPowerSelectMultipleTrigger.extend({
actions: {
chooseOption(option) {
this.select.actions.choose(option);
},
handleOptionMouseDown(event) {
if (!event.target.closest('[data-selected-index]')) {
let action = this.get('extra.optionMouseDown');
if (action) {
return action(event);
}
}
},
handleOptionTouchStart(event) {
let action = this.get('extra.optionTouchStart');
if (action) {
return action(event);
}
},
reorderItems() {
// ember-drag-drop's sortable-objects has two-way bindings and will
// update EPS' selected value directly. We have to create a copy
// after sorting in order to force the onchange action to be triggered
let selectedCopy = this.select.selected.slice();
this.select.actions.select(selectedCopy);
},
// copied directly from EPS, the default behaviour of stopping propagation
// of keydown events prevents our shortcuts from being triggered
onKeydown(e) {
let {onKeydown, select} = this;
if (onKeydown && onKeydown(e) === false) {
e.stopPropagation();
return false;
}
if (e.keyCode === 8) {
e.stopPropagation();
if (isBlank(e.target.value)) {
let lastSelection = select.selected[select.selected.length - 1];
if (lastSelection) {
select.actions.select(this.buildSelection(lastSelection, select), e);
if (typeof lastSelection === 'string') {
select.actions.search(lastSelection);
} else {
let searchField = this.searchField;
assert('`{{power-select-multiple}}` requires a `searchField` when the options are not strings to remove options using backspace', searchField);
select.actions.search(get(lastSelection, searchField));
}
select.actions.open(e);
}
}
}
// Disable the propagation cancellation so that our shortcuts still work
// } else if (e.keyCode >= 48 && e.keyCode <= 90 || e.keyCode === 32) { // Keys 0-9, a-z or SPACE
// e.stopPropagation();
// }
}
}
});