diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 8c96e0bd..129914df 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -74,6 +74,15 @@ export default function DHApplicationMixin(Base) { class DHSheetV2 extends HandlebarsApplicationMixin(Base) { #nonHeaderAttribution = ['environment', 'ancestry', 'community', 'domainCard']; + /** + * @param {DHSheetV2Configuration} [options={}] + */ + constructor(options = {}) { + super(options); + + this._setupDragDrop(); + } + /** * The default options for the sheet. * @type {DHSheetV2Configuration} @@ -165,7 +174,9 @@ export default function DHApplicationMixin(Base) { /**@inheritdoc */ _attachPartListeners(partId, htmlElement, options) { super._attachPartListeners(partId, htmlElement, options); - // this._dragDrop.forEach(d => d.bind(htmlElement)); + + /* Core dragDrop from ActorDocument is always only 1. Possible we could refactor our own */ + if (Array.isArray(this._dragDrop)) this._dragDrop.forEach(d => d.bind(htmlElement)); // Handle delta inputs for (const deltaInput of htmlElement.querySelectorAll('input[data-allow-delta]')) { @@ -338,6 +349,26 @@ export default function DHApplicationMixin(Base) { /* Drag and Drop */ /* -------------------------------------------- */ + /** + * Creates drag-drop handlers from the configured options. + * @returns {foundry.applications.ux.DragDrop[]} + * @private + */ + _setupDragDrop() { + if (this._dragDrop) { + this._dragDrop.callbacks.dragStart = this._onDragStart; + this._dragDrop.callback.drop = this._onDrop; + } else { + this._dragDrop = this.options.dragDrop.map(d => { + d.callbacks = { + dragstart: this._onDragStart.bind(this), + drop: this._onDrop.bind(this) + }; + return new foundry.applications.ux.DragDrop.implementation(d); + }); + } + } + /** * Handle dragStart event. * @param {DragEvent} event