2018-01-31 11:32:27 +03:00
|
|
|
import Component from '@ember/component';
|
2018-02-13 21:00:54 +03:00
|
|
|
import formatMarkdown from 'ghost-admin/utils/format-markdown';
|
2018-01-31 11:32:27 +03:00
|
|
|
import layout from '../templates/components/koenig-card-markdown';
|
2018-02-13 21:00:54 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {htmlSafe} from '@ember/string';
|
|
|
|
import {run} from '@ember/runloop';
|
2018-01-31 11:32:27 +03:00
|
|
|
import {set} from '@ember/object';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
layout,
|
|
|
|
|
2018-02-13 21:00:54 +03:00
|
|
|
// attrs
|
2018-01-31 11:32:27 +03:00
|
|
|
payload: null,
|
2018-02-13 21:00:54 +03:00
|
|
|
isSelected: false,
|
|
|
|
isEditing: false,
|
|
|
|
|
|
|
|
// properties
|
|
|
|
toolbar: null,
|
|
|
|
|
|
|
|
// closure actions
|
2018-01-31 11:32:27 +03:00
|
|
|
saveCard: null,
|
2018-02-13 21:00:54 +03:00
|
|
|
selectCard: null,
|
|
|
|
|
|
|
|
renderedMarkdown: computed('payload.markdown', function () {
|
|
|
|
return htmlSafe(formatMarkdown(this.get('payload.markdown')));
|
|
|
|
}),
|
2018-01-31 11:32:27 +03:00
|
|
|
|
|
|
|
actions: {
|
2018-02-13 21:00:54 +03:00
|
|
|
enterEditMode() {
|
|
|
|
// this action is called before the component is rendered so we
|
|
|
|
// need to wait to ensure that the textarea element is present
|
|
|
|
run.scheduleOnce('afterRender', this, this._focusTextarea);
|
|
|
|
},
|
|
|
|
|
2018-01-31 11:32:27 +03:00
|
|
|
updateMarkdown(markdown) {
|
|
|
|
let payload = this.get('payload');
|
|
|
|
let save = this.get('saveCard');
|
|
|
|
|
|
|
|
set(payload, 'markdown', markdown);
|
|
|
|
|
|
|
|
// update the mobiledoc and stay in edit mode
|
|
|
|
save(payload, false);
|
|
|
|
}
|
2018-02-13 21:00:54 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_focusTextarea() {
|
|
|
|
this.element.querySelector('textarea').focus();
|
2018-01-31 11:32:27 +03:00
|
|
|
}
|
|
|
|
});
|