2019-07-23 20:13:41 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-09 12:19:45 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2019-07-23 20:13:41 +03:00
|
|
|
import {action, computed} from '@ember/object';
|
2022-02-09 12:19:45 +03:00
|
|
|
import {classNameBindings, tagName} from '@ember-decorators/component';
|
2019-07-23 20:13:41 +03:00
|
|
|
import {kgStyle} from '../helpers/kg-style';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
@classic
|
|
|
|
@tagName('figcaption')
|
|
|
|
@classNameBindings('figCaptionClass')
|
|
|
|
export default class KoenigAltInput extends Component {
|
|
|
|
@service koenigUi;
|
2019-07-23 20:13:41 +03:00
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
alt = '';
|
|
|
|
placeholder = '';
|
2019-07-23 20:13:41 +03:00
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
update() {}
|
|
|
|
addParagraphAfterCard() {}
|
|
|
|
moveCursorToNextSection() {}
|
|
|
|
moveCursorToPrevSection() {}
|
2019-07-23 20:13:41 +03:00
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
@computed
|
|
|
|
get figCaptionClass() {
|
2019-07-23 20:13:41 +03:00
|
|
|
return `${kgStyle(['figcaption'])} w-100 relative`;
|
2022-02-09 12:19:45 +03:00
|
|
|
}
|
2019-07-23 20:13:41 +03:00
|
|
|
|
|
|
|
didInsertElement() {
|
2022-02-09 12:19:45 +03:00
|
|
|
super.didInsertElement(...arguments);
|
2019-07-23 20:13:41 +03:00
|
|
|
this.element.querySelector('input').focus();
|
2022-02-09 12:19:45 +03:00
|
|
|
}
|
2019-07-23 20:13:41 +03:00
|
|
|
|
|
|
|
willDestroyElement() {
|
2022-02-09 12:19:45 +03:00
|
|
|
super.willDestroyElement(...arguments);
|
2019-07-23 20:13:41 +03:00
|
|
|
this.koenigUi.captionLostFocus(this);
|
2022-02-09 12:19:45 +03:00
|
|
|
}
|
2019-07-23 20:13:41 +03:00
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
@action
|
|
|
|
onInput(event) {
|
2019-07-23 20:13:41 +03:00
|
|
|
this.update(event.target.value);
|
2022-02-09 12:19:45 +03:00
|
|
|
}
|
2019-07-23 20:13:41 +03:00
|
|
|
|
2022-02-09 12:19:45 +03:00
|
|
|
@action
|
|
|
|
onKeydown(event) {
|
2019-07-23 20:13:41 +03:00
|
|
|
let {selectionStart, selectionEnd, value} = event.target;
|
|
|
|
let noSelection = selectionStart === selectionEnd;
|
|
|
|
|
|
|
|
let {altKey, ctrlKey, metaKey, shiftKey} = event;
|
|
|
|
let hasModifier = altKey || ctrlKey || metaKey || shiftKey;
|
|
|
|
|
|
|
|
if (hasModifier) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event.key) {
|
|
|
|
case 'Enter':
|
|
|
|
event.preventDefault();
|
|
|
|
event.target.blur();
|
|
|
|
this.addParagraphAfterCard();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Escape':
|
|
|
|
event.target.blur();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ArrowUp':
|
|
|
|
case 'ArrowLeft':
|
|
|
|
if (noSelection && selectionStart === 0) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.target.blur();
|
|
|
|
this.moveCursorToPrevSection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ArrowRight':
|
|
|
|
case 'ArrowDown':
|
|
|
|
if (noSelection && selectionEnd === value.length) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.target.blur();
|
|
|
|
this.moveCursorToNextSection();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-02-09 12:19:45 +03:00
|
|
|
}
|
|
|
|
}
|