mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-04 08:54:36 +03:00
61cf4d46db
refs https://github.com/TryGhost/Ghost/issues/9311 Koenig is being fully rebooted, first port of call is to focus on getting the rich-text only aspect of mobiledoc-kit working with our popup toolbar. - renames old koenig implementation (used for reference, will eventually be deleted) - new `{{koenig-editor}}` mobiledoc-kit component implementation based on ember-mobiledoc-editor - markdown text expansions - new `{{gh-koenig-edtor}}` that wraps our title+editor and handles keyboard navigation between the two - clicks below content will focus the editor - new `{{koenig-toolbar}}` component for the popup formatting toolbar with improved behaviour and simplified code
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
import OneWayTextarea from 'ember-one-way-controls/components/one-way-textarea';
|
|
import TextInputMixin from 'ghost-admin/mixins/text-input';
|
|
import {run} from '@ember/runloop';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default OneWayTextarea.extend(TextInputMixin, {
|
|
resizeDetector: service(),
|
|
|
|
classNames: 'gh-input',
|
|
|
|
autoExpand: false,
|
|
|
|
didReceiveAttrs() {
|
|
this._super(...arguments);
|
|
|
|
// trigger auto-expand any time the value changes
|
|
if (this.get('autoExpand')) {
|
|
run.scheduleOnce('afterRender', this, this._autoExpand);
|
|
}
|
|
},
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
// set up resize handler on element insert so that we can autoexpand
|
|
// when the element container changes size
|
|
if (this.get('autoExpand')) {
|
|
run.scheduleOnce('afterRender', this, this._setupAutoExpand);
|
|
}
|
|
|
|
if (this.get('didCreateTextarea')) {
|
|
this.get('didCreateTextarea')(this.element);
|
|
}
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._teardownAutoExpand();
|
|
this._super(...arguments);
|
|
},
|
|
|
|
willInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
// disable the draggable resize element that browsers add to textareas
|
|
if (this.get('autoExpand')) {
|
|
this.element.style.resize = 'none';
|
|
}
|
|
},
|
|
|
|
_autoExpand() {
|
|
let el = this.element;
|
|
|
|
// collapse the element first so that we can shrink as well as expand
|
|
// then set the height to match the text height
|
|
if (el) {
|
|
el.style.height = 0;
|
|
el.style.height = `${el.scrollHeight}px`;
|
|
}
|
|
},
|
|
|
|
_setupAutoExpand() {
|
|
this._resizeCallback = run.bind(this, this._onResize);
|
|
this.get('resizeDetector').setup(this.get('autoExpand'), this._resizeCallback);
|
|
this._autoExpand();
|
|
},
|
|
|
|
_onResize() {
|
|
this._autoExpand();
|
|
},
|
|
|
|
_teardownAutoExpand() {
|
|
this.get('resizeDetector').teardown(this.get('autoExpand'), this._resizeCallback);
|
|
}
|
|
});
|