Bug/153 undeploy jquery (#270)

* REFACTOR: remove unnecessary handlebars

* REFACTOR: add jsdoc to DHContextMenu class

* remove jquery cont ChatLog class

* FIX error on create weapons

* REFACTOR:make more legible  _preCreate

---------

Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com>
This commit is contained in:
joaquinpereyra98 2025-07-05 15:10:49 -03:00 committed by GitHub
parent 41181f19f1
commit eac58c1386
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 154 additions and 135 deletions

View file

@ -124,7 +124,7 @@ Hooks.once('init', () => {
CONFIG.Token.rulerClass = placeables.DhTokenRuler; CONFIG.Token.rulerClass = placeables.DhTokenRuler;
CONFIG.ui.resources = applications.ui.DhFearTracker; CONFIG.ui.resources = applications.ui.DhFearTracker;
CONFIG.ux.ContextMenu = applications.ux.ContextMenu; CONFIG.ux.ContextMenu = applications.ux.DHContextMenu;
CONFIG.ux.TooltipManager = documents.DhTooltipManager; CONFIG.ux.TooltipManager = documents.DhTooltipManager;
game.socket.on(`system.${SYSTEM.id}`, socketRegistration.handleSocketEvent); game.socket.on(`system.${SYSTEM.id}`, socketRegistration.handleSocketEvent);

View file

@ -50,13 +50,13 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
element.addEventListener('mouseenter', this.hoverAdvantage) element.addEventListener('mouseenter', this.hoverAdvantage)
); );
html.querySelectorAll('.advantage').forEach(element => html.querySelectorAll('.advantage').forEach(element =>
element.addEventListener('click', event => this.selectAdvantage.bind(this)(event, data.message)) element.addEventListener('click', event => this.selectAdvantage.call(this, event, data.message))
); );
html.querySelectorAll('.ability-use-button').forEach(element => html.querySelectorAll('.ability-use-button').forEach(element =>
element.addEventListener('click', event => this.abilityUseButton.bind(this)(event, data.message)) element.addEventListener('click', event => this.abilityUseButton.call(this, event, data.message))
); );
html.querySelectorAll('.action-use-button').forEach(element => html.querySelectorAll('.action-use-button').forEach(element =>
element.addEventListener('click', event => this.actionUseButton.bind(this)(event, data.message)) element.addEventListener('click', event => this.actionUseButton.call(this, event, data.message))
); );
}; };
@ -156,8 +156,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
getTargetList = (event, message) => { getTargetList = (event, message) => {
const targetSelection = event.target const targetSelection = event.target
.closest('.message-content') .closest('.message-content')
.querySelector('.button-target-selection.target-selected'), .querySelector('.button-target-selection.target-selected'),
isHit = Boolean(targetSelection.dataset.targetHit); isHit = Boolean(targetSelection.dataset.targetHit);
return { return {
isHit, isHit,
@ -229,24 +229,54 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
} }
}; };
onToggleTargets = async event => { /**
* Toggle visibility of target containers.
* @param {MouseEvent} event
*/
onToggleTargets(event) {
event.stopPropagation(); event.stopPropagation();
$($(event.currentTarget).parent()).find('.target-container').toggleClass('hidden'); event.currentTarget.parentElement
}; ?.querySelectorAll('.target-container')
.forEach(el => el.classList.toggle('hidden'));
}
hoverAdvantage = event => { /**
$(event.currentTarget).siblings('.advantage').toggleClass('unused'); * Highlight advantage icons on hover.
}; * @param {MouseEvent} event
*/
hoverAdvantage(event) {
const parent = event.currentTarget.parentElement;
if (!parent) return;
selectAdvantage = async (event, message) => { parent.querySelectorAll('.advantage').forEach(el => {
if (el !== event.currentTarget) {
el.classList.toggle('unused');
}
});
}
/**
* Handle selecting an advantage and disable further selection.
* @param {MouseEvent} event
* @param {object} message
*/
async selectAdvantage(event, message) {
event.stopPropagation(); event.stopPropagation();
const updateMessage = game.messages.get(message._id); const updateMessage = game.messages.get(message._id);
await updateMessage.update({ system: { advantageSelected: event.currentTarget.id === 'hope' ? 1 : 2 } }); await updateMessage?.update({
system: { advantageSelected: event.currentTarget.id === 'hope' ? 1 : 2 }
});
const parent = event.currentTarget.parentElement;
if (!parent) return;
parent.querySelectorAll('.advantage').forEach(el => {
el.replaceWith(el.cloneNode(true));
});
}
$(event.currentTarget).siblings('.advantage').off('click');
$(event.currentTarget).off('click');
};
abilityUseButton = async (event, message) => { abilityUseButton = async (event, message) => {
event.stopPropagation(); event.stopPropagation();

View file

@ -1,2 +1,2 @@
export { default as FilterMenu } from './filter-menu.mjs'; export { default as FilterMenu } from './filter-menu.mjs';
export { default as ContextMenu } from './contextMenu.mjs'; export { default as DHContextMenu } from './contextMenu.mjs';

View file

@ -1,4 +1,63 @@
export default class DhContextMenu extends foundry.applications.ux.ContextMenu.implementation { /**
* @typedef ContextMenuEntry
* @property {string} name The context menu label. Can be localized.
* @property {string} [icon] A string containing an HTML icon element for the menu item.
* @property {string} [classes] Additional CSS classes to apply to this menu item.
* @property {string} [group] An identifier for a group this entry belongs to.
* @property {ContextMenuJQueryCallback} callback The function to call when the menu item is clicked.
* @property {ContextMenuCondition|boolean} [condition] A function to call or boolean value to determine if this entry
* appears in the menu.
*/
/**
* @callback ContextMenuCondition
* @param {jQuery|HTMLElement} html The element of the context menu entry.
* @returns {boolean} Whether the entry should be rendered in the context menu.
*/
/**
* @callback ContextMenuCallback
* @param {HTMLElement} target The element that the context menu has been triggered for.
* @returns {unknown}
*/
/**
* @callback ContextMenuJQueryCallback
* @param {HTMLElement|jQuery} target The element that the context menu has been triggered for. Will
* either be a jQuery object or an HTMLElement instance, depending
* on how the ContextMenu was configured.
* @returns {unknown}
*/
/**
* @typedef ContextMenuOptions
* @property {string} [eventName="contextmenu"] Optionally override the triggering event which can spawn the menu. If
* the menu is using fixed positioning, this event must be a MouseEvent.
* @property {ContextMenuCallback} [onOpen] A function to call when the context menu is opened.
* @property {ContextMenuCallback} [onClose] A function to call when the context menu is closed.
* @property {boolean} [fixed=false] If true, the context menu is given a fixed position rather than being
* injected into the target.
* @property {boolean} [jQuery=true] If true, callbacks will be passed jQuery objects instead of HTMLElement
* instances.
*/
/**
* @typedef ContextMenuRenderOptions
* @property {Event} [event] The event that triggered the context menu opening.
* @property {boolean} [animate=true] Animate the context menu opening.
*/
/**
* A subclass of ContextMenu.
* @extends {foundry.applications.ux.ContextMenu}
*/
export default class DHContextMenu extends foundry.applications.ux.ContextMenu {
/**
* @param {HTMLElement|jQuery} container - The HTML element that contains the context menu targets.
* @param {string} selector - A CSS selector which activates the context menu.
* @param {ContextMenuEntry[]} menuItems - An Array of entries to display in the menu
* @param {ContextMenuOptions} [options] - Additional options to configure the context menu.
*/
constructor(container, selector, menuItems, options) { constructor(container, selector, menuItems, options) {
super(container, selector, menuItems, options); super(container, selector, menuItems, options);
@ -6,12 +65,21 @@ export default class DhContextMenu extends foundry.applications.ux.ContextMenu.i
this.#jQuery = options.jQuery; this.#jQuery = options.jQuery;
} }
/**
* Whether to pass jQuery objects or HTMLElement instances to callback.
* @type {boolean}
*/
#jQuery; #jQuery;
/**@inheritdoc */
activateListeners(menu) { activateListeners(menu) {
menu.addEventListener('click', this.#onClickItem.bind(this)); menu.addEventListener('click', this.#onClickItem.bind(this));
} }
/**
* Handle click events on context menu items.
* @param {PointerEvent} event The click event
*/
#onClickItem(event) { #onClickItem(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -22,6 +90,12 @@ export default class DhContextMenu extends foundry.applications.ux.ContextMenu.i
this.close(); this.close();
} }
/* -------------------------------------------- */
/**
* Trigger a context menu event in response to a normal click on a additional options button.
* @param {PointerEvent} event
*/
static triggerContextMenu(event) { static triggerContextMenu(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View file

@ -197,10 +197,12 @@ export default class FilterMenu extends foundry.applications.ux.ContextMenu {
} }
})); }));
const sort = arr => game.i18n.sortObjects(arr, 'name');
return [ return [
...game.i18n.sortObjects(typesFilters, 'name'), ...sort(typesFilters, 'name'),
...game.i18n.sortObjects(burdenFilter, 'name'), ...sort(burdenFilter, 'name'),
...game.i18n.sortObjects(damageTypeFilter, 'name') ...sort(damageTypeFilter, 'name')
]; ];
} }

View file

@ -1,4 +1,4 @@
// import { actionsTypes } from '../action/_module.mjs'; import { actionsTypes } from '../action/_module.mjs';
/** /**
* Describes metadata about the item data model type * Describes metadata about the item data model type
@ -55,24 +55,28 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
return data; return data;
} }
/**@inheritdoc */
async _preCreate(data, options, user) { async _preCreate(data, options, user) {
// Skip if no initial action is required or actions already exist
if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return; if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
const actionType = {
weapon: 'attack' const metadataType = this.constructor.metadata.type;
}[this.constructor.metadata.type], const actionType = { weapon: "attack" }[metadataType];
cls = game.system.api.models.actionsTypes[actionType], const ActionClass = actionsTypes[actionType];
// cls = actionsTypes.attack,
action = new cls( const action = new ActionClass(
{ {
_id: foundry.utils.randomID(), _id: foundry.utils.randomID(),
type: actionType, type: actionType,
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name), name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.parent) ...ActionClass.getSourceConfig(this.parent)
}, },
{ {
parent: this.parent parent: this.parent
} }
); );
this.updateSource({ actions: [action] }); this.updateSource({ actions: [action] });
} }
} }

View file

@ -7,49 +7,11 @@ export default class RegisterHandlebarsHelpers {
join: this.join, join: this.join,
add: this.add, add: this.add,
subtract: this.subtract, subtract: this.subtract,
objectSelector: this.objectSelector,
includes: this.includes, includes: this.includes,
debug: this.debug,
signedNumber: this.signedNumber,
length: this.length,
switch: this.switch,
case: this.case, case: this.case,
eq: this.eq,
ne: this.ne,
lt: this.lt,
gt: this.gt,
lte: this.lte,
gte: this.gte,
and: this.and,
or: this.or
}); });
} }
static eq(v1, v2) {
return v1 === v2;
}
static ne(v1, v2) {
return v1 !== v2;
}
static lt(v1, v2) {
return v1 < v2;
}
static gt(v1, v2) {
return v1 > v2;
}
static lte(v1, v2) {
return v1 <= v2;
}
static gte(v1, v2) {
return v1 >= v2;
}
static and() {
return Array.prototype.every.call(arguments, Boolean);
}
static or() {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
}
static times(nr, block) { static times(nr, block) {
var accum = ''; var accum = '';
for (var i = 0; i < nr; ++i) accum += block.fn(i); for (var i = 0; i < nr; ++i) accum += block.fn(i);
@ -72,59 +34,11 @@ export default class RegisterHandlebarsHelpers {
return (Number.isNaN(aNum) ? 0 : aNum) - (Number.isNaN(bNum) ? 0 : bNum); return (Number.isNaN(aNum) ? 0 : aNum) - (Number.isNaN(bNum) ? 0 : bNum);
} }
static objectSelector(options) {
let { title, values, titleFontSize, ids, style } = options.hash;
const titleLength = getWidthOfText(title, titleFontSize, true, true);
const margins = 12;
const buttons = options.fn();
const nrButtons = Math.max($(buttons).length - 1, 1);
const iconWidth = 26;
const texts = values
.reduce((acc, x, index) => {
if (x) {
acc.push(
`<span class="object-select-item" data-action="viewObject" data-value="${ids[index]}">${x}</span>`
);
}
return acc;
}, [])
.join(' ');
const html = `<div ${style ? 'style="' + style + '"' : ''}">
<div class="object-select-display iconbar">
<span class="object-select-title">${title}</span>
<div class="object-select-text" style="padding-left: ${titleLength + margins}px; padding-right: ${nrButtons * iconWidth}px;">
${texts}
</div>
${buttons}
</div>
</div>
`;
return new Handlebars.SafeString(html);
}
static includes(list, item) { static includes(list, item) {
return list.includes(item); return list.includes(item);
} }
static signedNumber(number) {
return number >= 0 ? `+${number}` : number;
}
static length(obj) {
return Object.keys(obj).length;
}
static switch(value, options) {
this.switch_value = value;
this.switch_break = false;
return options.fn(this);
}
static case(value, options) { static case(value, options) {
if (value == this.switch_value) { if (value == this.switch_value) {
@ -132,9 +46,4 @@ export default class RegisterHandlebarsHelpers {
return options.fn(this); return options.fn(this);
} }
} }
static debug(a) {
console.log(a);
return a;
}
} }

View file

@ -74,7 +74,7 @@
{{#each experience.values as |experience id|}} {{#each experience.values as |experience id|}}
<div class="experience-container"> <div class="experience-container">
<input class="experience-description" type="text" name="{{concat "experiences." id ".description" }}" value="{{experience.description}}" placeholder="{{localize "DAGGERHEART.CharacterCreation.NewExperience"}}" /> <input class="experience-description" type="text" name="{{concat "experiences." id ".description" }}" value="{{experience.description}}" placeholder="{{localize "DAGGERHEART.CharacterCreation.NewExperience"}}" />
<div class="experience-value">{{signedNumber this.value}}</div> <div class="experience-value">{{numberFormat this.value sign=true}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>

View file

@ -12,7 +12,7 @@
<div class="achievement-experience-card"> <div class="achievement-experience-card">
<div class="flexrow"> <div class="flexrow">
<input type="text" name="{{concat "levelup.levels." this.level ".achievements.experiences." this.key ".name"}}" value="{{this.name}}" placeholder="{{localize "DAGGERHEART.Application.LevelUp.summary.experiencePlaceholder"}}" /> <input type="text" name="{{concat "levelup.levels." this.level ".achievements.experiences." this.key ".name"}}" value="{{this.name}}" placeholder="{{localize "DAGGERHEART.Application.LevelUp.summary.experiencePlaceholder"}}" />
<div class="flex0">{{signedNumber this.modifier}}</div> <div class="flex0">{{numberFormat this.modifier sign=true}}</div>
</div> </div>
<div class="achievement-experience-marker"> <div class="achievement-experience-marker">
{{#if this.name}}<i class="fa-solid fa-check"></i>{{/if}} {{#if this.name}}<i class="fa-solid fa-check"></i>{{/if}}

View file

@ -48,7 +48,7 @@
<h5>{{localize "DAGGERHEART.Application.LevelUp.summary.newExperiences"}}</h5> <h5>{{localize "DAGGERHEART.Application.LevelUp.summary.newExperiences"}}</h5>
<div class="summary-selection-container"> <div class="summary-selection-container">
{{#each this.achievements.experiences.values}} {{#each this.achievements.experiences.values}}
<div class="summary-selection">{{this.name}} {{signedNumber this.modifier}}</div> <div class="summary-selection">{{this.name}} {{numberFormat this.modifier sign=true}}</div>
{{/each}} {{/each}}
</div> </div>
</div> </div>
@ -125,7 +125,7 @@
<h5>{{localize "DAGGERHEART.Application.LevelUp.summary.experienceIncreases"}}</h5> <h5>{{localize "DAGGERHEART.Application.LevelUp.summary.experienceIncreases"}}</h5>
<div class="summary-selection-container"> <div class="summary-selection-container">
{{#each this.advancements.experiences}} {{#each this.advancements.experiences}}
<div class="summary-selection">{{this.name}} {{signedNumber this.modifier}}</div> <div class="summary-selection">{{this.name}} {{numberFormat this.modifier sign=true}}</div>
{{/each}} {{/each}}
</div> </div>
</div> </div>

View file

@ -17,7 +17,7 @@
{{#each source.system.experiences as |experience key|}} {{#each source.system.experiences as |experience key|}}
<div class="flexrow"> <div class="flexrow">
<input type="text" name="{{concat "system.experiences." key ".name"}}" value="{{experience.name}}" /> <input type="text" name="{{concat "system.experiences." key ".name"}}" value="{{experience.name}}" />
<div>{{signedNumber experience.value}}</div> <div>{{numberFormat experience.value sign=true}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>