diff --git a/src/api/Editor.js b/src/api/Editor.js index 471ca347c0..58effad893 100644 --- a/src/api/Editor.js +++ b/src/api/Editor.js @@ -28,11 +28,6 @@ export default class Editor extends EventEmitter { super(); this.editing = false; this.openmct = openmct; - document.addEventListener('drop', (event) => { - if (!this.isEditing()) { - this.edit(); - } - }, {capture: true}); } /** diff --git a/src/ui/components/ObjectView.vue b/src/ui/components/ObjectView.vue index cc481f18a2..caf43071fe 100644 --- a/src/ui/components/ObjectView.vue +++ b/src/ui/components/ObjectView.vue @@ -34,7 +34,10 @@ export default { this.currentObject = this.object; this.updateView(); this.$el.addEventListener('dragover', this.onDragOver); - this.$el.addEventListener('drop', this.onDrop); + this.$el.addEventListener('drop', this.addObjectToParent); + this.$el.addEventListener('drop', this.editIfEditable, { + capture: true + }); }, methods: { clear() { @@ -70,22 +73,18 @@ export default { this.viewContainer = document.createElement('div'); this.viewContainer.classList.add('c-object-view','u-contents'); this.$el.append(this.viewContainer); - let provider = this.openmct.objectViews.getByProviderKey(this.viewKey); - + let provider = this.getViewProvider(); if (!provider) { - provider = this.openmct.objectViews.get(this.currentObject)[0]; - if (!provider) { - return; - } + return; } - if (provider.edit && this.showEditView) { if (this.openmct.editor.isEditing()) { this.currentView = provider.edit(this.currentObject); } else { this.currentView = provider.view(this.currentObject, false); } + this.openmct.editor.on('isEditing', this.toggleEditView); this.releaseEditModeHandler = () => this.openmct.editor.off('isEditing', this.toggleEditView); } else { @@ -133,7 +132,7 @@ export default { event.preventDefault(); } }, - onDrop(event) { + addObjectToParent(event) { if (this.hasComposableDomainObject(event)) { let composableDomainObject = this.getComposableDomainObject(event); this.currentObject.composition.push(composableDomainObject.identifier); @@ -142,6 +141,25 @@ export default { event.stopPropagation(); } }, + getViewProvider() { + let provider = this.openmct.objectViews.getByProviderKey(this.viewKey); + + if (!provider) { + provider = this.openmct.objectViews.get(this.currentObject)[0]; + if (!provider) { + return; + } + } + return provider; + }, + editIfEditable(event) { + let provider = this.getViewProvider(); + if (provider && + provider.canEdit(this.currentObject) && + !this.openmct.editor.isEditing()) { + this.openmct.editor.edit(); + } + }, hasComposableDomainObject(event) { return event.dataTransfer.types.includes('openmct/composable-domain-object') },