Remade apps handling

This commit is contained in:
WBHarry 2025-07-24 21:42:05 +02:00
parent 967b3ba2ab
commit 7ff7f718ed
7 changed files with 72 additions and 13 deletions

View file

@ -108,6 +108,13 @@ export default function DHApplicationMixin(Base) {
tagifyConfigs: []
};
/**
* Related documents that should cause a rerender of this application when updated.
*/
get relatedDocs() {
return [];
}
/* -------------------------------------------- */
/**@inheritdoc */
@ -118,9 +125,17 @@ export default function DHApplicationMixin(Base) {
/**@inheritdoc */
async _onFirstRender(context, options) {
await super._onFirstRender(context, options);
this.relatedDocs.map(doc => (doc.apps[this.id] = this));
if (!!this.options.contextMenus.length) this._createContextMenus();
}
/** @inheritDoc */
_onClose(options) {
super._onClose(options);
this.relatedDocs.map(doc => delete doc.apps[this.id]);
}
/**@inheritdoc */
async _onRender(context, options) {
await super._onRender(context, options);
@ -511,19 +526,7 @@ export default function DHApplicationMixin(Base) {
*/
static async #editDoc(_event, target) {
const doc = getDocFromElement(target);
if (doc) {
const appId = this.element.id;
doc.apps[appId] = this;
const app = await doc.sheet.render({ force: true });
app.addEventListener(
'close',
() => {
delete doc.apps[appId];
},
{ once: true }
);
return;
}
if (doc) return doc.sheet.render({ force: true });
// TODO: REDO this
const { actionId } = target.closest('[data-action-id]').dataset;