mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
8c046740f0
refs https://github.com/TryGhost/Team/issues/2906 Adds a way to select posts using CMD, shift and CMD+A. And adds a placeholder context menu. Behind the making it rain feature flag.
78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import SelectionList from '../utils/selection-list';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class GhContextMenu extends Component {
|
|
@service dropdown;
|
|
|
|
@tracked isOpen = false;
|
|
@tracked left = 0;
|
|
@tracked top = 0;
|
|
@tracked selectionList = new SelectionList();
|
|
|
|
get name() {
|
|
return this.args.name;
|
|
}
|
|
|
|
get style() {
|
|
return `left: ${this.left}px; top: ${this.top}px;`;
|
|
}
|
|
|
|
@action
|
|
setup() {
|
|
const dropdownService = this.dropdown;
|
|
dropdownService.on('close', this, this.close);
|
|
dropdownService.on('toggle', this, this.toggle);
|
|
}
|
|
|
|
willDestroy() {
|
|
super.willDestroy(...arguments);
|
|
const dropdownService = this.dropdown;
|
|
dropdownService.off('close', this, this.close);
|
|
dropdownService.off('toggle', this, this.toggle);
|
|
}
|
|
|
|
@action
|
|
open() {
|
|
this.isOpen = true;
|
|
}
|
|
|
|
@action
|
|
close() {
|
|
this.isOpen = false;
|
|
}
|
|
|
|
@action
|
|
onContextMenuOutside(event) {
|
|
this.close();
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
|
|
// Called by the dropdown service when the context menu should open
|
|
@action
|
|
toggle(options) {
|
|
const targetDropdownName = options.target;
|
|
if (this.name === targetDropdownName) {
|
|
if (options.left !== undefined) {
|
|
this.left = options.left;
|
|
this.top = options.top;
|
|
}
|
|
if (options.selectionList) {
|
|
this.selectionList = options.selectionList;
|
|
}
|
|
|
|
this.open();
|
|
} else if (this.isOpen) {
|
|
this.close();
|
|
}
|
|
}
|
|
|
|
@action
|
|
stopClicks(event) {
|
|
event.stopPropagation();
|
|
}
|
|
}
|