Add the ability to display / edit the description from the item sheet

This commit is contained in:
Oliver-Akins 2025-02-10 23:04:28 -07:00
parent 46a235b603
commit 69db3ca719
13 changed files with 168 additions and 17 deletions

View file

@ -1,5 +1,7 @@
import { deleteItemFromElement, editItemFromElement } from "./utils.mjs";
import { DicePool } from "./DicePool.mjs";
import { RichEditor } from "./RichEditor.mjs";
import { toBoolean } from "../consts.mjs";
/**
* A mixin that takes the class from HandlebarsApplicationMixin and
@ -16,6 +18,7 @@ export function GenericAppMixin(HandlebarsApp) {
roll: this._rollDice,
editItem: (_event, target) => editItemFromElement(target),
deleteItem: (_event, target) => deleteItemFromElement(target),
openRichEditor: this.#openRichEditor,
},
};
@ -57,14 +60,39 @@ export function GenericAppMixin(HandlebarsApp) {
// #region Actions
/** @this {GenericRipCryptApp} */
static async _rollDice(_$e, el) {
const data = el.dataset;
static async _rollDice(_event, target) {
const data = target.dataset;
const diceCount = parseInt(data.diceCount);
const flavor = data.flavor;
const dp = new DicePool({ diceCount, flavor });
dp.render({ force: true });
};
/** @this {GenericRipCryptApp} */
static async #openRichEditor(_event, target) {
const data = target.dataset;
const {
uuid,
path,
collaborative,
compact,
} = data;
if (!uuid || !path) {
console.error(`Rich Editor requires a document uuid and path to edit`);
return;
};
const document = await fromUuid(uuid);
const app = new RichEditor({
document,
path,
collaborative: toBoolean(collaborative),
compact: toBoolean(compact ),
});
app.render({ force: true });
};
// #endregion
};
return GenericRipCryptApp;

View file

@ -20,8 +20,6 @@ export class AllItemSheetV1 extends GenericAppMixin(HandlebarsApplicationMixin(I
window: {
resizable: false,
},
actions: {
},
form: {
submitOnChange: true,
closeOnSubmit: false,
@ -40,7 +38,7 @@ export class AllItemSheetV1 extends GenericAppMixin(HandlebarsApplicationMixin(I
ctx = await super._preparePartContext(partId, ctx, opts);
ctx.item = this.document;
ctx.formFields = this.document.system.getFormFields(ctx);
ctx.formFields = await this.document.system.getFormFields(ctx);
Logger.debug(`Context:`, ctx);
return ctx;

View file

@ -79,11 +79,6 @@ export class RichEditor extends HandlebarsApplicationMixin(DocumentSheetV2) {
path: this.path,
};
console.log({
doc: this.document,
path: this.path,
value: this.document.system.description,
});
const value = getProperty(this.document, this.path);
ctx.enriched = await TextEditor.enrichHTML(value);
ctx.raw = value;