mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-04 08:54:36 +03:00
cb59388c5b
no issue - adds `eslint-plugin-sort-imports-es6-autofix` dependency - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single` - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order - updates all unordered import rules by using `eslint --fix` With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
169 lines
4.3 KiB
JavaScript
169 lines
4.3 KiB
JavaScript
import Component from 'ember-component';
|
|
import run from 'ember-runloop';
|
|
import {
|
|
IMAGE_EXTENSIONS,
|
|
IMAGE_MIME_TYPES
|
|
} from 'ghost-admin/components/gh-image-uploader';
|
|
|
|
const {debounce} = run;
|
|
|
|
export default Component.extend({
|
|
|
|
classNameBindings: [
|
|
'isDraggedOver:-drag-over',
|
|
'isFullScreen:gh-editor-fullscreen',
|
|
'isPreview:gh-editor-preview'
|
|
],
|
|
|
|
// Public attributes
|
|
navIsClosed: false,
|
|
|
|
// Internal attributes
|
|
droppedFiles: null,
|
|
headerClass: '',
|
|
imageExtensions: IMAGE_EXTENSIONS,
|
|
imageMimeTypes: IMAGE_MIME_TYPES,
|
|
isDraggedOver: false,
|
|
isFullScreen: false,
|
|
isSplitScreen: false,
|
|
uploadedImageUrls: null,
|
|
|
|
// Private
|
|
_dragCounter: 0,
|
|
_navIsClosed: false,
|
|
_onResizeHandler: null,
|
|
_viewActionsWidth: 190,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
this._onResizeHandler = (evt) => {
|
|
debounce(this, this._setHeaderClass, evt, 100);
|
|
};
|
|
},
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
window.addEventListener('resize', this._onResizeHandler);
|
|
this._setHeaderClass();
|
|
},
|
|
|
|
didReceiveAttrs() {
|
|
let navIsClosed = this.get('navIsClosed');
|
|
|
|
if (navIsClosed !== this._navIsClosed) {
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
|
}
|
|
|
|
this._navIsClosed = navIsClosed;
|
|
},
|
|
|
|
_setHeaderClass() {
|
|
let $editorTitle = this.$('.gh-editor-title');
|
|
let smallHeaderClass = 'gh-editor-header-small';
|
|
|
|
if (this.get('isSplitScreen')) {
|
|
this.set('headerClass', smallHeaderClass);
|
|
return;
|
|
}
|
|
|
|
if ($editorTitle.length > 0) {
|
|
let boundingRect = $editorTitle[0].getBoundingClientRect();
|
|
let maxRight = window.innerWidth - this._viewActionsWidth;
|
|
|
|
if (boundingRect.right >= maxRight) {
|
|
this.set('headerClass', smallHeaderClass);
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.set('headerClass', '');
|
|
},
|
|
|
|
// dragOver is needed so that drop works
|
|
dragOver(event) {
|
|
if (!event.dataTransfer) {
|
|
return;
|
|
}
|
|
|
|
// this is needed to work around inconsistencies with dropping files
|
|
// from Chrome's downloads bar
|
|
let eA = event.dataTransfer.effectAllowed;
|
|
event.dataTransfer.dropEffect = (eA === 'move' || eA === 'linkMove') ? 'move' : 'copy';
|
|
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
},
|
|
|
|
// dragEnter is needed so that the drag class is correctly removed
|
|
dragEnter(event) {
|
|
if (!event.dataTransfer) {
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
// the counter technique prevents flickering of the drag class when
|
|
// dragging across child elements
|
|
this._dragCounter++;
|
|
|
|
this.set('isDraggedOver', true);
|
|
},
|
|
|
|
dragLeave(event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
this._dragCounter--;
|
|
if (this._dragCounter === 0) {
|
|
this.set('isDraggedOver', false);
|
|
}
|
|
},
|
|
|
|
drop(event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
this._dragCounter = 0;
|
|
this.set('isDraggedOver', false);
|
|
|
|
if (event.dataTransfer.files) {
|
|
this.set('droppedFiles', event.dataTransfer.files);
|
|
}
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super(...arguments);
|
|
window.removeEventListener('resize', this._onResizeHandler);
|
|
},
|
|
|
|
actions: {
|
|
toggleFullScreen(isFullScreen) {
|
|
this.set('isFullScreen', isFullScreen);
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
|
},
|
|
|
|
togglePreview(isPreview) {
|
|
this.set('isPreview', isPreview);
|
|
},
|
|
|
|
toggleSplitScreen(isSplitScreen) {
|
|
this.set('isSplitScreen', isSplitScreen);
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
|
},
|
|
|
|
uploadImages(fileList) {
|
|
this.set('droppedFiles', fileList);
|
|
},
|
|
|
|
uploadComplete(uploads) {
|
|
this.set('uploadedImageUrls', uploads.mapBy('url'));
|
|
this.set('droppedFiles', null);
|
|
},
|
|
|
|
uploadCancelled() {
|
|
this.set('droppedFiles', null);
|
|
}
|
|
}
|
|
});
|