First row of tests and fixes

This commit is contained in:
2026-03-05 22:50:53 +01:00
parent 12458925a1
commit f28df2ae76
23 changed files with 442 additions and 126 deletions
+43 -1
View File
@@ -30,7 +30,9 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
dragDrop: [{ dragSelector: "[data-drag]", dropSelector: null }],
actions: {
toggleSheet: AwEItemSheet.#onToggleSheet,
editImage: AwEItemSheet.#onEditImage
editImage: AwEItemSheet.#onEditImage,
addTrait: AwEItemSheet.#onAddTrait,
removeTrait: AwEItemSheet.#onRemoveTrait
}
}
@@ -77,6 +79,16 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
_onRender(context, options) {
super._onRender(context, options)
this.#dragDrop.forEach(d => d.bind(this.element))
// Bind Enter key on tag input fields to trigger the addTrait/addSpecialization actions
this.element.querySelectorAll("input.new-tag[data-action]").forEach(input => {
input.addEventListener("keydown", event => {
if (event.key !== "Enter") return
event.preventDefault()
const actionName = input.dataset.action
const handler = this.options.actions?.[actionName]
if (handler) handler.call(this, event, input)
})
})
}
// #region Drag-and-Drop Workflow
@@ -182,4 +194,34 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
}
// #endregion
// #region Array field helpers (traits, specializations)
/**
* Handle adding a tag (trait, specialization) from the input field.
* @param {PointerEvent|KeyboardEvent} event - The initiating event.
* @param {HTMLElement} target - The input element.
*/
static async #onAddTrait(event, target) {
const value = target.value.trim()
if (!value) return
const fieldName = target.dataset.field ?? "system.traits"
const current = foundry.utils.getProperty(this.document, fieldName) ?? []
await this.document.update({ [fieldName]: [...current, value] })
target.value = ""
}
/**
* Handle removing a tag (trait, specialization) from an array field.
* @param {PointerEvent} event - The initiating click event.
* @param {HTMLElement} target - The remove button.
*/
static async #onRemoveTrait(event, target) {
const index = Number(target.dataset.index)
const fieldName = target.dataset.field ?? "system.traits"
const current = [...(foundry.utils.getProperty(this.document, fieldName) ?? [])]
current.splice(index, 1)
await this.document.update({ [fieldName]: current })
}
// #endregion
}