Item Support #69

Merged
Oliver merged 50 commits from feature/item-support into main 2026-04-15 02:42:54 +00:00
3 changed files with 59 additions and 1 deletions
Showing only changes of commit 4c05171e04 - Show all commits

View file

@ -58,6 +58,7 @@
"confirm-and-close": "Confirm and Close",
"save-and-close": "Save and Close",
"delete": "Delete",
"edit": "Edit",
"resizable": "Resizable",
"not-resizable": "Not Resizable",
"item": {

View file

@ -4,11 +4,12 @@ import { attributeSorter } from "../utils/attributeSort.mjs";
import { config } from "../config.mjs";
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
import { deleteItemFromElement, editItemFromElement } from "./utils.mjs";
const { HandlebarsApplicationMixin } = foundry.applications.api;
const { ActorSheetV2 } = foundry.applications.sheets;
const { getProperty } = foundry.utils;
const { TextEditor } = foundry.applications.ux;
const { ContextMenu, TextEditor } = foundry.applications.ux;
export class PlayerSheet extends
TAFDocumentSheetMixin(
@ -146,6 +147,36 @@ export class PlayerSheet extends
return controls;
};
async _onRender(ctx, options) {
await super._onRender(ctx, options);
new ContextMenu.implementation(
this.element,
`li.item`,
[
{
label: _loc(`taf.misc.edit`),
condition: (el) => {
const itemUuid = el.dataset.itemUuid;
const itemExists = itemUuid != null && itemUuid !== "";
return this.isEditable && itemExists;
},
onClick: editItemFromElement,
},
{
label: _loc(`taf.misc.delete`),
condition: (el) => {
const itemUuid = el.dataset.itemUuid;
const itemExists = itemUuid != null && itemUuid !== "";
return this.isEditable && itemExists;
},
onClick: deleteItemFromElement,
},
],
{ jQuery: false, fixed: true, },
);
};
async close() {
this.#attributeManager?.close();
this.#attributeManager = null;

View file

@ -3,6 +3,32 @@ This file contains utility methods used by Applications in order to be
DRYer
*/
/**
* @param {Event} _event The click event
* @param {HTMLElement} target The element to operate on
*/
export async function editItemFromElement(_event, target) {
const itemEl = target.closest(`[data-item-uuid]`);
if (!itemEl) { return };
const uuid = itemEl.dataset.itemUuid;
if (!uuid) { return };
const item = await fromUuid(uuid);
item.sheet.render({ force: true, orBringToFront: true });
};
/**
* @param {Event} _event The click event
* @param {HTMLElement} target The element to operate on
*/
export async function deleteItemFromElement(_event, target) {
const itemEl = target.closest(`[data-item-uuid]`);
if (!itemEl) { return };
const uuid = itemEl.dataset.itemUuid;
if (!uuid) { return };
const item = await fromUuid(uuid);
item.deleteDialog();
};
/**
* Updates a document using the UUID, this is most useful for editing
* documents from a sheet of another document (e.g. an Item embedded