fix: replace {{editor}} handlebars helper with <prose-mirror> custom element

This commit is contained in:
Alexander Minges 2025-07-13 13:38:29 +02:00
parent 093c94961d
commit 3284b132b4
Signed by: Athemis
GPG key ID: 31FBDEF92DDB162B
2 changed files with 30 additions and 12 deletions

View file

@ -34,6 +34,8 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
}, },
}; };
static TABS = {}; static TABS = {};
constructor(options = {}) { constructor(options = {}) {
@ -95,17 +97,11 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
} }
} }
// Enrich description HTML content // Provide raw description content to editor (let editor handle enrichment)
if (context.data.system.description) { // Don't pre-enrich the HTML as it interferes with editor activation
context.data.system.description = await TextEditor.enrichHTML( // The editor will handle enrichment internally
context.data.system.description,
{
async: true,
relativeTo: this.item,
}
);
}
console.log("DS4ItemSheet: _prepareContext completed for item:", this.item.name);
return context; return context;
} }
@ -244,22 +240,39 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
} }
} }
/** @override */ /** @override */
async _onRender(context, options) { async _onRender(context, options) {
console.log("DS4ItemSheet: _onRender called for item:", this.item.name);
await super._onRender(context, options); await super._onRender(context, options);
console.log("DS4ItemSheet: About to initialize tabs");
// Initialize first tab as active // Initialize first tab as active
this._initializeTabs(); this._initializeTabs();
console.log("DS4ItemSheet: Tabs initialized");
console.log("DS4ItemSheet: _onRender completed, <prose-mirror> elements handle editor activation automatically");
}
/** @override */
async _onClose(options) {
console.log("DS4ItemSheet: _onClose called");
await super._onClose(options);
} }
/** /**
* Initialize tab state - show first tab, hide others * Initialize tab state - show first tab, hide others
*/ */
_initializeTabs() { _initializeTabs() {
console.log("DS4ItemSheet: _initializeTabs called");
const nav = this.element.querySelector(".ds4-sheet-tab-nav"); const nav = this.element.querySelector(".ds4-sheet-tab-nav");
const sheet = this.element.querySelector(".ds4-sheet-body"); const sheet = this.element.querySelector(".ds4-sheet-body");
if (!nav || !sheet) { if (!nav || !sheet) {
console.warn("DS4ItemSheet: Could not find nav or sheet elements");
return; return;
} }
@ -267,6 +280,8 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
const navItems = nav.querySelectorAll(".ds4-sheet-tab-nav__item"); const navItems = nav.querySelectorAll(".ds4-sheet-tab-nav__item");
const tabContents = sheet.querySelectorAll(".ds4-sheet-tab"); const tabContents = sheet.querySelectorAll(".ds4-sheet-tab");
console.log("DS4ItemSheet: Found", navItems.length, "nav items and", tabContents.length, "tab contents");
// Remove active class from all items first // Remove active class from all items first
navItems.forEach(item => item.classList.remove("active")); navItems.forEach(item => item.classList.remove("active"));
tabContents.forEach(content => content.classList.remove("active")); tabContents.forEach(content => content.classList.remove("active"));
@ -281,6 +296,8 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
targetTab = targetNavItem?.dataset.tab; targetTab = targetNavItem?.dataset.tab;
} }
console.log("DS4ItemSheet: Setting active tab to:", targetTab);
// Set target tab navigation as active // Set target tab navigation as active
if (targetNavItem && targetTab) { if (targetNavItem && targetTab) {
targetNavItem.classList.add("active"); targetNavItem.classList.add("active");
@ -289,7 +306,9 @@ export class DS4ItemSheet extends foundry.applications.sheets.ItemSheetV2 {
const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${targetTab}"]`); const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${targetTab}"]`);
if (activeTabContent) { if (activeTabContent) {
activeTabContent.classList.add("active"); activeTabContent.classList.add("active");
console.log("DS4ItemSheet: Tab content activated:", activeTabContent);
} }
} }
console.log("DS4ItemSheet: _initializeTabs completed");
} }
} }

View file

@ -5,6 +5,5 @@ SPDX-License-Identifier: MIT
--}} --}}
<div class="ds4-sheet-tab tab description" data-group="primary" data-tab="description"> <div class="ds4-sheet-tab tab description" data-group="primary" data-tab="description">
{{editor data.system.description target="system.description" button=true owner=owner <prose-mirror name="system.description" toggled="{{editable}}" value="{{data.system.description}}"></prose-mirror>
editable=editable engine="prosemirror"}}
</div> </div>