Skip to content

Commit eabc814

Browse files
authored
Search sources in addition to item names in ABC Picker (foundryvtt#17040)
1 parent 3fc8419 commit eabc814

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"nouislider": "^15.8.1",
9494
"remeda": "^2.15.2",
9595
"sortablejs": "^1.15.3",
96-
"svelte": "^5.0.2",
96+
"svelte": "^5.1.4",
9797
"uuid": "^10.0.0"
9898
}
9999
}

src/module/actor/character/apps/abc-picker/app.svelte

+36-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
2-
import type { ItemPF2e } from "@item";
3-
import { ErrorPF2e, htmlQuery } from "@util";
2+
import { ErrorPF2e } from "@util";
3+
import type { KeyboardEventHandler, MouseEventHandler } from "svelte/elements";
44
import type { ABCPickerContext } from "./app.ts";
55
66
const { actor, foundryApp, state: data }: ABCPickerContext = $props();
@@ -11,64 +11,63 @@
1111
1212
let selection: string | null = $state(null);
1313
/** Show the confirmation button. */
14-
function showConfirmation(button: HTMLButtonElement): void {
15-
const row = button.closest("li");
14+
const showConfirmation: MouseEventHandler<HTMLButtonElement> = (event): void => {
15+
const row = event.currentTarget.closest("li");
1616
selection = selection === row?.dataset.uuid ? null : (row?.dataset.uuid ?? null);
17-
}
17+
};
1818
1919
/** Open an item sheet to show additional details. */
20-
async function viewItemSheet(uuid: ItemUUID): Promise<void> {
21-
const item = await fromUuid<ItemPF2e>(uuid);
20+
const viewItemSheet: MouseEventHandler<HTMLButtonElement> = async (event): Promise<void> => {
21+
const uuid = event.currentTarget.closest("li")?.dataset?.uuid ?? "";
22+
const item = await fromUuid(uuid);
2223
item?.sheet.render(true);
23-
}
24+
};
2425
2526
/** Create a new embedded ABC item on the character. */
26-
async function saveSelection(uuid: ItemUUID): Promise<void> {
27-
const item = await fromUuid<ItemPF2e>(uuid);
28-
if (!item) throw ErrorPF2e(`Unexpected error retrieving ${data.itemType}`);
29-
actor.createEmbeddedDocuments("Item", [item.clone().toObject()]);
27+
const saveSelection: MouseEventHandler<HTMLButtonElement> = async (event): Promise<void> => {
28+
const uuid = event.currentTarget.closest("li")?.dataset?.uuid ?? "";
29+
const item = await fromUuid(uuid);
30+
if (!(item instanceof Item) || item.type !== data.itemType) {
31+
throw ErrorPF2e(`Unexpected error retrieving ${data.itemType}`);
32+
}
33+
actor.createEmbeddedDocuments("Item", [{ ...item.toObject(), _id: null }]);
3034
foundryApp.close();
31-
}
35+
};
3236
3337
/** Search list and show or hide according to match result. */
34-
const searchItems = fu.debounce((query: string) => {
38+
const searchItems: KeyboardEventHandler<HTMLInputElement> = (event) => debouncedSearch(event.currentTarget.value);
39+
const debouncedSearch = fu.debounce((query: string) => {
3540
const regexp = new RegExp(RegExp.escape(query.trim()), "i");
3641
for (const row of foundryApp.element.getElementsByTagName("li")) {
37-
row.hidden = !regexp.test(htmlQuery(row, "[data-name]")?.innerText ?? "");
42+
row.hidden = !regexp.test(row.innerText ?? "");
3843
}
3944
}, 200);
4045
</script>
4146

4247
<header class="search">
4348
<i class="fa-solid fa-search"></i>
44-
<input
45-
type="search"
46-
spellcheck="false"
47-
placeholder={searchPlaceholder}
48-
onkeyup={(event) => searchItems(event.currentTarget.value)}
49-
/>
49+
<input type="search" spellcheck="false" placeholder={searchPlaceholder} onkeyup={searchItems} />
5050
</header>
5151

5252
<ul>
5353
{#each data.items as item}
54-
<li data-uuid={item.uuid}>
54+
<li class:selected={selection === item.uuid} data-uuid={item.uuid}>
5555
<img src={item.img} loading="lazy" alt="Class icon" />
56-
<button type="button" class="flat name-source" onclick={(e) => showConfirmation(e.currentTarget)}>
57-
<div class="name" data-name>{item.name}</div>
56+
<button type="button" class="flat name-source" onclick={showConfirmation}>
57+
<div class="name">{item.name}</div>
5858
<div class="source" class:publication={item.source.publication}>{item.source.name}</div>
5959
</button>
6060
<div class="buttons">
6161
<button
6262
type="button"
6363
class="confirm"
64-
class:selected={selection === item.uuid}
6564
data-tooltip="PF2E.Actor.Character.ABCPicker.Tooltip.ConfirmSelection"
66-
onclick={() => saveSelection(item.uuid)}><i class="fa-solid fa-check"></i></button
65+
onclick={saveSelection}><i class="fa-solid fa-check"></i></button
6766
>
6867
<button
6968
type="button"
7069
data-tooltip="PF2E.Actor.Character.ABCPicker.Tooltip.ViewSheet"
71-
onclick={() => viewItemSheet(item.uuid)}><i class="fa-solid fa-info fa-fw"></i></button
70+
onclick={viewItemSheet}><i class="fa-solid fa-info fa-fw"></i></button
7271
>
7372
</div>
7473
</li>
@@ -129,11 +128,6 @@
129128
font-style: italic;
130129
}
131130
}
132-
133-
&:hover + .buttons button.confirm:not(.selected) {
134-
opacity: 0.33;
135-
visibility: visible;
136-
}
137131
}
138132
139133
.buttons {
@@ -159,14 +153,19 @@
159153
&:not(:hover) {
160154
color: darkgreen;
161155
}
162-
163-
&.selected {
164-
opacity: 1;
165-
visibility: visible;
166-
}
167156
}
168157
}
169158
}
159+
160+
&:hover:not(.selected) button.confirm {
161+
opacity: 0.33;
162+
visibility: visible;
163+
}
164+
165+
&.selected button.confirm {
166+
opacity: 1;
167+
visibility: visible;
168+
}
170169
}
171170
}
172171
</style>

0 commit comments

Comments
 (0)