Skip to content

Commit

Permalink
[#2678] Fix "Reveal" button in secret blocks in multi-editor
Browse files Browse the repository at this point in the history
Fixes the issues with reveal buttons for secret blocks for items
and actors that use multiple description editors. This required
overriding `_getSecretContent` and `_updateSecret` to look for
`data-target` in addition to `data-edit`. The locking code was
also modified to avoid disabling the secret button when the sheets
are in play mode.

There is a still a bug with the PC sheet and the item sheets with
only a single description (like classes), which don't retain the
secret state if the play/edit toggle is changed immediately after
changing the secret state. This appears to be because when it
submits `FormDataExtended` is fetching old data from the editor
instances on the sheet.

Closes #2678
  • Loading branch information
arbron committed Jan 21, 2025
1 parent b66f53c commit 5097fec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion module/applications/api/application-v2-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default function ApplicationV2Mixin(Base) {
const selector = `.window-content :is(${[
"INPUT", "SELECT", "TEXTAREA", "BUTTON", "DND5E-CHECKBOX", "COLOR-PICKER", "DOCUMENT-TAGS",
"FILE-PICKER", "HUE-SLIDER", "MULTI-SELECT", "PROSE-MIRROR", "RANGE-PICKER", "STRING-TAGS"
].join(", ")}):not(.interface-only)`;
].join(", ")}):not(.interface-only, .secret > button)`;
for ( const element of this.element.querySelectorAll(selector) ) {
if ( element.tagName === "TEXTAREA" ) element.readOnly = true;
else element.disabled = true;
Expand Down
2 changes: 1 addition & 1 deletion module/applications/item/sheet-v2-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default function ItemSheetV2Mixin(Base) {
const selector = `:is(${[
"INPUT", "SELECT", "TEXTAREA", "BUTTON", "DND5E-CHECKBOX", "COLOR-PICKER", "DOCUMENT-TAGS",
"FILE-PICKER", "HUE-SLIDER", "MULTI-SELECT", "PROSE-MIRROR", "RANGE-PICKER", "STRING-TAGS"
].join(", ")}):not(.interface-only, .description-edit)`;
].join(", ")}):not(.interface-only, .description-edit, .secret > button)`;
for ( const element of form.querySelectorAll(selector) ) {
if ( element.tagName === "TEXTAREA" ) element.readOnly = true;
else element.disabled = true;
Expand Down
20 changes: 19 additions & 1 deletion module/applications/mixins/sheet-v2-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ export default function DocumentSheetV2Mixin(Base) {

/* -------------------------------------------- */

/** @override */
_getSecretContent(secret) {
const edit = secret.closest("[data-edit]")?.dataset.edit
?? secret.closest("[data-target]")?.dataset.target;
if ( edit ) return foundry.utils.getProperty(this.document, edit);
}

/* -------------------------------------------- */

/**
* Handle the user toggling the sheet mode.
* @param {Event} event The triggering event.
Expand Down Expand Up @@ -277,13 +286,22 @@ export default function DocumentSheetV2Mixin(Base) {
const content = await renderTemplate("systems/dnd5e/templates/items/parts/item-summary.hbs", context);
summary.querySelectorAll(".item-summary").forEach(el => el.remove());
summary.insertAdjacentHTML("beforeend", content);
await new Promise(resolve => requestAnimationFrame(resolve));
await new Promise(resolve => { requestAnimationFrame(resolve); });
this._expanded.add(item.id);
}

row.classList.toggle("collapsed", expanded);
icon.classList.toggle("fa-compress", !expanded);
icon.classList.toggle("fa-expand", expanded);
}

/* -------------------------------------------- */

/** @override */
_updateSecret(secret, content) {
const edit = secret.closest("[data-edit]")?.dataset.edit
?? secret.closest("[data-target]")?.dataset.target;
if ( edit ) return this.document.update({ [edit]: content });
}
};
}
2 changes: 1 addition & 1 deletion templates/actors/tabs/character-biography.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>

{{!-- Biography --}}
<div class="bottom">
<div class="bottom" data-target="system.details.biography.value">
<h3 class="icon">
<i class="fas fa-feather"></i>
<dnd5e-icon src="systems/dnd5e/icons/svg/ink-pot.svg"></dnd5e-icon>
Expand Down
7 changes: 4 additions & 3 deletions templates/items/parts/item-description2.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#*inline "description"}}
<div class="card description {{#if collapsible}}collapsible{{/if}} {{#if (lookup @root.collapsed target)}}collapsed{{/if}} {{#unless enriched}}empty{{/unless}}"
data-target="{{ target }}">
<div class="card description {{#if collapsible}}collapsible{{/if}} {{#if (lookup @root.collapsed target)}}collapsed{{/if}}
{{~#unless enriched}} empty{{/unless}}" data-target="{{ target }}">
<div class="header">
<span>{{ localize label }}</span>
{{#if @root.owner}}
Expand All @@ -18,7 +18,8 @@
</div>
{{/inline}}

<div class="tab {{#if singleDescription}}single-description{{/if}}" data-group="primary" data-tab="description">
<div class="tab {{#if singleDescription}}single-description{{/if}}" data-group="primary" data-tab="description"
{{~#if singleDescription}} data-target="system.description.value"{{/if}}>

{{#if editingDescriptionTarget}}
{{ editor enriched.editing target=editingDescriptionTarget button=false editable=true engine="prosemirror"
Expand Down

0 comments on commit 5097fec

Please sign in to comment.