Have the PopoverManager call a hook to get additional options for the popover Application
This commit is contained in:
parent
e8fdf6e952
commit
69bf712eca
2 changed files with 23 additions and 8 deletions
|
|
@ -44,12 +44,12 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
||||||
// #region Lifecycle
|
// #region Lifecycle
|
||||||
async _onFirstRender(context, options) {
|
async _onFirstRender(context, options) {
|
||||||
await super._onFirstRender(context, options);
|
await super._onFirstRender(context, options);
|
||||||
HeroSkillsCardV1._createPopoverListeners.bind(this)();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async _onRender(context, options) {
|
async _onRender(context, options) {
|
||||||
await super._onRender(context, options);
|
await super._onRender(context, options);
|
||||||
HeroSkillsCardV1._onRender.bind(this)(context, options);
|
HeroSkillsCardV1._onRender.bind(this)(context, options);
|
||||||
|
HeroSkillsCardV1._createPopoverListeners.bind(this)();
|
||||||
};
|
};
|
||||||
|
|
||||||
static async _onRender(_context, options) {
|
static async _onRender(_context, options) {
|
||||||
|
|
@ -84,13 +84,20 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
||||||
|
|
||||||
/** @type {Map<string, PopoverEventManager>} */
|
/** @type {Map<string, PopoverEventManager>} */
|
||||||
#popoverManagers = new Map();
|
#popoverManagers = new Map();
|
||||||
|
/** @type {Map<number, string>} */
|
||||||
|
#hookIDs = new Map();
|
||||||
/** @this {HeroSkillsCardV1} */
|
/** @this {HeroSkillsCardV1} */
|
||||||
static async _createPopoverListeners() {
|
static async _createPopoverListeners() {
|
||||||
const ammoInfoIcon = this.element.querySelector(`.ammo-info-icon`);
|
const ammoInfoIcon = this.element.querySelector(`.ammo-info-icon`);
|
||||||
|
|
||||||
this.#popoverManagers.set(
|
this.#popoverManagers.set(
|
||||||
`.ammo-info-icon`,
|
`.ammo-info-icon`,
|
||||||
new PopoverEventManager(ammoInfoIcon, AmmoTracker, { lockable: true }),
|
new PopoverEventManager(ammoInfoIcon, AmmoTracker),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.#hookIDs.set(Hooks.on(`get${AmmoTracker.name}Options`, (opts) => {
|
||||||
|
opts.ammo = this.actor.itemTypes.ammo;
|
||||||
|
}), `get${AmmoTracker.name}Options`);
|
||||||
};
|
};
|
||||||
|
|
||||||
async _preparePartContext(partId, ctx, opts) {
|
async _preparePartContext(partId, ctx, opts) {
|
||||||
|
|
@ -193,6 +200,9 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
||||||
manager.destroy();
|
manager.destroy();
|
||||||
};
|
};
|
||||||
this.#popoverManagers.clear();
|
this.#popoverManagers.clear();
|
||||||
|
for (const [id, hook] of this.#hookIDs.entries()) {
|
||||||
|
Hooks.off(hook, id);
|
||||||
|
}
|
||||||
super._tearDown(options);
|
super._tearDown(options);
|
||||||
};
|
};
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { getTooltipDelay } from "../consts.mjs";
|
import { getTooltipDelay } from "../consts.mjs";
|
||||||
import { Logger } from "./Logger.mjs";
|
|
||||||
|
|
||||||
export class PopoverEventManager {
|
export class PopoverEventManager {
|
||||||
#options;
|
#options;
|
||||||
|
|
@ -64,16 +63,22 @@ export class PopoverEventManager {
|
||||||
#frameless;
|
#frameless;
|
||||||
#framed;
|
#framed;
|
||||||
|
|
||||||
|
#construct(options) {
|
||||||
|
const valid = Hooks.call(`get${this.#class.name}Options`, options);
|
||||||
|
if (!valid) { return };
|
||||||
|
return new this.#class(options);
|
||||||
|
};
|
||||||
|
|
||||||
#clickHandler() {
|
#clickHandler() {
|
||||||
// Cleanup for the frameless lifecycle
|
// Cleanup for the frameless lifecycle
|
||||||
this.stopOpen();
|
this.stopOpen();
|
||||||
|
this.stopClose();
|
||||||
this.#frameless?.close({ force: true });
|
this.#frameless?.close({ force: true });
|
||||||
|
|
||||||
if (!this.#framed) {
|
if (!this.#framed) {
|
||||||
const app = new this.#class({ popover: { ...this.#options, framed: true } });
|
this.#framed = this.#construct({ popover: { ...this.#options, framed: true } });
|
||||||
this.#framed = app;
|
|
||||||
}
|
}
|
||||||
this.#framed.render({ force: true });
|
this.#framed?.render({ force: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
#pointerEnterHandler(event) {
|
#pointerEnterHandler(event) {
|
||||||
|
|
@ -104,14 +109,14 @@ export class PopoverEventManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#frameless = new this.#class({
|
this.#frameless = this.#construct({
|
||||||
popover: {
|
popover: {
|
||||||
...this.#options,
|
...this.#options,
|
||||||
framed: false,
|
framed: false,
|
||||||
x, y,
|
x, y,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.#frameless.render({ force: true });
|
this.#frameless?.render({ force: true });
|
||||||
},
|
},
|
||||||
getTooltipDelay(),
|
getTooltipDelay(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue