Add foundation for being able to create embedded items without requiring going through the sidebar

This commit is contained in:
Oliver-Akins 2025-02-20 21:30:26 -07:00
parent 4f138202ce
commit 5eedea5001
2 changed files with 24 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import { deleteItemFromElement, editItemFromElement } from "./utils.mjs"; import { createItemFromElement, deleteItemFromElement, editItemFromElement } from "./utils.mjs";
import { DicePool } from "./DicePool.mjs"; import { DicePool } from "./DicePool.mjs";
import { RichEditor } from "./RichEditor.mjs"; import { RichEditor } from "./RichEditor.mjs";
import { toBoolean } from "../consts.mjs"; import { toBoolean } from "../consts.mjs";
@ -16,6 +16,10 @@ export function GenericAppMixin(HandlebarsApp) {
], ],
actions: { actions: {
roll: this.#rollDice, roll: this.#rollDice,
createItem: (_event, target) => {
const parent = this.document;
createItemFromElement(target, { parent });
},
editItem: (_event, target) => editItemFromElement(target), editItem: (_event, target) => editItemFromElement(target),
deleteItem: (_event, target) => deleteItemFromElement(target), deleteItem: (_event, target) => deleteItemFromElement(target),
openRichEditor: this.#openRichEditor, openRichEditor: this.#openRichEditor,

View file

@ -3,7 +3,24 @@ This file contains utilities used by Applications in order to be DRYer
*/ */
/** /**
* @param {HTMLElement} target The element that gets * @param {HTMLElement} target The element to operate on
*/
export async function createItemFromElement(target, { parent } = {}) {
const data = target.dataset;
const types = data.itemTypes?.split(`,`);
const type = data.defaultItemType;
await Item.createDialog(
{ type },
{ parent },
{
types,
folders: [],
},
);
};
/**
* @param {HTMLElement} target The element to operate on
*/ */
export async function editItemFromElement(target) { export async function editItemFromElement(target) {
const itemEl = target.closest(`[data-item-id]`); const itemEl = target.closest(`[data-item-id]`);
@ -15,7 +32,7 @@ export async function editItemFromElement(target) {
}; };
/** /**
* @param {HTMLElement} target The element that gets * @param {HTMLElement} target The element to operate on
*/ */
export async function deleteItemFromElement(target) { export async function deleteItemFromElement(target) {
const itemEl = target.closest(`[data-item-id]`); const itemEl = target.closest(`[data-item-id]`);