mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
09435ecf76
no issue Keeps component JS backing files and template files in the same directory which avoids hunting across directories when working with components. Also lets you see all components when looking at one directory, whereas previously template-only or js-only components may not have been obvious without looking at both directories. - ran [codemod](https://github.com/ember-codemods/ember-component-template-colocation-migrator/) for app-level components - manually moved in-repo-addon component templates in `lib/koenig-editor` - removed all explicit `layout` imports as JS/template associations are now made at build-time removing the need for them - updated `.embercli` to default to new flat component structure
87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
import Component from '@ember/component';
|
|
import {computed} from '@ember/object';
|
|
import {utils as ghostHelperUtils} from '@tryghost/helpers';
|
|
import {isBlank} from '@ember/utils';
|
|
import {run} from '@ember/runloop';
|
|
import {set} from '@ember/object';
|
|
|
|
const {countWords, countImages} = ghostHelperUtils;
|
|
|
|
export default Component.extend({
|
|
// attrs
|
|
payload: null,
|
|
isSelected: false,
|
|
isEditing: false,
|
|
headerOffset: 0,
|
|
|
|
// closure actions
|
|
selectCard() {},
|
|
deselectCard() {},
|
|
editCard() {},
|
|
saveCard() {},
|
|
deleteCard() {},
|
|
registerComponent() {},
|
|
|
|
counts: computed('payload.html', function () {
|
|
return {
|
|
wordCount: countWords(this.payload.html),
|
|
imageCount: countImages(this.payload.html)
|
|
};
|
|
}),
|
|
|
|
toolbar: computed('isEditing', function () {
|
|
if (this.isEditing) {
|
|
return false;
|
|
}
|
|
|
|
return {
|
|
items: [{
|
|
buttonClass: 'fw4 flex items-center white',
|
|
icon: 'koenig/kg-edit',
|
|
iconClass: 'fill-white',
|
|
title: 'Edit',
|
|
text: '',
|
|
action: run.bind(this, this.editCard)
|
|
}]
|
|
};
|
|
}),
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
let payload = this.payload || {};
|
|
|
|
// CodeMirror errors on a `null` or `undefined` value
|
|
if (!payload.html) {
|
|
set(payload, 'html', '');
|
|
}
|
|
|
|
this.set('payload', payload);
|
|
|
|
this.registerComponent(this);
|
|
},
|
|
|
|
actions: {
|
|
updateHtml(html) {
|
|
this._updatePayloadAttr('html', html);
|
|
},
|
|
|
|
leaveEditMode() {
|
|
if (isBlank(this.payload.html)) {
|
|
// afterRender is required to avoid double modification of `isSelected`
|
|
// TODO: see if there's a way to avoid afterRender
|
|
run.scheduleOnce('afterRender', this, this.deleteCard);
|
|
}
|
|
}
|
|
},
|
|
|
|
_updatePayloadAttr(attr, value) {
|
|
let payload = this.payload;
|
|
let save = this.saveCard;
|
|
|
|
set(payload, attr, value);
|
|
|
|
// update the mobiledoc and stay in edit mode
|
|
save(payload, false);
|
|
}
|
|
});
|